Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ai boost action capability #1862

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 85 additions & 10 deletions Assets/Scripts/Model/Actions/ActionsList/BoostAction.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Actions;
using ActionsList;
using AI;
using BoardTools;
using GameModes;
using System.Linq;
using Editions;
using GameModes;
using Obstacles;
using ActionsList;
using Actions;
using Players;
using Ship;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;







namespace ActionsList
{
Expand Down Expand Up @@ -44,6 +53,19 @@ public override void RevertActionOnFail(bool hasSecondChance = false)
{
Phases.GoBack();
}

public override int GetActionPriority()
{
int result = 0;

// Check to see if we are before the maneuver phase or not.
bool isBeforeManeuverPhase = !Selection.ActiveShip.AiPlans.shipHasManeuvered;
// Until I get Advanced Sensors fixed...
isBeforeManeuverPhase = false;
result = AI.Aggressor.NavigationSubSystem.TryActionPossibilities(this, isBeforeManeuverPhase);

return result;
}
}

public class BoostMove
Expand Down Expand Up @@ -130,8 +152,23 @@ public void StartBoostPlanning()
AvailableBoostMoves = TheShip.GetAvailableBoostTemplates();

InitializeRendering();

AskSelectTemplate();
if (TheShip.Owner.PlayerType == PlayerType.Ai)
{
// We have AI here. Do AI things.
AiSinglePlan aiBoostAction = TheShip.AiPlans.GetPlanByActionName("Boost");
if (aiBoostAction != null)
{
SelectTemplateByName(aiBoostAction.actionName, aiBoostAction.isRedAction);

// Now that we're done with the plan, remove it.
TheShip.AiPlans.RemovePlan(aiBoostAction);
}
}
else
{
// We have a player here. Ask them about their boost.
AskSelectTemplate();
}
}

private void AskSelectTemplate()
Expand Down Expand Up @@ -188,6 +225,25 @@ private void SelectTemplate(BoostMove move)
DecisionSubPhase.ConfirmDecision();
}

private void SelectTemplateByName(string actionName, bool isRed)
{
if (isRed && !HostAction.IsRed)
{
HostAction.Color = ActionColor.Red;
TheShip.OnActionIsPerformed += ResetActionColor;
}

SelectedBoostHelper = actionName;
if (TheShip.Owner.PlayerType == PlayerType.Ai)
{
SelectTemplateDecisionIsTaken();
}
else
{
DecisionSubPhase.ConfirmDecision();
}
}

private void ResetActionColor(GenericAction action)
{
action.HostShip.OnActionIsPerformed -= ResetActionColor;
Expand Down Expand Up @@ -316,7 +372,24 @@ private void GetResults(System.Action<bool> canBoostCallback = null)
}
else
{
GameMode.CurrentGameMode.CancelBoost(boostProblems);
if (TheShip.Owner.PlayerType == PlayerType.Ai)
{
// Skip the failed boost action.
GameMode.CurrentGameMode.FinishBoost();
string tempName = Phases.CurrentSubPhase.Name;
Phases.CurrentSubPhase = Phases.CurrentSubPhase.PreviousSubPhase;
tempName = Phases.CurrentSubPhase.Name;

UpdateHelpInfo();



CallBack();
}
else
{
GameMode.CurrentGameMode.CancelBoost(boostProblems);
}
}
}

Expand Down Expand Up @@ -433,6 +506,7 @@ private void FinishBoostAnimation()
{
Phases.CurrentSubPhase = Phases.CurrentSubPhase.PreviousSubPhase;
Phases.CurrentSubPhase = Phases.CurrentSubPhase.PreviousSubPhase;

UpdateHelpInfo();

CallBack();
Expand All @@ -449,5 +523,6 @@ public override bool AnotherShipCanBeSelected(Ship.GenericShip anotherShip, int
bool result = false;
return result;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class NavigationResult
public bool isLandedOnObstacle;

public int enemiesInShotRange;
public int enemiesTargetingThisShip;

public int obstaclesHit;
public int minesHit;
Expand Down Expand Up @@ -42,7 +43,10 @@ public void CalculatePriority()

if (isOffTheBoardNextTurn) Priority -= 20000;

// Base our priority off of how many enemies can shoot us versus how many we can shoot.
Priority += enemiesInShotRange * 1000;
// Allow up to two enemies targeting us to equal one enemy in our attack range.
// Priority -= enemiesTargetingThisShip * 500;

Priority -= obstaclesHit * 2000;
Priority -= minesHit * 2000;
Expand Down
Loading