Files
tbd-station-14/Content.Server/AI/Components/AiControllerComponent.cs
Moony 36181334b5 StationSystem/jobs/partial spawning refactor (#7580)
* Partial work on StationSystem refactor.

* WIP station jobs API.

* forgor to fire off grid events.

* Partial implementation of StationSpawningSystem

* whoops infinite loop.

* Spawners should work now.

* it compiles.

* tfw

* Vestigial code cleanup.

* fix station deletion.

* attempt to make tests go brr

* add latejoin spawnpoints to test maps.

* make sure the station still exists while destructing spawners.

* forgot an exists check.

* destruction order check.

* hopefully fix final test.

* fail-safe radstorm.

* Deep-clean job code further. This is bugged!!!!!

* Fix job bug. (init order moment)

* whooo cleanup

* New job selection algorithm that tries to distribute fairly across stations.

* small nitpicks

* Give the heads their weights to replace the head field.

* make overflow assign take a station list.

* moment

* Fixes and test #1 of many.

* please fix nullspace

* AssignJobs should no longer even consider showing up on a trace.

* add comment.

* Introduce station configs, praying i didn't miss something.

* in one small change stations are now fully serializable.

* Further doc comments.

* whoops.

* Solve bug where assignjobs didn't account for roundstart.

* Fix spawning, improve the API.
Caught an oversight in stationsystem that should've broke everything but didn't, whoops.

* Goodbye JobController.

* minor fix..

* fix test fail, remove debug logs.

* quick serialization fixes.

* fixes..

* sus

* partialing

* Update Content.Server/Station/Systems/StationJobsSystem.Roundstart.cs

Co-authored-by: Kara <lunarautomaton6@gmail.com>

* Use dirtying to avoid rebuilding the list 2,100 times.

* add a bajillion more lines of docs (mostly in AssignJobs so i don't ever forget how it works)

* Update Content.IntegrationTests/Tests/Station/StationJobsTest.cs

Co-authored-by: Kara <lunarautomaton6@gmail.com>

* Add the Mysteriously Missing Captain Check.

* Put maprender back the way it belongs.

* I love addressing reviews.

* Update Content.Server/Station/Systems/StationJobsSystem.cs

Co-authored-by: Kara <lunarautomaton6@gmail.com>

* doc cleanup.

* Fix bureaucratic error, add job slot tests.

* zero cost abstractions when

* cri

* saner error.

* Fix spawning failing certain tests due to gameticker not handling falliability correctly.
Can't fix this until I refactor the rest of spawning code.

* submodule gaming

* Packedenger.

* Documentation consistency.

Co-authored-by: Kara <lunarautomaton6@gmail.com>
2022-05-10 13:43:30 -05:00

149 lines
4.6 KiB
C#

using Content.Server.AI.EntitySystems;
using Content.Server.Station.Systems;
using Content.Shared.Movement.Components;
using Content.Shared.Roles;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.Server.AI.Components
{
[RegisterComponent]
[ComponentReference(typeof(IMobMoverComponent))]
[Virtual]
public class AiControllerComponent : Component, IMobMoverComponent, IMoverComponent
{
[DataField("logic")] private float _visionRadius = 8.0f;
public bool CanMove { get; set; } = true;
// TODO: Need to ECS a lot more of the AI first before we can ECS this
/// <summary>
/// Whether the AI is actively iterated.
/// </summary>
public bool Awake
{
get => _awake;
set
{
if (_awake == value) return;
_awake = value;
if (_awake)
EntitySystem.Get<NPCSystem>().WakeNPC(this);
else
EntitySystem.Get<NPCSystem>().SleepNPC(this);
}
}
[DataField("awake")]
private bool _awake = true;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("startingGear")]
public string? StartingGearPrototype { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public float VisionRadius
{
get => _visionRadius;
set => _visionRadius = value;
}
/// <inheritdoc />
protected override void Initialize()
{
base.Initialize();
// This component requires a physics component.
Owner.EnsureComponent<PhysicsComponent>();
}
protected override void Startup()
{
base.Startup();
if (StartingGearPrototype != null)
{
var stationSpawning = EntitySystem.Get<StationSpawningSystem>();
var protoManager = IoCManager.Resolve<IPrototypeManager>();
var startingGear = protoManager.Index<StartingGearPrototype>(StartingGearPrototype);
stationSpawning.EquipStartingGear(Owner, startingGear, null);
}
}
/// <summary>
/// Movement speed (m/s) that the entity walks, after modifiers
/// </summary>
[ViewVariables]
public float CurrentWalkSpeed
{
get
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out MovementSpeedModifierComponent? component))
{
return component.CurrentWalkSpeed;
}
return MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
}
}
/// <summary>
/// Movement speed (m/s) that the entity walks, after modifiers
/// </summary>
[ViewVariables]
public float CurrentSprintSpeed
{
get
{
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out MovementSpeedModifierComponent? component))
{
return component.CurrentSprintSpeed;
}
return MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
}
}
public Angle LastGridAngle { get => Angle.Zero; set {} }
/// <inheritdoc />
[ViewVariables(VVAccess.ReadWrite)]
public float PushStrength { get; set; } = IMobMoverComponent.PushStrengthDefault;
[ViewVariables(VVAccess.ReadWrite)]
public float WeightlessStrength { get; set; } = IMobMoverComponent.WeightlessStrengthDefault;
/// <inheritdoc />
[ViewVariables(VVAccess.ReadWrite)]
public float GrabRange { get; set; } = IMobMoverComponent.GrabRangeDefault;
/// <summary>
/// Is the entity Sprinting (running)?
/// </summary>
[ViewVariables]
public bool Sprinting { get; } = true;
/// <summary>
/// Calculated linear velocity direction of the entity.
/// </summary>
[ViewVariables]
public Vector2 VelocityDir { get; set; }
(Vector2 walking, Vector2 sprinting) IMoverComponent.VelocityDir =>
Sprinting ? (Vector2.Zero, VelocityDir) : (VelocityDir, Vector2.Zero);
public EntityCoordinates LastPosition { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public float StepSoundDistance { get; set; }
public void SetVelocityDirection(Direction direction, ushort subTick, bool enabled) { }
public void SetSprinting(ushort subTick, bool walking) { }
public virtual void Update(float frameTime) {}
}
}