Skip to content

Commit 16810e5

Browse files
committed
fix(gameplay): fix usages of ceil instead of Ceil2Int
this fixes platform inconsistencies between Linux and Windows on certain floating point values. for example, on Windows servers, small ammo packs will grant 41 metal when on Linux servers they provide the intended 40 metal. Ceil2Int is also faster computationally
1 parent c1e6730 commit 16810e5

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

src/game/server/tf/entity_ammopack.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,19 @@ bool CAmmoPack::MyTouch( CBasePlayer *pPlayer )
6666
float flPackRatio = PackRatios[GetPowerupSize()];
6767

6868
int iMaxPrimary = pTFPlayer->GetMaxAmmo(TF_AMMO_PRIMARY);
69-
if ( pTFPlayer->GiveAmmo( ceil(iMaxPrimary * flPackRatio), TF_AMMO_PRIMARY, true, kAmmoSource_Pickup ) )
69+
if ( pTFPlayer->GiveAmmo( Ceil2Int(iMaxPrimary * flPackRatio), TF_AMMO_PRIMARY, true, kAmmoSource_Pickup ) )
7070
{
7171
bSuccess = true;
7272
}
7373

7474
int iMaxSecondary = pTFPlayer->GetMaxAmmo(TF_AMMO_SECONDARY);
75-
if ( pTFPlayer->GiveAmmo( ceil(iMaxSecondary * flPackRatio), TF_AMMO_SECONDARY, true, kAmmoSource_Pickup ) )
75+
if ( pTFPlayer->GiveAmmo( Ceil2Int(iMaxSecondary * flPackRatio), TF_AMMO_SECONDARY, true, kAmmoSource_Pickup ) )
7676
{
7777
bSuccess = true;
7878
}
7979

8080
int iMaxMetal = pTFPlayer->GetMaxAmmo(TF_AMMO_METAL);
81-
if ( pTFPlayer->GiveAmmo( ceil(iMaxMetal * flPackRatio), TF_AMMO_METAL, true, kAmmoSource_Pickup ) )
81+
if ( pTFPlayer->GiveAmmo( Ceil2Int(iMaxMetal * flPackRatio), TF_AMMO_METAL, true, kAmmoSource_Pickup ) )
8282
{
8383
bSuccess = true;
8484
}
@@ -112,7 +112,7 @@ bool CAmmoPack::MyTouch( CBasePlayer *pPlayer )
112112
if ( pTFPlayer->IsPlayerClass( TF_CLASS_ENGINEER ) )
113113
{
114114
int iMaxGrenades1 = pTFPlayer->GetMaxAmmo(TF_AMMO_GRENADES1);
115-
if ( pTFPlayer->GiveAmmo( ceil(iMaxGrenades1 * flPackRatio), TF_AMMO_GRENADES1, true, kAmmoSource_Pickup ) )
115+
if ( pTFPlayer->GiveAmmo( Ceil2Int(iMaxGrenades1 * flPackRatio), TF_AMMO_GRENADES1, true, kAmmoSource_Pickup ) )
116116
{
117117
bSuccess = true;
118118
}

src/game/server/tf/entity_healthkit.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ bool CHealthKit::MyTouch( CBasePlayer *pPlayer )
9090
{
9191
float flRuneHealthBonus = ( pTFPlayer->m_Shared.GetCarryingRuneType() != RUNE_KNOCKOUT ) ? pTFPlayer->GetRuneHealthBonus() : 0;
9292

93-
float flHealth = ceil( ( pPlayer->GetMaxHealth() - flRuneHealthBonus ) * PackRatios[GetPowerupSize()] );
93+
float flHealth = Ceil2Int( ( pPlayer->GetMaxHealth() - flRuneHealthBonus ) * PackRatios[GetPowerupSize()] );
9494

9595
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( pPlayer, flHealth, mult_health_frompacks );
9696

@@ -116,7 +116,7 @@ bool CHealthKit::MyTouch( CBasePlayer *pPlayer )
116116
{
117117
float flDisguiseHealth = pTFPlayer->m_Shared.GetDisguiseHealth();
118118
float flDisguiseMaxHealth = pTFPlayer->m_Shared.GetDisguiseMaxHealth();
119-
float flHealthToAdd = ceil(flDisguiseMaxHealth * PackRatios[GetPowerupSize()]);
119+
float flHealthToAdd = Ceil2Int(flDisguiseMaxHealth * PackRatios[GetPowerupSize()]);
120120

121121
// don't want to add more than we're allowed to have
122122
if ( flHealthToAdd > flDisguiseMaxHealth - flDisguiseHealth )
@@ -248,19 +248,19 @@ bool CHealthAmmoKit::MyTouch( CBasePlayer *pPlayer )
248248
float flPackRatio = PackRatios[GetPowerupSize()];
249249

250250
int iMaxPrimary = pTFPlayer->GetMaxAmmo( TF_AMMO_PRIMARY );
251-
if ( pTFPlayer->GiveAmmo( ceil( iMaxPrimary * flPackRatio ), TF_AMMO_PRIMARY, true, kAmmoSource_Pickup ) )
251+
if ( pTFPlayer->GiveAmmo( Ceil2Int( iMaxPrimary * flPackRatio ), TF_AMMO_PRIMARY, true, kAmmoSource_Pickup ) )
252252
{
253253
bAmmoSuccess = true;
254254
}
255255

256256
int iMaxSecondary = pTFPlayer->GetMaxAmmo( TF_AMMO_SECONDARY );
257-
if ( pTFPlayer->GiveAmmo( ceil( iMaxSecondary * flPackRatio ), TF_AMMO_SECONDARY, true, kAmmoSource_Pickup ) )
257+
if ( pTFPlayer->GiveAmmo( Ceil2Int( iMaxSecondary * flPackRatio ), TF_AMMO_SECONDARY, true, kAmmoSource_Pickup ) )
258258
{
259259
bAmmoSuccess = true;
260260
}
261261

262262
int iMaxMetal = pTFPlayer->GetMaxAmmo( TF_AMMO_METAL );
263-
if ( pTFPlayer->GiveAmmo( ceil( iMaxMetal * flPackRatio ), TF_AMMO_METAL, true, kAmmoSource_Pickup ) )
263+
if ( pTFPlayer->GiveAmmo( Ceil2Int( iMaxMetal * flPackRatio ), TF_AMMO_METAL, true, kAmmoSource_Pickup ) )
264264
{
265265
bAmmoSuccess = true;
266266
}
@@ -278,7 +278,7 @@ bool CHealthAmmoKit::MyTouch( CBasePlayer *pPlayer )
278278
if ( pTFPlayer->IsPlayerClass( TF_CLASS_ENGINEER ) )
279279
{
280280
int iMaxGrenades1 = pTFPlayer->GetMaxAmmo( TF_AMMO_GRENADES1 );
281-
if ( pTFPlayer->GiveAmmo( ceil( iMaxGrenades1 * flPackRatio ), TF_AMMO_GRENADES1, true, kAmmoSource_Pickup ) )
281+
if ( pTFPlayer->GiveAmmo( Ceil2Int( iMaxGrenades1 * flPackRatio ), TF_AMMO_GRENADES1, true, kAmmoSource_Pickup ) )
282282
{
283283
bAmmoSuccess = true;
284284
}

src/game/server/tf/tf_ammo_pack.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ void CTFAmmoPack::PackTouch( CBaseEntity *pOther )
345345
}
346346

347347
int iMaxPrimary = pPlayer->GetMaxAmmo(TF_AMMO_PRIMARY);
348-
GiveAmmo( ceil( iMaxPrimary * m_flAmmoRatio ), TF_AMMO_PRIMARY );
348+
GiveAmmo( Ceil2Int( iMaxPrimary * m_flAmmoRatio ), TF_AMMO_PRIMARY );
349349

350350
int iMaxSecondary = pPlayer->GetMaxAmmo(TF_AMMO_SECONDARY);
351-
GiveAmmo( ceil( iMaxSecondary * m_flAmmoRatio ), TF_AMMO_SECONDARY );
351+
GiveAmmo( Ceil2Int( iMaxSecondary * m_flAmmoRatio ), TF_AMMO_SECONDARY );
352352

353353
int iAmmoTaken = 0;
354354

@@ -393,7 +393,7 @@ void CTFAmmoPack::PackTouch( CBaseEntity *pOther )
393393
if ( pPlayer->IsPlayerClass( TF_CLASS_ENGINEER ) )
394394
{
395395
int iMaxGrenades1 = pPlayer->GetMaxAmmo( TF_AMMO_GRENADES1 );
396-
iAmmoTaken += pPlayer->GiveAmmo( ceil(iMaxGrenades1 * m_flAmmoRatio), TF_AMMO_GRENADES1 );
396+
iAmmoTaken += pPlayer->GiveAmmo( Ceil2Int(iMaxGrenades1 * m_flAmmoRatio), TF_AMMO_GRENADES1 );
397397
}
398398

399399
if ( m_PackType == AP_HALLOWEEN )

src/game/server/tf/tf_obj.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ void CBaseObject::SetHealth( float flHealth )
16041604
bool changed = m_flHealth != flHealth;
16051605

16061606
m_flHealth = flHealth;
1607-
m_iHealth = ceil(m_flHealth);
1607+
m_iHealth = Ceil2Int(m_flHealth);
16081608

16091609

16101610
/*
@@ -2950,7 +2950,7 @@ int CBaseObject::Command_Repair( CTFPlayer *pActivator, float flAmount, float fl
29502950

29512951
float flRepairAmountMax = flAmount * flRepairMod;
29522952
int iRepairAmount = Min( RoundFloatToInt( flRepairAmountMax ), GetMaxHealth() - RoundFloatToInt( GetHealth() ) );
2953-
int iRepairCost = ceil( (float)( iRepairAmount ) / flRepairToMetalRatio );
2953+
int iRepairCost = Ceil2Int( (float)( iRepairAmount ) / flRepairToMetalRatio );
29542954
if ( iRepairCost > pActivator->GetBuildResources() )
29552955
{
29562956
// What can we afford?

src/game/server/tf/tf_obj_teleporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ int CObjectTeleporter::Command_Repair( CTFPlayer *pActivator, float flAmount, fl
690690
{
691691
float flRepairAmountMax = flAmount * flRepairMod;
692692
int iRepairAmount = Min( flRepairAmountMax, pMatch->GetMaxHealth() - pMatch->GetHealth() );
693-
int iRepairCost = ceil( (float)iRepairAmount / flRepairToMetalRatio );
693+
int iRepairCost = Ceil2Int( (float)iRepairAmount / flRepairToMetalRatio );
694694
if ( iRepairCost > pActivator->GetBuildResources() )
695695
{
696696
// What can we afford?

src/game/server/tf/tf_player.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,7 @@ void CTFPlayer::RegenThink( void )
19151915
}
19161916
else if ( m_flAccumulatedHealthRegen < -1.f )
19171917
{
1918-
nHealAmount = ceil( m_flAccumulatedHealthRegen );
1918+
nHealAmount = Ceil2Int( m_flAccumulatedHealthRegen );
19191919
TakeDamage( CTakeDamageInfo( this, this, NULL, vec3_origin, WorldSpaceCenter(), nHealAmount * -1, DMG_GENERIC ) );
19201920
}
19211921

@@ -2049,7 +2049,7 @@ void CTFPlayer::RuneRegenThink( void )
20492049
}
20502050
else if ( m_flAccumulatedRuneHealthRegen < -1.0 )
20512051
{
2052-
nHealAmount = ceil( m_flAccumulatedRuneHealthRegen );
2052+
nHealAmount = Ceil2Int( m_flAccumulatedRuneHealthRegen );
20532053
TakeDamage( CTakeDamageInfo( this, this, NULL, vec3_origin, WorldSpaceCenter(), nHealAmount * -1, DMG_GENERIC ) );
20542054
}
20552055

0 commit comments

Comments
 (0)