Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 5 additions & 2 deletions Content.Server/Procedural/DungeonJob/DungeonJob.Biome.cs
Copy link
Contributor

Choose a reason for hiding this comment

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

this all needs comments, & please put macro usings together as well

Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Content.Server.Parallax;
using Content.Shared.Maps;
using Content.Shared.Parallax.Biomes;
using Content.Shared.Procedural;
using Content.Shared.Procedural.PostGeneration;
using Robust.Shared.Map;
using Robust.Shared.Noise;
using Robust.Shared.Utility;

namespace Content.Server.Procedural.DungeonJob;
Expand All @@ -23,6 +25,7 @@ private async Task PostGen(BiomeDunGen dunGen, Dungeon dungeon, HashSet<Vector2i

var seed = random.Next();
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
var noiseCache = new Dictionary<int, FastNoiseLite>();

var tiles = _maps.GetAllTilesEnumerator(_gridUid, _grid);
while (tiles.MoveNext(out var tileRef))
Expand All @@ -44,15 +47,15 @@ private async Task PostGen(BiomeDunGen dunGen, Dungeon dungeon, HashSet<Vector2i
_maps.SetTile(_gridUid, _grid, node, tile.Value);
}

if (biomeSystem.TryGetDecals(node, indexedBiome.Layers, seed, (_gridUid, _grid), out var decals))
if (biomeSystem.TryGetDecals(node, indexedBiome.Layers, seed, (_gridUid, _grid), out var decals, noiseCache))
{
foreach (var decal in decals)
{
_decals.TryAddDecal(decal.ID, new EntityCoordinates(_gridUid, decal.Position), out _);
}
}

if (biomeSystem.TryGetEntity(node, indexedBiome.Layers, tile ?? tileRef.Value.Tile, seed, (_gridUid, _grid), out var entityProto))
if (biomeSystem.TryGetEntity(node, indexedBiome.Layers, tile ?? tileRef.Value.Tile, seed, (_gridUid, _grid), out var entityProto, noiseCache))
{
var ent = _entManager.SpawnEntity(entityProto, new EntityCoordinates(_gridUid, node + _grid.TileSizeHalfVector));
var xform = xformQuery.Get(ent);
Expand Down
117 changes: 113 additions & 4 deletions Content.Server/Salvage/SalvageSystem.Magnet.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
using System.Collections.Generic; // Macro
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.Noise; // Macro
Comment on lines +1 to +23
Copy link
Contributor

Choose a reason for hiding this comment

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

others are free to veto me on this but i prefer having all our usings grouped together underneath upstream usings because it looks nice

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"; // Macro
private static readonly ProtoId<BiomeTemplatePrototype> SpaceRuinBiome = "SpaceRuin"; // Macro

private EntityQuery<SalvageMobRestrictionsComponent> _salvMobQuery;
private EntityQuery<MobStateComponent> _mobStateQuery;
Expand Down Expand Up @@ -305,14 +323,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 +405,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 +485,49 @@ 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;
var noiseCache = new Dictionary<int, FastNoiseLite>();

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, noiseCache))
{
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, noiseCache))
{
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