Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Cleanup: Refactor getAvailableTrickAttackChar
Browse files Browse the repository at this point in the history
  • Loading branch information
zach2good committed Nov 27, 2020
1 parent b2ccd95 commit 5959782
Showing 1 changed file with 61 additions and 70 deletions.
131 changes: 61 additions & 70 deletions src/map/utils/battleutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3552,7 +3552,8 @@ namespace battleutils
float slope = 0;
float maxSlope = 0;
float minSlope = 0;
bool zDependent = true; //using a slope where z is dependent var
bool zDependent = true; // using a slope where z is dependent var

if (abs(xdif) <= abs(zdif))
{
slope = xdif / zdif;
Expand All @@ -3569,7 +3570,8 @@ namespace battleutils
minSlope = ((minXpoint - mobX) / (minZpoint - mobZ));
zDependent = false;
}
else {
else
{
slope = zdif / xdif;

float angle = (float)atan((double)1) * 2 - atan(slope);
Expand All @@ -3583,98 +3585,87 @@ namespace battleutils
maxSlope = (maxZpoint - mobZ) / (maxXpoint - mobX);
minSlope = (minZpoint - mobZ) / (minXpoint - mobX);
}
if (taUser->PParty != nullptr)

auto checkPosition = [&](CBattleEntity* PEntity) -> bool
{
if (taUser->PParty->m_PAlliance != nullptr)
if (taUser->id != PEntity->id && distance(PEntity->loc.p, PMob->loc.p) <= distance(taUser->loc.p, PMob->loc.p))
{
for (uint8 a = 0; a < taUser->PParty->m_PAlliance->partyList.size(); ++a)
float memberXdif = PEntity->loc.p.x - mobX;
float memberZdif = PEntity->loc.p.z - mobZ;
if (zDependent)
{
for (uint8 i = 0; i < taUser->PParty->m_PAlliance->partyList.at(a)->members.size(); ++i)
if ((memberZdif <= memberXdif * maxSlope) && (memberZdif >= memberXdif * minSlope))
{
CBattleEntity* member = taUser->PParty->m_PAlliance->partyList.at(a)->members.at(i);
if (taUser->id != member->id && distance(member->loc.p, PMob->loc.p) <= distance(taUser->loc.p, PMob->loc.p))
{
float memberXdif = member->loc.p.x - mobX;
float memberZdif = member->loc.p.z - mobZ;
if (zDependent)
{
if ((memberZdif <= memberXdif * maxSlope) &&
(memberZdif >= memberXdif * minSlope))
{
//finally found a TA partner
return member;
}
}
else {
if ((memberXdif <= memberZdif * maxSlope) &&
(memberXdif >= memberZdif * minSlope))
{
//finally found a TA partner
return member;
}
}
}
// finally found a TA partner
return true;
}
}
else
{
if ((memberXdif <= memberZdif * maxSlope) && (memberXdif >= memberZdif * minSlope))
{
// finally found a TA partner
return true;
}
}
}
else {//no alliance
for (uint8 i = 0; i < taUser->PParty->members.size(); ++i)

return false;
};

auto checkTrusts = [&](CBattleEntity* PEntity) -> CBattleEntity*
{
if (auto* PChar = dynamic_cast<CCharEntity*>(PEntity))
{
for (auto* PTrust : PChar->PTrusts)
{
CBattleEntity* member = taUser->PParty->members.at(i);
if (member->id != taUser->id && distance(member->loc.p, PMob->loc.p) <= distance(taUser->loc.p, PMob->loc.p))
if (checkPosition(PTrust))
{
float memberXdif = member->loc.p.x - mobX;
float memberZdif = member->loc.p.z - mobZ;
if (zDependent)
{
if ((memberZdif <= memberXdif * maxSlope) &&
(memberZdif >= memberXdif * minSlope))
{
//finally found a TA partner
return member;
}
}
else {
if ((memberXdif <= memberZdif * maxSlope) &&
(memberXdif >= memberZdif * minSlope))
{
//finally found a TA partner
return member;
}
}
return PTrust;
}
}
}
}

// Check for trusts
// TODO: Roll this into all the loops above
if (auto PChar = dynamic_cast<CCharEntity*>(taUser))
return nullptr;
};

if (taUser->PParty != nullptr)
{
PChar->ForPartyWithTrusts([&](CBattleEntity* member)
if (taUser->PParty->m_PAlliance != nullptr)
{
if (member->id != taUser->id && distance(member->loc.p, PMob->loc.p) <= distance(taUser->loc.p, PMob->loc.p))
for (uint8 a = 0; a < taUser->PParty->m_PAlliance->partyList.size(); ++a)
{
float memberXdif = member->loc.p.x - mobX;
float memberZdif = member->loc.p.z - mobZ;
if (zDependent)
for (uint8 i = 0; i < taUser->PParty->m_PAlliance->partyList.at(a)->members.size(); ++i)
{
if ((memberZdif <= memberXdif * maxSlope) && (memberZdif >= memberXdif * minSlope))
CBattleEntity* member = taUser->PParty->m_PAlliance->partyList.at(a)->members.at(i);
if (checkPosition(member))
{
// finally found a TA partner
return member;
}
}
else
{
if ((memberXdif <= memberZdif * maxSlope) && (memberXdif >= memberZdif * minSlope))

if (auto* potentialTrust = checkTrusts(member))
{
// finally found a TA partner
return member;
return potentialTrust;
}
}
}
});
}
else
{ // No alliance
for (uint8 i = 0; i < taUser->PParty->members.size(); ++i)
{
CBattleEntity* member = taUser->PParty->members.at(i);
if (checkPosition(member))
{
return member;
}

if (auto* potentialTrust = checkTrusts(member))
{
return potentialTrust;
}
}
}
}

// No Trick attack party member available
Expand Down

0 comments on commit 5959782

Please sign in to comment.