From a70eadecf47697432755d304488cc9042e779c73 Mon Sep 17 00:00:00 2001 From: Arthur Ice Date: Sun, 30 Nov 2014 20:23:18 -0800 Subject: [PATCH] Replaced GetX(), GetY(), GetZ(), and GetHeading() in Doors with GetPosition() --- zone/bot.cpp | 62 ++++++++++++++++++++------------------------- zone/doors.cpp | 2 +- zone/doors.h | 5 +--- zone/entity.cpp | 36 +++++++++++++------------- zone/lua_door.cpp | 8 +++--- zone/perl_doors.cpp | 8 +++--- 6 files changed, 54 insertions(+), 67 deletions(-) diff --git a/zone/bot.cpp b/zone/bot.cpp index add609d9a..76363ab7c 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -15854,47 +15854,39 @@ std::list EntityList::GetBotsByBotOwnerCharacterID(uint32 botOwnerCharacte void EntityList::BotPickLock(Bot* rogue) { - auto it = door_list.begin(); for (auto it = door_list.begin(); it != door_list.end(); ++it) { Doors *cdoor = it->second; - if(cdoor && !cdoor->IsDoorOpen()) { - float zdiff = rogue->GetZ() - cdoor->GetZ(); - if(zdiff < 0) - zdiff = 0 - zdiff; - float curdist = 0; - float tmp = rogue->GetX() - cdoor->GetX(); - curdist += (tmp * tmp); - tmp = rogue->GetY() - cdoor->GetY(); - curdist += (tmp * tmp); - if((zdiff < 10) && (curdist <= 130)) { - // All rogue items with lock pick bonuses are hands or primary - const ItemInst* item1 = rogue->GetBotItem(MainHands); - const ItemInst* item2 = rogue->GetBotItem(MainPrimary); + if(!cdoor || cdoor->IsDoorOpen()) + continue; - float bonus1 = 0.0f; - float bonus2 = 0.0f; - float skill = rogue->GetSkill(SkillPickLock); + auto diff = rogue->GetPosition() - cdoor->GetPosition(); + diff.ABS_XYZ(); - if(item1) { // Hand slot item - if(item1->GetItem()->SkillModType == SkillPickLock) { - bonus1 = skill * (((float)item1->GetItem()->SkillModValue) / 100.0f); - } - } + float curdist = diff.m_X * diff.m_X + diff.m_Y * diff.m_Y; - if(item2) { // Primary slot item - if(item2->GetItem()->SkillModType == SkillPickLock) { - bonus2 = skill * (((float)item2->GetItem()->SkillModValue) / 100.0f); - } - } + if((diff.m_Z * diff.m_Z >= 10) || (curdist > 130)) + continue; - if((skill+bonus1+bonus2) >= cdoor->GetLockpick()) { - cdoor->ForceOpen(rogue); - } - else { - rogue->Say("I am not skilled enough for this lock."); - } - } - } + // All rogue items with lock pick bonuses are hands or primary + const ItemInst* item1 = rogue->GetBotItem(MainHands); + const ItemInst* item2 = rogue->GetBotItem(MainPrimary); + + float bonus1 = 0.0f; + float bonus2 = 0.0f; + float skill = rogue->GetSkill(SkillPickLock); + + if(item1) // Hand slot item + if(item1->GetItem()->SkillModType == SkillPickLock) + bonus1 = skill * (((float)item1->GetItem()->SkillModValue) / 100.0f); + + if(item2) // Primary slot item + if(item2->GetItem()->SkillModType == SkillPickLock) + bonus2 = skill * (((float)item2->GetItem()->SkillModValue) / 100.0f); + + if((skill+bonus1+bonus2) >= cdoor->GetLockpick()) + cdoor->ForceOpen(rogue); + else + rogue->Say("I am not skilled enough for this lock."); } } diff --git a/zone/doors.cpp b/zone/doors.cpp index be4b733a5..d54d75edf 100644 --- a/zone/doors.cpp +++ b/zone/doors.cpp @@ -750,6 +750,6 @@ void Doors::CreateDatabaseEntry() { return; } - database.InsertDoor(GetDoorDBID(), GetDoorID(), GetDoorName(), GetX(), GetY(), GetZ(), GetHeading(), GetOpenType(), GetGuildID(), GetLockpick(), GetKeyItem(), GetDoorParam(), GetInvertState(), GetIncline(), GetSize()); + database.InsertDoor(GetDoorDBID(), GetDoorID(), GetDoorName(), m_Position.m_X, m_Position.m_Y, m_Position.m_Z, m_Position.m_Heading, GetOpenType(), GetGuildID(), GetLockpick(), GetKeyItem(), GetDoorParam(), GetInvertState(), GetIncline(), GetSize()); } diff --git a/zone/doors.h b/zone/doors.h index 1a31b67c1..3c57b967c 100644 --- a/zone/doors.h +++ b/zone/doors.h @@ -25,10 +25,7 @@ public: char* GetDoorName() { return door_name; } uint32 GetDoorParam() { return door_param; } int GetInvertState() { return invert_state; } - float GetX() { return m_Position.m_X; } - float GetY() { return m_Position.m_Y; } - float GetZ() { return m_Position.m_Z; } - float GetHeading() { return m_Position.m_Heading; } + const xyz_heading GetPosition() const{ return m_Position; } int GetIncline() { return incline; } bool triggered; void SetOpenState(bool st) { isopen = st; } diff --git a/zone/entity.cpp b/zone/entity.cpp index 792deaad4..da95f4025 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -855,10 +855,11 @@ bool EntityList::MakeDoorSpawnPacket(EQApplicationPacket *app, Client *client) strlen(door->GetDoorName()) > 3) { memset(&nd, 0, sizeof(nd)); memcpy(nd.name, door->GetDoorName(), 32); - nd.xPos = door->GetX(); - nd.yPos = door->GetY(); - nd.zPos = door->GetZ(); - nd.heading = door->GetHeading(); + auto position = door->GetPosition(); + nd.xPos = position.m_X; + nd.yPos = position.m_Y; + nd.zPos = position.m_Z; + nd.heading = position.m_Heading; nd.incline = door->GetIncline(); nd.size = door->GetSize(); nd.doorId = door->GetDoorID(); @@ -3085,22 +3086,19 @@ void EntityList::AddHealAggro(Mob *target, Mob *caster, uint16 thedam) void EntityList::OpenDoorsNear(NPC *who) { - auto it = door_list.begin(); - while (it != door_list.end()) { + + for (auto it = door_list.begin();it != door_list.end(); ++it) { Doors *cdoor = it->second; - if (cdoor && !cdoor->IsDoorOpen()) { - float zdiff = who->GetZ() - cdoor->GetZ(); - if (zdiff < 0) - zdiff = 0 - zdiff; - float curdist = 0; - float tmp = who->GetX() - cdoor->GetX(); - curdist += tmp * tmp; - tmp = who->GetY() - cdoor->GetY(); - curdist += tmp * tmp; - if (zdiff < 10 && curdist <= 100) - cdoor->NPCOpen(who); - } - ++it; + if (!cdoor || cdoor->IsDoorOpen()) + continue; + + auto diff = who->GetPosition() - cdoor->GetPosition(); + diff.ABS_XYZ(); + + float curdist = diff.m_X * diff.m_X + diff.m_Y * diff.m_Y; + + if (diff.m_Z * diff.m_Z < 10 && curdist <= 100) + cdoor->NPCOpen(who); } } diff --git a/zone/lua_door.cpp b/zone/lua_door.cpp index 091cd0c0e..b6427e70e 100644 --- a/zone/lua_door.cpp +++ b/zone/lua_door.cpp @@ -20,22 +20,22 @@ const char *Lua_Door::GetDoorName() { float Lua_Door::GetX() { Lua_Safe_Call_Real(); - return self->GetX(); + return self->GetPosition().m_X; } float Lua_Door::GetY() { Lua_Safe_Call_Real(); - return self->GetY(); + return self->GetPosition().m_Y; } float Lua_Door::GetZ() { Lua_Safe_Call_Real(); - return self->GetZ(); + return self->GetPosition().m_Z; } float Lua_Door::GetHeading() { Lua_Safe_Call_Real(); - return self->GetHeading(); + return self->GetPosition().m_Heading; } void Lua_Door::SetX(float x) { diff --git a/zone/perl_doors.cpp b/zone/perl_doors.cpp index 77ad1902b..acdef2003 100644 --- a/zone/perl_doors.cpp +++ b/zone/perl_doors.cpp @@ -138,7 +138,7 @@ XS(XS_Doors_GetX) if(THIS == nullptr) Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); - RETVAL = THIS->GetX(); + RETVAL = THIS->GetPosition().m_X; XSprePUSH; PUSHn((double)RETVAL); } XSRETURN(1); @@ -164,7 +164,7 @@ XS(XS_Doors_GetY) if(THIS == nullptr) Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); - RETVAL = THIS->GetY(); + RETVAL = THIS->GetPosition().m_Y; XSprePUSH; PUSHn((double)RETVAL); } XSRETURN(1); @@ -190,7 +190,7 @@ XS(XS_Doors_GetZ) if(THIS == nullptr) Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); - RETVAL = THIS->GetZ(); + RETVAL = THIS->GetPosition().m_Z; XSprePUSH; PUSHn((double)RETVAL); } XSRETURN(1); @@ -216,7 +216,7 @@ XS(XS_Doors_GetHeading) if(THIS == nullptr) Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); - RETVAL = THIS->GetHeading(); + RETVAL = THIS->GetPosition().m_Heading; XSprePUSH; PUSHn((double)RETVAL); } XSRETURN(1);