public void SpawnImmigrant(Structure requester) { Structure mapEntrance = GameObject.FindGameObjectWithTag("MapEntrance").GetComponent <Structure>(); if (mapEntrance == null) { return; } Node start = new Node(mapEntrance.X, mapEntrance.Y); Node end = new Node(requester.X, requester.Y); List <Node> testpath = worldController.Map.pathfinder.FindPath(start, end); if (testpath.Count == 0) { return; } GameObject go = Instantiate(Resources.Load <GameObject>("Walkers/Immigrant"), mapEntrance.transform.position, Quaternion.Euler(new Vector3(0, 0, 0))); go.name = "ImmigrantTo_" + name; Walker w = go.GetComponent <Walker>(); w.world = worldController; w.Origin = mapEntrance; w.Destination = requester; w.Path = w.FindPath(start, end); w.Activate(); }
void SearchForTree() { List <Node> entrances = GetAdjRoadTiles(); if (entrances.Count == 0) { return; } Node start = entrances[0]; SimplePriorityQueue <Structure, float> queue = FindClosestStructureOfType("Tree"); for (int i = 0; queue.Count > 0 && i < 5 && !ActiveSmartWalker; i++) { Structure s = queue.Dequeue(); Node end = new Node(s); Queue <Node> path = pathfinder.FindPath(start, end, "Lumberjack"); if (path.Count == 0) { continue; } GameObject go = world.SpawnObject("Walkers", "Lumberjack", start); Walker c = go.GetComponent <Walker>(); c.world = world; c.Origin = this; c.Destination = s; c.Activate(); c.SetPath(path); } }
public void SpawnImmigrant(Node start, Structure requester, Prole immigrant) { //by the way: it's way easier to deal with the starting point as a node than a structure, especially because we don't need to know where the immigrant came from // no matter how weird that we instantiate 'end' here but not 'start' Queue <Node> path = new Pathfinder(worldController.Map).FindPath(start, new Node(requester), "Immigrant"); if (path.Count == 0) { return; } GameObject go = worldController.SpawnObject("Walkers", "Immigrant", start); Walker w = go.GetComponent <Walker>(); w.world = worldController; w.Destination = requester; w.SetPath(path); w.SetPersonData(immigrant); //data for immigrant moving into house w.Activate(); immigrant.EvictHouse(false); //quit current house if they have one, but don't quit work because they're still here if (immigrant.Employed) { immigrant.QuitWork(); } }
public void SpawnEmigrant() { Structure mapExit = GameObject.FindGameObjectWithTag("MapExit").GetComponent <Structure>(); if (mapExit == null) { return; } Node start = new Node(X, Y); Node end = new Node(mapExit.X, mapExit.Y); List <Node> testpath = world.Map.pathfinder.FindPath(start, end); if (testpath.Count == 0) { return; } GameObject go = Instantiate(Resources.Load <GameObject>("Walkers/Emigrant")); go.transform.position = mapExit.transform.position; go.name = "ImmigrantTo_" + name; Walker w = go.GetComponent <Walker>(); w.world = world; w.Origin = this; w.Destination = mapExit; w.Path = w.FindPath(start, end); w.Activate(); }
public void SpawnLaborSeeker() { List <Node> entrances = GetAdjRoadTiles(); //proceed only if there are available roads if (entrances.Count == 0) { return; } GameObject go = world.SpawnObject("Walkers/RandomWalkers", "LaborSeeker", entrances[0]); Walker w = go.GetComponent <Walker>(); w.world = world; w.Origin = this; w.Activate(); }
public void SpawnLaborSeeker() { List <Node> entrances = CheckAdjRoads(); //proceed only if there are available roads if (entrances.Count == 0) { return; } GameObject go = Instantiate(Resources.Load <GameObject>("Walkers/RandomWalkers/LaborSeeker"), entrances[0].GetVector3(), Quaternion.Euler(new Vector3(0, 0, 0))); Walker w = go.GetComponent <Walker>(); w.world = world; w.Origin = this; w.Activate(); }
public void SpawnImporter(ItemOrder co) { Structure mapEntrance = GameObject.FindGameObjectWithTag("MapEntrance").GetComponent <Structure>(); Structure target = mapEntrance.FindStorageBuildingToAccept(co); if (mapEntrance == null || target == null || co.direction != TradeDirection.Import) { return; } List <Node> entrances = target.CheckAdjRoads(); if (entrances.Count == 0) { return; } Node start = new Node(mapEntrance.X, mapEntrance.Y); Node end = entrances[0]; target.GetComponent <StorageBuilding>().Queue[co.item] += co.amount; List <Node> testpath = worldController.Map.pathfinder.FindPath(start, end); if (testpath.Count == 0) { return; } GameObject go = Instantiate(Resources.Load <GameObject>("Walkers/Importer")); go.transform.position = mapEntrance.transform.position; go.name = "CaravanTo_" + target.name; Walker w = go.GetComponent <Walker>(); w.Order = co; w.world = worldController; w.Origin = mapEntrance; w.Destination = target; w.Path = w.FindPath(start, end); w.Activate(); }
public void SpawnLivestock() { //spawn if no active walker and the building has a walker if (!string.IsNullOrEmpty(RandomWalker)) { List <Node> entrances = GetAdjBareGroundTiles(); //proceed only if there are available roads if (entrances.Count == 0) { return; } GameObject go = world.SpawnObject("Walkers/Animals", RandomWalker, entrances[0]); Walker w = go.GetComponent <Walker>(); w.world = world; w.Origin = this; w.Activate(); } }
public void SpawnLivestock() { //spawn if no active walker and the building has a walker if (!string.IsNullOrEmpty(RandomWalker)) { List <Node> entrances = CheckAdjGround(); //proceed only if there are available roads if (entrances.Count == 0) { return; } GameObject go = Instantiate(Resources.Load <GameObject>("Walkers/Animals/" + RandomWalker)); go.transform.position = entrances[0].GetVector3(); Walker w = go.GetComponent <Walker>(); w.world = world; w.Origin = this; w.Activate(); } }
public void SpawnEmigrant(Node start, Prole emigrant) { GameObject mapEntrance = GameObject.FindGameObjectWithTag("MapEntrance"); if (mapEntrance == null) { return; } Node end = new Node(mapEntrance.GetComponent <Structure>()); Queue <Node> path = new Pathfinder(worldController.Map).FindPath(start, end, "Emigrant"); if (path.Count == 0) { return; } GameObject go = worldController.SpawnObject("Walkers", "Emigrant", start); //GameObject go = Instantiate(Resources.Load<GameObject>("Walkers/Emigrant")); //go.transform.position = mapExit.transform.position; //go.name = "Emigrant"; Walker w = go.GetComponent <Walker>(); w.world = worldController; w.Destination = mapEntrance.GetComponent <Structure>(); w.SetPersonData(emigrant); w.SetPath(path); w.Activate(); //evict house at the very end to remove homeNode and remove prole data from house //quit job too because they're leaving the city emigrant.EvictHouse(false); emigrant.QuitWork(); //RemoveResidents(ExcessResidents); }
public void SpawnRandomWalker() { if (string.IsNullOrEmpty(RandomWalker)) { return; } List <Node> entrances = GetAdjRoadTiles(); //proceed only if there are available roads if (entrances.Count == 0) { return; } Node start = entrances[0]; GameObject go = world.SpawnObject("Walkers/RandomWalkers", RandomWalker, start); Walker w = go.GetComponent <Walker>(); w.world = world; w.Origin = this; w.Activate(); }
public void SpawnCaravan(ItemOrder co) { bool import = co.direction == TradeDirection.Import; //check if map entrance Structure mapEntrance = GameObject.FindGameObjectWithTag("MapEntrance").GetComponent <Structure>(); if (mapEntrance == null) { Debug.LogError("No map entrance for caravan found"); } //make queue of storage buildings SimplePriorityQueue <StorageBuilding> queue = import ? mapEntrance.FindStorageBuildingToAccept(co) : mapEntrance.FindStorageBuildingThatHas(co); for (int i = 0; queue.Count > 0 && i < 5; i++) { Node start = new Node(mapEntrance); //pop storage building, make sure it has an exit Structure strg = queue.Dequeue(); List <Node> exits = strg.GetAdjRoadTiles(); if (exits.Count == 0) { continue; } //find a path, continue only if it exists string caravanName = import ? "Importer" : "Exporter"; Queue <Node> path = new Pathfinder(worldController.Map).FindPath(start, exits, caravanName); if (path.Count == 0) { continue; } GameObject go = worldController.SpawnObject("Walkers", caravanName, start); Walker w = go.GetComponent <Walker>(); w.Order = co; w.world = worldController; w.Origin = mapEntrance; w.Destination = strg; w.SetPath(path); w.Activate(); break; } //List<Node> entrances = target.GetAdjRoadTiles(); //if (entrances.Count == 0) // return; //Node start = new Node(mapEntrance.X, mapEntrance.Y); //Node end = entrances[0]; //if(tradeDirection == TradeDirection.Import) // target.GetComponent<StorageBuilding>().Queue[co.item] += co.amount; //string caravanName = tradeDirection == TradeDirection.Import ? "Importer" : "Exporter"; //Stack<Node> path = worldController.Map.pathfinder.FindPath(start, end, WalkerDatabase.GetData(caravanName)); //if (path.Count == 0) // return; //GameObject go = worldController.SpawnObject("Walkers", caravanName, start); //Walker w = go.GetComponent<Walker>(); //w.Order = co; //w.world = worldController; //w.Origin = mapEntrance; //w.Destination = target; //w.Path = path; //w.Activate(); }