src/tile_map.h
author rubidium
Fri, 21 Dec 2007 19:21:21 +0000
changeset 8609 8c0c3e9dd6a0
parent 8604 8afdd9877afd
child 8635 3bbb6f87fced
permissions -rw-r--r--
(svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2125
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2125
diff changeset
     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"
8afdd9877afd (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 7866
diff changeset
    10
#include "map.h"
8609
8c0c3e9dd6a0 (svn r11674) -Codechange: refactor some functions out of macros.h into more logical locations.
rubidium
parents: 8604
diff changeset
    11
#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
    12
7861
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    13
/**
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    14
 * 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
    15
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    16
 * 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
    17
 * 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
    18
 * 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
    19
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    20
 * @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
    21
 * @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
    22
 * @pre tile < MapSize()
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    23
 */
1044
9b73df700a7c (svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents: 1041
diff changeset
    24
static inline uint TileHeight(TileIndex tile)
9b73df700a7c (svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents: 1041
diff changeset
    25
{
9b73df700a7c (svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents: 1041
diff changeset
    26
	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
    27
	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
    28
}
9b73df700a7c (svn r1545) Add TileHeight() which returns the height (not multiplied by 8)
tron
parents: 1041
diff changeset
    29
7861
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    30
/**
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    31
 * 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
    32
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    33
 * 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
    34
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    35
 * @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
    36
 * @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
    37
 * @pre tile < MapSize()
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    38
 * @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
    39
 */
1059
c28c6be74291 (svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents: 1044
diff changeset
    40
static inline void SetTileHeight(TileIndex tile, uint height)
c28c6be74291 (svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents: 1044
diff changeset
    41
{
c28c6be74291 (svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents: 1044
diff changeset
    42
	assert(tile < MapSize());
7861
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    43
	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
    44
	SB(_m[tile].type_height, 0, 4, height);
1059
c28c6be74291 (svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents: 1044
diff changeset
    45
}
c28c6be74291 (svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents: 1044
diff changeset
    46
7861
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    47
/**
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    48
 * 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
    49
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    50
 * 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
    51
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    52
 * @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
    53
 * @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
    54
 */
1041
be151b7bc909 (svn r1542) Rename TileHeight to TilePixelHeight, because this is what it actually returns
tron
parents: 1035
diff changeset
    55
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
    56
{
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4067
diff changeset
    57
	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
    58
}
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
7861
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    60
/**
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    61
 * 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
    62
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    63
 * @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
    64
 * @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
    65
 * @pre tile < MapSize()
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    66
 */
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
    67
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
    68
{
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
	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
    70
	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
    71
}
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
7861
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    73
/**
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    74
 * 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
    75
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    76
 * 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
    77
 * 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
    78
 * 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
    79
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    80
 * @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
    81
 * @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
    82
 * @pre tile < MapSize()
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    83
 * @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
    84
 */
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
    85
static inline void SetTileType(TileIndex tile, TileType type)
1059
c28c6be74291 (svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents: 1044
diff changeset
    86
{
c28c6be74291 (svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents: 1044
diff changeset
    87
	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
    88
	/* 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
    89
	 * 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
    90
	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
    91
	SB(_m[tile].type_height, 4, 4, type);
1059
c28c6be74291 (svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents: 1044
diff changeset
    92
}
c28c6be74291 (svn r1560) Introduce SetTileType() and SetTileHeight()
tron
parents: 1044
diff changeset
    93
7861
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    94
/**
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    95
 * 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
    96
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    97
 * 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
    98
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
    99
 * @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
   100
 * @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
   101
 * @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
   102
 */
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   103
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
   104
{
1214
33e07bbb7779 (svn r1718) Use the enum TileType as parameter/return type for [GS]etTileType() instead of plain int.
tron
parents: 1211
diff changeset
   105
	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
   106
}
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
7861
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
   108
/**
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
   109
 * 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
   110
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
   111
 * 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
   112
 * 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
   113
 * 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
   114
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
   115
 * @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
   116
 * @return The owner of the tile
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
   117
 * @pre tile < MapSize()
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
   118
 * @pre The type of the tile must not be 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
   119
 */
1333
9ac74f431ed2 (svn r1837) GetTileOwner returns Owner, not bool
tron
parents: 1330
diff changeset
   120
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
   121
{
1333
9ac74f431ed2 (svn r1837) GetTileOwner returns Owner, not bool
tron
parents: 1330
diff changeset
   122
	assert(tile < MapSize());
1898
b9fe2a5b7e13 (svn r2404) assert that GetTileOwner() isn't called for tiles, which don't store owner information
tron
parents: 1852
diff changeset
   123
	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
   124
	assert(!IsTileType(tile, MP_VOID));
b9fe2a5b7e13 (svn r2404) assert that GetTileOwner() isn't called for tiles, which don't store owner information
tron
parents: 1852
diff changeset
   125
	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
   126
3900
4984308f9125 (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents: 3794
diff changeset
   127
	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
   128
}
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
   129
7861
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
   130
/**
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
   131
 * 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
   132
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
   133
 * 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
   134
 * 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
   135
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
   136
 * @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
   137
 * @param owner The new owner.
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
   138
 * @pre tile < MapSize()
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
   139
 * @pre The type of the tile must not be 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
   140
 */
1902
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1898
diff changeset
   141
static inline void SetTileOwner(TileIndex tile, Owner owner)
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1898
diff changeset
   142
{
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1898
diff changeset
   143
	assert(tile < MapSize());
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1898
diff changeset
   144
	assert(!IsTileType(tile, MP_HOUSE));
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1898
diff changeset
   145
	assert(!IsTileType(tile, MP_VOID));
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1898
diff changeset
   146
	assert(!IsTileType(tile, MP_INDUSTRY));
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1898
diff changeset
   147
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
   148
	_m[tile].m1 = owner;
1902
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1898
diff changeset
   149
}
5d653da1abb7 (svn r2408) Introduce SetTileOwner() and use it
tron
parents: 1898
diff changeset
   150
7861
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
   151
/**
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
   152
 * 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
   153
 *
e45fe49dbe58 (svn r10728) -Documentation [FS#1088]: of tile.h. Based on a patch by Progman.
rubidium
parents: 7809
diff changeset
   154
 * @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
   155
 * @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
   156
 * @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
   157
 */
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
   158
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
   159
{
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
   160
	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
   161
}
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
   162
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
   163
/**
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
   164
 * 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
   165
 * @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
   166
 * @param type the new 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
   167
 * @pre assert(tile < MapSize());
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
   168
 */
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
   169
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
   170
{
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
   171
	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
   172
	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
   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
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
/**
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
 * 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
   177
 * @param tile the tile to get 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
   178
 * @pre assert(tile < MapSize());
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
 * @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
   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
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
   182
{
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
	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
   184
	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
   185
}
8604
8afdd9877afd (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 7866
diff changeset
   186
8afdd9877afd (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 7866
diff changeset
   187
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
   188
uint GetTileZ(TileIndex tile);
8afdd9877afd (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 7866
diff changeset
   189
uint GetTileMaxZ(TileIndex tile);
8afdd9877afd (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 7866
diff changeset
   190
8afdd9877afd (svn r11669) -Codechange: refactor tile.h -> tile_type.h and tile_map.h
rubidium
parents: 7866
diff changeset
   191
#endif /* TILE_TYPE_H */