diff --git a/Content.Client/_FTL/FtlPoints/StarmapControl.cs b/Content.Client/_FTL/FtlPoints/StarmapControl.cs index 23dcf66941..d7ef37bc7f 100644 --- a/Content.Client/_FTL/FtlPoints/StarmapControl.cs +++ b/Content.Client/_FTL/FtlPoints/StarmapControl.cs @@ -1,9 +1,11 @@ using System.Numerics; using Content.Shared._FTL.FtlPoints; +using Content.Shared.Input; using Robust.Client.Graphics; using Robust.Client.Input; using Robust.Client.ResourceManagement; using Robust.Client.UserInterface; +using Robust.Shared.Input; using YamlDotNet.Core.Tokens; namespace Content.Client._FTL.FtlPoints; @@ -107,7 +109,7 @@ protected override void Draw(DrawingHandleScreen handle) handle.DrawCircle(uiPosition, radius, color); // after circle rendering incase we wish to show text/etc - if (hovered) + if (hovered && _inputManager.IsKeyDown(Keyboard.Key.MouseLeft)) { handle.DrawString(_font, uiPosition + new Vector2(10, 0), name); diff --git a/Content.Server/_FTL/AutomatedShip/Systems/AutomatedShipSystem.Combat.cs b/Content.Server/_FTL/AutomatedShip/Systems/AutomatedShipSystem.Combat.cs index f2c7ff7903..3c269249a6 100644 --- a/Content.Server/_FTL/AutomatedShip/Systems/AutomatedShipSystem.Combat.cs +++ b/Content.Server/_FTL/AutomatedShip/Systems/AutomatedShipSystem.Combat.cs @@ -61,19 +61,16 @@ private CombatResult PerformCombat( EntityUid targetShip ) { - Log.Debug("Les go!!1!!11"); // realistically this should factor in distance but ¯\_(ツ)_/¯ var weaponGroup = _random.Pick(GetWeaponGroupsOnGrid(entity)); // get gun, aim, and shoot at place if (!TryComp(weaponGroup, out var sourceComponent)) return CombatResult.ERROR; - Log.Debug("got device!!"); // get a list of prio entities and select one var prioEnts = GetPriorityEntities(targetShip); if (prioEnts.Count <= 0) return CombatResult.NOPRIOENT; - Log.Debug("there's more prioents!!!"); var prioEnt = _random.Pick(prioEnts); var prioTransform = Transform(prioEnt); diff --git a/Content.Server/_FTL/AutomatedShip/Systems/AutomatedShipSystem.cs b/Content.Server/_FTL/AutomatedShip/Systems/AutomatedShipSystem.cs index 57fe841601..334024770b 100644 --- a/Content.Server/_FTL/AutomatedShip/Systems/AutomatedShipSystem.cs +++ b/Content.Server/_FTL/AutomatedShip/Systems/AutomatedShipSystem.cs @@ -2,6 +2,7 @@ using Content.Server._FTL.AutomatedShip.Components; using Content.Server._FTL.ShipTracker.Components; using Content.Server.NPC.Systems; +using Content.Server.Shuttles.Components; using Content.Server.Weapons.Ranged.Systems; using Robust.Server.GameObjects; using Robust.Shared.Random; @@ -25,10 +26,10 @@ public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnInit); + SubscribeLocalEvent(OnStartup); } - private void OnInit(EntityUid uid, AutomatedShipComponent component, ComponentInit args) + private void OnStartup(EntityUid uid, AutomatedShipComponent component, ComponentStartup args) { EnsureComp(uid); UpdateName(uid, component); @@ -51,11 +52,6 @@ private void UpdateName(EntityUid uid, AutomatedShipComponent component) _metaDataSystem.SetEntityName(uid, tag + meta.EntityName); } - public void AutomatedShipJump() - { - // TODO: Make all ships jump to a random point in range - } - public override void Update(float frameTime) { base.Update(frameTime); @@ -111,7 +107,15 @@ public override void Update(float frameTime) Log.Debug("Lack of a hostile ship."); break; } - Log.Debug("Fihjying"); + + // var gyroscope = EntityQuery().Where(component => component.Item1.Type == ThrusterType.Angular && component.Item2.GridUid == entity ); + // + // if (gyroscope.Any()) + // { + // var angle = (_entityManager.GetCoordinates(xform.LocalPosition).ToMapPos(_entityManager, _transformSystem) - entityXform.MapPosition.Position).ToWorldAngle(); + // _transformSystem.SetWorldRotation(entity, angle); + // } + PerformCombat(entity, aiComponent, aiTrackerComponent, diff --git a/Content.Server/_FTL/AutomatedShip/Systems/WarpEveryTickSystem.cs b/Content.Server/_FTL/AutomatedShip/Systems/WarpEveryTickSystem.cs new file mode 100644 index 0000000000..8cb3262b96 --- /dev/null +++ b/Content.Server/_FTL/AutomatedShip/Systems/WarpEveryTickSystem.cs @@ -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 +{ + [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(mapUid)) + return; + + var shuttleComp = EnsureComp(uid); + _shuttleSystem.FTLTravel(uid, shuttleComp, mapUid); + } +} diff --git a/Content.Server/_FTL/FTLPoints/Prototypes/FtlPointPrototype.cs b/Content.Server/_FTL/FTLPoints/Prototypes/FtlPointPrototype.cs index fc79e09707..4982f5c154 100644 --- a/Content.Server/_FTL/FTLPoints/Prototypes/FtlPointPrototype.cs +++ b/Content.Server/_FTL/FTLPoints/Prototypes/FtlPointPrototype.cs @@ -28,4 +28,9 @@ public sealed class FtlPointPrototype : IPrototype /// FTL point effects. /// [DataField("effects")] public FtlPointEffect[] FtlPointEffects = default!; + + /// + /// Components for systems + /// + [DataField("components")] public ComponentRegistry? TickComponents = default!; } diff --git a/Content.Server/_FTL/FTLPoints/Systems/FtlPointsSystem.cs b/Content.Server/_FTL/FTLPoints/Systems/FtlPointsSystem.cs index 9a9afb1fb6..fe05bf56bd 100644 --- a/Content.Server/_FTL/FTLPoints/Systems/FtlPointsSystem.cs +++ b/Content.Server/_FTL/FTLPoints/Systems/FtlPointsSystem.cs @@ -16,6 +16,7 @@ using Robust.Shared.Map; using Robust.Shared.Prototypes; using Robust.Shared.Random; +using Robust.Shared.Serialization.Manager; namespace Content.Server._FTL.FTLPoints.Systems; @@ -32,6 +33,7 @@ public sealed partial class FtlPointsSystem : SharedFtlPointsSystem [Dependency] private readonly ShuttleConsoleSystem _consoleSystem = default!; [Dependency] private readonly UserInterfaceSystem _userInterface = default!; [Dependency] private readonly ShuttleSystem _shuttleSystem = default!; + [Dependency] private readonly ISerializationManager _serializationManager = default!; public override void Initialize() { @@ -41,6 +43,17 @@ public override void Initialize() SubscribeLocalEvent(OnWarpToStarMessage); } + /// + /// Generates a float within minimum and maximum, with a 50% chance of being negative. + /// + /// + /// + /// + private float GeneratePositionWithRandomRadius(float minRadius, float maxRadius) + { + return _random.NextFloat(minRadius, maxRadius) * (_random.Prob(0.5f) ? -1 : 1); + } + /// /// Generates a random sector. /// @@ -76,8 +89,8 @@ public MapId GenerateSector(int maxStars) var mapId = GeneratePoint(prototype); var mapUid = _mapManager.GetMapEntityId(mapId); var position = new Vector2( - origin.X + _random.NextFloat(-10, 10), - origin.Y + _random.NextFloat(-10, 10) + origin.X + GeneratePositionWithRandomRadius(3, 10), + origin.Y + GeneratePositionWithRandomRadius(3, 10) ); TryAddPoint(mapId, position, MetaData(mapUid).EntityName); latestGeneration.Add(position); @@ -86,6 +99,21 @@ public MapId GenerateSector(int maxStars) } } + for (var i = 0; i < 3; i++) + { + var origin = _random.Pick(latestGeneration); + var prototype = _prototypeManager.Index("WarpPoint"); + var mapId = GeneratePoint(prototype); + var mapUid = _mapManager.GetMapEntityId(mapId); + var position = new Vector2( + origin.X + GeneratePositionWithRandomRadius(5, 7), + origin.Y + GeneratePositionWithRandomRadius(5, 7) + ); + TryAddPoint(mapId, position, MetaData(mapUid).EntityName); + latestGeneration.Add(position); + starsCreated++; + } + Log.Debug("Generated a brand new sector."); return centerStation; @@ -145,6 +173,20 @@ public MapId GeneratePoint(FtlPointPrototype prototype) } } + // Add all components required by the prototype + if (prototype.TickComponents == null) + return mapId; + + foreach (var entry in prototype.TickComponents.Values) + { + if (HasComp(mapUid, entry.Component.GetType())) + continue; + + var comp = (Component) _serializationManager.CreateCopy(entry.Component, notNullableOverride: true); + comp.Owner = mapUid; + EntityManager.AddComponent(mapUid, comp); + } + return mapId; } } diff --git a/Content.Server/_FTL/FTLPoints/Tick/AvoidStar/AvoidStarComponent.cs b/Content.Server/_FTL/FTLPoints/Tick/AvoidStar/AvoidStarComponent.cs new file mode 100644 index 0000000000..0d219755ce --- /dev/null +++ b/Content.Server/_FTL/FTLPoints/Tick/AvoidStar/AvoidStarComponent.cs @@ -0,0 +1,10 @@ +namespace Content.Server._FTL.FTLPoints.Tick.AvoidStar; + +/// +/// This is used for disallowing ships to visit the selected star +/// +[RegisterComponent] +public sealed partial class AvoidStarComponent : Component +{ + +} diff --git a/Content.Server/_FTL/FTLPoints/Tick/Factory/FactoryTickComponent.cs b/Content.Server/_FTL/FTLPoints/Tick/Factory/FactoryTickComponent.cs new file mode 100644 index 0000000000..f12060193c --- /dev/null +++ b/Content.Server/_FTL/FTLPoints/Tick/Factory/FactoryTickComponent.cs @@ -0,0 +1,13 @@ +using Robust.Shared.Utility; + +namespace Content.Server._FTL.FTLPoints.Tick.Factory; + +/// +/// This is used for tracking the ResPaths to maps that we would like to spawn. +/// +[RegisterComponent] +public sealed partial class FactoryTickComponent : Component +{ + [DataField("mapPaths", required: true)] + public List MapPaths { set; get; } = new(); +} diff --git a/Content.Server/_FTL/FTLPoints/Tick/Factory/FactoryTickSystem.cs b/Content.Server/_FTL/FTLPoints/Tick/Factory/FactoryTickSystem.cs new file mode 100644 index 0000000000..1e666097dd --- /dev/null +++ b/Content.Server/_FTL/FTLPoints/Tick/Factory/FactoryTickSystem.cs @@ -0,0 +1,26 @@ +using Robust.Server.GameObjects; +using Robust.Shared.Map; +using Robust.Shared.Random; + +namespace Content.Server._FTL.FTLPoints.Tick.Factory; + +/// +/// This system spawns ships every tick. +/// +public sealed class FactoryTickSystem : StarmapTickSystem +{ + [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!"); + } + } +} diff --git a/Content.Server/_FTL/FTLPoints/Tick/StarmapTickSystem.cs b/Content.Server/_FTL/FTLPoints/Tick/StarmapTickSystem.cs new file mode 100644 index 0000000000..7f1dadfef8 --- /dev/null +++ b/Content.Server/_FTL/FTLPoints/Tick/StarmapTickSystem.cs @@ -0,0 +1,50 @@ +namespace Content.Server._FTL.FTLPoints.Tick; + +public abstract class StarmapTickSystem : EntitySystem where T : Component +{ + private float _timeSinceLastTick = 0f; // SIN + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(Added); + } + + /// + /// Called on entities when added + /// + private void Added(EntityUid uid, T component, ComponentInit args) + { + + } + + /// + /// Called on entities every tick + /// + protected virtual void Ticked(EntityUid uid, T component, float frameTime) + { + + } + + protected EntityQueryEnumerator QueryStars() + { + return EntityQueryEnumerator(); + } + + 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!"); + } +} diff --git a/Content.Server/_FTL/ShipTracker/Rules/GeneratePoints/GeneratePointsSystem.cs b/Content.Server/_FTL/ShipTracker/Rules/GeneratePoints/GeneratePointsSystem.cs index f6f38fb328..818d97a603 100644 --- a/Content.Server/_FTL/ShipTracker/Rules/GeneratePoints/GeneratePointsSystem.cs +++ b/Content.Server/_FTL/ShipTracker/Rules/GeneratePoints/GeneratePointsSystem.cs @@ -31,30 +31,32 @@ public override void Initialize() private void OnPlayerSpawnEvent(PlayerSpawningEvent ev) { - var component = EntityQuery().First(); - - if (component.Generated) - return; + var activeRules = QueryActiveRules(); + while (activeRules.MoveNext(out _, out var component, out _)) + { + if (component.Generated) + return; - if (!_configurationManager.GetCVar(CCVars.GenerateFTLPointsRoundstart)) - return; - var station = _pointsSystem.GenerateSector(40); + if (!_configurationManager.GetCVar(CCVars.GenerateFTLPointsRoundstart)) + return; + var station = _pointsSystem.GenerateSector(20); - if (ev.Station.HasValue) - { - if (TryComp(ev.Station.Value, out var stationDataComponent)) + if (ev.Station.HasValue) { - var grid = _stationSystem.GetLargestGrid(stationDataComponent); - if (grid.HasValue) + if (TryComp(ev.Station.Value, out var stationDataComponent)) { - var shuttle = EnsureComp(grid.Value); - _shuttleSystem.FTLTravel(grid.Value, shuttle, _mapManager.GetMapEntityId(station)); + var grid = _stationSystem.GetLargestGrid(stationDataComponent); + if (grid.HasValue) + { + var shuttle = EnsureComp(grid.Value); + _shuttleSystem.FTLTravel(grid.Value, shuttle, _mapManager.GetMapEntityId(station)); + } } } - } - component.Generated = true; + component.Generated = true; - Log.Info("Finished generation of sector."); + Log.Info("Finished generation of sector."); + } } } diff --git a/Resources/Locale/en-US/_ftl/starmap.ftl b/Resources/Locale/en-US/_ftl/starmap.ftl index 63b4ba81d5..54f1c45b1a 100644 --- a/Resources/Locale/en-US/_ftl/starmap.ftl +++ b/Resources/Locale/en-US/_ftl/starmap.ftl @@ -13,12 +13,11 @@ ship-inbound-message = Alert! Sensor array output have detected {$amount -> ship-ftl-tag-star = STAR ship-ftl-tag-base = BASE -ship-ftl-tag-danger = !!!! -ship-ftl-tag-unknown = ???? ship-ftl-tag-planet = PLNT -ship-ftl-tag-moon = MOON ship-ftl-tag-ruin = RUIN ship-ftl-tag-yard = YARD +ship-ftl-tag-gateway = GATE +ship-ftl-tag-warp = WARP ship-ftl-tag-asteroid = ROID ship-ftl-tag-oor = OUT OF RANGE diff --git a/Resources/Prototypes/_FTL/ftl_points.yml b/Resources/Prototypes/_FTL/ftl_points.yml index 51ad56c4f7..dd2b6043c6 100644 --- a/Resources/Prototypes/_FTL/ftl_points.yml +++ b/Resources/Prototypes/_FTL/ftl_points.yml @@ -3,10 +3,12 @@ tag: ship-ftl-tag-base effects: - !type:SpawnStationEffect + components: + - type: AvoidStar - type: ftlPoint id: LoDangerPoint - tag: ship-ftl-tag-unknown + tag: ship-ftl-tag-star probability: 0.6 effects: - !type:SpawnMapEffect @@ -19,7 +21,7 @@ - type: ftlPoint id: HiDangerPoint - tag: ship-ftl-tag-unknown + tag: ship-ftl-tag-star probability: 0.9 effects: - !type:SpawnMapEffect @@ -33,7 +35,7 @@ - type: ftlPoint id: ConfDangerPoint - tag: ship-ftl-tag-danger + tag: ship-ftl-tag-star effects: - !type:SpawnMapEffect mapPaths: @@ -72,16 +74,8 @@ - Blood - !type:SpawnDungeonEffect range: 75 - -- type: ftlPoint - id: MoonPoint - tag: ship-ftl-tag-moon - effects: - - !type:ToPlanetEffect - biomeTemplates: - - Caves - - !type:SpawnDungeonEffect - range: 100 + components: + - type: AvoidStar - type: ftlPoint id: AsteroidPoint @@ -104,12 +98,40 @@ tag: ship-ftl-tag-ruin effects: - !type:SpawnDungeonEffect + components: + - type: AvoidStar - type: ftlPoint id: NoDangerPoint tag: ship-ftl-tag-unknown effects: [] +- type: ftlPoint + id: WarpPoint + tag: ship-ftl-tag-warp + effects: [] + components: + - type: AvoidStar + - type: FactoryTick + mapPaths: + - /Maps/_FTL/ancient/easy-drone.yml + - /Maps/_FTL/ancient/tough-drone.yml + - /Maps/_FTL/independent/orb.yml + - /Maps/_FTL/independent/pod.yml + - /Maps/_FTL/independent/rod.yml + - /Maps/_FTL/independent/hostile-escape-pod.yml + - /Maps/_FTL/independent/cargo-vessel.yml + - /Maps/_FTL/incsek/bomber.yml + - /Maps/_FTL/coregov/retribution.yml + - /Maps/_FTL/fsc/fighter.yml + +#- type: ftlPoint +# id: ShipyardPoint +# tag: ship-ftl-tag-yard +# effects: [] +# components: +# - type: FactoryTick + - type: weightedRandom id: FTLPoints weights: @@ -118,5 +140,4 @@ HiDangerPoint: 3 NoDangerPoint: 1 StarPoint: 1 - MoonPoint: 0.25 RuinPoint: 0.15