/// <summary> /// Generate non airport client (fire,observer,alert) /// </summary> public void GeneratePositionableClient() { LastClient = new PositionableClient(); Rnd = new Random(DateTime.Now.Millisecond); int nbCall; //Observator LastClient = (PositionableClient)ClientFactory.CreateObserver(); AddClientToAirport(LastClient, 1); ActiveClient.Add(LastClient); //Fire LastClient = (PositionableClient)ClientFactory.CreateFire(); AddClientToAirport(LastClient, 2); ActiveClient.Add(LastClient); //ResuceTeam nbCall = Rnd.Next(1, 2); for (int i = 0; i < nbCall; i++) { LastClient = (PositionableClient)ClientFactory.CreateRescueTeam(); AddClientToAirport(LastClient, 3); ActiveClient.Add(LastClient); } }
/// <summary> /// Check if the fire is done /// </summary> /// <param name="aircraft"></param> /// <returns></returns> public bool fireIsExtinct(Aircraft aircraft) { RescueAircraft rescue = (RescueAircraft)aircraft; //Parcours les clients de l'aeroport for (int i = 0; i < rescue.airport.Clients.Count; i++) { if (rescue.airport.Clients[i] is PositionableClient) { PositionableClient posClient = (PositionableClient)rescue.airport.Clients[i]; //si le client correspond au client de l'avion, if (posClient == rescue.client) { Fire fireClient = (Fire)rescue.client; //Si le client a son fire span a 0, return true if (fireClient.FireSpan == 0) { return(true); } } } } return(false); }
/// <summary> /// Return the closest airport /// </summary> /// <param name="paramClient"></param> /// <param name="type"></param> /// <returns></returns> public Airport GetClosestAirport(PositionableClient paramClient, int type) { Airport closestAirport = new Airport(); int posX = paramClient.PosX; int posY = paramClient.PosY; double distance = 10000; for (int i = 0; i < Airports.Count; i++) { if ((Airports[i].hasObserverPlane() && type == 1) || (Airports[i].hasWaterBomber() && type == 2) || (Airports[i].hasRescueHelicopter() && type == 3)) { double newDistance = Math.Sqrt((Math.Pow(Airports[i].Y - posY, 2)) + (Math.Pow(Airports[i].X - posX, 2))); if (newDistance < distance) { distance = newDistance; closestAirport = Airports[i]; } } } return(closestAirport); }
/// <summary> /// Reduce the fire span of the client of the plane /// </summary> /// <param name="aircraft"></param> public void reduceFireSpan(Aircraft aircraft) { RescueAircraft rescue = (RescueAircraft)aircraft; //Parcours les aeroports for (int i = 0; i < rescue.airport.Clients.Count; i++) { if (rescue.airport.Clients[i] is PositionableClient) { PositionableClient posClient = (PositionableClient)rescue.airport.Clients[i]; //Si le client correspond au client de la list, reduire le fire span if (posClient == rescue.client) { Fire fireClient = (Fire)rescue.client; fireClient.FireSpan--; rescue.destinationX = fireClient.PosX; rescue.destinationY = fireClient.PosY; rescue.HasArrived = false; } } } }
/// <summary> /// Add the client to the airport client's list /// </summary> /// <param name="paramClient"></param> /// <param name="type"></param> private void AddClientToAirport(PositionableClient paramClient, int type) { closestAirport = GetClosestAirport(paramClient, type); closestAirport.Clients.Add(paramClient); }