(svn r1722) -Feature: Bigger maps - anyone?

This commit is contained in:
tron 2005-01-29 19:45:14 +00:00
parent 752b3f0dd6
commit 3a89108a55
11 changed files with 118 additions and 45 deletions

View File

@ -462,25 +462,27 @@ void RunTileLoop(void)
_cur_tileloop_tile = tile; _cur_tileloop_tile = tile;
} }
void InitializeLandscape(void) void InitializeLandscape(uint log_x, uint log_y)
{ {
uint map_size = MapSize(); uint map_size;
uint i; uint i;
memset(_map_owner, OWNER_NONE, map_size); InitMap(log_x, log_y);
memset(_map2, 0, map_size * sizeof(uint16)); map_size = MapSize();
memset(_map3_lo, 0, map_size);
memset(_map3_hi, 0, map_size);
memset(_map_extra_bits, 0, map_size / 4);
memset(_map_type_and_height, MP_CLEAR << 4, map_size); 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 // create void tiles at the border
for (i = 0; i < MapMaxY(); ++i) for (i = 0; i < MapMaxY(); ++i)
SetTileType(i * MapSizeX() + MapMaxX(), MP_VOID); SetTileType(i * MapSizeX() + MapMaxX(), MP_VOID);
for (i = 0; i < MapSizeX(); ++i) for (i = 0; i < MapSizeX(); ++i)
SetTileType(MapSizeX() * MapMaxY() + i, MP_VOID); SetTileType(MapSizeX() * MapMaxY() + i, MP_VOID);
memset(_map5, 3, map_size);
} }
void ConvertGroundTilesIntoWaterTiles(void) void ConvertGroundTilesIntoWaterTiles(void)

View File

@ -1397,6 +1397,9 @@ STR_NETWORK_SEND :{BLACK}Send
############ end network gui strings ############ 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 ##id 0x0800
STR_0800_COST :{TINYFONT}{RED}Cost: {CURRENCY} STR_0800_COST :{TINYFONT}{RED}Cost: {CURRENCY}
STR_0801_COST :{RED}Cost: {CURRENCY} STR_0801_COST :{RED}Cost: {CURRENCY}

View File

@ -40,7 +40,7 @@ static int _rename_what;
static byte _terraform_size = 1; static byte _terraform_size = 1;
static byte _last_built_railtype; 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 GenerateIndustries(void);
extern void GenerateTowns(void); extern void GenerateTowns(void);
@ -1081,7 +1081,7 @@ static void ResetLandscape(void)
_random_seeds[0][0] = InteractiveRandom(); _random_seeds[0][0] = InteractiveRandom();
_random_seeds[0][1] = InteractiveRandom(); _random_seeds[0][1] = InteractiveRandom();
GenerateWorld(1); GenerateWorld(1, _patches.map_x, _patches.map_y);
MarkWholeScreenDirty(); MarkWholeScreenDirty();
} }
@ -2389,14 +2389,14 @@ void SetupColorsAndInitialWindow(void)
switch(_game_mode) { switch(_game_mode) {
case GM_MENU: case GM_MENU:
w = AllocateWindow(0, 0, width, height, MainWindowWndProc, 0, NULL); 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 = AllocateWindowDesc(&_toolb_intro_desc);
// w->flags4 &= ~WF_WHITE_BORDER_MASK; // w->flags4 &= ~WF_WHITE_BORDER_MASK;
ShowSelectGameWindow(); ShowSelectGameWindow();
break; break;
case GM_NORMAL: case GM_NORMAL:
w = AllocateWindow(0, 0, width, height, MainWindowWndProc, 0, NULL); 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(); ShowVitalWindows();

53
map.c
View File

@ -1,22 +1,51 @@
#include "stdafx.h" #include "stdafx.h"
#include "ttd.h" #include "ttd.h"
#include "functions.h"
#include "map.h" #include "map.h"
#define TILE_X_BITS 8 uint _map_log_x;
#define TILE_Y_BITS 8 uint _map_log_y;
uint _map_log_x = TILE_X_BITS; byte *_map_type_and_height = NULL;
uint _map_log_y = TILE_Y_BITS; 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]; void InitMap(uint log_x, uint log_y)
byte _map5 [MAP_SIZE]; {
byte _map3_lo [MAP_SIZE]; uint map_size;
byte _map3_hi [MAP_SIZE];
byte _map_owner [MAP_SIZE]; assert(log_x <= 15 && log_y <= 15);
uint16 _map2 [MAP_SIZE];
byte _map_extra_bits [MAP_SIZE / 4]; _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 #ifdef _DEBUG

16
map.h
View File

@ -8,13 +8,15 @@
#define TILE_MASK(x) ((x) & ((1 << (MapLogX() + MapLogY())) - 1)) #define TILE_MASK(x) ((x) & ((1 << (MapLogX() + MapLogY())) - 1))
extern byte _map_type_and_height[]; extern byte *_map_type_and_height;
extern byte _map5[]; extern byte *_map_owner;
extern byte _map3_lo[]; extern uint16 *_map2;
extern byte _map3_hi[]; extern byte *_map3_lo;
extern byte _map_owner[]; extern byte *_map3_hi;
extern uint16 _map2[]; extern byte *_map5;
extern byte _map_extra_bits[]; 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 // 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; } static inline uint MapLogX(void) { extern uint _map_log_x; return _map_log_x; }

33
misc.c
View File

@ -165,7 +165,7 @@ void InitializeAirportGui(void);
void InitializeDock(void); void InitializeDock(void);
void InitializeDockGui(void); void InitializeDockGui(void);
void InitializeIndustries(void); void InitializeIndustries(void);
void InitializeLandscape(void); void InitializeLandscape(uint log_x, uint log_y);
void InitializeTowns(void); void InitializeTowns(void);
void InitializeTrees(void); void InitializeTrees(void);
void InitializeSigns(void); void InitializeSigns(void);
@ -187,7 +187,7 @@ void GenerateTrees(void);
void ConvertGroundTilesIntoWaterTiles(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 // Initialize the autoreplace array. Needs to be cleared between each game
uint i; uint i;
@ -217,7 +217,7 @@ void InitializeGame(void)
InitializeOrders(); InitializeOrders();
InitNewsItemStructs(); InitNewsItemStructs();
InitializeLandscape(); InitializeLandscape(log_x, log_y);
InitializeClearLand(); InitializeClearLand();
InitializeRail(); InitializeRail();
InitializeRailGui(); InitializeRailGui();
@ -248,7 +248,7 @@ void InitializeGame(void)
ResetObjectToPlace(); ResetObjectToPlace();
} }
void GenerateWorld(int mode) void GenerateWorld(int mode, uint log_x, uint log_y)
{ {
int i; int i;
@ -256,7 +256,7 @@ void GenerateWorld(int mode)
_current_player = OWNER_NONE; _current_player = OWNER_NONE;
_generating_world = true; _generating_world = true;
InitializeGame(); InitializeGame(log_x, log_y);
SetObjectToPlace(1, 0, 0, 0); SetObjectToPlace(1, 0, 0, 0);
// Must start economy early because of the costs. // Must start economy early because of the costs.
@ -860,6 +860,28 @@ static void SaveLoad_VIEW(void)
SlGlobList(_view_desc); 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) static void SaveLoad_MAPT(void)
{ {
SlArray(_map_type_and_height, MapSize(), SLE_UINT8); SlArray(_map_type_and_height, MapSize(), SLE_UINT8);
@ -928,6 +950,7 @@ static void Load_CHTS(void)
const ChunkHandler _misc_chunk_handlers[] = { const ChunkHandler _misc_chunk_handlers[] = {
{ 'MAPS', Save_MAPSIZE, Load_MAPSIZE, CH_RIFF },
{ 'MAPT', SaveLoad_MAPT, SaveLoad_MAPT, CH_RIFF }, { 'MAPT', SaveLoad_MAPT, SaveLoad_MAPT, CH_RIFF },
{ 'MAP2', SaveLoad_MAP2, SaveLoad_MAP2, CH_RIFF }, { 'MAP2', SaveLoad_MAP2, SaveLoad_MAP2, CH_RIFF },
{ 'M3LO', SaveLoad_M3LO, SaveLoad_M3LO, CH_RIFF }, { 'M3LO', SaveLoad_M3LO, SaveLoad_M3LO, CH_RIFF },

View File

@ -1007,7 +1007,7 @@ static const SaveLoadFormat *GetSavegameFormat(const char *s)
} }
// actual loader/saver function // actual loader/saver function
extern void InitializeGame(void); void InitializeGame(uint log_x, uint log_y);
extern bool AfterLoadGame(uint version); extern bool AfterLoadGame(uint version);
extern void BeforeSaveGame(void); extern void BeforeSaveGame(void);
extern bool LoadOldSaveGame(const char *file); extern bool LoadOldSaveGame(const char *file);
@ -1021,7 +1021,7 @@ int SaveOrLoad(const char *filename, int mode)
// old style load // old style load
if (mode == SL_OLD_LOAD) { if (mode == SL_OLD_LOAD) {
InitializeGame(); InitializeGame(8, 8);
if (!LoadOldSaveGame(filename)) return SL_REINIT; if (!LoadOldSaveGame(filename)) return SL_REINIT;
AfterLoadGame(0); AfterLoadGame(0);
return SL_OK; return SL_OK;
@ -1126,7 +1126,10 @@ init_err:
if (!fmt->init_read()) goto init_err; if (!fmt->init_read()) goto init_err;
// Clear everything // 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(); SlLoadChunks();
fmt->uninit_read(); fmt->uninit_read();
} }

View File

@ -909,6 +909,9 @@ const SettingDesc patch_settings[] = {
{"ainew_active", SDT_BOOL, (void*)false, &_patches.ainew_active, NULL}, {"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} {NULL, 0, NULL, NULL, NULL}
}; };

View File

@ -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_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_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_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[] = { static const PatchEntry _patches_construction[] = {

12
ttd.c
View File

@ -32,7 +32,7 @@
#include <stdarg.h> #include <stdarg.h>
void IncreaseSpriteLRU(void); void IncreaseSpriteLRU(void);
void GenerateWorld(int mode); void GenerateWorld(int mode, uint log_x, uint log_y);
void CallLandscapeTick(void); void CallLandscapeTick(void);
void IncreaseDate(void); void IncreaseDate(void);
void RunOtherPlayersLoop(void); void RunOtherPlayersLoop(void);
@ -534,6 +534,8 @@ static void LoadIntroGame(void)
GfxLoadSprites(); GfxLoadSprites();
LoadStringWidthTable(); LoadStringWidthTable();
GenerateWorld(1, 6, 6); // Make the viewport initialization happy
// Setup main window // Setup main window
InitWindowSystem(); InitWindowSystem();
SetupColorsAndInitialWindow(); SetupColorsAndInitialWindow();
@ -545,7 +547,7 @@ static void LoadIntroGame(void)
sprintf(filename, "%sopntitle.dat", _path.second_data_dir); sprintf(filename, "%sopntitle.dat", _path.second_data_dir);
if (SaveOrLoad(filename, SL_LOAD) != SL_OK) if (SaveOrLoad(filename, SL_LOAD) != SL_OK)
#endif #endif
GenerateWorld(1); // if failed loading, make empty world. GenerateWorld(1, 6, 6); // if failed loading, make empty world.
} }
_opt.currency = _new_opt.currency; _opt.currency = _new_opt.currency;
@ -804,7 +806,7 @@ static void MakeNewGame(void)
SetupColorsAndInitialWindow(); SetupColorsAndInitialWindow();
// Randomize world // Randomize world
GenerateWorld(0); GenerateWorld(0, _patches.map_x, _patches.map_y);
// In a dedicated server, the server does not play // In a dedicated server, the server does not play
if (_network_dedicated) { if (_network_dedicated) {
@ -836,7 +838,7 @@ static void MakeNewEditorWorld(void)
SetupColorsAndInitialWindow(); SetupColorsAndInitialWindow();
// Startup the game system // Startup the game system
GenerateWorld(1); GenerateWorld(1, _patches.map_x, _patches.map_y);
_local_player = OWNER_NONE; _local_player = OWNER_NONE;
MarkWholeScreenDirty(); MarkWholeScreenDirty();
@ -1022,7 +1024,7 @@ normal_load:
break; break;
case SM_GENRANDLAND: case SM_GENRANDLAND:
GenerateWorld(2); GenerateWorld(2, _patches.map_x, _patches.map_y);
// XXX: set date // XXX: set date
_local_player = OWNER_NONE; _local_player = OWNER_NONE;
MarkWholeScreenDirty(); MarkWholeScreenDirty();

View File

@ -180,6 +180,9 @@ typedef struct Patches {
byte wait_oneway_signal; //waitingtime in days before a oneway signal byte wait_oneway_signal; //waitingtime in days before a oneway signal
byte wait_twoway_signal; //waitingtime in days before a twoway 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 byte drag_signals_density; // many signals density
bool ainew_active; // Is the new AI active? bool ainew_active; // Is the new AI active?