1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-03 20:39:40 +00:00

ToggleAI script instruction

This commit is contained in:
gus 2013-11-18 23:03:44 +01:00
parent 4559e932ae
commit dff3cf162d
8 changed files with 76 additions and 33 deletions

View file

@ -114,6 +114,9 @@ namespace MWBase
/// references that are currently not in the scene should be ignored. /// references that are currently not in the scene should be ignored.
virtual bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string& groupName) = 0; virtual bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string& groupName) = 0;
virtual void toggleAI() = 0;
virtual bool isAIActive() = 0;
}; };
} }

View file

@ -39,8 +39,12 @@ namespace MWMechanics
if(!MWBase::Environment::get().getWindowManager()->isGuiMode()) if(!MWBase::Environment::get().getWindowManager()->isGuiMode())
{ {
// AI // AI
if(MWBase::Environment::get().getMechanicsManager())//check MechanismsManager is already created
{
if(MWBase::Environment::get().getMechanicsManager()->isAIActive())//MWBase::Environment::get().getMechanicsManager()->isAIActive())
{
CreatureStats& creatureStats = MWWorld::Class::get (ptr).getCreatureStats (ptr); CreatureStats& creatureStats = MWWorld::Class::get (ptr).getCreatureStats (ptr);
if(ptr != MWBase::Environment::get().getWorld()->getPlayer().getPlayer()) MWBase::Environment::get().getMechanicsManager()->restoreDynamicStats();
//engage combat or not? //engage combat or not?
if(ptr != MWBase::Environment::get().getWorld()->getPlayer().getPlayer() && !creatureStats.isHostile()) if(ptr != MWBase::Environment::get().getWorld()->getPlayer().getPlayer() && !creatureStats.isHostile())
{ {
@ -74,6 +78,8 @@ namespace MWMechanics
} }
creatureStats.getAiSequence().execute (ptr,duration); creatureStats.getAiSequence().execute (ptr,duration);
}
}
// fatigue restoration // fatigue restoration
calculateRestoration(ptr, duration); calculateRestoration(ptr, duration);

View file

@ -165,7 +165,7 @@ namespace MWMechanics
MechanicsManager::MechanicsManager() MechanicsManager::MechanicsManager()
: mUpdatePlayer (true), mClassSelected (false), : mUpdatePlayer (true), mClassSelected (false),
mRaceSelected (false) mRaceSelected (false), mAI(true)
{ {
buildPlayer(); buildPlayer();
} }
@ -679,4 +679,14 @@ namespace MWMechanics
return false; return false;
} }
void MechanicsManager::toggleAI()
{
mAI = !mAI;
}
bool MechanicsManager::isAIActive()
{
return mAI;
}
} }

View file

@ -29,6 +29,7 @@ namespace MWMechanics
bool mUpdatePlayer; bool mUpdatePlayer;
bool mClassSelected; bool mClassSelected;
bool mRaceSelected; bool mRaceSelected;
bool mAI;///< is AI active?
Objects mObjects; Objects mObjects;
Actors mActors; Actors mActors;
@ -100,6 +101,9 @@ namespace MWMechanics
virtual void playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number); virtual void playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number);
virtual void skipAnimation(const MWWorld::Ptr& ptr); virtual void skipAnimation(const MWWorld::Ptr& ptr);
virtual bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string &groupName); virtual bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string &groupName);
virtual void toggleAI();
virtual bool isAIActive();
}; };
} }

View file

@ -25,6 +25,8 @@
#include <iostream> #include <iostream>
#include "../mwbase/mechanicsmanager.hpp"
namespace MWScript namespace MWScript
{ {
namespace Ai namespace Ai
@ -390,6 +392,17 @@ namespace MWScript
} }
}; };
template<class R>
class OpToggleAI : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWBase::Environment::get().getMechanicsManager()->toggleAI();
}
};
void installOpcodes (Interpreter::Interpreter& interpreter) void installOpcodes (Interpreter::Interpreter& interpreter)
{ {
interpreter.installSegment3 (Compiler::Ai::opcodeAIActivate, new OpAiActivate<ImplicitRef>); interpreter.installSegment3 (Compiler::Ai::opcodeAIActivate, new OpAiActivate<ImplicitRef>);
@ -416,6 +429,8 @@ namespace MWScript
interpreter.installSegment3 (Compiler::Ai::opcodeGetDetectedExplicit, new OpGetDetected<ExplicitRef>); interpreter.installSegment3 (Compiler::Ai::opcodeGetDetectedExplicit, new OpGetDetected<ExplicitRef>);
interpreter.installSegment5 (Compiler::Ai::opcodeGetLineOfSight, new OpGetLineOfSight<ImplicitRef>); interpreter.installSegment5 (Compiler::Ai::opcodeGetLineOfSight, new OpGetLineOfSight<ImplicitRef>);
interpreter.installSegment5 (Compiler::Ai::opcodeGetLineOfSightExplicit, new OpGetLineOfSight<ExplicitRef>); interpreter.installSegment5 (Compiler::Ai::opcodeGetLineOfSightExplicit, new OpGetLineOfSight<ExplicitRef>);
interpreter.installSegment5 (Compiler::Ai::opcodeToggleAI, new OpToggleAI<ImplicitRef>);
interpreter.installSegment5 (Compiler::Ai::opcodeToggleAIExplicit, new OpToggleAI<ExplicitRef>);
interpreter.installSegment5 (Compiler::Ai::opcodeSetHello, new OpSetAiSetting<ImplicitRef>(0)); interpreter.installSegment5 (Compiler::Ai::opcodeSetHello, new OpSetAiSetting<ImplicitRef>(0));
interpreter.installSegment5 (Compiler::Ai::opcodeSetHelloExplicit, new OpSetAiSetting<ExplicitRef>(0)); interpreter.installSegment5 (Compiler::Ai::opcodeSetHelloExplicit, new OpSetAiSetting<ExplicitRef>(0));

View file

@ -356,5 +356,7 @@ op 0x2000220: DisableLevitation
op 0x2000221: EnableLevitation op 0x2000221: EnableLevitation
op 0x2000222: GetLineOfSight op 0x2000222: GetLineOfSight
op 0x2000223: GetLineOfSightExplicit op 0x2000223: GetLineOfSightExplicit
op 0x2000224: ToggleAI
op 0x2000225: ToggleAIExplicit
opcodes 0x2000224-0x3ffffff unused opcodes 0x2000226-0x3ffffff unused

View file

@ -59,6 +59,7 @@ namespace Compiler
extensions.registerInstruction ("modfight", "l", opcodeModFight, opcodeModFightExplicit); extensions.registerInstruction ("modfight", "l", opcodeModFight, opcodeModFightExplicit);
extensions.registerInstruction ("modflee", "l", opcodeModFlee, opcodeModFleeExplicit); extensions.registerInstruction ("modflee", "l", opcodeModFlee, opcodeModFleeExplicit);
extensions.registerInstruction ("modalarm", "l", opcodeModAlarm, opcodeModAlarmExplicit); extensions.registerInstruction ("modalarm", "l", opcodeModAlarm, opcodeModAlarmExplicit);
extensions.registerInstruction ("toggleai", "", opcodeToggleAI, opcodeToggleAI);
extensions.registerFunction ("gethello", 'l', "", opcodeGetHello, opcodeGetHelloExplicit); extensions.registerFunction ("gethello", 'l', "", opcodeGetHello, opcodeGetHelloExplicit);
extensions.registerFunction ("getfight", 'l', "", opcodeGetFight, opcodeGetFightExplicit); extensions.registerFunction ("getfight", 'l', "", opcodeGetFight, opcodeGetFightExplicit);
extensions.registerFunction ("getflee", 'l', "", opcodeGetFlee, opcodeGetFleeExplicit); extensions.registerFunction ("getflee", 'l', "", opcodeGetFlee, opcodeGetFleeExplicit);

View file

@ -51,6 +51,8 @@ namespace Compiler
const int opcodeGetAlarmExplicit = 0x20001c6; const int opcodeGetAlarmExplicit = 0x20001c6;
const int opcodeGetLineOfSight = 0x2000222; const int opcodeGetLineOfSight = 0x2000222;
const int opcodeGetLineOfSightExplicit = 0x2000223; const int opcodeGetLineOfSightExplicit = 0x2000223;
const int opcodeToggleAI = 0x2000224;
const int opcodeToggleAIExplicit = 0x2000225;
} }
namespace Animation namespace Animation