From 0c957a3cde6c93830c587b3bb6e5a4687f6184be Mon Sep 17 00:00:00 2001 From: Jeffrey Haines Date: Thu, 3 Apr 2014 14:53:31 -0400 Subject: [PATCH] Added witnesses to the mix --- apps/openmw/mwmechanics/actors.cpp | 44 ++++++++++++------- apps/openmw/mwmechanics/creaturestats.cpp | 12 ++++- apps/openmw/mwmechanics/creaturestats.hpp | 5 +++ .../mwmechanics/mechanicsmanagerimp.cpp | 11 ++++- apps/openmw/mwworld/player.cpp | 13 +++++- apps/openmw/mwworld/player.hpp | 6 +++ 6 files changed, 70 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 11469c1a9..6d9f23aa2 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -719,9 +719,9 @@ namespace MWMechanics void Actors::updateCrimePersuit(const MWWorld::Ptr& ptr, float duration) { MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayerPtr(); - int bounty = player.getClass().getNpcStats(player).getBounty(); + CreatureStats& creatureStats = MWWorld::Class::get(ptr).getCreatureStats(ptr); - // TODO: Move me! I shouldn't be here... + /// \todo Move me! I shouldn't be here... const MWWorld::ESMStore& esmStore = MWBase::Environment::get().getWorld()->getStore(); float cutoff = float(esmStore.get().find("iCrimeThreshold")->getInt()) * float(esmStore.get().find("iCrimeThresholdMultiplier")->getInt()) * @@ -729,30 +729,40 @@ namespace MWMechanics if (ptr != player) { - CreatureStats& creatureStats = MWWorld::Class::get(ptr).getCreatureStats(ptr); - // Alarmed or not, I will kill you because you've commited heinous against the empire - if ((!creatureStats.isAlarmed() || creatureStats.isAlarmed()) && - ptr.getClass().isClass(ptr, "Guard") && bounty >= cutoff && !creatureStats.isHostile()) - creatureStats.getAiSequence().stack(AiPersue(player.getClass().getId(player))); - else if (creatureStats.isAlarmed()) + // If I'm a guard and I'm not hostile + if (ptr.getClass().isClass(ptr, "Guard") && !creatureStats.isHostile()) + { + // Attack on sight if bounty is greater than the cutoff + if ( player.getClass().getNpcStats(player).getBounty() >= cutoff + && MWBase::Environment::get().getWorld()->getLOS(ptr, player) + && MWBase::Environment::get().getMechanicsManager()->awarenessCheck(player, ptr)) + { + creatureStats.getAiSequence().stack(AiCombat(player)); + creatureStats.setHostile(true); + } + } + + // if I was a witness to a crime + if (creatureStats.getCrimeId() != -1) { - MWBase::Environment::get().getDialogueManager()->say(ptr, "Thief"); - if(bounty == 0) + if(player.getClass().getNpcStats(player).getBounty() == 0) { creatureStats.setAlarmed(false); creatureStats.setHostile(false); if (ptr.getClass().isClass(ptr, "Guard")) creatureStats.getAiSequence().stopPersue(); creatureStats.getAiSequence().stopCombat(); - + creatureStats.setCrimeId(-1); } - - if (ptr.getClass().isClass(ptr, "Guard") && !creatureStats.isHostile()) - creatureStats.getAiSequence().stack(AiPersue(player.getClass().getId(player))); - else if (!creatureStats.isHostile()) + else if (creatureStats.isAlarmed()) { - creatureStats.getAiSequence().stack(AiCombat(player)); - creatureStats.setHostile(true); + if (ptr.getClass().isClass(ptr, "Guard") && !creatureStats.isHostile()) + creatureStats.getAiSequence().stack(AiPersue(player.getClass().getId(player))); + else if (!creatureStats.isHostile()) + { + creatureStats.getAiSequence().stack(AiCombat(player)); + creatureStats.setHostile(true); + } } } } diff --git a/apps/openmw/mwmechanics/creaturestats.cpp b/apps/openmw/mwmechanics/creaturestats.cpp index a358917de..17d36be79 100644 --- a/apps/openmw/mwmechanics/creaturestats.cpp +++ b/apps/openmw/mwmechanics/creaturestats.cpp @@ -15,7 +15,7 @@ namespace MWMechanics : mLevel (0), mDead (false), mDied (false), mFriendlyHits (0), mTalkedTo (false), mAlarmed (false), mAttacked (false), mHostile (false), mAssaulted(false), - mAttackingOrSpell(false), + mAttackingOrSpell(false), mCrimeId(-1), mIsWerewolf(false), mFallHeight(0), mRecalcDynamicStats(false), mKnockdown(false), mHitRecovery(false), mBlock(false), mMovementFlags(0), mDrawState (DrawState_Nothing), mAttackStrength(0.f) @@ -326,6 +326,16 @@ namespace MWMechanics mAssaulted = assaulted; } + int CreatureStats::getCrimeId() const + { + return mCrimeId; + } + + void CreatureStats::setCrimeId (int id) + { + mCrimeId = id; + } + bool CreatureStats::getCreatureTargetted() const { std::string target; diff --git a/apps/openmw/mwmechanics/creaturestats.hpp b/apps/openmw/mwmechanics/creaturestats.hpp index 7db895dab..67afd9f25 100644 --- a/apps/openmw/mwmechanics/creaturestats.hpp +++ b/apps/openmw/mwmechanics/creaturestats.hpp @@ -40,6 +40,7 @@ namespace MWMechanics bool mAttacked; bool mHostile; bool mAssaulted; + int mCrimeId; bool mAttackingOrSpell; bool mKnockdown; bool mHitRecovery; @@ -191,6 +192,10 @@ namespace MWMechanics void setAssaulted (bool assaulted); + int getCrimeId() const; + + void setCrimeId (int id); + bool getCreatureTargetted() const; float getEvasion() const; diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index 39cf63cd0..54622c0b4 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -810,6 +810,7 @@ namespace MWMechanics return false; const MWWorld::ESMStore& esmStore = MWBase::Environment::get().getWorld()->getStore(); + MWWorld::Player player = MWBase::Environment::get().getWorld()->getPlayer(); // What amount of alarm did this crime generate? int alarm; @@ -858,13 +859,19 @@ namespace MWMechanics if (*it1 == ptr) // Not the player continue; - // was the witness alarmed? + // Will the witness be affected by the crime? CreatureStats& creatureStats1 = MWWorld::Class::get(*it1).getCreatureStats(*it1); if (creatureStats1.getAiSetting(CreatureStats::AI_Alarm).getBase() >= alarm) + { creatureStats1.setAlarmed(true); + creatureStats1.setCrimeId(player.getWitnessTotal()); + player.addWitness(); + } } break; // Someone saw the crime and everyone has been told - } + } + else if (type == OT_Assault) + creatureStats.setAlarmed(true); } } if (reported) diff --git a/apps/openmw/mwworld/player.cpp b/apps/openmw/mwworld/player.cpp index 6d551ecf1..7c576960f 100644 --- a/apps/openmw/mwworld/player.cpp +++ b/apps/openmw/mwworld/player.cpp @@ -28,8 +28,9 @@ namespace MWWorld : mCellStore(0), mLastKnownExteriorPosition(0,0,0), mAutoMove(false), - mForwardBackward (0), + mForwardBackward(0), mTeleported(false), + mWitnessTotal(0), mMarkedCell(NULL) { mPlayer.mBase = player; @@ -65,6 +66,16 @@ namespace MWWorld return mSign; } + void Player::addWitness() + { + mWitnessTotal++; + } + + int Player::getWitnessTotal() const + { + return mWitnessTotal; + } + void Player::setDrawState (MWMechanics::DrawState_ state) { MWWorld::Ptr ptr = getPlayer(); diff --git a/apps/openmw/mwworld/player.hpp b/apps/openmw/mwworld/player.hpp index 9d3fbbeec..71c231481 100644 --- a/apps/openmw/mwworld/player.hpp +++ b/apps/openmw/mwworld/player.hpp @@ -41,6 +41,8 @@ namespace MWWorld bool mAutoMove; int mForwardBackward; bool mTeleported; + + int mWitnessTotal; public: @@ -65,6 +67,10 @@ namespace MWWorld void setBirthSign(const std::string &sign); + void addWitness(); + + int getWitnessTotal() const; + const std::string &getBirthSign() const; void setDrawState (MWMechanics::DrawState_ state);