public void UpdatePerDay() { m_graphBuildings.Foreach((UT_Node <BuildingStats> node) => { node.GetData().overallMood = 0; node.GetData().availability = 0; node.GetData().createdInstances = 0; }); List <IBuilding> buildings = M_BuildingManager.SGetBuildings(); foreach (IBuilding building in buildings) { if (building is IBuildingHouse) { GetNode(building.GetData().id).GetData().createdInstances++; continue; } if (!(building is IBuildingProduction)) { continue; } IBuildingProduction prod = (IBuildingProduction)building; UT_Node <BuildingStats> node = GetNode(building.GetData().id); node.GetData().overallMood += prod.GetMood(); node.GetData().createdInstances++; if (prod.IsWorking()) { M_WaresManager.SAddProductiveBuilding(prod.GetId(), prod.GetProducedWareType()); } else { M_WaresManager.SRemoveProductiveBuilding(prod.GetId(), prod.GetProducedWareType()); } } m_graphBuildings.Foreach((UT_Node <BuildingStats> node) => { BuildingStats stats = node.GetData(); foreach (DAT_Building.BuildDependency dep in stats.data.dependencies) { if (stats.overallMood > dep.requiredMood) { UT_Node <BuildingStats> tempNode = GetNode(dep.unlocksBuilding); tempNode.GetData().availability += 1; if (tempNode.GetData().availability == tempNode.GetAdjacent().Count && m_currentBuildingsLevel < tempNode.GetData().buildingLevel) { m_currentBuildingsLevel = tempNode.GetData().buildingLevel; } } } }); }
public void GetPathLengths(int start) { List <UT_Node <BuildingStats> > m_nodes = m_graphBuildings.GetNodes(); int level = 0; bool[] visited = new bool[m_nodes.Count]; Queue <UT_Node <BuildingStats> > queue = new Queue <UT_Node <BuildingStats> >(); UT_Node <BuildingStats> startNode = GetNode(start); visited[m_nodes.IndexOf(startNode)] = true; queue.Enqueue(startNode); startNode.GetData().buildingLevel = level; while (queue.Count > 0) { UT_Node <BuildingStats> temp = queue.Dequeue(); if (temp.GetData().buildingLevel > level) { level++; } List <UT_Node <BuildingStats> > adj = temp.GetAdjacent(); foreach (UT_Node <BuildingStats> node in adj) { int index = m_nodes.IndexOf(node); if (!visited[index]) { visited[index] = true; node.GetData().buildingLevel = level + 1; queue.Enqueue(node); } } } }
public int GetCount(int id) { UT_Node <BuildingStats> node = GetNode(id); return(node.GetData().createdInstances); }