PDA

View Full Version : Code review: ReduceDamage(...) > v1



Higor
08-24-2012, 02:25 PM
In SiegeGI, the current implementation of ReduceDamage has a few problems:

1 - Spawn protection is being checked for all kinds victims, even walls...
Since non-player actors don't have a ReplicationInfo or even an inventory chain, they produce log warnings.

2 - Top attacker statistic was being calculated from player damage instead of building damage.

3 - Core attacker statistic being inflated if attacked with sniper rifle or at long distances.

Replace the function ReduceDamage in SiegeGi with this one:

function int ReduceDamage(int damage, name damageType, Pawn injured, Pawn instigatedBy)
{
local string sMessage;
local sgSpawnProt sgSP;
local bool bPlayerInstigated;

//Fast condition
bPlayerInstigated = (instigatedBy != none) && instigatedBy.bIsPlayer && (instigatedBy.PlayerReplicationInfo != none);

//Spawn protection...
if ( bPlayerInstigated && (injured.PlayerReplicationInfo != none) )
{
if ( injured.bIsPlayer && (injured.PlayerReplicationInfo.Team != instigatedBy.PlayerReplicationInfo.Team) )
{
if (injured != instigatedBy)
{
sgSP=sgSpawnProt(injured.FindInventoryType(class's gSpawnProt'));
if (sgSP != None )
{
//instigatedBy.TakeDamage(damage, instigatedBy, instigatedBy.Location, vect(0,0,0), 'exploded');
sMessage="Player "@[email protected]" is spawn protected.";
AnnounceToPawn(instigatedBy,sMessage);
return 0;
}
}
else
{
sgSP=sgSpawnProt(instigatedBy.FindInventoryType(cl ass'sgSpawnProt'));
if ( sgSP != None )
sgSP.DisableProt();
}
}
}

damage = Super.ReduceDamage(damage, damageType, injured, instigatedBy);

//Building related
if ( sgBuilding(injured) != none )
{
if ( sgBaseCore(injured) != None )
{
if ( bPlayerInstigated &&
(SniperRifle(instigatedBy.Weapon) != None ||
Ripper(instigatedBy.Weapon) != None) &&
VSize(injured.Location - instigatedBy.Location) >
MaxCoreSnipeDistance )
return damage / 10;
}
else
{
if ( bPlayerInstigated && (sgBuilding(injured).Team != instigatedBy.PlayerReplicationInfo.Team) )
sgPRI(instigatedBy.PlayerReplicationInfo).sgInfoBu ildingHurt += damage;
}
}
//Non-building related
else
{
if ( (DamageType == 'sgSpecial') && (Injured.Health - Damage <= 10) )
{
injured.Health = 10;
return 0;
}
}
return damage;
}

EDIT:
The server log sizes will greatly decrease now, that will speed it up since less disk write operations will be made, and it will flush the logs on map change at greater speeds.
This will speedup map loading.