AI State Machine First Pass

Implemented first pass on code-driven state machine logic for flexible AI agents
This commit is contained in:
Reinier Vens 2021-02-11 03:14:20 +00:00
commit 8d4bd04891
26 changed files with 489 additions and 137 deletions

View file

@ -19,6 +19,7 @@ using int2 = Unity.Mathematics.int2;
public class InventoryPanel : MonoBehaviour
{
public ConfirmationDialog ConfirmationDialog;
public bool Flip;
public GameSettings Settings;
public ActionGameManager GameManager;
@ -100,9 +101,18 @@ public class InventoryPanel : MonoBehaviour
{
if (_displayedEntity != GameManager.CurrentShip)
{
GameManager.CurrentShip = (Ship) _displayedEntity;
GameManager.DockingBay.DockedShip = (Ship) _displayedEntity;
Current.targetGraphic.color = ToggleEnabledColor;
if(_displayedEntity is Ship ship)
{
GameManager.CurrentShip = ship;
GameManager.DockingBay.DockedShip = ship;
Current.targetGraphic.color = ToggleEnabledColor;
}
else
{
ConfirmationDialog.Clear();
ConfirmationDialog.Title.text = "Can't select entity, you can only pilot a ship!";
ConfirmationDialog.Show();
}
}
});
}
@ -111,18 +121,18 @@ public class InventoryPanel : MonoBehaviour
Dropdown.onClick.AddListener(() =>
{
ContextMenu.Clear();
foreach (var ship in GameManager.AvailableShips())
foreach (var entity in GameManager.AvailableEntities())
{
if (ship.CargoBays.Any())
if (entity.CargoBays.Any())
{
var options = ship.CargoBays
var options = entity.CargoBays
.Where(bay => bay != _displayedCargo)
.Select<EquippedCargoBay, (string text, Action action, bool enabled)>((bay, index) =>
($"Bay {index}", () => Display(bay), true));
if(ship != _displayedEntity) options = options.Prepend(("Equipment", () => Display(ship), true));
ContextMenu.AddDropdown(ship.Name, options);
if(entity != _displayedEntity) options = options.Prepend(("Equipment", () => Display(entity), true));
ContextMenu.AddDropdown(entity.Name, options);
}
else if(ship != _displayedEntity) ContextMenu.AddOption(ship.Name, () => Display(ship));
else if(entity != _displayedEntity) ContextMenu.AddOption(entity.Name, () => Display(entity));
}
if(GameManager.DockingBay!=null && _displayedCargo!=GameManager.DockingBay)
@ -143,7 +153,7 @@ public class InventoryPanel : MonoBehaviour
{
var ship = EntityPack.Unpack(GameManager.ItemManager, GameManager.Zone, pack, true);
ship.SetParent(GameManager.DockedEntity);
GameManager.PlayerShips.Add(ship);
GameManager.PlayerEntities.Add(ship);
GameManager.Credits -= pack.Price(GameManager.ItemManager);
GameManager.CurrentShip = ship;
GameManager.DockingBay.DockedShip = ship;

View file

@ -272,7 +272,7 @@ public class TradeMenu : MonoBehaviour
data => () =>
{
if (data is HullData)
return GameManager.PlayerShips.Count(s => s.Hull.Data == data.ID && s.Parent == GameManager.CurrentShip.Parent).ToString();
return GameManager.PlayerEntities.Count(s => s.Hull.Data == data.ID && s.Parent == GameManager.DockedEntity).ToString();
if(data is SimpleCommodityData)
return (_targetCargo.ItemsOfType.ContainsKey(data.ID) ? _targetCargo.ItemsOfType[data.ID].Cast<SimpleCommodity>().Sum(s=>s.Quantity) : 0).ToString();
return (_targetCargo.ItemsOfType.ContainsKey(data.ID) ? _targetCargo.ItemsOfType[data.ID].Count : 0).ToString();
@ -280,7 +280,7 @@ public class TradeMenu : MonoBehaviour
data =>
{
if (data is HullData)
return GameManager.PlayerShips.Count(s => s.Hull.Data == data.ID && s.Parent == GameManager.CurrentShip.Parent);
return GameManager.PlayerEntities.Count(s => s.Hull.Data == data.ID && s.Parent == GameManager.DockedEntity);
if(data is SimpleCommodityData)
return _targetCargo.ItemsOfType.ContainsKey(data.ID) ? _targetCargo.ItemsOfType[data.ID].Cast<SimpleCommodity>().Sum(s=>s.Quantity) : 0;
return _targetCargo.ItemsOfType.ContainsKey(data.ID) ? _targetCargo.ItemsOfType[data.ID].Count : 0;
@ -355,9 +355,13 @@ public class TradeMenu : MonoBehaviour
{
if (data.Price < GameManager.Credits)
{
var ship = new Ship(GameManager.ItemManager, GameManager.Zone, GameManager.ItemManager.CreateInstance(data, .1f, 1) as EquippableItem);
ship.SetParent(GameManager.CurrentShip.Parent);
GameManager.PlayerShips.Add(ship);
var hull = GameManager.ItemManager.CreateInstance(data, .1f, 1) as EquippableItem;
Entity entity;
if(data.HullType==HullType.Ship)
entity = new Ship(GameManager.ItemManager, GameManager.Zone, hull);
else entity = new OrbitalEntity(GameManager.ItemManager, GameManager.Zone, hull, Guid.Empty);
entity.SetParent(GameManager.DockedEntity);
GameManager.PlayerEntities.Add(entity);
GameManager.Credits -= data.Price;
}
@ -444,7 +448,7 @@ public class TradeMenu : MonoBehaviour
_targetCargo = GameManager.DockingBay;
TargetCargoLabel.text = "Docking Bay";
});
foreach (var ship in GameManager.CurrentShip.Parent.Children.Where(GameManager.PlayerShips.Contains))
foreach (var ship in GameManager.CurrentShip.Parent.Children.Where(GameManager.PlayerEntities.Contains))
{
foreach (var bay in ship.CargoBays.Select((bay, index) => (bay, index)))
ContextMenu.AddOption($"{ship.Name} Bay {bay.index}",