From 09bbf3eff99f916ddece02d28c98851b9d65104b Mon Sep 17 00:00:00 2001 From: Vidi_Aquam <89811652+VidiAquam@users.noreply.github.com> Date: Wed, 27 Sep 2023 15:05:42 -0500 Subject: [PATCH] (Server) Add Lua functions to read actor AI packets --- apps/openmw-mp/Script/Functions/Actors.cpp | 70 ++++++++++++ apps/openmw-mp/Script/Functions/Actors.hpp | 120 +++++++++++++++++++++ 2 files changed, 190 insertions(+) diff --git a/apps/openmw-mp/Script/Functions/Actors.cpp b/apps/openmw-mp/Script/Functions/Actors.cpp index c236e992e..f27229047 100644 --- a/apps/openmw-mp/Script/Functions/Actors.cpp +++ b/apps/openmw-mp/Script/Functions/Actors.cpp @@ -476,6 +476,76 @@ void ActorFunctions::SetActorAIRepetition(bool shouldRepeat) noexcept tempActor.aiShouldRepeat = shouldRepeat; } +unsigned int ActorFunctions::GetActorAIAction(unsigned int index) noexcept +{ + return readActorList->baseActors.at(index).aiAction; +} + +bool ActorFunctions::DoesActorAIHavePlayerTarget(unsigned int index) noexcept +{ + return readActorList->baseActors.at(index).aiTarget.isPlayer; +} + +int ActorFunctions::GetActorAITargetPid(unsigned int index) noexcept +{ + Player* player = Players::getPlayer(readActorList->baseActors.at(index).aiTarget.guid); + + if (player != nullptr) + return player->getId(); + + return -1; +} + +unsigned int ActorFunctions::GetActorAITargetRefNum(unsigned int index) noexcept +{ + return readActorList->baseActors.at(index).aiTarget.refNum; +} + +unsigned int ActorFunctions::GetActorAITargetMpNum(unsigned int index) noexcept +{ + return readActorList->baseActors.at(index).aiTarget.mpNum; +} + +const char *ActorFunctions::GetActorAITargetRefId(unsigned int index) noexcept +{ + return readActorList->baseActors.at(index).aiTarget.refId.c_str(); +} + +const char *ActorFunctions::GetActorAITargetName(unsigned int index) noexcept +{ + return readActorList->baseActors.at(index).aiTarget.name.c_str(); +} + +double ActorFunctions::GetActorAICoordinateX(unsigned int index) noexcept +{ + return readActorList->baseActors.at(index).aiCoordinates.pos[0]; +} + +double ActorFunctions::GetActorAICoordinateY(unsigned int index) noexcept +{ + return readActorList->baseActors.at(index).aiCoordinates.pos[1]; +} + +double ActorFunctions::GetActorAICoordinateZ(unsigned int index) noexcept +{ + return readActorList->baseActors.at(index).aiCoordinates.pos[2]; +} + +unsigned int ActorFunctions::GetActorAIDistance(unsigned int index) noexcept +{ + return readActorList->baseActors.at(index).aiDistance; +} + +unsigned int ActorFunctions::GetActorAIDuration(unsigned int index) noexcept +{ + return readActorList->baseActors.at(index).aiDuration; +} + +bool ActorFunctions::GetActorAIRepetition(unsigned int index) noexcept +{ + return readActorList->baseActors.at(index).aiShouldRepeat; +} + void ActorFunctions::EquipActorItem(unsigned short slot, const char *refId, unsigned int count, int charge, double enchantmentCharge) noexcept { tempActor.equipmentItems[slot].refId = refId; diff --git a/apps/openmw-mp/Script/Functions/Actors.hpp b/apps/openmw-mp/Script/Functions/Actors.hpp index 09f5381f7..043c98102 100644 --- a/apps/openmw-mp/Script/Functions/Actors.hpp +++ b/apps/openmw-mp/Script/Functions/Actors.hpp @@ -66,6 +66,20 @@ {"GetActorSpellsActiveCasterRefNum", ActorFunctions::GetActorSpellsActiveCasterRefNum},\ {"GetActorSpellsActiveCasterMpNum", ActorFunctions::GetActorSpellsActiveCasterMpNum},\ \ + {"DoesActorAIHavePlayerTarget", ActorFunctions::DoesActorAIHavePlayerTarget},\ + {"GetActorAIAction", ActorFunctions::GetActorAIAction},\ + {"GetActorAITargetPid", ActorFunctions::GetActorAITargetPid},\ + {"GetActorAITargetRefNum", ActorFunctions::GetActorAITargetRefNum},\ + {"GetActorAITargetMpNum", ActorFunctions::GetActorAITargetMpNum},\ + {"GetActorAITargetRefId", ActorFunctions::GetActorAITargetRefId},\ + {"GetActorAITargetName", ActorFunctions::GetActorAITargetName},\ + {"GetActorAICoordinateX", ActorFunctions::GetActorAICoordinateX},\ + {"GetActorAICoordinateY", ActorFunctions::GetActorAICoordinateY},\ + {"GetActorAICoordinateZ", ActorFunctions::GetActorAICoordinateZ},\ + {"GetActorAIDistance", ActorFunctions::GetActorAIDistance},\ + {"GetActorAIDuration", ActorFunctions::GetActorAIDuration},\ + {"GetActorAIRepetition", ActorFunctions::GetActorAIRepetition},\ + \ {"DoesActorHavePosition", ActorFunctions::DoesActorHavePosition},\ {"DoesActorHaveStatsDynamic", ActorFunctions::DoesActorHaveStatsDynamic},\ \ @@ -585,6 +599,112 @@ public: */ static unsigned int GetActorSpellsActiveCasterMpNum(unsigned int actorIndex, unsigned int spellIndex) noexcept; + /** + * \brief Get the AI action of the actor at a certain index in the read actor list. + * + * \param index The index of the actor. + * \return The AI action. + */ + static unsigned int GetActorAIAction(unsigned int index) noexcept; + + /** + * \brief Check whether the AI target of the actor at a certain index in the read actor list is a player. + * + * \param index The index of the actor. + * \return Whether the actor AI targets a player. + */ + static bool DoesActorAIHavePlayerTarget(unsigned int index) noexcept; + + /** + * \brief Get the player ID of the AI target of the actor at a certain index in the read actor list. + * + * \param index The index of the actor. + * \return The player ID of the target. + */ + static int GetActorAITargetPid(unsigned int index) noexcept; + + /** + * \brief Get the refNum of the AI target of the actor at a certain index in the read actor list. + * + * \param index The index of the actor. + * \return The refNum of the target. + */ + static unsigned int GetActorAITargetRefNum(unsigned int index) noexcept; + + /** + * \brief Get the mpNum of the AI target of the actor at a certain index in the read actor list. + * + * \param index The index of the actor. + * \return The mpNum of the target. + */ + static unsigned int GetActorAITargetMpNum(unsigned int index) noexcept; + + /** + * \brief Get the refId of the AI target of the actor at a certain index in the read actor list. + * + * \param index The index of the actor. + * \return The refNum of the target. + */ + static const char* GetActorAITargetRefId(unsigned int index) noexcept; + + /** + * \brief Get the name of the AI target of the actor at a certain index in the read actor list. + * + * \param index The index of the actor. + * \return The name of the target. + */ + static const char* GetActorAITargetName(unsigned int index) noexcept; + + /** + * \brief Get the X position of the AI target position of the actor at a certain index in the read actor list. + * + * \param index The index of the actor. + * \return The X position. + */ + static double GetActorAICoordinateX(unsigned int index) noexcept; + + /** + * \brief Get the Y position of the AI target position of the actor at a certain index in the read actor list. + * + * \param index The index of the actor. + * \return The Y position. + */ + static double GetActorAICoordinateY(unsigned int index) noexcept; + + /** + * \brief Get the Z position of the AI target position of the actor at a certain index in the read actor list. + * + * \param index The index of the actor. + * \return The Z position. + */ + static double GetActorAICoordinateZ(unsigned int index) noexcept; + + /** + * \brief Get the distance of the AI package associated with the AI action of the actor at a certain index in the read actor list. + * + * \param index The index of the actor. + * \return The distance of the package. + */ + static unsigned int GetActorAIDistance(unsigned int index) noexcept; + + /** + * \brief Get the duration of the AI package associated with the AI action of the actor at a certain index in the read actor list. + * + * \param index The index of the actor. + * \return The duration of the package. + */ + static unsigned int GetActorAIDuration(unsigned int index) noexcept; + + /** + * \brief Get whether the AI package associated with the AI action of the actor at a certain index in the read actor list should be repeated. + * + * Note: This only applies to the WANDER package. + * + * \param index The index of the actor. + * \return Whether the package should be repeated + */ + static bool GetActorAIRepetition(unsigned int index) noexcept; + /** * \brief Check whether there is any positional data for the actor at a certain index in * the read actor list.