mirror of
https://github.com/kwsch/NHSE.git
synced 2026-04-25 15:47:17 -05:00
add initial exterior acre pixel calculation
no functional changes to NHSE
This commit is contained in:
parent
c1e7f2dc28
commit
07e393177f
|
|
@ -40,4 +40,12 @@ public static string GetTileName(TerrainTile tile)
|
|||
return name.Substring(0, num) + Environment.NewLine + name.Substring(num);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AcreTileColor
|
||||
{
|
||||
public static int GetAcreTileColor(byte acre, int x, int y)
|
||||
{
|
||||
return Color.ForestGreen.ToArgb();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@ namespace NHSE.Core
|
|||
public class TerrainManager : MapGrid
|
||||
{
|
||||
public readonly TerrainTile[] Tiles;
|
||||
public readonly byte[] BaseAcres;
|
||||
|
||||
public TerrainManager(TerrainTile[] tiles) : base(16, 16)
|
||||
public TerrainManager(TerrainTile[] tiles, byte[] acres) : base(16, 16)
|
||||
{
|
||||
BaseAcres = acres;
|
||||
Tiles = tiles;
|
||||
Debug.Assert(MapTileCount == tiles.Length);
|
||||
}
|
||||
|
|
@ -109,5 +111,24 @@ public bool IsWithinGrid(int acreScale, int relX, int relY)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetTileColor(int x, in int y)
|
||||
{
|
||||
//var acre = GetTileAcre(x, y);
|
||||
//if (acre != 0)
|
||||
// return AcreTileColor.GetAcreTileColor(acre, x % 16, y % 16);
|
||||
|
||||
var tile = GetTile(x, y);
|
||||
return TerrainTileColor.GetTileColor(tile).ToArgb();
|
||||
}
|
||||
|
||||
private byte GetTileAcre(int x, int y)
|
||||
{
|
||||
var acreX = 1 + (x / 16);
|
||||
var acreY = 1 + (y / 16);
|
||||
|
||||
var acreIndex = ((AcreWidth + 2) * acreY) + acreX;
|
||||
return BaseAcres[acreIndex * 2]; // u16 array, never > 255
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class MapTerrainStructure
|
|||
|
||||
public MapTerrainStructure(MainSave sav)
|
||||
{
|
||||
Terrain = new TerrainManager(sav.GetTerrainTiles());
|
||||
Terrain = new TerrainManager(sav.GetTerrainTiles(), sav.GetAcreBytes());
|
||||
Buildings = sav.Buildings;
|
||||
PlazaX = sav.EventPlazaLeftUpX;
|
||||
PlazaY = sav.EventPlazaLeftUpZ;
|
||||
|
|
|
|||
81
NHSE.Parsing/PBC/PBC.cs
Normal file
81
NHSE.Parsing/PBC/PBC.cs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
|
||||
namespace NHSE.Parsing
|
||||
{
|
||||
public class PBC
|
||||
{
|
||||
private const uint MAGIC = 0x00636270; // pbc\0
|
||||
|
||||
public readonly byte[] Data;
|
||||
|
||||
public PBC(byte[] data)
|
||||
{
|
||||
Data = data;
|
||||
Debug.Assert(Magic == MAGIC);
|
||||
|
||||
Tiles = GetTiles();
|
||||
}
|
||||
|
||||
public readonly byte[] Tiles;
|
||||
|
||||
private byte[] GetTiles()
|
||||
{
|
||||
int offset = 0x14;
|
||||
var w = Width;
|
||||
var h = Height;
|
||||
byte[] data = new byte[w * h * 4];
|
||||
|
||||
for (int y = 0; y < h; y++)
|
||||
{
|
||||
for (int x = 0; x < w; x++)
|
||||
{
|
||||
var ofs = offset + 0x30;
|
||||
data[(x * 2) + (w * 2 * (y * 2))] = Data[ofs + 0];
|
||||
data[(x * 2) + (w * 2 * ((y * 2) + 1))] = Data[ofs + 1];
|
||||
data[(x * 2) + (w * 2 * ((y * 2) + 1)) + 1] = Data[ofs + 2];
|
||||
data[(x * 2) + (w * 2 * (y * 2)) + 1] = Data[ofs + 3];
|
||||
offset += 0x34;
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public byte GetTile(int x, int y) => Tiles[(y * Width) + x];
|
||||
public Color GetTileColor(int x, int y) => Dict[GetTile(x, y)];
|
||||
|
||||
public uint Magic => BitConverter.ToUInt32(Data, 0x00);
|
||||
public uint Width => BitConverter.ToUInt32(Data, 0x04);
|
||||
public uint Height => BitConverter.ToUInt32(Data, 0x08);
|
||||
|
||||
public static readonly Dictionary<byte, Color> Dict = new Dictionary<byte, Color>
|
||||
{
|
||||
{00, Color.FromArgb( 70, 120, 64)}, // Grass
|
||||
{01, Color.FromArgb(128, 215, 195)}, // River
|
||||
{03, Color.FromArgb(192, 192, 192)}, // Stone
|
||||
{04, Color.FromArgb(240, 230, 170)}, // Sand
|
||||
{05, Color.FromArgb(128, 215, 195)}, // Sea
|
||||
{06, Color.FromArgb(255, 128, 128)}, // Wood
|
||||
{07, Color.FromArgb(0 , 0, 0)}, // Null
|
||||
{08, Color.FromArgb(32 , 32, 32)}, // Building
|
||||
{09, Color.FromArgb(255, 0, 0)}, // ??
|
||||
{10, Color.FromArgb(48 , 48, 48)}, // Door
|
||||
{12, Color.FromArgb(128, 215, 195)}, // Water at mouths of river
|
||||
{15, Color.FromArgb(128, 215, 195)}, // Strip of water between river mouth and river
|
||||
{22, Color.FromArgb(190, 98, 98)}, // Wood (thin)
|
||||
{28, Color.FromArgb(255, 0, 0)}, // ?? this one isn't even in ColGroundAttributeParam...
|
||||
{29, Color.FromArgb(232, 222, 162)}, // Edge of beach, next to sea
|
||||
{41, Color.FromArgb(118, 122, 132)}, // Rocks at top of map
|
||||
{42, Color.FromArgb(128, 133, 147)}, // Taller regions, rocks at top of map
|
||||
{44, Color.FromArgb( 62, 112, 56)}, // Edge connecting grass and beach
|
||||
{45, Color.FromArgb(118, 122, 132)}, // Some kind of rock
|
||||
{46, Color.FromArgb(120, 207, 187)}, // Edge of sea, next to beach
|
||||
{47, Color.FromArgb(128, 128, 0)}, // Sandstone
|
||||
{49, Color.FromArgb(190, 98, 98)}, // Pier
|
||||
{51, Color.FromArgb(32 , 152, 32)}, // "Grass-growing building"??
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -124,10 +124,7 @@ private static void GetAcre1(int topX, int topY, TerrainManager t, int[] data)
|
|||
{
|
||||
var yi = y + topY;
|
||||
for (int x = 0; x < 16; x++, index++)
|
||||
{
|
||||
var tile = t.GetTile(x + topX, yi);
|
||||
data[index] = TerrainTileColor.GetTileColor(tile).ToArgb();
|
||||
}
|
||||
data[index] = t.GetTileColor(x + topX, yi);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public TerrainEditor(MainSave sav)
|
|||
this.TranslateInterface(GameInfo.CurrentLanguage);
|
||||
|
||||
SAV = sav;
|
||||
Terrain = new TerrainManager(SAV.GetTerrainTiles());
|
||||
Terrain = new TerrainManager(SAV.GetTerrainTiles(), sav.GetAcreBytes());
|
||||
Grid = GenerateGrid(GridWidth, GridHeight);
|
||||
|
||||
foreach (var acre in MapGrid.Acres)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user