Refactored Ghost Entities
Game Context was creating an empty OrbitalEntity for every planet; this was an ugly hack so I refactored it, as well as refactoring some object references to GUIDs as they should be
This commit is contained in:
parent
35fb4381ed
commit
4f29bf24d0
13 changed files with 199 additions and 191 deletions
|
|
@ -10,21 +10,23 @@ public class AgentController
|
|||
public Entity Entity { get; }
|
||||
public EntityAgent EntityAgent { get; }
|
||||
public GameContext Context { get; }
|
||||
public ZoneData Zone { get; set; }
|
||||
public Guid Zone { get; set; }
|
||||
|
||||
public Guid HomeZone;
|
||||
|
||||
private Locomotion _locomotion;
|
||||
private VelocityMatch _velocityMatch;
|
||||
private Random _random = new Random((uint) (DateTime.Now.Ticks%uint.MaxValue));
|
||||
private KeyValuePair<DatabaseEntry, Entity> _objective;
|
||||
private Guid _targetOrbit;
|
||||
|
||||
public AgentController(GameContext context, ZoneData zone, Entity entity)
|
||||
public AgentController(GameContext context, Guid zone, Entity entity)
|
||||
{
|
||||
Entity = entity;
|
||||
Zone = zone;
|
||||
Context = context;
|
||||
EntityAgent = new EntityAgent(context, zone, entity);
|
||||
_locomotion = new Locomotion(entity);
|
||||
_velocityMatch = new VelocityMatch(entity);
|
||||
_velocityMatch = new VelocityMatch(context, entity);
|
||||
_velocityMatch.OnMatch += () =>
|
||||
{
|
||||
EntityAgent.CurrentBehavior = _locomotion;
|
||||
|
|
@ -37,7 +39,6 @@ public class AgentController
|
|||
public void Update(float delta)
|
||||
{
|
||||
EntityAgent.Update(delta);
|
||||
var distance = length(_locomotion.Objective.Position - Entity.Position);
|
||||
// Context.Log(
|
||||
// $"Agent Mode: {EntityAgent.CurrentBehavior.GetType()} " +
|
||||
// $"Agent Distance: {distance} " +
|
||||
|
|
@ -46,9 +47,11 @@ public class AgentController
|
|||
|
||||
if (EntityAgent.CurrentBehavior == _locomotion)
|
||||
{
|
||||
_velocityMatch.Objective = _locomotion.Objective;
|
||||
var orbitData = Context.Cache.Get<OrbitData>(_targetOrbit);
|
||||
_velocityMatch.TargetOrbit = _targetOrbit;
|
||||
var matchDistanceTime = _velocityMatch.MatchDistanceTime;
|
||||
_locomotion.LeadTime = matchDistanceTime.y;
|
||||
_locomotion.Objective = Context.GetOrbitPosition(_targetOrbit) + Context.GetOrbitVelocity(_targetOrbit) * matchDistanceTime.y;
|
||||
var distance = length(_locomotion.Objective - Entity.Position);
|
||||
if (distance < matchDistanceTime.x)
|
||||
EntityAgent.CurrentBehavior = _velocityMatch;
|
||||
}
|
||||
|
|
@ -56,8 +59,7 @@ public class AgentController
|
|||
|
||||
private void RandomTarget()
|
||||
{
|
||||
var entities = Context.ZoneContents[Zone].Where(kvp=>!(kvp.Key is ShipData)).ToArray();
|
||||
_objective = entities[_random.NextInt(entities.Length)];
|
||||
_locomotion.Objective = _objective.Value;
|
||||
var entities = Context.ZonePlanets[Zone];
|
||||
_targetOrbit = Context.Cache.Get<PlanetData>(entities[_random.NextInt(entities.Length)]).Orbit;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue