Skip to content

Commit

Permalink
Possible fix to AircraftTrackerClass range issue (#1306)
Browse files Browse the repository at this point in the history
* Possible fix to AircraftTrackerClass range issue

* Add credits / changelog
  • Loading branch information
Starkku authored Jul 14, 2024
1 parent c3c8938 commit 83ab322
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ This page lists all the individual contributions to the project by their author.
- Custom tint effects
- Revenge weapons
- AttachEffect
- Air unit tracking fix for large range / `CellSpread`
- **Morton (MortonPL)**:
- `XDrawOffset` for animations
- Shield passthrough & absorption
Expand Down
2 changes: 1 addition & 1 deletion YRpp
Submodule YRpp updated 1 files
+0 −3 MapClass.h
1 change: 1 addition & 0 deletions docs/Fixed-or-Improved-Logics.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ This page describes all ingame logics that are fixed or improved in Phobos witho
- Objects in invalid map coordinates are no longer used for starting view and AI base center calculations.
- Units & buildings with `DecloakToFire=false` weapons now cloak while targeting & reloading.
- Units with `Sensors=true` will no longer reveal ally buildings.
- Air units are now reliably included by target scan with large range and Warhead detonation by large `CellSpread`.

## Fixes / interactions with other extensions

Expand Down
1 change: 1 addition & 0 deletions docs/Whats-New.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ Vanilla fixes:
- Units & buildings with `DecloakToFire=false` weapons can now cloak while targeting & reloading (by Starkku)
- Units with `Sensors=true` will no longer reveal ally buildings (by Starkku)
- Waypoint path is drawn for all units under player control or `DebugKeysEnabled=yes` (by Trsdy)
- Air units are now reliably included by target scan with large range and Warhead detonation by large `CellSpread` (by Starkku)
Phobos fixes:
- Fixed a few errors of calling for superweapon launch by `LaunchSW` or building infiltration (by Trsdy)
Expand Down
42 changes: 41 additions & 1 deletion src/Misc/Hooks.BugFixes.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <AircraftClass.h>
#include <AircraftTrackerClass.h>
#include <AnimClass.h>
#include <BuildingClass.h>
#include <TechnoClass.h>
Expand Down Expand Up @@ -676,7 +677,7 @@ DEFINE_HOOK(0x53AD85, IonStormClass_AdjustLighting_ColorSchemes, 0x5)
if (paletteCount > 0)
{
int schemeCount = ColorScheme::GetNumberOfSchemes();
Debug::Log("Recalculated %d extra palettes across %d color schemes (total: %d).\n", paletteCount, schemeCount, schemeCount* paletteCount);
Debug::Log("Recalculated %d extra palettes across %d color schemes (total: %d).\n", paletteCount, schemeCount, schemeCount * paletteCount);
}

return SkipGameCode;
Expand Down Expand Up @@ -805,3 +806,42 @@ DEFINE_JUMP(LJMP, 0x67E3BD, 0x67E3D3); // Save
DEFINE_JUMP(LJMP, 0x67F72E, 0x67F744); // Load

#pragma endregion save_load

// An attempt to fix an issue where the ATC->CurrentVector does not contain every air Techno in given range that increases in frequency as the range goes up.
// Real talk: I have absolutely no clue how the original function works besides doing vector looping and manipulation, as far as I can tell it never even explicitly
// clears CurrentVector but somehow it only contains applicable items afterwards anyway. It is possible this one does not achieve everything the original does functionality and/or
// performance-wise but it does work and produces results with greater accuracy than the original for large ranges. - Starkku
DEFINE_HOOK(0x412B40, AircraftTrackerClass_FillCurrentVector, 0x5)
{
enum { SkipGameCode = 0x413482 };

GET(AircraftTrackerClass*, pThis, ECX);
GET_STACK(CellClass*, pCell, 0x4);
GET_STACK(int, range, 0x8);

pThis->CurrentVector.Clear();

if (range < 1)
range = 1;

auto const bounds = MapClass::Instance->MapCoordBounds;
auto const mapCoords = pCell->MapCoords;
int sectorWidth = bounds.Right / 20;
int sectorHeight = bounds.Bottom / 20;
int sectorIndexXStart = Math::clamp((mapCoords.X - range) / sectorWidth, 0, 19);
int sectorIndexYStart = Math::clamp((mapCoords.Y - range) / sectorHeight, 0, 19);
int sectorIndexXEnd = Math::clamp((mapCoords.X + range) / sectorWidth, 0, 19);
int sectorIndexYEnd = Math::clamp((mapCoords.Y + range) / sectorHeight, 0, 19);

for (int y = sectorIndexYStart; y <= sectorIndexYEnd; y++)
{
for (int x = sectorIndexXStart; x <= sectorIndexXEnd; x++)
{
for (auto const pTechno : pThis->TrackerVectors[y][x])
pThis->CurrentVector.AddItem(pTechno);
}
}

R->EAX(0); // The original function returns some number, hell if I know what (it is 0 most of the time though and never actually used for anything).
return SkipGameCode;
}

0 comments on commit 83ab322

Please sign in to comment.