public void SelectUnitToMove() { GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.MULTIUNITSELECTIONKEYWORD + " " + name); List <GameObject> movementHexes = new List <GameObject>(); if (GetComponent <Toggle>().isOn) { if (unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack) { GlobalDefinitions.GuiUpdateStatusMessage("Unit selected is committed to an attack\nCancel attack if you want to move this unit"); GetComponent <Toggle>().isOn = false; } else { GlobalDefinitions.HighlightUnit(unit); GlobalDefinitions.selectedUnit = unit; GlobalDefinitions.startHex = unit.GetComponent <UnitDatabaseFields>().occupiedHex; // We don't want to highlight the movement hexes if we're in setup mode if (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name != "setUpStateInstance") { movementHexes = GameControl.movementRoutinesInstance.GetComponent <MovementRoutines>().ReturnAvailableMovementHexes(GlobalDefinitions.startHex, GlobalDefinitions.selectedUnit); foreach (GameObject hex in movementHexes) { GlobalDefinitions.HighlightHexForMovement(hex); } } GUIRoutines.RemoveGUI(transform.parent.gameObject); 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>().ExecuteSelectUnitDestination; } else if (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "setUpStateInstance") { GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod = GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.GetComponent <SetUpState>().ExecuteSelectUnitDestination; } //if (GlobalDefinitions.localControl && (GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.Network)) // GameControl.sendMouseClickToNetwork(GlobalDefinitions.selectedUnit, GlobalDefinitions.startHex); } } else { // This actually should never happen since when the toggle is selected the gui is removed so there is never a chance to unselect the toggle GUIRoutines.RemoveGUI(transform.parent.gameObject); } }
/// <summary> /// Highlights the hexes for the invasion area passed /// </summary> /// <param name="targetArea"></param> private void HighlightAvailableInvasionHexes(InvasionArea targetArea) { foreach (GameObject hex in targetArea.invasionHexes) { if (hex.GetComponent <HexDatabaseFields>().occupyingUnit.Count < 2) { GlobalDefinitions.HighlightHexForMovement(hex); hex.GetComponent <HexDatabaseFields>().availableForMovement = true; } } }
/// <summary> /// Called when a unit is selected from the gui to retreat when there are multiple units avaialble /// </summary> public void SelectUnitsToMove() { if (GetComponent <Toggle>().isOn) { GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.RETREATSELECTIONKEYWORD + " " + name); // The unit has been selected so move it to the zero position in the list since that is what will be moved GlobalDefinitions.retreatingUnits.Remove(GetComponent <RetreatToggleRoutines>().unit); GlobalDefinitions.retreatingUnits.Insert(0, GetComponent <RetreatToggleRoutines>().unit); List <GameObject> retreatHexes = CombatResolutionRoutines.ReturnRetreatHexes(GetComponent <RetreatToggleRoutines>().unit); if (retreatHexes.Count > 0) { GlobalDefinitions.HighlightUnit(unit); foreach (GameObject hex in retreatHexes) { GlobalDefinitions.HighlightHexForMovement(hex); } GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod = GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.GetComponent <CombatState>().ExecuteRetreatMovement; } // This executes when there is no retreat available for the unit. While the units without retreat available is checked early on, // this is a case where there was more than one unit that needed to retreat but there wasn't room for all of them else { GlobalDefinitions.GuiUpdateStatusMessage("No retreat available - eliminating unit" + unit.name); GlobalDefinitions.MoveUnitToDeadPile(unit); GlobalDefinitions.retreatingUnits.RemoveAt(0); // Need to call selection routines in case there are more units that cannot retreat CombatResolutionRoutines.SelectUnitsForRetreat(); } GUIRoutines.RemoveGUI(transform.parent.gameObject); } }
public void MoveSelectedUnit() { if (GetComponent <Toggle>().isOn) { GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.SELECTPOSTCOMBATMOVEMENTKEYWORD + " " + name); // The user has selected a unit. If there is only one hex available move it there. // Otherwise turn off the gui, highlight the hexes available and wait for user selection if (GlobalDefinitions.hexesAvailableForPostCombatMovement.Count == 0) { // This should never happen GlobalDefinitions.GuiUpdateStatusMessage("Internal Error - Post-combat unit selected for move but no hexes available"); } else if (GlobalDefinitions.hexesAvailableForPostCombatMovement.Count == 1) { if (GlobalDefinitions.HexUnderStackingLimit(GlobalDefinitions.hexesAvailableForPostCombatMovement[0], GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality)) { // Don't need to wait for user input since there is only one hex available // If the unit is on a sea hex than this is a successful invasion if (gameObject.GetComponent <PostCombatMovementToggleRoutines>().unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().sea) { GlobalDefinitions.hexesAvailableForPostCombatMovement[0].GetComponent <HexDatabaseFields>().successfullyInvaded = true; GlobalDefinitions.hexesAvailableForPostCombatMovement[0].GetComponent <HexDatabaseFields>().alliedControl = true; } GameControl.movementRoutinesInstance.GetComponent <MovementRoutines>().MoveUnit(GlobalDefinitions.hexesAvailableForPostCombatMovement[0], gameObject.GetComponent <PostCombatMovementToggleRoutines>().unit.GetComponent <UnitDatabaseFields>().occupiedHex, gameObject.GetComponent <PostCombatMovementToggleRoutines>().unit); } else { GlobalDefinitions.GuiUpdateStatusMessage("Hex is at stacking limit; cannot move unit"); GetComponent <Toggle>().isOn = false; } } else { // The user has options so turn off the gui, highlight the available hexes, load the unit selected, and set the flag to wait for user input GlobalDefinitions.postCombatMovementGuiInstance.SetActive(false); foreach (GameObject hex in GlobalDefinitions.hexesAvailableForPostCombatMovement) { if (GlobalDefinitions.HexUnderStackingLimit(hex, GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality)) { hex.GetComponent <HexDatabaseFields>().availableForMovement = true; GlobalDefinitions.HighlightHexForMovement(hex); } } GlobalDefinitions.unitSelectedForPostCombatMovement = gameObject.GetComponent <PostCombatMovementToggleRoutines>().unit; GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod = GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.GetComponent <CombatState>().ExecutePostCombatMovement; } } // This executes when a unit is deselected else { GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.DESELECTPOSTCOMBATMOVEMENTKEYWORD + " " + name); // Take the unit and move it back to its beginning hex GameControl.movementRoutinesInstance.GetComponent <MovementRoutines>().MoveUnit(beginningHex, gameObject.GetComponent <PostCombatMovementToggleRoutines>().unit.GetComponent <UnitDatabaseFields>().occupiedHex, gameObject.GetComponent <PostCombatMovementToggleRoutines>().unit); } }