Graphics Reference
In-Depth Information
The race controller instance held by tempRC is taken from the Hashtable based on
the value of b from the loop, which means eventually tempRC will hit upon the same
RaceController instance as the one held by focusPlayerScript. Before any position or way-
point checking can happen, the script compares the IDs of focusPlayerScript and tempRC to
make sure that they are not the same:
if ( focusPlayerScript.GetID() != tempRC.GetID() )
{ // <-- make sure we're not trying to compare same objects!
There are several conditions we test against to find out whether the player within
focusPlayerScript is ahead of the one that the loop is currently looking at.
The first condition is whether the current lap of the focused player is higher than the lap
of the race controller in tempRC—if it is, we know that focusPlayerScript is ahead of tempRC:
// is the focussed player a lap ahead?
if ( focusPlayerScript.GetCurrentLap() >
tempRC.GetCurrentLap() )
isAhead = true;
The next condition checks to see whether the current lap of the focused player is the
same as the lap of the race controller in tempRC. If they are both on the same lap, we look
to the waypoints to see whether the focusPlayerScript waypoint index number is greater
than that of tempRC. If it is, we know that focusPlayerScript is ahead of tempRC because
its waypoint is further along the track, in which case, isAhead is set to true:
// is the focussed player on the same lap, but at a higher
// waypoint number?
if ( focusPlayerScript.GetCurrentLap() ==
tempRC.GetCurrentLap() &&
focusPlayerScript.GetCurrentWaypointNum() > tempRC.
GetCurrentWaypointNum() && !tempRC.IsLapDone() )
isAhead = true;
The third condition checks that focusPlayerScript and tempRC are on the same lap as
well as on the same waypoint. From there, it checks to see whether the distance between
focusPlayerScript and its target waypoint is less than tempRC's distance to its waypoint. If
focusPlayerScript is closer to its waypoint (which is the same waypoint as tempRC) and tem-
pRC has not finished its lap, then we know that focusPlayerScript must be ahead, and the
script can go ahead, and set isAhead to true. Note that IsLapDone() is checked on the tempRC
object because its distance may be off when the waypoint has switched over to the next lap:
// is the focussed player on the same lap, same waypoint,
// but closer to it?
if ( focusPlayerScript.GetCurrentLap() ==
tempRC.GetCurrentLap() &&
focusPlayerScript.GetCurrentWaypointNum() == tempRC.GetCurrentWaypointNum()
&& focusPlayerScript.GetCurrentWaypointDist() <
tempRC.GetCurrentWaypointDist() && !tempRC.IsLapDone() )
isAhead = true;
The fourth condition checks that both players are on the same lap and on the same
waypoint, but this time looks to see whether the focus player has registered a lap done
Search WWH ::




Custom Search