src/unmovable_map.h
branchcpp_gui
changeset 6308 646711c5feaa
parent 6307 f40e88cff863
equal deleted inserted replaced
6307:f40e88cff863 6308:646711c5feaa
     4 
     4 
     5 #ifndef UNMOVABLE_MAP_H
     5 #ifndef UNMOVABLE_MAP_H
     6 #define UNMOVABLE_MAP_H
     6 #define UNMOVABLE_MAP_H
     7 
     7 
     8 enum {
     8 enum {
     9 	HQ_NUM_TILE = 4,
     9 	HQ_NUM_TILE = 4, ///< Number of HQ tiles
    10 	HQ_NUM_SIZE = 5
    10 	HQ_NUM_SIZE = 5  ///< Number of stages of an HQ
    11 };
    11 };
    12 
    12 
       
    13 /** Types of unmovable structure */
    13 enum UnmovableType {
    14 enum UnmovableType {
    14 	UNMOVABLE_TRANSMITTER = 0,
    15 	UNMOVABLE_TRANSMITTER = 0,    ///< The large antenna
    15 	UNMOVABLE_LIGHTHOUSE  = 1,
    16 	UNMOVABLE_LIGHTHOUSE  = 1,    ///< The nice lighthouse
    16 	UNMOVABLE_STATUE      = 2,
    17 	UNMOVABLE_STATUE      = 2,    ///< Statue in towns
    17 	UNMOVABLE_OWNED_LAND  = 3,
    18 	UNMOVABLE_OWNED_LAND  = 3,    ///< Owned land 'flag'
    18 	UNMOVABLE_HQ_NORTH    = 0x80,
    19 	UNMOVABLE_HQ_NORTH    = 0x80, ///< Offset for the northern HQ tile
    19 	UNMOVABLE_HQ_WEST     = 0x81,
    20 	UNMOVABLE_HQ_WEST     = 0x81, ///< Offset for the western HQ tile
    20 	UNMOVABLE_HQ_EAST     = 0x82,
    21 	UNMOVABLE_HQ_EAST     = 0x82, ///< Offset for the eastern HQ tile
    21 	UNMOVABLE_HQ_SOUTH    = 0x83,
    22 	UNMOVABLE_HQ_SOUTH    = 0x83, ///< Offset for the southern HQ tile
    22 
    23 
       
    24 	/** End of the HQ (rather end + 1 for IS_INT_INSIDE) */
    23 	UNMOVABLE_HQ_END      = UNMOVABLE_HQ_NORTH + HQ_NUM_SIZE * HQ_NUM_TILE
    25 	UNMOVABLE_HQ_END      = UNMOVABLE_HQ_NORTH + HQ_NUM_SIZE * HQ_NUM_TILE
    24 };
    26 };
    25 
    27 
    26 
    28 
    27 
    29 
       
    30 /**
       
    31  * Gets the UnmovableType of the given unmovable tile
       
    32  * @param t the tile to get the type from.
       
    33  * @pre IsTileType(t, MP_UNMOVABLE)
       
    34  * @return the type.
       
    35  */
    28 static inline UnmovableType GetUnmovableType(TileIndex t)
    36 static inline UnmovableType GetUnmovableType(TileIndex t)
    29 {
    37 {
    30 	assert(IsTileType(t, MP_UNMOVABLE));
    38 	assert(IsTileType(t, MP_UNMOVABLE));
    31 	return (UnmovableType)_m[t].m5;
    39 	return (UnmovableType)_m[t].m5;
    32 }
    40 }
    33 
    41 
    34 
    42 /**
       
    43  * Does the given tile have a transmitter?
       
    44  * @param t the tile to inspect.
       
    45  * @return true if and only if the tile has a transmitter.
       
    46  */
    35 static inline bool IsTransmitterTile(TileIndex t)
    47 static inline bool IsTransmitterTile(TileIndex t)
    36 {
    48 {
    37 	return
    49 	return IsTileType(t, MP_UNMOVABLE) && GetUnmovableType(t) == UNMOVABLE_TRANSMITTER;
    38 		IsTileType(t, MP_UNMOVABLE) &&
    50 }
    39 		GetUnmovableType(t) == UNMOVABLE_TRANSMITTER;
    51 
    40 }
    52 /**
    41 
    53  * Is this unmovable tile an 'owned land' tile?
    42 
    54  * @param t the tile to inspect.
       
    55  * @pre IsTileType(t, MP_UNMOVABLE)
       
    56  * @return true if and only if the tile is an 'owned land' tile.
       
    57  */
    43 static inline bool IsOwnedLand(TileIndex t)
    58 static inline bool IsOwnedLand(TileIndex t)
    44 {
    59 {
    45 	assert(IsTileType(t, MP_UNMOVABLE));
    60 	assert(IsTileType(t, MP_UNMOVABLE));
    46 	return GetUnmovableType(t) == UNMOVABLE_OWNED_LAND;
    61 	return GetUnmovableType(t) == UNMOVABLE_OWNED_LAND;
    47 }
    62 }
    48 
    63 
       
    64 /**
       
    65  * Is the given tile (pre-)owned by someone (the little flags)?
       
    66  * @param t the tile to inspect.
       
    67  * @return true if and only if the tile is an 'owned land' tile.
       
    68  */
    49 static inline bool IsOwnedLandTile(TileIndex t)
    69 static inline bool IsOwnedLandTile(TileIndex t)
    50 {
    70 {
    51 	return IsTileType(t, MP_UNMOVABLE) && IsOwnedLand(t);
    71 	return IsTileType(t, MP_UNMOVABLE) && IsOwnedLand(t);
    52 }
    72 }
    53 
    73 
       
    74 /**
       
    75  * Is this unmovable tile a HQ tile?
       
    76  * @param t the tile to inspect.
       
    77  * @pre IsTileType(t, MP_UNMOVABLE)
       
    78  * @return true if and only if the tile is a HQ tile.
       
    79  */
    54 static inline bool IsCompanyHQ(TileIndex t)
    80 static inline bool IsCompanyHQ(TileIndex t)
    55 {
    81 {
       
    82 	assert(IsTileType(t, MP_UNMOVABLE));
    56 	return IS_INT_INSIDE(GetUnmovableType(t), UNMOVABLE_HQ_NORTH, UNMOVABLE_HQ_END);
    83 	return IS_INT_INSIDE(GetUnmovableType(t), UNMOVABLE_HQ_NORTH, UNMOVABLE_HQ_END);
    57 }
    84 }
    58 
    85 
       
    86 /**
       
    87  * Is this unmovable tile a statue?
       
    88  * @param t the tile to inspect.
       
    89  * @pre IsTileType(t, MP_UNMOVABLE)
       
    90  * @return true if and only if the tile is a statue.
       
    91  */
    59 static inline bool IsStatue(TileIndex t)
    92 static inline bool IsStatue(TileIndex t)
    60 {
    93 {
    61 	assert(IsTileType(t, MP_UNMOVABLE));
    94 	assert(IsTileType(t, MP_UNMOVABLE));
    62 	return GetUnmovableType(t) == UNMOVABLE_STATUE;
    95 	return GetUnmovableType(t) == UNMOVABLE_STATUE;
    63 }
    96 }
    64 
    97 
       
    98 /**
       
    99  * Is the given tile a statue?
       
   100  * @param t the tile to inspect.
       
   101  * @return true if and only if the tile is a statue.
       
   102  */
    65 static inline bool IsStatueTile(TileIndex t)
   103 static inline bool IsStatueTile(TileIndex t)
    66 {
   104 {
    67 	return IsTileType(t, MP_UNMOVABLE) && IsStatue(t);
   105 	return IsTileType(t, MP_UNMOVABLE) && IsStatue(t);
    68 }
   106 }
    69 
   107 
       
   108 /**
       
   109  * Get the town of the given statue tile.
       
   110  * @param t the tile of the statue.
       
   111  * @pre IsStatueTile(t)
       
   112  * @return the town the given statue is in.
       
   113  */
    70 static inline TownID GetStatueTownID(TileIndex t)
   114 static inline TownID GetStatueTownID(TileIndex t)
    71 {
   115 {
    72 	assert(IsStatue(t));
   116 	assert(IsStatueTile(t));
    73 	return _m[t].m2;
   117 	return _m[t].m2;
    74 }
   118 }
    75 
   119 
       
   120 /**
       
   121  * Get the 'stage' of the HQ.
       
   122  * @param t a tile of the HQ.
       
   123  * @pre IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t)
       
   124  * @return the 'stage' of the HQ.
       
   125  */
    76 static inline byte GetCompanyHQSize(TileIndex t)
   126 static inline byte GetCompanyHQSize(TileIndex t)
    77 {
   127 {
    78 	assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
   128 	assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
    79 	return GB(_m[t].m5, 2, 3);
   129 	return GB(_m[t].m5, 2, 3);
    80 }
   130 }
    81 
   131 
       
   132 /**
       
   133  * Get the 'section' (including stage) of the HQ.
       
   134  * @param t a tile of the HQ.
       
   135  * @pre IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t)
       
   136  * @return the 'section' of the HQ.
       
   137  */
    82 static inline byte GetCompanyHQSection(TileIndex t)
   138 static inline byte GetCompanyHQSection(TileIndex t)
    83 {
   139 {
    84 	assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
   140 	assert(IsTileType(t, MP_UNMOVABLE) && IsCompanyHQ(t));
    85 	return GB(_m[t].m5, 0, 5);
   141 	return GB(_m[t].m5, 0, 5);
    86 }
   142 }
    87 
   143 
    88 
   144 /**
       
   145  * Enlarge the given HQ to the given size. If the new size
       
   146  * is larger than the current size, nothing happens.
       
   147  * @param t the tile of the HQ.
       
   148  * @param size the new size of the HQ.
       
   149  * @pre t is the northern tile of the HQ
       
   150  */
    89 static inline void EnlargeCompanyHQ(TileIndex t, byte size)
   151 static inline void EnlargeCompanyHQ(TileIndex t, byte size)
    90 {
   152 {
       
   153 	assert(GB(GetCompanyHQSection(t), 0, 2) == 0);
       
   154 
    91 	size *= 4;
   155 	size *= 4;
    92 	if (size <= _m[t].m5 - UNMOVABLE_HQ_NORTH) return;
   156 	if (size <= _m[t].m5 - UNMOVABLE_HQ_NORTH) return;
    93 
   157 
    94 	_m[t + TileDiffXY(0, 0)].m5 = UNMOVABLE_HQ_NORTH + size;
   158 	_m[t + TileDiffXY(0, 0)].m5 = UNMOVABLE_HQ_NORTH + size;
    95 	_m[t + TileDiffXY(0, 1)].m5 = UNMOVABLE_HQ_WEST  + size;
   159 	_m[t + TileDiffXY(0, 1)].m5 = UNMOVABLE_HQ_WEST  + size;
    96 	_m[t + TileDiffXY(1, 0)].m5 = UNMOVABLE_HQ_EAST  + size;
   160 	_m[t + TileDiffXY(1, 0)].m5 = UNMOVABLE_HQ_EAST  + size;
    97 	_m[t + TileDiffXY(1, 1)].m5 = UNMOVABLE_HQ_SOUTH + size;
   161 	_m[t + TileDiffXY(1, 1)].m5 = UNMOVABLE_HQ_SOUTH + size;
    98 }
   162 }
    99 
   163 
   100 
   164 
       
   165 /**
       
   166  * Make an Unmovable tile.
       
   167  * @note do not use this function directly. Use one of the other Make* functions.
       
   168  * @param t the tile to make unmovable.
       
   169  * @param u the unmovable type of the tile.
       
   170  * @param o the new owner of the tile.
       
   171  */
   101 static inline void MakeUnmovable(TileIndex t, UnmovableType u, Owner o)
   172 static inline void MakeUnmovable(TileIndex t, UnmovableType u, Owner o)
   102 {
   173 {
   103 	SetTileType(t, MP_UNMOVABLE);
   174 	SetTileType(t, MP_UNMOVABLE);
   104 	SetTileOwner(t, o);
   175 	SetTileOwner(t, o);
   105 	_m[t].m2 = 0;
   176 	_m[t].m2 = 0;
   107 	_m[t].m4 = 0;
   178 	_m[t].m4 = 0;
   108 	_m[t].m5 = u;
   179 	_m[t].m5 = u;
   109 }
   180 }
   110 
   181 
   111 
   182 
       
   183 /**
       
   184  * Make a transmitter tile.
       
   185  * @param t the tile to make a transmitter.
       
   186  */
   112 static inline void MakeTransmitter(TileIndex t)
   187 static inline void MakeTransmitter(TileIndex t)
   113 {
   188 {
   114 	MakeUnmovable(t, UNMOVABLE_TRANSMITTER, OWNER_NONE);
   189 	MakeUnmovable(t, UNMOVABLE_TRANSMITTER, OWNER_NONE);
   115 }
   190 }
   116 
   191 
       
   192 /**
       
   193  * Make a lighthouse tile.
       
   194  * @param t the tile to make a transmitter.
       
   195  */
   117 static inline void MakeLighthouse(TileIndex t)
   196 static inline void MakeLighthouse(TileIndex t)
   118 {
   197 {
   119 	MakeUnmovable(t, UNMOVABLE_LIGHTHOUSE, OWNER_NONE);
   198 	MakeUnmovable(t, UNMOVABLE_LIGHTHOUSE, OWNER_NONE);
   120 }
   199 }
   121 
   200 
       
   201 /**
       
   202  * Make a statue tile.
       
   203  * @param t the tile to make a statue.
       
   204  * @param o the owner of the statue.
       
   205  * @param town_id the town the statue was built in.
       
   206  */
   122 static inline void MakeStatue(TileIndex t, Owner o, TownID town_id)
   207 static inline void MakeStatue(TileIndex t, Owner o, TownID town_id)
   123 {
   208 {
   124 	MakeUnmovable(t, UNMOVABLE_STATUE, o);
   209 	MakeUnmovable(t, UNMOVABLE_STATUE, o);
   125 	_m[t].m2 = town_id;
   210 	_m[t].m2 = town_id;
   126 }
   211 }
   127 
   212 
       
   213 /**
       
   214  * Make an 'owned land' tile.
       
   215  * @param t the tile to make an 'owned land' tile.
       
   216  * @param o the owner of the land.
       
   217  */
   128 static inline void MakeOwnedLand(TileIndex t, Owner o)
   218 static inline void MakeOwnedLand(TileIndex t, Owner o)
   129 {
   219 {
   130 	MakeUnmovable(t, UNMOVABLE_OWNED_LAND, o);
   220 	MakeUnmovable(t, UNMOVABLE_OWNED_LAND, o);
   131 }
   221 }
   132 
   222 
       
   223 /**
       
   224  * Make an HQ with the give tile as it's northern tile.
       
   225  * @param t the tile to make the northern tile of a HQ.
       
   226  * @param o the owner of the HQ.
       
   227  */
   133 static inline void MakeCompanyHQ(TileIndex t, Owner o)
   228 static inline void MakeCompanyHQ(TileIndex t, Owner o)
   134 {
   229 {
   135 	MakeUnmovable(t + TileDiffXY(0, 0), UNMOVABLE_HQ_NORTH, o);
   230 	MakeUnmovable(t + TileDiffXY(0, 0), UNMOVABLE_HQ_NORTH, o);
   136 	MakeUnmovable(t + TileDiffXY(0, 1), UNMOVABLE_HQ_WEST, o);
   231 	MakeUnmovable(t + TileDiffXY(0, 1), UNMOVABLE_HQ_WEST, o);
   137 	MakeUnmovable(t + TileDiffXY(1, 0), UNMOVABLE_HQ_EAST, o);
   232 	MakeUnmovable(t + TileDiffXY(1, 0), UNMOVABLE_HQ_EAST, o);