author | Tero Marttila <terom@fixme.fi> |
Fri, 18 Jul 2008 21:59:53 +0300 | |
changeset 11176 | 874f8008e6e5 |
parent 9147 | 54271cd8f27f |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
8604
8afdd9877afd
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
7866
diff
changeset
|
3 |
/** @file tile_map.h Map writing/reading functions for tiles. */ |
7809
40156c450f13
(svn r10665) -Codechange: replace magic 15 with MAX_TILE_HEIGHT (bilbo)
truelight
parents:
6918
diff
changeset
|
4 |
|
8604
8afdd9877afd
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
7866
diff
changeset
|
5 |
#ifndef TILE_MAP_H |
8afdd9877afd
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
7866
diff
changeset
|
6 |
#define TILE_MAP_H |
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1211
diff
changeset
|
7 |
|
8604
8afdd9877afd
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
7866
diff
changeset
|
8 |
#include "tile_type.h" |
8afdd9877afd
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
7866
diff
changeset
|
9 |
#include "slope_type.h" |
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8635
diff
changeset
|
10 |
#include "player_type.h" |
8635
3bbb6f87fced
(svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents:
8609
diff
changeset
|
11 |
#include "map_func.h" |
8609
8c0c3e9dd6a0
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents:
8604
diff
changeset
|
12 |
#include "core/bitmath_func.hpp" |
1335
a635854c23b6
(svn r1839) Move GetTileSlope() and GetTileZ() into tile.[ch] and use more explicit types as parameters
tron
parents:
1333
diff
changeset
|
13 |
|
7861
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
14 |
/** |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
15 |
* Returns the height of a tile |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
16 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
17 |
* This function returns the height of the northern corner of a tile. |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
18 |
* This is saved in the global map-array. It does not take affect by |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
19 |
* any slope-data of the tile. |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
20 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
21 |
* @param tile The tile to get the height from |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
22 |
* @return the height of the tile |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
23 |
* @pre tile < MapSize() |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
24 |
*/ |
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1041
diff
changeset
|
25 |
static inline uint TileHeight(TileIndex tile) |
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1041
diff
changeset
|
26 |
{ |
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1041
diff
changeset
|
27 |
assert(tile < MapSize()); |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1967
diff
changeset
|
28 |
return GB(_m[tile].type_height, 0, 4); |
1044
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1041
diff
changeset
|
29 |
} |
9b73df700a7c
(svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents:
1041
diff
changeset
|
30 |
|
7861
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
31 |
/** |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
32 |
* Sets the height of a tile. |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
33 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
34 |
* This function sets the height of the northern corner of a tile. |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
35 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
36 |
* @param tile The tile to change the height |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
37 |
* @param height The new height value of the tile |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
38 |
* @pre tile < MapSize() |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
39 |
* @pre heigth <= MAX_TILE_HEIGHT |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
40 |
*/ |
1059
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
41 |
static inline void SetTileHeight(TileIndex tile, uint height) |
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
42 |
{ |
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
43 |
assert(tile < MapSize()); |
7861
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
44 |
assert(height <= MAX_TILE_HEIGHT); |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1967
diff
changeset
|
45 |
SB(_m[tile].type_height, 0, 4, height); |
1059
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
46 |
} |
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
47 |
|
7861
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
48 |
/** |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
49 |
* Returns the height of a tile in pixels. |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
50 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
51 |
* This function returns the height of the northern corner of a tile in pixels. |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
52 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
53 |
* @param tile The tile to get the height |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
54 |
* @return The height of the tile in pixel |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
55 |
*/ |
1041
be151b7bc909
(svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents:
1035
diff
changeset
|
56 |
static inline uint TilePixelHeight(TileIndex tile) |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
979
diff
changeset
|
57 |
{ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
58 |
return TileHeight(tile) * TILE_HEIGHT; |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
979
diff
changeset
|
59 |
} |
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
979
diff
changeset
|
60 |
|
7861
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
61 |
/** |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
62 |
* Get the tiletype of a given tile. |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
63 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
64 |
* @param tile The tile to get the TileType |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
65 |
* @return The tiletype of the tile |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
66 |
* @pre tile < MapSize() |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
67 |
*/ |
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1211
diff
changeset
|
68 |
static inline TileType GetTileType(TileIndex tile) |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
979
diff
changeset
|
69 |
{ |
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
979
diff
changeset
|
70 |
assert(tile < MapSize()); |
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3794
diff
changeset
|
71 |
return (TileType)GB(_m[tile].type_height, 4, 4); |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
979
diff
changeset
|
72 |
} |
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
979
diff
changeset
|
73 |
|
7861
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
74 |
/** |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
75 |
* Set the type of a tile |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
76 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
77 |
* This functions sets the type of a tile. If the type |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
78 |
* MP_VOID is selected the tile must be at the south-west or |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
79 |
* south-east edges of the map and vice versa. |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
80 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
81 |
* @param tile The tile to save the new type |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
82 |
* @param type The type to save |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
83 |
* @pre tile < MapSize() |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
84 |
* @pre type MP_VOID <=> tile is on the south-east or south-west edge. |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
85 |
*/ |
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1211
diff
changeset
|
86 |
static inline void SetTileType(TileIndex tile, TileType type) |
1059
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
87 |
{ |
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
88 |
assert(tile < MapSize()); |
4010
e1c717629783
(svn r5221) Make the assertion in SetTileType() more strict: "lower edge of map <=> VOID" instead of just "lower edge of map => VOID"
tron
parents:
3900
diff
changeset
|
89 |
/* VOID tiles (and no others) are exactly allowed at the lower left and right |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4067
diff
changeset
|
90 |
* edges of the map */ |
4010
e1c717629783
(svn r5221) Make the assertion in SetTileType() more strict: "lower edge of map <=> VOID" instead of just "lower edge of map => VOID"
tron
parents:
3900
diff
changeset
|
91 |
assert((TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) == (type == MP_VOID)); |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1967
diff
changeset
|
92 |
SB(_m[tile].type_height, 4, 4, type); |
1059
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
93 |
} |
c28c6be74291
(svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents:
1044
diff
changeset
|
94 |
|
7861
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
95 |
/** |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
96 |
* Checks if a tile is a give tiletype. |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
97 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
98 |
* This function checks if a tile got the given tiletype. |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
99 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
100 |
* @param tile The tile to check |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
101 |
* @param type The type to check agains |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
102 |
* @return true If the type matches agains the type of the tile |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
103 |
*/ |
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1211
diff
changeset
|
104 |
static inline bool IsTileType(TileIndex tile, TileType type) |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
979
diff
changeset
|
105 |
{ |
1214
33e07bbb7779
(svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents:
1211
diff
changeset
|
106 |
return GetTileType(tile) == type; |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
979
diff
changeset
|
107 |
} |
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
979
diff
changeset
|
108 |
|
7861
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
109 |
/** |
9147
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
110 |
* Checks if a tile is valid |
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
111 |
* |
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
112 |
* @param tile The tile to check |
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
113 |
* @return True if the tile is on the map and not one of MP_VOID. |
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
114 |
*/ |
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
115 |
static inline bool IsValidTile(TileIndex tile) |
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
116 |
{ |
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
117 |
return tile < MapSize() && !IsTileType(tile, MP_VOID); |
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
118 |
} |
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
119 |
|
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
120 |
/** |
7861
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
121 |
* Returns the owner of a tile |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
122 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
123 |
* This function returns the owner of a tile. This cannot used |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
124 |
* for tiles which type is one of MP_HOUSE, MP_VOID and MP_INDUSTRY |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
125 |
* as no player owned any of these buildings. |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
126 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
127 |
* @param tile The tile to check |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
128 |
* @return The owner of the tile |
9147
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
129 |
* @pre IsValidTile(tile) |
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
130 |
* @pre The type of the tile must not be MP_HOUSE and MP_INDUSTRY |
7861
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
131 |
*/ |
1333 | 132 |
static inline Owner GetTileOwner(TileIndex tile) |
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1214
diff
changeset
|
133 |
{ |
9147
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
134 |
assert(IsValidTile(tile)); |
1898
b9fe2a5b7e13
(svn r2404) assert that GetTileOwner() isn't called for tiles, which don't store owner information
tron
parents:
1852
diff
changeset
|
135 |
assert(!IsTileType(tile, MP_HOUSE)); |
b9fe2a5b7e13
(svn r2404) assert that GetTileOwner() isn't called for tiles, which don't store owner information
tron
parents:
1852
diff
changeset
|
136 |
assert(!IsTileType(tile, MP_INDUSTRY)); |
b9fe2a5b7e13
(svn r2404) assert that GetTileOwner() isn't called for tiles, which don't store owner information
tron
parents:
1852
diff
changeset
|
137 |
|
3900
4984308f9125
(svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
3794
diff
changeset
|
138 |
return (Owner)_m[tile].m1; |
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1214
diff
changeset
|
139 |
} |
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1214
diff
changeset
|
140 |
|
7861
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
141 |
/** |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
142 |
* Sets the owner of a tile |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
143 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
144 |
* This function sets the owner status of a tile. Note that you cannot |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
145 |
* set a owner for tiles of type MP_HOUSE, MP_VOID and MP_INDUSTRY. |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
146 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
147 |
* @param tile The tile to change the owner status. |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
148 |
* @param owner The new owner. |
9147
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
149 |
* @pre IsValidTile(tile) |
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
150 |
* @pre The type of the tile must not be MP_HOUSE and MP_INDUSTRY |
7861
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
151 |
*/ |
1902 | 152 |
static inline void SetTileOwner(TileIndex tile, Owner owner) |
153 |
{ |
|
9147
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
154 |
assert(IsValidTile(tile)); |
1902 | 155 |
assert(!IsTileType(tile, MP_HOUSE)); |
156 |
assert(!IsTileType(tile, MP_INDUSTRY)); |
|
157 |
||
2360
09e42e4ee139
(svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents:
2186
diff
changeset
|
158 |
_m[tile].m1 = owner; |
1902 | 159 |
} |
160 |
||
7861
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
161 |
/** |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
162 |
* Checks if a tile belongs to the given owner |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
163 |
* |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
164 |
* @param tile The tile to check |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
165 |
* @param owner The owner to check agains |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
166 |
* @return True if a tile belongs the the given owner |
e45fe49dbe58
(svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents:
7809
diff
changeset
|
167 |
*/ |
1330
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1214
diff
changeset
|
168 |
static inline bool IsTileOwner(TileIndex tile, Owner owner) |
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1214
diff
changeset
|
169 |
{ |
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1214
diff
changeset
|
170 |
return GetTileOwner(tile) == owner; |
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1214
diff
changeset
|
171 |
} |
8a67d04016ce
(svn r1834) - Fix: NPF does not check the owner of its target, busses try to enter other players' depots. TODO
matthijs
parents:
1214
diff
changeset
|
172 |
|
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
173 |
/** |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
174 |
* Set the tropic zone |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
175 |
* @param tile the tile to set the zone of |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
176 |
* @param type the new type |
9147
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
177 |
* @pre tile < MapSize() |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
178 |
*/ |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
179 |
static inline void SetTropicZone(TileIndex tile, TropicZone type) |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
180 |
{ |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
181 |
assert(tile < MapSize()); |
5847
9ce114e1d90d
(svn r8050) -Codechange: Rename map member extra to m6, since its usage has been widden.
belugas
parents:
5838
diff
changeset
|
182 |
SB(_m[tile].m6, 0, 2, type); |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
183 |
} |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
184 |
|
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
185 |
/** |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
186 |
* Get the tropic zone |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
187 |
* @param tile the tile to get the zone of |
9147
54271cd8f27f
(svn r12303) -Codechange: move IsValidTile() in a more suitable place and make it static inline
glx
parents:
8750
diff
changeset
|
188 |
* @pre tile < MapSize() |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
189 |
* @return the zone type |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
190 |
*/ |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
191 |
static inline TropicZone GetTropicZone(TileIndex tile) |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
192 |
{ |
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
193 |
assert(tile < MapSize()); |
5847
9ce114e1d90d
(svn r8050) -Codechange: Rename map member extra to m6, since its usage has been widden.
belugas
parents:
5838
diff
changeset
|
194 |
return (TropicZone)GB(_m[tile].m6, 0, 2); |
3379
ea8aa9e71328
(svn r4181) CodeChange : Replaced [G/S]etMapExtraBits by [G/S]etTropicZone. Although it was an accessor, nor his usage nor the values were clear.
belugas
parents:
3279
diff
changeset
|
195 |
} |
8604
8afdd9877afd
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
7866
diff
changeset
|
196 |
|
8afdd9877afd
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
7866
diff
changeset
|
197 |
Slope GetTileSlope(TileIndex tile, uint *h); |
8afdd9877afd
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
7866
diff
changeset
|
198 |
uint GetTileZ(TileIndex tile); |
8afdd9877afd
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
7866
diff
changeset
|
199 |
uint GetTileMaxZ(TileIndex tile); |
8afdd9877afd
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
7866
diff
changeset
|
200 |
|
8afdd9877afd
(svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents:
7866
diff
changeset
|
201 |
#endif /* TILE_TYPE_H */ |