From 2924a27eb4bd2c0eb5afec339f7987c0009ac1d1 Mon Sep 17 00:00:00 2001 From: dongresource Date: Sun, 10 Sep 2023 19:47:42 +0200 Subject: [PATCH] Rename coord args in summonNPC() and constructors to clarify purpose This makes it clearer that the real coords aren't set until the first call to updateNPCPosition(). --- src/Entities.hpp | 8 ++++---- src/MobAI.hpp | 10 +++++----- src/NPCManager.cpp | 5 ++--- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Entities.hpp b/src/Entities.hpp index 2867801..22eb50a 100644 --- a/src/Entities.hpp +++ b/src/Entities.hpp @@ -106,11 +106,11 @@ struct CombatNPC : public BaseNPC, public ICombatant { std::unordered_map buffs = {}; - CombatNPC(int x, int y, int z, int angle, uint64_t iID, int t, int id, int maxHP) + CombatNPC(int spawnX, int spawnY, int spawnZ, int angle, uint64_t iID, int t, int id, int maxHP) : BaseNPC(angle, iID, t, id), maxHealth(maxHP) { - spawnX = x; - spawnY = y; - spawnZ = z; + this->spawnX = spawnX; + this->spawnY = spawnY; + this->spawnZ = spawnZ; kind = EntityKind::COMBAT_NPC; diff --git a/src/MobAI.hpp b/src/MobAI.hpp index 3e74d3f..a55f565 100644 --- a/src/MobAI.hpp +++ b/src/MobAI.hpp @@ -50,8 +50,8 @@ struct Mob : public CombatNPC { // temporary; until we're sure what's what nlohmann::json data = {}; - Mob(int x, int y, int z, int angle, uint64_t iID, int t, nlohmann::json d, int32_t id) - : CombatNPC(x, y, z, angle, iID, t, id, d["m_iHP"]), + Mob(int spawnX, int spawnY, int spawnZ, int angle, uint64_t iID, int t, nlohmann::json d, int32_t id) + : CombatNPC(spawnX, spawnY, spawnZ, angle, iID, t, id, d["m_iHP"]), sightRange(d["m_iSightRange"]) { state = AIState::ROAMING; @@ -62,9 +62,9 @@ struct Mob : public CombatNPC { idleRange = (int)data["m_iIdleRange"]; level = data["m_iNpcLevel"]; - roamX = x; - roamY = y; - roamZ = z; + roamX = spawnX; + roamY = spawnY; + roamZ = spawnZ; offsetX = 0; offsetY = 0; diff --git a/src/NPCManager.cpp b/src/NPCManager.cpp index b0b8963..8a368bf 100644 --- a/src/NPCManager.cpp +++ b/src/NPCManager.cpp @@ -122,16 +122,15 @@ static void npcUnsummonHandler(CNSocket* sock, CNPacketData* data) { } // type must already be checked and updateNPCPosition() must be called on the result -BaseNPC *NPCManager::summonNPC(int x, int y, int z, uint64_t instance, int type, bool respawn, bool baseInstance) { +BaseNPC *NPCManager::summonNPC(int spawnX, int spawnY, int spawnZ, uint64_t instance, int type, bool respawn, bool baseInstance) { uint64_t inst = baseInstance ? MAPNUM(instance) : instance; - //assert(nextId < INT32_MAX); int id = nextId--; int team = NPCData[type]["m_iTeam"]; BaseNPC *npc = nullptr; if (team == 2) { - npc = new Mob(x, y, z, inst, type, NPCData[type], id); + npc = new Mob(spawnX, spawnY, spawnZ, inst, type, NPCData[type], id); // re-enable respawning, if desired ((Mob*)npc)->summoned = !respawn;