diff options
-rw-r--r-- | docs/landscape.html | 6 | ||||
-rw-r--r-- | docs/landscape_grid.html | 4 | ||||
-rw-r--r-- | src/saveload/afterload.cpp | 15 | ||||
-rw-r--r-- | src/saveload/saveload.cpp | 2 | ||||
-rw-r--r-- | src/unmovable_cmd.cpp | 5 | ||||
-rw-r--r-- | src/unmovable_map.h | 82 |
6 files changed, 78 insertions, 36 deletions
diff --git a/docs/landscape.html b/docs/landscape.html index bee6e994d..c361f4f01 100644 --- a/docs/landscape.html +++ b/docs/landscape.html @@ -1566,6 +1566,8 @@ <ul> <li>m1: <a href="#OwnershipInfo">owner</a> of the object (for lighthouses and transmitters normally <tt>10</tt>)</li> <li>m2: see company statue + <li>m3 bits 4..2: size of HQ + <li>m3 bits 1..0: section identification of the HQ <li>m5: tile type: <table> <tr> @@ -1593,8 +1595,8 @@ </tr> <tr> - <td nowrap valign=top><tt>80</tt>..<tt>93</tt> </td> - <td align=left>company headquarters (5 sets of 4 tiles each, updated quarterly depending on the company performance)</td> + <td nowrap valign=top><tt>04</tt><tt></tt> </td> + <td align=left>company headquarters</td> </tr> </table> </li> diff --git a/docs/landscape_grid.html b/docs/landscape_grid.html index 8ace41304..1b33f51a9 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. <td class="bits">XXXX XXXX</td> <td class="bits"><span class="option">~~~</span>X XXXX</td> <td class="bits"><span class="free">OOOO OOOO OOOO OOOO</span></td> + <td class="bits"><span class="free">OOO</span>X XXXX</td> <td class="bits"><span class="free">OOOO OOOO</span></td> - <td class="bits"><span class="free">OOOO OOOO</span></td> - <td class="bits">X<span class="option">~~</span>X XXXX</td> + <td class="bits">XXXX XXXX</td> <td class="bits">XX<span class="free">OO OO</span>XX</td> <td class="bits"><span class="free">OOOO OOOO</span></td> </tr> diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index acfe903dd..af22f844c 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 0f241f3a1..466a67d53 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -42,7 +42,7 @@ #include <list> -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 f6eb3ea70..adcc57bac 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 c814096d0..91782728b 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); +} + +/** + * 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' (including stage) of the HQ. + * 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); } @@ -224,16 +236,28 @@ static inline void MakeOwnedLand(TileIndex t, Owner 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. * @param o the owner of the HQ. */ 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 */ |