2019-01-29 22:48:40 +13:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using NexusForever.MapGenerator.IO.Area;
|
|
|
|
|
|
using NexusForever.Shared.IO;
|
|
|
|
|
|
using NexusForever.Shared.IO.Map;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NexusForever.MapGenerator.IO.Map
|
|
|
|
|
|
{
|
|
|
|
|
|
public class WritableMapFileCell : MapFileCell, IWritable
|
|
|
|
|
|
{
|
|
|
|
|
|
public WritableMapFileCell(ChnkCell cell)
|
|
|
|
|
|
{
|
|
|
|
|
|
X = cell.X;
|
|
|
|
|
|
Y = cell.Y;
|
|
|
|
|
|
|
2021-04-10 21:54:07 +12:00
|
|
|
|
if ((cell.Flags & ChnkCellFlags.Zone) != 0)
|
2019-01-29 22:48:40 +13:00
|
|
|
|
{
|
2021-11-27 18:55:11 +13:00
|
|
|
|
worldZoneIds = new uint[4];
|
2021-04-10 21:54:07 +12:00
|
|
|
|
Array.Copy(cell.WorldZoneIds, worldZoneIds, 4);
|
|
|
|
|
|
flags |= Flags.Zone;
|
2019-01-29 22:48:40 +13:00
|
|
|
|
}
|
2019-08-12 09:22:54 +12:00
|
|
|
|
|
|
|
|
|
|
if ((cell.Flags & ChnkCellFlags.HeightMap) != 0)
|
|
|
|
|
|
{
|
2021-11-27 18:55:11 +13:00
|
|
|
|
heightMap = new float[17, 17];
|
2019-08-12 09:22:54 +12:00
|
|
|
|
for (int y = 0; y < 17; y++)
|
|
|
|
|
|
for (int x = 0; x < 17; x++)
|
|
|
|
|
|
heightMap[x, y] = (cell.Heightmap[x + 1, y + 1] / 8.0f) - 2048f;
|
|
|
|
|
|
|
|
|
|
|
|
flags |= Flags.Height;
|
|
|
|
|
|
}
|
2021-04-10 21:54:07 +12:00
|
|
|
|
|
|
|
|
|
|
if ((cell.Flags & ChnkCellFlags.ZoneBound) != 0)
|
|
|
|
|
|
{
|
2021-11-27 18:55:11 +13:00
|
|
|
|
worldZoneBounds = new byte[64, 64];
|
2021-04-10 21:54:07 +12:00
|
|
|
|
for (int y = 0; y < 64; y++)
|
|
|
|
|
|
for (int x = 0; x < 64; x++)
|
|
|
|
|
|
worldZoneBounds[x, y] = cell.WorldZoneBounds[x, y];
|
|
|
|
|
|
|
|
|
|
|
|
flags |= Flags.ZoneBound;
|
|
|
|
|
|
}
|
2019-01-29 22:48:40 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Write(BinaryWriter writer)
|
|
|
|
|
|
{
|
|
|
|
|
|
writer.Write(X);
|
|
|
|
|
|
writer.Write(Y);
|
|
|
|
|
|
writer.Write((uint)flags);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 32; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Flags flag = (Flags)(1 << i);
|
|
|
|
|
|
if ((flags & flag) == 0)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
switch (flag)
|
|
|
|
|
|
{
|
2021-04-10 21:54:07 +12:00
|
|
|
|
case Flags.Zone:
|
2019-01-29 22:48:40 +13:00
|
|
|
|
{
|
2021-04-10 21:54:07 +12:00
|
|
|
|
foreach (uint worldZoneId in worldZoneIds)
|
|
|
|
|
|
writer.Write(worldZoneId);
|
2019-01-29 22:48:40 +13:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2019-08-12 09:22:54 +12:00
|
|
|
|
case Flags.Height:
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int y = 0; y < 17; y++)
|
|
|
|
|
|
for (int x = 0; x < 17; x++)
|
|
|
|
|
|
writer.Write(heightMap[x, y]);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2021-04-10 21:54:07 +12:00
|
|
|
|
case Flags.ZoneBound:
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int y = 0; y < 64; y++)
|
|
|
|
|
|
for (int x = 0; x < 64; x++)
|
|
|
|
|
|
writer.Write(worldZoneBounds[x, y]);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2019-01-29 22:48:40 +13:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|