Game Development Reference
In-Depth Information
// Clamp negative urgency to 0
if ( Urgency < 0.0 ) {
Urgency = 0.0;
} // end if
return Urgency;
}
Once we have
ThreatRatio
and
Urgency
, we proceed with building the infor-
mation about this target. Remember that
sTARGET_INFO
represents a combination
of a Dude and a weapon that we are scoring for comparison purposes. We create a
new instance of
sTARGET_INFO
, set the appropriate Dude and weapon information,
and then save the score using the simple equation we decided on above.
ThisTarget.Score = ThreatRatio / Urgency;
We then push it onto the list of targets and exit the function. That is the entire
process for scoring the utility of attacking one of our enemies with one of our
weapons.
Of course, we need to repeat
ScoreTarget()
for each of the enemies we face and
for each of the weapons we carry. If we are facing three Dudes and have four
weapons available to us, we have 12 options to score. By looping through the two
lists, we can call
ScoreTarget()
for each of the 12 combinations.
void CAgent::ScoreAllTargets()
{
sWEAPON_INFO ThisWeapon;
CDude* pThisEnemy;
USHORT ei, wi; // loop indexes
mvTargets.empty(); // start with a fresh list of targets