src/town_map.h
author KUDr
Sat, 21 Apr 2007 08:23:57 +0000
branchcpp_gui
changeset 6308 646711c5feaa
parent 6307 f40e88cff863
child 6743 cabfaa4a0295
permissions -rw-r--r--
(svn r9708) [cpp_gui] -Sync with trunk (r9633:9707)
3319
7d04847e4689 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
diff changeset
     1
/* $Id$ */
7d04847e4689 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
diff changeset
     2
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
     3
/** @file town_map.h Accessors for towns */
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
     4
3426
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
     5
#ifndef TOWN_MAP_H
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
     6
#define TOWN_MAP_H
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
     7
3319
7d04847e4689 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
diff changeset
     8
#include "town.h"
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
     9
#include "date.h"
3319
7d04847e4689 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
diff changeset
    10
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    11
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    12
 * Get the index of which town this house/street is attached to.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    13
 * @param t the tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    14
 * @pre IsTileType(t, MP_HOUSE) or IsTileType(t, MP_STREET)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    15
 * @return TownID
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    16
 */
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
    17
static inline TownID GetTownIndex(TileIndex t)
3319
7d04847e4689 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
diff changeset
    18
{
3369
00c2ca209a89 (svn r4166) Sprinkle several map accessors with assert()s
tron
parents: 3319
diff changeset
    19
	assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_STREET)); // XXX incomplete
3319
7d04847e4689 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
diff changeset
    20
	return _m[t].m2;
7d04847e4689 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
diff changeset
    21
}
7d04847e4689 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
diff changeset
    22
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
    23
/**
3983
d2d6496238e4 (svn r5171) Get rid of an ungly hack in the load routine, which temporarily turned house and road tiles into void tiles to calculate the closest town
tron
parents: 3432
diff changeset
    24
 * Set the town index for a road or house tile.
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    25
 * @param t the tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    26
 * @pre IsTileType(t, MP_HOUSE) or IsTileType(t, MP_STREET)
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
    27
 * @param index the index of the town
6220
0c2371b1edda (svn r8651) -Codechange: group the functions related to getting and setting the town index and move one function that is not related to the map array out of town_map.h.
rubidium
parents: 5726
diff changeset
    28
 * @pre IsTileType(t, MP_STREET) || IsTileType(t, MP_HOUSE)
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
    29
 */
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
    30
static inline void SetTownIndex(TileIndex t, TownID index)
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
    31
{
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    32
	assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_STREET));
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
    33
	_m[t].m2 = index;
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
    34
}
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
    35
6220
0c2371b1edda (svn r8651) -Codechange: group the functions related to getting and setting the town index and move one function that is not related to the map array out of town_map.h.
rubidium
parents: 5726
diff changeset
    36
/**
0c2371b1edda (svn r8651) -Codechange: group the functions related to getting and setting the town index and move one function that is not related to the map array out of town_map.h.
rubidium
parents: 5726
diff changeset
    37
 * Gets the town associated with the house or road tile
0c2371b1edda (svn r8651) -Codechange: group the functions related to getting and setting the town index and move one function that is not related to the map array out of town_map.h.
rubidium
parents: 5726
diff changeset
    38
 * @param t the tile to get the town of
0c2371b1edda (svn r8651) -Codechange: group the functions related to getting and setting the town index and move one function that is not related to the map array out of town_map.h.
rubidium
parents: 5726
diff changeset
    39
 * @return the town
0c2371b1edda (svn r8651) -Codechange: group the functions related to getting and setting the town index and move one function that is not related to the map array out of town_map.h.
rubidium
parents: 5726
diff changeset
    40
 */
0c2371b1edda (svn r8651) -Codechange: group the functions related to getting and setting the town index and move one function that is not related to the map array out of town_map.h.
rubidium
parents: 5726
diff changeset
    41
static inline Town* GetTownByTile(TileIndex t)
0c2371b1edda (svn r8651) -Codechange: group the functions related to getting and setting the town index and move one function that is not related to the map array out of town_map.h.
rubidium
parents: 5726
diff changeset
    42
{
0c2371b1edda (svn r8651) -Codechange: group the functions related to getting and setting the town index and move one function that is not related to the map array out of town_map.h.
rubidium
parents: 5726
diff changeset
    43
	return GetTown(GetTownIndex(t));
0c2371b1edda (svn r8651) -Codechange: group the functions related to getting and setting the town index and move one function that is not related to the map array out of town_map.h.
rubidium
parents: 5726
diff changeset
    44
}
0c2371b1edda (svn r8651) -Codechange: group the functions related to getting and setting the town index and move one function that is not related to the map array out of town_map.h.
rubidium
parents: 5726
diff changeset
    45
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    46
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    47
 * Get the type of this house, which is an index into the house spec array
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    48
 * Since m4 is only a byte and we want to support 512 houses, we use the bit 6
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    49
 * of m3 as an additional bit to house type.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    50
 * @param t the tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    51
 * @pre IsTileType(t, MP_HOUSE)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    52
 * @return house type
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    53
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    54
static inline HouseID GetHouseType(TileIndex t)
6220
0c2371b1edda (svn r8651) -Codechange: group the functions related to getting and setting the town index and move one function that is not related to the map array out of town_map.h.
rubidium
parents: 5726
diff changeset
    55
{
0c2371b1edda (svn r8651) -Codechange: group the functions related to getting and setting the town index and move one function that is not related to the map array out of town_map.h.
rubidium
parents: 5726
diff changeset
    56
	assert(IsTileType(t, MP_HOUSE));
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    57
	return _m[t].m4 | (GB(_m[t].m3, 6, 1) << 8);
3426
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
    58
}
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
    59
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    60
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    61
 * Set the house type.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    62
 * @param t the tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    63
 * @param house_id the new house type
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    64
 * @pre IsTileType(t, MP_HOUSE)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    65
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    66
static inline void SetHouseType(TileIndex t, HouseID house_id)
3426
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
    67
{
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    68
	assert(IsTileType(t, MP_HOUSE));
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    69
	_m[t].m4 = GB(house_id, 0, 8);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    70
	SB(_m[t].m3, 6, 1, GB(house_id, 8, 1));
3426
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
    71
}
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
    72
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    73
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    74
 * Check if the lift of this animated house has a destination
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    75
 * @param t the tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    76
 * @return has destination
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    77
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    78
static inline bool LiftHasDestination(TileIndex t)
3426
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
    79
{
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    80
	return HASBIT(_me[t].m7, 0);
3426
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
    81
}
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
    82
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    83
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    84
 * Set the new destination of the lift for this animated house, and activate
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    85
 * the LiftHasDestination bit.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    86
 * @param t the tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    87
 * @param dest new destination
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    88
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    89
static inline void SetLiftDestination(TileIndex t, byte dest)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    90
{
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    91
	SETBIT(_me[t].m7, 0);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    92
	SB(_me[t].m7, 1, 3, dest);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    93
}
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    94
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    95
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    96
 * Get the current destination for this lift
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    97
 * @param t the tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    98
 * @return destination
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
    99
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   100
static inline byte GetLiftDestination(TileIndex t)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   101
{
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   102
	return GB(_me[t].m7, 1, 3);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   103
}
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   104
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   105
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   106
 * Stop the lift of this animated house from moving.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   107
 * Clears the first 4 bits of m7 at once, clearing the LiftHasDestination bit
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   108
 * and the destination.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   109
 * @param t the tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   110
 */
3426
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   111
static inline void HaltLift(TileIndex t)
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   112
{
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   113
	SB(_me[t].m7, 0, 4, 0);
3426
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   114
	DeleteAnimatedTile(t);
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   115
}
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   116
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   117
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   118
 * Get the position of the lift on this animated house
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   119
 * @param t the tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   120
 * @return position, from 0 to 36
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   121
 */
3426
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   122
static inline byte GetLiftPosition(TileIndex t)
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   123
{
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   124
	return GB(_m[t].m6, 2, 6);
3426
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   125
}
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   126
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   127
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   128
 * Set the position of the lift on this animated house
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   129
 * @param t the tile
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   130
 * @param pos position, from 0 to 36
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   131
 */
3426
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   132
static inline void SetLiftPosition(TileIndex t, byte pos)
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   133
{
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   134
	SB(_m[t].m6, 2, 6, pos);
3426
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   135
}
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   136
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   137
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   138
 * Get the current animation frame for this house
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   139
 * @param t the tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   140
 * @pre IsTileType(t, MP_HOUSE)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   141
 * @return frame number
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   142
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   143
static inline byte GetHouseAnimationFrame(TileIndex t)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   144
{
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   145
	assert(IsTileType(t, MP_HOUSE));
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   146
	return GB(_m[t].m6, 3, 5);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   147
}
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   148
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   149
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   150
 * Set a new animation frame for this house
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   151
 * @param t the tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   152
 * @param frame the new frame number
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   153
 * @pre IsTileType(t, MP_HOUSE)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   154
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   155
static inline void SetHouseAnimationFrame(TileIndex t, byte frame)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   156
{
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   157
	assert(IsTileType(t, MP_HOUSE));
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   158
	SB(_m[t].m6, 3, 5, frame);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   159
}
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   160
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   161
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   162
 * Get the completion of this house
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   163
 * @param t the tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   164
 * @return true if it is, false if it is not
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   165
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   166
static inline bool IsHouseCompleted(TileIndex t)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   167
{
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   168
	assert(IsTileType(t, MP_HOUSE));
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   169
	return HASBIT(_m[t].m3, 7);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   170
}
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   171
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   172
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   173
 * Mark this house as been completed
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   174
 * @param t the tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   175
 * @param status
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   176
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   177
static inline void SetHouseCompleted(TileIndex t, bool status)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   178
{
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   179
	assert(IsTileType(t, MP_HOUSE));
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   180
	SB(_m[t].m3, 7, 1, !!status);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   181
}
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   182
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   183
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   184
 * Make the tile a house.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   185
 * @param t tile index
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   186
 * @param tid Town index
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   187
 * @param counter of construction step
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   188
 * @param stage of construction (used for drawing)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   189
 * @param type of house.  Index into house specs array
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   190
 * @param random_bits required for newgrf houses
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   191
 * @pre IsTileType(t, MP_CLEAR)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   192
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   193
static inline void MakeHouseTile(TileIndex t, TownID tid, byte counter, byte stage, HouseID type, byte random_bits)
3382
c9c8d85aa632 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3377
diff changeset
   194
{
c9c8d85aa632 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3377
diff changeset
   195
	assert(IsTileType(t, MP_CLEAR));
c9c8d85aa632 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3377
diff changeset
   196
c9c8d85aa632 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3377
diff changeset
   197
	SetTileType(t, MP_HOUSE);
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   198
	_m[t].m1 = random_bits;
3382
c9c8d85aa632 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3377
diff changeset
   199
	_m[t].m2 = tid;
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   200
	_m[t].m3 = 0;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   201
	SetHouseType(t, type);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   202
	SetHouseCompleted(t, stage == TOWN_HOUSE_COMPLETED);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   203
	_m[t].m5 = IsHouseCompleted(t) ? 0 : (stage << 3 | counter);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   204
	SetHouseAnimationFrame(t, 0);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   205
	_me[t].m7 = GetHouseSpecs(type)->processing_time;
3382
c9c8d85aa632 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3377
diff changeset
   206
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   207
	if (GetHouseSpecs(type)->building_flags & BUILDING_IS_ANIMATED) AddAnimatedTile(t);
3382
c9c8d85aa632 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3377
diff changeset
   208
	MarkTileDirtyByTile(t);
c9c8d85aa632 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3377
diff changeset
   209
}
c9c8d85aa632 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3377
diff changeset
   210
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   211
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   212
 * Helper function for MakeHouseTile.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   213
 * It is called  for each tile of a multi-tile house.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   214
 * Parametes are the same.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   215
 * @param t tile index
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   216
 * @param tid Town index
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   217
 * @param counter of construction step
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   218
 * @param stage of construction (used for drawing)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   219
 * @param type of house.  Index into house specs array
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   220
 * @param random_bits required for newgrf houses
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   221
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   222
static inline void MakeTownHouse(TileIndex t, TownID tid, byte counter, byte stage, HouseID type, byte random_bits)
3382
c9c8d85aa632 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3377
diff changeset
   223
{
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   224
	BuildingFlags size = GetHouseSpecs(type)->building_flags;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   225
	MakeHouseTile(t, tid, counter, stage, type, random_bits);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   226
	if (size & BUILDING_2_TILES_Y)   MakeHouseTile(t + TileDiffXY(0, 1), tid, counter, stage, ++type, random_bits);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   227
	if (size & BUILDING_2_TILES_X)   MakeHouseTile(t + TileDiffXY(1, 0), tid, counter, stage, ++type, random_bits);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   228
	if (size & BUILDING_HAS_4_TILES) MakeHouseTile(t + TileDiffXY(1, 1), tid, counter, stage, ++type, random_bits);
3382
c9c8d85aa632 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3377
diff changeset
   229
}
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   230
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   231
/**
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   232
 * House Construction Scheme.
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   233
 *  Construction counter, for buildings under construction. Incremented on every
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   234
 *  periodic tile processing.
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   235
 *  On wraparound, the stage of building in is increased.
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   236
 *  GetHouseBuildingStage is taking care of the real stages,
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   237
 *  (as the sprite for the next phase of house building)
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   238
 *  (Get|Inc)HouseConstructionTick is simply a tick counter between the
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   239
 *  different stages
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   240
 */
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   241
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   242
/**
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   243
 * Gets the building stage of a house
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   244
 * Since the stage is used for determining what sprite to use,
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   245
 * if the house is complete (and that stage no longuer is available),
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   246
 * fool the system by returning the TOWN_HOUSE_COMPLETE (3),
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   247
 * thus showing a beautiful complete house.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   248
 * @param t the tile of the house to get the building stage of
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   249
 * @pre IsTileType(t, MP_HOUSE)
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   250
 * @return the building stage of the house
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   251
 */
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   252
static inline byte GetHouseBuildingStage(TileIndex t)
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   253
{
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   254
	assert(IsTileType(t, MP_HOUSE));
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   255
	return IsHouseCompleted(t) ? (byte)TOWN_HOUSE_COMPLETED : GB(_m[t].m5, 3, 2);
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   256
}
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   257
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   258
/**
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   259
 * Gets the construction stage of a house
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   260
 * @param t the tile of the house to get the construction stage of
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   261
 * @pre IsTileType(t, MP_HOUSE)
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   262
 * @return the construction stage of the house
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   263
 */
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   264
static inline byte GetHouseConstructionTick(TileIndex t)
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   265
{
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   266
	assert(IsTileType(t, MP_HOUSE));
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   267
	return IsHouseCompleted(t) ? 0 : GB(_m[t].m5, 0, 3);
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   268
}
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   269
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   270
/**
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   271
 * Sets the increment stage of a house
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   272
 * It is working with the whole counter + stage 5 bits, making it
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   273
 * easier to work:  the wraparound is automatic.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   274
 * @param t the tile of the house to increment the construction stage of
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   275
 * @pre IsTileType(t, MP_HOUSE)
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   276
 */
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   277
static inline void IncHouseConstructionTick(TileIndex t)
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   278
{
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   279
	assert(IsTileType(t, MP_HOUSE));
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   280
	AB(_m[t].m5, 0, 5, 1);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   281
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   282
	if (GB(_m[t].m5, 3, 2) == TOWN_HOUSE_COMPLETED) {
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   283
		/* House is now completed.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   284
		 * Store the year of construction as well, for newgrf house purpose */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   285
		SetHouseCompleted(t, true);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   286
		_m[t].m5 = clamp(_cur_year - ORIGINAL_BASE_YEAR, 0, 0xFF);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   287
	}
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   288
}
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   289
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   290
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   291
 * Get the year that this house was constructed (between 1920 and 2175).
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   292
 * @param t the tile of this house
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   293
 * @pre IsTileType(t, MP_HOUSE)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   294
 * @return year
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   295
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   296
static inline Year GetHouseConstructionYear(TileIndex t)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   297
{
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   298
	assert(IsTileType(t, MP_HOUSE));
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   299
	return IsHouseCompleted(t) ? _m[t].m5 + ORIGINAL_BASE_YEAR : 0;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   300
}
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   301
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   302
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   303
 * Get the random bits for this house.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   304
 * This is required for newgrf house
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   305
 * @param t the tile of this house
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   306
 * @pre IsTileType(t, MP_HOUSE)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   307
 * @return random bits
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   308
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   309
static inline byte GetHouseRandomBits(TileIndex t)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   310
{
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   311
	assert(IsTileType(t, MP_HOUSE));
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   312
	return _m[t].m1;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   313
}
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   314
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   315
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   316
 * Set the activated triggers bits for this house.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   317
 * This is required for newgrf house
6307
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   318
 * @param t        the tile of this house
f40e88cff863 (svn r9639) [cpp_gui] -Sync with trunk (r9476:9633)
KUDr
parents: 6303
diff changeset
   319
 * @param triggers the activated triggers
6303
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   320
 * @pre IsTileType(t, MP_HOUSE)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   321
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   322
static inline void SetHouseTriggers(TileIndex t, byte triggers)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   323
{
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   324
	assert(IsTileType(t, MP_HOUSE));
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   325
	SB(_m[t].m3, 0, 5, triggers);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   326
}
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   327
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   328
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   329
 * Get the already activated triggers bits for this house.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   330
 * This is required for newgrf house
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   331
 * @param t the tile of this house
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   332
 * @pre IsTileType(t, MP_HOUSE)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   333
 * @return triggers
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   334
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   335
static inline byte GetHouseTriggers(TileIndex t)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   336
{
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   337
	assert(IsTileType(t, MP_HOUSE));
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   338
	return GB(_m[t].m3, 0, 5);
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   339
}
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   340
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   341
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   342
 * Get the amount of time remaining before the tile loop processes this tile.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   343
 * @param t the house tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   344
 * @pre IsTileType(t, MP_HOUSE)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   345
 * @return time remaining
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   346
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   347
static inline byte GetHouseProcessingTime(TileIndex t)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   348
{
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   349
	assert(IsTileType(t, MP_HOUSE));
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   350
	return _me[t].m7;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   351
}
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   352
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   353
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   354
 * Set the amount of time remaining before the tile loop processes this tile.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   355
 * @param t the house tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   356
 * @param time the time to be set
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   357
 * @pre IsTileType(t, MP_HOUSE)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   358
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   359
static inline void SetHouseProcessingTime(TileIndex t, byte time)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   360
{
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   361
	assert(IsTileType(t, MP_HOUSE));
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   362
	_me[t].m7 = time;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   363
}
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   364
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   365
/**
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   366
 * Decrease the amount of time remaining before the tile loop processes this tile.
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   367
 * @param t the house tile
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   368
 * @pre IsTileType(t, MP_HOUSE)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   369
 */
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   370
static inline void DecHouseProcessingTime(TileIndex t)
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   371
{
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   372
	assert(IsTileType(t, MP_HOUSE));
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   373
	_me[t].m7--;
84c215fc8eb8 (svn r9486) [cpp_gui] -Sync with trunk (r9100:9476)
KUDr
parents: 6220
diff changeset
   374
}
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   375
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   376
#endif /* TOWN_MAP_H */