mirror of
https://github.com/1dot13/source.git
synced 2026-08-12 14:10: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:
@@ -6130,10 +6130,8 @@ void ProcessNoise(UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bLevel, UINT8 ubTerrTy
|
||||
{
|
||||
// ALL RIGHT! Passed all the tests, this listener hears this noise!!!
|
||||
HearNoise(pSoldier,ubSource,sGridNo,bLevel,ubEffVolume,ubNoiseType, (UINT8 *)&bSeen);
|
||||
|
||||
bHeard = TRUE;
|
||||
|
||||
ubNoiseDir = atan8(CenterX(pSoldier->sGridNo),CenterY(pSoldier->sGridNo),CenterX(sGridNo),CenterY(sGridNo));
|
||||
ubNoiseDir = GetDirectionFromCenterCellXYGridNo(pSoldier->sGridNo, sGridNo);
|
||||
|
||||
// check the 'noise heard & reported' bit for that soldier & direction
|
||||
if ( ubNoiseType != NOISE_MOVEMENT || bTeam != OUR_TEAM || (pSoldier->aiData.bInterruptDuelPts != NO_INTERRUPT) || !(pSoldier->ubMovementNoiseHeard & (1 << ubNoiseDir) ) )
|
||||
@@ -6441,8 +6439,7 @@ void HearNoise(SOLDIERTYPE *pSoldier, UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bL
|
||||
// ignore muzzle flashes when turning head to see noise
|
||||
if ( ubNoiseType == NOISE_GUNFIRE && ubNoiseMaker != NOBODY && MercPtrs[ ubNoiseMaker ]->flags.fMuzzleFlash )
|
||||
{
|
||||
sNoiseX = CenterX(sGridNo);
|
||||
sNoiseY = CenterY(sGridNo);
|
||||
ConvertGridNoToCenterCellXY(sGridNo, &sNoiseX, &sNoiseY);
|
||||
bDirection = atan8(pSoldier->sX,pSoldier->sY,sNoiseX,sNoiseY);
|
||||
if ( pSoldier->ubDirection != bDirection && pSoldier->ubDirection != gOneCDirection[ bDirection ] && pSoldier->ubDirection != gOneCCDirection[ bDirection ] )
|
||||
{
|
||||
@@ -6463,8 +6460,7 @@ void HearNoise(SOLDIERTYPE *pSoldier, UINT8 ubNoiseMaker, INT32 sGridNo, INT8 bL
|
||||
if (PythSpacesAway(pSoldier->sGridNo,sGridNo) <= sDistVisible )
|
||||
{
|
||||
// just use the XXadjustedXX center of the gridno
|
||||
sNoiseX = CenterX(sGridNo);
|
||||
sNoiseY = CenterY(sGridNo);
|
||||
ConvertGridNoToCenterCellXY(sGridNo, &sNoiseX, &sNoiseY);
|
||||
|
||||
if (pSoldier->ubDirection != atan8(pSoldier->sX,pSoldier->sY,sNoiseX,sNoiseY))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user