Changeset - r6343:4d2d12eee7b9
[Not reviewed]
master
0 12 1
maedhros - 18 years ago 2007-03-20 13:47:00
maedhros@openttd.org
(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.
13 files changed with 122 insertions and 14 deletions:
0 comments (0 inline, 0 general)
src/clear_cmd.cpp
Show inline comments
 
@@ -13,12 +13,13 @@
 
#include "tile.h"
 
#include "viewport.h"
 
#include "command.h"
 
#include "tunnel_map.h"
 
#include "bridge_map.h"
 
#include "bridge.h"
 
#include "landscape.h"
 
#include "variables.h"
 
#include "table/sprites.h"
 
#include "unmovable_map.h"
 
#include "genworld.h"
 
#include "industry.h"
 

	
 
@@ -617,13 +618,13 @@ void TileLoopClearHelper(TileIndex tile)
 
}
 

	
 

	
 
/* convert into snowy tiles */
 
static void TileLoopClearAlps(TileIndex tile)
 
{
 
	int k = GetTileZ(tile) - _opt.snow_line + TILE_HEIGHT;
 
	int k = GetTileZ(tile) - GetSnowLine() + TILE_HEIGHT;
 

	
 
	if (k < 0) { // well below the snow line
 
		if (!IsClearGround(tile, CLEAR_SNOW)) return;
 
		if (GetClearDensity(tile) == 0) SetClearGroundDensity(tile, CLEAR_GRASS, 3);
 
	} else {
 
		if (!IsClearGround(tile, CLEAR_SNOW)) {
src/industry_cmd.cpp
Show inline comments
 
@@ -9,12 +9,13 @@
 
#include "industry_map.h"
 
#include "station_map.h"
 
#include "table/strings.h"
 
#include "table/sprites.h"
 
#include "map.h"
 
#include "tile.h"
 
#include "landscape.h"
 
#include "viewport.h"
 
#include "command.h"
 
#include "industry.h"
 
#include "town.h"
 
#include "vehicle.h"
 
#include "news.h"
 
@@ -811,13 +812,13 @@ static void PlantFarmField(TileIndex til
 
	uint count;
 
	uint counter;
 
	uint field_type;
 
	int type;
 

	
 
	if (_opt.landscape == LT_HILLY) {
 
		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= _opt.snow_line)
 
		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= GetSnowLine())
 
			return;
 
	}
 

	
 
	/* determine field size */
 
	r = (Random() & 0x303) + 0x404;
 
	if (_opt.landscape == LT_HILLY) r += 0x404;
 
@@ -1013,13 +1014,13 @@ static bool CheckNewIndustry_NULL(TileIn
 
	return true;
 
}
 

	
 
static bool CheckNewIndustry_Forest(TileIndex tile)
 
{
 
	if (_opt.landscape == LT_HILLY) {
 
		if (GetTileZ(tile) < _opt.snow_line + TILE_HEIGHT * 2U) {
 
		if (GetTileZ(tile) < HighestSnowLine() + TILE_HEIGHT * 2U) {
 
			_error_message = STR_4831_FOREST_CAN_ONLY_BE_PLANTED;
 
			return false;
 
		}
 
	}
 
	return true;
 
}
 
@@ -1045,13 +1046,13 @@ static bool CheckNewIndustry_OilRig(Tile
 
	return false;
 
}
 

	
 
static bool CheckNewIndustry_Farm(TileIndex tile)
 
{
 
	if (_opt.landscape == LT_HILLY) {
 
		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= _opt.snow_line) {
 
		if (GetTileZ(tile) + TILE_HEIGHT * 2 >= HighestSnowLine()) {
 
			_error_message = STR_0239_SITE_UNSUITABLE;
 
			return false;
 
		}
 
	}
 
	return true;
 
}
src/landscape.cpp
Show inline comments
 
@@ -2,21 +2,23 @@
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "bridge_map.h"
 
#include "heightmap.h"
 
#include "clear_map.h"
 
#include "date.h"
 
#include "functions.h"
 
#include "map.h"
 
#include "player.h"
 
#include "spritecache.h"
 
#include "table/sprites.h"
 
#include "tile.h"
 
#include <stdarg.h>
 
#include "viewport.h"
 
#include "command.h"
 
#include "landscape.h"
 
#include "vehicle.h"
 
#include "variables.h"
 
#include "void_map.h"
 
#include "water_map.h"
 
#include "tgp.h"
 
#include "genworld.h"
 
@@ -58,12 +60,13 @@ const byte _tileh_to_sprite[32] = {
 
const Slope _inclined_tileh[] = {
 
	SLOPE_SW,  SLOPE_NW,  SLOPE_SW,  SLOPE_SE, SLOPE_NE, SLOPE_SE, SLOPE_NE, SLOPE_NW,
 
	SLOPE_E,   SLOPE_N,   SLOPE_W,   SLOPE_S,
 
	SLOPE_NWS, SLOPE_WSE, SLOPE_SEN, SLOPE_ENW
 
};
 

	
 
SnowLine *_snow_line = NULL;
 

	
 
uint GetPartialZ(int x, int y, Slope corners)
 
{
 
	int z = 0;
 

	
 
	switch (corners) {
 
@@ -299,12 +302,68 @@ void ClickTile(TileIndex tile)
 

	
 
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
 
 * @param p1 unused
 
 * @param p2 unused
 
 */
src/landscape.h
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
/** @file landscape.h */
 

	
 
enum {
 
	SNOW_LINE_MONTHS = 12,
 
	SNOW_LINE_DAYS   = 32,
 
};
 

	
 
struct SnowLine {
 
	byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS];
 
	byte highest_value;
 
};
 

	
 
bool IsSnowLineSet(void);
 
void SetSnowLine(byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS]);
 
byte GetSnowLine(void);
 
byte HighestSnowLine(void);
 
void ClearSnowLine(void);
src/newgrf.cpp
Show inline comments
 
@@ -24,12 +24,13 @@
 
#include "vehicle.h"
 
#include "newgrf_text.h"
 
#include "table/sprites.h"
 
#include "fontcache.h"
 
#include "date.h"
 
#include "currency.h"
 
#include "landscape.h"
 
#include "sound.h"
 
#include "newgrf_config.h"
 
#include "newgrf_house.h"
 
#include "newgrf_sound.h"
 
#include "newgrf_spritegroup.h"
 
#include "helpers.hpp"
 
@@ -1507,12 +1508,28 @@ static bool GlobalVarChangeInfo(uint gvi
 
					grfmsg(1, "GlobalVarChangeInfo: Euro intro date %d out of range, ignoring", curidx);
 
				}
 
			}
 
			break;
 

	
 
		case 0x10: // 12 * 32 * B Snow line height table
 
			if (numinfo > 1 || IsSnowLineSet()) {
 
				grfmsg(1, "GlobalVarChangeInfo: The snowline can only be set once (%d)", numinfo);
 
			} else if (len < SNOW_LINE_MONTHS * SNOW_LINE_DAYS) {
 
				grfmsg(1, "GlobalVarChangeInfo: Not enough entries set in the snowline table (%d)", len);
 
			} else {
 
				byte table[SNOW_LINE_MONTHS][SNOW_LINE_DAYS];
 

	
 
				for (uint i = 0; i < SNOW_LINE_MONTHS; i++) {
 
					for (uint j = 0; j < SNOW_LINE_DAYS; j++) {
 
						table[i][j] = grf_load_byte(&buf);
 
					}
 
				}
 
				SetSnowLine(table);
 
			}
 
			break;
 

	
 
		default:
 
			ret = true;
 
	}
 

	
 
	*bufp = buf;
 
	return ret;
 
@@ -3970,12 +3987,15 @@ static void ResetNewGRFData()
 
	ResetHouses();
 

	
 
	// Reset station classes
 
	ResetStationClasses();
 
	ResetCustomStations();
 

	
 
	/* Reset the snowline table. */
 
	ClearSnowLine();
 

	
 
	/* Reset NewGRF files */
 
	ResetNewGRF();
 

	
 
	// Add engine type to engine data. This is needed for the refit precalculation.
 
	AddTypeToEngines();
 

	
src/newgrf_house.cpp
Show inline comments
 
@@ -5,12 +5,13 @@
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "functions.h"
 
#include "variables.h"
 
#include "debug.h"
 
#include "viewport.h"
 
#include "landscape.h"
 
#include "date.h"
 
#include "town.h"
 
#include "town_map.h"
 
#include "sound.h"
 
#include "sprite.h"
 
#include "strings.h"
 
@@ -249,13 +250,13 @@ static uint32 GetNumHouses(HouseID house
 
}
 

	
 
static uint32 GetTerrainType(TileIndex tile)
 
{
 
	switch (_opt.landscape) {
 
		case LT_DESERT: return GetTropicZone(tile) == TROPICZONE_DESERT ? 1 : 2;
 
		case LT_HILLY:  return GetTileZ(tile) >= _opt.snow_line ? 4 : 0;
 
		case LT_HILLY:  return GetTileZ(tile) >= GetSnowLine() ? 4 : 0;
 
		default:        return 0;
 
	}
 
}
 

	
 
static uint32 GetGRFParameter(HouseID house_id, byte parameter)
 
{
src/newgrf_spritegroup.cpp
Show inline comments
 
/* $Id$ */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "variables.h"
 
#include "macros.h"
 
#include "landscape.h"
 
#include "oldpool.h"
 
#include "newgrf_callbacks.h"
 
#include "newgrf_spritegroup.h"
 
#include "date.h"
 
#include "sprite.h"
 

	
 
@@ -88,13 +89,13 @@ static inline uint32 GetVariable(const R
 
		case 0x10: return object->callback_param1;
 
		case 0x11: return 0;
 
		case 0x18: return object->callback_param2;
 
		case 0x1A: return UINT_MAX;
 
		case 0x1B: return GB(_display_opt, 0, 6);
 
		case 0x1C: return object->last_value;
 
		case 0x20: return _opt.landscape == LT_HILLY ? _opt.snow_line : 0xFF;
 
		case 0x20: return _opt.landscape == LT_HILLY ? GetSnowLine() : 0xFF;
 

	
 
		/* Not a common variable, so evalute the feature specific variables */
 
		default: return object->GetVariable(object, variable, parameter, available);
 
	}
 
}
 

	
src/newgrf_station.cpp
Show inline comments
 
@@ -3,12 +3,13 @@
 
/** @file newgrf_station.cpp Functions for dealing with station classes and custom stations. */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "variables.h"
 
#include "functions.h"
 
#include "landscape.h"
 
#include "debug.h"
 
#include "sprite.h"
 
#include "table/sprites.h"
 
#include "table/strings.h"
 
#include "station.h"
 
#include "station_map.h"
 
@@ -367,13 +368,13 @@ static uint32 StationGetVariable(const R
 

	
 
	switch (variable) {
 
		/* Calculated station variables */
 
		case 0x40: return GetPlatformInfoHelper(tile, false, false, false);
 
		case 0x41: return GetPlatformInfoHelper(tile, true,  false, false);
 
		case 0x42: /* Terrain and rail type */
 
			return ((_opt.landscape == LT_HILLY && GetTileZ(tile) > _opt.snow_line) ? 4 : 0) |
 
			return ((_opt.landscape == LT_HILLY && GetTileZ(tile) > GetSnowLine()) ? 4 : 0) |
 
			       (_opt.landscape == LT_DESERT ? GetTropicZone(tile) : 0) |
 
			       (GetRailType(tile) << 8);
 
		case 0x43: return st->owner; /* Station owner */
 
		case 0x44: return 2;         /* PBS status */
 
		case 0x45: return GetRailContinuationInfo(tile);
 
		case 0x46: return GetPlatformInfoHelper(tile, false, false, true);
src/rail_cmd.cpp
Show inline comments
 
@@ -9,12 +9,13 @@
 
#include "functions.h"
 
#include "rail_map.h"
 
#include "road_map.h"
 
#include "table/sprites.h"
 
#include "table/strings.h"
 
#include "map.h"
 
#include "landscape.h"
 
#include "tile.h"
 
#include "town_map.h"
 
#include "tunnel_map.h"
 
#include "vehicle.h"
 
#include "viewport.h"
 
#include "command.h"
 
@@ -1735,13 +1736,13 @@ static void TileLoop_Track(TileIndex til
 
{
 
	RailGroundType old_ground = GetRailGroundType(tile);
 
	RailGroundType new_ground;
 

	
 
	switch (_opt.landscape) {
 
		case LT_HILLY:
 
			if (GetTileZ(tile) > _opt.snow_line) {
 
			if (GetTileZ(tile) > GetSnowLine()) {
 
				new_ground = RAIL_GROUND_ICE_DESERT;
 
				goto set_ground;
 
			}
 
			break;
 

	
 
		case LT_DESERT:
src/road_cmd.cpp
Show inline comments
 
@@ -9,12 +9,13 @@
 
#include "road_map.h"
 
#include "sprite.h"
 
#include "table/sprites.h"
 
#include "table/strings.h"
 
#include "functions.h"
 
#include "map.h"
 
#include "landscape.h"
 
#include "tile.h"
 
#include "town_map.h"
 
#include "vehicle.h"
 
#include "viewport.h"
 
#include "command.h"
 
#include "player.h"
 
@@ -861,13 +862,13 @@ static const Roadside _town_road_types_2
 

	
 

	
 
static void TileLoop_Road(TileIndex tile)
 
{
 
	switch (_opt.landscape) {
 
		case LT_HILLY:
 
			if (IsOnSnow(tile) != (GetTileZ(tile) > _opt.snow_line)) {
 
			if (IsOnSnow(tile) != (GetTileZ(tile) > GetSnowLine())) {
 
				ToggleSnow(tile);
 
				MarkTileDirtyByTile(tile);
 
			}
 
			break;
 

	
 
		case LT_DESERT:
src/town_cmd.cpp
Show inline comments
 
@@ -8,12 +8,13 @@
 
#include "debug.h"
 
#include "strings.h"
 
#include "road_map.h"
 
#include "table/strings.h"
 
#include "table/sprites.h"
 
#include "map.h"
 
#include "landscape.h"
 
#include "tile.h"
 
#include "town_map.h"
 
#include "tunnel_map.h"
 
#include "viewport.h"
 
#include "town.h"
 
#include "command.h"
 
@@ -1697,13 +1698,13 @@ static void UpdateTownGrowRate(Town *t)
 
			210, 150, 110, 80, 50
 
		};
 
		m = _grow_count_values[min(n, 5) - 1];
 
	}
 

	
 
	if (_opt.landscape == LT_HILLY) {
 
		if (TilePixelHeight(t->xy) >= _opt.snow_line && t->act_food == 0 && t->population > 90)
 
		if (TilePixelHeight(t->xy) >= GetSnowLine() && t->act_food == 0 && t->population > 90)
 
			return;
 
	} else if (_opt.landscape == LT_DESERT) {
 
		if (GetTropicZone(t->xy) == TROPICZONE_DESERT && (t->act_food==0 || t->act_water==0) && t->population > 60)
 
			return;
 
	}
 

	
src/tree_cmd.cpp
Show inline comments
 
@@ -6,12 +6,13 @@
 
#include "clear_map.h"
 
#include "table/strings.h"
 
#include "table/sprites.h"
 
#include "table/tree_land.h"
 
#include "functions.h"
 
#include "map.h"
 
#include "landscape.h"
 
#include "tile.h"
 
#include "tree_map.h"
 
#include "viewport.h"
 
#include "command.h"
 
#include "town.h"
 
#include "sound.h"
 
@@ -50,13 +51,13 @@ static void PlaceTree(TileIndex tile, ui
 
	TreeType tree = GetRandomTreeType(tile, GB(r, 24, 8));
 

	
 
	if (tree != TREE_INVALID) {
 
		MakeTree(tile, tree, GB(r, 22, 2), min(GB(r, 16, 3), 6), TREE_GROUND_GRASS, 0);
 

	
 
		// above snowline?
 
		if (_opt.landscape == LT_HILLY && GetTileZ(tile) > _opt.snow_line) {
 
		if (_opt.landscape == LT_HILLY && GetTileZ(tile) > GetSnowLine()) {
 
			SetTreeGroundDensity(tile, TREE_GROUND_SNOW_DESERT, 3);
 
			SetTreeCounter(tile, (TreeGround)GB(r, 24, 3));
 
		} else {
 
			SetTreeGroundDensity(tile, (TreeGround)GB(r, 28, 1), 0);
 
			SetTreeCounter(tile, (TreeGround)GB(r, 24, 4));
 
		}
 
@@ -147,13 +148,13 @@ void PlaceTreesRandomly()
 
			 *  It is almost real life ;) */
 
			ht = GetTileZ(tile);
 
			/* The higher we get, the more trees we plant */
 
			j = GetTileZ(tile) / TILE_HEIGHT * 2;
 
			while (j--) {
 
				/* Above snowline more trees! */
 
				if (_opt.landscape == LT_HILLY && ht > _opt.snow_line) {
 
				if (_opt.landscape == LT_HILLY && ht > GetSnowLine()) {
 
					PlaceTreeAtSameHeight(tile, ht);
 
					PlaceTreeAtSameHeight(tile, ht);
 
				};
 

	
 
				PlaceTreeAtSameHeight(tile, ht);
 
			}
 
@@ -493,13 +494,13 @@ static void TileLoopTreesDesert(TileInde
 
		default: break;
 
	}
 
}
 

	
 
static void TileLoopTreesAlps(TileIndex tile)
 
{
 
	int k = GetTileZ(tile) - _opt.snow_line + TILE_HEIGHT;
 
	int k = GetTileZ(tile) - GetSnowLine() + TILE_HEIGHT;
 

	
 
	if (k < 0) {
 
		if (GetTreeGround(tile) != TREE_GROUND_SNOW_DESERT) return;
 
		SetTreeGroundDensity(tile, TREE_GROUND_GRASS, 0);
 
	} else {
 
		uint density = min((uint)k / TILE_HEIGHT, 3);
src/tunnelbridge_cmd.cpp
Show inline comments
 
@@ -11,12 +11,13 @@
 
#include "rail_map.h"
 
#include "road_map.h"
 
#include "table/sprites.h"
 
#include "table/strings.h"
 
#include "functions.h"
 
#include "map.h"
 
#include "landscape.h"
 
#include "tile.h"
 
#include "tunnel_map.h"
 
#include "unmovable_map.h"
 
#include "vehicle.h"
 
#include "viewport.h"
 
#include "command.h"
 
@@ -1175,13 +1176,13 @@ static void AnimateTile_TunnelBridge(Til
 

	
 
static void TileLoop_TunnelBridge(TileIndex tile)
 
{
 
	bool snow_or_desert = IsTunnelTile(tile) ? HasTunnelSnowOrDesert(tile) : HasBridgeSnowOrDesert(tile);
 
	switch (_opt.landscape) {
 
		case LT_HILLY:
 
			if (snow_or_desert != (GetTileZ(tile) > _opt.snow_line)) {
 
			if (snow_or_desert != (GetTileZ(tile) > GetSnowLine())) {
 
				if (IsTunnelTile(tile)) {
 
					SetTunnelSnowOrDesert(tile, !snow_or_desert);
 
				} else {
 
					SetBridgeSnowOrDesert(tile, !snow_or_desert);
 
				}
 
				MarkTileDirtyByTile(tile);
0 comments (0 inline, 0 general)