Exemplo n.º 1
0
        public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionBuilding(Tower);
            d.SetActionTower(Tower);

            return new MoveToTower();
        }
 public override Selector ActivateBehavior(Dwarf d)
 {
     DwarfConsole.WriteLine("Move crafted task taken: " + Obj.ElementType + " - dwarf: " +d.Id, ConsoleColor.Red);
     d.SetActionBuilding(CraftBuilding);
     d.SetActionWorldObject(Obj);
     return new MoveCraftToDepot(CraftBuilding);
 }
 public override Selector ActivateBehavior(Dwarf d)
 {
     d.SetActionBuilding(GeneratorBuilding);
     d.SetActionLevel(1);
     d.SetActionMapElementType(Map.MapElementType.Coal);
     return new GetCoal();
 }
Exemplo n.º 4
0
        public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionMapElementType(Type);
            d.SetActionBuilding(Building);
            d.SetActionLevel(Level);

            return new GetBuildingMaterial(Building, this);
        }
        private TaskState FindDepot(Dwarf d, float dt, double dtd)
        {
            if (State == TaskState.NotActive)
            {
                List<BuildingRequest> depoesCandidates = new List<BuildingRequest>();

                List<Building> depos = WorldMap.Instance.GetDepos(d.GetActionMapElementType(), d.GetActionLevel());
                foreach (Building b in depos)
                {
                    depoesCandidates.Add(new BuildingRequest() { Building = b, TypeToGet = d.GetActionMapElementType(), Level = d.GetActionLevel() });
                }

                // If no depot exist that has the required materials, the behavier fails
                if (depoesCandidates.Count == 0)
                {
                    if (_pwo == null)
                        return TaskState.Fail;

                    if (_pwo.HasRequestedConstructionOfNeededItem == true)
                        return TaskState.Fail;

                    TaskManager.AddTask(new CraftingOfResourceTask(d.GetActionMapElementType(), d.GetActionLevel()));
                    _pwo.HasRequestedConstructionOfNeededItem = true;

                    return TaskState.Fail;
                }

                foreach (BuildingRequest b in depoesCandidates)
                {
                    AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), b.Building.GetActivationPoint(), b);
                    _numerOfPaths++;
                }
            }

            _paths.AddRange(AsyncPathfinding.GetFinishedPathsWithData(d));

            if (_paths.Count > _numerOfPaths)
            {

            }

            if (_numerOfPaths != _paths.Count)
                return TaskState.Running;

            PathfindingResult shortestPath = Path.ShortestPath(_paths);

            d.SetActionBuilding(((BuildingRequest)shortestPath.Data).Building);
            d.SetActionMapElementType(((BuildingRequest)shortestPath.Data).TypeToGet);
            d.SetActionLevel(((BuildingRequest)shortestPath.Data).Level);
            d.SetMovePath(shortestPath.Path);

            return TaskState.Success;
        }
Exemplo n.º 6
0
        private TaskState FindDepot(Dwarf d, float dt, double dtd)
        {
            if (State == TaskState.NotActive)
            {
                List<BuildingRequest> depoesCandidates = new List<BuildingRequest>();

                List<Building> depos = WorldMap.Instance.GetDeposWithFood();
                foreach (Building b in depos)
                {
                    depoesCandidates.Add(new BuildingRequest() { Building = b, TypeToGet = MapElementType.None, Level = 1 });
                }

                // If no depot exist that has the required food, the behavier fails
                if (depoesCandidates.Count == 0)
                {
                    return TaskState.PersonalFail;
                }

                foreach (BuildingRequest b in depoesCandidates)
                {
                    AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), b.Building.GetActivationPoint(), b);
                    _numerOfPaths++;
                }
            }

            _paths.AddRange(AsyncPathfinding.GetFinishedPathsWithData(d));

            if (_paths.Count > _numerOfPaths)
            {

            }

            if (_numerOfPaths != _paths.Count)
                return TaskState.Running;

            PathfindingResult shortestPath = Path.ShortestPath(_paths);
            BuildingRequest br = (BuildingRequest)shortestPath.Data;

            WorldObject reservedFood = br.Building.ReserveAnyFood();

            if (reservedFood == null)
                return TaskState.PersonalFail;

            d.SetActionWorldObject(reservedFood);
            d.SetActionBuilding(br.Building);
            d.SetMovePath(shortestPath.Path);

            return TaskState.Success;
        }
        private TaskState Pickup(Dwarf d, float dt, double dtd)
        {
            WorldObject m = d.GetActionbuilding().WithdrawWorldObject(d.GetActionMapElementType(), d.GetActionLevel());

            if (m == null)
                return TaskState.Fail;

            if (m.RegisteredForConsumption == true)
            {
                //throw new Exception("");
            }

            if (m.ElementType == MapElementType.Plank)
                DwarfDebugInfo.PlanksPickedUp++;

            d.CarryWorldObject(m);
            d.SetActionBuilding(d.GetPrevActionBuilding());
            return TaskState.Success;
        }
Exemplo n.º 8
0
        private TaskState Find(Dwarf d, float dt, double dtd)
        {
            List<Building> depots = WorldMap.Instance.GetBuildings(BuildingType.Depot);

            if (State == TaskState.NotActive)
            {
                if (depots.Count == 0)
                    return TaskState.Fail;

                foreach (Building b in depots)
                {
                    AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), b.GetActivationPoint(), null);
                    _numerOfPaths++;
                }
            }

            _paths.AddRange(AsyncPathfinding.GetFinishedPaths(d));

            if (_numerOfPaths != _paths.Count)
                return TaskState.Running;

            Path shortestPath = Path.ShortestPath(_paths);
            Building depot = null;

            foreach (Building b in depots)
            {
                Point p = b.GetActivationPoint();
                // TODO: This is bad. Use the object parameter on RequestPathfinding to solve
                if (p.X == shortestPath.GetEndPoint().X && p.Y == shortestPath.GetEndPoint().Y)
                {
                    depot = b;
                }
            }

            if (depot == null)
                throw new Exception("Depot not found.. It should be there");

            d.SetActionBuilding(depot);
            d.SetMovePath(shortestPath);

            return TaskState.Success;
        }
 private TaskState Set(Dwarf d, float dt, double dtd)
 {
     d.SetActionBuilding(d.GetActionTower());
     return TaskState.Success;
 }
Exemplo n.º 10
0
        public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionBuilding(Building);

            return new BuildBuilding(Building, this);
        }
Exemplo n.º 11
0
        public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionBuilding(WorldMap.Instance.GetTradingStation());

            return new MoveToTrader();
        }
Exemplo n.º 12
0
 public override Selector ActivateBehavior(Dwarf d)
 {
     d.SetActionBuilding(Building);
     return new MoveToFortress();
 }
Exemplo n.º 13
0
        private TaskState FindPath(Dwarf d, float dt, double dtd)
        {
            if (d.GetActionMapElementType() == MapElementType.Meal)
            {

            }
            if (State == TaskState.NotActive)
            {
                //List<Building> craftingBuildings = WorldMap.Instance.GetCraftingBuildings(d.GetActionMapElementType());

                //if (d.GetActionMapElementType() == MapElementType.Arrow)
                //{

                //}

                //foreach (Building b in craftingBuildings)
                //{
                //    if (_cot.AssignedWorkshop != null && b != _cot.AssignedWorkshop)
                //        continue;

                Building b = d.AssignedWorkBuilding;

                if (b.IsCraftingItem() == false ||
                    //b.IsTakenByDwarf(d, d.GetActionMapElementType()) == true ||
                    (b.IsCraftingItem() == true && b.HasADwarfWorkingOnItem() == false && b.TypeThatIsBeingCrafted() == d.GetActionMapElementType()))
                {
                    AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), b.GetActivationPoint(), b);
                    _numerOfPaths++;

                }
                else
                {
                    DwarfConsole.WriteLine("DWARF TRIED TO TAKE CRAFTING BUILD, BUT WAS ALREADY IN USE. THIS SHOULD HAPPEN RARELY", ConsoleColor.DarkRed);
                    //Debugger.Break();
                    return TaskState.Fail;
                }

                // If no crafting building that can be used
                if (_numerOfPaths == 0)
                {
                    return TaskState.Fail;
                }

            }

            _paths.AddRange(AsyncPathfinding.GetFinishedPathsWithData(d));

            if (_numerOfPaths != _paths.Count)
                return TaskState.Running;

            PathfindingResult shortestPath = Path.ShortestPath(_paths);

            Building bb = (Building)shortestPath.Data;

            // If the crafting building was taken by another dwarf while we where calculating paths.
            if (bb.HasADwarfWorkingOnItem() == true)
                return TaskState.SmallFail;

            d.SetActionBuilding(bb);
            d.SetMovePath(shortestPath.Path);
            d.GetActionbuilding().TakeForCrafting(d, d.GetActionMapElementType());
            _cot.AssignedWorkshop = d.GetActionbuilding();

            return TaskState.Success;
        }
Exemplo n.º 14
0
        public override Selector ActivateBehavior(Dwarf d)
        {
            d.SetActionBuilding(Building);

            return new BikeGeneration();
        }