// Start is called before the first frame update void Start() { inventory = InventoryBuilding.inventory; timer = 0f; if (this.gameObject.tag == "Factory") { spawnTimer = inventory.coalFactoryStructure.timeMoney; money = inventory.coalFactoryStructure.moneyPerTap; } else if (this.gameObject.tag == "Gas") { spawnTimer = inventory.gasExtractorStructure.timeMoney; money = inventory.gasExtractorStructure.moneyPerTap; } else if (this.gameObject.tag == "Windmill") { spawnTimer = inventory.windmillStructure.timeMoney; money = inventory.windmillStructure.moneyPerTap; } else if (this.gameObject.tag == "Solar") { spawnTimer = inventory.solarPanelStructure.timeMoney; money = inventory.solarPanelStructure.moneyPerTap; } // energy = inventory.coalFactoryStructure.energyPerTap; player = GameObject.Find("Player").GetComponent <Player>(); Destroy(GetComponent <BoxCollider>(), 0.5f); }
public static bool UpdateRessourceLimit(HexCoordinates coordinates, RessourceType type, int newValue) { HexCell cell = grid.GetCell(coordinates); if (cell != null) { if (cell.Structure is InventoryBuilding) { InventoryBuilding building = (InventoryBuilding)cell.Structure; if (newValue < 0 || building.Inventory.RessourceLimit < newValue) { return(false); } if (building.Inventory.RessourceLimits.ContainsKey(type)) { building.Inventory.RessourceLimits[type] = newValue; } else { building.Inventory.RessourceLimits.Add(type, newValue); } if (building.Inventory.GetRessourceAmount(type) > newValue) { building.Inventory.Storage[type] = newValue; } return(true); } } return(false); }
// Start is called before the first frame update void Start() { player = GameObject.Find("Player").GetComponent <Player>(); inventory = InventoryBuilding.inventory; //LockTabs(); if (CheckCoalSuccess()) { UnlockCoalFactory(); } if (CheckGasSuccess()) { UnlockGasFactory(); } if (CheckSolarSuccess()) { UnlockSolar(); } if (CheckWindSuccess()) { UnlockWind(); } else { UpdateLevelResearchCoal(inventory.coalFactoryStructure.levelResearch); Debug.Log("Level of the coal research: " + inventory.coalFactoryStructure.levelResearch); if (!CheckCoalSuccess()) { LockAllEnergyBuildings(); LockTabs(); UpdateCostResearchCoal(inventory.coalFactoryStructure.costResearches[inventory.coalFactoryStructure.levelResearch]); } UpdateTextCostBuildCoal(inventory.coalFactoryStructure.cost); UpdateTextCostBuildGas(inventory.gasExtractorStructure.cost); UpdateTextCostBuildWind(inventory.windmillStructure.cost); UpdateTextCostBuildSolar(inventory.solarPanelStructure.cost); UpdateTextCostLiberty(inventory.statueOfLiberty.cost); UpdateTextCostPark(inventory.park.cost); UpdateTextCostPisa(inventory.pisaTower.cost); UpdateTextCostWheel(inventory.ferrisWheel.cost); UpdateTextCostEiffle(inventory.eiffleTower.cost); UpdateTextCostPolice(inventory.policeStation.cost); UpdateTextCostFire(inventory.fireStation.cost); } // this.gameObject.SetActive(false); }
//List<StructureBlueprint> listOfBlueprints = new List<StructureBlueprint>(); void Awake() { if (inventory == null) { inventory = this; } else if (inventory != this) { Destroy(this.gameObject); } DontDestroyOnLoad(this.gameObject); }
public static bool ChangeAllowedRessource(HexCoordinates origin, HexCoordinates destination, RessourceType ressourceType, bool newValue) { HexCell originCell = grid.GetCell(origin); HexCell destinationCell = grid.GetCell(destination); if (originCell.Structure is InventoryBuilding && destinationCell.Structure is InventoryBuilding) { InventoryBuilding originBuilding = (InventoryBuilding)originCell.Structure; InventoryBuilding destinationBuilding = (InventoryBuilding)destinationCell.Structure; originBuilding.AllowedRessources[destinationBuilding][ressourceType] = newValue; return(true); } return(false); }
private void Awake() { if (instance != null) { Debug.LogError("More than a one buildmanager in the scene"); return; } instance = this; player = GameObject.Find("Player").GetComponent <Player>(); createEnvironment = this.gameObject.GetComponent <CreateEnvironment>(); inventoryBuilding = GameObject.Find("TypesOfBuildings").GetComponent <InventoryBuilding>(); //destroyParticle = destroyParticlePrefab.GetComponentInChildren<ParticleSystem>(); }
public static bool MoveRessources(HexCoordinates originCoordinates, HexCoordinates destinationCoordinates, RessourceType type, int amount) { HexCell originCell = grid.GetCell(originCoordinates); HexCell destinationCell = grid.GetCell(destinationCoordinates); if (originCell != null && destinationCell != null) { if (originCell.Structure is InventoryBuilding && destinationCell.Structure is InventoryBuilding) { InventoryBuilding origin = (InventoryBuilding)originCell.Structure; InventoryBuilding destination = (InventoryBuilding)destinationCell.Structure; if (origin.Inventory.GetRessourceAmount(type) >= amount && destination.Inventory.AvailableSpace() >= amount) { origin.Inventory.RemoveRessource(type, amount); destination.Inventory.AddRessource(type, amount); return(true); } } } return(false); }
public static void ComputeConnectedStorages(Road current, InventoryBuilding origin, HexDirection direction, int minRoadLevel, int depth) { //Check if the tribe is already in the current dictionary and add it if it isn't if (!current.connectedStorages.ContainsKey(origin.Tribe)) { current.connectedStorages.Add(origin.Tribe, new Dictionary <InventoryBuilding, Tuple <HexDirection, int, int> >()); } //Check if the origin Building already has an entry in the dictionary if (current.connectedStorages[origin.Tribe].ContainsKey(origin)) { //An entry of the origin Building already exists. Check if the current Route has a better flowrate. if (FlowRate(current.connectedStorages[origin.Tribe][origin].Item2, current.connectedStorages[origin.Tribe][origin].Item3) >= FlowRate(minRoadLevel, depth)) { return; } else { current.connectedStorages[origin.Tribe][origin] = new Tuple <HexDirection, int, int>(direction, Mathf.Min(minRoadLevel, current.Level), depth); } } else { current.connectedStorages[origin.Tribe].Add(origin, new Tuple <HexDirection, int, int>(direction, Mathf.Min(minRoadLevel, current.Level), depth)); } //Look at the neighbors of the current road for (HexDirection dir = HexDirection.NE; dir <= HexDirection.NW; dir++) { HexCell neighbor = current.Cell.GetNeighbor(dir); //Propogate the route to origin through the roads if (neighbor != null && neighbor.Structure is Road && current.HasRoad(dir)) { ComputeConnectedStorages((Road)neighbor.Structure, origin, dir.Opposite(), Mathf.Min(minRoadLevel, current.Level), depth + 1); } //Add the entry to a connected Building if (neighbor != null && neighbor.Structure is InventoryBuilding && current.HasBuilding(dir) && neighbor.Structure != origin && ((InventoryBuilding)neighbor.Structure).Tribe == origin.Tribe) { InventoryBuilding inventoryBuilding = (InventoryBuilding)neighbor.Structure; if (inventoryBuilding.ConnectedInventories.ContainsKey(origin)) { if (FlowRate(inventoryBuilding.ConnectedInventories[origin].Item2, inventoryBuilding.ConnectedInventories[origin].Item3) < FlowRate(minRoadLevel, depth + 1)) { inventoryBuilding.ConnectedInventories[origin] = new Tuple <HexDirection, int, int>(dir.Opposite(), minRoadLevel, depth + 1); } } else { inventoryBuilding.ConnectedInventories.Add(origin, new Tuple <HexDirection, int, int>(dir.Opposite(), minRoadLevel, depth + 1)); } //Init allowed Ressources for origin Building if (!origin.AllowedRessources.ContainsKey(inventoryBuilding)) { origin.AllowedRessources.Add(inventoryBuilding, new Dictionary <RessourceType, bool>()); } foreach (RessourceType ressourceType in origin.Inventory.Outgoing) { if (inventoryBuilding.Inventory.Incoming.Contains(ressourceType)) { if (!origin.AllowedRessources[inventoryBuilding].ContainsKey(ressourceType)) { origin.AllowedRessources[inventoryBuilding].Add(ressourceType, true); } } } } } }