Reduce code duplication (#233)

* Use ConvertGridNoToCenterCellXY instead of CenterX & CenterY

* Add direction utility function

We have a lot of places in the code that calculate direction based on center cell coordinates, but lack a utility function for it similar to other direction methods.

* Use utility function for calculating direction

* Use ConvertGridNoToCenterCellXY

* Use utility function for direction

* Use ConvertGridNoToCenterCellXY instead of CenterX & CenterY

* Use ConvertGridNoToCenterCellXY instead of CenterX & CenterY

* Remove CenterX & CenterY functions

Use ConvertGridNoToCenterCellXY instead

* Remove CenterX & CenterY calls from UB configuration

* Address review feedback

* Remove duplicate function

ConvertGridNoToCenterCellXY and ConvertMapPosToWorldTileCenter do the exact same thing

* Use PythSpacesAway instead of GetRangeFromGridNoDiff

Both functions calculate the same thing

* Remove GetRangeFromGridNoDiff

* Remove calls to abs()

The values end up being squared anyways making these unnecessary
This commit is contained in:
Asdow
2023-10-07 15:14:15 +03:00
committed by GitHub
parent b68f206969
commit b8a870df02
37 changed files with 389 additions and 382 deletions
+11 -22
View File
@@ -1367,11 +1367,9 @@ void InternalSoldierInSectorSleep( SOLDIERTYPE *pSoldier, INT32 sGridNo, BOOLEAN
usAnim = STANDING;
}
// OK, look for sutable placement....
// OK, look for suitable placement....
sGoodGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, usAnim, sGridNo, 5, &ubNewDirection, FALSE );
sWorldX = CenterX( sGoodGridNo );
sWorldY = CenterY( sGoodGridNo );
ConvertGridNoToCenterCellXY(sGoodGridNo, &sWorldX, &sWorldY);
pSoldier->EVENT_SetSoldierPosition( sWorldX, sWorldY );
@@ -1408,11 +1406,9 @@ void SoldierInSectorIncompaciated( SOLDIERTYPE *pSoldier, INT32 sGridNo )
return;
}
// OK, look for sutable placement....
// OK, look for suitable placement....
sGoodGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, STAND_FALLFORWARD_STOP, sGridNo, 5, &ubNewDirection, FALSE );
sWorldX = CenterX( sGoodGridNo );
sWorldY = CenterY( sGoodGridNo );
ConvertGridNoToCenterCellXY(sGoodGridNo, &sWorldX, &sWorldY);
pSoldier->EVENT_SetSoldierPosition( sWorldX, sWorldY );
@@ -1444,11 +1440,9 @@ void SoldierInSectorPatient( SOLDIERTYPE *pSoldier, INT32 sGridNo )
return;
}
// OK, look for sutable placement....
// OK, look for suitable placement....
sGoodGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, BEING_PATIENT, sGridNo, 5, &ubNewDirection, FALSE );
sWorldX = CenterX( sGoodGridNo );
sWorldY = CenterY( sGoodGridNo );
ConvertGridNoToCenterCellXY(sGoodGridNo, &sWorldX, &sWorldY);
pSoldier->EVENT_SetSoldierPosition( sWorldX, sWorldY );
@@ -1479,11 +1473,9 @@ void SoldierInSectorDoctor( SOLDIERTYPE *pSoldier, INT32 sGridNo )
return;
}
// OK, look for sutable placement....
// OK, look for suitable placement....
sGoodGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, BEING_DOCTOR, sGridNo, 5, &ubNewDirection, FALSE );
sWorldX = CenterX( sGoodGridNo );
sWorldY = CenterY( sGoodGridNo );
ConvertGridNoToCenterCellXY(sGoodGridNo, &sWorldX, &sWorldY);
pSoldier->EVENT_SetSoldierPosition( sWorldX, sWorldY );
@@ -1514,11 +1506,9 @@ void SoldierInSectorRepair( SOLDIERTYPE *pSoldier, INT32 sGridNo )
return;
}
// OK, look for sutable placement....
// OK, look for suitable placement....
sGoodGridNo = FindGridNoFromSweetSpotWithStructData( pSoldier, BEING_REPAIRMAN, sGridNo, 5, &ubNewDirection, FALSE );
sWorldX = CenterX( sGoodGridNo );
sWorldY = CenterY( sGoodGridNo );
ConvertGridNoToCenterCellXY(sGoodGridNo, &sWorldX, &sWorldY);
pSoldier->EVENT_SetSoldierPosition( sWorldX, sWorldY );
@@ -1550,8 +1540,7 @@ void AddSoldierToSectorGridNo( SOLDIERTYPE *pSoldier, INT32 sGridNo, UINT8 ubDir
DebugMsg(TOPIC_JA2,DBG_LEVEL_3,String("AddSoldierToSectorGridNo"));
// Add merc to gridno
sWorldX = CenterX( sGridNo );
sWorldY = CenterY( sGridNo );
ConvertGridNoToCenterCellXY(sGridNo, &sWorldX, &sWorldY);
// Set reserved location!
pSoldier->sReservedMovementGridNo = NOWHERE;