Game Development Reference
In-Depth Information
GetAccuracy( pTarget->GetWeapon(),
Dist,
pTarget->GetPointer() );
double TimeToKillMe = TimeToKill( mHealth,
DamageITake,
EnemyAccuracy );
// Calculate threat ratio
double ThreatRatio = ( TimeToKillMe + ( 3 * TimeToKillEnemy ) ) / 4;
// Calculate target urgency based on proximity to the goal
double Urgency = CalcTargetUrgency( pTarget->GetDistToGoal() );
// Create and store the target information
sTARGET_INFO ThisTarget;
ThisTarget.pDude = pTarget;
ThisTarget.pWeapon = Weapon.pWeapon;
ThisTarget.Score = ThreatRatio / Urgency;
mvTargets.push_back( ThisTarget );
}
The function ScoreTarget() takes a pointer to a CDude and a weapon type as
its parameters. We will see where these come from in a moment.
The beginning of the function is familiar. First, we calculate the time it takes us
to kill the selected enemy. Second, we calculate the same information in the other
direction—the time it would take for the selected enemy to kill us. This is the portion
we addressed above. Immediately after that, however, we calculate ThreatRatio
according to the weighted average formula we defined earlier.
We then calculate the urgency of the target based on his distance from the
detonator. The function we call to do this is simple.
double CAgent::CalcTargetUrgency( USHORT Dist )
{
double Urgency = 1 - ( pow( Dist, 0.4) / 10);
Search WWH ::




Custom Search