Beispiel #1
0
        private TaskState FindPath(Dwarf d, float dt)
        {
            if (State == TaskState.NotActive)
            {
                RequestPathfinding(d.GetActionMapElement(), d);
            }

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

            if (_paths.Count != _numberOfPathRequests)
                return TaskState.Running;
            else
            {
                Path shortest = Path.ShortestPath(_paths);

                if (shortest == null)
                    return TaskState.Fail;
                else
                {
                    d.SetMovePath(shortest);
                    return TaskState.Success;
                }

            }
        }
Beispiel #2
0
        private TaskState Find(Dwarf d, float dt)
        {
            if (State == TaskState.NotActive)
            {

                    AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), new Point((int)d.GetActionVector().X, (int)d.GetActionVector().Y), null);
                    _numerOfPaths = 1;
            }

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

            if (_paths.Count > _numerOfPaths)
            {

            }

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

            PathfindingResult shortestPath = Path.ShortestPath(_paths);

            d.SetMovePath(shortestPath.Path);

            return TaskState.Success;
        }
        private TaskState FindPath(Dwarf d, float dt)
        {
            WorldObject m = d.GetActionWorldObject();

            if (State == TaskState.NotActive)
            {
                AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), new Point(m.Position.X, m.Position.Y), null);
            }

            List<Path> paths = AsyncPathfinding.GetFinishedPaths(d);
            if (paths.Count == 0)
                return TaskState.Running;
            else
            {
                if (paths[0] == null)
                    return TaskState.Fail;

                d.SetMovePath(paths[0]);

                Point p = paths[0].PathPoints[paths[0].PathPoints.Count - 1];

                if (p.X == m.Position.X && p.Y == m.Position.Y)
                {

                }
                else
                {

                }

                return TaskState.Success;
            }
        }
Beispiel #4
0
        private TaskState FindDepot(Dwarf d, float dt)
        {
            if (State == TaskState.NotActive)
            {
                List<BuildingRequest> depoesCandidates = new List<BuildingRequest>();

                List<Building> depos = WorldMap.Instance.GetDeposWithTool();
                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;

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

            return TaskState.Success;
        }
        private TaskState FindPath(Dwarf d, float dt)
        {
            if (State == TaskState.NotActive)
            {
                AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), d.GetActionbuilding().GetActivationPoint(), null);
            }

            List<Path> paths = AsyncPathfinding.GetFinishedPaths(d);
            if (paths.Count == 0)
                return TaskState.Running;
            else
            {
                if (paths[0] == null)
                    return TaskState.Fail;

                d.SetMovePath(paths[0]);
                return TaskState.Success;
            }
        }
        private TaskState Find(Dwarf d, float dt)
        {
            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 FindDepot(Dwarf d, float dt)
        {
            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 (_buildBuilding.HasRequestedNeededResourcesForCrafting== true)
                        return TaskState.Fail;

                    if (CraftRules.IsMapElementTypeCraftable(d.GetActionMapElementType()) == true)
                    {
                        TaskManager.AddTask(new CraftingOfResourceTask(d.GetActionMapElementType(), d.GetActionLevel()));
                        _buildBuilding.HasRequestedNeededResourcesForCrafting = 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);
            BuildingRequest br = (BuildingRequest)shortestPath.Data;

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

            return TaskState.Success;
        }
        private TaskState FindPath(Dwarf d, float dt)
        {
            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;

                    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
                        continue;
                }

                // 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;
        }