diff --git a/zone/aggro.cpp b/zone/aggro.cpp index b2b3881bb..7e8080cc7 100644 --- a/zone/aggro.cpp +++ b/zone/aggro.cpp @@ -88,7 +88,7 @@ void EntityList::DescribeAggro(Client *towho, NPC *from_who, float d, bool verbo if (mob->IsClient()) //also ensures that mob != around continue; - if (mob->DistNoRoot(*from_who) > d2) + if (ComparativeDistance(mob->GetPosition(), from_who->GetPosition()) > d2) continue; if (engaged) { @@ -150,7 +150,8 @@ void NPC::DescribeAggro(Client *towho, Mob *mob, bool verbose) { return; } - float dist2 = mob->DistNoRoot(*this); + float dist2 = ComparativeDistance(mob->GetPosition(), m_Position); + float iAggroRange2 = iAggroRange*iAggroRange; if( dist2 > iAggroRange2 ) { towho->Message(0, "...%s is out of range. %.3f > %.3f ", mob->GetName(), @@ -295,7 +296,7 @@ bool Mob::CheckWillAggro(Mob *mob) { return(false); } - float dist2 = mob->DistNoRoot(*this); + float dist2 = ComparativeDistance(mob->GetPosition(), m_Position); float iAggroRange2 = iAggroRange*iAggroRange; if( dist2 > iAggroRange2 ) { @@ -413,7 +414,7 @@ int EntityList::GetHatedCount(Mob *attacker, Mob *exclude) AggroRange *= AggroRange; - if (mob->DistNoRoot(*attacker) > AggroRange) + if (ComparativeDistance(mob->GetPosition(), attacker->GetPosition()) > AggroRange) continue; Count++; @@ -443,7 +444,7 @@ void EntityList::AIYellForHelp(Mob* sender, Mob* attacker) { // && !mob->IsCorpse() // && mob->IsAIControlled() && mob->GetPrimaryFaction() != 0 - && mob->DistNoRoot(*sender) <= r + && ComparativeDistance(mob->GetPosition(), sender->GetPosition()) <= r && !mob->IsEngaged() && ((!mob->IsPet()) || (mob->IsPet() && mob->GetOwner() && !mob->GetOwner()->IsClient())) // If we're a pet we don't react to any calls for help if our owner is a client @@ -470,7 +471,7 @@ void EntityList::AIYellForHelp(Mob* sender, Mob* attacker) { if(mob->CheckLosFN(sender)) { #if (EQDEBUG>=5) LogFile->write(EQEmuLog::Debug, "AIYellForHelp(\"%s\",\"%s\") %s attacking %s Dist %f Z %f", - sender->GetName(), attacker->GetName(), mob->GetName(), attacker->GetName(), mob->DistNoRoot(*sender), fabs(sender->GetZ()+mob->GetZ())); + sender->GetName(), attacker->GetName(), mob->GetName(), attacker->GetName(), ComparativeDistance(mob->GetPosition(), sender->GetPosition()), fabs(sender->GetZ()+mob->GetZ())); #endif mob->AddToHateList(attacker, 1, 0, false); } @@ -877,7 +878,7 @@ bool Mob::CombatRange(Mob* other) if (size_mod > 10000) size_mod = size_mod / 7; - float _DistNoRoot = DistNoRoot(*other); + float _DistNoRoot = ComparativeDistance(m_Position, other->GetPosition()); if (GetSpecialAbility(NPC_CHASE_DISTANCE)){ diff --git a/zone/beacon.cpp b/zone/beacon.cpp index c3988e866..aa44b2504 100644 --- a/zone/beacon.cpp +++ b/zone/beacon.cpp @@ -35,7 +35,7 @@ class Zone; #include "../common/races.h" #include "beacon.h" #include "entity.h" -#include "mob.h" +#include "mob.h" #ifdef BOTS @@ -68,19 +68,12 @@ Beacon::Beacon(Mob *at_mob, int lifetime) caster_id = 0; if(lifetime) - { remove_timer.Start(); - } -#ifdef SOLAR - entity_list.Message(0, 0, "Beacon being created at %0.2f %0.2f %0.2f heading %0.2f lifetime %d", GetX(), GetY(), GetZ(), GetHeading(), lifetime); -#endif } Beacon::~Beacon() { -#ifdef SOLAR - entity_list.Message(0, 0, "Beacon %d being removed at %0.2f %0.2f %0.2f heading %0.2f", GetID(), GetX(), GetY(), GetZ(), GetHeading()); -#endif + } bool Beacon::Process() diff --git a/zone/bot.cpp b/zone/bot.cpp index e9d708d80..6e6201ee3 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -3354,7 +3354,7 @@ void Bot::AI_Process() { if(GetHasBeenSummoned()) { if(IsBotCaster() || IsBotArcher()) { if (AImovement_timer->Check()) { - if(!GetTarget() || (IsBotCaster() && !IsBotCasterCombatRange(GetTarget())) || (IsBotArcher() && IsArcheryRange(GetTarget())) || (DistNoRootNoZ(m_PreSummonLocation.m_X, m_PreSummonLocation.m_Y) < 10)) { + if(!GetTarget() || (IsBotCaster() && !IsBotCasterCombatRange(GetTarget())) || (IsBotArcher() && IsArcheryRange(GetTarget())) || (ComparativeDistanceNoZ(static_cast(m_Position), m_PreSummonLocation) < 10)) { if(GetTarget()) FaceTarget(GetTarget()); SetHasBeenSummoned(false); @@ -3505,7 +3505,7 @@ void Bot::AI_Process() { if(IsBotCasterCombatRange(GetTarget())) atCombatRange = true; } - else if(DistNoRoot(*GetTarget()) <= meleeDistance) { + else if(ComparativeDistance(m_Position, GetTarget()->GetPosition()) <= meleeDistance) { atCombatRange = true; } @@ -3533,7 +3533,7 @@ void Bot::AI_Process() { return; } } - else if(!IsMoving() && GetClass() != ROGUE && (DistNoRootNoZ(*GetTarget()) < GetTarget()->GetSize())) { + else if(!IsMoving() && GetClass() != ROGUE && (ComparativeDistanceNoZ(m_Position, GetTarget()->GetPosition()) < GetTarget()->GetSize())) { // If we are not a rogue trying to backstab, let's try to adjust our melee range so we don't appear to be bunched up float newX = 0; float newY = 0; @@ -3732,7 +3732,7 @@ void Bot::AI_Process() { Mob* follow = entity_list.GetMob(GetFollowID()); if(follow) { - float dist = DistNoRoot(*follow); + float dist = ComparativeDistance(m_Position, follow->GetPosition()); float speed = follow->GetRunspeed(); if(dist < GetFollowDistance() + 1000) @@ -3865,7 +3865,7 @@ void Bot::PetAIProcess() { return; } } - else if(botPet->DistNoRootNoZ(*botPet->GetTarget()) < botPet->GetTarget()->GetSize()) { + else if(ComparativeDistanceNoZ(botPet->GetPosition(), botPet->GetTarget()->GetPosition()) < botPet->GetTarget()->GetSize()) { // Let's try to adjust our melee range so we don't appear to be bunched up bool isBehindMob = false; bool moveBehindMob = false; @@ -4003,7 +4003,7 @@ void Bot::PetAIProcess() { switch(pStandingPetOrder) { case SPO_Follow: { - float dist = botPet->DistNoRoot(*botPet->GetTarget()); + float dist = ComparativeDistance(botPet->GetPosition(), botPet->GetTarget()->GetPosition()); botPet->SetRunAnimSpeed(0); if(dist > 184) { botPet->CalculateNewPosition2(botPet->GetTarget()->GetX(), botPet->GetTarget()->GetY(), botPet->GetTarget()->GetZ(), botPet->GetTarget()->GetRunspeed()); @@ -10387,7 +10387,7 @@ bool Bot::IsArcheryRange(Mob *target) { range *= range; - float targetDistance = DistNoRootNoZ(*target); + float targetDistance = ComparativeDistanceNoZ(m_Position, target->GetPosition()); float minRuleDistance = RuleI(Combat, MinRangedAttackDist) * RuleI(Combat, MinRangedAttackDist); @@ -10411,7 +10411,7 @@ bool Bot::IsBotCasterCombatRange(Mob *target) { // half the max so the bot doesn't always stop at max range to allow combat movement range *= .5; - float targetDistance = DistNoRootNoZ(*target); + float targetDistance = ComparativeDistanceNoZ(m_Position, target->GetPosition()); if(targetDistance > range) result = false; @@ -15811,7 +15811,7 @@ void EntityList::ShowSpawnWindow(Client* client, int Distance, bool NamedOnly) { for (auto it = mob_list.begin(); it != mob_list.end(); ++it) { curMob = it->second; - if (curMob && curMob->DistNoZ(*client)<=Distance) { + if (curMob && DistanceNoZ(curMob->GetPosition(), client->GetPosition()) <= Distance) { if(curMob->IsTrackable()) { Mob* cur_entity = curMob; int Extras = (cur_entity->IsBot() || cur_entity->IsPet() || cur_entity->IsFamiliar() || cur_entity->IsClient()); diff --git a/zone/botspellsai.cpp b/zone/botspellsai.cpp index a5be7341e..c6c5e920c 100644 --- a/zone/botspellsai.cpp +++ b/zone/botspellsai.cpp @@ -898,7 +898,7 @@ bool Bot::AIDoSpellCast(uint8 i, Mob* tar, int32 mana_cost, uint32* oDontDoAgain if (AIspells[i].type & SpellType_Escape) { dist2 = 0; } else - dist2 = DistNoRoot(*tar); + dist2 = ComparativeDistance(m_Position, tar->GetPosition()); if (((((spells[AIspells[i].spellid].targettype==ST_GroupTeleport && AIspells[i].type==2) || spells[AIspells[i].spellid].targettype==ST_AECaster @@ -1755,7 +1755,7 @@ Mob* Bot::GetFirstIncomingMobToMez(Bot* botCaster, BotSpell botSpell) { for(std::list::iterator itr = npc_list.begin(); itr != npc_list.end(); ++itr) { NPC* npc = *itr; - if(npc->DistNoRootNoZ(*botCaster) <= botCaster->GetActSpellRange(botSpell.SpellId, spells[botSpell.SpellId].range)) { + if(ComparativeDistanceNoZ(npc->GetPosition(), botCaster->GetPosition()) <= botCaster->GetActSpellRange(botSpell.SpellId, spells[botSpell.SpellId].range)) { if(!npc->IsMezzed()) { if(botCaster->HasGroup()) { Group* g = botCaster->GetGroup(); diff --git a/zone/client.cpp b/zone/client.cpp index a988c04a6..f640fa77b 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -40,6 +40,7 @@ extern volatile bool RunLoops; #include "../common/rulesys.h" #include "../common/string_util.h" #include "../common/data_verification.h" +#include "position.h" #include "net.h" #include "worldserver.h" #include "zonedb.h" @@ -993,7 +994,7 @@ void Client::ChannelMessageReceived(uint8 chan_num, uint8 language, uint8 lang_s CheckEmoteHail(GetTarget(), message); - if(DistNoRootNoZ(*GetTarget()) <= 200) { + if(ComparativeDistanceNoZ(m_Position, GetTarget()->GetPosition()) <= 200) { NPC *tar = GetTarget()->CastToNPC(); parse->EventNPC(EVENT_SAY, tar->CastToNPC(), this, message, language); @@ -1005,7 +1006,7 @@ void Client::ChannelMessageReceived(uint8 chan_num, uint8 language, uint8 lang_s } } else { - if (DistNoRootNoZ(*GetTarget()) <= 200) { + if (ComparativeDistanceNoZ(m_Position, GetTarget()->GetPosition()) <= 200) { parse->EventNPC(EVENT_AGGRO_SAY, GetTarget()->CastToNPC(), this, message, language); } } @@ -2539,7 +2540,7 @@ bool Client::BindWound(Mob* bindmob, bool start, bool fail){ } else { - if (!GetFeigned() && (bindmob->DistNoRoot(*this) <= 400)) { + if (!GetFeigned() && (ComparativeDistance(bindmob->GetPosition(), m_Position) <= 400)) { // send bindmob bind done if(!bindmob->IsAIControlled() && bindmob != this ) { @@ -3178,7 +3179,7 @@ void Client::Insight(uint32 t_id) Message(0,"This ability can only be used on NPCs."); return; } - if (Dist(*who) > 200) + if (Distance(static_cast(m_Position), static_cast(who->GetPosition())) > 200) { Message(0,"You must get closer to your target!"); return; @@ -4552,7 +4553,7 @@ void Client::HandleLDoNOpen(NPC *target) return; } - if(DistNoRootNoZ(*target) > RuleI(Adventure, LDoNTrapDistanceUse)) + if(ComparativeDistanceNoZ(m_Position, target->GetPosition()) > RuleI(Adventure, LDoNTrapDistanceUse)) { LogFile->write(EQEmuLog::Debug, "%s tried to open %s but %s was out of range", GetName(), target->GetName(), target->GetName()); @@ -6186,7 +6187,7 @@ void Client::DragCorpses() Mob *corpse = entity_list.GetMob(It->second); if (corpse && corpse->IsPlayerCorpse() && - (DistNoRootNoZ(*corpse) <= RuleR(Character, DragCorpseDistance))) + (ComparativeDistanceNoZ(m_Position, corpse->GetPosition()) <= RuleR(Character, DragCorpseDistance))) continue; if (!corpse || !corpse->IsPlayerCorpse() || diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 5cc3da16d..88fb64e6d 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -2030,7 +2030,7 @@ void Client::Handle_OP_AdventureMerchantPurchase(const EQApplicationPacket *app) return; //you have to be somewhat close to them to be properly using them - if (DistNoRoot(*tmp) > USE_NPC_RANGE2) + if (ComparativeDistance(m_Position, tmp->GetPosition()) > USE_NPC_RANGE2) return; merchantid = tmp->CastToNPC()->MerchantType; @@ -2205,7 +2205,7 @@ void Client::Handle_OP_AdventureMerchantRequest(const EQApplicationPacket *app) return; //you have to be somewhat close to them to be properly using them - if (DistNoRoot(*tmp) > USE_NPC_RANGE2) + if (ComparativeDistance(m_Position, tmp->GetPosition()) > USE_NPC_RANGE2) return; merchantid = tmp->CastToNPC()->MerchantType; @@ -2296,7 +2296,7 @@ void Client::Handle_OP_AdventureMerchantSell(const EQApplicationPacket *app) return; } - if (DistNoRoot(*vendor) > USE_NPC_RANGE2) + if (ComparativeDistance(m_Position, vendor->GetPosition()) > USE_NPC_RANGE2) { Message(13, "Vendor is out of range."); return; @@ -2554,7 +2554,7 @@ void Client::Handle_OP_AltCurrencyMerchantRequest(const EQApplicationPacket *app NPC* tar = entity_list.GetNPCByID(*((uint32*)app->pBuffer)); if (tar) { - if (DistNoRoot(*tar) > USE_NPC_RANGE2) + if (ComparativeDistance(m_Position, tar->GetPosition()) > USE_NPC_RANGE2) return; if (tar->GetClass() != ALT_CURRENCY_MERCHANT) { @@ -2633,7 +2633,7 @@ void Client::Handle_OP_AltCurrencyPurchase(const EQApplicationPacket *app) AltCurrencyPurchaseItem_Struct *purchase = (AltCurrencyPurchaseItem_Struct*)app->pBuffer; NPC* tar = entity_list.GetNPCByID(purchase->merchant_entity_id); if (tar) { - if (DistNoRoot(*tar) > USE_NPC_RANGE2) + if (ComparativeDistance(m_Position, tar->GetPosition())> USE_NPC_RANGE2) return; if (tar->GetClass() != ALT_CURRENCY_MERCHANT) { @@ -2770,7 +2770,7 @@ void Client::Handle_OP_AltCurrencySell(const EQApplicationPacket *app) NPC* tar = entity_list.GetNPCByID(sell->merchant_entity_id); if (tar) { - if (DistNoRoot(*tar) > USE_NPC_RANGE2) + if (ComparativeDistance(m_Position, tar->GetPosition()) > USE_NPC_RANGE2) return; if (tar->GetClass() != ALT_CURRENCY_MERCHANT) { @@ -2867,7 +2867,7 @@ void Client::Handle_OP_AltCurrencySellSelection(const EQApplicationPacket *app) AltCurrencySelectItem_Struct *select = (AltCurrencySelectItem_Struct*)app->pBuffer; NPC* tar = entity_list.GetNPCByID(select->merchant_entity_id); if (tar) { - if (DistNoRoot(*tar) > USE_NPC_RANGE2) + if (ComparativeDistance(m_Position, tar->GetPosition()) > USE_NPC_RANGE2) return; if (tar->GetClass() != ALT_CURRENCY_MERCHANT) { @@ -3025,7 +3025,7 @@ void Client::Handle_OP_Assist(const EQApplicationPacket *app) if (assistee->GetTarget()) { Mob *new_target = assistee->GetTarget(); if (new_target && (GetGM() || - Dist(*assistee) <= TARGETING_RANGE)) { + Distance(m_Position, assistee->GetPosition()) <= TARGETING_RANGE)) { SetAssistExemption(true); eid->entity_id = new_target->GetID(); } @@ -8707,7 +8707,7 @@ void Client::Handle_OP_LDoNDisarmTraps(const EQApplicationPacket *app) { if (HasSkill(SkillDisarmTraps)) { - if (DistNoRootNoZ(*target) > RuleI(Adventure, LDoNTrapDistanceUse)) + if (ComparativeDistanceNoZ(m_Position, target->GetPosition()) > RuleI(Adventure, LDoNTrapDistanceUse)) { Message(13, "%s is too far away.", target->GetCleanName()); return; @@ -8740,7 +8740,7 @@ void Client::Handle_OP_LDoNPickLock(const EQApplicationPacket *app) { if (HasSkill(SkillPickLock)) { - if (DistNoRootNoZ(*target) > RuleI(Adventure, LDoNTrapDistanceUse)) + if (ComparativeDistanceNoZ(m_Position, target->GetPosition()) > RuleI(Adventure, LDoNTrapDistanceUse)) { Message(13, "%s is too far away.", target->GetCleanName()); return; @@ -8759,7 +8759,7 @@ void Client::Handle_OP_LDoNSenseTraps(const EQApplicationPacket *app) { if (HasSkill(SkillSenseTraps)) { - if (DistNoRootNoZ(*target) > RuleI(Adventure, LDoNTrapDistanceUse)) + if (ComparativeDistanceNoZ(m_Position, target->GetPosition()) > RuleI(Adventure, LDoNTrapDistanceUse)) { Message(13, "%s is too far away.", target->GetCleanName()); return; @@ -9182,7 +9182,7 @@ void Client::Handle_OP_LootRequest(const EQApplicationPacket *app) { SetLooting(ent->GetID()); //store the entity we are looting Corpse *ent_corpse = ent->CastToCorpse(); - if (DistNoRootNoZ(ent_corpse->GetX(), ent_corpse->GetY()) > 625) + if (ComparativeDistanceNoZ(m_Position, ent_corpse->GetPosition()) > 625) { Message(13, "Corpse too far away."); Corpse::SendLootReqErrorPacket(this); @@ -9414,7 +9414,7 @@ void Client::Handle_OP_MercenaryDataRequest(const EQApplicationPacket *app) int mercTypeCount = 0; int mercCount = 0; - if (DistNoRoot(*tar) > USE_NPC_RANGE2) + if (ComparativeDistance(m_Position, tar->GetPosition()) > USE_NPC_RANGE2) return; if (tar->GetClass() != MERCERNARY_MASTER) { @@ -9796,7 +9796,7 @@ void Client::Handle_OP_OpenGuildTributeMaster(const EQApplicationPacket *app) StartTribute_Struct* st = (StartTribute_Struct*)app->pBuffer; Mob* tribmast = entity_list.GetMob(st->tribute_master_id); if (tribmast && tribmast->IsNPC() && tribmast->GetClass() == GUILD_TRIBUTE_MASTER - && DistNoRoot(*tribmast) <= USE_NPC_RANGE2) { + && ComparativeDistance(m_Position, tribmast->GetPosition()) <= USE_NPC_RANGE2) { st->response = 1; QueuePacket(app); tribute_master_id = st->tribute_master_id; @@ -9828,7 +9828,7 @@ void Client::Handle_OP_OpenTributeMaster(const EQApplicationPacket *app) StartTribute_Struct* st = (StartTribute_Struct*)app->pBuffer; Mob* tribmast = entity_list.GetMob(st->tribute_master_id); if (tribmast && tribmast->IsNPC() && tribmast->GetClass() == TRIBUTE_MASTER - && DistNoRoot(*tribmast) <= USE_NPC_RANGE2) { + && ComparativeDistance(m_Position, tribmast->GetPosition()) <= USE_NPC_RANGE2) { st->response = 1; QueuePacket(app); tribute_master_id = st->tribute_master_id; @@ -9923,7 +9923,7 @@ void Client::Handle_OP_PetCommands(const EQApplicationPacket *app) } if ((mypet->GetPetType() == petAnimation && GetAA(aaAnimationEmpathy) >= 2) || mypet->GetPetType() != petAnimation) { - if (GetTarget() != this && mypet->DistNoRootNoZ(*GetTarget()) <= (RuleR(Pets, AttackCommandRange)*RuleR(Pets, AttackCommandRange))) { + if (GetTarget() != this && ComparativeDistanceNoZ(mypet->GetPosition(), GetTarget()->GetPosition()) <= (RuleR(Pets, AttackCommandRange)*RuleR(Pets, AttackCommandRange))) { if (mypet->IsHeld()) { if (!mypet->IsFocused()) { mypet->SetHeld(false); //break the hold and guard if we explicitly tell the pet to attack. @@ -9958,7 +9958,7 @@ void Client::Handle_OP_PetCommands(const EQApplicationPacket *app) } if ((mypet->GetPetType() == petAnimation && GetAA(aaAnimationEmpathy) >= 2) || mypet->GetPetType() != petAnimation) { - if (GetTarget() != this && mypet->DistNoRootNoZ(*GetTarget()) <= (RuleR(Pets, AttackCommandRange)*RuleR(Pets, AttackCommandRange))) { + if (GetTarget() != this && ComparativeDistanceNoZ(mypet->GetPosition(), GetTarget()->GetPosition()) <= (RuleR(Pets, AttackCommandRange)*RuleR(Pets, AttackCommandRange))) { zone->AddAggroMob(); mypet->AddToHateList(GetTarget(), 1); Message_StringID(MT_PetResponse, PET_ATTACKING, mypet->GetCleanName(), GetTarget()->GetCleanName()); @@ -12102,7 +12102,7 @@ void Client::Handle_OP_ShopPlayerBuy(const EQApplicationPacket *app) if (mp->quantity < 1) return; //you have to be somewhat close to them to be properly using them - if (DistNoRoot(*tmp) > USE_NPC_RANGE2) + if (ComparativeDistance(m_Position, tmp->GetPosition()) > USE_NPC_RANGE2) return; merchantid = tmp->CastToNPC()->MerchantType; @@ -12351,7 +12351,7 @@ void Client::Handle_OP_ShopPlayerSell(const EQApplicationPacket *app) return; //you have to be somewhat close to them to be properly using them - if (DistNoRoot(*vendor) > USE_NPC_RANGE2) + if (ComparativeDistance(m_Position, vendor->GetPosition()) > USE_NPC_RANGE2) return; uint32 price = 0; @@ -12510,7 +12510,7 @@ void Client::Handle_OP_ShopRequest(const EQApplicationPacket *app) return; //you have to be somewhat close to them to be properly using them - if (DistNoRoot(*tmp) > USE_NPC_RANGE2) + if (ComparativeDistance(m_Position, tmp->GetPosition()) > USE_NPC_RANGE2) return; merchantid = tmp->CastToNPC()->MerchantType; @@ -13006,7 +13006,7 @@ void Client::Handle_OP_TargetCommand(const EQApplicationPacket *app) // For /target, send reject or success packet if (app->GetOpcode() == OP_TargetCommand) { - if (GetTarget() && !GetTarget()->CastToMob()->IsInvisible(this) && (DistNoRoot(*GetTarget()) <= TARGETING_RANGE*TARGETING_RANGE || GetGM())) { + if (GetTarget() && !GetTarget()->CastToMob()->IsInvisible(this) && (ComparativeDistance(m_Position, GetTarget()->GetPosition()) <= TARGETING_RANGE*TARGETING_RANGE || GetGM())) { if (GetTarget()->GetBodyType() == BT_NoTarget2 || GetTarget()->GetBodyType() == BT_Special || GetTarget()->GetBodyType() == BT_NoTarget) { @@ -13095,9 +13095,9 @@ void Client::Handle_OP_TargetCommand(const EQApplicationPacket *app) } else if (GetBindSightTarget()) { - if (GetBindSightTarget()->DistNoRoot(*GetTarget()) > (zone->newzone_data.maxclip*zone->newzone_data.maxclip)) + if (ComparativeDistance(GetBindSightTarget()->GetPosition(), GetTarget()->GetPosition()) > (zone->newzone_data.maxclip*zone->newzone_data.maxclip)) { - if (DistNoRoot(*GetTarget()) > (zone->newzone_data.maxclip*zone->newzone_data.maxclip)) + if (ComparativeDistance(m_Position, GetTarget()->GetPosition()) > (zone->newzone_data.maxclip*zone->newzone_data.maxclip)) { char *hacker_str = nullptr; MakeAnyLenString(&hacker_str, "%s attempting to target something beyond the clip plane of %.2f units," @@ -13111,7 +13111,7 @@ void Client::Handle_OP_TargetCommand(const EQApplicationPacket *app) } } } - else if (DistNoRoot(*GetTarget()) > (zone->newzone_data.maxclip*zone->newzone_data.maxclip)) + else if (ComparativeDistance(m_Position, GetTarget()->GetPosition()) > (zone->newzone_data.maxclip*zone->newzone_data.maxclip)) { char *hacker_str = nullptr; MakeAnyLenString(&hacker_str, "%s attempting to target something beyond the clip plane of %.2f units," @@ -13743,7 +13743,7 @@ void Client::Handle_OP_TributeItem(const EQApplicationPacket *app) Mob* tribmast = entity_list.GetMob(t->tribute_master_id); if (!tribmast || !tribmast->IsNPC() || tribmast->GetClass() != TRIBUTE_MASTER) return; - if (DistNoRoot(*tribmast) > USE_NPC_RANGE2) + if (ComparativeDistance(m_Position, tribmast->GetPosition()) > USE_NPC_RANGE2) return; t->tribute_points = TributeItem(t->slot, t->quantity); @@ -13772,7 +13772,7 @@ void Client::Handle_OP_TributeMoney(const EQApplicationPacket *app) Mob* tribmast = entity_list.GetMob(t->tribute_master_id); if (!tribmast || !tribmast->IsNPC() || tribmast->GetClass() != TRIBUTE_MASTER) return; - if (DistNoRoot(*tribmast) > USE_NPC_RANGE2) + if (ComparativeDistance(m_Position, tribmast->GetPosition()) > USE_NPC_RANGE2) return; t->tribute_points = TributeMoney(t->platinum); diff --git a/zone/client_process.cpp b/zone/client_process.cpp index 542390da9..fc94fd415 100644 --- a/zone/client_process.cpp +++ b/zone/client_process.cpp @@ -1601,7 +1601,7 @@ void Client::OPGMTraining(const EQApplicationPacket *app) return; //you have to be somewhat close to a trainer to be properly using them - if(DistNoRoot(*pTrainer) > USE_NPC_RANGE2) + if(ComparativeDistance(m_Position,pTrainer->GetPosition()) > USE_NPC_RANGE2) return; // if this for-loop acts up again (crashes linux), try enabling the before and after #pragmas @@ -1649,7 +1649,7 @@ void Client::OPGMEndTraining(const EQApplicationPacket *app) return; //you have to be somewhat close to a trainer to be properly using them - if(DistNoRoot(*pTrainer) > USE_NPC_RANGE2) + if(ComparativeDistance(m_Position, pTrainer->GetPosition()) > USE_NPC_RANGE2) return; // goodbye message @@ -1678,7 +1678,7 @@ void Client::OPGMTrainSkill(const EQApplicationPacket *app) return; //you have to be somewhat close to a trainer to be properly using them - if(DistNoRoot(*pTrainer) > USE_NPC_RANGE2) + if(ComparativeDistance(m_Position, pTrainer->GetPosition()) > USE_NPC_RANGE2) return; if (gmskill->skillbank == 0x01) diff --git a/zone/command.cpp b/zone/command.cpp index ea527cbe8..fe479848f 100644 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -4908,7 +4908,7 @@ void command_manaburn(Client *c, const Seperator *sep) c->Message(0, "#Manaburn needs a target."); else { int cur_level=c->GetAA(MANA_BURN);//ManaBurn ID - if (c->DistNoRootNoZ(*target) > 200) + if (ComparativeDistance(c->GetPosition(), target->GetPosition()) > 200) c->Message(0,"You are too far away from your target."); else { if(cur_level == 1) { @@ -10183,7 +10183,7 @@ void command_distance(Client *c, const Seperator *sep) { if(c && c->GetTarget()) { Mob* target = c->GetTarget(); - c->Message(0, "Your target, %s, is %1.1f units from you.", c->GetTarget()->GetName(), c->Dist(*target)); + c->Message(0, "Your target, %s, is %1.1f units from you.", c->GetTarget()->GetName(), Distance(c->GetPosition(), target->GetPosition())); } } @@ -10305,7 +10305,7 @@ void command_disarmtrap(Client *c, const Seperator *sep) { if(c->HasSkill(SkillDisarmTraps)) { - if(c->DistNoRootNoZ(*target) > RuleI(Adventure, LDoNTrapDistanceUse)) + if(ComparativeDistanceNoZ(c->GetPosition(), target->GetPosition()) > RuleI(Adventure, LDoNTrapDistanceUse)) { c->Message(13, "%s is too far away.", target->GetCleanName()); return; @@ -10330,7 +10330,7 @@ void command_sensetrap(Client *c, const Seperator *sep) { if(c->HasSkill(SkillSenseTraps)) { - if(c->DistNoRootNoZ(*target) > RuleI(Adventure, LDoNTrapDistanceUse)) + if(ComparativeDistanceNoZ(c->GetPosition(), target->GetPosition()) > RuleI(Adventure, LDoNTrapDistanceUse)) { c->Message(13, "%s is too far away.", target->GetCleanName()); return; @@ -10355,7 +10355,7 @@ void command_picklock(Client *c, const Seperator *sep) { if(c->HasSkill(SkillPickLock)) { - if(c->DistNoRootNoZ(*target) > RuleI(Adventure, LDoNTrapDistanceUse)) + if(ComparativeDistanceNoZ(c->GetPosition(), target->GetPosition()) > RuleI(Adventure, LDoNTrapDistanceUse)) { c->Message(13, "%s is too far away.", target->GetCleanName()); return; diff --git a/zone/corpse.cpp b/zone/corpse.cpp index e1c519e89..b860f02fe 100644 --- a/zone/corpse.cpp +++ b/zone/corpse.cpp @@ -1328,7 +1328,7 @@ bool Corpse::Summon(Client* client, bool spell, bool CheckDistance) { client->Message(13, "That corpse is locked by a GM."); return false; } - if (!CheckDistance || (DistNoRootNoZ(*client) <= dist2)) { + if (!CheckDistance || (ComparativeDistanceNoZ(m_Position, client->GetPosition()) <= dist2)) { GMMove(client->GetX(), client->GetY(), client->GetZ()); is_corpse_changed = true; } @@ -1343,7 +1343,7 @@ bool Corpse::Summon(Client* client, bool spell, bool CheckDistance) { std::list::iterator itr; for(itr = client->consent_list.begin(); itr != client->consent_list.end(); ++itr) { if(strcmp(this->GetOwnerName(), itr->c_str()) == 0) { - if (!CheckDistance || (DistNoRootNoZ(*client) <= dist2)) { + if (!CheckDistance || (ComparativeDistanceNoZ(m_Position, client->GetPosition()) <= dist2)) { GMMove(client->GetX(), client->GetY(), client->GetZ()); is_corpse_changed = true; } diff --git a/zone/effects.cpp b/zone/effects.cpp index ec463bddf..c43b91168 100644 --- a/zone/effects.cpp +++ b/zone/effects.cpp @@ -26,6 +26,7 @@ #include "string_ids.h" #include "worldserver.h" #include "zonedb.h" +#include "position.h" float Mob::GetActSpellRange(uint16 spell_id, float range, bool IsBard) { @@ -673,7 +674,7 @@ void EntityList::AETaunt(Client* taunter, float range) zdiff *= -1; if (zdiff < 10 && taunter->IsAttackAllowed(them) - && taunter->DistNoRootNoZ(*them) <= range) { + && ComparativeDistanceNoZ(taunter->GetPosition(), them->GetPosition()) <= range) { if (taunter->CheckLosFN(them)) { taunter->Taunt(them, true); } @@ -720,10 +721,10 @@ void EntityList::AESpell(Mob *caster, Mob *center, uint16 spell_id, bool affect_ continue; if (spells[spell_id].targettype == ST_Ring) { - dist_targ = curmob->DistNoRoot(caster->GetTargetRingX(), caster->GetTargetRingY(), caster->GetTargetRingZ()); + dist_targ = ComparativeDistance(static_cast(curmob->GetPosition()), caster->GetTargetRingLocation()); } else if (center) { - dist_targ = center->DistNoRoot(*curmob); + dist_targ = ComparativeDistance(curmob->GetPosition(), center->GetPosition()); } if (dist_targ > dist2) //make sure they are in range @@ -795,7 +796,7 @@ void EntityList::MassGroupBuff(Mob *caster, Mob *center, uint16 spell_id, bool a continue; if (curmob == caster && !affect_caster) //watch for caster too continue; - if (center->DistNoRoot(*curmob) > dist2) //make sure they are in range + if (ComparativeDistance(center->GetPosition(), curmob->GetPosition()) > dist2) //make sure they are in range continue; //Only npcs mgb should hit are client pets... @@ -837,7 +838,7 @@ void EntityList::AEBardPulse(Mob *caster, Mob *center, uint16 spell_id, bool aff continue; if (curmob == caster && !affect_caster) //watch for caster too continue; - if (center->DistNoRoot(*curmob) > dist2) //make sure they are in range + if (ComparativeDistance(center->GetPosition(), curmob->GetPosition()) > dist2) //make sure they are in range continue; if (isnpc && curmob->IsNPC()) { //check npc->npc casting FACTION_VALUE f = curmob->GetReverseFactionCon(caster); @@ -887,7 +888,7 @@ void EntityList::AEAttack(Mob *attacker, float dist, int Hand, int count, bool I && curmob != attacker //this is not needed unless NPCs can use this &&(attacker->IsAttackAllowed(curmob)) && curmob->GetRace() != 216 && curmob->GetRace() != 472 /* dont attack horses */ - && (curmob->DistNoRoot(*attacker) <= dist2) + && (ComparativeDistance(curmob->GetPosition(), attacker->GetPosition()) <= dist2) ) { attacker->Attack(curmob, Hand, false, false, IsFromSpell); hit++; diff --git a/zone/entity.cpp b/zone/entity.cpp index 6eb32b684..6ec20832e 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -1119,7 +1119,7 @@ void EntityList::ChannelMessage(Mob *from, uint8 chan_num, uint8 language, filter = FilterAuctions; // // Only say is limited in range - if (chan_num != 8 || client->Dist(*from) < 200) + if (chan_num != 8 || Distance(client->GetPosition(), from->GetPosition()) < 200) if (filter == FilterNone || client->GetFilter(filter) != FilterHide) client->ChannelMessageSend(from->GetName(), 0, chan_num, language, lang_skill, buffer); ++it; @@ -1442,7 +1442,7 @@ void EntityList::QueueCloseClients(Mob *sender, const EQApplicationPacket *app, || (filter2 == FilterShowGroupOnly && (sender == ent || (ent->GetGroup() && ent->GetGroup()->IsGroupMember(sender)))) || (filter2 == FilterShowSelfOnly && ent == sender)) - && (ent->DistNoRoot(*sender) <= dist2)) { + && (ComparativeDistance(ent->GetPosition(), sender->GetPosition()) <= dist2)) { ent->QueuePacket(app, ackreq, Client::CLIENT_CONNECTED); } } @@ -1558,7 +1558,7 @@ Client *EntityList::GetRandomClient(const xyz_location& location, float Distance for (auto it = client_list.begin();it != client_list.end(); ++it) - if ((it->second != ExcludeClient) && (it->second->DistNoRoot(location.m_X, location.m_Y, location.m_Z) <= Distance)) + if ((it->second != ExcludeClient) && (ComparativeDistance(static_cast(it->second->GetPosition()), location) <= Distance)) ClientsInRange.push_back(it->second); if (ClientsInRange.empty()) @@ -1584,7 +1584,7 @@ Corpse *EntityList::GetCorpseByOwnerWithinRange(Client *client, Mob *center, int auto it = corpse_list.begin(); while (it != corpse_list.end()) { if (it->second->IsPlayerCorpse()) - if (center->DistNoRootNoZ(*it->second) < range && + if (ComparativeDistanceNoZ(center->GetPosition(), it->second->GetPosition()) < range && strcasecmp(it->second->GetOwnerName(), client->GetName()) == 0) return it->second; ++it; @@ -1921,7 +1921,7 @@ void EntityList::MessageClose_StringID(Mob *sender, bool skipsender, float dist, for (auto it = client_list.begin(); it != client_list.end(); ++it) { c = it->second; - if(c && c->DistNoRoot(*sender) <= dist2 && (!skipsender || c != sender)) + if(c && ComparativeDistance(c->GetPosition(), sender->GetPosition()) <= dist2 && (!skipsender || c != sender)) c->Message_StringID(type, string_id, message1, message2, message3, message4, message5, message6, message7, message8, message9); } } @@ -1937,7 +1937,7 @@ void EntityList::FilteredMessageClose_StringID(Mob *sender, bool skipsender, for (auto it = client_list.begin(); it != client_list.end(); ++it) { c = it->second; - if (c && c->DistNoRoot(*sender) <= dist2 && (!skipsender || c != sender)) + if (c && ComparativeDistance(c->GetPosition(), sender->GetPosition()) <= dist2 && (!skipsender || c != sender)) c->FilteredMessage_StringID(sender, type, filter, string_id, message1, message2, message3, message4, message5, message6, message7, message8, message9); @@ -1985,7 +1985,7 @@ void EntityList::MessageClose(Mob* sender, bool skipsender, float dist, uint32 t auto it = client_list.begin(); while (it != client_list.end()) { - if (it->second->DistNoRoot(*sender) <= dist2 && (!skipsender || it->second != sender)) + if (ComparativeDistance(it->second->GetPosition(), sender->GetPosition()) <= dist2 && (!skipsender || it->second != sender)) it->second->Message(type, buffer); ++it; } @@ -2460,7 +2460,7 @@ void EntityList::SendPositionUpdates(Client *client, uint32 cLastUpdate, //bool Grouped = client->HasGroup() && mob->IsClient() && (client->GetGroup() == mob->CastToClient()->GetGroup()); //if (range == 0 || (iterator.GetData() == alwayssend) || Grouped || (mob->DistNoRootNoZ(*client) <= range)) { - if (range == 0 || (it->second == alwayssend) || mob->IsClient() || (mob->DistNoRoot(*client) <= range)) { + if (range == 0 || (it->second == alwayssend) || mob->IsClient() || (ComparativeDistance(mob->GetPosition(), client->GetPosition()) <= range)) { mob->MakeSpawnUpdate(ppu); } if(mob && mob->IsClient() && mob->GetID()>0) { @@ -2942,7 +2942,7 @@ bool EntityList::MakeTrackPacket(Client *client) it->second->IsInvisible(client)) continue; - MobDistance = it->second->DistNoZ(*client); + MobDistance = DistanceNoZ(it->second->GetPosition(), client->GetPosition()); if (MobDistance > distance) continue; @@ -2991,7 +2991,8 @@ void EntityList::MessageGroup(Mob *sender, bool skipclose, uint32 type, const ch auto it = client_list.begin(); while (it != client_list.end()) { - if (it->second != sender && (it->second->Dist(*sender) <= dist2 || it->second->GetGroup() == sender->CastToClient()->GetGroup())) { + if (it->second != sender && + (Distance(it->second->GetPosition(), sender->GetPosition()) <= dist2 || it->second->GetGroup() == sender->CastToClient()->GetGroup())) { it->second->Message(type, buffer); } ++it; @@ -3545,7 +3546,7 @@ void EntityList::RadialSetLogging(Mob *around, bool enabled, bool clients, continue; } - if (around->DistNoRoot(*mob) > range2) + if (ComparativeDistance(around->GetPosition(), mob->GetPosition()) > range2) continue; if (enabled) @@ -3665,7 +3666,7 @@ void EntityList::QuestJournalledSayClose(Mob *sender, Client *QuestInitiator, // Use the old method for all other nearby clients for (auto it = client_list.begin(); it != client_list.end(); ++it) { c = it->second; - if(c && (c != QuestInitiator) && c->DistNoRoot(*sender) <= dist2) + if(c && (c != QuestInitiator) && ComparativeDistance(c->GetPosition(), sender->GetPosition()) <= dist2) c->Message_StringID(10, GENERIC_SAY, mobname, message); } } @@ -3867,7 +3868,7 @@ Mob *EntityList::GetTargetForMez(Mob *caster) continue; } - if (caster->DistNoRoot(*d) > 22250) { //only pick targets within 150 range + if (ComparativeDistance(caster->GetPosition(), d->GetPosition()) > 22250) { //only pick targets within 150 range ++it; continue; } diff --git a/zone/groups.cpp b/zone/groups.cpp index 6adc6735a..1b26d47b4 100644 --- a/zone/groups.cpp +++ b/zone/groups.cpp @@ -758,7 +758,7 @@ void Group::CastGroupSpell(Mob* caster, uint16 spell_id) { } else if(members[z] != nullptr) { - distance = caster->DistNoRoot(*members[z]); + distance = ComparativeDistance(caster->GetPosition(), members[z]->GetPosition()); if(distance <= range2 && distance >= min_range2) { members[z]->CalcSpellPowerDistanceMod(spell_id, distance); caster->SpellOnTarget(spell_id, members[z]); @@ -798,7 +798,7 @@ void Group::GroupBardPulse(Mob* caster, uint16 spell_id) { } else if(members[z] != nullptr) { - distance = caster->DistNoRoot(*members[z]); + distance = ComparativeDistance(caster->GetPosition(), members[z]->GetPosition()); if(distance <= range2) { members[z]->BardPulse(spell_id, caster); #ifdef GROUP_BUFF_PETS @@ -1197,7 +1197,7 @@ void Group::HealGroup(uint32 heal_amt, Mob* caster, float range) for(; gi < MAX_GROUP_MEMBERS; gi++) { if(members[gi]){ - distance = caster->DistNoRoot(*members[gi]); + distance = ComparativeDistance(caster->GetPosition(), members[gi]->GetPosition()); if(distance <= range2){ numMem += 1; } @@ -1208,7 +1208,7 @@ void Group::HealGroup(uint32 heal_amt, Mob* caster, float range) for(gi = 0; gi < MAX_GROUP_MEMBERS; gi++) { if(members[gi]){ - distance = caster->DistNoRoot(*members[gi]); + distance = ComparativeDistance(caster->GetPosition(), members[gi]->GetPosition()); if(distance <= range2){ members[gi]->HealDamage(heal_amt, caster); members[gi]->SendHPUpdate(); @@ -1235,7 +1235,7 @@ void Group::BalanceHP(int32 penalty, float range, Mob* caster, int32 limit) for(; gi < MAX_GROUP_MEMBERS; gi++) { if(members[gi]){ - distance = caster->DistNoRoot(*members[gi]); + distance = ComparativeDistance(caster->GetPosition(), members[gi]->GetPosition()); if(distance <= range2){ dmgtaken_tmp = members[gi]->GetMaxHP() - members[gi]->GetHP(); @@ -1253,7 +1253,7 @@ void Group::BalanceHP(int32 penalty, float range, Mob* caster, int32 limit) for(gi = 0; gi < MAX_GROUP_MEMBERS; gi++) { if(members[gi]){ - distance = caster->DistNoRoot(*members[gi]); + distance = ComparativeDistance(caster->GetPosition(), members[gi]->GetPosition()); if(distance <= range2){ if((members[gi]->GetMaxHP() - dmgtaken) < 1){ //this way the ability will never kill someone members[gi]->SetHP(1); //but it will come darn close @@ -1284,7 +1284,7 @@ void Group::BalanceMana(int32 penalty, float range, Mob* caster, int32 limit) for(; gi < MAX_GROUP_MEMBERS; gi++) { if(members[gi] && (members[gi]->GetMaxMana() > 0)){ - distance = caster->DistNoRoot(*members[gi]); + distance = ComparativeDistance(caster->GetPosition(), members[gi]->GetPosition()); if(distance <= range2){ manataken_tmp = members[gi]->GetMaxMana() - members[gi]->GetMana(); @@ -1306,7 +1306,7 @@ void Group::BalanceMana(int32 penalty, float range, Mob* caster, int32 limit) for(gi = 0; gi < MAX_GROUP_MEMBERS; gi++) { if(members[gi]){ - distance = caster->DistNoRoot(*members[gi]); + distance = ComparativeDistance(caster->GetPosition(), members[gi]->GetPosition()); if(distance <= range2){ if((members[gi]->GetMaxMana() - manataken) < 1){ members[gi]->SetMana(1); diff --git a/zone/hate_list.cpp b/zone/hate_list.cpp index b37b07f59..ad49b00fd 100644 --- a/zone/hate_list.cpp +++ b/zone/hate_list.cpp @@ -158,7 +158,7 @@ Mob* HateList::GetClosestEntOnHateList(Mob *hater) { auto iterator = list.begin(); while (iterator != list.end()) { - this_distance = (*iterator)->entity_on_hatelist->DistNoRootNoZ(*hater); + this_distance = ComparativeDistanceNoZ((*iterator)->entity_on_hatelist->GetPosition(), hater->GetPosition()); if ((*iterator)->entity_on_hatelist != nullptr && this_distance <= close_distance) { close_distance = this_distance; close_entity = (*iterator)->entity_on_hatelist; @@ -592,7 +592,7 @@ void HateList::SpellCast(Mob *caster, uint32 spell_id, float range, Mob* ae_cent struct_HateList *h = (*iterator); if (range > 0) { - dist_targ = center->DistNoRoot(*h->entity_on_hatelist); + dist_targ = ComparativeDistance(center->GetPosition(), h->entity_on_hatelist->GetPosition()); if (dist_targ <= range && dist_targ >= min_range2) { id_list.push_back(h->entity_on_hatelist->GetID()); diff --git a/zone/merc.cpp b/zone/merc.cpp index e50cb04c5..700287ffe 100644 --- a/zone/merc.cpp +++ b/zone/merc.cpp @@ -1318,7 +1318,7 @@ bool Merc::IsMercCasterCombatRange(Mob *target) { // half the max so the merc doesn't always stop at max range to allow combat movement range *= .5; - float targetDistance = DistNoRootNoZ(*target); + float targetDistance = ComparativeDistanceNoZ(m_Position, target->GetPosition()); if(targetDistance > range) result = false; @@ -1480,7 +1480,7 @@ void Merc::AI_Process() { if(IsMercCasterCombatRange(GetTarget())) atCombatRange = true; } - else if(DistNoRoot(*GetTarget()) <= meleeDistance) { + else if(ComparativeDistance(m_Position, GetTarget()->GetPosition()) <= meleeDistance) { atCombatRange = true; } @@ -1513,7 +1513,7 @@ void Merc::AI_Process() { return; } } - else if(!IsMoving() && GetClass() != ROGUE && (DistNoRootNoZ(*GetTarget()) < GetTarget()->GetSize())) + else if(!IsMoving() && GetClass() != ROGUE && (ComparativeDistanceNoZ(m_Position, GetTarget()->GetPosition()) < GetTarget()->GetSize())) { // If we are not a rogue trying to backstab, let's try to adjust our melee range so we don't appear to be bunched up float newX = 0; @@ -1701,7 +1701,7 @@ void Merc::AI_Process() { if(follow) { - float dist = DistNoRoot(*follow); + float dist = ComparativeDistance(m_Position, follow->GetPosition()); float speed = GetRunspeed(); if(dist < GetFollowDistance() + 1000) @@ -1938,7 +1938,7 @@ bool Merc::AIDoSpellCast(uint16 spellid, Mob* tar, int32 mana_cost, uint32* oDon if (mercSpell.type & SpellType_Escape) { dist2 = 0; } else - dist2 = DistNoRoot(*tar); + dist2 = ComparativeDistance(m_Position, tar->GetPosition()); if (((((spells[spellid].targettype==ST_GroupTeleport && mercSpell.type==SpellType_Heal) || spells[spellid].targettype==ST_AECaster @@ -2435,7 +2435,7 @@ void Merc::CheckHateList() { if(MercOwner && MercOwner->GetTarget() && MercOwner->GetTarget()->IsNPC() && (MercOwner->GetTarget()->GetHateAmount(MercOwner) || MercOwner->CastToClient()->AutoAttackEnabled()) && IsAttackAllowed(MercOwner->GetTarget())) { float range = g->HasRole(MercOwner, RolePuller) ? RuleI(Mercs, AggroRadiusPuller) : RuleI(Mercs, AggroRadius); range = range * range; - if(MercOwner->GetTarget()->DistNoRootNoZ(*this) < range) { + if(ComparativeDistanceNoZ(m_Position, MercOwner->GetTarget()->GetPosition()) < range) { AddToHateList(MercOwner->GetTarget(), 1); } } @@ -2445,7 +2445,7 @@ void Merc::CheckHateList() { for(std::list::iterator itr = npc_list.begin(); itr != npc_list.end(); ++itr) { NPC* npc = *itr; - float dist = npc->DistNoRootNoZ(*this); + float dist = ComparativeDistanceNoZ(m_Position, npc->GetPosition()); int radius = RuleI(Mercs, AggroRadius); radius *= radius; if(dist <= radius) { @@ -2457,7 +2457,7 @@ void Merc::CheckHateList() { if(!hate_list.IsEntOnHateList(npc)) { float range = g->HasRole(groupMember, RolePuller) ? RuleI(Mercs, AggroRadiusPuller) : RuleI(Mercs, AggroRadius); range *= range; - if(npc->DistNoRootNoZ(*this) < range) { + if(ComparativeDistanceNoZ(m_Position, npc->GetPosition()) < range) { hate_list.AddEntToHateList(npc, 1); } } @@ -2499,7 +2499,7 @@ bool Merc::CheckAENuke(Merc* caster, Mob* tar, uint16 spell_id, uint8 &numTarget for(std::list::iterator itr = npc_list.begin(); itr != npc_list.end(); ++itr) { NPC* npc = *itr; - if(npc->DistNoRootNoZ(*tar) <= spells[spell_id].aoerange * spells[spell_id].aoerange) { + if(ComparativeDistanceNoZ(npc->GetPosition(), tar->GetPosition()) <= spells[spell_id].aoerange * spells[spell_id].aoerange) { if(!npc->IsMezzed()) { numTargets++; } @@ -4098,7 +4098,7 @@ bool Merc::CheckAETaunt() { for(std::list::iterator itr = npc_list.begin(); itr != npc_list.end(); ++itr) { NPC* npc = *itr; - float dist = npc->DistNoRootNoZ(*this); + float dist = ComparativeDistanceNoZ(m_Position, npc->GetPosition()); int range = GetActSpellRange(mercSpell.spellid, spells[mercSpell.spellid].range); range *= range; @@ -4201,7 +4201,7 @@ bool Merc::CheckConfidence() { AggroRange = AggroRange * AggroRange; - if(mob->DistNoRoot(*this) > AggroRange) continue; + if(ComparativeDistance(m_Position, mob->GetPosition()) > AggroRange) continue; CurrentCon = this->GetLevelCon(mob->GetLevel()); switch(CurrentCon) { @@ -5150,7 +5150,7 @@ bool Client::CheckCanHireMerc(Mob* merchant, uint32 template_id) { } //check for merchant too far away - if(DistNoRoot(*merchant) > USE_NPC_RANGE2) { + if(ComparativeDistance(m_Position, merchant->GetPosition()) > USE_NPC_RANGE2) { SendMercResponsePackets(18); return false; } diff --git a/zone/mob.cpp b/zone/mob.cpp index d1e6ac7c5..b6644a4aa 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -2267,59 +2267,7 @@ bool Mob::CanThisClassBlock(void) const return(CastToClient()->HasSkill(SkillBlock)); } } - -float Mob::Dist(const Mob &other) const { - float xDiff = other.m_Position.m_X - m_Position.m_X; - float yDiff = other.m_Position.m_Y - m_Position.m_Y; - float zDiff = other.m_Position.m_Z - m_Position.m_Z; - - return sqrtf( (xDiff * xDiff) - + (yDiff * yDiff) - + (zDiff * zDiff) ); -} - -float Mob::DistNoZ(const Mob &other) const { - float xDiff = other.m_Position.m_X - m_Position.m_X; - float yDiff = other.m_Position.m_Y - m_Position.m_Y; - - return sqrtf( (xDiff * xDiff) - + (yDiff * yDiff) ); -} - -float Mob::DistNoRoot(const Mob &other) const { - float xDiff = other.m_Position.m_X - m_Position.m_X; - float yDiff = other.m_Position.m_Y - m_Position.m_Y; - float zDiff = other.m_Position.m_Z - m_Position.m_Z; - - return ( (xDiff * xDiff) - + (yDiff * yDiff) - + (zDiff * zDiff) ); -} - -float Mob::DistNoRoot(float x, float y, float z) const { - float xDiff = x - m_Position.m_X; - float yDiff = y - m_Position.m_Y; - float zDiff = z - m_Position.m_Z; - - return ( (xDiff * xDiff) - + (yDiff * yDiff) - + (zDiff * zDiff) ); -} - -float Mob::DistNoRootNoZ(float x, float y) const { - float xDiff = x - m_Position.m_X; - float yDiff = y - m_Position.m_Y; - - return ( (xDiff * xDiff) + (yDiff * yDiff) ); -} - -float Mob::DistNoRootNoZ(const Mob &other) const { - float xDiff = other.m_Position.m_X - m_Position.m_X; - float yDiff = other.m_Position.m_Y - m_Position.m_Y; - - return ( (xDiff * xDiff) + (yDiff * yDiff) ); -} - +/* float Mob::GetReciprocalHeading(Mob* target) { float Result = 0; @@ -2336,7 +2284,7 @@ float Mob::GetReciprocalHeading(Mob* target) { return Result; } - +*/ bool Mob::PlotPositionAroundTarget(Mob* target, float &x_dest, float &y_dest, float &z_dest, bool lookForAftArc) { bool Result = false; @@ -2344,7 +2292,7 @@ bool Mob::PlotPositionAroundTarget(Mob* target, float &x_dest, float &y_dest, fl float look_heading = 0; if(lookForAftArc) - look_heading = GetReciprocalHeading(target); + look_heading = GetReciprocalHeading(target->GetPosition()); else look_heading = target->GetHeading(); diff --git a/zone/mob.h b/zone/mob.h index 6e304c34a..09c9bf56f 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -294,6 +294,7 @@ public: inline virtual uint32 GetNimbusEffect2() const { return nimbus_effect2; } inline virtual uint32 GetNimbusEffect3() const { return nimbus_effect3; } void RemoveNimbusEffect(int effectid); + inline const xyz_location& GetTargetRingLocation() const { return m_TargetRing; } inline float GetTargetRingX() const { return m_TargetRing.m_X; } inline float GetTargetRingY() const { return m_TargetRing.m_Y; } inline float GetTargetRingZ() const { return m_TargetRing.m_Z; } @@ -510,13 +511,6 @@ public: void ShowStats(Client* client); void ShowBuffs(Client* client); void ShowBuffList(Client* client); - float Dist(const Mob &) const; - float DistNoZ(const Mob &) const; - float DistNoRoot(const Mob &) const; - float DistNoRoot(float x, float y, float z) const; - float DistNoRootNoZ(float x, float y) const; - float DistNoRootNoZ(const Mob &) const; - static float GetReciprocalHeading(Mob* target); bool PlotPositionAroundTarget(Mob* target, float &x_dest, float &y_dest, float &z_dest, bool lookForAftArc = true); diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp index f6310801d..3902ee072 100644 --- a/zone/mob_ai.cpp +++ b/zone/mob_ai.cpp @@ -67,7 +67,7 @@ bool NPC::AICastSpell(Mob* tar, uint8 iChance, uint16 iSpellTypes) { dist2 = 0; //DistNoRoot(*this); //WTF was up with this... } else - dist2 = DistNoRoot(*tar); + dist2 = ComparativeDistance(m_Position, tar->GetPosition()); bool checked_los = false; //we do not check LOS until we are absolutely sure we need to, and we only do it once. @@ -401,7 +401,7 @@ bool EntityList::AICheckCloseBeneficialSpells(NPC* caster, uint8 iChance, float if (t1 > iRange || t2 > iRange || t3 > iRange - || mob->DistNoRoot(*caster) > iRange2 + || ComparativeDistance(mob->GetPosition(), caster->GetPosition()) > iRange2 //this call should seem backwards: || !mob->CheckLosFN(caster) || mob->GetReverseFactionCon(caster) >= FACTION_KINDLY @@ -622,7 +622,7 @@ void Client::AI_SpellCast() if(!targ) return; - float dist = DistNoRootNoZ(*targ); + float dist = ComparativeDistanceNoZ(m_Position, targ->GetPosition()); std::vector valid_spells; std::vector slots; @@ -997,7 +997,7 @@ void Client::AI_Process() if(owner == nullptr) return; - float dist = DistNoRoot(*owner); + float dist = ComparativeDistance(m_Position, owner->GetPosition()); if (dist >= 100) { float speed = dist >= 225 ? GetRunspeed() : GetWalkspeed(); @@ -1129,14 +1129,14 @@ void Mob::AI_Process() { float tether_range = static_cast(GetSpecialAbilityParam(TETHER, 0)); tether_range = tether_range > 0.0f ? tether_range * tether_range : pAggroRange * pAggroRange; - if(DistNoRootNoZ(npcSpawnPoint.m_X, npcSpawnPoint.m_Y) > tether_range) { + if(ComparativeDistanceNoZ(m_Position, npcSpawnPoint) > tether_range) { GMMove(npcSpawnPoint.m_X, npcSpawnPoint.m_Y, npcSpawnPoint.m_Z, npcSpawnPoint.m_Heading); } } else if(GetSpecialAbility(LEASH)) { float leash_range = static_cast(GetSpecialAbilityParam(LEASH, 0)); leash_range = leash_range > 0.0f ? leash_range * leash_range : pAggroRange * pAggroRange; - if(DistNoRootNoZ(npcSpawnPoint.m_X, npcSpawnPoint.m_Y) > leash_range) { + if(ComparativeDistanceNoZ(m_Position, npcSpawnPoint) > leash_range) { GMMove(npcSpawnPoint.m_X, npcSpawnPoint.m_Y, npcSpawnPoint.m_Z, npcSpawnPoint.m_Heading); SetHP(GetMaxHP()); BuffFadeAll(); @@ -1492,7 +1492,7 @@ void Mob::AI_Process() { //if(owner->IsClient()) // printf("Pet start pos: (%f, %f, %f)\n", GetX(), GetY(), GetZ()); - float dist = DistNoRoot(*owner); + float dist = ComparativeDistance(m_Position, owner->GetPosition()); if (dist >= 400) { float speed = GetWalkspeed(); @@ -1547,7 +1547,7 @@ void Mob::AI_Process() { if (!follow) SetFollowID(0); else { - float dist2 = DistNoRoot(*follow); + float dist2 = ComparativeDistance(m_Position, follow->GetPosition()); int followdist = GetFollowDistance(); if (dist2 >= followdist) // Default follow distance is 100 @@ -1812,7 +1812,7 @@ void NPC::AI_DoMovement() { ClearFeignMemory(); moved=false; SetMoving(false); - if (GetTarget() == nullptr || DistNoRoot(*GetTarget()) >= 5*5 ) + if (GetTarget() == nullptr || ComparativeDistance(m_Position, GetTarget()->GetPosition()) >= 5*5 ) { SetHeading(m_GuardPoint.m_Heading); } else { diff --git a/zone/perl_client.cpp b/zone/perl_client.cpp index df0a48e69..46b3b761a 100644 --- a/zone/perl_client.cpp +++ b/zone/perl_client.cpp @@ -5963,7 +5963,7 @@ XS(XS_Client_SilentMessage) Perl_croak(aTHX_ "THIS is NULL, avoiding crash."); if(THIS->GetTarget() != NULL){ if(THIS->GetTarget()->IsNPC()){ - if (THIS->DistNoRootNoZ(*THIS->GetTarget()) <= 200) { + if (ComparativeDistanceNoZ(THIS->GetPosition(), THIS->GetTarget()->GetPosition()) <= 200) { if(THIS->GetTarget()->CastToNPC()->IsMoving() && !THIS->GetTarget()->CastToNPC()->IsOnHatelist(THIS->GetTarget())) THIS->GetTarget()->CastToNPC()->PauseWandering(RuleI(NPC, SayPauseTimeInSec)); THIS->ChannelMessageReceived(8, 0, 100, SvPV_nolen(ST(1))); diff --git a/zone/position.cpp b/zone/position.cpp index 56e7da563..a7b32cb62 100644 --- a/zone/position.cpp +++ b/zone/position.cpp @@ -148,6 +148,13 @@ float ComparativeDistance(const xyz_location& point1, const xyz_location& 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) { + ComparativeDistance(static_cast(point1), static_cast(point2)); +} + /** * Produces the distance between the two points. */ @@ -155,6 +162,13 @@ 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) { + Distance(static_cast(point1), static_cast(point2)); +} + /** * Produces the distance between the two points within the XY plane. */ @@ -162,6 +176,13 @@ 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)); +} + /** * Produces the non square root'ed distance between the two points within the XY plane. */ @@ -169,6 +190,13 @@ float ComparativeDistanceNoZ(const xyz_location& point1, const xyz_location& poi 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)); +} + /** * Determines if 'position' is within (inclusive) the axis aligned * box (3 dimensional) formed from the points minimum and maximum. @@ -197,3 +225,33 @@ bool IsWithinAxisAlignedBox(const xy_location &position, const xy_location &mini return xcheck && ycheck; } + +/** +* Gives the heading directly 180 degrees from the +* current heading. +* Takes the EQfloat from the xyz_heading and returns +* an EQFloat. +*/ +float GetReciprocalHeading(const xyz_heading& point1) { + return GetReciprocalHeading(point1.m_Heading); +} + +/** +* Gives the heading directly 180 degrees from the +* current heading. +* Takes an EQfloat and returns an EQFloat. +*/ +float GetReciprocalHeading(const float heading) { + float result = 0; + + // Convert to radians + float h = (heading / 256.0f) * 6.283184f; + + // Calculate the reciprocal heading in radians + result = h + 3.141592f; + + // Convert back to eq heading from radians + result = (result / 6.283184f) * 256.0f; + + return result; +} \ No newline at end of file diff --git a/zone/position.h b/zone/position.h index fd66ede5f..f422a5247 100644 --- a/zone/position.h +++ b/zone/position.h @@ -94,4 +94,12 @@ 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 GetReciprocalHeading(const xyz_heading& point1); +float GetReciprocalHeading(const float heading); + #endif diff --git a/zone/raids.cpp b/zone/raids.cpp index b01d169fd..3bed5af2e 100644 --- a/zone/raids.cpp +++ b/zone/raids.cpp @@ -489,7 +489,7 @@ void Raid::CastGroupSpell(Mob* caster, uint16 spellid, uint32 gid) else if(members[x].member != nullptr) { if(members[x].GroupNumber == gid){ - distance = caster->DistNoRoot(*members[x].member); + distance = ComparativeDistance(caster->GetPosition(), members[x].member->GetPosition()); if(distance <= range2){ caster->SpellOnTarget(spellid, members[x].member); #ifdef GROUP_BUFF_PETS @@ -537,7 +537,7 @@ void Raid::HealGroup(uint32 heal_amt, Mob* caster, uint32 gid, float range) if(members[gi].member){ if(members[gi].GroupNumber == gid) { - distance = caster->DistNoRoot(*members[gi].member); + distance = ComparativeDistance(caster->GetPosition(), members[gi].member->GetPosition()); if(distance <= range2){ numMem += 1; } @@ -551,7 +551,7 @@ void Raid::HealGroup(uint32 heal_amt, Mob* caster, uint32 gid, float range) if(members[gi].member){ if(members[gi].GroupNumber == gid) { - distance = caster->DistNoRoot(*members[gi].member); + distance = ComparativeDistance(caster->GetPosition(), members[gi].member->GetPosition()); if(distance <= range2){ members[gi].member->SetHP(members[gi].member->GetHP() + heal_amt); members[gi].member->SendHPUpdate(); @@ -581,7 +581,7 @@ void Raid::BalanceHP(int32 penalty, uint32 gid, float range, Mob* caster, int32 if(members[gi].member){ if(members[gi].GroupNumber == gid) { - distance = caster->DistNoRoot(*members[gi].member); + distance = ComparativeDistance(caster->GetPosition(), members[gi].member->GetPosition()); if(distance <= range2){ dmgtaken_tmp = members[gi].member->GetMaxHP() - members[gi].member->GetHP(); @@ -602,7 +602,7 @@ void Raid::BalanceHP(int32 penalty, uint32 gid, float range, Mob* caster, int32 if(members[gi].member){ if(members[gi].GroupNumber == gid) { - distance = caster->DistNoRoot(*members[gi].member); + distance = ComparativeDistance(caster->GetPosition(), members[gi].member->GetPosition()); if(distance <= range2){ if((members[gi].member->GetMaxHP() - dmgtaken) < 1){//this way the ability will never kill someone members[gi].member->SetHP(1); //but it will come darn close @@ -637,7 +637,7 @@ void Raid::BalanceMana(int32 penalty, uint32 gid, float range, Mob* caster, int3 if(members[gi].GroupNumber == gid) { if (members[gi].member->GetMaxMana() > 0) { - distance = caster->DistNoRoot(*members[gi].member); + distance = ComparativeDistance(caster->GetPosition(), members[gi].member->GetPosition()); if(distance <= range2){ manataken_tmp = members[gi].member->GetMaxMana() - members[gi].member->GetMana(); @@ -660,7 +660,7 @@ void Raid::BalanceMana(int32 penalty, uint32 gid, float range, Mob* caster, int3 if(members[gi].member){ if(members[gi].GroupNumber == gid) { - distance = caster->DistNoRoot(*members[gi].member); + distance = ComparativeDistance(caster->GetPosition(), members[gi].member->GetPosition()); if(distance <= range2){ if((members[gi].member->GetMaxMana() - manataken) < 1){ members[gi].member->SetMana(1); @@ -791,7 +791,7 @@ void Raid::GroupBardPulse(Mob* caster, uint16 spellid, uint32 gid){ else if(members[z].member != nullptr) { if(members[z].GroupNumber == gid){ - distance = caster->DistNoRoot(*members[z].member); + distance = ComparativeDistance(caster->GetPosition(), members[z].member->GetPosition()); if(distance <= range2) { members[z].member->BardPulse(spellid, caster); #ifdef GROUP_BUFF_PETS diff --git a/zone/special_attacks.cpp b/zone/special_attacks.cpp index 5255ff1f6..b3014c7d9 100644 --- a/zone/special_attacks.cpp +++ b/zone/special_attacks.cpp @@ -769,7 +769,7 @@ void Client::RangedAttack(Mob* other, bool CanDoubleAttack) { float range = RangeItem->Range + AmmoItem->Range + GetRangeDistTargetSizeMod(GetTarget()); mlog(COMBAT__RANGED, "Calculated bow range to be %.1f", range); range *= range; - float dist = DistNoRoot(*other); + float dist = ComparativeDistance(m_Position, other->GetPosition()); if(dist > range) { mlog(COMBAT__RANGED, "Ranged attack out of range... client should catch this. (%f > %f).\n", dist, range); Message_StringID(13,TARGET_OUT_OF_RANGE);//Client enforces range and sends the message, this is a backup just incase. @@ -1219,9 +1219,9 @@ void NPC::RangedAttack(Mob* other) min_range = static_cast(sa_min_range); max_range *= max_range; - if(DistNoRoot(*other) > max_range) + if(ComparativeDistance(m_Position, other->GetPosition()) > max_range) return; - else if(DistNoRoot(*other) < (min_range * min_range)) + else if(ComparativeDistance(m_Position, other->GetPosition()) < (min_range * min_range)) return; if(!other || !IsAttackAllowed(other) || @@ -1408,7 +1408,7 @@ void Client::ThrowingAttack(Mob* other, bool CanDoubleAttack) { //old was 51 float range = item->Range + GetRangeDistTargetSizeMod(other); mlog(COMBAT__RANGED, "Calculated bow range to be %.1f", range); range *= range; - float dist = DistNoRoot(*other); + float dist = ComparativeDistance(m_Position, other->GetPosition()); if(dist > range) { mlog(COMBAT__RANGED, "Throwing attack out of range... client should catch this. (%f > %f).\n", dist, range); Message_StringID(13,TARGET_OUT_OF_RANGE);//Client enforces range and sends the message, this is a backup just incase. diff --git a/zone/spells.cpp b/zone/spells.cpp index a794d58a4..96a1f87dd 100644 --- a/zone/spells.cpp +++ b/zone/spells.cpp @@ -2002,7 +2002,7 @@ bool Mob::SpellFinished(uint16 spell_id, Mob *spell_target, uint16 slot, uint16 } if(spell_target != nullptr && spell_target != this) { //casting a spell on somebody but ourself, make sure they are in range - float dist2 = DistNoRoot(*spell_target); + float dist2 = ComparativeDistance(m_Position, spell_target->GetPosition()); float range2 = range * range; float min_range2 = spells[spell_id].min_range * spells[spell_id].min_range; if(dist2 > range2) { @@ -2344,7 +2344,7 @@ bool Mob::ApplyNextBardPulse(uint16 spell_id, Mob *spell_target, uint16 slot) { range = GetActSpellRange(spell_id, spells[spell_id].range, true); if(spell_target != nullptr && spell_target != this) { //casting a spell on somebody but ourself, make sure they are in range - float dist2 = DistNoRoot(*spell_target); + float dist2 = ComparativeDistance(m_Position, spell_target->GetPosition()); float range2 = range * range; if(dist2 > range2) { //target is out of range.