2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file openttd.cpp Functions related to starting OpenTTD. */
|
2007-03-21 15:19:33 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2008-03-31 07:03:35 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
#define VARDEF
|
2008-03-31 07:03:35 +00:00
|
|
|
#include "variables.h"
|
|
|
|
#undef VARDEF
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2008-03-31 07:03:35 +00:00
|
|
|
|
|
|
|
#include "driver.h"
|
|
|
|
#include "blitter/factory.hpp"
|
|
|
|
#include "sound/sound_driver.hpp"
|
|
|
|
#include "music/music_driver.hpp"
|
|
|
|
#include "video/video_driver.hpp"
|
|
|
|
|
|
|
|
#include "fontcache.h"
|
2005-08-14 18:10:18 +00:00
|
|
|
#include "gfxinit.h"
|
2008-03-31 07:03:35 +00:00
|
|
|
#include "gfx_func.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "gui.h"
|
2008-03-31 07:03:35 +00:00
|
|
|
#include "mixer.h"
|
|
|
|
#include "sound_func.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_func.h"
|
2008-03-31 07:03:35 +00:00
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
#include "saveload.h"
|
|
|
|
#include "landscape.h"
|
2008-01-12 14:10:35 +00:00
|
|
|
#include "player_func.h"
|
|
|
|
#include "player_base.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "town.h"
|
|
|
|
#include "industry.h"
|
2008-03-28 08:53:36 +00:00
|
|
|
#include "news_func.h"
|
2008-08-31 10:50:05 +00:00
|
|
|
#include "fileio_func.h"
|
2007-12-28 03:14:55 +00:00
|
|
|
#include "fios.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "airport.h"
|
2007-03-02 12:01:24 +00:00
|
|
|
#include "aircraft.h"
|
2008-05-24 10:15:06 +00:00
|
|
|
#include "console_func.h"
|
2004-11-15 19:25:59 +00:00
|
|
|
#include "screenshot.h"
|
2007-01-02 17:34:03 +00:00
|
|
|
#include "network/network.h"
|
2008-05-30 18:20:26 +00:00
|
|
|
#include "network/network_func.h"
|
2008-03-31 07:25:49 +00:00
|
|
|
#include "signs_base.h"
|
|
|
|
#include "signs_func.h"
|
2005-03-24 17:03:37 +00:00
|
|
|
#include "waypoint.h"
|
2005-09-07 15:10:11 +00:00
|
|
|
#include "ai/ai.h"
|
2006-01-18 15:05:01 +00:00
|
|
|
#include "train.h"
|
2006-05-27 16:12:16 +00:00
|
|
|
#include "yapf/yapf.h"
|
2008-01-07 00:19:09 +00:00
|
|
|
#include "settings_func.h"
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
#include "genworld.h"
|
2007-03-02 01:17:11 +00:00
|
|
|
#include "player_face.h"
|
2007-05-19 09:40:18 +00:00
|
|
|
#include "group.h"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_func.h"
|
2007-12-27 13:35:39 +00:00
|
|
|
#include "vehicle_func.h"
|
2008-06-03 18:35:58 +00:00
|
|
|
#include "gamelog.h"
|
2008-04-17 21:21:01 +00:00
|
|
|
#include "cheat_func.h"
|
2008-04-20 08:22:59 +00:00
|
|
|
#include "animated_tile_func.h"
|
2008-04-20 08:43:31 +00:00
|
|
|
#include "functions.h"
|
2008-05-08 16:48:29 +00:00
|
|
|
#include "elrail_func.h"
|
2008-05-04 21:53:36 +00:00
|
|
|
#include "rev.h"
|
2008-03-31 07:03:35 +00:00
|
|
|
|
|
|
|
#include "newgrf.h"
|
|
|
|
#include "newgrf_config.h"
|
|
|
|
#include "newgrf_house.h"
|
|
|
|
#include "newgrf_commons.h"
|
2008-03-31 06:42:26 +00:00
|
|
|
#include "newgrf_station.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
#include "clear_map.h"
|
2008-03-31 06:42:26 +00:00
|
|
|
#include "tree_map.h"
|
2006-12-27 12:38:02 +00:00
|
|
|
#include "rail_map.h"
|
|
|
|
#include "road_map.h"
|
2008-03-31 06:42:26 +00:00
|
|
|
#include "station_map.h"
|
|
|
|
#include "town_map.h"
|
2006-12-30 11:57:52 +00:00
|
|
|
#include "industry_map.h"
|
2007-03-08 14:34:32 +00:00
|
|
|
#include "unmovable_map.h"
|
2008-03-31 06:42:26 +00:00
|
|
|
#include "tunnel_map.h"
|
|
|
|
#include "bridge_map.h"
|
|
|
|
#include "water_map.h"
|
2007-12-16 15:38:51 +00:00
|
|
|
#include "tunnelbridge_map.h"
|
2007-12-19 23:26:02 +00:00
|
|
|
#include "void_map.h"
|
2008-02-02 09:28:43 +00:00
|
|
|
#include "water.h"
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2008-04-18 10:16:51 +00:00
|
|
|
StringID _switch_mode_errorstr;
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void CallLandscapeTick();
|
|
|
|
void IncreaseDate();
|
|
|
|
void DoPaletteAnimations();
|
|
|
|
void MusicLoop();
|
|
|
|
void ResetMusic();
|
2008-04-19 08:21:55 +00:00
|
|
|
void ResetOldNames();
|
2008-04-19 10:18:38 +00:00
|
|
|
void ProcessAsyncSaveFinish();
|
2008-05-09 09:29:27 +00:00
|
|
|
void CallWindowTickEvent();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-25 22:36:44 +00:00
|
|
|
extern void SetDifficultyLevel(int mode, DifficultySettings *gm_opt);
|
2008-09-30 20:39:50 +00:00
|
|
|
extern Company *DoStartupNewCompany(bool is_ai);
|
2008-06-05 20:54:52 +00:00
|
|
|
extern void ShowOSErrorBox(const char *buf, bool system);
|
2008-04-03 21:54:31 +00:00
|
|
|
extern void InitializeRailGUI();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-29 18:19:29 +00:00
|
|
|
/**
|
2008-06-05 20:54:52 +00:00
|
|
|
* Error handling for fatal user errors.
|
|
|
|
* @param s the string to print.
|
|
|
|
* @note Does NEVER return.
|
|
|
|
*/
|
|
|
|
void CDECL usererror(const char *s, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
char buf[512];
|
|
|
|
|
|
|
|
va_start(va, s);
|
|
|
|
vsnprintf(buf, lengthof(buf), s, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
ShowOSErrorBox(buf, false);
|
|
|
|
if (_video_driver != NULL) _video_driver->Stop();
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Error handling for fatal non-user errors.
|
2008-04-29 18:19:29 +00:00
|
|
|
* @param s the string to print.
|
|
|
|
* @note Does NEVER return.
|
|
|
|
*/
|
2006-07-26 03:33:12 +00:00
|
|
|
void CDECL error(const char *s, ...)
|
2005-11-14 19:48:04 +00:00
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
va_list va;
|
|
|
|
char buf[512];
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
va_start(va, s);
|
2006-11-28 20:55:16 +00:00
|
|
|
vsnprintf(buf, lengthof(buf), s, va);
|
2004-08-09 17:04:08 +00:00
|
|
|
va_end(va);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2008-06-05 20:54:52 +00:00
|
|
|
ShowOSErrorBox(buf, true);
|
2007-07-05 12:23:54 +00:00
|
|
|
if (_video_driver != NULL) _video_driver->Stop();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
assert(0);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2008-04-29 18:19:29 +00:00
|
|
|
/**
|
|
|
|
* Shows some information on the console/a popup box depending on the OS.
|
|
|
|
* @param str the text to show.
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
void CDECL ShowInfoF(const char *str, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
char buf[1024];
|
|
|
|
va_start(va, str);
|
2006-11-28 20:55:16 +00:00
|
|
|
vsnprintf(buf, lengthof(buf), str, va);
|
2004-08-09 17:04:08 +00:00
|
|
|
va_end(va);
|
|
|
|
ShowInfo(buf);
|
|
|
|
}
|
|
|
|
|
2008-04-29 18:19:29 +00:00
|
|
|
/**
|
|
|
|
* Show the help message when someone passed a wrong parameter.
|
|
|
|
*/
|
|
|
|
static void ShowHelp()
|
|
|
|
{
|
|
|
|
char buf[4096];
|
|
|
|
char *p = buf;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-11-28 20:55:16 +00:00
|
|
|
p += snprintf(p, lengthof(buf), "OpenTTD %s\n", _openttd_revision);
|
|
|
|
p = strecpy(p,
|
2006-01-06 22:52:31 +00:00
|
|
|
"\n"
|
|
|
|
"\n"
|
2004-08-09 17:04:08 +00:00
|
|
|
"Command line options:\n"
|
2004-12-04 17:54:56 +00:00
|
|
|
" -v drv = Set video driver (see below)\n"
|
2007-01-31 20:20:36 +00:00
|
|
|
" -s drv = Set sound driver (see below) (param bufsize,hz)\n"
|
2004-12-04 17:54:56 +00:00
|
|
|
" -m drv = Set music driver (see below)\n"
|
2007-06-11 11:50:49 +00:00
|
|
|
" -b drv = Set the blitter to use (see below)\n"
|
2004-12-04 17:54:56 +00:00
|
|
|
" -r res = Set resolution (for instance 800x600)\n"
|
|
|
|
" -h = Display this help text\n"
|
2006-08-15 14:52:17 +00:00
|
|
|
" -t year = Set starting year\n"
|
2005-03-06 16:08:19 +00:00
|
|
|
" -d [[fac=]lvl[,...]]= Debug mode\n"
|
2004-12-04 17:54:56 +00:00
|
|
|
" -e = Start Editor\n"
|
|
|
|
" -g [savegame] = Start new/save game immediately\n"
|
|
|
|
" -G seed = Set random seed\n"
|
2007-01-16 15:20:22 +00:00
|
|
|
#if defined(ENABLE_NETWORK)
|
2008-09-30 20:39:50 +00:00
|
|
|
" -n [ip:port#company]= Start networkgame\n"
|
2007-01-03 18:29:15 +00:00
|
|
|
" -D [ip][:port] = Start dedicated server\n"
|
2007-02-08 12:27:53 +00:00
|
|
|
" -l ip[:port] = Redirect DEBUG()\n"
|
2006-06-27 21:25:53 +00:00
|
|
|
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
|
2004-12-18 14:19:21 +00:00
|
|
|
" -f = Fork into the background (dedicated only)\n"
|
2006-06-27 21:25:53 +00:00
|
|
|
#endif
|
2007-01-16 15:20:22 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2008-08-23 20:16:54 +00:00
|
|
|
" -i = Force to use the DOS (0) or Windows (1) palette\n"
|
2006-01-06 22:52:31 +00:00
|
|
|
" (use this if you see a lot of pink)\n"
|
2008-08-24 08:41:38 +00:00
|
|
|
" -I graphics_set = Force the graphics set (see below)\n"
|
2006-01-06 22:52:31 +00:00
|
|
|
" -c config_file = Use 'config_file' instead of 'openttd.cfg'\n"
|
2008-08-24 08:41:38 +00:00
|
|
|
" -x = Do not automatically save to config file on exit\n"
|
|
|
|
"\n",
|
2006-11-28 20:55:16 +00:00
|
|
|
lastof(buf)
|
2004-08-09 17:04:08 +00:00
|
|
|
);
|
|
|
|
|
2008-08-24 08:41:38 +00:00
|
|
|
/* List the graphics packs */
|
|
|
|
p = GetGraphicsSetsList(p, lastof(buf));
|
|
|
|
|
2007-07-05 12:23:54 +00:00
|
|
|
/* List the drivers */
|
|
|
|
p = VideoDriverFactoryBase::GetDriversInfo(p, lastof(buf));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-11 11:50:49 +00:00
|
|
|
/* List the blitters */
|
|
|
|
p = BlitterFactoryBase::GetBlittersInfo(p, lastof(buf));
|
|
|
|
|
2007-01-18 14:08:56 +00:00
|
|
|
/* ShowInfo put output to stderr, but version information should go
|
|
|
|
* to stdout; this is the only exception */
|
|
|
|
#if !defined(WIN32) && !defined(WIN64)
|
|
|
|
printf("%s\n", buf);
|
|
|
|
#else
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowInfo(buf);
|
2007-01-18 14:08:56 +00:00
|
|
|
#endif
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
struct MyGetOptData {
|
2004-08-09 17:04:08 +00:00
|
|
|
char *opt;
|
|
|
|
int numleft;
|
|
|
|
char **argv;
|
|
|
|
const char *options;
|
2007-01-10 18:56:51 +00:00
|
|
|
const char *cont;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
MyGetOptData(int argc, char **argv, const char *options)
|
|
|
|
{
|
|
|
|
opt = NULL;
|
|
|
|
numleft = argc;
|
|
|
|
this->argv = argv;
|
|
|
|
this->options = options;
|
|
|
|
cont = NULL;
|
|
|
|
}
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static int MyGetOpt(MyGetOptData *md)
|
|
|
|
{
|
2007-01-10 18:56:51 +00:00
|
|
|
const char *s,*r,*t;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
s = md->cont;
|
|
|
|
if (s != NULL)
|
2004-08-09 17:04:08 +00:00
|
|
|
goto md_continue_here;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
for (;;) {
|
|
|
|
if (--md->numleft < 0) return -1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
s = *md->argv++;
|
|
|
|
if (*s == '-') {
|
|
|
|
md_continue_here:;
|
|
|
|
s++;
|
|
|
|
if (*s != 0) {
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Found argument, try to locate it in options. */
|
2004-08-09 17:04:08 +00:00
|
|
|
if (*s == ':' || (r = strchr(md->options, *s)) == NULL) {
|
2007-03-21 15:19:33 +00:00
|
|
|
/* ERROR! */
|
2004-08-09 17:04:08 +00:00
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
if (r[1] == ':') {
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Item wants an argument. Check if the argument follows, or if it comes as a separate arg. */
|
2004-08-09 17:04:08 +00:00
|
|
|
if (!*(t = s + 1)) {
|
2007-03-21 15:19:33 +00:00
|
|
|
/* It comes as a separate arg. Check if out of args? */
|
2004-08-09 17:04:08 +00:00
|
|
|
if (--md->numleft < 0 || *(t = *md->argv) == '-') {
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Check if item is optional? */
|
2004-08-09 17:04:08 +00:00
|
|
|
if (r[2] != ':')
|
|
|
|
return -2;
|
|
|
|
md->numleft++;
|
|
|
|
t = NULL;
|
|
|
|
} else {
|
|
|
|
md->argv++;
|
|
|
|
}
|
|
|
|
}
|
2007-01-10 18:56:51 +00:00
|
|
|
md->opt = (char*)t;
|
2004-08-09 17:04:08 +00:00
|
|
|
md->cont = NULL;
|
|
|
|
return *s;
|
|
|
|
}
|
|
|
|
md->opt = NULL;
|
|
|
|
md->cont = s;
|
|
|
|
return *s;
|
|
|
|
}
|
|
|
|
} else {
|
2007-03-21 15:19:33 +00:00
|
|
|
/* This is currently not supported. */
|
2004-08-09 17:04:08 +00:00
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-29 18:19:29 +00:00
|
|
|
/**
|
|
|
|
* Extract the resolution from the given string and store
|
|
|
|
* it in the 'res' parameter.
|
|
|
|
* @param res variable to store the resolution in.
|
|
|
|
* @param s the string to decompose.
|
|
|
|
*/
|
2008-06-16 19:38:41 +00:00
|
|
|
static void ParseResolution(Dimension *res, const char *s)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-01-10 18:56:51 +00:00
|
|
|
const char *t = strchr(s, 'x');
|
2004-08-09 17:04:08 +00:00
|
|
|
if (t == NULL) {
|
|
|
|
ShowInfoF("Invalid resolution '%s'", s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-16 19:38:41 +00:00
|
|
|
res->width = max(strtoul(s, NULL, 0), 64UL);
|
|
|
|
res->height = max(strtoul(t + 1, NULL, 0), 64UL);
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void InitializeDynamicVariables()
|
2005-01-06 22:31:58 +00:00
|
|
|
{
|
|
|
|
/* Dynamic stuff needs to be initialized somewhere... */
|
2007-07-04 01:34:28 +00:00
|
|
|
_industry_mngr.ResetMapping();
|
|
|
|
_industile_mngr.ResetMapping();
|
2008-09-30 20:39:50 +00:00
|
|
|
_Company_pool.AddBlockToPool();
|
2005-01-06 22:31:58 +00:00
|
|
|
}
|
|
|
|
|
2007-01-14 17:17:30 +00:00
|
|
|
|
2008-05-08 23:26:17 +00:00
|
|
|
/** Unitializes drivers, frees allocated memory, cleans pools, ...
|
|
|
|
* Generally, prepares the game for shutting down
|
|
|
|
*/
|
|
|
|
static void ShutdownGame()
|
2005-01-06 22:31:58 +00:00
|
|
|
{
|
2008-05-08 23:26:17 +00:00
|
|
|
/* stop the AI */
|
|
|
|
AI_Uninitialize();
|
|
|
|
|
|
|
|
IConsoleFree();
|
|
|
|
|
|
|
|
if (_network_available) NetworkShutDown(); // Shut down the network and close any open connections
|
|
|
|
|
|
|
|
DriverFactoryBase::ShutdownDrivers();
|
|
|
|
|
2007-01-14 17:17:30 +00:00
|
|
|
UnInitWindowSystem();
|
|
|
|
|
|
|
|
/* Uninitialize airport state machines */
|
|
|
|
UnInitializeAirports();
|
|
|
|
|
|
|
|
/* Uninitialize variables that are allocated dynamically */
|
2008-06-03 18:35:58 +00:00
|
|
|
GamelogReset();
|
2007-08-03 20:18:38 +00:00
|
|
|
_Town_pool.CleanPool();
|
|
|
|
_Industry_pool.CleanPool();
|
|
|
|
_Station_pool.CleanPool();
|
|
|
|
_Vehicle_pool.CleanPool();
|
|
|
|
_Sign_pool.CleanPool();
|
|
|
|
_Order_pool.CleanPool();
|
|
|
|
_Group_pool.CleanPool();
|
|
|
|
_CargoPacket_pool.CleanPool();
|
2008-04-29 21:31:29 +00:00
|
|
|
_Engine_pool.CleanPool();
|
2008-09-30 20:39:50 +00:00
|
|
|
_Company_pool.CleanPool();
|
2005-02-01 18:32:01 +00:00
|
|
|
|
2005-03-10 21:44:17 +00:00
|
|
|
free(_config_file);
|
2008-05-08 23:26:17 +00:00
|
|
|
|
|
|
|
/* Close all and any open filehandles */
|
|
|
|
FioCloseAll();
|
2005-03-09 19:48:20 +00:00
|
|
|
}
|
2005-01-06 22:31:58 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void LoadIntroGame()
|
2004-12-04 17:54:56 +00:00
|
|
|
{
|
|
|
|
_game_mode = GM_MENU;
|
2007-04-05 07:49:04 +00:00
|
|
|
|
2006-12-04 08:30:04 +00:00
|
|
|
ResetGRFConfig(false);
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Setup main window */
|
2005-03-09 19:48:20 +00:00
|
|
|
ResetWindowSystem();
|
2004-12-04 17:54:56 +00:00
|
|
|
SetupColorsAndInitialWindow();
|
|
|
|
|
2007-06-17 15:48:57 +00:00
|
|
|
/* Load the default opening screen savegame */
|
|
|
|
if (SaveOrLoad("opntitle.dat", SL_LOAD, DATA_DIR) != SL_OK) {
|
2006-02-18 14:41:24 +00:00
|
|
|
GenerateWorld(GW_EMPTY, 64, 64); // if failed loading, make empty world.
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
WaitTillGeneratedWorld();
|
2008-09-30 20:39:50 +00:00
|
|
|
SetLocalCompany(COMPANY_SPECTATOR);
|
2008-09-15 23:50:12 +00:00
|
|
|
} else {
|
2008-09-30 20:39:50 +00:00
|
|
|
SetLocalCompany(COMPANY_FIRST);
|
2005-01-07 08:07:24 +00:00
|
|
|
}
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2007-03-06 20:59:52 +00:00
|
|
|
_pause_game = 0;
|
2006-08-21 14:59:23 +00:00
|
|
|
_cursor.fix_at = false;
|
2004-12-04 17:54:56 +00:00
|
|
|
MarkWholeScreenDirty();
|
|
|
|
|
2007-12-16 18:38:19 +00:00
|
|
|
CheckForMissingGlyphsInLoadedLanguagePack();
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Play main theme */
|
2007-07-05 12:23:54 +00:00
|
|
|
if (_music_driver->IsSongPlaying()) ResetMusic();
|
2004-12-04 17:54:56 +00:00
|
|
|
}
|
|
|
|
|
2008-01-13 13:36:01 +00:00
|
|
|
byte _savegame_sort_order;
|
2005-08-06 14:58:06 +00:00
|
|
|
#if defined(UNIX) && !defined(__MORPHOS__)
|
2007-03-07 11:47:46 +00:00
|
|
|
extern void DedicatedFork();
|
2005-08-06 14:58:06 +00:00
|
|
|
#endif
|
2004-12-18 14:19:21 +00:00
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
int ttd_main(int argc, char *argv[])
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int i;
|
2005-01-14 19:44:42 +00:00
|
|
|
const char *optformat;
|
2008-08-24 08:41:38 +00:00
|
|
|
char musicdriver[32], sounddriver[32], videodriver[32], blitter[32], graphics_set[32];
|
2008-06-16 19:38:41 +00:00
|
|
|
Dimension resolution = {0, 0};
|
2006-08-16 11:39:55 +00:00
|
|
|
Year startyear = INVALID_YEAR;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
uint generation_seed = GENERATE_NEW_SEED;
|
2007-01-16 15:20:22 +00:00
|
|
|
bool save_config = true;
|
|
|
|
#if defined(ENABLE_NETWORK)
|
2006-02-21 17:29:53 +00:00
|
|
|
bool dedicated = false;
|
|
|
|
bool network = false;
|
|
|
|
char *network_conn = NULL;
|
2007-02-08 12:27:53 +00:00
|
|
|
char *debuglog_conn = NULL;
|
2007-01-03 18:29:15 +00:00
|
|
|
char *dedicated_host = NULL;
|
|
|
|
uint16 dedicated_port = 0;
|
2007-01-16 15:20:22 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2005-02-23 09:13:12 +00:00
|
|
|
|
2008-08-24 08:41:38 +00:00
|
|
|
musicdriver[0] = sounddriver[0] = videodriver[0] = blitter[0] = graphics_set[0] = '\0';
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
_game_mode = GM_MENU;
|
|
|
|
_switch_mode = SM_MENU;
|
2004-09-06 22:46:02 +00:00
|
|
|
_switch_mode_errorstr = INVALID_STRING_ID;
|
2004-12-18 14:19:21 +00:00
|
|
|
_dedicated_forks = false;
|
2005-03-10 21:44:17 +00:00
|
|
|
_config_file = NULL;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* The last param of the following function means this:
|
|
|
|
* a letter means: it accepts that param (e.g.: -h)
|
|
|
|
* a ':' behind it means: it need a param (e.g.: -m<driver>)
|
|
|
|
* a '::' behind it means: it can optional have a param (e.g.: -d<debug>) */
|
2008-08-24 08:41:38 +00:00
|
|
|
optformat = "m:s:v:b:hD::n::ei::I:t:d::r:g::G:c:xl:"
|
2006-06-27 21:25:53 +00:00
|
|
|
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
|
|
|
|
"f"
|
|
|
|
#endif
|
|
|
|
;
|
2004-12-22 21:12:36 +00:00
|
|
|
|
2007-04-18 22:10:36 +00:00
|
|
|
MyGetOptData mgo(argc - 1, argv + 1, optformat);
|
2007-01-10 18:56:51 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
while ((i = MyGetOpt(&mgo)) != -1) {
|
2006-02-01 06:32:03 +00:00
|
|
|
switch (i) {
|
2008-08-24 08:41:38 +00:00
|
|
|
case 'I': ttd_strlcpy(graphics_set, mgo.opt, sizeof(graphics_set)); break;
|
2004-08-09 17:04:08 +00:00
|
|
|
case 'm': ttd_strlcpy(musicdriver, mgo.opt, sizeof(musicdriver)); break;
|
|
|
|
case 's': ttd_strlcpy(sounddriver, mgo.opt, sizeof(sounddriver)); break;
|
|
|
|
case 'v': ttd_strlcpy(videodriver, mgo.opt, sizeof(videodriver)); break;
|
2007-06-11 11:50:49 +00:00
|
|
|
case 'b': ttd_strlcpy(blitter, mgo.opt, sizeof(blitter)); break;
|
2007-01-16 15:20:22 +00:00
|
|
|
#if defined(ENABLE_NETWORK)
|
2006-02-21 17:29:53 +00:00
|
|
|
case 'D':
|
|
|
|
strcpy(musicdriver, "null");
|
|
|
|
strcpy(sounddriver, "null");
|
|
|
|
strcpy(videodriver, "dedicated");
|
2007-06-12 20:24:12 +00:00
|
|
|
strcpy(blitter, "null");
|
2006-02-21 17:29:53 +00:00
|
|
|
dedicated = true;
|
2007-01-31 20:20:36 +00:00
|
|
|
if (mgo.opt != NULL) {
|
2007-01-03 18:29:15 +00:00
|
|
|
/* Use the existing method for parsing (openttd -n).
|
2008-09-30 20:39:50 +00:00
|
|
|
* However, we do ignore the #company part. */
|
2007-01-03 18:29:15 +00:00
|
|
|
const char *temp = NULL;
|
|
|
|
const char *port = NULL;
|
|
|
|
ParseConnectionString(&temp, &port, mgo.opt);
|
2007-01-31 20:20:36 +00:00
|
|
|
if (!StrEmpty(mgo.opt)) dedicated_host = mgo.opt;
|
2007-01-03 18:29:15 +00:00
|
|
|
if (port != NULL) dedicated_port = atoi(port);
|
|
|
|
}
|
2006-02-21 17:29:53 +00:00
|
|
|
break;
|
|
|
|
case 'f': _dedicated_forks = true; break;
|
|
|
|
case 'n':
|
|
|
|
network = true;
|
2006-02-21 17:48:40 +00:00
|
|
|
network_conn = mgo.opt; // optional IP parameter, NULL if unset
|
2006-02-21 17:29:53 +00:00
|
|
|
break;
|
2007-02-08 12:27:53 +00:00
|
|
|
case 'l':
|
|
|
|
debuglog_conn = mgo.opt;
|
|
|
|
break;
|
2007-01-16 15:20:22 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2008-06-16 19:38:41 +00:00
|
|
|
case 'r': ParseResolution(&resolution, mgo.opt); break;
|
2006-08-15 14:52:17 +00:00
|
|
|
case 't': startyear = atoi(mgo.opt); break;
|
2004-08-09 17:04:08 +00:00
|
|
|
case 'd': {
|
|
|
|
#if defined(WIN32)
|
|
|
|
CreateConsole();
|
|
|
|
#endif
|
2005-11-14 19:48:04 +00:00
|
|
|
if (mgo.opt != NULL) SetDebugString(mgo.opt);
|
2004-08-09 17:04:08 +00:00
|
|
|
} break;
|
|
|
|
case 'e': _switch_mode = SM_EDITOR; break;
|
2008-08-23 20:16:54 +00:00
|
|
|
case 'i': _use_palette = (mgo.opt == NULL || atoi(mgo.opt) == 0) ? PAL_DOS : PAL_WINDOWS; break;
|
2004-09-10 19:02:27 +00:00
|
|
|
case 'g':
|
2005-11-14 19:48:04 +00:00
|
|
|
if (mgo.opt != NULL) {
|
2008-07-28 15:17:47 +00:00
|
|
|
ttd_strlcpy(_file_to_saveload.name, mgo.opt, sizeof(_file_to_saveload.name));
|
2004-08-09 17:04:08 +00:00
|
|
|
_switch_mode = SM_LOAD;
|
2008-07-28 15:31:11 +00:00
|
|
|
_file_to_saveload.mode = SL_LOAD;
|
|
|
|
|
|
|
|
/* if the file doesn't exist or it is not a valid savegame, let the saveload code show an error */
|
|
|
|
const char *t = strrchr(_file_to_saveload.name, '.');
|
|
|
|
if (t != NULL) {
|
|
|
|
FiosType ft = FiosGetSavegameListCallback(SLD_LOAD_GAME, _file_to_saveload.name, t, NULL);
|
|
|
|
if (ft != FIOS_TYPE_INVALID) SetFiosType(ft);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2006-06-27 21:25:53 +00:00
|
|
|
}
|
2008-07-28 15:31:11 +00:00
|
|
|
|
|
|
|
_switch_mode = SM_NEWGAME;
|
2008-09-27 22:19:34 +00:00
|
|
|
/* Give a random map if no seed has been given */
|
|
|
|
if (generation_seed == GENERATE_NEW_SEED) {
|
|
|
|
generation_seed = InteractiveRandom();
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
case 'G': generation_seed = atoi(mgo.opt); break;
|
2006-02-21 17:29:53 +00:00
|
|
|
case 'c': _config_file = strdup(mgo.opt); break;
|
2007-01-03 18:06:50 +00:00
|
|
|
case 'x': save_config = false; break;
|
2004-08-09 17:04:08 +00:00
|
|
|
case -2:
|
2005-07-08 22:25:24 +00:00
|
|
|
case 'h':
|
2008-08-24 08:41:38 +00:00
|
|
|
/* The next two functions are needed to list the graphics sets.
|
|
|
|
* We can't do them earlier because then we can't show it on
|
|
|
|
* the debug console as that hasn't been configured yet. */
|
|
|
|
DeterminePaths(argv[0]);
|
|
|
|
FindGraphicsSets();
|
2008-04-29 18:19:29 +00:00
|
|
|
ShowHelp();
|
2004-08-09 17:04:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-04 12:53:41 +00:00
|
|
|
#if defined(WINCE) && defined(_DEBUG)
|
|
|
|
/* Switch on debug lvl 4 for WinCE if Debug release, as you can't give params, and you most likely do want this information */
|
|
|
|
SetDebugString("4");
|
|
|
|
#endif
|
|
|
|
|
2007-03-17 11:36:04 +00:00
|
|
|
DeterminePaths(argv[0]);
|
2008-08-24 08:41:38 +00:00
|
|
|
FindGraphicsSets();
|
2004-12-18 14:19:21 +00:00
|
|
|
|
2005-08-06 14:58:06 +00:00
|
|
|
#if defined(UNIX) && !defined(__MORPHOS__)
|
2007-03-21 15:19:33 +00:00
|
|
|
/* We must fork here, or we'll end up without some resources we need (like sockets) */
|
2004-12-18 14:19:21 +00:00
|
|
|
if (_dedicated_forks)
|
|
|
|
DedicatedFork();
|
|
|
|
#endif
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
LoadFromConfig();
|
2005-04-13 23:03:31 +00:00
|
|
|
CheckConfig();
|
2005-01-11 00:54:06 +00:00
|
|
|
LoadFromHighScore();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-08-31 08:46:43 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* override config? */
|
2008-08-31 08:46:43 +00:00
|
|
|
if (!StrEmpty(graphics_set)) ttd_strlcpy(_ini_graphics_set, graphics_set, sizeof(_ini_graphics_set));
|
2007-01-31 20:20:36 +00:00
|
|
|
if (!StrEmpty(musicdriver)) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver));
|
|
|
|
if (!StrEmpty(sounddriver)) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver));
|
|
|
|
if (!StrEmpty(videodriver)) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver));
|
2007-09-13 12:28:53 +00:00
|
|
|
if (!StrEmpty(blitter)) ttd_strlcpy(_ini_blitter, blitter, sizeof(_ini_blitter));
|
2008-06-16 19:38:41 +00:00
|
|
|
if (resolution.width != 0) { _cur_resolution = resolution; }
|
2008-05-25 19:17:03 +00:00
|
|
|
if (startyear != INVALID_YEAR) _settings_newgame.game_creation.starting_year = startyear;
|
|
|
|
if (generation_seed != GENERATE_NEW_SEED) _settings_newgame.game_creation.generation_seed = generation_seed;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-13 14:57:42 +00:00
|
|
|
/* The width and height must be at least 1 pixel, this
|
|
|
|
* way all internal drawing routines work correctly. */
|
2008-06-16 19:38:41 +00:00
|
|
|
if (_cur_resolution.width <= 0) _cur_resolution.width = 1;
|
|
|
|
if (_cur_resolution.height <= 0) _cur_resolution.height = 1;
|
2007-06-13 14:57:42 +00:00
|
|
|
|
2007-01-16 15:20:22 +00:00
|
|
|
#if defined(ENABLE_NETWORK)
|
2008-05-29 20:21:28 +00:00
|
|
|
if (dedicated_host) snprintf(_settings_client.network.server_bind_ip, sizeof(_settings_client.network.server_bind_ip), "%s", dedicated_host);
|
|
|
|
if (dedicated_port) _settings_client.network.server_port = dedicated_port;
|
2006-02-01 06:32:03 +00:00
|
|
|
if (_dedicated_forks && !dedicated) _dedicated_forks = false;
|
2007-01-16 15:20:22 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2004-12-18 14:19:21 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* enumerate language files */
|
2004-08-09 17:04:08 +00:00
|
|
|
InitializeLanguagePacks();
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* initialize screenshot formats */
|
2004-08-09 17:04:08 +00:00
|
|
|
InitializeScreenshotFormats();
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* initialize airport state machines */
|
2004-08-22 10:23:37 +00:00
|
|
|
InitializeAirports();
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
/* initialize all variables that are allocated dynamically */
|
|
|
|
InitializeDynamicVariables();
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Sample catalogue */
|
2006-12-26 17:36:18 +00:00
|
|
|
DEBUG(misc, 1, "Loading sound effects...");
|
2005-03-12 09:38:03 +00:00
|
|
|
MxInitialize(11025);
|
|
|
|
SoundInitialize("sample.cat");
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
/* Initialize FreeType */
|
|
|
|
InitFreeType();
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* This must be done early, since functions use the InvalidateWindow* calls */
|
2004-08-25 10:17:39 +00:00
|
|
|
InitWindowSystem();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-08-31 08:46:43 +00:00
|
|
|
if (!SetGraphicsSet(_ini_graphics_set)) {
|
|
|
|
StrEmpty(_ini_graphics_set) ?
|
2008-08-24 08:41:38 +00:00
|
|
|
usererror("Failed to find a graphics set. Please acquire a graphics set for OpenTTD.") :
|
2008-08-31 08:46:43 +00:00
|
|
|
usererror("Failed to select requested graphics set '%s'", _ini_graphics_set);
|
2008-08-24 08:41:38 +00:00
|
|
|
}
|
|
|
|
|
2006-11-28 14:32:24 +00:00
|
|
|
/* Initialize game palette */
|
|
|
|
GfxInitPalettes();
|
|
|
|
|
2007-09-13 12:28:53 +00:00
|
|
|
DEBUG(misc, 1, "Loading blitter...");
|
|
|
|
if (BlitterFactoryBase::SelectBlitter(_ini_blitter) == NULL)
|
|
|
|
StrEmpty(_ini_blitter) ?
|
2008-06-05 20:54:52 +00:00
|
|
|
usererror("Failed to autoprobe blitter") :
|
|
|
|
usererror("Failed to select requested blitter '%s'; does it exist?", _ini_blitter);
|
2007-07-05 12:23:54 +00:00
|
|
|
|
2006-12-26 17:36:18 +00:00
|
|
|
DEBUG(driver, 1, "Loading drivers...");
|
2007-07-05 12:23:54 +00:00
|
|
|
|
|
|
|
_sound_driver = (SoundDriver*)SoundDriverFactoryBase::SelectDriver(_ini_sounddriver, Driver::DT_SOUND);
|
|
|
|
if (_sound_driver == NULL) {
|
|
|
|
StrEmpty(_ini_sounddriver) ?
|
2008-06-05 20:54:52 +00:00
|
|
|
usererror("Failed to autoprobe sound driver") :
|
|
|
|
usererror("Failed to select requested sound driver '%s'", _ini_sounddriver);
|
2007-07-05 12:23:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_music_driver = (MusicDriver*)MusicDriverFactoryBase::SelectDriver(_ini_musicdriver, Driver::DT_MUSIC);
|
|
|
|
if (_music_driver == NULL) {
|
|
|
|
StrEmpty(_ini_musicdriver) ?
|
2008-06-05 20:54:52 +00:00
|
|
|
usererror("Failed to autoprobe music driver") :
|
|
|
|
usererror("Failed to select requested music driver '%s'", _ini_musicdriver);
|
2007-07-05 12:23:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_video_driver = (VideoDriver*)VideoDriverFactoryBase::SelectDriver(_ini_videodriver, Driver::DT_VIDEO);
|
|
|
|
if (_video_driver == NULL) {
|
|
|
|
StrEmpty(_ini_videodriver) ?
|
2008-06-05 20:54:52 +00:00
|
|
|
usererror("Failed to autoprobe video driver") :
|
|
|
|
usererror("Failed to select requested video driver '%s'", _ini_videodriver);
|
2007-07-05 12:23:54 +00:00
|
|
|
}
|
|
|
|
|
2005-10-17 19:57:00 +00:00
|
|
|
_savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING;
|
2007-05-19 23:52:04 +00:00
|
|
|
/* Initialize the zoom level of the screen to normal */
|
|
|
|
_screen.zoom = ZOOM_LVL_NORMAL;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* restore saved music volume */
|
2007-07-05 12:23:54 +00:00
|
|
|
_music_driver->SetVolume(msf.music_vol);
|
2006-04-27 21:05:32 +00:00
|
|
|
|
2006-10-12 14:59:27 +00:00
|
|
|
NetworkStartUp(); // initialize network-core
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2007-02-08 12:27:53 +00:00
|
|
|
#if defined(ENABLE_NETWORK)
|
|
|
|
if (debuglog_conn != NULL && _network_available) {
|
|
|
|
const char *not_used = NULL;
|
|
|
|
const char *port = NULL;
|
|
|
|
uint16 rport;
|
|
|
|
|
|
|
|
rport = NETWORK_DEFAULT_DEBUGLOG_PORT;
|
|
|
|
|
|
|
|
ParseConnectionString(¬_used, &port, debuglog_conn);
|
|
|
|
if (port != NULL) rport = atoi(port);
|
|
|
|
|
|
|
|
NetworkStartDebugLog(debuglog_conn, rport);
|
|
|
|
}
|
|
|
|
#endif /* ENABLE_NETWORK */
|
|
|
|
|
2006-12-04 08:30:04 +00:00
|
|
|
ScanNewGRFFiles();
|
|
|
|
|
|
|
|
ResetGRFConfig(false);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-03-12 21:21:47 +00:00
|
|
|
/* XXX - ugly hack, if diff_level is 9, it means we got no setting from the config file */
|
2008-05-25 22:36:44 +00:00
|
|
|
if (_settings_newgame.difficulty.diff_level == 9) SetDifficultyLevel(0, &_settings_newgame.difficulty);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-26 21:38:17 +00:00
|
|
|
/* Make sure _settings is filled with _settings_newgame if we switch to a game directly */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_switch_mode != SM_NONE) _settings_game = _settings_newgame;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* initialize the ingame console */
|
2004-08-25 10:17:39 +00:00
|
|
|
IConsoleInit();
|
2006-03-24 00:42:35 +00:00
|
|
|
_cursor.in_window = true;
|
2005-01-31 11:03:23 +00:00
|
|
|
InitializeGUI();
|
2004-12-13 22:13:02 +00:00
|
|
|
IConsoleCmdExec("exec scripts/autoexec.scr 0");
|
2004-12-14 20:27:00 +00:00
|
|
|
|
2006-01-06 21:57:37 +00:00
|
|
|
GenerateWorld(GW_EMPTY, 64, 64); // Make the viewport initialization happy
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
WaitTillGeneratedWorld();
|
2005-02-02 18:28:08 +00:00
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2006-02-01 06:32:03 +00:00
|
|
|
if (network && _network_available) {
|
2004-12-04 17:54:56 +00:00
|
|
|
if (network_conn != NULL) {
|
2005-02-06 22:25:27 +00:00
|
|
|
const char *port = NULL;
|
2008-09-30 20:39:50 +00:00
|
|
|
const char *company = NULL;
|
2004-12-04 17:54:56 +00:00
|
|
|
uint16 rport;
|
|
|
|
|
|
|
|
rport = NETWORK_DEFAULT_PORT;
|
2008-09-30 20:39:50 +00:00
|
|
|
_network_playas = COMPANY_NEW_COMPANY;
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
ParseConnectionString(&company, &port, network_conn);
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
if (company != NULL) {
|
|
|
|
_network_playas = (CompanyID)atoi(company);
|
2006-10-17 22:16:46 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
if (_network_playas != COMPANY_SPECTATOR) {
|
2006-10-17 23:34:12 +00:00
|
|
|
_network_playas--;
|
2008-09-30 20:39:50 +00:00
|
|
|
if (_network_playas >= MAX_COMPANIES) return false;
|
2006-10-17 22:16:46 +00:00
|
|
|
}
|
2006-10-15 23:48:34 +00:00
|
|
|
}
|
2004-12-04 17:54:56 +00:00
|
|
|
if (port != NULL) rport = atoi(port);
|
|
|
|
|
|
|
|
LoadIntroGame();
|
|
|
|
_switch_mode = SM_NONE;
|
|
|
|
NetworkClientConnectGame(network_conn, rport);
|
2005-01-23 13:09:35 +00:00
|
|
|
}
|
2004-12-04 17:54:56 +00:00
|
|
|
}
|
|
|
|
#endif /* ENABLE_NETWORK */
|
|
|
|
|
2007-07-05 12:23:54 +00:00
|
|
|
_video_driver->MainLoop();
|
2004-08-25 10:17:39 +00:00
|
|
|
|
2005-08-05 09:15:41 +00:00
|
|
|
WaitTillSaved();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-03 18:06:50 +00:00
|
|
|
/* only save config if we have to */
|
|
|
|
if (save_config) {
|
|
|
|
SaveToConfig();
|
|
|
|
SaveToHighScore();
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-05-08 23:26:17 +00:00
|
|
|
/* Reset windowing system, stop drivers, free used memory, ... */
|
|
|
|
ShutdownGame();
|
2005-01-16 12:14:52 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void HandleExitGameRequest()
|
2006-09-04 17:30:30 +00:00
|
|
|
{
|
|
|
|
if (_game_mode == GM_MENU) { // do not ask to quit on the main screen
|
|
|
|
_exit_game = true;
|
2008-05-29 15:13:28 +00:00
|
|
|
} else if (_settings_client.gui.autosave_on_exit) {
|
2006-09-04 17:30:30 +00:00
|
|
|
DoExitSave();
|
|
|
|
_exit_game = true;
|
|
|
|
} else {
|
|
|
|
AskExitGame();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void ShowScreenshotResult(bool b)
|
|
|
|
{
|
|
|
|
if (b) {
|
2005-07-14 09:43:59 +00:00
|
|
|
SetDParamStr(0, _screenshot_name);
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_031B_SCREENSHOT_SUCCESSFULLY, 0, 0);
|
|
|
|
} else {
|
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_031C_SCREENSHOT_FAILED, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void MakeNewGameDone()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-07-03 18:00:36 +00:00
|
|
|
SettingsDisableElrail(_settings_game.vehicle.disable_elrails);
|
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
/* In a dedicated server, the server does not play */
|
|
|
|
if (_network_dedicated) {
|
2008-09-30 20:39:50 +00:00
|
|
|
SetLocalCompany(COMPANY_SPECTATOR);
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
/* Create a single company */
|
|
|
|
DoStartupNewCompany(false);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
SetLocalCompany(COMPANY_FIRST);
|
|
|
|
_current_company = _local_company;
|
2008-05-29 15:13:28 +00:00
|
|
|
DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-03 21:54:31 +00:00
|
|
|
InitializeRailGUI();
|
2006-11-17 19:31:44 +00:00
|
|
|
|
2008-01-11 00:30:32 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2008-09-30 20:39:50 +00:00
|
|
|
/* We are the server, we start a new company (not dedicated),
|
2007-12-02 14:48:26 +00:00
|
|
|
* so set the default password *if* needed. */
|
2008-05-29 20:21:28 +00:00
|
|
|
if (_network_server && !StrEmpty(_settings_client.network.default_company_pass)) {
|
|
|
|
char *password = _settings_client.network.default_company_pass;
|
2007-12-02 14:48:26 +00:00
|
|
|
NetworkChangeCompanyPassword(1, &password);
|
|
|
|
}
|
2008-01-11 00:30:32 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2007-12-02 14:48:26 +00:00
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
static void MakeNewGame(bool from_heightmap)
|
|
|
|
{
|
|
|
|
_game_mode = GM_NORMAL;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-10 12:12:26 +00:00
|
|
|
ResetGRFConfig(true);
|
2007-05-15 21:36:58 +00:00
|
|
|
_house_mngr.ResetMapping();
|
2007-07-04 01:34:28 +00:00
|
|
|
_industile_mngr.ResetMapping();
|
|
|
|
_industry_mngr.ResetMapping();
|
2006-12-10 12:12:26 +00:00
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
GenerateWorldSetCallback(&MakeNewGameDone);
|
2008-05-29 15:13:28 +00:00
|
|
|
GenerateWorld(from_heightmap ? GW_HEIGHTMAP : GW_NEWGAME, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void MakeNewEditorWorldDone()
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
{
|
2008-09-30 20:39:50 +00:00
|
|
|
SetLocalCompany(OWNER_NONE);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void MakeNewEditorWorld()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
_game_mode = GM_EDITOR;
|
|
|
|
|
2006-12-10 12:12:26 +00:00
|
|
|
ResetGRFConfig(true);
|
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
GenerateWorldSetCallback(&MakeNewEditorWorldDone);
|
2008-05-29 15:13:28 +00:00
|
|
|
GenerateWorld(GW_EMPTY, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
void StartupCompanies();
|
2007-03-07 11:47:46 +00:00
|
|
|
void StartupDisasters();
|
|
|
|
extern void StartupEconomy();
|
2004-08-23 10:59:03 +00:00
|
|
|
|
2005-03-12 21:21:47 +00:00
|
|
|
/**
|
|
|
|
* Start Scenario starts a new game based on a scenario.
|
|
|
|
* Eg 'New Game' --> select a preset scenario
|
2005-03-13 11:47:04 +00:00
|
|
|
* This starts a scenario based on your current difficulty settings
|
2005-03-12 21:21:47 +00:00
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
static void StartScenario()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
_game_mode = GM_NORMAL;
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* invalid type */
|
2004-08-09 17:04:08 +00:00
|
|
|
if (_file_to_saveload.mode == SL_INVALID) {
|
2006-12-26 17:36:18 +00:00
|
|
|
DEBUG(sl, 0, "Savegame is obsolete or invalid format: '%s'", _file_to_saveload.name);
|
2008-07-17 13:47:04 +00:00
|
|
|
SetDParam(0, STR_JUST_RAW_STRING);
|
|
|
|
SetDParamStr(1, GetSaveLoadErrorString());
|
2007-06-24 12:27:11 +00:00
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
_game_mode = GM_MENU;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Reinitialize windows */
|
2005-03-09 19:48:20 +00:00
|
|
|
ResetWindowSystem();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
SetupColorsAndInitialWindow();
|
|
|
|
|
2006-12-10 12:12:26 +00:00
|
|
|
ResetGRFConfig(true);
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Load game */
|
2007-06-17 15:48:57 +00:00
|
|
|
if (SaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, SCENARIO_DIR) != SL_OK) {
|
2004-08-09 17:04:08 +00:00
|
|
|
LoadIntroGame();
|
2008-07-17 13:47:04 +00:00
|
|
|
SetDParam(0, STR_JUST_RAW_STRING);
|
|
|
|
SetDParamStr(1, GetSaveLoadErrorString());
|
2007-06-24 12:27:11 +00:00
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 15:13:28 +00:00
|
|
|
_settings_game.difficulty = _settings_newgame.difficulty;
|
2005-03-12 21:21:47 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Inititalize data */
|
2006-05-22 16:44:16 +00:00
|
|
|
StartupEconomy();
|
2008-09-30 20:39:50 +00:00
|
|
|
StartupCompanies();
|
2004-08-23 08:59:36 +00:00
|
|
|
StartupEngines();
|
|
|
|
StartupDisasters();
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
SetLocalCompany(COMPANY_FIRST);
|
|
|
|
_current_company = _local_company;
|
2008-05-29 15:13:28 +00:00
|
|
|
DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, NULL, CMD_SET_AUTOREPLACE);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
|
|
|
|
2007-06-17 15:48:57 +00:00
|
|
|
/** Load the specified savegame but on error do different things.
|
|
|
|
* If loading fails due to corrupt savegame, bad version, etc. go back to
|
|
|
|
* a previous correct state. In the menu for example load the intro game again.
|
|
|
|
* @param filename file to be loaded
|
|
|
|
* @param mode mode of loading, either SL_LOAD or SL_OLD_LOAD
|
|
|
|
* @param newgm switch to this mode of loading fails due to some unknown error
|
2008-04-29 18:19:29 +00:00
|
|
|
* @param subdir default directory to look for filename, set to 0 if not needed
|
|
|
|
*/
|
2007-06-17 15:48:57 +00:00
|
|
|
bool SafeSaveOrLoad(const char *filename, int mode, int newgm, Subdirectory subdir)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
byte ogm = _game_mode;
|
|
|
|
|
|
|
|
_game_mode = newgm;
|
2007-06-17 15:48:57 +00:00
|
|
|
assert(mode == SL_LOAD || mode == SL_OLD_LOAD);
|
|
|
|
switch (SaveOrLoad(filename, mode, subdir)) {
|
2006-02-14 07:32:45 +00:00
|
|
|
case SL_OK: return true;
|
|
|
|
|
|
|
|
case SL_REINIT:
|
|
|
|
switch (ogm) {
|
2008-02-20 19:37:02 +00:00
|
|
|
default:
|
2006-02-14 07:32:45 +00:00
|
|
|
case GM_MENU: LoadIntroGame(); break;
|
|
|
|
case GM_EDITOR: MakeNewEditorWorld(); break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
default:
|
|
|
|
_game_mode = ogm;
|
|
|
|
return false;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
void SwitchMode(int new_mode)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-12-04 17:54:56 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2007-03-21 15:19:33 +00:00
|
|
|
/* If we are saving something, the network stays in his current state */
|
2004-12-04 17:54:56 +00:00
|
|
|
if (new_mode != SM_SAVE) {
|
2007-03-21 15:19:33 +00:00
|
|
|
/* If the network is active, make it not-active */
|
2004-12-04 17:54:56 +00:00
|
|
|
if (_networking) {
|
|
|
|
if (_network_server && (new_mode == SM_LOAD || new_mode == SM_NEWGAME)) {
|
|
|
|
NetworkReboot();
|
|
|
|
} else {
|
|
|
|
NetworkDisconnect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* If we are a server, we restart the server */
|
2004-12-04 17:54:56 +00:00
|
|
|
if (_is_network_server) {
|
2007-03-21 15:19:33 +00:00
|
|
|
/* But not if we are going to the menu */
|
2004-12-04 17:54:56 +00:00
|
|
|
if (new_mode != SM_MENU) {
|
2008-01-13 01:39:22 +00:00
|
|
|
/* check if we should reload the config */
|
2008-05-29 20:21:28 +00:00
|
|
|
if (_settings_client.network.reload_cfg) {
|
2008-01-13 01:39:22 +00:00
|
|
|
LoadFromConfig();
|
2008-05-29 15:13:28 +00:00
|
|
|
_settings_game = _settings_newgame;
|
2008-01-13 01:39:22 +00:00
|
|
|
ResetGRFConfig(false);
|
|
|
|
}
|
2004-12-04 17:54:56 +00:00
|
|
|
NetworkServerStart();
|
|
|
|
} else {
|
2007-03-21 15:19:33 +00:00
|
|
|
/* This client no longer wants to be a network-server */
|
2004-12-04 17:54:56 +00:00
|
|
|
_is_network_server = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* ENABLE_NETWORK */
|
|
|
|
|
2005-03-12 21:21:47 +00:00
|
|
|
switch (new_mode) {
|
2008-04-29 18:19:29 +00:00
|
|
|
case SM_EDITOR: /* Switch to scenario editor */
|
|
|
|
MakeNewEditorWorld();
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-29 18:19:29 +00:00
|
|
|
case SM_NEWGAME: /* New Game --> 'Random game' */
|
2004-12-13 17:58:53 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2008-04-29 18:19:29 +00:00
|
|
|
if (_network_server) {
|
|
|
|
snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "Random Map");
|
|
|
|
}
|
2004-12-13 17:58:53 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2008-04-29 18:19:29 +00:00
|
|
|
MakeNewGame(false);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-29 18:19:29 +00:00
|
|
|
case SM_START_SCENARIO: /* New Game --> Choose one of the preset scenarios */
|
2006-02-01 06:32:03 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2008-04-29 18:19:29 +00:00
|
|
|
if (_network_server) {
|
|
|
|
snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded scenario)", _file_to_saveload.title);
|
|
|
|
}
|
2006-02-01 06:32:03 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2008-04-29 18:19:29 +00:00
|
|
|
StartScenario();
|
|
|
|
break;
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2008-04-29 18:19:29 +00:00
|
|
|
case SM_LOAD: { /* Load game, Play Scenario */
|
|
|
|
ResetGRFConfig(true);
|
|
|
|
ResetWindowSystem();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-29 18:19:29 +00:00
|
|
|
if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL, NO_DIRECTORY)) {
|
|
|
|
LoadIntroGame();
|
2008-07-17 13:47:04 +00:00
|
|
|
SetDParam(0, STR_JUST_RAW_STRING);
|
|
|
|
SetDParamStr(1, GetSaveLoadErrorString());
|
2008-04-29 18:19:29 +00:00
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
|
|
|
|
} else {
|
2008-05-04 22:38:18 +00:00
|
|
|
if (_saveload_mode == SLD_LOAD_SCENARIO) {
|
|
|
|
StartupEngines();
|
|
|
|
}
|
2008-09-30 20:39:50 +00:00
|
|
|
/* Update the local company for a loaded game. It is either always
|
|
|
|
* company #1 (eg 0) or in the case of a dedicated server a spectator */
|
|
|
|
SetLocalCompany(_network_dedicated ? COMPANY_SPECTATOR : COMPANY_FIRST);
|
2008-04-29 18:19:29 +00:00
|
|
|
/* Decrease pause counter (was increased from opening load dialog) */
|
|
|
|
DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
|
2004-12-13 17:58:53 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2008-04-29 18:19:29 +00:00
|
|
|
if (_network_server) {
|
|
|
|
snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Loaded game)", _file_to_saveload.title);
|
|
|
|
}
|
2004-12-13 17:58:53 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2008-04-29 18:19:29 +00:00
|
|
|
}
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-04-29 18:19:29 +00:00
|
|
|
case SM_START_HEIGHTMAP: /* Load a heightmap and start a new game from it */
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2008-04-29 18:19:29 +00:00
|
|
|
if (_network_server) {
|
|
|
|
snprintf(_network_game_info.map_name, lengthof(_network_game_info.map_name), "%s (Heightmap)", _file_to_saveload.title);
|
|
|
|
}
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2008-04-29 18:19:29 +00:00
|
|
|
MakeNewGame(true);
|
|
|
|
break;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
2008-04-29 18:19:29 +00:00
|
|
|
case SM_LOAD_HEIGHTMAP: /* Load heightmap from scenario editor */
|
2008-09-30 20:39:50 +00:00
|
|
|
SetLocalCompany(OWNER_NONE);
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
2008-05-29 15:13:28 +00:00
|
|
|
GenerateWorld(GW_HEIGHTMAP, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
|
2008-04-29 18:19:29 +00:00
|
|
|
MarkWholeScreenDirty();
|
|
|
|
break;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
2008-04-29 18:19:29 +00:00
|
|
|
case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */
|
|
|
|
if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR, NO_DIRECTORY)) {
|
2008-09-30 20:39:50 +00:00
|
|
|
SetLocalCompany(OWNER_NONE);
|
2008-05-25 19:17:03 +00:00
|
|
|
_settings_newgame.game_creation.starting_year = _cur_year;
|
2008-04-29 18:19:29 +00:00
|
|
|
} else {
|
2008-07-17 13:47:04 +00:00
|
|
|
SetDParam(0, STR_JUST_RAW_STRING);
|
|
|
|
SetDParamStr(1, GetSaveLoadErrorString());
|
2008-04-29 18:19:29 +00:00
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
|
|
|
|
}
|
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-29 18:19:29 +00:00
|
|
|
case SM_MENU: /* Switch to game intro menu */
|
|
|
|
LoadIntroGame();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SM_SAVE: /* Save game */
|
|
|
|
/* Make network saved games on pause compatible to singleplayer */
|
|
|
|
if (_networking && _pause_game == 1) _pause_game = 2;
|
|
|
|
if (SaveOrLoad(_file_to_saveload.name, SL_SAVE, NO_DIRECTORY) != SL_OK) {
|
2008-07-17 13:47:04 +00:00
|
|
|
SetDParam(0, STR_JUST_RAW_STRING);
|
|
|
|
SetDParamStr(1, GetSaveLoadErrorString());
|
2008-04-29 18:19:29 +00:00
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_012D, 0, 0);
|
|
|
|
} else {
|
|
|
|
DeleteWindowById(WC_SAVELOAD, 0);
|
|
|
|
}
|
|
|
|
if (_networking && _pause_game == 2) _pause_game = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SM_GENRANDLAND: /* Generate random land within scenario editor */
|
2008-09-30 20:39:50 +00:00
|
|
|
SetLocalCompany(OWNER_NONE);
|
2008-05-29 15:13:28 +00:00
|
|
|
GenerateWorld(GW_RANDOM, 1 << _settings_game.game_creation.map_x, 1 << _settings_game.game_creation.map_y);
|
2008-04-29 18:19:29 +00:00
|
|
|
/* XXX: set date */
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-02-01 06:32:03 +00:00
|
|
|
if (_switch_mode_errorstr != INVALID_STRING_ID) {
|
|
|
|
ShowErrorMessage(INVALID_STRING_ID, _switch_mode_errorstr, 0, 0);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-29 18:19:29 +00:00
|
|
|
/**
|
|
|
|
* State controlling game loop.
|
|
|
|
* The state must not be changed from anywhere but here.
|
|
|
|
* That check is enforced in DoCommand.
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
void StateGameLoop()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-21 15:19:33 +00:00
|
|
|
/* dont execute the state loop during pause */
|
2008-01-01 22:34:00 +00:00
|
|
|
if (_pause_game) {
|
|
|
|
CallWindowTickEvent();
|
|
|
|
return;
|
|
|
|
}
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
if (IsGeneratingWorld()) return;
|
2004-09-12 15:29:37 +00:00
|
|
|
|
2008-01-15 18:51:46 +00:00
|
|
|
ClearStorageChanges(false);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (_game_mode == GM_EDITOR) {
|
|
|
|
RunTileLoop();
|
|
|
|
CallVehicleTicks();
|
|
|
|
CallLandscapeTick();
|
2008-01-15 18:51:46 +00:00
|
|
|
ClearStorageChanges(true);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
CallWindowTickEvent();
|
|
|
|
NewsLoop();
|
|
|
|
} else {
|
2008-04-23 22:17:33 +00:00
|
|
|
#ifdef DEBUG_DUMP_COMMANDS
|
|
|
|
Vehicle *v;
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if (v != v->First()) continue;
|
|
|
|
|
|
|
|
switch (v->type) {
|
|
|
|
case VEH_ROAD: {
|
|
|
|
extern byte GetRoadVehLength(const Vehicle *v);
|
|
|
|
if (GetRoadVehLength(v) != v->u.road.cached_veh_length) {
|
2008-09-30 20:39:50 +00:00
|
|
|
printf("cache mismatch: vehicle %i, company %i, unit number %i\n", v->index, (int)v->owner, v->unitnumber);
|
2008-04-23 22:17:33 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case VEH_TRAIN: {
|
|
|
|
uint length = 0;
|
|
|
|
for (Vehicle *u = v; u != NULL; u = u->Next()) length++;
|
|
|
|
|
|
|
|
VehicleRail *wagons = MallocT<VehicleRail>(length);
|
|
|
|
length = 0;
|
|
|
|
for (Vehicle *u = v; u != NULL; u = u->Next()) wagons[length++] = u->u.rail;
|
|
|
|
|
2008-07-24 15:19:26 +00:00
|
|
|
TrainConsistChanged(v, true);
|
2008-04-23 22:17:33 +00:00
|
|
|
|
|
|
|
length = 0;
|
|
|
|
for (Vehicle *u = v; u != NULL; u = u->Next()) {
|
|
|
|
if (memcmp(&wagons[length], &u->u.rail, sizeof(VehicleRail)) != 0) {
|
2008-09-30 20:39:50 +00:00
|
|
|
printf("cache mismatch: vehicle %i, company %i, unit number %i, wagon %i\n", v->index, (int)v->owner, v->unitnumber, length);
|
2008-04-23 22:17:33 +00:00
|
|
|
}
|
|
|
|
length++;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(wagons);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case VEH_AIRCRAFT: {
|
|
|
|
uint speed = v->u.air.cached_max_speed;
|
|
|
|
UpdateAircraftCache(v);
|
|
|
|
if (speed != v->u.air.cached_max_speed) {
|
2008-09-30 20:39:50 +00:00
|
|
|
printf("cache mismatch: vehicle %i, company %i, unit number %i\n", v->index, (int)v->owner, v->unitnumber);
|
2008-04-23 22:17:33 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* All these actions has to be done from OWNER_NONE
|
|
|
|
* for multiplayer compatibility */
|
2008-09-30 20:39:50 +00:00
|
|
|
CompanyID old_company = _current_company;
|
|
|
|
_current_company = OWNER_NONE;
|
2004-09-11 19:34:11 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
AnimateAnimatedTiles();
|
|
|
|
IncreaseDate();
|
|
|
|
RunTileLoop();
|
|
|
|
CallVehicleTicks();
|
|
|
|
CallLandscapeTick();
|
2008-01-15 18:51:46 +00:00
|
|
|
ClearStorageChanges(true);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-07 15:10:11 +00:00
|
|
|
AI_RunGameLoop();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
CallWindowTickEvent();
|
|
|
|
NewsLoop();
|
2008-09-30 20:39:50 +00:00
|
|
|
_current_company = old_company;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-17 15:48:57 +00:00
|
|
|
/** Create an autosave. The default name is "autosave#.sav". However with
|
|
|
|
* the patch setting 'keep_all_autosave' the name defaults to company-name + date */
|
2007-03-07 11:47:46 +00:00
|
|
|
static void DoAutosave()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-06-17 15:48:57 +00:00
|
|
|
char buf[MAX_PATH];
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-02-11 14:04:40 +00:00
|
|
|
#if defined(PSP)
|
|
|
|
/* Autosaving in networking is too time expensive for the PSP */
|
2008-04-29 18:19:29 +00:00
|
|
|
if (_networking) return;
|
2007-02-11 14:04:40 +00:00
|
|
|
#endif /* PSP */
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
if (_settings_client.gui.keep_all_autosave && _local_company != COMPANY_SPECTATOR) {
|
|
|
|
SetDParam(0, _local_company);
|
2007-06-25 13:30:38 +00:00
|
|
|
SetDParam(1, _date);
|
2007-06-17 15:48:57 +00:00
|
|
|
GetString(buf, STR_4004, lastof(buf));
|
2007-08-06 06:23:44 +00:00
|
|
|
ttd_strlcat(buf, ".sav", lengthof(buf));
|
2007-06-17 15:48:57 +00:00
|
|
|
} else {
|
2008-05-29 15:13:28 +00:00
|
|
|
/* generate a savegame name and number according to _settings_client.gui.max_num_autosaves */
|
2007-06-17 15:48:57 +00:00
|
|
|
snprintf(buf, sizeof(buf), "autosave%d.sav", _autosave_ctr);
|
|
|
|
|
2008-05-29 15:13:28 +00:00
|
|
|
if (++_autosave_ctr >= _settings_client.gui.max_num_autosaves) _autosave_ctr = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-12-26 17:36:18 +00:00
|
|
|
DEBUG(sl, 2, "Autosaving to '%s'", buf);
|
2008-04-29 18:19:29 +00:00
|
|
|
if (SaveOrLoad(buf, SL_SAVE, AUTOSAVE_DIR) != SL_OK) {
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0);
|
2008-04-29 18:19:29 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void GameLoop()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-04-19 10:18:38 +00:00
|
|
|
ProcessAsyncSaveFinish();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* autosave game? */
|
2004-08-09 17:04:08 +00:00
|
|
|
if (_do_autosave) {
|
|
|
|
_do_autosave = false;
|
|
|
|
DoAutosave();
|
|
|
|
RedrawAutosave();
|
|
|
|
}
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* make a screenshot? */
|
2006-07-28 21:51:00 +00:00
|
|
|
if (IsScreenshotRequested()) ShowScreenshotResult(MakeScreenshot());
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* switch game mode? */
|
2006-02-14 07:32:45 +00:00
|
|
|
if (_switch_mode != SM_NONE) {
|
|
|
|
SwitchMode(_switch_mode);
|
2004-08-09 17:04:08 +00:00
|
|
|
_switch_mode = SM_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IncreaseSpriteLRU();
|
|
|
|
InteractiveRandom();
|
|
|
|
|
|
|
|
_caret_timer += 3;
|
2007-06-22 20:04:21 +00:00
|
|
|
_palette_animation_counter += 8;
|
2004-08-09 17:04:08 +00:00
|
|
|
CursorTick();
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Check for UDP stuff */
|
2006-10-12 14:59:27 +00:00
|
|
|
if (_network_available) NetworkUDPGameLoop();
|
2004-12-04 17:54:56 +00:00
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
if (_networking && !IsGeneratingWorld()) {
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Multiplayer */
|
2004-12-04 17:54:56 +00:00
|
|
|
NetworkGameLoop();
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2004-12-04 17:54:56 +00:00
|
|
|
if (_network_reconnect > 0 && --_network_reconnect == 0) {
|
2007-03-21 15:19:33 +00:00
|
|
|
/* This means that we want to reconnect to the last host
|
|
|
|
* We do this here, because it means that the network is really closed */
|
2008-05-29 20:21:28 +00:00
|
|
|
NetworkClientConnectGame(_settings_client.network.last_host, _settings_client.network.last_port);
|
2004-12-04 17:54:56 +00:00
|
|
|
}
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Singleplayer */
|
2004-09-12 15:29:37 +00:00
|
|
|
StateGameLoop();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-12-04 17:54:56 +00:00
|
|
|
#else
|
|
|
|
StateGameLoop();
|
|
|
|
#endif /* ENABLE_NETWORK */
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!_pause_game && HasBit(_display_opt, DO_FULL_ANIMATION)) DoPaletteAnimations();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-06 20:59:52 +00:00
|
|
|
if (!_pause_game || _cheats.build_in_pause.value) MoveAllTextEffects();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-03-26 04:16:39 +00:00
|
|
|
InputLoop();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-03-30 19:52:26 +00:00
|
|
|
MusicLoop();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void ConvertTownOwner()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-04-29 18:19:29 +00:00
|
|
|
for (TileIndex tile = 0; tile != MapSize(); tile++) {
|
2006-06-10 08:37:41 +00:00
|
|
|
switch (GetTileType(tile)) {
|
2007-07-29 23:42:59 +00:00
|
|
|
case MP_ROAD:
|
2008-09-18 15:32:20 +00:00
|
|
|
if (GB(_m[tile].m5, 4, 2) == ROAD_TILE_CROSSING && HasBit(_m[tile].m3, 7)) {
|
|
|
|
_m[tile].m3 = OWNER_TOWN;
|
2006-06-10 08:37:41 +00:00
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
|
|
|
case MP_TUNNELBRIDGE:
|
|
|
|
if (GetTileOwner(tile) & 0x80) SetTileOwner(tile, OWNER_TOWN);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-06-10 08:37:41 +00:00
|
|
|
default: break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* since savegame version 4.1, exclusive transport rights are stored at towns */
|
2007-03-07 11:47:46 +00:00
|
|
|
static void UpdateExclusiveRights()
|
2004-08-23 21:04:39 +00:00
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
Town *t;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
|
|
|
FOR_ALL_TOWNS(t) {
|
2008-09-30 20:39:50 +00:00
|
|
|
t->exclusivity = INVALID_COMPANY;
|
2004-08-23 21:04:39 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-23 21:29:25 +00:00
|
|
|
/* FIXME old exclusive rights status is not being imported (stored in s->blocked_months_obsolete)
|
2006-09-04 20:40:33 +00:00
|
|
|
* could be implemented this way:
|
|
|
|
* 1.) Go through all stations
|
2008-09-30 20:39:50 +00:00
|
|
|
* Build an array town_blocked[ town_id ][ company_id ]
|
|
|
|
* that stores if at least one station in that town is blocked for a company
|
2006-09-04 20:40:33 +00:00
|
|
|
* 2.) Go through that array, if you find a town that is not blocked for
|
2008-09-30 20:39:50 +00:00
|
|
|
* one company, but for all others, then give him exclusivity.
|
2006-09-04 20:40:33 +00:00
|
|
|
*/
|
2004-08-23 21:04:39 +00:00
|
|
|
}
|
|
|
|
|
2005-12-14 06:51:19 +00:00
|
|
|
static const byte convert_currency[] = {
|
2004-12-22 16:54:55 +00:00
|
|
|
0, 1, 12, 8, 3,
|
|
|
|
10, 14, 19, 4, 5,
|
|
|
|
9, 11, 13, 6, 17,
|
|
|
|
16, 22, 21, 7, 15,
|
|
|
|
18, 2, 20, };
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* since savegame version 4.2 the currencies are arranged differently */
|
2007-03-07 11:47:46 +00:00
|
|
|
static void UpdateCurrencies()
|
2004-12-22 16:54:55 +00:00
|
|
|
{
|
2008-06-05 11:26:38 +00:00
|
|
|
_settings_game.locale.currency = convert_currency[_settings_game.locale.currency];
|
2004-12-22 16:54:55 +00:00
|
|
|
}
|
|
|
|
|
2005-01-26 18:17:50 +00:00
|
|
|
/* Up to revision 1413 the invisible tiles at the southern border have not been
|
|
|
|
* MP_VOID, even though they should have. This is fixed by this function
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
static void UpdateVoidTiles()
|
2005-01-07 18:13:56 +00:00
|
|
|
{
|
2005-01-09 21:25:44 +00:00
|
|
|
uint i;
|
2005-01-26 18:17:50 +00:00
|
|
|
|
2006-02-24 19:52:26 +00:00
|
|
|
for (i = 0; i < MapMaxY(); ++i) MakeVoid(i * MapSizeX() + MapMaxX());
|
|
|
|
for (i = 0; i < MapSizeX(); ++i) MakeVoid(MapSizeX() * MapMaxY() + i);
|
2005-01-07 18:13:56 +00:00
|
|
|
}
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* since savegame version 6.0 each sign has an "owner", signs without owner (from old games are set to 255) */
|
2007-03-07 11:47:46 +00:00
|
|
|
static void UpdateSignOwner()
|
2005-01-25 15:38:36 +00:00
|
|
|
{
|
2006-08-22 16:38:50 +00:00
|
|
|
Sign *si;
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2006-08-22 16:38:50 +00:00
|
|
|
FOR_ALL_SIGNS(si) si->owner = OWNER_NONE;
|
2005-01-25 15:38:36 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
extern void UpdateOldAircraft();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-04-25 07:29:02 +00:00
|
|
|
|
|
|
|
static inline RailType UpdateRailType(RailType rt, RailType min)
|
|
|
|
{
|
|
|
|
return rt >= min ? (RailType)(rt + 1): rt;
|
|
|
|
}
|
|
|
|
|
2007-11-28 15:42:52 +00:00
|
|
|
/**
|
|
|
|
* Initialization of the windows and several kinds of caches.
|
|
|
|
* This is not done directly in AfterLoadGame because these
|
|
|
|
* functions require that all saveload conversions have been
|
|
|
|
* done. As people tend to add savegame conversion stuff after
|
|
|
|
* the intialization of the windows and caches quite some bugs
|
|
|
|
* had been made.
|
|
|
|
* Moving this out of there is both cleaner and less bug-prone.
|
|
|
|
*
|
|
|
|
* @return true if everything went according to plan, otherwise false.
|
|
|
|
*/
|
|
|
|
static bool InitializeWindowsAndCaches()
|
|
|
|
{
|
|
|
|
/* Initialize windows */
|
|
|
|
ResetWindowSystem();
|
|
|
|
SetupColorsAndInitialWindow();
|
|
|
|
|
2008-05-29 10:16:59 +00:00
|
|
|
extern void ResetViewportAfterLoadGame();
|
|
|
|
ResetViewportAfterLoadGame();
|
2007-11-28 15:42:52 +00:00
|
|
|
|
|
|
|
/* Update coordinates of the signs. */
|
|
|
|
UpdateAllStationVirtCoord();
|
|
|
|
UpdateAllSignVirtCoords();
|
|
|
|
UpdateAllTownVirtCoords();
|
|
|
|
UpdateAllWaypointSigns();
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
Company *c;
|
|
|
|
FOR_ALL_COMPANIES(c) {
|
|
|
|
/* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it
|
|
|
|
* accordingly if it is not the case. No need to set it on companies that are not been used already,
|
2007-12-28 04:20:56 +00:00
|
|
|
* thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */
|
2008-09-30 20:39:50 +00:00
|
|
|
if (_file_to_saveload.filetype == FT_SCENARIO && c->inaugurated_year != MIN_YEAR) {
|
|
|
|
c->inaugurated_year = _cur_year;
|
2008-05-13 21:36:09 +00:00
|
|
|
}
|
2007-12-28 04:20:56 +00:00
|
|
|
}
|
2007-11-28 15:42:52 +00:00
|
|
|
|
2008-05-13 21:36:09 +00:00
|
|
|
SetCachedEngineCounts();
|
2007-11-28 15:42:52 +00:00
|
|
|
|
2008-05-24 02:54:47 +00:00
|
|
|
/* Towns have a noise controlled number of airports system
|
|
|
|
* So each airport's noise value must be added to the town->noise_reached value
|
|
|
|
* Reset each town's noise_reached value to '0' before. */
|
|
|
|
UpdateAirportsNoise();
|
|
|
|
|
2008-07-24 15:19:26 +00:00
|
|
|
CheckTrainsLengths();
|
|
|
|
|
2007-11-28 15:42:52 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
bool AfterLoadGame()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-01-17 06:33:23 +00:00
|
|
|
TileIndex map_size = MapSize();
|
2008-09-30 20:39:50 +00:00
|
|
|
Company *c;
|
2005-01-12 11:21:28 +00:00
|
|
|
|
2008-06-03 18:35:58 +00:00
|
|
|
if (CheckSavegameVersion(98)) GamelogOldver();
|
|
|
|
|
|
|
|
GamelogTestRevision();
|
|
|
|
GamelogTestMode();
|
|
|
|
|
|
|
|
if (CheckSavegameVersion(98)) GamelogGRFAddList(_grfconfig);
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* in version 2.1 of the savegame, town owner was unified. */
|
2005-11-22 19:33:29 +00:00
|
|
|
if (CheckSavegameVersionOldStyle(2, 1)) ConvertTownOwner();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* from version 4.1 of the savegame, exclusive rights are stored at towns */
|
2005-11-22 19:33:29 +00:00
|
|
|
if (CheckSavegameVersionOldStyle(4, 1)) UpdateExclusiveRights();
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* from version 4.2 of the savegame, currencies are in a different order */
|
2005-11-22 19:33:29 +00:00
|
|
|
if (CheckSavegameVersionOldStyle(4, 2)) UpdateCurrencies();
|
2004-12-22 16:54:55 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* from version 6.1 of the savegame, signs have an "owner" */
|
2005-11-22 19:33:29 +00:00
|
|
|
if (CheckSavegameVersionOldStyle(6, 1)) UpdateSignOwner();
|
2005-01-25 15:38:36 +00:00
|
|
|
|
2004-12-30 10:29:28 +00:00
|
|
|
/* In old version there seems to be a problem that water is owned by
|
2008-03-18 12:28:21 +00:00
|
|
|
* OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current
|
|
|
|
* (4.3) version, so I just check when versions are older, and then
|
|
|
|
* walk through the whole map.. */
|
2005-11-22 19:33:29 +00:00
|
|
|
if (CheckSavegameVersionOldStyle(4, 3)) {
|
2007-01-17 06:33:23 +00:00
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
2008-09-30 20:39:50 +00:00
|
|
|
if (IsTileType(t, MP_WATER) && GetTileOwner(t) >= MAX_COMPANIES) {
|
2007-01-17 06:33:23 +00:00
|
|
|
SetTileOwner(t, OWNER_WATER);
|
|
|
|
}
|
|
|
|
}
|
2004-12-30 10:29:28 +00:00
|
|
|
}
|
|
|
|
|
2008-01-12 19:58:06 +00:00
|
|
|
if (CheckSavegameVersion(84)) {
|
2008-09-30 20:39:50 +00:00
|
|
|
FOR_ALL_COMPANIES(c) {
|
|
|
|
c->name = CopyFromOldName(c->name_1);
|
|
|
|
if (c->name != NULL) c->name_1 = STR_SV_UNNAMED;
|
|
|
|
c->president_name = CopyFromOldName(c->president_name_1);
|
|
|
|
if (c->president_name != NULL) c->president_name_1 = SPECSTR_PRESIDENT_NAME;
|
2008-01-12 19:58:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Station *st;
|
|
|
|
FOR_ALL_STATIONS(st) {
|
|
|
|
st->name = CopyFromOldName(st->string_id);
|
2008-09-15 22:45:18 +00:00
|
|
|
/* generating new name would be too much work for little effect, use the station name fallback */
|
|
|
|
if (st->name != NULL) st->string_id = STR_SV_STNAME_FALLBACK;
|
2008-01-12 19:58:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Town *t;
|
|
|
|
FOR_ALL_TOWNS(t) {
|
|
|
|
t->name = CopyFromOldName(t->townnametype);
|
2008-05-29 15:13:28 +00:00
|
|
|
if (t->name != NULL) t->townnametype = SPECSTR_TOWNNAME_START + _settings_game.game_creation.town_name;
|
2008-01-12 19:58:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Waypoint *wp;
|
|
|
|
FOR_ALL_WAYPOINTS(wp) {
|
|
|
|
wp->name = CopyFromOldName(wp->string);
|
|
|
|
wp->string = STR_EMPTY;
|
|
|
|
}
|
2008-09-16 11:19:07 +00:00
|
|
|
|
|
|
|
for (uint i = 0; i < GetSignPoolSize(); i++) {
|
2008-09-30 20:39:50 +00:00
|
|
|
/* invalid signs are determined by si->ower == INVALID_COMPANY now */
|
2008-09-16 11:19:07 +00:00
|
|
|
Sign *si = GetSign(i);
|
|
|
|
if (!si->IsValid() && si->name != NULL) {
|
|
|
|
si->owner = OWNER_NONE;
|
|
|
|
}
|
|
|
|
}
|
2008-01-12 19:58:06 +00:00
|
|
|
}
|
|
|
|
|
2008-04-19 08:21:55 +00:00
|
|
|
/* From this point the old names array is cleared. */
|
|
|
|
ResetOldNames();
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* convert road side to my format. */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.vehicle.road_side) _settings_game.vehicle.road_side = 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-13 17:42:50 +00:00
|
|
|
/* Check if all NewGRFs are present, we are very strict in MP mode */
|
2007-03-06 19:33:28 +00:00
|
|
|
GRFListCompatibility gcf_res = IsGoodGRFConfigList();
|
2007-06-24 12:27:11 +00:00
|
|
|
if (_networking && gcf_res != GLC_ALL_GOOD) {
|
|
|
|
SetSaveLoadError(STR_NETWORK_ERR_CLIENT_NEWGRF_MISMATCH);
|
|
|
|
return false;
|
|
|
|
}
|
2007-01-13 17:42:50 +00:00
|
|
|
|
|
|
|
switch (gcf_res) {
|
2007-03-06 19:33:28 +00:00
|
|
|
case GLC_COMPATIBLE: _switch_mode_errorstr = STR_NEWGRF_COMPATIBLE_LOAD_WARNING; break;
|
2008-03-04 12:14:34 +00:00
|
|
|
case GLC_NOT_FOUND: _switch_mode_errorstr = STR_NEWGRF_DISABLED_WARNING; _pause_game = -1; break;
|
2007-01-13 21:28:46 +00:00
|
|
|
default: break;
|
2007-01-13 17:42:50 +00:00
|
|
|
}
|
2006-12-04 08:30:04 +00:00
|
|
|
|
2006-12-18 15:34:12 +00:00
|
|
|
/* Update current year
|
|
|
|
* must be done before loading sprites as some newgrfs check it */
|
|
|
|
SetDate(_date);
|
|
|
|
|
2008-04-29 21:31:29 +00:00
|
|
|
/* Force dynamic engines off when loading older savegames */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (CheckSavegameVersion(95)) _settings_game.vehicle.dynamic_engines = 0;
|
2008-04-29 21:31:29 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Load the sprites */
|
2004-08-09 17:04:08 +00:00
|
|
|
GfxLoadSprites();
|
2006-11-24 18:39:22 +00:00
|
|
|
LoadStringWidthTable();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-04-29 21:31:29 +00:00
|
|
|
/* Copy temporary data to Engine pool */
|
|
|
|
CopyTempEngineData();
|
|
|
|
|
2006-01-04 20:18:39 +00:00
|
|
|
/* Connect front and rear engines of multiheaded trains and converts
|
|
|
|
* subtype to the new format */
|
|
|
|
if (CheckSavegameVersionOldStyle(17, 1)) ConvertOldMultiheadToNew();
|
|
|
|
|
2006-01-29 23:04:51 +00:00
|
|
|
/* Connect front and rear engines of multiheaded trains */
|
|
|
|
ConnectMultiheadedTrains();
|
2006-01-18 15:05:01 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* reinit the landscape variables (landscape might have changed) */
|
2004-08-09 17:04:08 +00:00
|
|
|
InitializeLandscapeVariables(true);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Update all vehicles */
|
2008-01-01 15:06:37 +00:00
|
|
|
AfterLoadVehicles(true);
|
2005-03-24 17:03:37 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Update all waypoints */
|
2005-11-22 19:33:29 +00:00
|
|
|
if (CheckSavegameVersion(12)) FixOldWaypoints();
|
2005-03-24 17:03:37 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* in version 2.2 of the savegame, we have new airports */
|
2005-11-22 19:33:29 +00:00
|
|
|
if (CheckSavegameVersionOldStyle(2, 2)) UpdateOldAircraft();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
AfterLoadTown();
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* make sure there is a town in the game */
|
2005-11-14 19:48:04 +00:00
|
|
|
if (_game_mode == GM_NORMAL && !ClosestTownFromTile(0, (uint)-1)) {
|
2007-06-24 12:27:11 +00:00
|
|
|
SetSaveLoadError(STR_NO_TOWN_IN_SCENARIO);
|
2004-08-09 17:04:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-02-08 19:57:56 +00:00
|
|
|
/* The void tiles on the southern border used to belong to a wrong class (pre 4.3).
|
|
|
|
* This problem appears in savegame version 21 too, see r3455. But after loading the
|
|
|
|
* savegame and saving again, the buggy map array could be converted to new savegame
|
|
|
|
* version. It didn't show up before r12070. */
|
|
|
|
if (CheckSavegameVersion(87)) UpdateVoidTiles();
|
2005-01-07 18:13:56 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* If Load Scenario / New (Scenario) Game is used,
|
2008-09-30 20:39:50 +00:00
|
|
|
* a company does not exist yet. So create one here.
|
|
|
|
* 1 exeption: network-games. Those can have 0 companies
|
2007-05-04 22:45:37 +00:00
|
|
|
* But this exeption is not true for non dedicated network_servers! */
|
2008-09-30 20:39:50 +00:00
|
|
|
if (!IsValidCompanyID(COMPANY_FIRST) && (!_networking || (_networking && _network_server && !_network_dedicated)))
|
|
|
|
DoStartupNewCompany(false);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-16 23:55:22 +00:00
|
|
|
if (CheckSavegameVersion(72)) {
|
|
|
|
/* Locks/shiplifts in very old savegames had OWNER_WATER as owner */
|
|
|
|
for (TileIndex t = 0; t < MapSize(); t++) {
|
|
|
|
switch (GetTileType(t)) {
|
|
|
|
default: break;
|
|
|
|
|
|
|
|
case MP_WATER:
|
|
|
|
if (GetWaterTileType(t) == WATER_TILE_LOCK && GetTileOwner(t) == OWNER_WATER) SetTileOwner(t, OWNER_NONE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_STATION: {
|
2007-11-20 13:35:54 +00:00
|
|
|
if (HasBit(_m[t].m6, 3)) SetBit(_m[t].m6, 2);
|
2007-07-16 23:55:22 +00:00
|
|
|
StationGfx gfx = GetStationGfx(t);
|
|
|
|
StationType st;
|
2007-11-24 10:38:43 +00:00
|
|
|
if ( IsInsideMM(gfx, 0, 8)) { // Railway station
|
2007-07-16 23:55:22 +00:00
|
|
|
st = STATION_RAIL;
|
|
|
|
SetStationGfx(t, gfx - 0);
|
2007-11-24 10:38:43 +00:00
|
|
|
} else if (IsInsideMM(gfx, 8, 67)) { // Airport
|
2007-07-16 23:55:22 +00:00
|
|
|
st = STATION_AIRPORT;
|
|
|
|
SetStationGfx(t, gfx - 8);
|
2007-11-24 10:38:43 +00:00
|
|
|
} else if (IsInsideMM(gfx, 67, 71)) { // Truck
|
2007-07-16 23:55:22 +00:00
|
|
|
st = STATION_TRUCK;
|
|
|
|
SetStationGfx(t, gfx - 67);
|
2007-11-24 10:38:43 +00:00
|
|
|
} else if (IsInsideMM(gfx, 71, 75)) { // Bus
|
2007-07-16 23:55:22 +00:00
|
|
|
st = STATION_BUS;
|
|
|
|
SetStationGfx(t, gfx - 71);
|
|
|
|
} else if (gfx == 75) { // Oil rig
|
|
|
|
st = STATION_OILRIG;
|
|
|
|
SetStationGfx(t, gfx - 75);
|
2007-11-24 10:38:43 +00:00
|
|
|
} else if (IsInsideMM(gfx, 76, 82)) { // Dock
|
2007-07-16 23:55:22 +00:00
|
|
|
st = STATION_DOCK;
|
|
|
|
SetStationGfx(t, gfx - 76);
|
|
|
|
} else if (gfx == 82) { // Buoy
|
|
|
|
st = STATION_BUOY;
|
|
|
|
SetStationGfx(t, gfx - 82);
|
2007-11-24 10:38:43 +00:00
|
|
|
} else if (IsInsideMM(gfx, 83, 168)) { // Extended airport
|
2007-07-16 23:55:22 +00:00
|
|
|
st = STATION_AIRPORT;
|
|
|
|
SetStationGfx(t, gfx - 83 + 67 - 8);
|
2007-11-24 10:38:43 +00:00
|
|
|
} else if (IsInsideMM(gfx, 168, 170)) { // Drive through truck
|
2007-07-16 23:55:22 +00:00
|
|
|
st = STATION_TRUCK;
|
|
|
|
SetStationGfx(t, gfx - 168 + GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET);
|
2007-11-24 10:38:43 +00:00
|
|
|
} else if (IsInsideMM(gfx, 170, 172)) { // Drive through bus
|
2007-07-16 23:55:22 +00:00
|
|
|
st = STATION_BUS;
|
|
|
|
SetStationGfx(t, gfx - 170 + GFX_TRUCK_BUS_DRIVETHROUGH_OFFSET);
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
SB(_m[t].m6, 3, 3, st);
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-31 09:49:02 +00:00
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
switch (GetTileType(t)) {
|
2007-02-21 07:37:31 +00:00
|
|
|
case MP_STATION: {
|
|
|
|
Station *st = GetStationByTile(t);
|
|
|
|
|
|
|
|
st->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
|
|
|
|
|
2007-01-31 09:49:02 +00:00
|
|
|
switch (GetStationType(t)) {
|
|
|
|
case STATION_TRUCK:
|
|
|
|
case STATION_BUS:
|
|
|
|
if (CheckSavegameVersion(6)) {
|
2007-02-21 07:37:31 +00:00
|
|
|
/* From this version on there can be multiple road stops of the
|
|
|
|
* same type per station. Convert the existing stops to the new
|
|
|
|
* internal data structure. */
|
2007-01-31 09:49:02 +00:00
|
|
|
RoadStop *rs = new RoadStop(t);
|
|
|
|
if (rs == NULL) error("Too many road stops in savegame");
|
|
|
|
|
|
|
|
RoadStop **head =
|
|
|
|
IsTruckStop(t) ? &st->truck_stops : &st->bus_stops;
|
|
|
|
*head = rs;
|
|
|
|
}
|
|
|
|
break;
|
2007-01-31 06:25:46 +00:00
|
|
|
|
2007-01-31 10:50:12 +00:00
|
|
|
case STATION_OILRIG: {
|
|
|
|
/* Very old savegames sometimes have phantom oil rigs, i.e.
|
|
|
|
* an oil rig which got shut down, but not completly removed from
|
|
|
|
* the map
|
|
|
|
*/
|
2007-10-16 20:44:59 +00:00
|
|
|
TileIndex t1 = TILE_ADDXY(t, 0, 1);
|
2007-01-31 21:38:09 +00:00
|
|
|
if (IsTileType(t1, MP_INDUSTRY) &&
|
2007-10-16 20:44:59 +00:00
|
|
|
GetIndustryGfx(t1) == GFX_OILRIG_1) {
|
2007-01-31 21:38:09 +00:00
|
|
|
/* The internal encoding of oil rigs was changed twice.
|
|
|
|
* It was 3 (till 2.2) and later 5 (till 5.1).
|
|
|
|
* Setting it unconditionally does not hurt.
|
|
|
|
*/
|
|
|
|
GetStationByTile(t)->airport_type = AT_OILRIG;
|
|
|
|
} else {
|
2007-01-31 10:50:12 +00:00
|
|
|
DeleteOilRig(t);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-31 09:49:02 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
break;
|
2007-02-21 07:37:31 +00:00
|
|
|
}
|
2007-01-31 09:49:02 +00:00
|
|
|
|
|
|
|
default: break;
|
2007-01-31 06:25:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-22 19:33:29 +00:00
|
|
|
/* In version 6.1 we put the town index in the map-array. To do this, we need
|
|
|
|
* to use m2 (16bit big), so we need to clean m2, and that is where this is
|
|
|
|
* all about ;) */
|
|
|
|
if (CheckSavegameVersionOldStyle(6, 1)) {
|
2007-01-17 06:33:23 +00:00
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
switch (GetTileType(t)) {
|
2006-06-08 18:31:54 +00:00
|
|
|
case MP_HOUSE:
|
2007-01-17 06:33:23 +00:00
|
|
|
_m[t].m4 = _m[t].m2;
|
|
|
|
SetTownIndex(t, CalcClosestTownFromTile(t, (uint)-1)->index);
|
2006-06-08 18:31:54 +00:00
|
|
|
break;
|
|
|
|
|
2007-07-29 23:42:59 +00:00
|
|
|
case MP_ROAD:
|
2007-01-17 06:33:23 +00:00
|
|
|
_m[t].m4 |= (_m[t].m2 << 4);
|
2008-09-18 15:32:20 +00:00
|
|
|
if ((GB(_m[t].m5, 4, 2) == ROAD_TILE_CROSSING ? (Owner)_m[t].m3 : GetTileOwner(t)) == OWNER_TOWN) {
|
2007-01-17 06:33:23 +00:00
|
|
|
SetTownIndex(t, CalcClosestTownFromTile(t, (uint)-1)->index);
|
2006-06-08 18:31:54 +00:00
|
|
|
} else {
|
2007-01-17 06:33:23 +00:00
|
|
|
SetTownIndex(t, 0);
|
2006-06-08 18:31:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
2005-02-02 14:17:13 +00:00
|
|
|
}
|
2007-01-17 06:33:23 +00:00
|
|
|
}
|
2005-02-02 14:17:13 +00:00
|
|
|
}
|
|
|
|
|
2005-11-22 19:33:29 +00:00
|
|
|
/* From version 9.0, we update the max passengers of a town (was sometimes negative
|
|
|
|
* before that. */
|
|
|
|
if (CheckSavegameVersion(9)) {
|
2005-02-17 10:56:19 +00:00
|
|
|
Town *t;
|
2005-11-14 19:48:04 +00:00
|
|
|
FOR_ALL_TOWNS(t) UpdateTownMaxPass(t);
|
2005-02-17 10:56:19 +00:00
|
|
|
}
|
|
|
|
|
2005-11-22 19:33:29 +00:00
|
|
|
/* From version 16.0, we included autorenew on engines, which are now saved, but
|
|
|
|
* of course, we do need to initialize them for older savegames. */
|
|
|
|
if (CheckSavegameVersion(16)) {
|
2008-09-30 20:39:50 +00:00
|
|
|
FOR_ALL_COMPANIES(c) {
|
|
|
|
c->engine_renew_list = NULL;
|
|
|
|
c->engine_renew = false;
|
|
|
|
c->engine_renew_months = -6;
|
|
|
|
c->engine_renew_money = 100000;
|
2005-08-06 16:07:22 +00:00
|
|
|
}
|
2006-12-26 12:56:48 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
/* When loading a game, _local_company is not yet set to the correct value.
|
2006-12-26 12:56:48 +00:00
|
|
|
* However, in a dedicated server we are a spectator, so nothing needs to
|
2008-09-30 20:39:50 +00:00
|
|
|
* happen. In case we are not a dedicated server, the local company always
|
|
|
|
* becomes company 0, unless we are in the scenario editor where all the
|
|
|
|
* companies are 'invalid'.
|
2006-12-26 12:56:48 +00:00
|
|
|
*/
|
2008-09-30 20:39:50 +00:00
|
|
|
if (!_network_dedicated && IsValidCompanyID(COMPANY_FIRST)) {
|
|
|
|
c = GetCompany(COMPANY_FIRST);
|
|
|
|
c->engine_renew = _settings_client.gui.autorenew;
|
|
|
|
c->engine_renew_months = _settings_client.gui.autorenew_months;
|
|
|
|
c->engine_renew_money = _settings_client.gui.autorenew_money;
|
2005-08-10 21:16:38 +00:00
|
|
|
}
|
2005-08-06 16:07:22 +00:00
|
|
|
}
|
|
|
|
|
2007-05-20 19:14:08 +00:00
|
|
|
if (CheckSavegameVersion(48)) {
|
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
switch (GetTileType(t)) {
|
|
|
|
case MP_RAILWAY:
|
|
|
|
if (IsPlainRailTile(t)) {
|
|
|
|
/* Swap ground type and signal type for plain rail tiles, so the
|
|
|
|
* ground type uses the same bits as for depots and waypoints. */
|
|
|
|
uint tmp = GB(_m[t].m4, 0, 4);
|
|
|
|
SB(_m[t].m4, 0, 4, GB(_m[t].m2, 0, 4));
|
|
|
|
SB(_m[t].m2, 0, 4, tmp);
|
2007-11-19 21:02:30 +00:00
|
|
|
} else if (HasBit(_m[t].m5, 2)) {
|
2007-05-20 19:14:08 +00:00
|
|
|
/* Split waypoint and depot rail type and remove the subtype. */
|
2007-11-19 21:32:20 +00:00
|
|
|
ClrBit(_m[t].m5, 2);
|
|
|
|
ClrBit(_m[t].m5, 6);
|
2007-05-20 19:14:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-29 23:42:59 +00:00
|
|
|
case MP_ROAD:
|
2007-05-20 19:14:08 +00:00
|
|
|
/* Swap m3 and m4, so the track type for rail crossings is the
|
|
|
|
* same as for normal rail. */
|
|
|
|
Swap(_m[t].m3, _m[t].m4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CheckSavegameVersion(61)) {
|
|
|
|
/* Added the RoadType */
|
2007-05-29 08:19:37 +00:00
|
|
|
bool old_bridge = CheckSavegameVersion(42);
|
2007-05-20 19:14:08 +00:00
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
switch(GetTileType(t)) {
|
2007-07-29 23:42:59 +00:00
|
|
|
case MP_ROAD:
|
2007-05-20 19:14:08 +00:00
|
|
|
SB(_m[t].m5, 6, 2, GB(_m[t].m5, 4, 2));
|
|
|
|
switch (GetRoadTileType(t)) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case ROAD_TILE_NORMAL:
|
|
|
|
SB(_m[t].m4, 0, 4, GB(_m[t].m5, 0, 4));
|
|
|
|
SB(_m[t].m4, 4, 4, 0);
|
|
|
|
SB(_m[t].m6, 2, 4, 0);
|
|
|
|
break;
|
|
|
|
case ROAD_TILE_CROSSING:
|
|
|
|
SB(_m[t].m4, 5, 2, GB(_m[t].m5, 2, 2));
|
|
|
|
break;
|
|
|
|
case ROAD_TILE_DEPOT: break;
|
|
|
|
}
|
|
|
|
SetRoadTypes(t, ROADTYPES_ROAD);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_STATION:
|
|
|
|
if (IsRoadStop(t)) SetRoadTypes(t, ROADTYPES_ROAD);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_TUNNELBRIDGE:
|
2007-05-29 08:19:37 +00:00
|
|
|
/* Middle part of "old" bridges */
|
2008-01-23 14:51:36 +00:00
|
|
|
if (old_bridge && IsBridge(t) && HasBit(_m[t].m5, 6)) break;
|
|
|
|
if (((old_bridge && IsBridge(t)) ? (TransportType)GB(_m[t].m5, 1, 2) : GetTunnelBridgeTransportType(t)) == TRANSPORT_ROAD) {
|
2007-05-20 19:14:08 +00:00
|
|
|
SetRoadTypes(t, ROADTYPES_ROAD);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-27 12:38:02 +00:00
|
|
|
if (CheckSavegameVersion(42)) {
|
|
|
|
Vehicle* v;
|
|
|
|
|
2007-01-17 06:33:23 +00:00
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
if (MayHaveBridgeAbove(t)) ClearBridgeMiddle(t);
|
|
|
|
if (IsBridgeTile(t)) {
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(_m[t].m5, 6)) { // middle part
|
2007-01-17 06:33:23 +00:00
|
|
|
Axis axis = (Axis)GB(_m[t].m5, 0, 1);
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(_m[t].m5, 5)) { // transport route under bridge?
|
2007-01-17 06:33:23 +00:00
|
|
|
if (GB(_m[t].m5, 3, 2) == TRANSPORT_RAIL) {
|
2006-12-27 12:38:02 +00:00
|
|
|
MakeRailNormal(
|
2007-01-17 06:33:23 +00:00
|
|
|
t,
|
|
|
|
GetTileOwner(t),
|
2006-12-27 12:38:02 +00:00
|
|
|
axis == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X,
|
2007-01-17 06:33:23 +00:00
|
|
|
GetRailType(t)
|
2006-12-27 12:38:02 +00:00
|
|
|
);
|
|
|
|
} else {
|
2007-01-17 06:33:23 +00:00
|
|
|
TownID town = IsTileOwner(t, OWNER_TOWN) ? ClosestTownFromTile(t, (uint)-1)->index : 0;
|
2006-12-27 12:38:02 +00:00
|
|
|
|
|
|
|
MakeRoadNormal(
|
2007-01-17 06:33:23 +00:00
|
|
|
t,
|
2006-12-27 12:38:02 +00:00
|
|
|
axis == AXIS_X ? ROAD_Y : ROAD_X,
|
2007-05-20 19:14:08 +00:00
|
|
|
ROADTYPES_ROAD,
|
|
|
|
town,
|
|
|
|
GetTileOwner(t), OWNER_NONE, OWNER_NONE
|
2006-12-27 12:38:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
} else {
|
2007-01-17 06:33:23 +00:00
|
|
|
if (GB(_m[t].m5, 3, 2) == 0) {
|
|
|
|
MakeClear(t, CLEAR_GRASS, 3);
|
2006-12-27 12:38:02 +00:00
|
|
|
} else {
|
2008-01-24 14:57:43 +00:00
|
|
|
if (GetTileSlope(t, NULL) != SLOPE_FLAT) {
|
|
|
|
MakeShore(t);
|
|
|
|
} else {
|
|
|
|
if (GetTileOwner(t) == OWNER_WATER) {
|
|
|
|
MakeWater(t);
|
|
|
|
} else {
|
|
|
|
MakeCanal(t, GetTileOwner(t), Random());
|
|
|
|
}
|
|
|
|
}
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
|
|
|
}
|
2007-01-17 06:33:23 +00:00
|
|
|
SetBridgeMiddle(t, axis);
|
2006-12-27 12:38:02 +00:00
|
|
|
} else { // ramp
|
2007-01-17 06:33:23 +00:00
|
|
|
Axis axis = (Axis)GB(_m[t].m5, 0, 1);
|
|
|
|
uint north_south = GB(_m[t].m5, 5, 1);
|
2006-12-27 12:38:02 +00:00
|
|
|
DiagDirection dir = ReverseDiagDir(XYNSToDiagDir(axis, north_south));
|
2007-01-17 06:33:23 +00:00
|
|
|
TransportType type = (TransportType)GB(_m[t].m5, 1, 2);
|
2006-12-27 12:38:02 +00:00
|
|
|
|
2007-01-17 06:33:23 +00:00
|
|
|
_m[t].m5 = 1 << 7 | type << 2 | dir;
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type != VEH_TRAIN && v->type != VEH_ROAD) continue;
|
2006-12-27 12:38:02 +00:00
|
|
|
if (IsBridgeTile(v->tile)) {
|
2007-12-16 15:38:51 +00:00
|
|
|
DiagDirection dir = GetTunnelBridgeDirection(v->tile);
|
2006-12-27 12:38:02 +00:00
|
|
|
|
|
|
|
if (dir != DirToDiagDir(v->direction)) continue;
|
|
|
|
switch (dir) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case DIAGDIR_NE: if ((v->x_pos & 0xF) != 0) continue; break;
|
|
|
|
case DIAGDIR_SE: if ((v->y_pos & 0xF) != TILE_SIZE - 1) continue; break;
|
|
|
|
case DIAGDIR_SW: if ((v->x_pos & 0xF) != TILE_SIZE - 1) continue; break;
|
|
|
|
case DIAGDIR_NW: if ((v->y_pos & 0xF) != 0) continue; break;
|
|
|
|
}
|
|
|
|
} else if (v->z_pos > GetSlopeZ(v->x_pos, v->y_pos)) {
|
|
|
|
v->tile = GetNorthernBridgeEnd(v->tile);
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_TRAIN) {
|
2007-01-10 18:56:51 +00:00
|
|
|
v->u.rail.track = TRACK_BIT_WORMHOLE;
|
2006-12-27 12:38:02 +00:00
|
|
|
} else {
|
2007-02-13 22:27:27 +00:00
|
|
|
v->u.road.state = RVSB_WORMHOLE;
|
2006-12-27 12:38:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-29 16:30:26 +00:00
|
|
|
/* Elrails got added in rev 24 */
|
|
|
|
if (CheckSavegameVersion(24)) {
|
2006-07-26 03:33:12 +00:00
|
|
|
Vehicle *v;
|
2006-04-25 07:29:02 +00:00
|
|
|
RailType min_rail = RAILTYPE_ELECTRIC;
|
2006-03-29 16:30:26 +00:00
|
|
|
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_TRAIN) {
|
2007-01-24 07:14:09 +00:00
|
|
|
RailType rt = RailVehInfo(v->engine_type)->railtype;
|
2006-03-29 16:30:26 +00:00
|
|
|
|
|
|
|
v->u.rail.railtype = rt;
|
2006-04-25 07:29:02 +00:00
|
|
|
if (rt == RAILTYPE_ELECTRIC) min_rail = RAILTYPE_RAIL;
|
2006-03-29 16:30:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* .. so we convert the entire map from normal to elrail (so maintain "fairness") */
|
2007-01-17 06:33:23 +00:00
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
2006-03-29 16:30:26 +00:00
|
|
|
switch (GetTileType(t)) {
|
|
|
|
case MP_RAILWAY:
|
2006-04-25 07:29:02 +00:00
|
|
|
SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
|
2006-03-29 16:30:26 +00:00
|
|
|
break;
|
|
|
|
|
2007-07-29 23:42:59 +00:00
|
|
|
case MP_ROAD:
|
2006-04-25 07:29:02 +00:00
|
|
|
if (IsLevelCrossing(t)) {
|
2007-02-27 23:36:28 +00:00
|
|
|
SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
|
2006-04-25 07:29:02 +00:00
|
|
|
}
|
2006-03-29 16:30:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_STATION:
|
2006-06-27 21:25:53 +00:00
|
|
|
if (IsRailwayStation(t)) {
|
2006-04-25 07:29:02 +00:00
|
|
|
SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
|
|
|
|
}
|
2006-03-29 16:30:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_TUNNELBRIDGE:
|
2007-12-16 19:30:42 +00:00
|
|
|
if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) {
|
|
|
|
SetRailType(t, UpdateRailType(GetRailType(t), min_rail));
|
2006-03-29 16:30:26 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
2008-07-24 15:19:26 +00:00
|
|
|
if (v->type == VEH_TRAIN && (IsFrontEngine(v) || IsFreeWagon(v))) TrainConsistChanged(v, true);
|
2006-03-29 16:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
/* In version 16.1 of the savegame a company can decide if trains, which get
|
2005-12-29 12:42:59 +00:00
|
|
|
* replaced, shall keep their old length. In all prior versions, just default
|
|
|
|
* to false */
|
2005-11-22 19:33:29 +00:00
|
|
|
if (CheckSavegameVersionOldStyle(16, 1)) {
|
2008-09-30 20:39:50 +00:00
|
|
|
FOR_ALL_COMPANIES(c) c->renew_keep_length = false;
|
2005-11-07 23:20:47 +00:00
|
|
|
}
|
|
|
|
|
2005-11-16 22:20:15 +00:00
|
|
|
/* In version 17, ground type is moved from m2 to m4 for depots and
|
|
|
|
* waypoints to make way for storing the index in m2. The custom graphics
|
|
|
|
* id which was stored in m4 is now saved as a grf/id reference in the
|
|
|
|
* waypoint struct. */
|
2005-11-22 19:33:29 +00:00
|
|
|
if (CheckSavegameVersion(17)) {
|
2005-11-16 22:20:15 +00:00
|
|
|
Waypoint *wp;
|
|
|
|
|
|
|
|
FOR_ALL_WAYPOINTS(wp) {
|
2006-08-22 15:33:35 +00:00
|
|
|
if (wp->deleted == 0) {
|
2006-04-27 18:28:56 +00:00
|
|
|
const StationSpec *statspec = NULL;
|
2005-11-16 22:20:15 +00:00
|
|
|
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(_m[wp->xy].m3, 4))
|
2006-04-27 18:28:56 +00:00
|
|
|
statspec = GetCustomStationSpec(STAT_CLASS_WAYP, _m[wp->xy].m4 + 1);
|
2005-11-16 22:20:15 +00:00
|
|
|
|
2006-04-27 18:28:56 +00:00
|
|
|
if (statspec != NULL) {
|
2005-11-16 22:20:15 +00:00
|
|
|
wp->stat_id = _m[wp->xy].m4 + 1;
|
2007-04-11 21:04:03 +00:00
|
|
|
wp->grfid = statspec->grffile->grfid;
|
2006-04-27 18:28:56 +00:00
|
|
|
wp->localidx = statspec->localidx;
|
2005-11-16 22:20:15 +00:00
|
|
|
} else {
|
2007-03-21 15:19:33 +00:00
|
|
|
/* No custom graphics set, so set to default. */
|
2005-11-16 22:20:15 +00:00
|
|
|
wp->stat_id = 0;
|
|
|
|
wp->grfid = 0;
|
|
|
|
wp->localidx = 0;
|
|
|
|
}
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Move ground type bits from m2 to m4. */
|
2005-11-16 22:20:15 +00:00
|
|
|
_m[wp->xy].m4 = GB(_m[wp->xy].m2, 0, 4);
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Store waypoint index in the tile. */
|
2005-11-16 22:20:15 +00:00
|
|
|
_m[wp->xy].m2 = wp->index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* As of version 17, we recalculate the custom graphic ID of waypoints
|
|
|
|
* from the GRF ID / station index. */
|
2006-12-21 00:13:56 +00:00
|
|
|
AfterLoadWaypoints();
|
2005-11-16 22:20:15 +00:00
|
|
|
}
|
|
|
|
|
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
- The only change is that the nsignalsw.grf file is kept and that existing nightlies with PBS signals get those signals converted to combo-signals.
2006-01-29 18:57:26 +00:00
|
|
|
/* From version 15, we moved a semaphore bit from bit 2 to bit 3 in m4, making
|
|
|
|
* room for PBS. Now in version 21 move it back :P. */
|
|
|
|
if (CheckSavegameVersion(21) && !CheckSavegameVersion(15)) {
|
2007-01-17 06:33:23 +00:00
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
2007-01-17 06:54:03 +00:00
|
|
|
switch (GetTileType(t)) {
|
|
|
|
case MP_RAILWAY:
|
|
|
|
if (HasSignals(t)) {
|
2007-03-21 15:19:33 +00:00
|
|
|
/* convert PBS signals to combo-signals */
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(_m[t].m2, 2)) SetSignalType(t, TRACK_X, SIGTYPE_COMBO);
|
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
- The only change is that the nsignalsw.grf file is kept and that existing nightlies with PBS signals get those signals converted to combo-signals.
2006-01-29 18:57:26 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* move the signal variant back */
|
2007-11-19 21:02:30 +00:00
|
|
|
SetSignalVariant(t, TRACK_X, HasBit(_m[t].m2, 3) ? SIG_SEMAPHORE : SIG_ELECTRIC);
|
2007-11-19 21:32:20 +00:00
|
|
|
ClrBit(_m[t].m2, 3);
|
2007-01-17 06:54:03 +00:00
|
|
|
}
|
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
/* Clear PBS reservation on track */
|
2008-04-17 18:24:45 +00:00
|
|
|
if (!IsRailDepotTile(t)) {
|
2007-01-17 06:54:03 +00:00
|
|
|
SB(_m[t].m4, 4, 4, 0);
|
|
|
|
} else {
|
2007-11-19 21:32:20 +00:00
|
|
|
ClrBit(_m[t].m3, 6);
|
2007-01-17 06:54:03 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-07-29 23:42:59 +00:00
|
|
|
case MP_ROAD: /* Clear PBS reservation on crossing */
|
2007-11-19 21:32:20 +00:00
|
|
|
if (IsLevelCrossing(t)) ClrBit(_m[t].m5, 0);
|
2007-01-17 06:54:03 +00:00
|
|
|
break;
|
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
- The only change is that the nsignalsw.grf file is kept and that existing nightlies with PBS signals get those signals converted to combo-signals.
2006-01-29 18:57:26 +00:00
|
|
|
|
2007-03-21 15:19:33 +00:00
|
|
|
case MP_STATION: /* Clear PBS reservation on station */
|
2007-11-19 21:32:20 +00:00
|
|
|
ClrBit(_m[t].m3, 6);
|
2007-01-17 06:54:03 +00:00
|
|
|
break;
|
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
- The only change is that the nsignalsw.grf file is kept and that existing nightlies with PBS signals get those signals converted to combo-signals.
2006-01-29 18:57:26 +00:00
|
|
|
|
2007-01-17 06:54:03 +00:00
|
|
|
default: break;
|
|
|
|
}
|
2007-01-17 06:33:23 +00:00
|
|
|
}
|
(svn r3472) - [PBS] Remove from trunk. Anyone interested can still find it in branch/pbs. This reverts revisions r3158, r3140, r3075, r2977, r2674, r2625, r2621, r2529, r2528, r2525, r2524, r2519, r2517, r2516, r2507, r2499. (in conjunction with Tron)
- The only change is that the nsignalsw.grf file is kept and that existing nightlies with PBS signals get those signals converted to combo-signals.
2006-01-29 18:57:26 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 14:25:32 +00:00
|
|
|
if (CheckSavegameVersion(25)) {
|
|
|
|
Vehicle *v;
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_ROAD) {
|
2006-04-03 14:25:32 +00:00
|
|
|
v->vehstatus &= ~0x40;
|
|
|
|
v->u.road.slot = NULL;
|
|
|
|
v->u.road.slot_age = 0;
|
|
|
|
}
|
|
|
|
}
|
2007-01-14 23:09:25 +00:00
|
|
|
} else {
|
|
|
|
Vehicle *v;
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_ROAD && v->u.road.slot != NULL) v->u.road.slot->num_vehicles++;
|
2007-01-14 23:09:25 +00:00
|
|
|
}
|
2006-04-03 14:25:32 +00:00
|
|
|
}
|
|
|
|
|
2006-04-18 08:50:17 +00:00
|
|
|
if (CheckSavegameVersion(26)) {
|
|
|
|
Station *st;
|
|
|
|
FOR_ALL_STATIONS(st) {
|
2007-03-08 16:27:54 +00:00
|
|
|
st->last_vehicle_type = VEH_INVALID;
|
2006-04-18 08:50:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-27 16:12:16 +00:00
|
|
|
YapfNotifyTrackLayoutChange(INVALID_TILE, INVALID_TRACK);
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
if (CheckSavegameVersion(34)) FOR_ALL_COMPANIES(c) ResetCompanyLivery(c);
|
2006-09-15 12:27:00 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
FOR_ALL_COMPANIES(c) {
|
|
|
|
c->avail_railtypes = GetCompanyRailtypes(c->index);
|
|
|
|
c->avail_roadtypes = GetCompanyRoadtypes(c->index);
|
2007-05-25 08:13:01 +00:00
|
|
|
}
|
2005-07-20 22:02:58 +00:00
|
|
|
|
2006-05-06 21:46:26 +00:00
|
|
|
if (!CheckSavegameVersion(27)) AfterLoadStations();
|
|
|
|
|
2006-08-20 18:40:57 +00:00
|
|
|
/* Time starts at 0 instead of 1920.
|
|
|
|
* Account for this in older games by adding an offset */
|
|
|
|
if (CheckSavegameVersion(31)) {
|
|
|
|
Station *st;
|
|
|
|
Waypoint *wp;
|
|
|
|
Engine *e;
|
|
|
|
Industry *i;
|
|
|
|
Vehicle *v;
|
|
|
|
|
|
|
|
_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
|
2006-08-26 11:06:54 +00:00
|
|
|
_cur_year += ORIGINAL_BASE_YEAR;
|
2006-08-20 18:40:57 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
FOR_ALL_STATIONS(st) st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
|
|
|
|
FOR_ALL_WAYPOINTS(wp) wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
|
|
|
|
FOR_ALL_ENGINES(e) e->intro_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
|
|
|
|
FOR_ALL_COMPANIES(c) c->inaugurated_year += ORIGINAL_BASE_YEAR;
|
|
|
|
FOR_ALL_INDUSTRIES(i) i->last_prod_year += ORIGINAL_BASE_YEAR;
|
2006-08-20 18:40:57 +00:00
|
|
|
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
v->date_of_last_service += DAYS_TILL_ORIGINAL_BASE_YEAR;
|
|
|
|
v->build_year += ORIGINAL_BASE_YEAR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-20 18:44:26 +00:00
|
|
|
/* From 32 on we save the industry who made the farmland.
|
|
|
|
* To give this prettyness to old savegames, we remove all farmfields and
|
|
|
|
* plant new ones. */
|
|
|
|
if (CheckSavegameVersion(32)) {
|
|
|
|
Industry *i;
|
|
|
|
|
2007-01-17 06:33:23 +00:00
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_FIELDS)) {
|
2008-04-03 23:52:43 +00:00
|
|
|
/* remove fields */
|
2007-01-17 06:33:23 +00:00
|
|
|
MakeClear(t, CLEAR_GRASS, 3);
|
2008-04-03 23:52:43 +00:00
|
|
|
} else if (IsTileType(t, MP_CLEAR) || IsTileType(t, MP_TREES)) {
|
|
|
|
/* remove fences around fields */
|
|
|
|
SetFenceSE(t, 0);
|
|
|
|
SetFenceSW(t, 0);
|
2006-08-20 18:44:26 +00:00
|
|
|
}
|
2007-01-17 06:33:23 +00:00
|
|
|
}
|
2006-08-20 18:44:26 +00:00
|
|
|
|
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
|
|
|
uint j;
|
|
|
|
|
2007-05-30 20:20:58 +00:00
|
|
|
if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
|
2006-08-20 18:44:26 +00:00
|
|
|
for (j = 0; j != 50; j++) PlantRandomFarmField(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-03 14:52:39 +00:00
|
|
|
/* Setting no refit flags to all orders in savegames from before refit in orders were added */
|
|
|
|
if (CheckSavegameVersion(36)) {
|
|
|
|
Order *order;
|
|
|
|
Vehicle *v;
|
|
|
|
|
|
|
|
FOR_ALL_ORDERS(order) {
|
2008-04-06 07:07:21 +00:00
|
|
|
order->SetRefit(CT_NO_REFIT);
|
2006-10-03 14:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
2008-04-06 07:07:21 +00:00
|
|
|
v->current_order.SetRefit(CT_NO_REFIT);
|
2006-10-03 14:52:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-06 11:08:40 +00:00
|
|
|
/* from version 38 we have optional elrails, since we cannot know the
|
|
|
|
* preference of a user, let elrails enabled; it can be disabled manually */
|
|
|
|
if (CheckSavegameVersion(38)) _settings_game.vehicle.disable_elrails = false;
|
|
|
|
/* do the same as when elrails were enabled/disabled manually just now */
|
|
|
|
SettingsDisableElrail(_settings_game.vehicle.disable_elrails);
|
|
|
|
InitializeRailGUI();
|
|
|
|
|
2007-03-19 11:41:21 +00:00
|
|
|
/* From version 53, the map array was changed for house tiles to allow
|
2007-03-19 11:27:30 +00:00
|
|
|
* space for newhouses grf features. A new byte, m7, was also added. */
|
2007-03-19 11:41:21 +00:00
|
|
|
if (CheckSavegameVersion(53)) {
|
2007-03-19 11:27:30 +00:00
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
if (IsTileType(t, MP_HOUSE)) {
|
|
|
|
if (GB(_m[t].m3, 6, 2) != TOWN_HOUSE_COMPLETED) {
|
|
|
|
/* Move the construction stage from m3[7..6] to m5[5..4].
|
|
|
|
* The construction counter does not have to move. */
|
|
|
|
SB(_m[t].m5, 3, 2, GB(_m[t].m3, 6, 2));
|
|
|
|
SB(_m[t].m3, 6, 2, 0);
|
|
|
|
|
|
|
|
/* The "house is completed" bit is now in m6[2]. */
|
|
|
|
SetHouseCompleted(t, false);
|
|
|
|
} else {
|
|
|
|
/* The "lift has destination" bit has been moved from
|
|
|
|
* m5[7] to m7[0]. */
|
2007-11-19 21:02:30 +00:00
|
|
|
SB(_me[t].m7, 0, 1, HasBit(_m[t].m5, 7));
|
2007-11-19 21:32:20 +00:00
|
|
|
ClrBit(_m[t].m5, 7);
|
2007-03-19 11:27:30 +00:00
|
|
|
|
|
|
|
/* The "lift is moving" bit has been removed, as it does
|
|
|
|
* the same job as the "lift has destination" bit. */
|
2007-11-19 21:32:20 +00:00
|
|
|
ClrBit(_m[t].m1, 7);
|
2007-03-19 11:27:30 +00:00
|
|
|
|
|
|
|
/* The position of the lift goes from m1[7..0] to m6[7..2],
|
|
|
|
* making m1 totally free, now. The lift position does not
|
|
|
|
* have to be a full byte since the maximum value is 36. */
|
|
|
|
SetLiftPosition(t, GB(_m[t].m1, 0, 6 ));
|
|
|
|
|
|
|
|
_m[t].m1 = 0;
|
|
|
|
_m[t].m3 = 0;
|
|
|
|
SetHouseCompleted(t, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-18 12:28:21 +00:00
|
|
|
/* Check and update house and town values */
|
|
|
|
UpdateHousesAndTowns();
|
2007-03-19 11:27:30 +00:00
|
|
|
|
2006-12-30 11:57:52 +00:00
|
|
|
if (CheckSavegameVersion(43)) {
|
2007-01-17 06:33:23 +00:00
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
if (IsTileType(t, MP_INDUSTRY)) {
|
|
|
|
switch (GetIndustryGfx(t)) {
|
2006-12-30 11:57:52 +00:00
|
|
|
case GFX_POWERPLANT_SPARKS:
|
2007-01-17 06:33:23 +00:00
|
|
|
SetIndustryAnimationState(t, GB(_m[t].m1, 2, 5));
|
2006-12-30 11:57:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_OILWELL_ANIMATED_1:
|
|
|
|
case GFX_OILWELL_ANIMATED_2:
|
|
|
|
case GFX_OILWELL_ANIMATED_3:
|
2007-01-17 06:33:23 +00:00
|
|
|
SetIndustryAnimationState(t, GB(_m[t].m1, 0, 2));
|
2006-12-30 11:57:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GFX_COAL_MINE_TOWER_ANIMATED:
|
|
|
|
case GFX_COPPER_MINE_TOWER_ANIMATED:
|
|
|
|
case GFX_GOLD_MINE_TOWER_ANIMATED:
|
2007-01-17 06:33:23 +00:00
|
|
|
SetIndustryAnimationState(t, _m[t].m1);
|
2006-12-30 11:57:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* No animation states to change */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-01-17 06:33:23 +00:00
|
|
|
}
|
2006-12-30 11:57:52 +00:00
|
|
|
}
|
|
|
|
|
2007-01-15 14:42:24 +00:00
|
|
|
if (CheckSavegameVersion(44)) {
|
|
|
|
Vehicle *v;
|
|
|
|
/* If we remove a station while cargo from it is still enroute, payment calculation will assume
|
2007-06-22 11:58:59 +00:00
|
|
|
* 0, 0 to be the source of the cargo, resulting in very high payments usually. v->source_xy
|
2007-01-15 14:42:24 +00:00
|
|
|
* stores the coordinates, preserving them even if the station is removed. However, if a game is loaded
|
2007-06-22 11:58:59 +00:00
|
|
|
* where this situation exists, the cargo-source information is lost. in this case, we set the source
|
2007-01-15 14:42:24 +00:00
|
|
|
* to the current tile of the vehicle to prevent excessive profits
|
|
|
|
*/
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
2007-06-22 11:58:59 +00:00
|
|
|
const CargoList::List *packets = v->cargo.Packets();
|
|
|
|
for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
|
|
|
|
CargoPacket *cp = *it;
|
|
|
|
cp->source_xy = IsValidStationID(cp->source) ? GetStation(cp->source)->xy : v->tile;
|
|
|
|
cp->loaded_at_xy = cp->source_xy;
|
|
|
|
}
|
|
|
|
v->cargo.InvalidateCache();
|
2007-01-15 14:42:24 +00:00
|
|
|
}
|
2007-03-13 21:31:09 +00:00
|
|
|
|
|
|
|
/* Store position of the station where the goods come from, so there
|
|
|
|
* are no very high payments when stations get removed. However, if the
|
|
|
|
* station where the goods came from is already removed, the source
|
|
|
|
* information is lost. In that case we set it to the position of this
|
|
|
|
* station */
|
|
|
|
Station *st;
|
|
|
|
FOR_ALL_STATIONS(st) {
|
|
|
|
for (CargoID c = 0; c < NUM_CARGO; c++) {
|
|
|
|
GoodsEntry *ge = &st->goods[c];
|
|
|
|
|
2007-06-22 11:58:59 +00:00
|
|
|
const CargoList::List *packets = ge->cargo.Packets();
|
|
|
|
for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
|
|
|
|
CargoPacket *cp = *it;
|
|
|
|
cp->source_xy = IsValidStationID(cp->source) ? GetStation(cp->source)->xy : st->xy;
|
|
|
|
cp->loaded_at_xy = cp->source_xy;
|
2007-03-13 21:31:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-01-15 14:42:24 +00:00
|
|
|
}
|
|
|
|
|
2007-01-31 22:33:24 +00:00
|
|
|
if (CheckSavegameVersion(45)) {
|
|
|
|
Vehicle *v;
|
|
|
|
/* Originally just the fact that some cargo had been paid for was
|
|
|
|
* stored to stop people cheating and cashing in several times. This
|
|
|
|
* wasn't enough though as it was cleared when the vehicle started
|
|
|
|
* loading again, even if it didn't actually load anything, so now the
|
|
|
|
* amount of cargo that has been paid for is stored. */
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
2007-06-22 11:58:59 +00:00
|
|
|
const CargoList::List *packets = v->cargo.Packets();
|
|
|
|
for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
|
|
|
|
CargoPacket *cp = *it;
|
2007-11-19 21:02:30 +00:00
|
|
|
cp->paid_for = HasBit(v->vehicle_flags, 2);
|
2007-01-31 22:33:24 +00:00
|
|
|
}
|
2007-11-19 21:32:20 +00:00
|
|
|
ClrBit(v->vehicle_flags, 2);
|
2007-06-22 11:58:59 +00:00
|
|
|
v->cargo.InvalidateCache();
|
2007-01-31 22:33:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-12 12:52:37 +00:00
|
|
|
/* Buoys do now store the owner of the previous water tile, which can never
|
|
|
|
* be OWNER_NONE. So replace OWNER_NONE with OWNER_WATER. */
|
|
|
|
if (CheckSavegameVersion(46)) {
|
|
|
|
Station *st;
|
|
|
|
FOR_ALL_STATIONS(st) {
|
2007-10-22 17:03:08 +00:00
|
|
|
if (st->IsBuoy() && IsTileOwner(st->xy, OWNER_NONE) && TileHeight(st->xy) == 0) SetTileOwner(st->xy, OWNER_WATER);
|
2007-02-12 12:52:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-02 12:01:24 +00:00
|
|
|
if (CheckSavegameVersion(50)) {
|
|
|
|
Vehicle *v;
|
|
|
|
/* Aircraft units changed from 8 mph to 1 km/h */
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_AIRCRAFT && v->subtype <= AIR_AIRCRAFT) {
|
2007-03-02 12:01:24 +00:00
|
|
|
const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type);
|
|
|
|
v->cur_speed *= 129;
|
|
|
|
v->cur_speed /= 10;
|
|
|
|
v->max_speed = avi->max_speed;
|
|
|
|
v->acceleration = avi->acceleration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
if (CheckSavegameVersion(49)) FOR_ALL_COMPANIES(c) c->face = ConvertFromOldCompanyManagerFace(c->face);
|
2007-03-02 01:17:11 +00:00
|
|
|
|
2007-03-08 14:34:32 +00:00
|
|
|
if (CheckSavegameVersion(52)) {
|
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
if (IsStatueTile(t)) {
|
|
|
|
_m[t].m2 = CalcClosestTownFromTile(t, (uint)-1)->index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-18 14:23:30 +00:00
|
|
|
/* A patch option containing the proportion of towns that grow twice as
|
|
|
|
* fast was added in version 54. From version 56 this is now saved in the
|
|
|
|
* town as cities can be built specifically in the scenario editor. */
|
|
|
|
if (CheckSavegameVersion(56)) {
|
|
|
|
Town *t;
|
|
|
|
|
|
|
|
FOR_ALL_TOWNS(t) {
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.economy.larger_towns != 0 && (t->index % _settings_game.economy.larger_towns) == 0) {
|
2007-04-18 14:23:30 +00:00
|
|
|
t->larger_town = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-20 08:00:30 +00:00
|
|
|
if (CheckSavegameVersion(57)) {
|
|
|
|
Vehicle *v;
|
|
|
|
/* Added a FIFO queue of vehicles loading at stations */
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if ((v->type != VEH_TRAIN || IsFrontEngine(v)) && // for all locs
|
|
|
|
!(v->vehstatus & (VS_STOPPED | VS_CRASHED)) && // not stopped or crashed
|
2008-04-05 23:36:54 +00:00
|
|
|
v->current_order.IsType(OT_LOADING)) { // loading
|
2007-04-20 08:00:30 +00:00
|
|
|
GetStation(v->last_station_visited)->loading_vehicles.push_back(v);
|
2007-05-14 20:17:26 +00:00
|
|
|
|
|
|
|
/* The loading finished flag is *only* set when actually completely
|
|
|
|
* finished. Because the vehicle is loading, it is not finished. */
|
2007-11-19 21:32:20 +00:00
|
|
|
ClrBit(v->vehicle_flags, VF_LOADING_FINISHED);
|
2007-04-20 08:00:30 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-26 14:38:44 +00:00
|
|
|
} else if (CheckSavegameVersion(59)) {
|
|
|
|
/* For some reason non-loading vehicles could be in the station's loading vehicle list */
|
|
|
|
|
|
|
|
Station *st;
|
|
|
|
FOR_ALL_STATIONS(st) {
|
|
|
|
std::list<Vehicle *>::iterator iter;
|
|
|
|
for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end();) {
|
|
|
|
Vehicle *v = *iter;
|
|
|
|
iter++;
|
2008-04-05 23:36:54 +00:00
|
|
|
if (!v->current_order.IsType(OT_LOADING)) st->loading_vehicles.remove(v);
|
2007-08-26 14:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
2007-04-20 08:00:30 +00:00
|
|
|
}
|
|
|
|
|
2007-05-01 17:16:51 +00:00
|
|
|
if (CheckSavegameVersion(58)) {
|
2008-08-20 01:38:12 +00:00
|
|
|
/* patch difficulty number_industries other than zero get bumped to +1
|
2007-05-01 17:16:51 +00:00
|
|
|
* since a new option (very low at position1) has been added */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.difficulty.number_industries > 0) {
|
|
|
|
_settings_game.difficulty.number_industries++;
|
2007-05-01 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Same goes for number of towns, although no test is needed, just an increment */
|
2008-05-29 15:13:28 +00:00
|
|
|
_settings_game.difficulty.number_towns++;
|
2007-05-01 17:16:51 +00:00
|
|
|
}
|
|
|
|
|
2007-05-31 21:21:04 +00:00
|
|
|
if (CheckSavegameVersion(64)) {
|
|
|
|
/* copy the signal type/variant and move signal states bits */
|
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
if (IsTileType(t, MP_RAILWAY) && HasSignals(t)) {
|
|
|
|
SetSignalStates(t, GB(_m[t].m2, 4, 4));
|
|
|
|
SetSignalVariant(t, INVALID_TRACK, GetSignalVariant(t, TRACK_X));
|
|
|
|
SetSignalType(t, INVALID_TRACK, GetSignalType(t, TRACK_X));
|
2007-11-19 21:32:20 +00:00
|
|
|
ClrBit(_m[t].m2, 7);
|
2007-05-31 21:21:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-22 17:33:13 +00:00
|
|
|
if (CheckSavegameVersion(69)) {
|
|
|
|
/* In some old savegames a bit was cleared when it should not be cleared */
|
|
|
|
Vehicle *v;
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if (v->type == VEH_ROAD && (v->u.road.state == 250 || v->u.road.state == 251)) {
|
2007-11-20 13:35:54 +00:00
|
|
|
SetBit(v->u.road.state, RVS_IS_STOPPING);
|
2007-06-22 17:33:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-07 08:53:19 +00:00
|
|
|
if (CheckSavegameVersion(70)) {
|
|
|
|
/* Added variables to support newindustries */
|
|
|
|
Industry *i;
|
|
|
|
FOR_ALL_INDUSTRIES(i) i->founder = OWNER_NONE;
|
|
|
|
}
|
|
|
|
|
2007-10-16 19:48:58 +00:00
|
|
|
/* From version 82, old style canals (above sealevel (0), WATER owner) are no longer supported.
|
|
|
|
Replace the owner for those by OWNER_NONE. */
|
|
|
|
if (CheckSavegameVersion(82)) {
|
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
if (IsTileType(t, MP_WATER) &&
|
|
|
|
GetWaterTileType(t) == WATER_TILE_CLEAR &&
|
|
|
|
GetTileOwner(t) == OWNER_WATER &&
|
|
|
|
TileHeight(t) != 0) {
|
|
|
|
SetTileOwner(t, OWNER_NONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-07 21:14:54 +00:00
|
|
|
/*
|
|
|
|
* Add the 'previous' owner to the ship depots so we can reset it with
|
|
|
|
* the correct values when it gets destroyed. This prevents that
|
|
|
|
* someone can remove canals owned by somebody else and it prevents
|
|
|
|
* making floods using the removal of ship depots.
|
|
|
|
*/
|
|
|
|
if (CheckSavegameVersion(83)) {
|
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
if (IsTileType(t, MP_WATER) && IsShipDepot(t)) {
|
|
|
|
_m[t].m4 = (TileHeight(t) == 0) ? OWNER_WATER : OWNER_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-01 08:04:08 +00:00
|
|
|
if (CheckSavegameVersion(74)) {
|
|
|
|
Station *st;
|
|
|
|
FOR_ALL_STATIONS(st) {
|
|
|
|
for (CargoID c = 0; c < NUM_CARGO; c++) {
|
|
|
|
st->goods[c].last_speed = 0;
|
2007-11-20 13:35:54 +00:00
|
|
|
if (st->goods[c].cargo.Count() != 0) SetBit(st->goods[c].acceptance_pickup, GoodsEntry::PICKUP);
|
2007-09-01 08:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-27 21:39:13 +00:00
|
|
|
if (CheckSavegameVersion(78)) {
|
|
|
|
Industry *i;
|
|
|
|
uint j;
|
|
|
|
FOR_ALL_INDUSTRIES(i) {
|
|
|
|
const IndustrySpec *indsp = GetIndustrySpec(i->type);
|
|
|
|
for (j = 0; j < lengthof(i->produced_cargo); j++) {
|
|
|
|
i->produced_cargo[j] = indsp->produced_cargo[j];
|
|
|
|
}
|
|
|
|
for (j = 0; j < lengthof(i->accepts_cargo); j++) {
|
|
|
|
i->accepts_cargo[j] = indsp->accepts_cargo[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2007-10-11 11:06:04 +00:00
|
|
|
/* Before version 81, the density of grass was always stored as zero, and
|
|
|
|
* grassy trees were always drawn fully grassy. Furthermore, trees on rough
|
|
|
|
* land used to have zero density, now they have full density. Therefore,
|
|
|
|
* make all grassy/rough land trees have a density of 3. */
|
|
|
|
if (CheckSavegameVersion(81)) {
|
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
if (GetTileType(t) == MP_TREES) {
|
|
|
|
TreeGround groundType = GetTreeGround(t);
|
|
|
|
if (groundType != TREE_GROUND_SNOW_DESERT) SetTreeGroundDensity(t, groundType, 3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-13 19:46:26 +00:00
|
|
|
|
|
|
|
if (CheckSavegameVersion(93)) {
|
|
|
|
/* Rework of orders. */
|
|
|
|
Order *order;
|
|
|
|
FOR_ALL_ORDERS(order) order->ConvertFromOldSavegame();
|
|
|
|
|
|
|
|
Vehicle *v;
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if (v->orders != NULL && !v->orders->IsValid()) v->orders = NULL;
|
|
|
|
|
|
|
|
v->current_order.ConvertFromOldSavegame();
|
2008-08-17 19:56:17 +00:00
|
|
|
if (v->type == VEH_ROAD && v->IsPrimaryVehicle() && v->FirstShared() == v) {
|
2008-04-13 19:46:26 +00:00
|
|
|
FOR_VEHICLE_ORDERS(v, order) order->SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (CheckSavegameVersion(94)) {
|
|
|
|
/* Unload and transfer are now mutual exclusive. */
|
|
|
|
Order *order;
|
|
|
|
FOR_ALL_ORDERS(order) {
|
|
|
|
if ((order->GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) == (OUFB_UNLOAD | OUFB_TRANSFER)) {
|
|
|
|
order->SetUnloadType(OUFB_TRANSFER);
|
|
|
|
order->SetLoadType(OLFB_NO_LOAD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Vehicle *v;
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if ((v->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) == (OUFB_UNLOAD | OUFB_TRANSFER)) {
|
|
|
|
v->current_order.SetUnloadType(OUFB_TRANSFER);
|
|
|
|
v->current_order.SetLoadType(OLFB_NO_LOAD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-11 17:44:55 +00:00
|
|
|
if (CheckSavegameVersion(84)) {
|
2007-12-28 18:25:30 +00:00
|
|
|
/* Update go to buoy orders because they are just waypoints */
|
2007-12-11 17:44:55 +00:00
|
|
|
Order *order;
|
|
|
|
FOR_ALL_ORDERS(order) {
|
2008-04-06 07:48:51 +00:00
|
|
|
if (order->IsType(OT_GOTO_STATION) && GetStation(order->GetDestination())->IsBuoy()) {
|
2008-04-07 20:03:46 +00:00
|
|
|
order->SetLoadType(OLF_LOAD_IF_POSSIBLE);
|
|
|
|
order->SetUnloadType(OUF_UNLOAD_IF_POSSIBLE);
|
2007-12-11 17:44:55 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-28 18:25:30 +00:00
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
/* Set all share owners to INVALID_COMPANY for
|
|
|
|
* 1) all inactive companies
|
|
|
|
* (when inactive companies were stored in the savegame - TTD, TTDP and some
|
|
|
|
* *really* old revisions of OTTD; else it is already set in InitializeCompanies())
|
|
|
|
* 2) shares that are owned by inactive companies or self
|
|
|
|
* (caused by cheating clients in earlier revisions) */
|
|
|
|
FOR_ALL_COMPANIES(c) {
|
2008-07-18 16:40:29 +00:00
|
|
|
for (uint i = 0; i < 4; i++) {
|
2008-09-30 20:39:50 +00:00
|
|
|
CompanyID company = c->share_owners[i];
|
|
|
|
if (company == INVALID_COMPANY) continue;
|
|
|
|
if (!IsValidCompanyID(company) || company == c->index) c->share_owners[i] = INVALID_COMPANY;
|
2007-12-28 18:25:30 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-11 17:44:55 +00:00
|
|
|
}
|
|
|
|
|
2008-01-17 19:49:06 +00:00
|
|
|
if (CheckSavegameVersion(86)) {
|
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
2008-02-02 09:28:43 +00:00
|
|
|
/* Move river flag and update canals to use water class */
|
|
|
|
if (IsTileType(t, MP_WATER)) {
|
2008-05-13 12:15:52 +00:00
|
|
|
if (GetWaterClass(t) != WATER_CLASS_RIVER) {
|
2008-02-06 15:32:06 +00:00
|
|
|
if (IsWater(t)) {
|
|
|
|
Owner o = GetTileOwner(t);
|
|
|
|
if (o == OWNER_WATER) {
|
|
|
|
MakeWater(t);
|
|
|
|
} else {
|
|
|
|
MakeCanal(t, o, Random());
|
|
|
|
}
|
|
|
|
} else if (IsShipDepot(t)) {
|
|
|
|
Owner o = (Owner)_m[t].m4; // Original water owner
|
|
|
|
SetWaterClass(t, o == OWNER_WATER ? WATER_CLASS_SEA : WATER_CLASS_CANAL);
|
2008-02-02 09:28:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update locks, depots, docks and buoys to have a water class based
|
|
|
|
* on its neighbouring tiles. Done after river and canal updates to
|
|
|
|
* ensure neighbours are correct. */
|
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
if (GetTileSlope(t, NULL) != SLOPE_FLAT) continue;
|
|
|
|
|
2008-07-26 16:14:10 +00:00
|
|
|
if (IsTileType(t, MP_WATER) && IsLock(t)) SetWaterClassDependingOnSurroundings(t, false);
|
|
|
|
if (IsTileType(t, MP_STATION) && (IsDock(t) || IsBuoy(t))) SetWaterClassDependingOnSurroundings(t, false);
|
2008-01-17 19:49:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-09 17:36:21 +00:00
|
|
|
if (CheckSavegameVersion(87)) {
|
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
2008-02-20 16:24:56 +00:00
|
|
|
/* skip oil rigs at borders! */
|
|
|
|
if ((IsTileType(t, MP_WATER) || IsBuoyTile(t)) &&
|
|
|
|
(TileX(t) == 0 || TileY(t) == 0 || TileX(t) == MapMaxX() - 1 || TileY(t) == MapMaxY() - 1)) {
|
2008-02-10 14:00:52 +00:00
|
|
|
/* Some version 86 savegames have wrong water class at map borders (under buoy, or after removing buoy).
|
|
|
|
* This conversion has to be done before buoys with invalid owner are removed. */
|
|
|
|
SetWaterClass(t, WATER_CLASS_SEA);
|
|
|
|
}
|
|
|
|
|
2008-02-09 17:36:21 +00:00
|
|
|
if (IsBuoyTile(t) || IsDriveThroughStopTile(t) || IsTileType(t, MP_WATER)) {
|
|
|
|
Owner o = GetTileOwner(t);
|
2008-09-30 20:39:50 +00:00
|
|
|
if (o < MAX_COMPANIES && !IsValidCompanyID(o)) {
|
|
|
|
_current_company = o;
|
|
|
|
ChangeTileOwner(t, o, INVALID_OWNER);
|
2008-02-09 17:36:21 +00:00
|
|
|
}
|
|
|
|
if (IsBuoyTile(t)) {
|
|
|
|
/* reset buoy owner to OWNER_NONE in the station struct
|
2008-09-30 20:39:50 +00:00
|
|
|
* (even if it is owned by active company) */
|
2008-02-09 17:36:21 +00:00
|
|
|
GetStationByTile(t)->owner = OWNER_NONE;
|
|
|
|
}
|
|
|
|
} else if (IsTileType(t, MP_ROAD)) {
|
|
|
|
/* works for all RoadTileType */
|
|
|
|
for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
|
|
|
|
/* update even non-existing road types to update tile owner too */
|
|
|
|
Owner o = GetRoadOwner(t, rt);
|
2008-09-30 20:39:50 +00:00
|
|
|
if (o < MAX_COMPANIES && !IsValidCompanyID(o)) SetRoadOwner(t, rt, OWNER_NONE);
|
2008-02-09 17:36:21 +00:00
|
|
|
}
|
2008-02-14 15:59:16 +00:00
|
|
|
if (IsLevelCrossing(t)) {
|
2008-02-09 17:36:21 +00:00
|
|
|
Owner o = GetTileOwner(t);
|
2008-09-30 20:39:50 +00:00
|
|
|
if (!IsValidCompanyID(o)) {
|
2008-02-09 17:36:21 +00:00
|
|
|
/* remove leftover rail piece from crossing (from very old savegames) */
|
2008-09-30 20:39:50 +00:00
|
|
|
_current_company = o;
|
2008-02-18 18:35:36 +00:00
|
|
|
DoCommand(t, 0, GetCrossingRailTrack(t), DC_EXEC | DC_BANKRUPT, CMD_REMOVE_SINGLE_RAIL);
|
2008-02-09 17:36:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-02-13 14:21:36 +00:00
|
|
|
|
|
|
|
/* Convert old PF settings to new */
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.pf.yapf.rail_use_yapf || CheckSavegameVersion(28)) {
|
|
|
|
_settings_game.pf.pathfinder_for_trains = VPF_YAPF;
|
2008-02-13 14:21:36 +00:00
|
|
|
} else {
|
2008-05-29 15:13:28 +00:00
|
|
|
_settings_game.pf.pathfinder_for_trains = (_settings_game.pf.new_pathfinding_all ? VPF_NPF : VPF_NTP);
|
2008-02-13 14:21:36 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.pf.yapf.road_use_yapf || CheckSavegameVersion(28)) {
|
|
|
|
_settings_game.pf.pathfinder_for_roadvehs = VPF_YAPF;
|
2008-02-13 14:21:36 +00:00
|
|
|
} else {
|
2008-05-29 15:13:28 +00:00
|
|
|
_settings_game.pf.pathfinder_for_roadvehs = (_settings_game.pf.new_pathfinding_all ? VPF_NPF : VPF_OPF);
|
2008-02-13 14:21:36 +00:00
|
|
|
}
|
|
|
|
|
2008-05-29 15:13:28 +00:00
|
|
|
if (_settings_game.pf.yapf.ship_use_yapf) {
|
|
|
|
_settings_game.pf.pathfinder_for_ships = VPF_YAPF;
|
2008-02-13 14:21:36 +00:00
|
|
|
} else {
|
2008-05-29 15:13:28 +00:00
|
|
|
_settings_game.pf.pathfinder_for_ships = (_settings_game.pf.new_pathfinding_all ? VPF_NPF : VPF_OPF);
|
2008-02-13 14:21:36 +00:00
|
|
|
}
|
2008-02-09 17:36:21 +00:00
|
|
|
}
|
|
|
|
|
2008-02-13 19:24:40 +00:00
|
|
|
if (CheckSavegameVersion(88)) {
|
|
|
|
/* Profits are now with 8 bit fract */
|
|
|
|
Vehicle *v;
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
v->profit_this_year <<= 8;
|
|
|
|
v->profit_last_year <<= 8;
|
|
|
|
v->running_ticks = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-06 14:21:10 +00:00
|
|
|
if (CheckSavegameVersion(91)) {
|
|
|
|
/* Increase HouseAnimationFrame from 5 to 7 bits */
|
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
if (IsTileType(t, MP_HOUSE) && GetHouseType(t) >= NEW_HOUSE_OFFSET) {
|
|
|
|
SetHouseAnimationFrame(t, GB(_m[t].m6, 3, 5));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-25 16:33:40 +00:00
|
|
|
if (CheckSavegameVersion(62)) {
|
|
|
|
/* Remove all trams from savegames without tram support.
|
|
|
|
* There would be trams without tram track under causing crashes sooner or later. */
|
|
|
|
Vehicle *v;
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if (v->type == VEH_ROAD && v->First() == v &&
|
|
|
|
HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM)) {
|
|
|
|
if (_switch_mode_errorstr == INVALID_STRING_ID || _switch_mode_errorstr == STR_NEWGRF_COMPATIBLE_LOAD_WARNING) {
|
|
|
|
_switch_mode_errorstr = STR_LOADGAME_REMOVED_TRAMS;
|
|
|
|
}
|
|
|
|
delete v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-26 16:14:10 +00:00
|
|
|
if (CheckSavegameVersion(99)) {
|
|
|
|
/* Set newly introduced WaterClass of industry tiles */
|
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
if (IsTileType(t, MP_STATION) && IsOilRig(t)) {
|
|
|
|
SetWaterClassDependingOnSurroundings(t, true);
|
|
|
|
}
|
|
|
|
if (IsTileType(t, MP_INDUSTRY)) {
|
|
|
|
if ((GetIndustrySpec(GetIndustryType(t))->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0) {
|
|
|
|
SetWaterClassDependingOnSurroundings(t, true);
|
|
|
|
} else {
|
|
|
|
SetWaterClass(t, WATER_CLASS_INVALID);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-02 22:48:43 +00:00
|
|
|
/* Move the signal variant back up one bit for PBS. We don't convert the old PBS
|
|
|
|
* format here, as an old layout wouldn't work properly anyway. To be safe, we
|
|
|
|
* clear any possible PBS reservations as well. */
|
|
|
|
if (CheckSavegameVersion(100)) {
|
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
switch (GetTileType(t)) {
|
|
|
|
case MP_RAILWAY:
|
|
|
|
if (HasSignals(t)) {
|
|
|
|
/* move the signal variant */
|
|
|
|
SetSignalVariant(t, TRACK_UPPER, HasBit(_m[t].m2, 2) ? SIG_SEMAPHORE : SIG_ELECTRIC);
|
|
|
|
SetSignalVariant(t, TRACK_LOWER, HasBit(_m[t].m2, 6) ? SIG_SEMAPHORE : SIG_ELECTRIC);
|
|
|
|
ClrBit(_m[t].m2, 2);
|
|
|
|
ClrBit(_m[t].m2, 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear PBS reservation on track */
|
|
|
|
if (IsRailDepot(t) ||IsRailWaypoint(t)) {
|
|
|
|
SetDepotWaypointReservation(t, false);
|
|
|
|
} else {
|
|
|
|
SetTrackReservation(t, TRACK_BIT_NONE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_ROAD: /* Clear PBS reservation on crossing */
|
|
|
|
if (IsLevelCrossing(t)) SetCrossingReservation(t, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_STATION: /* Clear PBS reservation on station */
|
|
|
|
if (IsRailwayStation(t)) SetRailwayStationReservation(t, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MP_TUNNELBRIDGE: /* Clear PBS reservation on tunnels/birdges */
|
|
|
|
if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) SetTunnelBridgeReservation(t, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-10 13:37:09 +00:00
|
|
|
/* Reserve all tracks trains are currently on. */
|
|
|
|
if (CheckSavegameVersion(101)) {
|
|
|
|
Vehicle *v;
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if (v->type == VEH_TRAIN) {
|
|
|
|
if ((v->u.rail.track & TRACK_BIT_WORMHOLE) == TRACK_BIT_WORMHOLE) {
|
|
|
|
TryReserveRailTrack(v->tile, DiagDirToDiagTrack(GetTunnelBridgeDirection(v->tile)));
|
|
|
|
} else if ((v->u.rail.track & TRACK_BIT_MASK) != TRACK_BIT_NONE) {
|
|
|
|
TryReserveRailTrack(v->tile, TrackBitsToTrack(v->u.rail.track));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-08-23 02:15:46 +00:00
|
|
|
|
|
|
|
/* Give owners to waypoints, based on rail tracks it is sitting on.
|
|
|
|
* If none is available, specify OWNER_NONE */
|
|
|
|
Waypoint *wp;
|
|
|
|
FOR_ALL_WAYPOINTS(wp) {
|
2008-09-09 12:26:25 +00:00
|
|
|
Owner owner = (IsRailWaypointTile(wp->xy) ? GetTileOwner(wp->xy) : OWNER_NONE);
|
2008-09-30 20:39:50 +00:00
|
|
|
wp->owner = IsValidCompanyID(owner) ? owner : OWNER_NONE;
|
2008-08-23 02:15:46 +00:00
|
|
|
}
|
2008-08-10 13:37:09 +00:00
|
|
|
}
|
|
|
|
|
2008-09-11 17:41:43 +00:00
|
|
|
if (CheckSavegameVersion(102)) {
|
|
|
|
for (TileIndex t = 0; t < map_size; t++) {
|
|
|
|
/* Now all crossings should be in correct state */
|
|
|
|
if (IsLevelCrossingTile(t)) UpdateLevelCrossing(t, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-16 20:57:49 +00:00
|
|
|
if (CheckSavegameVersion(103)) {
|
|
|
|
/* signs with invalid owner left from older savegames */
|
|
|
|
Sign *si;
|
|
|
|
FOR_ALL_SIGNS(si) {
|
2008-09-30 20:39:50 +00:00
|
|
|
if (si->owner != OWNER_NONE && !IsValidCompanyID(si->owner)) si->owner = OWNER_NONE;
|
2008-09-16 20:57:49 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-11 17:41:43 +00:00
|
|
|
|
2008-07-18 12:11:46 +00:00
|
|
|
GamelogPrintDebug(1);
|
2008-06-03 18:35:58 +00:00
|
|
|
|
2007-11-28 15:42:52 +00:00
|
|
|
return InitializeWindowsAndCaches();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-12-21 10:29:16 +00:00
|
|
|
|
|
|
|
/** Reload all NewGRF files during a running game. This is a cut-down
|
|
|
|
* version of AfterLoadGame().
|
|
|
|
* XXX - We need to reset the vehicle position hash because with a non-empty
|
|
|
|
* hash AfterLoadVehicles() will loop infinitely. We need AfterLoadVehicles()
|
|
|
|
* to recalculate vehicle data as some NewGRF vehicle sets could have been
|
|
|
|
* removed or added and changed statistics */
|
2007-03-07 11:47:46 +00:00
|
|
|
void ReloadNewGRFData()
|
2006-12-21 10:29:16 +00:00
|
|
|
{
|
|
|
|
/* reload grf data */
|
|
|
|
GfxLoadSprites();
|
|
|
|
LoadStringWidthTable();
|
2008-07-26 14:58:08 +00:00
|
|
|
ResetEconomy();
|
2006-12-21 10:29:16 +00:00
|
|
|
/* reload vehicles */
|
|
|
|
ResetVehiclePosHash();
|
2008-01-01 15:06:37 +00:00
|
|
|
AfterLoadVehicles(false);
|
2007-03-02 15:17:48 +00:00
|
|
|
StartupEngines();
|
2008-05-14 15:29:48 +00:00
|
|
|
SetCachedEngineCounts();
|
2006-12-21 10:29:16 +00:00
|
|
|
/* update station and waypoint graphics */
|
|
|
|
AfterLoadWaypoints();
|
|
|
|
AfterLoadStations();
|
2008-03-18 12:28:21 +00:00
|
|
|
/* Check and update house and town values */
|
|
|
|
UpdateHousesAndTowns();
|
2008-05-14 23:02:05 +00:00
|
|
|
/* Update livery selection windows */
|
2008-09-30 20:39:50 +00:00
|
|
|
for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) InvalidateWindowData(WC_COMPANY_COLOR, i, _loaded_newgrf_features.has_2CC);
|
2006-12-21 10:29:16 +00:00
|
|
|
/* redraw the whole screen */
|
|
|
|
MarkWholeScreenDirty();
|
2008-07-24 15:19:26 +00:00
|
|
|
CheckTrainsLengths();
|
2006-12-21 10:29:16 +00:00
|
|
|
}
|