-
Notifications
You must be signed in to change notification settings - Fork 9
[Funky port] Salvage ruins #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
3f20541
a997fdc
d109b88
15e5461
fb53bcb
92a3a3d
9a62cb0
8adf7dd
7fd0c5f
8b301db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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,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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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!; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
|
|
||
There was a problem hiding this comment.
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