From 4b71d28747e71738dd319aa60a68a70f5ea5d78a Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Sun, 30 Nov 2014 14:17:14 -0800 Subject: [PATCH] guard_x, guard_y, guard_z, guard_heading converted to xyz_heading as m_GuardPoint --- zone/mob_ai.cpp | 10 ++++----- zone/npc.cpp | 11 ++++------ zone/npc.h | 12 +++++------ zone/waypoints.cpp | 54 ++++++++++++++++++++-------------------------- 4 files changed, 38 insertions(+), 49 deletions(-) diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp index b727d20b2..9c720957e 100644 --- a/zone/mob_ai.cpp +++ b/zone/mob_ai.cpp @@ -1787,13 +1787,13 @@ void NPC::AI_DoMovement() { { bool CP2Moved; if(!RuleB(Pathing, Guard) || !zone->pathing) - CP2Moved = CalculateNewPosition2(guard_x, guard_y, guard_z, walksp); + CP2Moved = CalculateNewPosition2(m_GuardPoint.m_X, m_GuardPoint.m_Y, m_GuardPoint.m_Z, walksp); else { - if(!((m_Position.m_X == guard_x) && (m_Position.m_Y == guard_y) && (m_Position.m_Z == guard_z))) + if(!((m_Position.m_X == m_GuardPoint.m_X) && (m_Position.m_Y == m_GuardPoint.m_Y) && (m_Position.m_Z == m_GuardPoint.m_Z))) { bool WaypointChanged, NodeReached; - Map::Vertex Goal = UpdatePath(guard_x, guard_y, guard_z, walksp, WaypointChanged, NodeReached); + Map::Vertex Goal = UpdatePath(m_GuardPoint.m_X, m_GuardPoint.m_Y, m_GuardPoint.m_Z, walksp, WaypointChanged, NodeReached); if(WaypointChanged) tar_ndx = 20; @@ -1809,13 +1809,13 @@ void NPC::AI_DoMovement() { if (!CP2Moved) { if(moved) { - mlog(AI__WAYPOINTS, "Reached guard point (%.3f,%.3f,%.3f)", guard_x, guard_y, guard_z); + mlog(AI__WAYPOINTS, "Reached guard point (%.3f,%.3f,%.3f)", m_GuardPoint.m_X, m_GuardPoint.m_Y, m_GuardPoint.m_Z); ClearFeignMemory(); moved=false; SetMoving(false); if (GetTarget() == nullptr || DistNoRoot(*GetTarget()) >= 5*5 ) { - SetHeading(guard_heading); + SetHeading(m_GuardPoint.m_Heading); } else { FaceTarget(GetTarget()); } diff --git a/zone/npc.cpp b/zone/npc.cpp index 147d275f9..4469292f6 100644 --- a/zone/npc.cpp +++ b/zone/npc.cpp @@ -114,7 +114,8 @@ NPC::NPC(const NPCType* d, Spawn2* in_respawn, float x, float y, float z, float sendhpupdate_timer(1000), enraged_timer(1000), taunt_timer(TauntReuseTime * 1000), - m_SpawnPoint(x,y,z,heading) + m_SpawnPoint(x,y,z,heading), + m_GuardPoint(-1,-1,-1,0) { //What is the point of this, since the names get mangled.. Mob* mob = entity_list.GetMob(name); @@ -205,10 +206,6 @@ NPC::NPC(const NPCType* d, Spawn2* in_respawn, float x, float y, float z, float merchant_open = GetClass() == MERCHANT; adventure_template_id = d->adventure_template; flymode = iflymode; - guard_x = -1; //just some value we might be able to recongize as "unset" - guard_y = -1; - guard_z = -1; - guard_heading = 0; guard_anim = eaStanding; roambox_distance = 0; roambox_max_x = -2; @@ -673,8 +670,8 @@ bool NPC::Process() DoGravityEffect(); } - if(reface_timer->Check() && !IsEngaged() && (guard_x == GetX() && guard_y == GetY() && guard_z == GetZ())) { - SetHeading(guard_heading); + if(reface_timer->Check() && !IsEngaged() && (m_GuardPoint.m_X == GetX() && m_GuardPoint.m_Y == GetY() && m_GuardPoint.m_Z == GetZ())) { + SetHeading(m_GuardPoint.m_Heading); SendPosition(); reface_timer->Disable(); } diff --git a/zone/npc.h b/zone/npc.h index 1770219ba..ce943174c 100644 --- a/zone/npc.h +++ b/zone/npc.h @@ -215,10 +215,10 @@ public: float GetSpawnPointY() const { return m_SpawnPoint.m_Y; } float GetSpawnPointZ() const { return m_SpawnPoint.m_Z; } float GetSpawnPointH() const { return m_SpawnPoint.m_Heading; } - float GetGuardPointX() const { return guard_x; } - float GetGuardPointY() const { return guard_y; } - float GetGuardPointZ() const { return guard_z; } - float GetGuardPointH() const { return guard_heading; } + float GetGuardPointX() const { return m_GuardPoint.m_X; } + float GetGuardPointY() const { return m_GuardPoint.m_Y; } + float GetGuardPointZ() const { return m_GuardPoint.m_Z; } + float GetGuardPointH() const { return m_GuardPoint.m_Heading; } EmuAppearance GetGuardPointAnim() const { return guard_anim; } void SaveGuardPointAnim(EmuAppearance anim) { guard_anim = anim; } @@ -295,7 +295,7 @@ public: void NextGuardPosition(); void SaveGuardSpot(bool iClearGuardSpot = false); - inline bool IsGuarding() const { return(guard_heading != 0); } + inline bool IsGuarding() const { return(m_GuardPoint.m_Heading != 0); } void SaveGuardSpotCharm(); void RestoreGuardSpotCharm(); void AI_SetRoambox(float iDist, float iRoamDist, uint32 iDelay = 2500, uint32 iMinDelay = 2500); @@ -473,7 +473,7 @@ protected: void _ClearWaypints(); int max_wp; int save_wp; - float guard_x, guard_y, guard_z, guard_heading; + xyz_heading m_GuardPoint; float guard_x_saved, guard_y_saved, guard_z_saved, guard_heading_saved; EmuAppearance guard_anim; float roambox_max_x; diff --git a/zone/waypoints.cpp b/zone/waypoints.cpp index 6f4b3e90a..606149925 100644 --- a/zone/waypoints.cpp +++ b/zone/waypoints.cpp @@ -187,18 +187,15 @@ void NPC::MoveTo(float mtx, float mty, float mtz, float mth, bool saveguardspot) } if (saveguardspot) { - guard_x = mtx; - guard_y = mty; - guard_z = mtz; - guard_heading = mth; + m_GuardPoint = xyz_heading(mtx, mty, mtz, mth); - if(guard_heading == 0) - guard_heading = 0.0001; //hack to make IsGuarding simpler + if(m_GuardPoint.m_Heading == 0) + m_GuardPoint.m_Heading = 0.0001; //hack to make IsGuarding simpler - if(guard_heading == -1) - guard_heading = this->CalculateHeadingToTarget(mtx, mty); + if(m_GuardPoint.m_Heading == -1) + m_GuardPoint.m_Heading = this->CalculateHeadingToTarget(mtx, mty); - mlog(AI__WAYPOINTS, "Setting guard position to (%.3f, %.3f, %.3f)", guard_x, guard_y, guard_z); + mlog(AI__WAYPOINTS, "Setting guard position to %s", to_string(static_cast(m_GuardPoint)).c_str()); } m_CurrentWayPoint = xyz_heading(mtx, mty, mtz, mth); @@ -425,28 +422,23 @@ void NPC::SetWaypointPause() void NPC::SaveGuardSpot(bool iClearGuardSpot) { if (iClearGuardSpot) { mlog(AI__WAYPOINTS, "Clearing guard order."); - guard_x = 0; - guard_y = 0; - guard_z = 0; - guard_heading = 0; + m_GuardPoint = xyz_heading(0, 0, 0, 0); } else { - guard_x = m_Position.m_X; - guard_y = m_Position.m_Y; - guard_z = m_Position.m_Z; - guard_heading = m_Position.m_Heading; - if(guard_heading == 0) - guard_heading = 0.0001; //hack to make IsGuarding simpler - mlog(AI__WAYPOINTS, "Setting guard position to (%.3f, %.3f, %.3f)", guard_x, guard_y, guard_z); + m_GuardPoint = m_Position; + + if(m_GuardPoint.m_Heading == 0) + m_GuardPoint.m_Heading = 0.0001; //hack to make IsGuarding simpler + mlog(AI__WAYPOINTS, "Setting guard position to %s", to_string(static_cast(m_GuardPoint)).c_str()); } } void NPC::NextGuardPosition() { - if (!CalculateNewPosition2(guard_x, guard_y, guard_z, GetMovespeed())) { - SetHeading(guard_heading); + if (!CalculateNewPosition2(m_GuardPoint.m_X, m_GuardPoint.m_Y, m_GuardPoint.m_Z, GetMovespeed())) { + SetHeading(m_GuardPoint.m_Heading); mlog(AI__WAYPOINTS, "Unable to move to next guard position. Probably rooted."); } - else if((m_Position.m_X == guard_x) && (m_Position.m_Y == guard_y) && (m_Position.m_Z == guard_z)) + else if((m_Position.m_X == m_GuardPoint.m_X) && (m_Position.m_Y == m_GuardPoint.m_Y) && (m_Position.m_Z == m_GuardPoint.m_Z)) { if(moved) { @@ -1336,16 +1328,16 @@ int ZoneDatabase::GetHighestWaypoint(uint32 zoneid, uint32 gridid) { void NPC::SaveGuardSpotCharm() { - guard_x_saved = guard_x; - guard_y_saved = guard_y; - guard_z_saved = guard_z; - guard_heading_saved = guard_heading; + guard_x_saved = m_GuardPoint.m_X; + guard_y_saved = m_GuardPoint.m_Y; + guard_z_saved = m_GuardPoint.m_Z; + guard_heading_saved = m_GuardPoint.m_Heading; } void NPC::RestoreGuardSpotCharm() { - guard_x = guard_x_saved; - guard_y = guard_y_saved; - guard_z = guard_z_saved; - guard_heading = guard_heading_saved; + m_GuardPoint.m_X = guard_x_saved; + m_GuardPoint.m_Y = guard_y_saved; + m_GuardPoint.m_Z = guard_z_saved; + m_GuardPoint.m_Heading = guard_heading_saved; }