2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2005-01-29 12:19:05 +00:00
|
|
|
#include "tile.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
#define VARDEF
|
|
|
|
#include "ttd.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "station.h"
|
|
|
|
#include "vehicle.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "window.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "town.h"
|
|
|
|
#include "industry.h"
|
|
|
|
#include "news.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "economy.h"
|
|
|
|
#include "fileio.h"
|
|
|
|
#include "hal.h"
|
|
|
|
#include "airport.h"
|
|
|
|
#include "saveload.h"
|
2004-08-25 10:17:39 +00:00
|
|
|
#include "ai.h"
|
2004-08-24 08:34:28 +00:00
|
|
|
#include "console.h"
|
2004-11-15 19:25:59 +00:00
|
|
|
#include "screenshot.h"
|
2004-12-04 17:54:56 +00:00
|
|
|
#include "network.h"
|
2005-01-12 11:21:28 +00:00
|
|
|
#include "signs.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void IncreaseSpriteLRU(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
void GenerateWorld(int mode);
|
2005-01-22 20:23:18 +00:00
|
|
|
void CallLandscapeTick(void);
|
|
|
|
void IncreaseDate(void);
|
|
|
|
void RunOtherPlayersLoop(void);
|
|
|
|
void DoPaletteAnimations(void);
|
|
|
|
void MusicLoop(void);
|
|
|
|
void ResetMusic(void);
|
|
|
|
void InitializeStations(void);
|
|
|
|
void DeleteAllPlayerStations(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
extern void SetDifficultyLevel(int mode, GameOptions *gm_opt);
|
|
|
|
extern void DoStartupNewPlayer(bool is_ai);
|
|
|
|
extern void ShowOSErrorBox(const char *buf);
|
|
|
|
|
|
|
|
void redsq_debug(int tile);
|
|
|
|
bool LoadSavegame(const char *filename);
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
extern void HalGameLoop(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
uint32 _pixels_redrawn;
|
|
|
|
bool _dbg_screen_rect;
|
2004-12-04 17:54:56 +00:00
|
|
|
bool disable_computer; // We should get ride of this thing.. is only used for a debug-cheat
|
2004-09-12 22:03:14 +00:00
|
|
|
static byte _os_version = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
void CDECL error(const char *s, ...) {
|
|
|
|
va_list va;
|
|
|
|
char buf[512];
|
|
|
|
va_start(va, s);
|
|
|
|
vsprintf(buf, s, va);
|
|
|
|
va_end(va);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowOSErrorBox(buf);
|
|
|
|
if (_video_driver)
|
|
|
|
_video_driver->stop();
|
|
|
|
|
|
|
|
assert(0);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CDECL debug(const char *s, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
char buf[1024];
|
|
|
|
va_start(va, s);
|
|
|
|
vsprintf(buf, s, va);
|
|
|
|
va_end(va);
|
2004-08-25 10:17:39 +00:00
|
|
|
fprintf(stderr, "dbg: %s\n", buf);
|
2005-01-23 10:54:32 +00:00
|
|
|
IConsoleDebug(buf);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CDECL ShowInfoF(const char *str, ...)
|
|
|
|
{
|
|
|
|
va_list va;
|
|
|
|
char buf[1024];
|
|
|
|
va_start(va, str);
|
|
|
|
vsprintf(buf, str, va);
|
|
|
|
va_end(va);
|
|
|
|
ShowInfo(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
char * CDECL str_fmt(const char *str, ...)
|
|
|
|
{
|
|
|
|
char buf[4096];
|
|
|
|
va_list va;
|
|
|
|
int len;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
va_start(va, str);
|
|
|
|
len = vsprintf(buf, str, va);
|
|
|
|
va_end(va);
|
|
|
|
p = malloc(len + 1);
|
|
|
|
if (p)
|
|
|
|
memcpy(p, buf, len + 1);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NULL midi driver
|
|
|
|
static char *NullMidiStart(char **parm) { return NULL; }
|
2005-01-22 20:23:18 +00:00
|
|
|
static void NullMidiStop(void) {}
|
2004-08-09 17:04:08 +00:00
|
|
|
static void NullMidiPlaySong(const char *filename) {}
|
2005-01-22 20:23:18 +00:00
|
|
|
static void NullMidiStopSong(void) {}
|
|
|
|
static bool NullMidiIsSongPlaying(void) { return true; }
|
2004-08-09 17:04:08 +00:00
|
|
|
static void NullMidiSetVolume(byte vol) {}
|
|
|
|
|
|
|
|
const HalMusicDriver _null_music_driver = {
|
|
|
|
NullMidiStart,
|
|
|
|
NullMidiStop,
|
|
|
|
NullMidiPlaySong,
|
|
|
|
NullMidiStopSong,
|
|
|
|
NullMidiIsSongPlaying,
|
|
|
|
NullMidiSetVolume,
|
|
|
|
};
|
|
|
|
|
|
|
|
// NULL video driver
|
|
|
|
static void *_null_video_mem;
|
|
|
|
static const char *NullVideoStart(char **parm) {
|
|
|
|
_screen.width = _screen.pitch = _cur_resolution[0];
|
|
|
|
_screen.height = _cur_resolution[1];
|
|
|
|
_null_video_mem = malloc(_cur_resolution[0]*_cur_resolution[1]);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-01-22 20:23:18 +00:00
|
|
|
static void NullVideoStop(void) { free(_null_video_mem); }
|
2004-08-09 17:04:08 +00:00
|
|
|
static void NullVideoMakeDirty(int left, int top, int width, int height) {}
|
2005-01-22 20:23:18 +00:00
|
|
|
static int NullVideoMainLoop(void)
|
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
int i = 1000;
|
|
|
|
do {
|
|
|
|
GameLoop();
|
|
|
|
_screen.dst_ptr = _null_video_mem;
|
|
|
|
UpdateWindows();
|
|
|
|
} while (--i);
|
|
|
|
return ML_QUIT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool NullVideoChangeRes(int w, int h) { return false; }
|
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
const HalVideoDriver _null_video_driver = {
|
|
|
|
NullVideoStart,
|
|
|
|
NullVideoStop,
|
|
|
|
NullVideoMakeDirty,
|
|
|
|
NullVideoMainLoop,
|
|
|
|
NullVideoChangeRes,
|
|
|
|
};
|
|
|
|
|
|
|
|
// NULL sound driver
|
|
|
|
static char *NullSoundStart(char **parm) { return NULL; }
|
2005-01-22 20:23:18 +00:00
|
|
|
static void NullSoundStop(void) {}
|
2004-08-09 17:04:08 +00:00
|
|
|
const HalSoundDriver _null_sound_driver = {
|
|
|
|
NullSoundStart,
|
|
|
|
NullSoundStop,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
DF_PRIORITY_MASK = 0xf,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const DriverDesc *descs;
|
|
|
|
const char *name;
|
|
|
|
void *var;
|
|
|
|
} DriverClass;
|
|
|
|
|
|
|
|
static DriverClass _driver_classes[] = {
|
|
|
|
{_video_driver_descs, "video", &_video_driver},
|
|
|
|
{_sound_driver_descs, "sound", &_sound_driver},
|
|
|
|
{_music_driver_descs, "music", &_music_driver},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const DriverDesc *GetDriverByName(const DriverDesc *dd, const char *name)
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
if (!strcmp(dd->name, name))
|
|
|
|
return dd;
|
|
|
|
} while ((++dd)->name);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const DriverDesc *ChooseDefaultDriver(const DriverDesc *dd)
|
|
|
|
{
|
|
|
|
const DriverDesc *best = NULL;
|
|
|
|
int best_pri = -1;
|
|
|
|
do {
|
2004-09-12 22:03:14 +00:00
|
|
|
if ((int)(dd->flags&DF_PRIORITY_MASK) > best_pri && _os_version >= (byte)dd->flags) {
|
2004-08-09 17:04:08 +00:00
|
|
|
best_pri = dd->flags&DF_PRIORITY_MASK;
|
|
|
|
best = dd;
|
|
|
|
}
|
|
|
|
} while ((++dd)->name);
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
2005-01-23 15:16:47 +00:00
|
|
|
void ttd_strlcpy(char *dst, const char *src, size_t size)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-01-23 15:16:47 +00:00
|
|
|
assert(size > 0);
|
|
|
|
while (--size > 0 && *src != '\0') *dst++ = *src++;
|
|
|
|
*dst = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
void ttd_strlcat(char *dst, const char *src, size_t size)
|
|
|
|
{
|
|
|
|
assert(size > 0);
|
|
|
|
for (; size > 0 && *dst != '\0'; --size, ++dst) {}
|
|
|
|
assert(size > 0);
|
|
|
|
while (--size > 0 && *src != '\0') *dst++ = *src++;
|
|
|
|
*dst = '\0';
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 22:47:58 +00:00
|
|
|
static char *strecpy(char *dst, const char *src)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
while ( (*dst++ = *src++) != 0) {}
|
|
|
|
return dst - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize)
|
|
|
|
{
|
|
|
|
FILE *in;
|
2005-01-23 10:54:32 +00:00
|
|
|
byte *mem;
|
2004-08-09 17:04:08 +00:00
|
|
|
size_t len;
|
|
|
|
|
|
|
|
in = fopen(filename, "rb");
|
|
|
|
if (in == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
fseek(in, 0, SEEK_END);
|
|
|
|
len = ftell(in);
|
|
|
|
fseek(in, 0, SEEK_SET);
|
2005-01-23 10:54:32 +00:00
|
|
|
if (len > maxsize || (mem = malloc(len + 1)) == NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
fclose(in);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-01-23 10:54:32 +00:00
|
|
|
mem[len] = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (fread(mem, len, 1, in) != 1) {
|
|
|
|
fclose(in);
|
|
|
|
free(mem);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
fclose(in);
|
|
|
|
|
|
|
|
*lenp = len;
|
|
|
|
return mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadDriver(int driver, const char *name)
|
|
|
|
{
|
|
|
|
const DriverClass *dc = &_driver_classes[driver];
|
|
|
|
const DriverDesc *dd;
|
|
|
|
const void **var;
|
|
|
|
const void *drv;
|
|
|
|
const char *err;
|
|
|
|
char *parm;
|
|
|
|
char buffer[256];
|
|
|
|
char *parms[32];
|
|
|
|
|
|
|
|
parms[0] = NULL;
|
|
|
|
|
|
|
|
if (!*name) {
|
|
|
|
dd = ChooseDefaultDriver(dc->descs);
|
|
|
|
} else {
|
|
|
|
// Extract the driver name and put parameter list in parm
|
|
|
|
ttd_strlcpy(buffer, name, sizeof(buffer));
|
|
|
|
parm = strchr(buffer, ':');
|
|
|
|
if (parm) {
|
2005-01-09 21:25:44 +00:00
|
|
|
uint np = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
// Tokenize the parm.
|
|
|
|
do {
|
|
|
|
*parm++ = 0;
|
|
|
|
if (np < lengthof(parms) - 1)
|
|
|
|
parms[np++] = parm;
|
|
|
|
while (*parm != 0 && *parm != ',')
|
|
|
|
parm++;
|
|
|
|
} while (*parm == ',');
|
|
|
|
parms[np] = NULL;
|
|
|
|
}
|
|
|
|
dd = GetDriverByName(dc->descs, buffer);
|
|
|
|
if (dd == NULL)
|
|
|
|
error("No such %s driver: %s\n", dc->name, buffer);
|
|
|
|
}
|
|
|
|
var = dc->var;
|
2004-09-12 21:49:38 +00:00
|
|
|
if (*var != NULL) ((const HalCommonDriver*)*var)->stop();
|
2004-08-09 17:04:08 +00:00
|
|
|
*var = NULL;
|
|
|
|
drv = dd->drv;
|
2004-09-12 21:49:38 +00:00
|
|
|
if ((err=((const HalCommonDriver*)drv)->start(parms)) != NULL)
|
2004-08-09 17:04:08 +00:00
|
|
|
error("Unable to load driver %s(%s). The error was: %s\n", dd->name, dd->longname, err);
|
|
|
|
*var = drv;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void showhelp(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
char buf[4096], *p;
|
|
|
|
const DriverClass *dc = _driver_classes;
|
|
|
|
const DriverDesc *dd;
|
|
|
|
int i;
|
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
p = strecpy(buf,
|
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"
|
|
|
|
" -s drv = Set sound driver (see below)\n"
|
|
|
|
" -m drv = Set music driver (see below)\n"
|
|
|
|
" -r res = Set resolution (for instance 800x600)\n"
|
|
|
|
" -h = Display this help text\n"
|
|
|
|
" -t date = Set starting date\n"
|
|
|
|
" -d [dbg] = Debug mode\n"
|
|
|
|
" -l lng = Select Language\n"
|
|
|
|
" -e = Start Editor\n"
|
|
|
|
" -g [savegame] = Start new/save game immediately\n"
|
|
|
|
" -G seed = Set random seed\n"
|
|
|
|
" -n [ip#player:port] = Start networkgame\n"
|
|
|
|
" -D = Start dedicated server\n"
|
2004-12-22 21:12:36 +00:00
|
|
|
#if !defined(__MORPHOS__) && !defined(__AMIGA__)
|
2004-12-18 14:19:21 +00:00
|
|
|
" -f = Fork into the background (dedicated only)\n"
|
2004-12-22 21:12:36 +00:00
|
|
|
#endif
|
2004-12-12 20:36:24 +00:00
|
|
|
" -i = Force to use the DOS palette (use this if you see a lot of pink)\n"
|
2004-12-04 17:54:56 +00:00
|
|
|
" -p #player = Player as #player (deprecated) (network only)\n"
|
2004-08-09 17:04:08 +00:00
|
|
|
);
|
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
for(i=0; i!=lengthof(_driver_classes); i++,dc++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
p += sprintf(p, "List of %s drivers:\n", dc->name);
|
|
|
|
dd = dc->descs;
|
|
|
|
do {
|
|
|
|
p += sprintf(p, "%10s: %s\n", dd->name, dd->longname);
|
|
|
|
} while ((++dd)->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowInfo(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char *GetDriverParam(char **parm, const char *name)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
int len = strlen(name);
|
|
|
|
while ((p = *parm++) != NULL) {
|
|
|
|
if (!strncmp(p,name,len)) {
|
|
|
|
if (p[len] == '=') return p + len + 1;
|
|
|
|
if (p[len] == 0) return p + len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GetDriverParamBool(char **parm, const char *name)
|
|
|
|
{
|
|
|
|
char *p = GetDriverParam(parm, name);
|
|
|
|
return p != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GetDriverParamInt(char **parm, const char *name, int def)
|
|
|
|
{
|
|
|
|
char *p = GetDriverParam(parm, name);
|
|
|
|
return p != NULL ? atoi(p) : def;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
char *opt;
|
|
|
|
int numleft;
|
|
|
|
char **argv;
|
|
|
|
const char *options;
|
|
|
|
char *cont;
|
|
|
|
} MyGetOptData;
|
|
|
|
|
|
|
|
static void MyGetOptInit(MyGetOptData *md, int argc, char **argv, const char *options)
|
|
|
|
{
|
|
|
|
md->cont = NULL;
|
|
|
|
md->numleft = argc;
|
|
|
|
md->argv = argv;
|
|
|
|
md->options = options;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int MyGetOpt(MyGetOptData *md)
|
|
|
|
{
|
|
|
|
char *s,*r,*t;
|
|
|
|
|
|
|
|
if ((s=md->cont) != NULL)
|
|
|
|
goto md_continue_here;
|
|
|
|
|
|
|
|
while(true) {
|
|
|
|
if (--md->numleft < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
s = *md->argv++;
|
|
|
|
if (*s == '-') {
|
|
|
|
md_continue_here:;
|
|
|
|
s++;
|
|
|
|
if (*s != 0) {
|
|
|
|
// Found argument, try to locate it in options.
|
|
|
|
if (*s == ':' || (r = strchr(md->options, *s)) == NULL) {
|
|
|
|
// ERROR!
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
if (r[1] == ':') {
|
|
|
|
// Item wants an argument. Check if the argument follows, or if it comes as a separate arg.
|
|
|
|
if (!*(t = s + 1)) {
|
|
|
|
// It comes as a separate arg. Check if out of args?
|
|
|
|
if (--md->numleft < 0 || *(t = *md->argv) == '-') {
|
|
|
|
// Check if item is optional?
|
|
|
|
if (r[2] != ':')
|
|
|
|
return -2;
|
|
|
|
md->numleft++;
|
|
|
|
t = NULL;
|
|
|
|
} else {
|
|
|
|
md->argv++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
md->opt = t;
|
|
|
|
md->cont = NULL;
|
|
|
|
return *s;
|
|
|
|
}
|
|
|
|
md->opt = NULL;
|
|
|
|
md->cont = s;
|
|
|
|
return *s;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This is currently not supported.
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetDebugString(const char *s)
|
|
|
|
{
|
|
|
|
int v;
|
|
|
|
char *end;
|
|
|
|
const char *t;
|
|
|
|
int *p;
|
|
|
|
|
|
|
|
// global debugging level?
|
|
|
|
if (*s >= '0' && *s <= '9') {
|
|
|
|
v = strtoul(s, &end, 0);
|
|
|
|
s = end;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
_debug_spritecache_level = v;
|
|
|
|
_debug_misc_level = v;
|
2004-08-16 14:48:35 +00:00
|
|
|
_debug_grf_level = v;
|
2004-08-20 09:32:32 +00:00
|
|
|
_debug_ai_level = v;
|
2004-09-08 19:20:46 +00:00
|
|
|
_debug_net_level = v;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// individual levels
|
|
|
|
for(;;) {
|
|
|
|
// skip delimiters
|
|
|
|
while (*s == ' ' || *s == ',' || *s == '\t') s++;
|
|
|
|
if (*s == 0) break;
|
|
|
|
|
|
|
|
t = s;
|
|
|
|
while (*s >= 'a' && *s <= 'z') s++;
|
|
|
|
|
|
|
|
#define IS_LVL(x) (s - t == sizeof(x)-1 && !memcmp(t, x, sizeof(x)-1))
|
|
|
|
// check debugging levels
|
|
|
|
if IS_LVL("misc") p = &_debug_misc_level;
|
|
|
|
else if IS_LVL("spritecache") p = &_debug_spritecache_level;
|
2004-08-16 14:48:35 +00:00
|
|
|
else if IS_LVL("grf") p = &_debug_grf_level;
|
2004-08-20 09:32:32 +00:00
|
|
|
else if IS_LVL("ai") p = &_debug_ai_level;
|
2004-09-08 19:20:46 +00:00
|
|
|
else if IS_LVL("net") p = &_debug_net_level;
|
2004-08-09 17:04:08 +00:00
|
|
|
else {
|
|
|
|
ShowInfoF("Unknown debug level '%.*s'", s-t, t);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#undef IS_LVL
|
|
|
|
if (*s == '=') s++;
|
|
|
|
v = strtoul(s, &end, 0);
|
|
|
|
s = end;
|
|
|
|
if (p) *p = v;
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 22:47:58 +00:00
|
|
|
static void ParseResolution(int res[2], char *s)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
char *t = strchr(s, 'x');
|
|
|
|
if (t == NULL) {
|
|
|
|
ShowInfoF("Invalid resolution '%s'", s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-09-23 21:44:36 +00:00
|
|
|
res[0] = strtoul(s, NULL, 0);
|
|
|
|
res[1] = strtoul(t + 1, NULL, 0);
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
static void InitializeDynamicVariables(void)
|
|
|
|
{
|
|
|
|
/* Dynamic stuff needs to be initialized somewhere... */
|
|
|
|
_stations_size = lengthof(_stations);
|
|
|
|
_station_sort = NULL;
|
|
|
|
|
|
|
|
_vehicles_size = lengthof(_vehicles);
|
|
|
|
_vehicle_sort = NULL;
|
|
|
|
|
|
|
|
_towns_size = lengthof(_towns);
|
|
|
|
_town_sort = NULL;
|
|
|
|
|
|
|
|
_industries_size = lengthof(_industries);
|
|
|
|
_industry_sort = NULL;
|
2005-01-12 11:21:28 +00:00
|
|
|
|
|
|
|
_sign_size = lengthof(_sign_list);
|
2005-01-15 19:06:22 +00:00
|
|
|
_orders_size = lengthof(_orders);
|
2005-01-06 22:31:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void UnInitializeDynamicVariables(void)
|
|
|
|
{
|
|
|
|
/* Dynamic stuff needs to be free'd somewhere... */
|
|
|
|
free(_station_sort);
|
|
|
|
|
|
|
|
free(_vehicle_sort);
|
|
|
|
|
|
|
|
free(_town_sort);
|
|
|
|
|
|
|
|
free(_industry_sort);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-22 22:47:58 +00:00
|
|
|
static void LoadIntroGame(void)
|
2004-12-04 17:54:56 +00:00
|
|
|
{
|
|
|
|
char filename[256];
|
|
|
|
_game_mode = GM_MENU;
|
|
|
|
_display_opt &= ~DO_TRANS_BUILDINGS; // don't make buildings transparent in intro
|
|
|
|
|
|
|
|
_opt_mod_ptr = &_new_opt;
|
|
|
|
GfxLoadSprites();
|
|
|
|
LoadStringWidthTable();
|
|
|
|
|
|
|
|
// Setup main window
|
|
|
|
InitWindowSystem();
|
|
|
|
SetupColorsAndInitialWindow();
|
|
|
|
|
|
|
|
// Generate a world.
|
|
|
|
sprintf(filename, "%sopntitle.dat", _path.data_dir);
|
2005-01-07 08:07:24 +00:00
|
|
|
if (SaveOrLoad(filename, SL_LOAD) != SL_OK) {
|
2004-12-07 17:16:57 +00:00
|
|
|
#if defined SECOND_DATA_DIR
|
|
|
|
sprintf(filename, "%sopntitle.dat", _path.second_data_dir);
|
|
|
|
if (SaveOrLoad(filename, SL_LOAD) != SL_OK)
|
|
|
|
#endif
|
|
|
|
GenerateWorld(1); // if failed loading, make empty world.
|
2005-01-07 08:07:24 +00:00
|
|
|
}
|
2004-12-04 17:54:56 +00:00
|
|
|
_opt.currency = _new_opt.currency;
|
|
|
|
|
|
|
|
_pause = 0;
|
|
|
|
_local_player = 0;
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
|
|
|
|
// Play main theme
|
|
|
|
if (_music_driver->is_song_playing()) ResetMusic();
|
|
|
|
}
|
|
|
|
|
2004-12-23 00:24:44 +00:00
|
|
|
extern void DedicatedFork(void);
|
2005-01-22 20:23:18 +00:00
|
|
|
extern void CheckExternalFiles(void);
|
2004-12-18 14:19:21 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
int ttd_main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
MyGetOptData mgo;
|
|
|
|
int i;
|
2004-12-04 17:54:56 +00:00
|
|
|
bool network = false;
|
2004-08-09 17:04:08 +00:00
|
|
|
char *network_conn = NULL;
|
|
|
|
char *language = NULL;
|
2005-01-14 19:44:42 +00:00
|
|
|
const char *optformat;
|
2004-11-20 11:15:31 +00:00
|
|
|
char musicdriver[16], sounddriver[16], videodriver[16];
|
2004-08-09 17:04:08 +00:00
|
|
|
int resolution[2] = {0,0};
|
|
|
|
uint startdate = -1;
|
|
|
|
musicdriver[0] = sounddriver[0] = videodriver[0] = 0;
|
|
|
|
|
|
|
|
_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;
|
|
|
|
_dedicated_enabled = false;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-15 20:10:44 +00:00
|
|
|
_redirect_console_to_client = 0;
|
|
|
|
|
2004-12-04 17:54:56 +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>)
|
2004-12-22 21:12:36 +00:00
|
|
|
#if !defined(__MORPHOS__) && !defined(__AMIGA__)
|
|
|
|
optformat = "m:s:v:hDfn::l:eit:d::r:g::G:p:";
|
|
|
|
#else
|
|
|
|
optformat = "m:s:v:hDn::l:eit:d::r:g::G:p:"; // no fork option
|
|
|
|
#endif
|
|
|
|
|
|
|
|
MyGetOptInit(&mgo, argc-1, argv+1, optformat);
|
2004-08-09 17:04:08 +00:00
|
|
|
while ((i = MyGetOpt(&mgo)) != -1) {
|
|
|
|
switch(i) {
|
|
|
|
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;
|
2004-12-04 17:54:56 +00:00
|
|
|
case 'D': {
|
|
|
|
sprintf(musicdriver,"null");
|
|
|
|
sprintf(sounddriver,"null");
|
|
|
|
sprintf(videodriver,"dedicated");
|
2004-12-18 14:19:21 +00:00
|
|
|
_dedicated_enabled = true;
|
2004-12-04 17:54:56 +00:00
|
|
|
} break;
|
2004-12-18 14:19:21 +00:00
|
|
|
case 'f': {
|
|
|
|
_dedicated_forks = true;
|
|
|
|
}; break;
|
2004-08-10 14:14:00 +00:00
|
|
|
case 'n': {
|
2004-12-04 17:54:56 +00:00
|
|
|
network = true;
|
|
|
|
if (mgo.opt)
|
|
|
|
// Optional, you can give an IP
|
2004-09-10 19:02:27 +00:00
|
|
|
network_conn = mgo.opt;
|
2004-08-10 14:14:00 +00:00
|
|
|
else
|
|
|
|
network_conn = NULL;
|
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
case 'r': ParseResolution(resolution, mgo.opt); break;
|
|
|
|
case 'l': {
|
|
|
|
language = mgo.opt;
|
|
|
|
} break;
|
|
|
|
case 't': {
|
|
|
|
startdate = atoi(mgo.opt);
|
|
|
|
} break;
|
|
|
|
case 'd': {
|
|
|
|
#if defined(WIN32)
|
|
|
|
CreateConsole();
|
|
|
|
#endif
|
|
|
|
if (mgo.opt)
|
|
|
|
SetDebugString(mgo.opt);
|
|
|
|
} break;
|
|
|
|
case 'e': _switch_mode = SM_EDITOR; break;
|
2004-12-12 20:36:24 +00:00
|
|
|
case 'i': _use_dos_palette = true; break;
|
2004-09-10 19:02:27 +00:00
|
|
|
case 'g':
|
2004-08-09 17:04:08 +00:00
|
|
|
if (mgo.opt) {
|
|
|
|
strcpy(_file_to_saveload.name, mgo.opt);
|
|
|
|
_switch_mode = SM_LOAD;
|
|
|
|
} else
|
|
|
|
_switch_mode = SM_NEWGAME;
|
|
|
|
break;
|
|
|
|
case 'G':
|
2004-09-11 19:34:11 +00:00
|
|
|
_random_seeds[0][0] = atoi(mgo.opt);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
case 'p': {
|
|
|
|
int i = atoi(mgo.opt);
|
2004-12-04 17:54:56 +00:00
|
|
|
// Play as an other player in network games
|
|
|
|
if (IS_INT_INSIDE(i, 1, MAX_PLAYERS)) _network_playas = i;
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case -2:
|
|
|
|
case 'h':
|
|
|
|
showhelp();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DeterminePaths();
|
2005-01-10 01:14:26 +00:00
|
|
|
CheckExternalFiles();
|
2004-12-18 14:19:21 +00:00
|
|
|
|
|
|
|
#ifdef UNIX
|
|
|
|
// We must fork here, or we'll end up without some resources we need (like sockets)
|
|
|
|
if (_dedicated_forks)
|
|
|
|
DedicatedFork();
|
|
|
|
#endif
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
LoadFromConfig();
|
2005-01-11 00:54:06 +00:00
|
|
|
LoadFromHighScore();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// override config?
|
2004-11-20 11:15:31 +00:00
|
|
|
if (musicdriver[0]) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver));
|
|
|
|
if (sounddriver[0]) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver));
|
|
|
|
if (videodriver[0]) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver));
|
2004-08-09 17:04:08 +00:00
|
|
|
if (resolution[0]) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; }
|
2005-01-12 11:54:51 +00:00
|
|
|
if (startdate != (uint)-1) _patches.starting_date = startdate;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-18 14:19:21 +00:00
|
|
|
if (_dedicated_forks && !_dedicated_enabled)
|
|
|
|
_dedicated_forks = false;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// enumerate language files
|
|
|
|
InitializeLanguagePacks();
|
|
|
|
|
|
|
|
// initialize screenshot formats
|
|
|
|
InitializeScreenshotFormats();
|
|
|
|
|
2004-08-22 10:23:37 +00:00
|
|
|
// initialize airport state machines
|
|
|
|
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();
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// Sample catalogue
|
|
|
|
DEBUG(misc, 1) ("Loading sound effects...");
|
2004-09-12 22:03:14 +00:00
|
|
|
_os_version = GetOSVersion();
|
2004-09-10 19:02:27 +00:00
|
|
|
MxInitialize(11025, "sample.cat");
|
2004-08-09 17:04:08 +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
|
|
|
|
|
|
|
GfxLoadSprites();
|
|
|
|
LoadStringWidthTable();
|
|
|
|
|
|
|
|
DEBUG(misc, 1) ("Loading drivers...");
|
|
|
|
LoadDriver(SOUND_DRIVER, _ini_sounddriver);
|
|
|
|
LoadDriver(MUSIC_DRIVER, _ini_musicdriver);
|
|
|
|
LoadDriver(VIDEO_DRIVER, _ini_videodriver); // load video last, to prevent an empty window while sound and music loads
|
|
|
|
MusicLoop();
|
2004-09-06 21:20:01 +00:00
|
|
|
_savegame_sort_order = 1; // default sorting of savegames is by date, newest first
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
|
|
|
// initialize network-core
|
|
|
|
NetworkStartUp();
|
|
|
|
#endif /* ENABLE_NETWORK */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// Default difficulty level
|
|
|
|
_opt_mod_ptr = &_new_opt;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// ugly hack, if diff_level is 9, it means we got no setting from the config file, so we load the default settings.
|
|
|
|
if (_opt_mod_ptr->diff_level == 9)
|
|
|
|
SetDifficultyLevel(0, _opt_mod_ptr);
|
|
|
|
|
2004-08-25 10:17:39 +00:00
|
|
|
// initialize the ingame console
|
|
|
|
IConsoleInit();
|
2004-12-13 22:13:02 +00:00
|
|
|
IConsoleCmdExec("exec scripts/autoexec.scr 0");
|
2004-12-14 20:27:00 +00:00
|
|
|
|
2004-09-11 19:34:11 +00:00
|
|
|
InitPlayerRandoms();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
|
|
|
if ((network) && (_network_available)) {
|
|
|
|
if (network_conn != NULL) {
|
|
|
|
const byte *port = NULL;
|
|
|
|
const byte *player = NULL;
|
|
|
|
uint16 rport;
|
|
|
|
|
|
|
|
rport = NETWORK_DEFAULT_PORT;
|
|
|
|
|
|
|
|
ParseConnectionString(&player, &port, network_conn);
|
|
|
|
|
|
|
|
if (player != NULL) _network_playas = atoi(player);
|
|
|
|
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 */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
while (_video_driver->main_loop() == ML_SWITCHDRIVER) {}
|
2004-08-25 10:17:39 +00:00
|
|
|
|
|
|
|
IConsoleFree();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2004-08-22 10:23:37 +00:00
|
|
|
if (_network_available) {
|
2004-12-04 17:54:56 +00:00
|
|
|
// Shut down the network and close any open connections
|
|
|
|
NetworkDisconnect();
|
|
|
|
NetworkUDPClose();
|
|
|
|
NetworkShutDown();
|
|
|
|
}
|
|
|
|
#endif /* ENABLE_NETWORK */
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
_video_driver->stop();
|
|
|
|
_music_driver->stop();
|
|
|
|
_sound_driver->stop();
|
|
|
|
|
|
|
|
SaveToConfig();
|
2005-01-11 00:54:06 +00:00
|
|
|
SaveToHighScore();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-08-22 10:23:37 +00:00
|
|
|
// uninitialize airport state machines
|
|
|
|
UnInitializeAirports();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
/* uninitialize variables that are allocated dynamic */
|
|
|
|
UnInitializeDynamicVariables();
|
|
|
|
|
2005-01-16 12:14:52 +00:00
|
|
|
/* Close all and any open filehandles */
|
|
|
|
FioCloseAll();
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ShowScreenshotResult(bool b)
|
|
|
|
{
|
|
|
|
if (b) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, STR_SPEC_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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-01-22 22:47:58 +00:00
|
|
|
static void MakeNewGame(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
_game_mode = GM_NORMAL;
|
|
|
|
|
|
|
|
// Copy in game options
|
|
|
|
_opt_mod_ptr = &_opt;
|
|
|
|
memcpy(&_opt, &_new_opt, sizeof(_opt));
|
|
|
|
|
|
|
|
GfxLoadSprites();
|
|
|
|
|
2004-08-25 08:55:53 +00:00
|
|
|
// Reinitialize windows
|
2004-08-09 17:04:08 +00:00
|
|
|
InitWindowSystem();
|
|
|
|
LoadStringWidthTable();
|
|
|
|
|
|
|
|
SetupColorsAndInitialWindow();
|
|
|
|
|
|
|
|
// Randomize world
|
|
|
|
GenerateWorld(0);
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
// In a dedicated server, the server does not play
|
|
|
|
if (_network_dedicated) {
|
|
|
|
_local_player = OWNER_SPECTATOR;
|
|
|
|
} else {
|
|
|
|
// Create a single player
|
|
|
|
DoStartupNewPlayer(false);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
_local_player = 0;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void MakeNewEditorWorld(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
_game_mode = GM_EDITOR;
|
|
|
|
|
|
|
|
// Copy in game options
|
|
|
|
_opt_mod_ptr = &_opt;
|
|
|
|
memcpy(&_opt, &_new_opt, sizeof(_opt));
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
GfxLoadSprites();
|
|
|
|
|
2004-08-25 08:55:53 +00:00
|
|
|
// Re-init the windowing system
|
2004-08-09 17:04:08 +00:00
|
|
|
InitWindowSystem();
|
|
|
|
|
|
|
|
// Create toolbars
|
|
|
|
SetupColorsAndInitialWindow();
|
|
|
|
|
|
|
|
// Startup the game system
|
|
|
|
GenerateWorld(1);
|
|
|
|
|
|
|
|
_local_player = OWNER_NONE;
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void StartupPlayers(void);
|
|
|
|
void StartupDisasters(void);
|
2004-08-23 10:59:03 +00:00
|
|
|
|
2005-01-22 22:47:58 +00:00
|
|
|
static void StartScenario(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
_game_mode = GM_NORMAL;
|
|
|
|
|
|
|
|
// invalid type
|
|
|
|
if (_file_to_saveload.mode == SL_INVALID) {
|
|
|
|
printf("Savegame is obsolete or invalid format: %s\n", _file_to_saveload.name);
|
|
|
|
ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0);
|
|
|
|
_game_mode = GM_MENU;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy in game options
|
2004-09-19 23:05:09 +00:00
|
|
|
// Removed copying of game options when using "new game". --dominik
|
|
|
|
// _opt_mod_ptr = &_opt;
|
|
|
|
// memcpy(&_opt, &_new_opt, sizeof(_opt));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
GfxLoadSprites();
|
|
|
|
|
2004-08-25 08:55:53 +00:00
|
|
|
// Reinitialize windows
|
2004-08-09 17:04:08 +00:00
|
|
|
InitWindowSystem();
|
|
|
|
LoadStringWidthTable();
|
|
|
|
|
|
|
|
SetupColorsAndInitialWindow();
|
|
|
|
|
|
|
|
// Load game
|
|
|
|
if (SaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode) != SL_OK) {
|
|
|
|
LoadIntroGame();
|
|
|
|
ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0);
|
|
|
|
}
|
|
|
|
|
2004-08-23 08:59:36 +00:00
|
|
|
// Inititalize data
|
|
|
|
StartupPlayers();
|
|
|
|
StartupEngines();
|
|
|
|
StartupDisasters();
|
|
|
|
|
2004-08-25 10:17:39 +00:00
|
|
|
// When starting a scenario, is it really a load..
|
|
|
|
// and in AfterLoad a player is started when it is
|
|
|
|
// a scenario.. so we do not need it here.
|
|
|
|
// DoStartupNewPlayer(false);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
_local_player = 0;
|
|
|
|
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
bool SafeSaveOrLoad(const char *filename, int mode, int newgm)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
byte ogm = _game_mode;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
_game_mode = newgm;
|
|
|
|
r = SaveOrLoad(filename, mode);
|
|
|
|
if (r == SL_REINIT) {
|
|
|
|
if (ogm == GM_MENU)
|
|
|
|
LoadIntroGame();
|
|
|
|
else if (ogm == GM_EDITOR)
|
|
|
|
MakeNewEditorWorld();
|
|
|
|
else
|
|
|
|
MakeNewGame();
|
|
|
|
return false;
|
|
|
|
} else if (r != SL_OK) {
|
|
|
|
_game_mode = ogm;
|
2004-09-10 19:02:27 +00:00
|
|
|
return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
void SwitchMode(int new_mode)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-08-25 10:17:39 +00:00
|
|
|
_in_state_game_loop = true;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
|
|
|
// If we are saving something, the network stays in his current state
|
|
|
|
if (new_mode != SM_SAVE) {
|
|
|
|
// If the network is active, make it not-active
|
|
|
|
if (_networking) {
|
|
|
|
if (_network_server && (new_mode == SM_LOAD || new_mode == SM_NEWGAME)) {
|
|
|
|
NetworkReboot();
|
|
|
|
NetworkUDPClose();
|
|
|
|
} else {
|
|
|
|
NetworkDisconnect();
|
|
|
|
NetworkUDPClose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are a server, we restart the server
|
|
|
|
if (_is_network_server) {
|
|
|
|
// But not if we are going to the menu
|
|
|
|
if (new_mode != SM_MENU) {
|
|
|
|
NetworkServerStart();
|
|
|
|
} else {
|
|
|
|
// This client no longer wants to be a network-server
|
|
|
|
_is_network_server = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* ENABLE_NETWORK */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
switch(new_mode) {
|
|
|
|
case SM_EDITOR: // Switch to scenario editor
|
|
|
|
MakeNewEditorWorld();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SM_NEWGAME:
|
2004-12-13 17:58:53 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2004-12-04 17:54:56 +00:00
|
|
|
if (_network_server)
|
|
|
|
snprintf(_network_game_info.map_name, 40, "Random");
|
2004-12-13 17:58:53 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2004-08-09 17:04:08 +00:00
|
|
|
MakeNewGame();
|
|
|
|
break;
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
case SM_START_SCENARIO:
|
|
|
|
StartScenario();
|
|
|
|
break;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
normal_load:
|
|
|
|
case SM_LOAD: { // Load game
|
|
|
|
|
|
|
|
_error_message = INVALID_STRING_ID;
|
|
|
|
if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL)) {
|
2005-01-08 15:26:58 +00:00
|
|
|
LoadIntroGame();
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0);
|
|
|
|
} else {
|
|
|
|
_opt_mod_ptr = &_opt;
|
|
|
|
_local_player = 0;
|
|
|
|
DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog)
|
2004-12-13 17:58:53 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2004-12-04 17:54:56 +00:00
|
|
|
if (_network_server)
|
|
|
|
snprintf(_network_game_info.map_name, 40, "Loaded game");
|
2004-12-13 17:58:53 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SM_LOAD_SCENARIO: {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (_game_mode == GM_MENU) goto normal_load;
|
|
|
|
|
|
|
|
if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR)) {
|
|
|
|
_opt_mod_ptr = &_opt;
|
|
|
|
|
|
|
|
_local_player = OWNER_NONE;
|
|
|
|
_generating_world = true;
|
|
|
|
// delete all players.
|
|
|
|
for(i=0; i != MAX_PLAYERS; i++) {
|
|
|
|
ChangeOwnershipOfPlayerItems(i, 0xff);
|
|
|
|
_players[i].is_active = false;
|
|
|
|
}
|
|
|
|
_generating_world = false;
|
|
|
|
// delete all stations owned by a player
|
|
|
|
DeleteAllPlayerStations();
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2004-12-13 17:58:53 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2004-12-04 17:54:56 +00:00
|
|
|
if (_network_server)
|
|
|
|
snprintf(_network_game_info.map_name, 40, "Loaded scenario");
|
2004-12-13 17:58:53 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2004-08-09 17:04:08 +00:00
|
|
|
} else
|
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case SM_MENU: // Switch to game menu
|
|
|
|
LoadIntroGame();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SM_SAVE: // Save game
|
|
|
|
if (SaveOrLoad(_file_to_saveload.name, SL_SAVE) != SL_OK)
|
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_4007_GAME_SAVE_FAILED, 0, 0);
|
|
|
|
else
|
|
|
|
DeleteWindowById(WC_SAVELOAD, 0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SM_GENRANDLAND:
|
|
|
|
GenerateWorld(2);
|
|
|
|
// XXX: set date
|
|
|
|
_local_player = OWNER_NONE;
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
break;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
|
|
|
if (_switch_mode_errorstr!=INVALID_STRING_ID)
|
2004-09-06 22:46:02 +00:00
|
|
|
ShowErrorMessage(INVALID_STRING_ID,_switch_mode_errorstr,0,0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
_in_state_game_loop = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// State controlling game loop.
|
|
|
|
// The state must not be changed from anywhere
|
|
|
|
// but here.
|
|
|
|
// That check is enforced in DoCommand.
|
2005-01-22 20:23:18 +00:00
|
|
|
void StateGameLoop(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-09-12 15:29:37 +00:00
|
|
|
// dont execute the state loop during pause
|
|
|
|
if (_pause) return;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
_in_state_game_loop = true;
|
2004-12-04 17:54:56 +00:00
|
|
|
// _frame_counter is increased somewhere else when in network-mode
|
|
|
|
// Sidenote: _frame_counter is ONLY used for _savedump in non-MP-games
|
|
|
|
// Should that not be deleted? If so, the next 2 lines can also be deleted
|
|
|
|
if (!_networking)
|
|
|
|
_frame_counter++;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
if (_savedump_path[0] && (uint)_frame_counter >= _savedump_first && (uint)(_frame_counter -_savedump_first) % _savedump_freq == 0 ) {
|
|
|
|
char buf[100];
|
|
|
|
sprintf(buf, "%s%.5d.sav", _savedump_path, _frame_counter);
|
|
|
|
SaveOrLoad(buf, SL_SAVE);
|
2004-08-09 17:04:08 +00:00
|
|
|
if ((uint)_frame_counter >= _savedump_last) exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_game_mode == GM_EDITOR) {
|
|
|
|
RunTileLoop();
|
|
|
|
CallVehicleTicks();
|
|
|
|
CallLandscapeTick();
|
|
|
|
CallWindowTickEvent();
|
|
|
|
NewsLoop();
|
|
|
|
} else {
|
2004-09-11 19:34:11 +00:00
|
|
|
// All these actions has to be done from OWNER_NONE
|
|
|
|
// for multiplayer compatibility
|
|
|
|
uint p = _current_player;
|
|
|
|
_current_player = OWNER_NONE;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
AnimateAnimatedTiles();
|
|
|
|
IncreaseDate();
|
|
|
|
RunTileLoop();
|
|
|
|
CallVehicleTicks();
|
|
|
|
CallLandscapeTick();
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
// To bad the AI does not work in multiplayer, because states are not saved
|
|
|
|
// perfectly
|
|
|
|
if (!disable_computer && !_networking)
|
2004-08-09 17:04:08 +00:00
|
|
|
RunOtherPlayersLoop();
|
|
|
|
|
|
|
|
CallWindowTickEvent();
|
|
|
|
NewsLoop();
|
2004-09-11 19:34:11 +00:00
|
|
|
_current_player = p;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
_in_state_game_loop = false;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void DoAutosave(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
char buf[200];
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-10 14:14:00 +00:00
|
|
|
if (_patches.keep_all_autosave && _local_player != OWNER_SPECTATOR) {
|
2004-08-09 17:04:08 +00:00
|
|
|
Player *p;
|
|
|
|
char *s;
|
|
|
|
sprintf(buf, "%s%s", _path.autosave_dir, PATHSEP);
|
|
|
|
p = DEREF_PLAYER(_local_player);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, p->name_1);
|
|
|
|
SetDParam(1, p->name_2);
|
|
|
|
SetDParam(2, _date);
|
2004-12-22 15:32:50 +00:00
|
|
|
s= (char*)GetString(buf + strlen(_path.autosave_dir) + strlen(PATHSEP), STR_4004);
|
2004-08-09 17:04:08 +00:00
|
|
|
strcpy(s, ".sav");
|
|
|
|
} else {
|
|
|
|
int n = _autosave_ctr;
|
|
|
|
_autosave_ctr = (_autosave_ctr + 1) & 15;
|
|
|
|
sprintf(buf, "%s%sautosave%d.sav", _path.autosave_dir, PATHSEP, n);
|
|
|
|
}
|
|
|
|
|
2004-12-05 20:02:49 +00:00
|
|
|
DEBUG(misc, 2) ("Autosaving to %s", buf);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (SaveOrLoad(buf, SL_SAVE) != SL_OK)
|
|
|
|
ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0);
|
|
|
|
}
|
|
|
|
|
2005-01-28 09:30:19 +00:00
|
|
|
extern void HandleKeyScrolling(void);
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void GameLoop(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int m;
|
|
|
|
|
|
|
|
// autosave game?
|
|
|
|
if (_do_autosave) {
|
|
|
|
_do_autosave = false;
|
|
|
|
DoAutosave();
|
|
|
|
RedrawAutosave();
|
|
|
|
}
|
|
|
|
|
2005-01-28 09:30:19 +00:00
|
|
|
// handle scrolling of the main window
|
|
|
|
if (_dirkeys) HandleKeyScrolling();
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// make a screenshot?
|
|
|
|
if ((m=_make_screenshot) != 0) {
|
|
|
|
_make_screenshot = 0;
|
|
|
|
switch(m) {
|
|
|
|
case 1: // make small screenshot
|
|
|
|
UndrawMouseCursor();
|
|
|
|
ShowScreenshotResult(MakeScreenshot());
|
|
|
|
break;
|
|
|
|
case 2: // make large screenshot
|
2005-01-03 18:59:58 +00:00
|
|
|
ShowScreenshotResult(MakeWorldScreenshot(-(int)MapMaxX() * 32, 0, MapMaxX() * 64, MapSizeY() * 32, 0));
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// switch game mode?
|
|
|
|
if ((m=_switch_mode) != SM_NONE) {
|
|
|
|
_switch_mode = SM_NONE;
|
|
|
|
SwitchMode(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
IncreaseSpriteLRU();
|
|
|
|
InteractiveRandom();
|
|
|
|
|
|
|
|
if (_scroller_click_timeout > 3)
|
|
|
|
_scroller_click_timeout -= 3;
|
|
|
|
else
|
|
|
|
_scroller_click_timeout = 0;
|
|
|
|
|
|
|
|
_caret_timer += 3;
|
|
|
|
_timer_counter+=8;
|
|
|
|
CursorTick();
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
|
|
|
// Check for UDP stuff
|
|
|
|
NetworkUDPGameLoop();
|
|
|
|
|
|
|
|
if (_networking) {
|
|
|
|
// Multiplayer
|
|
|
|
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) {
|
|
|
|
// This means that we want to reconnect to the last host
|
|
|
|
// We do this here, because it means that the network is really closed
|
|
|
|
NetworkClientConnectGame(_network_last_host, _network_last_port);
|
|
|
|
}
|
|
|
|
// 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
|
|
|
|
|
|
|
if (!_pause && _display_opt&DO_FULL_ANIMATION)
|
|
|
|
DoPaletteAnimations();
|
|
|
|
|
2004-08-16 18:46:54 +00:00
|
|
|
if (!_pause || _cheats.build_in_pause.value)
|
2004-08-09 17:04:08 +00:00
|
|
|
MoveAllTextEffects();
|
|
|
|
|
|
|
|
MouseLoop();
|
|
|
|
|
|
|
|
if (_game_mode != GM_MENU)
|
|
|
|
MusicLoop();
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void BeforeSaveGame(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
|
|
|
|
2005-01-11 00:54:06 +00:00
|
|
|
if (w != NULL) {
|
|
|
|
_saved_scrollpos_x = WP(w,vp_d).scrollpos_x;
|
|
|
|
_saved_scrollpos_y = WP(w,vp_d).scrollpos_y;
|
|
|
|
_saved_scrollpos_zoom = w->viewport->zoom;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 22:47:58 +00:00
|
|
|
static void ConvertTownOwner(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
uint tile;
|
|
|
|
|
2005-01-03 18:59:58 +00:00
|
|
|
for (tile = 0; tile != MapSize(); tile++) {
|
2005-01-16 11:24:58 +00:00
|
|
|
if (IsTileType(tile, MP_STREET)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if ((_map5[tile] & 0xF0) == 0x10 && _map3_lo[tile] & 0x80)
|
|
|
|
_map3_lo[tile] = OWNER_TOWN;
|
|
|
|
|
|
|
|
if (_map_owner[tile] & 0x80)
|
|
|
|
_map_owner[tile] = OWNER_TOWN;
|
2005-01-16 11:24:58 +00:00
|
|
|
} else if (IsTileType(tile, MP_TUNNELBRIDGE)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (_map_owner[tile] & 0x80)
|
|
|
|
_map_owner[tile] = OWNER_TOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// before savegame version 4, the name of the company determined if it existed
|
2005-01-22 22:47:58 +00:00
|
|
|
static void CheckIsPlayerActive(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Player *p;
|
|
|
|
FOR_ALL_PLAYERS(p) {
|
|
|
|
if (p->name_1 != 0) {
|
|
|
|
p->is_active = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-23 21:04:39 +00:00
|
|
|
// since savegame version 4.1, exclusive transport rights are stored at towns
|
2005-01-22 22:47:58 +00:00
|
|
|
static void UpdateExclusiveRights(void)
|
2004-08-23 21:04:39 +00:00
|
|
|
{
|
|
|
|
Town *t;
|
|
|
|
FOR_ALL_TOWNS(t) if (t->xy != 0) {
|
|
|
|
t->exclusivity=(byte)-1;
|
|
|
|
}
|
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)
|
2004-08-23 21:04:39 +00:00
|
|
|
could be implemented this way:
|
|
|
|
1.) Go through all stations
|
|
|
|
Build an array town_blocked[ town_id ][ player_id ]
|
|
|
|
that stores if at least one station in that town is blocked for a player
|
|
|
|
2.) Go through that array, if you find a town that is not blocked for
|
|
|
|
one player, but for all others, then give him exclusivity.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2004-12-22 19:48:27 +00:00
|
|
|
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, };
|
|
|
|
|
|
|
|
// since savegame version 4.2 the currencies are arranged differently
|
2005-01-22 22:47:58 +00:00
|
|
|
static void UpdateCurrencies(void)
|
2004-12-22 16:54:55 +00:00
|
|
|
{
|
2004-12-22 19:48:27 +00:00
|
|
|
_opt.currency = convert_currency[_opt.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
|
|
|
|
*/
|
2005-01-22 22:47:58 +00:00
|
|
|
static void UpdateVoidTiles(void)
|
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
|
|
|
|
|
|
|
for (i = 0; i < MapMaxY(); ++i)
|
|
|
|
SetTileType(i * MapSizeX() + MapMaxX(), MP_VOID);
|
|
|
|
for (i = 0; i < MapSizeX(); ++i)
|
|
|
|
SetTileType(MapSizeX() * MapMaxY() + i, MP_VOID);
|
2005-01-07 18:13:56 +00:00
|
|
|
}
|
|
|
|
|
2005-01-25 15:38:36 +00:00
|
|
|
// since savegame version 6.0 each sign has an "owner", signs without owner (from old games are set to 255)
|
|
|
|
static void UpdateSignOwner(void)
|
|
|
|
{
|
|
|
|
SignStruct *ss;
|
|
|
|
FOR_ALL_SIGNS(ss) {
|
|
|
|
ss->owner = OWNER_NONE; // no owner
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-09 08:49:40 +00:00
|
|
|
extern void UpdateOldAircraft( void );
|
|
|
|
extern void UpdateOilRig( void );
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
bool AfterLoadGame(uint version)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
ViewPort *vp;
|
2005-01-12 11:21:28 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// in version 2.1 of the savegame, town owner was unified.
|
|
|
|
if (version <= 0x200) {
|
|
|
|
ConvertTownOwner();
|
|
|
|
}
|
|
|
|
|
2004-08-23 21:04:39 +00:00
|
|
|
// from version 4.1 of the savegame, exclusive rights are stored at towns
|
|
|
|
if (version <= 0x400) {
|
|
|
|
UpdateExclusiveRights();
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-12-22 16:54:55 +00:00
|
|
|
// from version 4.2 of the savegame, currencies are in a different order
|
|
|
|
if (version <= 0x401) {
|
|
|
|
UpdateCurrencies();
|
|
|
|
}
|
|
|
|
|
2005-01-25 15:38:36 +00:00
|
|
|
// from version 6.0 of the savegame, signs have an "owner"
|
|
|
|
if (version <= 0x600) {
|
|
|
|
UpdateSignOwner();
|
|
|
|
}
|
|
|
|
|
2004-12-30 10:29:28 +00:00
|
|
|
/* In old version there seems to be a problem that water is owned by
|
|
|
|
OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current
|
|
|
|
(0x402) version, so I just check when versions are older, and then
|
|
|
|
walk through the whole map.. */
|
|
|
|
if (version <= 0x402) {
|
|
|
|
TileIndex tile = TILE_XY(0,0);
|
|
|
|
uint w = MapSizeX();
|
|
|
|
uint h = MapSizeY();
|
|
|
|
|
|
|
|
BEGIN_TILE_LOOP(tile_cur, w, h, tile)
|
2005-01-16 11:24:58 +00:00
|
|
|
if (IsTileType(tile_cur, MP_WATER) && _map_owner[tile_cur] >= MAX_PLAYERS)
|
2004-12-30 10:29:28 +00:00
|
|
|
_map_owner[tile_cur] = OWNER_WATER;
|
|
|
|
END_TILE_LOOP(tile_cur, w, h, tile)
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// convert road side to my format.
|
|
|
|
if (_opt.road_side) _opt.road_side = 1;
|
|
|
|
|
|
|
|
// Load the sprites
|
|
|
|
GfxLoadSprites();
|
|
|
|
|
|
|
|
// Update current year
|
|
|
|
SetDate(_date);
|
|
|
|
|
|
|
|
// reinit the landscape variables (landscape might have changed)
|
|
|
|
InitializeLandscapeVariables(true);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// Update all vehicles
|
|
|
|
AfterLoadVehicles();
|
|
|
|
// in version 2.2 of the savegame, we have new airports
|
|
|
|
if (version <= 0x201) {
|
|
|
|
UpdateOldAircraft();
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateAllStationVirtCoord();
|
|
|
|
|
|
|
|
// Setup town coords
|
|
|
|
AfterLoadTown();
|
|
|
|
UpdateAllSignVirtCoords();
|
|
|
|
|
|
|
|
// make sure there is a town in the game
|
|
|
|
if (_game_mode == GM_NORMAL && !ClosestTownFromTile(0, (uint)-1))
|
|
|
|
{
|
|
|
|
_error_message = STR_NO_TOWN_IN_SCENARIO;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize windows
|
|
|
|
InitWindowSystem();
|
|
|
|
SetupColorsAndInitialWindow();
|
|
|
|
|
|
|
|
w = FindWindowById(WC_MAIN_WINDOW, 0);
|
|
|
|
|
|
|
|
WP(w,vp_d).scrollpos_x = _saved_scrollpos_x;
|
|
|
|
WP(w,vp_d).scrollpos_y = _saved_scrollpos_y;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
vp = w->viewport;
|
|
|
|
vp->zoom = _saved_scrollpos_zoom;
|
|
|
|
vp->virtual_width = vp->width << vp->zoom;
|
|
|
|
vp->virtual_height = vp->height << vp->zoom;
|
|
|
|
|
|
|
|
|
|
|
|
// in version 4.0 of the savegame, is_active was introduced to determine
|
|
|
|
// if a player does exist, rather then checking name_1
|
|
|
|
if (version <= 0x400) {
|
|
|
|
CheckIsPlayerActive();
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-07 18:13:56 +00:00
|
|
|
// the void tiles on the southern border used to belong to a wrong class.
|
|
|
|
if (version <= 0x402)
|
|
|
|
UpdateVoidTiles();
|
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
// If Load Scenario / New (Scenario) Game is used,
|
2004-08-25 10:17:39 +00:00
|
|
|
// a player does not exist yet. So create one here.
|
2004-12-04 17:54:56 +00:00
|
|
|
// 1 exeption: network-games. Those can have 0 players
|
|
|
|
// But this exeption is not true for network_servers!
|
|
|
|
if (!_players[0].is_active && (!_networking || (_networking && _network_server)))
|
2004-08-25 10:17:39 +00:00
|
|
|
DoStartupNewPlayer(false);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-09-03 19:59:05 +00:00
|
|
|
DoZoomInOutWindow(ZOOM_NONE, w); // update button status
|
2004-08-09 17:04:08 +00:00
|
|
|
MarkWholeScreenDirty();
|
|
|
|
|
2005-01-09 08:49:40 +00:00
|
|
|
//In 5.1, Oilrigs have been moved (again)
|
|
|
|
if (version <= 0x500) {
|
|
|
|
UpdateOilRig();
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugProc(int i)
|
|
|
|
{
|
|
|
|
switch(i) {
|
|
|
|
case 0:
|
|
|
|
*(byte*)0 = 0;
|
|
|
|
break;
|
|
|
|
case 1:
|
2004-12-23 21:58:01 +00:00
|
|
|
/* Server can not cheat in advertise mode either! */
|
2004-12-24 00:13:32 +00:00
|
|
|
#ifdef ENABLE_NETWORK
|
2004-12-23 21:58:01 +00:00
|
|
|
if (!_networking || !_network_server || !_network_advertise)
|
2004-12-24 00:13:32 +00:00
|
|
|
#endif /* ENABLE_NETWORK */
|
2004-12-23 21:58:01 +00:00
|
|
|
DoCommandP(0, -10000000, 0, NULL, CMD_MONEY_CHEAT);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
UpdateAllStationVirtCoord();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|