public void SetCycleOnly(int cycleNumber) { currentCycle = cycleNumber < cycles.Count ? cycles[cycleNumber] : null; }
public void UpdateCycle(int cycleNumber) { SetCycleOnly(cycleNumber); if (!GameManager.instance.cityManager.isTutorialRun && cycleNumber <= 1) { // We skip the first cycle when tutorial is not enabled - lack of XML timeline in this precise case makes settlers arrive too early return; } if (currentCycle == null) { currentCycle = new CycleInformation(); int value = lastSpikeValue + 1; if (cycleNumber % spikeEvery == 0) { lastSpikeValue += spikeIncrement; value = lastSpikeValue; } value = Mathf.RoundToInt(randomRange * UnityEngine.Random.value + value); for (int i = 0; i < value; i++) { Population pop = GameManager.instance.populationManager.populationTypeList[Mathf.FloorToInt(GameManager.instance.populationManager.populationTypeList.Length * UnityEngine.Random.value)]; if (!currentCycle.settlers.ContainsKey(pop)) { currentCycle.settlers.Add(pop, 0); } currentCycle.settlers[pop] += 1; } nextCycleSettlersBonus.Clear(); } ; // Add bonus (from events ?) foreach (KeyValuePair <Population, int> settlerBonus in nextCycleSettlersBonus) { if (!currentCycle.settlers.ContainsKey(settlerBonus.Key)) { currentCycle.settlers.Add(settlerBonus.Key, 0); } currentCycle.settlers[settlerBonus.Key] += settlerBonus.Value; } // Effective spawn SpawnCitizens(); // Unlocks CheckUnlocks(); // Events if (currentCycle.eventId > 0) { try { GameManager.instance.eventManager.TriggerEvent(currentCycle.eventId, true); } catch { Logger.Error("Tried to trigger non existent event ID " + currentCycle.eventId + " on cycle " + cycleNumber); } } Logger.Debug("New cycle, spawning " + currentCycle.settlers.Count.ToString() + " citizens and unlocking " + currentCycle.unlocks.Count.ToString() + " buildings"); }
CycleInformation ReadXCycle(XmlNode xCycle) { CycleInformation cycle = new CycleInformation(); foreach (XmlNode xProperty in xCycle.ChildNodes) { switch (xProperty.Name) { case "unlocks": foreach (XmlNode xUnlock in xProperty.ChildNodes) { // Garbage unlock if (xUnlock.Name != "building") { continue; } int id = Convert.ToInt32(xUnlock.InnerText); // Garbage ID if (!GameManager.instance.library.BlockExists(id)) { Logger.Error("Skipped unlock building:" + id + " because it doesn't exists"); continue; } cycle.unlocks.Add(id); } break; case "settlers": foreach (XmlNode xSettler in xProperty.ChildNodes) { string codeName = xSettler.Name; Population pop; if (codeName == "_random") { pop = GameManager.instance.populationManager.populationTypeList[Mathf.FloorToInt(GameManager.instance.populationManager.populationTypeList.Length * UnityEngine.Random.value)]; } else { pop = GameManager.instance.populationManager.GetPopulationByCodename(codeName); } // Garbage codename if (pop == null) { continue; } int amount = 0; if (xSettler.InnerText.Contains("~")) { string[] values = xSettler.InnerText.Split('~'); amount = Mathf.RoundToInt(Convert.ToInt32(values[0]) + Convert.ToInt32(values[1]) * UnityEngine.Random.value); } else { amount = Convert.ToInt32(xSettler.InnerText); } lastSpikeValue = amount; cycle.settlers.Add(pop, amount); } break; case "event": int eid = Convert.ToInt32(xProperty.InnerText); cycle.eventId = eid; break; } } return(cycle); }