refactor(backend): align api namespaces and project name
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
namespace SpaceGame.Simulation.Api.Simulation;
|
||||
using SpaceGame.Api.Simulation.Engine;
|
||||
using SpaceGame.Api.Simulation.Model;
|
||||
|
||||
namespace SpaceGame.Api.Simulation.AI;
|
||||
|
||||
// ─── Planning State ────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
namespace SpaceGame.Simulation.Api.Simulation;
|
||||
using SpaceGame.Api.Simulation.Engine;
|
||||
using SpaceGame.Api.Simulation.Model;
|
||||
|
||||
namespace SpaceGame.Api.Simulation.AI;
|
||||
|
||||
public abstract class GoapAction<TState>
|
||||
{
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
namespace SpaceGame.Simulation.Api.Simulation;
|
||||
using SpaceGame.Api.Simulation.Engine;
|
||||
using SpaceGame.Api.Simulation.Model;
|
||||
|
||||
namespace SpaceGame.Api.Simulation.AI;
|
||||
|
||||
internal interface IShipBehaviorState
|
||||
{
|
||||
string Kind { get; }
|
||||
string Kind { get; }
|
||||
|
||||
void Plan(SimulationEngine engine, ShipRuntime ship, SimulationWorld world);
|
||||
void Plan(SimulationEngine engine, ShipRuntime ship, SimulationWorld world);
|
||||
|
||||
void ApplyEvent(SimulationEngine engine, ShipRuntime ship, SimulationWorld world, string controllerEvent);
|
||||
void ApplyEvent(SimulationEngine engine, ShipRuntime ship, SimulationWorld world, string controllerEvent);
|
||||
}
|
||||
|
||||
@@ -1,38 +1,41 @@
|
||||
namespace SpaceGame.Simulation.Api.Simulation;
|
||||
using SpaceGame.Api.Simulation.Engine;
|
||||
using SpaceGame.Api.Simulation.Model;
|
||||
|
||||
namespace SpaceGame.Api.Simulation.AI;
|
||||
|
||||
internal sealed class ShipBehaviorStateMachine
|
||||
{
|
||||
private readonly IReadOnlyDictionary<string, IShipBehaviorState> states;
|
||||
private readonly IShipBehaviorState fallbackState;
|
||||
private readonly IReadOnlyDictionary<string, IShipBehaviorState> states;
|
||||
private readonly IShipBehaviorState fallbackState;
|
||||
|
||||
private ShipBehaviorStateMachine(IReadOnlyDictionary<string, IShipBehaviorState> states, IShipBehaviorState fallbackState)
|
||||
{
|
||||
this.states = states;
|
||||
this.fallbackState = fallbackState;
|
||||
}
|
||||
private ShipBehaviorStateMachine(IReadOnlyDictionary<string, IShipBehaviorState> states, IShipBehaviorState fallbackState)
|
||||
{
|
||||
this.states = states;
|
||||
this.fallbackState = fallbackState;
|
||||
}
|
||||
|
||||
public static ShipBehaviorStateMachine CreateDefault()
|
||||
public static ShipBehaviorStateMachine CreateDefault()
|
||||
{
|
||||
var idleState = new IdleShipBehaviorState();
|
||||
var knownStates = new IShipBehaviorState[]
|
||||
{
|
||||
var idleState = new IdleShipBehaviorState();
|
||||
var knownStates = new IShipBehaviorState[]
|
||||
{
|
||||
idleState,
|
||||
new PatrolShipBehaviorState(),
|
||||
new ResourceHarvestShipBehaviorState("auto-mine", "ore", "mining"),
|
||||
new ConstructStationShipBehaviorState(),
|
||||
};
|
||||
};
|
||||
|
||||
return new ShipBehaviorStateMachine(
|
||||
knownStates.ToDictionary(state => state.Kind, StringComparer.Ordinal),
|
||||
idleState);
|
||||
}
|
||||
return new ShipBehaviorStateMachine(
|
||||
knownStates.ToDictionary(state => state.Kind, StringComparer.Ordinal),
|
||||
idleState);
|
||||
}
|
||||
|
||||
public void Plan(SimulationEngine engine, ShipRuntime ship, SimulationWorld world) =>
|
||||
Resolve(ship.DefaultBehavior.Kind).Plan(engine, ship, world);
|
||||
public void Plan(SimulationEngine engine, ShipRuntime ship, SimulationWorld world) =>
|
||||
Resolve(ship.DefaultBehavior.Kind).Plan(engine, ship, world);
|
||||
|
||||
public void ApplyEvent(SimulationEngine engine, ShipRuntime ship, SimulationWorld world, string controllerEvent) =>
|
||||
Resolve(ship.DefaultBehavior.Kind).ApplyEvent(engine, ship, world, controllerEvent);
|
||||
public void ApplyEvent(SimulationEngine engine, ShipRuntime ship, SimulationWorld world, string controllerEvent) =>
|
||||
Resolve(ship.DefaultBehavior.Kind).ApplyEvent(engine, ship, world, controllerEvent);
|
||||
|
||||
private IShipBehaviorState Resolve(string kind) =>
|
||||
states.TryGetValue(kind, out var state) ? state : fallbackState;
|
||||
private IShipBehaviorState Resolve(string kind) =>
|
||||
states.TryGetValue(kind, out var state) ? state : fallbackState;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
namespace SpaceGame.Simulation.Api.Simulation;
|
||||
using SpaceGame.Api.Simulation.Engine;
|
||||
using SpaceGame.Api.Simulation.Model;
|
||||
|
||||
namespace SpaceGame.Api.Simulation.AI;
|
||||
|
||||
internal sealed class IdleShipBehaviorState : IShipBehaviorState
|
||||
{
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
namespace SpaceGame.Simulation.Api.Simulation;
|
||||
using SpaceGame.Api.Simulation.Engine;
|
||||
using SpaceGame.Api.Simulation.Model;
|
||||
|
||||
namespace SpaceGame.Api.Simulation.AI;
|
||||
|
||||
// ─── Planning State ────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
Reference in New Issue
Block a user