Beispiel #1
0
 /// <summary>
 /// Called by a slave to pass a Airplane from the slave to another slave
 /// </summary>
 /// <param name="airplane">The Airplane to pass</param>
 /// <param name="airportID"></param>
 public void PassPlane(Airplane airplane, int airportID)
 {
     try
     {
         m_airports.Find(x => x.airportID == airportID).slaveCallback.AddPlane(airplane);
     }
     catch (Exception exception)
     {
         System.Console.WriteLine(exception.Message);
         try
         {
             foreach (Airport a in m_airports)
             {
                 a.slaveCallback.Reset();
             }
         }
         catch (Exception e)
         {
             System.Console.WriteLine(e.Message);
         }
         Initialise();
     }
 }
 /// <summary>
 /// Do not call: Not implemented
 /// </summary>
 /// <param name="plane"></param>
 public void AddPlane(Airplane plane)
 {
     throw new NotImplementedException("You called a function designed for a slave in the GUI");
 }
        /// <summary>
        /// Step 15 mins forward for a plane that is queued (incoming)
        /// </summary>
        /// <param name="airplane"></param>
        private void PlaneQueuedStep(Airplane airplane)
        {
            airplane.simTime = airplane.simTime + 15;

            //don't do anything is the plane is crashed
            if (airplane.state != PlaneState.Crashed)
            {
                //update the distance travelled
                airplane.distanceAlongRoute = airplane.distanceAlongRoute + airplane.cruisingKPH * 0.25;

                //check if you are circling
                if (airplane.currentAirRoute.distanceKM - airplane.distanceAlongRoute < 0.0)
                {
                    airplane.distanceAlongRoute = airplane.currentAirRoute.distanceKM;
                    airplane.state = PlaneState.Circling;
                }

                //update the fuel
                airplane.fuel = airplane.fuel - airplane.fuelConsPerHour * 0.25;

                //check if you are out of fuel (therefore crashed)
                if (airplane.fuel < 0)
                {
                    airplane.fuel = 0;
                    airplane.state = PlaneState.Crashed;
                }
            }
        }
 /// <summary>
 /// Updates a plane's state to take off and moves it into the departed queue
 /// </summary>
 /// <param name="airplane">the airplane that is taking off</param>
 private void TakeOff(Airplane airplane)
 {
     //pick the next route, update the airplane object and switch it into the departed queue
     airplane.simTime = airplane.simTime + 15;
     AirRoute route = m_Airport.DepartingRouteList.Peek();
     m_Airport.DepartingRouteList.Enqueue(m_Airport.DepartingRouteList.Dequeue());
     airplane.fuel = (route.distanceKM / airplane.cruisingKPH) * airplane.fuelConsPerHour * 1.15;
     airplane.distanceAlongRoute = 0;
     airplane.timeLanded = -1;
     airplane.currentAirRoute = route;
     airplane.currentAirRouteID = route.airRouteID;
     airplane.state = PlaneState.InTransit;
     airplane.currentAirportID = -1;
 }
 /// <summary>
 /// Step 15 mins forward for a plane that has landed
 /// </summary>
 /// <param name="airplane"></param>
 private void PlaneLandedStep(Airplane airplane)
 {
     //check to make sure plane isn't ahead, and the increment timeLanded
     if (airplane.simTime == m_SimTime)
     {
         airplane.timeLanded = airplane.timeLanded + 15;
         airplane.simTime = airplane.simTime + 15;
     }
 }
        /// <summary>
        /// Step 15 mins forward for a plane that has departed (outgoing)
        /// </summary>
        /// <param name="airplane">The plane to step forward</param>
        private void PlaneDepartedStep(Airplane airplane)
        {
            //add 15 minutes to the simulation clock of the plane
            airplane.simTime = airplane.simTime + 15;

            //update the distance travelled and remaining fuel
            airplane.distanceAlongRoute = airplane.distanceAlongRoute + airplane.cruisingKPH * 0.25;
            airplane.fuel = airplane.fuel - airplane.fuelConsPerHour * 0.25;

            //check if we need to transfer to another slave/airport
            if (airplane.currentAirRoute.distanceKM - airplane.distanceAlongRoute <= 300.00)
            {
                airplane.state = PlaneState.Entering;
                m_ATCMaster.PassPlane(airplane, airplane.currentAirRoute.toAirportID);
            }
        }
        public void AddPlane(Airplane airplane)
        {
            //add a reference to the plane's route
            airplane.currentAirRoute = m_Airport.IncomingRouteList.Find(x => x.airRouteID == airplane.currentAirRouteID);

            //check if the plane has entered circling, if so then change the state
            if (airplane.currentAirRoute.distanceKM - airplane.distanceAlongRoute < 0.0)
            {
                airplane.distanceAlongRoute = airplane.currentAirRoute.distanceKM;
                airplane.state = PlaneState.Circling;
            }

            //check if the plane has run out of fuel and crashed, if so then change the state
            if (airplane.fuel < 0)
            {
                airplane.fuel = 0;
                airplane.state = PlaneState.Crashed;
            }

            //add the plane to the queued (incoming) plane list
            m_Airport.planeQueuedList.Add(airplane);
        }
 /// <summary>
 /// Called by a slave to pass a Airplane from the slave to another slave
 /// </summary>
 /// <param name="airplane">The Airplane to pass</param>
 /// <param name="airportID"></param>
 public void PassPlane(Airplane airplane, int airportID)
 {
     try
     {
         m_airports.Find(x => x.airportID == airportID).slaveCallback.AddPlane(airplane);
     }
     catch (Exception exception)
     {
         System.Console.WriteLine(exception.Message);
         try
         {
             foreach (Airport a in m_airports)
             {
                 a.slaveCallback.Reset();
             }
         }
         catch (Exception e)
         {
             System.Console.WriteLine(e.Message);
         }
         Initialise();
     }
 }