Skip to content

Commit

Permalink
more and more progress...
Browse files Browse the repository at this point in the history
  • Loading branch information
Just-a-Unity-Dev committed Nov 10, 2023
1 parent 81132d3 commit 642d3c3
Show file tree
Hide file tree
Showing 13 changed files with 258 additions and 48 deletions.
4 changes: 3 additions & 1 deletion Content.Client/_FTL/FtlPoints/StarmapControl.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DeviceLinkSourceComponent>(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);

Expand Down
20 changes: 12 additions & 8 deletions Content.Server/_FTL/AutomatedShip/Systems/AutomatedShipSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,10 +26,10 @@ public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<AutomatedShipComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<AutomatedShipComponent, ComponentStartup>(OnStartup);
}

private void OnInit(EntityUid uid, AutomatedShipComponent component, ComponentInit args)
private void OnStartup(EntityUid uid, AutomatedShipComponent component, ComponentStartup args)
{
EnsureComp<ActiveAutomatedShipComponent>(uid);
UpdateName(uid, component);
Expand All @@ -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);
Expand Down Expand Up @@ -111,7 +107,15 @@ public override void Update(float frameTime)
Log.Debug("Lack of a hostile ship.");
break;
}
Log.Debug("Fihjying");

// var gyroscope = EntityQuery<ThrusterComponent, TransformComponent>().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,
Expand Down
39 changes: 39 additions & 0 deletions Content.Server/_FTL/AutomatedShip/Systems/WarpEveryTickSystem.cs
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);
}
}
5 changes: 5 additions & 0 deletions Content.Server/_FTL/FTLPoints/Prototypes/FtlPointPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public sealed class FtlPointPrototype : IPrototype
/// FTL point effects.
/// </summary>
[DataField("effects")] public FtlPointEffect[] FtlPointEffects = default!;

/// <summary>
/// Components for systems
/// </summary>
[DataField("components")] public ComponentRegistry? TickComponents = default!;
}
46 changes: 44 additions & 2 deletions Content.Server/_FTL/FTLPoints/Systems/FtlPointsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()
{
Expand All @@ -41,6 +43,17 @@ public override void Initialize()
SubscribeLocalEvent<StarmapConsoleComponent, WarpToStarMessage>(OnWarpToStarMessage);
}

/// <summary>
/// Generates a float within minimum and maximum, with a 50% chance of being negative.
/// </summary>
/// <param name="minRadius"></param>
/// <param name="maxRadius"></param>
/// <returns></returns>
private float GeneratePositionWithRandomRadius(float minRadius, float maxRadius)
{
return _random.NextFloat(minRadius, maxRadius) * (_random.Prob(0.5f) ? -1 : 1);
}

/// <summary>
/// Generates a random sector.
/// </summary>
Expand Down Expand Up @@ -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);
Expand All @@ -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<FtlPointPrototype>("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;
Expand Down Expand Up @@ -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;
}
}
10 changes: 10 additions & 0 deletions Content.Server/_FTL/FTLPoints/Tick/AvoidStar/AvoidStarComponent.cs
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 Content.Server/_FTL/FTLPoints/Tick/Factory/FactoryTickComponent.cs
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 Content.Server/_FTL/FTLPoints/Tick/Factory/FactoryTickSystem.cs
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!");
}
}
}
50 changes: 50 additions & 0 deletions Content.Server/_FTL/FTLPoints/Tick/StarmapTickSystem.cs
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!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,32 @@ public override void Initialize()

private void OnPlayerSpawnEvent(PlayerSpawningEvent ev)
{
var component = EntityQuery<GeneratePointsComponent>().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<StationDataComponent>(ev.Station.Value, out var stationDataComponent))
if (ev.Station.HasValue)
{
var grid = _stationSystem.GetLargestGrid(stationDataComponent);
if (grid.HasValue)
if (TryComp<StationDataComponent>(ev.Station.Value, out var stationDataComponent))
{
var shuttle = EnsureComp<ShuttleComponent>(grid.Value);
_shuttleSystem.FTLTravel(grid.Value, shuttle, _mapManager.GetMapEntityId(station));
var grid = _stationSystem.GetLargestGrid(stationDataComponent);
if (grid.HasValue)
{
var shuttle = EnsureComp<ShuttleComponent>(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.");
}
}
}
5 changes: 2 additions & 3 deletions Resources/Locale/en-US/_ftl/starmap.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 642d3c3

Please sign in to comment.