mirror of
https://github.com/1dot13/source.git
synced 2026-08-05 14:00:23 +02:00
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:
@@ -1827,7 +1827,7 @@ void HandleNPCDoAction( UINT8 ubTargetNPC, UINT16 usActionCode, UINT8 ubQuoteNum
|
||||
EXITGRID ExitGrid;
|
||||
INT32 iRandom = 0;
|
||||
UINT8 ubMineIndex;
|
||||
|
||||
INT16 sX, sY, sX2, sY2;
|
||||
|
||||
pSoldier2 = NULL;
|
||||
//ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"Handling %s, action %d at %ld", gMercProfiles[ ubTargetNPC ].zNickname, usActionCode, GetJA2Clock() );
|
||||
@@ -1840,7 +1840,9 @@ void HandleNPCDoAction( UINT8 ubTargetNPC, UINT16 usActionCode, UINT8 ubQuoteNum
|
||||
if (pSoldier && pSoldier2)
|
||||
{
|
||||
// see if we are facing this person
|
||||
ubDesiredMercDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(pSoldier2->sGridNo),CenterY(pSoldier2->sGridNo));
|
||||
ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY);
|
||||
ConvertGridNoToCenterCellXY(pSoldier2->sGridNo, &sX2, &sY2);
|
||||
ubDesiredMercDir = atan8(sX, sY, sX2, sY2);
|
||||
// if not already facing in that direction,
|
||||
if (pSoldier->ubDirection != ubDesiredMercDir)
|
||||
{
|
||||
@@ -2317,7 +2319,9 @@ void HandleNPCDoAction( UINT8 ubTargetNPC, UINT16 usActionCode, UINT8 ubQuoteNum
|
||||
if (!TileIsOutOfBounds(sGridNo))
|
||||
{
|
||||
// see if we are facing this person
|
||||
ubDesiredMercDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sGridNo),CenterY(sGridNo));
|
||||
ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY);
|
||||
ConvertGridNoToCenterCellXY(sGridNo, &sX2, &sY2);
|
||||
ubDesiredMercDir = atan8(sX, sY, sX2, sY2);
|
||||
// if not already facing in that direction,
|
||||
if (pSoldier->ubDirection != ubDesiredMercDir)
|
||||
{
|
||||
@@ -5632,7 +5636,9 @@ void HandleRaulBlowingHimselfUp()
|
||||
|
||||
//blow himself up with, hmmm, lets say TNT. :)
|
||||
usItem = HAND_GRENADE;
|
||||
IgniteExplosion( RAUL_UB, CenterX( pSoldier->sGridNo ), CenterY( pSoldier->sGridNo ), 0, pSoldier->sGridNo, usItem, pSoldier->pathing.bLevel );
|
||||
INT16 sX, sY;
|
||||
ConvertGridNoToCenterCellXY(pSoldier->sGridNo, &sX, &sY);
|
||||
IgniteExplosion( RAUL_UB, sX, sY, 0, pSoldier->sGridNo, usItem, pSoldier->pathing.bLevel );
|
||||
|
||||
SetJa25GeneralFlag( JA_GF__RAUL_BLOW_HIMSELF_UP );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user