diff --git a/OpenPolytopia.Common/City.cs b/OpenPolytopia.Common/City.cs index a66f21b..0fc40ca 100644 --- a/OpenPolytopia.Common/City.cs +++ b/OpenPolytopia.Common/City.cs @@ -165,9 +165,9 @@ public struct CityData : ITileCustomData { /// public int Owner { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => (int)_inner.GetBits(FOUR_BITS, OWNER_POSITION); + get => (int)_inner.GetBits(FIVE_BITS, OWNER_POSITION); [MethodImpl(MethodImplOptions.AggressiveInlining)] - set => _inner.SetBits((uint)value, FOUR_BITS, OWNER_POSITION); + set => _inner.SetBits((uint)value, FIVE_BITS, OWNER_POSITION); } /// diff --git a/OpenPolytopia.Common/Grid.cs b/OpenPolytopia.Common/Grid.cs index dbc7f14..cc29050 100644 --- a/OpenPolytopia.Common/Grid.cs +++ b/OpenPolytopia.Common/Grid.cs @@ -181,10 +181,10 @@ public struct Tile { private const int TILEKIND_POSITION = 59; private const int TILE_MODIFIER_POSITION = 57; private const int TILE_BUILDING_POSITION = 54; - private const int TILE_OWNER_POSITION = 50; - private const int TILE_BIOME_POSITION = 45; - private const int CITY_POSITION = 37; - private const int WONDER_POSITION = 33; + private const int TILE_OWNER_POSITION = 49; + private const int TILE_BIOME_POSITION = 44; + private const int CITY_POSITION = 36; + private const int WONDER_POSITION = 32; private const int CUSTOM_DATA_POSITION = 0; private const int ONE_BIT = 1; @@ -202,7 +202,7 @@ public struct Tile { /// /// This is represented as the number of bits set to 1, not as the number itself /// - public const ulong MAX_CUSTOM_DATA_BITS = 8_589_934_591; + public const ulong MAX_CUSTOM_DATA_BITS = 4_294_967_295; /// /// Returns the corresponding modifier enum's from a @@ -232,11 +232,11 @@ public static Type GetModifier(TileKind kind) => /// [2, 4] -> /// [5, 6] -> Tile modifier /// [7, 9] -> Tile buildings - /// [10, 13] -> Tile owner; if 0 no owner - /// [14, 18] -> Tribe biome - /// [19, 26] -> City ID; if 0 no city - /// [27, 30] -> Wonder - /// [31, 63] -> Custom data + /// [10, 14] -> Tile owner; if 0 no owner + /// [15, 19] -> Tribe biome + /// [20, 27] -> City ID; if 0 no city + /// [28, 31] -> Wonder + /// [32, 63] -> Custom data /// /// private ulong _inner; @@ -299,9 +299,9 @@ public int Building { /// public int Owner { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => (int)_inner.GetBits(FOUR_BITS, TILE_OWNER_POSITION); + get => (int)_inner.GetBits(FIVE_BITS, TILE_OWNER_POSITION); [MethodImpl(MethodImplOptions.AggressiveInlining)] - set => _inner.SetBits((ulong)value, FOUR_BITS, TILE_OWNER_POSITION); + set => _inner.SetBits((ulong)value, FIVE_BITS, TILE_OWNER_POSITION); } /// diff --git a/OpenPolytopia.Common/TerrainGeneration.cs b/OpenPolytopia.Common/TerrainGeneration.cs index a38f63c..beb43f3 100644 --- a/OpenPolytopia.Common/TerrainGeneration.cs +++ b/OpenPolytopia.Common/TerrainGeneration.cs @@ -56,9 +56,12 @@ public class TerrainGeneration( // one village every VILLAGE_DIVISOR eligible tiles private const int VILLAGE_DIVISOR = 9; - // Tile.City is 8 bits so there can't be more than 255 cities in a grid + // registering more cities than this makes CityManager throw private const int MAX_CITIES = 255; + // biggest lobby a game can be started from + private const int MAX_PLAYERS = 16; + // zone map values, used for village spacing and resource spawning private const byte ZONE_FREE = 0; private const byte ZONE_BORDER = 1; @@ -128,17 +131,16 @@ public async Task GenerateMapAsync() { "the map has already been generated; create a new TerrainGeneration to generate another map"); } - // Tile.Owner is 4 bits, so there can't be more than 15 players - if (players.Length is 0 or > 15) { + if (players.Length is 0 or > MAX_PLAYERS) { throw new InvalidOperationException( - $"invalid number of players: {players.Length}; must be between 1 and 15"); + $"invalid number of players: {players.Length}; must be between 1 and {MAX_PLAYERS}"); } var seenIds = 0; foreach (var player in players) { - // player ids must fit in the 4-bit Tile.Owner field, where 0 means no owner - if (player.Id is < 1 or > 15) { - throw new InvalidOperationException($"invalid player id: {player.Id}; must be between 1 and 15"); + // 0 is the id of the tiles nobody owns, so no player can have it + if (player.Id is < 1 or > MAX_PLAYERS) { + throw new InvalidOperationException($"invalid player id: {player.Id}; must be between 1 and {MAX_PLAYERS}"); } // a duplicate id would merge the territories of two players