summaryrefslogtreecommitdiff
path: root/src/landscape.cpp
diff options
context:
space:
mode:
authormaedhros <maedhros@openttd.org>2007-03-20 13:47:00 +0000
committermaedhros <maedhros@openttd.org>2007-03-20 13:47:00 +0000
commit48f2bf9bb1bd7b8859d3527c6c205386471cc4e4 (patch)
treea58aa837d70b430e5ab2ea0f71158e3b6032453b /src/landscape.cpp
parent7812f7fd0ac617a9df41730e6770519154bc5344 (diff)
downloadopenttd-48f2bf9bb1bd7b8859d3527c6c205386471cc4e4.tar.xz
(svn r9371) -Feature: Add support for variable snow lines in the arctic climate, supplied
by newgrf files. When this is enabled forests cannot be built below the highest snow line, and farms can't be built above it. Houses still use the _opt.snow_line so they are all consistent, so to make them respect the snowline you may want to use some newhouses features as well.
Diffstat (limited to 'src/landscape.cpp')
-rw-r--r--src/landscape.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/landscape.cpp b/src/landscape.cpp
index 7c3ada82f..9ed7d9df1 100644
--- a/src/landscape.cpp
+++ b/src/landscape.cpp
@@ -5,6 +5,7 @@
#include "bridge_map.h"
#include "heightmap.h"
#include "clear_map.h"
+#include "date.h"
#include "functions.h"
#include "map.h"
#include "player.h"
@@ -14,6 +15,7 @@
#include <stdarg.h>
#include "viewport.h"
#include "command.h"
+#include "landscape.h"
#include "vehicle.h"
#include "variables.h"
#include "void_map.h"
@@ -61,6 +63,7 @@ const Slope _inclined_tileh[] = {
SLOPE_NWS, SLOPE_WSE, SLOPE_SEN, SLOPE_ENW
};
+SnowLine *_snow_line = NULL;
uint GetPartialZ(int x, int y, Slope corners)
{
@@ -302,6 +305,62 @@ void GetTileDesc(TileIndex tile, TileDesc *td)
_tile_type_procs[GetTileType(tile)]->get_tile_desc_proc(tile, td);
}
+/**
+ * Has a snow line table already been loaded.
+ * @return true if the table has been loaded already.
+ */
+bool IsSnowLineSet(void)
+{
+ return _snow_line != NULL;
+}
+
+/**
+ * Set a variable snow line, as loaded from a newgrf file.
+ * @param table the 12 * 32 byte table containing the snowline for each day
+ */
+void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS])
+{
+ _snow_line = CallocT<SnowLine>(1);
+ memcpy(_snow_line->table, table, sizeof(_snow_line->table));
+
+ for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
+ for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
+ _snow_line->highest_value = max(_snow_line->highest_value, table[i][j]);
+ }
+ }
+}
+
+/**
+ * Get the current snow line, either variable or static.
+ * @return the snow line height.
+ */
+byte GetSnowLine(void)
+{
+ if (_snow_line == NULL) return _opt.snow_line;
+
+ YearMonthDay ymd;
+ ConvertDateToYMD(_date, &ymd);
+ return _snow_line->table[ymd.month][ymd.day];
+}
+
+/**
+ * Get the highest possible snow line height, either variable or static.
+ * @return the highest snow line height.
+ */
+byte HighestSnowLine(void)
+{
+ return _snow_line == NULL ? _opt.snow_line : _snow_line->highest_value;
+}
+
+/**
+ * Clear the variable snow line table and free the memory.
+ */
+void ClearSnowLine(void)
+{
+ free(_snow_line);
+ _snow_line = NULL;
+}
+
/** Clear a piece of landscape
* @param tile tile to clear
* @param flags of operation to conduct