Changeset - r10951:c8234203bc5f
[Not reviewed]
master
0 6 0
belugas - 16 years ago 2009-01-28 19:57:23
belugas@openttd.org
(svn r15290) -Codechange: Isolate size and section of the UnMovable HQ object, in order to keep the Unmovable type free of any irrelevant data
6 files changed with 78 insertions and 36 deletions:
0 comments (0 inline, 0 general)
docs/landscape.html
Show inline comments
 
@@ -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>&nbsp; </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>&nbsp; </td>
 
        <td align=left>company headquarters</td>
 
       </tr>
 
      </table>
 
     </li>
docs/landscape_grid.html
Show inline comments
 
@@ -331,9 +331,9 @@ the array so you can quickly see what is
 
      <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">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">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>
src/saveload/afterload.cpp
Show inline comments
 
@@ -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();
src/saveload/saveload.cpp
Show inline comments
 
@@ -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
 

	
src/unmovable_cmd.cpp
Show inline comments
 
@@ -167,6 +167,7 @@ static void DrawTile_Unmovable(TileInfo 
 
{
 

	
 
	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 
 
			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;
src/unmovable_map.h
Show inline comments
 
@@ -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(TileI
 
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(Til
 
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(Tile
 
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(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(TileInd
 
}
 

	
 
/**
 
 * 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 */
0 comments (0 inline, 0 general)