private void changeTransportSlider() { App app = UnityEngine.Object.FindObjectOfType <App>(); Nation player = State.getNations()[app.GetHumanIndex()]; int oldFlow = PlayerCalculator.calculateTransportFlow(player); // int oldFlow = player.industry.getTransportFlow(); updateFlow(player); int newFlow = PlayerCalculator.calculateTransportFlow(player); //If slider was reduced new flow will be less than old flow - return coal to player int difference = Math.Abs(oldFlow - newFlow); int totalNumberOfProvinces = PlayerCalculator.getTotalNumberOfProvinces(player); // In case we reduced the flow if (newFlow < oldFlow) { if (oldFlow <= totalNumberOfProvinces) { // do nothing } else if (oldFlow > totalNumberOfProvinces) { if (newFlow >= totalNumberOfProvinces) { player.collectResource(MyEnum.Resources.coal, difference * 0.2f); } else { player.collectResource(MyEnum.Resources.coal, (oldFlow - totalNumberOfProvinces) * 0.2f); } } } else // The case where we have increased the amount of flow { if (newFlow <= totalNumberOfProvinces) { // do nothing } else if (newFlow > totalNumberOfProvinces) { // The case where we were already making use of some coal for transport if (oldFlow >= totalNumberOfProvinces) { player.consumeResource(MyEnum.Resources.coal, difference * 0.2f); } else { player.consumeResource(MyEnum.Resources.coal, (newFlow - player.getProvinces().Count) * 0.2f); } } } updateTransportPanel(); }
private void updateTransportPanel() { Debug.Log("Begin Updating Transport Panel"); App app = UnityEngine.Object.FindObjectOfType <App>(); Nation player = State.getNations()[app.GetHumanIndex()]; int transportFlow = PlayerCalculator.calculateTransportFlow(player); int totalNumberProv = PlayerCalculator.getTotalNumberOfProvinces(player); int realTransportCapacity = PlayerCalculator.calculateMaxTransportFlow(player); Debug.Log("Transport Flow: " + transportFlow); Debug.Log("Current Transport Capacity: " + realTransportCapacity); // player.industry.setTransportFlow(PlayerCalculator.calculateTransportFlow(player)); float coalUsedForTransport = (transportFlow - totalNumberProv) * 0.2f; transportCapacity.text = transportFlow.ToString() + "/" + realTransportCapacity.ToString(); coalCapacity.text = player.getNumberResource(MyEnum.Resources.coal).ToString(); int remainingFlow = realTransportCapacity - transportFlow; Debug.Log("Remaining Flow Capacity: " + remainingFlow); if (PlayerCalculator.canBuildTrain(player)) { addTransportCapacityButton.interactable = true; } else { addTransportCapacityButton.interactable = false; } // Counter used for switching from first to second table in Production GUI int counter = 0; foreach (MyEnum.Resources res in Enum.GetValues(typeof(MyEnum.Resources))) { int producing = PlayerCalculator.getResourceProducing(player, res); int currentFlow = player.getResTransportFlow(res); Debug.Log("Resource is: " + res + "---------------------------------------------"); Debug.Log("Producing: " + producing); Debug.Log("Current Flow: " + currentFlow); //int systemFlow = player.industry.getTransportFlow(); int capacity = Math.Min(producing - currentFlow, remainingFlow); Debug.Log("Remaining " + res + " capacity: " + capacity); int max = currentFlow + capacity; Debug.Log("Max: " + max); if (counter <= 5) { Debug.Log("check 2553"); Text resFlow = resourceTableA.Rows[counter].Cells[1].GetComponentInChildren <Text>(); Slider resSlider = resourceTableA.Rows[counter].Cells[2].GetComponentInChildren <Slider>(); resFlow.text = currentFlow + "/" + producing; if (max == currentFlow && max < producing) { Debug.Log("poop"); resFlow.color = new Color32(170, 12, 12, 255); } else { resFlow.color = new Color32(0, 0, 0, 255); } resSlider.maxValue = max; resSlider.minValue = 0; resSlider.value = currentFlow; Debug.Log("check 2569"); } else { Debug.Log("check 2573"); Text resFlow = resourceTableB.Rows[counter % 6].Cells[1].GetComponentInChildren <Text>(); Slider resSlider = resourceTableB.Rows[counter % 6].Cells[2].GetComponentInChildren <Slider>(); resFlow.text = currentFlow + "/" + producing; if (max == currentFlow && max < producing) { Debug.Log("poop"); resFlow.color = new Color32(170, 12, 12, 255); } else { resFlow.color = new Color32(0, 0, 0, 255); } resSlider.maxValue = max; resSlider.minValue = 0; resSlider.value = currentFlow; } counter++; Debug.Log("Counter: " + counter); } }