Some std::abs usage and a bit of clang-formatting

This commit is contained in:
Michael Cook (mackal) 2015-01-22 22:59:52 -05:00
parent 45ca5520fe
commit f702e953e7
12 changed files with 408 additions and 386 deletions

View File

@ -467,8 +467,12 @@ void EntityList::AIYellForHelp(Mob* sender, Mob* attacker) {
//Father Nitwit: make sure we can see them. //Father Nitwit: make sure we can see them.
if(mob->CheckLosFN(sender)) { if(mob->CheckLosFN(sender)) {
#if (EQDEBUG>=5) #if (EQDEBUG>=5)
Log.Out(Logs::General, Logs::None, "AIYellForHelp(\"%s\",\"%s\") %s attacking %s Dist %f Z %f", Log.Out(Logs::General, Logs::None,
sender->GetName(), attacker->GetName(), mob->GetName(), attacker->GetName(), ComparativeDistance(mob->GetPosition(), sender->GetPosition()), fabs(sender->GetZ()+mob->GetZ())); "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 #endif
mob->AddToHateList(attacker, 1, 0, false); mob->AddToHateList(attacker, 1, 0, false);
} }

View File

@ -22,14 +22,11 @@
#include <stdio.h> #include <stdio.h>
// for windows compile // for windows compile
#ifdef _WINDOWS #ifndef _WINDOWS
#define abs64 _abs64
#else
#include <stdarg.h> #include <stdarg.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
#include "../common/unix.h" #include "../common/unix.h"
#define abs64 abs
#endif #endif
extern volatile bool RunLoops; extern volatile bool RunLoops;
@ -1967,7 +1964,7 @@ bool Client::TakeMoneyFromPP(uint64 copper, bool updateclient) {
copperpp -= copper; copperpp -= copper;
if(copperpp <= 0) if(copperpp <= 0)
{ {
copper = abs64(copperpp); copper = std::abs(copperpp);
m_pp.copper = 0; m_pp.copper = 0;
} }
else else
@ -1981,7 +1978,7 @@ bool Client::TakeMoneyFromPP(uint64 copper, bool updateclient) {
silver -= copper; silver -= copper;
if(silver <= 0) if(silver <= 0)
{ {
copper = abs64(silver); copper = std::abs(silver);
m_pp.silver = 0; m_pp.silver = 0;
} }
else else
@ -1998,7 +1995,7 @@ bool Client::TakeMoneyFromPP(uint64 copper, bool updateclient) {
if(gold <= 0) if(gold <= 0)
{ {
copper = abs64(gold); copper = std::abs(gold);
m_pp.gold = 0; m_pp.gold = 0;
} }
else else

View File

@ -10242,7 +10242,9 @@ void command_zopp(Client *c, const Seperator *sep)
ItemInst* FakeItemInst = database.CreateItem(FakeItem, charges); ItemInst* FakeItemInst = database.CreateItem(FakeItem, charges);
c->SendItemPacket(slotid, FakeItemInst, packettype); 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); safe_delete(FakeItemInst);
} }
} }

View File

@ -2869,9 +2869,7 @@ bool Merc::CheckStance(int16 stance) {
//checks of current stance matches stances listed as valid for spell in database //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 //stance = 0 for all stances, stance # for only that stance & -stance# for all but that stance
if(stance == 0 if (stance == 0 || (stance > 0 && stance == GetStance()) || (stance < 0 && std::abs(stance) != GetStance())) {
|| (stance > 0 && stance == GetStance())
|| (stance < 0 && abs(stance) != GetStance())) {
return true; return true;
} }

View File

@ -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 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); //int effect = CalcSpellEffectValue(buffs[i].spellid, spells[buffs[i].spellid].effectid[j], buffs[i].casterlevel);
if (val < 0 && abs(val) > worst_snare) if (val < 0 && std::abs(val) > worst_snare)
worst_snare = abs(val); worst_snare = std::abs(val);
} }
} }
} }
@ -4493,7 +4493,8 @@ void Mob::DoGravityEffect()
if(value > 0) if(value > 0)
away = 1; 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; x_vector = cur_x - caster_x;
y_vector = cur_y - caster_y; 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); 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 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())) { 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) if (angle < 40.0 && heading > 472.0)
angle = heading; angle = heading;
if (fabs(angle - heading) <= 80.0) if (std::abs(angle - heading) <= 80.0)
return true; return true;
return false; return false;
@ -5186,8 +5187,8 @@ float Mob::HeadingAngleToMob(Mob *other)
float this_x = GetX(); float this_x = GetX();
float this_y = GetY(); float this_y = GetY();
float y_diff = fabs(this_y - mob_y); float y_diff = std::abs(this_y - mob_y);
float x_diff = fabs(this_x - mob_x); float x_diff = std::abs(this_x - mob_x);
if (y_diff < 0.0000009999999974752427) if (y_diff < 0.0000009999999974752427)
y_diff = 0.0000009999999974752427; y_diff = 0.0000009999999974752427;

View File

@ -43,7 +43,6 @@ extern Zone *zone;
#else #else
#define MobAI_DEBUG_Spells -1 #define MobAI_DEBUG_Spells -1
#endif #endif
#define ABS(x) ((x)<0?-(x):(x))
//NOTE: do NOT pass in beneficial and detrimental spell types into the same call here! //NOTE: do NOT pass in beneficial and detrimental spell types into the same call here!
bool NPC::AICastSpell(Mob* tar, uint8 iChance, uint16 iSpellTypes) { bool NPC::AICastSpell(Mob* tar, uint8 iChance, uint16 iSpellTypes) {
@ -784,7 +783,8 @@ void Client::AI_Process()
if(AImovement_timer->Check()) { if(AImovement_timer->Check()) {
animation = GetRunspeed() * 21; animation = GetRunspeed() * 21;
// Check if we have reached the last fear point // 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 // Calculate a new point to run to
CalculateNewFearpoint(); CalculateNewFearpoint();
} }
@ -1052,7 +1052,8 @@ void Mob::AI_Process() {
} else { } else {
if(AImovement_timer->Check()) { if(AImovement_timer->Check()) {
// Check if we have reached the last fear point // 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 // Calculate a new point to run to
CalculateNewFearpoint(); CalculateNewFearpoint();
} }
@ -2784,15 +2785,16 @@ uint32 ZoneDatabase::GetMaxNPCSpellsID() {
return atoi(row[0]); return atoi(row[0]);
} }
DBnpcspellseffects_Struct* ZoneDatabase::GetNPCSpellsEffects(uint32 iDBSpellsEffectsID) { DBnpcspellseffects_Struct *ZoneDatabase::GetNPCSpellsEffects(uint32 iDBSpellsEffectsID)
{
if (iDBSpellsEffectsID == 0) if (iDBSpellsEffectsID == 0)
return nullptr; return nullptr;
if (!npc_spellseffects_cache) { if (!npc_spellseffects_cache) {
npc_spellseffects_maxid = GetMaxNPCSpellsEffectsID(); npc_spellseffects_maxid = GetMaxNPCSpellsEffectsID();
npc_spellseffects_cache = new DBnpcspellseffects_Struct*[npc_spellseffects_maxid+1]; npc_spellseffects_cache = new DBnpcspellseffects_Struct *[npc_spellseffects_maxid + 1];
npc_spellseffects_loadtried = new bool[npc_spellseffects_maxid+1]; npc_spellseffects_loadtried = new bool[npc_spellseffects_maxid + 1];
for (uint32 i=0; i<=npc_spellseffects_maxid; i++) { for (uint32 i = 0; i <= npc_spellseffects_maxid; i++) {
npc_spellseffects_cache[i] = 0; npc_spellseffects_cache[i] = 0;
npc_spellseffects_loadtried[i] = false; npc_spellseffects_loadtried[i] = false;
} }
@ -2801,53 +2803,55 @@ DBnpcspellseffects_Struct* ZoneDatabase::GetNPCSpellsEffects(uint32 iDBSpellsEff
if (iDBSpellsEffectsID > npc_spellseffects_maxid) if (iDBSpellsEffectsID > npc_spellseffects_maxid)
return nullptr; 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]; return npc_spellseffects_cache[iDBSpellsEffectsID];
if (npc_spellseffects_loadtried[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); std::string query =
auto results = QueryDatabase(query); StringFormat("SELECT id, parent_list FROM npc_spells_effects WHERE id=%d", iDBSpellsEffectsID);
if (!results.Success()) { auto results = QueryDatabase(query);
return nullptr; if (!results.Success()) {
} return nullptr;
}
if (results.RowCount() != 1) if (results.RowCount() != 1)
return nullptr; return nullptr;
auto row = results.begin(); auto row = results.begin();
uint32 tmpparent_list = atoi(row[1]); uint32 tmpparent_list = atoi(row[1]);
query = StringFormat("SELECT spell_effect_id, minlevel, " query = StringFormat("SELECT spell_effect_id, minlevel, "
"maxlevel,se_base, se_limit, se_max " "maxlevel,se_base, se_limit, se_max "
"FROM npc_spells_effects_entries " "FROM npc_spells_effects_entries "
"WHERE npc_spells_effects_id = %d ORDER BY minlevel", iDBSpellsEffectsID); "WHERE npc_spells_effects_id = %d ORDER BY minlevel",
results = QueryDatabase(query); iDBSpellsEffectsID);
if (!results.Success()) results = QueryDatabase(query);
return nullptr; if (!results.Success())
return nullptr;
uint32 tmpSize = sizeof(DBnpcspellseffects_Struct) + (sizeof(DBnpcspellseffects_entries_Struct) * results.RowCount()); uint32 tmpSize =
npc_spellseffects_cache[iDBSpellsEffectsID] = (DBnpcspellseffects_Struct*) new uchar[tmpSize]; sizeof(DBnpcspellseffects_Struct) + (sizeof(DBnpcspellseffects_entries_Struct) * results.RowCount());
memset(npc_spellseffects_cache[iDBSpellsEffectsID], 0, tmpSize); npc_spellseffects_cache[iDBSpellsEffectsID] = (DBnpcspellseffects_Struct *)new uchar[tmpSize];
npc_spellseffects_cache[iDBSpellsEffectsID]->parent_list = tmpparent_list; memset(npc_spellseffects_cache[iDBSpellsEffectsID], 0, tmpSize);
npc_spellseffects_cache[iDBSpellsEffectsID]->numentries = results.RowCount(); npc_spellseffects_cache[iDBSpellsEffectsID]->parent_list = tmpparent_list;
npc_spellseffects_cache[iDBSpellsEffectsID]->numentries = results.RowCount();
int entryIndex = 0; int entryIndex = 0;
for (row = results.begin(); row != results.end(); ++row, ++entryIndex) for (row = results.begin(); row != results.end(); ++row, ++entryIndex) {
{ int spell_effect_id = atoi(row[0]);
int spell_effect_id = atoi(row[0]); npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].spelleffectid = spell_effect_id;
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].minlevel = atoi(row[1]); npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].maxlevel = atoi(row[2]);
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].base = atoi(row[3]); npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].limit = atoi(row[4]);
npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].limit = atoi(row[4]); npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].max = atoi(row[5]);
npc_spellseffects_cache[iDBSpellsEffectsID]->entries[entryIndex].max = atoi(row[5]); }
}
return npc_spellseffects_cache[iDBSpellsEffectsID]; return npc_spellseffects_cache[iDBSpellsEffectsID];
} }
uint32 ZoneDatabase::GetMaxNPCSpellsEffectsID() { uint32 ZoneDatabase::GetMaxNPCSpellsEffectsID() {

View File

@ -17,7 +17,6 @@
#endif #endif
//#define PATHDEBUG //#define PATHDEBUG
#define ABS(x) ((x)<0?-(x):(x))
extern Zone *zone; extern Zone *zone;
@ -371,10 +370,9 @@ std::deque<int> PathManager::FindRoute(Map::Vertex Start, Map::Vertex End)
for(uint32 i = 0 ; i < Head.PathNodeCount; ++i) for(uint32 i = 0 ; i < Head.PathNodeCount; ++i)
{ {
if((ABS(Start.x - PathNodes[i].v.x) <= CandidateNodeRangeXY) && if ((std::abs(Start.x - PathNodes[i].v.x) <= CandidateNodeRangeXY) &&
(ABS(Start.y - PathNodes[i].v.y) <= CandidateNodeRangeXY) && (std::abs(Start.y - PathNodes[i].v.y) <= CandidateNodeRangeXY) &&
(ABS(Start.z - PathNodes[i].v.z) <= CandidateNodeRangeZ)) (std::abs(Start.z - PathNodes[i].v.z) <= CandidateNodeRangeZ)) {
{
TempNode.id = i; TempNode.id = i;
TempNode.Distance = VertexDistanceNoRoot(Start, PathNodes[i].v); TempNode.Distance = VertexDistanceNoRoot(Start, PathNodes[i].v);
SortedByDistance.push_back(TempNode); SortedByDistance.push_back(TempNode);
@ -410,10 +408,9 @@ std::deque<int> PathManager::FindRoute(Map::Vertex Start, Map::Vertex End)
for(uint32 i = 0 ; i < Head.PathNodeCount; ++i) for(uint32 i = 0 ; i < Head.PathNodeCount; ++i)
{ {
if((ABS(End.x - PathNodes[i].v.x) <= CandidateNodeRangeXY) && if ((std::abs(End.x - PathNodes[i].v.x) <= CandidateNodeRangeXY) &&
(ABS(End.y - PathNodes[i].v.y) <= CandidateNodeRangeXY) && (std::abs(End.y - PathNodes[i].v.y) <= CandidateNodeRangeXY) &&
(ABS(End.z - PathNodes[i].v.z) <= CandidateNodeRangeZ)) (std::abs(End.z - PathNodes[i].v.z) <= CandidateNodeRangeZ)) {
{
TempNode.id = i; TempNode.id = i;
TempNode.Distance = VertexDistanceNoRoot(End, PathNodes[i].v); TempNode.Distance = VertexDistanceNoRoot(End, PathNodes[i].v);
SortedByDistance.push_back(TempNode); 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); Log.Out(Logs::Detail, Logs::None, " Distance between From and To (NoRoot) is %8.3f", Distance);
if((Distance <= RuleR(Pathing, MinDistanceForLOSCheckShort)) if ((Distance <= RuleR(Pathing, MinDistanceForLOSCheckShort)) &&
&& (ABS(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) (std::abs(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) {
{
if(!zone->zonemap->LineIntersectsZone(HeadPosition, To, 1.0f, nullptr)) if(!zone->zonemap->LineIntersectsZone(HeadPosition, To, 1.0f, nullptr))
PathingLOSState = HaveLOS; PathingLOSState = HaveLOS;
else 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); Log.Out(Logs::Detail, Logs::None, " Distance between From and To (NoRoot) is %8.3f", Distance);
if((Distance <= RuleR(Pathing, MinDistanceForLOSCheckShort)) if ((Distance <= RuleR(Pathing, MinDistanceForLOSCheckShort)) &&
&& (ABS(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) (std::abs(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) {
{
if(!zone->zonemap->LineIntersectsZone(HeadPosition, To, 1.0f, nullptr)) if(!zone->zonemap->LineIntersectsZone(HeadPosition, To, 1.0f, nullptr))
PathingLOSState = HaveLOS; PathingLOSState = HaveLOS;
else else
@ -889,9 +884,8 @@ Map::Vertex Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &
{ {
float Distance = VertexDistanceNoRoot(From, To); float Distance = VertexDistanceNoRoot(From, To);
if((Distance <= RuleR(Pathing, MinDistanceForLOSCheckShort)) if ((Distance <= RuleR(Pathing, MinDistanceForLOSCheckShort)) &&
&& (ABS(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) (std::abs(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) {
{
Log.Out(Logs::Detail, Logs::None, " Checking for short LOS at distance %8.3f.", Distance); Log.Out(Logs::Detail, Logs::None, " Checking for short LOS at distance %8.3f.", Distance);
if(!zone->zonemap->LineIntersectsZone(HeadPosition, To, 1.0f, nullptr)) if(!zone->zonemap->LineIntersectsZone(HeadPosition, To, 1.0f, nullptr))
PathingLOSState = HaveLOS; PathingLOSState = HaveLOS;
@ -1041,9 +1035,8 @@ Map::Vertex Mob::UpdatePath(float ToX, float ToY, float ToZ, float Speed, bool &
float Distance = VertexDistanceNoRoot(From, To); float Distance = VertexDistanceNoRoot(From, To);
if((Distance <= RuleR(Pathing, MinDistanceForLOSCheckLong)) if ((Distance <= RuleR(Pathing, MinDistanceForLOSCheckLong)) &&
&& (ABS(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) (std::abs(From.z - To.z) <= RuleR(Pathing, ZDiffThreshold))) {
{
Log.Out(Logs::Detail, Logs::None, " Checking for long LOS at distance %8.3f.", Distance); Log.Out(Logs::Detail, Logs::None, " Checking for long LOS at distance %8.3f.", Distance);
if(!zone->zonemap->LineIntersectsZone(HeadPosition, To, 1.0f, nullptr)) 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) for(uint32 i = 0 ; i < Head.PathNodeCount; ++i)
{ {
if((ABS(Position.x - PathNodes[i].v.x) <= CandidateNodeRangeXY) && if ((std::abs(Position.x - PathNodes[i].v.x) <= CandidateNodeRangeXY) &&
(ABS(Position.y - PathNodes[i].v.y) <= CandidateNodeRangeXY) && (std::abs(Position.y - PathNodes[i].v.y) <= CandidateNodeRangeXY) &&
(ABS(Position.z - PathNodes[i].v.z) <= CandidateNodeRangeZ)) (std::abs(Position.z - PathNodes[i].v.z) <= CandidateNodeRangeZ)) {
{
TempNode.id = i; TempNode.id = i;
TempNode.Distance = VertexDistanceNoRoot(Position, PathNodes[i].v); TempNode.Distance = VertexDistanceNoRoot(Position, PathNodes[i].v);
SortedByDistance.push_back(TempNode); SortedByDistance.push_back(TempNode);
@ -1148,8 +1140,7 @@ bool PathManager::NoHazards(Map::Vertex From, Map::Vertex To)
float NewZ = zone->zonemap->FindBestZ(MidPoint, nullptr); 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", 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); 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); Map::Vertex TestPoint(curx, cury, curz);
float NewZ = zone->zonemap->FindBestZ(TestPoint, nullptr); 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", 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); From.x, From.y, From.z, TestPoint.x, TestPoint.y, TestPoint.z, NewZ, NewZ - From.z);
return false; return false;
@ -1222,14 +1212,17 @@ bool PathManager::NoHazardsAccurate(Map::Vertex From, Map::Vertex To)
} }
else else
{ {
if (ABS(NewZ - best_z2) > RuleR(Pathing, ZDiffThreshold)) if (std::abs(NewZ - best_z2) > RuleR(Pathing, ZDiffThreshold)) {
{ Log.Out(Logs::Detail, Logs::None,
Log.Out(Logs::Detail, Logs::None, " HAZARD DETECTED, water is fairly deep at %8.3f units deep", ABS(NewZ - best_z2)); " HAZARD DETECTED, water is fairly deep at %8.3f units deep",
std::abs(NewZ - best_z2));
return false; return false;
} }
else 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.y = cury;
cur.z = curz; cur.z = curz;
if (ABS(curx - To.x) < step_size) cur.x = To.x; if (std::abs(curx - To.x) < step_size)
if (ABS(cury - To.y) < step_size) cur.y = To.y; cur.x = To.x;
if (ABS(curz - To.z) < step_size) cur.z = To.z; 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); } while (cur.x != To.x || cur.y != To.y || cur.z != To.z);
return true; return true;

View File

@ -4,223 +4,237 @@
#include "../common/string_util.h" #include "../common/string_util.h"
#include <algorithm> #include <algorithm>
xy_location::xy_location(float x, float y) : xy_location::xy_location(float x, float y) : m_X(x), m_Y(y)
m_X(x), {
m_Y(y) {
} }
xy_location xy_location::operator -(const xy_location& rhs) const { 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 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 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 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) : xyz_heading::xyz_heading(float x, float y, float z, float heading) : m_X(x), m_Y(y), m_Z(z), m_Heading(heading)
m_X(x), {
m_Y(y),
m_Z(z),
m_Heading(heading) {
} }
xyz_heading::xyz_heading(const xyz_heading& locationDir) : xyz_heading::xyz_heading(const xyz_heading &locationDir)
m_X(locationDir.m_X), : m_X(locationDir.m_X), m_Y(locationDir.m_Y), m_Z(locationDir.m_Z), m_Heading(locationDir.m_Heading)
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) : xyz_heading::xyz_heading(const xyz_location &locationDir, float heading)
m_X(locationDir.m_X), : m_X(locationDir.m_X), m_Y(locationDir.m_Y), m_Z(locationDir.m_Z), m_Heading(heading)
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) : xyz_heading::xyz_heading(const xy_location &locationDir, float z, float heading)
m_X(locationDir.m_X), : m_X(locationDir.m_X), m_Y(locationDir.m_Y), m_Z(z), m_Heading(heading)
m_Y(locationDir.m_Y), {
m_Z(z),
m_Heading(heading) {
} }
xyz_heading::xyz_heading(const xy_location locationDir, float z, float heading) : xyz_heading::xyz_heading(const xy_location locationDir, float z, float heading)
m_X(locationDir.m_X), : m_X(locationDir.m_X), m_Y(locationDir.m_Y), m_Z(z), m_Heading(heading)
m_Y(locationDir.m_Y), {
m_Z(z),
m_Heading(heading) {
} }
xyz_heading::operator xyz_location() const { xyz_heading::operator xyz_location() const
return xyz_location(m_X,m_Y,m_Z); {
return xyz_location(m_X, m_Y, m_Z);
} }
xyz_heading::operator xy_location() const { xyz_heading::operator xy_location() const
return xy_location(m_X,m_Y); {
return xy_location(m_X, m_Y);
} }
const xyz_heading xyz_heading::operator +(const xyz_location& rhs) const{ 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); {
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{ 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); {
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{ 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); {
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) { void xyz_heading::ABS_XYZ(void)
m_X = abs(m_X); {
m_Y = abs(m_Y); m_X = std::abs(m_X);
m_Z = abs(m_Z); m_Y = std::abs(m_Y);
m_Z = std::abs(m_Z);
} }
xyz_location::xyz_location(float x, float y, float z) : xyz_location::xyz_location(float x, float y, float z) : m_X(x), m_Y(y), m_Z(z)
m_X(x), {
m_Y(y),
m_Z(z) {
} }
xyz_location::xyz_location(double x, double y, double z) : xyz_location::xyz_location(double x, double y, double z)
m_X(static_cast<float>(x)), : m_X(static_cast<float>(x)), m_Y(static_cast<float>(y)), m_Z(static_cast<float>(z))
m_Y(static_cast<float>(y)), {
m_Z(static_cast<float>(z)) {
} }
xyz_location::operator xy_location() const { xyz_location::operator xy_location() const
return xy_location(m_X, m_Y); {
return xy_location(m_X, m_Y);
} }
xyz_location xyz_location::operator -(const xyz_location& rhs) const { 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); {
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 { 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); {
return xyz_location(m_X + rhs.m_X, m_Y + rhs.m_Y, m_Z + rhs.m_Z);
} }
void xyz_location::ABS_XYZ(void) { void xyz_location::ABS_XYZ(void)
m_X = abs(m_X); {
m_Y = abs(m_Y); m_X = std::abs(m_X);
m_Z = abs(m_Z); m_Y = std::abs(m_Y);
m_Z = std::abs(m_Z);
} }
std::string to_string(const xyz_heading &position) { 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); {
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){ std::string to_string(const xyz_location &position)
return StringFormat("(%.3f, %.3f, %.3f)", position.m_X,position.m_Y,position.m_Z); {
return StringFormat("(%.3f, %.3f, %.3f)", position.m_X, position.m_Y, position.m_Z);
} }
std::string to_string(const xy_location &position){ std::string to_string(const xy_location &position)
return StringFormat("(%.3f, %.3f)", position.m_X,position.m_Y); {
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. * 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) { 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; 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. * Produces the distance between the two points on the XY plane.
*/ */
float Distance(const xy_location& point1, const xy_location& point2) { float Distance(const xy_location &point1, const xy_location &point2)
return sqrt(ComparativeDistance(point1, point2)); {
return sqrt(ComparativeDistance(point1, point2));
} }
/** /**
* Produces the non square root'ed distance between the two points. * Produces the non square root'ed distance between the two points.
*/ */
float ComparativeDistance(const xyz_location& point1, const xyz_location& point2) { 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; 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. * Produces the non square root'ed distance between the two points.
*/ */
float ComparativeDistance(const xyz_heading& point1, const xyz_heading& point2) { float ComparativeDistance(const xyz_heading &point1, const xyz_heading &point2)
return ComparativeDistance(static_cast<xyz_location>(point1), static_cast<xyz_location>(point2)); {
return ComparativeDistance(static_cast<xyz_location>(point1), static_cast<xyz_location>(point2));
} }
/** /**
* Produces the distance between the two points. * Produces the distance between the two points.
*/ */
float Distance(const xyz_location& point1, const xyz_location& point2) { float Distance(const xyz_location &point1, const xyz_location &point2)
return sqrt(ComparativeDistance(point1, point2)); {
return sqrt(ComparativeDistance(point1, point2));
} }
/** /**
* Produces the distance between the two points. * Produces the distance between the two points.
*/ */
float Distance(const xyz_heading& point1, const xyz_heading& point2) { float Distance(const xyz_heading &point1, const xyz_heading &point2)
return Distance(static_cast<xyz_location>(point1), static_cast<xyz_location>(point2)); {
return Distance(static_cast<xyz_location>(point1), static_cast<xyz_location>(point2));
} }
/** /**
* Produces the distance between the two points within the XY plane. * Produces the distance between the two points within the XY plane.
*/ */
float DistanceNoZ(const xyz_location& point1, const xyz_location& point2) { float DistanceNoZ(const xyz_location &point1, const xyz_location &point2)
return Distance(static_cast<xy_location>(point1),static_cast<xy_location>(point2)); {
return Distance(static_cast<xy_location>(point1), static_cast<xy_location>(point2));
} }
/** /**
* Produces the distance between the two points within the XY plane. * Produces the distance between the two points within the XY plane.
*/ */
float DistanceNoZ(const xyz_heading& point1, const xyz_heading& point2) { float DistanceNoZ(const xyz_heading &point1, const xyz_heading &point2)
return Distance(static_cast<xy_location>(point1),static_cast<xy_location>(point2)); {
return Distance(static_cast<xy_location>(point1), static_cast<xy_location>(point2));
} }
/** /**
* Produces the non square root'ed distance between the two points within the XY plane. * 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) { float ComparativeDistanceNoZ(const xyz_location &point1, const xyz_location &point2)
return ComparativeDistance(static_cast<xy_location>(point1),static_cast<xy_location>(point2)); {
return ComparativeDistance(static_cast<xy_location>(point1), static_cast<xy_location>(point2));
} }
/** /**
* Produces the non square root'ed distance between the two points within the XY plane. * 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) { float ComparativeDistanceNoZ(const xyz_heading &point1, const xyz_heading &point2)
return ComparativeDistance(static_cast<xy_location>(point1),static_cast<xy_location>(point2)); {
return ComparativeDistance(static_cast<xy_location>(point1), static_cast<xy_location>(point2));
} }
/** /**
* Determines if 'position' is within (inclusive) the axis aligned * Determines if 'position' is within (inclusive) the axis aligned
* box (3 dimensional) formed from the points minimum and maximum. * box (3 dimensional) formed from the points minimum and maximum.
*/ */
bool IsWithinAxisAlignedBox(const xyz_location &position, const xyz_location &minimum, const xyz_location &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)); 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 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 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 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 * Determines if 'position' is within (inclusive) the axis aligned
* box (2 dimensional) formed from the points minimum and maximum. * box (2 dimensional) formed from the points minimum and maximum.
*/ */
bool IsWithinAxisAlignedBox(const xy_location &position, const xy_location &minimum, const xy_location &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)); 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 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 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 * Takes the EQfloat from the xyz_heading and returns
* an EQFloat. * an EQFloat.
*/ */
float GetReciprocalHeading(const xyz_heading& point1) { float GetReciprocalHeading(const xyz_heading &point1)
return GetReciprocalHeading(point1.m_Heading); {
return GetReciprocalHeading(point1.m_Heading);
} }
/** /**
@ -238,17 +253,18 @@ float GetReciprocalHeading(const xyz_heading& point1) {
* current heading. * current heading.
* Takes an EQfloat and returns an EQFloat. * Takes an EQfloat and returns an EQFloat.
*/ */
float GetReciprocalHeading(const float heading) { float GetReciprocalHeading(const float heading)
float result = 0; {
float result = 0;
// Convert to radians // Convert to radians
float h = (heading / 256.0f) * 6.283184f; float h = (heading / 256.0f) * 6.283184f;
// Calculate the reciprocal heading in radians // Calculate the reciprocal heading in radians
result = h + 3.141592f; result = h + 3.141592f;
// Convert back to eq heading from radians // Convert back to eq heading from radians
result = (result / 6.283184f) * 256.0f; result = (result / 6.283184f) * 256.0f;
return result; return result;
} }

View File

@ -20,64 +20,74 @@
#include <string> #include <string>
class xy_location { class xy_location
{
public: public:
float m_X; float m_X;
float m_Y; 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: public:
float m_X; float m_X;
float m_Y; float m_Y;
float m_Z; 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(float x = 0.0f, float y = 0.0f, float z = 0.0f);
xyz_location(double x, double y, double z); 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;
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;}
void ABS_XYZ();
bool isOrigin() const { return m_X == 0 && m_Y == 0 && m_Z == 0; }
}; };
class xyz_heading { class xyz_heading
{
public: public:
float m_X; float m_X;
float m_Y; float m_Y;
float m_Z; 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(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_heading &locationDir);
xyz_heading(const xyz_location& locationDir, float heading = 0.0f); 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);
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 xyz_location() const;
operator xy_location() const; operator xy_location() const;
const xyz_heading operator +(const xyz_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 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(); void ABS_XYZ();
bool isOrigin() const { return m_X == 0.0f && m_Y == 0.0f && m_Z == 0.0f;} bool isOrigin() const { return m_X == 0.0f && m_Y == 0.0f && m_Z == 0.0f; }
}; };
std::string to_string(const xyz_heading &position); 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 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); 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 ComparativeDistance(const xy_location &point1, const xy_location &point2);
float Distance(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 ComparativeDistance(const xyz_location &point1, const xyz_location &point2);
float Distance(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 DistanceNoZ(const xyz_location &point1, const xyz_location &point2);
float ComparativeDistanceNoZ(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 ComparativeDistance(const xyz_heading &point1, const xyz_heading &point2);
float Distance(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 DistanceNoZ(const xyz_heading &point1, const xyz_heading &point2);
float ComparativeDistanceNoZ(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); float GetReciprocalHeading(const float heading);
#endif #endif

View File

@ -369,8 +369,8 @@ bool Mob::SpellEffect(Mob* caster, uint16 spell_id, float partial)
snprintf(effect_desc, _EDLEN, "Current Mana: %+i", effect_value); snprintf(effect_desc, _EDLEN, "Current Mana: %+i", effect_value);
#endif #endif
SetMana(GetMana() + effect_value); SetMana(GetMana() + effect_value);
caster->SetMana(caster->GetMana() + abs(effect_value)); caster->SetMana(caster->GetMana() + std::abs(effect_value));
if (effect_value < 0) if (effect_value < 0)
TryTriggerOnValueAmount(false, true); TryTriggerOnValueAmount(false, true);
#ifdef SPELL_EFFECT_SPAM #ifdef SPELL_EFFECT_SPAM
@ -3211,7 +3211,7 @@ snare has both of them negative, yet their range should work the same:
break; break;
} }
case 123: // added 2/6/04 case 123: // added 2/6/04
result = zone->random.Int(ubase, abs(max)); result = zone->random.Int(ubase, std::abs(max));
break; break;
case 124: // check sign case 124: // check sign

View File

@ -1024,8 +1024,8 @@ void Mob::CastedSpellFinished(uint16 spell_id, uint32 target_id, uint16 slot,
// it gets squarely harder to regain concentration // it gets squarely harder to regain concentration
if(GetX() != GetSpellX() || GetY() != GetSpellY()) if(GetX() != GetSpellX() || GetY() != GetSpellY())
{ {
d_x = fabs(fabs(GetX()) - fabs(GetSpellX())); d_x = std::abs(std::abs(GetX()) - std::abs(GetSpellX()));
d_y = fabs(fabs(GetY()) - fabs(GetSpellY())); d_y = std::abs(std::abs(GetY()) - std::abs(GetSpellY()));
if(d_x < 5 && d_y < 5) if(d_x < 5 && d_y < 5)
{ {
//avoid the square root... //avoid the square root...
@ -5488,7 +5488,7 @@ void Mob::BeamDirectional(uint16 spell_id, int16 resist_adjust)
} }
//# shortest distance from line to target point //# 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) if (d <= spells[spell_id].aoerange)
{ {

View File

@ -39,12 +39,6 @@ struct wp_distance
int index; 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) { 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); 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); 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; 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); Log.Out(Logs::Detail, Logs::AI, "Calc Position2 (%.3f, %.3f, %.3f) inWater=%d: We are there.", x, y, z, inWater);
return false; return false;
} } else if ((std::abs(m_Position.m_X - x) < 0.1) && (std::abs(m_Position.m_Y - y) < 0.1)) {
else if ((ABS(m_Position.m_X - x) < 0.1) && (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); Log.Out(Logs::Detail, Logs::AI, "Calc Position2 (%.3f, %.3f, %.3f): X/Y difference <0.1, Jumping to target.", x, y, z);
if(IsNPC()) { 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); 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 ((std::abs(x - m_Position.m_X) < 0.5) &&
{ (std::abs(y - m_Position.m_Y) < 0.5)) {
if(ABS(z-m_Position.m_Z) <= RuleR(Map, FixPathingZMaxDeltaMoving)) if (std::abs(z - m_Position.m_Z) <=
RuleR(Map, FixPathingZMaxDeltaMoving))
m_Position.m_Z = z; m_Position.m_Z = z;
else else
m_Position.m_Z = newz + 1; 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); 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 (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))
if(ABS(z - m_Position.m_Z) <= RuleR(Map, FixPathingZMaxDeltaMoving))
m_Position.m_Z = z; m_Position.m_Z = z;
else else
m_Position.m_Z = newz + 1; 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); 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 (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))
if(ABS(z - m_Position.m_Z) <= RuleR(Map, FixPathingZMaxDeltaMoving))
m_Position.m_Z = z; m_Position.m_Z = z;
else else
m_Position.m_Z = newz + 1; 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; return true;
} }
void NPC::AssignWaypoints(int32 grid) { void NPC::AssignWaypoints(int32 grid)
if(grid == 0) {
return; //grid ID 0 not supported if (grid == 0)
return; // grid ID 0 not supported
if(grid < 0) { if (grid < 0) {
// Allow setting negative grid values for pausing pathing // Allow setting negative grid values for pausing pathing
this->CastToNPC()->SetGrid(grid); this->CastToNPC()->SetGrid(grid);
return; return;
} }
Waypoints.clear(); Waypoints.clear();
roamer = false; roamer = false;
// Retrieve the wander and pause types for this grid // 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); auto results = database.QueryDatabase(query);
if (!results.Success()) { 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()); Log.Out(Logs::General, Logs::Error, "MySQL Error while trying to assign grid %u to mob %s: %s", grid,
return; name, results.ErrorMessage().c_str());
return;
} }
if (results.RowCount() == 0) if (results.RowCount() == 0)
return; return;
auto row = results.begin(); auto row = results.begin();
wandertype = atoi(row[0]); wandertype = atoi(row[0]);
pausetype = atoi(row[1]); 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 roamer = true;
query = StringFormat("SELECT `x`,`y`,`z`,`pause`,`heading` " max_wp = 0; // Initialize it; will increment it for each waypoint successfully added to the list
"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; for (auto row = results.begin(); row != results.end(); ++row, ++max_wp) {
max_wp = 0; // Initialize it; will increment it for each waypoint successfully added to the list 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) if (zone->HasMap() && RuleB(Map, FixPathingZWhenLoading)) {
{ auto positon = xyz_location(newwp.x, newwp.y, newwp.z);
wplist newwp; if (!RuleB(Watermap, CheckWaypointsInWaterWhenLoading) || !zone->HasWaterMap() ||
newwp.index = max_wp; (zone->HasWaterMap() && !zone->watermap->InWater(positon))) {
newwp.x = atof(row[0]); Map::Vertex dest(newwp.x, newwp.y, newwp.z);
newwp.y = atof(row[1]);
newwp.z = atof(row[2]);
if(zone->HasMap() && RuleB(Map, FixPathingZWhenLoading) ) float newz = zone->zonemap->FindBestZ(dest, nullptr);
{
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); 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.pause = atoi(row[3]);
newwp.z = newz + 1; newwp.heading = atof(row[4]);
} Waypoints.push_back(newwp);
} }
newwp.pause = atoi(row[3]); if (Waypoints.size() < 2) {
newwp.heading = atof(row[4]);
Waypoints.push_back(newwp);
}
if(Waypoints.size() < 2) {
roamer = false; roamer = false;
} }
UpdateWaypoint(0); UpdateWaypoint(0);
SetWaypointPause(); SetWaypointPause();
if (wandertype == 1 || wandertype == 2 || wandertype == 5)
CalculateNewWaypoint();
if (wandertype == 1 || wandertype == 2 || wandertype == 5)
CalculateNewWaypoint();
} }
void Mob::SendTo(float new_x, float new_y, float new_z) { 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); 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; 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); 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; 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 // looks like most of the stuff in spawn2 is straight integers
// so let's try that first // 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", 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); zone->GetShortName(), (int)location.m_X, (int)location.m_Y);
auto results = QueryDatabase(query); auto results = QueryDatabase(query);
if(!results.Success()) { if (!results.Success()) {
return; return;
} }
// how much it's allowed to be off by // how much it's allowed to be off by
#define _GASSIGN_TOLERANCE 1.0 #define _GASSIGN_TOLERANCE 1.0
if (results.RowCount() == 0) // try a fuzzy match if that didn't find it 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 " query = StringFormat("SELECT id,x,y FROM spawn2 WHERE zone='%s' AND "
"ABS( ABS(x) - ABS(%f) ) < %f AND " "ABS( ABS(x) - ABS(%f) ) < %f AND "
"ABS( ABS(y) - ABS(%f) ) < %f", "ABS( ABS(y) - ABS(%f) ) < %f",
zone->GetShortName(), location.m_X, _GASSIGN_TOLERANCE, location.m_Y, _GASSIGN_TOLERANCE); zone->GetShortName(), location.m_X, _GASSIGN_TOLERANCE, location.m_Y,
results = QueryDatabase(query); _GASSIGN_TOLERANCE);
results = QueryDatabase(query);
if (!results.Success()) { if (!results.Success()) {
return; return;
} }
@ -1073,47 +1071,43 @@ void ZoneDatabase::AssignGrid(Client *client, const xy_location& location, uint3
matches = results.RowCount(); matches = results.RowCount();
} }
if (matches == 0) if (matches == 0) {
{ client->Message(0, "ERROR: Unable to assign grid - can't find it in spawn2");
client->Message(0, "ERROR: Unable to assign grid - can't find it in spawn2"); return;
return; }
}
if(matches > 1) if (matches > 1) {
{
client->Message(0, "ERROR: Unable to assign grid - multiple spawn2 rows match"); client->Message(0, "ERROR: Unable to assign grid - multiple spawn2 rows match");
return; return;
} }
auto row = results.begin(); auto row = results.begin();
spawn2id = atoi(row[0]); spawn2id = atoi(row[0]);
xy_location dbLocation = xy_location(atof(row[1]), atof(row[2])); xy_location dbLocation = xy_location(atof(row[1]), atof(row[2]));
query = StringFormat("UPDATE spawn2 SET pathgrid = %d WHERE id = %d", grid, spawn2id); query = StringFormat("UPDATE spawn2 SET pathgrid = %d WHERE id = %d", grid, spawn2id);
results = QueryDatabase(query); results = QueryDatabase(query);
if (!results.Success()) if (!results.Success()) {
{
return; return;
} }
if (results.RowsAffected() != 1) if (results.RowsAffected() != 1) {
{ client->Message(0, "ERROR: found spawn2 id %d but the update query failed", spawn2id);
client->Message(0, "ERROR: found spawn2 id %d but the update query failed", spawn2id); return;
return; }
}
if(client) if (client)
client->LogSQL(query.c_str()); client->LogSQL(query.c_str());
if (!fuzzy) if (!fuzzy) {
{ client->Message(0, "Grid assign: spawn2 id = %d updated - exact match", spawn2id);
client->Message(0, "Grid assign: spawn2 id = %d updated - exact match", spawn2id); return;
return; }
}
float difference = sqrtf(pow(fabs(location.m_X - dbLocation.m_X) , 2) + pow(fabs(location.m_Y - dbLocation.m_Y), 2)); float difference =
client->Message(0, "Grid assign: spawn2 id = %d updated - fuzzy match: deviation %f", spawn2id, 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);
} }
/****************** /******************