Game Development Reference
In-Depth Information
for ( ei = 0; ei < mpDudeCollection->GetSize(); ei++ ) {
pThisEnemy = mpDudeCollection->GetPointer( DUDE_TYPE(ei) );
for ( wi = 0; wi < mvWeapons.size(); wi++ ) {
ThisWeapon = mvWeapons[wi];
// Only consider loaded weapons
if ( ThisWeapon.Ammo > 0 ) {
ScoreTarget( pThisEnemy, ThisWeapon );
} // end if
} // end for
} // end for
}
We have also placed our call to ScoreTarget() inside an if statement that
checks to see if we have ammo for the selected weapon. If not, there is no need to
check it and add it to the list.
S ELECTING AN O PTION
At the end of ScoreAllTargets() , we have a list of all the possible attack combi-
nations. Selecting an option is a simple exercise at this point. Because we built our
scoring algorithm so that the lower the value, the better the option, we can logically
deduce that the target with the lowest score is the best option for us to select. We can
sort mvTargets of targets by the Score value so that the lowest value is at the
beginning of the vector. (Naturally, we could simply walk the list and make a note
of the lowest-scored item. I sort it here because doing so will come in handy in
Chapter 16.) We then set our target and weapon to the values held in that location.
The entire function for selecting a target is:
CDude* CAgent::SelectTarget()
{
ScoreAllTargets();
std::sort( mvTargets.begin(), mvTargets.end() );
 
Search WWH ::




Custom Search