void Farm() { Debug.Log("FOOD PRODUCTION: Farming!"); resourceManager.ChangeResource("Water", -waterConsumed); // resourceManager.ChargeOreorWater ("Water", -waterConsumed); // then add the food resourceManager.ChangeResource("Food", foodProduced); farming = true; }
/// <summary> /// Charges the resource from this storage /// </summary> /// <param name="ammnt">Ammnt.</param> /// <param name="id">Identifier.</param> public void ChargeResource(int ammnt, string id) { if (id == "Ore") { oreStored = oreStored + ammnt; Debug.Log("STORAGE: Charging stored ore for " + ammnt); playerResources.ChangeResource(id, ammnt); } else if (id == "Water") { waterStored = waterStored + ammnt; playerResources.ChangeResource(id, ammnt); Debug.Log("STORAGE: Charging stored water for " + ammnt); } else { Debug.Log("STORAGE: Can't Find that resource ID!"); } }
void FollowMouse(){ m = Camera.main.ScreenToWorldPoint (Input.mousePosition); mX = Mathf.RoundToInt(m.x); mY = Mathf.RoundToInt(m.y); // Making sure that we are not trying to Build outside the BOUNDARIES of the GRID if (mX > resourceGrid.mapSizeX - 3){ mX = resourceGrid.mapSizeX - 3; } if (mY > resourceGrid.mapSizeY -3){ mY = resourceGrid.mapSizeY - 3; } if (mX < 3){ mX = 3; } if (mY < 3){ mY = 3; } // Move building with the mouse Vector3 followPos = new Vector3 (mX, mY); transform.position = followPos; if (CheckEmptyBeneath (mX, mY)) { if (tileType == TileData.Types.extractor) { if (CheckForResource (mX, mY + 1, true)) { // top sr.color = trueColor; canBuild = true; } else if (CheckForResource (mX, mY - 1, true)) { // bottom sr.color = trueColor; canBuild = true; } else if (CheckForResource (mX - 1, mY, true)) { // left canBuild = true; sr.color = trueColor; } else if (CheckForResource (mX + 1, mY, true)) { // right canBuild = true; sr.color = trueColor; } else if (CheckForResource (mX - 1, mY + 1, true)) { // top left canBuild = true; sr.color = trueColor; } else if (CheckForResource (mX + 1, mY + 1, true)) { // top right canBuild = true; sr.color = trueColor; } else if (CheckForResource (mX - 1, mY - 1, true)) { // bottom left canBuild = true; sr.color = trueColor; } else if (CheckForResource (mX + 1, mY - 1, true)) { // bottom right canBuild = true; sr.color = trueColor; } else { // NOT ON ROCK sr.color = halfColor; canBuild = false; } } else if (tileType == TileData.Types.desalt_s) { // THIS building is an EXTRACTOR so it needs to check for Rock if (CheckForResource (mX, mY + 1, false)) { // top sr.color = trueColor; canBuild = true; } else if (CheckForResource (mX, mY - 1, false)) { // bottom sr.color = trueColor; canBuild = true; } else if (CheckForResource (mX - 1, mY, false)) { // left canBuild = true; sr.color = trueColor; } else if (CheckForResource (mX + 1, mY, false)) { // right canBuild = true; sr.color = trueColor; } else if (CheckForResource (mX - 1, mY + 1, false)) { // top left canBuild = true; sr.color = trueColor; } else if (CheckForResource (mX + 1, mY + 1, false)) { // top right canBuild = true; sr.color = trueColor; } else if (CheckForResource (mX - 1, mY - 1, false)) { // bottom left canBuild = true; sr.color = trueColor; } else if (CheckForResource (mX + 1, mY - 1, false)) { // bottom right canBuild = true; sr.color = trueColor; } else { // NOT ON Water sr.color = halfColor; canBuild = false; } } else{ // not an extractor or desalt pump if (CheckForEmptySides (mX, mY)) { // we are on a legal building position sr.color = trueColor; canBuild = true; } else {// we DO NOT have an empty tile on our sides or beneath sr.color = halfColor; canBuild = false; } } } else { // NOT ON EMPTY sr.color = halfColor; canBuild = false; } // MAKE SURE WE HAVE ENOUGH ORE TO BUILD! if (resourceManager.ore >= currOreCost ) { canAfford = true; } // At this point we KNOW the mouse is NOT over a building or a rock, AND we have found rocks if extractor, if (Input.GetMouseButtonDown (0) && canBuild && canAfford) { // So LEFT CLICK to BUILD!! // Subtract the cost // resourceManager.ChargeOreorWater("Ore", -currOreCost); resourceManager.ChangeResource("Ore", -currOreCost); // stop following and tell grid to swap this tile to this new building mapPosX = mX; mapPosY = mY; resourceGrid.SwapTileType (mX, mY, tileType); followMouse = false; // Right BEFORE pooling this object we tell Building UI that we are NOT currently building anymore this.buildingUI.currentlyBuilding = false; // Pool this object PoolObject (gameObject); // Pool this because resourceGrid just discovered the tile/building for us } if (Input.GetMouseButtonDown (1)) { // CANCEL THE BUILD PoolObject(gameObject); } }