protected virtual void CheckSwerveAlternativePrediction() { if ((movementPrediction.AsteroidsHit.Count == 0) && (!movementPrediction.IsOffTheBoard)) { if (DebugManager.DebugAI) { Debug.Log("And it works!"); } alternativeManeuvers = new List <ManeuverHolder>(); GenericMovement assignedManeuver = movementPrediction.CurrentMovement; assignedManeuver.movementPrediction = movementPrediction; Selection.ThisShip.SetAssignedManeuver(assignedManeuver); LaunchMovementFinally(); } else { if (DebugManager.DebugAI) { Debug.Log("But it doesn't works..."); } if (IsForced) { if (DebugManager.DebugAI) { Debug.Log("Search for new alternatives..."); } GetAlternativeManeuvers(movementPrediction.CurrentMovement); } TryAlternativeMovement(); } }
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); }
private void CheckAbility(GenericShip ship, ref MovementStruct movement) { if (HostShip.Shields == 0 && movement.Bearing == ManeuverBearing.Bank) { movement.ColorComplexity = GenericMovement.ReduceComplexity(movement.ColorComplexity); } }
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); } }
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(); } }
IEnumerator Transformation() { if (playerAffected != null) { PlayerControls controls = playerAffected.GetComponent <PlayerControls>(); Object sheepObject = Object.Instantiate(Resources.Load("Prefabs/Sheep"), null); sheep = ((GameObject)sheepObject); sheep.transform.position = playerAffected.transform.position; GenericMovement sheepMovement = sheep.AddComponent <GenericMovement>(); sheepMovement.Manette = controls.Manette; sheepMovement.moveSpeed = controls.moveSpeed / 2; playerAffected.SetActive(false); yield return(new WaitForSeconds(time)); if (playerAffected != null) { if (!playerAffected.activeSelf) { playerAffected.SetActive(true); playerAffected.transform.position = sheep.transform.position; GameObject.Destroy(sheep); } } } }
private void DecreaseDifficulty(GenericShip ship, ref ManeuverHolder movement) { if (HostShip.State.ShieldsCurrent == 0 && movement.ColorComplexity != MovementComplexity.None && movement.Bearing == ManeuverBearing.Bank) { movement.ColorComplexity = GenericMovement.ReduceComplexity(movement.ColorComplexity); } }
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); }
private void CheckReduceComplexity(GenericShip ship) { if (ship.Owner.PlayerNo == HostShip.Owner.PlayerNo && ship.AssignedManeuver.ColorComplexity == MovementComplexity.Complex) { ship.AssignedManeuver.ColorComplexity = GenericMovement.ReduceComplexity(ship.AssignedManeuver.ColorComplexity); } }
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 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); }
protected virtual void CheckSwerveAlternativePrediction() { if ((movementPrediction.AsteroidsHit.Count == 0) && (!movementPrediction.IsOffTheBoard)) { if (DebugManager.DebugAI) { Debug.Log("And it works!"); } Console.Write("Ship found maneuver to avoid asteroid collision\n", LogTypes.AI, true, "yellow"); alternativeManeuvers = new List <MovementStruct>(); GenericMovement assignedManeuver = movementPrediction.CurrentMovement; assignedManeuver.movementPrediction = movementPrediction; Selection.ThisShip.SetAssignedManeuver(assignedManeuver); Selection.ThisShip.AssignedManeuver.LaunchShipMovement(); } else { if (DebugManager.DebugAI) { Debug.Log("But it doesn't works..."); } if (IsForced) { if (DebugManager.DebugAI) { Debug.Log("Search for new alternatives..."); } GetAlternativeManeuvers(movementPrediction.CurrentMovement); } TryAlternativeMovement(); } }
void Start() { genMov = GetComponent <GenericMovement>(); animator = GetComponent <Animator> (); player = genMov.player; canExit = false; }
protected virtual void Start() { _anim = gameObject.GetComponent <Animator>(); Keys = gameObject.GetComponent <GenericInput>(); Stats = gameObject.GetComponent <GenericStats>(); Movement = gameObject.GetComponent <GenericMovement>(); }
public Swerve(bool isForced = false) { IsForced = isForced; originalMovement = Selection.ThisShip.AssignedManeuver; alternativeManeuvers = GetAlternativeManeuvers(Selection.ThisShip.AssignedManeuver); TryAlternativeMovement(); }
private void StartBoostExecution() { Rules.Collision.ClearBumps(TheShip); switch (SelectedBoostHelper) { case "Straight 1": BoostMovement = new StraightBoost(1, ManeuverDirection.Forward, ManeuverBearing.Straight, MovementComplexity.None); break; case "Bank 1 Left": BoostMovement = new BankBoost(1, ManeuverDirection.Left, ManeuverBearing.Bank, MovementComplexity.None); break; case "Bank 1 Right": BoostMovement = new BankBoost(1, ManeuverDirection.Right, ManeuverBearing.Bank, MovementComplexity.None); break; case "Turn 1 Right": BoostMovement = new TurnBoost(1, ManeuverDirection.Right, ManeuverBearing.Turn, MovementComplexity.None); break; case "Turn 1 Left": BoostMovement = new TurnBoost(1, ManeuverDirection.Left, ManeuverBearing.Turn, MovementComplexity.None); break; case "Straight 2": BoostMovement = new StraightBoost(2, ManeuverDirection.Forward, ManeuverBearing.Straight, MovementComplexity.None); break; case "Bank 2 Left": BoostMovement = new BankBoost(2, ManeuverDirection.Left, ManeuverBearing.Bank, MovementComplexity.None); break; case "Bank 2 Right": BoostMovement = new BankBoost(2, ManeuverDirection.Right, ManeuverBearing.Bank, MovementComplexity.None); break; case "Turn 2 Right": BoostMovement = new TurnBoost(2, ManeuverDirection.Right, ManeuverBearing.Turn, MovementComplexity.None); break; case "Turn 2 Left": BoostMovement = new TurnBoost(2, ManeuverDirection.Left, ManeuverBearing.Turn, MovementComplexity.None); break; default: BoostMovement = new StraightBoost(1, ManeuverDirection.Forward, ManeuverBearing.Straight, MovementComplexity.None); break; } BoostMovement.FinalPositionInfo = FinalPositionInfo; BoostMovement.TheShip = TheShip; MovementTemplates.ApplyMovementRuler(TheShip, BoostMovement); GameManagerScript.Instance.StartCoroutine(BoostExecutionCoroutine()); }
public static GenericMovement MovementFromStruct(ManeuverHolder movementStruct) { GenericMovement result = null; if (movementStruct.Bearing == ManeuverBearing.Straight) { result = new StraightMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity); } else if (movementStruct.Bearing == ManeuverBearing.KoiogranTurn) { result = new KoiogranTurnMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity); } else if (movementStruct.Bearing == ManeuverBearing.Turn) { result = new TurnMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity); } else if (movementStruct.Bearing == ManeuverBearing.Bank) { result = new BankMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity); } else if (movementStruct.Bearing == ManeuverBearing.SegnorsLoop) { result = new SegnorsLoopMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity); } else if (movementStruct.Bearing == ManeuverBearing.SegnorsLoopUsingTurnTemplate) { result = new SegnorsLoopUsingTurnTemplateMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity); } else if (movementStruct.Bearing == ManeuverBearing.TallonRoll) { result = new TallonRollMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity); } else if (movementStruct.Bearing == ManeuverBearing.Stationary) { result = new StationaryMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity); } else if (movementStruct.Bearing == ManeuverBearing.SideslipBank) { result = new SideslipBankMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity); } else if (movementStruct.Bearing == ManeuverBearing.SideslipTurn) { result = new SideslipTurnMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity); } else if (movementStruct.Bearing == ManeuverBearing.ReverseStraight) { if (movementStruct.Direction == ManeuverDirection.Forward) { result = new ReverseStraightMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity); } else { result = new ReverseBankMovement(movementStruct.SpeedIntUnsigned, movementStruct.Direction, movementStruct.Bearing, movementStruct.ColorComplexity); } } return(result); }
private void UseAbility(object sender, EventArgs e) { if (HostUpgrade.State.Charges > 0) { HostShip.AssignedManeuver.ColorComplexity = GenericMovement.ReduceComplexity(HostShip.AssignedManeuver.ColorComplexity); HostUpgrade.State.SpendCharge(); } SubPhases.DecisionSubPhase.ConfirmDecision(); }
private void ChangeComplexity(GenericShip ship, ref ManeuverHolder movement) { if (movement.ToString() == HostShip.AssignedManeuver.ToString()) { return; } movement.ColorComplexity = GenericMovement.IncreaseComplexity(movement.ColorComplexity); }
private void ApplyAbility(GenericShip ship, ref MovementStruct movement) { if (movement.Speed == ManeuverSpeed.Speed1 || movement.Speed == ManeuverSpeed.Speed2) { if (movement.Bearing == ManeuverBearing.Straight || movement.Bearing == ManeuverBearing.Bank || movement.Bearing == ManeuverBearing.Turn) { movement.ColorComplexity = GenericMovement.ReduceComplexity(movement.ColorComplexity); } } }
private void NienNunbAbility(GenericShip ship, ref MovementStruct movement) { if (movement.ColorComplexity != MovementComplexity.None) { if (movement.Bearing == ManeuverBearing.Bank) { movement.ColorComplexity = GenericMovement.ReduceComplexity(movement.ColorComplexity); } } }
private void ApplyAbility(GenericShip ship, ref ManeuverHolder movement) { if (movement.Direction == ManeuverDirection.Left) { if (movement.Bearing == ManeuverBearing.Bank || movement.Bearing == ManeuverBearing.Turn || movement.Bearing == ManeuverBearing.SegnorsLoop) { movement.ColorComplexity = GenericMovement.ReduceComplexity(movement.ColorComplexity); } } }
private void UpdateSlamTemplate(GenericMovement movement) { if (ActionsHolder.CurrentAction.IsRed) { if (movement.TryIncreaseSpeed()) { Messages.ShowInfo("Overdrive Thursters: Template of 1 speed higher is used"); } } }
private void ApplyAbility(GenericShip ship, ref ManeuverHolder movement) { if (movement.Bearing == ManeuverBearing.Straight) { movement.ColorComplexity = GenericMovement.ReduceComplexity(movement.ColorComplexity); // Update revealed dial in UI Roster.UpdateAssignedManeuverDial(HostShip, HostShip.AssignedManeuver); Messages.ShowInfoToHuman("Repulsorlift Stabilizers (Inactive): Difficulty of straight maneuvers is reduced"); } }
private void DecreaseComplexityOfManeuver(object sender, EventArgs e) { Selection.ThisShip.AssignedManeuver.ColorComplexity = GenericMovement.ReduceComplexity(Selection.ThisShip.AssignedManeuver.ColorComplexity); // Update revealed dial in UI Roster.UpdateAssignedManeuverDial(Selection.ThisShip, Selection.ThisShip.AssignedManeuver); Messages.ShowInfo("Leia Organa: Difficulty of maneuver is reduced"); HostShip.State.SpendForce(1, DecisionSubPhase.ConfirmDecision); }
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()); }
private void ChangeManeuverColorAbility(Action callback) { GenericMovement movement = HostShip.AssignedManeuver; movement.ColorComplexity = MovementComplexity.Normal; HostShip.SetAssignedManeuver(movement); Messages.ShowInfoToHuman(string.Format("{0} changed maneuver, Adrenaline Rush is disabled on {0}", HostShip.PilotInfo.PilotName)); HostUpgrade.TryDiscard(callback); }
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); }
private void ApplyAbility(GenericShip ship, ref ManeuverHolder movement) { if (movement.Speed == ManeuverSpeed.Speed3) { if (movement.Bearing == ManeuverBearing.Straight || movement.Bearing == ManeuverBearing.Bank) { movement.ColorComplexity = GenericMovement.ReduceComplexity(movement.ColorComplexity); // Update revealed dial in UI Roster.UpdateAssignedManeuverDial(HostShip, HostShip.AssignedManeuver); Messages.ShowInfoToHuman("Maneuver-Assist MGK-300: Difficulty of maneuvers is reduced"); } } }
public GenericMovement GetManeuver(GenericShip thisShip, GenericShip anotherShip) { float vector = ActionsHolder.GetVector(thisShip, anotherShip); bool isClosing = ActionsHolder.IsClosing(thisShip, anotherShip); if (inDebug) { Debug.Log("Vector: " + vector + ", Closing: " + isClosing); } GenericMovement result = GetManeuverFromTable(vector, isClosing); return(result); }