Game Development Reference
In-Depth Information
We overload the
<
operator for the
std::sort
algorithm because we have to
explain to the compiler that we are sorting by a particular member of the
sTARGET_INFO
(specifically,
Score
).
Rather than list the entire header file here and spoil the surprise, we will look only
at a few key items of
CAgent
. First, there are no surprises in the member variables.
USHORT mHealth; // Current Health
USHORT mLocation; // Current Location in 1D
TARGET_LIST mvTargets; // List of available targets
WEAPON_LIST mvWeapons; // List of available weapons
CDude* mpCurrentTarget; // Current target to attack
WEAPON_TYPE mCurrentWeapon; // Current weapon to use
We have defined two member list variables—one for our current targets and
one for our current weapons.
When the agent needs the distance to a selected enemy, we call the function
GetDistToTarget( CDude* pTarget )
The implementation is simply
USHORT CAgent::GetDistToTarget(CDude *pTarget)
{
USHORT Dist = abs( mLocation - pTarget->GetLocation() );
return Dist;
}
The constructor for
CAgent
sets
mLocation = 0
and
mHealth = 100
. Its other
function is to initialize our weapons. We do this through the functions
InitWeapons()
and
AddWeapon()
.
void CAgent::InitWeapons()
{
AddWeapon( WEAPON_PISTOL, 20 );
AddWeapon( WEAPON_MACHINEGUN, 100 );
AddWeapon( WEAPON_SHOTGUN, 10 );