From dacbce1c5f6090f2433913647ef4ba233911ae30 Mon Sep 17 00:00:00 2001 From: KimLS Date: Thu, 29 Nov 2018 23:11:39 -0800 Subject: [PATCH] Some changes to fixz while pathing --- common/ruletypes.h | 3 ++- zone/bonuses.cpp | 4 ---- zone/bot.cpp | 4 ---- zone/entity.cpp | 2 +- zone/mob.cpp | 20 +------------------- zone/mob.h | 3 --- zone/mob_ai.cpp | 21 +-------------------- zone/mob_movement_manager.cpp | 33 +++++++++++++++++++++++++++------ zone/waypoints.cpp | 16 ++++++++++++---- 9 files changed, 44 insertions(+), 62 deletions(-) diff --git a/common/ruletypes.h b/common/ruletypes.h index 37f47b21d..b76f3ab15 100644 --- a/common/ruletypes.h +++ b/common/ruletypes.h @@ -277,7 +277,8 @@ RULE_CATEGORY_END() RULE_CATEGORY(Map) RULE_BOOL(Map, FixPathingZOnSendTo, false) //try to repair Z coords in the SendTo routine as well. -RULE_BOOL(Map, FixZWhenMoving, true) // Automatically fix NPC Z coordinates when moving/pathing/engaged (Far less CPU intensive than its predecessor) +RULE_BOOL(Map, FixZWhenPathing, true) // Automatically fix NPC Z coordinates when moving/pathing/engaged (Far less CPU intensive than its predecessor) +RULE_REAL(Map, DistanceCanTravelBeforeAdjustment, 10.0) // distance a mob can path before FixZ is called, depends on FixZWhenPathing RULE_BOOL(Map, MobZVisualDebug, false) // Displays spell effects determining whether or not NPC is hitting Best Z calcs (blue for hit, red for miss) RULE_REAL(Map, FixPathingZMaxDeltaSendTo, 20) //at runtime in SendTo: max change in Z to allow the BestZ code to apply. RULE_INT(Map, FindBestZHeightAdjust, 1) // Adds this to the current Z before seeking the best Z position diff --git a/zone/bonuses.cpp b/zone/bonuses.cpp index e71c6e0d5..d2b0d11f8 100644 --- a/zone/bonuses.cpp +++ b/zone/bonuses.cpp @@ -52,10 +52,6 @@ void Mob::CalcBonuses() We set this here because NPC's can cast spells to change walkspeed/runspeed */ float get_walk_speed = static_cast(0.025f * this->GetWalkspeed()); - if (get_walk_speed >= 0.9 && this->fix_z_timer.GetDuration() != 100) { - this->fix_z_timer.SetTimer(100); - } - rooted = FindType(SE_Root); } diff --git a/zone/bot.cpp b/zone/bot.cpp index b793e8520..f78363649 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -2722,10 +2722,6 @@ void Bot::AI_Process() { } // Fix Z when following during pull, not when engaged and stationary - if (IsMoving() && fix_z_timer_engaged.Check()) { - TryFixZ(); - return; - } if (GetTarget() && GetTarget()->IsFeared() && !spellend_timer.Enabled() && AI_think_timer->Check()) { if (!IsFacingMob(GetTarget())) diff --git a/zone/entity.cpp b/zone/entity.cpp index 9f08b7ea3..f7f5b4594 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -648,7 +648,7 @@ void EntityList::AddNPC(NPC *npc, bool SendSpawnPacket, bool dontqueue) parse->EventNPC(EVENT_SPAWN, npc, nullptr, "", 0); - npc->TryFixZ(); + npc->FixZ(); uint16 emoteid = npc->GetEmoteID(); if (emoteid != 0) diff --git a/zone/mob.cpp b/zone/mob.cpp index b2912f46a..a2e55dd19 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -112,8 +112,6 @@ Mob::Mob(const char* in_name, tmHidden(-1), mitigation_ac(0), m_specialattacks(eSpecialAttacks::None), - fix_z_timer(300), - fix_z_timer_engaged(100), attack_anim_timer(1000), position_update_melee_push_timer(500), hate_list_cleanup_timer(6000) @@ -3426,7 +3424,7 @@ float Mob::FindDestGroundZ(glm::vec3 dest, float z_offset) if (zone->zonemap != nullptr) { dest.z += z_offset; - best_z = zone->zonemap->FindBestZ(dest, nullptr); + best_z = zone->zonemap->FindClosestZ(dest, nullptr); } return best_z; } @@ -6003,22 +6001,6 @@ float Mob::GetDefaultRaceSize() const { return GetRaceGenderDefaultHeight(race, gender); } -void Mob::TryFixZ(int32 z_find_offset, bool fix_client_z) -{ - if (fix_z_timer.Check() && flymode != GravityBehavior::Flying) { - auto watermap = zone->watermap; - if (watermap) { - if (!watermap->InLiquid(m_Position)) { - FixZ(); - } - } - else { - FixZ(); - } - } -} - - #ifdef BOTS bool Mob::JoinHealRotationTargetPool(std::shared_ptr* heal_rotation) { diff --git a/zone/mob.h b/zone/mob.h index 66d43ef7c..ffa471597 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -982,7 +982,6 @@ public: void SendToFixZ(float new_x, float new_y, float new_z); float GetZOffset() const; float GetDefaultRaceSize() const; - void TryFixZ(int32 z_find_offset = 5, bool fix_client_z = false); void FixZ(int32 z_find_offset = 5, bool fix_client_z = false); float GetFixedZ(const glm::vec3 &destination, int32 z_find_offset = 5); virtual int GetStuckBehavior() const { return 0; } @@ -1457,8 +1456,6 @@ protected: bool flee_mode; Timer flee_timer; - Timer fix_z_timer; - Timer fix_z_timer_engaged; Timer attack_anim_timer; Timer position_update_melee_push_timer; diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp index f37c550a5..e44a1246c 100644 --- a/zone/mob_ai.cpp +++ b/zone/mob_ai.cpp @@ -781,9 +781,6 @@ void Client::AI_Process() if (RuleB(Combat, EnableFearPathing)) { if (currently_fleeing) { - if (fix_z_timer.Check()) - TryFixZ(5, true); - if (IsRooted()) { //make sure everybody knows were not moving, for appearance sake if (IsMoving()) { @@ -994,7 +991,7 @@ void Mob::ProcessForcedMovement() Teleport(m_Position + m_Delta); m_Delta = glm::vec4(); SentPositionPacket(0.0f, 0.0f, 0.0f, 0.0f, 0, true); - TryFixZ(); // so we teleport to the ground locally, we want the client to interpolate falling etc + FixZ(); // so we teleport to the ground locally, we want the client to interpolate falling etc } else if (--ForcedMovement) { if (normal.z < -0.15f) // prevent too much wall climbing. ex. OMM's room in anguish normal.z = 0.0f; @@ -1100,22 +1097,6 @@ void Mob::AI_Process() { } if (engaged) { - - /* Fix Z when following during pull, not when engaged and stationary */ - if (moving && fix_z_timer_engaged.Check()) { - if (this->GetTarget()) { - /* If we are engaged, moving and following client, let's look for best Z more often */ - float target_distance = DistanceNoZ(this->GetPosition(), this->GetTarget()->GetPosition()); - TryFixZ(); - - if (target_distance <= 15 && !this->CheckLosFN(this->GetTarget())) { - Mob *target = this->GetTarget(); - - Teleport(target->GetPosition()); - } - } - } - if (!(m_PlayerState & static_cast(PlayerState::Aggressive))) SendAddPlayerState(PlayerState::Aggressive); diff --git a/zone/mob_movement_manager.cpp b/zone/mob_movement_manager.cpp index 917ec502c..ca1b9b14e 100644 --- a/zone/mob_movement_manager.cpp +++ b/zone/mob_movement_manager.cpp @@ -98,6 +98,7 @@ class MoveToCommand : public IMovementCommand { public: MoveToCommand(float x, float y, float z, MobMovementMode mode) { + m_distance_moved_since_correction = 0.0; m_move_to_x = x; m_move_to_y = y; m_move_to_z = z; @@ -139,7 +140,6 @@ public: //rotate to the point m->SetMoving(true); m->SetHeading(m->CalculateHeadingToTarget(m_move_to_x, m_move_to_y)); - m->TryFixZ(); m_last_sent_speed = current_speed; m_last_sent_time = current_time; @@ -150,7 +150,11 @@ public: //When speed changes if (current_speed != m_last_sent_speed) { - m->TryFixZ(); + if (RuleB(Map, FixZWhenPathing)) { + m->FixZ(); + } + + m_distance_moved_since_correction = 0.0; m_last_sent_speed = current_speed; m_last_sent_time = current_time; @@ -159,7 +163,11 @@ public: //If x seconds have passed without sending an update. if (current_time - m_last_sent_time >= 5.0) { - m->TryFixZ(); + if (RuleB(Map, FixZWhenPathing)) { + m->FixZ(); + } + + m_distance_moved_since_correction = 0.0; m_last_sent_speed = current_speed; m_last_sent_time = current_time; @@ -187,7 +195,9 @@ public: m->SetPosition(m_move_to_x, m_move_to_y, m_move_to_z); - m->TryFixZ(); + if (RuleB(Map, FixZWhenPathing)) { + m->FixZ(); + } return true; } else { @@ -203,6 +213,15 @@ public: } m->SetPosition(npos.x, npos.y, z_at_pos); + + + if (RuleB(Map, FixZWhenPathing)) { + m_distance_moved_since_correction += distance_moved; + if (m_distance_moved_since_correction > RuleR(Map, DistanceCanTravelBeforeAdjustment)) { + m_distance_moved_since_correction = 0.0; + m->FixZ(); + } + } } return false; @@ -213,7 +232,7 @@ public: } protected: - + double m_distance_moved_since_correction; double m_move_to_x; double m_move_to_y; double m_move_to_z; @@ -382,7 +401,9 @@ public: if (m->IsMoving()) { m->SetMoving(false); - m->TryFixZ(); + if (RuleB(Map, FixZWhenPathing)) { + m->FixZ(); + } mgr->SendCommandToClients(m, 0.0, 0.0, 0.0, 0.0, 0, ClientRangeCloseMedium); } return true; diff --git a/zone/waypoints.cpp b/zone/waypoints.cpp index 833a8132b..e7b4298d5 100644 --- a/zone/waypoints.cpp +++ b/zone/waypoints.cpp @@ -608,7 +608,7 @@ float Mob::GetFixedZ(const glm::vec3 &destination, int32 z_find_offset) { float new_z = destination.z; - if (zone->HasMap() && RuleB(Map, FixZWhenMoving)) { + if (zone->HasMap()) { if (flymode == GravityBehavior::Flying) return new_z; @@ -645,11 +645,19 @@ float Mob::GetFixedZ(const glm::vec3 &destination, int32 z_find_offset) { } void Mob::FixZ(int32 z_find_offset /*= 5*/, bool fix_client_z /*= false*/) { - glm::vec3 current_loc(m_Position); - - if (IsClient() && !fix_client_z) + if (IsClient() && !fix_client_z) { return; + } + + if (flymode == GravityBehavior::Flying) { + return; + } + if (zone->watermap && zone->watermap->InLiquid(m_Position)) { + return; + } + + glm::vec3 current_loc(m_Position); float new_z = GetFixedZ(current_loc, z_find_offset); if (new_z == m_Position.z)