src/town_map.h
author rubidium
Wed, 19 Dec 2007 23:26:02 +0000
changeset 8604 8afdd9877afd
parent 8427 143b0be22af1
child 8627 448ebf3a8291
permissions -rw-r--r--
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
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"
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
     9
#include "date.h"
8604
8afdd9877afd (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 8427
diff changeset
    10
#include "tile_map.h"
3319
7d04847e4689 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
diff changeset
    11
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    12
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    13
 * Get the index of which town this house/street is attached to.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    14
 * @param t the tile
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7814
diff changeset
    15
 * @pre IsTileType(t, MP_HOUSE) or IsTileType(t, MP_ROAD)
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    16
 * @return TownID
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    17
 */
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
    18
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
    19
{
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7814
diff changeset
    20
	assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_ROAD)); // 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
    21
	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
    22
}
7d04847e4689 (svn r4085) Add GetTown{Index,ByTile}() to get the town index resp. the town from a tile
tron
parents:
diff changeset
    23
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
    24
/**
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
    25
 * Set the town index for a road or house tile.
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    26
 * @param t the tile
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7814
diff changeset
    27
 * @pre IsTileType(t, MP_HOUSE) or IsTileType(t, MP_ROAD)
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
    28
 * @param index the index of the town
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7814
diff changeset
    29
 * @pre IsTileType(t, MP_ROAD) || 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
    30
 */
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
    31
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
    32
{
7866
e19fda04e8d3 (svn r10733) -Codechange: change MP_STREET into MP_ROAD as we use the word "road" everywhere except in the tile type.
rubidium
parents: 7814
diff changeset
    33
	assert(IsTileType(t, MP_HOUSE) || IsTileType(t, MP_ROAD));
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
    34
	_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
    35
}
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
    36
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
    37
/**
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
 * 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
    39
 * @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
    40
 * @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
    41
 */
7814
fe643468ad64 (svn r10673) -Cleanup: some assorted style cleanups. Primarily type* var -> type *var.
rubidium
parents: 6918
diff changeset
    42
static inline Town *GetTownByTile(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
    43
{
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
	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
    45
}
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
    46
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    47
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    48
 * Get the type of this house, which is an index into the house spec array
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    49
 * Since m4 is only a byte and we want to support 512 houses, we use the bit 6
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    50
 * of m3 as an additional bit to house type.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    51
 * @param t the tile
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    52
 * @pre IsTileType(t, MP_HOUSE)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    53
 * @return house type
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    54
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    55
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
    56
{
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
    57
	assert(IsTileType(t, MP_HOUSE));
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    58
	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
    59
}
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
    60
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    61
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    62
 * Set the house type.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    63
 * @param t the tile
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    64
 * @param house_id the new house type
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    65
 * @pre IsTileType(t, MP_HOUSE)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    66
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    67
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
    68
{
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    69
	assert(IsTileType(t, MP_HOUSE));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    70
	_m[t].m4 = GB(house_id, 0, 8);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    71
	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
    72
}
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
    73
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    74
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    75
 * Check if the lift of this animated house has a destination
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    76
 * @param t the tile
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    77
 * @return has destination
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    78
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    79
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
    80
{
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
    81
	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
    82
}
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
    83
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    84
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    85
 * Set the new destination of the lift for this animated house, and activate
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    86
 * the LiftHasDestination bit.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    87
 * @param t the tile
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    88
 * @param dest new destination
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    89
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    90
static inline void SetLiftDestination(TileIndex t, byte dest)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    91
{
8427
143b0be22af1 (svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents: 8424
diff changeset
    92
	SetBit(_me[t].m7, 0);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    93
	SB(_me[t].m7, 1, 3, dest);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    94
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    95
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    96
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    97
 * Get the current destination for this lift
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    98
 * @param t the tile
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
    99
 * @return destination
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   100
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   101
static inline byte GetLiftDestination(TileIndex t)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   102
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   103
	return GB(_me[t].m7, 1, 3);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   104
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   105
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   106
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   107
 * Stop the lift of this animated house from moving.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   108
 * Clears the first 4 bits of m7 at once, clearing the LiftHasDestination bit
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   109
 * and the destination.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   110
 * @param t the tile
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   111
 */
3426
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   112
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
   113
{
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   114
	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
   115
	DeleteAnimatedTile(t);
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   116
}
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   117
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   118
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   119
 * Get the position of the lift on this animated house
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   120
 * @param t the tile
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   121
 * @return position, from 0 to 36
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   122
 */
3426
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   123
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
   124
{
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   125
	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
   126
}
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   127
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   128
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   129
 * Set the position of the lift on this animated house
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   130
 * @param t the tile
6918
5589c415e28f (svn r9558) -Documentation: doxygen and comment changes: 'T' now. Almost done
belugas
parents: 6914
diff changeset
   131
 * @param pos position, from 0 to 36
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   132
 */
3426
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   133
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
   134
{
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   135
	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
   136
}
dab412dcee39 (svn r4254) -Codechange: Add and make use of map accessors for town lifts.
celestar
parents: 3382
diff changeset
   137
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   138
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   139
 * Get the current animation frame for this house
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   140
 * @param t the tile
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   141
 * @pre IsTileType(t, MP_HOUSE)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   142
 * @return frame number
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   143
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   144
static inline byte GetHouseAnimationFrame(TileIndex t)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   145
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   146
	assert(IsTileType(t, MP_HOUSE));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   147
	return GB(_m[t].m6, 3, 5);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   148
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   149
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   150
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   151
 * Set a new animation frame for this house
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   152
 * @param t the tile
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   153
 * @param frame the new frame number
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   154
 * @pre IsTileType(t, MP_HOUSE)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   155
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   156
static inline void SetHouseAnimationFrame(TileIndex t, byte frame)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   157
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   158
	assert(IsTileType(t, MP_HOUSE));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   159
	SB(_m[t].m6, 3, 5, frame);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   160
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   161
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   162
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   163
 * Get the completion of this house
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   164
 * @param t the tile
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   165
 * @return true if it is, false if it is not
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   166
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   167
static inline bool IsHouseCompleted(TileIndex t)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   168
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   169
	assert(IsTileType(t, MP_HOUSE));
8424
4a488a90ccab (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 8418
diff changeset
   170
	return HasBit(_m[t].m3, 7);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   171
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   172
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   173
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   174
 * Mark this house as been completed
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   175
 * @param t the tile
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   176
 * @param status
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   177
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   178
static inline void SetHouseCompleted(TileIndex t, bool status)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   179
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   180
	assert(IsTileType(t, MP_HOUSE));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   181
	SB(_m[t].m3, 7, 1, !!status);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   182
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   183
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   184
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   185
 * Make the tile a house.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   186
 * @param t tile index
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   187
 * @param tid Town index
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   188
 * @param counter of construction step
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   189
 * @param stage of construction (used for drawing)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   190
 * @param type of house.  Index into house specs array
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   191
 * @param random_bits required for newgrf houses
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   192
 * @pre IsTileType(t, MP_CLEAR)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   193
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   194
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
   195
{
c9c8d85aa632 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3377
diff changeset
   196
	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
   197
c9c8d85aa632 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3377
diff changeset
   198
	SetTileType(t, MP_HOUSE);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   199
	_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
   200
	_m[t].m2 = tid;
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   201
	_m[t].m3 = 0;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   202
	SetHouseType(t, type);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   203
	SetHouseCompleted(t, stage == TOWN_HOUSE_COMPLETED);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   204
	_m[t].m5 = IsHouseCompleted(t) ? 0 : (stage << 3 | counter);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   205
	SetHouseAnimationFrame(t, 0);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   206
	_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
   207
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   208
	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
   209
	MarkTileDirtyByTile(t);
c9c8d85aa632 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3377
diff changeset
   210
}
c9c8d85aa632 (svn r4190) -Codechange: Add and make use of an accessor function to create houses
celestar
parents: 3377
diff changeset
   211
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   212
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   213
 * Helper function for MakeHouseTile.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   214
 * It is called  for each tile of a multi-tile house.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   215
 * Parametes are the same.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   216
 * @param t tile index
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   217
 * @param tid Town index
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   218
 * @param counter of construction step
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   219
 * @param stage of construction (used for drawing)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   220
 * @param type of house.  Index into house specs array
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   221
 * @param random_bits required for newgrf houses
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   222
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   223
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
   224
{
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   225
	BuildingFlags size = GetHouseSpecs(type)->building_flags;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   226
	MakeHouseTile(t, tid, counter, stage, type, random_bits);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   227
	if (size & BUILDING_2_TILES_Y)   MakeHouseTile(t + TileDiffXY(0, 1), tid, counter, stage, ++type, random_bits);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   228
	if (size & BUILDING_2_TILES_X)   MakeHouseTile(t + TileDiffXY(1, 0), tid, counter, stage, ++type, random_bits);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   229
	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
   230
}
3432
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
/**
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   233
 * 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
   234
 *  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
   235
 *  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
   236
 *  On wraparound, the stage of building in is increased.
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   237
 *  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
   238
 *  (as the sprite for the next phase of house building)
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   239
 *  (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
   240
 *  different stages
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
/**
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   244
 * Gets the building stage of a house
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   245
 * Since the stage is used for determining what sprite to use,
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   246
 * if the house is complete (and that stage no longuer is available),
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   247
 * fool the system by returning the TOWN_HOUSE_COMPLETE (3),
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   248
 * thus showing a beautiful complete house.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   249
 * @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
   250
 * @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
   251
 * @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
   252
 */
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   253
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
   254
{
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   255
	assert(IsTileType(t, MP_HOUSE));
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   256
	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
   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
/**
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   260
 * Gets the construction stage of a house
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   261
 * @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
   262
 * @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
   263
 * @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
   264
 */
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   265
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
   266
{
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   267
	assert(IsTileType(t, MP_HOUSE));
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   268
	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
   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
/**
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   272
 * Sets the increment stage of a house
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   273
 * It is working with the whole counter + stage 5 bits, making it
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   274
 * easier to work:  the wraparound is automatic.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   275
 * @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
   276
 * @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
   277
 */
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   278
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
   279
{
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   280
	assert(IsTileType(t, MP_HOUSE));
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   281
	AB(_m[t].m5, 0, 5, 1);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   282
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   283
	if (GB(_m[t].m5, 3, 2) == TOWN_HOUSE_COMPLETED) {
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   284
		/* House is now completed.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   285
		 * Store the year of construction as well, for newgrf house purpose */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   286
		SetHouseCompleted(t, true);
8418
b49fc6be1ab9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 8357
diff changeset
   287
		_m[t].m5 = Clamp(_cur_year - ORIGINAL_BASE_YEAR, 0, 0xFF);
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   288
	}
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   289
}
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   290
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   291
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   292
 * Get the year that this house was constructed (between 1920 and 2175).
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   293
 * @param t the tile of this house
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   294
 * @pre IsTileType(t, MP_HOUSE)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   295
 * @return year
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   296
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   297
static inline Year GetHouseConstructionYear(TileIndex t)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   298
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   299
	assert(IsTileType(t, MP_HOUSE));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   300
	return IsHouseCompleted(t) ? _m[t].m5 + ORIGINAL_BASE_YEAR : 0;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   301
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   302
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   303
/**
8357
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7866
diff changeset
   304
 * Set the random bits for this house.
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7866
diff changeset
   305
 * This is required for newgrf house
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7866
diff changeset
   306
 * @param t      the tile of this house
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7866
diff changeset
   307
 * @param random the new random bits
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7866
diff changeset
   308
 * @pre IsTileType(t, MP_HOUSE)
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7866
diff changeset
   309
 */
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7866
diff changeset
   310
static inline void SetHouseRandomBits(TileIndex t, byte random)
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7866
diff changeset
   311
{
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7866
diff changeset
   312
	assert(IsTileType(t, MP_HOUSE));
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7866
diff changeset
   313
	_m[t].m1 = random;
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7866
diff changeset
   314
}
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7866
diff changeset
   315
279c5953ec04 (svn r11411) -Codechange: implement random triggers for houses.
rubidium
parents: 7866
diff changeset
   316
/**
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   317
 * Get the random bits for this house.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   318
 * This is required for newgrf house
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   319
 * @param t the tile of this house
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   320
 * @pre IsTileType(t, MP_HOUSE)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   321
 * @return random bits
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   322
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   323
static inline byte GetHouseRandomBits(TileIndex t)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   324
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   325
	assert(IsTileType(t, MP_HOUSE));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   326
	return _m[t].m1;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   327
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   328
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   329
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   330
 * Set the activated triggers bits for this house.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   331
 * This is required for newgrf house
6914
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6658
diff changeset
   332
 * @param t        the tile of this house
3ba37b6fa39b (svn r9554) -Documentation: add documentation to some map accessors.
rubidium
parents: 6658
diff changeset
   333
 * @param triggers the activated triggers
6658
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   334
 * @pre IsTileType(t, MP_HOUSE)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   335
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   336
static inline void SetHouseTriggers(TileIndex t, byte triggers)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   337
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   338
	assert(IsTileType(t, MP_HOUSE));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   339
	SB(_m[t].m3, 0, 5, triggers);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   340
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   341
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   342
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   343
 * Get the already activated triggers bits for this house.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   344
 * This is required for newgrf house
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   345
 * @param t the tile of this house
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   346
 * @pre IsTileType(t, MP_HOUSE)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   347
 * @return triggers
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   348
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   349
static inline byte GetHouseTriggers(TileIndex t)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   350
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   351
	assert(IsTileType(t, MP_HOUSE));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   352
	return GB(_m[t].m3, 0, 5);
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   353
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   354
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   355
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   356
 * Get the amount of time remaining before the tile loop processes this tile.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   357
 * @param t the house tile
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   358
 * @pre IsTileType(t, MP_HOUSE)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   359
 * @return time remaining
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   360
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   361
static inline byte GetHouseProcessingTime(TileIndex t)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   362
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   363
	assert(IsTileType(t, MP_HOUSE));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   364
	return _me[t].m7;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   365
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   366
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   367
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   368
 * Set the amount of time remaining before the tile loop processes this tile.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   369
 * @param t the house tile
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   370
 * @param time the time to be set
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   371
 * @pre IsTileType(t, MP_HOUSE)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   372
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   373
static inline void SetHouseProcessingTime(TileIndex t, byte time)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   374
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   375
	assert(IsTileType(t, MP_HOUSE));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   376
	_me[t].m7 = time;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   377
}
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   378
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   379
/**
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   380
 * Decrease the amount of time remaining before the tile loop processes this tile.
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   381
 * @param t the house tile
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   382
 * @pre IsTileType(t, MP_HOUSE)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   383
 */
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   384
static inline void DecHouseProcessingTime(TileIndex t)
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   385
{
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   386
	assert(IsTileType(t, MP_HOUSE));
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   387
	_me[t].m7--;
59048224be55 (svn r9315) -Merge: The newhouses branch. With this merge comes almost complete support for
maedhros
parents: 6220
diff changeset
   388
}
3432
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   389
507fa7fd189d (svn r4261) CodeChange : Add and Use Accessor for Houses Construction. And cleaning on town.flags12 too
belugas
parents: 3426
diff changeset
   390
#endif /* TOWN_MAP_H */