Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Content.Client/Salvage/UI/SalvageMagnetBoundUserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ protected override void UpdateState(BoundUserInterfaceState state)

option.AddContent(salvContainer);
break;
// Macro start - Adding RuinOffering to the salvage system
case RuinOffering ruin:
option.Title = Loc.GetString("salvage-magnet-ruin");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asking someone smarter than me. how do we feel about hardcoded string here. is it worth

break;
// Macro end
default:
throw new ArgumentOutOfRangeException();
}
Expand Down
114 changes: 110 additions & 4 deletions Content.Server/Salvage/SalvageSystem.Magnet.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
using System.Linq;
using System.Numerics;
using System.Threading.Tasks;
using Content.Server.Decals; // Macro
using Content.Server.Salvage.Magnet;
using Content.Shared.Damage; // Macro
using Content.Shared.Damage.Components; // Macro
using Content.Shared.Damage.Prototypes; // Macro
using Content.Shared.Damage.Systems; // Macro
using Content.Shared.FixedPoint; // Macro
using Content.Shared.Maps; // Macro
using Content.Shared.Mobs.Components;
using Content.Shared.Parallax.Biomes; // Macro
using Content.Shared.Physics; // Macro
using Content.Shared.Procedural;
using Content.Shared.Radio;
using Content.Shared.Salvage; // Macro
using Content.Shared.Salvage.Magnet;
using Robust.Shared.Exceptions;
using Robust.Shared.Map;
using Robust.Shared.Map.Components; //Macro
using Robust.Shared.Prototypes;

namespace Content.Server.Salvage;

public sealed partial class SalvageSystem
{
[Dependency] private readonly DecalSystem _decals = default!;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment & sort

[Dependency] private readonly IRuntimeLog _runtimeLog = default!;
[Dependency] private readonly DamageableSystem _damageable = default!; // Macro
[Dependency] private readonly SalvageRuinGeneratorSystem _ruinGenerator = default!; // Macro

private static readonly ProtoId<RadioChannelPrototype> MagnetChannel = "Supply";
private static readonly ProtoId<DamageTypePrototype> StructuralDamageType = "Structural";
private static readonly ProtoId<BiomeTemplatePrototype> SpaceRuinBiome = "SpaceRuin";

private EntityQuery<SalvageMobRestrictionsComponent> _salvMobQuery;
private EntityQuery<MobStateComponent> _mobStateQuery;
Expand Down Expand Up @@ -305,14 +321,63 @@ private async Task TakeMagnetOffer(Entity<SalvageMagnetDataComponent> data, int
break;
case SalvageOffering wreck:
var salvageProto = wreck.SalvageMap;

// Macro Start - Adding RuinOffering to the salvage system
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can probably move comment here down to above the case statement and just add a comment to 329 adding .Owner?

if (!_loader.TryLoadGrid(salvMapXform.MapID, salvageProto.MapPath, out _))
{
Report(magnet, MagnetChannel, "salvage-system-announcement-spawn-debris-disintegrated");
Report(magnet.Owner, MagnetChannel, "salvage-system-announcement-spawn-debris-disintegrated");
_mapSystem.DeleteMap(salvMapXform.MapID);
return;
}

break;
case RuinOffering ruin:
var ruinConfigId = new ProtoId<SalvageMagnetRuinConfigPrototype>("Default");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i imagine that breaking up SalvageRuinGenerator might also give the ability to chunk down the code here somewhat

_prototypeManager.TryIndex<Content.Shared.Salvage.SalvageMagnetRuinConfigPrototype>(ruinConfigId, out var ruinConfig);

var ruinResult = _ruinGenerator.GenerateRuin(ruin.RuinMap.MapPath, seed, ruinConfig);
if (ruinResult == null)
{
Report(magnet.Owner, MagnetChannel, "salvage-system-announcement-spawn-no-debris-available");
_mapSystem.DeleteMap(salvMapXform.MapID);
return;
}

var ruinGrid = _mapManager.CreateGridEntity(salvMap);
_mapSystem.SetTiles(ruinGrid.Owner, ruinGrid.Comp, ruinResult.FloorTiles);

foreach (var (wallPos, wallProto) in ruinResult.WallEntities)
{
var wallEntity = SpawnAtPosition(wallProto, new EntityCoordinates(ruinGrid.Owner, wallPos));
var wallXform = Transform(wallEntity);
if (!wallXform.Anchored)
_transform.AnchorEntity((wallEntity, wallXform), (ruinGrid.Owner, ruinGrid.Comp), wallPos);
}

var windowDamageChance = ruinResult.Config?.WindowDamageChance ?? 0.0f;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make eveything to do with window damage its own helper method

var windowRand = new System.Random(seed);
foreach (var (windowPos, windowProto, windowRotation) in ruinResult.WindowEntities)
{
var tileRef = _mapSystem.GetTileRef(ruinGrid.Owner, ruinGrid.Comp, windowPos);
if (tileRef.Tile.IsEmpty)
continue;

var windowEntity = SpawnAttachedTo(windowProto, new EntityCoordinates(ruinGrid.Owner, windowPos), rotation: windowRotation);
var windowXform = Transform(windowEntity);
if (!windowXform.Anchored)
_transform.AnchorEntity((windowEntity, windowXform), (ruinGrid.Owner, ruinGrid.Comp), windowPos);

if (windowDamageChance > 0.0f && windowRand.NextSingle() < windowDamageChance &&
TryComp<DamageableComponent>(windowEntity, out _))
{
var damage = new DamageSpecifier(
_prototypeManager.Index(StructuralDamageType),
FixedPoint2.New(25));
_damageable.TryChangeDamage(windowEntity, damage);
}
}

SpawnRuinBiomeEntities(ruinGrid.Owner, ruinGrid.Comp, ruinResult, seed);

break;
default:
throw new ArgumentOutOfRangeException();
Expand All @@ -338,13 +403,13 @@ private async Task TakeMagnetOffer(Entity<SalvageMagnetDataComponent> data, int
bounds = bounds?.Union(childAABB) ?? childAABB;

// Update mass scanner names as relevant.
if (offering is AsteroidOffering or DebrisOffering)
if (offering is AsteroidOffering or DebrisOffering or RuinOffering)
{
_metaData.SetEntityName(mapChild, Loc.GetString("salvage-asteroid-name"));
_gravity.EnableGravity(mapChild);
}
}

// Macro end
Comment on lines -341 to +414
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can just move macro comment up and add comment to ruinoffering, since lots of this code isnt getting touched

var magnetXform = _xformQuery.GetComponent(magnet.Owner);
var magnetGridUid = magnetXform.GridUid;
var attachedBounds = new Box2Rotated();
Expand Down Expand Up @@ -418,7 +483,48 @@ private async Task TakeMagnetOffer(Entity<SalvageMagnetDataComponent> data, int

RaiseLocalEvent(ref active);
}
// Macro start - Adding mobs and loot to the salvage system via SpaceRuin biome template
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there not a way to piggyback off methods for the existing debris mob/loot spawn?

private void SpawnRuinBiomeEntities(EntityUid gridUid, MapGridComponent grid, SalvageRuinGeneratorSystem.RuinResult ruinResult, int seed)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

summary block needed

{
var blockedPositions = new HashSet<Vector2i>(
ruinResult.WallEntities.Select(w => w.Position)
.Concat(ruinResult.WindowEntities.Select(w => w.Position)));

if (!_prototypeManager.TryIndex(SpaceRuinBiome, out var ruinTemplate))
return;

var layers = ruinTemplate.Layers;

foreach (var (pos, tile) in ruinResult.FloorTiles)
{
if (blockedPositions.Contains(pos))
continue;

var tileRef = _mapSystem.GetTileRef(gridUid, grid, pos);
if (tileRef.Tile.IsEmpty)
continue;

if (_biome.TryGetDecals(pos, layers, seed, (gridUid, grid), out var decals))
{
foreach (var decal in decals)
{
_decals.TryAddDecal(decal.ID, new EntityCoordinates(gridUid, decal.Position), out _);
}
}

if (_biome.TryGetEntity(pos, layers, tileRef.Tile, seed, (gridUid, grid), out var entityProto))
{
if (!_anchorable.TileFree((gridUid, grid), pos, (int)CollisionGroup.MachineLayer, (int)CollisionGroup.MachineLayer))
continue;

var entity = SpawnAtPosition(entityProto, new EntityCoordinates(gridUid, pos + grid.TileSizeHalfVector));
var xform = Transform(entity);
if (!xform.Anchored)
_transform.AnchorEntity((entity, xform), (gridUid, grid), pos);
}
}
}
// Macro end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

private bool TryGetSalvagePlacementLocation(Entity<SalvageMagnetComponent> magnet, MapId mapId, Box2Rotated attachedBounds, Box2 bounds, Angle worldAngle, out MapCoordinates coords, out Angle angle)
{
var attachedAABB = attachedBounds.CalcBoundingBox();
Expand Down
Loading
Loading