From f702e953e7444f0cc0de97e9daefee747f5b5e86 Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" Date: Thu, 22 Jan 2015 22:59:52 -0500 Subject: [PATCH] Some std::abs usage and a bit of clang-formatting --- zone/aggro.cpp | 8 +- zone/client.cpp | 11 +- zone/command.cpp | 4 +- zone/merc.cpp | 4 +- zone/mob.cpp | 15 +-- zone/mob_ai.cpp | 90 ++++++++------- zone/pathing.cpp | 68 ++++++----- zone/position.cpp | 254 ++++++++++++++++++++++------------------- zone/position.h | 106 +++++++++-------- zone/spell_effects.cpp | 6 +- zone/spells.cpp | 6 +- zone/waypoints.cpp | 222 ++++++++++++++++++----------------- 12 files changed, 408 insertions(+), 386 deletions(-) diff --git a/zone/aggro.cpp b/zone/aggro.cpp index 9eed2e80d..63b016149 100644 --- a/zone/aggro.cpp +++ b/zone/aggro.cpp @@ -467,8 +467,12 @@ void EntityList::AIYellForHelp(Mob* sender, Mob* attacker) { //Father Nitwit: make sure we can see them. if(mob->CheckLosFN(sender)) { #if (EQDEBUG>=5) - Log.Out(Logs::General, Logs::None, "AIYellForHelp(\"%s\",\"%s\") %s attacking %s Dist %f Z %f", - sender->GetName(), attacker->GetName(), mob->GetName(), attacker->GetName(), ComparativeDistance(mob->GetPosition(), sender->GetPosition()), fabs(sender->GetZ()+mob->GetZ())); + Log.Out(Logs::General, Logs::None, + "AIYellForHelp(\"%s\",\"%s\") %s attacking %s Dist %f Z %f", + sender->GetName(), attacker->GetName(), mob->GetName(), + attacker->GetName(), + ComparativeDistance(mob->GetPosition(), sender->GetPosition()), + std::abs(sender->GetZ() + mob->GetZ())); #endif mob->AddToHateList(attacker, 1, 0, false); } diff --git a/zone/client.cpp b/zone/client.cpp index 698b7967d..2fe451e0f 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -22,14 +22,11 @@ #include // for windows compile -#ifdef _WINDOWS - #define abs64 _abs64 -#else +#ifndef _WINDOWS #include #include #include #include "../common/unix.h" - #define abs64 abs #endif extern volatile bool RunLoops; @@ -1967,7 +1964,7 @@ bool Client::TakeMoneyFromPP(uint64 copper, bool updateclient) { copperpp -= copper; if(copperpp <= 0) { - copper = abs64(copperpp); + copper = std::abs(copperpp); m_pp.copper = 0; } else @@ -1981,7 +1978,7 @@ bool Client::TakeMoneyFromPP(uint64 copper, bool updateclient) { silver -= copper; if(silver <= 0) { - copper = abs64(silver); + copper = std::abs(silver); m_pp.silver = 0; } else @@ -1998,7 +1995,7 @@ bool Client::TakeMoneyFromPP(uint64 copper, bool updateclient) { if(gold <= 0) { - copper = abs64(gold); + copper = std::abs(gold); m_pp.gold = 0; } else diff --git a/zone/command.cpp b/zone/command.cpp index 5f615bb51..cca2aec78 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -10242,7 +10242,9 @@ void command_zopp(Client *c, const Seperator *sep) ItemInst* FakeItemInst = database.CreateItem(FakeItem, charges); c->SendItemPacket(slotid, FakeItemInst, packettype); - c->Message(0, "Sending zephyr op packet to client - [%s] %s (%u) with %i %s to slot %i.", packettype==ItemPacketTrade?"Trade":"Summon", FakeItem->Name, itemid, charges, abs(charges==1)?"charge":"charges", slotid); + c->Message(0, "Sending zephyr op packet to client - [%s] %s (%u) with %i %s to slot %i.", + packettype == ItemPacketTrade ? "Trade" : "Summon", FakeItem->Name, itemid, charges, + std::abs(charges == 1) ? "charge" : "charges", slotid); safe_delete(FakeItemInst); } } diff --git a/zone/merc.cpp b/zone/merc.cpp index ef8d0ed22..ed3d8f502 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -2869,9 +2869,7 @@ bool Merc::CheckStance(int16 stance) { //checks of current stance matches stances listed as valid for spell in database //stance = 0 for all stances, stance # for only that stance & -stance# for all but that stance - if(stance == 0 - || (stance > 0 && stance == GetStance()) - || (stance < 0 && abs(stance) != GetStance())) { + if (stance == 0 || (stance > 0 && stance == GetStance()) || (stance < 0 && std::abs(stance) != GetStance())) { return true; } diff --git a/zone/mob.cpp b/zone/mob.cpp index 2c3b6383b..4c81c99db 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -3126,8 +3126,8 @@ int Mob::GetSnaredAmount() { int val = CalcSpellEffectValue_formula(spells[buffs[i].spellid].formula[j], spells[buffs[i].spellid].base[j], spells[buffs[i].spellid].max[j], buffs[i].casterlevel, buffs[i].spellid); //int effect = CalcSpellEffectValue(buffs[i].spellid, spells[buffs[i].spellid].effectid[j], buffs[i].casterlevel); - if (val < 0 && abs(val) > worst_snare) - worst_snare = abs(val); + if (val < 0 && std::abs(val) > worst_snare) + worst_snare = std::abs(val); } } } @@ -4493,7 +4493,8 @@ void Mob::DoGravityEffect() if(value > 0) away = 1; - amount = fabs(value) / (100.0f); // to bring the values in line, arbitarily picked + amount = std::abs(value) / + (100.0f); // to bring the values in line, arbitarily picked x_vector = cur_x - caster_x; y_vector = cur_y - caster_y; @@ -4512,7 +4513,7 @@ void Mob::DoGravityEffect() } } - if((fabs(my_x - cur_x) > 0.01) || (fabs(my_y - cur_y) > 0.01)) { + if ((std::abs(my_x - cur_x) > 0.01) || (std::abs(my_y - cur_y) > 0.01)) { float new_ground = GetGroundZ(cur_x, cur_y); // If we cant get LoS on our new spot then keep checking up to 5 units up. if(!CheckLosFN(cur_x, cur_y, new_ground, GetSize())) { @@ -5172,7 +5173,7 @@ bool Mob::IsFacingMob(Mob *other) if (angle < 40.0 && heading > 472.0) angle = heading; - if (fabs(angle - heading) <= 80.0) + if (std::abs(angle - heading) <= 80.0) return true; return false; @@ -5186,8 +5187,8 @@ float Mob::HeadingAngleToMob(Mob *other) float this_x = GetX(); float this_y = GetY(); - float y_diff = fabs(this_y - mob_y); - float x_diff = fabs(this_x - mob_x); + float y_diff = std::abs(this_y - mob_y); + float x_diff = std::abs(this_x - mob_x); if (y_diff < 0.0000009999999974752427) y_diff = 0.0000009999999974752427; diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp index 85ac74518..b9f3a3c58 100644 --- a/zone/mob_ai.cpp +++ b/zone/mob_ai.cpp @@ -43,7 +43,6 @@ extern Zone *zone; #else #define MobAI_DEBUG_Spells -1 #endif -#define ABS(x) ((x)<0?-(x):(x)) //NOTE: do NOT pass in beneficial and detrimental spell types into the same call here! bool NPC::AICastSpell(Mob* tar, uint8 iChance, uint16 iSpellTypes) { @@ -784,7 +783,8 @@ void Client::AI_Process() if(AImovement_timer->Check()) { animation = GetRunspeed() * 21; // Check if we have reached the last fear point - if((ABS(GetX()-m_FearWalkTarget.m_X) < 0.1) && (ABS(GetY()-m_FearWalkTarget.m_Y) <0.1)) { + if ((std::abs(GetX() - m_FearWalkTarget.m_X) < 0.1) && + (std::abs(GetY() - m_FearWalkTarget.m_Y) < 0.1)) { // Calculate a new point to run to CalculateNewFearpoint(); } @@ -1052,7 +1052,8 @@ void Mob::AI_Process() { } else { if(AImovement_timer->Check()) { // Check if we have reached the last fear point - if((ABS(GetX()-m_FearWalkTarget.m_X) < 0.1) && (ABS(GetY()-m_FearWalkTarget.m_Y) <0.1)) { + if ((std::abs(GetX() - m_FearWalkTarget.m_X) < 0.1) && + (std::abs(GetY() - m_FearWalkTarget.m_Y) < 0.1)) { // Calculate a new point to run to CalculateNewFearpoint(); } @@ -2784,15 +2785,16 @@ uint32 ZoneDatabase::GetMaxNPCSpellsID() { return atoi(row[0]); } -DBnpcspellseffects_Struct* ZoneDatabase::GetNPCSpellsEffects(uint32 iDBSpellsEffectsID) { +DBnpcspellseffects_Struct *ZoneDatabase::GetNPCSpellsEffects(uint32 iDBSpellsEffectsID) +{ if (iDBSpellsEffectsID == 0) return nullptr; if (!npc_spellseffects_cache) { npc_spellseffects_maxid = GetMaxNPCSpellsEffectsID(); - npc_spellseffects_cache = new DBnpcspellseffects_Struct*[npc_spellseffects_maxid+1]; - npc_spellseffects_loadtried = new bool[npc_spellseffects_maxid+1]; - for (uint32 i=0; i<=npc_spellseffects_maxid; i++) { + npc_spellseffects_cache = new DBnpcspellseffects_Struct *[npc_spellseffects_maxid + 1]; + npc_spellseffects_loadtried = new bool[npc_spellseffects_maxid + 1]; + for (uint32 i = 0; i <= npc_spellseffects_maxid; i++) { npc_spellseffects_cache[i] = 0; npc_spellseffects_loadtried[i] = false; } @@ -2801,53 +2803,55 @@ DBnpcspellseffects_Struct* ZoneDatabase::GetNPCSpellsEffects(uint32 iDBSpellsEff if (iDBSpellsEffectsID > npc_spellseffects_maxid) return nullptr; - if (npc_spellseffects_cache[iDBSpellsEffectsID]) // it's in the cache, easy =) + if (npc_spellseffects_cache[iDBSpellsEffectsID]) // it's in the cache, easy =) return npc_spellseffects_cache[iDBSpellsEffectsID]; if (npc_spellseffects_loadtried[iDBSpellsEffectsID]) - return nullptr; + return nullptr; - npc_spellseffects_loadtried[iDBSpellsEffectsID] = true; + npc_spellseffects_loadtried[iDBSpellsEffectsID] = true; - std::string query = StringFormat("SELECT id, parent_list FROM npc_spells_effects WHERE id=%d", iDBSpellsEffectsID); - auto results = QueryDatabase(query); - if (!results.Success()) { - return nullptr; - } + std::string query = + StringFormat("SELECT id, parent_list FROM npc_spells_effects WHERE id=%d", iDBSpellsEffectsID); + auto results = QueryDatabase(query); + if (!results.Success()) { + return nullptr; + } - if (results.RowCount() != 1) - return nullptr; + if (results.RowCount() != 1) + return nullptr; - auto row = results.begin(); - uint32 tmpparent_list = atoi(row[1]); + auto row = results.begin(); + uint32 tmpparent_list = atoi(row[1]); - query = StringFormat("SELECT spell_effect_id, minlevel, " - "maxlevel,se_base, se_limit, se_max " - "FROM npc_spells_effects_entries " - "WHERE npc_spells_effects_id = %d ORDER BY minlevel", iDBSpellsEffectsID); - results = QueryDatabase(query); - if (!results.Success()) - return nullptr; + query = StringFormat("SELECT spell_effect_id, minlevel, " + "maxlevel,se_base, se_limit, se_max " + "FROM npc_spells_effects_entries " + "WHERE npc_spells_effects_id = %d ORDER BY minlevel", + iDBSpellsEffectsID); + results = QueryDatabase(query); + if (!results.Success()) + return nullptr; - uint32 tmpSize = sizeof(DBnpcspellseffects_Struct) + (sizeof(DBnpcspellseffects_entries_Struct) * results.RowCount()); - npc_spellseffects_cache[iDBSpellsEffectsID] = (DBnpcspellseffects_Struct*) new uchar[tmpSize]; - memset(npc_spellseffects_cache[iDBSpellsEffectsID], 0, tmpSize); - npc_spellseffects_cache[iDBSpellsEffectsID]->parent_list = tmpparent_list; - npc_spellseffects_cache[iDBSpellsEffectsID]->numentries = results.RowCount(); + uint32 tmpSize = + sizeof(DBnpcspellseffects_Struct) + (sizeof(DBnpcspellseffects_entries_Struct) * results.RowCount()); + npc_spellseffects_cache[iDBSpellsEffectsID] = (DBnpcspellseffects_Struct *)new uchar[tmpSize]; + memset(npc_spellseffects_cache[iDBSpellsEffectsID], 0, tmpSize); + npc_spellseffects_cache[iDBSpellsEffectsID]->parent_list = tmpparent_list; + npc_spellseffects_cache[iDBSpellsEffectsID]->numentries = results.RowCount(); - int entryIndex = 0; - for (row = results.begin(); row != results.end(); ++row, ++entryIndex) - { - int spell_effect_id = atoi(row[0]); - npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].spelleffectid = spell_effect_id; - npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].minlevel = atoi(row[1]); - npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].maxlevel = atoi(row[2]); - npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].base = atoi(row[3]); - npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].limit = atoi(row[4]); - npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].max = atoi(row[5]); - } + int entryIndex = 0; + for (row = results.begin(); row != results.end(); ++row, ++entryIndex) { + int spell_effect_id = atoi(row[0]); + npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].spelleffectid = spell_effect_id; + npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].minlevel = atoi(row[1]); + npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].maxlevel = atoi(row[2]); + npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].base = atoi(row[3]); + npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].limit = atoi(row[4]); + npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].max = atoi(row[5]); + } - return npc_spellseffects_cache[iDBSpellsEffectsID]; + return npc_spellseffects_cache[iDBSpellsEffectsID]; } uint32 ZoneDatabase::GetMaxNPCSpellsEffectsID() { diff --git a/zone/pathing.cpp b/zone/pathing.cpp index 61abe1b49..55ee3c50c 100644 --- a/zone/pathing.cpp +++ b/zone/pathing.cpp @@ -17,7 +17,6 @@ #endif //#define PATHDEBUG -#define ABS(x) ((x)<0?-(x):(x)) extern Zone *zone; @@ -371,10 +370,9 @@ std::deque PathManager::FindRoute(Map::Vertex Start, Map::Vertex End) for(uint32 i = 0 ; i < Head.PathNodeCount; ++i) { - if((ABS(Start.x - PathNodes[i].v.x) <= CandidateNodeRangeXY) && - (ABS(Start.y - PathNodes[i].v.y) <= CandidateNodeRangeXY) && - (ABS(Start.z - PathNodes[i].v.z) <= CandidateNodeRangeZ)) - { + if ((std::abs(Start.x - PathNodes[i].v.x) <= CandidateNodeRangeXY) && + (std::abs(Start.y - PathNodes[i].v.y) <= CandidateNodeRangeXY) && + (std::abs(Start.z - PathNodes[i].v.z) <= CandidateNodeRangeZ)) { TempNode.id = i; TempNode.Distance = VertexDistanceNoRoot(Start, PathNodes[i].v); SortedByDistance.push_back(TempNode); @@ -410,10 +408,9 @@ std::deque PathManager::FindRoute(Map::Vertex Start, Map::Vertex End) for(uint32 i = 0 ; i < Head.PathNodeCount; ++i) { - if((ABS(End.x - PathNodes[i].v.x) <= CandidateNodeRangeXY) && - (ABS(End.y - PathNodes[i].v.y) <= CandidateNodeRangeXY) && - (ABS(End.z - PathNodes[i].v.z) <= CandidateNodeRangeZ)) - { + if ((std::abs(End.x - PathNodes[i].v.x) <= CandidateNodeRangeXY) && + (std::abs(End.y - PathNodes[i].v.y) <= CandidateNodeRangeXY) && + (std::abs(End.z - PathNodes[i].v.z) <= CandidateNodeRangeZ)) { TempNode.id = i; TempNode.Distance = VertexDistanceNoRoot(End, PathNodes[i].v); SortedByDistance.push_back(TempNode); @@ -758,9 +755,8 @@ Map::Vertex Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool & Log.Out(Logs::Detail, Logs::None, " Distance between From and To (NoRoot) is %8.3f", Distance); - if((Distance <= RuleR(Pathing, MinDistanceForLOSCheckShort)) - && (ABS(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) - { + if ((Distance <= RuleR(Pathing, MinDistanceForLOSCheckShort)) && + (std::abs(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) { if(!zone->zonemap->LineIntersectsZone(HeadPosition, To, 1.0f, nullptr)) PathingLOSState = HaveLOS; else @@ -851,9 +847,8 @@ Map::Vertex Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool & Log.Out(Logs::Detail, Logs::None, " Distance between From and To (NoRoot) is %8.3f", Distance); - if((Distance <= RuleR(Pathing, MinDistanceForLOSCheckShort)) - && (ABS(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) - { + if ((Distance <= RuleR(Pathing, MinDistanceForLOSCheckShort)) && + (std::abs(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) { if(!zone->zonemap->LineIntersectsZone(HeadPosition, To, 1.0f, nullptr)) PathingLOSState = HaveLOS; else @@ -889,9 +884,8 @@ Map::Vertex Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool & { float Distance = VertexDistanceNoRoot(From, To); - if((Distance <= RuleR(Pathing, MinDistanceForLOSCheckShort)) - && (ABS(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) - { + if ((Distance <= RuleR(Pathing, MinDistanceForLOSCheckShort)) && + (std::abs(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) { Log.Out(Logs::Detail, Logs::None, " Checking for short LOS at distance %8.3f.", Distance); if(!zone->zonemap->LineIntersectsZone(HeadPosition, To, 1.0f, nullptr)) PathingLOSState = HaveLOS; @@ -1041,9 +1035,8 @@ Map::Vertex Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool & float Distance = VertexDistanceNoRoot(From, To); - if((Distance <= RuleR(Pathing, MinDistanceForLOSCheckLong)) - && (ABS(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) - { + if ((Distance <= RuleR(Pathing, MinDistanceForLOSCheckLong)) && + (std::abs(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) { Log.Out(Logs::Detail, Logs::None, " Checking for long LOS at distance %8.3f.", Distance); if(!zone->zonemap->LineIntersectsZone(HeadPosition, To, 1.0f, nullptr)) @@ -1109,10 +1102,9 @@ int PathManager::FindNearestPathNode(Map::Vertex Position) for(uint32 i = 0 ; i < Head.PathNodeCount; ++i) { - if((ABS(Position.x - PathNodes[i].v.x) <= CandidateNodeRangeXY) && - (ABS(Position.y - PathNodes[i].v.y) <= CandidateNodeRangeXY) && - (ABS(Position.z - PathNodes[i].v.z) <= CandidateNodeRangeZ)) - { + if ((std::abs(Position.x - PathNodes[i].v.x) <= CandidateNodeRangeXY) && + (std::abs(Position.y - PathNodes[i].v.y) <= CandidateNodeRangeXY) && + (std::abs(Position.z - PathNodes[i].v.z) <= CandidateNodeRangeZ)) { TempNode.id = i; TempNode.Distance = VertexDistanceNoRoot(Position, PathNodes[i].v); SortedByDistance.push_back(TempNode); @@ -1148,8 +1140,7 @@ bool PathManager::NoHazards(Map::Vertex From, Map::Vertex To) float NewZ = zone->zonemap->FindBestZ(MidPoint, nullptr); - if(ABS(NewZ - From.z) > RuleR(Pathing, ZDiffThreshold)) - { + if (std::abs(NewZ - From.z) > RuleR(Pathing, ZDiffThreshold)) { Log.Out(Logs::Detail, Logs::None, " HAZARD DETECTED moving from %8.3f, %8.3f, %8.3f to %8.3f, %8.3f, %8.3f. Z Change is %8.3f", From.x, From.y, From.z, MidPoint.x, MidPoint.y, MidPoint.z, NewZ - From.z); @@ -1187,8 +1178,7 @@ bool PathManager::NoHazardsAccurate(Map::Vertex From, Map::Vertex To) Map::Vertex TestPoint(curx, cury, curz); float NewZ = zone->zonemap->FindBestZ(TestPoint, nullptr); - if (ABS(NewZ - last_z) > 5.0f) - { + if (std::abs(NewZ - last_z) > 5.0f) { Log.Out(Logs::Detail, Logs::None, " HAZARD DETECTED moving from %8.3f, %8.3f, %8.3f to %8.3f, %8.3f, %8.3f. Best Z %8.3f, Z Change is %8.3f", From.x, From.y, From.z, TestPoint.x, TestPoint.y, TestPoint.z, NewZ, NewZ - From.z); return false; @@ -1222,14 +1212,17 @@ bool PathManager::NoHazardsAccurate(Map::Vertex From, Map::Vertex To) } else { - if (ABS(NewZ - best_z2) > RuleR(Pathing, ZDiffThreshold)) - { - Log.Out(Logs::Detail, Logs::None, " HAZARD DETECTED, water is fairly deep at %8.3f units deep", ABS(NewZ - best_z2)); + if (std::abs(NewZ - best_z2) > RuleR(Pathing, ZDiffThreshold)) { + Log.Out(Logs::Detail, Logs::None, + " HAZARD DETECTED, water is fairly deep at %8.3f units deep", + std::abs(NewZ - best_z2)); return false; } else { - Log.Out(Logs::Detail, Logs::None, " HAZARD NOT DETECTED, water is shallow at %8.3f units deep", ABS(NewZ - best_z2)); + Log.Out(Logs::Detail, Logs::None, + " HAZARD NOT DETECTED, water is shallow at %8.3f units deep", + std::abs(NewZ - best_z2)); } } } @@ -1251,9 +1244,12 @@ bool PathManager::NoHazardsAccurate(Map::Vertex From, Map::Vertex To) cur.y = cury; cur.z = curz; - if (ABS(curx - To.x) < step_size) cur.x = To.x; - if (ABS(cury - To.y) < step_size) cur.y = To.y; - if (ABS(curz - To.z) < step_size) cur.z = To.z; + if (std::abs(curx - To.x) < step_size) + cur.x = To.x; + if (std::abs(cury - To.y) < step_size) + cur.y = To.y; + if (std::abs(curz - To.z) < step_size) + cur.z = To.z; } while (cur.x != To.x || cur.y != To.y || cur.z != To.z); return true; diff --git a/zone/position.cpp b/zone/position.cpp index e6996797f..38643ac22 100644 --- a/zone/position.cpp +++ b/zone/position.cpp @@ -4,223 +4,237 @@ #include "../common/string_util.h" #include -xy_location::xy_location(float x, float y) : - m_X(x), - m_Y(y) { +xy_location::xy_location(float x, float y) : m_X(x), m_Y(y) +{ } -xy_location xy_location::operator -(const xy_location& rhs) const { - xy_location minus(m_X - rhs.m_X, m_Y - rhs.m_Y); - return minus; +xy_location xy_location::operator-(const xy_location &rhs) const +{ + xy_location minus(m_X - rhs.m_X, m_Y - rhs.m_Y); + return minus; } -xy_location xy_location::operator +(const xy_location& rhs) const { - xy_location addition(m_X + rhs.m_X, m_Y + rhs.m_Y); - return addition; +xy_location xy_location::operator+(const xy_location &rhs) const +{ + xy_location addition(m_X + rhs.m_X, m_Y + rhs.m_Y); + return addition; } -xyz_heading::xyz_heading(float x, float y, float z, float heading) : - m_X(x), - m_Y(y), - m_Z(z), - m_Heading(heading) { +xyz_heading::xyz_heading(float x, float y, float z, float heading) : m_X(x), m_Y(y), m_Z(z), m_Heading(heading) +{ } -xyz_heading::xyz_heading(const xyz_heading& locationDir) : - m_X(locationDir.m_X), - m_Y(locationDir.m_Y), - m_Z(locationDir.m_Z), - m_Heading(locationDir.m_Heading) { +xyz_heading::xyz_heading(const xyz_heading &locationDir) + : m_X(locationDir.m_X), m_Y(locationDir.m_Y), m_Z(locationDir.m_Z), m_Heading(locationDir.m_Heading) +{ } -xyz_heading::xyz_heading(const xyz_location& locationDir, float heading) : - m_X(locationDir.m_X), - m_Y(locationDir.m_Y), - m_Z(locationDir.m_Z), - m_Heading(heading) { +xyz_heading::xyz_heading(const xyz_location &locationDir, float heading) + : m_X(locationDir.m_X), m_Y(locationDir.m_Y), m_Z(locationDir.m_Z), m_Heading(heading) +{ } -xyz_heading::xyz_heading(const xy_location& locationDir, float z, float heading) : - m_X(locationDir.m_X), - m_Y(locationDir.m_Y), - m_Z(z), - m_Heading(heading) { +xyz_heading::xyz_heading(const xy_location &locationDir, float z, float heading) + : m_X(locationDir.m_X), m_Y(locationDir.m_Y), m_Z(z), m_Heading(heading) +{ } -xyz_heading::xyz_heading(const xy_location locationDir, float z, float heading) : - m_X(locationDir.m_X), - m_Y(locationDir.m_Y), - m_Z(z), - m_Heading(heading) { +xyz_heading::xyz_heading(const xy_location locationDir, float z, float heading) + : m_X(locationDir.m_X), m_Y(locationDir.m_Y), m_Z(z), m_Heading(heading) +{ } -xyz_heading::operator xyz_location() const { - return xyz_location(m_X,m_Y,m_Z); +xyz_heading::operator xyz_location() const +{ + return xyz_location(m_X, m_Y, m_Z); } -xyz_heading::operator xy_location() const { - return xy_location(m_X,m_Y); +xyz_heading::operator xy_location() const +{ + return xy_location(m_X, m_Y); } -const xyz_heading xyz_heading::operator +(const xyz_location& rhs) const{ - return xyz_heading(m_X + rhs.m_X, m_Y + rhs.m_Y, m_Z + rhs.m_Z, m_Heading); +const xyz_heading xyz_heading::operator+(const xyz_location &rhs) const +{ + return xyz_heading(m_X + rhs.m_X, m_Y + rhs.m_Y, m_Z + rhs.m_Z, m_Heading); } -const xyz_heading xyz_heading::operator +(const xy_location& rhs) const{ - return xyz_heading(m_X + rhs.m_X, m_Y + rhs.m_Y, m_Z, m_Heading); +const xyz_heading xyz_heading::operator+(const xy_location &rhs) const +{ + return xyz_heading(m_X + rhs.m_X, m_Y + rhs.m_Y, m_Z, m_Heading); } -const xyz_heading xyz_heading::operator -(const xyz_location& rhs) const{ - return xyz_heading(m_X - rhs.m_X, m_Y - rhs.m_Y, m_Z - rhs.m_Z, m_Heading); +const xyz_heading xyz_heading::operator-(const xyz_location &rhs) const +{ + return xyz_heading(m_X - rhs.m_X, m_Y - rhs.m_Y, m_Z - rhs.m_Z, m_Heading); } -void xyz_heading::ABS_XYZ(void) { - m_X = abs(m_X); - m_Y = abs(m_Y); - m_Z = abs(m_Z); +void xyz_heading::ABS_XYZ(void) +{ + m_X = std::abs(m_X); + m_Y = std::abs(m_Y); + m_Z = std::abs(m_Z); } -xyz_location::xyz_location(float x, float y, float z) : - m_X(x), - m_Y(y), - m_Z(z) { +xyz_location::xyz_location(float x, float y, float z) : m_X(x), m_Y(y), m_Z(z) +{ } -xyz_location::xyz_location(double x, double y, double z) : - m_X(static_cast(x)), - m_Y(static_cast(y)), - m_Z(static_cast(z)) { +xyz_location::xyz_location(double x, double y, double z) + : m_X(static_cast(x)), m_Y(static_cast(y)), m_Z(static_cast(z)) +{ } -xyz_location::operator xy_location() const { - return xy_location(m_X, m_Y); +xyz_location::operator xy_location() const +{ + return xy_location(m_X, m_Y); } -xyz_location xyz_location::operator -(const xyz_location& rhs) const { - return xyz_location(m_X - rhs.m_X, m_Y - rhs.m_Y, m_Z - rhs.m_Z); +xyz_location xyz_location::operator-(const xyz_location &rhs) const +{ + return xyz_location(m_X - rhs.m_X, m_Y - rhs.m_Y, m_Z - rhs.m_Z); } -xyz_location xyz_location::operator +(const xyz_location& rhs) const { - return xyz_location(m_X + rhs.m_X, m_Y + rhs.m_Y, m_Z + rhs.m_Z); +xyz_location xyz_location::operator+(const xyz_location &rhs) const +{ + return xyz_location(m_X + rhs.m_X, m_Y + rhs.m_Y, m_Z + rhs.m_Z); } -void xyz_location::ABS_XYZ(void) { - m_X = abs(m_X); - m_Y = abs(m_Y); - m_Z = abs(m_Z); +void xyz_location::ABS_XYZ(void) +{ + m_X = std::abs(m_X); + m_Y = std::abs(m_Y); + m_Z = std::abs(m_Z); } -std::string to_string(const xyz_heading &position) { - return StringFormat("(%.3f, %.3f, %.3f, %.3f)", position.m_X,position.m_Y,position.m_Z,position.m_Heading); +std::string to_string(const xyz_heading &position) +{ + return StringFormat("(%.3f, %.3f, %.3f, %.3f)", position.m_X, position.m_Y, position.m_Z, position.m_Heading); } -std::string to_string(const xyz_location &position){ - return StringFormat("(%.3f, %.3f, %.3f)", position.m_X,position.m_Y,position.m_Z); +std::string to_string(const xyz_location &position) +{ + return StringFormat("(%.3f, %.3f, %.3f)", position.m_X, position.m_Y, position.m_Z); } -std::string to_string(const xy_location &position){ - return StringFormat("(%.3f, %.3f)", position.m_X,position.m_Y); +std::string to_string(const xy_location &position) +{ + return StringFormat("(%.3f, %.3f)", position.m_X, position.m_Y); } /** * Produces the non square root'ed distance between the two points within the XY plane. */ -float ComparativeDistance(const xy_location& point1, const xy_location& point2) { - auto diff = point1 - point2; - return diff.m_X * diff.m_X + diff.m_Y * diff.m_Y; +float ComparativeDistance(const xy_location &point1, const xy_location &point2) +{ + auto diff = point1 - point2; + return diff.m_X * diff.m_X + diff.m_Y * diff.m_Y; } /** * Produces the distance between the two points on the XY plane. */ -float Distance(const xy_location& point1, const xy_location& point2) { - return sqrt(ComparativeDistance(point1, point2)); +float Distance(const xy_location &point1, const xy_location &point2) +{ + return sqrt(ComparativeDistance(point1, point2)); } /** * Produces the non square root'ed distance between the two points. */ -float ComparativeDistance(const xyz_location& point1, const xyz_location& point2) { - auto diff = point1 - point2; - return diff.m_X * diff.m_X + diff.m_Y * diff.m_Y + diff.m_Z * diff.m_Z; +float ComparativeDistance(const xyz_location &point1, const xyz_location &point2) +{ + auto diff = point1 - point2; + return diff.m_X * diff.m_X + diff.m_Y * diff.m_Y + diff.m_Z * diff.m_Z; } /** * Produces the non square root'ed distance between the two points. */ -float ComparativeDistance(const xyz_heading& point1, const xyz_heading& point2) { - return ComparativeDistance(static_cast(point1), static_cast(point2)); +float ComparativeDistance(const xyz_heading &point1, const xyz_heading &point2) +{ + return ComparativeDistance(static_cast(point1), static_cast(point2)); } /** * Produces the distance between the two points. */ -float Distance(const xyz_location& point1, const xyz_location& point2) { - return sqrt(ComparativeDistance(point1, point2)); +float Distance(const xyz_location &point1, const xyz_location &point2) +{ + return sqrt(ComparativeDistance(point1, point2)); } /** * Produces the distance between the two points. */ -float Distance(const xyz_heading& point1, const xyz_heading& point2) { - return Distance(static_cast(point1), static_cast(point2)); +float Distance(const xyz_heading &point1, const xyz_heading &point2) +{ + return Distance(static_cast(point1), static_cast(point2)); } /** * Produces the distance between the two points within the XY plane. */ -float DistanceNoZ(const xyz_location& point1, const xyz_location& point2) { - return Distance(static_cast(point1),static_cast(point2)); +float DistanceNoZ(const xyz_location &point1, const xyz_location &point2) +{ + return Distance(static_cast(point1), static_cast(point2)); } /** * Produces the distance between the two points within the XY plane. */ -float DistanceNoZ(const xyz_heading& point1, const xyz_heading& point2) { - return Distance(static_cast(point1),static_cast(point2)); +float DistanceNoZ(const xyz_heading &point1, const xyz_heading &point2) +{ + return Distance(static_cast(point1), static_cast(point2)); } /** * Produces the non square root'ed distance between the two points within the XY plane. */ -float ComparativeDistanceNoZ(const xyz_location& point1, const xyz_location& point2) { - return ComparativeDistance(static_cast(point1),static_cast(point2)); +float ComparativeDistanceNoZ(const xyz_location &point1, const xyz_location &point2) +{ + return ComparativeDistance(static_cast(point1), static_cast(point2)); } /** * Produces the non square root'ed distance between the two points within the XY plane. */ -float ComparativeDistanceNoZ(const xyz_heading& point1, const xyz_heading& point2) { - return ComparativeDistance(static_cast(point1),static_cast(point2)); +float ComparativeDistanceNoZ(const xyz_heading &point1, const xyz_heading &point2) +{ + return ComparativeDistance(static_cast(point1), static_cast(point2)); } /** * Determines if 'position' is within (inclusive) the axis aligned * box (3 dimensional) formed from the points minimum and maximum. */ -bool IsWithinAxisAlignedBox(const xyz_location &position, const xyz_location &minimum, const xyz_location &maximum) { - auto actualMinimum = xyz_location(std::min(minimum.m_X, maximum.m_X), std::min(minimum.m_Y, maximum.m_Y),std::min(minimum.m_Z, maximum.m_Z)); - auto actualMaximum = xyz_location(std::max(minimum.m_X, maximum.m_X), std::max(minimum.m_Y, maximum.m_Y),std::max(minimum.m_Z, maximum.m_Z)); +bool IsWithinAxisAlignedBox(const xyz_location &position, const xyz_location &minimum, const xyz_location &maximum) +{ + auto actualMinimum = xyz_location(std::min(minimum.m_X, maximum.m_X), std::min(minimum.m_Y, maximum.m_Y), + std::min(minimum.m_Z, maximum.m_Z)); + auto actualMaximum = xyz_location(std::max(minimum.m_X, maximum.m_X), std::max(minimum.m_Y, maximum.m_Y), + std::max(minimum.m_Z, maximum.m_Z)); - bool xcheck = position.m_X >= actualMinimum.m_X && position.m_X <= actualMaximum.m_X; - bool ycheck = position.m_Y >= actualMinimum.m_Y && position.m_Y <= actualMaximum.m_Y; - bool zcheck = position.m_Z >= actualMinimum.m_Z && position.m_Z <= actualMaximum.m_Z; + bool xcheck = position.m_X >= actualMinimum.m_X && position.m_X <= actualMaximum.m_X; + bool ycheck = position.m_Y >= actualMinimum.m_Y && position.m_Y <= actualMaximum.m_Y; + bool zcheck = position.m_Z >= actualMinimum.m_Z && position.m_Z <= actualMaximum.m_Z; - return xcheck && ycheck && zcheck; + return xcheck && ycheck && zcheck; } /** * Determines if 'position' is within (inclusive) the axis aligned * box (2 dimensional) formed from the points minimum and maximum. */ -bool IsWithinAxisAlignedBox(const xy_location &position, const xy_location &minimum, const xy_location &maximum) { - auto actualMinimum = xy_location(std::min(minimum.m_X, maximum.m_X), std::min(minimum.m_Y, maximum.m_Y)); - auto actualMaximum = xy_location(std::max(minimum.m_X, maximum.m_X), std::max(minimum.m_Y, maximum.m_Y)); +bool IsWithinAxisAlignedBox(const xy_location &position, const xy_location &minimum, const xy_location &maximum) +{ + auto actualMinimum = xy_location(std::min(minimum.m_X, maximum.m_X), std::min(minimum.m_Y, maximum.m_Y)); + auto actualMaximum = xy_location(std::max(minimum.m_X, maximum.m_X), std::max(minimum.m_Y, maximum.m_Y)); - bool xcheck = position.m_X >= actualMinimum.m_X && position.m_X <= actualMaximum.m_X; - bool ycheck = position.m_Y >= actualMinimum.m_Y && position.m_Y <= actualMaximum.m_Y; + bool xcheck = position.m_X >= actualMinimum.m_X && position.m_X <= actualMaximum.m_X; + bool ycheck = position.m_Y >= actualMinimum.m_Y && position.m_Y <= actualMaximum.m_Y; - return xcheck && ycheck; + return xcheck && ycheck; } /** @@ -229,8 +243,9 @@ bool IsWithinAxisAlignedBox(const xy_location &position, const xy_location &mini * Takes the EQfloat from the xyz_heading and returns * an EQFloat. */ -float GetReciprocalHeading(const xyz_heading& point1) { - return GetReciprocalHeading(point1.m_Heading); +float GetReciprocalHeading(const xyz_heading &point1) +{ + return GetReciprocalHeading(point1.m_Heading); } /** @@ -238,17 +253,18 @@ float GetReciprocalHeading(const xyz_heading& point1) { * current heading. * Takes an EQfloat and returns an EQFloat. */ -float GetReciprocalHeading(const float heading) { - float result = 0; +float GetReciprocalHeading(const float heading) +{ + float result = 0; - // Convert to radians - float h = (heading / 256.0f) * 6.283184f; + // Convert to radians + float h = (heading / 256.0f) * 6.283184f; - // Calculate the reciprocal heading in radians - result = h + 3.141592f; + // Calculate the reciprocal heading in radians + result = h + 3.141592f; - // Convert back to eq heading from radians - result = (result / 6.283184f) * 256.0f; + // Convert back to eq heading from radians + result = (result / 6.283184f) * 256.0f; - return result; -} \ No newline at end of file + return result; +} diff --git a/zone/position.h b/zone/position.h index f422a5247..7c45b9f75 100644 --- a/zone/position.h +++ b/zone/position.h @@ -20,64 +20,74 @@ #include -class xy_location { +class xy_location +{ public: - float m_X; - float m_Y; + float m_X; + float m_Y; - xy_location(float x = 0.0f, float y = 0.0f); + xy_location(float x = 0.0f, float y = 0.0f); - xy_location operator -(const xy_location& rhs) const; - xy_location operator +(const xy_location& rhs) const; + xy_location operator-(const xy_location &rhs) const; + xy_location operator+(const xy_location &rhs) const; }; -class xyz_location { +class xyz_location +{ public: - float m_X; - float m_Y; - float m_Z; + float m_X; + float m_Y; + float m_Z; - static const xyz_location& Origin() {static xyz_location origin; return origin;} + static const xyz_location &Origin() + { + static xyz_location origin; + return origin; + } - xyz_location(float x = 0.0f, float y = 0.0f, float z = 0.0f); - xyz_location(double x, double y, double z); + xyz_location(float x = 0.0f, float y = 0.0f, float z = 0.0f); + xyz_location(double x, double y, double z); - operator xy_location() const; + operator xy_location() const; - xyz_location operator -(const xyz_location& rhs) const; - xyz_location operator +(const xyz_location& rhs) const; - - void ABS_XYZ(); - bool isOrigin() const { return m_X == 0 && m_Y == 0 && m_Z == 0;} + xyz_location operator-(const xyz_location &rhs) const; + xyz_location operator+(const xyz_location &rhs) const; + void ABS_XYZ(); + bool isOrigin() const { return m_X == 0 && m_Y == 0 && m_Z == 0; } }; -class xyz_heading { +class xyz_heading +{ public: - float m_X; - float m_Y; - float m_Z; + float m_X; + float m_Y; + float m_Z; - float m_Heading; + float m_Heading; - static const xyz_heading& Origin() {static xyz_heading origin; return origin;} + static const xyz_heading &Origin() + { + static xyz_heading origin; + return origin; + } - xyz_heading(float x = 0.0f, float y = 0.0f, float z = 0.0f, float heading = 0.0f); - xyz_heading(const xyz_heading& locationDir); - xyz_heading(const xyz_location& locationDir, float heading = 0.0f); - explicit xyz_heading(const xy_location& locationDir, float z, float heading); - explicit xyz_heading(const xy_location locationDir, float z, float heading); + xyz_heading(float x = 0.0f, float y = 0.0f, float z = 0.0f, float heading = 0.0f); + xyz_heading(const xyz_heading &locationDir); + xyz_heading(const xyz_location &locationDir, float heading = 0.0f); + explicit xyz_heading(const xy_location &locationDir, float z, float heading); + explicit xyz_heading(const xy_location locationDir, float z, float heading); - operator xyz_location() const; - operator xy_location() const; + operator xyz_location() const; + operator xy_location() const; - const xyz_heading operator +(const xyz_location& rhs) const; - const xyz_heading operator +(const xy_location& rhs) const; + const xyz_heading operator+(const xyz_location &rhs) const; + const xyz_heading operator+(const xy_location &rhs) const; - const xyz_heading operator -(const xyz_location& rhs) const; + const xyz_heading operator-(const xyz_location &rhs) const; - void ABS_XYZ(); - bool isOrigin() const { return m_X == 0.0f && m_Y == 0.0f && m_Z == 0.0f;} + void ABS_XYZ(); + bool isOrigin() const { return m_X == 0.0f && m_Y == 0.0f && m_Z == 0.0f; } }; std::string to_string(const xyz_heading &position); @@ -87,19 +97,19 @@ std::string to_string(const xy_location &position); bool IsWithinAxisAlignedBox(const xyz_location &position, const xyz_location &minimum, const xyz_location &maximum); bool IsWithinAxisAlignedBox(const xy_location &position, const xy_location &minimum, const xy_location &maximum); -float ComparativeDistance(const xy_location& point1, const xy_location& point2); -float Distance(const xy_location& point1, const xy_location& point2); -float ComparativeDistance(const xyz_location& point1, const xyz_location& point2); -float Distance(const xyz_location& point1, const xyz_location& point2); -float DistanceNoZ(const xyz_location& point1, const xyz_location& point2); -float ComparativeDistanceNoZ(const xyz_location& point1, const xyz_location& point2); +float ComparativeDistance(const xy_location &point1, const xy_location &point2); +float Distance(const xy_location &point1, const xy_location &point2); +float ComparativeDistance(const xyz_location &point1, const xyz_location &point2); +float Distance(const xyz_location &point1, const xyz_location &point2); +float DistanceNoZ(const xyz_location &point1, const xyz_location &point2); +float ComparativeDistanceNoZ(const xyz_location &point1, const xyz_location &point2); -float ComparativeDistance(const xyz_heading& point1, const xyz_heading& point2); -float Distance(const xyz_heading& point1, const xyz_heading& point2); -float DistanceNoZ(const xyz_heading& point1, const xyz_heading& point2); -float ComparativeDistanceNoZ(const xyz_heading& point1, const xyz_heading& point2); +float ComparativeDistance(const xyz_heading &point1, const xyz_heading &point2); +float Distance(const xyz_heading &point1, const xyz_heading &point2); +float DistanceNoZ(const xyz_heading &point1, const xyz_heading &point2); +float ComparativeDistanceNoZ(const xyz_heading &point1, const xyz_heading &point2); -float GetReciprocalHeading(const xyz_heading& point1); +float GetReciprocalHeading(const xyz_heading &point1); float GetReciprocalHeading(const float heading); #endif diff --git a/zone/spell_effects.cpp b/zone/spell_effects.cpp index b05dfeacd..024c938c9 100644 --- a/zone/spell_effects.cpp +++ b/zone/spell_effects.cpp @@ -369,8 +369,8 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial) snprintf(effect_desc, _EDLEN, "Current Mana: %+i", effect_value); #endif SetMana(GetMana() + effect_value); - caster->SetMana(caster->GetMana() + abs(effect_value)); - + caster->SetMana(caster->GetMana() + std::abs(effect_value)); + if (effect_value < 0) TryTriggerOnValueAmount(false, true); #ifdef SPELL_EFFECT_SPAM @@ -3211,7 +3211,7 @@ snare has both of them negative, yet their range should work the same: break; } case 123: // added 2/6/04 - result = zone->random.Int(ubase, abs(max)); + result = zone->random.Int(ubase, std::abs(max)); break; case 124: // check sign diff --git a/zone/spells.cpp b/zone/spells.cpp index ee8723f9b..205029116 100644 --- a/zone/spells.cpp +++ b/zone/spells.cpp @@ -1024,8 +1024,8 @@ void Mob::CastedSpellFinished(uint16 spell_id, uint32 target_id, uint16 slot, // it gets squarely harder to regain concentration if(GetX() != GetSpellX() || GetY() != GetSpellY()) { - d_x = fabs(fabs(GetX()) - fabs(GetSpellX())); - d_y = fabs(fabs(GetY()) - fabs(GetSpellY())); + d_x = std::abs(std::abs(GetX()) - std::abs(GetSpellX())); + d_y = std::abs(std::abs(GetY()) - std::abs(GetSpellY())); if(d_x < 5 && d_y < 5) { //avoid the square root... @@ -5488,7 +5488,7 @@ void Mob::BeamDirectional(uint16 spell_id, int16 resist_adjust) } //# shortest distance from line to target point - float d = abs( (*iter)->GetY() - m * (*iter)->GetX() - b) / sqrt(m * m + 1); + float d = std::abs((*iter)->GetY() - m * (*iter)->GetX() - b) / sqrt(m * m + 1); if (d <= spells[spell_id].aoerange) { diff --git a/zone/waypoints.cpp b/zone/waypoints.cpp index 8f6c75fc9..448ae5696 100644 --- a/zone/waypoints.cpp +++ b/zone/waypoints.cpp @@ -39,12 +39,6 @@ struct wp_distance int index; }; -static inline float ABS(float x) { - if(x < 0) - return(-x); - return(x); -} - void NPC::AI_SetRoambox(float iDist, float iRoamDist, uint32 iDelay, uint32 iMinDelay) { AI_SetRoambox(iDist, GetX()+iRoamDist, GetX()-iRoamDist, GetY()+iRoamDist, GetY()-iRoamDist, iDelay, iMinDelay); } @@ -228,7 +222,7 @@ void NPC::UpdateWaypoint(int wp_index) float newz = zone->zonemap->FindBestZ(dest, nullptr); - if( (newz > -2000) && ABS(newz - dest.z) < RuleR(Map, FixPathingZMaxDeltaWaypoint)) + if ((newz > -2000) && std::abs(newz - dest.z) < RuleR(Map, FixPathingZMaxDeltaWaypoint)) m_CurrentWayPoint.m_Z = newz + 1; } } @@ -507,9 +501,7 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, float speed, b } Log.Out(Logs::Detail, Logs::AI, "Calc Position2 (%.3f, %.3f, %.3f) inWater=%d: We are there.", x, y, z, inWater); return false; - } - else if ((ABS(m_Position.m_X - x) < 0.1) && (ABS(m_Position.m_Y - y) < 0.1)) - { + } else if ((std::abs(m_Position.m_X - x) < 0.1) && (std::abs(m_Position.m_Y - y) < 0.1)) { Log.Out(Logs::Detail, Logs::AI, "Calc Position2 (%.3f, %.3f, %.3f): X/Y difference <0.1, Jumping to target.", x, y, z); if(IsNPC()) { @@ -557,11 +549,13 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, float speed, b Log.Out(Logs::Detail, Logs::AI, "BestZ returned %4.3f at %4.3f, %4.3f, %4.3f", newz,m_Position.m_X,m_Position.m_Y,m_Position.m_Z); - if( (newz > -2000) && ABS(newz - dest.z) < RuleR(Map, FixPathingZMaxDeltaMoving)) // Sanity check. + if ((newz > -2000) && + std::abs(newz - dest.z) < RuleR(Map, FixPathingZMaxDeltaMoving)) // Sanity check. { - if((ABS(x - m_Position.m_X) < 0.5) && (ABS(y - m_Position.m_Y) < 0.5)) - { - if(ABS(z-m_Position.m_Z) <= RuleR(Map, FixPathingZMaxDeltaMoving)) + if ((std::abs(x - m_Position.m_X) < 0.5) && + (std::abs(y - m_Position.m_Y) < 0.5)) { + if (std::abs(z - m_Position.m_Z) <= + RuleR(Map, FixPathingZMaxDeltaMoving)) m_Position.m_Z = z; else m_Position.m_Z = newz + 1; @@ -684,11 +678,11 @@ bool Mob::MakeNewPositionAndSendUpdate(float x, float y, float z, float speed, b Log.Out(Logs::Detail, Logs::AI, "BestZ returned %4.3f at %4.3f, %4.3f, %4.3f", newz,m_Position.m_X,m_Position.m_Y,m_Position.m_Z); - if( (newz > -2000) && ABS(newz - dest.z) < RuleR(Map, FixPathingZMaxDeltaMoving)) // Sanity check. + if ((newz > -2000) && + std::abs(newz - dest.z) < RuleR(Map, FixPathingZMaxDeltaMoving)) // Sanity check. { - if(ABS(x - m_Position.m_X) < 0.5 && ABS(y - m_Position.m_Y) < 0.5) - { - if(ABS(z - m_Position.m_Z) <= RuleR(Map, FixPathingZMaxDeltaMoving)) + if (std::abs(x - m_Position.m_X) < 0.5 && std::abs(y - m_Position.m_Y) < 0.5) { + if (std::abs(z - m_Position.m_Z) <= RuleR(Map, FixPathingZMaxDeltaMoving)) m_Position.m_Z = z; else m_Position.m_Z = newz + 1; @@ -806,11 +800,11 @@ bool Mob::CalculateNewPosition(float x, float y, float z, float speed, bool chec Log.Out(Logs::Detail, Logs::AI, "BestZ returned %4.3f at %4.3f, %4.3f, %4.3f", newz,m_Position.m_X,m_Position.m_Y,m_Position.m_Z); - if( (newz > -2000) && ABS(newz - dest.z) < RuleR(Map, FixPathingZMaxDeltaMoving)) // Sanity check. + if ((newz > -2000) && + std::abs(newz - dest.z) < RuleR(Map, FixPathingZMaxDeltaMoving)) // Sanity check. { - if(ABS(x - m_Position.m_X) < 0.5 && ABS(y - m_Position.m_Y) < 0.5) - { - if(ABS(z - m_Position.m_Z) <= RuleR(Map, FixPathingZMaxDeltaMoving)) + if (std::abs(x - m_Position.m_X) < 0.5 && std::abs(y - m_Position.m_Y) < 0.5) { + if (std::abs(z - m_Position.m_Z) <= RuleR(Map, FixPathingZMaxDeltaMoving)) m_Position.m_Z = z; else m_Position.m_Z = newz + 1; @@ -837,89 +831,90 @@ bool Mob::CalculateNewPosition(float x, float y, float z, float speed, bool chec return true; } -void NPC::AssignWaypoints(int32 grid) { - if(grid == 0) - return; //grid ID 0 not supported +void NPC::AssignWaypoints(int32 grid) +{ + if (grid == 0) + return; // grid ID 0 not supported - if(grid < 0) { + if (grid < 0) { // Allow setting negative grid values for pausing pathing this->CastToNPC()->SetGrid(grid); return; } Waypoints.clear(); - roamer = false; + roamer = false; // Retrieve the wander and pause types for this grid - std::string query = StringFormat("SELECT `type`, `type2` FROM `grid` WHERE `id` = %i AND `zoneid` = %i", grid, zone->GetZoneID()); + std::string query = StringFormat("SELECT `type`, `type2` FROM `grid` WHERE `id` = %i AND `zoneid` = %i", grid, + zone->GetZoneID()); auto results = database.QueryDatabase(query); if (!results.Success()) { - Log.Out(Logs::General, Logs::Error, "MySQL Error while trying to assign grid %u to mob %s: %s", grid, name, results.ErrorMessage().c_str()); - return; + Log.Out(Logs::General, Logs::Error, "MySQL Error while trying to assign grid %u to mob %s: %s", grid, + name, results.ErrorMessage().c_str()); + return; } if (results.RowCount() == 0) - return; + return; auto row = results.begin(); - wandertype = atoi(row[0]); - pausetype = atoi(row[1]); + wandertype = atoi(row[0]); + pausetype = atoi(row[1]); + this->CastToNPC()->SetGrid(grid); // Assign grid number - this->CastToNPC()->SetGrid(grid); // Assign grid number + // Retrieve all waypoints for this grid + query = StringFormat("SELECT `x`,`y`,`z`,`pause`,`heading` " + "FROM grid_entries WHERE `gridid` = %i AND `zoneid` = %i " + "ORDER BY `number`", + grid, zone->GetZoneID()); + results = database.QueryDatabase(query); + if (!results.Success()) { + Log.Out(Logs::General, Logs::Error, + "MySQL Error while trying to assign waypoints from grid %u to mob %s: %s", grid, name, + results.ErrorMessage().c_str()); + return; + } - // Retrieve all waypoints for this grid - query = StringFormat("SELECT `x`,`y`,`z`,`pause`,`heading` " - "FROM grid_entries WHERE `gridid` = %i AND `zoneid` = %i " - "ORDER BY `number`", grid, zone->GetZoneID()); - results = database.QueryDatabase(query); - if (!results.Success()) { - Log.Out(Logs::General, Logs::Error, "MySQL Error while trying to assign waypoints from grid %u to mob %s: %s", grid, name, results.ErrorMessage().c_str()); - return; - } + roamer = true; + max_wp = 0; // Initialize it; will increment it for each waypoint successfully added to the list - roamer = true; - max_wp = 0; // Initialize it; will increment it for each waypoint successfully added to the list + for (auto row = results.begin(); row != results.end(); ++row, ++max_wp) { + wplist newwp; + newwp.index = max_wp; + newwp.x = atof(row[0]); + newwp.y = atof(row[1]); + newwp.z = atof(row[2]); - for (auto row = results.begin(); row != results.end(); ++row, ++max_wp) - { - wplist newwp; - newwp.index = max_wp; - newwp.x = atof(row[0]); - newwp.y = atof(row[1]); - newwp.z = atof(row[2]); + if (zone->HasMap() && RuleB(Map, FixPathingZWhenLoading)) { + auto positon = xyz_location(newwp.x, newwp.y, newwp.z); + if (!RuleB(Watermap, CheckWaypointsInWaterWhenLoading) || !zone->HasWaterMap() || + (zone->HasWaterMap() && !zone->watermap->InWater(positon))) { + Map::Vertex dest(newwp.x, newwp.y, newwp.z); - if(zone->HasMap() && RuleB(Map, FixPathingZWhenLoading) ) - { - auto positon = xyz_location(newwp.x,newwp.y,newwp.z); - if(!RuleB(Watermap, CheckWaypointsInWaterWhenLoading) || !zone->HasWaterMap() || - (zone->HasWaterMap() && !zone->watermap->InWater(positon))) - { - Map::Vertex dest(newwp.x, newwp.y, newwp.z); + float newz = zone->zonemap->FindBestZ(dest, nullptr); - float newz = zone->zonemap->FindBestZ(dest, nullptr); + if ((newz > -2000) && std::abs(newz - dest.z) < RuleR(Map, FixPathingZMaxDeltaLoading)) + newwp.z = newz + 1; + } + } - if( (newz > -2000) && ABS(newz-dest.z) < RuleR(Map, FixPathingZMaxDeltaLoading)) - newwp.z = newz + 1; - } - } + newwp.pause = atoi(row[3]); + newwp.heading = atof(row[4]); + Waypoints.push_back(newwp); + } - newwp.pause = atoi(row[3]); - newwp.heading = atof(row[4]); - Waypoints.push_back(newwp); - } - - if(Waypoints.size() < 2) { + if (Waypoints.size() < 2) { roamer = false; } - UpdateWaypoint(0); - SetWaypointPause(); - - if (wandertype == 1 || wandertype == 2 || wandertype == 5) - CalculateNewWaypoint(); + UpdateWaypoint(0); + SetWaypointPause(); + if (wandertype == 1 || wandertype == 2 || wandertype == 5) + CalculateNewWaypoint(); } void Mob::SendTo(float new_x, float new_y, float new_z) { @@ -948,7 +943,8 @@ void Mob::SendTo(float new_x, float new_y, float new_z) { Log.Out(Logs::Detail, Logs::AI, "BestZ returned %4.3f at %4.3f, %4.3f, %4.3f", newz,m_Position.m_X,m_Position.m_Y,m_Position.m_Z); - if( (newz > -2000) && ABS(newz - dest.z) < RuleR(Map, FixPathingZMaxDeltaSendTo)) // Sanity check. + if ((newz > -2000) && + std::abs(newz - dest.z) < RuleR(Map, FixPathingZMaxDeltaSendTo)) // Sanity check. m_Position.m_Z = newz + 1; } } @@ -979,7 +975,8 @@ void Mob::SendToFixZ(float new_x, float new_y, float new_z) { Log.Out(Logs::Detail, Logs::AI, "BestZ returned %4.3f at %4.3f, %4.3f, %4.3f", newz,m_Position.m_X,m_Position.m_Y,m_Position.m_Z); - if( (newz > -2000) && ABS(newz-dest.z) < RuleR(Map, FixPathingZMaxDeltaSendTo)) // Sanity check. + if ((newz > -2000) && + std::abs(newz - dest.z) < RuleR(Map, FixPathingZMaxDeltaSendTo)) // Sanity check. m_Position.m_Z = newz + 1; } } @@ -1050,21 +1047,22 @@ void ZoneDatabase::AssignGrid(Client *client, const xy_location& location, uint3 // looks like most of the stuff in spawn2 is straight integers // so let's try that first std::string query = StringFormat("SELECT id, x, y FROM spawn2 WHERE zone = '%s' AND x = %i AND y = %i", - zone->GetShortName(), (int)location.m_X, (int)location.m_Y); - auto results = QueryDatabase(query); - if(!results.Success()) { + zone->GetShortName(), (int)location.m_X, (int)location.m_Y); + auto results = QueryDatabase(query); + if (!results.Success()) { return; } // how much it's allowed to be off by -#define _GASSIGN_TOLERANCE 1.0 - if (results.RowCount() == 0) // try a fuzzy match if that didn't find it +#define _GASSIGN_TOLERANCE 1.0 + if (results.RowCount() == 0) // try a fuzzy match if that didn't find it { - query = StringFormat("SELECT id,x,y FROM spawn2 WHERE zone='%s' AND " - "ABS( ABS(x) - ABS(%f) ) < %f AND " - "ABS( ABS(y) - ABS(%f) ) < %f", - zone->GetShortName(), location.m_X, _GASSIGN_TOLERANCE, location.m_Y, _GASSIGN_TOLERANCE); - results = QueryDatabase(query); + query = StringFormat("SELECT id,x,y FROM spawn2 WHERE zone='%s' AND " + "ABS( ABS(x) - ABS(%f) ) < %f AND " + "ABS( ABS(y) - ABS(%f) ) < %f", + zone->GetShortName(), location.m_X, _GASSIGN_TOLERANCE, location.m_Y, + _GASSIGN_TOLERANCE); + results = QueryDatabase(query); if (!results.Success()) { return; } @@ -1073,47 +1071,43 @@ void ZoneDatabase::AssignGrid(Client *client, const xy_location& location, uint3 matches = results.RowCount(); } - if (matches == 0) - { - client->Message(0, "ERROR: Unable to assign grid - can't find it in spawn2"); - return; - } + if (matches == 0) { + client->Message(0, "ERROR: Unable to assign grid - can't find it in spawn2"); + return; + } - if(matches > 1) - { + if (matches > 1) { client->Message(0, "ERROR: Unable to assign grid - multiple spawn2 rows match"); return; } - auto row = results.begin(); + auto row = results.begin(); - spawn2id = atoi(row[0]); - xy_location dbLocation = xy_location(atof(row[1]), atof(row[2])); + spawn2id = atoi(row[0]); + xy_location dbLocation = xy_location(atof(row[1]), atof(row[2])); query = StringFormat("UPDATE spawn2 SET pathgrid = %d WHERE id = %d", grid, spawn2id); results = QueryDatabase(query); - if (!results.Success()) - { + if (!results.Success()) { return; - } + } - if (results.RowsAffected() != 1) - { - client->Message(0, "ERROR: found spawn2 id %d but the update query failed", spawn2id); - return; - } + if (results.RowsAffected() != 1) { + client->Message(0, "ERROR: found spawn2 id %d but the update query failed", spawn2id); + return; + } - if(client) - client->LogSQL(query.c_str()); + if (client) + client->LogSQL(query.c_str()); - if (!fuzzy) - { - client->Message(0, "Grid assign: spawn2 id = %d updated - exact match", spawn2id); - return; - } + if (!fuzzy) { + client->Message(0, "Grid assign: spawn2 id = %d updated - exact match", spawn2id); + return; + } - float difference = sqrtf(pow(fabs(location.m_X - dbLocation.m_X) , 2) + pow(fabs(location.m_Y - dbLocation.m_Y), 2)); - client->Message(0, "Grid assign: spawn2 id = %d updated - fuzzy match: deviation %f", spawn2id, difference); + float difference = + sqrtf(pow(std::abs(location.m_X - dbLocation.m_X), 2) + pow(std::abs(location.m_Y - dbLocation.m_Y), 2)); + client->Message(0, "Grid assign: spawn2 id = %d updated - fuzzy match: deviation %f", spawn2id, difference); } /******************