Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 2D distance to check whether team members have arrived destination #1487

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/Misc/Hooks.BugFixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,20 +1138,11 @@ DEFINE_HOOK(0x4C75DA, EventClass_RespondToEvent_Stop, 0x6)

#pragma region TeamCloseRangeFix

int __fastcall Check2DDistanceInsteadOf3D(AbstractClass* pSource, void* _, AbstractClass* pTarget)
int __fastcall Check2DDistanceInsteadOf3D(ObjectClass* pSource, void* _, AbstractClass* pTarget)
{
const auto sourceCoords = pSource->GetCoords();
const auto targetCoords = pTarget->GetCoords();

// Aircraft has its own unique treatment, and it will not be changed here
int distance = Game::F2I((pSource->IsInAir() && pSource->WhatAmI() != AbstractType::Aircraft) ? // Jumpjets or sth in the air ?
(Point2D { sourceCoords.X - targetCoords.X, sourceCoords.Y - targetCoords.Y }.Magnitude() * 2) : // bonus to units in the air
sourceCoords.DistanceFrom(targetCoords)); // Original

if (const auto pBuilding = abstract_cast<BuildingClass*>(pTarget)) // Vanilla bonus to building
distance -= ((pBuilding->Type->GetFoundationWidth() + pBuilding->Type->GetFoundationHeight(false)) << 6);

return Math::max(0, distance);
return (pSource->IsInAir() && pSource->WhatAmI() != AbstractType::Aircraft) // Jumpjets or sth in the air
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you omit AircraftClass? Also does all the in air stuff need to be considered like so?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At present, it seems that aircrafts use their own mapcoords and the team destination's mapcoords to check.
During the previous test, it was found that if the aircraft uses this and needs to return to the airport with the script first, it will interrupt the remaining tasks for unknown reasons.

? (pSource->DistanceFrom(pTarget) * 2) // 2D distance (2x is the bonus to units in the air)
: reinterpret_cast<int(__thiscall*)(ObjectClass*, AbstractClass*)>(0x5F6360)(pSource, pTarget); // 3D distance (vanilla)
Metadorius marked this conversation as resolved.
Show resolved Hide resolved
}
DEFINE_JUMP(CALL, 0x6EBCC9, GET_OFFSET(Check2DDistanceInsteadOf3D));

Expand Down
Loading