forked from mirror/openmw-tes3mp
Cleaned up code, implemented crime ids
There is a problem with my game freezing. ToggleAi stops my character
This commit is contained in:
parent
df5cbe5dec
commit
940c88d2ec
8 changed files with 95 additions and 53 deletions
|
@ -31,8 +31,6 @@
|
||||||
#include "aifollow.hpp"
|
#include "aifollow.hpp"
|
||||||
#include "aipersue.hpp"
|
#include "aipersue.hpp"
|
||||||
|
|
||||||
#include "../mwbase/dialoguemanager.hpp" //------------------------
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -718,49 +716,58 @@ namespace MWMechanics
|
||||||
|
|
||||||
void Actors::updateCrimePersuit(const MWWorld::Ptr& ptr, float duration)
|
void Actors::updateCrimePersuit(const MWWorld::Ptr& ptr, float duration)
|
||||||
{
|
{
|
||||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
MWWorld::Ptr playerPtr = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||||
CreatureStats& creatureStats = MWWorld::Class::get(ptr).getCreatureStats(ptr);
|
if (ptr != playerPtr)
|
||||||
|
|
||||||
/// \todo Move me! I shouldn't be here...
|
|
||||||
const MWWorld::ESMStore& esmStore = MWBase::Environment::get().getWorld()->getStore();
|
|
||||||
float cutoff = float(esmStore.get<ESM::GameSetting>().find("iCrimeThreshold")->getInt()) *
|
|
||||||
float(esmStore.get<ESM::GameSetting>().find("iCrimeThresholdMultiplier")->getInt()) *
|
|
||||||
esmStore.get<ESM::GameSetting>().find("fCrimeGoldDiscountMult")->getFloat();
|
|
||||||
|
|
||||||
if (ptr != player)
|
|
||||||
{
|
{
|
||||||
|
// get stats of witness
|
||||||
|
CreatureStats& creatureStats = MWWorld::Class::get(ptr).getCreatureStats(ptr);
|
||||||
|
NpcStats& npcStats = MWWorld::Class::get(ptr).getNpcStats(ptr);
|
||||||
|
MWWorld::Player player = MWBase::Environment::get().getWorld()->getPlayer();
|
||||||
|
|
||||||
// If I'm a guard and I'm not hostile
|
// If I'm a guard and I'm not hostile
|
||||||
if (ptr.getClass().isClass(ptr, "Guard") && !creatureStats.isHostile())
|
if (ptr.getClass().isClass(ptr, "Guard") && !creatureStats.isHostile())
|
||||||
{
|
{
|
||||||
|
/// \todo Move me! I shouldn't be here...
|
||||||
|
const MWWorld::ESMStore& esmStore = MWBase::Environment::get().getWorld()->getStore();
|
||||||
|
float cutoff = float(esmStore.get<ESM::GameSetting>().find("iCrimeThreshold")->getInt()) *
|
||||||
|
float(esmStore.get<ESM::GameSetting>().find("iCrimeThresholdMultiplier")->getInt()) *
|
||||||
|
esmStore.get<ESM::GameSetting>().find("fCrimeGoldDiscountMult")->getFloat();
|
||||||
// Attack on sight if bounty is greater than the cutoff
|
// Attack on sight if bounty is greater than the cutoff
|
||||||
if ( player.getClass().getNpcStats(player).getBounty() >= cutoff
|
if ( playerPtr.getClass().getNpcStats(playerPtr).getBounty() >= cutoff
|
||||||
&& MWBase::Environment::get().getWorld()->getLOS(ptr, player)
|
&& MWBase::Environment::get().getWorld()->getLOS(ptr, playerPtr)
|
||||||
&& MWBase::Environment::get().getMechanicsManager()->awarenessCheck(player, ptr))
|
&& MWBase::Environment::get().getMechanicsManager()->awarenessCheck(playerPtr, ptr))
|
||||||
{
|
{
|
||||||
creatureStats.getAiSequence().stack(AiCombat(player));
|
creatureStats.getAiSequence().stack(AiCombat(playerPtr));
|
||||||
creatureStats.setHostile(true);
|
creatureStats.setHostile(true);
|
||||||
creatureStats.setAlarmed(true);
|
npcStats.setCrimeId(player.getNewCrimeId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if I was a witness to a crime
|
// if I was a witness to a crime
|
||||||
if (creatureStats.isAlarmed())
|
if (npcStats.getCrimeId() != -1)
|
||||||
{
|
{
|
||||||
if(player.getClass().getNpcStats(player).getBounty() == 0)
|
// if you've payed for your crimes and I havent noticed
|
||||||
|
if(npcStats.getCrimeId() < player.getCrimeId() )
|
||||||
{
|
{
|
||||||
creatureStats.setAlarmed(false);
|
// Calm witness down
|
||||||
creatureStats.setHostile(false);
|
|
||||||
creatureStats.setAttacked(false);
|
|
||||||
if (ptr.getClass().isClass(ptr, "Guard"))
|
if (ptr.getClass().isClass(ptr, "Guard"))
|
||||||
creatureStats.getAiSequence().stopPersue();
|
creatureStats.getAiSequence().stopPersue();
|
||||||
creatureStats.getAiSequence().stopCombat();
|
creatureStats.getAiSequence().stopCombat();
|
||||||
|
|
||||||
|
// Reset factors to attack
|
||||||
|
// TODO: Not a complete list, disposition changes?
|
||||||
|
creatureStats.setHostile(false);
|
||||||
|
creatureStats.setAttacked(false);
|
||||||
|
|
||||||
|
// Update witness crime id
|
||||||
|
npcStats.setCrimeId(-1);
|
||||||
}
|
}
|
||||||
else if (!creatureStats.isHostile())
|
else if (!creatureStats.isHostile())
|
||||||
{
|
{
|
||||||
if (ptr.getClass().isClass(ptr, "Guard"))
|
if (ptr.getClass().isClass(ptr, "Guard"))
|
||||||
creatureStats.getAiSequence().stack(AiPersue(player.getClass().getId(player)));
|
creatureStats.getAiSequence().stack(AiPersue(playerPtr.getClass().getId(playerPtr)));
|
||||||
else
|
else
|
||||||
creatureStats.getAiSequence().stack(AiCombat(player));
|
creatureStats.getAiSequence().stack(AiCombat(playerPtr));
|
||||||
creatureStats.setHostile(true);
|
creatureStats.setHostile(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -768,7 +775,7 @@ namespace MWMechanics
|
||||||
// if I didn't report a crime was I attacked?
|
// if I didn't report a crime was I attacked?
|
||||||
else if (creatureStats.getAttacked() && !creatureStats.isHostile())
|
else if (creatureStats.getAttacked() && !creatureStats.isHostile())
|
||||||
{
|
{
|
||||||
creatureStats.getAiSequence().stack(AiCombat(player));
|
creatureStats.getAiSequence().stack(AiCombat(playerPtr));
|
||||||
creatureStats.setHostile(true);
|
creatureStats.setHostile(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,6 @@ namespace MWMechanics
|
||||||
bool mAlarmed;
|
bool mAlarmed;
|
||||||
bool mAttacked;
|
bool mAttacked;
|
||||||
bool mHostile;
|
bool mHostile;
|
||||||
bool mAssaulted;
|
|
||||||
bool mAttackingOrSpell;
|
bool mAttackingOrSpell;
|
||||||
bool mKnockdown;
|
bool mKnockdown;
|
||||||
bool mHitRecovery;
|
bool mHitRecovery;
|
||||||
|
@ -176,15 +175,12 @@ namespace MWMechanics
|
||||||
void talkedToPlayer();
|
void talkedToPlayer();
|
||||||
|
|
||||||
bool isAlarmed() const;
|
bool isAlarmed() const;
|
||||||
|
|
||||||
void setAlarmed (bool alarmed);
|
void setAlarmed (bool alarmed);
|
||||||
|
|
||||||
bool getAttacked() const;
|
bool getAttacked() const;
|
||||||
|
|
||||||
void setAttacked (bool attacked);
|
void setAttacked (bool attacked);
|
||||||
|
|
||||||
bool isHostile() const;
|
bool isHostile() const;
|
||||||
|
|
||||||
void setHostile (bool hostile);
|
void setHostile (bool hostile);
|
||||||
|
|
||||||
bool getCreatureTargetted() const;
|
bool getCreatureTargetted() const;
|
||||||
|
|
|
@ -828,42 +828,43 @@ namespace MWMechanics
|
||||||
// Innocent until proven guilty
|
// Innocent until proven guilty
|
||||||
bool reported = false;
|
bool reported = false;
|
||||||
|
|
||||||
// Find all the NPC's close enough, ie. within fAlarmRadius of the player
|
// Find all the NPCs within the alarm radius
|
||||||
std::vector<MWWorld::Ptr> neighbors;
|
std::vector<MWWorld::Ptr> neighbors;
|
||||||
mActors.getObjectsInRange(Ogre::Vector3(ptr.getRefData().getPosition().pos),
|
mActors.getObjectsInRange(Ogre::Vector3(ptr.getRefData().getPosition().pos),
|
||||||
esmStore.get<ESM::GameSetting>().find("fAlarmRadius")->getInt(), neighbors);
|
esmStore.get<ESM::GameSetting>().find("fAlarmRadius")->getInt(), neighbors);
|
||||||
|
|
||||||
|
// Find an actor who witnessed the crime
|
||||||
for (std::vector<MWWorld::Ptr>::iterator it = neighbors.begin(); it != neighbors.end(); ++it)
|
for (std::vector<MWWorld::Ptr>::iterator it = neighbors.begin(); it != neighbors.end(); ++it)
|
||||||
{
|
{
|
||||||
if (*it == ptr) // Not the player
|
if (*it == ptr) continue; // not the player
|
||||||
continue;
|
|
||||||
|
|
||||||
CreatureStats& creatureStats = MWWorld::Class::get(*it).getCreatureStats(*it);
|
|
||||||
|
|
||||||
// Was the crime seen?
|
// Was the crime seen?
|
||||||
if ( ( MWBase::Environment::get().getWorld()->getLOS(ptr, *it) && awarenessCheck(ptr, *it) ) ||
|
if ( ( MWBase::Environment::get().getWorld()->getLOS(ptr, *it) && awarenessCheck(ptr, *it) ) ||
|
||||||
type == OT_Assault )
|
type == OT_Assault )
|
||||||
{
|
{
|
||||||
// Say something!
|
|
||||||
// TODO: Add more messages
|
// TODO: Add more messages
|
||||||
if (type == OT_Theft)
|
if (type == OT_Theft)
|
||||||
MWBase::Environment::get().getDialogueManager()->say(*it, "Thief");
|
MWBase::Environment::get().getDialogueManager()->say(*it, "thief");
|
||||||
|
else if (type == OT_Assault)
|
||||||
|
MWBase::Environment::get().getDialogueManager()->say(*it, "attack");
|
||||||
|
|
||||||
// Will the witness report the crime?
|
// Will the witness report the crime?
|
||||||
if (creatureStats.getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm)
|
if (it->getClass().getCreatureStats(*it).getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm)
|
||||||
{
|
{
|
||||||
reported = true;
|
reported = true;
|
||||||
|
int id = player.getNewCrimeId();
|
||||||
|
|
||||||
// Tell everyone else
|
// Tell everyone, including yourself
|
||||||
for (std::vector<MWWorld::Ptr>::iterator it1 = neighbors.begin(); it1 != neighbors.end(); ++it1)
|
for (std::vector<MWWorld::Ptr>::iterator it1 = neighbors.begin(); it1 != neighbors.end(); ++it1)
|
||||||
{
|
{
|
||||||
if (*it1 == ptr) // Not the player
|
if (*it1 == ptr) continue; // not the player
|
||||||
continue;
|
|
||||||
|
|
||||||
// Will the witness be affected by the crime?
|
// Will other witnesses paticipate in crime
|
||||||
CreatureStats& creatureStats1 = MWWorld::Class::get(*it1).getCreatureStats(*it1);
|
if ( it1->getClass().getCreatureStats(*it1).getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm
|
||||||
if (creatureStats1.getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm ||
|
|| type == OT_Assault )
|
||||||
type == OT_Assault)
|
{
|
||||||
creatureStats1.setAlarmed(true);
|
it1->getClass().getNpcStats(*it1).setCrimeId(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break; // Someone saw the crime and everyone has been told
|
break; // Someone saw the crime and everyone has been told
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ MWMechanics::NpcStats::NpcStats()
|
||||||
, mLevelProgress(0)
|
, mLevelProgress(0)
|
||||||
, mDisposition(0)
|
, mDisposition(0)
|
||||||
, mReputation(0)
|
, mReputation(0)
|
||||||
|
, mCrimeId(-1)
|
||||||
, mWerewolfKills (0)
|
, mWerewolfKills (0)
|
||||||
, mProfit(0)
|
, mProfit(0)
|
||||||
, mTimeToStartDrowning(20.0)
|
, mTimeToStartDrowning(20.0)
|
||||||
|
@ -340,6 +341,16 @@ void MWMechanics::NpcStats::setReputation(int reputation)
|
||||||
mReputation = reputation;
|
mReputation = reputation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int MWMechanics::NpcStats::getCrimeId() const
|
||||||
|
{
|
||||||
|
return mCrimeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MWMechanics::NpcStats::setCrimeId(int id)
|
||||||
|
{
|
||||||
|
mCrimeId = id;
|
||||||
|
}
|
||||||
|
|
||||||
bool MWMechanics::NpcStats::hasSkillsForRank (const std::string& factionId, int rank) const
|
bool MWMechanics::NpcStats::hasSkillsForRank (const std::string& factionId, int rank) const
|
||||||
{
|
{
|
||||||
if (rank<0 || rank>=10)
|
if (rank<0 || rank>=10)
|
||||||
|
|
|
@ -37,6 +37,7 @@ namespace MWMechanics
|
||||||
std::set<std::string> mExpelled;
|
std::set<std::string> mExpelled;
|
||||||
std::map<std::string, int> mFactionReputation;
|
std::map<std::string, int> mFactionReputation;
|
||||||
int mReputation;
|
int mReputation;
|
||||||
|
int mCrimeId;
|
||||||
int mWerewolfKills;
|
int mWerewolfKills;
|
||||||
int mProfit;
|
int mProfit;
|
||||||
float mAttackStrength;
|
float mAttackStrength;
|
||||||
|
@ -63,13 +64,14 @@ namespace MWMechanics
|
||||||
void modifyProfit(int diff);
|
void modifyProfit(int diff);
|
||||||
|
|
||||||
int getBaseDisposition() const;
|
int getBaseDisposition() const;
|
||||||
|
|
||||||
void setBaseDisposition(int disposition);
|
void setBaseDisposition(int disposition);
|
||||||
|
|
||||||
int getReputation() const;
|
int getReputation() const;
|
||||||
|
|
||||||
void setReputation(int reputation);
|
void setReputation(int reputation);
|
||||||
|
|
||||||
|
int getCrimeId() const;
|
||||||
|
void setCrimeId(int id);
|
||||||
|
|
||||||
const SkillValue& getSkill (int index) const;
|
const SkillValue& getSkill (int index) const;
|
||||||
SkillValue& getSkill (int index);
|
SkillValue& getSkill (int index);
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "../mwbase/scriptmanager.hpp"
|
#include "../mwbase/scriptmanager.hpp"
|
||||||
|
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
#include "../mwworld/player.hpp"
|
||||||
#include "../mwworld/containerstore.hpp"
|
#include "../mwworld/containerstore.hpp"
|
||||||
#include "../mwworld/esmstore.hpp"
|
#include "../mwworld/esmstore.hpp"
|
||||||
|
|
||||||
|
@ -802,6 +803,7 @@ namespace MWScript
|
||||||
{
|
{
|
||||||
MWBase::World* world = MWBase::Environment::get().getWorld();
|
MWBase::World* world = MWBase::Environment::get().getWorld();
|
||||||
world->goToJail();
|
world->goToJail();
|
||||||
|
MWBase::Environment::get().getWorld()->getPlayer().recordCrimeId();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -812,6 +814,7 @@ namespace MWScript
|
||||||
{
|
{
|
||||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||||
player.getClass().getNpcStats(player).setBounty(0);
|
player.getClass().getNpcStats(player).setBounty(0);
|
||||||
|
MWBase::Environment::get().getWorld()->getPlayer().recordCrimeId();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -823,6 +826,7 @@ namespace MWScript
|
||||||
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr();
|
||||||
player.getClass().getNpcStats(player).setBounty(0);
|
player.getClass().getNpcStats(player).setBounty(0);
|
||||||
MWBase::Environment::get().getWorld()->confiscateStolenItems(player);
|
MWBase::Environment::get().getWorld()->confiscateStolenItems(player);
|
||||||
|
MWBase::Environment::get().getWorld()->getPlayer().recordCrimeId();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,9 @@ namespace MWWorld
|
||||||
mAutoMove(false),
|
mAutoMove(false),
|
||||||
mForwardBackward(0),
|
mForwardBackward(0),
|
||||||
mTeleported(false),
|
mTeleported(false),
|
||||||
mMarkedCell(NULL)
|
mMarkedCell(NULL),
|
||||||
|
mCurrentCrimeId(-1),
|
||||||
|
mPayedCrimeId(-1)
|
||||||
{
|
{
|
||||||
mPlayer.mBase = player;
|
mPlayer.mBase = player;
|
||||||
mPlayer.mRef.mRefID = "player";
|
mPlayer.mRef.mRefID = "player";
|
||||||
|
@ -274,4 +276,19 @@ namespace MWWorld
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Player::getNewCrimeId()
|
||||||
|
{
|
||||||
|
return mCurrentCrimeId++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::recordCrimeId()
|
||||||
|
{
|
||||||
|
mPayedCrimeId = mCurrentCrimeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Player::getCrimeId() const
|
||||||
|
{
|
||||||
|
return mCurrentCrimeId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,9 @@ namespace MWWorld
|
||||||
bool mAutoMove;
|
bool mAutoMove;
|
||||||
int mForwardBackward;
|
int mForwardBackward;
|
||||||
bool mTeleported;
|
bool mTeleported;
|
||||||
|
|
||||||
|
int mCurrentCrimeId; // the id assigned witnesses
|
||||||
|
int mPayedCrimeId; // the last id payed off (0 bounty)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -64,15 +67,12 @@ namespace MWWorld
|
||||||
MWWorld::Ptr getPlayer();
|
MWWorld::Ptr getPlayer();
|
||||||
|
|
||||||
void setBirthSign(const std::string &sign);
|
void setBirthSign(const std::string &sign);
|
||||||
|
|
||||||
const std::string &getBirthSign() const;
|
const std::string &getBirthSign() const;
|
||||||
|
|
||||||
void setDrawState (MWMechanics::DrawState_ state);
|
void setDrawState (MWMechanics::DrawState_ state);
|
||||||
|
|
||||||
bool getAutoMove() const;
|
|
||||||
|
|
||||||
MWMechanics::DrawState_ getDrawState(); /// \todo constness
|
MWMechanics::DrawState_ getDrawState(); /// \todo constness
|
||||||
|
|
||||||
|
bool getAutoMove() const;
|
||||||
void setAutoMove (bool enable);
|
void setAutoMove (bool enable);
|
||||||
|
|
||||||
void setLeftRight (int value);
|
void setLeftRight (int value);
|
||||||
|
@ -95,6 +95,10 @@ namespace MWWorld
|
||||||
void write (ESM::ESMWriter& writer) const;
|
void write (ESM::ESMWriter& writer) const;
|
||||||
|
|
||||||
bool readRecord (ESM::ESMReader& reader, int32_t type);
|
bool readRecord (ESM::ESMReader& reader, int32_t type);
|
||||||
|
|
||||||
|
int getNewCrimeId(); // get new id for witnesses
|
||||||
|
void recordCrimeId(); // record the payed crime id when bounty is 0
|
||||||
|
int getCrimeId() const; // get the last payed crime id
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue