changeset 8391:443c5f4c083f draft

(svn r11961) -Feature[newGRF]: Add support for Action 0D, var 13: informations about current map size.
author belugas <belugas@openttd.org>
date Wed, 23 Jan 2008 17:08:35 +0000
parents 381a22f19287
children ab6601cad472
files src/map.cpp src/map_func.h src/newgrf.cpp
diffstat 3 files changed, 45 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -16,6 +16,7 @@
 #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 @@
 	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;
--- a/src/map_func.h
+++ b/src/map_func.h
@@ -57,6 +57,17 @@
 }
 
 /**
+ * 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
  */
--- 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 @@
 	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;