Game Development Reference
In-Depth Information
values of goals A and B. In the final example, goal B was not only worth more but,
due to the 1% decay rate, was losing value four times as fast as goal A. In layman's
terms, we “didn't have time to waste� in dealing with the lesser objective of goal A.
So, as we can see, the time one spends in travel is a valuable commodity.
Similarly, the amount of time that may be spent in performing an activity also
needs to be considered. If we were in an RTS environment, for example, goals A
and B could be constructing buildings. Not only would the travel time to the loca-
tions need to be considered (such as we did above), but the time spent in the actual
building process would need to be added. The process is much the same—the only
difference being that we would have to include two more variables, one for the con-
struction time of each building.
P UTTING I TIN C ODE
Just as we did with the warranty and tower examples above, we can create a simple
utility function to calculate the utility values of accomplishing the goals at various
times. In this case, we can create a function, GoalUtility() , that calculates the
utility of a particular goal. This is based on the value of the goal itself, the time spent
traveling to the goal, and the decay rate at which the goal value will be reduced over
that time. This function is the business end of the process in that it is the sole place
where the utility of the goals is being calculated.
int MyGame::GoalUtility( int ValGoal, // value of the goal
int Time, // time to the goal
float Decay ) // decay rate %
{
// Calculate utility of a goal based on the value of the
// goal, the time traveled to get to it,
// and the decay rate
int Utility; // Temporary local utility value
// Utility is the value of the goal reduced by however
// much the value decays during the time over which
// the distance is traveled
Utility = ValGoal * ( 1.0 - ( Time * Decay ) );
Search WWH ::




Custom Search