private void FinishAdaptiveAileronsAbility()
        {
            doAilerons = false;
            HostShip.CanPerformActionsWhenBumped      = false;
            HostShip.CanPerformActionsWhenOverlapping = false;
            RestoreManuverColors(HostShip);
            Phases.CurrentSubPhase.IsReadyForCommands = true;
            //ship may have flown off the board; only assign saved maneuver if ship is exists
            if (Roster.GetShipById("ShipId:" + Selection.ThisShip.ShipId) != null)
            {
                ManeuverSelectionSubphase subphase = Phases.StartTemporarySubPhaseNew <ManeuverSelectionSubphase>(
                    "Select a maneuver",
                    Triggers.FinishTrigger
                    );
                subphase.RequiredPlayer = Selection.ThisShip.Owner.PlayerNo;
                subphase.Start();
                subphase.IsReadyForCommands = true;

                ShipMovementScript.SendAssignManeuverCommand(Selection.ThisShip.ShipId, SavedManeuver.ToString());
            }
            else
            {
                Triggers.FinishTrigger();
            }
        }
Beispiel #2
0
 public override void Execute()
 {
     ShipMovementScript.AssignManeuverSimple(
         int.Parse(GetString("id")),
         GetString("maneuver")
         );
 }
Beispiel #3
0
        protected virtual void TryAlternativeMovement()
        {
            if (alternativeManeuvers.Count > 0)
            {
                MovementStruct maneuver = alternativeManeuvers[0];
                alternativeManeuvers.Remove(alternativeManeuvers[0]);

                if (failedManeuvers.Contains(maneuver))
                {
                    TryAlternativeMovement();
                }
                else
                {
                    GenericMovement newMovementAttempt = ShipMovementScript.MovementFromStruct(maneuver);

                    if (DebugManager.DebugAI)
                    {
                        Debug.Log("Tries: " + newMovementAttempt);
                    }

                    Selection.ThisShip.SetAssignedManeuver(newMovementAttempt);
                    newMovementAttempt.Initialize();
                    movementPrediction = new MovementPrediction(newMovementAttempt, CheckSwerveAlternativePrediction);
                }
            }
            else
            {
                Console.Write("Ship doesn't see alternatives to the asteroid collision", LogTypes.AI, false, "yellow");
                Selection.ThisShip.SetAssignedManeuver(originalMovement);
                Selection.ThisShip.AssignedManeuver.LaunchShipMovement();
            }
        }
    private void InitializeScripts()
    {
        PrefabsList = this.GetComponent <PrefabsList>();
        UI          = this.GetComponent <UI>();

        Movement = this.GetComponent <ShipMovementScript>();
    }
        private static IEnumerator PredictManeuversOfThisShip()
        {
            Selection.ChangeActiveShip(CurrentShip);

            NavigationResults = new Dictionary <string, NavigationResult>();

            foreach (var maneuver in CurrentShip.GetManeuvers())
            {
                GenericMovement movement = ShipMovementScript.MovementFromString(maneuver.Key);
                CurrentShip.SetAssignedManeuver(movement, isSilent: true);
                movement.Initialize();
                movement.IsSimple = true;

                CurrentMovementPrediction = new MovementPrediction(movement);
                yield return(CurrentMovementPrediction.CalculateMovementPredicition());

                VirtualBoard.SetVirtualPositionInfo(CurrentShip, CurrentMovementPrediction.FinalPositionInfo);
                VirtualBoard.SwitchToVirtualPosition(CurrentShip);
                yield return(CheckNextTurnRecursive(GetShortestTurnManeuvers()));

                yield return(ProcessMovementPredicition());

                VirtualBoard.SwitchToRealPosition(CurrentShip);
            }
        }
Beispiel #6
0
        private static IEnumerator CheckNextTurnRecursive(GenericShip ship)
        {
            VirtualBoard.RemoveCollisionsExcept(ship);

            bool HasAnyManeuverWithoutOffBoardFinish    = false;
            bool HasAnyManeuverWithoutAsteroidCollision = false;

            foreach (string turnManeuver in GetShortestTurnManeuvers(ship))
            {
                GenericMovement movement = ShipMovementScript.MovementFromString(turnManeuver);

                ship.SetAssignedManeuver(movement, isSilent: true);
                movement.Initialize();
                movement.IsSimple = true;

                MovementPrediction prediction = new MovementPrediction(ship, movement);
                yield return(prediction.CalculateMovementPredicition());

                if (!CurrentNavigationResult.isOffTheBoard)
                {
                    HasAnyManeuverWithoutOffBoardFinish = true;
                }
                if (CurrentNavigationResult.obstaclesHit == 0)
                {
                    HasAnyManeuverWithoutAsteroidCollision = true;
                }
            }

            CurrentNavigationResult.isOffTheBoardNextTurn = !HasAnyManeuverWithoutOffBoardFinish;
            CurrentNavigationResult.isHitAsteroidNextTurn = !HasAnyManeuverWithoutAsteroidCollision;

            VirtualBoard.ReturnCollisionsExcept(ship);
        }
Beispiel #7
0
        protected void PerformManeuverOfShip(GenericShip ship)
        {
            ship.IsManeuverPerformed = true;
            GameCommand command = ShipMovementScript.GenerateActivateAndMoveCommand(Selection.ThisShip.ShipId);

            GameMode.CurrentGameMode.ExecuteCommand(command);
        }
        private static IEnumerator CheckNextTurnRecursive(List <string> turnManeuvers)
        {
            NextTurnNavigationResults = new List <NavigationResult>();

            VirtualBoard.RemoveCollisionsExcept(CurrentShip);
            foreach (string turnManeuver in turnManeuvers)
            {
                GenericMovement movement = ShipMovementScript.MovementFromString(turnManeuver);
                if (movement.Bearing == ManeuverBearing.Stationary)
                {
                    continue;
                }

                CurrentShip.SetAssignedManeuver(movement, isSilent: true);
                movement.Initialize();
                movement.IsSimple             = true;
                CurrentTurnMovementPrediction = new MovementPrediction(movement);
                yield return(CurrentTurnMovementPrediction.CalculateMovementPredicition());

                NextTurnNavigationResults.Add(new NavigationResult()
                {
                    isOffTheBoard = CurrentTurnMovementPrediction.IsOffTheBoard,
                    obstaclesHit  = CurrentMovementPrediction.AsteroidsHit.Count
                });
            }
            VirtualBoard.ReturnCollisionsExcept(CurrentShip);
        }
Beispiel #9
0
        protected virtual void TryAlternativeMovement()
        {
            if (alternativeManeuvers.Count > 0)
            {
                ManeuverHolder maneuver = alternativeManeuvers[0];
                maneuver.UpdateColorComplexity();
                alternativeManeuvers.Remove(alternativeManeuvers[0]);

                if (failedManeuvers.Contains(maneuver) || !Selection.ThisShip.HasManeuver(maneuver))
                {
                    TryAlternativeMovement();
                }
                else
                {
                    GenericMovement newMovementAttempt = ShipMovementScript.MovementFromStruct(maneuver);

                    if (DebugManager.DebugAI)
                    {
                        Debug.Log("Tries: " + newMovementAttempt);
                    }

                    Selection.ThisShip.SetAssignedManeuver(newMovementAttempt);
                    newMovementAttempt.Initialize();
                    //movementPrediction = new MovementPrediction(newMovementAttempt, CheckSwerveAlternativePrediction);
                }
            }
            else
            {
                Selection.ThisShip.SetAssignedManeuver(originalMovement);
                LaunchMovementFinally();
            }
        }
Beispiel #10
0
        public override void AskAssignManeuver()
        {
            Selection.ThisShip.Ai.TimeManeuverAssigned = Time.time;
            ShipMovementScript.SendAssignManeuverCommand(Selection.ThisShip.ShipId, AI.Aggressor.NavigationSubSystem.BestManeuver);

            AssignManeuverRecursive();
        }
Beispiel #11
0
        private void DoPseudoBoost(object sender, System.EventArgs e)
        {
            Messages.ShowInfo(HostShip.PilotInfo.PilotName + " is resolving Boost as a maneuver");

            SavedManeuver = HostShip.AssignedManeuver;

            SavedManeuverColors = new Dictionary <string, MovementComplexity>();
            foreach (var changedManeuver in ChangedManeuversCodes)
            {
                KeyValuePair <ManeuverHolder, MovementComplexity> existingManeuver = (HostShip.DialInfo.PrintedDial.FirstOrDefault(n => n.Key.ToString() == changedManeuver));
                SavedManeuverColors.Add(changedManeuver, (existingManeuver.Equals(default(KeyValuePair <ManeuverHolder, MovementComplexity>))) ? MovementComplexity.None : existingManeuver.Value);
                HostShip.Maneuvers[changedManeuver] = MovementComplexity.Normal;
            }

            // Direction from action
            HostShip.SetAssignedManeuver(
                ShipMovementScript.MovementFromString(
                    ManeuverFromBoostTemplate(
                        (ActionToRevert as BoostAction).SelectedBoostTemplate
                        )
                    )
                );

            HostShip.AssignedManeuver.IsRevealDial = false;
            HostShip.AssignedManeuver.GrantedBy    = HostShip.PilotInfo.PilotName;
            ShipMovementScript.LaunchMovement(FinishAbility);
        }
Beispiel #12
0
 private static void RevealManeuver()
 {
     Selection.ThisShip.CallManeuverIsRevealed(
         delegate { ShipMovementScript.LaunchMovement(FinishMovementAndStartActionDecision); },
         FinishMovementAndStartActionDecision
         );
 }
Beispiel #13
0
        private void ExecuteSelectedManeuver()
        {
            Selection.ThisShip.AssignedManeuver.IsRevealDial = false;

            Selection.ThisShip.CallUpdateChosenSlamTemplate(Selection.ThisShip.AssignedManeuver);

            ShipMovementScript.LaunchMovement(AssignWeaponsDisabledToken);
        }
 private void RpcLaunchStoredManeuver(int shipId)
 {
     if (DebugManager.DebugNetwork)
     {
         UI.AddTestLogEntry("C: RpcLaunchStoredManeuver");
     }
     ShipMovementScript.PerformStoredManeuver(shipId);
 }
Beispiel #15
0
        public override void Execute()
        {
            int shipId = int.Parse(GetString("id"));

            Console.Write($"\nMovement activation of : {Roster.GetShipById("ShipId:" + shipId).PilotInfo.PilotName} (ID:{shipId})");

            ShipMovementScript.ActivateAndMove(shipId);
        }
Beispiel #16
0
 private void ManeuverSelected(string maneuverString)
 {
     if (maneuverString != TargetShip.AssignedManeuver.ToString())
     {
         HostShip.State.Force--;
     }
     ShipMovementScript.SendAssignManeuverCommand(maneuverString);
 }
Beispiel #17
0
        private void FinishAdaptiveAileronsAbility()
        {
            RestoreManuverColors(HostShip);

            Phases.CurrentSubPhase.IsReadyForCommands = true;
            ShipMovementScript.SendAssignManeuverCommand(Selection.ThisShip.ShipId, SavedManeuver.ToString());
            //GameMode.CurrentGameMode.AssignManeuver(SavedManeuver.ToString());
            // It calls Triggers.FinishTrigger
        }
        public override void Execute()
        {
            int    shipId       = int.Parse(GetString("id"));
            string maneuverCode = GetString("maneuver");

            Console.Write($"Maneuver is assigned: \"{maneuverCode}\" for {Roster.GetShipById("ShipId:" + shipId).PilotInfo.PilotName} (ID:{shipId})");

            ShipMovementScript.AssignManeuver(shipId, maneuverCode);
        }
Beispiel #19
0
        public override void AskAssignManeuver()
        {
            base.AskAssignManeuver();

            if (DebugManager.DebugStraightToCombat)
            {
                ShipMovementScript.SendAssignManeuverCommand("2.F.S");
                AssignManeuversRecursive();
            }
        }
Beispiel #20
0
    private void InitializeScripts()
    {
        PrefabsList = this.GetComponent <PrefabsList>();
        UI          = this.GetComponent <UI>();
        UI.Initialize();

        Movement = this.GetComponent <ShipMovementScript>();
        Movement.Initialize();
        Position = this.GetComponent <ShipPositionManager>();
    }
            private static IEnumerator PredictCurrentManeuver()
            {
                string          maneuverCode = Ship.AssignedManeuver.ToString();
                GenericMovement movement     = ShipMovementScript.MovementFromString(maneuverCode);

                Ship.SetAssignedManeuver(movement, isSilent: true);
                movement.Initialize();

                MovementPrediction = new MovementPrediction(Ship, movement);
                yield return(MovementPrediction.CalculateMovementPredicition());
            }
Beispiel #22
0
        private static IEnumerator PredictFinalPosionsOfOwnShip(GenericShip ship)
        {
            Selection.ChangeActiveShip(ship);
            VirtualBoard.SwitchToRealPosition(ship);

            Dictionary <string, NavigationResult> navigationResults = new Dictionary <string, NavigationResult>();

            foreach (var maneuver in ship.GetManeuvers())
            {
                GenericMovement movement = ShipMovementScript.MovementFromString(maneuver.Key);
                ship.SetAssignedManeuver(movement, isSilent: true);
                movement.Initialize();
                movement.IsSimple = true;

                MovementPrediction prediction = new MovementPrediction(ship, movement);
                prediction.CalculateOnlyFinalPositionIgnoringCollisions();

                VirtualBoard.SetVirtualPositionInfo(ship, prediction.FinalPositionInfo, prediction.CurrentMovement.ToString());
                VirtualBoard.SwitchToVirtualPosition(ship);

                float minDistanceToEnemyShip, minDistanceToNearestEnemyInShotRange, minAngle;
                int   enemiesInShotRange;
                ProcessHeavyGeometryCalculations(ship, out minDistanceToEnemyShip, out minDistanceToNearestEnemyInShotRange, out minAngle, out enemiesInShotRange);

                NavigationResult result = new NavigationResult()
                {
                    movement = prediction.CurrentMovement,
                    distanceToNearestEnemy            = minDistanceToEnemyShip,
                    distanceToNearestEnemyInShotRange = minDistanceToNearestEnemyInShotRange,
                    angleToNearestEnemy = minAngle,
                    enemiesInShotRange  = enemiesInShotRange,
                    isBumped            = prediction.IsBumped,
                    isLandedOnObstacle  = prediction.IsLandedOnAsteroid,
                    isOffTheBoard       = prediction.IsOffTheBoard,
                    FinalPositionInfo   = prediction.FinalPositionInfo
                };
                result.CalculatePriority();

                if (DebugManager.DebugAiNavigation)
                {
                    Console.Write("", LogTypes.AI);
                }

                navigationResults.Add(maneuver.Key, result);

                VirtualBoard.SwitchToRealPosition(ship);

                yield return(true);
            }

            ship.ClearAssignedManeuver();
            VirtualBoard.UpdateNavigationResults(ship, navigationResults);
        }
Beispiel #23
0
        private void AssignManeuverWithIncreasedComplexity(string maneuverCode)
        {
            if (maneuverCode != HostShip.AssignedManeuver.ToString())
            {
                Messages.ShowInfo(HostUpgrade.UpgradeInfo.Name + ": The difficulty of the maneuver has been increased");

                HostShip.AfterGetManeuverColorIncreaseComplexity += ChangeComplexity;
                HostShip.OnMovementFinish += ClearAbility;
            }

            ShipMovementScript.SendAssignManeuverCommand(maneuverCode);
        }
Beispiel #24
0
 public override void DoSelectThisShip(GenericShip ship, int mouseKeyIsPressed)
 {
     if (!ship.IsManeuverPerformed)
     {
         GameCommand command = ShipMovementScript.GenerateActivateAndMoveCommand(Selection.ThisShip.ShipId);
         GameMode.CurrentGameMode.ExecuteCommand(command);
     }
     else
     {
         Messages.ShowErrorToHuman("This ship has already executed his maneuver");
     };
 }
 public override void AskAssignManeuver()
 {
     if (!DebugManager.DebugStraightToCombat)
     {
         AI.Aggressor.NavigationSubSystem.AssignPlannedManeuver(AssignManeuversRecursive);
     }
     else
     {
         ShipMovementScript.SendAssignManeuverCommand("2.F.S");
         AssignManeuversRecursive();
     }
 }
Beispiel #26
0
        private void AskChangeManeuver(object sender, System.EventArgs e)
        {
            Messages.ShowInfoToHuman(HostShip.PilotInfo.PilotName + " : You can change your maneuver");

            HostShip.Owner.ChangeManeuver(
                (maneuverCode) => {
                ShipMovementScript.SendAssignManeuverCommand(maneuverCode);
            },
                Triggers.FinishTrigger,
                IsSpeedPlusMinus1
                );
        }
Beispiel #27
0
 private void ExecuteSelectedManeuver()
 {
     if (doAilerons)
     {
         HostShip.AssignedManeuver.IsRevealDial = false;
         ShipMovementScript.LaunchMovement(FinishAdaptiveAileronsAbility);
     }
     else
     {
         doAilerons = true;
         FinishAdaptiveAileronsAbility();
     }
 }
Beispiel #28
0
 private void ManeuverSelected(string maneuverString)
 {
     if (maneuverString != TargetShip.AssignedManeuver.ToString())
     {
         HostShip.State.SpendForce(
             1,
             delegate { ShipMovementScript.SendAssignManeuverCommand(maneuverString); }
             );
     }
     else
     {
         ShipMovementScript.SendAssignManeuverCommand(maneuverString);
     }
 }
Beispiel #29
0
        private bool FilterOnlyForward(string maneuverCode)
        {
            bool            result   = true;
            GenericMovement maneuver = ShipMovementScript.MovementFromString(maneuverCode);

            if (maneuver.Bearing == ManeuverBearing.Stationary ||
                maneuver.Bearing == ManeuverBearing.ReverseStraight ||
                maneuver.Bearing == ManeuverBearing.ReverseBank)
            {
                result = false;
            }

            return(result);
        }
    private void RpcExtraMovementStart()
    {
        if (ShipMovementScript.ExtraMovementCallback == null)
        {
            Console.Write("Waiting to sync extra movement callback...", LogTypes.Everything, true, "orange");

            GameManagerScript Game = GameObject.Find("GameManager").GetComponent <GameManagerScript>();
            Game.Wait(0.5f, RpcExtraMovementStart);
        }
        else
        {
            ShipMovementScript.LaunchMovement(null);
        }
    }
Beispiel #31
0
 // Use this for initialization
 void Start()
 {
     shipscript = GameObject.FindObjectOfType<ShipMovementScript>();
     guiText = GetComponent<GUIText>();
 }