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
+4 -7
View File
@@ -815,10 +815,8 @@ void recievePATH(RPCParameters *rpcParameters)
SendGetNewSoldierPathEvent( pSoldier, SNetPath->sDestGridNo, SNetPath->ubNewState );
INT16 sCellX, sCellY;
sCellX = CenterX( SNetPath->sAtGridNo );
sCellY = CenterY( SNetPath->sAtGridNo );
ConvertGridNoToCenterCellXY(SNetPath->sAtGridNo, &sCellX, &sCellY);
if (( gAnimControl[ pSoldier->usAnimState ].uiFlags & ( ANIM_MOVING | ANIM_SPECIALMOVE ) ) && !(pSoldier->flags.fNoAPToFinishMove ) )
{
}
@@ -4251,8 +4249,7 @@ void UpdateSoldierFromNetwork (RPCParameters *rpcParameters)
pSoldier->stats.bLife=SUpdateNetworkSoldier->bLife;
INT16 sCellX, sCellY;
sCellX = CenterX( SUpdateNetworkSoldier->sAtGridNo );
sCellY = CenterY( SUpdateNetworkSoldier->sAtGridNo );
ConvertGridNoToCenterCellXY(SUpdateNetworkSoldier->sAtGridNo, &sCellX, &sCellY);
if( pSoldier->sGridNo != SUpdateNetworkSoldier->sAtGridNo)
{
@@ -5281,4 +5278,4 @@ void ChatCallback( UINT8 ubResult )
void OpenChatMsgBox( void )
{
DoChatBox((guiCurrentScreen == GAME_SCREEN? true : false),gzMPChatboxText[1],guiCurrentScreen,ChatCallback,NULL);
}
}