summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-01-29 19:45:14 +0000
committertron <tron@openttd.org>2005-01-29 19:45:14 +0000
commit3a89108a55b6ee45550ed8b5e01434b51c2f6995 (patch)
tree911339d12234fdbe85e78c906881ba0d7989b09c
parent752b3f0dd614217d68f361e2d0b2cc599a37c860 (diff)
downloadopenttd-3a89108a55b6ee45550ed8b5e01434b51c2f6995.tar.xz
(svn r1722) -Feature: Bigger maps - anyone?
-rw-r--r--landscape.c20
-rw-r--r--lang/english.txt3
-rw-r--r--main_gui.c8
-rw-r--r--map.c53
-rw-r--r--map.h16
-rw-r--r--misc.c33
-rw-r--r--saveload.c9
-rw-r--r--settings.c3
-rw-r--r--settings_gui.c3
-rw-r--r--ttd.c12
-rw-r--r--variables.h3
11 files changed, 118 insertions, 45 deletions
diff --git a/landscape.c b/landscape.c
index 16694f137..1cbb39983 100644
--- a/landscape.c
+++ b/landscape.c
@@ -462,25 +462,27 @@ void RunTileLoop(void)
_cur_tileloop_tile = tile;
}
-void InitializeLandscape(void)
+void InitializeLandscape(uint log_x, uint log_y)
{
- uint map_size = MapSize();
+ uint map_size;
uint i;
- memset(_map_owner, OWNER_NONE, map_size);
- memset(_map2, 0, map_size * sizeof(uint16));
- memset(_map3_lo, 0, map_size);
- memset(_map3_hi, 0, map_size);
- memset(_map_extra_bits, 0, map_size / 4);
+ InitMap(log_x, log_y);
+ map_size = MapSize();
+
memset(_map_type_and_height, MP_CLEAR << 4, map_size);
+ memset(_map_owner, OWNER_NONE, map_size);
+ memset(_map2, 0, map_size * sizeof(_map2[0]));
+ memset(_map3_lo, 0, map_size);
+ memset(_map3_hi, 0, map_size);
+ memset(_map5, 3, map_size);
+ memset(_map_extra_bits, 0, map_size / 4);
// create void tiles at the border
for (i = 0; i < MapMaxY(); ++i)
SetTileType(i * MapSizeX() + MapMaxX(), MP_VOID);
for (i = 0; i < MapSizeX(); ++i)
SetTileType(MapSizeX() * MapMaxY() + i, MP_VOID);
-
- memset(_map5, 3, map_size);
}
void ConvertGroundTilesIntoWaterTiles(void)
diff --git a/lang/english.txt b/lang/english.txt
index 4071f47c7..305d28141 100644
--- a/lang/english.txt
+++ b/lang/english.txt
@@ -1397,6 +1397,9 @@ STR_NETWORK_SEND :{BLACK}Send
############ end network gui strings
+STR_CONFIG_PATCHES_MAP_X :{LTBLUE}X-size of map: {ORANGE}{STRING}
+STR_CONFIG_PATCHES_MAP_Y :{LTBLUE}Y-size of map: {ORANGE}{STRING}
+
##id 0x0800
STR_0800_COST :{TINYFONT}{RED}Cost: {CURRENCY}
STR_0801_COST :{RED}Cost: {CURRENCY}
diff --git a/main_gui.c b/main_gui.c
index ab1fc3844..6fac303a3 100644
--- a/main_gui.c
+++ b/main_gui.c
@@ -40,7 +40,7 @@ static int _rename_what;
static byte _terraform_size = 1;
static byte _last_built_railtype;
-extern void GenerateWorld(int mode);
+extern void GenerateWorld(int mode, uint log_x, uint log_y);
extern void GenerateIndustries(void);
extern void GenerateTowns(void);
@@ -1081,7 +1081,7 @@ static void ResetLandscape(void)
_random_seeds[0][0] = InteractiveRandom();
_random_seeds[0][1] = InteractiveRandom();
- GenerateWorld(1);
+ GenerateWorld(1, _patches.map_x, _patches.map_y);
MarkWholeScreenDirty();
}
@@ -2389,14 +2389,14 @@ void SetupColorsAndInitialWindow(void)
switch(_game_mode) {
case GM_MENU:
w = AllocateWindow(0, 0, width, height, MainWindowWndProc, 0, NULL);
- AssignWindowViewport(w, 0, 0, width, height, 0x8080, 0);
+ AssignWindowViewport(w, 0, 0, width, height, TILE_XY(32, 32), 0);
// w = AllocateWindowDesc(&_toolb_intro_desc);
// w->flags4 &= ~WF_WHITE_BORDER_MASK;
ShowSelectGameWindow();
break;
case GM_NORMAL:
w = AllocateWindow(0, 0, width, height, MainWindowWndProc, 0, NULL);
- AssignWindowViewport(w, 0, 0, width, height, 0x8080, 0);
+ AssignWindowViewport(w, 0, 0, width, height, TILE_XY(32, 32), 0);
ShowVitalWindows();
diff --git a/map.c b/map.c
index 6e9721b3b..b04d8d4a9 100644
--- a/map.c
+++ b/map.c
@@ -1,22 +1,51 @@
#include "stdafx.h"
#include "ttd.h"
+#include "functions.h"
#include "map.h"
-#define TILE_X_BITS 8
-#define TILE_Y_BITS 8
+uint _map_log_x;
+uint _map_log_y;
-uint _map_log_x = TILE_X_BITS;
-uint _map_log_y = TILE_Y_BITS;
+byte *_map_type_and_height = NULL;
+byte *_map_owner = NULL;
+uint16 *_map2 = NULL;
+byte *_map3_lo = NULL;
+byte *_map3_hi = NULL;
+byte *_map5 = NULL;
+byte *_map_extra_bits = NULL;
-#define MAP_SIZE ((1 << TILE_X_BITS) * (1 << TILE_Y_BITS))
-byte _map_type_and_height [MAP_SIZE];
-byte _map5 [MAP_SIZE];
-byte _map3_lo [MAP_SIZE];
-byte _map3_hi [MAP_SIZE];
-byte _map_owner [MAP_SIZE];
-uint16 _map2 [MAP_SIZE];
-byte _map_extra_bits [MAP_SIZE / 4];
+void InitMap(uint log_x, uint log_y)
+{
+ uint map_size;
+
+ assert(log_x <= 15 && log_y <= 15);
+
+ _map_log_x = log_x;
+ _map_log_y = log_y;
+
+ map_size = MapSize();
+
+ _map_type_and_height =
+ realloc(_map_type_and_height, map_size * sizeof(_map_type_and_height[0]));
+ _map_owner = realloc(_map_owner, map_size * sizeof(_map_owner[0]));
+ _map2 = realloc(_map2, map_size * sizeof(_map2[0]));
+ _map3_lo = realloc(_map3_lo, map_size * sizeof(_map3_lo[0]));
+ _map3_hi = realloc(_map3_hi, map_size * sizeof(_map3_hi[0]));
+ _map5 = realloc(_map5, map_size * sizeof(_map5[0]));
+ _map_extra_bits =
+ realloc(_map_extra_bits, map_size * sizeof(_map_extra_bits[0] / 4));
+
+ // XXX TODO handle memory shortage more gracefully
+ if (_map_type_and_height == NULL ||
+ _map_owner == NULL ||
+ _map2 == NULL ||
+ _map3_lo == NULL ||
+ _map3_hi == NULL ||
+ _map5 == NULL ||
+ _map_extra_bits == NULL)
+ error("Failed to allocate memory for the map");
+}
#ifdef _DEBUG
diff --git a/map.h b/map.h
index b504cb209..d5628fe45 100644
--- a/map.h
+++ b/map.h
@@ -8,13 +8,15 @@
#define TILE_MASK(x) ((x) & ((1 << (MapLogX() + MapLogY())) - 1))
-extern byte _map_type_and_height[];
-extern byte _map5[];
-extern byte _map3_lo[];
-extern byte _map3_hi[];
-extern byte _map_owner[];
-extern uint16 _map2[];
-extern byte _map_extra_bits[];
+extern byte *_map_type_and_height;
+extern byte *_map_owner;
+extern uint16 *_map2;
+extern byte *_map3_lo;
+extern byte *_map3_hi;
+extern byte *_map5;
+extern byte *_map_extra_bits;
+
+void InitMap(uint log_x, uint log_y);
// binary logarithm of the map size, try to avoid using this one
static inline uint MapLogX(void) { extern uint _map_log_x; return _map_log_x; }
diff --git a/misc.c b/misc.c
index 1ed230671..43415a208 100644
--- a/misc.c
+++ b/misc.c
@@ -165,7 +165,7 @@ void InitializeAirportGui(void);
void InitializeDock(void);
void InitializeDockGui(void);
void InitializeIndustries(void);
-void InitializeLandscape(void);
+void InitializeLandscape(uint log_x, uint log_y);
void InitializeTowns(void);
void InitializeTrees(void);
void InitializeSigns(void);
@@ -187,7 +187,7 @@ void GenerateTrees(void);
void ConvertGroundTilesIntoWaterTiles(void);
-void InitializeGame(void)
+void InitializeGame(uint log_x, uint log_y)
{
// Initialize the autoreplace array. Needs to be cleared between each game
uint i;
@@ -217,7 +217,7 @@ void InitializeGame(void)
InitializeOrders();
InitNewsItemStructs();
- InitializeLandscape();
+ InitializeLandscape(log_x, log_y);
InitializeClearLand();
InitializeRail();
InitializeRailGui();
@@ -248,7 +248,7 @@ void InitializeGame(void)
ResetObjectToPlace();
}
-void GenerateWorld(int mode)
+void GenerateWorld(int mode, uint log_x, uint log_y)
{
int i;
@@ -256,7 +256,7 @@ void GenerateWorld(int mode)
_current_player = OWNER_NONE;
_generating_world = true;
- InitializeGame();
+ InitializeGame(log_x, log_y);
SetObjectToPlace(1, 0, 0, 0);
// Must start economy early because of the costs.
@@ -860,6 +860,28 @@ static void SaveLoad_VIEW(void)
SlGlobList(_view_desc);
}
+static uint32 _map_dim_x;
+static uint32 _map_dim_y;
+
+static const SaveLoadGlobVarList _map_dimensions[] = {
+ {&_map_dim_x, SLE_UINT32, 6, 255},
+ {&_map_dim_y, SLE_UINT32, 6, 255},
+ {NULL, 0, 0, 0}
+};
+
+static void Save_MAPSIZE(void)
+{
+ _map_dim_x = MapLogX();
+ _map_dim_y = MapLogY();
+ SlGlobList(_map_dimensions);
+}
+
+static void Load_MAPSIZE(void)
+{
+ SlGlobList(_map_dimensions);
+ InitMap(_map_dim_x, _map_dim_y);
+}
+
static void SaveLoad_MAPT(void)
{
SlArray(_map_type_and_height, MapSize(), SLE_UINT8);
@@ -928,6 +950,7 @@ static void Load_CHTS(void)
const ChunkHandler _misc_chunk_handlers[] = {
+ { 'MAPS', Save_MAPSIZE, Load_MAPSIZE, CH_RIFF },
{ 'MAPT', SaveLoad_MAPT, SaveLoad_MAPT, CH_RIFF },
{ 'MAP2', SaveLoad_MAP2, SaveLoad_MAP2, CH_RIFF },
{ 'M3LO', SaveLoad_M3LO, SaveLoad_M3LO, CH_RIFF },
diff --git a/saveload.c b/saveload.c
index 580665c49..54931a2bb 100644
--- a/saveload.c
+++ b/saveload.c
@@ -1007,7 +1007,7 @@ static const SaveLoadFormat *GetSavegameFormat(const char *s)
}
// actual loader/saver function
-extern void InitializeGame(void);
+void InitializeGame(uint log_x, uint log_y);
extern bool AfterLoadGame(uint version);
extern void BeforeSaveGame(void);
extern bool LoadOldSaveGame(const char *file);
@@ -1021,7 +1021,7 @@ int SaveOrLoad(const char *filename, int mode)
// old style load
if (mode == SL_OLD_LOAD) {
- InitializeGame();
+ InitializeGame(8, 8);
if (!LoadOldSaveGame(filename)) return SL_REINIT;
AfterLoadGame(0);
return SL_OK;
@@ -1126,7 +1126,10 @@ init_err:
if (!fmt->init_read()) goto init_err;
// Clear everything
- InitializeGame();
+ /* Set the current map to 256x256, in case of an old map.
+ * Else MAPS will read the right information */
+ InitializeGame(8, 8);
+
SlLoadChunks();
fmt->uninit_read();
}
diff --git a/settings.c b/settings.c
index 31af159fc..3d0d8f87f 100644
--- a/settings.c
+++ b/settings.c
@@ -909,6 +909,9 @@ const SettingDesc patch_settings[] = {
{"ainew_active", SDT_BOOL, (void*)false, &_patches.ainew_active, NULL},
+ {"map_x", SDT_UINT32, (void*)8, &_patches.map_x, NULL},
+ {"map_y", SDT_UINT32, (void*)8, &_patches.map_y, NULL},
+
{NULL, 0, NULL, NULL, NULL}
};
diff --git a/settings_gui.c b/settings_gui.c
index 4091005c1..515141206 100644
--- a/settings_gui.c
+++ b/settings_gui.c
@@ -622,6 +622,9 @@ static const PatchEntry _patches_ui[] = {
{PE_UINT8, PF_0ISDIS | PF_PLAYERBASED, STR_CONFIG_PATCHES_SNAP_RADIUS, "window_snap_radius", &_patches.window_snap_radius, 1, 32, 1, NULL},
{PE_BOOL, PF_PLAYERBASED, STR_CONFIG_PATCHES_INVISIBLE_TREES, "invisible_trees", &_patches.invisible_trees, 0, 1, 1, &InvisibleTreesActive},
{PE_BOOL, PF_PLAYERBASED, STR_CONFIG_PATCHES_POPULATION_IN_LABEL, "population_in_label", &_patches.population_in_label, 0, 1, 1, &PopulationInLabelActive},
+
+ {PE_INT32, 0, STR_CONFIG_PATCHES_MAP_X, "map_x", &_patches.map_x, 6, 11, 1, NULL},
+ {PE_INT32, 0, STR_CONFIG_PATCHES_MAP_Y, "map_y", &_patches.map_y, 6, 11, 1, NULL},
};
static const PatchEntry _patches_construction[] = {
diff --git a/ttd.c b/ttd.c
index 68212250f..1abaab110 100644
--- a/ttd.c
+++ b/ttd.c
@@ -32,7 +32,7 @@
#include <stdarg.h>
void IncreaseSpriteLRU(void);
-void GenerateWorld(int mode);
+void GenerateWorld(int mode, uint log_x, uint log_y);
void CallLandscapeTick(void);
void IncreaseDate(void);
void RunOtherPlayersLoop(void);
@@ -534,6 +534,8 @@ static void LoadIntroGame(void)
GfxLoadSprites();
LoadStringWidthTable();
+ GenerateWorld(1, 6, 6); // Make the viewport initialization happy
+
// Setup main window
InitWindowSystem();
SetupColorsAndInitialWindow();
@@ -545,7 +547,7 @@ static void LoadIntroGame(void)
sprintf(filename, "%sopntitle.dat", _path.second_data_dir);
if (SaveOrLoad(filename, SL_LOAD) != SL_OK)
#endif
- GenerateWorld(1); // if failed loading, make empty world.
+ GenerateWorld(1, 6, 6); // if failed loading, make empty world.
}
_opt.currency = _new_opt.currency;
@@ -804,7 +806,7 @@ static void MakeNewGame(void)
SetupColorsAndInitialWindow();
// Randomize world
- GenerateWorld(0);
+ GenerateWorld(0, _patches.map_x, _patches.map_y);
// In a dedicated server, the server does not play
if (_network_dedicated) {
@@ -836,7 +838,7 @@ static void MakeNewEditorWorld(void)
SetupColorsAndInitialWindow();
// Startup the game system
- GenerateWorld(1);
+ GenerateWorld(1, _patches.map_x, _patches.map_y);
_local_player = OWNER_NONE;
MarkWholeScreenDirty();
@@ -1022,7 +1024,7 @@ normal_load:
break;
case SM_GENRANDLAND:
- GenerateWorld(2);
+ GenerateWorld(2, _patches.map_x, _patches.map_y);
// XXX: set date
_local_player = OWNER_NONE;
MarkWholeScreenDirty();
diff --git a/variables.h b/variables.h
index 4533d81db..71d70d7b3 100644
--- a/variables.h
+++ b/variables.h
@@ -180,6 +180,9 @@ typedef struct Patches {
byte wait_oneway_signal; //waitingtime in days before a oneway signal
byte wait_twoway_signal; //waitingtime in days before a twoway signal
+ uint map_x; // Size of map
+ uint map_y;
+
byte drag_signals_density; // many signals density
bool ainew_active; // Is the new AI active?