SubscribeLocalEvent<ThrusterComponent, ComponentShutdown>(OnThrusterShutdown);
SubscribeLocalEvent<ThrusterComponent, PowerChangedEvent>(OnPowerChange);
SubscribeLocalEvent<ThrusterComponent, AnchorStateChangedEvent>(OnAnchorChange);
- SubscribeLocalEvent<ThrusterComponent, ReAnchorEvent>(OnThrusterReAnchor);
SubscribeLocalEvent<ThrusterComponent, MoveEvent>(OnRotate);
SubscribeLocalEvent<ThrusterComponent, IsHotEvent>(OnIsHotEvent);
SubscribeLocalEvent<ThrusterComponent, StartCollideEvent>(OnStartCollide);
private void OnRotate(EntityUid uid, ThrusterComponent component, ref MoveEvent args)
{
// TODO: Disable visualizer for old direction
+ // TODO: Don't make them rotatable and make it require anchoring.
if (!component.Enabled ||
- component.Type != ThrusterType.Linear ||
!EntityManager.TryGetComponent(uid, out TransformComponent? xform) ||
!EntityManager.TryGetComponent(xform.GridUid, out ShuttleComponent? shuttleComponent))
{
// Disable if new tile invalid
if (component.IsOn && !canEnable)
{
- DisableThruster(uid, component, xform, args.OldRotation);
+ DisableThruster(uid, component, args.OldPosition.EntityId, xform, args.OldRotation);
return;
}
var oldDirection = (int) args.OldRotation.GetCardinalDir() / 2;
var direction = (int) args.NewRotation.GetCardinalDir() / 2;
+ var oldShuttleComponent = shuttleComponent;
- shuttleComponent.LinearThrust[oldDirection] -= component.Thrust;
- shuttleComponent.BaseLinearThrust[oldDirection] -= component.BaseThrust;
- DebugTools.Assert(shuttleComponent.LinearThrusters[oldDirection].Contains(uid));
- shuttleComponent.LinearThrusters[oldDirection].Remove(uid);
+ if (args.ParentChanged)
+ {
+ oldShuttleComponent = Comp<ShuttleComponent>(args.OldPosition.EntityId);
+
+ // If no parent change doesn't matter for angular.
+ if (component.Type == ThrusterType.Angular)
+ {
+ oldShuttleComponent.AngularThrust -= component.Thrust;
+ DebugTools.Assert(oldShuttleComponent.AngularThrusters.Contains(uid));
+ oldShuttleComponent.AngularThrusters.Remove(uid);
+
+ shuttleComponent.AngularThrust += component.Thrust;
+ DebugTools.Assert(!shuttleComponent.AngularThrusters.Contains(uid));
+ shuttleComponent.AngularThrusters.Add(uid);
+ return;
+ }
+ }
- shuttleComponent.LinearThrust[direction] += component.Thrust;
- shuttleComponent.BaseLinearThrust[direction] += component.BaseThrust;
- DebugTools.Assert(!shuttleComponent.LinearThrusters[direction].Contains(uid));
- shuttleComponent.LinearThrusters[direction].Add(uid);
+ if (component.Type == ThrusterType.Linear)
+ {
+ oldShuttleComponent.LinearThrust[oldDirection] -= component.Thrust;
+ oldShuttleComponent.BaseLinearThrust[oldDirection] -= component.BaseThrust;
+ DebugTools.Assert(oldShuttleComponent.LinearThrusters[oldDirection].Contains(uid));
+ oldShuttleComponent.LinearThrusters[oldDirection].Remove(uid);
+
+ shuttleComponent.LinearThrust[direction] += component.Thrust;
+ shuttleComponent.BaseLinearThrust[direction] += component.BaseThrust;
+ DebugTools.Assert(!shuttleComponent.LinearThrusters[direction].Contains(uid));
+ shuttleComponent.LinearThrusters[direction].Add(uid);
+ }
}
private void OnAnchorChange(EntityUid uid, ThrusterComponent component, ref AnchorStateChangedEvent args)
}
}
- private void OnThrusterReAnchor(EntityUid uid, ThrusterComponent component, ref ReAnchorEvent args)
- {
- DisableThruster(uid, component, args.OldGrid);
-
- if (CanEnable(uid, component))
- EnableThruster(uid, component);
- }
-
private void OnThrusterInit(EntityUid uid, ThrusterComponent component, ComponentInit args)
{
_ambient.SetAmbience(uid, false);