예제 #1
0
        public int ExtinguishAll(Firefighter firefighter, Field destination)
        {
            int fireLevel = (int)((Room)destination).FireState;

            ((Room)destination).ExtinguishFire(fireLevel);

            return fireLevel * firefighter.ActionCosts[ActionName.ExtinguishToSmoke];
        }
예제 #2
0
        public List<ActionMenu> GenerateActions(Firefighter firefighter, Room destination)
        {
            Route route = CheapestRoute(firefighter, (Room)firefighter.Position, destination);

            List<ActionMenu> list = new List<ActionMenu>();

            if (firefighter.Position != destination && !AreAdjacent(firefighter.Position, destination))
                return list;

            //Move
            if (firefighter.Position != destination && AreAdjacent(firefighter.Position, destination))
            {
                int cost = firefighter.ActionCosts[ActionName.Move];

                if(firefighter.Carry == null)
                {
                    if(destination.FireState >= FireState.Fire)
                        cost *= 2;
                    if(cost <= firefighter.AP)
                    {
                        Action move = new Action(ActionName.Move, cost, () => { Jump(firefighter, destination); });
                        list.Add(move);
                    }
                }
                else if (firefighter.Carry != null && destination.FireState < FireState.Fire)
                {
                    cost *= 2;
                    if (cost <= firefighter.AP)
                    {
                        Action move = new Action(ActionName.Move, cost, () => { Jump(firefighter, destination); });
                        list.Add(move);
                    }
                }

            }

            //Extinguish

            Route subRoute = GetSubRoute(route);
            ActionMenu extinguish;

            if (destination.FireState == FireState.Smoke)
            {

                if(firefighter.Position != destination && !AreAdjacent(firefighter.Position, destination))
                {
                    extinguish = new Action(ActionName.SubmenuExtinguishing, subRoute.Cost + firefighter.ActionCosts[ActionName.ExtinguishToSmoke],
                        () => { GetMoveAction(subRoute).Perform(); ExtinguishSmoke(firefighter, destination); });
                }
                else
                {
                    extinguish = new Action(ActionName.SubmenuExtinguishing, firefighter.ActionCosts[ActionName.ExtinguishToSmoke],
                        () => { ExtinguishSmoke(firefighter, destination); });
                }

                if((extinguish as Action).Cost <= firefighter.AP)
                    list.Add(extinguish);
            }
            else if (destination.FireState >= FireState.Fire)
            {
                List<ActionMenu> extList = new List<ActionMenu>();
                Action toSmoke;
                Action all;

                if (firefighter.Position != destination && !AreAdjacent(firefighter.Position, destination))
                {
                    toSmoke = new Action(ActionName.ExtinguishToSmoke, subRoute.Cost + firefighter.ActionCosts[ActionName.ExtinguishToSmoke],
                        () => { GetMoveAction(subRoute).Perform(); ExtinguishSmoke(firefighter, destination); });
                    all = new Action(ActionName.ExtinguishAll, subRoute.Cost + firefighter.ActionCosts[ActionName.ExtinguishAll],
                        () => { GetMoveAction(subRoute).Perform(); ExtinguishAll(firefighter, destination); });
                }
                else
                {
                    toSmoke = new Action(ActionName.ExtinguishToSmoke, firefighter.ActionCosts[ActionName.ExtinguishToSmoke],
                        () => { ExtinguishSmoke(firefighter, destination); });
                    all = new Action(ActionName.ExtinguishAll, firefighter.ActionCosts[ActionName.ExtinguishAll],
                        () => { ExtinguishAll(firefighter, destination); });

                }
                if (all.Cost <= firefighter.AP)
                {
                    extList.Add(toSmoke);
                    extList.Add(all);
                    extinguish = new SubMenu(ActionName.SubmenuExtinguishing, extList);
                    list.Add(extinguish);
                }
                else if (toSmoke.Cost <= firefighter.AP)
                {

                    list.Add(toSmoke);
                }
            }

            //POI, HAZARD
            if(firefighter.Carry != null)
            {
                if(destination.FireState < FireState.Fire)
                {
                    Action put;
                    if (firefighter.Carry == Marker.Victim)
                    {
                        if (firefighter.Position != destination)
                        {
                            put = new Action(ActionName.PutPOI, route.Cost + firefighter.ActionCosts[ActionName.PutPOI],
                                () => { GetMoveAction(route).Perform(); PutPOI(firefighter, destination); });
                        }
                        else
                        {
                            put = new Action(ActionName.PutPOI, firefighter.ActionCosts[ActionName.PutPOI],
                                () => { PutPOI(firefighter, destination); });
                        }
                    }
                    else
                    {
                        if (firefighter.Position != destination)
                        {
                            put = new Action(ActionName.PutHazard, route.Cost + firefighter.ActionCosts[ActionName.PutHazard],
                                () => { GetMoveAction(route).Perform(); PutHazard(firefighter, destination); });
                        }
                        else
                        {
                            put = new Action(ActionName.PutPOI, firefighter.ActionCosts[ActionName.PutHazard],
                                () => { PutHazard(firefighter, destination); });
                        }
                    }
                    if(put.Cost <= firefighter.AP)
                        list.Add(put);
                }
            }
            else
            {

                if(destination.OnField[Marker.Victim] > 0)
                {
                    Action takePOI;
                    if (firefighter.Position != destination)
                    {
                        takePOI = new Action(ActionName.PickPOI, route.Cost + firefighter.ActionCosts[ActionName.PickPOI],
                            () => { GetMoveAction(route).Perform(); PickPOI(firefighter, destination); });
                    }
                    else
                    {
                        takePOI = new Action(ActionName.PickPOI, firefighter.ActionCosts[ActionName.PickPOI],
                            () => { PickPOI(firefighter, destination); });
                    }
                    if(takePOI.Cost <= firefighter.AP)
                        list.Add(takePOI);
                }

                if (destination.OnField[Marker.Hazard] > 0)
                {
                    Action takeHazard;
                    if (firefighter.Position != destination)
                    {
                        takeHazard = new Action(ActionName.PickHazard, route.Cost + firefighter.ActionCosts[ActionName.PickHazard],
                            () => { GetMoveAction(route).Perform(); PickHazard(firefighter, destination); });
                    }
                    else
                    {
                        takeHazard = new Action(ActionName.PickHazard, firefighter.ActionCosts[ActionName.PickHazard],
                            () => { PickHazard(firefighter, destination); });
                    }
                    if(takeHazard.Cost <= firefighter.AP)
                        list.Add(takeHazard);
                }

            }
            return list;
        }
예제 #3
0
        public int ExtinguishSmoke(Firefighter firefighter, Field destination)
        {
            ((Room)destination).ExtinguishFire(1);

            return firefighter.ActionCosts[ActionName.ExtinguishToSmoke];
        }
예제 #4
0
        public int PutPOI(Firefighter firefighter, Field destination)
        {
            if(firefighter.Carry != null && firefighter.Carry == Marker.Victim)
            {
                firefighter.Carry = null;

                return firefighter.ActionCosts[ActionName.PutPOI];
            }

            return 0;
        }
예제 #5
0
        private Route CheapestRoute(Firefighter firefigher, Room start, Room end)
        {
            int cost = 1;
            List<Room> steps = new List<Room>();
            List<Door> doors = new List<Door>();

            steps.Add(start);

            //To DO: Znaleźć drogę. Każdy ruch pomiędzy sąsiednimi polami dodać do steps, a jego koszt do cost.

            steps.Add(end);
            //Koniec - przypisanie i zwrócenie wyniku;
            Route route = new Route();
            route.Steps = steps;
            route.Doors = doors;
            route.Cost = cost;
            route.Firefighter = firefigher;

            return route;
        }
예제 #6
0
 public int PickPOI(Firefighter firefighter, Field destination)
 {
     if((destination as Room).OnField[Marker.Victim] > 0 && firefighter.Carry == null)
     {
         firefighter.Carry = Marker.Victim;
         return firefighter.ActionCosts[ActionName.PickPOI];
     }
     return 0;
 }
예제 #7
0
        public int PutHazard(Firefighter firefighter, Field destination)
        {
            if (firefighter.Carry != null && firefighter.Carry == Marker.Hazard)
            {
                firefighter.Carry = null;

                return firefighter.ActionCosts[ActionName.PutHazard];
            }

            return 0;
        }
예제 #8
0
 public int PickHazard(Firefighter firefighter, Field destination)
 {
     if ((destination as Room).OnField[Marker.Hazard] > 0 && firefighter.Carry == null)
     {
         firefighter.Carry = Marker.Hazard;
         return firefighter.ActionCosts[ActionName.PickHazard];
     }
     return 0;
 }
예제 #9
0
        public int Move(Firefighter firefighter, Field destination)
        {
            if (!(destination is Room))
                return 0;

            if (!AreAdjacent (firefighter.Position, destination))
                return 0;

            int cost = firefighter.ActionCosts [ActionName.Move];
            if (((Room)destination).FireState == FireState.Fire) {
                cost *= 2;
            }

            firefighter.Position = destination;
            IdentifyPOI(firefighter, destination);

            return cost;
        }
예제 #10
0
        public void Jump(Firefighter ff, Room destination)
        {
            Room start = ff.Position as Room;

            start.TakeFirefighter(ff);

            destination.PutFirefighter(ff);

            ff.Position = destination;

            IdentifyPOI(ff, destination);
        }
예제 #11
0
        //TO DO: Rest;
        public int IdentifyPOI(Firefighter firefighter, Field destination)
        {
            if(firefighter.Position == destination && (destination is Room) && (destination as Room).OnField[Marker.UncoveredPoi] > 0)
            {
                (destination as Room).TakeMarker(Marker.UncoveredPoi);
                Random r = new Random();
                int chance = r.Next(3);
                if(chance == 2 && GameValues.FalseAlarms > 0)
                {
                    return 0;
                }

                (destination as Room).PutMarker(Marker.Victim);

                return firefighter.ActionCosts[ActionName.IdentifyPOI];
            }
            return 0;
        }
예제 #12
0
        public int GetMoveCost(Firefighter firefighter, Room start, Room end)
        {
            int oneStep = firefighter.ActionCosts[ActionName.Move];
            if(AreAdjacent(start, end))
            {
                if (firefighter.Carry != null) oneStep *= 2;
                if (end.FireState >= FireState.Fire) oneStep *= 2;
                return oneStep;
            }

            return oneStep; // (Math.Abs(start.Row - end.Row) + Math.Abs(start.Column - end.Column)) * firefighter.ActionCosts[ActionName.Move]
        }