forked from Chinzilla00/AncientsAwakened
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConversionHandler.cs
257 lines (236 loc) · 11.4 KB
/
ConversionHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
using System;
using System.Threading;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace AAMod.Worldgen
{
internal enum ConversionType
{
MIRE,
INFERNO,
}
class ConversionHandler
{
public static int startMireX = -1;
public static int startMireY = -1;
public static int genMireWidth = -1;
public static int startInfernoX = -1;
public static int startInfernoY = -1;
public static int genInfernoWidth = -1;
public static void ConvertDown(int centerX, int y, int width, ConversionType convertType)
{
int worldSize = GetWorldSize();
int biomeRadius = worldSize == 3 ? 220 : worldSize == 2 ? 180 : 150;
biomeRadius /= 2;
switch (convertType)
{
case ConversionType.MIRE:
{
startMireX = centerX;
startMireY = y;
genMireWidth = width;
ThreadPool.QueueUserWorkItem(new WaitCallback(ConvertDownMireCallback), null);
break;
}
case ConversionType.INFERNO:
{
startInfernoX = centerX;
startInfernoY = y;
genInfernoWidth = width;
ThreadPool.QueueUserWorkItem(new WaitCallback(ConvertDownInfernoCallback), null);
break;
}
}
}
public static int GetWorldSize()
{
switch (Main.maxTilesX)
{
case 4200:
return 1;
case 6400:
return 2;
case 8400:
return 3;
default:
return 1;
}
}
#region Thread Callback Stuff
public static void ConvertDownMireCallback(object threadContext)
{
try
{
Do_ConvertDownMire(threadContext);
}
catch (Exception)
{
}
}
public static void Do_ConvertDownMire(object threadContext)
{
Dodo_ConvertDown(startMireX, startMireY, genMireWidth, ConversionType.MIRE);
}
public static void ConvertDownInfernoCallback(object threadContext)
{
try
{
Do_ConvertDownInferno(threadContext);
}
catch (Exception)
{
}
}
public static void Do_ConvertDownInferno(object threadContext)
{
Dodo_ConvertDown(startInfernoX, startInfernoY, genInfernoWidth, ConversionType.INFERNO);
}
#endregion
public static void Dodo_ConvertDown(int startX, int startY, int genWidth, ConversionType conversionType)
{
Mod mod = AAMod.instance;
int tileGrass = 0, wallGrass = 0, tileStone = 0, wallStone = 0, tileSand = 0, tileSandHard = 0, wallSandHard = 0,
tileSandstone = 0, wallSandstone = 0, tileIce = 0, tileThorn = 0, tileWood = 0, tileLeaves = 0, wallLeaves = 0,
livingwoodWall = 0;
switch (conversionType)
{
case ConversionType.MIRE:
{
tileGrass = mod.TileType("MireGrass");
wallGrass = mod.WallType("MireJungleWall");
tileStone = mod.TileType("Depthstone");
wallStone = mod.WallType("DepthstoneWall");
tileSand = mod.TileType("Depthsand");
tileSandHard = mod.TileType("DepthsandHardened");
wallSandHard = mod.WallType("DepthsandHardenedWall");
tileSandstone = mod.TileType("Depthsandstone");
wallSandstone = mod.WallType("DepthsandstoneWall");
tileIce = mod.TileType("IndigoIce");
tileWood = mod.TileType("LivingBogwood");
tileLeaves = mod.TileType("LivingBogleaves");
wallLeaves = mod.TileType("LivingBogleafWall");
livingwoodWall = mod.TileType("LivingBogwoodWall");
break;
}
case ConversionType.INFERNO:
{
tileGrass = mod.TileType("InfernoGrass");
wallGrass = mod.WallType("InfernoGrassWall");
tileStone = mod.TileType("Torchstone");
wallStone = mod.WallType("TorchstoneWall");
tileSand = mod.TileType("Torchand");
tileSandHard = mod.TileType("TorchsandHardened");
wallSandHard = mod.WallType("TorchsandHardenedWall");
tileSandstone = mod.TileType("Infernosandstone");
wallSandstone = mod.WallType("InfernosandstoneWall");
tileIce = mod.TileType("Torchice");
tileWood = mod.TileType("LivingRazewood");
tileLeaves = mod.TileType("LivingRazeleaves");
wallLeaves = mod.TileType("LivingRazeleafWall");
break;
}
default:
break;
}
int centerX = startX, y = startY;
for (int x1 = 0; x1 < genWidth; x1++)
{
while (y < (Main.maxTilesY - 50))
{
Convert(centerX + x1, y, genWidth, tileGrass, wallGrass, tileStone, wallStone, tileSand, tileSandHard, wallSandHard, tileSandstone, wallSandstone, tileIce, tileThorn, tileWood, tileLeaves, wallLeaves, livingwoodWall);
y += genWidth * 2;
}
}
}
public static void Convert(int i, int j, int size, int tileGrass, int wallGrass, int tileStone, int wallStone, int tileSand, int tileSandHard, int wallSandHard, int tileSandstone, int wallSandstone, int tileIce, int tileThorn, int tileWood, int tileLeaves, int wallLeaves, int wallWood = 0)
{
for (int k = i - size; k <= i + size; k++)
{
for (int l = j - size; l <= j + size; l++)
{
if (WorldGen.InWorld(k, l, 1))
{
int type = Main.tile[k, l].type;
int wall = Main.tile[k, l].wall;
if (wallGrass != 0 && WallID.Sets.Conversion.Grass[wall] && wall != wallGrass)
{
Main.tile[k, l].wall = (ushort)wallGrass;
NetMessage.SendTileSquare(-1, k, l, 1, TileChangeType.None);
}
else if (wallStone != 0 && WallID.Sets.Conversion.Stone[wall] && wall != wallStone)
{
Main.tile[k, l].wall = (ushort)wallStone;
NetMessage.SendTileSquare(-1, k, l, 1, TileChangeType.None);
}
else if (wallSandHard != 0 && WallID.Sets.Conversion.HardenedSand[wall] && wall != wallSandHard)
{
Main.tile[k, l].wall = (ushort)wallSandHard;
NetMessage.SendTileSquare(-1, k, l, 1, TileChangeType.None);
}
else if (wallSandstone != 0 && WallID.Sets.Conversion.Sandstone[wall] && wall != wallSandstone)
{
Main.tile[k, l].wall = (ushort)wallSandstone;
NetMessage.SendTileSquare(-1, k, l, 1, TileChangeType.None);
}
else if (wallLeaves != 0 && wall == WallID.LivingLeaf && wall != wallLeaves)
{
Main.tile[k, l].wall = (ushort)wallLeaves;
NetMessage.SendTileSquare(-1, k, l, 1, TileChangeType.None);
}
else if (wallWood != 0 && wall == WallID.LivingWood && wall != wallLeaves)
{
Main.tile[k, l].wall = (ushort)wallWood;
NetMessage.SendTileSquare(-1, k, l, 1, TileChangeType.None);
}
if (tileStone != 0 && (Main.tileMoss[type] || TileID.Sets.Conversion.Stone[type]) && type != tileStone)
{
Main.tile[k, l].type = (ushort)tileStone;
NetMessage.SendTileSquare(-1, k, l, 1, TileChangeType.None);
}
else if (tileGrass != 0 && TileID.Sets.Conversion.Grass[type] && type != tileGrass)
{
Main.tile[k, l].type = (ushort)tileGrass;
NetMessage.SendTileSquare(-1, k, l, 1, TileChangeType.None);
}
else if (tileIce != 0 && TileID.Sets.Conversion.Ice[type] && type != tileIce)
{
Main.tile[k, l].type = (ushort)tileIce;
NetMessage.SendTileSquare(-1, k, l, 1, TileChangeType.None);
}
else if (tileSand != 0 && TileID.Sets.Conversion.Sand[type] && type != tileSand)
{
Main.tile[k, l].type = (ushort)tileSand;
NetMessage.SendTileSquare(-1, k, l, 1, TileChangeType.None);
}
else if (tileSandHard != 0 && TileID.Sets.Conversion.HardenedSand[type] && type != tileSandHard)
{
Main.tile[k, l].type = (ushort)tileSandHard;
NetMessage.SendTileSquare(-1, k, l, 1, TileChangeType.None);
}
else if (tileSandstone != 0 && TileID.Sets.Conversion.Sandstone[type] && type != tileSandstone)
{
Main.tile[k, l].type = (ushort)tileSandstone;
NetMessage.SendTileSquare(-1, k, l, 1, TileChangeType.None);
}
else if (tileThorn != 0 && TileID.Sets.Conversion.Thorn[type] && type != tileThorn)
{
Main.tile[k, l].type = (ushort)tileThorn;
NetMessage.SendTileSquare(-1, k, l, 1, TileChangeType.None);
}
else if (tileWood != 0 && (type == TileID.LivingMahogany || type == TileID.LivingWood) && type != tileWood)
{
Main.tile[k, l].type = (ushort)tileWood;
NetMessage.SendTileSquare(-1, k, l, 1, TileChangeType.None);
}
else if (tileLeaves != 0 && (type == TileID.LivingMahoganyLeaves || type == TileID.LeafBlock) && type != tileLeaves)
{
Main.tile[k, l].type = (ushort)tileLeaves;
NetMessage.SendTileSquare(-1, k, l, 1, TileChangeType.None);
}
}
}
}
}
}
}