src/map.h
branchgamebalance
changeset 9895 7bd07f43b0e3
parent 6527 f584ab6d87f8
child 6303 84c215fc8eb8
equal deleted inserted replaced
9894:70d78ac95d6c 9895:7bd07f43b0e3
    16 extern uint _map_size;
    16 extern uint _map_size;
    17 
    17 
    18 #define TILE_MASK(x) ((x) & _map_tile_mask)
    18 #define TILE_MASK(x) ((x) & _map_tile_mask)
    19 #define TILE_ASSERT(x) assert(TILE_MASK(x) == (x));
    19 #define TILE_ASSERT(x) assert(TILE_MASK(x) == (x));
    20 
    20 
    21 typedef struct Tile {
    21 struct Tile {
    22 	byte type_height;
    22 	byte type_height;
    23 	byte m1;
    23 	byte m1;
    24 	uint16 m2;
    24 	uint16 m2;
    25 	byte m3;
    25 	byte m3;
    26 	byte m4;
    26 	byte m4;
    27 	byte m5;
    27 	byte m5;
    28 	byte m6;
    28 	byte m6;
    29 } Tile;
    29 };
    30 
    30 
    31 extern Tile* _m;
    31 extern Tile* _m;
    32 
    32 
    33 void AllocateMap(uint size_x, uint size_y);
    33 void AllocateMap(uint size_x, uint size_y);
    34 
    34 
    35 /* binary logarithm of the map size, try to avoid using this one */
    35 /* binary logarithm of the map size, try to avoid using this one */
    36 static inline uint MapLogX(void)  { return _map_log_x; }
    36 static inline uint MapLogX()  { return _map_log_x; }
    37 /* The size of the map */
    37 /* The size of the map */
    38 static inline uint MapSizeX(void) { return _map_size_x; }
    38 static inline uint MapSizeX() { return _map_size_x; }
    39 static inline uint MapSizeY(void) { return _map_size_y; }
    39 static inline uint MapSizeY() { return _map_size_y; }
    40 /* The maximum coordinates */
    40 /* The maximum coordinates */
    41 static inline uint MapMaxX(void) { return _map_size_x - 1; }
    41 static inline uint MapMaxX() { return _map_size_x - 1; }
    42 static inline uint MapMaxY(void) { return _map_size_y - 1; }
    42 static inline uint MapMaxY() { return _map_size_y - 1; }
    43 /* The number of tiles in the map */
    43 /* The number of tiles in the map */
    44 static inline uint MapSize(void) { return _map_size; }
    44 static inline uint MapSize() { return _map_size; }
    45 
    45 
    46 /* Scale a number relative to the map size */
    46 /* Scale a number relative to the map size */
    47 uint ScaleByMapSize(uint); // Scale relative to the number of tiles
    47 uint ScaleByMapSize(uint); // Scale relative to the number of tiles
    48 uint ScaleByMapSize1D(uint); // Scale relative to the circumference of the map
    48 uint ScaleByMapSize1D(uint); // Scale relative to the circumference of the map
    49 
    49 
    90 {
    90 {
    91 	return tile >> MapLogX();
    91 	return tile >> MapLogX();
    92 }
    92 }
    93 
    93 
    94 
    94 
    95 typedef struct TileIndexDiffC {
    95 struct TileIndexDiffC {
    96 	int16 x;
    96 	int16 x;
    97 	int16 y;
    97 	int16 y;
    98 } TileIndexDiffC;
    98 };
    99 
    99 
   100 static inline TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
   100 static inline TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
   101 {
   101 {
   102 	return (tidc.y << MapLogX()) + tidc.x;
   102 	return (tidc.y << MapLogX()) + tidc.x;
   103 }
   103 }