adding script instruction getLOS + some test about AI

actorid
gus 11 years ago
parent fb7273e14a
commit 46a734852b

@ -356,6 +356,9 @@ namespace MWBase
virtual void getItemsOwnedBy (const MWWorld::Ptr& npc, std::vector<MWWorld::Ptr>& out) = 0;
///< get all items in active cells owned by this Npc
virtual bool getLOS(const MWWorld::Ptr& npc,const MWWorld::Ptr& targetNpc) = 0;
///< get Line of Sight (morrowind stupid implementation)
virtual void enableActorCollision(const MWWorld::Ptr& actor, bool enable) = 0;
virtual void setupExternalRendering (MWRender::ExternalRendering& rendering) = 0;

@ -9,6 +9,13 @@
#include "aifollow.hpp"
#include "aiactivate.hpp"
#include "..\mwworld\class.hpp"
#include "creaturestats.hpp"
#include "npcstats.hpp"
#include "..\mwbase\environment.hpp"
#include "..\mwbase\world.hpp"
#include "..\mwworld\player.hpp"
void MWMechanics::AiSequence::copy (const AiSequence& sequence)
{
for (std::list<AiPackage *>::const_iterator iter (sequence.mPackages.begin());
@ -54,6 +61,50 @@ bool MWMechanics::AiSequence::isPackageDone() const
void MWMechanics::AiSequence::execute (const MWWorld::Ptr& actor)
{
/*if(actor != MWBase::Environment::get().getWorld()->getPlayer().getPlayer())
{
MWMechanics::DrawState_ state = MWWorld::Class::get(actor).getNpcStats(actor).getDrawState();
if (state == MWMechanics::DrawState_Spell || state == MWMechanics::DrawState_Nothing)
MWWorld::Class::get(actor).getNpcStats(actor).setDrawState(MWMechanics::DrawState_Weapon);
MWWorld::Class::get(actor).getCreatureStats(actor).setAttackingOrSpell(true);
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
ESM::Position pos = actor.getRefData().getPosition();
const ESM::Pathgrid *pathgrid =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Pathgrid>().search(*actor.getCell()->mCell);
int cellX = actor.getCell()->mCell->mData.mX;
int cellY = actor.getCell()->mCell->mData.mY;
float xCell = 0;
float yCell = 0;
if (actor.getCell()->mCell->isExterior())
{
xCell = actor.getCell()->mCell->mData.mX * ESM::Land::REAL_SIZE;
yCell = actor.getCell()->mCell->mData.mY * ESM::Land::REAL_SIZE;
}
ESM::Pathgrid::Point dest;
dest.mX = player.getRefData().getPosition().pos[0];
dest.mY = player.getRefData().getPosition().pos[1];
dest.mZ = player.getRefData().getPosition().pos[2];
ESM::Pathgrid::Point start;
start.mX = pos.pos[0];
start.mY = pos.pos[1];
start.mZ = pos.pos[2];
PathFinder mPathFinder;
mPathFinder.buildPath(start, dest, pathgrid, xCell, yCell, true);
float zAngle = mPathFinder.getZAngleToNext(pos.pos[0], pos.pos[1]);
MWBase::Environment::get().getWorld()->rotateObject(actor, 0, 0, zAngle, false);
MWWorld::Class::get(actor).getMovementSettings(actor).mPosition[1] = 1;
if(dest.mX - start.mX < 100)
{
MWWorld::Class::get(actor).getCreatureStats(actor).setAttackingOrSpell(false);
}
}*/
if (!mPackages.empty())
{
if (mPackages.front()->execute (actor))

@ -17,6 +17,9 @@
#include "../mwmechanics/aitravel.hpp"
#include "../mwmechanics/aiwander.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "interpretercontext.hpp"
#include "ref.hpp"
@ -364,6 +367,28 @@ namespace MWScript
}
};
template<class R>
class OpGetLineOfSight : public Interpreter::Opcode0
{
public:
virtual void execute (Interpreter::Runtime& runtime)
{
MWWorld::Ptr source = R()(runtime);
std::string actorID = runtime.getStringLiteral (runtime[0].mInteger);
runtime.pop();
MWWorld::Ptr dest = MWBase::Environment::get().getWorld()->getPtr(actorID,true);
bool value = false;
if(dest != MWWorld::Ptr() )
{
value = MWBase::Environment::get().getWorld()->getLOS(source,dest);
}
runtime.push (value);
}
};
void installOpcodes (Interpreter::Interpreter& interpreter)
{
@ -389,6 +414,9 @@ namespace MWScript
interpreter.installSegment5 (Compiler::Ai::opcodeGetCurrentAiPackageExplicit, new OpGetCurrentAIPackage<ExplicitRef>);
interpreter.installSegment3 (Compiler::Ai::opcodeGetDetected, new OpGetDetected<ImplicitRef>);
interpreter.installSegment3 (Compiler::Ai::opcodeGetDetectedExplicit, new OpGetDetected<ExplicitRef>);
interpreter.installSegment5 (Compiler::Ai::opcodeGetLineOfSight, new OpGetLineOfSight<ImplicitRef>);
interpreter.installSegment5 (Compiler::Ai::opcodeGetLineOfSightExplicit, new OpGetLineOfSight<ExplicitRef>);
interpreter.installSegment5 (Compiler::Ai::opcodeSetHello, new OpSetAiSetting<ImplicitRef>(0));
interpreter.installSegment5 (Compiler::Ai::opcodeSetHelloExplicit, new OpSetAiSetting<ExplicitRef>(0));
interpreter.installSegment5 (Compiler::Ai::opcodeSetFight, new OpSetAiSetting<ImplicitRef>(1));

@ -351,5 +351,7 @@ op 0x200021b: SetWerewolfAcrobatics
op 0x200021c: SetWerewolfAcrobaticsExplicit
op 0x200021d: ShowVars
op 0x200021e: ShowVarsExplicit
op 0x200021f: GetLineOfSight
op 0x200022a: GetLineOfSightExplicit
opcodes 0x200021f-0x3ffffff unused

@ -1779,6 +1779,11 @@ namespace MWWorld
}
}
bool World::getLOS(const MWWorld::Ptr& npc,const MWWorld::Ptr& targetNpc)
{
return false;
}
void World::enableActorCollision(const MWWorld::Ptr& actor, bool enable)
{
OEngine::Physic::PhysicActor *physicActor = mPhysEngine->getCharacter(actor.getRefData().getHandle());

@ -403,6 +403,9 @@ namespace MWWorld
virtual void getItemsOwnedBy (const MWWorld::Ptr& npc, std::vector<MWWorld::Ptr>& out);
///< get all items in active cells owned by this Npc
virtual bool getLOS(const MWWorld::Ptr& npc,const MWWorld::Ptr& targetNpc);
///< get Line of Sight (morrowind stupid implementation)
virtual void enableActorCollision(const MWWorld::Ptr& actor, bool enable);
virtual void setupExternalRendering (MWRender::ExternalRendering& rendering);

@ -63,6 +63,7 @@ namespace Compiler
extensions.registerFunction ("getfight", 'l', "", opcodeGetFight, opcodeGetFightExplicit);
extensions.registerFunction ("getflee", 'l', "", opcodeGetFlee, opcodeGetFleeExplicit);
extensions.registerFunction ("getalarm", 'l', "", opcodeGetAlarm, opcodeGetAlarmExplicit);
extensions.registerFunction ("getlineofsight", 'l', "c", opcodeGetLineOfSight, opcodeGetLineOfSightExplicit);
}
}

@ -49,6 +49,8 @@ namespace Compiler
const int opcodeGetFleeExplicit = 0x20001c4;
const int opcodeGetAlarm = 0x20001c5;
const int opcodeGetAlarmExplicit = 0x20001c6;
const int opcodeGetLineOfSight = 0x200021f;
const int opcodeGetLineOfSightExplicit = 0x200022a;
}
namespace Animation

Loading…
Cancel
Save