-
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.
- Loading branch information
1 parent
81132d3
commit 642d3c3
Showing
13 changed files
with
258 additions
and
48 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
39 changes: 39 additions & 0 deletions
39
Content.Server/_FTL/AutomatedShip/Systems/WarpEveryTickSystem.cs
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,39 @@ | ||
using Content.Server._FTL.AutomatedShip.Components; | ||
using Content.Server._FTL.FTLPoints.Systems; | ||
using Content.Server._FTL.FTLPoints.Tick; | ||
using Content.Server._FTL.FTLPoints.Tick.AvoidStar; | ||
using Content.Server.Shuttles.Components; | ||
using Content.Server.Shuttles.Systems; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Random; | ||
|
||
namespace Content.Server._FTL.AutomatedShip.Systems; | ||
|
||
public sealed class WarpEveryTickSystem : StarmapTickSystem<AutomatedShipComponent> | ||
{ | ||
[Dependency] private readonly FtlPointsSystem _ftlPointsSystem = default!; | ||
[Dependency] private readonly ShuttleSystem _shuttleSystem = default!; | ||
[Dependency] private readonly IMapManager _mapManager = default!; | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
|
||
protected override void Ticked(EntityUid uid, AutomatedShipComponent component, float frameTime) | ||
{ | ||
base.Ticked(uid, component, frameTime); | ||
|
||
if (component.AiState == AutomatedShipComponent.AiStates.Fighting) | ||
return; // can't warp mid-fight | ||
|
||
var star = _ftlPointsSystem.GetStarWithMapId(Transform(uid).MapID); | ||
if (!star.HasValue) | ||
return; | ||
var stars = _ftlPointsSystem.GetStarsInRange(star.Value.Position, 10); | ||
var destination = _random.Pick(stars); | ||
var mapUid = _mapManager.GetMapEntityId(destination.Map); | ||
|
||
if (HasComp<AvoidStarComponent>(mapUid)) | ||
return; | ||
|
||
var shuttleComp = EnsureComp<ShuttleComponent>(uid); | ||
_shuttleSystem.FTLTravel(uid, shuttleComp, mapUid); | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
Content.Server/_FTL/FTLPoints/Tick/AvoidStar/AvoidStarComponent.cs
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,10 @@ | ||
namespace Content.Server._FTL.FTLPoints.Tick.AvoidStar; | ||
|
||
/// <summary> | ||
/// This is used for disallowing ships to visit the selected star | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class AvoidStarComponent : Component | ||
{ | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
Content.Server/_FTL/FTLPoints/Tick/Factory/FactoryTickComponent.cs
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,13 @@ | ||
using Robust.Shared.Utility; | ||
|
||
namespace Content.Server._FTL.FTLPoints.Tick.Factory; | ||
|
||
/// <summary> | ||
/// This is used for tracking the ResPaths to maps that we would like to spawn. | ||
/// </summary> | ||
[RegisterComponent] | ||
public sealed partial class FactoryTickComponent : Component | ||
{ | ||
[DataField("mapPaths", required: true)] | ||
public List<ResPath> MapPaths { set; get; } = new(); | ||
} |
26 changes: 26 additions & 0 deletions
26
Content.Server/_FTL/FTLPoints/Tick/Factory/FactoryTickSystem.cs
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,26 @@ | ||
using Robust.Server.GameObjects; | ||
using Robust.Shared.Map; | ||
using Robust.Shared.Random; | ||
|
||
namespace Content.Server._FTL.FTLPoints.Tick.Factory; | ||
|
||
/// <summary> | ||
/// This system spawns ships every tick. | ||
/// </summary> | ||
public sealed class FactoryTickSystem : StarmapTickSystem<FactoryTickComponent> | ||
{ | ||
[Dependency] private readonly IRobustRandom _random = default!; | ||
[Dependency] private readonly MapLoaderSystem _mapLoader = default!; | ||
|
||
protected override void Ticked(EntityUid uid, FactoryTickComponent component, float frameTime) | ||
{ | ||
base.Ticked(uid, component, frameTime); | ||
|
||
var transform = Transform(uid); | ||
|
||
if (_mapLoader.TryLoad(transform.MapID, _random.Pick(component.MapPaths).ToString(), out _)) | ||
{ | ||
Log.Debug("Created a new ship!"); | ||
} | ||
} | ||
} |
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,50 @@ | ||
namespace Content.Server._FTL.FTLPoints.Tick; | ||
|
||
public abstract class StarmapTickSystem<T> : EntitySystem where T : Component | ||
{ | ||
private float _timeSinceLastTick = 0f; // SIN | ||
|
||
public override void Initialize() | ||
{ | ||
base.Initialize(); | ||
|
||
SubscribeLocalEvent<T, ComponentInit>(Added); | ||
} | ||
|
||
/// <summary> | ||
/// Called on entities when added | ||
/// </summary> | ||
private void Added(EntityUid uid, T component, ComponentInit args) | ||
{ | ||
|
||
} | ||
|
||
/// <summary> | ||
/// Called on entities every tick | ||
/// </summary> | ||
protected virtual void Ticked(EntityUid uid, T component, float frameTime) | ||
{ | ||
|
||
} | ||
|
||
protected EntityQueryEnumerator<T> QueryStars() | ||
{ | ||
return EntityQueryEnumerator<T>(); | ||
} | ||
|
||
public override void Update(float frameTime) | ||
{ | ||
base.Update(frameTime); | ||
|
||
_timeSinceLastTick += frameTime; | ||
if (!(_timeSinceLastTick >= 10)) | ||
return; | ||
_timeSinceLastTick = 0; | ||
var stars = QueryStars(); | ||
while (stars.MoveNext(out var uid, out var component)) | ||
{ | ||
Ticked(uid, component, frameTime); | ||
} | ||
Log.Info("Tick!"); | ||
} | ||
} |
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.