Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
GenBounds.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using UnityEngine;
4
5public class GenBounds : EClass
6{
7 public Map map;
8
9 public Zone zone;
10
11 public int Size;
12
13 public int x;
14
15 public int y;
16
17 public int width;
18
19 public int height;
20
21 public int marginPartial;
22
23 public Func<Cell, bool> FuncCheckEmpty;
24
25 private bool IsSub(BiomeProfile.Tile g, int x, int y)
26 {
27 return g.subType switch
28 {
29 BiomeProfile.BaseTile.SubType.Rnd5 => EClass.rnd(5) == 0,
30 BiomeProfile.BaseTile.SubType.Rnd10 => EClass.rnd(10) == 0,
31 BiomeProfile.BaseTile.SubType.Rnd20 => EClass.rnd(20) == 0,
32 BiomeProfile.BaseTile.SubType.Pattern => (x + y % 2) % 2 == 0,
33 _ => false,
34 };
35 }
36
37 public void SetFloor(BiomeProfile.Tile t, int x, int z)
38 {
39 bool flag = IsSub(t, x, z);
40 SetFloor(x, z, flag ? t.matSub : t.mat, flag ? t.idSub : t.id, EClass.rnd(EClass.rnd(8) + 1));
41 }
42
43 public void SetBlock(BiomeProfile.Tile t, int x, int z, int idMat = -1)
44 {
45 bool flag = IsSub(t, x, z);
46 SetBlock(x, z, (idMat != -1) ? idMat : (flag ? t.matSub : t.mat), flag ? t.idSub : t.id);
47 }
48
49 public void SetFloor(int x, int z, int idMat, int idFloor, int direction = 0)
50 {
51 Cell cell = map.cells[x, z];
52 cell._floorMat = (byte)idMat;
53 cell._floor = (byte)idFloor;
54 cell.floorDir = direction;
55 }
56
57 public void SetBlock(int x, int z, int idMat, int idBlock, int direction = 0)
58 {
59 Cell cell = map.cells[x, z];
60 cell._blockMat = (byte)idMat;
61 cell._block = (byte)idBlock;
62 cell.blockDir = direction;
63 cell.effect = null;
64 }
65
66 public bool IsEmpty()
67 {
68 for (int i = y - marginPartial; i < y + height + marginPartial; i++)
69 {
70 if (i < 0 || i >= EClass._map.Size)
71 {
72 return false;
73 }
74 for (int j = x - marginPartial; j < x + width + marginPartial; j++)
75 {
76 if (j < 0 || j >= EClass._map.Size)
77 {
78 return false;
79 }
80 Cell cell = map.cells[j, i];
81 if (FuncCheckEmpty != null && !FuncCheckEmpty(cell))
82 {
83 return false;
84 }
85 if (cell.blocked || cell.HasBlock || cell.Installed != null)
86 {
87 return false;
88 }
89 }
90 }
91 return true;
92 }
93
94 public List<Point> ListEmptyPoint()
95 {
96 List<Point> list = new List<Point>();
97 for (int i = y; i < y + height; i++)
98 {
99 if (i < 0 || i >= EClass._map.Size)
100 {
101 continue;
102 }
103 for (int j = x; j < x + width; j++)
104 {
105 if (j < 0 || j >= EClass._map.Size)
106 {
107 continue;
108 }
109 Cell cell = map.cells[j, i];
110 if (!cell.blocked && !cell.HasBlock && (cell.Installed == null || !cell.Installed.trait.IsBlockPath))
111 {
112 Point point = new Point(j, i);
113 if (!point.HasChara)
114 {
115 list.Add(point);
116 }
117 }
118 }
119 }
120 return list;
121 }
122
123 public static GenBounds Create(Zone z)
124 {
125 MapBounds bounds = z.map.bounds;
126 return new GenBounds
127 {
128 zone = z,
129 map = z.map,
130 x = bounds.x,
131 y = bounds.z,
132 width = bounds.Width,
133 height = bounds.Height
134 };
135 }
136
137 public GenBounds GetBounds(int w, int h, bool ignoreBlock)
138 {
139 return GetBounds(map, zone, x, y, width, height, w, h, ignoreBlock);
140 }
141
142 public GenBounds GetBounds(Map map, Zone zone, int x, int y, int width, int height, int dw, int dh, bool ignoreBlock)
143 {
144 if (dw >= width || dh >= height)
145 {
146 return null;
147 }
148 GenBounds genBounds = new GenBounds
149 {
150 x = x,
151 y = y,
152 width = dw,
153 height = dh,
154 map = map,
155 zone = zone,
158 };
159 for (int i = 0; i < 200; i++)
160 {
161 if (ignoreBlock)
162 {
163 genBounds.x = EClass.rnd(width - dw) + x - dw / 2;
164 genBounds.y = EClass.rnd(height - dh) + y - dh / 2;
165 if (genBounds.x > 0 && genBounds.y > 0)
166 {
167 return genBounds;
168 }
169 }
170 else
171 {
172 genBounds.x = EClass.rnd(width - dw) + x;
173 genBounds.y = EClass.rnd(height - dh) + y;
174 if (genBounds.IsEmpty())
175 {
176 return genBounds;
177 }
178 }
179 }
180 return null;
181 }
182
183 public PartialMap TryAddMapPiece(MapPiece.Type type = MapPiece.Type.Any, float ruin = -1f, string tags = null, Action<PartialMap, GenBounds> onCreate = null)
184 {
185 if (ruin == -1f)
186 {
187 ruin = zone.RuinChance;
188 }
189 PartialMap partialMap = MapPiece.Instance.GetMap(type, tags.IsEmpty(zone.biome.tags), ruin);
190 if (partialMap == null)
191 {
192 Debug.Log("TryAddMap Piece: no map");
193 return null;
194 }
195 bool flag = partialMap.dir == 1 || partialMap.dir == 3;
196 GenBounds bounds = GetBounds(flag ? partialMap.h : partialMap.w, flag ? partialMap.w : partialMap.h, partialMap.ignoreBlock);
197 if (bounds == null)
198 {
199 return null;
200 }
201 partialMap.Apply(new Point(bounds.x, bounds.y), PartialMap.ApplyMode.Apply);
202 onCreate?.Invoke(partialMap, bounds);
203 Debug.Log(partialMap.path);
204 return partialMap;
205 }
206}
Trait trait
Definition: Card.cs:49
Definition: Cell.cs:7
bool HasBlock
Definition: Cell.cs:643
Thing Installed
Definition: Cell.cs:975
Definition: EClass.cs:5
static int rnd(int a)
Definition: EClass.cs:50
static Map _map
Definition: EClass.cs:18
static GenBounds Create(Zone z)
Definition: GenBounds.cs:123
int height
Definition: GenBounds.cs:19
List< Point > ListEmptyPoint()
Definition: GenBounds.cs:94
void SetBlock(BiomeProfile.Tile t, int x, int z, int idMat=-1)
Definition: GenBounds.cs:43
GenBounds GetBounds(int w, int h, bool ignoreBlock)
Definition: GenBounds.cs:137
void SetBlock(int x, int z, int idMat, int idBlock, int direction=0)
Definition: GenBounds.cs:57
Func< Cell, bool > FuncCheckEmpty
Definition: GenBounds.cs:23
int width
Definition: GenBounds.cs:17
bool IsEmpty()
Definition: GenBounds.cs:66
Zone zone
Definition: GenBounds.cs:9
int marginPartial
Definition: GenBounds.cs:21
PartialMap TryAddMapPiece(MapPiece.Type type=MapPiece.Type.Any, float ruin=-1f, string tags=null, Action< PartialMap, GenBounds > onCreate=null)
Definition: GenBounds.cs:183
int Size
Definition: GenBounds.cs:11
Map map
Definition: GenBounds.cs:7
void SetFloor(int x, int z, int idMat, int idFloor, int direction=0)
Definition: GenBounds.cs:49
void SetFloor(BiomeProfile.Tile t, int x, int z)
Definition: GenBounds.cs:37
bool IsSub(BiomeProfile.Tile g, int x, int y)
Definition: GenBounds.cs:25
GenBounds GetBounds(Map map, Zone zone, int x, int y, int width, int height, int dw, int dh, bool ignoreBlock)
Definition: GenBounds.cs:142
int Size
Definition: MapBounds.cs:20
int Width
Definition: MapBounds.cs:26
int x
Definition: MapBounds.cs:8
static MapPiece Instance
Definition: MapPiece.cs:45
PartialMap GetMap(Type type, string tag, float ruin)
Definition: MapPiece.cs:49
Definition: Map.cs:13
Cell[,] cells
Definition: Map.cs:85
MapBounds bounds
Definition: Map.cs:52
string path
Definition: PartialMap.cs:68
void Apply(Point _point, ApplyMode mode)
Definition: PartialMap.cs:112
bool ignoreBlock
Definition: PartialMap.cs:58
Definition: Point.cs:9
bool HasChara
Definition: Point.cs:226
virtual bool IsBlockPath
Definition: Trait.cs:52
Definition: Zone.cs:12
BiomeProfile biome
Definition: Zone.cs:126
virtual float RuinChance
Definition: Zone.cs:310
Map map
Definition: Zone.cs:60