diff --git a/docs/landscape.html b/docs/landscape.html
index bee6e994de..c361f4f01d 100644
--- a/docs/landscape.html
+++ b/docs/landscape.html
@@ -1566,6 +1566,8 @@
- m1: owner of the object (for lighthouses and transmitters normally 10)
- m2: see company statue
+
- m3 bits 4..2: size of HQ
+
- m3 bits 1..0: section identification of the HQ
- m5: tile type:
@@ -1593,8 +1595,8 @@
- 80..93 |
- company headquarters (5 sets of 4 tiles each, updated quarterly depending on the company performance) |
+ 04 |
+ company headquarters |
diff --git a/docs/landscape_grid.html b/docs/landscape_grid.html
index 8ace413046..1b33f51a95 100644
--- a/docs/landscape_grid.html
+++ b/docs/landscape_grid.html
@@ -331,9 +331,9 @@ the array so you can quickly see what is used and what is not.
XXXX XXXX |
~~~X XXXX |
OOOO OOOO OOOO OOOO |
+ OOOX XXXX |
OOOO OOOO |
- OOOO OOOO |
- X~~X XXXX |
+ XXXX XXXX |
XXOO OOXX |
OOOO OOOO |
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index acfe903dd9..af22f844c9 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -1694,6 +1694,21 @@ bool AfterLoadGame()
}
}
+ if (CheckSavegameVersion(112)) {
+ for (TileIndex t = 0; t < map_size; t++) {
+ /* Check for HQ bit being set, instead of using map accessor,
+ * since we've already changed it code-wise */
+ if (IsTileType(t, MP_UNMOVABLE) && HasBit(_m[t].m5, 7)) {
+ /* Move size and part identification of HQ out of the m5 attribute,
+ * on new locations */
+ uint8 old_m5 = _m[t].m5;
+ _m[t].m5 = UNMOVABLE_HQ;
+ SetCompanyHQSize(t, GB(old_m5, 2, 3));
+ SetCompanyHQSection(t, GB(old_m5, 0, 2));
+ }
+ }
+ }
+
GamelogPrintDebug(1);
bool ret = InitializeWindowsAndCaches();
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 0f241f3a1b..466a67d539 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -42,7 +42,7 @@
#include
-extern const uint16 SAVEGAME_VERSION = 111;
+extern const uint16 SAVEGAME_VERSION = 112;
SavegameType _savegame_type; ///< type of savegame we are loading
diff --git a/src/unmovable_cmd.cpp b/src/unmovable_cmd.cpp
index f6eb3ea700..adcc57bac2 100644
--- a/src/unmovable_cmd.cpp
+++ b/src/unmovable_cmd.cpp
@@ -167,6 +167,7 @@ static void DrawTile_Unmovable(TileInfo *ti)
{
switch (GetUnmovableType(ti->tile)) {
+ default: NOT_REACHED(); break;
case UNMOVABLE_TRANSMITTER:
case UNMOVABLE_LIGHTHOUSE: {
const DrawTileSeqStruct *dtu = &_draw_tile_transmitterlighthouse_data[GetUnmovableType(ti->tile)];
@@ -205,13 +206,13 @@ static void DrawTile_Unmovable(TileInfo *ti)
DrawBridgeMiddle(ti);
break;
- default: {
+ case UNMOVABLE_HQ:{
assert(IsCompanyHQ(ti->tile));
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
SpriteID palette = COMPANY_SPRITE_COLOR(GetTileOwner(ti->tile));
- const DrawTileSprites *t = &_unmovable_display_datas[GetCompanyHQSection(ti->tile)];
+ const DrawTileSprites *t = &_unmovable_display_datas[GetCompanyHQSize(ti->tile) << 2 | GetCompanyHQSection(ti->tile)];
DrawGroundSprite(t->ground.sprite, palette);
if (IsInvisibilitySet(TO_STRUCTURES)) break;
diff --git a/src/unmovable_map.h b/src/unmovable_map.h
index c814096d0d..91782728bb 100644
--- a/src/unmovable_map.h
+++ b/src/unmovable_map.h
@@ -8,28 +8,15 @@
#include "core/bitmath_func.hpp"
#include "tile_map.h"
-enum {
- HQ_NUM_TILE = 4, ///< Number of HQ tiles
- HQ_NUM_SIZE = 5 ///< Number of stages of an HQ
-};
-
/** Types of unmovable structure */
enum UnmovableType {
UNMOVABLE_TRANSMITTER = 0, ///< The large antenna
UNMOVABLE_LIGHTHOUSE = 1, ///< The nice lighthouse
UNMOVABLE_STATUE = 2, ///< Statue in towns
UNMOVABLE_OWNED_LAND = 3, ///< Owned land 'flag'
- UNMOVABLE_HQ_NORTH = 0x80, ///< Offset for the northern HQ tile
- UNMOVABLE_HQ_WEST = 0x81, ///< Offset for the western HQ tile
- UNMOVABLE_HQ_EAST = 0x82, ///< Offset for the eastern HQ tile
- UNMOVABLE_HQ_SOUTH = 0x83, ///< Offset for the southern HQ tile
-
- /** End of the HQ (rather end + 1 for IsInside) */
- UNMOVABLE_HQ_END = UNMOVABLE_HQ_NORTH + HQ_NUM_SIZE * HQ_NUM_TILE
+ UNMOVABLE_HQ = 4, ///< HeadQuarter of a player
};
-
-
/**
* Gets the UnmovableType of the given unmovable tile
* @param t the tile to get the type from.
@@ -83,7 +70,7 @@ static inline bool IsOwnedLandTile(TileIndex t)
static inline bool IsCompanyHQ(TileIndex t)
{
assert(IsTileType(t, MP_UNMOVABLE));
- return HasBit(_m[t].m5, 7);
+ return _m[t].m5 == UNMOVABLE_HQ;
}
/**
@@ -129,11 +116,24 @@ static inline TownID GetStatueTownID(TileIndex t)
static inline byte GetCompanyHQSize(TileIndex t)
{
assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
- return GB(_m[t].m5, 2, 3);
+ return GB(_m[t].m3, 2, 3);
}
/**
- * Get the 'section' (including stage) of the HQ.
+ * Set the 'stage' of the HQ.
+ * @param t a tile of the HQ.
+ * @param size the actual stage of the HQ
+ * @pre IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t)
+ */
+static inline void SetCompanyHQSize(TileIndex t, uint8 size)
+{
+ assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
+ SB(_m[t].m3, 2, 3, size);
+}
+
+/**
+ * Get the 'section' of the HQ.
+ * The scetion is in fact which side of teh HQ the tile represent
* @param t a tile of the HQ.
* @pre IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t)
* @return the 'section' of the HQ.
@@ -141,7 +141,19 @@ static inline byte GetCompanyHQSize(TileIndex t)
static inline byte GetCompanyHQSection(TileIndex t)
{
assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
- return GB(_m[t].m5, 0, 5);
+ return GB(_m[t].m3, 0, 2);
+}
+
+/**
+ * Set the 'section' of the HQ.
+ * @param t a tile of the HQ.
+ * param section to be set.
+ * @pre IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t)
+ */
+static inline void SetCompanyHQSection(TileIndex t, uint8 section)
+{
+ assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
+ SB(_m[t].m3, 0, 2, section);
}
/**
@@ -153,15 +165,15 @@ static inline byte GetCompanyHQSection(TileIndex t)
*/
static inline void EnlargeCompanyHQ(TileIndex t, byte size)
{
- assert(GB(GetCompanyHQSection(t), 0, 2) == 0);
+ assert(GetCompanyHQSection(t) == 0);
- size *= 4;
- if (size <= _m[t].m5 - UNMOVABLE_HQ_NORTH) return;
+ size++;
+ if (size <= GetCompanyHQSize(t)) return;
- _m[t + TileDiffXY(0, 0)].m5 = UNMOVABLE_HQ_NORTH + size;
- _m[t + TileDiffXY(0, 1)].m5 = UNMOVABLE_HQ_WEST + size;
- _m[t + TileDiffXY(1, 0)].m5 = UNMOVABLE_HQ_EAST + size;
- _m[t + TileDiffXY(1, 1)].m5 = UNMOVABLE_HQ_SOUTH + size;
+ SetCompanyHQSize(t , size);
+ SetCompanyHQSize(t + TileDiffXY(0, 1), size);
+ SetCompanyHQSize(t + TileDiffXY(1, 0), size);
+ SetCompanyHQSize(t + TileDiffXY(1, 1), size);
}
@@ -223,6 +235,18 @@ static inline void MakeOwnedLand(TileIndex t, Owner o)
MakeUnmovable(t, UNMOVABLE_OWNED_LAND, o);
}
+/**
+ * Make a HeadQuarter tile after making it an Unmovable
+ * @param t the tile to make an HQ.
+ * @param section the part of the HQ this one will be.
+ * @param o the new owner of the tile.
+ */
+static inline void MakeUnmovableHQHelper(TileIndex t, uint8 section, Owner o)
+{
+ MakeUnmovable(t, UNMOVABLE_HQ, o);
+ SetCompanyHQSection(t, section);
+}
+
/**
* Make an HQ with the give tile as it's northern tile.
* @param t the tile to make the northern tile of a HQ.
@@ -230,10 +254,10 @@ static inline void MakeOwnedLand(TileIndex t, Owner o)
*/
static inline void MakeCompanyHQ(TileIndex t, Owner o)
{
- MakeUnmovable(t + TileDiffXY(0, 0), UNMOVABLE_HQ_NORTH, o);
- MakeUnmovable(t + TileDiffXY(0, 1), UNMOVABLE_HQ_WEST, o);
- MakeUnmovable(t + TileDiffXY(1, 0), UNMOVABLE_HQ_EAST, o);
- MakeUnmovable(t + TileDiffXY(1, 1), UNMOVABLE_HQ_SOUTH, o);
+ MakeUnmovableHQHelper(t , 0, o);
+ MakeUnmovableHQHelper(t + TileDiffXY(0, 1), 1, o);
+ MakeUnmovableHQHelper(t + TileDiffXY(1, 0), 2, o);
+ MakeUnmovableHQHelper(t + TileDiffXY(1, 1), 3, o);
}
#endif /* UNMOVABLE_MAP_H */