aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfusion32 <marcopuzziello@gmail.com>2026-02-20 23:34:24 -0300
committerfusion32 <marcopuzziello@gmail.com>2026-02-20 23:52:07 -0300
commitb1fd46d8c5e2febf6a6fe61e5aaa2daaeffc3954 (patch)
treebe21cebd0ba2a51a28c9957ed023273b1359dcc5 /src
parentb22be90dc86d487d82bafe25057a3feb564b52c4 (diff)
downloadgame-b1fd46d8c5e2febf6a6fe61e5aaa2daaeffc3954.tar.gz
game-b1fd46d8c5e2febf6a6fe61e5aaa2daaeffc3954.zip
modify SearchFlightField to more closely match the original binary
Diffstat (limited to 'src')
-rw-r--r--src/info.cc41
-rw-r--r--src/map.cc2
2 files changed, 25 insertions, 18 deletions
diff --git a/src/info.cc b/src/info.cc
index 8102801..e0e9467 100644
--- a/src/info.cc
+++ b/src/info.cc
@@ -1054,30 +1054,39 @@ bool SearchFlightField(uint32 FugitiveID, uint32 PursuerID, int *x, int *y, int
}
int Dir[9];
+ for(int i = 0; i < NARRAY(Dir); i += 1){
+ Dir[i] = DIRECTION_NONE;
+ }
+
+ // IMPORTANT(fusion): This is more closely related to the original binary. If
+ // you consider the offset to be the relative coordinate of the fugitive with
+ // respect to the pursuer, and the conditions to be half-plane inequalities,
+ // it shouldn't be too difficult to reason about it.
+
+ int OffsetX = Fugitive->posx - Pursuer->posx;
+ int OffsetY = Fugitive->posy - Pursuer->posy;
+ int DistanceX = std::abs(OffsetX);
+ int DistanceY = std::abs(OffsetY);
// NOTE(fusion): Prefer axial direction away from the pursuer.
- int DistX = std::abs(Fugitive->posx - Pursuer->posx);
- int DistY = std::abs(Fugitive->posy - Pursuer->posy);
- if(DistY > DistX){
- Dir[0] = (Fugitive->posy < Pursuer->posy) ? DIRECTION_NORTH : DIRECTION_SOUTH;
- }else if (DistX > DistY){
- Dir[0] = (Fugitive->posx < Pursuer->posx) ? DIRECTION_WEST : DIRECTION_EAST;
- }else{
- Dir[0] = DIRECTION_NONE;
+ if (DistanceX > DistanceY){
+ Dir[0] = (OffsetX < 0) ? DIRECTION_WEST : DIRECTION_EAST;
+ }else if(DistanceX < DistanceY){
+ Dir[0] = (OffsetY < 0) ? DIRECTION_NORTH : DIRECTION_SOUTH;
}
// NOTE(fusion): Fallback to random axial direction away from the pursuer.
- Dir[1] = (Fugitive->posy <= Pursuer->posy) ? DIRECTION_NORTH : DIRECTION_NONE;
- Dir[2] = (Fugitive->posx >= Pursuer->posx) ? DIRECTION_EAST : DIRECTION_NONE;
- Dir[3] = (Fugitive->posy >= Pursuer->posy) ? DIRECTION_SOUTH : DIRECTION_NONE;
- Dir[4] = (Fugitive->posx <= Pursuer->posx) ? DIRECTION_WEST : DIRECTION_NONE;
+ if(OffsetX >= 0) Dir[1] = DIRECTION_EAST;
+ if(OffsetY <= 0) Dir[2] = DIRECTION_NORTH;
+ if(OffsetX <= 0) Dir[3] = DIRECTION_WEST;
+ if(OffsetY >= 0) Dir[4] = DIRECTION_SOUTH;
RandomShuffle(&Dir[1], 4);
// NOTE(fusion): Fallback to diagonal direction away from the pursuer.
- Dir[5] = (Fugitive->posx <= Pursuer->posx && Fugitive->posy >= Pursuer->posy) ? DIRECTION_SOUTHWEST : DIRECTION_NONE;
- Dir[6] = (Fugitive->posx >= Pursuer->posx && Fugitive->posy >= Pursuer->posy) ? DIRECTION_SOUTHEAST : DIRECTION_NONE;
- Dir[7] = (Fugitive->posx >= Pursuer->posx && Fugitive->posy <= Pursuer->posy) ? DIRECTION_NORTHEAST : DIRECTION_NONE;
- Dir[8] = (Fugitive->posx <= Pursuer->posx && Fugitive->posy <= Pursuer->posy) ? DIRECTION_NORTHWEST : DIRECTION_NONE;
+ if(OffsetY <= OffsetX) Dir[5] = DIRECTION_NORTHEAST;
+ if(OffsetY <= -OffsetX) Dir[6] = DIRECTION_NORTHWEST;
+ if(OffsetY >= OffsetX) Dir[7] = DIRECTION_SOUTHWEST;
+ if(OffsetY >= -OffsetX) Dir[8] = DIRECTION_SOUTHEAST;
RandomShuffle(&Dir[5], 4);
for(int i = 0; i < NARRAY(Dir); i += 1){
diff --git a/src/map.cc b/src/map.cc
index c8cfd76..a404c32 100644
--- a/src/map.cc
+++ b/src/map.cc
@@ -682,8 +682,6 @@ void SwapSector(void){
File.writeQuad((uint32)OldestSectorX);
File.writeQuad((uint32)OldestSectorY);
File.writeQuad((uint32)OldestSectorZ);
- // TODO(fusion): I think tiles are stored in column major order but it doesn't
- // really matter as long as optimize for sequential access.
for(int X = 0; X < 32; X += 1){
for(int Y = 0; Y < 32; Y += 1){
SwapObject(&File, Oldest->MapCon[X][Y], FileNumber);