Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added AiBreathe package (feature #1374)
- Loading branch information
Showing
6 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "aibreathe.hpp" | ||
|
||
#include "../mwbase/world.hpp" | ||
#include "../mwbase/environment.hpp" | ||
|
||
#include "../mwworld/class.hpp" | ||
#include "../mwworld/esmstore.hpp" | ||
|
||
#include "npcstats.hpp" | ||
|
||
#include "movement.hpp" | ||
#include "steering.hpp" | ||
|
||
MWMechanics::AiBreathe::AiBreathe() | ||
: AiPackage() | ||
{ | ||
|
||
} | ||
|
||
bool MWMechanics::AiBreathe::execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration) | ||
{ | ||
static const float fHoldBreathTime = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("fHoldBreathTime")->getFloat(); | ||
|
||
const MWWorld::Class& actorClass = actor.getClass(); | ||
if (actorClass.isNpc()) | ||
{ | ||
if (actorClass.getNpcStats(actor).getTimeToStartDrowning() < fHoldBreathTime / 2) | ||
{ | ||
actor.getClass().getCreatureStats(actor).setMovementFlag(CreatureStats::Flag_Run, true); | ||
|
||
actor.getClass().getMovementSettings(actor).mPosition[1] = 1; | ||
smoothTurn(actor, -180, 0); | ||
|
||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
MWMechanics::AiBreathe *MWMechanics::AiBreathe::clone() const | ||
{ | ||
return new AiBreathe(*this); | ||
} | ||
|
||
int MWMechanics::AiBreathe::getTypeId() const | ||
{ | ||
return TypeIdBreathe; | ||
} | ||
|
||
unsigned int MWMechanics::AiBreathe::getPriority() const | ||
{ | ||
return 2; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#ifndef GAME_MWMECHANICS_AIBREATHE_H | ||
#define GAME_MWMECHANICS_AIBREATHE_H | ||
|
||
#include "aipackage.hpp" | ||
|
||
namespace MWMechanics | ||
{ | ||
/// \brief AiPackage to have an actor resurface to breathe | ||
// The AI will go up if lesser than half breath left | ||
class AiBreathe : public AiPackage | ||
{ | ||
public: | ||
AiBreathe(); | ||
|
||
virtual AiBreathe *clone() const; | ||
|
||
virtual bool execute (const MWWorld::Ptr& actor, CharacterController& characterController, AiState& state, float duration); | ||
|
||
virtual int getTypeId() const; | ||
|
||
virtual unsigned int getPriority() const; | ||
|
||
virtual bool canCancel() const { return false; } | ||
virtual bool shouldCancelPreviousAi() const { return false; } | ||
}; | ||
} | ||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters