map.h
author truelight
Thu, 06 Jan 2005 22:31:58 +0000
changeset 919 544f374ee392
parent 909 65cdb609b7a6
child 926 a6d140a6a4de
permissions -rw-r--r--
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
(in prepare of dynamic arrays):
- DEREF_XXX is changed into GetXXX
- All direct call are directed via GetXXX
- struct Industry has now an index-field
- ENUM'd some stuff
- Replaced home built loops with FOR_ALL_XXX
- Added _stations_size, _vehicles_size, ... which gives the length of the
array (which will be dynamic in the near future)
- Changed lengtof(XXX) to _XXX_size (e.g. _stations_size)
- Removed all endof(XXX) (because mostly it was part of a FOR_ALL_XXX)
- Made the sort-functions of all 4 dynamic
- Made all 4 Initialize functions more of the same
- Some minor tab-fixing and stuff
(tnx to Tron for proof-reading my 100kb patch ;))

Note for all: please do NOT directly call _stations, _vehicles, _towns and
_industries, but use the right wrapper to access them. Thank you.
Ps: please also do not use 'v++', where v is of type Vehicle *.
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff changeset
     1
#ifndef MAP_H
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff changeset
     2
#define MAP_H
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff changeset
     3
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff changeset
     4
#define TILE_X_BITS 8
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff changeset
     5
#define TILE_Y_BITS 8
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff changeset
     6
817
238bbdaa228b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 695
diff changeset
     7
extern byte   _map_type_and_height[];
238bbdaa228b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 695
diff changeset
     8
extern byte   _map5[];
238bbdaa228b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 695
diff changeset
     9
extern byte   _map3_lo[];
238bbdaa228b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 695
diff changeset
    10
extern byte   _map3_hi[];
238bbdaa228b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 695
diff changeset
    11
extern byte   _map_owner[];
238bbdaa228b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 695
diff changeset
    12
extern uint16 _map2[];
238bbdaa228b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 695
diff changeset
    13
extern byte   _map_extra_bits[];
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff changeset
    14
689
5a4b1536db82 (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    15
// binary logarithm of the map size, try to avoid using this one
5a4b1536db82 (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    16
static inline uint MapLogX(void)  { extern uint _map_log_x; return _map_log_x; }
5a4b1536db82 (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    17
static inline uint MapLogY(void)  { extern uint _map_log_y; return _map_log_y; }
5a4b1536db82 (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    18
/* The size of the map */
5a4b1536db82 (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    19
static inline uint MapSizeX(void) { return 1 << MapLogX(); }
5a4b1536db82 (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    20
static inline uint MapSizeY(void) { return 1 << MapLogY(); }
5a4b1536db82 (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    21
/* The maximum coordinates */
5a4b1536db82 (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    22
static inline uint MapMaxX(void) { return MapSizeX() - 1; }
5a4b1536db82 (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    23
static inline uint MapMaxY(void) { return MapSizeY() - 1; }
5a4b1536db82 (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    24
/* The number of tiles in the map */
5a4b1536db82 (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    25
static inline uint MapSize(void) { return MapSizeX() * MapSizeY(); }
5a4b1536db82 (svn r1130) Add helper functions to query map size
tron
parents: 679
diff changeset
    26
900
27eb21ced433 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    27
typedef int16 TileIndexDiff;
27eb21ced433 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    28
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    29
typedef struct TileIndexDiffC {
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    30
	int16 x;
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    31
	int16 y;
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    32
} TileIndexDiffC;
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    33
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    34
static inline TileIndexDiff ToTileIndexDiff(TileIndexDiffC tidc)
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    35
{
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    36
	return (tidc.y << MapLogX()) + tidc.x;
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    37
}
900
27eb21ced433 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    38
27eb21ced433 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    39
static inline TileIndexDiff TileOffsByDir(uint dir)
27eb21ced433 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    40
{
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    41
	extern const TileIndexDiffC _tileoffs_by_dir[4];
900
27eb21ced433 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    42
27eb21ced433 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    43
	assert(dir < lengthof(_tileoffs_by_dir));
909
65cdb609b7a6 (svn r1396) Introduce TileIndexDiffC - the compile time version of TileIndexDiff
tron
parents: 900
diff changeset
    44
	return ToTileIndexDiff(_tileoffs_by_dir[dir]);
900
27eb21ced433 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    45
}
27eb21ced433 (svn r1386) Move TileIndexDiff to map.h
tron
parents: 863
diff changeset
    46
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
diff changeset
    47
#endif