src/map.cpp
branchNewGRF_ports
changeset 6872 1c4a4a609f85
parent 6871 5a9dc001e1ad
child 6877 889301acc299
equal deleted inserted replaced
6871:5a9dc001e1ad 6872:1c4a4a609f85
     1 /* $Id$ */
     1 /* $Id$ */
     2 
     2 
     3 /** @file map.cpp */
     3 /** @file map.cpp */
     4 
     4 
     5 #include "stdafx.h"
     5 #include "stdafx.h"
     6 #include "openttd.h"
       
     7 #include "debug.h"
     6 #include "debug.h"
     8 #include "functions.h"
     7 #include "direction_func.h"
     9 #include "macros.h"
     8 #include "core/bitmath_func.hpp"
    10 #include "map.h"
     9 #include "core/alloc_func.hpp"
    11 #include "direction.h"
    10 #include "core/math_func.hpp"
    12 #include "helpers.hpp"
    11 #include "map_func.h"
    13 
    12 
    14 #if defined(_MSC_VER) && _MSC_VER >= 1400 /* VStudio 2005 is stupid! */
    13 #if defined(_MSC_VER) && _MSC_VER >= 1400 /* VStudio 2005 is stupid! */
    15 /* Why the hell is that not in all MSVC headers?? */
    14 /* Why the hell is that not in all MSVC headers?? */
    16 extern "C" _CRTIMP void __cdecl _assert(void *, void *, unsigned);
    15 extern "C" _CRTIMP void __cdecl _assert(void *, void *, unsigned);
    17 #endif
    16 #endif
    50 	_map_tile_mask = _map_size - 1;
    49 	_map_tile_mask = _map_size - 1;
    51 
    50 
    52 	free(_m);
    51 	free(_m);
    53 	free(_me);
    52 	free(_me);
    54 
    53 
    55 	_m = CallocT<Tile>(_map_size);
       
    56 	_me = CallocT<TileExtended>(_map_size);
       
    57 
       
    58 	/* XXX @todo handle memory shortage more gracefully
    54 	/* XXX @todo handle memory shortage more gracefully
       
    55 	 * CallocT does the out-of-memory check
    59 	 * Maybe some attemps could be made to try with smaller maps down to 64x64
    56 	 * Maybe some attemps could be made to try with smaller maps down to 64x64
    60 	 * Maybe check for available memory before doing the calls, after all, we know how big
    57 	 * Maybe check for available memory before doing the calls, after all, we know how big
    61 	 * the map is */
    58 	 * the map is */
    62 	if ((_m == NULL) || (_me == NULL)) error("Failed to allocate memory for the map");
    59 	_m = CallocT<Tile>(_map_size);
       
    60 	_me = CallocT<TileExtended>(_map_size);
    63 }
    61 }
    64 
    62 
    65 
    63 
    66 #ifdef _DEBUG
    64 #ifdef _DEBUG
    67 TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
    65 TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
   139  * @param tile the 'starting' point of the adding
   137  * @param tile the 'starting' point of the adding
   140  * @param addx the amount of tiles in the X direction to add
   138  * @param addx the amount of tiles in the X direction to add
   141  * @param addy the amount of tiles in the Y direction to add
   139  * @param addy the amount of tiles in the Y direction to add
   142  * @return translated tile, or INVALID_TILE when it would've wrapped.
   140  * @return translated tile, or INVALID_TILE when it would've wrapped.
   143  */
   141  */
   144 uint TileAddWrap(TileIndex tile, int addx, int addy)
   142 TileIndex TileAddWrap(TileIndex tile, int addx, int addy)
   145 {
   143 {
   146 	uint x = TileX(tile) + addx;
   144 	uint x = TileX(tile) + addx;
   147 	uint y = TileY(tile) + addy;
   145 	uint y = TileY(tile) + addy;
   148 
   146 
   149 	/* Are we about to wrap? */
   147 	/* Are we about to wrap? */