11 public static MapGen Instance
16 if ((result =
MapGen._Instance) ==
null)
18 result = (MapGen._Instance =
new MapGen());
25 protected override void GenerateTerrain()
27 base.SetSize(this.zp.useRootSize ?
this.zone.GetTopZone().bounds.Size :
this.zp.size, 10);
28 if (this.biomes ==
null || this.Size != this.biomes.GetLength(0))
31 this.subBiomes =
new bool[this.Size, this.Size];
32 this.heights1 =
new float[this.Size, this.Size];
33 this.heights2 =
new float[this.Size, this.Size];
34 this.heights3 =
new float[this.Size, this.Size];
35 this.waters =
new float[this.Size, this.Size];
36 this.heights3d =
new float[this.Size, this.Size];
37 this.lastSize = this.Size;
39 this.map.biomes = this.biomes;
40 this.layerHeight.SaveSettings();
41 this.layerStratum.SaveSettings();
42 this.layerBiome.SaveSettings();
43 this.layerRiver.SaveSettings();
44 this.layerBiome.SaveSettings();
45 this.skipWater = (this.zp.noWater || (this.bp.tileCenter !=
null && (this.bp.tileCenter.IsNeighborRoad || this.bp.tileCenter.isRoad)));
46 for (
int i = 0; i < 100; i++)
48 this.seed = (this.map.seed = this.bp.genSetting.seed + i);
49 Rand.SetSeed(this.seed);
50 if (this.OnGenerateTerrain())
54 Debug.Log(
"Failed map generation:" + i.ToString() +
" / " +
BaseMapGen.err);
55 this.skipWater =
true;
57 this.map.SetZone(
EClass._zone);
58 for (
int j = 0; j < this.Size; j++)
60 for (
int k = 0; k < this.Size; k++)
62 this.map.QuickRefreshTile(j, k);
69 protected override bool OnGenerateTerrain()
72 if (this.map.isGenerated)
74 if (this.map.Size !=
this.Size)
76 this.map.Resize(this.Size);
82 this.map.CreateNew(this.Size,
true);
84 this.map.poiMap.Reset();
85 if (this.bp.zoneProfile.useRootSize)
87 this.map.SetBounds(this.zone.GetTopZone().bounds);
91 this.map.SetBounds((this.bp.zoneProfile.sizeBounds == 0) ?
EClass.setting.defaultMapSize :
this.bp.zoneProfile.sizeBounds);
93 ZoneProfile.GenType genType = this.zp.genType;
98 this.map.config.idBiome =
"Underground";
99 this.zone._biome =
null;
101 this.waterCount = 0f;
104 float num = (float)(this.Size * this.Size) * this.variation.maxWaterRatio;
105 this.layerRiver.FillHeightMap(this.waters, this.OX, 0, this.OZ, this.Size, this.Size, this.seed, 1f);
106 for (
int i = 0; i < this.Size; i++)
108 for (
int j = 0; j < this.Size; j++)
110 this.waters[i, j] += (float)this.zp.water;
111 if (this.waters[i, j] > 0f)
113 this.waterCount += 1f;
116 if (this.waterCount > num)
118 BaseMapGen.err =
"Too many water";
123 this.layerBiome.FillHeightMap(this.heights1, this.OX, 0, this.OZ, this.Size, this.Size, this.zp.seeds.biome, 1f);
124 this.layerBiome.FillHeightMap(this.heights2, this.OX, 0, this.OZ, this.Size, this.Size, this.zp.seeds.biome + 1, 1f);
127 this.layerBiome.FillHeightMap(this.heights3, this.OX, 0, this.OZ, this.Size, this.Size, this.zp.seeds.biome + 2, 1f);
129 for (
int k = 0; k < this.Size; k++)
131 for (
int l = 0; l < this.Size; l++)
133 if (this.heights1[k, l] != 0f)
135 this.biomes[k, l] = this.biomeProfiles[1];
137 else if (this.heights2[k, l] != 0f)
139 this.biomes[k, l] = this.biomeProfiles[2];
141 else if (base.extraBiome &&
this.heights3[k, l] != 0f)
143 this.biomes[k, l] = this.biomeProfiles[3];
147 this.biomes[k, l] = this.biomeProfiles[0];
151 this.layerBiome.FillHeightMap(this.heights1, this.OX, 0, this.OZ, this.Size, this.Size, this.zp.seeds.biomeSub,
this.zp.biomeSubScale);
152 for (
int m = 0; m < this.Size; m++)
154 for (
int n = 0; n < this.Size; n++)
156 this.subBiomes[m, n] = (this.heights1[m, n] != 0f);
159 this.layerBiome.FillHeightMap(this.heights1, this.OX, 0, this.OZ, this.Size, this.Size, this.zp.seeds.biome, 1f);
160 for (
int num2 = 0; num2 < this.biomeProfiles.Length; num2++)
162 if (num2 == 0 || !(this.biomeProfiles[num2 - 1] == this.biomeProfiles[num2]))
164 this.biomeProfiles[num2].layerBlock.FillHeightMap(this.heights1, this.OX, 0, this.OZ, this.Size, this.Size, this.zp.seeds.biome, 1f);
165 bool flag =
EClass.sources.floors.rows[this.biomeProfiles[num2].exterior.floor.id].tag.Contains(
"soil");
166 for (
int num3 = 0; num3 < this.Size; num3++)
168 if (!this.zp.clearEdge || ((num3 <= this.map.bounds.x - 4 || num3 >
this.map.bounds.x + 4) && (num3 <= this.map.bounds.maxX - 4 || num3 >
this.map.bounds.maxX + 4)))
170 for (
int num4 = 0; num4 < this.Size; num4++)
172 if ((!this.zp.clearEdge || ((num4 <= this.map.bounds.z - 4 || num4 >
this.map.bounds.z + 4) && (num4 <= this.map.bounds.maxZ - 4 || num4 >
this.map.bounds.maxZ + 4))) && !(
this.biomes[num3, num4] !=
this.biomeProfiles[num2]) &&
this.heights1[num3, num4] > (
float)
this.blockHeight)
175 if (!flag || row.alias ==
"block_ice")
178 base.SetFloor(num3, num4, row2.DefaultMaterial.id, row2.id, 0);
180 base.SetBlock(num3, num4, this.biomeProfiles[num2].exterior.block.mat,
this.biomeProfiles[num2].exterior.block.id, 0);
188 for (
int num5 = this.Size / 2 - 4; num5 < this.Size / 2 + 4; num5++)
190 for (
int num6 = this.Size / 2 - 4; num6 < this.Size / 2 + 4; num6++)
192 if (num5 >= 0 && num6 >= 0 && num5 < this.Size && num6 < this.Size && this.map.cells[num5, num6]._block != 0)
201 for (
int num7 = 0; num7 < this.Size; num7++)
203 for (
int num8 = 0; num8 < this.Size; num8++)
205 base.SetBlock(num7, num8, 0, 0, 0);
209 this.layerHeight.FillHeightMap(this.heights1, this.OX, 0, this.OZ, this.Size, this.Size, this.seed, 1f);
210 this.layerHeight.FillHeightMap(this.heights2, this.OX, 0, this.OZ, this.Size, this.Size, this.zp.seeds.bush, 1f);
211 this.layerHeight.FillHeightMap(this.heights3, this.OX, 0, this.OZ, this.Size, this.Size, this.seed + 1, 1f);
213 byte b = (byte)
EClass.setting.maxGenHeight;
214 for (
int num9 = 0; num9 < this.Size; num9++)
216 for (
int num10 = 0; num10 < this.Size; num10++)
218 int num11 = (int)this.heights1[num9, num10];
219 Cell cell = this.map.cells[num9, num10];
220 if (cell._block == 0 || cell._floor == 0)
223 SourceMaterial.Row row3 = this.subBiomes[num9, num10] ? biomeProfile.MatSub : biomeProfile.MatFloor;
224 int dir = biomeProfile.exterior.floor.GetDir();
225 byte b2 = (byte)(this.heights1[num9, num10] * (
float)this.hSetting.heightMod + (
float)
this.hSetting.baseHeight);
226 if (this.hSetting.step > 0)
228 b2 = (byte)((
int)b2 / this.hSetting.step *
this.hSetting.step);
235 if (!this.skipWater && this.waters[num9, num10] > 0f && cell._block == 0)
241 for (
int num12 = num10 - 2; num12 < num10 + 3; num12++)
243 for (
int num13 = num9 - 2; num13 < num9 + 3; num13++)
245 if (num12 >= 0 && num13 >= 0 && num13 < this.Size && num12 < this.Size && this.waters[num13, num12] <= 0f)
252 base.SetFloor(num9, num10, this.biomeWater.MatFloor.id, flag3 ? 44 : 43, 0);
256 base.SetFloor(num9, num10, idMat, (this.waters[num9, num10] < 5f) ? 44 : 43, 0);
259 else if (this.zp.shoreHeight > 0f && (
float)num11 <
this.zp.shoreHeight)
261 base.SetFloor(num9, num10, this.biomeShore.MatFloor.id,
this.biomeShore.MatFloor.defFloor, 0);
262 this.biomes[num9, num10] = this.biomeShore;
264 else if (biomeProfile.floor_height != 0 && (
int)
this.heights2[num9, num10] +
this.zp.bushMod >= 4)
266 base.SetFloor(num9, num10, (
int)((
byte)row3.id), biomeProfile.floor_height, dir);
270 base.SetFloor(num9, num10, (
int)((
byte)row3.id), (biomeProfile.exterior.floor.id != 0) ? biomeProfile.exterior.floor.id : row3.defFloor, dir);
275 if (this.hSetting.heightMod > 0)
277 this.ModifyHeight(this.map);
280 for (
int num14 = 0; num14 < this.Size; num14++)
282 for (
int num15 = 0; num15 < this.Size; num15++)
284 Cell cell2 = this.map.cells[num14, num15];
285 if (this.zp.setShore && !cell2.HasBlock && !cell2.IsTopWater && cell2.height <= 20)
288 for (
int num16 = num14 - 1; num16 < num14 + 2; num16++)
290 if (num16 >= 0 && num16 < this.Size)
292 for (
int num17 = num15 - 1; num17 < num15 + 2; num17++)
294 if (num17 >= 0 && num17 < this.Size && (num16 != num14 || num17 != num15) && this.map.cells[num16, num17].IsTopWater)
308 base.SetFloor(num14, num15, this.biomeShore.MatFloor.id,
this.biomeShore.MatFloor.defFloor, 0);
309 this.biomes[num14, num15] = this.biomeShore;
310 if (this.zp.extraShores > 0)
312 int extraShores = this.zp.extraShores;
313 for (
int num18 = num14 - extraShores; num18 < num14 + extraShores + 1; num18++)
315 if (num18 >= 0 && num18 < this.Size)
317 for (
int num19 = num15 - extraShores; num19 < num15 + extraShores + 1; num19++)
319 if (num19 >= 0 && num19 < this.Size && !(this.biomes[num18, num19] == this.biomeShore) && !this.map.cells[num18, num19].IsTopWater && !
this.map.cells[num18, num19].HasBlock)
321 base.SetFloor(num18, num19, this.biomeShore.MatFloor.id,
this.biomeShore.MatFloor.defFloor, 0);
322 this.biomes[num18, num19] = this.biomeShore;
334 this.map.config.idBiome =
"Sky";
335 this.zone._biome =
null;
336 for (
int num20 = 0; num20 < this.Size; num20++)
338 for (
int num21 = 0; num21 < this.Size; num21++)
340 base.SetFloor(num20, num21, 0, 90, 0);
347 public void MakeNeighbor()
349 MapGen.<>c__DisplayClass5_0 CS$<>8__locals1;
350 CS$<>8__locals1.<>4__this =
this;
351 if (this.bp.surrounding ==
null)
355 CS$<>8__locals1.thisInfo = this.bp.surrounding[1, 1];
356 CS$<>8__locals1.seaDir = (CS$<>8__locals1.thisInfo.sea ? (1 +
EClass.rnd(4)) : 0);
357 this.<MakeNeighbor>g___MakeNeighbor|5_0(this.bp.surrounding[1, 2],
this.Size / 3 + 7,
new Point(0, this.Size - 1), 0, -1, 3, 1, ref CS$<>8__locals1);
358 this.<MakeNeighbor>g___MakeNeighbor|5_0(this.bp.surrounding[1, 0],
this.Size / 3 + 7,
new Point(0, 0), 0, 1, 1, 3, ref CS$<>8__locals1);
359 this.<MakeNeighbor>g___MakeNeighbor|5_0(this.bp.surrounding[2, 1],
this.Size / 3 + 7,
new Point(this.Size - 1, 0), -1, 0, 2, 4, ref CS$<>8__locals1);
360 this.<MakeNeighbor>g___MakeNeighbor|5_0(this.bp.surrounding[0, 1],
this.Size / 3 + 7,
new Point(0, 0), 1, 0, 4, 2, ref CS$<>8__locals1);
361 EClass._map.config.seaDir = CS$<>8__locals1.seaDir;
365 public void MakeNeighbor_old()
367 if (this.bp.surrounding ==
null)
371 this.<MakeNeighbor_old>g___MakeNeighbor|6_0(this.bp.surrounding[1, 2],
new Point(this.Size / 2, this.Size / 3 * 2 - 5), 0, 1);
372 this.<MakeNeighbor_old>g___MakeNeighbor|6_0(this.bp.surrounding[1, 0],
new Point(this.Size / 2, this.Size / 3 + 6), 0, -1);
373 this.<MakeNeighbor_old>g___MakeNeighbor|6_0(this.bp.surrounding[2, 1],
new Point(this.Size / 3 * 2 - 5, this.Size / 2), 1, 0);
374 this.<MakeNeighbor_old>g___MakeNeighbor|6_0(this.bp.surrounding[0, 1],
new Point(this.Size / 3 + 6, this.Size / 2), -1, 0);
378 public void MakeRoad()
380 if (this.bp.tileCenter ==
null ||
this.bp.ignoreRoad)
385 if (tileCenter.roadLeft)
387 this.<MakeRoad>g___MakeRoad|7_0(-1, 0);
389 if (tileCenter.roadRight)
391 this.<MakeRoad>g___MakeRoad|7_0(1, 0);
393 if (tileCenter.roadUp)
395 this.<MakeRoad>g___MakeRoad|7_0(0, 1);
397 if (tileCenter.roadDown)
399 this.<MakeRoad>g___MakeRoad|7_0(0, -1);
404 public void ModifyHeight(
Map _map)
407 Cell[,] cells = this.map.cells;
409 for (
int i = this.Size - 1; i > 0; i--)
411 for (
int j = 0; j < this.Size - 1; j++)
413 Cell cell = cells[i, j];
414 byte height = cell.height;
415 Cell cell2 = cells[i - 1, j];
416 Cell cell3 = cells[i, j + 1];
417 if (!cell2.IsTopWater && !cell3.IsTopWater)
427 cell2.height = height;
431 cell3.height = height;
434 if (this.hSetting.smoothDownhill &&
EClass.rnd(3) == 0)
436 if (cell2.height < height - 2)
438 cell2.height = height - 2;
440 if (cell3.height < height - 2)
442 cell3.height = height - 2;
447 if (this.hSetting.mod1 && (cell2.height >= height - 1 || cell3.height >= height - 1))
449 if (
EClass.rnd(4) == 0 && height != 0)
451 cell2.height = (cell3.height = height);
455 cell.height = (cell2.height = cell3.height);
458 if (this.hSetting.mod2 && (cell2.height < height - 1 || cell3.height < height - 1))
462 cell2.height = (cell3.height = height);
466 cells[i, j].height = (cell2.height = cell3.height);
469 if (this.hSetting.mod3 && (cell2.height >= height - 1 || cell3.height >= height - 1))
473 cell2.height = (cell3.height = height);
477 cells[i, j].height = (cell2.height = cell3.height);
484 if (this.hSetting.smoothDownhill)
486 for (
int k = this.Size - 1; k > 0; k--)
488 for (
int l = 0; l < this.Size - 1; l++)
490 byte height2 = cells[k, l].height;
491 Cell cell4 = cells[k - 1, l];
492 Cell cell5 = cells[k, l + 1];
495 if (cell4.height < height2 - 2 && !cell4.IsTopWater)
497 cell4.height = height2 - 2;
499 if (cell5.height < height2 - 2 && !cell5.IsTopWater)
501 cell5.height = height2 - 2;
510 public void MakeRiver(
Map _map)
513 for (
int i = 0; i < 100; i++)
517 for (
int j = 0; j < 1000; j++)
519 point = _map.GetRandomEdge(1);
520 if (!point.cell.blocked)
525 for (
int k = 0; k < 1000; k++)
527 point2 = _map.GetRandomEdge(1);
528 if (point.x != point2.x && point.z != point2.z && !point2.cell.blocked && point.Distance(point2) >= _map.Size / 2)
533 if (this.TryMakeRiver(point, point2))
547 List<Point> list =
new List<Point>();
549 for (
int i = 0; i < num; i++)
553 x = p1.x + (p2.x - p1.x) * i / num,
554 z = p1.z + (p2.z - p1.z) * i / num
557 for (
int j = 0; j < num; j++)
559 Point point = list[j];
560 if (!p1.Equals(point))
564 base.SetBlock(p1.x, p1.z, 0, 0, 0);
565 base.SetFloor(p1.x, p1.z, 67, 44, 0);
570 p1.x += ((p1.x > point.x) ? -1 : 1);
572 else if (p1.z != point.z)
574 p1.z += ((p1.z > point.z) ? -1 : 1);
577 else if (p1.z != point.z)
579 p1.z += ((p1.z > point.z) ? -1 : 1);
581 else if (p1.x != point.x)
583 p1.x += ((p1.x > point.x) ? -1 : 1);
585 if (p1.Equals(point))
590 if (p1.IsWater || p1.Equals(p2))
600 public void Populate(
Map _map)
603 EClass._zone.isShore = this.bp.zoneProfile.isShore;
604 Rand.SetSeed(this.zp.seeds.poi);
607 this.MakeRiver(_map);
609 this.map.RefreshAllTiles();
610 this.layerStratum.FillHeightMap(this.heights1, this.OX, 0, this.OZ, this.Size, this.Size, this.seed, 1f);
611 this.layerStratum.FillHeightMap(this.heights2, this.OX, 0, this.OZ, this.Size, this.Size, this.seed + 1, 1f);
612 this.layerStratum.FillHeightMap(this.heights3, this.OX, 0, this.OZ, this.Size, this.Size, this.seed + 2, 1f);
613 this.layerStratum.FillHeightMap(this.heights3d, this.OX, 0, this.OZ, this.Size, this.Size, this.seed, 1f);
615 for (
int i = 0; i < this.Size; i++)
617 for (
int j = 0; j < this.Size; j++)
620 Cell cell = point.cell;
621 if (cell.IsTopWater &&
this.biomeWater)
623 if (cell.Left.IsTopWater && cell.Right.IsTopWater && cell.Front.IsTopWater && cell.Back.IsTopWater)
625 this.biomeWater.Populate(point,
false);
633 biome.Populate(point,
false);
638 if (this.zp.name ==
"R_Plain")
642 crawler.CrawlUntil(_map, () => _map.GetRandomPoint(), tries, delegate(
Crawler.
Result r)
644 int id = (EClass.rnd(3) == 0) ? 108 : 105;
645 foreach (Point point2 in r.points)
647 this.map.SetObj(point2.x, point2.z, id, 1, 0);
649 if (EClass.rnd(6) == 0)
653 point2.growth.SetStage(num, false);
658 if (this.crawlers !=
null)
660 Crawler[] crawlers = this.crawlers;
661 for (
int k = 0; k < crawlers.Length; k++)
663 crawlers[k].Crawl(this.map);
673 Debug.Log(this.zp.name +
"/" +
this.variation.name);
674 Debug.Log(
string.Concat(
new string[]
677 EClass._map.seed.ToString(),
687 private void <MakeNeighbor>g___MakeNeighbor|5_0(
EloMap.
TileInfo info,
int _s,
Point p,
int vx,
int vz,
int _seaDir1,
int _seaDir2, ref
MapGen.<>c__DisplayClass5_0 A_8)
698 num += ((
EClass.rnd(2) == 0) ? 1 : -1);
699 num = Mathf.Clamp(num, _s - 3, _s + 3);
702 for (
int i = 0; i < num; i++)
706 point.x = p.x + i * vx;
710 point.z = p.z + i * vz;
716 if (!A_8.thisInfo.sea)
718 A_8.seaDir = _seaDir1;
720 base.SetFloor(point.x, point.z, 66, (i >= num - 3) ? 44 : 43, 0);
724 base.SetBlock(point.x, point.z, 45, 1, 0);
728 if (!A_8.thisInfo.shore)
730 A_8.seaDir = _seaDir2;
732 base.SetFloor(point.x, point.z, 97, 33, 0);
749 private void <MakeNeighbor_old>g___MakeNeighbor|6_0(
EloMap.
TileInfo info,
Point p,
int vx,
int vz)
764 for (
int i = -this.Size / 2; i < this.Size / 2; i++)
778 base.SetFloor(point.x, point.z, 66, 43, 0);
782 base.SetBlock(point.x, point.z, 45, 1, 0);
786 base.SetFloor(point.x, point.z, 97, 33, 0);
797 private void <MakeRoad>g___MakeRoad|7_0(
int vx,
int vz)
799 Point point =
new Point(this.Size / 2, this.Size / 2);
801 while (point.IsValid)
804 for (
int i = -1; i < 2; i++)
808 point2.z = point.z + i;
812 point2.x = point.x + i;
816 base.SetFloor(point2.x, point2.z, 45, 40, 0);
817 base.SetBlock(point2.x, point2.z, 0, 0, 0);
825 point.x += ((vx == 0) ? (
EClass.rnd(3) - 1) : 0);
826 point.z += ((vz == 0) ? (
EClass.rnd(3) - 1) : 0);
832 private static MapGen _Instance;