Added Console

Debug commands can now be executed using an in-game console
This commit is contained in:
hyperion51 2020-04-28 01:50:50 +01:00
commit 75eb534983
305 changed files with 2975 additions and 17480 deletions

View file

@ -15,14 +15,7 @@ public class AgentController
private Locomotion _locomotion;
private VelocityMatch _velocityMatch;
private Random _random = new Random((uint) (DateTime.Now.Ticks%uint.MaxValue));
private float _stoppingTime;
private float _stoppingDistance;
private float _turnaroundDistance;
private float _turnaroundTime;
private IAnalogBehavior _thrust;
private IAnalogBehavior _turning;
private KeyValuePair<DatabaseEntry, Entity> _objective;
private float _velocityLimit;
public AgentController(GameContext context, ZoneData zone, Entity entity)
{
@ -39,41 +32,31 @@ public class AgentController
};
EntityAgent.CurrentBehavior = _locomotion;
RandomTarget();
_thrust = entity.Axes.Keys.FirstOrDefault(x => x is Thruster);
_turning = entity.Axes.Keys.FirstOrDefault(x => x is Turning);
var velocityLimitData = entity.GetBehaviorData<VelocityLimitData>().FirstOrDefault();
_velocityLimit = Context.Evaluate(velocityLimitData.TopSpeed, entity.Hull, entity);
_stoppingTime = _velocityLimit / Context.Evaluate((_thrust.Data as ThrusterData).Thrust, _thrust.Item, Entity) * Entity.Mass;
_stoppingDistance = _stoppingTime * _velocityLimit / 2;
_turnaroundTime = PI / Context.Evaluate((_turning.Data as TurningData).Torque, _turning.Item, entity) * entity.Mass;
_turnaroundDistance = _turnaroundTime * _velocityLimit;
_locomotion.LeadTime = _stoppingTime;
}
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} " +
$"Turnaround Distance: {_stoppingDistance + _turnaroundDistance} " +
$"Objective: {_objective.Key.ID.ToString().Substring(0, 8)}");
// Context.Log(
// $"Agent Mode: {EntityAgent.CurrentBehavior.GetType()} " +
// $"Agent Distance: {distance} " +
// $"Turnaround Distance: {_stoppingDistance + _turnaroundDistance} " +
// $"Objective: {_objective.Key.ID.ToString().Substring(0, 8)}");
if (EntityAgent.CurrentBehavior == _locomotion)
{
var velocity = length(Entity.Velocity);
_stoppingTime = velocity / Context.Evaluate((_thrust.Data as ThrusterData).Thrust, _thrust.Item, Entity) * Entity.Mass;
_stoppingDistance = _stoppingTime * velocity / 2;
if (distance < _stoppingDistance + _turnaroundDistance)
EntityAgent.CurrentBehavior = _velocityMatch;
_velocityMatch.Objective = _locomotion.Objective;
var matchDistanceTime = _velocityMatch.MatchDistanceTime;
_locomotion.LeadTime = matchDistanceTime.y;
if (distance < matchDistanceTime.x)
EntityAgent.CurrentBehavior = _velocityMatch;
}
}
private void RandomTarget()
{
var entities = Context.ZoneContents[Zone].ToArray();
var entities = Context.ZoneContents[Zone].Where(kvp=>!(kvp.Key is ShipData)).ToArray();
_objective = entities[_random.NextInt(entities.Length)];
_locomotion.Objective = _objective.Value;
}

View file

@ -35,4 +35,22 @@ public class VelocityMatch : AgentBehavior
_entity.Axes[_thrust] = saturate(length(pow(saturate(dot(normalize(_entity.Direction),normalize(deltaV))), 8)*length(deltaV))*ThrustSensitivity);
}
}
public float2 MatchDistanceTime
{
get
{
var velocity = length(_entity.Velocity);
var deltaV = Objective.Velocity - _entity.Velocity;
var stoppingTime = length(deltaV) / _entity.Context.Evaluate((_thrust.Data as ThrusterData).Thrust, _thrust.Item, _entity) * _entity.Mass;
var stoppingDistance = stoppingTime * velocity / 2;
var angleDiff = _entity.Direction.AngleDiff(deltaV);
var turnaroundTime = angleDiff / _entity.Context.Evaluate((_turning.Data as TurningData).Torque, _turning.Item, _entity) * _entity.Mass;
var turnaroundDistance = turnaroundTime * velocity;
return float2(stoppingDistance + turnaroundDistance, stoppingTime + turnaroundTime);
}
}
}