/// <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> /// Land a rescue plane /// </summary> /// <param name="aircraft"></param> public void landRescue(Aircraft aircraft) { scenario.FlyingAicrafts.Remove(aircraft); RescueAircraft rescue = (RescueAircraft)aircraft; aircraft.airport.Clients.Remove(rescue.client); scenario.ActiveClient.Remove(rescue.client); }
/// <summary> /// Move the aircraft /// </summary> /// <param name="aircraft"></param> public override void MoveAircraft(Aircraft aircraft) { //Calcul le deplacement en x et y de 1 tick de l'avion int destX = aircraft.destinationX; int destY = aircraft.destinationY; RescueAircraft rescueAircraft = (RescueAircraft)aircraft; FlyingState position = (FlyingState)rescueAircraft.CurrentState; double distance = Math.Sqrt((Math.Pow(destY - position.PosY, 2)) + (Math.Pow(destX - position.PosX, 2))); double tickRequired = distance / (rescueAircraft.Speed * 15); //Si le tick est plus grand que 1, deplacer l'avion if (tickRequired > 1) { double XbyTick = (destX - position.PosX) / tickRequired; double YbyTick = (destY - position.PosY) / tickRequired; position.PosX += Convert.ToInt32(XbyTick); position.PosY += Convert.ToInt32(YbyTick); }//Sinon, l'avion est arrivé else if (tickRequired < 1 && rescueAircraft.HasArrived == false) { HasArrived = true; position.PosX = destX; position.PosY = destY; aircraft.destinationX = aircraft.airport.X; aircraft.destinationY = aircraft.airport.Y; } else { if (aircraft is WaterBomber) // Si l'avion est un water bomber { if (airport.fireIsExtinct(aircraft)) // verifie su le feu est éteint { aircraft.CurrentState.ChangeState(aircraft); rescueAircraft.HasArrived = false; } else // si le feu n'est pas éteint, reduire son envergure { aircraft.airport.reduceFireSpan(aircraft); } } else { // sinon, changer son etat aircraft.CurrentState.ChangeState(aircraft); rescueAircraft.HasArrived = false; } } }
/// <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; } } } }