private void UpdateOddsText() { // Update the text displaying the combat odds GameObject.Find("OddsText").GetComponent <TextMeshProUGUI>().text = "Combat Odds " + GlobalDefinitions.ConvertOddsToString( CalculateBattleOddsRoutines.ReturnCombatOdds( currentCombat.GetComponent <Combat>().defendingUnits, currentCombat.GetComponent <Combat>().attackingUnits, currentCombat.GetComponent <Combat>().attackAirSupport)) + "\nDefense = " + CalculateBattleOddsRoutines.CalculateDefenseFactor( currentCombat.GetComponent <Combat>().defendingUnits, currentCombat.GetComponent <Combat>().attackingUnits) + "\nAttack = " + CalculateBattleOddsRoutines.CalculateAttackFactor( currentCombat.GetComponent <Combat>().attackingUnits, currentCombat.GetComponent <Combat>().attackAirSupport); }
// Called when the user select to change the status of air support on the combat resolution gui public void AddAttackAirSupport() { if (GetComponent <Toggle>().isOn) { GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.ADDCOMBATAIRSUPPORTKEYWORD + " " + name); if (GlobalDefinitions.tacticalAirMissionsThisTurn < GlobalDefinitions.maxNumberOfTacticalAirMissions) { curentCombat.GetComponent <Combat>().attackAirSupport = true; GlobalDefinitions.WriteToLogFile("addAttackAirSupport: incrementing GlobalDefinitions.tacticalAirMissionsThisTurn"); GlobalDefinitions.tacticalAirMissionsThisTurn++; attackFactorTextGameObject.GetComponent <TextMeshProUGUI>().text = CalculateBattleOddsRoutines.CalculateAttackFactor( curentCombat.GetComponent <Combat>().attackingUnits, curentCombat.GetComponent <Combat>().attackAirSupport).ToString(); oddsTextGameObject.GetComponent <TextMeshProUGUI>().text = GlobalDefinitions.ConvertOddsToString( CalculateBattleOddsRoutines.ReturnCombatOdds(curentCombat.GetComponent <Combat>().defendingUnits, curentCombat.GetComponent <Combat>().attackingUnits, curentCombat.GetComponent <Combat>().attackAirSupport)); } else { GlobalDefinitions.GuiUpdateStatusMessage("No more air support missions left to assign"); GetComponent <Toggle>().isOn = false; } } else { GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.REMOVECOMBATAIRSUPPORTKEYWORD + " " + name); curentCombat.GetComponent <Combat>().attackAirSupport = false; GlobalDefinitions.tacticalAirMissionsThisTurn--; attackFactorTextGameObject.GetComponent <TextMeshProUGUI>().text = CalculateBattleOddsRoutines.CalculateAttackFactor( curentCombat.GetComponent <Combat>().attackingUnits, curentCombat.GetComponent <Combat>().attackAirSupport).ToString(); oddsTextGameObject.GetComponent <TextMeshProUGUI>().text = GlobalDefinitions.ConvertOddsToString( CalculateBattleOddsRoutines.ReturnCombatOdds( curentCombat.GetComponent <Combat>().defendingUnits, curentCombat.GetComponent <Combat>().attackingUnits, curentCombat.GetComponent <Combat>().attackAirSupport)); } }
/// <summary> /// This executes when the OK button on the combat assignment gui is pressed /// </summary> public void OkCombatGUISelection() { Button yesButton = null; Button noButton = null; List <GameObject> removeUnit = new List <GameObject>(); GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.COMBATGUIOKKEYWORD + " " + name); removeUnit.Clear(); // Get a list of the defending units that were not added to the combat foreach (GameObject unit in singleCombat.GetComponent <Combat>().defendingUnits) { if (!unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack) { removeUnit.Add(unit); } } // Now go through the defenders and remove non-committed units from the combat foreach (GameObject unit in removeUnit) { singleCombat.GetComponent <Combat>().defendingUnits.Remove(unit); } removeUnit.Clear(); // Get a list of the attacking units that were not added to the combat foreach (GameObject unit in singleCombat.GetComponent <Combat>().attackingUnits) { if (!unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack) { removeUnit.Add(unit); } } // Now go through the attackers and remove non-committed units from the combat foreach (GameObject unit in removeUnit) { singleCombat.GetComponent <Combat>().attackingUnits.Remove(unit); } // Need to check if the user has selected both attackers and defenders. If not then nothing should be changed if ((singleCombat.GetComponent <Combat>().attackingUnits.Count == 0) || (singleCombat.GetComponent <Combat>().defendingUnits.Count == 0)) { NoAbort(); } // Check for if a combat is being selected that is less than 1:6 odds - this is useless but need to check just in case else if (GlobalDefinitions.ConvertOddsToString(CalculateBattleOddsRoutines.ReturnCombatGUICombatOdds( singleCombat.GetComponent <Combat>().defendingUnits, singleCombat.GetComponent <Combat>().attackingUnits)) == "1:7") { // If the odds or worse than 1:6 then the attackers are eliminated and no battle takes place. It does not // count as an attack on the defending units // Turn off the combat assignment gui before brining up the yes/no question so the user doesn't select any of the buttons on the gui before answering the // question which creates all kinds of problems transform.parent.gameObject.SetActive(false); GlobalDefinitions.AskUserYesNoQuestion("Attacking at odds less than 1:6 is useless: do you want to continue? Note that if Yes is selected the attackers will be eliminated and this will not count as a combat if you are trying to use this as a soak-off attack", ref yesButton, ref noButton, YesContinue, NoAbort, 4f, 5f); } else { foreach (Transform childTransform in transform.parent.transform) { if ((childTransform.GetComponent <CombatToggleRoutines>() != null) && (childTransform.GetComponent <CombatToggleRoutines>().unit != null)) { //if (childTransform.GetComponent<Toggle>().isOn && GlobalDefinitions.localControl) I removed the local control check here because units on the remote computer and not being reset. The local control check was added for a reason, though, and I don't know why which is why I'm leaving this here as a comment if (childTransform.GetComponent <Toggle>().isOn) { GlobalDefinitions.UnhighlightUnit(childTransform.GetComponent <CombatToggleRoutines>().unit); childTransform.GetComponent <CombatToggleRoutines>().unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = true; } } } // Check whether air support is to be used in this attack if (GlobalDefinitions.combatAirSupportToggle != null) { if (GlobalDefinitions.combatAirSupportToggle.GetComponent <Toggle>().isOn) { singleCombat.GetComponent <Combat>().attackAirSupport = true; } else { singleCombat.GetComponent <Combat>().attackAirSupport = false; } } // Check if carpet bombing is to be used in this attack if (GlobalDefinitions.combatCarpetBombingToggle != null) { if (GlobalDefinitions.combatCarpetBombingToggle.GetComponent <Toggle>().isOn) { GlobalDefinitions.carpetBombingUsedThisTurn = true; GlobalDefinitions.numberOfCarpetBombingsUsed++; singleCombat.GetComponent <Combat>().carpetBombing = true; singleCombat.GetComponent <Combat>().defendingUnits[0].GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().carpetBombingActive = true; } else { singleCombat.GetComponent <Combat>().carpetBombing = false; } } GlobalDefinitions.allCombats.Add(singleCombat); GUIRoutines.RemoveGUI(GlobalDefinitions.combatGUIInstance); // Check if the Must Attack toggle is on and if it is highlight uncommitted units that must participate in an attack if ((GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "alliedCombatStateInstance") || (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "germanCombatStateInstance") || GlobalDefinitions.MustAttackToggle.GetComponent <Toggle>().isOn) { CombatRoutines.CheckIfRequiredUnitsAreUncommitted(GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality, true); } // Determine what state we are in and set the next executeMethod if ((GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "alliedMovementStateInstance") || (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "germanMovementStateInstance")) { GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod = GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.GetComponent <MovementState>().ExecuteSelectUnit; } if ((GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "alliedCombatStateInstance") || (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "germanCombatStateInstance")) { GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod = GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.GetComponent <CombatState>().ExecuteSelectUnit; } if (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "alliedInvasionStateInstance") { GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod = GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.GetComponent <AlliedInvasionState>().ExecuteSelectUnit; } if (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "alliedAirborneStateInstance") { GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod = GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.GetComponent <AlliedAirborneState>().ExecuteSelectUnit; } } }