summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbelugas <belugas@openttd.org>2008-01-23 17:08:35 +0000
committerbelugas <belugas@openttd.org>2008-01-23 17:08:35 +0000
commit4a3e135086fb2c29221a70e1bd0adf279f36c3bd (patch)
tree9a885c0e543d6bc0b57a61d035fa6563b4b145aa
parent0b888ccc001c3157d1990467036a557783ca38be (diff)
downloadopenttd-4a3e135086fb2c29221a70e1bd0adf279f36c3bd.tar.xz
(svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
-rw-r--r--src/map.cpp2
-rw-r--r--src/map_func.h11
-rw-r--r--src/newgrf.cpp32
3 files changed, 45 insertions, 0 deletions
diff --git a/src/map.cpp b/src/map.cpp
index 865e92b35..76cd384d4 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -16,6 +16,7 @@ extern "C" _CRTIMP void __cdecl _assert(void *, void *, unsigned);
#endif
uint _map_log_x; ///< 2^_map_log_x == _map_size_x
+uint _map_log_y; ///< 2^_map_log_y == _map_size_y
uint _map_size_x; ///< Size of the map along the X
uint _map_size_y; ///< Size of the map along the Y
uint _map_size; ///< The number of tiles on the map
@@ -43,6 +44,7 @@ void AllocateMap(uint size_x, uint size_y)
DEBUG(map, 1, "Allocating map of size %dx%d", size_x, size_y);
_map_log_x = FindFirstBit(size_x);
+ _map_log_y = FindFirstBit(size_y);
_map_size_x = size_x;
_map_size_y = size_y;
_map_size = size_x * size_y;
diff --git a/src/map_func.h b/src/map_func.h
index dc40b1011..9e2a5d70e 100644
--- a/src/map_func.h
+++ b/src/map_func.h
@@ -57,6 +57,17 @@ static inline uint MapLogX()
}
/**
+ * Logarithm of the map size along the y side.
+ * @note try to avoid using this one
+ * @return 2^"return value" == MapSizeY()
+ */
+static inline uint MapLogY()
+{
+ extern uint _map_log_y;
+ return _map_log_y;
+}
+
+/**
* Get the size of the map along the X
* @return the number of tiles along the X of the map
*/
diff --git a/src/newgrf.cpp b/src/newgrf.cpp
index d4514d38d..c4e44df5a 100644
--- a/src/newgrf.cpp
+++ b/src/newgrf.cpp
@@ -44,6 +44,7 @@
#include "road_func.h"
#include "player_base.h"
#include "settings_type.h"
+#include "map_func.h"
#include "table/strings.h"
#include "table/sprites.h"
@@ -4025,15 +4026,46 @@ static uint32 GetPatchVariable(uint8 param)
switch (param) {
/* start year - 1920 */
case 0x0B: return max(_patches.starting_year, ORIGINAL_BASE_YEAR) - ORIGINAL_BASE_YEAR;
+
/* freight trains weight factor */
case 0x0E: return _patches.freight_trains;
+
/* empty wagon speed increase */
case 0x0F: return 0;
+
/* plane speed factor */
case 0x10: return 4;
+
/* 2CC colormap base sprite */
case 0x11: return SPR_2CCMAP_BASE;
+ /* map size: format = -MABXYSS
+ * M : the type of map
+ * bit 0 : set : squared map. Bit 1 is now not relevant
+ * clear : rectangle map. Bit 1 will indicate the bigger edge of the map
+ * bit 1 : set : Y is the bigger edge. Bit 0 is clear
+ * clear : X is the bigger edge.
+ * A : minimum edge(log2) of the map
+ * B : maximum edge(log2) of the map
+ * XY : edges(log2) of each side of the map.
+ * SS : combination of both X and Y, thus giving the size(log2) of the map
+ */
+ case 0x13: {
+ byte map_bits = 0;
+ byte log_X = MapLogX() - 6;
+ byte log_Y = MapLogY() - 6;
+ byte max_edge = max(log_X, log_Y);
+
+ if (log_X == log_Y) { // we have a squared map, since both edges are identical
+ SetBit(map_bits ,0);
+ } else {
+ if (max_edge == log_Y) SetBit(map_bits, 1); // edge Y been the biggest, mark it
+ }
+
+ return (map_bits << 24) | (min(log_X, log_Y) << 20) | (max_edge << 16) |
+ (log_X << 12) | (log_Y << 8) | (log_X + log_Y);
+ }
+
default:
grfmsg(2, "ParamSet: Unknown Patch variable 0x%02X.", param);
return 0;