Ejemplo n.º 1
0
        /// <summary>
        /// Gets the race place for an agent
        /// </summary>
        /// <param name="agent">The agent</param>
        /// <returns>what place the agent is in (1st,2nd, 3rd...)</returns>
        public string GetAgentPlace(AircraftAgent agent)
        {
            int place = aircraftStatuses[agent].place;

            if (place <= 0)
            {
                return(string.Empty);
            }

            if (place >= 11 && place <= 13)
            {
                return(place.ToString() + "th");
            }
            switch (place % 10)
            {
            case 1:
                return(place.ToString() + "st");

            case 2:
                return(place.ToString() + "nd");

            case 3:
                return(place.ToString() + "rd");

            default:
                return(place.ToString() + "th");
            }
        }
        /// <summary>
        /// Resets the position of an agent using it's current current NextCheckPointIndex
        /// unless randomize is true, then will pick a new random checkpoint
        /// </summary>
        /// <param name="agent">The agent to reset</param>
        /// <param name="randomize">If true, will choose a NextCheckPointIndex before reset</param>
        public void ResetAgentPosition(AircraftAgent agent, bool randomize = false)
        {
            if (randomize)
            {
                // Pick a new NextCheckPointIndex at random
                agent.NextCheckpointIndex = Random.Range(0, Checkpoints.Count);
            }

            // set start position to the previous checkpoint
            int previousCheckPointIndex = agent.NextCheckpointIndex - 1;

            if (previousCheckPointIndex == -1)
            {
                previousCheckPointIndex = Checkpoints.Count - 1;
            }

            float startPosition = racePath.FromPathNativeUnits(previousCheckPointIndex, CinemachinePathBase.PositionUnits.PathUnits);

            // Convert the position on the race path to a position in 3d space
            Vector3 basePosition = racePath.EvaluatePosition(startPosition);

            // Get the orientation at that position on the race path
            Quaternion orientation = racePath.EvaluateOrientation(startPosition);

            // Calculate horizontal offset so that agents are spread out
            Vector3 positionOffset = Vector3.right * (AircraftAgents.IndexOf(agent) - AircraftAgents.Count / 2f)
                                     * UnityEngine.Random.Range(8f, 10f);

            // set the aircraft position and rotation
            agent.transform.position = basePosition + orientation * positionOffset;
            agent.transform.rotation = orientation;
        }
Ejemplo n.º 3
0
        //<summary>
        //Resets agent posiiton if they crash using its current Next checkpoint Index
        //If randomize is true it resets the plane at  a random checkpoint
        //</summary>
        public void ResetAgentPosition(AircraftAgent agent, bool randomize = false)
        {
            if (randomize)
            {
                //Picka a new next checkpoint at  random
                agent.NextCheckpointIndex = Random.Range(0, Checkpoints.Count);
            }

            //Set start position to the previous checkpoint
            int previousCheckpointIndex = agent.NextCheckpointIndex - 1;

            if (previousCheckpointIndex == -1)
            {
                previousCheckpointIndex = Checkpoints.Count - 1;
            }

            float startPosition = racePath.FromPathNativeUnits(previousCheckpointIndex, CinemachinePathBase.PositionUnits.PathUnits);

            //Convert the position on the race path to a position in 3d space;
            Vector3 basePosition = racePath.EvaluatePosition(startPosition);

            //Get orientation at that position oin the race path
            Quaternion orientation = racePath.EvaluateOrientation(startPosition);

            //Calculate a horizontal offset so that agents are spread out
            //Calcualtes based on number of agents and current agent how far away another agent needs to spawn
            //Make it random so that the game isnt exactly the same
            Vector3 positionOffset = Vector3.right * (AircraftAgents.IndexOf(agent) - AircraftAgents.Count / 2f)
                                     * UnityEngine.Random.Range(5f, 10f);

            //Set the aircraft position and rotation
            agent.transform.position = basePosition + orientation * positionOffset;
            agent.transform.rotation = orientation;
        }
        /// <summary>
        /// Compares the race place (i.e. 1st, 2nd, 3rd, etc)
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns>-1 if a is before b, 0 if equal, 1 if b is before a</returns>
        private int PlaceCompare(AircraftAgent a, AircraftAgent b)
        {
            AircraftStatus statusA     = aircraftStatuses[a];
            AircraftStatus statusB     = aircraftStatuses[b];
            int            checkPointA = statusA.checkpointIndex + (statusA.lap - 1) * aircraftArea.Checkpoints.Count;
            int            checkPointB = statusB.checkpointIndex + (statusB.lap - 1) * aircraftArea.Checkpoints.Count;

            if (checkPointA == checkPointB)
            {
                // Compare distance to the next checkpoint
                Vector3 nextCheckpointPosition = GetAgentNextCheckpoint(a).position;
                int     compare = Vector3.Distance(a.transform.position, nextCheckpointPosition)
                                  .CompareTo(Vector3.Distance(b.transform.position, nextCheckpointPosition));
                return(compare);
            }
            else
            {
                // Compare number of checkpoints hit
                // The agent with more checkpoints is
                // ahead (lower place), so we flip the compare

                int compare = -1 * checkPointA.CompareTo(checkPointB);
                return(compare);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Get the agents lap
 /// </summary>
 /// <param name="agent">The Agent</param>
 /// <returns>The lap the agent is on</returns>
 public int getAgentLap(AircraftAgent agent)
 {
     return(aircraftStatuses[agent].lap);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Get the agents next checkpoints transform
 /// </summary>
 /// <param name="a">The agent</param>
 /// <returns>returns the transform of the next checkpoint the agent should got to</returns>
 public Transform GetAgentNextCheckpoint(AircraftAgent agent)
 {
     return(aircraftArea.Checkpoints[aircraftStatuses[agent].checkpointIndex].transform);
 }
Ejemplo n.º 7
0
 public float GetAgentTime(AircraftAgent agent)
 {
     return(aircraftStatuses[agent].timeRemaining);
 }