-
Notifications
You must be signed in to change notification settings - Fork 4
/
CrashZoneSanctuaryBiome.cs
209 lines (176 loc) · 7 KB
/
CrashZoneSanctuaryBiome.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.IO;
using SMLHelper.V2.Assets;
using SMLHelper.V2.Handlers;
using SMLHelper.V2.Crafting;
using SMLHelper.V2.Interfaces;
using SMLHelper.V2.Json;
using SMLHelper.V2.Utility;
using UnityEngine;
using ReikaKalseki.DIAlterra;
namespace ReikaKalseki.SeaToSea {
public class CrashZoneSanctuaryBiome : CustomBiome {
public static readonly float biomeRadius = 120;
private static readonly float radiusFuzz = 24;
public static readonly Vector3 biomeCenter = new Vector3(1111.16F, -360.5F, -985F);
private static readonly Simplex3DGenerator edgeFuzz = (Simplex3DGenerator)new Simplex3DGenerator(2376547).setFrequency(0.1);
public static readonly string biomeName = "Glowing Sanctuary";
public static readonly CrashZoneSanctuaryBiome instance = new CrashZoneSanctuaryBiome();
private readonly Dictionary<string, int> creatureCounts = new Dictionary<string, int>();
private CrashZoneSanctuaryBiome() : base(biomeName, 1F) {
creatureCounts[VanillaCreatures.BLADDERFISH.prefab] = 36;
creatureCounts[VanillaCreatures.BOOMERANG.prefab] = 48;
creatureCounts[VanillaCreatures.CAVECRAWLER.prefab] = 27;
creatureCounts[VanillaCreatures.GASOPOD.prefab] = 4;
creatureCounts[VanillaCreatures.HOOPFISH.prefab] = 90;
creatureCounts[VanillaCreatures.MESMER.prefab] = 6;
creatureCounts[VanillaCreatures.SCHOOL_HOOPFISH.prefab] = 6;
creatureCounts[VanillaCreatures.SCHOOL_HOLEFISH.prefab] = 3;
creatureCounts[VanillaCreatures.SCHOOL_BOOMERANG.prefab] = 6;
creatureCounts[VanillaCreatures.SCHOOL_BLADDERFISH.prefab] = 3;
}
public override void register() {
UnityEngine.Random.InitState(873451871);
/* prebaked
GenUtil.registerWorldgen(new PositionedPrefab(SeaToSeaMod.crashSanctuarySpawner.ClassID, biomeCenter));
for (int i = 0; i < 160; i++) {
Vector3 pos = MathUtil.getRandomVectorAround(biomeCenter, new Vector3(biomeRadius, 0, biomeRadius)*0.8F).setY(-300);
if (isInBiome(pos))
GenUtil.registerWorldgen(new PositionedPrefab(SeaToSeaMod.sanctuaryGrassSpawner.ClassID, pos));
}
*/
creatureCounts[SeaToSeaMod.sanctuaryray.ClassID] = 18;
foreach (KeyValuePair<string, int> kvp in creatureCounts) {
for (int i = 0; i < kvp.Value; i++) {
Vector3 pos = MathUtil.getRandomVectorAround(biomeCenter, new Vector3(biomeRadius, 0, biomeRadius)*0.67F).setY(-340);
if (isInBiome(pos))
GenUtil.registerWorldgen(new PositionedPrefab(kvp.Key, pos));
}
}
}
public override mset.Sky getSky() {
return WorldUtil.getSkybox("sparseReef");
}
public override VanillaMusic[] getMusicOptions() {
return new VanillaMusic[]{VanillaMusic.COVE};
}
public override bool isCaveBiome() {
return false;
}
public override bool existsInSeveralPlaces() {
return false;
}
public override bool isInBiome(Vector3 pos) {
float dist = Vector3.Distance(pos, biomeCenter);
if (dist > biomeRadius+radiusFuzz)
return false;
return dist <= biomeRadius+edgeFuzz.getValue(pos)*radiusFuzz;
}
public override double getDistanceToBiome(Vector3 vec) {
return Math.Max(0, Vector3.Distance(vec, biomeCenter)-biomeRadius);
}
public override float getMurkiness(float orig) {
return 0.99F;
}
public override float getScatteringFactor(float orig) {
return orig;
}
public override Vector3 getColorFalloff(Vector3 orig) {
return new Vector3(40, 3.12F, 2.75F)*0.875F;
}
public override float getFogStart(float orig) {
return 18;
}
public override float getScatterFactor(float orig) {
return orig;
}
public override Color getWaterColor(Color orig) {
return orig;
}
public override float getSunScale(float orig) {
return 0.5F;
}
public static void cleanPlantOverlap() { //called manually to compute prebaked positions
HashSet<Vector3> positions = new HashSet<Vector3>();
foreach (SanctuaryPlantTag sp in UnityEngine.Object.FindObjectsOfType<SanctuaryPlantTag>()) {
Vector3 pos = sp.transform.position;
if (!instance.isInBiome(pos))
continue;
positions.Add(pos);
foreach (PrefabIdentifier pi in WorldUtil.getObjectsNearWithComponent<PrefabIdentifier>(pos, 2.5F)) { //does not find the grass because no collider
if (CrashZoneSanctuarySpawner.spawnsPlant(pi.ClassId))
UnityEngine.Object.DestroyImmediate(pi.gameObject);
}
}
HashSet<Vector3> satellitePositions = new HashSet<Vector3>();
foreach (PrefabIdentifier pi in UnityEngine.Object.FindObjectsOfType<PrefabIdentifier>()) {
if (pi && CrashZoneSanctuarySpawner.spawnsPlant(pi.ClassId))
satellitePositions.Add(pi.transform.position);
}
HashSet<Vector3> fernPositions = new HashSet<Vector3>();
foreach (PrefabIdentifier pi in UnityEngine.Object.FindObjectsOfType<PrefabIdentifier>()) {
if (pi && pi.ClassId == SeaToSeaMod.crashSanctuaryFern.ClassID) {
foreach (Vector3 pos in positions) {
if (Vector3.Distance(pos, pi.transform.position) <= 3.75F) {
UnityEngine.Object.DestroyImmediate(pi.gameObject);
break;
}
}
if (!pi || !pi.transform)
continue;
foreach (Vector3 pos in satellitePositions) {
if (Vector3.Distance(pos, pi.transform.position) <= 2F) {
UnityEngine.Object.DestroyImmediate(pi.gameObject);
break;
}
}
if (!pi || !pi.transform)
continue;
foreach (Vector3 pos in fernPositions) {
if (Vector3.Distance(pos, pi.transform.position) <= 0.3F) {
UnityEngine.Object.DestroyImmediate(pi.gameObject);
break;
}
}
if (!pi || !pi.transform)
continue;
fernPositions.Add(pi.transform.position);
}
}
}
public static void dumpPlantData() {
string path = BuildingHandler.instance.getDumpFile("sanctuary_plants");
XmlDocument doc = new XmlDocument();
XmlElement rootnode = doc.CreateElement("Root");
doc.AppendChild(rootnode);
foreach (SanctuaryPlantTag sp in UnityEngine.Object.FindObjectsOfType<SanctuaryPlantTag>()) {
if (!instance.isInBiome(sp.transform.position))
continue;
PositionedPrefab pfb = new PositionedPrefab(sp.GetComponent<PrefabIdentifier>());
XmlElement e = doc.CreateElement("flame");
pfb.saveToXML(e);
doc.DocumentElement.AppendChild(e);
}
foreach (PrefabIdentifier pi in UnityEngine.Object.FindObjectsOfType<PrefabIdentifier>()) {
if (pi && CrashZoneSanctuarySpawner.spawnsPlant(pi.ClassId) && instance.isInBiome(pi.transform.position)) {
PositionedPrefab pfb = new PositionedPrefab(pi);
XmlElement e = doc.CreateElement("plant");
pfb.saveToXML(e);
doc.DocumentElement.AppendChild(e);
}
}
foreach (PrefabIdentifier pi in UnityEngine.Object.FindObjectsOfType<PrefabIdentifier>()) {
if (pi && pi.ClassId == SeaToSeaMod.crashSanctuaryFern.ClassID) {
PositionedPrefab pfb = new PositionedPrefab(pi);
XmlElement e = doc.CreateElement("fern");
pfb.saveToXML(e);
doc.DocumentElement.AppendChild(e);
}
}
doc.Save(path);
}
}
}