|
1 | | -using System; |
| 1 | +using System; |
2 | 2 | using System.Linq; |
3 | 3 | using System.Numerics; |
4 | 4 | using Content.Server._Lavaland.Procedural.Components; |
| 5 | +using Content.Server.Atmos; |
| 6 | +using Content.Server.Atmos.Components; |
| 7 | +using Content.Server.Atmos.EntitySystems; |
| 8 | +using Content.Server.Light.Components; |
5 | 9 | using Content.Shared._Lavaland.Procedural.Components; |
6 | 10 | using Content.Shared._Lavaland.Procedural.Prototypes; |
| 11 | +using Content.Shared.Atmos; |
| 12 | +using Content.Shared.Atmos.Components; |
| 13 | +using Content.Shared.Light.Components; |
| 14 | +using Content.Shared.Light.EntitySystems; |
7 | 15 | using Content.Shared.Maps; |
8 | 16 | using Robust.Server.Physics; |
9 | 17 | using Robust.Shared.Map; |
10 | 18 | using Robust.Shared.Map.Components; |
11 | 19 | using Robust.Shared.Random; |
| 20 | +using Robust.Shared.Utility; |
12 | 21 |
|
13 | 22 | namespace Content.Server._Lavaland.Procedural.Systems; |
14 | 23 |
|
15 | 24 | public sealed partial class LavalandPlanetSystem |
16 | 25 | { |
17 | 26 | [Dependency] private readonly GridFixtureSystem _gridFixture = default!; |
18 | 27 | [Dependency] private readonly ITileDefinitionManager _tileDef = default!; |
| 28 | + [Dependency] private readonly SharedRoofSystem _roofSystem = default!; |
19 | 29 |
|
20 | 30 | private bool LoadGridRuin( |
21 | 31 | LavalandGridRuinPrototype ruin, |
@@ -130,27 +140,41 @@ private bool LoadGridRuin( |
130 | 140 | // Get the rotation of the target grid |
131 | 141 | var rotation = Transform(spawned.Value).LocalRotation; |
132 | 142 |
|
133 | | - // Replace empty tiles in spawned grid with tiles from the same position in lavaland grid |
134 | | - foreach (var tile in _map.GetAllTiles(spawned.Value, spawnedGrid, false)) |
| 143 | + var tilesToRoof = new HashSet<Vector2i>(); |
| 144 | + Entity<MapGridComponent, RoofComponent> spawnedRoof = (spawned.Value, spawnedGrid, EnsureComp<RoofComponent>(spawned.Value)); |
| 145 | + Entity<MapGridComponent?, RoofComponent?> roofMap = (sourceGridUid, sourceGrid, EnsureComp<RoofComponent>(sourceGridUid)); |
| 146 | + |
| 147 | + var matrix = Matrix3Helpers.CreateTransform(offset, rotation); |
| 148 | + |
135 | 149 | { |
136 | | - if (tile.Tile == Tile.Empty) |
| 150 | + var enumerator = _map.GetAllTilesEnumerator(spawned.Value, spawnedGrid); |
| 151 | + while (enumerator.MoveNext(out var tileRef)) |
137 | 152 | { |
138 | | - // Get world position of this tile |
139 | | - var tileWorldPos = _map.GridTileToWorldPos(spawned.Value, spawnedGrid, tile.GridIndices); |
| 153 | + var offsetTile = Vector2.Transform(new Vector2(tileRef.Value.GridIndices.X, tileRef.Value.GridIndices.Y) + sourceGrid.TileSizeHalfVector, matrix) |
| 154 | + .Floored(); |
| 155 | + if (_roofSystem.IsRooved(spawnedRoof, tileRef.Value.GridIndices)) |
| 156 | + { |
| 157 | + _roofSystem.SetRoof(roofMap, offsetTile, true); |
| 158 | + tilesToRoof.Add(offsetTile); |
| 159 | + } |
140 | 160 |
|
141 | | - // Convert to local coordinates in lavaland grid |
142 | | - var lavalandTileIndices = _map.WorldToTile(sourceGridUid, sourceGrid, tileWorldPos); |
| 161 | + if(tileRef.Value.Tile != Tile.Empty) |
| 162 | + continue; |
143 | 163 |
|
144 | | - // Get tile from lavaland grid at this position |
145 | | - if (_map.TryGetTileRef(sourceGridUid, sourceGrid, lavalandTileIndices, out var lavalandTile) && |
| 164 | + if (_map.TryGetTileRef(sourceGridUid, sourceGrid, offsetTile, out var lavalandTile) && |
146 | 165 | !lavalandTile.Tile.IsEmpty) |
147 | 166 | { |
148 | | - _map.SetTile(spawned.Value, spawnedGrid, tile.GridIndices, lavalandTile.Tile); |
| 167 | + _map.SetTile(spawned.Value, spawnedGrid, offsetTile, lavalandTile.Tile); |
149 | 168 | } |
150 | 169 | } |
151 | 170 | } |
152 | 171 |
|
153 | | - _gridFixture.Merge(sourceGridUid, spawned.Value, offset, rotation); |
| 172 | + _gridFixture.Merge(sourceGridUid, spawned.Value, matrix); |
| 173 | + |
| 174 | + foreach (var vector2I in tilesToRoof) |
| 175 | + { |
| 176 | + _roofSystem.SetRoof(roofMap, vector2I, true); |
| 177 | + } |
154 | 178 | } |
155 | 179 | catch (Exception ex) |
156 | 180 | { |
|
0 commit comments