src/map.cpp
branchnoai
changeset 9723 eee46cb39750
parent 9722 ebf0ece7d8f6
child 9724 b39bc69bb2f2
--- a/src/map.cpp	Fri Nov 23 16:59:30 2007 +0000
+++ b/src/map.cpp	Wed Jan 09 18:11:12 2008 +0000
@@ -3,13 +3,12 @@
 /** @file map.cpp */
 
 #include "stdafx.h"
-#include "openttd.h"
 #include "debug.h"
-#include "functions.h"
-#include "macros.h"
-#include "map.h"
-#include "direction.h"
-#include "helpers.hpp"
+#include "direction_func.h"
+#include "core/bitmath_func.hpp"
+#include "core/alloc_func.hpp"
+#include "core/math_func.hpp"
+#include "map_func.h"
 
 #if defined(_MSC_VER) && _MSC_VER >= 1400 /* VStudio 2005 is stupid! */
 /* Why the hell is that not in all MSVC headers?? */
@@ -52,14 +51,13 @@
 	free(_m);
 	free(_me);
 
-	_m = CallocT<Tile>(_map_size);
-	_me = CallocT<TileExtended>(_map_size);
-
 	/* XXX @todo handle memory shortage more gracefully
+	 * CallocT does the out-of-memory check
 	 * Maybe some attemps could be made to try with smaller maps down to 64x64
 	 * Maybe check for available memory before doing the calls, after all, we know how big
 	 * the map is */
-	if ((_m == NULL) || (_me == NULL)) error("Failed to allocate memory for the map");
+	_m = CallocT<Tile>(_map_size);
+	_me = CallocT<TileExtended>(_map_size);
 }
 
 
@@ -184,8 +182,8 @@
  */
 uint DistanceManhattan(TileIndex t0, TileIndex t1)
 {
-	const uint dx = delta(TileX(t0), TileX(t1));
-	const uint dy = delta(TileY(t0), TileY(t1));
+	const uint dx = Delta(TileX(t0), TileX(t1));
+	const uint dy = Delta(TileY(t0), TileY(t1));
 	return dx + dy;
 }
 
@@ -216,8 +214,8 @@
  */
 uint DistanceMax(TileIndex t0, TileIndex t1)
 {
-	const uint dx = delta(TileX(t0), TileX(t1));
-	const uint dy = delta(TileY(t0), TileY(t1));
+	const uint dx = Delta(TileX(t0), TileX(t1));
+	const uint dy = Delta(TileY(t0), TileY(t1));
 	return max(dx, dy);
 }
 
@@ -232,8 +230,8 @@
  */
 uint DistanceMaxPlusManhattan(TileIndex t0, TileIndex t1)
 {
-	const uint dx = delta(TileX(t0), TileX(t1));
-	const uint dy = delta(TileY(t0), TileY(t1));
+	const uint dx = Delta(TileX(t0), TileX(t1));
+	const uint dy = Delta(TileY(t0), TileY(t1));
 	return dx > dy ? 2 * dx + dy : 2 * dy + dx;
 }