-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Missiles minimum viable product (#313)
* Heat seeking missiles * end me * Point defense is successful! * Fix YML linter * Heatseeking improvements * Missile tweaks * appease the linter * Advanced targeting * datafield that !
- Loading branch information
1 parent
7c1f110
commit e41b594
Showing
17 changed files
with
387 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
namespace Content.Server._FTL.HeatSeeking; | ||
|
||
/// <summary> | ||
/// This is used for... | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class HeatSeekingComponent : Component | ||
{ | ||
/// <summary> | ||
/// How far does this fire a raycast onto? | ||
/// </summary> | ||
[DataField("seekRange")] | ||
public float DefaultSeekingRange = 100f; | ||
|
||
/// <summary> | ||
/// Should this lock onto ONE entity only? | ||
/// </summary> | ||
[DataField] | ||
public bool LockedIn; | ||
|
||
[DataField] | ||
public Angle WeaponArc = Angle.FromDegrees(360); | ||
|
||
/// <summary> | ||
/// If null it will instantly turn. | ||
/// </summary> | ||
[DataField, ViewVariables(VVAccess.ReadWrite)] | ||
public Angle? RotationSpeed; | ||
|
||
/// <summary> | ||
/// What is this entity targeting? | ||
/// </summary> | ||
[DataField] | ||
public EntityUid? TargetEntity; | ||
|
||
/// <summary> | ||
/// How fast does the missile accelerate? | ||
/// </summary> | ||
[DataField] | ||
public float Acceleration = 10f; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
using System.Linq; | ||
using System.Numerics; | ||
using Content.Shared.Interaction; | ||
using Content.Shared.Physics; | ||
using Robust.Server.GameObjects; | ||
using Robust.Shared.Physics; | ||
using Robust.Shared.Random; | ||
|
||
namespace Content.Server._FTL.HeatSeeking; | ||
|
||
/// <summary> | ||
/// This handles... | ||
/// </summary> | ||
public sealed class HeatSeekingSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly SharedTransformSystem _transform = default!; | ||
[Dependency] private readonly RotateToFaceSystem _rotate = default!; | ||
[Dependency] private readonly PhysicsSystem _physics = default!; | ||
|
||
public override void Update(float frameTime) | ||
{ | ||
base.Update(frameTime); | ||
|
||
var query = EntityQueryEnumerator<HeatSeekingComponent, TransformComponent>(); | ||
while (query.MoveNext(out var uid, out var comp, out var xform)) | ||
{ | ||
if (comp.TargetEntity.HasValue) | ||
{ | ||
var entXform = Transform(comp.TargetEntity.Value); | ||
var angle = ( | ||
_transform.ToMapCoordinates(xform.Coordinates).Position - | ||
_transform.ToMapCoordinates(entXform.Coordinates).Position | ||
).ToWorldAngle(); | ||
|
||
_transform.SetLocalRotationNoLerp(uid, angle, xform); | ||
|
||
if (!_rotate.TryRotateTo(uid, angle, frameTime, comp.WeaponArc, comp.RotationSpeed?.Theta ?? double.MaxValue, xform)) | ||
{ | ||
continue; | ||
} | ||
|
||
_physics.ApplyForce(uid, xform.LocalRotation.RotateVec(new Vector2(0, 1)) * comp.Acceleration); | ||
return; | ||
} | ||
|
||
var ray = new CollisionRay(_transform.GetMapCoordinates(uid, xform).Position, | ||
xform.LocalRotation.ToWorldVec(), | ||
(int) (CollisionGroup.Impassable | CollisionGroup.BulletImpassable)); | ||
var results = _physics.IntersectRay(xform.MapID, ray, comp.DefaultSeekingRange, uid).ToList(); | ||
if (results.Count <= 0) | ||
return; // nothing to heatseek ykwim | ||
|
||
if (comp is { LockedIn: true, TargetEntity: not null }) | ||
return; // Don't reassign target entity if we have one AND we have the LockedIn property | ||
|
||
comp.TargetEntity = results[0].HitEntity; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.