/// <summary> /// Coroutine that handles execution of weather event, it finds the current weather event to execute /// and makes a call to display the weather card /// </summary> IEnumerator TriggerWeatherEvent() { // eventindex is randomised at start, order of weather events is cyclic //reset turn counter turnCounter = TURN_COUNTER; Debug.Log("triggering weather " + eventIndex); if (weatherEvents.TryGetValue(eventIndex, out ClimateEvent value)) { currentEvent = value; switch (value) { case ClimateEvent.AcidRain: rain.PlayAnim(); Debug.Log("raining"); break; case ClimateEvent.Hurricane: storm.PlayAnim(); Debug.Log("storming"); break; case ClimateEvent.WildFire: wildfire.PlayAnim(); Debug.Log("firing"); break; case ClimateEvent.Smog: smog.PlayAnim(); Debug.Log("smogging"); break; } cardManager.SetState(CardManager.GameState.WeatherEvent); } yield return(null); }
private void resolveOptionSelect(int option) { if (currentEventIndex < 0) { Debug.LogWarning("currentEventIndex out of bounds"); return; } //set rotate of camera CameraController.instance.rotateDestination = -1; ClimateEvent currentEvent = events[currentEventIndex]; //set updated resource values int[] resourceValues = MainGameBackend.instance.getResourceValues(); int updatedMoneyVal = resourceValues[0] - currentEvent.choices[option].moneyRequired; int updatedScienceVal = resourceValues[1] - currentEvent.choices[option].scienceRequired; int updatedGlobalCoopVal = resourceValues[2] - currentEvent.choices[option].globalCoopRequired; int updatedEducationVal = resourceValues[3] - currentEvent.choices[option].educationRequired; MainGameBackend.instance.setResourceValues(updatedMoneyVal, updatedScienceVal, updatedGlobalCoopVal, updatedEducationVal); //update metrics if changed float[] metricValues = MainGameBackend.instance.getMetricValues(); float glblTempVal = metricValues[0] + currentEvent.choices[option].globalTempDelta; float oceanTempVal = metricValues[1] + currentEvent.choices[option].oceanTempDelta; float seaLvlVal = metricValues[2] + currentEvent.choices[option].seaLevelDelta; float iceSheetVal = metricValues[3] + currentEvent.choices[option].iceSheetDelta; float co2Val = metricValues[4] + currentEvent.choices[option].co2Delta; float glblTempDelta = metricValues[5] + currentEvent.choices[option].globalTempDeltaDelta; float oceanTempDelta = metricValues[6] + currentEvent.choices[option].globalTempDeltaDelta; float seaLvlDelta = metricValues[7] + currentEvent.choices[option].globalTempDeltaDelta; float iceSheetDelta = metricValues[8] + currentEvent.choices[option].globalTempDeltaDelta; float co2Delta = metricValues[9] + currentEvent.choices[option].globalTempDeltaDelta; float date = metricValues[10]; int currYear = (int)date; int currSeason = (int)((date - currYear) * 4); MainGameBackend.instance.setMetricValues(glblTempVal, oceanTempVal, seaLvlVal, iceSheetVal, co2Val, glblTempDelta, oceanTempDelta, seaLvlDelta, iceSheetDelta, co2Delta, currYear, currSeason); //update flag updateXML(currentEventIndex, true); //getFlagValues(); currentEventIndex = -1; MainGameUI.instance.EventEnded(); }
void Start() { metricManager = MetricManager.Instance; cardManager = CardManager.Instance; envHealth = (float)metricManager.EnvHealth; weatherEvents = new Dictionary <int, ClimateEvent>(); weatherEvents.Add(0, ClimateEvent.AcidRain); weatherEvents.Add(1, ClimateEvent.WildFire); weatherEvents.Add(2, ClimateEvent.Hurricane); weatherEvents.Add(3, ClimateEvent.Smog); turnCounter = TURN_COUNTER; currentEvent = ClimateEvent.NoEvent; eventIndex = Random.Range(0, 4); //y = ((5/((x+15)/100))-4)/30 function to map score to probability }
private void LoadEvent(int climateEventIndex) { //delay for x seconds //MainGameUI.hidestuff currentEventIndex = climateEventIndex; ClimateEvent ce = events[climateEventIndex]; if (ce.location >= 0) { StartCoroutine(MainGameUI.instance.ShowEvent(ce.location)); } print("Load Event:" + ce.title); title.text = ce.title; prompt.text = ce.prompt; int[] resourceValues = MainGameBackend.instance.getResourceValues(); int moneyVal = resourceValues[0]; int scienceVal = resourceValues[1]; int globalCoopVal = resourceValues[2]; int educationVal = resourceValues[3]; for (int i = 0; i < buttons.Length; i++) { if (i < ce.choices.Length) { Choice c = ce.choices[i]; buttons[i].SetActive(true); buttons[i].GetComponentInChildren <TextMeshProUGUI>().text = ce.choices[i].text; if (c.moneyRequired > moneyVal || c.scienceRequired > scienceVal || c.globalCoopRequired > globalCoopVal || c.educationRequired > educationVal) { buttons[i].GetComponent <Button>().interactable = false; } else { buttons[i].GetComponent <Button>().interactable = true; } } //if there is less than i choices, disable the unused buttons else { buttons[i].SetActive(false); } } }
private void AnyEventsTriggered() { float[] metricValues = MainGameBackend.instance.getMetricValues(); float glblTemp = metricValues[0]; float oceanTemp = metricValues[1]; float seaLvl = metricValues[2]; float iceSheet = metricValues[3]; float co2Cond = metricValues[4]; bool[] triggered = getFlagValues(); for (int i = 0; i < events.Length; i++) { ClimateEvent ce = events[i]; if (glblTemp >= ce.glblTempCond && oceanTemp >= ce.oceanTempCond && seaLvl >= ce.seaLvlCond && iceSheet >= ce.iceSheetCond && co2Cond >= ce.co2Cond && !triggered[i]) { LoadEvent(i); } } }