author | miham |
Wed, 17 Aug 2005 12:30:07 +0000 | |
changeset 2349 | df02d0ffb588 |
parent 2340 | 0a9f3eeccb96 |
child 2360 | 09e42e4ee139 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
0 | 3 |
#include "stdafx.h" |
1317
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
1314
diff
changeset
|
4 |
#include "string.h" |
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
497
diff
changeset
|
5 |
#include "table/strings.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1296
diff
changeset
|
6 |
#include "debug.h" |
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
7 |
#include "driver.h" |
2162
c1ded3bd3d0c
(svn r2672) Move saving/loading related declarations to saveload.h
tron
parents:
2147
diff
changeset
|
8 |
#include "saveload.h" |
1309
dab90d4cbf2d
(svn r1813) Declare functions implemented in strings.c in their own shiny new header (though i think some of these function don't belong into strings.c)
tron
parents:
1301
diff
changeset
|
9 |
#include "strings.h" |
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
659
diff
changeset
|
10 |
#include "map.h" |
1209
a1ac96655b79
(svn r1713) Split off several functions which query/set information about a single tile from map.h and put them into a seperate file tile.h
tron
parents:
1199
diff
changeset
|
11 |
#include "tile.h" |
0 | 12 |
|
13 |
#define VARDEF |
|
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1885
diff
changeset
|
14 |
#include "openttd.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2162
diff
changeset
|
15 |
#include "functions.h" |
1496
3d0b86f5dcb8
(svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents:
1482
diff
changeset
|
16 |
#include "mixer.h" |
1349
07514c2cc6d1
(svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents:
1329
diff
changeset
|
17 |
#include "spritecache.h" |
0 | 18 |
#include "gfx.h" |
2340
0a9f3eeccb96
(svn r2866) Move all functions and tables which aren't directly involved in managing the sprite heap to a new file gfxinit.c.
tron
parents:
2322
diff
changeset
|
19 |
#include "gfxinit.h" |
0 | 20 |
#include "gui.h" |
21 |
#include "station.h" |
|
22 |
#include "vehicle.h" |
|
23 |
#include "viewport.h" |
|
24 |
#include "window.h" |
|
25 |
#include "player.h" |
|
26 |
#include "command.h" |
|
27 |
#include "town.h" |
|
28 |
#include "industry.h" |
|
29 |
#include "news.h" |
|
30 |
#include "engine.h" |
|
31 |
#include "sound.h" |
|
32 |
#include "economy.h" |
|
33 |
#include "fileio.h" |
|
34 |
#include "hal.h" |
|
35 |
#include "airport.h" |
|
126 | 36 |
#include "console.h" |
430 | 37 |
#include "screenshot.h" |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
38 |
#include "network.h" |
988
2482369a61ff
(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
983
diff
changeset
|
39 |
#include "signs.h" |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1310
diff
changeset
|
40 |
#include "depot.h" |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1501
diff
changeset
|
41 |
#include "waypoint.h" |
0 | 42 |
|
43 |
#include <stdarg.h> |
|
44 |
||
2033
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
45 |
#ifdef GPMI |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
46 |
#include <gpmi.h> |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
47 |
#include <gpmi/packages/paths.h> |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
48 |
#endif /* GPMI */ |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
49 |
|
2051 | 50 |
void GenerateWorld(int mode, uint size_x, uint size_y); |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
51 |
void CallLandscapeTick(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
52 |
void IncreaseDate(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
53 |
void RunOtherPlayersLoop(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
54 |
void DoPaletteAnimations(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
55 |
void MusicLoop(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
56 |
void ResetMusic(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
57 |
void InitializeStations(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
58 |
void DeleteAllPlayerStations(void); |
0 | 59 |
|
60 |
extern void SetDifficultyLevel(int mode, GameOptions *gm_opt); |
|
61 |
extern void DoStartupNewPlayer(bool is_ai); |
|
62 |
extern void ShowOSErrorBox(const char *buf); |
|
63 |
||
64 |
bool LoadSavegame(const char *filename); |
|
65 |
||
66 |
bool _dbg_screen_rect; |
|
67 |
||
1436 | 68 |
/* TODO: usrerror() for errors which are not of an internal nature but |
69 |
* caused by the user, i.e. missing files or fatal configuration errors. |
|
70 |
* Post-0.4.0 since Celestar doesn't want this in SVN before. --pasky */ |
|
71 |
||
0 | 72 |
void CDECL error(const char *s, ...) { |
73 |
va_list va; |
|
74 |
char buf[512]; |
|
75 |
va_start(va, s); |
|
76 |
vsprintf(buf, s, va); |
|
77 |
va_end(va); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
78 |
|
0 | 79 |
ShowOSErrorBox(buf); |
80 |
if (_video_driver) |
|
81 |
_video_driver->stop(); |
|
82 |
||
83 |
assert(0); |
|
84 |
exit(1); |
|
85 |
} |
|
86 |
||
87 |
void CDECL ShowInfoF(const char *str, ...) |
|
88 |
{ |
|
89 |
va_list va; |
|
90 |
char buf[1024]; |
|
91 |
va_start(va, str); |
|
92 |
vsprintf(buf, str, va); |
|
93 |
va_end(va); |
|
94 |
ShowInfo(buf); |
|
95 |
} |
|
96 |
||
97 |
||
1310
85cde2193afc
(svn r1814) Let ReadFileToMem() return void* (instead of byte*) because we don't know what the caller wants to do with the data
tron
parents:
1309
diff
changeset
|
98 |
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize) |
0 | 99 |
{ |
100 |
FILE *in; |
|
1105 | 101 |
byte *mem; |
0 | 102 |
size_t len; |
103 |
||
104 |
in = fopen(filename, "rb"); |
|
105 |
if (in == NULL) |
|
106 |
return NULL; |
|
107 |
||
108 |
fseek(in, 0, SEEK_END); |
|
109 |
len = ftell(in); |
|
110 |
fseek(in, 0, SEEK_SET); |
|
1105 | 111 |
if (len > maxsize || (mem = malloc(len + 1)) == NULL) { |
0 | 112 |
fclose(in); |
113 |
return NULL; |
|
114 |
} |
|
1105 | 115 |
mem[len] = 0; |
0 | 116 |
if (fread(mem, len, 1, in) != 1) { |
117 |
fclose(in); |
|
118 |
free(mem); |
|
119 |
return NULL; |
|
120 |
} |
|
121 |
fclose(in); |
|
122 |
||
123 |
*lenp = len; |
|
124 |
return mem; |
|
125 |
} |
|
126 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
127 |
static void showhelp(void) |
0 | 128 |
{ |
129 |
char buf[4096], *p; |
|
130 |
||
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
131 |
p = strecpy(buf, |
0 | 132 |
"Command line options:\n" |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
133 |
" -v drv = Set video driver (see below)\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
134 |
" -s drv = Set sound driver (see below)\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
135 |
" -m drv = Set music driver (see below)\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
136 |
" -r res = Set resolution (for instance 800x600)\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
137 |
" -h = Display this help text\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
138 |
" -t date = Set starting date\n" |
1440
2eb4dd1e0465
(svn r1944) Make --help output for -d at least somewhat useful.
pasky
parents:
1436
diff
changeset
|
139 |
" -d [[fac=]lvl[,...]]= Debug mode\n" |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
140 |
" -l lng = Select Language\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
141 |
" -e = Start Editor\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
142 |
" -g [savegame] = Start new/save game immediately\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
143 |
" -G seed = Set random seed\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
144 |
" -n [ip#player:port] = Start networkgame\n" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
145 |
" -D = Start dedicated server\n" |
770
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
768
diff
changeset
|
146 |
#if !defined(__MORPHOS__) && !defined(__AMIGA__) |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
147 |
" -f = Fork into the background (dedicated only)\n" |
770
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
768
diff
changeset
|
148 |
#endif |
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
561
diff
changeset
|
149 |
" -i = Force to use the DOS palette (use this if you see a lot of pink)\n" |
1482
46a8146adecf
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1478
diff
changeset
|
150 |
" -p #player = Player as #player (deprecated) (network only)\n" |
46a8146adecf
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1478
diff
changeset
|
151 |
" -c config_file = Use 'config_file' instead of 'openttd.cfg'\n", |
1317
f382f1b439c7
(svn r1821) Move generic string handling functions to string.[ch] and introduce stre{cpy,cat}, see string.h for their semantics
tron
parents:
1314
diff
changeset
|
152 |
lastof(buf) |
0 | 153 |
); |
154 |
||
2171
008122046f7f
(svn r2685) -Codechange: Split the music/sound/video drivers into separate files and move them into subfolders.
tron
parents:
2163
diff
changeset
|
155 |
GetDriverList(p); |
0 | 156 |
|
157 |
ShowInfo(buf); |
|
158 |
} |
|
159 |
||
160 |
||
161 |
typedef struct { |
|
162 |
char *opt; |
|
163 |
int numleft; |
|
164 |
char **argv; |
|
165 |
const char *options; |
|
166 |
char *cont; |
|
167 |
} MyGetOptData; |
|
168 |
||
169 |
static void MyGetOptInit(MyGetOptData *md, int argc, char **argv, const char *options) |
|
170 |
{ |
|
171 |
md->cont = NULL; |
|
172 |
md->numleft = argc; |
|
173 |
md->argv = argv; |
|
174 |
md->options = options; |
|
175 |
} |
|
176 |
||
177 |
static int MyGetOpt(MyGetOptData *md) |
|
178 |
{ |
|
179 |
char *s,*r,*t; |
|
180 |
||
181 |
if ((s=md->cont) != NULL) |
|
182 |
goto md_continue_here; |
|
183 |
||
184 |
while(true) { |
|
185 |
if (--md->numleft < 0) |
|
186 |
return -1; |
|
187 |
||
188 |
s = *md->argv++; |
|
189 |
if (*s == '-') { |
|
190 |
md_continue_here:; |
|
191 |
s++; |
|
192 |
if (*s != 0) { |
|
193 |
// Found argument, try to locate it in options. |
|
194 |
if (*s == ':' || (r = strchr(md->options, *s)) == NULL) { |
|
195 |
// ERROR! |
|
196 |
return -2; |
|
197 |
} |
|
198 |
if (r[1] == ':') { |
|
199 |
// Item wants an argument. Check if the argument follows, or if it comes as a separate arg. |
|
200 |
if (!*(t = s + 1)) { |
|
201 |
// It comes as a separate arg. Check if out of args? |
|
202 |
if (--md->numleft < 0 || *(t = *md->argv) == '-') { |
|
203 |
// Check if item is optional? |
|
204 |
if (r[2] != ':') |
|
205 |
return -2; |
|
206 |
md->numleft++; |
|
207 |
t = NULL; |
|
208 |
} else { |
|
209 |
md->argv++; |
|
210 |
} |
|
211 |
} |
|
212 |
md->opt = t; |
|
213 |
md->cont = NULL; |
|
214 |
return *s; |
|
215 |
} |
|
216 |
md->opt = NULL; |
|
217 |
md->cont = s; |
|
218 |
return *s; |
|
219 |
} |
|
220 |
} else { |
|
221 |
// This is currently not supported. |
|
222 |
return -2; |
|
223 |
} |
|
224 |
} |
|
225 |
} |
|
226 |
||
227 |
||
1095 | 228 |
static void ParseResolution(int res[2], char *s) |
0 | 229 |
{ |
230 |
char *t = strchr(s, 'x'); |
|
231 |
if (t == NULL) { |
|
232 |
ShowInfoF("Invalid resolution '%s'", s); |
|
233 |
return; |
|
234 |
} |
|
235 |
||
1764
a976570cdbd9
(svn r2268) - Fix [ 1195595 ] high resolutions don't work. Clamp all possible inputs of resolutions to the maximum availble
Darkvater
parents:
1688
diff
changeset
|
236 |
res[0] = clamp(strtoul(s, NULL, 0), 64, MAX_SCREEN_WIDTH); |
a976570cdbd9
(svn r2268) - Fix [ 1195595 ] high resolutions don't work. Clamp all possible inputs of resolutions to the maximum availble
Darkvater
parents:
1688
diff
changeset
|
237 |
res[1] = clamp(strtoul(t + 1, NULL, 0), 64, MAX_SCREEN_HEIGHT); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
238 |
} |
0 | 239 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
240 |
static void InitializeDynamicVariables(void) |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
241 |
{ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
242 |
/* Dynamic stuff needs to be initialized somewhere... */ |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1264
diff
changeset
|
243 |
_station_sort = NULL; |
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1264
diff
changeset
|
244 |
_vehicle_sort = NULL; |
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1264
diff
changeset
|
245 |
_town_sort = NULL; |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
246 |
_industry_sort = NULL; |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
247 |
} |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
248 |
|
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
249 |
static void UnInitializeDynamicVariables(void) |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
250 |
{ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
251 |
/* Dynamic stuff needs to be free'd somewhere... */ |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1246
diff
changeset
|
252 |
CleanPool(&_town_pool); |
1267
cbd68e5e31ac
(svn r1771) -Add: Industries are now dynamic (up to 64k industries). Generating
truelight
parents:
1264
diff
changeset
|
253 |
CleanPool(&_industry_pool); |
1272
d3e09adb7736
(svn r1776) -Add: Dynamic stations. You can now have up to 64k of stations
truelight
parents:
1268
diff
changeset
|
254 |
CleanPool(&_station_pool); |
1279
4f83fbde72de
(svn r1783) -Add: Dynamic vehicles (now up to 64k of vehicles)
truelight
parents:
1272
diff
changeset
|
255 |
CleanPool(&_vehicle_pool); |
1283
b9569cc0644f
(svn r1787) -Add: Dynamic signs (euh.. yeah, this means you can built 64k signs)
truelight
parents:
1279
diff
changeset
|
256 |
CleanPool(&_sign_pool); |
1314
d6a253cf92c3
(svn r1818) -Add: Dynamic orders (up to 64k orders)
truelight
parents:
1313
diff
changeset
|
257 |
CleanPool(&_order_pool); |
1260
c60e76928e5c
(svn r1764) -Add: dynamic towns, you can now have up to 64k towns (let me know when
truelight
parents:
1246
diff
changeset
|
258 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
259 |
free(_station_sort); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
260 |
free(_vehicle_sort); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
261 |
free(_town_sort); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
262 |
free(_industry_sort); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
263 |
} |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
264 |
|
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1440
diff
changeset
|
265 |
static void UnInitializeGame(void) |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1440
diff
changeset
|
266 |
{ |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1440
diff
changeset
|
267 |
UnInitWindowSystem(); |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1440
diff
changeset
|
268 |
UnInitNewgrEngines(); |
1482
46a8146adecf
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1478
diff
changeset
|
269 |
|
46a8146adecf
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1478
diff
changeset
|
270 |
free(_config_file); |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1440
diff
changeset
|
271 |
} |
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
272 |
|
1095 | 273 |
static void LoadIntroGame(void) |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
274 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
275 |
char filename[256]; |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
276 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
277 |
_game_mode = GM_MENU; |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
278 |
CLRBITS(_display_opt, DO_TRANS_BUILDINGS); // don't make buildings transparent in intro |
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
279 |
_opt_ptr = &_opt_newgame; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
280 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
281 |
GfxLoadSprites(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
282 |
LoadStringWidthTable(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
283 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
284 |
// Setup main window |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1440
diff
changeset
|
285 |
ResetWindowSystem(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
286 |
SetupColorsAndInitialWindow(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
287 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
288 |
// Generate a world. |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
289 |
sprintf(filename, "%sopntitle.dat", _path.data_dir); |
921 | 290 |
if (SaveOrLoad(filename, SL_LOAD) != SL_OK) { |
561
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
557
diff
changeset
|
291 |
#if defined SECOND_DATA_DIR |
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
557
diff
changeset
|
292 |
sprintf(filename, "%sopntitle.dat", _path.second_data_dir); |
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
557
diff
changeset
|
293 |
if (SaveOrLoad(filename, SL_LOAD) != SL_OK) |
e3b9689745ab
(svn r970) Added 2nd data path for all non-windows OSes
bjarni
parents:
557
diff
changeset
|
294 |
#endif |
2051 | 295 |
GenerateWorld(1, 64, 64); // if failed loading, make empty world. |
921 | 296 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
297 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
298 |
_pause = 0; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
299 |
_local_player = 0; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
300 |
MarkWholeScreenDirty(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
301 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
302 |
// Play main theme |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
303 |
if (_music_driver->is_song_playing()) ResetMusic(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
304 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
305 |
|
2290 | 306 |
#if defined(UNIX) && !defined(__MORPHOS__) |
774
258c11431acb
(svn r1240) -Fix: OpenTTD once again compiles if ENABLE_NETWORK is disabled.
darkvater
parents:
770
diff
changeset
|
307 |
extern void DedicatedFork(void); |
2290 | 308 |
#endif |
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
309 |
extern void CheckExternalFiles(void); |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
310 |
|
0 | 311 |
int ttd_main(int argc, char* argv[]) |
312 |
{ |
|
313 |
MyGetOptData mgo; |
|
314 |
int i; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
315 |
bool network = false; |
0 | 316 |
char *network_conn = NULL; |
317 |
char *language = NULL; |
|
1010
17470a8e5eb7
(svn r1509) Const correctness and add static where appropriate while touching the lines anyway
tron
parents:
1009
diff
changeset
|
318 |
const char *optformat; |
469
d26f0e5705dc
(svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents:
430
diff
changeset
|
319 |
char musicdriver[16], sounddriver[16], videodriver[16]; |
0 | 320 |
int resolution[2] = {0,0}; |
321 |
uint startdate = -1; |
|
1406
2d5baabe4046
(svn r1910) Move two variables out of variables.h which are only used locally
tron
parents:
1397
diff
changeset
|
322 |
bool dedicated; |
2d5baabe4046
(svn r1910) Move two variables out of variables.h which are only used locally
tron
parents:
1397
diff
changeset
|
323 |
|
0 | 324 |
musicdriver[0] = sounddriver[0] = videodriver[0] = 0; |
325 |
||
326 |
_game_mode = GM_MENU; |
|
327 |
_switch_mode = SM_MENU; |
|
172
8d8b3383470d
(svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater
parents:
168
diff
changeset
|
328 |
_switch_mode_errorstr = INVALID_STRING_ID; |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
329 |
_dedicated_forks = false; |
1406
2d5baabe4046
(svn r1910) Move two variables out of variables.h which are only used locally
tron
parents:
1397
diff
changeset
|
330 |
dedicated = false; |
1482
46a8146adecf
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1478
diff
changeset
|
331 |
_config_file = NULL; |
0 | 332 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
333 |
// The last param of the following function means this: |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
334 |
// a letter means: it accepts that param (e.g.: -h) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
335 |
// a ':' behind it means: it need a param (e.g.: -m<driver>) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
336 |
// a '::' behind it means: it can optional have a param (e.g.: -d<debug>) |
1478
00b0798b34d5
(svn r1982) -Fix: also windows has no 'fork' option
truelight
parents:
1474
diff
changeset
|
337 |
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32) |
1482
46a8146adecf
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1478
diff
changeset
|
338 |
optformat = "m:s:v:hDfn::l:eit:d::r:g::G:p:c:"; |
770
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
768
diff
changeset
|
339 |
#else |
1482
46a8146adecf
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1478
diff
changeset
|
340 |
optformat = "m:s:v:hDn::l:eit:d::r:g::G:p:c:"; // no fork option |
770
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
768
diff
changeset
|
341 |
#endif |
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
768
diff
changeset
|
342 |
|
89dab23f04ca
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
768
diff
changeset
|
343 |
MyGetOptInit(&mgo, argc-1, argv+1, optformat); |
0 | 344 |
while ((i = MyGetOpt(&mgo)) != -1) { |
345 |
switch(i) { |
|
346 |
case 'm': ttd_strlcpy(musicdriver, mgo.opt, sizeof(musicdriver)); break; |
|
347 |
case 's': ttd_strlcpy(sounddriver, mgo.opt, sizeof(sounddriver)); break; |
|
348 |
case 'v': ttd_strlcpy(videodriver, mgo.opt, sizeof(videodriver)); break; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
349 |
case 'D': { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
350 |
sprintf(musicdriver,"null"); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
351 |
sprintf(sounddriver,"null"); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
352 |
sprintf(videodriver,"dedicated"); |
1406
2d5baabe4046
(svn r1910) Move two variables out of variables.h which are only used locally
tron
parents:
1397
diff
changeset
|
353 |
dedicated = true; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
354 |
} break; |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
355 |
case 'f': { |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
356 |
_dedicated_forks = true; |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
357 |
}; break; |
1 | 358 |
case 'n': { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
359 |
network = true; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
360 |
if (mgo.opt) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
361 |
// Optional, you can give an IP |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
362 |
network_conn = mgo.opt; |
1 | 363 |
else |
364 |
network_conn = NULL; |
|
365 |
} break; |
|
0 | 366 |
case 'r': ParseResolution(resolution, mgo.opt); break; |
367 |
case 'l': { |
|
368 |
language = mgo.opt; |
|
369 |
} break; |
|
370 |
case 't': { |
|
371 |
startdate = atoi(mgo.opt); |
|
372 |
} break; |
|
373 |
case 'd': { |
|
374 |
#if defined(WIN32) |
|
375 |
CreateConsole(); |
|
376 |
#endif |
|
377 |
if (mgo.opt) |
|
378 |
SetDebugString(mgo.opt); |
|
379 |
} break; |
|
380 |
case 'e': _switch_mode = SM_EDITOR; break; |
|
614
e016770cb781
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
561
diff
changeset
|
381 |
case 'i': _use_dos_palette = true; break; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
382 |
case 'g': |
0 | 383 |
if (mgo.opt) { |
384 |
strcpy(_file_to_saveload.name, mgo.opt); |
|
385 |
_switch_mode = SM_LOAD; |
|
386 |
} else |
|
387 |
_switch_mode = SM_NEWGAME; |
|
388 |
break; |
|
389 |
case 'G': |
|
206 | 390 |
_random_seeds[0][0] = atoi(mgo.opt); |
0 | 391 |
break; |
392 |
case 'p': { |
|
393 |
int i = atoi(mgo.opt); |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
394 |
// Play as an other player in network games |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
395 |
if (IS_INT_INSIDE(i, 1, MAX_PLAYERS)) _network_playas = i; |
0 | 396 |
break; |
397 |
} |
|
1482
46a8146adecf
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1478
diff
changeset
|
398 |
case 'c': |
46a8146adecf
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1478
diff
changeset
|
399 |
_config_file = strdup(mgo.opt); |
46a8146adecf
(svn r1986) - Fix: free _config_file when shutting down openttd. Strange that Valgrind didn't catch this, kudos to TrueLight
Darkvater
parents:
1478
diff
changeset
|
400 |
break; |
0 | 401 |
case -2: |
2026 | 402 |
case 'h': |
0 | 403 |
showhelp(); |
404 |
return 0; |
|
405 |
} |
|
406 |
} |
|
407 |
||
408 |
DeterminePaths(); |
|
961 | 409 |
CheckExternalFiles(); |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
410 |
|
2033
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
411 |
#ifdef GPMI |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
412 |
/* Set the debug proc */ |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
413 |
gpmi_debug_proc = &gpmi_debug_openttd; |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
414 |
|
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
415 |
/* Initialize GPMI */ |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
416 |
gpmi_init(); |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
417 |
|
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
418 |
/* Add our paths so we can find our own packages */ |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
419 |
gpmi_path_append(&gpmi_path_modules, "gpmi/modules"); |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
420 |
gpmi_path_append(&gpmi_path_packages, "gpmi/packages"); |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
421 |
#endif /* GPMI */ |
1eb15b79b6f3
(svn r2542) -Add: [GPMI] Added GPMI (http://sourceforge.net/projects/libgpmi/)
truelight
parents:
2026
diff
changeset
|
422 |
|
2290 | 423 |
#if defined(UNIX) && !defined(__MORPHOS__) |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
424 |
// We must fork here, or we'll end up without some resources we need (like sockets) |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
425 |
if (_dedicated_forks) |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
426 |
DedicatedFork(); |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
427 |
#endif |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
428 |
|
0 | 429 |
LoadFromConfig(); |
1688
787400219027
(svn r2192) - Add greater control to the 'message options' window. Now you can turn off the telegraphc ticker sound for summarized messages, or turn off news-messages altogether (you get a red blot to notify you though). The [<][>] set the settings in one way, while clicking on the option itself, cycles it. This commit also 'fixes' bugs [1166973], [1121484] and patch [1169930].
Darkvater
parents:
1608
diff
changeset
|
430 |
CheckConfig(); |
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
961
diff
changeset
|
431 |
LoadFromHighScore(); |
0 | 432 |
|
433 |
// override config? |
|
469
d26f0e5705dc
(svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents:
430
diff
changeset
|
434 |
if (musicdriver[0]) ttd_strlcpy(_ini_musicdriver, musicdriver, sizeof(_ini_musicdriver)); |
d26f0e5705dc
(svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents:
430
diff
changeset
|
435 |
if (sounddriver[0]) ttd_strlcpy(_ini_sounddriver, sounddriver, sizeof(_ini_sounddriver)); |
d26f0e5705dc
(svn r702) -Fix: Buffer overflow in music/sound/video-driver-parameter (Oskar_)
truelight
parents:
430
diff
changeset
|
436 |
if (videodriver[0]) ttd_strlcpy(_ini_videodriver, videodriver, sizeof(_ini_videodriver)); |
0 | 437 |
if (resolution[0]) { _cur_resolution[0] = resolution[0]; _cur_resolution[1] = resolution[1]; } |
990
5cbf62b64f36
(svn r1488) -Fix: fixed some spelling mistakes (tnx to Tron)
truelight
parents:
988
diff
changeset
|
438 |
if (startdate != (uint)-1) _patches.starting_date = startdate; |
0 | 439 |
|
1406
2d5baabe4046
(svn r1910) Move two variables out of variables.h which are only used locally
tron
parents:
1397
diff
changeset
|
440 |
if (_dedicated_forks && !dedicated) |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
441 |
_dedicated_forks = false; |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
679
diff
changeset
|
442 |
|
0 | 443 |
// enumerate language files |
444 |
InitializeLanguagePacks(); |
|
445 |
||
446 |
// initialize screenshot formats |
|
447 |
InitializeScreenshotFormats(); |
|
448 |
||
105 | 449 |
// initialize airport state machines |
450 |
InitializeAirports(); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
451 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
452 |
/* initialize all variables that are allocated dynamically */ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
453 |
InitializeDynamicVariables(); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
454 |
|
0 | 455 |
// Sample catalogue |
456 |
DEBUG(misc, 1) ("Loading sound effects..."); |
|
1496
3d0b86f5dcb8
(svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents:
1482
diff
changeset
|
457 |
MxInitialize(11025); |
3d0b86f5dcb8
(svn r2000) Split the sound system into backend (mixer.[ch]) and frontend (sound.[ch])
tron
parents:
1482
diff
changeset
|
458 |
SoundInitialize("sample.cat"); |
0 | 459 |
|
460 |
// This must be done early, since functions use the InvalidateWindow* calls |
|
139 | 461 |
InitWindowSystem(); |
0 | 462 |
|
463 |
GfxLoadSprites(); |
|
464 |
LoadStringWidthTable(); |
|
465 |
||
466 |
DEBUG(misc, 1) ("Loading drivers..."); |
|
467 |
LoadDriver(SOUND_DRIVER, _ini_sounddriver); |
|
468 |
LoadDriver(MUSIC_DRIVER, _ini_musicdriver); |
|
469 |
LoadDriver(VIDEO_DRIVER, _ini_videodriver); // load video last, to prevent an empty window while sound and music loads |
|
168
79f9ed5b23e6
(svn r169) -Fix: move around sort-widgets a bit so it looks more natural
darkvater
parents:
152
diff
changeset
|
470 |
_savegame_sort_order = 1; // default sorting of savegames is by date, newest first |
0 | 471 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
472 |
#ifdef ENABLE_NETWORK |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
473 |
// initialize network-core |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
474 |
NetworkStartUp(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
475 |
#endif /* ENABLE_NETWORK */ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
476 |
|
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
477 |
_opt_ptr = &_opt_newgame; |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
478 |
|
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
479 |
/* XXX - ugly hack, if diff_level is 9, it means we got no setting from the config file */ |
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
480 |
if (_opt_newgame.diff_level == 9) |
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
481 |
SetDifficultyLevel(0, &_opt_newgame); |
0 | 482 |
|
139 | 483 |
// initialize the ingame console |
484 |
IConsoleInit(); |
|
1246
45f15251412b
(svn r1750) - Feature: [ 1093261 ] Saving vehicle sorting criteria for each vehicle type (bociusz)
darkvater
parents:
1243
diff
changeset
|
485 |
InitializeGUI(); |
644
e833509107ad
(svn r1077) Implements scripts/autoexec.scr to get executed on game starting (sign_de)
dominik
parents:
630
diff
changeset
|
486 |
IConsoleCmdExec("exec scripts/autoexec.scr 0"); |
656
01540e6c0fed
(svn r1090) -Fix: Made the _openttd_revision variable global, and with that
truelight
parents:
644
diff
changeset
|
487 |
|
2051 | 488 |
GenerateWorld(1, 64, 64); // Make the viewport initialization happy |
1268
306ebfea663a
(svn r1772) -Fix: [ 1114100 ] Dedicated server boots again
truelight
parents:
1267
diff
changeset
|
489 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
490 |
#ifdef ENABLE_NETWORK |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
491 |
if ((network) && (_network_available)) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
492 |
if (network_conn != NULL) { |
1329 | 493 |
const char *port = NULL; |
494 |
const char *player = NULL; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
495 |
uint16 rport; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
496 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
497 |
rport = NETWORK_DEFAULT_PORT; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
498 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
499 |
ParseConnectionString(&player, &port, network_conn); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
500 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
501 |
if (player != NULL) _network_playas = atoi(player); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
502 |
if (port != NULL) rport = atoi(port); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
503 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
504 |
LoadIntroGame(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
505 |
_switch_mode = SM_NONE; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
506 |
NetworkClientConnectGame(network_conn, rport); |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1105
diff
changeset
|
507 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
508 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
509 |
#endif /* ENABLE_NETWORK */ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
510 |
|
2228 | 511 |
_video_driver->main_loop(); |
139 | 512 |
|
2285
3193cbd1ba88
(svn r2809) Implement more generic threading functions, which allow more than one thread
tron
parents:
2234
diff
changeset
|
513 |
WaitTillSaved(); |
139 | 514 |
IConsoleFree(); |
0 | 515 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
516 |
#ifdef ENABLE_NETWORK |
105 | 517 |
if (_network_available) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
518 |
// Shut down the network and close any open connections |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
519 |
NetworkDisconnect(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
520 |
NetworkUDPClose(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
521 |
NetworkShutDown(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
522 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
523 |
#endif /* ENABLE_NETWORK */ |
0 | 524 |
|
525 |
_video_driver->stop(); |
|
526 |
_music_driver->stop(); |
|
527 |
_sound_driver->stop(); |
|
528 |
||
529 |
SaveToConfig(); |
|
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
961
diff
changeset
|
530 |
SaveToHighScore(); |
0 | 531 |
|
105 | 532 |
// uninitialize airport state machines |
533 |
UnInitializeAirports(); |
|
0 | 534 |
|
919
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
535 |
/* uninitialize variables that are allocated dynamic */ |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
536 |
UnInitializeDynamicVariables(); |
b0d6c7642f99
(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries
truelight
parents:
865
diff
changeset
|
537 |
|
1036
5f0c307fbadd
(svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents:
1035
diff
changeset
|
538 |
/* Close all and any open filehandles */ |
5f0c307fbadd
(svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents:
1035
diff
changeset
|
539 |
FioCloseAll(); |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1440
diff
changeset
|
540 |
UnInitializeGame(); |
1036
5f0c307fbadd
(svn r1537) -Fix: Close all and any open filehandles open at shutdown (tamlin)
darkvater
parents:
1035
diff
changeset
|
541 |
|
0 | 542 |
return 0; |
543 |
} |
|
544 |
||
545 |
static void ShowScreenshotResult(bool b) |
|
546 |
{ |
|
547 |
if (b) { |
|
2055
9361b56db8ba
(svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents:
2051
diff
changeset
|
548 |
SetDParamStr(0, _screenshot_name); |
0 | 549 |
ShowErrorMessage(INVALID_STRING_ID, STR_031B_SCREENSHOT_SUCCESSFULLY, 0, 0); |
550 |
} else { |
|
551 |
ShowErrorMessage(INVALID_STRING_ID, STR_031C_SCREENSHOT_FAILED, 0, 0); |
|
552 |
} |
|
553 |
||
554 |
} |
|
555 |
||
1095 | 556 |
static void MakeNewGame(void) |
0 | 557 |
{ |
558 |
_game_mode = GM_NORMAL; |
|
559 |
||
560 |
// Copy in game options |
|
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
561 |
_opt_ptr = &_opt; |
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
562 |
memcpy(_opt_ptr, &_opt_newgame, sizeof(GameOptions)); |
0 | 563 |
|
564 |
GfxLoadSprites(); |
|
565 |
||
136
78ac8de2b2b8
(svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents:
126
diff
changeset
|
566 |
// Reinitialize windows |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1440
diff
changeset
|
567 |
ResetWindowSystem(); |
0 | 568 |
LoadStringWidthTable(); |
569 |
||
570 |
SetupColorsAndInitialWindow(); |
|
571 |
||
572 |
// Randomize world |
|
2051 | 573 |
GenerateWorld(0, 1<<_patches.map_x, 1<<_patches.map_y); |
0 | 574 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
575 |
// In a dedicated server, the server does not play |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
576 |
if (_network_dedicated) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
577 |
_local_player = OWNER_SPECTATOR; |
2026 | 578 |
} else { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
579 |
// Create a single player |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
580 |
DoStartupNewPlayer(false); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
581 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
582 |
_local_player = 0; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
583 |
_current_player = _local_player; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
584 |
DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_REPLACE_VEHICLE); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
585 |
} |
0 | 586 |
|
587 |
MarkWholeScreenDirty(); |
|
588 |
} |
|
589 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
590 |
static void MakeNewEditorWorld(void) |
0 | 591 |
{ |
592 |
_game_mode = GM_EDITOR; |
|
593 |
||
594 |
// Copy in game options |
|
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
595 |
_opt_ptr = &_opt; |
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
596 |
memcpy(_opt_ptr, &_opt_newgame, sizeof(GameOptions)); |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
597 |
|
0 | 598 |
GfxLoadSprites(); |
599 |
||
136
78ac8de2b2b8
(svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents:
126
diff
changeset
|
600 |
// Re-init the windowing system |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1440
diff
changeset
|
601 |
ResetWindowSystem(); |
0 | 602 |
|
603 |
// Create toolbars |
|
604 |
SetupColorsAndInitialWindow(); |
|
605 |
||
606 |
// Startup the game system |
|
2051 | 607 |
GenerateWorld(1, 1<<_patches.map_x, 1<<_patches.map_y); |
0 | 608 |
|
609 |
_local_player = OWNER_NONE; |
|
610 |
MarkWholeScreenDirty(); |
|
611 |
} |
|
612 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
613 |
void StartupPlayers(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
614 |
void StartupDisasters(void); |
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
115
diff
changeset
|
615 |
|
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
616 |
/** |
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
617 |
* Start Scenario starts a new game based on a scenario. |
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
618 |
* Eg 'New Game' --> select a preset scenario |
1501
0faec0f792b0
(svn r2005) - Fix: fix previous commit. Using 'New Game (scenario)' will use YOUR difficulty settings but ingame options (eg townnames, currency). Also settings are correctly saved when closing the difficulty window now.
Darkvater
parents:
1500
diff
changeset
|
619 |
* This starts a scenario based on your current difficulty settings |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
620 |
*/ |
1095 | 621 |
static void StartScenario(void) |
0 | 622 |
{ |
623 |
_game_mode = GM_NORMAL; |
|
624 |
||
625 |
// invalid type |
|
626 |
if (_file_to_saveload.mode == SL_INVALID) { |
|
627 |
printf("Savegame is obsolete or invalid format: %s\n", _file_to_saveload.name); |
|
628 |
ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0); |
|
629 |
_game_mode = GM_MENU; |
|
630 |
return; |
|
631 |
} |
|
632 |
||
633 |
GfxLoadSprites(); |
|
634 |
||
136
78ac8de2b2b8
(svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents:
126
diff
changeset
|
635 |
// Reinitialize windows |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1440
diff
changeset
|
636 |
ResetWindowSystem(); |
0 | 637 |
LoadStringWidthTable(); |
638 |
||
639 |
SetupColorsAndInitialWindow(); |
|
640 |
||
641 |
// Load game |
|
642 |
if (SaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode) != SL_OK) { |
|
643 |
LoadIntroGame(); |
|
644 |
ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0); |
|
645 |
} |
|
646 |
||
1501
0faec0f792b0
(svn r2005) - Fix: fix previous commit. Using 'New Game (scenario)' will use YOUR difficulty settings but ingame options (eg townnames, currency). Also settings are correctly saved when closing the difficulty window now.
Darkvater
parents:
1500
diff
changeset
|
647 |
_opt_ptr = &_opt; |
0faec0f792b0
(svn r2005) - Fix: fix previous commit. Using 'New Game (scenario)' will use YOUR difficulty settings but ingame options (eg townnames, currency). Also settings are correctly saved when closing the difficulty window now.
Darkvater
parents:
1500
diff
changeset
|
648 |
memcpy(&_opt_ptr->diff, &_opt_newgame.diff, sizeof(GameDifficulty)); |
0faec0f792b0
(svn r2005) - Fix: fix previous commit. Using 'New Game (scenario)' will use YOUR difficulty settings but ingame options (eg townnames, currency). Also settings are correctly saved when closing the difficulty window now.
Darkvater
parents:
1500
diff
changeset
|
649 |
_opt.diff_level = _opt_newgame.diff_level; |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
650 |
|
115
3a3c64e7be82
(svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents:
105
diff
changeset
|
651 |
// Inititalize data |
3a3c64e7be82
(svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents:
105
diff
changeset
|
652 |
StartupPlayers(); |
3a3c64e7be82
(svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents:
105
diff
changeset
|
653 |
StartupEngines(); |
3a3c64e7be82
(svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents:
105
diff
changeset
|
654 |
StartupDisasters(); |
3a3c64e7be82
(svn r116) Fix: [ 963056 ] Wrong trains you can buy with scenarios
dominik
parents:
105
diff
changeset
|
655 |
|
0 | 656 |
_local_player = 0; |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
657 |
_current_player = _local_player; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
658 |
DoCommandP(0, (_patches.autorenew << 15 ) | (_patches.autorenew_months << 16) | 4, _patches.autorenew_money, NULL, CMD_REPLACE_VEHICLE); |
0 | 659 |
|
660 |
MarkWholeScreenDirty(); |
|
661 |
} |
|
662 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
663 |
bool SafeSaveOrLoad(const char *filename, int mode, int newgm) |
0 | 664 |
{ |
665 |
byte ogm = _game_mode; |
|
666 |
int r; |
|
667 |
||
668 |
_game_mode = newgm; |
|
669 |
r = SaveOrLoad(filename, mode); |
|
670 |
if (r == SL_REINIT) { |
|
671 |
if (ogm == GM_MENU) |
|
672 |
LoadIntroGame(); |
|
673 |
else if (ogm == GM_EDITOR) |
|
674 |
MakeNewEditorWorld(); |
|
675 |
else |
|
676 |
MakeNewGame(); |
|
677 |
return false; |
|
678 |
} else if (r != SL_OK) { |
|
679 |
_game_mode = ogm; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
680 |
return false; |
0 | 681 |
} else |
682 |
return true; |
|
683 |
} |
|
684 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
685 |
void SwitchMode(int new_mode) |
0 | 686 |
{ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
687 |
#ifdef ENABLE_NETWORK |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
688 |
// If we are saving something, the network stays in his current state |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
689 |
if (new_mode != SM_SAVE) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
690 |
// If the network is active, make it not-active |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
691 |
if (_networking) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
692 |
if (_network_server && (new_mode == SM_LOAD || new_mode == SM_NEWGAME)) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
693 |
NetworkReboot(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
694 |
NetworkUDPClose(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
695 |
} else { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
696 |
NetworkDisconnect(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
697 |
NetworkUDPClose(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
698 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
699 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
700 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
701 |
// If we are a server, we restart the server |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
702 |
if (_is_network_server) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
703 |
// But not if we are going to the menu |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
704 |
if (new_mode != SM_MENU) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
705 |
NetworkServerStart(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
706 |
} else { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
707 |
// This client no longer wants to be a network-server |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
708 |
_is_network_server = false; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
709 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
710 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
711 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
712 |
#endif /* ENABLE_NETWORK */ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
713 |
|
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
714 |
switch (new_mode) { |
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
715 |
case SM_EDITOR: /* Switch to scenario editor */ |
0 | 716 |
MakeNewEditorWorld(); |
717 |
break; |
|
718 |
||
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
719 |
case SM_NEWGAME: /* New Game --> 'Random game' */ |
630
fd3c36132342
(svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents:
614
diff
changeset
|
720 |
#ifdef ENABLE_NETWORK |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
721 |
if (_network_server) |
2100
868d62687c9a
(svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents:
2096
diff
changeset
|
722 |
snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "Random Map"); |
630
fd3c36132342
(svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents:
614
diff
changeset
|
723 |
#endif /* ENABLE_NETWORK */ |
0 | 724 |
MakeNewGame(); |
725 |
break; |
|
726 |
||
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
727 |
case SM_START_SCENARIO: /* New Game --> Choose one of the preset scenarios */ |
2100
868d62687c9a
(svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents:
2096
diff
changeset
|
728 |
#ifdef ENABLE_NETWORK |
868d62687c9a
(svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents:
2096
diff
changeset
|
729 |
if (_network_server) |
868d62687c9a
(svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents:
2096
diff
changeset
|
730 |
snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "%s (Loaded scenario)", _file_to_saveload.title); |
868d62687c9a
(svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents:
2096
diff
changeset
|
731 |
#endif /* ENABLE_NETWORK */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
732 |
StartScenario(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
733 |
break; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
734 |
|
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
735 |
case SM_LOAD: { /* Load game, Play Scenario */ |
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
736 |
_opt_ptr = &_opt; |
0 | 737 |
|
738 |
_error_message = INVALID_STRING_ID; |
|
739 |
if (!SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_NORMAL)) { |
|
942
31f28eedd2b8
(svn r1430) -Fix: starting openttd with -g <invalid_name> now acts normal
truelight
parents:
929
diff
changeset
|
740 |
LoadIntroGame(); |
0 | 741 |
ShowErrorMessage(_error_message, STR_4009_GAME_LOAD_FAILED, 0, 0); |
742 |
} else { |
|
743 |
_local_player = 0; |
|
744 |
DoCommandP(0, 0, 0, NULL, CMD_PAUSE); // decrease pause counter (was increased from opening load dialog) |
|
630
fd3c36132342
(svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents:
614
diff
changeset
|
745 |
#ifdef ENABLE_NETWORK |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
746 |
if (_network_server) |
2100
868d62687c9a
(svn r2610) - Feature: set server map name to the loaded name of the game/scenario. Also truncate where neccessary
Darkvater
parents:
2096
diff
changeset
|
747 |
snprintf(_network_game_info.map_name, NETWORK_NAME_LENGTH, "%s (Loaded game)", _file_to_saveload.title); |
630
fd3c36132342
(svn r1061) -Fix: [Network] Compiling without ENABLE_NETWORK now works again correctly
truelight
parents:
614
diff
changeset
|
748 |
#endif /* ENABLE_NETWORK */ |
0 | 749 |
} |
750 |
break; |
|
751 |
} |
|
752 |
||
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
753 |
case SM_LOAD_SCENARIO: { /* Load scenario from scenario editor */ |
0 | 754 |
int i; |
755 |
||
756 |
if (SafeSaveOrLoad(_file_to_saveload.name, _file_to_saveload.mode, GM_EDITOR)) { |
|
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
757 |
_opt_ptr = &_opt; |
0 | 758 |
|
759 |
_local_player = OWNER_NONE; |
|
760 |
_generating_world = true; |
|
761 |
// delete all players. |
|
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
762 |
for (i = 0; i != MAX_PLAYERS; i++) { |
0 | 763 |
ChangeOwnershipOfPlayerItems(i, 0xff); |
764 |
_players[i].is_active = false; |
|
765 |
} |
|
766 |
_generating_world = false; |
|
767 |
// delete all stations owned by a player |
|
768 |
DeleteAllPlayerStations(); |
|
769 |
} else |
|
770 |
ShowErrorMessage(INVALID_STRING_ID, STR_4009_GAME_LOAD_FAILED, 0, 0); |
|
771 |
||
772 |
break; |
|
773 |
} |
|
774 |
||
775 |
||
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
776 |
case SM_MENU: /* Switch to game intro menu */ |
0 | 777 |
LoadIntroGame(); |
778 |
break; |
|
779 |
||
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
780 |
case SM_SAVE: /* Save game */ |
0 | 781 |
if (SaveOrLoad(_file_to_saveload.name, SL_SAVE) != SL_OK) |
782 |
ShowErrorMessage(INVALID_STRING_ID, STR_4007_GAME_SAVE_FAILED, 0, 0); |
|
783 |
else |
|
784 |
DeleteWindowById(WC_SAVELOAD, 0); |
|
785 |
break; |
|
786 |
||
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
787 |
case SM_GENRANDLAND: /* Generate random land within scenario editor */ |
2051 | 788 |
GenerateWorld(2, 1<<_patches.map_x, 1<<_patches.map_y); |
0 | 789 |
// XXX: set date |
790 |
_local_player = OWNER_NONE; |
|
791 |
MarkWholeScreenDirty(); |
|
792 |
break; |
|
793 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
794 |
|
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
795 |
if (_switch_mode_errorstr != INVALID_STRING_ID) |
172
8d8b3383470d
(svn r173) -Network: [1023231] Debug Code + ErrorBoxes + Load Game/Scenario. Added some more desync debug code and replaced some of the error() calls with some better error boxes. Hopefully find desyncs easier (sign_de)
darkvater
parents:
168
diff
changeset
|
796 |
ShowErrorMessage(INVALID_STRING_ID,_switch_mode_errorstr,0,0); |
0 | 797 |
} |
798 |
||
799 |
||
800 |
// State controlling game loop. |
|
801 |
// The state must not be changed from anywhere |
|
802 |
// but here. |
|
803 |
// That check is enforced in DoCommand. |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
804 |
void StateGameLoop(void) |
0 | 805 |
{ |
213
770e504a6e51
(svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents:
208
diff
changeset
|
806 |
// dont execute the state loop during pause |
770e504a6e51
(svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents:
208
diff
changeset
|
807 |
if (_pause) return; |
770e504a6e51
(svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents:
208
diff
changeset
|
808 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
809 |
// _frame_counter is increased somewhere else when in network-mode |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
810 |
// Sidenote: _frame_counter is ONLY used for _savedump in non-MP-games |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
811 |
// Should that not be deleted? If so, the next 2 lines can also be deleted |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
812 |
if (!_networking) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
813 |
_frame_counter++; |
0 | 814 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
815 |
if (_savedump_path[0] && (uint)_frame_counter >= _savedump_first && (uint)(_frame_counter -_savedump_first) % _savedump_freq == 0 ) { |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
816 |
char buf[100]; |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
817 |
sprintf(buf, "%s%.5d.sav", _savedump_path, _frame_counter); |
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
818 |
SaveOrLoad(buf, SL_SAVE); |
0 | 819 |
if ((uint)_frame_counter >= _savedump_last) exit(1); |
820 |
} |
|
821 |
||
822 |
if (_game_mode == GM_EDITOR) { |
|
823 |
RunTileLoop(); |
|
824 |
CallVehicleTicks(); |
|
825 |
CallLandscapeTick(); |
|
826 |
CallWindowTickEvent(); |
|
827 |
NewsLoop(); |
|
828 |
} else { |
|
206 | 829 |
// All these actions has to be done from OWNER_NONE |
830 |
// for multiplayer compatibility |
|
831 |
uint p = _current_player; |
|
832 |
_current_player = OWNER_NONE; |
|
833 |
||
0 | 834 |
AnimateAnimatedTiles(); |
835 |
IncreaseDate(); |
|
836 |
RunTileLoop(); |
|
837 |
CallVehicleTicks(); |
|
838 |
CallLandscapeTick(); |
|
839 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
840 |
// To bad the AI does not work in multiplayer, because states are not saved |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
841 |
// perfectly |
2092
c30495feef79
(svn r2602) -Codechange: removed unused variable (disable_computer)
truelight
parents:
2078
diff
changeset
|
842 |
if (!_networking) |
0 | 843 |
RunOtherPlayersLoop(); |
844 |
||
845 |
CallWindowTickEvent(); |
|
846 |
NewsLoop(); |
|
206 | 847 |
_current_player = p; |
0 | 848 |
} |
849 |
} |
|
850 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
851 |
static void DoAutosave(void) |
0 | 852 |
{ |
853 |
char buf[200]; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
854 |
|
1 | 855 |
if (_patches.keep_all_autosave && _local_player != OWNER_SPECTATOR) { |
1962
51ee4f459268
(svn r2468) -Codechange: Got rid of DEREF_PLAYER and replaced it by GetPlayer
celestar
parents:
1927
diff
changeset
|
856 |
const Player *p = GetPlayer(_local_player); |
0 | 857 |
char *s; |
858 |
sprintf(buf, "%s%s", _path.autosave_dir, PATHSEP); |
|
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
859 |
|
534
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
860 |
SetDParam(0, p->name_1); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
861 |
SetDParam(1, p->name_2); |
17ab2f22ff74
(svn r901) Small step in the process to clean up the DPARAM mess:
tron
parents:
507
diff
changeset
|
862 |
SetDParam(2, _date); |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
863 |
s = (char*)GetString(buf + strlen(_path.autosave_dir) + strlen(PATHSEP), STR_4004); |
0 | 864 |
strcpy(s, ".sav"); |
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
865 |
} else { /* Save a maximum of 15 autosaves */ |
0 | 866 |
int n = _autosave_ctr; |
867 |
_autosave_ctr = (_autosave_ctr + 1) & 15; |
|
868 |
sprintf(buf, "%s%sautosave%d.sav", _path.autosave_dir, PATHSEP, n); |
|
869 |
} |
|
870 |
||
557
8540788a827e
(svn r959) -Fix: fix previous typo for workaround of braindead MSVC6 (Tron)
darkvater
parents:
543
diff
changeset
|
871 |
DEBUG(misc, 2) ("Autosaving to %s", buf); |
0 | 872 |
if (SaveOrLoad(buf, SL_SAVE) != SL_OK) |
873 |
ShowErrorMessage(INVALID_STRING_ID, STR_AUTOSAVE_FAILED, 0, 0); |
|
874 |
} |
|
875 |
||
1397
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
876 |
static void ScrollMainViewport(int x, int y) |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
877 |
{ |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
878 |
if (_game_mode != GM_MENU) { |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
879 |
Window *w = FindWindowById(WC_MAIN_WINDOW, 0); |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
880 |
assert(w); |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
881 |
|
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
882 |
WP(w,vp_d).scrollpos_x += x << w->viewport->zoom; |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
883 |
WP(w,vp_d).scrollpos_y += y << w->viewport->zoom; |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
884 |
} |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
885 |
} |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
886 |
|
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
887 |
static const int8 scrollamt[16][2] = { |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
888 |
{ 0, 0}, |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
889 |
{-2, 0}, // 1:left |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
890 |
{ 0,-2}, // 2:up |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
891 |
{-2,-1}, // 3:left + up |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
892 |
{ 2, 0}, // 4:right |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
893 |
{ 0, 0}, // 5:left + right |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
894 |
{ 2,-1}, // 6:right + up |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
895 |
{ 0,-2}, // 7:left + right + up = up |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
896 |
{ 0 ,2}, // 8:down |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
897 |
{-2 ,1}, // 9:down+left |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
898 |
{ 0, 0}, // 10:impossible |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
899 |
{-2, 0}, // 11:left + up + down = left |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
900 |
{ 2, 1}, // 12:down+right |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
901 |
{ 0, 2}, // 13:left + right + down = down |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
902 |
{ 0,-2}, // 14:left + right + up = up |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
903 |
{ 0, 0}, // 15:impossible |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
904 |
}; |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
905 |
|
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
906 |
static void HandleKeyScrolling(void) |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
907 |
{ |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
908 |
if (_dirkeys && !_no_scroll) { |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
909 |
int factor = _shift_pressed ? 50 : 10; |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
910 |
ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor); |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
911 |
} |
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1385
diff
changeset
|
912 |
} |
1199
15d0c3424a45
(svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents:
1181
diff
changeset
|
913 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
914 |
void GameLoop(void) |
0 | 915 |
{ |
916 |
int m; |
|
917 |
||
918 |
// autosave game? |
|
919 |
if (_do_autosave) { |
|
920 |
_do_autosave = false; |
|
921 |
DoAutosave(); |
|
922 |
RedrawAutosave(); |
|
923 |
} |
|
924 |
||
1199
15d0c3424a45
(svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents:
1181
diff
changeset
|
925 |
// handle scrolling of the main window |
15d0c3424a45
(svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents:
1181
diff
changeset
|
926 |
if (_dirkeys) HandleKeyScrolling(); |
15d0c3424a45
(svn r1703) - Fix: Scrolling with the arrow keys is now smooth and it now also scrolls exactly in tile direction if e.g. up and left are pressed
dominik
parents:
1181
diff
changeset
|
927 |
|
0 | 928 |
// make a screenshot? |
929 |
if ((m=_make_screenshot) != 0) { |
|
930 |
_make_screenshot = 0; |
|
931 |
switch(m) { |
|
932 |
case 1: // make small screenshot |
|
933 |
UndrawMouseCursor(); |
|
934 |
ShowScreenshotResult(MakeScreenshot()); |
|
935 |
break; |
|
936 |
case 2: // make large screenshot |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
861
diff
changeset
|
937 |
ShowScreenshotResult(MakeWorldScreenshot(-(int)MapMaxX() * 32, 0, MapMaxX() * 64, MapSizeY() * 32, 0)); |
0 | 938 |
break; |
939 |
} |
|
940 |
} |
|
941 |
||
942 |
// switch game mode? |
|
943 |
if ((m=_switch_mode) != SM_NONE) { |
|
944 |
_switch_mode = SM_NONE; |
|
945 |
SwitchMode(m); |
|
946 |
} |
|
947 |
||
948 |
IncreaseSpriteLRU(); |
|
949 |
InteractiveRandom(); |
|
950 |
||
951 |
if (_scroller_click_timeout > 3) |
|
952 |
_scroller_click_timeout -= 3; |
|
953 |
else |
|
954 |
_scroller_click_timeout = 0; |
|
955 |
||
956 |
_caret_timer += 3; |
|
957 |
_timer_counter+=8; |
|
958 |
CursorTick(); |
|
959 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
960 |
#ifdef ENABLE_NETWORK |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
961 |
// Check for UDP stuff |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
962 |
NetworkUDPGameLoop(); |
0 | 963 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
964 |
if (_networking) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
965 |
// Multiplayer |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
966 |
NetworkGameLoop(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
967 |
} else { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
968 |
if (_network_reconnect > 0 && --_network_reconnect == 0) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
969 |
// This means that we want to reconnect to the last host |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
970 |
// We do this here, because it means that the network is really closed |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
971 |
NetworkClientConnectGame(_network_last_host, _network_last_port); |
206 | 972 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
973 |
// Singleplayer |
213
770e504a6e51
(svn r214) -Feature: CMD_NET_INSTANT [just in time command handling over network] (sign_de)
darkvater
parents:
208
diff
changeset
|
974 |
StateGameLoop(); |
0 | 975 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
976 |
#else |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
977 |
StateGameLoop(); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
978 |
#endif /* ENABLE_NETWORK */ |
0 | 979 |
|
980 |
if (!_pause && _display_opt&DO_FULL_ANIMATION) |
|
981 |
DoPaletteAnimations(); |
|
982 |
||
67
b2b551af3d9f
(svn r68) -Fix: [1009621] build in pause is now a cheat instead of a patch (truesatan)
darkvater
parents:
65
diff
changeset
|
983 |
if (!_pause || _cheats.build_in_pause.value) |
0 | 984 |
MoveAllTextEffects(); |
985 |
||
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1542
diff
changeset
|
986 |
InputLoop(); |
0 | 987 |
|
1608
074dff2e4890
(svn r2112) -Fix: ExtMidi no longer halts the game while starting a song
tron
parents:
1570
diff
changeset
|
988 |
MusicLoop(); |
0 | 989 |
} |
990 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1036
diff
changeset
|
991 |
void BeforeSaveGame(void) |
0 | 992 |
{ |
993 |
Window *w = FindWindowById(WC_MAIN_WINDOW, 0); |
|
994 |
||
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
961
diff
changeset
|
995 |
if (w != NULL) { |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
961
diff
changeset
|
996 |
_saved_scrollpos_x = WP(w,vp_d).scrollpos_x; |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
961
diff
changeset
|
997 |
_saved_scrollpos_y = WP(w,vp_d).scrollpos_y; |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
961
diff
changeset
|
998 |
_saved_scrollpos_zoom = w->viewport->zoom; |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
961
diff
changeset
|
999 |
} |
0 | 1000 |
} |
1001 |
||
1095 | 1002 |
static void ConvertTownOwner(void) |
0 | 1003 |
{ |
1977
4392ae3d8e31
(svn r2483) Replace almost 500 "uint tile" (and variants) with "TileIndex tile"
tron
parents:
1962
diff
changeset
|
1004 |
TileIndex tile; |
0 | 1005 |
|
863
8d09f9331a80
(svn r1344) Use MapSize[XY]() (or MapSize()/MapMax[XY]() where appropriate) instead of TILES_[XY]
tron
parents:
861
diff
changeset
|
1006 |
for (tile = 0; tile != MapSize(); tile++) { |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1027
diff
changeset
|
1007 |
if (IsTileType(tile, MP_STREET)) { |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2033
diff
changeset
|
1008 |
if (IsLevelCrossing(tile) && _m[tile].m3 & 0x80) |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2033
diff
changeset
|
1009 |
_m[tile].m3 = OWNER_TOWN; |
0 | 1010 |
|
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2033
diff
changeset
|
1011 |
if (_m[tile].owner & 0x80) SetTileOwner(tile, OWNER_TOWN); |
1035
0a170deb6e33
(svn r1536) Move GET_TILEHEIGHT, GET_TILETYPE and IS_TILETYPE to map.h, turn them into inline functions and add some asserts
tron
parents:
1027
diff
changeset
|
1012 |
} else if (IsTileType(tile, MP_TUNNELBRIDGE)) { |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2033
diff
changeset
|
1013 |
if (_m[tile].owner & 0x80) SetTileOwner(tile, OWNER_TOWN); |
0 | 1014 |
} |
1015 |
} |
|
1016 |
} |
|
1017 |
||
1018 |
// before savegame version 4, the name of the company determined if it existed |
|
1095 | 1019 |
static void CheckIsPlayerActive(void) |
0 | 1020 |
{ |
1021 |
Player *p; |
|
1022 |
FOR_ALL_PLAYERS(p) { |
|
1023 |
if (p->name_1 != 0) { |
|
1024 |
p->is_active = true; |
|
1025 |
} |
|
1026 |
} |
|
1027 |
} |
|
1028 |
||
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1029 |
// since savegame version 4.1, exclusive transport rights are stored at towns |
1095 | 1030 |
static void UpdateExclusiveRights(void) |
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1031 |
{ |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1032 |
Town *t; |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1033 |
FOR_ALL_TOWNS(t) if (t->xy != 0) { |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1034 |
t->exclusivity=(byte)-1; |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1035 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1036 |
|
123
d550772c61e6
(svn r124) Prepared code for removal of block_months variable in next major savegame version
dominik
parents:
121
diff
changeset
|
1037 |
/* FIXME old exclusive rights status is not being imported (stored in s->blocked_months_obsolete) |
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1038 |
could be implemented this way: |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1039 |
1.) Go through all stations |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1040 |
Build an array town_blocked[ town_id ][ player_id ] |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1041 |
that stores if at least one station in that town is blocked for a player |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1042 |
2.) Go through that array, if you find a town that is not blocked for |
2026 | 1043 |
one player, but for all others, then give him exclusivity. |
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1044 |
*/ |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1045 |
} |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1046 |
|
1500
228f77e88adf
(svn r2004) - Fix: [ 1149487 ] Autosave ignoring settings
Darkvater
parents:
1496
diff
changeset
|
1047 |
const byte convert_currency[] = { |
762
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
760
diff
changeset
|
1048 |
0, 1, 12, 8, 3, |
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
760
diff
changeset
|
1049 |
10, 14, 19, 4, 5, |
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
760
diff
changeset
|
1050 |
9, 11, 13, 6, 17, |
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
760
diff
changeset
|
1051 |
16, 22, 21, 7, 15, |
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
760
diff
changeset
|
1052 |
18, 2, 20, }; |
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
760
diff
changeset
|
1053 |
|
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
760
diff
changeset
|
1054 |
// since savegame version 4.2 the currencies are arranged differently |
1095 | 1055 |
static void UpdateCurrencies(void) |
762
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
760
diff
changeset
|
1056 |
{ |
768
deb40d3554a2
(svn r1233) Fixed several currency issues. Now currencies should work correctly again.
dominik
parents:
762
diff
changeset
|
1057 |
_opt.currency = convert_currency[_opt.currency]; |
762
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
760
diff
changeset
|
1058 |
} |
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
760
diff
changeset
|
1059 |
|
1181
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1060 |
/* Up to revision 1413 the invisible tiles at the southern border have not been |
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1061 |
* MP_VOID, even though they should have. This is fixed by this function |
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1062 |
*/ |
1095 | 1063 |
static void UpdateVoidTiles(void) |
929
1a071a06af3f
(svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents:
921
diff
changeset
|
1064 |
{ |
959
b031d88c76f3
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
950
diff
changeset
|
1065 |
uint i; |
1181
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1066 |
|
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1067 |
for (i = 0; i < MapMaxY(); ++i) |
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1068 |
SetTileType(i * MapSizeX() + MapMaxX(), MP_VOID); |
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1069 |
for (i = 0; i < MapSizeX(); ++i) |
6231b823d796
(svn r1683) Fix placement of MP_VOID tiles. On square maps it accidently works, but on non-square maps the wrong tiles would get marked as MP_VOID
tron
parents:
1165
diff
changeset
|
1070 |
SetTileType(MapSizeX() * MapMaxY() + i, MP_VOID); |
929
1a071a06af3f
(svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents:
921
diff
changeset
|
1071 |
} |
1a071a06af3f
(svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents:
921
diff
changeset
|
1072 |
|
1165
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1073 |
// since savegame version 6.0 each sign has an "owner", signs without owner (from old games are set to 255) |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1074 |
static void UpdateSignOwner(void) |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1075 |
{ |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1076 |
SignStruct *ss; |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1077 |
FOR_ALL_SIGNS(ss) { |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1078 |
ss->owner = OWNER_NONE; // no owner |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1079 |
} |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1080 |
} |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1081 |
|
950
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
942
diff
changeset
|
1082 |
extern void UpdateOldAircraft( void ); |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
942
diff
changeset
|
1083 |
extern void UpdateOilRig( void ); |
0 | 1084 |
|
1085 |
bool AfterLoadGame(uint version) |
|
1086 |
{ |
|
1087 |
Window *w; |
|
1088 |
ViewPort *vp; |
|
2147
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
2100
diff
changeset
|
1089 |
Player *p; |
988
2482369a61ff
(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
983
diff
changeset
|
1090 |
|
0 | 1091 |
// in version 2.1 of the savegame, town owner was unified. |
1092 |
if (version <= 0x200) { |
|
1093 |
ConvertTownOwner(); |
|
1094 |
} |
|
1095 |
||
121
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1096 |
// from version 4.1 of the savegame, exclusive rights are stored at towns |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1097 |
if (version <= 0x400) { |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1098 |
UpdateExclusiveRights(); |
c2f18f4d8be1
(svn r122) Change: exclusive transport rights are now stored per town instead of per station
dominik
parents:
116
diff
changeset
|
1099 |
} |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1100 |
|
762
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
760
diff
changeset
|
1101 |
// from version 4.2 of the savegame, currencies are in a different order |
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
760
diff
changeset
|
1102 |
if (version <= 0x401) { |
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
760
diff
changeset
|
1103 |
UpdateCurrencies(); |
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
760
diff
changeset
|
1104 |
} |
7afe6c8554cb
(svn r1222) Currency cleanup. Changed some currency symbols according to forum suggestions (thx ChrisCF) and rearranged the currencies alphabetically (except for the major ones).
dominik
parents:
760
diff
changeset
|
1105 |
|
1165
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1106 |
// from version 6.0 of the savegame, signs have an "owner" |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1107 |
if (version <= 0x600) { |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1108 |
UpdateSignOwner(); |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1109 |
} |
2cdf7a0e217a
(svn r1667) - Feature: Signs are now shown in the color of the player who created them
dominik
parents:
1115
diff
changeset
|
1110 |
|
831
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1111 |
/* In old version there seems to be a problem that water is owned by |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1112 |
OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1113 |
(0x402) version, so I just check when versions are older, and then |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1114 |
walk through the whole map.. */ |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1115 |
if (version <= 0x402) { |
1981 | 1116 |
TileIndex tile = TileXY(0, 0); |
831
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1117 |
uint w = MapSizeX(); |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1118 |
uint h = MapSizeY(); |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1119 |
|
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1120 |
BEGIN_TILE_LOOP(tile_cur, w, h, tile) |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1121 |
if (IsTileType(tile_cur, MP_WATER) && GetTileOwner(tile_cur) >= MAX_PLAYERS) |
1902 | 1122 |
SetTileOwner(tile_cur, OWNER_WATER); |
831
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1123 |
END_TILE_LOOP(tile_cur, w, h, tile) |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1124 |
} |
f1cee10e3422
(svn r1302) -Fix: [ 1091655 ] In some older maps somehow water is owned by
truelight
parents:
802
diff
changeset
|
1125 |
|
0 | 1126 |
// convert road side to my format. |
1127 |
if (_opt.road_side) _opt.road_side = 1; |
|
1128 |
||
1129 |
// Load the sprites |
|
1130 |
GfxLoadSprites(); |
|
1131 |
||
1132 |
// Update current year |
|
1133 |
SetDate(_date); |
|
1134 |
||
1135 |
// reinit the landscape variables (landscape might have changed) |
|
1136 |
InitializeLandscapeVariables(true); |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1137 |
|
0 | 1138 |
// Update all vehicles |
1139 |
AfterLoadVehicles(); |
|
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1501
diff
changeset
|
1140 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1501
diff
changeset
|
1141 |
// Update all waypoints |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1501
diff
changeset
|
1142 |
if (version < 0x0C00) |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1501
diff
changeset
|
1143 |
FixOldWaypoints(); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1501
diff
changeset
|
1144 |
|
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1501
diff
changeset
|
1145 |
UpdateAllWaypointSigns(); |
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1501
diff
changeset
|
1146 |
|
0 | 1147 |
// in version 2.2 of the savegame, we have new airports |
1148 |
if (version <= 0x201) { |
|
1149 |
UpdateOldAircraft(); |
|
1150 |
} |
|
1151 |
||
1152 |
UpdateAllStationVirtCoord(); |
|
1153 |
||
1154 |
// Setup town coords |
|
1155 |
AfterLoadTown(); |
|
1156 |
UpdateAllSignVirtCoords(); |
|
1157 |
||
1158 |
// make sure there is a town in the game |
|
1159 |
if (_game_mode == GM_NORMAL && !ClosestTownFromTile(0, (uint)-1)) |
|
1160 |
{ |
|
1161 |
_error_message = STR_NO_TOWN_IN_SCENARIO; |
|
1162 |
return false; |
|
1163 |
} |
|
1164 |
||
1165 |
// Initialize windows |
|
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1440
diff
changeset
|
1166 |
ResetWindowSystem(); |
0 | 1167 |
SetupColorsAndInitialWindow(); |
1168 |
||
1169 |
w = FindWindowById(WC_MAIN_WINDOW, 0); |
|
1170 |
||
1171 |
WP(w,vp_d).scrollpos_x = _saved_scrollpos_x; |
|
1172 |
WP(w,vp_d).scrollpos_y = _saved_scrollpos_y; |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1173 |
|
0 | 1174 |
vp = w->viewport; |
1175 |
vp->zoom = _saved_scrollpos_zoom; |
|
1176 |
vp->virtual_width = vp->width << vp->zoom; |
|
1177 |
vp->virtual_height = vp->height << vp->zoom; |
|
1178 |
||
1179 |
||
1180 |
// in version 4.0 of the savegame, is_active was introduced to determine |
|
1181 |
// if a player does exist, rather then checking name_1 |
|
1182 |
if (version <= 0x400) { |
|
1183 |
CheckIsPlayerActive(); |
|
1184 |
} |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1185 |
|
929
1a071a06af3f
(svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents:
921
diff
changeset
|
1186 |
// the void tiles on the southern border used to belong to a wrong class. |
1a071a06af3f
(svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents:
921
diff
changeset
|
1187 |
if (version <= 0x402) |
1a071a06af3f
(svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents:
921
diff
changeset
|
1188 |
UpdateVoidTiles(); |
1a071a06af3f
(svn r1417) Fix: The invisible tiles on the southern border are now converted to class MP_VOID when an old map (with wrong classified invisible tiles) is loaded.
dominik
parents:
921
diff
changeset
|
1189 |
|
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
185
diff
changeset
|
1190 |
// If Load Scenario / New (Scenario) Game is used, |
139 | 1191 |
// a player does not exist yet. So create one here. |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1192 |
// 1 exeption: network-games. Those can have 0 players |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1193 |
// But this exeption is not true for network_servers! |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
534
diff
changeset
|
1194 |
if (!_players[0].is_active && (!_networking || (_networking && _network_server))) |
139 | 1195 |
DoStartupNewPlayer(false); |
0 | 1196 |
|
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
139
diff
changeset
|
1197 |
DoZoomInOutWindow(ZOOM_NONE, w); // update button status |
0 | 1198 |
MarkWholeScreenDirty(); |
1199 |
||
950
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
942
diff
changeset
|
1200 |
//In 5.1, Oilrigs have been moved (again) |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
942
diff
changeset
|
1201 |
if (version <= 0x500) { |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
942
diff
changeset
|
1202 |
UpdateOilRig(); |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
942
diff
changeset
|
1203 |
} |
1f6546ea35a3
(svn r1440) -Feature: Allows more flexible airport layouts now, as the number of
celestar
parents:
942
diff
changeset
|
1204 |
|
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1205 |
if (version <= 0x600) { |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1206 |
BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) { |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1207 |
if (IsTileType(tile, MP_HOUSE)) { |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2033
diff
changeset
|
1208 |
_m[tile].m4 = _m[tile].m2; |
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1209 |
//XXX magic |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1210 |
SetTileType(tile, MP_VOID); |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2033
diff
changeset
|
1211 |
_m[tile].m2 = ClosestTownFromTile(tile,(uint)-1)->index; |
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1212 |
SetTileType(tile, MP_HOUSE); |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1213 |
} else if (IsTileType(tile, MP_STREET)) { |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1214 |
//XXX magic |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2033
diff
changeset
|
1215 |
_m[tile].m4 |= (_m[tile].m2 << 4); |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1216 |
if (IsTileOwner(tile, OWNER_TOWN)) { |
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1217 |
SetTileType(tile, MP_VOID); |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2033
diff
changeset
|
1218 |
_m[tile].m2 = ClosestTownFromTile(tile,(uint)-1)->index; |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1219 |
SetTileType(tile, MP_STREET); |
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1220 |
} else { |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2033
diff
changeset
|
1221 |
_m[tile].m2 = 0; |
1901
fb05044cf5c3
(svn r2407) Use {Get,Is}TileOwner to get/check the owner of a tile and fix some bogus reads of _map_owner
tron
parents:
1891
diff
changeset
|
1222 |
} |
1264
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1223 |
} |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1224 |
} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0); |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1225 |
} |
280792016b02
(svn r1768) -Codechange: Store town index in _map2 of town tiles
celestar
parents:
1260
diff
changeset
|
1226 |
|
1377
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1349
diff
changeset
|
1227 |
if (version < 0x900) { |
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1349
diff
changeset
|
1228 |
Town *t; |
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1349
diff
changeset
|
1229 |
FOR_ALL_TOWNS(t) { |
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1349
diff
changeset
|
1230 |
UpdateTownMaxPass(t); |
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1349
diff
changeset
|
1231 |
} |
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1349
diff
changeset
|
1232 |
} |
2a418162176e
(svn r1881) -Fix: [ 1119308 ] Max passengers / mail variables are now 32 bit
celestar
parents:
1349
diff
changeset
|
1233 |
|
1993
7410864cfac8
(svn r2499) -Codechange: Moved the semaphore bit from bit 2 to bit 3 in _map_hi for rails, in order to make way for pbs
celestar
parents:
1981
diff
changeset
|
1234 |
if (version < 0xF00) { |
7410864cfac8
(svn r2499) -Codechange: Moved the semaphore bit from bit 2 to bit 3 in _map_hi for rails, in order to make way for pbs
celestar
parents:
1981
diff
changeset
|
1235 |
BEGIN_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0) { |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2033
diff
changeset
|
1236 |
if (IsTileType(tile, MP_RAILWAY) && HasSignals(tile) && HASBIT(_m[tile].m4, 2)) { |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2033
diff
changeset
|
1237 |
CLRBIT(_m[tile].m4, 2); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
2033
diff
changeset
|
1238 |
SETBIT(_m[tile].m4, 3); |
1993
7410864cfac8
(svn r2499) -Codechange: Moved the semaphore bit from bit 2 to bit 3 in _map_hi for rails, in order to make way for pbs
celestar
parents:
1981
diff
changeset
|
1239 |
} |
7410864cfac8
(svn r2499) -Codechange: Moved the semaphore bit from bit 2 to bit 3 in _map_hi for rails, in order to make way for pbs
celestar
parents:
1981
diff
changeset
|
1240 |
} END_TILE_LOOP(tile, MapSizeX(), MapSizeY(), 0); |
7410864cfac8
(svn r2499) -Codechange: Moved the semaphore bit from bit 2 to bit 3 in _map_hi for rails, in order to make way for pbs
celestar
parents:
1981
diff
changeset
|
1241 |
} |
7410864cfac8
(svn r2499) -Codechange: Moved the semaphore bit from bit 2 to bit 3 in _map_hi for rails, in order to make way for pbs
celestar
parents:
1981
diff
changeset
|
1242 |
|
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
1243 |
if (version < 0x1000) { |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
1244 |
int i; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
1245 |
FOR_ALL_PLAYERS(p) { |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
1246 |
for (i = 0; i < 256; i++) { |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
1247 |
p->engine_replacement[i] = INVALID_ENGINE; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
1248 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
1249 |
p->engine_renew = false; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
1250 |
p->engine_renew_months = -6; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
1251 |
p->engine_renew_money = 100000; |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
1252 |
} |
2322
962f8825ff6b
(svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents:
2297
diff
changeset
|
1253 |
if (_local_player < MAX_PLAYERS) { |
962f8825ff6b
(svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents:
2297
diff
changeset
|
1254 |
// Set the human controlled player to the patch settings |
962f8825ff6b
(svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents:
2297
diff
changeset
|
1255 |
// Scenario editor do not have any companies |
962f8825ff6b
(svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents:
2297
diff
changeset
|
1256 |
p = GetPlayer(_local_player); |
962f8825ff6b
(svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents:
2297
diff
changeset
|
1257 |
p->engine_renew = _patches.autorenew; |
962f8825ff6b
(svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents:
2297
diff
changeset
|
1258 |
p->engine_renew_months = _patches.autorenew_months; |
962f8825ff6b
(svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents:
2297
diff
changeset
|
1259 |
p->engine_renew_money = _patches.autorenew_money; |
962f8825ff6b
(svn r2848) -Fix: [ 1256044 ] fixed crash when loading a map made before rev 2817 in scenario editor. This was introduced in 2817
bjarni
parents:
2297
diff
changeset
|
1260 |
} |
2293
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
1261 |
} |
a71c210076be
(svn r2817) -Codechange: [autoreplace]: moved autoreplace and autorenew to serverside
bjarni
parents:
2290
diff
changeset
|
1262 |
|
2147
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
2100
diff
changeset
|
1263 |
FOR_ALL_PLAYERS(p) { |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
2100
diff
changeset
|
1264 |
p->avail_railtypes = GetPlayerRailtypes(p->index); |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
2100
diff
changeset
|
1265 |
} |
42efdf5020d1
(svn r2657) -Codechange: The available railtypes per player are now a bitmask, so
celestar
parents:
2100
diff
changeset
|
1266 |
|
0 | 1267 |
return true; |
1268 |
} |