Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ LoadMapVersion1()

static void Terraria.Map.MapHelper.LoadMapVersion1 ( BinaryReader fileIO,
int release )
inlinestatic

Definition at line 3221 of file MapHelper.cs.

3222 {
3223 string text = fileIO.ReadString();
3224 int num = fileIO.ReadInt32();
3225 int num2 = fileIO.ReadInt32();
3226 int num3 = fileIO.ReadInt32();
3227 if (text != Main.worldName || num != Main.worldID || num3 != Main.maxTilesX || num2 != Main.maxTilesY)
3228 {
3229 throw new Exception("Map meta-data is invalid.");
3230 }
3231 OldMapHelper oldMapHelper = default(OldMapHelper);
3232 for (int i = 0; i < Main.maxTilesX; i++)
3233 {
3234 float num4 = (float)i / (float)Main.maxTilesX;
3235 Main.statusText = Lang.gen[67].Value + " " + (int)(num4 * 100f + 1f) + "%";
3236 for (int j = 0; j < Main.maxTilesY; j++)
3237 {
3238 if (fileIO.ReadBoolean())
3239 {
3240 int num5 = ((release <= 77) ? fileIO.ReadByte() : fileIO.ReadUInt16());
3241 byte b = fileIO.ReadByte();
3242 oldMapHelper.misc = fileIO.ReadByte();
3243 if (release >= 50)
3244 {
3245 oldMapHelper.misc2 = fileIO.ReadByte();
3246 }
3247 else
3248 {
3249 oldMapHelper.misc2 = 0;
3250 }
3251 bool flag = false;
3252 int num6 = oldMapHelper.option();
3253 int num7;
3254 if (oldMapHelper.active())
3255 {
3256 num7 = num6 + tileLookup[num5];
3257 }
3258 else if (oldMapHelper.water())
3259 {
3260 num7 = liquidPosition;
3261 }
3262 else if (oldMapHelper.lava())
3263 {
3264 num7 = liquidPosition + 1;
3265 }
3266 else if (oldMapHelper.honey())
3267 {
3268 num7 = liquidPosition + 2;
3269 }
3270 else if (oldMapHelper.wall())
3271 {
3272 num7 = num6 + wallLookup[num5];
3273 }
3274 else if ((double)j < Main.worldSurface)
3275 {
3276 flag = true;
3277 int num8 = (byte)(256.0 * ((double)j / Main.worldSurface));
3278 num7 = skyPosition + num8;
3279 }
3280 else if ((double)j < Main.rockLayer)
3281 {
3282 flag = true;
3283 if (num5 > 255)
3284 {
3285 num5 = 255;
3286 }
3287 num7 = num5 + dirtPosition;
3288 }
3289 else if (j < Main.UnderworldLayer)
3290 {
3291 flag = true;
3292 if (num5 > 255)
3293 {
3294 num5 = 255;
3295 }
3296 num7 = num5 + rockPosition;
3297 }
3298 else
3299 {
3300 num7 = hellPosition;
3301 }
3302 MapTile tile = MapTile.Create((ushort)num7, b, 0);
3303 Main.Map.SetTile(i, j, ref tile);
3304 int num9 = fileIO.ReadInt16();
3305 if (b == byte.MaxValue)
3306 {
3307 while (num9 > 0)
3308 {
3309 num9--;
3310 j++;
3311 if (flag)
3312 {
3313 if ((double)j < Main.worldSurface)
3314 {
3315 flag = true;
3316 int num10 = (byte)(256.0 * ((double)j / Main.worldSurface));
3317 num7 = skyPosition + num10;
3318 }
3319 else if ((double)j < Main.rockLayer)
3320 {
3321 flag = true;
3322 num7 = num5 + dirtPosition;
3323 }
3324 else if (j < Main.UnderworldLayer)
3325 {
3326 flag = true;
3327 num7 = num5 + rockPosition;
3328 }
3329 else
3330 {
3331 flag = true;
3332 num7 = hellPosition;
3333 }
3334 tile.Type = (ushort)num7;
3335 }
3336 Main.Map.SetTile(i, j, ref tile);
3337 }
3338 continue;
3339 }
3340 while (num9 > 0)
3341 {
3342 j++;
3343 num9--;
3344 b = fileIO.ReadByte();
3345 if (b <= 18)
3346 {
3347 continue;
3348 }
3349 tile.Light = b;
3350 if (flag)
3351 {
3352 if ((double)j < Main.worldSurface)
3353 {
3354 flag = true;
3355 int num11 = (byte)(256.0 * ((double)j / Main.worldSurface));
3356 num7 = skyPosition + num11;
3357 }
3358 else if ((double)j < Main.rockLayer)
3359 {
3360 flag = true;
3361 num7 = num5 + dirtPosition;
3362 }
3363 else if (j < Main.UnderworldLayer)
3364 {
3365 flag = true;
3366 num7 = num5 + rockPosition;
3367 }
3368 else
3369 {
3370 flag = true;
3371 num7 = hellPosition;
3372 }
3373 tile.Type = (ushort)num7;
3374 }
3375 Main.Map.SetTile(i, j, ref tile);
3376 }
3377 }
3378 else
3379 {
3380 int num12 = fileIO.ReadInt16();
3381 j += num12;
3382 }
3383 }
3384 }
3385 }
virtual bool ReadBoolean()
virtual byte ReadByte()
virtual string ReadString()
virtual ushort ReadUInt16()
virtual int ReadInt32()
virtual short ReadInt16()
static ushort rockPosition
Definition MapHelper.cs:194
static ushort dirtPosition
Definition MapHelper.cs:192
static ushort[] wallLookup
Definition MapHelper.cs:182
static ushort[] tileLookup
Definition MapHelper.cs:180
static ushort hellPosition
Definition MapHelper.cs:196
static ushort skyPosition
Definition MapHelper.cs:190
static ushort liquidPosition
Definition MapHelper.cs:188

References Terraria.Map.MapHelper.OldMapHelper.active(), Terraria.Map.MapTile.Create(), Terraria.Map.MapHelper.dirtPosition, Terraria.Lang.gen, Terraria.Map.MapHelper.hellPosition, Terraria.Map.MapHelper.OldMapHelper.honey(), Terraria.Map.MapHelper.OldMapHelper.lava(), Terraria.Map.MapHelper.liquidPosition, Terraria.Main.Map, Terraria.Main.maxTilesX, Terraria.Main.maxTilesY, Terraria.Map.MapHelper.OldMapHelper.option(), System.IO.BinaryReader.ReadBoolean(), System.IO.BinaryReader.ReadByte(), System.IO.BinaryReader.ReadInt16(), System.IO.BinaryReader.ReadInt32(), System.IO.BinaryReader.ReadString(), System.IO.BinaryReader.ReadUInt16(), Terraria.Main.rockLayer, Terraria.Map.MapHelper.rockPosition, Terraria.Map.MapHelper.skyPosition, System.text, Terraria.Map.MapHelper.tileLookup, Terraria.Main.UnderworldLayer, Terraria.Map.MapHelper.OldMapHelper.wall(), Terraria.Map.MapHelper.wallLookup, Terraria.Map.MapHelper.OldMapHelper.water(), Terraria.Main.worldID, Terraria.Main.worldName, and Terraria.Main.worldSurface.

Referenced by Terraria.Map.WorldMap.Load().