/// <summary>
        /// Executed when the ok button is selected on the supply sources gui for supply assignment.  At the end of a phase.
        /// </summary>
        public void OkSupplyWithEndPhase()
        {
            GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.OKSUPPLYWITHENDPHASEKEYWORD + " " + name);

            // Reset all highlighting
            foreach (GameObject unit in GlobalDefinitions.alliedUnitsOnBoard)
            {
                GlobalDefinitions.UnhighlightUnit(unit);
                if (unit.GetComponent <UnitDatabaseFields>().inSupply)
                {
                    unit.GetComponent <UnitDatabaseFields>().supplyIncrementsOutOfSupply = 0;
                }
            }

            GameControl.supplyRoutinesInstance.GetComponent <SupplyRoutines>().CheckIfAlliedUnsuppliedUnitsShouldBeEliminated(false);
            GUIRoutines.RemoveGUI(GlobalDefinitions.supplySourceGUIInstance);

            // Got rid of the GUI, now get rid of the global copies of the supply gui's
            //int count = GlobalDefinitions.supplyGUI.Count;
            //for (int i = 0; i < count; i++)
            //    DestroyImmediate(GlobalDefinitions.supplyGUI[i]);
            //GlobalDefinitions.supplyGUI.Clear();

            // Turn the button back on
            GameObject.Find("SupplySourcesButton").GetComponent <Button>().interactable = true;

            GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.ExecuteQuit();
        }
        /// <summary>
        /// Determines the hex that the selected unit will invade from.
        /// </summary>
        /// <param name="selectedUnit"></param>
        public void GetUnitInvasionHex(GameObject selectedUnit, GameObject selectedHex)
        {
            if (selectedHex != null)
            {
                if (selectedHex.GetComponent <HexDatabaseFields>().availableForMovement)
                {
                    GameControl.movementRoutinesInstance.GetComponent <MovementRoutines>().LandAlliedUnitFromOffBoard(selectedUnit, selectedHex, false);
                }
                else
                {
                    GlobalDefinitions.GuiDisplayUnitsOnHex(selectedHex);
                    GlobalDefinitions.GuiUpdateStatusMessage("Hex selected is not available for invasion, must select a highlighted hex");
                }
            }
            else
            {
                GlobalDefinitions.GuiUpdateStatusMessage("No hex selected, must select a highlighted hex");
            }

            if (GlobalDefinitions.selectedUnit != null)
            {
                GlobalDefinitions.UnhighlightUnit(GlobalDefinitions.selectedUnit);
            }
            GlobalDefinitions.selectedUnit = null;

            foreach (GameObject hex in HexDefinitions.allHexesOnBoard)
            {
                GlobalDefinitions.UnhighlightHex(hex.gameObject);
                hex.GetComponent <HexDatabaseFields>().availableForMovement = false;
            }
        }
Exemple #3
0
        /// <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();
            //}
        }
        /// <summary>
        /// Called to exit the supply gui when used for display
        /// </summary>
        public void OkSupply()
        {
            GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.OKSUPPLYKEYWORD + " " + name);

            // Reset all highlighting
            foreach (GameObject unit in GlobalDefinitions.alliedUnitsOnBoard)
            {
                GlobalDefinitions.UnhighlightUnit(unit);
                if (unit.GetComponent <UnitDatabaseFields>().inSupply)
                {
                    unit.GetComponent <UnitDatabaseFields>().supplyIncrementsOutOfSupply = 0;
                }
            }

            // I need to know whether this is the beginning or end of a turn since unsupplied units are only eliminated at the end of a turn
            // With the implementation of the AI there is no Allied supply state but I think that the check at the end of combat doesn't come through this path... which might not be right
            //if (GameControl.gameStateControlInstance.GetComponent<gameStateControl>().currentState == GameControl.alliedSupplyStateInstance.GetComponent<SupplyState>())
            GameControl.supplyRoutinesInstance.GetComponent <SupplyRoutines>().CheckIfAlliedUnsuppliedUnitsShouldBeEliminated(false);
            //else
            //GameControl.supplyRoutinesInstance.GetComponent<SupplyRoutines>().checkIfAlliedUnsuppliedUnitsShouldBeEliminated(true);

            // Turn the button back on
            GameObject.Find("SupplySourcesButton").GetComponent <Button>().interactable = true;

            GUIRoutines.RemoveGUI(GlobalDefinitions.supplySourceGUIInstance);
        }
Exemple #5
0
 /// <summary>
 /// Executes when the toogle is changed and either makes the units on the board visible or hides them
 /// </summary>
 public void HideUnits()
 {
     if (GameObject.Find("HideUnitsToggle").GetComponent <Toggle>().isOn)
     {
         // The toggle is on so hide the units
         //foreach (GameObject unit in GlobalDefinitions.germanUnitsOnBoard)
         //{
         //    Renderer targetRenderer = unit.GetComponent(typeof(SpriteRenderer)) as Renderer;
         //    targetRenderer.material.color = new Vector4(0f, 0f, 0f, 0f);
         //}
         //foreach (GameObject unit in GlobalDefinitions.alliedUnitsOnBoard)
         //{
         //    Renderer targetRenderer = unit.GetComponent(typeof(SpriteRenderer)) as Renderer;
         //    targetRenderer.material.color = new Vector4(0f, 0f, 0f, 0f);
         //}
         foreach (Transform unit in GlobalDefinitions.allUnitsOnBoard.transform)
         {
             Renderer targetRenderer = unit.GetComponent(typeof(SpriteRenderer)) as Renderer;
             targetRenderer.material.color = new Vector4(0f, 0f, 0f, 0f);
         }
     }
     else
     {
         // Bring the units back
         //foreach (GameObject unit in GlobalDefinitions.germanUnitsOnBoard)
         //    GlobalDefinitions.unhighlightUnit(unit);
         //foreach (GameObject unit in GlobalDefinitions.alliedUnitsOnBoard)
         //    GlobalDefinitions.unhighlightUnit(unit);
         foreach (Transform unit in GlobalDefinitions.allUnitsOnBoard.transform)
         {
             GlobalDefinitions.UnhighlightUnit(unit.gameObject);
         }
     }
 }
 /// <summary>
 /// This routine is called when attacking from a fortress is removed.  It toggles off the adjacent units
 /// </summary>
 /// <param name="fortressHex"></param>
 public void RemoveDefendersOfFortressAttack(GameObject fortressHex)
 {
     foreach (HexDefinitions.HexSides hexSide in Enum.GetValues(typeof(HexDefinitions.HexSides)))
     {
         if (fortressHex.GetComponent <HexDatabaseFields>().Neighbors[(int)hexSide] != null)
         {
             if (!fortressHex.GetComponent <BooleanArrayData>().riverSides[(int)hexSide])
             {
                 // No need to check the type of hex.  If there are enemy units on it turn the toggle off
                 if ((fortressHex.GetComponent <HexDatabaseFields>().Neighbors[(int)hexSide].GetComponent <HexDatabaseFields>().occupyingUnit.Count > 0) &&
                     (fortressHex.GetComponent <HexDatabaseFields>().Neighbors[(int)hexSide].GetComponent <HexDatabaseFields>().occupyingUnit[0].GetComponent <UnitDatabaseFields>().nationality !=
                      fortressHex.GetComponent <HexDatabaseFields>().occupyingUnit[0].GetComponent <UnitDatabaseFields>().nationality))
                 {
                     foreach (GameObject unit in fortressHex.GetComponent <HexDatabaseFields>().Neighbors[(int)hexSide].GetComponent <HexDatabaseFields>().occupyingUnit)
                     {
                         foreach (Transform childTransform in transform.parent.transform)
                         {
                             if ((childTransform.gameObject.GetComponent <CombatToggleRoutines>() != null) && (childTransform.gameObject.GetComponent <CombatToggleRoutines>().unit == unit))
                             {
                                 GlobalDefinitions.UnhighlightUnit(unit);
                                 unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = false;
                                 // Turn off the selection of the unit
                                 childTransform.GetComponent <Toggle>().isOn = false;
                                 // Allow the user to select the unit
                                 childTransform.GetComponent <Toggle>().interactable = true;
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #7
0
        // 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;
            }
        }
Exemple #8
0
        /// <summary>
        /// This routine takes the selectedUnit and places it on the hex at the location passed
        /// </summary>
        /// <param name="selectedUnit"></param>
        /// <param name="xCoord"></param>
        /// <param name="yCoord"></param>
        public void GetUnitSetupDestination(GameObject selectedUnit, int xCoord, int yCoord)
        {
            GameObject targetHex;

            targetHex = GeneralHexRoutines.GetHexAtXY(xCoord, yCoord);
            if ((targetHex != null) && (VerifyValidHex(selectedUnit, targetHex)))
            {
                // If the unit already occupies a hex (not gauranteed since this is setup) need
                // to remove it from the hex so it isn't counting against stacking when it isn't there
                if (selectedUnit.GetComponent <UnitDatabaseFields>().occupiedHex != null)
                {
                    GeneralHexRoutines.RemoveUnitFromHex(selectedUnit, selectedUnit.GetComponent <UnitDatabaseFields>().occupiedHex);
                }

                GeneralHexRoutines.PutUnitOnHex(selectedUnit, targetHex);
            }
            GlobalDefinitions.UnhighlightUnit(selectedUnit);
            selectedUnit.transform.parent = GlobalDefinitions.allUnitsOnBoard.transform;
            selectedUnit.GetComponent <UnitDatabaseFields>().inBritain = false;
            selectedUnit = null;
        }
Exemple #9
0
 public void AddOrSubtractExchangeFactors()
 {
     if (GetComponent <ExchangeToggleRoutines>().attacker)
     {
         if (GetComponent <Toggle>().isOn)
         {
             GlobalDefinitions.exchangeFactorsSelected += CalculateBattleOddsRoutines.ReturnAttackFactor(GetComponent <ExchangeToggleRoutines>().unit);
             GlobalDefinitions.unitsToExchange.Add(GetComponent <ExchangeToggleRoutines>().unit);
             GlobalDefinitions.HighlightUnit(GetComponent <ExchangeToggleRoutines>().unit);
             GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.ADDEXCHANGEKEYWORD + " " + name);
         }
         else
         {
             GlobalDefinitions.exchangeFactorsSelected -= CalculateBattleOddsRoutines.ReturnAttackFactor(GetComponent <ExchangeToggleRoutines>().unit);
             GlobalDefinitions.unitsToExchange.Remove(GetComponent <ExchangeToggleRoutines>().unit);
             GlobalDefinitions.UnhighlightUnit(GetComponent <ExchangeToggleRoutines>().unit);
             GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.REMOVEEXCHANGEKEYWORD + " " + name);
         }
     }
     else
     {
         if (GetComponent <Toggle>().isOn)
         {
             GlobalDefinitions.exchangeFactorsSelected += CalculateBattleOddsRoutines.CalculateUnitDefendingFactor(GetComponent <ExchangeToggleRoutines>().unit, attackingUnits);
             GlobalDefinitions.unitsToExchange.Add(GetComponent <ExchangeToggleRoutines>().unit);
             GlobalDefinitions.HighlightUnit(GetComponent <ExchangeToggleRoutines>().unit);
             GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.ADDEXCHANGEKEYWORD + " " + name);
         }
         else
         {
             GlobalDefinitions.exchangeFactorsSelected -= CalculateBattleOddsRoutines.CalculateUnitDefendingFactor(GetComponent <ExchangeToggleRoutines>().unit, attackingUnits);
             GlobalDefinitions.unitsToExchange.Remove(GetComponent <ExchangeToggleRoutines>().unit);
             GlobalDefinitions.UnhighlightUnit(GetComponent <ExchangeToggleRoutines>().unit);
             GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.REMOVEEXCHANGEKEYWORD + " " + name);
         }
     }
     GameObject.Find("ExchangeText").GetComponent <TextMeshProUGUI>().text = "Select " + GlobalDefinitions.exchangeFactorsToLose + " factors\nFactors selected so far: " + GlobalDefinitions.exchangeFactorsSelected;
 }
        /// <summary>
        /// This routine is called when a toggle value is changed (note not clicked - don't want to have the overhead of coding event handlers to use the onPointerClick
        /// </summary>
        public void CheckToggle()
        {
            if (GetComponent <Toggle>().isOn)
            {
                GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.SETSUPPLYKEYWORD + " " + name);

                // The toggle was turned on.  Turn any other toggles that are on off.
                // Don't need to reset highlighting since the highlighting routine called
                // sets all units.
                //GlobalDefinitions.writeToLogFile("checkToggle: number of supply GUI = " + GlobalDefinitions.supplyGUI.Count);
                //GlobalDefinitions.writeToLogFile("checkToggle: this toggle name = " + this.name);
                foreach (GameObject supplyGui in GlobalDefinitions.supplyGUI)
                {
                    if (supplyGui.GetComponent <SupplyGUIObject>().supplyToggle.name != this.name)
                    {
                        //GlobalDefinitions.writeToLogFile("checkToggle:      turning off Toggle = " + supplyGui.GetComponent<SupplyGUIObject>().supplyToggle.name);
                        supplyGui.GetComponent <SupplyGUIObject>().supplyToggle.GetComponent <Toggle>().isOn = false;
                    }
                }

                //GlobalDefinitions.writeToLogFile("checkToggle: setting currentSupplySource to " + supplySource.name);
                GlobalDefinitions.currentSupplySource = supplySource;
                GameControl.supplyRoutinesInstance.GetComponent <SupplyRoutines>().HighlightUnitsAvailableForSupply(supplySource);
            }
            else
            {
                GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.RESETSUPPLYKEYWORD + " " + name);

                GlobalDefinitions.currentSupplySource = null;
                // The toggle was turned off so reset all highlighting
                foreach (GameObject unit in GlobalDefinitions.alliedUnitsOnBoard)
                {
                    GlobalDefinitions.UnhighlightUnit(unit);
                }
            }
        }
        /// <summary>
        /// This routine is called when a new defender is added to the attack and updates the toggles on the combat gui
        /// </summary>
        private void RefreshAttackersBasedOnDefenders()
        {
            // First go through and enable all the attacking units since if I don't once a unit is disabled it will never be enabled again and this way
            // I don't have to explicitly check for adjacency to all defenders

            foreach (GameObject attackingUnit in currentCombat.GetComponent <Combat>().attackingUnits)
            {
                foreach (Transform childTransform in transform.parent.transform)
                {
                    if ((childTransform.gameObject.GetComponent <CombatToggleRoutines>() != null) && (childTransform.gameObject.GetComponent <CombatToggleRoutines>().unit == attackingUnit))
                    {
                        // check if there is an invasion taking place and if so do not turn the check back on.
                        if (!GameControl.combatRoutinesInstance.GetComponent <CombatRoutines>().CheckForInvadingAttacker(childTransform.gameObject.GetComponent <CombatToggleRoutines>().unit))
                        {
                            childTransform.gameObject.GetComponent <Toggle>().interactable = true;
                        }
                    }
                }
            }

            // Go through each of the defenders and gray out any attacker that isn't adjacent.  By going through each of the defenders I am left
            // with only attackers that are adjacent to all defending units
            foreach (GameObject defendingUnit in currentCombat.GetComponent <Combat>().defendingUnits)
            {
                // Only check for adjacency if the defnder is selected

                // When this is called because of the code changing a toggle status, the routine is called before the committed variable is set (since it is event triggered
                // I used to check the isCommittedToAttack variable but this doesn't work in complex situations.  Therefore I will check if the unit is committed to the attack by
                // checking the unit's toggle status

                bool defendererIsCommitted = false;
                foreach (Transform defenderChildTransform in transform.parent.transform)
                {
                    if ((defenderChildTransform.gameObject.GetComponent <CombatToggleRoutines>() != null) &&
                        (defenderChildTransform.gameObject.GetComponent <CombatToggleRoutines>().unit == defendingUnit))
                    {
                        if (defenderChildTransform.gameObject.GetComponent <Toggle>().isOn)
                        {
                            defendererIsCommitted = true;
                        }
                    }
                }

                if (defendererIsCommitted)
                {
                    foreach (GameObject attackingUnit in currentCombat.GetComponent <Combat>().attackingUnits)
                    {
                        if (!GlobalDefinitions.TwoUnitsAdjacent(attackingUnit, defendingUnit))
                        {
                            // The attacking unit is not adjacent to the defending unit so it needs to be greyed out and disabled in the display
                            foreach (Transform childTransform in transform.parent.transform)
                            {
                                if ((childTransform.gameObject.GetComponent <CombatToggleRoutines>() != null) && (childTransform.gameObject.GetComponent <CombatToggleRoutines>().unit == attackingUnit))
                                {
                                    GlobalDefinitions.WriteToLogFile("refreshAttackersBasedOnDefenders: decommitting attacker and making non-interactable " + attackingUnit.name);
                                    GlobalDefinitions.UnhighlightUnit(attackingUnit);
                                    attackingUnit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = false;
                                    childTransform.gameObject.GetComponent <Toggle>().isOn         = false;
                                    childTransform.gameObject.GetComponent <Toggle>().interactable = false;
                                }
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// This routine is called whenever an unit selection toggle on the combat gui is changed
        /// </summary>
        public void AddOrDeleteSelectedUnit()
        {
            if (GetComponent <Toggle>().isOn)
            {
                // Turn on the toggle on the remote computer
                GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.SETCOMBATTOGGLEKEYWORD + " " + name);

                unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = true;
                GlobalDefinitions.HighlightUnit(unit);
                if (attackingUnitFlag)
                {
                    // An attacking unit was added

                    // Need to check for adding an attack from a fortress.
                    if (unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().fortress)
                    {
                        AddDefendersOfFortressAttack(unit.GetComponent <UnitDatabaseFields>().occupiedHex);
                    }
                    else
                    {
                        RefreshDefendersBasedOnAttackers();
                    }
                }
                else
                {
                    // A defending unit was added

                    // If the defender that was just added is a unit in a fortress, go through and turn on all other units that
                    // are in the fortress since attacking into a fortress means you have to attack all defenders

                    // Loop through the other toggles
                    if (unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().fortress)
                    {
                        foreach (Transform childTransform in transform.parent.transform)
                        {
                            if ((childTransform.gameObject.GetComponent <CombatToggleRoutines>() != null) &&
                                (childTransform.gameObject.GetComponent <CombatToggleRoutines>().unit != null) &&
                                (childTransform.gameObject.GetComponent <CombatToggleRoutines>().unit != unit) &&
                                (childTransform.gameObject.GetComponent <CombatToggleRoutines>().unit.GetComponent <UnitDatabaseFields>().occupiedHex ==
                                 unit.GetComponent <UnitDatabaseFields>().occupiedHex) &&
                                !childTransform.GetComponent <Toggle>().isOn)
                            {
                                // This is another unit in the fotress, turn it on also.  Note this doesn't add to the checks that need
                                // to be done because it is on the same hex as the unit being checked already
                                childTransform.GetComponent <Toggle>().isOn = true;
                            }
                        }
                    }

                    RefreshAttackersBasedOnDefenders();
                }
            }
            else
            {
                // Turn off the toggle on the remote computer
                GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.RESETCOMBATTOGGLEKEYWORD + " " + name);

                GlobalDefinitions.UnhighlightUnit(unit);
                unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = false;
                if (attackingUnitFlag)
                {
                    // An attacking unit was removed

                    // Need to check for removing an attack from a fortress.  If there are no more units attacking from a fortress than remove the adjacent units.
                    // They still may need to be attacked due to other units but that will be set by the process below.
                    if (unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().fortress)
                    {
                        bool attackStillTakingPlace = false;
                        foreach (Transform childTransform in transform.parent.transform)
                        {
                            if ((childTransform.gameObject.GetComponent <CombatToggleRoutines>() != null) &&
                                (childTransform.GetComponent <CombatToggleRoutines>().unit != null) &&
                                (childTransform.GetComponent <CombatToggleRoutines>().unit != unit) &&
                                (childTransform.GetComponent <CombatToggleRoutines>().unit.GetComponent <UnitDatabaseFields>().occupiedHex ==
                                 unit.GetComponent <UnitDatabaseFields>().occupiedHex) &&
                                childTransform.GetComponent <Toggle>().isOn)
                            {
                                attackStillTakingPlace = true;
                            }
                        }

                        if (!attackStillTakingPlace)
                        {
                            RemoveDefendersOfFortressAttack(unit.GetComponent <UnitDatabaseFields>().occupiedHex);
                        }
                    }
                    else
                    {
                        RefreshDefendersBasedOnAttackers();
                    }
                }
                else
                {
                    // A defending unit was removed

                    // If the defender that was just removed is a unit in a fortress, go through and turn on all other units that
                    // are in the fortress and turn them off also since you can't pick and choose what units to attack in a fortress

                    // Loop through the other toggles
                    if (unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().fortress)
                    {
                        foreach (Transform childTransform in transform.parent.transform)
                        {
                            if ((childTransform.gameObject.GetComponent <CombatToggleRoutines>() != null) &&
                                (childTransform.gameObject.GetComponent <CombatToggleRoutines>().unit != null) &&
                                (childTransform.gameObject.GetComponent <CombatToggleRoutines>().unit != unit) &&
                                (childTransform.gameObject.GetComponent <CombatToggleRoutines>().unit.GetComponent <UnitDatabaseFields>().occupiedHex ==
                                 unit.GetComponent <UnitDatabaseFields>().occupiedHex) &&
                                childTransform.GetComponent <Toggle>().isOn)
                            {
                                // This is another unit in the fotress, turn it off also.  Note this doesn't add to the checks that need
                                // to be done because it is on the same hex as the unit being checked already
                                childTransform.GetComponent <Toggle>().isOn = false;
                            }
                        }
                    }

                    RefreshAttackersBasedOnDefenders();
                }
            }

            // Check if carpet bombing is available with the current set of defenders
            // When the game sets the state of a defender or an attacker it is executing this before the gui is finished and the code
            // below will cause an exception.  Need to check that the toggle is there.
            if (GlobalDefinitions.combatCarpetBombingToggle != null)
            {
                if (CombatRoutines.CheckIfCarpetBombingIsAvailable(currentCombat))
                {
                    GlobalDefinitions.combatCarpetBombingToggle.GetComponent <Toggle>().interactable = true;
                }
                else
                {
                    GlobalDefinitions.combatCarpetBombingToggle.GetComponent <Toggle>().isOn         = false;
                    GlobalDefinitions.combatCarpetBombingToggle.GetComponent <Toggle>().interactable = false;
                }
            }

            UpdateOddsText();
        }
Exemple #13
0
        /// <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;
                }
            }
        }
Exemple #14
0
        /// <summary>
        /// This routine is what processes the message received from the opponent computer or from the saved command file when restarting a game
        /// </summary>
        /// <param name="message"></param>
        public static void ProcessCommand(string message)
        {
            char[]   delimiterChars = { ' ' };
            string[] switchEntries  = message.Split(delimiterChars);

            string[] lineEntries = message.Split(delimiterChars);
            // I am going to use the same routine to read records that is used when reading from a file.
            // In order to do this I need to drop the first word on the line since the files don't have key words
            for (int index = 0; index < (lineEntries.Length - 1); index++)
            {
                lineEntries[index] = lineEntries[index + 1];
            }

            switch (switchEntries[0])
            {
            case GlobalDefinitions.PLAYSIDEKEYWORD:
                if (switchEntries[1] == "German")
                {
                    GlobalDefinitions.sideControled = GlobalDefinitions.Nationality.German;
                }
                else
                {
                    GlobalDefinitions.sideControled = GlobalDefinitions.Nationality.Allied;
                }
                break;

            case GlobalDefinitions.PASSCONTROLKEYWORK:
                GlobalDefinitions.SwitchLocalControl(true);
                GlobalDefinitions.WriteToLogFile("processNetworkMessage: Message received to set local control");
                break;

            case GlobalDefinitions.SETCAMERAPOSITIONKEYWORD:
                Camera.main.transform.position = new Vector3(float.Parse(switchEntries[1]), float.Parse(switchEntries[2]), float.Parse(switchEntries[3]));
                Camera.main.GetComponent <Camera>().orthographicSize = float.Parse(switchEntries[4]);
                break;

            case GlobalDefinitions.MOUSESELECTIONKEYWORD:
                if (switchEntries[1] != "null")
                {
                    GameControl.inputMessage.GetComponent <InputMessage>().hex = GameObject.Find(switchEntries[1]);
                }
                else
                {
                    GameControl.inputMessage.GetComponent <InputMessage>().hex = null;
                }

                if (switchEntries[2] != "null")
                {
                    GameControl.inputMessage.GetComponent <InputMessage>().unit = GameObject.Find(switchEntries[2]);
                }
                else
                {
                    GameControl.inputMessage.GetComponent <InputMessage>().unit = null;
                }

                GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod(GameControl.inputMessage.GetComponent <InputMessage>());
                break;

            case GlobalDefinitions.MOUSEDOUBLECLICKIONKEYWORD:
                GlobalDefinitions.Nationality passedNationality;

                if (switchEntries[2] == "German")
                {
                    passedNationality = GlobalDefinitions.Nationality.German;
                }
                else
                {
                    passedNationality = GlobalDefinitions.Nationality.Allied;
                }


                if (GlobalDefinitions.selectedUnit != null)
                {
                    GlobalDefinitions.UnhighlightUnit(GlobalDefinitions.selectedUnit);
                }
                foreach (Transform hex in GameObject.Find("Board").transform)
                {
                    GlobalDefinitions.UnhighlightHex(hex.gameObject);
                }
                GlobalDefinitions.selectedUnit = null;


                GameControl.movementRoutinesInstance.GetComponent <MovementRoutines>().CallMultiUnitDisplay(GameObject.Find(switchEntries[1]), passedNationality);
                break;

            case GlobalDefinitions.DISPLAYCOMBATRESOLUTIONKEYWORD:
                CombatResolutionRoutines.CombatResolutionDisplay();
                break;

            case GlobalDefinitions.NEXTPHASEKEYWORD:
                GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.ExecuteQuit();
                break;

            case GlobalDefinitions.EXECUTETACTICALAIROKKEYWORD:
                TacticalAirToggleRoutines.TacticalAirOK();
                break;

            case GlobalDefinitions.ADDCLOSEDEFENSEKEYWORD:
                GameObject.Find("CloseDefense").GetComponent <TacticalAirToggleRoutines>().AddCloseDefenseHex();
                break;

            case GlobalDefinitions.CANCELCLOSEDEFENSEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <TacticalAirToggleRoutines>().CancelCloseDefense();
                break;

            case GlobalDefinitions.LOCATECLOSEDEFENSEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <TacticalAirToggleRoutines>().LocateCloseDefense();
                break;

            case GlobalDefinitions.ADDRIVERINTERDICTIONKEYWORD:
                GameObject.Find("RiverInterdiction").GetComponent <TacticalAirToggleRoutines>().AddRiverInterdiction();
                break;

            case GlobalDefinitions.CANCELRIVERINTERDICTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <TacticalAirToggleRoutines>().CancelRiverInterdiction();
                break;

            case GlobalDefinitions.LOCATERIVERINTERDICTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <TacticalAirToggleRoutines>().LocateRiverInterdiction();
                break;

            case GlobalDefinitions.ADDUNITINTERDICTIONKEYWORD:
                GameObject.Find("UnitInterdiction").GetComponent <TacticalAirToggleRoutines>().AddInterdictedUnit();
                break;

            case GlobalDefinitions.CANCELUNITINTERDICTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <TacticalAirToggleRoutines>().CancelInterdictedUnit();
                break;

            case GlobalDefinitions.LOCATEUNITINTERDICTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <TacticalAirToggleRoutines>().LocateInterdictedUnit();
                break;

            case GlobalDefinitions.TACAIRMULTIUNITSELECTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <TacticalAirToggleRoutines>().MultiUnitSelection();
                break;

            case GlobalDefinitions.MULTIUNITSELECTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.MULTIUNITSELECTIONCANCELKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <MultiUnitMovementToggleRoutines>().CancelGui();
                break;

            case GlobalDefinitions.LOADCOMBATKEYWORD:
                GameObject GUIButtonInstance = new GameObject("GUIButtonInstance");
                GUIButtonInstance.AddComponent <GUIButtonRoutines>();
                GUIButtonInstance.GetComponent <GUIButtonRoutines>().LoadCombat();
                break;

            case GlobalDefinitions.SETCOMBATTOGGLEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.RESETCOMBATTOGGLEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = false;
                break;

            case GlobalDefinitions.COMBATGUIOKKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <CombatGUIOK>().OkCombatGUISelection();
                break;

            case GlobalDefinitions.COMBATGUICANCELKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <CombatGUIOK>().CancelCombatGUISelection();
                break;

            case GlobalDefinitions.ADDCOMBATAIRSUPPORTKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.REMOVECOMBATAIRSUPPORTKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = false;
                break;

            case GlobalDefinitions.COMBATRESOLUTIONSELECTEDKEYWORD:
                // Load the combat results; the die roll is on the Global variable
                //GlobalDefinitions.writeToLogFile("Die Roll 1 = " + GlobalDefinitions.dieRollResult1);
                //GlobalDefinitions.writeToLogFile("Die Roll 2 = " + GlobalDefinitions.dieRollResult2);
                GameObject.Find(switchEntries[1]).GetComponent <CombatResolutionButtonRoutines>().ResolutionSelected();
                break;

            case GlobalDefinitions.COMBATLOCATIONSELECTEDKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <CombatResolutionButtonRoutines>().LocateAttack();
                break;

            case GlobalDefinitions.COMBATCANCELKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <CombatResolutionButtonRoutines>().CancelAttack();
                break;

            case GlobalDefinitions.COMBATOKKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <CombatResolutionButtonRoutines>().Ok();
                break;

            case GlobalDefinitions.CARPETBOMBINGRESULTSSELECTEDKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.RETREATSELECTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.SELECTPOSTCOMBATMOVEMENTKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.DESELECTPOSTCOMBATMOVEMENTKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = false;
                break;

            case GlobalDefinitions.ADDEXCHANGEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.REMOVEEXCHANGEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = false;
                break;

            case GlobalDefinitions.OKEXCHANGEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <ExchangeOKRoutines>().ExchangeOKSelected();
                break;

            case GlobalDefinitions.POSTCOMBATOKKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <PostCombatMovementOkRoutines>().ExecutePostCombatMovement();
                break;

            case GlobalDefinitions.DISPLAYALLIEDSUPPLYKEYWORD:
                if (switchEntries[1] == "True")
                {
                    GameControl.supplyRoutinesInstance.GetComponent <SupplyRoutines>().CreateSupplySourceGUI(true);
                }
                else
                {
                    GameControl.supplyRoutinesInstance.GetComponent <SupplyRoutines>().CreateSupplySourceGUI(false);
                }
                break;

            case GlobalDefinitions.SETSUPPLYKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.RESETSUPPLYKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = false;
                break;

            case GlobalDefinitions.LOCATESUPPLYKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <SupplyButtonRoutines>().LocateSupplySource();
                break;

            case GlobalDefinitions.OKSUPPLYKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <SupplyButtonRoutines>().OkSupply();
                break;

            case GlobalDefinitions.OKSUPPLYWITHENDPHASEKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <SupplyButtonRoutines>().OkSupplyWithEndPhase();
                break;

            case GlobalDefinitions.CHANGESUPPLYSTATUSKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.YESBUTTONSELECTEDKEYWORD:
                GameObject.Find("YesButton").GetComponent <YesNoButtonRoutines>().YesButtonSelected();
                break;

            case GlobalDefinitions.NOBUTTONSELECTEDKEYWORD:
                GameObject.Find("NoButton").GetComponent <YesNoButtonRoutines>().NoButtonSelected();
                break;

            case GlobalDefinitions.SAVEFILENAMEKEYWORD:
                if (File.Exists(GameControl.path + "TGCOutputFiles\\TGCRemoteSaveFile.txt"))
                {
                    File.Delete(GameControl.path + "TGCOutputFiles\\TGCRemoteSaveFile.txt");
                }
                break;

            case GlobalDefinitions.SENDSAVEFILELINEKEYWORD:
                using (StreamWriter saveFile = File.AppendText(GameControl.path + "TGCOutputFiles\\TGCRemoteSaveFile.txt"))
                {
                    for (int index = 1; index < (switchEntries.Length); index++)
                    {
                        saveFile.Write(switchEntries[index] + " ");
                    }
                    saveFile.WriteLine();
                }
                break;

            case GlobalDefinitions.PLAYNEWGAMEKEYWORD:
                GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState = GameControl.setUpStateInstance.GetComponent <SetUpState>();
                GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.Initialize();

                // Set the global parameter on what file to use, can't pass it to the executeNoResponse since it is passed as a method delegate elsewhere
                GlobalDefinitions.germanSetupFileUsed = Convert.ToInt32(switchEntries[1]);

                GameControl.setUpStateInstance.GetComponent <SetUpState>().ExecuteNewGame();
                break;

            case GlobalDefinitions.INVASIONAREASELECTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.CARPETBOMBINGSELECTIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <Toggle>().isOn = true;
                break;

            case GlobalDefinitions.CARPETBOMBINGLOCATIONKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <CarpetBombingToggleRoutines>().LocateCarpetBombingHex();
                break;

            case GlobalDefinitions.CARPETBOMBINGOKKEYWORD:
                GameObject.Find(switchEntries[1]).GetComponent <CarpetBombingOKRoutines>().CarpetBombingOK();
                break;

            case GlobalDefinitions.DIEROLLRESULT1KEYWORD:
                GlobalDefinitions.dieRollResult1 = Convert.ToInt32(switchEntries[1]);
                break;

            case GlobalDefinitions.DIEROLLRESULT2KEYWORD:
                GlobalDefinitions.dieRollResult2 = Convert.ToInt32(switchEntries[1]);
                break;

            case GlobalDefinitions.UNDOKEYWORD:
                GameControl.GUIButtonRoutinesInstance.GetComponent <GUIButtonRoutines>().ExecuteUndo();
                break;

            case GlobalDefinitions.CHATMESSAGEKEYWORD:
                string chatMessage = "";
                for (int index = 0; index < (switchEntries.Length - 1); index++)
                {
                    chatMessage += switchEntries[index + 1] + " ";
                }
                GlobalDefinitions.WriteToLogFile("Chat message received: " + chatMessage);
                GlobalDefinitions.AddChatMessage(chatMessage);
                break;
            //case GlobalDefinitions.SENDTURNFILENAMEWORD:
            //    // This command tells the remote computer what the name of the file is that will provide the saved turn file

            //    // The file name could have ' ' in it so need to reconstruct the full name
            //    string receivedFileName;
            //    receivedFileName = switchEntries[1];
            //    for (int i = 2; i < switchEntries.Length; i++)
            //        receivedFileName = receivedFileName + " " + switchEntries[i];

            //    GameControl.fileTransferServerInstance.GetComponent<FileTransferServer>().InitiateFileTransferServer();
            //    GlobalDefinitions.WriteToLogFile("Received name of save file, calling FileTransferServer: fileName = " + receivedFileName + "  path to save = " + GameControl.path);
            //    GameControl.fileTransferServerInstance.GetComponent<FileTransferServer>().RequestFile(TransportScript.remoteComputerIPAddress, receivedFileName, GameControl.path, true);
            //    break;

            case GlobalDefinitions.DISPLAYALLIEDSUPPLYRANGETOGGLEWORD:
                if (GameObject.Find("AlliedSupplyToggle").GetComponent <Toggle>().isOn)
                {
                    GameObject.Find("AlliedSupplyToggle").GetComponent <Toggle>().isOn = false;
                }
                else
                {
                    GameObject.Find("AlliedSupplyToggle").GetComponent <Toggle>().isOn = true;
                }
                break;

            case GlobalDefinitions.DISPLAYGERMANSUPPLYRANGETOGGLEWORD:
                if (GameObject.Find("GermanSupplyToggle").GetComponent <Toggle>().isOn)
                {
                    GameObject.Find("GermanSupplyToggle").GetComponent <Toggle>().isOn = false;
                }
                else
                {
                    GameObject.Find("GermanSupplyToggle").GetComponent <Toggle>().isOn = true;
                }
                break;

            case GlobalDefinitions.DISPLAYMUSTATTACKTOGGLEWORD:
                if (GlobalDefinitions.MustAttackToggle.GetComponent <Toggle>().isOn)
                {
                    GlobalDefinitions.MustAttackToggle.GetComponent <Toggle>().isOn = false;
                }
                else
                {
                    GlobalDefinitions.MustAttackToggle.GetComponent <Toggle>().isOn = true;
                }
                break;

            case GlobalDefinitions.TOGGLEAIRSUPPORTCOMBATTOGGLE:
            {
                if (GlobalDefinitions.combatAirSupportToggle != null)
                {
                    if (GlobalDefinitions.combatAirSupportToggle.GetComponent <Toggle>().isOn)
                    {
                        GlobalDefinitions.combatAirSupportToggle.GetComponent <Toggle>().isOn = false;
                    }
                    else
                    {
                        GlobalDefinitions.combatAirSupportToggle.GetComponent <Toggle>().isOn = true;
                    }
                }
                break;
            }

            case GlobalDefinitions.TOGGLECARPETBOMBINGCOMBATTOGGLE:
            {
                if (GlobalDefinitions.combatCarpetBombingToggle != null)
                {
                    if (GlobalDefinitions.combatCarpetBombingToggle.GetComponent <Toggle>().isOn)
                    {
                        GlobalDefinitions.combatCarpetBombingToggle.GetComponent <Toggle>().isOn = false;
                    }
                    else
                    {
                        GlobalDefinitions.combatCarpetBombingToggle.GetComponent <Toggle>().isOn = true;
                    }
                }
                break;
            }

            case GlobalDefinitions.DISCONNECTFROMREMOTECOMPUTER:
            {
                // Quit the game and go back to the main menu
                GameObject guiButtonInstance = new GameObject("GUIButtonInstance");
                guiButtonInstance.AddComponent <GUIButtonRoutines>();
                guiButtonInstance.GetComponent <GUIButtonRoutines>().YesMain();
                break;
            }

            case GlobalDefinitions.ALLIEDREPLACEMENTKEYWORD:
                GameControl.movementRoutinesInstance.GetComponent <MovementRoutines>().SelectAlliedReplacementUnit(GameObject.Find(switchEntries[1]));
                break;

            case GlobalDefinitions.GERMANREPLACEMENTKEYWORD:
                GameControl.movementRoutinesInstance.GetComponent <MovementRoutines>().SelectGermanReplacementUnit(GameObject.Find(switchEntries[1]));
                break;

            case GlobalDefinitions.AGGRESSIVESETTINGKEYWORD:
                GlobalDefinitions.aggressiveSetting = Convert.ToInt32(switchEntries[1]);
                break;

            case GlobalDefinitions.DIFFICULTYSETTINGKEYWORD:
                GlobalDefinitions.difficultySetting = Convert.ToInt32(switchEntries[1]);
                break;

            default:
                GlobalDefinitions.WriteToLogFile("processCommand: Unknown network command received: " + message);
                break;
            }
        }
        /// <summary>
        /// This routine is what pulls up the GUI to assign units to a single combat
        /// </summary>
        /// <param name="singleCombat"></param>
        public void CallCombatDisplay(GameObject singleCombat)
        {
            Button okButton;
            Button cancelButton;
            Canvas combatCanvas = new Canvas();

            // I'm going to unhighight all the units potentially involved in this attack.  When selected for inclusion in the attack they
            // will be highlighted.  I will restore the must-attack and must-be-attacked highlighting when leaving the gui

            foreach (GameObject unit in singleCombat.GetComponent <Combat>().defendingUnits)
            {
                GlobalDefinitions.UnhighlightUnit(unit);
            }
            foreach (GameObject unit in singleCombat.GetComponent <Combat>().attackingUnits)
            {
                GlobalDefinitions.UnhighlightUnit(unit);
            }

            // The panel needs to be at least the width for four units to fit everything
            int maxUnits = 5;

            if (singleCombat.GetComponent <Combat>().defendingUnits.Count > maxUnits)
            {
                maxUnits = singleCombat.GetComponent <Combat>().defendingUnits.Count;
            }
            if (singleCombat.GetComponent <Combat>().attackingUnits.Count > maxUnits)
            {
                maxUnits = singleCombat.GetComponent <Combat>().attackingUnits.Count;
            }
            float panelWidth  = (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE;
            float panelHeight = 7 * GlobalDefinitions.GUIUNITIMAGESIZE;

            GlobalDefinitions.combatGUIInstance = GUIRoutines.CreateGUICanvas("CombatGUIInstance",
                                                                              panelWidth,
                                                                              panelHeight,
                                                                              ref combatCanvas);

            GUIRoutines.CreateUIText("Combat Odds", "OddsText",
                                     3 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                     GlobalDefinitions.GUIUNITIMAGESIZE,
                                     (0.5f * (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE) - 0.5f * panelWidth,
                                     6.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                     Color.white, combatCanvas);

            float xSeperation = (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE / maxUnits;
            float xOffset     = xSeperation / 2;

            for (int index = 0; index < singleCombat.GetComponent <Combat>().defendingUnits.Count; index++)
            {
                Toggle tempToggle;
                tempToggle = GUIRoutines.CreateUnitTogglePair("unitToggleDefendingPair" + index,
                                                              index * xSeperation + xOffset - 0.5f * panelWidth,
                                                              5.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                              combatCanvas,
                                                              singleCombat.GetComponent <Combat>().defendingUnits[index]);
                tempToggle.gameObject.AddComponent <CombatToggleRoutines>();
                tempToggle.gameObject.GetComponent <CombatToggleRoutines>().currentCombat     = singleCombat;
                tempToggle.gameObject.GetComponent <CombatToggleRoutines>().unit              = singleCombat.GetComponent <Combat>().defendingUnits[index];
                tempToggle.gameObject.GetComponent <CombatToggleRoutines>().attackingUnitFlag = false;
                tempToggle.onValueChanged.AddListener((bool value) => tempToggle.GetComponent <CombatToggleRoutines>().AddOrDeleteSelectedUnit());

                if (CheckForInvasionDefense(singleCombat.GetComponent <Combat>().defendingUnits[index], singleCombat))
                {
                    // This executes if the defender is on an invasion hex of at least one of the attackers.  If it is the toggle will be set and there are checks in the toggle routines from allowing
                    // it to be turned off.  If the defenders are being invaded they can't be attacked separately.
                    tempToggle.isOn         = true;
                    tempToggle.interactable = false;
                }
            }

            for (int index = 0; index < singleCombat.GetComponent <Combat>().attackingUnits.Count; index++)
            {
                Toggle tempToggle;
                tempToggle = GUIRoutines.CreateUnitTogglePair("unitToggleAttackingPair" + index,
                                                              index * xSeperation + xOffset - 0.5f * panelWidth,
                                                              3.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                              combatCanvas,
                                                              singleCombat.GetComponent <Combat>().attackingUnits[index]);
                tempToggle.gameObject.AddComponent <CombatToggleRoutines>();
                tempToggle.gameObject.GetComponent <CombatToggleRoutines>().currentCombat     = singleCombat;
                tempToggle.gameObject.GetComponent <CombatToggleRoutines>().unit              = singleCombat.GetComponent <Combat>().attackingUnits[index];
                tempToggle.gameObject.GetComponent <CombatToggleRoutines>().attackingUnitFlag = true;
                tempToggle.onValueChanged.AddListener((bool value) => tempToggle.GetComponent <CombatToggleRoutines>().AddOrDeleteSelectedUnit());

                if (CheckForInvadingAttacker(singleCombat.GetComponent <Combat>().attackingUnits[index]))
                {
                    // This executes if the attacker is invading this turn. The unit will be selected and the toggle routines will not allow it to be turned off
                    tempToggle.isOn         = true;
                    tempToggle.interactable = false;
                }
            }

            GlobalDefinitions.combatAirSupportToggle    = null;
            GlobalDefinitions.combatCarpetBombingToggle = null;
            // If there are air missions left present the user with the option of adding air support to the attack
            if (GameControl.gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality == GlobalDefinitions.Nationality.Allied)
            {
                Toggle airToggle;
                airToggle = GUIRoutines.CreateToggle("CombatAirSupportToggle",
                                                     0.5f * (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth - 2 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                     1.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                     combatCanvas).GetComponent <Toggle>();
                GlobalDefinitions.combatAirSupportToggle = airToggle.gameObject;
                airToggle.gameObject.AddComponent <CombatToggleRoutines>();
                airToggle.gameObject.GetComponent <CombatToggleRoutines>().currentCombat = singleCombat;
                airToggle.onValueChanged.AddListener((bool value) => airToggle.GetComponent <CombatToggleRoutines>().ToggleAirSupport());
                if (GlobalDefinitions.tacticalAirMissionsThisTurn <= GlobalDefinitions.maxNumberOfTacticalAirMissions)
                {
                    airToggle.GetComponent <Toggle>().interactable = true;
                }
                else
                {
                    airToggle.GetComponent <Toggle>().interactable = false;
                }

                GUIRoutines.CreateUIText("Air Support", "CombatAirSupportText",
                                         1 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                         1 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                         0.5f * (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth - 1 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                         1.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                         Color.white, combatCanvas);

                Toggle carpetToggle;
                carpetToggle = GUIRoutines.CreateToggle("CombatCarpetBombingToggle",
                                                        0.5f * (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth + 1 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                        1.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                        combatCanvas).GetComponent <Toggle>();
                GlobalDefinitions.combatCarpetBombingToggle = carpetToggle.gameObject;
                carpetToggle.gameObject.AddComponent <CombatToggleRoutines>();
                carpetToggle.gameObject.GetComponent <CombatToggleRoutines>().currentCombat = singleCombat;
                carpetToggle.onValueChanged.AddListener((bool value) => carpetToggle.GetComponent <CombatToggleRoutines>().ToggleCarpetBombing());
                if (CheckIfCarpetBombingIsAvailable(singleCombat))
                {
                    carpetToggle.GetComponent <Toggle>().interactable = true;
                }
                else
                {
                    carpetToggle.GetComponent <Toggle>().interactable = false;
                }

                GUIRoutines.CreateUIText("Carpet Bombing", "CarpetBombingSupportText",
                                         1.5f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                         1 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                         0.5f * (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth + 2 * GlobalDefinitions.GUIUNITIMAGESIZE,
                                         1.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                         Color.white, combatCanvas);
            }

            // OK button
            okButton = GUIRoutines.CreateButton("combatOKButton", "OK",
                                                0.5f * (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth - 0.5f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                0.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                combatCanvas);
            okButton.gameObject.AddComponent <CombatGUIOK>();
            okButton.gameObject.GetComponent <CombatGUIOK>().singleCombat = singleCombat;
            okButton.onClick.AddListener(okButton.GetComponent <CombatGUIOK>().OkCombatGUISelection);

            // Cancel button
            cancelButton = GUIRoutines.CreateButton("combatCancelButton", "Cancel",
                                                    0.5f * (maxUnits + 1) * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelWidth + 0.5f * GlobalDefinitions.GUIUNITIMAGESIZE,
                                                    0.5f * GlobalDefinitions.GUIUNITIMAGESIZE - 0.5f * panelHeight,
                                                    combatCanvas);
            cancelButton.gameObject.AddComponent <CombatGUIOK>();
            cancelButton.gameObject.GetComponent <CombatGUIOK>().singleCombat = singleCombat;
            cancelButton.onClick.AddListener(cancelButton.GetComponent <CombatGUIOK>().CancelCombatGUISelection);
        }
Exemple #16
0
        private float initialTouch; // Used to check if the mouse click is a double click
        void Update()
        {
            if (GlobalDefinitions.gameStarted)
            {
                if (GlobalDefinitions.localControl || (GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.Hotseat))
                {
                    if (!GlobalDefinitions.commandFileBeingRead)
                    {
                        // Left mouse button click
                        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
                        {
                            // Check if the user double clicked
                            if ((Time.time < initialTouch + 0.5f) &&
                                ((gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "alliedMovementStateInstance") ||
                                 (gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "germanMovementStateInstance") ||
                                 (gameStateControlInstance.GetComponent <GameStateControl>().currentState.name == "setUpStateInstance")))
                            {
                                // When we have a double click that means that there was already a single click that would have selected a unit
                                // Unhighlight it and then remove it
                                if (GlobalDefinitions.selectedUnit != null)
                                {
                                    GlobalDefinitions.UnhighlightUnit(GlobalDefinitions.selectedUnit);
                                }
                                foreach (Transform hex in GameObject.Find("Board").transform)
                                {
                                    GlobalDefinitions.UnhighlightHex(hex.gameObject);
                                }
                                GlobalDefinitions.selectedUnit = null;

                                GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.SETCAMERAPOSITIONKEYWORD + " " + Camera.main.transform.position.x + " " + Camera.main.transform.position.y + " " + Camera.main.transform.position.z + " " + Camera.main.GetComponent <Camera>().orthographicSize);

                                // I had a bug where double clicking on an off-board unit causes an exception in the following line because it is assuming a hex is being clicked
                                if (GeneralHexRoutines.GetHexFromUserInput(Input.mousePosition) != null)
                                {
                                    GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.MOUSEDOUBLECLICKIONKEYWORD + " " + GeneralHexRoutines.GetHexFromUserInput(Input.mousePosition).name + " " + gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality);
                                }

                                movementRoutinesInstance.GetComponent <MovementRoutines>().CallMultiUnitDisplay(GeneralHexRoutines.GetHexFromUserInput(Input.mousePosition),
                                                                                                                gameStateControlInstance.GetComponent <GameStateControl>().currentState.currentNationality);
                            }
                            // If not double click then process a normal click
                            else
                            {
                                inputMessage.GetComponent <InputMessage>().hex  = GeneralHexRoutines.GetHexFromUserInput(Input.mousePosition);
                                inputMessage.GetComponent <InputMessage>().unit = GeneralHexRoutines.GetUnitWithoutHex(Input.mousePosition);

                                RecordMouseClick(inputMessage.GetComponent <InputMessage>().unit, inputMessage.GetComponent <InputMessage>().hex);

                                gameStateControlInstance.GetComponent <GameStateControl>().currentState.executeMethod(inputMessage.GetComponent <InputMessage>());
                            }

                            initialTouch = Time.time;
                        }
                    }

                    // Note that the EventSystem check is to ensure the mouse isn't clicking a ui button
                    //else if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
                    //{
                    //    // This is a left mouse button click to select a unit or hex
                    //    inputMessage.GetComponent<InputMessage>().hex = GlobalDefinitions.getHexFromUserInput(Input.mousePosition);
                    //    inputMessage.GetComponent<InputMessage>().unit = GlobalDefinitions.getUnitWithoutHex(Input.mousePosition);

                    //    gameStateControlInstance.GetComponent<gameStateControl>().currentState.executeMethod(inputMessage.GetComponent<InputMessage>());
                    //    if ((GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.Network) && (GlobalDefinitions.localControl))
                    //        sendMouseClickToNetwork(inputMessage.GetComponent<InputMessage>().unit, inputMessage.GetComponent<InputMessage>().hex);
                    //}

                    // Even though this is for when the player is in control, still need to check for chat messages
                    //if (GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.Peer2PeerNetwork)
                    //{
                    //    string message;

                    //    NetworkEventType receivedNetworkEvent = TransportScript.checkForNetworkEvent(out message);

                    //    if (receivedNetworkEvent == NetworkEventType.DataEvent)
                    //    {
                    //        // The only message that is valid when in control is a chat message

                    //        char[] delimiterChars = { ' ' };
                    //        string[] switchEntries = message.Split(delimiterChars);

                    //        switch (switchEntries[0])
                    //        {
                    //            case GlobalDefinitions.CHATMESSAGEKEYWORD:
                    //                string chatMessage = "";
                    //                for (int index = 0; index < (switchEntries.Length - 1); index++)
                    //                    chatMessage += switchEntries[index + 1] + " ";
                    //                GlobalDefinitions.WriteToLogFile("Chat message received: " + chatMessage);
                    //                GlobalDefinitions.AddChatMessage(chatMessage);
                    //                break;
                    //            default:
                    //                GlobalDefinitions.WriteToLogFile("ERROR: unexpected data message received when in control (only chat message valid - message = " + message);
                    //                break;
                    //        }
                    //    }
                    //}

                    // Since I have enabled chat I have to do something to get hotkeys since chat will execute the hotkeys
                    //else if (Input.GetKeyDown(KeyCode.R))
                    //{
                    //    GUIButtonRoutinesInstance.GetComponent<GUIButtonRoutines>().executeCombatResolution();
                    //}

                    //else if (Input.GetKeyDown(KeyCode.Q))
                    //{
                    //    GUIButtonRoutinesInstance.GetComponent<GUIButtonRoutines>().goToNextPhase();
                    //}

                    //else if (Input.GetKeyDown(KeyCode.U))
                    //{
                    //    GUIButtonRoutinesInstance.GetComponent<GUIButtonRoutines>().executeUndo();
                    //}
                }

                //else if (!GlobalDefinitions.localControl && (GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.Peer2PeerNetwork))
                //{
                //    string message;
                //    NetworkEventType receivedNetworkEvent = TransportScript.checkForNetworkEvent(out message);

                //    if (receivedNetworkEvent == NetworkEventType.DataEvent)
                //        ExecuteGameCommand.ProcessCommand(message);
                //}

                else if (GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.AI)
                {
                    // The user side is controled by the hotseat section above.  The AI doesn't need anything during update since its states don't have input or transitions.
                }

                else if (GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.ClientServerNetwork)
                {
                }
            }
        }
        /// <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;
            }
        }
        public void ExchangeOKSelected()
        {
            List <GameObject> unitsToDelete = new List <GameObject>();

            // Determine if the user has selected enough factors
            if (GlobalDefinitions.exchangeFactorsSelected >= GlobalDefinitions.exchangeFactorsToLose)
            {
                GlobalDefinitions.WriteToCommandFile(GlobalDefinitions.OKEXCHANGEKEYWORD + " " + name);

                GlobalDefinitions.WriteToLogFile("exchangeOKSelected: attackerHadMostFactors = " + attackerHadMostFactors + " Units selected for exchange:");
                foreach (GameObject unit in GlobalDefinitions.unitsToExchange)
                {
                    GlobalDefinitions.WriteToLogFile("    unit " + unit.name);
                    unitsToDelete.Add(unit);
                }

                if (attackerHadMostFactors)
                {
                    foreach (GameObject unit in defendingUnits)
                    {
                        GlobalDefinitions.UnhighlightUnit(unit);
                        GlobalDefinitions.MoveUnitToDeadPile(unit);
                    }
                    defendingUnits.Clear();

                    foreach (GameObject unit in unitsToDelete)
                    {
                        attackingUnits.Remove(unit); // This is needed to see if there are any attackers left at the end for post-combat movement
                        GlobalDefinitions.UnhighlightUnit(unit);
                        GlobalDefinitions.MoveUnitToDeadPile(unit);
                    }
                }
                else
                {
                    foreach (GameObject unit in attackingUnits)
                    {
                        GlobalDefinitions.UnhighlightUnit(unit);
                        GlobalDefinitions.MoveUnitToDeadPile(unit);
                    }
                    attackingUnits.Clear();

                    foreach (GameObject unit in unitsToDelete)
                    {
                        GlobalDefinitions.UnhighlightUnit(unit);
                        GlobalDefinitions.MoveUnitToDeadPile(unit);
                    }
                }

                GUIRoutines.RemoveGUI(GlobalDefinitions.ExchangeGUIInstance);

                if (attackerHadMostFactors && (GlobalDefinitions.hexesAvailableForPostCombatMovement.Count > 0) && (attackingUnits.Count > 0))
                {
                    CombatResolutionRoutines.SelectUnitsForPostCombatMovement(attackingUnits);
                }
                else
                {
                    // The CombatResolution table will be activated after the post movement combat units are selected which is why this check is needed.
                    GlobalDefinitions.combatResolutionGUIInstance.SetActive(true);
                }

                GlobalDefinitions.unitsToExchange.Clear();
            }
            else
            {
                GlobalDefinitions.WriteToLogFile("exchangeOKSelected: ERROR - Not enough factors selected");
            }
        }
Exemple #19
0
        /// <summary>
        /// This routine reads a single record for a unit
        /// </summary>
        /// <param name="entries"></param>
        public void ProcessUnitRecord(string[] entries)
        {
            GameObject unit;

            unit = GameObject.Find(entries[0]);
            if (entries[1] == "null")
            {
                unit.GetComponent <UnitDatabaseFields>().occupiedHex = null;
            }
            else
            {
                unit.GetComponent <UnitDatabaseFields>().occupiedHex = GameObject.Find(entries[1]);
            }
            if (entries[2] == "null")
            {
                unit.GetComponent <UnitDatabaseFields>().beginningTurnHex = null;
            }
            else
            {
                unit.GetComponent <UnitDatabaseFields>().beginningTurnHex = GameObject.Find(entries[2]);
            }
            unit.GetComponent <UnitDatabaseFields>().inBritain                     = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[3]);
            unit.GetComponent <UnitDatabaseFields>().unitInterdiction              = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[4]);
            unit.GetComponent <UnitDatabaseFields>().invasionAreaIndex             = Convert.ToInt32(entries[5]);
            unit.GetComponent <UnitDatabaseFields>().availableForStrategicMovement = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[6]);
            unit.GetComponent <UnitDatabaseFields>().inSupply = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[7]);
            // Need to adjust the highlighting of the unit if it is out of supply
            GlobalDefinitions.UnhighlightUnit(unit);
            if (entries[8] == "null")
            {
                unit.GetComponent <UnitDatabaseFields>().supplySource = null;
            }
            else
            {
                unit.GetComponent <UnitDatabaseFields>().supplySource = GameObject.Find(entries[8]);
            }
            unit.GetComponent <UnitDatabaseFields>().supplyIncrementsOutOfSupply = Convert.ToInt32(entries[9]);
            unit.GetComponent <UnitDatabaseFields>().unitEliminated = GlobalDefinitions.ReturnBoolFromSaveFormat(entries[10]);


            if (unit.GetComponent <UnitDatabaseFields>().occupiedHex != null)
            {
                GeneralHexRoutines.PutUnitOnHex(unit, unit.GetComponent <UnitDatabaseFields>().occupiedHex);
                unit.transform.parent = GlobalDefinitions.allUnitsOnBoard.transform;
            }
            else if (unit.GetComponent <UnitDatabaseFields>().unitEliminated)
            {
                unit.transform.parent   = GameObject.Find("Units Eliminated").transform;
                unit.transform.position = unit.GetComponent <UnitDatabaseFields>().OOBLocation;
            }
            else if (unit.GetComponent <UnitDatabaseFields>().inBritain)
            {
                unit.transform.parent   = GameObject.Find("Units In Britain").transform;
                unit.transform.position = unit.GetComponent <UnitDatabaseFields>().locationInBritain;
            }
            else
            {
                GlobalDefinitions.WriteToLogFile("processUnitRecord: Unit read error - " + entries[1] + ": found no location to place this unit");
            }

            if (!unit.GetComponent <UnitDatabaseFields>().unitEliminated&& !unit.GetComponent <UnitDatabaseFields>().inBritain)
            {
                if (unit.GetComponent <UnitDatabaseFields>().nationality == GlobalDefinitions.Nationality.Allied)
                {
                    GlobalDefinitions.alliedUnitsOnBoard.Add(unit);
                }
                else
                {
                    GlobalDefinitions.germanUnitsOnBoard.Add(unit);
                }
            }
        }
Exemple #20
0
        /// <summary>
        /// Executes when the user indicates he wants to go to main menu
        /// </summary>
        public void YesMain()
        {
            List <GameObject> removeUnitList = new List <GameObject>();

            // If this is a network game I've already checked that the player is in control
            //if (GlobalDefinitions.gameMode == GlobalDefinitions.GameModeValues.Peer2PeerNetwork)
            //{
            //    GlobalDefinitions.WriteToLogFile("YesMain: Calling ResetConnection()");
            //    //byte error;
            //    //NetworkTransport.Disconnect(TransportScript.receivedHostId, TransportScript.gameConnectionId, out error);
            //    //Network.Disconnect();
            //    TransportScript.ResetConnection(TransportScript.computerId);
            //}

            // Copy list so the guis can be removed
            List <GameObject> removeList = new List <GameObject>();

            foreach (GameObject gui in GUIRoutines.guiList)
            {
                removeList.Add(gui);
            }


            // Get rid of all active guis
            foreach (GameObject gui in removeList)
            {
                GUIRoutines.RemoveGUI(gui);
            }

            // Put all the units back on the OOB sheet
            foreach (Transform unit in GlobalDefinitions.allUnitsOnBoard.transform)
            {
                unit.GetComponent <UnitDatabaseFields>().unitInterdiction      = false;
                unit.GetComponent <UnitDatabaseFields>().isCommittedToAnAttack = false;
                unit.GetComponent <UnitDatabaseFields>().hasMoved                    = false;
                unit.GetComponent <UnitDatabaseFields>().unitEliminated              = false;
                unit.GetComponent <UnitDatabaseFields>().occupiedHex                 = null;
                unit.GetComponent <UnitDatabaseFields>().beginningTurnHex            = null;
                unit.GetComponent <UnitDatabaseFields>().invasionAreaIndex           = -1;
                unit.GetComponent <UnitDatabaseFields>().inSupply                    = true;
                unit.GetComponent <UnitDatabaseFields>().supplySource                = null;
                unit.GetComponent <UnitDatabaseFields>().supplyIncrementsOutOfSupply = 0;
                unit.GetComponent <UnitDatabaseFields>().remainingMovement           = unit.GetComponent <UnitDatabaseFields>().movementFactor;
                if (unit.GetComponent <UnitDatabaseFields>().occupiedHex != null)
                {
                    GlobalDefinitions.UnhighlightUnit(unit.gameObject);
                    GeneralHexRoutines.RemoveUnitFromHex(unit.gameObject, unit.GetComponent <UnitDatabaseFields>().occupiedHex);
                    unit.GetComponent <UnitDatabaseFields>().occupiedHex = null;
                }

                removeUnitList.Add(unit.gameObject);
            }

            foreach (GameObject unit in removeUnitList)
            {
                GlobalDefinitions.ReturnUnitToOOBShet(unit);
            }

            // Clear out the lists keeping track of both side's units on board
            GlobalDefinitions.alliedUnitsOnBoard.Clear();
            GlobalDefinitions.germanUnitsOnBoard.Clear();

            // Go through the hexes and reset all highlighting
            foreach (GameObject hex in HexDefinitions.allHexesOnBoard)
            {
                hex.GetComponent <HexDatabaseFields>().riverInterdiction   = false;
                hex.GetComponent <HexDatabaseFields>().closeDefenseSupport = false;
                hex.GetComponent <HexDatabaseFields>().successfullyInvaded = false;
                hex.GetComponent <HexDatabaseFields>().alliedControl       = false;
                hex.GetComponent <HexDatabaseFields>().inAlliedZOC         = false;
                hex.GetComponent <HexDatabaseFields>().inGermanZOC         = false;
                hex.GetComponent <HexDatabaseFields>().occupyingUnit.Clear();
                hex.GetComponent <HexDatabaseFields>().unitsExertingZOC.Clear();
                hex.GetComponent <HexDatabaseFields>().availableForMovement       = false;
                hex.GetComponent <HexDatabaseFields>().strategicRemainingMovement = 0;
                hex.GetComponent <HexDatabaseFields>().remainingMovement          = 0;
                hex.GetComponent <HexDatabaseFields>().supplySources.Clear();
                hex.GetComponent <HexDatabaseFields>().unitsThatCanBeSupplied.Clear();
                hex.GetComponent <HexDatabaseFields>().closeDefenseSupport = false;
                hex.GetComponent <HexDatabaseFields>().riverInterdiction   = false;
                hex.GetComponent <HexDatabaseFields>().carpetBombingActive = false;

                GlobalDefinitions.UnhighlightHex(hex.gameObject);
            }

            GlobalDefinitions.WriteToLogFile("Putting Allied units in Britain");
            // When restarting a game the units won't have their Britain location loaded so this needs to be done before a restart file is read
            GameControl.createBoardInstance.GetComponent <CreateBoard>().ReadBritainPlacement(GlobalGameFields.britainUnitLocationFile);

            GlobalDefinitions.ResetAllGlobalDefinitions();

            // Turn the button back on
            GlobalDefinitions.mainMenuButton.GetComponent <Button>().interactable = true;

            MainMenuRoutines.GetGameModeUI();
        }
Exemple #21
0
        /// <summary>
        /// This routine goes through a series of checks to see if the units are setup properly.
        /// </summary>
        /// <returns></returns>
        public static bool UpdateHexFields()
        {
            bool returnState = true;

            // Do an initial load of the GermanUnitsOnBoardList
            GlobalDefinitions.germanUnitsOnBoard.Clear(); // Clear it out first in case multiple passes are made.
            foreach (Transform unit in GameObject.Find("Units On Board").transform)
            {
                if (unit.GetComponent <UnitDatabaseFields>().nationality == GlobalDefinitions.Nationality.German)
                {
                    GlobalDefinitions.germanUnitsOnBoard.Add(unit.gameObject);
                }
            }

            GlobalDefinitions.WriteToLogFile("updateHexFields: executing ... number of German units on board = " + GlobalDefinitions.germanUnitsOnBoard.Count);

            foreach (GameObject unit in GlobalDefinitions.germanUnitsOnBoard)
            {
                // Unhighlight the unit so that if all units pass they will be unhighlighted
                GlobalDefinitions.UnhighlightUnit(unit);

                // Not sure if this is needed.  Can't really be in "Units On Board" without a hex assignment
                if (unit.GetComponent <UnitDatabaseFields>().occupiedHex == null)
                {
                    GlobalDefinitions.GuiUpdateStatusMessage("Internal Error - Unit " + unit.GetComponent <UnitDatabaseFields>().name + " is not assigned a hex locunit.GetComponent<UnitDatabaseFields>().ation");
                    GlobalDefinitions.HighlightUnit(unit);
                    returnState = false;
                }

                // German static units must be on a coast or inland port hex
                else if (unit.GetComponent <UnitDatabaseFields>().germanStatic&&
                         !unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().coast&&
                         !unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().inlandPort&&
                         !unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().coastalPort)
                {
                    GlobalDefinitions.GuiUpdateStatusMessage(unit.GetComponent <UnitDatabaseFields>().unitDesignation + " is a static unit and must start on a coast hex, a port, or an inland port");
                    GlobalDefinitions.HighlightUnit(unit);
                    returnState = false;
                }

                else if (((unit.name == "Armor-German-3SS") ||
                          (unit.name == "Armor-German-9SS") ||
                          (unit.name == "Armor-German-25SS") ||
                          (unit.name == "Armor-German-49SS") ||
                          (unit.name == "Armor-German-51SS") ||
                          (unit.name == "Armor-German-106") ||
                          (unit.name == "Armor-German-15SS")) &&
                         (!unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().germanRepalcement))
                {
                    GlobalDefinitions.GuiUpdateStatusMessage(unit.GetComponent <UnitDatabaseFields>().unitDesignation + " must start on a replacement hex (hexes in Germany with a star on them");
                    GlobalDefinitions.HighlightUnit(unit);
                    returnState = false;
                }

                // Setup the ZOC for the hex and its neighbors.  Note that I did not bother to do this while the user was moving
                // units around since I think it makes sense to just do it once when he is done.
                unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().inGermanZOC = true;
                foreach (HexDefinitions.HexSides hexSides in Enum.GetValues(typeof(HexDefinitions.HexSides)))
                {
                    if ((unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().Neighbors[(int)hexSides] != null) &&
                        (unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <BooleanArrayData>().exertsZOC[(int)hexSides]))
                    {
                        unit.GetComponent <UnitDatabaseFields>().occupiedHex.GetComponent <HexDatabaseFields>().Neighbors[(int)hexSides].GetComponent <HexDatabaseFields>().inGermanZOC = true;
                    }
                }
            }
            if (!returnState)
            {
                GlobalDefinitions.GuiUpdateStatusMessage("Cannot exit setup until all issues are resolved");
            }
            return(returnState);
        }