Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
SubsystemCreatureSpawn.cs
浏览该文件的文档.
1using Engine;
4
5namespace Game {
7 public class CreatureType {
8 public string Name;
9
11
12 public bool RandomSpawn;
13
14 public bool ConstantSpawn;
15
16 public Func<CreatureType, Point3, float> SpawnSuitabilityFunction;
17
18 public Func<CreatureType, Point3, int> SpawnFunction;
19
20 public CreatureType(string name, SpawnLocationType spawnLocationType, bool randomSpawn, bool constantSpawn) {
21 Name = name;
22 SpawnLocationType = spawnLocationType;
23 RandomSpawn = randomSpawn;
24 ConstantSpawn = constantSpawn;
25 }
26
27 public override string ToString() => Name;
28 }
29
31
33
35
37
39
41
43
45
46 public Random m_random = new();
47
48 public List<CreatureType> m_creatureTypes = [];
49
50 public Dictionary<ComponentCreature, bool> m_creatures = [];
51
52 public DynamicArray<ComponentBody> m_componentBodies = [];
53
54 public List<SpawnChunk> m_newSpawnChunks = [];
55
56 public List<SpawnChunk> m_spawnChunks = [];
57
58 public static SpawnLocationType[] m_spawnLocations = EnumUtils.GetEnumValues<SpawnLocationType>().Cast<SpawnLocationType>().ToArray();
59
60 public static int m_totalLimit = 26;
61
62 public static int m_areaLimit = 3;
63
64 public static int m_areaRadius = 16;
65
66 public static int m_totalLimitConstant = 6;
67
68 public static int m_totalLimitConstantChallenging = 12;
69
70 public static int m_areaLimitConstant = 4;
71
72 public static int m_areaRadiusConstant = 42;
73
74 public const float m_populationReductionConstant = 0.25f;
75
76 public Dictionary<ComponentCreature, bool>.KeyCollection Creatures => m_creatures.Keys;
77
79
80 public virtual void Update(float dt) {
81 if (m_subsystemGameInfo.WorldSettings.EnvironmentBehaviorMode == EnvironmentBehaviorMode.Living) {
82 if (m_newSpawnChunks.Count > 0) {
83 m_newSpawnChunks.RandomShuffle(max => m_random.Int(0, max - 1));
84 foreach (SpawnChunk newSpawnChunk in m_newSpawnChunks) {
85 SpawnChunkCreatures(newSpawnChunk, 10, false);
86 }
87 m_newSpawnChunks.Clear();
88 }
89 if (m_spawnChunks.Count > 0) {
90 m_spawnChunks.RandomShuffle(max => m_random.Int(0, max - 1));
91 foreach (SpawnChunk spawnChunk in m_spawnChunks) {
92 SpawnChunkCreatures(spawnChunk, 2, true);
93 }
94 m_spawnChunks.Clear();
95 }
96 float num = m_subsystemSeasons.Season == Season.Winter ? 120f : 60f;
97 if (m_subsystemTime.PeriodicGameTimeEvent(num, 2.0)) {
99 }
100 }
101 }
102
103 public override void Load(ValuesDictionary valuesDictionary) {
104 m_subsystemGameInfo = Project.FindSubsystem<SubsystemGameInfo>(true);
105 m_subsystemSpawn = Project.FindSubsystem<SubsystemSpawn>(true);
106 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
107 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
108 m_subsystemSky = Project.FindSubsystem<SubsystemSky>(true);
109 m_subsystemSeasons = Project.FindSubsystem<SubsystemSeasons>(true);
110 m_subsystemBodies = Project.FindSubsystem<SubsystemBodies>(true);
111 m_subsystemViews = Project.FindSubsystem<SubsystemGameWidgets>(true);
113 m_subsystemSpawn.SpawningChunk += delegate(SpawnChunk chunk) {
114 m_spawnChunks.Add(chunk);
115 if (!chunk.IsSpawned) {
116 m_newSpawnChunks.Add(chunk);
117 }
118 };
119 }
120
121 public override void OnEntityAdded(Entity entity) {
122 foreach (ComponentCreature item in entity.FindComponents<ComponentCreature>()) {
123 m_creatures.Add(item, true);
124 }
125 }
126
127 public override void OnEntityRemoved(Entity entity) {
128 foreach (ComponentCreature item in entity.FindComponents<ComponentCreature>()) {
129 m_creatures.Remove(item);
130 }
131 }
132
133 public virtual void InitializeCreatureTypes() {
134 m_creatureTypes.Add(
135 new CreatureType("Duck", SpawnLocationType.Surface, true, false) {
136 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
137 float num97 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
138 int humidity26 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
139 int temperature38 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
140 int num98 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
141 int topHeight3 = m_subsystemTerrain.Terrain.GetTopHeight(point.X, point.Z);
142 return humidity26 > 8
143 && temperature38 > 4
144 && num97 > 40f
145 && point.Y >= topHeight3
146 && (BlocksManager.Blocks[num98] is LeavesBlock || num98 == 18 || num98 == 8 || num98 == 2)
147 ? 2.5f
148 : 0f;
149 },
150 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Duck", point, 1).Count
151 }
152 );
153 m_creatureTypes.Add(
154 new CreatureType("Raven", SpawnLocationType.Surface, true, false) {
155 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
156 float num95 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
157 int temperature37 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
158 int humidity25 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
159 int num96 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
160 int topHeight2 = m_subsystemTerrain.Terrain.GetTopHeight(point.X, point.Z);
161 return (humidity25 <= 8 || temperature37 <= 4)
162 && num95 > 40f
163 && point.Y >= topHeight2
164 && (BlocksManager.Blocks[num96] is LeavesBlock || num96 == 62 || num96 == 8 || num96 == 2 || num96 == 7)
165 ? 2.5f
166 : 0f;
167 },
168 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Raven", point, 1).Count
169 }
170 );
171 m_creatureTypes.Add(
172 new CreatureType("Seagull", SpawnLocationType.Surface, true, false) {
173 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
174 float num93 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
175 int num94 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
176 int topHeight = m_subsystemTerrain.Terrain.GetTopHeight(point.X, point.Z);
177 return num93 > -100f && num93 < 40f && point.Y >= topHeight && (num94 == 18 || num94 == 7 || num94 == 6 || num94 == 62)
178 ? 2.5f
179 : 0f;
180 },
181 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Seagull", point, 1).Count
182 }
183 );
184 m_creatureTypes.Add(
185 new CreatureType("Wildboar", SpawnLocationType.Surface, false, false) {
186 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
187 float num91 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
188 int humidity24 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
189 int num92 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
190 return num91 > 20f && humidity24 > 8 && point.Y < 80 && (num92 == 8 || num92 == 2) ? 0.25f : 0f;
191 },
192 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Wildboar", point, 1).Count
193 }
194 );
195 m_creatureTypes.Add(
196 new CreatureType("Brown Cattle", SpawnLocationType.Surface, false, false) {
197 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
198 float num89 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
199 int humidity23 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
200 int temperature36 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
201 int num90 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
202 return num89 > 20f && humidity23 > 4 && temperature36 >= 8 && point.Y < 70 && (num90 == 8 || num90 == 2) ? 0.05f : 0f;
203 },
204 SpawnFunction = delegate(CreatureType creatureType, Point3 point) {
205 int num87 = m_random.Int(3, 5);
206 int num88 = MathUtils.Min(m_random.Int(1, 3), num87);
207 int count2 = num87 - num88;
208 return 0
209 + SpawnCreatures(creatureType, "Bull_Brown", point, num88).Count
210 + SpawnCreatures(creatureType, "Cow_Brown", point, count2).Count;
211 }
212 }
213 );
214 m_creatureTypes.Add(
215 new CreatureType("Black Cattle", SpawnLocationType.Surface, false, false) {
216 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
217 float num85 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
218 int humidity22 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
219 int temperature35 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
220 int num86 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
221 return num85 > 20f && humidity22 > 4 && temperature35 < 8 && point.Y < 70 && (num86 == 8 || num86 == 2) ? 0.05f : 0f;
222 },
223 SpawnFunction = delegate(CreatureType creatureType, Point3 point) {
224 int num83 = m_random.Int(3, 5);
225 int num84 = MathUtils.Min(m_random.Int(1, 3), num83);
226 int count = num83 - num84;
227 return 0
228 + SpawnCreatures(creatureType, "Bull_Black", point, num84).Count
229 + SpawnCreatures(creatureType, "Cow_Black", point, count).Count;
230 }
231 }
232 );
233 m_creatureTypes.Add(
234 new CreatureType("White Bull", SpawnLocationType.Surface, false, false) {
235 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
236 float num81 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
237 int humidity21 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
238 int temperature34 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
239 int num82 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
240 return num81 > 20f && humidity21 > 8 && temperature34 < 4 && point.Y < 70 && (num82 == 8 || num82 == 2) ? 0.01f : 0f;
241 },
242 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Bull_White", point, 1).Count
243 }
244 );
245 m_creatureTypes.Add(
246 new CreatureType("Gray Wolves", SpawnLocationType.Surface, false, false) {
247 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
248 float num79 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
249 int humidity20 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
250 int num80 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
251 return num79 > 40f && humidity20 >= 8 && point.Y < 100 && (num80 == 8 || num80 == 2) ? 0.075f : 0f;
252 },
253 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Wolf_Gray", point, m_random.Int(1, 3)).Count
254 }
255 );
256 m_creatureTypes.Add(
257 new CreatureType("Coyotes", SpawnLocationType.Surface, false, false) {
258 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
259 float num77 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
260 int humidity19 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
261 int temperature33 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
262 int num78 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
263 return num77 > 40f && temperature33 > 8 && humidity19 < 8 && humidity19 >= 2 && point.Y < 100 && num78 == 7 ? 0.075f : 0f;
264 },
265 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Wolf_Coyote", point, m_random.Int(1, 3)).Count
266 }
267 );
268 m_creatureTypes.Add(
269 new CreatureType("Brown Bears", SpawnLocationType.Surface, false, false) {
270 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
271 float num75 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
272 int temperature32 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
273 int humidity18 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
274 int num76 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
275 return num75 > 40f && humidity18 >= 4 && temperature32 >= 8 && point.Y < 110 && (num76 == 8 || num76 == 2 || num76 == 3)
276 ? 0.1f
277 : 0f;
278 },
279 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Bear_Brown", point, 1).Count
280 }
281 );
282 m_creatureTypes.Add(
283 new CreatureType("Black Bears", SpawnLocationType.Surface, false, false) {
284 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
285 float num73 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
286 int temperature31 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
287 int humidity17 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
288 int num74 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
289 return num73 > 40f && humidity17 >= 4 && temperature31 < 8 && point.Y < 120 && (num74 == 8 || num74 == 2 || num74 == 3)
290 ? 0.1f
291 : 0f;
292 },
293 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Bear_Black", point, 1).Count
294 }
295 );
296 m_creatureTypes.Add(
297 new CreatureType("Polar Bears", SpawnLocationType.Surface, false, false) {
298 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
299 float num71 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
300 int temperature30 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
301 int num72 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
302 return num71 > -40f && temperature30 < 8 && point.Y < 80 && num72 == 62 ? 0.1f : 0f;
303 },
304 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Bear_Polar", point, 1).Count
305 }
306 );
307 m_creatureTypes.Add(
308 new CreatureType("Horses", SpawnLocationType.Surface, false, false) {
309 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
310 float num69 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
311 int temperature29 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
312 int humidity16 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
313 int num70 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
314 return num69 > 20f && temperature29 > 3 && humidity16 > 6 && point.Y < 80 && (num70 == 8 || num70 == 2 || num70 == 3)
315 ? 0.05f
316 : 0f;
317 },
318 SpawnFunction = delegate(CreatureType creatureType, Point3 point) {
319 int temperature28 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
320 int num68 = 0;
321 if (m_random.Float(0f, 1f) < 0.35f) {
322 num68 += SpawnCreatures(creatureType, "Horse_Black", point, 1).Count;
323 }
324 if (m_random.Float(0f, 1f) < 0.5f) {
325 num68 += SpawnCreatures(creatureType, "Horse_Bay", point, 1).Count;
326 }
327 if (m_random.Float(0f, 1f) < 0.5f) {
328 num68 += SpawnCreatures(creatureType, "Horse_Chestnut", point, 1).Count;
329 }
330 if (temperature28 > 8
331 && m_random.Float(0f, 1f) < 0.3f) {
332 num68 += SpawnCreatures(creatureType, "Horse_Palomino", point, 1).Count;
333 }
334 if (temperature28 < 8
335 && m_random.Float(0f, 1f) < 0.3f) {
336 num68 += SpawnCreatures(creatureType, "Horse_White", point, 1).Count;
337 }
338 return num68;
339 }
340 }
341 );
342 m_creatureTypes.Add(
343 new CreatureType("Camels", SpawnLocationType.Surface, false, false) {
344 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
345 float num66 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
346 int temperature27 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
347 int humidity15 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
348 int num67 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
349 return num66 > 20f && temperature27 > 8 && humidity15 < 8 && point.Y < 80 && num67 == 7 ? 0.05f : 0f;
350 },
351 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Camel", point, m_random.Int(1, 2)).Count
352 }
353 );
354 m_creatureTypes.Add(
355 new CreatureType("Donkeys", SpawnLocationType.Surface, false, false) {
356 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
357 float num64 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
358 int temperature26 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
359 int num65 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
360 return num64 > 20f && temperature26 > 6 && point.Y < 120 && (num65 == 8 || num65 == 2 || num65 == 3 || num65 == 7)
361 ? 0.05f
362 : 0f;
363 },
364 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Donkey", point, 1).Count
365 }
366 );
367 m_creatureTypes.Add(
368 new CreatureType("Giraffes", SpawnLocationType.Surface, false, false) {
369 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
370 float num62 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
371 int temperature25 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
372 int humidity14 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
373 int num63 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
374 return num62 > 20f && temperature25 > 8 && humidity14 > 7 && point.Y < 75 && (num63 == 8 || num63 == 2 || num63 == 3)
375 ? 0.03f
376 : 0f;
377 },
378 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Giraffe", point, m_random.Int(1, 2)).Count
379 }
380 );
381 m_creatureTypes.Add(
382 new CreatureType("Rhinos", SpawnLocationType.Surface, false, false) {
383 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
384 float num60 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
385 int temperature24 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
386 int humidity13 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
387 int num61 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
388 return num60 > 40f && temperature24 > 8 && humidity13 > 7 && point.Y < 75 && (num61 == 8 || num61 == 2 || num61 == 3)
389 ? 0.03f
390 : 0f;
391 },
392 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Rhino", point, 1).Count
393 }
394 );
395 m_creatureTypes.Add(
396 new CreatureType("Tigers", SpawnLocationType.Surface, false, false) {
397 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
398 float num58 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
399 int humidity12 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
400 int num59 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
401 return num58 > 40f && humidity12 > 8 && point.Y < 80 && (num59 == 8 || num59 == 2 || num59 == 3 || num59 == 7) ? 0.025f : 0f;
402 },
403 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Tiger", point, 1).Count
404 }
405 );
406 m_creatureTypes.Add(
407 new CreatureType("White Tigers", SpawnLocationType.Surface, false, false) {
408 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
409 float num56 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
410 int temperature23 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
411 m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
412 int num57 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
413 return num56 > 40f
414 && temperature23 < 2
415 && point.Y < 90
416 && (num57 == 8 || num57 == 2 || num57 == 3 || num57 == 7 || num57 == 62)
417 ? 0.02f
418 : 0f;
419 },
420 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Tiger_White", point, 1).Count
421 }
422 );
423 m_creatureTypes.Add(
424 new CreatureType("Lions", SpawnLocationType.Surface, false, false) {
425 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
426 float num54 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
427 int temperature22 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
428 int num55 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
429 return num54 > 40f && temperature22 > 8 && point.Y < 80 && (num55 == 8 || num55 == 2 || num55 == 3 || num55 == 7)
430 ? 0.04f
431 : 0f;
432 },
433 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Lion", point, 1).Count
434 }
435 );
436 m_creatureTypes.Add(
437 new CreatureType("Jaguars", SpawnLocationType.Surface, false, false) {
438 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
439 float num52 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
440 int temperature21 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
441 int humidity11 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
442 int num53 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
443 return num52 > 40f
444 && humidity11 > 8
445 && temperature21 > 8
446 && point.Y < 100
447 && (num53 == 8 || num53 == 2 || num53 == 3 || num53 == 7 || num53 == 12)
448 ? 0.03f
449 : 0f;
450 },
451 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Jaguar", point, 1).Count
452 }
453 );
454 m_creatureTypes.Add(
455 new CreatureType("Leopards", SpawnLocationType.Surface, false, false) {
456 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
457 float num50 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
458 int temperature20 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
459 m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
460 int num51 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
461 return num50 > 40f
462 && temperature20 > 8
463 && point.Y < 120
464 && (num51 == 8 || num51 == 2 || num51 == 3 || num51 == 7 || num51 == 12)
465 ? 0.03f
466 : 0f;
467 },
468 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Leopard", point, 1).Count
469 }
470 );
471 m_creatureTypes.Add(
472 new CreatureType("Zebras", SpawnLocationType.Surface, false, false) {
473 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
474 float num48 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
475 int temperature19 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
476 int humidity10 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
477 int num49 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
478 return num48 > 20f && temperature19 > 8 && humidity10 > 7 && point.Y < 80 && (num49 == 8 || num49 == 2 || num49 == 3)
479 ? 0.05f
480 : 0f;
481 },
482 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Zebra", point, m_random.Int(1, 2)).Count
483 }
484 );
485 m_creatureTypes.Add(
486 new CreatureType("Gnus", SpawnLocationType.Surface, false, false) {
487 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
488 float num46 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
489 int temperature18 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
490 int num47 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
491 return num46 > 20f && temperature18 > 8 && point.Y < 80 && (num47 == 8 || num47 == 2 || num47 == 3) ? 0.05f : 0f;
492 },
493 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Gnu", point, m_random.Int(1, 2)).Count
494 }
495 );
496 m_creatureTypes.Add(
497 new CreatureType("Reindeers", SpawnLocationType.Surface, false, false) {
498 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
499 int temperature17 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
500 int num45 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
501 return temperature17 < 3 && point.Y < 90 && (num45 == 8 || num45 == 2 || num45 == 3 || num45 == 62) ? 0.05f : 0f;
502 },
503 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Reindeer", point, m_random.Int(1, 3)).Count
504 }
505 );
506 m_creatureTypes.Add(
507 new CreatureType("Mooses", SpawnLocationType.Surface, false, false) {
508 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
509 int temperature16 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
510 int num44 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
511 return temperature16 < 7 && point.Y < 90 && (num44 == 8 || num44 == 2 || num44 == 3 || num44 == 62) ? 0.1f : 0f;
512 },
513 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Moose", point, m_random.Int(1, 1)).Count
514 }
515 );
516 m_creatureTypes.Add(
517 new CreatureType("Bisons", SpawnLocationType.Surface, false, false) {
518 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
519 int temperature15 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
520 int humidity9 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
521 int num43 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
522 return temperature15 < 10 && humidity9 < 12 && point.Y < 80 && (num43 == 8 || num43 == 2 || num43 == 3 || num43 == 62)
523 ? 0.1f
524 : 0f;
525 },
526 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Bison", point, m_random.Int(1, 4)).Count
527 }
528 );
529 m_creatureTypes.Add(
530 new CreatureType("Ostriches", SpawnLocationType.Surface, false, false) {
531 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
532 float num41 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
533 int temperature14 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
534 int humidity8 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
535 int num42 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
536 return num41 > 20f && temperature14 > 8 && humidity8 < 8 && point.Y < 75 && (num42 == 8 || num42 == 2 || num42 == 7)
537 ? 0.05f
538 : 0f;
539 },
540 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Ostrich", point, m_random.Int(1, 2)).Count
541 }
542 );
543 m_creatureTypes.Add(
544 new CreatureType("Cassowaries", SpawnLocationType.Surface, false, false) {
545 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
546 float num39 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
547 int temperature13 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
548 int humidity7 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
549 int num40 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
550 return num39 > 20f && temperature13 > 8 && humidity7 < 12 && point.Y < 75 && (num40 == 8 || num40 == 2 || num40 == 7)
551 ? 0.05f
552 : 0f;
553 },
554 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Cassowary", point, 1).Count
555 }
556 );
557 m_creatureTypes.Add(
558 new CreatureType("Hyenas", SpawnLocationType.Surface, false, false) {
559 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
560 float num37 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
561 int temperature12 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
562 int num38 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
563 return num37 > 40f && temperature12 > 8 && point.Y < 80 && (num38 == 8 || num38 == 2 || num38 == 7) ? 0.05f : 0f;
564 },
565 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Hyena", point, m_random.Int(1, 2)).Count
566 }
567 );
568 m_creatureTypes.Add(
569 new CreatureType("Cave Bears", SpawnLocationType.Cave, false, false) {
570 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
571 int num36 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
572 return num36 == 3 || num36 == 67 || num36 == 4 || num36 == 66 || num36 == 2 || num36 == 7 ? 1f : 0f;
573 },
574 SpawnFunction = delegate(CreatureType creatureType, Point3 point) {
575 string templateName11 = m_random.Int(0, 1) == 0 ? "Bear_Black" : "Bear_Brown";
576 return SpawnCreatures(creatureType, templateName11, point, 1).Count;
577 }
578 }
579 );
580 m_creatureTypes.Add(
581 new CreatureType("Cave Tigers", SpawnLocationType.Cave, false, false) {
582 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
583 int num35 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
584 return num35 == 3 || num35 == 67 || num35 == 4 || num35 == 66 || num35 == 2 || num35 == 7 ? 0.25f : 0f;
585 },
586 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Tiger", point, 1).Count
587 }
588 );
589 m_creatureTypes.Add(
590 new CreatureType("Cave Lions", SpawnLocationType.Cave, false, false) {
591 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
592 int temperature11 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
593 int humidity6 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
594 int num34 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
595 return (num34 == 3 || num34 == 67 || num34 == 4 || num34 == 66 || num34 == 2 || num34 == 7)
596 && temperature11 > 8
597 && humidity6 < 8
598 ? 0.25f
599 : 0f;
600 },
601 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Lion", point, 1).Count
602 }
603 );
604 m_creatureTypes.Add(
605 new CreatureType("Cave Jaguars", SpawnLocationType.Cave, false, false) {
606 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
607 int num33 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
608 return num33 == 3 || num33 == 67 || num33 == 4 || num33 == 66 || num33 == 2 || num33 == 7 ? 0.5f : 0f;
609 },
610 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Jaguar", point, 1).Count
611 }
612 );
613 m_creatureTypes.Add(
614 new CreatureType("Cave Leopards", SpawnLocationType.Cave, false, false) {
615 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
616 int num32 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
617 return num32 == 3 || num32 == 67 || num32 == 4 || num32 == 66 || num32 == 2 || num32 == 7 ? 0.25f : 0f;
618 },
619 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Leopard", point, 1).Count
620 }
621 );
622 m_creatureTypes.Add(
623 new CreatureType("Cave Hyenas", SpawnLocationType.Cave, false, false) {
624 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
625 int temperature10 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
626 int num31 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
627 return (num31 == 3 || num31 == 67 || num31 == 4 || num31 == 66 || num31 == 2 || num31 == 7) && temperature10 > 8 ? 1f : 0f;
628 },
629 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Hyena", point, 1).Count
630 }
631 );
632 m_creatureTypes.Add(
633 new CreatureType("Bull Sharks", SpawnLocationType.Water, false, false) {
634 SpawnSuitabilityFunction =
635 (_, point) => !(m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z) < -2f) ? 0f : 0.4f,
636 SpawnFunction = delegate(CreatureType creatureType, Point3 point) {
637 string templateName10 = "Shark_Bull";
638 return SpawnCreatures(creatureType, templateName10, point, 1).Count;
639 }
640 }
641 );
642 m_creatureTypes.Add(
643 new CreatureType("Tiger Sharks", SpawnLocationType.Water, false, false) {
644 SpawnSuitabilityFunction =
645 (_, point) => !(m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z) < -5f) ? 0f : 0.3f,
646 SpawnFunction = delegate(CreatureType creatureType, Point3 point) {
647 string templateName9 = "Shark_Tiger";
648 return SpawnCreatures(creatureType, templateName9, point, 1).Count;
649 }
650 }
651 );
652 m_creatureTypes.Add(
653 new CreatureType("Great White Sharks", SpawnLocationType.Water, false, false) {
654 SpawnSuitabilityFunction =
655 (_, point) => !(m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z) < -20f) ? 0f : 0.2f,
656 SpawnFunction = delegate(CreatureType creatureType, Point3 point) {
657 string templateName8 = "Shark_GreatWhite";
658 return SpawnCreatures(creatureType, templateName8, point, 1).Count;
659 }
660 }
661 );
662 m_creatureTypes.Add(
663 new CreatureType("Barracudas", SpawnLocationType.Water, false, false) {
664 SpawnSuitabilityFunction =
665 (_, point) => !(m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z) < -2f) ? 0f : 0.5f,
666 SpawnFunction = delegate(CreatureType creatureType, Point3 point) {
667 string templateName7 = "Barracuda";
668 return SpawnCreatures(creatureType, templateName7, point, 1).Count;
669 }
670 }
671 );
672 m_creatureTypes.Add(
673 new CreatureType("Bass_Sea", SpawnLocationType.Water, false, false) {
674 SpawnSuitabilityFunction =
675 (_, point) => !(m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z) < -2f) ? 0f : 1f,
676 SpawnFunction = delegate(CreatureType creatureType, Point3 point) {
677 string templateName6 = "Bass_Sea";
678 return SpawnCreatures(creatureType, templateName6, point, 1).Count;
679 }
680 }
681 );
682 m_creatureTypes.Add(
683 new CreatureType("Bass_Freshwater", SpawnLocationType.Water, false, false) {
684 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
685 float num30 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
686 int temperature9 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
687 return num30 > 10f && temperature9 >= 4 ? 1f : 0f;
688 },
689 SpawnFunction = delegate(CreatureType creatureType, Point3 point) {
690 string templateName5 = "Bass_Freshwater";
691 return SpawnCreatures(creatureType, templateName5, point, m_random.Int(1, 2)).Count;
692 }
693 }
694 );
695 m_creatureTypes.Add(
696 new CreatureType("Rays", SpawnLocationType.Water, false, false) {
697 SpawnSuitabilityFunction =
698 (_, point) => !(m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z) < 10f) ? 1f : 0.5f,
699 SpawnFunction = delegate(CreatureType creatureType, Point3 point) {
700 int num27 = 0;
701 int num28 = 0;
702 for (int i = point.X - 2; i <= point.X + 2; i++) {
703 for (int j = point.Z - 2; j <= point.Z + 2; j++) {
704 if (m_subsystemTerrain.Terrain.GetCellContents(point.X, point.Y, point.Z) == 18) {
705 for (int num29 = point.Y - 1; num29 > 0; num29--) {
706 switch (m_subsystemTerrain.Terrain.GetCellContents(point.X, num29, point.Z)) {
707 case 2: num27++; break;
708 case 7: num28++; break;
709 default: continue;
710 }
711 break;
712 }
713 }
714 }
715 }
716 string templateName4 = num27 >= num28 ? "Ray_Brown" : "Ray_Yellow";
717 return SpawnCreatures(creatureType, templateName4, point, 1).Count;
718 }
719 }
720 );
721 m_creatureTypes.Add(
722 new CreatureType("Piranhas", SpawnLocationType.Water, false, false) {
723 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
724 float num26 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
725 int humidity5 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
726 int temperature8 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
727 return num26 > 10f && humidity5 >= 4 && temperature8 >= 7 ? 1f : 0f;
728 },
729 SpawnFunction = delegate(CreatureType creatureType, Point3 point) {
730 string templateName3 = "Piranha";
731 return SpawnCreatures(creatureType, templateName3, point, m_random.Int(2, 4)).Count;
732 }
733 }
734 );
735 m_creatureTypes.Add(
736 new CreatureType("Orcas", SpawnLocationType.Water, false, false) {
737 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
738 float num25 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
739 if (num25 < -100f) {
740 return 0.05f;
741 }
742 return num25 < -20f ? 0.01f : 0f;
743 },
744 SpawnFunction = delegate(CreatureType creatureType, Point3 point) {
745 string templateName2 = "Orca";
746 return SpawnCreatures(creatureType, templateName2, point, 1).Count;
747 }
748 }
749 );
750 m_creatureTypes.Add(
751 new CreatureType("Belugas", SpawnLocationType.Water, false, false) {
752 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
753 float num24 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
754 if (num24 < -100f) {
755 return 0.05f;
756 }
757 return num24 < -20f ? 0.01f : 0f;
758 },
759 SpawnFunction = delegate(CreatureType creatureType, Point3 point) {
760 string templateName = "Beluga";
761 return SpawnCreatures(creatureType, templateName, point, 1).Count;
762 }
763 }
764 );
765 m_creatureTypes.Add(
766 new CreatureType("Constant Gray Wolves", SpawnLocationType.Surface, false, true) {
767 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
768 if (m_subsystemSky.SkyLightIntensity < 0.1f) {
769 float num21 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
770 int humidity4 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
771 float num22 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
772 int num23 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
773 int cellLightFast10 = m_subsystemTerrain.Terrain.GetCellLightFast(point.X, point.Y + 1, point.Z);
774 if (((num21 > 20f && humidity4 >= 8) || (num22 <= 8f && point.Y < 90 && cellLightFast10 <= 7))
775 && (num23 == 8 || num23 == 2)) {
776 return 2f;
777 }
778 }
779 return 0f;
780 },
781 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Wolf_Gray", point, m_random.Int(1, 3)).Count
782 }
783 );
784 m_creatureTypes.Add(
785 new CreatureType("Constant Coyotes", SpawnLocationType.Surface, false, true) {
786 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
787 if (m_subsystemSky.SkyLightIntensity < 0.1f) {
788 float num17 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
789 float num18 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
790 float num19 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
791 int num20 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
792 int cellLightFast9 = m_subsystemTerrain.Terrain.GetCellLightFast(point.X, point.Y + 1, point.Z);
793 if (num17 > 20f
794 && num19 > 8f
795 && num18 < 8f
796 && point.Y < 90
797 && cellLightFast9 <= 7
798 && num20 == 7) {
799 return 2f;
800 }
801 }
802 return 0f;
803 },
804 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Wolf_Coyote", point, m_random.Int(1, 3)).Count
805 }
806 );
807 m_creatureTypes.Add(
808 new CreatureType("Constant Brown Bears", SpawnLocationType.Surface, false, true) {
809 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
810 if (m_subsystemSky.SkyLightIntensity < 0.1f) {
811 float num15 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
812 int temperature7 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
813 int humidity3 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
814 int num16 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
815 int cellLightFast8 = m_subsystemTerrain.Terrain.GetCellLightFast(point.X, point.Y + 1, point.Z);
816 if (num15 > 20f
817 && humidity3 >= 4
818 && temperature7 >= 8
819 && point.Y < 100
820 && cellLightFast8 <= 7
821 && (num16 == 8 || num16 == 2 || num16 == 3)) {
822 return 0.5f;
823 }
824 }
825 return 0f;
826 },
827 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Bear_Brown", point, 1).Count
828 }
829 );
830 m_creatureTypes.Add(
831 new CreatureType("Constant Black Bears", SpawnLocationType.Surface, false, true) {
832 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
833 if (m_subsystemSky.SkyLightIntensity < 0.1f) {
834 float num13 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
835 int temperature6 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
836 m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
837 int num14 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
838 int cellLightFast7 = m_subsystemTerrain.Terrain.GetCellLightFast(point.X, point.Y + 1, point.Z);
839 if (num13 > 20f
840 && temperature6 < 8
841 && point.Y < 110
842 && cellLightFast7 <= 7
843 && (num14 == 8 || num14 == 2 || num14 == 3)) {
844 return 0.5f;
845 }
846 }
847 return 0f;
848 },
849 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Bear_Black", point, 1).Count
850 }
851 );
852 m_creatureTypes.Add(
853 new CreatureType("Constant Polar Bears", SpawnLocationType.Surface, false, true) {
854 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
855 if (m_subsystemSky.SkyLightIntensity < 0.1f) {
856 float num11 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
857 int temperature5 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
858 int num12 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
859 int cellLightFast6 = m_subsystemTerrain.Terrain.GetCellLightFast(point.X, point.Y + 1, point.Z);
860 if (num11 > -40f
861 && temperature5 < 8
862 && point.Y < 90
863 && cellLightFast6 <= 7
864 && num12 == 62) {
865 return 0.25f;
866 }
867 }
868 return 0f;
869 },
870 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Bear_Black", point, 1).Count
871 }
872 );
873 m_creatureTypes.Add(
874 new CreatureType("Constant Tigers", SpawnLocationType.Surface, false, true) {
875 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
876 if (m_subsystemSky.SkyLightIntensity < 0.1f) {
877 float num9 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
878 int humidity2 = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
879 int num10 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
880 int cellLightFast5 = m_subsystemTerrain.Terrain.GetCellLightFast(point.X, point.Y + 1, point.Z);
881 if (num9 > 20f
882 && humidity2 > 8
883 && point.Y < 90
884 && cellLightFast5 <= 7
885 && (num10 == 8 || num10 == 2 || num10 == 3)) {
886 return 0.05f;
887 }
888 }
889 return 0f;
890 },
891 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Tiger", point, 1).Count
892 }
893 );
894 m_creatureTypes.Add(
895 new CreatureType("Constant Lions", SpawnLocationType.Surface, false, true) {
896 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
897 if (m_subsystemSky.SkyLightIntensity < 0.1f) {
898 float num7 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
899 int temperature4 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
900 int num8 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
901 int cellLightFast4 = m_subsystemTerrain.Terrain.GetCellLightFast(point.X, point.Y + 1, point.Z);
902 if (num7 > 20f
903 && temperature4 > 8
904 && point.Y < 90
905 && cellLightFast4 <= 7
906 && (num8 == 8 || num8 == 2 || num8 == 3 || num8 == 7)) {
907 return 0.25f;
908 }
909 }
910 return 0f;
911 },
912 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Lion", point, m_random.Int(1, 2)).Count
913 }
914 );
915 m_creatureTypes.Add(
916 new CreatureType("Constant Jaguars", SpawnLocationType.Surface, false, true) {
917 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
918 if (m_subsystemSky.SkyLightIntensity < 0.1f) {
919 float num5 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
920 int temperature3 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
921 int humidity = m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
922 int num6 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
923 int cellLightFast3 = m_subsystemTerrain.Terrain.GetCellLightFast(point.X, point.Y + 1, point.Z);
924 if (num5 > 20f
925 && temperature3 > 8
926 && humidity > 8
927 && point.Y < 100
928 && cellLightFast3 <= 7
929 && (num6 == 8 || num6 == 2 || num6 == 3 || num6 == 12)) {
930 return 0.25f;
931 }
932 }
933 return 0f;
934 },
935 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Jaguar", point, 1).Count
936 }
937 );
938 m_creatureTypes.Add(
939 new CreatureType("Constant Leopards", SpawnLocationType.Surface, false, true) {
940 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
941 if (m_subsystemSky.SkyLightIntensity < 0.1f) {
942 float num3 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
943 int temperature2 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
944 int num4 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
945 int cellLightFast2 = m_subsystemTerrain.Terrain.GetCellLightFast(point.X, point.Y + 1, point.Z);
946 if (num3 > 20f
947 && temperature2 > 8
948 && point.Y < 110
949 && cellLightFast2 <= 7
950 && (num4 == 8 || num4 == 2 || num4 == 3 || num4 == 12)) {
951 return 0.25f;
952 }
953 }
954 return 0f;
955 },
956 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Leopard", point, 1).Count
957 }
958 );
959 m_creatureTypes.Add(
960 new CreatureType("Constant Hyenas", SpawnLocationType.Surface, false, true) {
961 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
962 if (m_subsystemSky.SkyLightIntensity < 0.1f) {
963 float num = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
964 int temperature = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
965 int num2 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
966 int cellLightFast = m_subsystemTerrain.Terrain.GetCellLightFast(point.X, point.Y + 1, point.Z);
967 if (num > 20f
968 && temperature > 8
969 && point.Y < 100
970 && cellLightFast <= 7
971 && (num2 == 8 || num2 == 2 || num2 == 3 || num2 == 7)) {
972 return 1f;
973 }
974 }
975 return 0f;
976 },
977 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Hyena", point, m_random.Int(1, 2)).Count
978 }
979 );
980 m_creatureTypes.Add(
981 new CreatureType("Pigeon", SpawnLocationType.Surface, true, false) {
982 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
983 float num95 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
984 int temperature38 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
985 m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
986 int num96 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
987 int topHeight2 = m_subsystemTerrain.Terrain.GetTopHeight(point.X, point.Z);
988 return temperature38 > 3
989 && num95 > 30f
990 && point.Y >= topHeight2
991 && (BlocksManager.Blocks[num96] is LeavesBlock || num96 == 8 || num96 == 2 || num96 == 7)
992 ? 1.5f
993 : 0f;
994 },
995 SpawnFunction = (creatureType, point) => SpawnCreatures(creatureType, "Pigeon", point, 1).Count
996 }
997 );
998 m_creatureTypes.Add(
999 new CreatureType("Sparrow", SpawnLocationType.Surface, true, false) {
1000 SpawnSuitabilityFunction = delegate(CreatureType _, Point3 point) {
1001 float num93 = m_subsystemTerrain.TerrainContentsGenerator.CalculateOceanShoreDistance(point.X, point.Z);
1002 int temperature37 = m_subsystemTerrain.Terrain.GetTemperature(point.X, point.Z);
1003 m_subsystemTerrain.Terrain.GetHumidity(point.X, point.Z);
1004 int num94 = Terrain.ExtractContents(m_subsystemTerrain.Terrain.GetCellValueFast(point.X, point.Y - 1, point.Z));
1005 int topHeight = m_subsystemTerrain.Terrain.GetTopHeight(point.X, point.Z);
1006 return temperature37 > 3
1007 && num93 > 20f
1008 && point.Y >= topHeight
1009 && (BlocksManager.Blocks[num94] is LeavesBlock || num94 == 8 || num94 == 2 || num94 == 7)
1010 ? 1.5f
1011 : 0f;
1012 },
1013 SpawnFunction = delegate(CreatureType creatureType, Point3 point) {
1014 int count3 = m_random.Int(1, 2);
1015 return SpawnCreatures(creatureType, "Sparrow", point, count3).Count;
1016 }
1017 }
1018 );
1020 "InitializeCreatureTypes",
1021 modLoader => {
1022 modLoader.InitializeCreatureTypes(this, m_creatureTypes);
1023 return false;
1024 }
1025 );
1026 }
1027
1028 public virtual void SpawnRandomCreature() {
1029 if (CountCreatures(false) < m_totalLimit) {
1030 foreach (GameWidget gameWidget in m_subsystemViews.GameWidgets) {
1031 int num = 52;
1032 Vector2 v = new(gameWidget.ActiveCamera.ViewPosition.X, gameWidget.ActiveCamera.ViewPosition.Z);
1033 if (CountCreaturesInArea(v - new Vector2(68f), v + new Vector2(68f), false) >= num) {
1034 break;
1035 }
1036 SpawnLocationType spawnLocationType = GetRandomSpawnLocationType();
1037 Point3? spawnPoint = GetRandomSpawnPoint(gameWidget.ActiveCamera, spawnLocationType);
1038 if (spawnPoint.HasValue) {
1039 Vector2 c2 = new Vector2(spawnPoint.Value.X, spawnPoint.Value.Z) - new Vector2(16f);
1040 Vector2 c3 = new Vector2(spawnPoint.Value.X, spawnPoint.Value.Z) + new Vector2(16f);
1041 if (CountCreaturesInArea(c2, c3, false) >= 3) {
1042 break;
1043 }
1044 IEnumerable<CreatureType> source = m_creatureTypes.Where(c => c.SpawnLocationType == spawnLocationType && c.RandomSpawn);
1045 IEnumerable<CreatureType> creatureTypes = source as CreatureType[] ?? source.ToArray();
1046 IEnumerable<float> items = creatureTypes.Select(c => CalculateSpawnSuitability(c, spawnPoint.Value));
1047 int randomWeightedItem = GetRandomWeightedItem(items);
1048 if (randomWeightedItem >= 0) {
1049 CreatureType creatureType = creatureTypes.ElementAt(randomWeightedItem);
1050 creatureType.SpawnFunction(creatureType, spawnPoint.Value);
1051 }
1052 }
1053 }
1054 }
1055 }
1056
1057 public virtual void SpawnChunkCreatures(SpawnChunk chunk, int maxAttempts, bool constantSpawn) {
1058 int num = constantSpawn
1059 ? m_subsystemGameInfo.WorldSettings.GameMode >= GameMode.Challenging ? m_totalLimitConstantChallenging : m_totalLimitConstant
1060 : m_totalLimit;
1061 int num2 = constantSpawn ? m_areaLimitConstant : m_areaLimit;
1062 float v = constantSpawn ? m_areaRadiusConstant : m_areaRadius;
1063 int num3 = CountCreatures(constantSpawn);
1064 Vector2 c2 = new Vector2(chunk.Point.X * 16, chunk.Point.Y * 16) - new Vector2(v);
1065 Vector2 c3 = new Vector2((chunk.Point.X + 1) * 16, (chunk.Point.Y + 1) * 16) + new Vector2(v);
1066 int num4 = CountCreaturesInArea(c2, c3, constantSpawn);
1067 for (int i = 0; i < maxAttempts; i++) {
1068 if (num3 >= num) {
1069 break;
1070 }
1071 if (num4 >= num2) {
1072 break;
1073 }
1074 SpawnLocationType spawnLocationType = GetRandomSpawnLocationType();
1075 Point3? spawnPoint = GetRandomChunkSpawnPoint(chunk, spawnLocationType);
1076 if (spawnPoint.HasValue) {
1077 IEnumerable<CreatureType> source = m_creatureTypes.Where(c => c.SpawnLocationType == spawnLocationType
1078 && c.ConstantSpawn == constantSpawn
1079 );
1080 IEnumerable<CreatureType> creatureTypes = source as CreatureType[] ?? source.ToArray();
1081 IEnumerable<float> items = creatureTypes.Select(c => CalculateSpawnSuitability(c, spawnPoint.Value));
1082 int randomWeightedItem = GetRandomWeightedItem(items);
1083 if (randomWeightedItem >= 0) {
1084 CreatureType creatureType = creatureTypes.ElementAt(randomWeightedItem);
1085 int num5 = creatureType.SpawnFunction(creatureType, spawnPoint.Value);
1086 num3 += num5;
1087 num4 += num5;
1088 }
1089 }
1090 }
1091 }
1092
1093 public virtual List<Entity> SpawnCreatures(CreatureType creatureType, string templateName, Point3 point, int count) {
1094 List<Entity> list = new();
1095 int num = 0;
1096 while (count > 0
1097 && num < 50) {
1098 Point3 spawnPoint = point;
1099 if (num > 0) {
1100 spawnPoint.X += m_random.Int(-8, 8);
1101 spawnPoint.Y += m_random.Int(-4, 8);
1102 spawnPoint.Z += m_random.Int(-8, 8);
1103 }
1104 Point3? point2 = ProcessSpawnPoint(spawnPoint, creatureType.SpawnLocationType);
1105 if (point2.HasValue
1106 && CalculateSpawnSuitability(creatureType, point2.Value) > 0f) {
1107 Vector3 position = new(
1108 point2.Value.X + m_random.Float(0.4f, 0.6f),
1109 point2.Value.Y + 1.1f,
1110 point2.Value.Z + m_random.Float(0.4f, 0.6f)
1111 );
1112 Entity entity = SpawnCreature(templateName, position, creatureType.ConstantSpawn);
1113 if (entity != null) {
1114 list.Add(entity);
1115 count--;
1116 }
1117 }
1118 num++;
1119 }
1120 return list;
1121 }
1122
1123 public virtual Entity SpawnCreature(string templateName, Vector3 position, bool constantSpawn) {
1124 try {
1125 Entity entity = DatabaseManager.CreateEntity(Project, templateName, true);
1126 entity.FindComponent<ComponentBody>(true).Position = position;
1128 Vector3.UnitY,
1129 m_random.Float(0f, (float)Math.PI * 2f)
1130 );
1131 entity.FindComponent<ComponentCreature>(true).ConstantSpawn = constantSpawn;
1132 Project.AddEntity(entity);
1133 return entity;
1134 }
1135 catch (Exception ex) {
1136 Log.Error($"Unable to spawn creature with template \"{templateName}\". Reason: {ex}");
1137 return null;
1138 }
1139 }
1140
1141 public virtual Point3? GetRandomChunkSpawnPoint(SpawnChunk chunk, SpawnLocationType spawnLocationType) {
1142 for (int i = 0; i < 5; i++) {
1143 int x = 16 * chunk.Point.X + m_random.Int(0, 15);
1144 int y = m_random.Int(10, 246);
1145 int z = 16 * chunk.Point.Y + m_random.Int(0, 15);
1146 Point3? result = ProcessSpawnPoint(new Point3(x, y, z), spawnLocationType);
1147 if (result.HasValue) {
1148 return result;
1149 }
1150 }
1151 return null;
1152 }
1153
1154 public virtual Point3? GetRandomSpawnPoint(Camera camera, SpawnLocationType spawnLocationType) {
1155 for (int i = 0; i < 10; i++) {
1156 int x = Terrain.ToCell(camera.ViewPosition.X) + m_random.Sign() * m_random.Int(24, 48);
1157 int y = Math.Clamp(Terrain.ToCell(camera.ViewPosition.Y) + m_random.Int(-30, 30), 2, 254);
1158 int z = Terrain.ToCell(camera.ViewPosition.Z) + m_random.Sign() * m_random.Int(24, 48);
1159 Point3? result = ProcessSpawnPoint(new Point3(x, y, z), spawnLocationType);
1160 if (result.HasValue) {
1161 return result;
1162 }
1163 }
1164 return null;
1165 }
1166
1167 public virtual Point3? ProcessSpawnPoint(Point3 spawnPoint, SpawnLocationType spawnLocationType) {
1168 int x = spawnPoint.X;
1169 int num = Math.Clamp(spawnPoint.Y, 1, 254);
1170 int z = spawnPoint.Z;
1171 TerrainChunk chunkAtCell = m_subsystemTerrain.Terrain.GetChunkAtCell(x, z);
1172 if (chunkAtCell != null
1173 && chunkAtCell.State > TerrainChunkState.InvalidPropagatedLight) {
1174 for (int i = 0; i < 30; i++) {
1175 Point3 point = new(x, num + i, z);
1176 if (TestSpawnPoint(point, spawnLocationType)) {
1177 return point;
1178 }
1179 Point3 point2 = new(x, num - i, z);
1180 if (TestSpawnPoint(point2, spawnLocationType)) {
1181 return point2;
1182 }
1183 }
1184 }
1185 return null;
1186 }
1187
1188 public virtual bool TestSpawnPoint(Point3 spawnPoint, SpawnLocationType spawnLocationType) {
1189 int x = spawnPoint.X;
1190 int y = spawnPoint.Y;
1191 int z = spawnPoint.Z;
1192 if (y <= 3
1193 || y >= TerrainChunk.Height - 3) {
1194 return false;
1195 }
1196 switch (spawnLocationType) {
1197 case SpawnLocationType.Surface: {
1198 int cellLightFast2 = m_subsystemTerrain.Terrain.GetCellLightFast(x, y, z);
1199 if (m_subsystemSky.SkyLightValue - cellLightFast2 > 3) {
1200 return false;
1201 }
1202 int cellValueFast7 = m_subsystemTerrain.Terrain.GetCellValueFast(x, y - 1, z);
1203 int cellValueFast8 = m_subsystemTerrain.Terrain.GetCellValueFast(x, y, z);
1204 int cellValueFast9 = m_subsystemTerrain.Terrain.GetCellValueFast(x, y + 1, z);
1205 Block block6 = BlocksManager.Blocks[Terrain.ExtractContents(cellValueFast7)];
1206 Block block7 = BlocksManager.Blocks[Terrain.ExtractContents(cellValueFast8)];
1207 Block block8 = BlocksManager.Blocks[Terrain.ExtractContents(cellValueFast9)];
1208 if ((block6.IsCollidable_(cellValueFast7) || block6 is WaterBlock)
1209 && !block7.IsCollidable_(cellValueFast8)
1210 && !(block7 is WaterBlock)
1211 && !block8.IsCollidable_(cellValueFast9)) {
1212 return !(block8 is WaterBlock);
1213 }
1214 return false;
1215 }
1216 case SpawnLocationType.Cave: {
1217 int cellLightFast = m_subsystemTerrain.Terrain.GetCellLightFast(x, y, z);
1218 if (m_subsystemSky.SkyLightValue - cellLightFast < 5) {
1219 return false;
1220 }
1221 int cellValueFast4 = m_subsystemTerrain.Terrain.GetCellValueFast(x, y - 1, z);
1222 int cellValueFast5 = m_subsystemTerrain.Terrain.GetCellValueFast(x, y, z);
1223 int cellValueFast6 = m_subsystemTerrain.Terrain.GetCellValueFast(x, y + 1, z);
1224 Block block3 = BlocksManager.Blocks[Terrain.ExtractContents(cellValueFast4)];
1225 Block block4 = BlocksManager.Blocks[Terrain.ExtractContents(cellValueFast5)];
1226 Block block5 = BlocksManager.Blocks[Terrain.ExtractContents(cellValueFast6)];
1227 if ((block3.IsCollidable_(cellValueFast4) || block3 is WaterBlock)
1228 && !block4.IsCollidable_(cellValueFast5)
1229 && !(block4 is WaterBlock)
1230 && !block5.IsCollidable_(cellValueFast6)) {
1231 return !(block5 is WaterBlock);
1232 }
1233 return false;
1234 }
1235 case SpawnLocationType.Water: {
1236 int cellContentsFast = m_subsystemTerrain.Terrain.GetCellContentsFast(x, y, z);
1237 int cellValueFast2 = m_subsystemTerrain.Terrain.GetCellValueFast(x, y + 1, z);
1238 int cellValueFast3 = m_subsystemTerrain.Terrain.GetCellValueFast(x, y + 2, z);
1239 Block obj = BlocksManager.Blocks[Terrain.ExtractContents(cellContentsFast)];
1240 Block block = BlocksManager.Blocks[Terrain.ExtractContents(cellValueFast2)];
1241 Block block2 = BlocksManager.Blocks[Terrain.ExtractContents(cellValueFast3)];
1242 if (obj is WaterBlock
1243 && !block.IsCollidable_(cellValueFast2)) {
1244 return !block2.IsCollidable_(cellValueFast3);
1245 }
1246 return false;
1247 }
1248 default: throw new InvalidOperationException("Unknown spawn location type.");
1249 }
1250 }
1251
1252 public virtual float CalculateSpawnSuitability(CreatureType creatureType, Point3 spawnPoint) {
1253 float num = creatureType.SpawnSuitabilityFunction(creatureType, spawnPoint);
1254 if (CountCreatures(creatureType) > 8) {
1255 num *= 0.25f;
1256 }
1257 return num;
1258 }
1259
1260 public virtual int CountCreatures(CreatureType creatureType) {
1261 int num = 0;
1262 foreach (ComponentBody body in m_subsystemBodies.Bodies) {
1263 if (body.Entity.ValuesDictionary.DatabaseObject.Name == creatureType.Name) {
1264 num++;
1265 }
1266 }
1267 return num;
1268 }
1269
1270 public virtual int CountCreatures(bool constantSpawn) {
1271 int num = 0;
1272 foreach (ComponentBody body in m_subsystemBodies.Bodies) {
1273 ComponentCreature componentCreature = body.Entity.FindComponent<ComponentCreature>();
1274 if (componentCreature != null
1275 && componentCreature.ConstantSpawn == constantSpawn) {
1276 num++;
1277 }
1278 }
1279 return num;
1280 }
1281
1282 public virtual int CountCreaturesInArea(Vector2 c1, Vector2 c2, bool constantSpawn) {
1283 int num = 0;
1284 m_componentBodies.Clear();
1285 m_subsystemBodies.FindBodiesInArea(c1, c2, m_componentBodies);
1286 for (int i = 0; i < m_componentBodies.Count; i++) {
1287 ComponentBody componentBody = m_componentBodies.Array[i];
1288 ComponentCreature componentCreature = componentBody.Entity.FindComponent<ComponentCreature>();
1289 if (componentCreature != null
1290 && componentCreature.ConstantSpawn == constantSpawn) {
1291 Vector3 position = componentBody.Position;
1292 if (position.X >= c1.X
1293 && position.X <= c2.X
1294 && position.Z >= c1.Y
1295 && position.Z <= c2.Y) {
1296 num++;
1297 }
1298 }
1299 }
1300 Point2 point = Terrain.ToChunk(c1);
1301 Point2 point2 = Terrain.ToChunk(c2);
1302 for (int j = point.X; j <= point2.X; j++) {
1303 for (int k = point.Y; k <= point2.Y; k++) {
1304 SpawnChunk spawnChunk = m_subsystemSpawn.GetSpawnChunk(new Point2(j, k));
1305 if (spawnChunk != null) {
1306 foreach (SpawnEntityData spawnsDatum in spawnChunk.SpawnsData) {
1307 if (spawnsDatum.ConstantSpawn == constantSpawn) {
1308 Vector3 position2 = spawnsDatum.Position;
1309 if (position2.X >= c1.X
1310 && position2.X <= c2.X
1311 && position2.Z >= c1.Y
1312 && position2.Z <= c2.Y) {
1313 num++;
1314 }
1315 }
1316 }
1317 }
1318 }
1319 }
1320 return num;
1321 }
1322
1323 public virtual int GetRandomWeightedItem(IEnumerable<float> items) {
1324 IEnumerable<float> enumerable = items as float[] ?? items.ToArray();
1325 float max = MathUtils.Max(enumerable.Sum(), 1f);
1326 float num = m_random.Float(0f, max);
1327 int num2 = 0;
1328 foreach (float item in enumerable) {
1329 if (num < item) {
1330 return num2;
1331 }
1332 num -= item;
1333 num2++;
1334 }
1335 return -1;
1336 }
1337
1339 float num = m_random.Float();
1340 if (num <= 0.3f) {
1341 return SpawnLocationType.Surface;
1342 }
1343 if (num <= 0.6f) {
1344 return SpawnLocationType.Cave;
1345 }
1346 return SpawnLocationType.Water;
1347 }
1348 }
1349}
static void Error(object message)
定义 Log.cs:80
static int Min(int x1, int x2)
static int Max(int x1, int x2)
virtual bool IsCollidable_(int value)
Vector3 ViewPosition
static Entity CreateEntity(Project project, SpawnEntityData spawnEntityData, bool throwIfNotFound)
static IList< int > GetEnumValues(Type type)
float Float()
List< SpawnEntityData > SpawnsData
CreatureType(string name, SpawnLocationType spawnLocationType, bool randomSpawn, bool constantSpawn)
Func< CreatureType, Point3, float > SpawnSuitabilityFunction
DynamicArray< ComponentBody > m_componentBodies
virtual void SpawnChunkCreatures(SpawnChunk chunk, int maxAttempts, bool constantSpawn)
virtual float CalculateSpawnSuitability(CreatureType creatureType, Point3 spawnPoint)
override void Load(ValuesDictionary valuesDictionary)
virtual int CountCreatures(CreatureType creatureType)
virtual List< Entity > SpawnCreatures(CreatureType creatureType, string templateName, Point3 point, int count)
virtual Entity SpawnCreature(string templateName, Vector3 position, bool constantSpawn)
virtual bool TestSpawnPoint(Point3 spawnPoint, SpawnLocationType spawnLocationType)
virtual ? Point3 ProcessSpawnPoint(Point3 spawnPoint, SpawnLocationType spawnLocationType)
static SpawnLocationType[] m_spawnLocations
virtual int CountCreaturesInArea(Vector2 c1, Vector2 c2, bool constantSpawn)
virtual ? Point3 GetRandomSpawnPoint(Camera camera, SpawnLocationType spawnLocationType)
Dictionary< ComponentCreature, bool > m_creatures
virtual int CountCreatures(bool constantSpawn)
Dictionary< ComponentCreature, bool >.KeyCollection Creatures
virtual SpawnLocationType GetRandomSpawnLocationType()
override void OnEntityAdded(Entity entity)
virtual ? Point3 GetRandomChunkSpawnPoint(SpawnChunk chunk, SpawnLocationType spawnLocationType)
override void OnEntityRemoved(Entity entity)
virtual int GetRandomWeightedItem(IEnumerable< float > items)
TerrainChunkState State
static Point2 ToChunk(Vector2 p)
static int ExtractContents(int value)
static int ToCell(float x)
virtual int GetTemperature(int x, int z)
ValuesDictionary ValuesDictionary
Component FindComponent(Type type, string name, bool throwOnError)
ValuesDictionary ValuesDictionary
Camera ActiveCamera
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
static Quaternion CreateFromAxisAngle(Vector3 axis, float angle)
static readonly Vector3 UnitY