From f754cb1307d24f08bb08dcfaab969277652f2c58 Mon Sep 17 00:00:00 2001 From: KimLS Date: Tue, 18 Sep 2018 23:06:56 -0700 Subject: [PATCH] Move update path to movement manager so all movement will use paths --- common/data_verification.h | 6 +- common/misc_functions.h | 23 ----- zone/bot.cpp | 16 +--- zone/doors.cpp | 2 +- zone/doors.h | 2 +- zone/entity.cpp | 4 +- zone/entity.h | 2 +- zone/lua_entity_list.cpp | 4 +- zone/lua_entity_list.h | 2 +- zone/merc.cpp | 33 +------ zone/mob_ai.cpp | 167 ++++++---------------------------- zone/mob_movement_manager.cpp | 2 +- zone/perl_entity.cpp | 8 +- zone/waypoints.cpp | 31 +++++-- 14 files changed, 66 insertions(+), 236 deletions(-) diff --git a/common/data_verification.h b/common/data_verification.h index fe1152cb4..27ad017a9 100644 --- a/common/data_verification.h +++ b/common/data_verification.h @@ -17,11 +17,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef COMMON_DATA_VERIFICATION_H -#define COMMON_DATA_VERIFICATION_H +#pragma once #include - +#include namespace EQEmu { @@ -52,4 +51,3 @@ namespace EQEmu } /*EQEmu*/ -#endif /*COMMON_DATA_VERIFICATION_H*/ diff --git a/common/misc_functions.h b/common/misc_functions.h index 2ead697e7..16191916f 100644 --- a/common/misc_functions.h +++ b/common/misc_functions.h @@ -87,28 +87,5 @@ public: ~InitWinsock(); }; -template class AutoDelete { -public: - AutoDelete(T** iVar, T* iSetTo = 0) { - init(iVar, iSetTo); - } - AutoDelete() { pVar = nullptr; } - void init(T** iVar, T* iSetTo = 0) - { - pVar = iVar; - if (iSetTo) - *pVar = iSetTo; - } - ~AutoDelete() { - if(pVar != nullptr) - safe_delete(*pVar); - } - void ReallyClearIt() { - pVar = nullptr; - } -private: - T** pVar; -}; - #endif diff --git a/zone/bot.cpp b/zone/bot.cpp index 8223638eb..3cb75187d 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -2687,14 +2687,7 @@ void Bot::AI_Process() { Log(Logs::Detail, Logs::AI, "Pursuing %s while engaged.", GetTarget()->GetCleanName()); Goal = GetTarget()->GetPosition(); - - if (RuleB(Bots, UsePathing) && zone->pathing) { - bool WaypointChanged, NodeReached; - - Goal = UpdatePath(Goal.x, Goal.y, Goal.z, - GetBotRunspeed(), WaypointChanged, NodeReached); - } - + CalculateNewPosition(Goal.x, Goal.y, Goal.z, GetBotRunspeed()); return; } @@ -2813,13 +2806,6 @@ void Bot::AI_Process() { Goal = follow_mob->GetPosition(); - if (RuleB(Bots, UsePathing) && zone->pathing) { - bool WaypointChanged, NodeReached; - - Goal = UpdatePath(Goal.x, Goal.y, Goal.z, - speed, WaypointChanged, NodeReached); - } - CalculateNewPosition(Goal.x, Goal.y, Goal.z, speed); return; } diff --git a/zone/doors.cpp b/zone/doors.cpp index 9561757df..dc963ab2a 100644 --- a/zone/doors.cpp +++ b/zone/doors.cpp @@ -496,7 +496,7 @@ void Doors::HandleClick(Client* sender, uint8 trigger) { } } -void Doors::NPCOpen(NPC* sender, bool alt_mode) +void Doors::Open(Mob* sender, bool alt_mode) { if (sender) { if (GetTriggerType() == 255 || GetTriggerDoorID() > 0 || GetLockpick() != 0 || GetKeyItem() != 0 || open_type == 59 || open_type == 58 || !sender->IsNPC()) { // this object isnt triggered or door is locked - NPCs should not open locked doors! diff --git a/zone/doors.h b/zone/doors.h index f112f84f1..ef83361c4 100644 --- a/zone/doors.h +++ b/zone/doors.h @@ -49,7 +49,7 @@ public: void ForceClose(Mob *sender, bool alt_mode = false); void ForceOpen(Mob *sender, bool alt_mode = false); void HandleClick(Client *sender, uint8 trigger); - void NPCOpen(NPC *sender, bool alt_mode = false); + void Open(Mob *sender, bool alt_mode = false); void SetDisableTimer(bool flag); void SetDoorName(const char *name); void SetEntityID(uint32 entity) { entity_id = entity; } diff --git a/zone/entity.cpp b/zone/entity.cpp index 1ab6f214a..163d991c5 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -3263,7 +3263,7 @@ void EntityList::AddHealAggro(Mob *target, Mob *caster, uint16 hate) } } -void EntityList::OpenDoorsNear(NPC *who) +void EntityList::OpenDoorsNear(Mob *who) { for (auto it = door_list.begin();it != door_list.end(); ++it) { @@ -3276,7 +3276,7 @@ void EntityList::OpenDoorsNear(NPC *who) float curdist = diff.x * diff.x + diff.y * diff.y; if (diff.z * diff.z < 10 && curdist <= 100) - cdoor->NPCOpen(who); + cdoor->Open(who); } } diff --git a/zone/entity.h b/zone/entity.h index f32532392..816098294 100644 --- a/zone/entity.h +++ b/zone/entity.h @@ -370,7 +370,7 @@ public: void AddHealAggro(Mob* target, Mob* caster, uint16 hate); Mob* FindDefenseNPC(uint32 npcid); - void OpenDoorsNear(NPC* opener); + void OpenDoorsNear(Mob* opener); void UpdateWho(bool iSendFullUpdate = false); void SendPositionUpdates(Client* client, uint32 cLastUpdate = 0, float update_range = 0, Entity* always_send = 0, bool iSendEvenIfNotChanged = false); char* MakeNameUnique(char* name); diff --git a/zone/lua_entity_list.cpp b/zone/lua_entity_list.cpp index e6a572eca..abfc020d6 100644 --- a/zone/lua_entity_list.cpp +++ b/zone/lua_entity_list.cpp @@ -231,7 +231,7 @@ void Lua_EntityList::ReplaceWithTarget(Lua_Mob target, Lua_Mob new_target) { self->ReplaceWithTarget(target, new_target); } -void Lua_EntityList::OpenDoorsNear(Lua_NPC opener) { +void Lua_EntityList::OpenDoorsNear(Lua_Mob opener) { Lua_Safe_Call_Void(); self->OpenDoorsNear(opener); } @@ -479,7 +479,7 @@ luabind::scope lua_register_entity_list() { .def("RemoveFromTargets", (void(Lua_EntityList::*)(Lua_Mob))&Lua_EntityList::RemoveFromTargets) .def("RemoveFromTargets", (void(Lua_EntityList::*)(Lua_Mob, bool))&Lua_EntityList::RemoveFromTargets) .def("ReplaceWithTarget", (void(Lua_EntityList::*)(Lua_Mob, Lua_Mob))&Lua_EntityList::ReplaceWithTarget) - .def("OpenDoorsNear", (void(Lua_EntityList::*)(Lua_NPC))&Lua_EntityList::OpenDoorsNear) + .def("OpenDoorsNear", (void(Lua_EntityList::*)(Lua_Mob))&Lua_EntityList::OpenDoorsNear) .def("MakeNameUnique", (std::string(Lua_EntityList::*)(const char*))&Lua_EntityList::MakeNameUnique) .def("RemoveNumbers", (std::string(Lua_EntityList::*)(const char*))&Lua_EntityList::RemoveNumbers) .def("SignalMobsByNPCID", (void(Lua_EntityList::*)(uint32, int))&Lua_EntityList::SignalMobsByNPCID) diff --git a/zone/lua_entity_list.h b/zone/lua_entity_list.h index 6db846220..6b0074674 100644 --- a/zone/lua_entity_list.h +++ b/zone/lua_entity_list.h @@ -84,7 +84,7 @@ public: void RemoveFromTargets(Lua_Mob mob); void RemoveFromTargets(Lua_Mob mob, bool RemoveFromXTargets); void ReplaceWithTarget(Lua_Mob target, Lua_Mob new_target); - void OpenDoorsNear(Lua_NPC opener); + void OpenDoorsNear(Lua_Mob opener); std::string MakeNameUnique(const char *name); std::string RemoveNumbers(const char *name); void SignalMobsByNPCID(uint32 npc_id, int signal); diff --git a/zone/merc.cpp b/zone/merc.cpp index 2f0cae947..7cb480a2f 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -1478,25 +1478,8 @@ void Merc::AI_Process() { return; } else if (!CheckLosFN(GetTarget())) { - if (RuleB(Mercs, MercsUsePathing) && zone->pathing) { - bool WaypointChanged, NodeReached; - - glm::vec3 Goal = UpdatePath( - GetTarget()->GetX(), - GetTarget()->GetY(), - GetTarget()->GetZ(), - GetRunspeed(), - WaypointChanged, - NodeReached - ); - - CalculateNewPosition(Goal.x, Goal.y, Goal.z, GetRunspeed()); - } - else { - Mob* follow = entity_list.GetMob(GetFollowID()); - if (follow) - CalculateNewPosition(follow->GetX(), follow->GetY(), follow->GetZ(), GetRunspeed()); - } + auto Goal = GetTarget()->GetPosition(); + CalculateNewPosition(Goal.x, Goal.y, Goal.z, GetRunspeed()); return; } @@ -1775,17 +1758,7 @@ void Merc::AI_Process() { SetRunAnimSpeed(0); if (dist > GetFollowDistance()) { - if (RuleB(Mercs, MercsUsePathing) && zone->pathing) { - bool WaypointChanged, NodeReached; - - glm::vec3 Goal = UpdatePath(follow->GetX(), follow->GetY(), follow->GetZ(), - speed, WaypointChanged, NodeReached); - - CalculateNewPosition(Goal.x, Goal.y, Goal.z, speed); - } - else { - CalculateNewPosition(follow->GetX(), follow->GetY(), follow->GetZ(), speed); - } + CalculateNewPosition(follow->GetX(), follow->GetY(), follow->GetZ(), speed); if (rest_timer.Enabled()) rest_timer.Disable(); diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp index dd61a3112..9ecb96719 100644 --- a/zone/mob_ai.cpp +++ b/zone/mob_ai.cpp @@ -807,22 +807,7 @@ void Client::AI_Process() CalculateNewFearpoint(); } - if (!RuleB(Pathing, Fear) || !zone->pathing) - CalculateNewPosition(m_FearWalkTarget.x, m_FearWalkTarget.y, m_FearWalkTarget.z, speed, true); - else { - bool waypoint_changed, node_reached; - - glm::vec3 Goal = UpdatePath( - m_FearWalkTarget.x, - m_FearWalkTarget.y, - m_FearWalkTarget.z, - speed, - waypoint_changed, - node_reached - ); - - CalculateNewPosition(Goal.x, Goal.y, Goal.z, speed); - } + CalculateNewPosition(m_FearWalkTarget.x, m_FearWalkTarget.y, m_FearWalkTarget.z, speed, true); } return; } @@ -892,16 +877,7 @@ void Client::AI_Process() animation = newspeed; newspeed *= 2; SetCurrentSpeed(newspeed); - if(!RuleB(Pathing, Aggro) || !zone->pathing) - CalculateNewPosition(GetTarget()->GetX(), GetTarget()->GetY(), GetTarget()->GetZ(), newspeed); - else - { - bool WaypointChanged, NodeReached; - glm::vec3 Goal = UpdatePath(GetTarget()->GetX(), GetTarget()->GetY(), GetTarget()->GetZ(), - GetRunspeed(), WaypointChanged, NodeReached); - - CalculateNewPosition(Goal.x, Goal.y, Goal.z, newspeed); - } + CalculateNewPosition(GetTarget()->GetX(), GetTarget()->GetY(), GetTarget()->GetZ(), newspeed); } } else if(IsMoving()) @@ -1121,29 +1097,13 @@ void Mob::AI_Process() { // Calculate a new point to run to CalculateNewFearpoint(); } - if (!RuleB(Pathing, Fear) || !zone->pathing) { - CalculateNewPosition( - m_FearWalkTarget.x, - m_FearWalkTarget.y, - m_FearWalkTarget.z, - GetFearSpeed(), - true - ); - } - else { - bool WaypointChanged, NodeReached; - - glm::vec3 Goal = UpdatePath( - m_FearWalkTarget.x, - m_FearWalkTarget.y, - m_FearWalkTarget.z, - GetFearSpeed(), - WaypointChanged, - NodeReached - ); - - CalculateNewPosition(Goal.x, Goal.y, Goal.z, GetFearSpeed()); - } + CalculateNewPosition( + m_FearWalkTarget.x, + m_FearWalkTarget.y, + m_FearWalkTarget.z, + GetFearSpeed(), + true + ); } return; } @@ -1462,18 +1422,7 @@ void Mob::AI_Process() { else if (AI_movement_timer->Check() && target) { if (!IsRooted()) { Log(Logs::Detail, Logs::AI, "Pursuing %s while engaged.", target->GetName()); - if (!RuleB(Pathing, Aggro) || !zone->pathing) - CalculateNewPosition(target->GetX(), target->GetY(), target->GetZ(), GetRunspeed()); - else { - bool WaypointChanged, NodeReached; - - glm::vec3 Goal = UpdatePath( - target->GetX(), target->GetY(), target->GetZ(), - GetRunspeed(), WaypointChanged, NodeReached - ); - - CalculateNewPosition(Goal.x, Goal.y, Goal.z, GetRunspeed()); - } + CalculateNewPosition(target->GetX(), target->GetY(), target->GetZ(), GetRunspeed()); } else if (IsMoving()) { @@ -1572,14 +1521,7 @@ void Mob::AI_Process() { else { bool waypoint_changed, node_reached; - glm::vec3 Goal = UpdatePath( - owner->GetX(), - owner->GetY(), - owner->GetZ(), - pet_speed, - waypoint_changed, - node_reached - ); + auto &Goal = owner->GetPosition(); CalculateNewPosition(Goal.x, Goal.y, Goal.z, pet_speed, true); } @@ -1633,14 +1575,7 @@ void Mob::AI_Process() { bool waypoint_changed, node_reached; - glm::vec3 Goal = UpdatePath( - follow->GetX(), - follow->GetY(), - follow->GetZ(), - speed, - waypoint_changed, - node_reached - ); + auto &Goal = follow->GetPosition(); CalculateNewPosition(Goal.x, Goal.y, Goal.z, speed, true); } @@ -1768,18 +1703,7 @@ void NPC::AI_DoMovement() { roambox_destination_y); } - bool waypoint_changed, node_reached; - - glm::vec3 Goal = UpdatePath( - roambox_destination_x, - roambox_destination_y, - roambox_destination_z, - move_speed, - waypoint_changed, - node_reached - ); - - CalculateNewPosition(Goal.x, Goal.y, Goal.z, move_speed, true); + CalculateNewPosition(roambox_destination_x, roambox_destination_y, roambox_destination_z, move_speed, true); if (m_Position.x == roambox_destination_x && m_Position.y == roambox_destination_y) { time_until_can_move = Timer::GetCurrentTime() + RandomTimer(roambox_min_delay, roambox_delay); @@ -1843,31 +1767,13 @@ void NPC::AI_DoMovement() { ClearFeignMemory(); } if (doMove) { // not at waypoint yet or at 0 pause WP, so keep moving - if (!RuleB(Pathing, AggroReturnToGrid) || !zone->pathing || (DistractedFromGrid == 0)) - CalculateNewPosition( - m_CurrentWayPoint.x, - m_CurrentWayPoint.y, - m_CurrentWayPoint.z, - move_speed, - true - ); - else { - bool WaypointChanged; - bool NodeReached; - glm::vec3 Goal = UpdatePath( - m_CurrentWayPoint.x, - m_CurrentWayPoint.y, - m_CurrentWayPoint.z, - move_speed, - WaypointChanged, - NodeReached - ); - - if (NodeReached) - entity_list.OpenDoorsNear(CastToNPC()); - - CalculateNewPosition(Goal.x, Goal.y, Goal.z, move_speed, true); - } + CalculateNewPosition( + m_CurrentWayPoint.x, + m_CurrentWayPoint.y, + m_CurrentWayPoint.z, + move_speed, + true + ); } } @@ -1887,35 +1793,14 @@ void NPC::AI_DoMovement() { } else if (IsGuarding()) { bool CP2Moved; - if (!RuleB(Pathing, Guard) || !zone->pathing) { - CP2Moved = CalculateNewPosition(m_GuardPoint.x, m_GuardPoint.y, m_GuardPoint.z, move_speed); + + if (!((m_Position.x == m_GuardPoint.x) && (m_Position.y == m_GuardPoint.y) && (m_Position.z == m_GuardPoint.z))) { + CP2Moved = CalculateNewPosition(m_GuardPoint.x, m_GuardPoint.y, m_GuardPoint.z, move_speed); } else { - if (!((m_Position.x == m_GuardPoint.x) && (m_Position.y == m_GuardPoint.y) && - (m_Position.z == m_GuardPoint.z))) { - - bool WaypointChanged, NodeReached; - - glm::vec3 Goal = UpdatePath( - m_GuardPoint.x, - m_GuardPoint.y, - m_GuardPoint.z, - move_speed, - WaypointChanged, - NodeReached - ); - - if (NodeReached) { - entity_list.OpenDoorsNear(CastToNPC()); - } - - CP2Moved = CalculateNewPosition(Goal.x, Goal.y, Goal.z, move_speed); - } - else { - CP2Moved = false; - } - + CP2Moved = false; } + if (!CP2Moved) { if (moved) { Log(Logs::Detail, @@ -1981,7 +1866,7 @@ void NPC::AI_SetupNextWaypoint() { SetAppearance(eaStanding, false); - entity_list.OpenDoorsNear(CastToNPC()); + entity_list.OpenDoorsNear(this); if (!DistractedFromGrid) { //kick off event_waypoint depart diff --git a/zone/mob_movement_manager.cpp b/zone/mob_movement_manager.cpp index 138a85255..00a2536bb 100644 --- a/zone/mob_movement_manager.cpp +++ b/zone/mob_movement_manager.cpp @@ -165,7 +165,7 @@ void MobMovementManager::SendPositionUpdate(Mob *who, bool send_to_self) bool MobMovementManager::HeadingEqual(float a, float b) { - const float eps = 0.001f; + const float eps = 0.0001f; return abs(a - b) < eps; } diff --git a/zone/perl_entity.cpp b/zone/perl_entity.cpp index a38852b9c..58e25b263 100644 --- a/zone/perl_entity.cpp +++ b/zone/perl_entity.cpp @@ -1355,7 +1355,7 @@ XS(XS_EntityList_OpenDoorsNear) { Perl_croak(aTHX_ "Usage: EntityList::OpenDoorsNear(THIS, NPC* opener)"); { EntityList *THIS; - NPC *opener; + Mob *opener; if (sv_derived_from(ST(0), "EntityList")) { IV tmp = SvIV((SV *) SvRV(ST(0))); @@ -1365,11 +1365,11 @@ XS(XS_EntityList_OpenDoorsNear) { if (THIS == nullptr) Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); - if (sv_derived_from(ST(1), "NPC")) { + if (sv_derived_from(ST(1), "Mob")) { IV tmp = SvIV((SV *) SvRV(ST(1))); - opener = INT2PTR(NPC *, tmp); + opener = INT2PTR(Mob *, tmp); } else - Perl_croak(aTHX_ "opener is not of type NPC"); + Perl_croak(aTHX_ "opener is not of type Mob"); if (opener == nullptr) Perl_croak(aTHX_ "opener is nullptr, avoiding crash."); diff --git a/zone/waypoints.cpp b/zone/waypoints.cpp index f285b8887..74bb57c36 100644 --- a/zone/waypoints.cpp +++ b/zone/waypoints.cpp @@ -454,6 +454,17 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, float speed, b return true; } + bool WaypointChanged = false; + bool NodeReached = false; + glm::vec3 Goal = UpdatePath( + x, y, z, speed, WaypointChanged, NodeReached + ); + + if (WaypointChanged || NodeReached) { + calculate_heading = true; + entity_list.OpenDoorsNear(this); + } + SetCurrentSpeed(static_cast(speed)); pRunAnimSpeed = speed; @@ -467,7 +478,7 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, float speed, b } //Setup Vectors - glm::vec3 tar(x, y, z); + glm::vec3 tar(Goal.x, Goal.y, Goal.z); glm::vec3 pos(m_Position.x, m_Position.y, m_Position.z); double len = glm::distance(pos, tar); if (len == 0) { @@ -476,20 +487,16 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, float speed, b glm::vec3 dir = tar - pos; glm::vec3 ndir = glm::normalize(dir); - if (calculate_heading) { - m_Position.w = CalculateHeadingToTarget(x, y); - } - double time_since_last = static_cast(frame_time) / 1000.0; double distance_moved = time_since_last * speed * 2.275f; if (distance_moved > len) { - m_Position.x = x; - m_Position.y = y; - m_Position.z = z; + m_Position.x = Goal.x; + m_Position.y = Goal.y; + m_Position.z = Goal.z; if (IsNPC()) { - entity_list.ProcessMove(CastToNPC(), x, y, z); + entity_list.ProcessMove(CastToNPC(), Goal.x, Goal.y, Goal.z); } if (check_z && fix_z_timer.Check() && (!IsEngaged() || flee_mode || currently_fleeing)) { @@ -505,10 +512,14 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, float speed, b m_Position.z = npos.z; if (IsNPC()) { - entity_list.ProcessMove(CastToNPC(), x, y, z); + entity_list.ProcessMove(CastToNPC(), npos.x, npos.y, npos.z); } } + if (calculate_heading) { + m_Position.w = CalculateHeadingToTarget(Goal.x, Goal.y); + } + if (check_z && fix_z_timer.Check() && !IsEngaged()) { FixZ(); }