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 "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"
|
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
|
|
|
|
2009-01-04 15:32:25 +00:00
|
|
|
#include "saveload/saveload.h"
|
2008-03-31 07:03:35 +00:00
|
|
|
#include "landscape.h"
|
2008-09-30 20:51:04 +00:00
|
|
|
#include "company_func.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.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"
|
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"
|
2009-01-12 17:11:45 +00:00
|
|
|
#include "ai/ai.hpp"
|
|
|
|
#include "ai/ai_config.hpp"
|
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-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"
|
2009-01-31 20:16:06 +00:00
|
|
|
#include "cheat_type.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"
|
2009-01-03 18:44:20 +00:00
|
|
|
#include "highscore.h"
|
2008-03-31 07:03:35 +00:00
|
|
|
|
|
|
|
#include "newgrf_commons.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-01-31 20:16:06 +00:00
|
|
|
#include "town.h"
|
|
|
|
#include "industry.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 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()
|
|
|
|
{
|
2009-01-12 17:11:45 +00:00
|
|
|
char buf[8192];
|
2008-04-29 18:19:29 +00:00
|
|
|
char *p = buf;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-10-28 14:42:31 +00:00
|
|
|
p += seprintf(p, lastof(buf), "OpenTTD %s\n", _openttd_revision);
|
2006-11-28 20:55:16 +00:00
|
|
|
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"
|
2009-01-12 17:11:45 +00:00
|
|
|
" -a ai = Force use of specific AI (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-10-25 20:16:07 +00:00
|
|
|
" -i palette = Force to use the DOS (0) or Windows (1) palette\n"
|
|
|
|
" (defines default setting when adding newgrfs)\n"
|
2008-11-23 16:01:24 +00:00
|
|
|
" Default value (2) lets OpenTTD use the palette\n"
|
|
|
|
" specified in graphics set file (see below)\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));
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
/* We need to initialize the AI, so it finds the AIs */
|
|
|
|
AI::Initialize();
|
|
|
|
p = AI::GetConsoleList(p, lastof(buf));
|
|
|
|
AI::Uninitialize(true);
|
|
|
|
|
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)
|
|
|
|
{
|
2009-03-14 18:16:29 +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... */
|
2009-03-08 16:51:08 +00:00
|
|
|
_engine_mngr.ResetToDefaultMapping();
|
|
|
|
_house_mngr.ResetMapping();
|
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 */
|
2009-01-12 17:11:45 +00:00
|
|
|
AI::Uninitialize(false);
|
2008-05-08 23:26:17 +00:00
|
|
|
|
|
|
|
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();
|
2009-02-09 02:57:15 +00:00
|
|
|
SetupColoursAndInitialWindow();
|
2004-12-04 17:54:56 +00:00
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
void MakeNewgameSettingsLive()
|
|
|
|
{
|
|
|
|
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
|
|
|
if (_settings_game.ai_config[c] != NULL) {
|
|
|
|
delete _settings_game.ai_config[c];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_settings_game = _settings_newgame;
|
|
|
|
|
|
|
|
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
|
|
|
_settings_game.ai_config[c] = NULL;
|
|
|
|
if (_settings_newgame.ai_config[c] != NULL) {
|
|
|
|
_settings_game.ai_config[c] = new AIConfig(_settings_newgame.ai_config[c]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2009-01-08 11:06:07 +00:00
|
|
|
char *musicdriver = NULL;
|
|
|
|
char *sounddriver = NULL;
|
|
|
|
char *videodriver = NULL;
|
|
|
|
char *blitter = NULL;
|
|
|
|
char *graphics_set = NULL;
|
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
|
|
|
|
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) {
|
2009-01-08 11:06:07 +00:00
|
|
|
case 'I': free(graphics_set); graphics_set = strdup(mgo.opt); break;
|
|
|
|
case 'm': free(musicdriver); musicdriver = strdup(mgo.opt); break;
|
|
|
|
case 's': free(sounddriver); sounddriver = strdup(mgo.opt); break;
|
|
|
|
case 'v': free(videodriver); videodriver = strdup(mgo.opt); break;
|
|
|
|
case 'b': free(blitter); blitter = strdup(mgo.opt); break;
|
2007-01-16 15:20:22 +00:00
|
|
|
#if defined(ENABLE_NETWORK)
|
2006-02-21 17:29:53 +00:00
|
|
|
case 'D':
|
2009-01-08 14:10:39 +00:00
|
|
|
free(musicdriver);
|
|
|
|
free(sounddriver);
|
|
|
|
free(videodriver);
|
|
|
|
free(blitter);
|
|
|
|
musicdriver = strdup("null");
|
|
|
|
sounddriver = strdup("null");
|
|
|
|
videodriver = strdup("dedicated");
|
|
|
|
blitter = strdup("null");
|
2006-02-21 17:29:53 +00:00
|
|
|
dedicated = true;
|
2009-02-21 13:27:09 +00:00
|
|
|
SetDebugString("net=6");
|
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-11-23 16:01:24 +00:00
|
|
|
case 'i':
|
|
|
|
/* there is an argument, it is not empty, and it is exactly 1 char long */
|
|
|
|
if (!StrEmpty(mgo.opt) && mgo.opt[1] == '\0') {
|
|
|
|
_use_palette = (PaletteType)(mgo.opt[0] - '0');
|
|
|
|
if (_use_palette <= MAX_PAL) break;
|
|
|
|
}
|
|
|
|
usererror("Valid value for '-i' is 0, 1 or 2");
|
2004-09-10 19:02:27 +00:00
|
|
|
case 'g':
|
2005-11-14 19:48:04 +00:00
|
|
|
if (mgo.opt != NULL) {
|
2008-11-02 11:20:15 +00:00
|
|
|
strecpy(_file_to_saveload.name, mgo.opt, lastof(_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) {
|
2009-01-18 22:44:53 +00:00
|
|
|
FiosType ft = FiosGetSavegameListCallback(SLD_LOAD_GAME, _file_to_saveload.name, t, NULL, NULL);
|
2008-07-28 15:31:11 +00:00
|
|
|
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
|
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
AI::Initialize();
|
2004-08-09 17:04:08 +00:00
|
|
|
LoadFromConfig();
|
2009-01-12 17:11:45 +00:00
|
|
|
AI::Uninitialize(true);
|
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-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)
|
2009-04-10 12:56:55 +00:00
|
|
|
if (dedicated_host) {
|
|
|
|
_network_bind_list.Clear();
|
|
|
|
*_network_bind_list.Append() = strdup(dedicated_host);
|
|
|
|
}
|
2008-05-29 20:21:28 +00:00
|
|
|
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
|
|
|
|
2009-02-07 00:33:35 +00:00
|
|
|
if (graphics_set == NULL) graphics_set = _ini_graphics_set;
|
|
|
|
if (!SetGraphicsSet(graphics_set)) {
|
|
|
|
StrEmpty(graphics_set) ?
|
2008-08-24 08:41:38 +00:00
|
|
|
usererror("Failed to find a graphics set. Please acquire a graphics set for OpenTTD.") :
|
2009-02-07 00:33:35 +00:00
|
|
|
usererror("Failed to select requested graphics set '%s'", 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...");
|
2009-02-07 00:33:35 +00:00
|
|
|
if (blitter == NULL) blitter = _ini_blitter;
|
|
|
|
if (BlitterFactoryBase::SelectBlitter(blitter) == NULL)
|
|
|
|
StrEmpty(blitter) ?
|
2008-06-05 20:54:52 +00:00
|
|
|
usererror("Failed to autoprobe blitter") :
|
2009-02-07 00:33:35 +00:00
|
|
|
usererror("Failed to select requested blitter '%s'; does it exist?", 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
|
|
|
|
2009-02-07 00:33:35 +00:00
|
|
|
if (sounddriver == NULL) sounddriver = _ini_sounddriver;
|
|
|
|
_sound_driver = (SoundDriver*)SoundDriverFactoryBase::SelectDriver(sounddriver, Driver::DT_SOUND);
|
2007-07-05 12:23:54 +00:00
|
|
|
if (_sound_driver == NULL) {
|
2009-02-07 00:33:35 +00:00
|
|
|
StrEmpty(sounddriver) ?
|
2008-06-05 20:54:52 +00:00
|
|
|
usererror("Failed to autoprobe sound driver") :
|
2009-02-07 00:33:35 +00:00
|
|
|
usererror("Failed to select requested sound driver '%s'", sounddriver);
|
2007-07-05 12:23:54 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 00:33:35 +00:00
|
|
|
if (musicdriver == NULL) musicdriver = _ini_musicdriver;
|
|
|
|
_music_driver = (MusicDriver*)MusicDriverFactoryBase::SelectDriver(musicdriver, Driver::DT_MUSIC);
|
2007-07-05 12:23:54 +00:00
|
|
|
if (_music_driver == NULL) {
|
2009-02-07 00:33:35 +00:00
|
|
|
StrEmpty(musicdriver) ?
|
2008-06-05 20:54:52 +00:00
|
|
|
usererror("Failed to autoprobe music driver") :
|
2009-02-07 00:33:35 +00:00
|
|
|
usererror("Failed to select requested music driver '%s'", musicdriver);
|
2007-07-05 12:23:54 +00:00
|
|
|
}
|
|
|
|
|
2009-02-07 00:33:35 +00:00
|
|
|
if (videodriver == NULL) videodriver = _ini_videodriver;
|
|
|
|
_video_driver = (VideoDriver*)VideoDriverFactoryBase::SelectDriver(videodriver, Driver::DT_VIDEO);
|
2007-07-05 12:23:54 +00:00
|
|
|
if (_video_driver == NULL) {
|
2009-02-07 00:33:35 +00:00
|
|
|
StrEmpty(videodriver) ?
|
2008-06-05 20:54:52 +00:00
|
|
|
usererror("Failed to autoprobe video driver") :
|
2009-02-07 00:33:35 +00:00
|
|
|
usererror("Failed to select requested video driver '%s'", 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);
|
|
|
|
|
2009-01-20 01:32:06 +00:00
|
|
|
NetworkStartDebugLog(NetworkAddress(debuglog_conn, rport));
|
2007-02-08 12:27:53 +00:00
|
|
|
}
|
|
|
|
#endif /* ENABLE_NETWORK */
|
|
|
|
|
2006-12-04 08:30:04 +00:00
|
|
|
ScanNewGRFFiles();
|
|
|
|
|
|
|
|
ResetGRFConfig(false);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2009-02-14 23:17:32 +00:00
|
|
|
/* Make sure _settings is filled with _settings_newgame if we switch to a game directly */
|
|
|
|
if (_switch_mode != SM_NONE) MakeNewgameSettingsLive();
|
(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
|
|
|
|
2009-02-12 10:13:30 +00:00
|
|
|
CheckForMissingGlyphsInLoadedLanguagePack();
|
|
|
|
|
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;
|
2009-01-20 01:32:06 +00:00
|
|
|
NetworkClientConnectGame(NetworkAddress(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
|
|
|
|
2009-04-15 20:49:26 +00:00
|
|
|
free(graphics_set);
|
|
|
|
free(musicdriver);
|
|
|
|
free(sounddriver);
|
|
|
|
free(videodriver);
|
|
|
|
free(blitter);
|
|
|
|
|
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) {
|
2009-02-26 20:30:41 +00:00
|
|
|
extern char _screenshot_name[];
|
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 */
|
2009-01-12 17:11:45 +00:00
|
|
|
if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 0) {
|
2008-09-30 20:39:50 +00:00
|
|
|
SetLocalCompany(COMPANY_SPECTATOR);
|
2009-01-12 17:11:45 +00:00
|
|
|
IConsoleCmdExec("exec scripts/game_start.scr 0");
|
(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
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
IConsoleCmdExec("exec scripts/game_start.scr 0");
|
|
|
|
|
2008-09-30 20:39:50 +00:00
|
|
|
SetLocalCompany(COMPANY_FIRST);
|
|
|
|
_current_company = _local_company;
|
2008-12-28 14:37:19 +00:00
|
|
|
DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, 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);
|
2009-03-08 16:51:08 +00:00
|
|
|
_engine_mngr.ResetToDefaultMapping();
|
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
|
|
|
}
|
|
|
|
|
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-12-26 18:24:05 +00:00
|
|
|
SetDParamStr(0, GetSaveLoadErrorString());
|
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_JUST_RAW_STRING, 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
|
|
|
|
2009-02-09 02:57:15 +00:00
|
|
|
SetupColoursAndInitialWindow();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
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-12-26 18:24:05 +00:00
|
|
|
SetDParamStr(0, GetSaveLoadErrorString());
|
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_JUST_RAW_STRING, 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-12-28 14:37:19 +00:00
|
|
|
DoCommandP(0, (_settings_client.gui.autorenew << 15 ) | (_settings_client.gui.autorenew_months << 16) | 4, _settings_client.gui.autorenew_money, 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
|
|
|
|
*/
|
2009-02-25 00:14:46 +00:00
|
|
|
bool SafeSaveOrLoad(const char *filename, int mode, GameMode newgm, Subdirectory subdir)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2009-02-25 00:14:46 +00:00
|
|
|
GameMode ogm = _game_mode;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
_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
|
|
|
}
|
|
|
|
|
2009-02-25 00:45:52 +00:00
|
|
|
void SwitchToMode(SwitchMode 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();
|
2009-01-12 17:11:45 +00:00
|
|
|
MakeNewgameSettingsLive();
|
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 */
|
2009-01-12 17:11:45 +00:00
|
|
|
/* Make sure all AI controllers are gone at quiting game */
|
|
|
|
if (new_mode != SM_SAVE) AI::KillAll();
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2005-03-12 21:21:47 +00:00
|
|
|
switch (new_mode) {
|
2009-03-15 00:32:18 +00:00
|
|
|
case SM_EDITOR: // Switch to scenario editor
|
2008-04-29 18:19:29 +00:00
|
|
|
MakeNewEditorWorld();
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-15 00:32:18 +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
|
|
|
|
2009-03-15 00:32:18 +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
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case SM_LOAD: { // Load game, Play Scenario
|
2008-04-29 18:19:29 +00:00
|
|
|
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-12-26 18:24:05 +00:00
|
|
|
SetDParamStr(0, GetSaveLoadErrorString());
|
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_JUST_RAW_STRING, 0, 0);
|
2008-04-29 18:19:29 +00:00
|
|
|
} 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
|
2009-03-14 18:16:29 +00:00
|
|
|
* company #1 (eg 0) or in the case of a dedicated server a spectator */
|
2008-09-30 20:39:50 +00:00
|
|
|
SetLocalCompany(_network_dedicated ? COMPANY_SPECTATOR : COMPANY_FIRST);
|
2009-01-12 17:11:45 +00:00
|
|
|
/* Execute the game-start script */
|
|
|
|
IConsoleCmdExec("exec scripts/game_start.scr 0");
|
2008-04-29 18:19:29 +00:00
|
|
|
/* Decrease pause counter (was increased from opening load dialog) */
|
2008-12-28 14:37:19 +00:00
|
|
|
DoCommandP(0, 0, 0, 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
|
|
|
}
|
|
|
|
|
2009-03-15 00:32:18 +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
|
|
|
|
2009-03-15 00:32:18 +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
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case SM_LOAD_SCENARIO: { // Load scenario from scenario editor
|
2008-04-29 18:19:29 +00:00
|
|
|
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-12-26 18:24:05 +00:00
|
|
|
SetDParamStr(0, GetSaveLoadErrorString());
|
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_JUST_RAW_STRING, 0, 0);
|
2008-04-29 18:19:29 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case SM_MENU: // Switch to game intro menu
|
2008-04-29 18:19:29 +00:00
|
|
|
LoadIntroGame();
|
|
|
|
break;
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
case SM_SAVE: // Save game
|
2008-04-29 18:19:29 +00:00
|
|
|
/* 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-12-26 18:24:05 +00:00
|
|
|
SetDParamStr(0, GetSaveLoadErrorString());
|
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_JUST_RAW_STRING, 0, 0);
|
2008-04-29 18:19:29 +00:00
|
|
|
} else {
|
|
|
|
DeleteWindowById(WC_SAVELOAD, 0);
|
|
|
|
}
|
|
|
|
if (_networking && _pause_game == 2) _pause_game = 1;
|
|
|
|
break;
|
|
|
|
|
2009-03-15 00:32:18 +00:00
|
|
|
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;
|
2009-02-25 00:45:52 +00:00
|
|
|
|
|
|
|
default: NOT_REACHED();
|
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-12-29 21:50:25 +00:00
|
|
|
if (_debug_desync_level > 1) {
|
|
|
|
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) {
|
|
|
|
DEBUG(desync, 2, "cache mismatch: vehicle %i, company %i, unit number %i\n", v->index, (int)v->owner, v->unitnumber);
|
|
|
|
}
|
|
|
|
} break;
|
2008-04-23 22:17:33 +00:00
|
|
|
|
2008-12-29 21:50:25 +00:00
|
|
|
case VEH_TRAIN: {
|
|
|
|
uint length = 0;
|
|
|
|
for (Vehicle *u = v; u != NULL; u = u->Next()) length++;
|
2008-04-23 22:17:33 +00:00
|
|
|
|
2008-12-29 21:50:25 +00:00
|
|
|
VehicleRail *wagons = MallocT<VehicleRail>(length);
|
|
|
|
length = 0;
|
|
|
|
for (Vehicle *u = v; u != NULL; u = u->Next()) wagons[length++] = u->u.rail;
|
2008-04-23 22:17:33 +00:00
|
|
|
|
2008-12-29 21:50:25 +00:00
|
|
|
TrainConsistChanged(v, true);
|
2008-04-23 22:17:33 +00:00
|
|
|
|
2008-12-29 21:50:25 +00:00
|
|
|
length = 0;
|
|
|
|
for (Vehicle *u = v; u != NULL; u = u->Next()) {
|
|
|
|
if (memcmp(&wagons[length], &u->u.rail, sizeof(VehicleRail)) != 0) {
|
|
|
|
DEBUG(desync, 2, "cache mismatch: vehicle %i, company %i, unit number %i, wagon %i\n", v->index, (int)v->owner, v->unitnumber, length);
|
|
|
|
}
|
|
|
|
length++;
|
2008-04-23 22:17:33 +00:00
|
|
|
}
|
|
|
|
|
2008-12-29 21:50:25 +00:00
|
|
|
free(wagons);
|
|
|
|
} break;
|
2008-04-23 22:17:33 +00:00
|
|
|
|
2008-12-29 21:50:25 +00:00
|
|
|
case VEH_AIRCRAFT: {
|
|
|
|
uint speed = v->u.air.cached_max_speed;
|
|
|
|
UpdateAircraftCache(v);
|
|
|
|
if (speed != v->u.air.cached_max_speed) {
|
|
|
|
DEBUG(desync, 2, "cache mismatch: vehicle %i, company %i, unit number %i\n", v->index, (int)v->owner, v->unitnumber);
|
|
|
|
}
|
|
|
|
} break;
|
2008-04-23 22:17:33 +00:00
|
|
|
|
2008-12-29 21:50:25 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-04-23 22:17:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-01-12 17:11:45 +00:00
|
|
|
AI::GameLoop();
|
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
|
2009-02-08 12:25:13 +00:00
|
|
|
* the 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 */
|
|
|
|
|
2009-02-21 15:23:49 +00:00
|
|
|
if (_settings_client.gui.keep_all_autosave) {
|
2009-01-02 22:49:43 +00:00
|
|
|
GenerateDefaultSaveName(buf, lastof(buf));
|
2008-11-02 11:20:15 +00:00
|
|
|
strecat(buf, ".sav", lastof(buf));
|
2007-06-17 15:48:57 +00:00
|
|
|
} else {
|
2009-04-09 01:22:33 +00:00
|
|
|
static int _autosave_ctr = 0;
|
|
|
|
|
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) {
|
2009-02-25 00:45:52 +00:00
|
|
|
SwitchToMode(_switch_mode);
|
2004-08-09 17:04:08 +00:00
|
|
|
_switch_mode = SM_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IncreaseSpriteLRU();
|
|
|
|
InteractiveRandom();
|
|
|
|
|
2009-02-25 21:45:14 +00:00
|
|
|
extern int _caret_timer;
|
2004-08-09 17:04:08 +00:00
|
|
|
_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 */
|
2009-01-23 22:35:48 +00:00
|
|
|
_network_playas = COMPANY_SPECTATOR;
|
2009-01-20 01:32:06 +00:00
|
|
|
NetworkClientConnectGame(NetworkAddress(_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
|
|
|
|
2008-11-25 21:09:00 +00:00
|
|
|
_sound_driver->MainLoop();
|
2005-03-30 19:52:26 +00:00
|
|
|
MusicLoop();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|