Game Development Reference
In-Depth Information
Again, if we were to reverse this path, getting the Armor first, the data would be:
Leg
Time
Rate
Damage
Health Added
Net
Cover to Armor
7
2
-14
Armor to Health Kit
8
1
-8
+85
Health Kit to Cover
3
1
-3
Total
-
-
-25
+85
+60
By adding this one simple factor, we have reversed our original decision. If we
had proceeded on our original route of getting the Armor first, we still would have
taken 25 damage points over that time. However, the Health Kit that was worth 100
when we started was only worth 85 by the time we reached it 15 seconds later. Our
net gain for the three legs of the triangle would be 60. On the other hand, when we
go to get the Health Kit first, it only loses 3 points, down to 97. We still take 29
points of damage from fire during our brief stroll, but we end up with a net of 68
points greater than when we started.
In this example, if we were to only consider the (very relevant) factor that it is
better to be wearing armor when running out in front of enemy fire, we would have
decided to get the Armor first—and we would have been worse off in the end.
However, by recognizing the fact that the utility of time counts in two ways, we were
able to make the correct decision.
P UTTING I TIN C ODE
To reflect the fact that the value of the Health Kit is not static, we need to simply
replace the line where we added the Health Kit with a call to a function. This function
acts much the same way as our damage function does.
int MyGame::HealthKitValue( int Time, int Rate )
{
int HealthKitEndingValue;
// Calculate the ending value of the Health Kit
HealthKitEndingValue = mHealthKitValue - ( Time * Rate );
// A Health Kit can never be less than 0
if ( HealthKitEndingValue < 0 ) HealthKitEndingValue = 0;
return HealthKitEndingValue;
}
Search WWH ::




Custom Search