1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-07 12:40:01 +00:00
OpenMW/apps/openmw/mwscript/aiextensions.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

652 lines
27 KiB
C++
Raw Normal View History

#include "aiextensions.hpp"
#include <stdexcept>
2018-08-14 23:05:43 +04:00
#include <components/debug/debuglog.hpp>
#include <components/compiler/extensions.hpp>
#include <components/compiler/opcodes.hpp>
#include <components/interpreter/interpreter.hpp>
#include <components/interpreter/opcodes.hpp>
#include <components/interpreter/runtime.hpp>
#include "../mwworld/class.hpp"
#include "../mwworld/esmstore.hpp"
#include "../mwmechanics/actorutil.hpp"
2012-11-30 02:16:16 +02:00
#include "../mwmechanics/aiactivate.hpp"
#include "../mwmechanics/aiescort.hpp"
#include "../mwmechanics/aiface.hpp"
2012-11-30 02:16:16 +02:00
#include "../mwmechanics/aifollow.hpp"
#include "../mwmechanics/aitravel.hpp"
#include "../mwmechanics/aiwander.hpp"
#include "../mwmechanics/creaturestats.hpp"
#include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp"
#include "../mwbase/soundmanager.hpp"
#include "../mwbase/world.hpp"
#include "interpretercontext.hpp"
#include "ref.hpp"
namespace MWScript
{
namespace Ai
{
template <class R>
class OpAiActivate : public Interpreter::Opcode1
{
public:
void execute(Interpreter::Runtime& runtime, unsigned int arg0) override
2022-09-22 21:26:05 +03:00
{
MWWorld::Ptr ptr = R()(runtime);
2012-11-30 02:16:16 +02:00
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
ESM::RefId objectID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger));
runtime.pop();
2012-11-30 02:16:16 +02:00
// The value of the reset argument doesn't actually matter
bool repeat = arg0;
for (unsigned int i = 0; i < arg0; ++i)
2012-11-30 02:16:16 +02:00
runtime.pop();
if (!ptr.getClass().isActor() || ptr == MWMechanics::getPlayer())
return;
MWMechanics::AiActivate activatePackage(objectID, repeat);
ptr.getClass().getCreatureStats(ptr).getAiSequence().stack(activatePackage, ptr);
2018-08-14 23:05:43 +04:00
Log(Debug::Info) << "AiActivate";
}
};
2012-11-30 02:16:16 +02:00
template <class R>
class OpAiTravel : public Interpreter::Opcode1
{
public:
void execute(Interpreter::Runtime& runtime, unsigned int arg0) override
2022-09-22 21:26:05 +03:00
{
MWWorld::Ptr ptr = R()(runtime);
Interpreter::Type_Float x = runtime[0].mFloat;
runtime.pop();
Interpreter::Type_Float y = runtime[0].mFloat;
runtime.pop();
Interpreter::Type_Float z = runtime[0].mFloat;
runtime.pop();
// The value of the reset argument doesn't actually matter
bool repeat = arg0;
for (unsigned int i = 0; i < arg0; ++i)
runtime.pop();
if (!ptr.getClass().isActor() || ptr == MWMechanics::getPlayer())
return;
MWMechanics::AiTravel travelPackage(x, y, z, repeat);
ptr.getClass().getCreatureStats(ptr).getAiSequence().stack(travelPackage, ptr);
2012-11-30 02:16:16 +02:00
2018-08-14 23:05:43 +04:00
Log(Debug::Info) << "AiTravel: " << x << ", " << y << ", " << z;
}
};
template <class R>
class OpAiEscort : public Interpreter::Opcode1
{
public:
void execute(Interpreter::Runtime& runtime, unsigned int arg0) override
2022-09-22 21:26:05 +03:00
{
MWWorld::Ptr ptr = R()(runtime);
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
ESM::RefId actorID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger));
runtime.pop();
Interpreter::Type_Float duration = runtime[0].mFloat;
2012-11-30 02:16:16 +02:00
runtime.pop();
Interpreter::Type_Float x = runtime[0].mFloat;
runtime.pop();
Interpreter::Type_Float y = runtime[0].mFloat;
runtime.pop();
Interpreter::Type_Float z = runtime[0].mFloat;
runtime.pop();
// The value of the reset argument doesn't actually matter
bool repeat = arg0;
for (unsigned int i = 0; i < arg0; ++i)
runtime.pop();
if (!ptr.getClass().isActor() || ptr == MWMechanics::getPlayer())
return;
MWMechanics::AiEscort escortPackage(actorID, static_cast<int>(duration), x, y, z, repeat);
ptr.getClass().getCreatureStats(ptr).getAiSequence().stack(escortPackage, ptr);
2012-11-30 02:16:16 +02:00
2018-08-14 23:05:43 +04:00
Log(Debug::Info) << "AiEscort: " << x << ", " << y << ", " << z << ", " << duration;
2012-11-30 02:16:16 +02:00
}
};
template <class R>
class OpAiEscortCell : public Interpreter::Opcode1
{
public:
void execute(Interpreter::Runtime& runtime, unsigned int arg0) override
2022-09-22 21:26:05 +03:00
{
2012-11-30 02:16:16 +02:00
MWWorld::Ptr ptr = R()(runtime);
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
ESM::RefId actorID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger));
2012-11-30 02:16:16 +02:00
runtime.pop();
2023-01-19 17:31:45 +01:00
std::string_view cellID = runtime.getStringLiteral(runtime[0].mInteger);
2012-11-30 02:16:16 +02:00
runtime.pop();
Interpreter::Type_Float duration = runtime[0].mFloat;
runtime.pop();
Interpreter::Type_Float x = runtime[0].mFloat;
runtime.pop();
Interpreter::Type_Float y = runtime[0].mFloat;
runtime.pop();
Interpreter::Type_Float z = runtime[0].mFloat;
runtime.pop();
// The value of the reset argument doesn't actually matter
bool repeat = arg0;
for (unsigned int i = 0; i < arg0; ++i)
runtime.pop();
if (!ptr.getClass().isActor() || ptr == MWMechanics::getPlayer())
return;
if (cellID.empty())
return;
2023-04-20 21:07:53 +02:00
if (!MWBase::Environment::get().getESMStore()->get<ESM::Cell>().search(cellID))
return;
MWMechanics::AiEscort escortPackage(actorID, cellID, static_cast<int>(duration), x, y, z, repeat);
ptr.getClass().getCreatureStats(ptr).getAiSequence().stack(escortPackage, ptr);
2012-11-30 02:16:16 +02:00
2018-08-14 23:05:43 +04:00
Log(Debug::Info) << "AiEscort: " << x << ", " << y << ", " << z << ", " << duration;
}
};
template <class R>
class OpGetAiPackageDone : public Interpreter::Opcode0
{
public:
void execute(Interpreter::Runtime& runtime) override
{
MWWorld::Ptr ptr = R()(runtime);
bool done = false;
if (ptr.getClass().isActor())
done = ptr.getClass().getCreatureStats(ptr).getAiSequence().isPackageDone();
runtime.push(done);
}
};
template <class R>
class OpAiWander : public Interpreter::Opcode1
{
public:
void execute(Interpreter::Runtime& runtime, unsigned int arg0) override
2022-09-22 21:26:05 +03:00
{
MWWorld::Ptr ptr = R()(runtime);
Interpreter::Type_Integer range = static_cast<Interpreter::Type_Integer>(runtime[0].mFloat);
runtime.pop();
Interpreter::Type_Integer duration = static_cast<Interpreter::Type_Integer>(runtime[0].mFloat);
runtime.pop();
Interpreter::Type_Integer time = static_cast<Interpreter::Type_Integer>(runtime[0].mFloat);
runtime.pop();
// Chance for Idle is unused
if (arg0)
2022-09-22 21:26:05 +03:00
{
--arg0;
runtime.pop();
2022-09-22 21:26:05 +03:00
}
2014-06-12 23:27:04 +02:00
std::vector<unsigned char> idleList;
bool repeat = false;
2013-01-15 12:40:44 +01:00
// Chances for Idle2-Idle9
for (int i = 2; i <= 9 && arg0; ++i)
2013-01-15 12:40:44 +01:00
{
if (!repeat)
repeat = true;
2021-11-06 07:30:28 +03:00
Interpreter::Type_Integer idleValue = std::clamp(runtime[0].mInteger, 0, 255);
idleList.push_back(idleValue);
runtime.pop();
2013-01-15 12:40:44 +01:00
--arg0;
2012-11-30 02:16:16 +02:00
}
if (arg0)
{
2013-05-24 15:03:46 +02:00
repeat = runtime[0].mInteger != 0;
runtime.pop();
--arg0;
}
// discard additional arguments, because we have no idea what they mean.
for (unsigned int i = 0; i < arg0; ++i)
runtime.pop();
if (!ptr.getClass().isActor() || ptr == MWMechanics::getPlayer())
return;
MWMechanics::AiWander wanderPackage(range, duration, time, idleList, repeat);
ptr.getClass().getCreatureStats(ptr).getAiSequence().stack(wanderPackage, ptr);
}
};
template <class R>
2012-11-23 21:14:32 +01:00
class OpGetAiSetting : public Interpreter::Opcode0
{
MWMechanics::AiSetting mIndex;
2022-09-22 21:26:05 +03:00
public:
OpGetAiSetting(MWMechanics::AiSetting index)
: mIndex(index)
{
2022-09-22 21:26:05 +03:00
}
void execute(Interpreter::Runtime& runtime) override
2022-09-22 21:26:05 +03:00
{
MWWorld::Ptr ptr = R()(runtime);
2022-09-22 21:26:05 +03:00
Interpreter::Type_Integer value = 0;
if (ptr.getClass().isActor())
value = ptr.getClass().getCreatureStats(ptr).getAiSetting(mIndex).getModified(false);
runtime.push(value);
}
};
template <class R>
2012-11-23 21:14:32 +01:00
class OpModAiSetting : public Interpreter::Opcode0
{
MWMechanics::AiSetting mIndex;
2022-09-22 21:26:05 +03:00
public:
OpModAiSetting(MWMechanics::AiSetting index)
: mIndex(index)
2022-09-22 21:26:05 +03:00
{
}
void execute(Interpreter::Runtime& runtime) override
2022-09-22 21:26:05 +03:00
{
MWWorld::Ptr ptr = R()(runtime);
Interpreter::Type_Integer value = runtime[0].mInteger;
runtime.pop();
if (!ptr.getClass().isActor())
return;
int modified = ptr.getClass().getCreatureStats(ptr).getAiSetting(mIndex).getBase() + value;
2022-09-22 21:26:05 +03:00
ptr.getClass().getCreatureStats(ptr).setAiSetting(mIndex, modified);
ptr.getClass().setBaseAISetting(ptr.getCellRef().getRefId(), mIndex, modified);
}
};
template <class R>
2012-11-23 21:14:32 +01:00
class OpSetAiSetting : public Interpreter::Opcode0
{
MWMechanics::AiSetting mIndex;
2022-09-22 21:26:05 +03:00
public:
OpSetAiSetting(MWMechanics::AiSetting index)
: mIndex(index)
2022-09-22 21:26:05 +03:00
{
}
void execute(Interpreter::Runtime& runtime) override
2022-09-22 21:26:05 +03:00
{
2012-11-30 02:16:16 +02:00
MWWorld::Ptr ptr = R()(runtime);
Interpreter::Type_Integer value = runtime[0].mInteger;
2012-11-30 02:16:16 +02:00
runtime.pop();
if (ptr.getClass().isActor())
{
ptr.getClass().getCreatureStats(ptr).setAiSetting(mIndex, value);
ptr.getClass().setBaseAISetting(ptr.getCellRef().getRefId(), mIndex, value);
}
2022-09-22 21:26:05 +03:00
}
};
2012-11-30 02:16:16 +02:00
template <class R>
class OpAiFollow : public Interpreter::Opcode1
{
public:
void execute(Interpreter::Runtime& runtime, unsigned int arg0) override
2022-09-22 21:26:05 +03:00
{
2012-11-30 02:16:16 +02:00
MWWorld::Ptr ptr = R()(runtime);
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
ESM::RefId actorID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger));
2012-11-30 02:16:16 +02:00
runtime.pop();
Interpreter::Type_Float duration = runtime[0].mFloat;
2012-11-30 02:16:16 +02:00
runtime.pop();
Interpreter::Type_Float x = runtime[0].mFloat;
runtime.pop();
Interpreter::Type_Float y = runtime[0].mFloat;
runtime.pop();
Interpreter::Type_Float z = runtime[0].mFloat;
runtime.pop();
// The value of the reset argument doesn't actually matter
bool repeat = arg0;
for (unsigned int i = 0; i < arg0; ++i)
runtime.pop();
if (!ptr.getClass().isActor() || ptr == MWMechanics::getPlayer())
return;
MWMechanics::AiFollow followPackage(actorID, duration, x, y, z, repeat);
ptr.getClass().getCreatureStats(ptr).getAiSequence().stack(followPackage, ptr);
2012-11-30 02:16:16 +02:00
2023-03-06 22:19:29 +01:00
Log(Debug::Info) << "AiFollow: " << actorID << ", " << x << ", " << y << ", " << z << ", " << duration;
2012-11-30 02:16:16 +02:00
}
};
template <class R>
class OpAiFollowCell : public Interpreter::Opcode1
{
public:
void execute(Interpreter::Runtime& runtime, unsigned int arg0) override
2022-09-22 21:26:05 +03:00
{
2012-11-30 02:16:16 +02:00
MWWorld::Ptr ptr = R()(runtime);
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
ESM::RefId actorID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger));
2012-11-30 02:16:16 +02:00
runtime.pop();
2023-01-19 17:31:45 +01:00
std::string_view cellID = runtime.getStringLiteral(runtime[0].mInteger);
2012-11-30 02:16:16 +02:00
runtime.pop();
Interpreter::Type_Float duration = runtime[0].mFloat;
2012-11-30 02:16:16 +02:00
runtime.pop();
Interpreter::Type_Float x = runtime[0].mFloat;
runtime.pop();
Interpreter::Type_Float y = runtime[0].mFloat;
runtime.pop();
Interpreter::Type_Float z = runtime[0].mFloat;
runtime.pop();
// The value of the reset argument doesn't actually matter
bool repeat = arg0;
for (unsigned int i = 0; i < arg0; ++i)
runtime.pop();
if (!ptr.getClass().isActor() || ptr == MWMechanics::getPlayer())
return;
MWMechanics::AiFollow followPackage(actorID, cellID, duration, x, y, z, repeat);
ptr.getClass().getCreatureStats(ptr).getAiSequence().stack(followPackage, ptr);
2023-03-06 22:19:29 +01:00
Log(Debug::Info) << "AiFollow: " << actorID << ", " << x << ", " << y << ", " << z << ", " << duration;
2012-11-30 02:16:16 +02:00
}
};
template <class R>
class OpGetCurrentAIPackage : public Interpreter::Opcode0
{
public:
void execute(Interpreter::Runtime& runtime) override
2022-09-22 21:26:05 +03:00
{
2012-11-30 02:16:16 +02:00
MWWorld::Ptr ptr = R()(runtime);
Interpreter::Type_Integer value = -1;
if (ptr.getClass().isActor())
2012-11-30 02:16:16 +02:00
{
const auto& stats = ptr.getClass().getCreatureStats(ptr);
if (!stats.isDead() || !stats.isDeathAnimationFinished())
{
value = static_cast<Interpreter::Type_Integer>(stats.getAiSequence().getLastRunTypeId());
}
2012-11-30 02:16:16 +02:00
}
2022-09-22 21:26:05 +03:00
2012-11-30 02:16:16 +02:00
runtime.push(value);
2022-09-22 21:26:05 +03:00
}
2012-11-30 02:16:16 +02:00
};
template <class R>
class OpGetDetected : public Interpreter::Opcode0
2012-11-30 02:16:16 +02:00
{
public:
void execute(Interpreter::Runtime& runtime) override
2012-11-30 02:16:16 +02:00
{
MWWorld::Ptr observer = R()(runtime, false); // required=false
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
ESM::RefId actorID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger));
2012-11-30 02:16:16 +02:00
runtime.pop();
MWWorld::Ptr actor = MWBase::Environment::get().getWorld()->searchPtr(actorID, true, false);
2012-11-30 02:16:16 +02:00
Interpreter::Type_Integer value = 0;
if (!actor.isEmpty())
value = MWBase::Environment::get().getMechanicsManager()->isActorDetected(actor, observer);
2012-11-30 02:16:16 +02:00
runtime.push(value);
}
};
template <class R>
class OpGetLineOfSight : public Interpreter::Opcode0
{
public:
void execute(Interpreter::Runtime& runtime) override
{
MWWorld::Ptr source = R()(runtime);
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
ESM::RefId actorID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger));
runtime.pop();
MWWorld::Ptr dest = MWBase::Environment::get().getWorld()->searchPtr(actorID, true, false);
bool value = false;
if (!dest.isEmpty() && source.getClass().isActor() && dest.getClass().isActor())
{
value = MWBase::Environment::get().getWorld()->getLOS(source, dest);
}
runtime.push(value);
2022-09-22 21:26:05 +03:00
}
};
template <class R>
class OpGetTarget : public Interpreter::Opcode0
{
public:
void execute(Interpreter::Runtime& runtime) override
{
MWWorld::Ptr actor = R()(runtime);
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
ESM::RefId testedTargetId = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger));
runtime.pop();
bool targetsAreEqual = false;
if (actor.getClass().isActor())
2022-09-22 21:26:05 +03:00
{
const MWMechanics::CreatureStats& creatureStats = actor.getClass().getCreatureStats(actor);
MWWorld::Ptr targetPtr;
if (creatureStats.getAiSequence().getCombatTarget(targetPtr))
2022-09-22 21:26:05 +03:00
{
if (!targetPtr.isEmpty() && targetPtr.getCellRef().getRefId() == testedTargetId)
targetsAreEqual = true;
2022-09-22 21:26:05 +03:00
}
else if (testedTargetId == "Player") // Currently the player ID is hardcoded
{
MWBase::MechanicsManager* mechMgr = MWBase::Environment::get().getMechanicsManager();
bool greeting = mechMgr->getGreetingState(actor) == MWMechanics::Greet_InProgress;
bool sayActive = MWBase::Environment::get().getSoundManager()->sayActive(actor);
targetsAreEqual = (greeting && sayActive) || mechMgr->isTurningToPlayer(actor);
}
}
runtime.push(targetsAreEqual);
2022-09-22 21:26:05 +03:00
}
};
template <class R>
class OpStartCombat : public Interpreter::Opcode0
{
public:
void execute(Interpreter::Runtime& runtime) override
{
MWWorld::Ptr actor = R()(runtime);
Initial commit: In ESM structures, replace the string members that are RefIds to other records, to a new strong type The strong type is actually just a string underneath, but this will help in the future to have a distinction so it's easier to search and replace when we use an integer ID Slowly going through all the changes to make, still hundreds of errors a lot of functions/structures use std::string or stringview to designate an ID. So it takes time Continues slowly replacing ids. There are technically more and more compilation errors I have good hope that there is a point where the amount of errors will dramatically go down as all the main functions use the ESM::RefId type Continue moving forward, changes to the stores slowly moving along Starting to see the fruit of those changes. still many many error, but more and more Irun into a situation where a function is sandwiched between two functions that use the RefId type. More replacements. Things are starting to get easier I can see more and more often the issue is that the function is awaiting a RefId, but is given a string there is less need to go down functions and to fix a long list of them. Still moving forward, and for the first time error count is going down! Good pace, not sure about topics though, mId and mName are actually the same thing and are used interchangeably Cells are back to using string for the name, haven't fixed everything yet. Many other changes Under the bar of 400 compilation errors. more good progress <100 compile errors! More progress Game settings store can use string for find, it was a bit absurd how every use of it required to create refId from string some more progress on other fronts Mostly game settings clean one error opened a lot of other errors. Down to 18, but more will prbably appear only link errors left?? Fixed link errors OpenMW compiles, and launches, with some issues, but still!
2022-09-25 13:17:09 +02:00
ESM::RefId targetID = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger));
runtime.pop();
MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtr(targetID, true, false);
if (!target.isEmpty() && !target.getBase()->isDeleted()
&& !target.getClass().getCreatureStats(target).isDead())
MWBase::Environment::get().getMechanicsManager()->startCombat(actor, target, nullptr);
}
};
template <class R>
class OpStopCombat : public Interpreter::Opcode0
{
public:
void execute(Interpreter::Runtime& runtime) override
{
MWWorld::Ptr actor = R()(runtime);
if (!actor.getClass().isActor())
return;
MWBase::Environment::get().getMechanicsManager()->stopCombat(actor);
}
};
2013-11-18 23:03:44 +01:00
class OpToggleAI : public Interpreter::Opcode0
{
public:
void execute(Interpreter::Runtime& runtime) override
2013-11-18 23:03:44 +01:00
{
bool enabled = MWBase::Environment::get().getMechanicsManager()->toggleAI();
2015-03-03 23:46:53 +01:00
runtime.getContext().report(enabled ? "AI -> On" : "AI -> Off");
2013-11-18 23:03:44 +01:00
}
};
template <class R>
class OpFace : public Interpreter::Opcode0
{
public:
void execute(Interpreter::Runtime& runtime) override
{
MWWorld::Ptr actor = R()(runtime);
Interpreter::Type_Float x = runtime[0].mFloat;
runtime.pop();
Interpreter::Type_Float y = runtime[0].mFloat;
runtime.pop();
if (!actor.getClass().isActor() || actor == MWMechanics::getPlayer())
return;
MWMechanics::AiFace facePackage(x, y);
actor.getClass().getCreatureStats(actor).getAiSequence().stack(facePackage, actor);
}
};
2022-01-27 19:18:57 +00:00
void installOpcodes(Interpreter::Interpreter& interpreter)
{
2022-01-27 19:18:57 +00:00
interpreter.installSegment3<OpAiActivate<ImplicitRef>>(Compiler::Ai::opcodeAIActivate);
interpreter.installSegment3<OpAiActivate<ExplicitRef>>(Compiler::Ai::opcodeAIActivateExplicit);
interpreter.installSegment3<OpAiTravel<ImplicitRef>>(Compiler::Ai::opcodeAiTravel);
interpreter.installSegment3<OpAiTravel<ExplicitRef>>(Compiler::Ai::opcodeAiTravelExplicit);
interpreter.installSegment3<OpAiEscort<ImplicitRef>>(Compiler::Ai::opcodeAiEscort);
interpreter.installSegment3<OpAiEscort<ExplicitRef>>(Compiler::Ai::opcodeAiEscortExplicit);
interpreter.installSegment3<OpAiEscortCell<ImplicitRef>>(Compiler::Ai::opcodeAiEscortCell);
interpreter.installSegment3<OpAiEscortCell<ExplicitRef>>(Compiler::Ai::opcodeAiEscortCellExplicit);
interpreter.installSegment3<OpAiWander<ImplicitRef>>(Compiler::Ai::opcodeAiWander);
interpreter.installSegment3<OpAiWander<ExplicitRef>>(Compiler::Ai::opcodeAiWanderExplicit);
interpreter.installSegment3<OpAiFollow<ImplicitRef>>(Compiler::Ai::opcodeAiFollow);
interpreter.installSegment3<OpAiFollow<ExplicitRef>>(Compiler::Ai::opcodeAiFollowExplicit);
interpreter.installSegment3<OpAiFollowCell<ImplicitRef>>(Compiler::Ai::opcodeAiFollowCell);
interpreter.installSegment3<OpAiFollowCell<ExplicitRef>>(Compiler::Ai::opcodeAiFollowCellExplicit);
interpreter.installSegment5<OpGetAiPackageDone<ImplicitRef>>(Compiler::Ai::opcodeGetAiPackageDone);
interpreter.installSegment5<OpGetAiPackageDone<ExplicitRef>>(Compiler::Ai::opcodeGetAiPackageDoneExplicit);
interpreter.installSegment5<OpGetCurrentAIPackage<ImplicitRef>>(Compiler::Ai::opcodeGetCurrentAiPackage);
interpreter.installSegment5<OpGetCurrentAIPackage<ExplicitRef>>(
Compiler::Ai::opcodeGetCurrentAiPackageExplicit);
interpreter.installSegment5<OpGetDetected<ImplicitRef>>(Compiler::Ai::opcodeGetDetected);
interpreter.installSegment5<OpGetDetected<ExplicitRef>>(Compiler::Ai::opcodeGetDetectedExplicit);
interpreter.installSegment5<OpGetLineOfSight<ImplicitRef>>(Compiler::Ai::opcodeGetLineOfSight);
interpreter.installSegment5<OpGetLineOfSight<ExplicitRef>>(Compiler::Ai::opcodeGetLineOfSightExplicit);
interpreter.installSegment5<OpGetTarget<ImplicitRef>>(Compiler::Ai::opcodeGetTarget);
interpreter.installSegment5<OpGetTarget<ExplicitRef>>(Compiler::Ai::opcodeGetTargetExplicit);
interpreter.installSegment5<OpStartCombat<ImplicitRef>>(Compiler::Ai::opcodeStartCombat);
interpreter.installSegment5<OpStartCombat<ExplicitRef>>(Compiler::Ai::opcodeStartCombatExplicit);
interpreter.installSegment5<OpStopCombat<ImplicitRef>>(Compiler::Ai::opcodeStopCombat);
interpreter.installSegment5<OpStopCombat<ExplicitRef>>(Compiler::Ai::opcodeStopCombatExplicit);
interpreter.installSegment5<OpToggleAI>(Compiler::Ai::opcodeToggleAI);
interpreter.installSegment5<OpSetAiSetting<ImplicitRef>>(
Compiler::Ai::opcodeSetHello, MWMechanics::AiSetting::Hello);
interpreter.installSegment5<OpSetAiSetting<ExplicitRef>>(
Compiler::Ai::opcodeSetHelloExplicit, MWMechanics::AiSetting::Hello);
interpreter.installSegment5<OpSetAiSetting<ImplicitRef>>(
Compiler::Ai::opcodeSetFight, MWMechanics::AiSetting::Fight);
interpreter.installSegment5<OpSetAiSetting<ExplicitRef>>(
Compiler::Ai::opcodeSetFightExplicit, MWMechanics::AiSetting::Fight);
interpreter.installSegment5<OpSetAiSetting<ImplicitRef>>(
Compiler::Ai::opcodeSetFlee, MWMechanics::AiSetting::Flee);
interpreter.installSegment5<OpSetAiSetting<ExplicitRef>>(
Compiler::Ai::opcodeSetFleeExplicit, MWMechanics::AiSetting::Flee);
interpreter.installSegment5<OpSetAiSetting<ImplicitRef>>(
Compiler::Ai::opcodeSetAlarm, MWMechanics::AiSetting::Alarm);
interpreter.installSegment5<OpSetAiSetting<ExplicitRef>>(
Compiler::Ai::opcodeSetAlarmExplicit, MWMechanics::AiSetting::Alarm);
2022-09-22 21:26:05 +03:00
interpreter.installSegment5<OpModAiSetting<ImplicitRef>>(
Compiler::Ai::opcodeModHello, MWMechanics::AiSetting::Hello);
interpreter.installSegment5<OpModAiSetting<ExplicitRef>>(
Compiler::Ai::opcodeModHelloExplicit, MWMechanics::AiSetting::Hello);
interpreter.installSegment5<OpModAiSetting<ImplicitRef>>(
Compiler::Ai::opcodeModFight, MWMechanics::AiSetting::Fight);
interpreter.installSegment5<OpModAiSetting<ExplicitRef>>(
Compiler::Ai::opcodeModFightExplicit, MWMechanics::AiSetting::Fight);
interpreter.installSegment5<OpModAiSetting<ImplicitRef>>(
Compiler::Ai::opcodeModFlee, MWMechanics::AiSetting::Flee);
interpreter.installSegment5<OpModAiSetting<ExplicitRef>>(
Compiler::Ai::opcodeModFleeExplicit, MWMechanics::AiSetting::Flee);
interpreter.installSegment5<OpModAiSetting<ImplicitRef>>(
Compiler::Ai::opcodeModAlarm, MWMechanics::AiSetting::Alarm);
interpreter.installSegment5<OpModAiSetting<ExplicitRef>>(
Compiler::Ai::opcodeModAlarmExplicit, MWMechanics::AiSetting::Alarm);
2022-09-22 21:26:05 +03:00
interpreter.installSegment5<OpGetAiSetting<ImplicitRef>>(
Compiler::Ai::opcodeGetHello, MWMechanics::AiSetting::Hello);
interpreter.installSegment5<OpGetAiSetting<ExplicitRef>>(
Compiler::Ai::opcodeGetHelloExplicit, MWMechanics::AiSetting::Hello);
interpreter.installSegment5<OpGetAiSetting<ImplicitRef>>(
Compiler::Ai::opcodeGetFight, MWMechanics::AiSetting::Fight);
interpreter.installSegment5<OpGetAiSetting<ExplicitRef>>(
Compiler::Ai::opcodeGetFightExplicit, MWMechanics::AiSetting::Fight);
interpreter.installSegment5<OpGetAiSetting<ImplicitRef>>(
Compiler::Ai::opcodeGetFlee, MWMechanics::AiSetting::Flee);
interpreter.installSegment5<OpGetAiSetting<ExplicitRef>>(
Compiler::Ai::opcodeGetFleeExplicit, MWMechanics::AiSetting::Flee);
interpreter.installSegment5<OpGetAiSetting<ImplicitRef>>(
Compiler::Ai::opcodeGetAlarm, MWMechanics::AiSetting::Alarm);
interpreter.installSegment5<OpGetAiSetting<ExplicitRef>>(
Compiler::Ai::opcodeGetAlarmExplicit, MWMechanics::AiSetting::Alarm);
2022-01-27 19:18:57 +00:00
interpreter.installSegment5<OpFace<ImplicitRef>>(Compiler::Ai::opcodeFace);
interpreter.installSegment5<OpFace<ExplicitRef>>(Compiler::Ai::opcodeFaceExplicit);
}
}
}