Client LuaCsForBarotrauma
BarotraumaShared/SharedSource/Map/Levels/Ruins/RuinGenerator.cs
2 using Microsoft.Xna.Framework;
3 using System;
4 using System.Collections.Generic;
5 using Voronoi2;
6 
8 {
9  partial class Ruin
10  {
11  private readonly RuinGenerationParams generationParams;
12 
13  public List<VoronoiCell> PathCells = new List<VoronoiCell>();
14 
15  public Rectangle Area
16  {
17  get;
18  private set;
19  }
20 
22  {
23  get;
24  private set;
25  }
26 
27  public Ruin(Level level, RuinGenerationParams generationParams, Location location, Point position, bool mirror = false)
28  : this(level, generationParams, location.Type, position, mirror)
29  {
30  }
31 
32  public Ruin(Level level, RuinGenerationParams generationParams, LocationType locationType, Point position, bool mirror = false)
33  {
34  this.generationParams = generationParams;
35  Generate(level, locationType, position, mirror);
36  }
37 
38  public void Generate(Level level, LocationType locationType, Point position, bool mirror = false)
39  {
40  Submarine = OutpostGenerator.Generate(generationParams, locationType, onlyEntrance: false);
41  Submarine.Info.Name = $"Ruin ({level.Seed})";
44 
45  //prevent the ruin from extending above the level "ceiling"
46  position.Y = Math.Min(level.Size.Y - (Submarine.Borders.Height / 2) - 100, position.Y);
47  Submarine.SetPosition(position.ToVector2(), forceUndockFromStaticSubmarines: false);
48 
49  if (mirror)
50  {
51  Submarine.FlipX();
52  }
53 
54  Rectangle worldBorders = Submarine.Borders;
55  worldBorders.Location += Submarine.WorldPosition.ToPoint();
56  Area = new Rectangle(worldBorders.X, worldBorders.Y - worldBorders.Height, worldBorders.Width, worldBorders.Height);
57 
58  var waypoints = WayPoint.WayPointList.FindAll(wp => wp.Ruin == this || wp.Submarine == Submarine);
59  int interestingPosCount = 0;
60  foreach (WayPoint wp in waypoints)
61  {
62  if (wp.SpawnType != SpawnType.Enemy) { continue; }
63  level.PositionsOfInterest.Add(new Level.InterestingPosition(wp.WorldPosition.ToPoint(), Level.PositionType.Ruin, this));
64  interestingPosCount++;
65  }
66 
67  if (interestingPosCount == 0)
68  {
69  //make sure there's at least one PositionsOfInterest in the ruins
70  level.PositionsOfInterest.Add(new Level.InterestingPosition(waypoints.GetRandom(Rand.RandSync.ServerAndClient).WorldPosition.ToPoint(), Level.PositionType.Ruin, this));
71  }
72  }
73  }
74 }
virtual Vector2 WorldPosition
Definition: Entity.cs:49
Ruin(Level level, RuinGenerationParams generationParams, Location location, Point position, bool mirror=false)
void Generate(Level level, LocationType locationType, Point position, bool mirror=false)
Ruin(Level level, RuinGenerationParams generationParams, LocationType locationType, Point position, bool mirror=false)
void FlipX(List< Submarine > parents=null)
Rectangle? Borders
Extents of the solid items/structures (ones with a physics body) and hulls
void SetPosition(Vector2 position, List< Submarine > checkd=null, bool forceUndockFromStaticSubmarines=true)