// Update is called once per frame void Update() { if (RoadAccess || Upgrading) { if (Placed && ElapsedTime.NewMonth) { if (PopManager.Unemployment < .05) { GrowthModifier = 5; } else if (PopManager.Unemployment < .1) { GrowthModifier = 3; } else if (PopManager.Unemployment < .15) { GrowthModifier = 1; } else if (PopManager.Unemployment < .2) { GrowthModifier = 0; } else if (PopManager.Unemployment < .3) { GrowthModifier = -1; } else if (PopManager.Unemployment < .4) { GrowthModifier = -3; } else if (PopManager.Unemployment < .6) { GrowthModifier = -5; } else { GrowthModifier = -10; } GrowthModifier += desireability; maxThisTurn = maxPeople - CurrentPeople; if (CurrentPeople < maxPeople) { thisTurnPopChange = (int)Random.Range(GrowthModifier, maxThisTurn); if (CurrentPeople + thisTurnPopChange > maxPeople) { thisTurnPopChange = maxPeople - CurrentPeople; CurrentPeople = maxPeople; } else { CurrentPeople += thisTurnPopChange; } if (CurrentPeople < 0) { CurrentPeople = 0; } SaveFileControl.control.buildings [gameObject.GetComponent <Building> ().BuildingNum, 4] = CurrentPeople; PopManager.PlayerPopulation += thisTurnPopChange; } if (HouseLevel == 1) { if (pResource.PlayerFood - (int)(CurrentPeople / 2) >= 0) { pResource.PlayerFood = (pResource.PlayerFood - (int)(CurrentPeople / 2)); if (discontent.DiscontentAmmt > 0) { discontent.DiscontentAmmt -= .25f; } } else { discontent.DiscontentAmmt += 2; pResource.PlayerFood = 0; } if (MarketAccess && WellAccess) { Debug.Log("Upgrading to Level 2"); Destroy(gameObject.transform.GetChild(0).gameObject); newModel = Instantiate(Level2Model, gameObject.transform); newModel.transform.localPosition = new Vector3(0, .5f, 0); newModel.GetComponent <PlacingCollision> ().PB = GameObject.FindGameObjectWithTag("Game Control").GetComponent <PlaceBuilding> (); SaveFileControl.control.buildings [gameObject.GetComponent <Building> ().BuildingNum, 5] = 2; //House Level maxPeople = 25; HouseLevel = 2; prosp.ProsperityAmmt += .25f; Upgrading = true; } } else if (HouseLevel == 2) { if (Upgrading) { Upgrading = false; } if (HouseLevel == 2 && MarketAccess && WellAccess && InnAccess && ChurchAccess) { Upgrading = true; Debug.Log("Upgrading to Level 3"); Destroy(gameObject.transform.GetChild(0).gameObject); newModel = Instantiate(Level3Model, gameObject.transform); newModel.transform.localPosition = new Vector3(0, .5f, 0); newModel.GetComponent <PlacingCollision>().PB = GameObject.FindGameObjectWithTag("Game Control").GetComponent <PlaceBuilding>(); SaveFileControl.control.buildings[gameObject.GetComponent <Building>().BuildingNum, 5] = 3; //House Level maxPeople = 30; HouseLevel = 3; prosp.ProsperityAmmt += .25f; } if (MarketAccess) { if (pResource.PlayerFood - (2 * CurrentPeople) >= 0) { pResource.PlayerFood = (pResource.PlayerFood - (2 * CurrentPeople)); if (discontent.DiscontentAmmt > 0) { discontent.DiscontentAmmt -= .25f; } } else { discontent.DiscontentAmmt += 2; pResource.PlayerFood = 0; } } else { discontent.DiscontentAmmt += 2; } if (!WellAccess) { discontent.DiscontentAmmt += 2; } } else if (HouseLevel == 3) { if (Upgrading) { Upgrading = false; } if (HouseLevel == 2 && MarketAccess && WellAccess && InnAccess && ChurchAccess) //update needed { Debug.Log("Upgrading to Level 3"); Destroy(gameObject.transform.GetChild(0).gameObject); newModel = Instantiate(Level3Model, gameObject.transform); newModel.transform.localPosition = new Vector3(0, 1f, 0); newModel.GetComponent <PlacingCollision>().PB = GameObject.FindGameObjectWithTag("Game Control").GetComponent <PlaceBuilding>(); SaveFileControl.control.buildings[gameObject.GetComponent <Building>().BuildingNum, 5] = 3; //House Level maxPeople = 30; HouseLevel = 3; } if (MarketAccess) { if (pResource.PlayerFood - (2 * CurrentPeople) >= 0) { pResource.PlayerFood = (pResource.PlayerFood - (2 * CurrentPeople)); if (discontent.DiscontentAmmt > 0) { discontent.DiscontentAmmt -= .25f; } } else { discontent.DiscontentAmmt += 2; pResource.PlayerFood = 0; } } else { discontent.DiscontentAmmt += 2; } if (!WellAccess) { discontent.DiscontentAmmt += 2; } if (!ChurchAccess) { discontent.DiscontentAmmt += 2; } if (!InnAccess) { discontent.DiscontentAmmt += 2; } } } } else { if (CurrentPeople > 0) { PopManager.DecreasePopulation(CurrentPeople); CurrentPeople = 0; } } }
// Use this for initialization void Update() { if (Removing && Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100f)) { if (hit.collider.gameObject.transform.parent != null) { if (hit.collider.gameObject.transform.parent.tag == "House") { PopMan.DecreasePopulation(hit.collider.gameObject.transform.parent.GetComponent <House> ().CurrentPeople); SaveFileControl.control.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum, 3] = 0; PopMan.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum] = null; Destroy(hit.collider.gameObject.transform.parent.gameObject); } else if (hit.collider.gameObject.transform.parent.tag == "Mill") { PopMan.EmployedPeople = PopMan.EmployedPeople - hit.collider.gameObject.transform.parent.GetComponent <Mill> ().CurrentEmployees; SaveFileControl.control.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum, 3] = 0; PopMan.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum] = null; Destroy(hit.collider.gameObject.transform.parent.gameObject); } else if (hit.collider.gameObject.transform.parent.tag == "Field") { PopMan.EmployedPeople = PopMan.EmployedPeople - hit.collider.gameObject.transform.parent.GetComponent <Field> ().CurrentEmployees; SaveFileControl.control.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum, 3] = 0; PopMan.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum] = null; Destroy(hit.collider.gameObject.transform.parent.gameObject); } else if (hit.collider.gameObject.transform.parent.tag == "LumberYard") { PopMan.EmployedPeople = PopMan.EmployedPeople - hit.collider.gameObject.transform.parent.GetComponent <LumberYard> ().CurrentEmployees; SaveFileControl.control.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum, 3] = 0; PopMan.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum] = null; Destroy(hit.collider.gameObject.transform.parent.gameObject); } else if (hit.collider.gameObject.transform.parent.tag == "Quarry") { PopMan.EmployedPeople = PopMan.EmployedPeople - hit.collider.gameObject.transform.parent.GetComponent <Quarry> ().CurrentEmployees; SaveFileControl.control.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum, 3] = 0; PopMan.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum] = null; Destroy(hit.collider.gameObject.transform.parent.gameObject); } else if (hit.collider.gameObject.transform.parent.tag == "Market") { pBuilding.MarketCount--; PopMan.EmployedPeople = PopMan.EmployedPeople - hit.collider.gameObject.transform.parent.GetComponent <Market> ().CurrentEmployees; SaveFileControl.control.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum, 3] = 0; PopMan.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum].GetComponent <Market> ().DestroyMarket(); PopMan.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum] = null; } else if (hit.collider.gameObject.transform.parent.tag == "TradeDepo") { PopMan.EmployedPeople = PopMan.EmployedPeople - hit.collider.gameObject.transform.parent.GetComponent <TradeDepo> ().CurrentEmployees; SaveFileControl.control.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum, 3] = 0; PopMan.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum] = null; Destroy(hit.collider.gameObject.transform.parent.gameObject); } else if (hit.collider.gameObject.transform.parent.tag == "Well") { PopMan.EmployedPeople = PopMan.EmployedPeople - hit.collider.gameObject.transform.parent.GetComponent <Well> ().CurrentEmployees; SaveFileControl.control.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum, 3] = 0; PopMan.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum].GetComponent <Well> ().DestroyWell(); PopMan.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum] = null; } else if (hit.collider.gameObject.transform.parent.tag == "Inn") { PopMan.EmployedPeople = PopMan.EmployedPeople - hit.collider.gameObject.transform.parent.GetComponent <Inn> ().CurrentEmployees; SaveFileControl.control.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum, 3] = 0; PopMan.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum].GetComponent <Inn> ().DestroyInn(); PopMan.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum] = null; } else if (hit.collider.gameObject.transform.parent.tag == "Church") { PopMan.EmployedPeople = PopMan.EmployedPeople - hit.collider.gameObject.transform.parent.GetComponent <Church> ().CurrentEmployees; SaveFileControl.control.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum, 3] = 0; PopMan.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum].GetComponent <Church> ().DestroyChurch(); PopMan.buildings [hit.collider.gameObject.transform.parent.GetComponent <Building> ().BuildingNum] = null; } else { Debug.Log(hit.collider.gameObject.transform.parent.tag); } } else { if (hit.collider.gameObject.transform.tag == "Road") { SaveFileControl.control.buildings [hit.collider.gameObject.transform.GetComponent <Building> ().BuildingNum, 3] = 0; PopMan.buildings [hit.collider.gameObject.transform.GetComponent <Building> ().BuildingNum].GetComponent <Road> ().DestroyRoad(); PopMan.buildings [hit.collider.gameObject.transform.GetComponent <Building> ().BuildingNum] = null; } } } } else if (Removing && Input.GetMouseButtonDown(1)) { Removing = false; } }
public void OnDestroy() { popc.DecreasePopulation(1); StatisticsManager.CivilianCount--; }