コード例 #1
0
 public int GetCurrentLap()
 {
     return(raceControl.GetCurrentLap());
 }
コード例 #2
0
    public int GetPosition(int ofWhichID)
    {
        // first, let's make sure that we are ready to go (the hashtables may not have been set up yet, so it's
        // best to be safe and check this first)
        if (raceControllers == null)
        {
            Debug.Log("GetPosition raceControllers is NULL!");
            return(-1);
        }

        if (raceControllers.ContainsKey(ofWhichID) == false)
        {
            Debug.Log("GetPosition says no race controller found for id " + ofWhichID);
            return(-1);
        }

        // first, we need to find the player that we're trying to calculate the position of
        focusPlayerScript = (RaceController)raceControllers[ofWhichID];

        // start with the assumption that the player is in last place and work up
        myPos = numberOfRacers;

        // now we step through each racer and check their positions to determine whether or not
        // our focussed player is in front of them or not
        for (int b = 1; b <= numberOfRacers; b++)
        {
            // assume that we are behind this player
            isAhead = false;

            // grab a temporary reference to the 'other' player we want to check against
            tempRC = (RaceController)raceControllers [b];

            // if car 2 happens to be null (deleted for example) here's a little safety to skip this iteration in the loop
            if (tempRC == null)
            {
                continue;
            }

            if (focusPlayerScript.GetID() != tempRC.GetID())
            { // <-- make sure we're not trying to compare same objects!
                // is the focussed player a lap ahead?
                if (focusPlayerScript.GetCurrentLap() > tempRC.GetCurrentLap())
                {
                    isAhead = 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;
                }

                // 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;
                }

                // has the player completed a lap and is getting ready to move onto the next one?
                if (focusPlayerScript.GetCurrentLap() == tempRC.GetCurrentLap() && focusPlayerScript.GetCurrentWaypointNum() == tempRC.GetCurrentWaypointNum() && (focusPlayerScript.IsLapDone() == true && tempRC.IsLapDone() == false))
                {
                    isAhead = true;
                }

                if (focusPlayerScript.GetCurrentLap() == tempRC.GetCurrentLap() && (focusPlayerScript.IsLapDone() == true && !tempRC.IsLapDone()))
                {
                    isAhead = true;
                }

                if (isAhead)
                {
                    myPos--;
                }
            }
        }

        return(myPos);
    }