mirror of
https://github.com/kwsch/NHSE.git
synced 2026-06-13 03:20:55 -05:00
Remove hardcoded map dimension properties
we can refer to MaxWidth/MaxHeight instead
This commit is contained in:
parent
50b364ee20
commit
902dd90dc9
|
|
@ -14,7 +14,7 @@ public FieldItemLayer(Item[] tiles) : base(tiles, 32 * AcreWidth, 32 * AcreHeigh
|
|||
|
||||
public byte[] DumpAcre(int acre)
|
||||
{
|
||||
int count = AcreTileCount;
|
||||
int count = GridTileCount;
|
||||
var result = new byte[Item.SIZE * count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
|
|
@ -27,7 +27,7 @@ public byte[] DumpAcre(int acre)
|
|||
|
||||
public void ImportAcre(int acre, byte[] data)
|
||||
{
|
||||
int count = AcreTileCount;
|
||||
int count = GridTileCount;
|
||||
var tiles = Item.GetArray(data);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
|
|
@ -36,10 +36,10 @@ public void ImportAcre(int acre, byte[] data)
|
|||
}
|
||||
}
|
||||
|
||||
public int ClearFieldPlanted(Func<FieldItemKind, bool> criteria) => ClearFieldPlanted(0, 0, MapWidth, MapHeight, criteria);
|
||||
public int RemoveAll(Func<Item, bool> criteria) => RemoveAll(0, 0, MapWidth, MapHeight, criteria);
|
||||
public int RemoveAll(HashSet<ushort> items) => RemoveAll(0, 0, MapWidth, MapHeight, z => items.Contains(z.DisplayItemId));
|
||||
public int RemoveAll(ushort item) => RemoveAll(0, 0, MapWidth, MapHeight, z => z.DisplayItemId == item);
|
||||
public int ClearFieldPlanted(Func<FieldItemKind, bool> criteria) => ClearFieldPlanted(0, 0, MaxWidth, MaxHeight, criteria);
|
||||
public int RemoveAll(Func<Item, bool> criteria) => RemoveAll(0, 0, MaxWidth, MaxHeight, criteria);
|
||||
public int RemoveAll(HashSet<ushort> items) => RemoveAll(0, 0, MaxWidth, MaxHeight, z => items.Contains(z.DisplayItemId));
|
||||
public int RemoveAll(ushort item) => RemoveAll(0, 0, MaxWidth, MaxHeight, z => z.DisplayItemId == item);
|
||||
|
||||
public int ClearFieldPlanted(int xmin, int ymin, int width, int height, Func<FieldItemKind, bool> criteria)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ public TerrainLayer(TerrainTile[] tiles, byte[] acres) : base(16, 16, AcreWidth
|
|||
{
|
||||
BaseAcres = acres;
|
||||
Tiles = tiles;
|
||||
Debug.Assert(MapTileCount == tiles.Length);
|
||||
Debug.Assert(MaxTileCount == tiles.Length);
|
||||
}
|
||||
|
||||
public TerrainTile GetTile(int x, int y) => this[GetTileIndex(x, y)];
|
||||
|
|
@ -34,7 +34,7 @@ public byte[] DumpAll()
|
|||
|
||||
public byte[] DumpAcre(int acre)
|
||||
{
|
||||
int count = AcreTileCount;
|
||||
int count = GridTileCount;
|
||||
var result = new byte[TerrainTile.SIZE * count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
|
|
@ -54,7 +54,7 @@ public void ImportAll(byte[] data)
|
|||
|
||||
public void ImportAcre(int acre, byte[] data)
|
||||
{
|
||||
int count = AcreTileCount;
|
||||
int count = GridTileCount;
|
||||
var tiles = TerrainTile.GetArray(data);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
|
|
@ -70,8 +70,8 @@ public void SetAll(TerrainTile tile, in bool interiorOnly)
|
|||
// skip outermost ring of tiles
|
||||
int xmin = GridWidth;
|
||||
int ymin = GridHeight;
|
||||
int xmax = MapWidth - GridWidth;
|
||||
int ymax = MapHeight - GridHeight;
|
||||
int xmax = MaxWidth - GridWidth;
|
||||
int ymax = MaxHeight - GridHeight;
|
||||
for (int x = xmin; x < xmax; x++)
|
||||
{
|
||||
for (int y = ymin; y < ymax; y++)
|
||||
|
|
|
|||
|
|
@ -26,10 +26,8 @@ protected MapGrid(int gw, int gh, int mw, int mh)
|
|||
public const int AcreHeight = 6;
|
||||
public const int AcreCount = AcreWidth * AcreHeight;
|
||||
|
||||
public int AcreTileCount => GridWidth * GridHeight;
|
||||
public int MapHeight => AcreHeight * GridHeight; // 96 (when 16x16)
|
||||
public int MapWidth => AcreWidth * GridWidth; // 112 (when 16x16)
|
||||
public int MapTileCount => MapWidth * MapHeight; // 0x2A00 bytes (when 16x16)
|
||||
public int GridTileCount => GridWidth * GridHeight;
|
||||
public int MaxTileCount => MaxWidth * MaxHeight;
|
||||
|
||||
public const int MapTileCount16x16 = 16 * 16 * AcreCount;
|
||||
public const int MapTileCount32x32 = 32 * 32 * AcreCount;
|
||||
|
|
@ -81,8 +79,8 @@ public void GetViewAnchorCoordinates(int acre, out int x, out int y)
|
|||
|
||||
public void ClampCoordinates(ref int x, ref int y)
|
||||
{
|
||||
x = Math.Max(0, Math.Min(x, MapWidth - 1));
|
||||
y = Math.Max(0, Math.Min(y, MapHeight - 1));
|
||||
x = Math.Max(0, Math.Min(x, MaxWidth - 1));
|
||||
y = Math.Max(0, Math.Min(y, MaxHeight - 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ public class MapView
|
|||
protected MapView(MapManager m) => Map = m;
|
||||
|
||||
public bool CanUp => Y != 0;
|
||||
public bool CanDown => Y < Map.CurrentLayer.MapHeight - Map.CurrentLayer.GridHeight;
|
||||
public bool CanDown => Y < Map.CurrentLayer.MaxHeight - Map.CurrentLayer.GridHeight;
|
||||
public bool CanLeft => X != 0;
|
||||
public bool CanRight => X < Map.CurrentLayer.MapWidth - Map.CurrentLayer.GridWidth;
|
||||
public bool CanRight => X < Map.CurrentLayer.MaxWidth - Map.CurrentLayer.GridWidth;
|
||||
|
||||
public bool ArrowUp()
|
||||
{
|
||||
|
|
@ -40,7 +40,7 @@ public bool ArrowLeft()
|
|||
|
||||
public bool ArrowRight()
|
||||
{
|
||||
if (X >= Map.CurrentLayer.MapWidth - 2)
|
||||
if (X >= Map.CurrentLayer.MaxWidth - 2)
|
||||
return false;
|
||||
X += ViewInterval;
|
||||
return true;
|
||||
|
|
@ -48,7 +48,7 @@ public bool ArrowRight()
|
|||
|
||||
public bool ArrowDown()
|
||||
{
|
||||
if (Y >= Map.CurrentLayer.MapHeight - ViewInterval)
|
||||
if (Y >= Map.CurrentLayer.MaxHeight - ViewInterval)
|
||||
return false;
|
||||
Y += ViewInterval;
|
||||
return true;
|
||||
|
|
@ -57,8 +57,8 @@ public bool ArrowDown()
|
|||
public bool SetViewTo(in int x, in int y)
|
||||
{
|
||||
var info = Map.CurrentLayer;
|
||||
var newX = Math.Max(0, Math.Min(x, info.MapWidth - info.GridWidth));
|
||||
var newY = Math.Max(0, Math.Min(y, info.MapHeight - info.GridHeight));
|
||||
var newX = Math.Max(0, Math.Min(x, info.MaxWidth - info.GridWidth));
|
||||
var newY = Math.Max(0, Math.Min(y, info.MaxHeight - info.GridHeight));
|
||||
bool diff = X != newX || Y != newY;
|
||||
X = newX;
|
||||
Y = newY;
|
||||
|
|
@ -76,7 +76,7 @@ public int RemoveFieldItems(Func<int, int, int, int, int> removal, bool wholeMap
|
|||
{
|
||||
var layer = Map.CurrentLayer;
|
||||
return wholeMap
|
||||
? removal(0, 0, layer.MapWidth, layer.MapHeight)
|
||||
? removal(0, 0, layer.MaxWidth, layer.MaxHeight)
|
||||
: removal(X, Y, layer.GridWidth, layer.GridHeight);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ public MapViewer(MapManager m) : base(m)
|
|||
PixelsItemAcreX = new int[PixelsItemAcre1.Length * AcreScale * AcreScale];
|
||||
ScaleAcre = new Bitmap(l1.GridWidth * AcreScale, l1.GridHeight * AcreScale);
|
||||
|
||||
PixelsItemMap = new int[l1.MapWidth * l1.MapHeight * MapScale * MapScale];
|
||||
MapReticle = new Bitmap(l1.MapWidth * MapScale, l1.MapHeight * MapScale);
|
||||
PixelsItemMap = new int[l1.MaxWidth * l1.MaxHeight * MapScale * MapScale];
|
||||
MapReticle = new Bitmap(l1.MaxWidth * MapScale, l1.MaxHeight * MapScale);
|
||||
|
||||
PixelsBackgroundAcre1 = new int[16 * 16];
|
||||
PixelsBackgroundAcreX = new int[PixelsItemAcreX.Length];
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ public static class TerrainSprite
|
|||
public static void CreateMap(TerrainLayer mgr, int[] pixels)
|
||||
{
|
||||
int i = 0;
|
||||
for (int y = 0; y < mgr.MapHeight; y++)
|
||||
for (int y = 0; y < mgr.MaxHeight; y++)
|
||||
{
|
||||
for (int x = 0; x < mgr.MapWidth; x++, i++)
|
||||
for (int x = 0; x < mgr.MaxWidth; x++, i++)
|
||||
{
|
||||
pixels[i] = mgr.GetTileColor(x, y);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ public static bool ImportToLayerAcreSingle(FieldItemLayer layer, int acreIndex,
|
|||
var path = ofd.FileName;
|
||||
var fi = new FileInfo(path);
|
||||
|
||||
int expect = layer.AcreTileCount * Item.SIZE;
|
||||
int expect = layer.GridTileCount * Item.SIZE;
|
||||
if (fi.Length != expect)
|
||||
{
|
||||
WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expect));
|
||||
|
|
@ -45,7 +45,7 @@ public static bool ImportToLayerAcreAll(FieldItemLayer layer)
|
|||
var path = ofd.FileName;
|
||||
var fi = new FileInfo(path);
|
||||
|
||||
int expect = layer.MapTileCount * Item.SIZE;
|
||||
int expect = layer.MaxTileCount * Item.SIZE;
|
||||
if (fi.Length != expect)
|
||||
{
|
||||
WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expect));
|
||||
|
|
@ -100,7 +100,7 @@ public static bool ImportTerrainAcre(TerrainLayer m, int acreIndex, string acre)
|
|||
var path = ofd.FileName;
|
||||
var fi = new FileInfo(path);
|
||||
|
||||
int expect = m.AcreTileCount * TerrainTile.SIZE;
|
||||
int expect = m.GridTileCount * TerrainTile.SIZE;
|
||||
if (fi.Length != expect)
|
||||
{
|
||||
WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expect));
|
||||
|
|
@ -125,7 +125,7 @@ public static bool ImportTerrainAll(TerrainLayer m)
|
|||
var path = ofd.FileName;
|
||||
var fi = new FileInfo(path);
|
||||
|
||||
int expect = m.MapTileCount * TerrainTile.SIZE;
|
||||
int expect = m.MaxTileCount * TerrainTile.SIZE;
|
||||
if (fi.Length != expect)
|
||||
{
|
||||
WinFormsUtil.Error(string.Format(MessageStrings.MsgDataSizeMismatchImport, fi.Length, expect));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user