Terraria 1.4.0.5 Source Code

This commit is contained in:
MikeyIsBaeYT 2021-10-26 12:45:26 -04:00
commit 05205f009e
1059 changed files with 563450 additions and 0 deletions

View file

@ -0,0 +1,22 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Generation.ActionGrass
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Terraria.WorldBuilding;
namespace Terraria.GameContent.Generation
{
public class ActionGrass : GenAction
{
public override bool Apply(Point origin, int x, int y, params object[] args)
{
if (GenBase._tiles[x, y].active() || GenBase._tiles[x, y - 1].active())
return false;
WorldGen.PlaceTile(x, y, (int) Utils.SelectRandom<ushort>(GenBase._random, (ushort) 3, (ushort) 73), true);
return this.UnitApply(origin, x, y, args);
}
}
}

View file

@ -0,0 +1,26 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Generation.ActionPlaceStatue
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Terraria.DataStructures;
using Terraria.WorldBuilding;
namespace Terraria.GameContent.Generation
{
public class ActionPlaceStatue : GenAction
{
private int _statueIndex;
public ActionPlaceStatue(int index = -1) => this._statueIndex = index;
public override bool Apply(Point origin, int x, int y, params object[] args)
{
Point16 point16 = this._statueIndex != -1 ? WorldGen.statueList[this._statueIndex] : WorldGen.statueList[GenBase._random.Next(2, WorldGen.statueList.Length)];
WorldGen.PlaceTile(x, y, (int) point16.X, true, style: ((int) point16.Y));
return this.UnitApply(origin, x, y, args);
}
}
}

View file

@ -0,0 +1,20 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Generation.ActionStalagtite
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Terraria.WorldBuilding;
namespace Terraria.GameContent.Generation
{
public class ActionStalagtite : GenAction
{
public override bool Apply(Point origin, int x, int y, params object[] args)
{
WorldGen.PlaceTight(x, y);
return this.UnitApply(origin, x, y, args);
}
}
}

View file

@ -0,0 +1,37 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Generation.ActionVines
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using Terraria.WorldBuilding;
namespace Terraria.GameContent.Generation
{
public class ActionVines : GenAction
{
private int _minLength;
private int _maxLength;
private int _vineId;
public ActionVines(int minLength = 6, int maxLength = 10, int vineId = 52)
{
this._minLength = minLength;
this._maxLength = maxLength;
this._vineId = vineId;
}
public override bool Apply(Point origin, int x, int y, params object[] args)
{
int num1 = GenBase._random.Next(this._minLength, this._maxLength + 1);
int num2;
for (num2 = 0; num2 < num1 && !GenBase._tiles[x, y + num2].active(); ++num2)
{
GenBase._tiles[x, y + num2].type = (ushort) this._vineId;
GenBase._tiles[x, y + num2].active(true);
}
return num2 > 0 && this.UnitApply(origin, x, y, args);
}
}
}

View file

@ -0,0 +1,825 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Generation.PassLegacy
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using System.Collections.Generic;
using Terraria.IO;
using Terraria.WorldBuilding;
namespace Terraria.GameContent.Generation
{
public class PassLegacy : GenPass
{
private static readonly Dictionary<string, float> _weightMap_135 = new Dictionary<string, float>()
{
{
"Reset",
2.2056f
},
{
"Terrain",
449.3722f
},
{
"Tunnels",
5.379f
},
{
"Dunes",
779.3144f
},
{
"Mount Caves",
36.1749f
},
{
"Dirt Wall Backgrounds",
238.8786f
},
{
"Rocks In Dirt",
1539.898f
},
{
"Dirt In Rocks",
1640.048f
},
{
"Clay",
302.2475f
},
{
"Small Holes",
3047.099f
},
{
"Dirt Layer Caves",
250.0248f
},
{
"Rock Layer Caves",
2635.903f
},
{
"Surface Caves",
41.3442f
},
{
"Slush Check",
62.3121f
},
{
"Grass",
27.8485f
},
{
"Jungle",
10154.65f
},
{
"Marble",
3140.926f
},
{
"Granite",
6769.554f
},
{
"Mud Caves To Grass",
29042.46f
},
{
"Full Desert",
7802.509f
},
{
"Floating Islands",
1504.831f
},
{
"Mushroom Patches",
1001.21f
},
{
"Mud To Dirt",
355.9895f
},
{
"Silt",
198.4567f
},
{
"Shinies",
253.9256f
},
{
"Webs",
53.7234f
},
{
"Underworld",
9213.443f
},
{
"Lakes",
14.6001f
},
{
"Corruption",
1367.068f
},
{
"Dungeon",
386.8962f
},
{
"Slush",
56.7959f
},
{
"Mountain Caves",
14.2958f
},
{
"Beaches",
7.6043f
},
{
"Gems",
1016.745f
},
{
"Gravitating Sand",
875.1385f
},
{
"Clean Up Dirt",
632.9365f
},
{
"Pyramids",
0.3045f
},
{
"Dirt Rock Wall Runner",
24.1628f
},
{
"Living Trees",
5.6897f
},
{
"Wood Tree Walls",
72.6673f
},
{
"Altars",
24.975f
},
{
"Wet Jungle",
18.2339f
},
{
"Remove Water From Sand",
14.3244f
},
{
"Jungle Temple",
838.0293f
},
{
"Hives",
7194.68f
},
{
"Jungle Chests",
2.3522f
},
{
"Smooth World",
6418.349f
},
{
"Settle Liquids",
13069.07f
},
{
"Waterfalls",
4614.806f
},
{
"Ice",
236.3986f
},
{
"Wall Variety",
5988.028f
},
{
"Traps",
113.9219f
},
{
"Life Crystals",
3.4912f
},
{
"Statues",
72.0258f
},
{
"Buried Chests",
2371.881f
},
{
"Surface Chests",
22.1015f
},
{
"Jungle Chests Placement",
11.6857f
},
{
"Water Chests",
18.6092f
},
{
"Spider Caves",
8218.94f
},
{
"Gem Caves",
96.4863f
},
{
"Moss",
4440.283f
},
{
"Temple",
12.6321f
},
{
"Ice Walls",
8744.889f
},
{
"Jungle Trees",
933.2522f
},
{
"Floating Island Houses",
2.8349f
},
{
"Quick Cleanup",
1339.91f
},
{
"Pots",
1363.35f
},
{
"Spreading Grass",
80.3414f
},
{
"Piles",
274.4605f
},
{
"Cactus",
30.4524f
},
{
"Spawn Point",
0.3068f
},
{
"Grass Wall",
512.8323f
},
{
"Guide",
3.1494f
},
{
"Sunflowers",
4.7643f
},
{
"Planting Trees",
356.2866f
},
{
"Herbs",
123.8192f
},
{
"Dye Plants",
437.3852f
},
{
"Webs And Honey",
770.3133f
},
{
"Weeds",
224.6974f
},
{
"Mud Caves To Grass 2",
737.635f
},
{
"Jungle Plants",
1037.098f
},
{
"Vines",
897.331f
},
{
"Flowers",
1.3216f
},
{
"Mushrooms",
0.7789f
},
{
"Stalac",
1079.509f
},
{
"Gems In Ice Biome",
14.8002f
},
{
"Random Gems",
15.3893f
},
{
"Moss Grass",
770.8217f
},
{
"Muds Walls In Jungle",
73.5705f
},
{
"Larva",
0.5222f
},
{
"Settle Liquids Again",
7461.561f
},
{
"Tile Cleanup",
1813.04f
},
{
"Lihzahrd Altars",
0.2171f
},
{
"Micro Biomes",
24240.07f
},
{
"Final Cleanup",
1768.462f
}
};
private static readonly Dictionary<string, float> _weightMap = new Dictionary<string, float>()
{
{
"Reset",
0.9667f
},
{
"Terrain",
507.352f
},
{
"Dunes",
239.7913f
},
{
"Ocean Sand",
10.4129f
},
{
"Sand Patches",
452.6755f
},
{
"Tunnels",
4.3622f
},
{
"Mount Caves",
49.9993f
},
{
"Dirt Wall Backgrounds",
328.7817f
},
{
"Rocks In Dirt",
1537.466f
},
{
"Dirt In Rocks",
1515.23f
},
{
"Clay",
314.8327f
},
{
"Small Holes",
2955.926f
},
{
"Dirt Layer Caves",
238.2545f
},
{
"Rock Layer Caves",
2708.396f
},
{
"Surface Caves",
42.3857f
},
{
"Generate Ice Biome",
100.005f
},
{
"Grass",
29.7885f
},
{
"Jungle",
11205.83f
},
{
"Marble",
5358.884f
},
{
"Granite",
2142.664f
},
{
"Mud Caves To Grass",
3319.761f
},
{
"Full Desert",
9730.408f
},
{
"Floating Islands",
1364.346f
},
{
"Mushroom Patches",
743.7686f
},
{
"Dirt To Mud",
351.3519f
},
{
"Silt",
211.84f
},
{
"Shinies",
237.4298f
},
{
"Webs",
50.6646f
},
{
"Underworld",
8936.494f
},
{
"Lakes",
12.1766f
},
{
"Corruption",
1094.237f
},
{
"Dungeon",
477.1963f
},
{
"Slush",
55.1857f
},
{
"Mountain Caves",
11.4819f
},
{
"Beaches",
7.8287f
},
{
"Gems",
895.426f
},
{
"Gravitating Sand",
933.5295f
},
{
"Clean Up Dirt",
697.0276f
},
{
"Pyramids",
6.6884f
},
{
"Dirt Rock Wall Runner",
24.7648f
},
{
"Living Trees",
4.937f
},
{
"Wood Tree Walls",
76.8709f
},
{
"Altars",
72.6607f
},
{
"Wet Jungle",
23.492f
},
{
"Remove Water From Sand",
22.0898f
},
{
"Jungle Temple",
595.8422f
},
{
"Hives",
371.392f
},
{
"Jungle Chests",
0.5896f
},
{
"Smooth World",
5841.608f
},
{
"Settle Liquids",
9398.525f
},
{
"Waterfalls",
4118.666f
},
{
"Ice",
163.0777f
},
{
"Wall Variety",
5264.021f
},
{
"Life Crystals",
2.7582f
},
{
"Statues",
64.5737f
},
{
"Buried Chests",
1102.553f
},
{
"Surface Chests",
12.8337f
},
{
"Jungle Chests Placement",
1.3546f
},
{
"Water Chests",
12.5981f
},
{
"Spider Caves",
475.4143f
},
{
"Gem Caves",
36.0143f
},
{
"Moss",
655.8314f
},
{
"Temple",
5.6917f
},
{
"Ice Walls",
957.0317f
},
{
"Jungle Trees",
817.2459f
},
{
"Floating Island Houses",
1.5022f
},
{
"Quick Cleanup",
1374.467f
},
{
"Pots",
1638.609f
},
{
"Hellforge",
2.8645f
},
{
"Spreading Grass",
127.7581f
},
{
"Place Fallen Log",
17.3377f
},
{
"Traps",
562.9085f
},
{
"Piles",
288.3675f
},
{
"Spawn Point",
0.012f
},
{
"Grass Wall",
604.9992f
},
{
"Guide",
0.016f
},
{
"Sunflowers",
4.1757f
},
{
"Planting Trees",
325.0993f
},
{
"Cactus & Coral",
31.6349f
},
{
"Herbs",
120.1871f
},
{
"Dye Plants",
226.6394f
},
{
"Webs And Honey",
608.9524f
},
{
"Weeds",
187.9759f
},
{
"Mud Caves To Grass 2",
686.4958f
},
{
"Jungle Plants",
1295.038f
},
{
"Vines",
1132.555f
},
{
"Flowers",
16.7723f
},
{
"Mushrooms",
0.2294f
},
{
"Gems In Ice Biome",
10.3092f
},
{
"Random Gems",
18.4925f
},
{
"Moss Grass",
687.742f
},
{
"Muds Walls In Jungle",
89.7739f
},
{
"Larva",
0.2074f
},
{
"Settle Liquids Again",
7073.647f
},
{
"Tile Cleanup",
1896.76f
},
{
"Lihzahrd Altars",
0.0071f
},
{
"Micro Biomes",
3547.43f
},
{
"Stalac",
1180.906f
},
{
"Remove Broken Traps",
1293.425f
},
{
"Final Cleanup",
2080.294f
}
};
private readonly WorldGenLegacyMethod _method;
public PassLegacy(string name, WorldGenLegacyMethod method)
: base(name, PassLegacy.GetWeight(name))
{
this._method = method;
}
public PassLegacy(string name, WorldGenLegacyMethod method, float weight)
: base(name, weight)
{
this._method = method;
}
private static float GetWeight(string name)
{
float num;
if (!PassLegacy._weightMap.TryGetValue(name, out num))
num = 1f;
return num;
}
protected override void ApplyPass(GenerationProgress progress, GameConfiguration configuration) => this._method(progress, configuration);
}
}

View file

@ -0,0 +1,69 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Generation.ShapeBranch
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using Terraria.WorldBuilding;
namespace Terraria.GameContent.Generation
{
public class ShapeBranch : GenShape
{
private Point _offset;
private List<Point> _endPoints;
public ShapeBranch() => this._offset = new Point(10, -5);
public ShapeBranch(Point offset) => this._offset = offset;
public ShapeBranch(double angle, double distance) => this._offset = new Point((int) (Math.Cos(angle) * distance), (int) (Math.Sin(angle) * distance));
private bool PerformSegment(Point origin, GenAction action, Point start, Point end, int size)
{
size = Math.Max(1, size);
for (int index1 = -(size >> 1); index1 < size - (size >> 1); ++index1)
{
for (int index2 = -(size >> 1); index2 < size - (size >> 1); ++index2)
{
if (!Utils.PlotLine(new Point(start.X + index1, start.Y + index2), end, (Utils.TileActionAttempt) ((tileX, tileY) => this.UnitApply(action, origin, tileX, tileY) || !this._quitOnFail), false))
return false;
}
}
return true;
}
public override bool Perform(Point origin, GenAction action)
{
float num1 = new Vector2((float) this._offset.X, (float) this._offset.Y).Length();
int size = (int) ((double) num1 / 6.0);
if (this._endPoints != null)
this._endPoints.Add(new Point(origin.X + this._offset.X, origin.Y + this._offset.Y));
if (!this.PerformSegment(origin, action, origin, new Point(origin.X + this._offset.X, origin.Y + this._offset.Y), size))
return false;
int num2 = (int) ((double) num1 / 8.0);
for (int index = 0; index < num2; ++index)
{
float num3 = (float) (((double) index + 1.0) / ((double) num2 + 1.0));
Point point1 = new Point((int) ((double) num3 * (double) this._offset.X), (int) ((double) num3 * (double) this._offset.Y));
Vector2 spinningpoint = new Vector2((float) (this._offset.X - point1.X), (float) (this._offset.Y - point1.Y));
spinningpoint = spinningpoint.RotatedBy((GenBase._random.NextDouble() * 0.5 + 1.0) * (GenBase._random.Next(2) == 0 ? -1.0 : 1.0)) * 0.75f;
Point point2 = new Point((int) spinningpoint.X + point1.X, (int) spinningpoint.Y + point1.Y);
if (this._endPoints != null)
this._endPoints.Add(new Point(point2.X + origin.X, point2.Y + origin.Y));
if (!this.PerformSegment(origin, action, new Point(point1.X + origin.X, point1.Y + origin.Y), new Point(point2.X + origin.X, point2.Y + origin.Y), size - 1))
return false;
}
return true;
}
public ShapeBranch OutputEndpoints(List<Point> endpoints)
{
this._endPoints = endpoints;
return this;
}
}
}

View file

@ -0,0 +1,55 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Generation.ShapeFloodFill
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using Terraria.DataStructures;
using Terraria.WorldBuilding;
namespace Terraria.GameContent.Generation
{
public class ShapeFloodFill : GenShape
{
private int _maximumActions;
public ShapeFloodFill(int maximumActions = 100) => this._maximumActions = maximumActions;
public override bool Perform(Point origin, GenAction action)
{
Queue<Point> pointQueue = new Queue<Point>();
HashSet<Point16> point16Set = new HashSet<Point16>();
pointQueue.Enqueue(origin);
int maximumActions = this._maximumActions;
while (pointQueue.Count > 0 && maximumActions > 0)
{
Point point = pointQueue.Dequeue();
if (!point16Set.Contains(new Point16(point.X, point.Y)) && this.UnitApply(action, origin, point.X, point.Y))
{
point16Set.Add(new Point16(point));
--maximumActions;
if (point.X + 1 < Main.maxTilesX - 1)
pointQueue.Enqueue(new Point(point.X + 1, point.Y));
if (point.X - 1 >= 1)
pointQueue.Enqueue(new Point(point.X - 1, point.Y));
if (point.Y + 1 < Main.maxTilesY - 1)
pointQueue.Enqueue(new Point(point.X, point.Y + 1));
if (point.Y - 1 >= 1)
pointQueue.Enqueue(new Point(point.X, point.Y - 1));
}
}
while (pointQueue.Count > 0)
{
Point point = pointQueue.Dequeue();
if (!point16Set.Contains(new Point16(point.X, point.Y)))
{
pointQueue.Enqueue(point);
break;
}
}
return pointQueue.Count == 0;
}
}
}

View file

@ -0,0 +1,59 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Generation.ShapeRoot
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using System;
using Terraria.WorldBuilding;
namespace Terraria.GameContent.Generation
{
public class ShapeRoot : GenShape
{
private float _angle;
private float _startingSize;
private float _endingSize;
private float _distance;
public ShapeRoot(float angle, float distance = 10f, float startingSize = 4f, float endingSize = 1f)
{
this._angle = angle;
this._distance = distance;
this._startingSize = startingSize;
this._endingSize = endingSize;
}
private bool DoRoot(
Point origin,
GenAction action,
float angle,
float distance,
float startingSize)
{
float x = (float) origin.X;
float y = (float) origin.Y;
for (float num1 = 0.0f; (double) num1 < (double) distance * 0.850000023841858; ++num1)
{
float amount = num1 / distance;
float num2 = MathHelper.Lerp(startingSize, this._endingSize, amount);
x += (float) Math.Cos((double) angle);
y += (float) Math.Sin((double) angle);
angle += (float) ((double) GenBase._random.NextFloat() - 0.5 + (double) GenBase._random.NextFloat() * ((double) this._angle - 1.57079637050629) * 0.100000001490116 * (1.0 - (double) amount));
angle = (float) ((double) angle * 0.400000005960464 + 0.449999988079071 * (double) MathHelper.Clamp(angle, this._angle - (float) (2.0 * (1.0 - 0.5 * (double) amount)), this._angle + (float) (2.0 * (1.0 - 0.5 * (double) amount))) + (double) MathHelper.Lerp(this._angle, 1.570796f, amount) * 0.150000005960464);
for (int index1 = 0; index1 < (int) num2; ++index1)
{
for (int index2 = 0; index2 < (int) num2; ++index2)
{
if (!this.UnitApply(action, origin, (int) x + index1, (int) y + index2) && this._quitOnFail)
return false;
}
}
}
return true;
}
public override bool Perform(Point origin, GenAction action) => this.DoRoot(origin, action, this._angle, this._distance, this._startingSize);
}
}

View file

@ -0,0 +1,62 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Generation.ShapeRunner
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using System;
using Terraria.WorldBuilding;
namespace Terraria.GameContent.Generation
{
public class ShapeRunner : GenShape
{
private float _startStrength;
private int _steps;
private Vector2 _startVelocity;
public ShapeRunner(float strength, int steps, Vector2 velocity)
{
this._startStrength = strength;
this._steps = steps;
this._startVelocity = velocity;
}
public override bool Perform(Point origin, GenAction action)
{
float num1 = (float) this._steps;
float steps = (float) this._steps;
double num2 = (double) this._startStrength;
Vector2 vector2_1 = new Vector2((float) origin.X, (float) origin.Y);
Vector2 vector2_2 = this._startVelocity == Vector2.Zero ? Utils.RandomVector2(GenBase._random, -1f, 1f) : this._startVelocity;
while ((double) num1 > 0.0 && num2 > 0.0)
{
num2 = (double) this._startStrength * ((double) num1 / (double) steps);
float num3 = num1 - 1f;
int num4 = Math.Max(1, (int) ((double) vector2_1.X - num2 * 0.5));
int num5 = Math.Max(1, (int) ((double) vector2_1.Y - num2 * 0.5));
int num6 = Math.Min(GenBase._worldWidth, (int) ((double) vector2_1.X + num2 * 0.5));
int num7 = Math.Min(GenBase._worldHeight, (int) ((double) vector2_1.Y + num2 * 0.5));
for (int x = num4; x < num6; ++x)
{
for (int y = num5; y < num7; ++y)
{
if ((double) Math.Abs((float) x - vector2_1.X) + (double) Math.Abs((float) y - vector2_1.Y) < num2 * 0.5 * (1.0 + (double) GenBase._random.Next(-10, 11) * 0.015))
this.UnitApply(action, origin, x, y);
}
}
int num8 = (int) (num2 / 50.0) + 1;
num1 = num3 - (float) num8;
vector2_1 += vector2_2;
for (int index = 0; index < num8; ++index)
{
vector2_1 += vector2_2;
vector2_2 += Utils.RandomVector2(GenBase._random, -0.5f, 0.5f);
}
vector2_2 = Vector2.Clamp(vector2_2 + Utils.RandomVector2(GenBase._random, -0.5f, 0.5f), -Vector2.One, Vector2.One);
}
return true;
}
}
}

View file

@ -0,0 +1,424 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Generation.TrackGenerator
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Microsoft.Xna.Framework;
using System;
using System.Diagnostics;
using Terraria.ID;
using Terraria.WorldBuilding;
namespace Terraria.GameContent.Generation
{
public class TrackGenerator
{
private static readonly ushort[] InvalidWalls = new ushort[20]
{
(ushort) 7,
(ushort) 94,
(ushort) 95,
(ushort) 8,
(ushort) 98,
(ushort) 99,
(ushort) 9,
(ushort) 96,
(ushort) 97,
(ushort) 3,
(ushort) 83,
(ushort) 68,
(ushort) 62,
(ushort) 78,
(ushort) 87,
(ushort) 86,
(ushort) 42,
(ushort) 74,
(ushort) 27,
(ushort) 149
};
private static readonly ushort[] InvalidTiles = new ushort[22]
{
(ushort) 383,
(ushort) 384,
(ushort) 15,
(ushort) 304,
(ushort) 30,
(ushort) 321,
(ushort) 245,
(ushort) 246,
(ushort) 240,
(ushort) 241,
(ushort) 242,
(ushort) 16,
(ushort) 34,
(ushort) 158,
(ushort) 377,
(ushort) 94,
(ushort) 10,
(ushort) 19,
(ushort) 86,
(ushort) 219,
(ushort) 484,
(ushort) 190
};
private readonly TrackGenerator.TrackHistory[] _history = new TrackGenerator.TrackHistory[4096];
private readonly TrackGenerator.TrackHistory[] _rewriteHistory = new TrackGenerator.TrackHistory[25];
private int _xDirection;
private int _length;
private int playerHeight = 6;
public bool Place(Point origin, int minLength, int maxLength)
{
if (!TrackGenerator.FindSuitableOrigin(ref origin))
return false;
this.CreateTrackStart(origin);
if (!this.FindPath(minLength, maxLength))
return false;
this.PlacePath();
return true;
}
private void PlacePath()
{
bool[] flagArray = new bool[this._length];
for (int index1 = 0; index1 < this._length; ++index1)
{
if (WorldGen.genRand.Next(7) == 0)
this.playerHeight = WorldGen.genRand.Next(5, 9);
for (int index2 = 0; index2 < this.playerHeight; ++index2)
{
if (Main.tile[(int) this._history[index1].X, (int) this._history[index1].Y - index2 - 1].wall == (ushort) 244)
Main.tile[(int) this._history[index1].X, (int) this._history[index1].Y - index2 - 1].wall = (ushort) 0;
if (Main.tile[(int) this._history[index1].X, (int) this._history[index1].Y - index2].wall == (ushort) 244)
Main.tile[(int) this._history[index1].X, (int) this._history[index1].Y - index2].wall = (ushort) 0;
if (Main.tile[(int) this._history[index1].X, (int) this._history[index1].Y - index2 + 1].wall == (ushort) 244)
Main.tile[(int) this._history[index1].X, (int) this._history[index1].Y - index2 + 1].wall = (ushort) 0;
if (Main.tile[(int) this._history[index1].X, (int) this._history[index1].Y - index2].type == (ushort) 135)
flagArray[index1] = true;
WorldGen.KillTile((int) this._history[index1].X, (int) this._history[index1].Y - index2, noItem: true);
}
}
for (int index3 = 0; index3 < this._length; ++index3)
{
if (WorldGen.genRand.Next(7) == 0)
this.playerHeight = WorldGen.genRand.Next(5, 9);
TrackGenerator.TrackHistory trackHistory = this._history[index3];
Tile.SmoothSlope((int) trackHistory.X, (int) trackHistory.Y + 1);
Tile.SmoothSlope((int) trackHistory.X, (int) trackHistory.Y - this.playerHeight);
bool wire = Main.tile[(int) trackHistory.X, (int) trackHistory.Y].wire();
if (flagArray[index3] && index3 < this._length && index3 > 0 && (int) this._history[index3 - 1].Y == (int) trackHistory.Y && (int) this._history[index3 + 1].Y == (int) trackHistory.Y)
{
Main.tile[(int) trackHistory.X, (int) trackHistory.Y].ClearEverything();
WorldGen.PlaceTile((int) trackHistory.X, (int) trackHistory.Y, 314, forced: true, style: 1);
}
else
Main.tile[(int) trackHistory.X, (int) trackHistory.Y].ResetToType((ushort) 314);
Main.tile[(int) trackHistory.X, (int) trackHistory.Y].wire(wire);
if (index3 != 0)
{
for (int index4 = 0; index4 < 8; ++index4)
WorldUtils.TileFrame((int) this._history[index3 - 1].X, (int) this._history[index3 - 1].Y - index4, true);
if (index3 == this._length - 1)
{
for (int index5 = 0; index5 < this.playerHeight; ++index5)
WorldUtils.TileFrame((int) trackHistory.X, (int) trackHistory.Y - index5, true);
}
}
}
}
private void CreateTrackStart(Point origin)
{
this._xDirection = origin.X > Main.maxTilesX / 2 ? -1 : 1;
this._length = 1;
for (int index = 0; index < this._history.Length; ++index)
this._history[index] = new TrackGenerator.TrackHistory(origin.X + index * this._xDirection, origin.Y + index, TrackGenerator.TrackSlope.Down);
}
private bool FindPath(int minLength, int maxLength)
{
int length = this._length;
while (this._length < this._history.Length - 100)
{
this.AppendToHistory(this._history[this._length - 1].Slope == TrackGenerator.TrackSlope.Up ? TrackGenerator.TrackSlope.Straight : TrackGenerator.TrackSlope.Down);
TrackGenerator.TrackPlacementState avoidTiles = this.TryRewriteHistoryToAvoidTiles();
if (avoidTiles != TrackGenerator.TrackPlacementState.Invalid)
{
length = this._length;
TrackGenerator.TrackPlacementState trackPlacementState = avoidTiles;
while (trackPlacementState != TrackGenerator.TrackPlacementState.Available)
{
trackPlacementState = this.CreateTunnel();
if (trackPlacementState != TrackGenerator.TrackPlacementState.Invalid)
length = this._length;
else
break;
}
if (this._length >= maxLength)
break;
}
else
break;
}
this._length = Math.Min(maxLength, length);
if (this._length < minLength)
return false;
this.SmoothTrack();
return this.GetHistorySegmentPlacementState(0, this._length) != TrackGenerator.TrackPlacementState.Invalid;
}
private TrackGenerator.TrackPlacementState CreateTunnel()
{
TrackGenerator.TrackSlope trackSlope1 = TrackGenerator.TrackSlope.Straight;
int num = 10;
TrackGenerator.TrackPlacementState trackPlacementState1 = TrackGenerator.TrackPlacementState.Invalid;
int x = (int) this._history[this._length - 1].X;
int y = (int) this._history[this._length - 1].Y;
for (TrackGenerator.TrackSlope trackSlope2 = TrackGenerator.TrackSlope.Up; trackSlope2 <= TrackGenerator.TrackSlope.Down; ++trackSlope2)
{
TrackGenerator.TrackPlacementState trackPlacementState2 = TrackGenerator.TrackPlacementState.Invalid;
for (int index = 1; index < num; ++index)
{
trackPlacementState2 = TrackGenerator.CalculateStateForLocation(x + index * this._xDirection, y + index * (int) trackSlope2);
switch (trackPlacementState2)
{
case TrackGenerator.TrackPlacementState.Obstructed:
continue;
case TrackGenerator.TrackPlacementState.Invalid:
goto label_6;
default:
trackSlope1 = trackSlope2;
num = index;
trackPlacementState1 = trackPlacementState2;
goto label_6;
}
}
label_6:
if (trackPlacementState1 != TrackGenerator.TrackPlacementState.Available && trackPlacementState2 == TrackGenerator.TrackPlacementState.Obstructed && (trackPlacementState1 != TrackGenerator.TrackPlacementState.Obstructed || trackSlope1 != TrackGenerator.TrackSlope.Straight))
{
trackSlope1 = trackSlope2;
num = 10;
trackPlacementState1 = trackPlacementState2;
}
}
if (this._length == 0 || !TrackGenerator.CanSlopesTouch(this._history[this._length - 1].Slope, trackSlope1))
this.RewriteSlopeDirection(this._length - 1, TrackGenerator.TrackSlope.Straight);
this._history[this._length - 1].Mode = TrackGenerator.TrackMode.Tunnel;
for (int index = 1; index < num; ++index)
this.AppendToHistory(trackSlope1, TrackGenerator.TrackMode.Tunnel);
return trackPlacementState1;
}
private void AppendToHistory(TrackGenerator.TrackSlope slope, TrackGenerator.TrackMode mode = TrackGenerator.TrackMode.Normal)
{
this._history[this._length] = new TrackGenerator.TrackHistory((int) this._history[this._length - 1].X + this._xDirection, (int) ((sbyte) this._history[this._length - 1].Y + slope), slope);
this._history[this._length].Mode = mode;
++this._length;
}
private TrackGenerator.TrackPlacementState TryRewriteHistoryToAvoidTiles()
{
int index1 = this._length - 1;
int length = Math.Min(this._length, this._rewriteHistory.Length);
for (int index2 = 0; index2 < length; ++index2)
this._rewriteHistory[index2] = this._history[index1 - index2];
for (; index1 >= this._length - length; --index1)
{
if (this._history[index1].Slope == TrackGenerator.TrackSlope.Down)
{
TrackGenerator.TrackPlacementState segmentPlacementState = this.GetHistorySegmentPlacementState(index1, this._length - index1);
if (segmentPlacementState == TrackGenerator.TrackPlacementState.Available)
return segmentPlacementState;
this.RewriteSlopeDirection(index1, TrackGenerator.TrackSlope.Straight);
}
}
if (this.GetHistorySegmentPlacementState(index1 + 1, this._length - (index1 + 1)) == TrackGenerator.TrackPlacementState.Available)
return TrackGenerator.TrackPlacementState.Available;
int index3;
for (index3 = this._length - 1; index3 >= this._length - length + 1; --index3)
{
if (this._history[index3].Slope == TrackGenerator.TrackSlope.Straight)
{
TrackGenerator.TrackPlacementState segmentPlacementState = this.GetHistorySegmentPlacementState(this._length - length, length);
if (segmentPlacementState == TrackGenerator.TrackPlacementState.Available)
return segmentPlacementState;
this.RewriteSlopeDirection(index3, TrackGenerator.TrackSlope.Up);
}
}
for (int index4 = 0; index4 < length; ++index4)
this._history[this._length - 1 - index4] = this._rewriteHistory[index4];
this.RewriteSlopeDirection(this._length - 1, TrackGenerator.TrackSlope.Straight);
return this.GetHistorySegmentPlacementState(index3 + 1, this._length - (index3 + 1));
}
private void RewriteSlopeDirection(int index, TrackGenerator.TrackSlope slope)
{
int num = (int) (slope - this._history[index].Slope);
this._history[index].Slope = slope;
for (int index1 = index; index1 < this._length; ++index1)
this._history[index1].Y += (short) num;
}
private TrackGenerator.TrackPlacementState GetHistorySegmentPlacementState(
int startIndex,
int length)
{
TrackGenerator.TrackPlacementState trackPlacementState = TrackGenerator.TrackPlacementState.Available;
for (int index = startIndex; index < startIndex + length; ++index)
{
TrackGenerator.TrackPlacementState stateForLocation = TrackGenerator.CalculateStateForLocation((int) this._history[index].X, (int) this._history[index].Y);
switch (stateForLocation)
{
case TrackGenerator.TrackPlacementState.Obstructed:
if (this._history[index].Mode != TrackGenerator.TrackMode.Tunnel)
{
trackPlacementState = stateForLocation;
break;
}
break;
case TrackGenerator.TrackPlacementState.Invalid:
return stateForLocation;
}
}
return trackPlacementState;
}
private void SmoothTrack()
{
int val2 = this._length - 1;
bool flag = false;
for (int index1 = this._length - 1; index1 >= 0; --index1)
{
if (flag)
{
val2 = Math.Min(index1 + 15, val2);
if ((int) this._history[index1].Y >= (int) this._history[val2].Y)
{
for (int index2 = index1 + 1; (int) this._history[index2].Y > (int) this._history[index1].Y; ++index2)
{
this._history[index2].Y = this._history[index1].Y;
this._history[index2].Slope = TrackGenerator.TrackSlope.Straight;
}
if ((int) this._history[index1].Y == (int) this._history[val2].Y)
flag = false;
}
}
else if ((int) this._history[index1].Y > (int) this._history[val2].Y)
flag = true;
else
val2 = index1;
}
}
private static bool CanSlopesTouch(
TrackGenerator.TrackSlope leftSlope,
TrackGenerator.TrackSlope rightSlope)
{
return leftSlope == rightSlope || leftSlope == TrackGenerator.TrackSlope.Straight || rightSlope == TrackGenerator.TrackSlope.Straight;
}
private static bool FindSuitableOrigin(ref Point origin)
{
TrackGenerator.TrackPlacementState stateForLocation;
while ((stateForLocation = TrackGenerator.CalculateStateForLocation(origin.X, origin.Y)) != TrackGenerator.TrackPlacementState.Obstructed)
{
++origin.Y;
if (stateForLocation == TrackGenerator.TrackPlacementState.Invalid)
return false;
}
--origin.Y;
return TrackGenerator.CalculateStateForLocation(origin.X, origin.Y) == TrackGenerator.TrackPlacementState.Available;
}
private static TrackGenerator.TrackPlacementState CalculateStateForLocation(
int x,
int y)
{
for (int index = 0; index < 6; ++index)
{
if (TrackGenerator.IsLocationInvalid(x, y - index))
return TrackGenerator.TrackPlacementState.Invalid;
}
for (int index = 0; index < 6; ++index)
{
if (TrackGenerator.IsMinecartTrack(x, y + index))
return TrackGenerator.TrackPlacementState.Invalid;
}
for (int index = 0; index < 6; ++index)
{
if (WorldGen.SolidTile(x, y - index))
return TrackGenerator.TrackPlacementState.Obstructed;
}
return WorldGen.IsTileNearby(x, y, 314, 30) ? TrackGenerator.TrackPlacementState.Invalid : TrackGenerator.TrackPlacementState.Available;
}
private static bool IsMinecartTrack(int x, int y) => Main.tile[x, y].active() && Main.tile[x, y].type == (ushort) 314;
private static bool IsLocationInvalid(int x, int y)
{
if (y > Main.UnderworldLayer || x < 5 || y < (int) Main.worldSurface || x > Main.maxTilesX - 5 || WorldGen.oceanDepths(x, y))
return true;
ushort wall = Main.tile[x, y].wall;
for (int index = 0; index < TrackGenerator.InvalidWalls.Length; ++index)
{
if ((int) wall == (int) TrackGenerator.InvalidWalls[index] && (!WorldGen.notTheBees || wall != (ushort) 108))
return true;
}
ushort type = Main.tile[x, y].type;
for (int index = 0; index < TrackGenerator.InvalidTiles.Length; ++index)
{
if ((int) type == (int) TrackGenerator.InvalidTiles[index])
return true;
}
for (int index = -1; index <= 1; ++index)
{
if (Main.tile[x + index, y].active() && (Main.tile[x + index, y].type == (ushort) 314 || !TileID.Sets.GeneralPlacementTiles[(int) Main.tile[x + index, y].type]) && (!WorldGen.notTheBees || Main.tile[x + index, y].type != (ushort) 225))
return true;
}
return false;
}
[Conditional("DEBUG")]
private void DrawPause()
{
}
private enum TrackPlacementState
{
Available,
Obstructed,
Invalid,
}
private enum TrackSlope : sbyte
{
Up = -1, // 0xFF
Straight = 0,
Down = 1,
}
private enum TrackMode : byte
{
Normal,
Tunnel,
}
[DebuggerDisplay("X = {X}, Y = {Y}, Slope = {Slope}")]
private struct TrackHistory
{
public short X;
public short Y;
public TrackGenerator.TrackSlope Slope;
public TrackGenerator.TrackMode Mode;
public TrackHistory(int x, int y, TrackGenerator.TrackSlope slope)
{
this.X = (short) x;
this.Y = (short) y;
this.Slope = slope;
this.Mode = TrackGenerator.TrackMode.Normal;
}
}
}
}

View file

@ -0,0 +1,15 @@
// Decompiled with JetBrains decompiler
// Type: Terraria.GameContent.Generation.WorldGenLegacyMethod
// Assembly: Terraria, Version=1.4.0.5, Culture=neutral, PublicKeyToken=null
// MVID: 67F9E73E-0A81-4937-A22C-5515CD405A83
// Assembly location: C:\Users\mikeyisbaeyt\Downloads\depotdownloader-2.4.5\depots\105601\6707058\Terraria.exe
using Terraria.IO;
using Terraria.WorldBuilding;
namespace Terraria.GameContent.Generation
{
public delegate void WorldGenLegacyMethod(
GenerationProgress progress,
GameConfiguration configuration);
}