private TaskState FindPath(Dwarf d, float dt, double dtd) { 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; } }
private TaskState FindPath(Dwarf d, float dt, double dtd) { if (State == TaskState.NotActive) { // If dwarf has no assigned bed, sleep where he currently is if (d.AssignedBed == null) AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), new Point((int)d.Position.X, (int)d.Position.Y), null); else { AsyncPathfinding.RequestPathfinding(d, new Point((int)d.Position.X, (int)d.Position.Y), d.AssignedBed.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 FindPath(Dwarf d, float dt, double dtd) { 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; } } }
private TaskState Find(Dwarf d, float dt, double dtd) { 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 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 FindPath(Dwarf d, float dt, double dtd) { 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, 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 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; }
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; }