From 14af0be6573b2a937cd1e6e35726af0055b7588f Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 7 Aug 2019 11:21:22 +0300 Subject: [PATCH] [General] Include AI alarm & flee for creatures/NPCs in RecordDynamic --- .../Script/Functions/RecordsDynamic.cpp | 34 +++++++++++++++++++ .../Script/Functions/RecordsDynamic.hpp | 20 +++++++++++ apps/openmw/mwmp/RecordHelper.cpp | 12 +++++++ components/openmw-mp/Base/BaseWorldstate.hpp | 2 ++ .../Worldstate/PacketRecordDynamic.cpp | 8 +++++ 5 files changed, 76 insertions(+) diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp index 1e586466a..9763209a0 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.cpp @@ -1206,6 +1206,40 @@ void RecordsDynamicFunctions::SetRecordAIFight(int aiFight) noexcept tempOverrides.hasAiFight = true; } +void RecordsDynamicFunctions::SetRecordAIFlee(int aiFlee) noexcept +{ + unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; + + if (writeRecordsType == mwmp::RECORD_TYPE::CREATURE) + tempCreature.data.mAiData.mFlee = aiFlee; + else if (writeRecordsType == mwmp::RECORD_TYPE::NPC) + tempNpc.data.mAiData.mFlee = aiFlee; + else + { + LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Tried to set AI fight for record type %i which lacks that property", writeRecordsType); + return; + } + + tempOverrides.hasAiFlee = true; +} + +void RecordsDynamicFunctions::SetRecordAIAlarm(int aiAlarm) noexcept +{ + unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; + + if (writeRecordsType == mwmp::RECORD_TYPE::CREATURE) + tempCreature.data.mAiData.mAlarm = aiAlarm; + else if (writeRecordsType == mwmp::RECORD_TYPE::NPC) + tempNpc.data.mAiData.mAlarm = aiAlarm; + else + { + LOG_MESSAGE_SIMPLE(Log::LOG_ERROR, "Tried to set AI fight for record type %i which lacks that property", writeRecordsType); + return; + } + + tempOverrides.hasAiAlarm = true; +} + void RecordsDynamicFunctions::SetRecordAIServices(int aiServices) noexcept { unsigned short writeRecordsType = WorldstateFunctions::writeWorldstate.recordsType; diff --git a/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp b/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp index e2150dc3b..0a6040b24 100644 --- a/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp +++ b/apps/openmw-mp/Script/Functions/RecordsDynamic.hpp @@ -86,6 +86,8 @@ {"SetRecordFatigue", RecordsDynamicFunctions::SetRecordFatigue},\ \ {"SetRecordAIFight", RecordsDynamicFunctions::SetRecordAIFight},\ + {"SetRecordAIFlee", RecordsDynamicFunctions::SetRecordAIFlee},\ + {"SetRecordAIAlarm", RecordsDynamicFunctions::SetRecordAIAlarm},\ {"SetRecordAIServices", RecordsDynamicFunctions::SetRecordAIServices},\ \ {"SetRecordOpenSound", RecordsDynamicFunctions::SetRecordOpenSound},\ @@ -737,6 +739,24 @@ public: */ static void SetRecordAIFight(int aiFight) noexcept; + /** + * \brief Set the AI flee value of the temporary record stored on the server for the + * currently specified record type. + * + * \param aiFlee The AI flee value of the record. + * \return void + */ + static void SetRecordAIFlee(int aiFlee) noexcept; + + /** + * \brief Set the AI alarm value of the temporary record stored on the server for the + * currently specified record type. + * + * \param aiAlarm The AI alarm value of the record. + * \return void + */ + static void SetRecordAIAlarm(int aiAlarm) noexcept; + /** * \brief Set the AI services value of the temporary record stored on the server for the * currently specified record type. diff --git a/apps/openmw/mwmp/RecordHelper.cpp b/apps/openmw/mwmp/RecordHelper.cpp index 534434046..f52328338 100644 --- a/apps/openmw/mwmp/RecordHelper.cpp +++ b/apps/openmw/mwmp/RecordHelper.cpp @@ -214,6 +214,12 @@ void RecordHelper::overrideCreatureRecord(const mwmp::CreatureRecord& record) if (record.baseOverrides.hasAiFight) finalData.mAiData.mFight = recordData.mAiData.mFight; + if (record.baseOverrides.hasAiFlee) + finalData.mAiData.mFlee = recordData.mAiData.mFlee; + + if (record.baseOverrides.hasAiAlarm) + finalData.mAiData.mAlarm = recordData.mAiData.mAlarm; + if (record.baseOverrides.hasAiServices) finalData.mAiData.mServices = recordData.mAiData.mServices; @@ -323,6 +329,12 @@ void RecordHelper::overrideNpcRecord(const mwmp::NpcRecord& record) if (record.baseOverrides.hasAiFight) finalData.mAiData.mFight = recordData.mAiData.mFight; + if (record.baseOverrides.hasAiFlee) + finalData.mAiData.mFlee = recordData.mAiData.mFlee; + + if (record.baseOverrides.hasAiAlarm) + finalData.mAiData.mAlarm = recordData.mAiData.mAlarm; + if (record.baseOverrides.hasAiServices) finalData.mAiData.mServices = recordData.mAiData.mServices; diff --git a/components/openmw-mp/Base/BaseWorldstate.hpp b/components/openmw-mp/Base/BaseWorldstate.hpp index b57ed8a00..5b75149f9 100644 --- a/components/openmw-mp/Base/BaseWorldstate.hpp +++ b/components/openmw-mp/Base/BaseWorldstate.hpp @@ -112,6 +112,8 @@ namespace mwmp bool hasFatigue = false; bool hasAiFight = false; + bool hasAiFlee = false; + bool hasAiAlarm = false; bool hasAiServices = false; bool hasOpenSound = false; diff --git a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp index 4d9bb7515..e2caf71e0 100644 --- a/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp +++ b/components/openmw-mp/Packets/Worldstate/PacketRecordDynamic.cpp @@ -216,6 +216,8 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *bs, bool send) RW(recordData.mData.mMana, send); RW(recordData.mData.mFatigue, send); RW(recordData.mAiData.mFight, send); + RW(recordData.mAiData.mFlee, send); + RW(recordData.mAiData.mAlarm, send); RW(recordData.mAiData.mServices, send); RW(recordData.mFlags, send); RW(recordData.mScript, send, true); @@ -232,6 +234,8 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *bs, bool send) RW(overrides.hasMagicka, send); RW(overrides.hasFatigue, send); RW(overrides.hasAiFight, send); + RW(overrides.hasAiFlee, send); + RW(overrides.hasAiAlarm, send); RW(overrides.hasAiServices, send); RW(overrides.hasFlags, send); RW(overrides.hasScript, send); @@ -262,6 +266,8 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *bs, bool send) RW(recordData.mNpdt.mMana, send); RW(recordData.mNpdt.mFatigue, send); RW(recordData.mAiData.mFight, send); + RW(recordData.mAiData.mFlee, send); + RW(recordData.mAiData.mAlarm, send); RW(recordData.mAiData.mServices, send); RW(recordData.mNpdtType, send); @@ -283,6 +289,8 @@ void PacketRecordDynamic::Packet(RakNet::BitStream *bs, bool send) RW(overrides.hasMagicka, send); RW(overrides.hasFatigue, send); RW(overrides.hasAiFight, send); + RW(overrides.hasAiFlee, send); + RW(overrides.hasAiAlarm, send); RW(overrides.hasAiServices, send); RW(overrides.hasAutoCalc, send); RW(overrides.hasInventory, send);