src/town_map.h
changeset 5726 8f399788f6c9
parent 3983 d2d6496238e4
child 6220 0c2371b1edda
equal deleted inserted replaced
5725:8ad0e96437e0 5726:8f399788f6c9
       
     1 /* $Id$ */
       
     2 
       
     3 /** @file town_map.h Accessors for towns */
       
     4 
       
     5 #ifndef TOWN_MAP_H
       
     6 #define TOWN_MAP_H
       
     7 
       
     8 #include "town.h"
       
     9 
       
    10 static inline int GetHouseType(TileIndex t)
       
    11 {
       
    12 	assert(IsTileType(t, MP_HOUSE));
       
    13 	return _m[t].m4;
       
    14 }
       
    15 
       
    16 static inline TownID GetTownIndex(TileIndex t)
       
    17 {
       
    18 	assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_STREET)); // XXX incomplete
       
    19 	return _m[t].m2;
       
    20 }
       
    21 
       
    22 /**
       
    23  * Set the town index for a road or house tile.
       
    24  * @param tile the tile
       
    25  * @param index the index of the town
       
    26  */
       
    27 static inline void SetTownIndex(TileIndex t, TownID index)
       
    28 {
       
    29 	assert(IsTileType(t, MP_STREET) || IsTileType(t, MP_HOUSE));
       
    30 	_m[t].m2 = index;
       
    31 }
       
    32 
       
    33 static inline bool LiftHasDestination(TileIndex t)
       
    34 {
       
    35 	return HASBIT(_m[t].m5, 7);
       
    36 }
       
    37 
       
    38 static inline void SetLiftDestination(TileIndex t, byte dest)
       
    39 {
       
    40 	SB(_m[t].m5, 0, 6, dest);
       
    41 	SETBIT(_m[t].m1, 7); /* Start moving */
       
    42 }
       
    43 
       
    44 static inline byte GetLiftDestination(TileIndex t)
       
    45 {
       
    46 	return GB(_m[t].m5, 0, 6);
       
    47 }
       
    48 
       
    49 static inline bool IsLiftMoving(TileIndex t)
       
    50 {
       
    51 	return HASBIT(_m[t].m1, 7);
       
    52 }
       
    53 
       
    54 static inline void BeginLiftMovement(TileIndex t)
       
    55 {
       
    56 	SETBIT(_m[t].m5, 7);
       
    57 }
       
    58 
       
    59 static inline void HaltLift(TileIndex t)
       
    60 {
       
    61 	CLRBIT(_m[t].m1, 7);
       
    62 	CLRBIT(_m[t].m5, 7);
       
    63 	SB(_m[t].m5, 0, 6, 0);
       
    64 
       
    65 	DeleteAnimatedTile(t);
       
    66 }
       
    67 
       
    68 static inline byte GetLiftPosition(TileIndex t)
       
    69 {
       
    70 	return GB(_m[t].m1, 0, 7);
       
    71 }
       
    72 
       
    73 static inline void SetLiftPosition(TileIndex t, byte pos)
       
    74 {
       
    75 	SB(_m[t].m1, 0, 7, pos);
       
    76 }
       
    77 
       
    78 static inline Town* GetTownByTile(TileIndex t)
       
    79 {
       
    80 	return GetTown(GetTownIndex(t));
       
    81 }
       
    82 
       
    83 
       
    84 Town* CalcClosestTownFromTile(TileIndex tile, uint threshold);
       
    85 
       
    86 
       
    87 static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, byte type)
       
    88 {
       
    89 	assert(IsTileType(t, MP_CLEAR));
       
    90 
       
    91 	SetTileType(t, MP_HOUSE);
       
    92 	_m[t].m1 = 0;
       
    93 	_m[t].m2 = tid;
       
    94 	SB(_m[t].m3, 6, 2, stage);
       
    95 	_m[t].m4 = type;
       
    96 	SB(_m[t].m5, 0, 2, counter);
       
    97 
       
    98 	MarkTileDirtyByTile(t);
       
    99 }
       
   100 
       
   101 enum {
       
   102 	TWO_BY_TWO_BIT = 2, ///< House is two tiles in X and Y directions
       
   103 	ONE_BY_TWO_BIT = 1, ///< House is two tiles in Y direction
       
   104 	TWO_BY_ONE_BIT = 0, ///< House is two tiles in X direction
       
   105 };
       
   106 
       
   107 static inline void MakeTownHouse(TileIndex t, TownID tid, byte counter, byte stage, byte size, byte type)
       
   108 {
       
   109 	MakeHouseTile(t, tid, counter, stage, type);
       
   110 	if (HASBIT(size, TWO_BY_TWO_BIT) || HASBIT(size, ONE_BY_TWO_BIT)) MakeHouseTile(t + TileDiffXY(0, 1), tid, counter, stage, ++type);
       
   111 	if (HASBIT(size, TWO_BY_TWO_BIT) || HASBIT(size, TWO_BY_ONE_BIT)) MakeHouseTile(t + TileDiffXY(1, 0), tid, counter, stage, ++type);
       
   112 	if (HASBIT(size, TWO_BY_TWO_BIT)) MakeHouseTile(t + TileDiffXY(1, 1), tid, counter, stage, ++type);
       
   113 }
       
   114 
       
   115 /**
       
   116  * House Construction Scheme.
       
   117  *  Construction counter, for buildings under construction. Incremented on every
       
   118  *  periodic tile processing.
       
   119  *  On wraparound, the stage of building in is increased.
       
   120  *  (Get|Set|Inc)HouseBuildingStage are taking care of the real stages,
       
   121  *  (as the sprite for the next phase of house building)
       
   122  *  (Get|Set|Inc)HouseConstructionTick is simply a tick counter between the
       
   123  *  different stages
       
   124  */
       
   125 
       
   126 /**
       
   127  * Gets the building stage of a house
       
   128  * @param tile the tile of the house to get the building stage of
       
   129  * @pre IsTileType(t, MP_HOUSE)
       
   130  * @return the building stage of the house
       
   131  */
       
   132 static inline byte GetHouseBuildingStage(TileIndex t)
       
   133 {
       
   134 	assert(IsTileType(t, MP_HOUSE));
       
   135 	return GB(_m[t].m3, 6, 2);
       
   136 }
       
   137 
       
   138 /**
       
   139  * Sets the building stage of a house
       
   140  * @param tile the tile of the house to set the building stage of
       
   141  * @param stage the new stage
       
   142  * @pre IsTileType(t, MP_HOUSE)
       
   143  */
       
   144 static inline void SetHouseBuildingStage(TileIndex t, byte stage)
       
   145 {
       
   146 	assert(IsTileType(t, MP_HOUSE));
       
   147 	SB(_m[t].m3, 6, 2, stage);
       
   148 }
       
   149 
       
   150 /**
       
   151  * Increments the building stage of a house
       
   152  * @param tile the tile of the house to increment the building stage of
       
   153  * @pre IsTileType(t, MP_HOUSE)
       
   154  */
       
   155 static inline void IncHouseBuildingStage( TileIndex t )
       
   156 {
       
   157 	assert(IsTileType(t, MP_HOUSE));
       
   158 	AB(_m[t].m3, 6, 2, 1);
       
   159 }
       
   160 
       
   161 /**
       
   162  * Gets the construction stage of a house
       
   163  * @param tile the tile of the house to get the construction stage of
       
   164  * @pre IsTileType(t, MP_HOUSE)
       
   165  * @return the construction stage of the house
       
   166  */
       
   167 static inline byte GetHouseConstructionTick(TileIndex t)
       
   168 {
       
   169 	assert(IsTileType(t, MP_HOUSE));
       
   170 	return GB(_m[t].m5, 0, 3);
       
   171 }
       
   172 
       
   173 /**
       
   174  * Sets the construction stage of a house
       
   175  * @param tile the tile of the house to set the construction stage of
       
   176  * @param stage the new stage
       
   177  * @pre IsTileType(t, MP_HOUSE)
       
   178  */
       
   179 static inline void SetHouseConstructionTick(TileIndex t, byte stage)
       
   180 {
       
   181 	assert(IsTileType(t, MP_HOUSE));
       
   182 	SB(_m[t].m5, 0, 3, stage);
       
   183 }
       
   184 
       
   185 /**
       
   186  * Sets the increment stage of a house
       
   187  * @param tile the tile of the house to increment the construction stage of
       
   188  * @pre IsTileType(t, MP_HOUSE)
       
   189  */
       
   190 static inline void IncHouseConstructionTick(TileIndex t)
       
   191 {
       
   192 	assert(IsTileType(t, MP_HOUSE));
       
   193 	AB(_m[t].m5, 0, 3, 1);
       
   194 }
       
   195 
       
   196 
       
   197 #endif /* TOWN_MAP_H */