(svn r15290) -Codechange: Isolate size and section of the UnMovable HQ object, in order to keep the Unmovable type free of any irrelevant data

This commit is contained in:
belugas 2009-01-28 19:57:23 +00:00
parent bfde9f7eef
commit 3671ed9e4f
6 changed files with 78 additions and 36 deletions

View File

@ -1566,6 +1566,8 @@
<ul> <ul>
<li>m1: <a href="#OwnershipInfo">owner</a> of the object (for lighthouses and transmitters normally <tt>10</tt>)</li> <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>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: <li>m5: tile type:
<table> <table>
<tr> <tr>
@ -1593,8 +1595,8 @@
</tr> </tr>
<tr> <tr>
<td nowrap valign=top><tt>80</tt>..<tt>93</tt>&nbsp; </td> <td nowrap valign=top><tt>04</tt><tt></tt>&nbsp; </td>
<td align=left>company headquarters (5 sets of 4 tiles each, updated quarterly depending on the company performance)</td> <td align=left>company headquarters</td>
</tr> </tr>
</table> </table>
</li> </li>

View File

@ -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">XXXX XXXX</td>
<td class="bits"><span class="option">~~~</span>X 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">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"><span class="free">OOOO OOOO</span></td> <td class="bits">XXXX XXXX</td>
<td class="bits">X<span class="option">~~</span>X XXXX</td>
<td class="bits">XX<span class="free">OO OO</span>XX</td> <td class="bits">XX<span class="free">OO OO</span>XX</td>
<td class="bits"><span class="free">OOOO OOOO</span></td> <td class="bits"><span class="free">OOOO OOOO</span></td>
</tr> </tr>

View File

@ -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); GamelogPrintDebug(1);
bool ret = InitializeWindowsAndCaches(); bool ret = InitializeWindowsAndCaches();

View File

@ -42,7 +42,7 @@
#include <list> #include <list>
extern const uint16 SAVEGAME_VERSION = 111; extern const uint16 SAVEGAME_VERSION = 112;
SavegameType _savegame_type; ///< type of savegame we are loading SavegameType _savegame_type; ///< type of savegame we are loading

View File

@ -167,6 +167,7 @@ static void DrawTile_Unmovable(TileInfo *ti)
{ {
switch (GetUnmovableType(ti->tile)) { switch (GetUnmovableType(ti->tile)) {
default: NOT_REACHED(); break;
case UNMOVABLE_TRANSMITTER: case UNMOVABLE_TRANSMITTER:
case UNMOVABLE_LIGHTHOUSE: { case UNMOVABLE_LIGHTHOUSE: {
const DrawTileSeqStruct *dtu = &_draw_tile_transmitterlighthouse_data[GetUnmovableType(ti->tile)]; const DrawTileSeqStruct *dtu = &_draw_tile_transmitterlighthouse_data[GetUnmovableType(ti->tile)];
@ -205,13 +206,13 @@ static void DrawTile_Unmovable(TileInfo *ti)
DrawBridgeMiddle(ti); DrawBridgeMiddle(ti);
break; break;
default: { case UNMOVABLE_HQ:{
assert(IsCompanyHQ(ti->tile)); assert(IsCompanyHQ(ti->tile));
if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED);
SpriteID palette = COMPANY_SPRITE_COLOR(GetTileOwner(ti->tile)); 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); DrawGroundSprite(t->ground.sprite, palette);
if (IsInvisibilitySet(TO_STRUCTURES)) break; if (IsInvisibilitySet(TO_STRUCTURES)) break;

View File

@ -8,28 +8,15 @@
#include "core/bitmath_func.hpp" #include "core/bitmath_func.hpp"
#include "tile_map.h" #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 */ /** Types of unmovable structure */
enum UnmovableType { enum UnmovableType {
UNMOVABLE_TRANSMITTER = 0, ///< The large antenna UNMOVABLE_TRANSMITTER = 0, ///< The large antenna
UNMOVABLE_LIGHTHOUSE = 1, ///< The nice lighthouse UNMOVABLE_LIGHTHOUSE = 1, ///< The nice lighthouse
UNMOVABLE_STATUE = 2, ///< Statue in towns UNMOVABLE_STATUE = 2, ///< Statue in towns
UNMOVABLE_OWNED_LAND = 3, ///< Owned land 'flag' UNMOVABLE_OWNED_LAND = 3, ///< Owned land 'flag'
UNMOVABLE_HQ_NORTH = 0x80, ///< Offset for the northern HQ tile UNMOVABLE_HQ = 4, ///< HeadQuarter of a player
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
}; };
/** /**
* Gets the UnmovableType of the given unmovable tile * Gets the UnmovableType of the given unmovable tile
* @param t the tile to get the type from. * @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) static inline bool IsCompanyHQ(TileIndex t)
{ {
assert(IsTileType(t, MP_UNMOVABLE)); 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) static inline byte GetCompanyHQSize(TileIndex t)
{ {
assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(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. * @param t a tile of the HQ.
* @pre IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t) * @pre IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t)
* @return the 'section' of the HQ. * @return the 'section' of the HQ.
@ -141,7 +141,19 @@ static inline byte GetCompanyHQSize(TileIndex t)
static inline byte GetCompanyHQSection(TileIndex t) static inline byte GetCompanyHQSection(TileIndex t)
{ {
assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(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) static inline void EnlargeCompanyHQ(TileIndex t, byte size)
{ {
assert(GB(GetCompanyHQSection(t), 0, 2) == 0); assert(GetCompanyHQSection(t) == 0);
size *= 4; size++;
if (size <= _m[t].m5 - UNMOVABLE_HQ_NORTH) return; if (size <= GetCompanyHQSize(t)) return;
_m[t + TileDiffXY(0, 0)].m5 = UNMOVABLE_HQ_NORTH + size; SetCompanyHQSize(t , size);
_m[t + TileDiffXY(0, 1)].m5 = UNMOVABLE_HQ_WEST + size; SetCompanyHQSize(t + TileDiffXY(0, 1), size);
_m[t + TileDiffXY(1, 0)].m5 = UNMOVABLE_HQ_EAST + size; SetCompanyHQSize(t + TileDiffXY(1, 0), size);
_m[t + TileDiffXY(1, 1)].m5 = UNMOVABLE_HQ_SOUTH + 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); 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. * 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 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) static inline void MakeCompanyHQ(TileIndex t, Owner o)
{ {
MakeUnmovable(t + TileDiffXY(0, 0), UNMOVABLE_HQ_NORTH, o); MakeUnmovableHQHelper(t , 0, o);
MakeUnmovable(t + TileDiffXY(0, 1), UNMOVABLE_HQ_WEST, o); MakeUnmovableHQHelper(t + TileDiffXY(0, 1), 1, o);
MakeUnmovable(t + TileDiffXY(1, 0), UNMOVABLE_HQ_EAST, o); MakeUnmovableHQHelper(t + TileDiffXY(1, 0), 2, o);
MakeUnmovable(t + TileDiffXY(1, 1), UNMOVABLE_HQ_SOUTH, o); MakeUnmovableHQHelper(t + TileDiffXY(1, 1), 3, o);
} }
#endif /* UNMOVABLE_MAP_H */ #endif /* UNMOVABLE_MAP_H */