private void NoAbort() { foreach (GameObject unit in singleCombat.GetComponent <Combat>().defendingUnits) { if (unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack) { unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = false; } } foreach (GameObject unit in singleCombat.GetComponent <Combat>().attackingUnits) { if (unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack) { unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = false; } } Destroy(singleCombat); GUIRoutines.RemoveGUI(GlobalDefinitions.combatGUIInstance); 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; CombatRoutines.CheckIfRequiredUnitsAreUncommitted(GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality, true); } else { GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod = GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.GetComponent <MovementState>().ExecuteSelectUnit; CombatRoutines.CheckIfRequiredUnitsAreUncommitted(GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality, false); } }
/// <summary> /// Toggle that displays all units that must be attacked /// </summary> public void DisplayMustAttackUnits() { GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.DISPLAYMUSTATTACKTOGGLEWORD); if (gameObject.GetComponent <Toggle>().isOn) { CombatRoutines.CheckIfRequiredUnitsAreUncommitted(GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality, true); } else { foreach (GameObject unit in GlobalDefinitions.alliedUnitsOnBoard) { GlobalDefinitions.UnhighlightUnit(unit); } foreach (GameObject unit in GlobalDefinitions.germanUnitsOnBoard) { GlobalDefinitions.UnhighlightUnit(unit); } } //else //{ // foreach (GameObject unit in GlobalDefinitions.mustAttackUnits) // GlobalDefinitions.unhighlightUnit(unit); // foreach (GameObject unit in GlobalDefinitions.mustBeAttackedUnits) // GlobalDefinitions.unhighlightUnit(unit); // GlobalDefinitions.mustAttackUnits.Clear(); // GlobalDefinitions.mustBeAttackedUnits.Clear(); //} }
// Cancels the combat assignment public void CancelCombatGUISelection() { GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.COMBATGUICANCELKEYWORD + " " + name); foreach (GameObject unit in singleCombat.GetComponent <Combat>().defendingUnits) { GlobalDefinitions.UnhighlightUnit(unit); unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = false; } foreach (GameObject unit in singleCombat.GetComponent <Combat>().attackingUnits) { GlobalDefinitions.UnhighlightUnit(unit); unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = false; } Destroy(singleCombat); GUIRoutines.RemoveGUI(GlobalDefinitions.combatGUIInstance); 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; } }
/// <summary> /// This routine looks through the attackers and defenders and determines if there are defenders that need to be added to the mustBeAttackedUnits due to being in the ZOC of a defender being attacked cross river /// </summary> //private void checkIfDefenderToBeAdded() //{ // foreach (GameObject defendingUnit in currentCombat.GetComponent<Combat>().defendingUnits) // { // //check if the defender is across a river from a committed attacker // foreach (GameObject attackingUnit in currentCombat.GetComponent<Combat>().attackingUnits) // { // if (attackingUnit.GetComponent<UnitDatabaseFields>().isCommittedToAnAttack) // { // foreach (HexDefinitions.HexSides hexSide in Enum.GetValues(typeof(HexDefinitions.HexSides))) // { // if ((defendingUnit.GetComponent<UnitDatabaseFields>().occupiedHex.GetComponent<HexDatabaseFields>().Neighbors[(int)hexSide] != null) // && (defendingUnit.GetComponent<UnitDatabaseFields>().occupiedHex.GetComponent<HexDatabaseFields>().Neighbors[(int)hexSide] == attackingUnit.GetComponent<UnitDatabaseFields>().occupiedHex) // && defendingUnit.GetComponent<UnitDatabaseFields>().occupiedHex.GetComponent<BoolArrayData>().riverSides[(int)hexSide]) // { // // If the defender is committed to the attack, make sure it is on the mustBeAttackedUnits list // if (defendingUnit.GetComponent<UnitDatabaseFields>().isCommittedToAnAttack && !GlobalDefinitions.mustBeAttackedUnits.Contains(defendingUnit)) // { // GlobalDefinitions.mustBeAttackedUnits.Add(defendingUnit); // } // else // { // // Check if the defendingUnit is in the ZOC of another defender that is being attacked cross river // foreach (GameObject committedDefender in currentCombat.GetComponent<Combat>().defendingUnits) // { // if (committedDefender.GetComponent<UnitDatabaseFields>().isCommittedToAnAttack && (committedDefender != defendingUnit)) // { // foreach (HexDefinitions.HexSides hexSide2 in Enum.GetValues(typeof(HexDefinitions.HexSides))) // { // if ((committedDefender.GetComponent<UnitDatabaseFields>().occupiedHex.GetComponent<HexDatabaseFields>().Neighbors[(int)hexSide2] != null) // && (committedDefender.GetComponent<UnitDatabaseFields>().occupiedHex.GetComponent<HexDatabaseFields>().Neighbors[(int)hexSide2] == defendingUnit.GetComponent<UnitDatabaseFields>().occupiedHex) // && committedDefender.GetComponent<UnitDatabaseFields>().occupiedHex.GetComponent<BoolArrayData>().exertsZOC[(int)hexSide2] // && GlobalDefinitions.checkForRiverBetweenTwoHexes(attackingUnit.GetComponent<UnitDatabaseFields>().occupiedHex, committedDefender.GetComponent<UnitDatabaseFields>().occupiedHex)) // { // // If we get here the defending unit needs to get added to the mustBeAttackedUnits list // if (!GlobalDefinitions.mustBeAttackedUnits.Contains(defendingUnit)) // { // GlobalDefinitions.mustBeAttackedUnits.Add(defendingUnit); // // if (!defendingUnit.GetComponent<UnitDatabaseFields>().isCommittedToAnAttack) // // GlobalDefinitions.highlightUnit(unit); // } // } // } // } // } // } // } // } // } // } // } //} /// <summary> /// this routine will reset the defenders that are in the mustBeAttackedUnits list /// </summary> public void CheckDefenderToBeRemoved() { // The easiest thing to do is to remove all current defenders from the mustBeAttackedUnts list and then go through and add the units that need to be added //foreach (GameObject defendingUnit in currentCombat.GetComponent<Combat>().defendingUnits) // if (GlobalDefinitions.mustBeAttackedUnits.Contains(defendingUnit)) // { // GlobalDefinitions.mustBeAttackedUnits.Remove(defendingUnit); // //GlobalDefinitions.unhighlightUnit(defendingUnit); // } if (currentCombat.GetComponent <Combat>().attackingUnits.Count > 0) { if ((GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "alliedCombatStateInstance") || (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "germanCombatStateInstance")) { CombatRoutines.CheckIfRequiredUnitsAreUncommitted(GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality, true); } else { CombatRoutines.CheckIfRequiredUnitsAreUncommitted(GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality, false); } //checkIfDefenderToBeAdded(); } }
/// <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; } } }
/// <summary> /// This routine is called when the user selects the Resolve button for a combat /// </summary> public void ResolutionSelected() { // Write out the name of the toggle being executed in order to send it once the die roll is known if (GlobalDefinitions.localControl) { GlobalDefinitions.CombatResultToggleName = name; } // If combat resolution hasn't started then check to make sure all required combats have been created if (!GlobalDefinitions.combatResolutionStarted) { if (CombatRoutines.CheckIfRequiredUnitsAreUncommitted(GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality, true)) { GlobalDefinitions.GuiUpdateStatusMessage("Cannot start combat resolution, highlighted units must be committed to combat first."); } else { // All required units are attacking or being attacked GlobalDefinitions.combatResolutionStarted = true; // Get rid of the "Continue" button since combat resolution has started GlobalDefinitions.combatResolutionOKButton.SetActive(false); // Once combat resolution starts, canceling an attack is no longer an option so get rid of all cancel buttons // Also can't assign any more air support so make those toggles non-interactive foreach (GameObject combat in GlobalDefinitions.allCombats) { if (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality == GlobalDefinitions.Nationality.Allied) { combat.GetComponent <Combat>().airSupportToggle.interactable = false; } DestroyImmediate(combat.GetComponent <Combat>().cancelButton.gameObject); } // Only check for carpet bombing if Allies are attacking. This is needed to keep the German attacks from being loaded if (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality == GlobalDefinitions.Nationality.Allied) { GlobalDefinitions.combatResultsFromLastTurn.Clear(); GlobalDefinitions.hexesAttackedLastTurn.Clear(); // Store all hexes being attacked this turn. Used for carpet bombing availability next turn foreach (GameObject combat in GlobalDefinitions.allCombats) { foreach (GameObject defender in combat.GetComponent <Combat>().defendingUnits) { if (!GlobalDefinitions.hexesAttackedLastTurn.Contains(defender.GetComponent <UnitDatabaseFields>().occupiedHex)) { GlobalDefinitions.hexesAttackedLastTurn.Add(defender.GetComponent <UnitDatabaseFields>().occupiedHex); } } } } } } if (GlobalDefinitions.combatResolutionStarted) { CombatResolutionRoutines.DetermineCombatResults(curentCombat, gameObject.GetComponent <RectTransform>().anchoredPosition); // Get rid of the locate button on the attack being resolved, can't gaurantee that the units are still there after resolution DestroyImmediate(curentCombat.GetComponent <Combat>().locateButton.gameObject); //Get rid of the resolve button since the battle has been resolved. This is also used to determine if all combats have been resolved. //DestroyImmediate(GameObject.Find(GlobalDefinitions.CombatResultToggleName)); GUIRoutines.RemoveGUI(gameObject); } // Check if all the attacks have been resolved by seeing if there are any more Resolve buttons left bool allAttacksResolved = true; foreach (GameObject combat in GlobalDefinitions.allCombats) { if (combat.GetComponent <Combat>().resolveButton != null) { allAttacksResolved = false; } } // If all attacks have been resolved turn on the quit button (which is the continue button with the text changed if (allAttacksResolved) { GlobalDefinitions.combatResolutionOKButton.SetActive(true); GlobalDefinitions.combatResolutionOKButton.GetComponent <Button>().GetComponentInChildren <Text>().text = "Quit"; } }
/// <summary> /// Called from the combat resolution gui to cancel a combat - determined by the combatResoultionArrayIndex loaded /// </summary> public void CancelAttack() { GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.COMBATCANCELKEYWORD + " " + name); // Since we are going to reset the mustBeAttackedUnits list I need to clear out all the highlighting since // there are cases where units were added to the list because of cross river attacks but haven't been assigned // to a combat yet. If I don't clear highlighting here they won't be reset because they aren't mustBeAttackedUnits anymore foreach (GameObject unit in curentCombat.GetComponent <Combat>().defendingUnits) { unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = false; GlobalDefinitions.UnhighlightUnit(unit); } foreach (GameObject unit in curentCombat.GetComponent <Combat>().attackingUnits) { unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = false; GlobalDefinitions.UnhighlightUnit(unit); } // Check if we need to give a air mission back if (curentCombat.GetComponent <Combat>().attackAirSupport) { GlobalDefinitions.tacticalAirMissionsThisTurn--; } // Need to check if we need to give back carpet bombing if (curentCombat.GetComponent <Combat>().carpetBombing) { GlobalDefinitions.carpetBombingUsedThisTurn = false; GlobalDefinitions.numberOfCarpetBombingsUsed--; curentCombat.GetComponent <Combat>().carpetBombing = false; curentCombat.GetComponent <Combat>().defendingUnits[0].GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().carpetBombingActive = false; } GlobalDefinitions.allCombats.Remove(curentCombat); // Need to get rid of all the buttons and toggles in the remaining combats since they will be regenerated foreach (GameObject combat in GlobalDefinitions.allCombats) { DestroyImmediate(combat.GetComponent <Combat>().locateButton); DestroyImmediate(combat.GetComponent <Combat>().resolveButton); DestroyImmediate(combat.GetComponent <Combat>().cancelButton); DestroyImmediate(combat.GetComponent <Combat>().airSupportToggle); } GUIRoutines.RemoveGUI(GlobalDefinitions.combatResolutionGUIInstance); 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); } else { CombatRoutines.CheckIfRequiredUnitsAreUncommitted(GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality, false); } if (GlobalDefinitions.allCombats.Count > 0) { CombatResolutionRoutines.CombatResolutionDisplay(); } else { // If the last battle has been canceled then turn the button back on GameObject.Find("ResolveCombatButton").GetComponent <Button>().interactable = true; } }