author | tron |
Fri, 01 Jul 2005 15:46:27 +0000 | |
changeset 1999 | e1596a4aab01 |
parent 1914 | 2b4b3c3a95b4 |
child 2049 | 538e73c53f54 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
2 |
#include "openttd.h" |
1375
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
3 |
#include "string.h" |
1309
4403a69da4f8
(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:
1304
diff
changeset
|
4 |
#include "strings.h" // XXX GetParam* |
507
04b5403aaf6b
(svn r815) Include strings.h only in the files which need it.
tron
parents:
500
diff
changeset
|
5 |
#include "table/strings.h" |
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
6 |
#include "table/sprites.h" |
679
04ca2cd69420
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
543
diff
changeset
|
7 |
#include "map.h" |
0 | 8 |
#include "vehicle.h" |
9 |
#include "assert.h" |
|
10 |
#include "saveload.h" |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
11 |
#include "network.h" |
690
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
12 |
#include "network_data.h" |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
13 |
#include "network_server.h" |
842 | 14 |
#include "engine.h" |
1752
d65cd19f7117
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1595
diff
changeset
|
15 |
#include "vehicle_gui.h" |
0 | 16 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
17 |
extern void StartupEconomy(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
18 |
extern void InitNewsItemStructs(void); |
0 | 19 |
|
1328
eacd8225ed42
(svn r1832) Next byte -> char iteration: custom names
tron
parents:
1313
diff
changeset
|
20 |
char _name_array[512][32]; |
0 | 21 |
|
500
8e52f7797b48
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
410
diff
changeset
|
22 |
static inline uint32 ROR(uint32 x, int n) |
0 | 23 |
{ |
24 |
return (x >> n) + (x << ((sizeof(x)*8)-n)); |
|
25 |
} |
|
26 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
27 |
/* XXX - Player-seeds don't seem to be used anymore.. which is a good thing |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
28 |
so I just disabled them for now. If there are no problems, we can remove |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
29 |
it completely! -- TrueLight */ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
30 |
#undef PLAYER_SEED_RANDOM |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
31 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
32 |
#ifdef RANDOM_DEBUG |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
33 |
#include "network_data.h" |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
34 |
|
1120
047e8b16a954
(svn r1621) -Fix: fixed some compiler warnings for the random-debug-switch
truelight
parents:
1095
diff
changeset
|
35 |
uint32 DoRandom(int line, const char *file) |
260
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
256
diff
changeset
|
36 |
#else |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
37 |
uint32 Random(void) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
38 |
#endif |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
39 |
{ |
1121
8a7e7ace154f
(svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents:
1120
diff
changeset
|
40 |
|
8a7e7ace154f
(svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents:
1120
diff
changeset
|
41 |
uint32 s; |
8a7e7ace154f
(svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents:
1120
diff
changeset
|
42 |
uint32 t; |
8a7e7ace154f
(svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents:
1120
diff
changeset
|
43 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
44 |
#ifdef RANDOM_DEBUG |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
45 |
if (_networking && (DEREF_CLIENT(0)->status != STATUS_INACTIVE || !_network_server)) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
46 |
printf("Random [%d/%d] %s:%d\n",_frame_counter, _current_player, file, line); |
260
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
256
diff
changeset
|
47 |
#endif |
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
256
diff
changeset
|
48 |
|
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
256
diff
changeset
|
49 |
#ifdef PLAYER_SEED_RANDOM |
4819bcce8389
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
256
diff
changeset
|
50 |
if (_current_player>=MAX_PLAYERS || !_networking) { |
1121
8a7e7ace154f
(svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents:
1120
diff
changeset
|
51 |
s = _random_seeds[0][0]; |
8a7e7ace154f
(svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents:
1120
diff
changeset
|
52 |
t = _random_seeds[0][1]; |
1446
c95d3cb58985
(svn r1950) Fix: A slight adjustment in the DoRandom() function which however causes dramatic improvement in the distribution of random numbers.
pasky
parents:
1375
diff
changeset
|
53 |
_random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7) + 1; |
c95d3cb58985
(svn r1950) Fix: A slight adjustment in the DoRandom() function which however causes dramatic improvement in the distribution of random numbers.
pasky
parents:
1375
diff
changeset
|
54 |
return _random_seeds[0][1] = ROR(s, 3) - 1; |
206 | 55 |
} else { |
56 |
uint32 s = _player_seeds[_current_player][0]; |
|
57 |
uint32 t = _player_seeds[_current_player][1]; |
|
1446
c95d3cb58985
(svn r1950) Fix: A slight adjustment in the DoRandom() function which however causes dramatic improvement in the distribution of random numbers.
pasky
parents:
1375
diff
changeset
|
58 |
_player_seeds[_current_player][0] = s + ROR(t ^ 0x1234567F, 7) + 1; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
59 |
DEBUG(net, 1)("[NET-Seeds] Player seed called!"); |
1446
c95d3cb58985
(svn r1950) Fix: A slight adjustment in the DoRandom() function which however causes dramatic improvement in the distribution of random numbers.
pasky
parents:
1375
diff
changeset
|
60 |
return _player_seeds[_current_player][1] = ROR(s, 3) - 1; |
206 | 61 |
} |
256
dbeb1546519b
(svn r261) -Workaround: unplayeable network-game on busy maps because of wrong setup of _current_player. This is only a workaround that can cause desyncs too but not that often
signde
parents:
239
diff
changeset
|
62 |
#else |
1121
8a7e7ace154f
(svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents:
1120
diff
changeset
|
63 |
s = _random_seeds[0][0]; |
8a7e7ace154f
(svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents:
1120
diff
changeset
|
64 |
t = _random_seeds[0][1]; |
1446
c95d3cb58985
(svn r1950) Fix: A slight adjustment in the DoRandom() function which however causes dramatic improvement in the distribution of random numbers.
pasky
parents:
1375
diff
changeset
|
65 |
_random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7) + 1; |
c95d3cb58985
(svn r1950) Fix: A slight adjustment in the DoRandom() function which however causes dramatic improvement in the distribution of random numbers.
pasky
parents:
1375
diff
changeset
|
66 |
return _random_seeds[0][1] = ROR(s, 3) - 1; |
256
dbeb1546519b
(svn r261) -Workaround: unplayeable network-game on busy maps because of wrong setup of _current_player. This is only a workaround that can cause desyncs too but not that often
signde
parents:
239
diff
changeset
|
67 |
#endif |
0 | 68 |
} |
69 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
70 |
#ifdef RANDOM_DEBUG |
1120
047e8b16a954
(svn r1621) -Fix: fixed some compiler warnings for the random-debug-switch
truelight
parents:
1095
diff
changeset
|
71 |
uint DoRandomRange(uint max, int line, const char *file) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
72 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
73 |
return (uint16)DoRandom(line, file) * max >> 16; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
74 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
75 |
#else |
0 | 76 |
uint RandomRange(uint max) |
77 |
{ |
|
78 |
return (uint16)Random() * max >> 16; |
|
79 |
} |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
80 |
#endif |
0 | 81 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
82 |
uint32 InteractiveRandom(void) |
0 | 83 |
{ |
206 | 84 |
uint32 t = _random_seeds[1][1]; |
85 |
uint32 s = _random_seeds[1][0]; |
|
1446
c95d3cb58985
(svn r1950) Fix: A slight adjustment in the DoRandom() function which however causes dramatic improvement in the distribution of random numbers.
pasky
parents:
1375
diff
changeset
|
86 |
_random_seeds[1][0] = s + ROR(t ^ 0x1234567F, 7) + 1; |
c95d3cb58985
(svn r1950) Fix: A slight adjustment in the DoRandom() function which however causes dramatic improvement in the distribution of random numbers.
pasky
parents:
1375
diff
changeset
|
87 |
return _random_seeds[1][1] = ROR(s, 3) - 1; |
206 | 88 |
} |
89 |
||
239 | 90 |
uint InteractiveRandomRange(uint max) |
91 |
{ |
|
92 |
return (uint16)InteractiveRandom() * max >> 16; |
|
93 |
} |
|
94 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
95 |
void InitPlayerRandoms(void) |
206 | 96 |
{ |
97 |
int i; |
|
98 |
for (i=0; i<MAX_PLAYERS; i++) { |
|
99 |
_player_seeds[i][0]=InteractiveRandom(); |
|
100 |
_player_seeds[i][1]=InteractiveRandom(); |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
101 |
} |
0 | 102 |
} |
103 |
||
104 |
void SetDate(uint date) |
|
105 |
{ |
|
106 |
YearMonthDay ymd; |
|
107 |
ConvertDayToYMD(&ymd, _date = date); |
|
108 |
_cur_year = ymd.year; |
|
109 |
_cur_month = ymd.month; |
|
764
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
695
diff
changeset
|
110 |
#ifdef ENABLE_NETWORK |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
695
diff
changeset
|
111 |
_network_last_advertise_date = 0; |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
695
diff
changeset
|
112 |
#endif /* ENABLE_NETWORK */ |
0 | 113 |
} |
114 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
115 |
|
1812
26b041a529e9
(svn r2316) - Fix: [ 1154454 ] Fix BeOS build on Trunk (myob)
Darkvater
parents:
1752
diff
changeset
|
116 |
#ifdef ENABLE_NETWORK |
26b041a529e9
(svn r2316) - Fix: [ 1154454 ] Fix BeOS build on Trunk (myob)
Darkvater
parents:
1752
diff
changeset
|
117 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
118 |
// multi os compatible sleep function |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
119 |
|
770
c2eacca29601
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
764
diff
changeset
|
120 |
#ifdef __AMIGA__ |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
121 |
// usleep() implementation |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
122 |
# include <devices/timer.h> |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
123 |
# include <dos/dos.h> |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
124 |
|
770
c2eacca29601
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
764
diff
changeset
|
125 |
extern struct Device *TimerBase = NULL; |
c2eacca29601
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
764
diff
changeset
|
126 |
extern struct MsgPort *TimerPort = NULL; |
c2eacca29601
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
764
diff
changeset
|
127 |
extern struct timerequest *TimerRequest = NULL; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
128 |
#endif // __AMIGA__ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
129 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
130 |
void CSleep(int milliseconds) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
131 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
132 |
#if defined(WIN32) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
133 |
Sleep(milliseconds); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
134 |
#endif |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
135 |
#if defined(UNIX) |
770
c2eacca29601
(svn r1236) MorphOS: added make release like in OSX (tokai)
bjarni
parents:
764
diff
changeset
|
136 |
#if !defined(__BEOS__) && !defined(__AMIGA__) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
137 |
usleep(milliseconds * 1000); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
138 |
#endif |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
139 |
#ifdef __BEOS__ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
140 |
snooze(milliseconds * 1000); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
141 |
#endif |
785
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
770
diff
changeset
|
142 |
#if defined(__AMIGA__) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
143 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
144 |
ULONG signals; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
145 |
ULONG TimerSigBit = 1 << TimerPort->mp_SigBit; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
146 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
147 |
// send IORequest |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
148 |
TimerRequest->tr_node.io_Command = TR_ADDREQUEST; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
149 |
TimerRequest->tr_time.tv_secs = (milliseconds * 1000) / 1000000; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
150 |
TimerRequest->tr_time.tv_micro = (milliseconds * 1000) % 1000000; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
151 |
SendIO((struct IORequest *)TimerRequest); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
152 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
153 |
if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) { |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
154 |
AbortIO((struct IORequest *)TimerRequest); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
155 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
156 |
WaitIO((struct IORequest *)TimerRequest); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
157 |
} |
785
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
770
diff
changeset
|
158 |
#endif // __AMIGA__ |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
159 |
#endif |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
160 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
161 |
|
1812
26b041a529e9
(svn r2316) - Fix: [ 1154454 ] Fix BeOS build on Trunk (myob)
Darkvater
parents:
1752
diff
changeset
|
162 |
#endif /* ENABLE_NETWORK */ |
26b041a529e9
(svn r2316) - Fix: [ 1154454 ] Fix BeOS build on Trunk (myob)
Darkvater
parents:
1752
diff
changeset
|
163 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
164 |
void InitializeVehicles(void); |
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1538
diff
changeset
|
165 |
void InitializeWaypoints(void); |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1309
diff
changeset
|
166 |
void InitializeDepot(void); |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
167 |
void InitializeOrders(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
168 |
void InitializeClearLand(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
169 |
void InitializeRail(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
170 |
void InitializeRailGui(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
171 |
void InitializeRoad(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
172 |
void InitializeRoadGui(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
173 |
void InitializeAirportGui(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
174 |
void InitializeDock(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
175 |
void InitializeDockGui(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
176 |
void InitializeIndustries(void); |
1218 | 177 |
void InitializeLandscape(uint log_x, uint log_y); |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
178 |
void InitializeTowns(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
179 |
void InitializeTrees(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
180 |
void InitializeSigns(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
181 |
void InitializeStations(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
182 |
static void InitializeNameMgr(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
183 |
void InitializePlayers(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
184 |
static void InitializeCheats(void); |
1247 | 185 |
void InitializeNPF(void); |
0 | 186 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
187 |
void GenerateLandscape(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
188 |
void GenerateClearTile(void); |
0 | 189 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
190 |
void GenerateIndustries(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
191 |
void GenerateUnmovables(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
192 |
void GenerateTowns(void); |
0 | 193 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
194 |
void StartupPlayers(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
195 |
void StartupDisasters(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
196 |
void GenerateTrees(void); |
0 | 197 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
198 |
void ConvertGroundTilesIntoWaterTiles(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
199 |
|
1218 | 200 |
void InitializeGame(uint log_x, uint log_y) |
0 | 201 |
{ |
842 | 202 |
// Initialize the autoreplace array. Needs to be cleared between each game |
959
e6a3bbda610f
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
955
diff
changeset
|
203 |
uint i; |
880
f3d9b97fff06
(svn r1365) -Fix: very, very nasty buffer overflow bug introduced with replace vehicles. You CANNOT access the i[255] of an array that only has 255 elements! I will kick the next person that does that so hard...goddammit (I only noticed it because it screwed up my console in the debug build and took me at least an hour to fix)
darkvater
parents:
865
diff
changeset
|
204 |
for (i = 0; i < lengthof(_autoreplace_array); i++) |
842 | 205 |
_autoreplace_array[i] = i; |
880
f3d9b97fff06
(svn r1365) -Fix: very, very nasty buffer overflow bug introduced with replace vehicles. You CANNOT access the i[255] of an array that only has 255 elements! I will kick the next person that does that so hard...goddammit (I only noticed it because it screwed up my console in the debug build and took me at least an hour to fix)
darkvater
parents:
865
diff
changeset
|
206 |
|
1178
7c39a741eafb
(svn r1680) Feature: Replace train GUI now remembers the railtype selected in the dropdown menu
bjarni
parents:
1175
diff
changeset
|
207 |
_railtype_selected_in_replace_gui = 0; |
7c39a741eafb
(svn r1680) Feature: Replace train GUI now remembers the railtype selected in the dropdown menu
bjarni
parents:
1175
diff
changeset
|
208 |
|
842 | 209 |
AddTypeToEngines(); // make sure all engines have a type |
915 | 210 |
|
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
211 |
SetObjectToPlace(SPR_CURSOR_ZZZ, 0, 0, 0); |
0 | 212 |
|
213 |
_pause = 0; |
|
214 |
_fast_forward = 0; |
|
215 |
_tick_counter = 0; |
|
216 |
_date_fract = 0; |
|
217 |
_cur_tileloop_tile = 0; |
|
218 |
_vehicle_id_ctr_day = 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
219 |
|
0 | 220 |
{ |
221 |
uint starting = ConvertIntDate(_patches.starting_date); |
|
222 |
if ( starting == (uint)-1) starting = 10958; |
|
223 |
SetDate(starting); |
|
224 |
} |
|
225 |
||
226 |
InitializeVehicles(); |
|
1542
62a03537ad0b
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1538
diff
changeset
|
227 |
InitializeWaypoints(); |
1313
f1013ec3d318
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1309
diff
changeset
|
228 |
InitializeDepot(); |
1024
5e446b5b3ec5
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1009
diff
changeset
|
229 |
InitializeOrders(); |
0 | 230 |
|
231 |
InitNewsItemStructs(); |
|
1218 | 232 |
InitializeLandscape(log_x, log_y); |
0 | 233 |
InitializeClearLand(); |
234 |
InitializeRail(); |
|
235 |
InitializeRailGui(); |
|
236 |
InitializeRoad(); |
|
237 |
InitializeRoadGui(); |
|
238 |
InitializeAirportGui(); |
|
239 |
InitializeDock(); |
|
240 |
InitializeDockGui(); |
|
241 |
InitializeTowns(); |
|
242 |
InitializeTrees(); |
|
988
4304525d1b8b
(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
983
diff
changeset
|
243 |
InitializeSigns(); |
0 | 244 |
InitializeStations(); |
245 |
InitializeIndustries(); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
246 |
|
0 | 247 |
InitializeNameMgr(); |
164
0cbdf3c9bde1
(svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents:
116
diff
changeset
|
248 |
InitializeVehiclesGuiList(); |
0 | 249 |
InitializeTrains(); |
1247 | 250 |
InitializeNPF(); |
0 | 251 |
|
252 |
InitializePlayers(); |
|
253 |
InitializeCheats(); |
|
254 |
||
255 |
InitTextEffects(); |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
256 |
InitTextMessage(); |
0 | 257 |
InitializeAnimatedTiles(); |
258 |
||
259 |
InitializeLandscapeVariables(false); |
|
260 |
||
261 |
ResetObjectToPlace(); |
|
262 |
} |
|
263 |
||
1218 | 264 |
void GenerateWorld(int mode, uint log_x, uint log_y) |
0 | 265 |
{ |
266 |
int i; |
|
267 |
||
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
268 |
// Make sure everything is done via OWNER_NONE |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
269 |
_current_player = OWNER_NONE; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
270 |
|
0 | 271 |
_generating_world = true; |
1218 | 272 |
InitializeGame(log_x, log_y); |
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
273 |
SetObjectToPlace(SPR_CURSOR_ZZZ, 0, 0, 0); |
0 | 274 |
|
275 |
// Must start economy early because of the costs. |
|
276 |
StartupEconomy(); |
|
277 |
||
278 |
// Don't generate landscape items when in the scenario editor. |
|
279 |
if (mode == 1) { |
|
280 |
// empty world in scenario editor |
|
281 |
ConvertGroundTilesIntoWaterTiles(); |
|
282 |
} else { |
|
283 |
GenerateLandscape(); |
|
284 |
GenerateClearTile(); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
285 |
|
0 | 286 |
// only generate towns, tree and industries in newgame mode. |
287 |
if (mode == 0) { |
|
288 |
GenerateTowns(); |
|
289 |
GenerateTrees(); |
|
290 |
GenerateIndustries(); |
|
291 |
GenerateUnmovables(); |
|
292 |
} |
|
293 |
} |
|
294 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
295 |
// These are probably pointless when inside the scenario editor. |
0 | 296 |
StartupPlayers(); |
297 |
StartupEngines(); |
|
298 |
StartupDisasters(); |
|
299 |
_generating_world = false; |
|
300 |
||
301 |
// No need to run the tile loop in the scenario editor. |
|
302 |
if (mode != 1) { |
|
303 |
for(i=0x500; i!=0; i--) |
|
304 |
RunTileLoop(); |
|
305 |
} |
|
306 |
||
307 |
ResetObjectToPlace(); |
|
308 |
} |
|
309 |
||
310 |
void DeleteName(StringID id) |
|
311 |
{ |
|
312 |
if ((id & 0xF800) == 0x7800) { |
|
313 |
memset(_name_array[id & 0x1FF], 0, sizeof(_name_array[id & 0x1FF])); |
|
314 |
} |
|
315 |
} |
|
316 |
||
1328
eacd8225ed42
(svn r1832) Next byte -> char iteration: custom names
tron
parents:
1313
diff
changeset
|
317 |
char *GetName(int id, char *buff) |
0 | 318 |
{ |
1375
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
319 |
if (id & 0x400) GetParamInt32(); |
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
320 |
if (id & 0x200) GetParamUint16(); |
0 | 321 |
|
1375
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
322 |
return strecpy(buff, _name_array[id & ~0x600], NULL); |
0 | 323 |
} |
324 |
||
325 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
326 |
static void InitializeCheats(void) |
0 | 327 |
{ |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
328 |
memset(&_cheats, 0, sizeof(Cheats)); |
0 | 329 |
} |
330 |
||
331 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
332 |
static void InitializeNameMgr(void) |
0 | 333 |
{ |
334 |
memset(_name_array, 0, sizeof(_name_array)); |
|
335 |
} |
|
336 |
||
1328
eacd8225ed42
(svn r1832) Next byte -> char iteration: custom names
tron
parents:
1313
diff
changeset
|
337 |
StringID RealAllocateName(const char *name, byte skip, bool check_double) |
0 | 338 |
{ |
1375
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
339 |
char (*free_item)[lengthof(*_name_array)] = NULL; |
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
340 |
char (*i)[lengthof(*_name_array)]; |
0 | 341 |
|
1375
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
342 |
for (i = _name_array; i != endof(_name_array); ++i) { |
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
343 |
if ((*i)[0] == '\0') { |
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
344 |
if (free_item == NULL) free_item = i; |
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
345 |
} else if (check_double && strncmp(*i, name, lengthof(*i) - 1) == 0) { |
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
346 |
_error_message = STR_0132_CHOSEN_NAME_IN_USE_ALREADY; |
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
347 |
return 0; |
0 | 348 |
} |
349 |
} |
|
350 |
||
1375
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
351 |
if (free_item != NULL) { |
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
352 |
ttd_strlcpy(*free_item, name, lengthof(*free_item)); |
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
353 |
return (free_item - _name_array) | 0x7800 | (skip << 8); |
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
354 |
} else { |
0 | 355 |
_error_message = STR_0131_TOO_MANY_NAMES_DEFINED; |
356 |
return 0; |
|
357 |
} |
|
358 |
} |
|
359 |
||
360 |
||
361 |
#define M(a,b) ((a<<5)|b) |
|
362 |
static const uint16 _month_date_from_year_day[] = { |
|
363 |
M(0,1),M(0,2),M(0,3),M(0,4),M(0,5),M(0,6),M(0,7),M(0,8),M(0,9),M(0,10),M(0,11),M(0,12),M(0,13),M(0,14),M(0,15),M(0,16),M(0,17),M(0,18),M(0,19),M(0,20),M(0,21),M(0,22),M(0,23),M(0,24),M(0,25),M(0,26),M(0,27),M(0,28),M(0,29),M(0,30),M(0,31), |
|
364 |
M(1,1),M(1,2),M(1,3),M(1,4),M(1,5),M(1,6),M(1,7),M(1,8),M(1,9),M(1,10),M(1,11),M(1,12),M(1,13),M(1,14),M(1,15),M(1,16),M(1,17),M(1,18),M(1,19),M(1,20),M(1,21),M(1,22),M(1,23),M(1,24),M(1,25),M(1,26),M(1,27),M(1,28),M(1,29), |
|
365 |
M(2,1),M(2,2),M(2,3),M(2,4),M(2,5),M(2,6),M(2,7),M(2,8),M(2,9),M(2,10),M(2,11),M(2,12),M(2,13),M(2,14),M(2,15),M(2,16),M(2,17),M(2,18),M(2,19),M(2,20),M(2,21),M(2,22),M(2,23),M(2,24),M(2,25),M(2,26),M(2,27),M(2,28),M(2,29),M(2,30),M(2,31), |
|
366 |
M(3,1),M(3,2),M(3,3),M(3,4),M(3,5),M(3,6),M(3,7),M(3,8),M(3,9),M(3,10),M(3,11),M(3,12),M(3,13),M(3,14),M(3,15),M(3,16),M(3,17),M(3,18),M(3,19),M(3,20),M(3,21),M(3,22),M(3,23),M(3,24),M(3,25),M(3,26),M(3,27),M(3,28),M(3,29),M(3,30), |
|
367 |
M(4,1),M(4,2),M(4,3),M(4,4),M(4,5),M(4,6),M(4,7),M(4,8),M(4,9),M(4,10),M(4,11),M(4,12),M(4,13),M(4,14),M(4,15),M(4,16),M(4,17),M(4,18),M(4,19),M(4,20),M(4,21),M(4,22),M(4,23),M(4,24),M(4,25),M(4,26),M(4,27),M(4,28),M(4,29),M(4,30),M(4,31), |
|
368 |
M(5,1),M(5,2),M(5,3),M(5,4),M(5,5),M(5,6),M(5,7),M(5,8),M(5,9),M(5,10),M(5,11),M(5,12),M(5,13),M(5,14),M(5,15),M(5,16),M(5,17),M(5,18),M(5,19),M(5,20),M(5,21),M(5,22),M(5,23),M(5,24),M(5,25),M(5,26),M(5,27),M(5,28),M(5,29),M(5,30), |
|
369 |
M(6,1),M(6,2),M(6,3),M(6,4),M(6,5),M(6,6),M(6,7),M(6,8),M(6,9),M(6,10),M(6,11),M(6,12),M(6,13),M(6,14),M(6,15),M(6,16),M(6,17),M(6,18),M(6,19),M(6,20),M(6,21),M(6,22),M(6,23),M(6,24),M(6,25),M(6,26),M(6,27),M(6,28),M(6,29),M(6,30),M(6,31), |
|
370 |
M(7,1),M(7,2),M(7,3),M(7,4),M(7,5),M(7,6),M(7,7),M(7,8),M(7,9),M(7,10),M(7,11),M(7,12),M(7,13),M(7,14),M(7,15),M(7,16),M(7,17),M(7,18),M(7,19),M(7,20),M(7,21),M(7,22),M(7,23),M(7,24),M(7,25),M(7,26),M(7,27),M(7,28),M(7,29),M(7,30),M(7,31), |
|
371 |
M(8,1),M(8,2),M(8,3),M(8,4),M(8,5),M(8,6),M(8,7),M(8,8),M(8,9),M(8,10),M(8,11),M(8,12),M(8,13),M(8,14),M(8,15),M(8,16),M(8,17),M(8,18),M(8,19),M(8,20),M(8,21),M(8,22),M(8,23),M(8,24),M(8,25),M(8,26),M(8,27),M(8,28),M(8,29),M(8,30), |
|
372 |
M(9,1),M(9,2),M(9,3),M(9,4),M(9,5),M(9,6),M(9,7),M(9,8),M(9,9),M(9,10),M(9,11),M(9,12),M(9,13),M(9,14),M(9,15),M(9,16),M(9,17),M(9,18),M(9,19),M(9,20),M(9,21),M(9,22),M(9,23),M(9,24),M(9,25),M(9,26),M(9,27),M(9,28),M(9,29),M(9,30),M(9,31), |
|
373 |
M(10,1),M(10,2),M(10,3),M(10,4),M(10,5),M(10,6),M(10,7),M(10,8),M(10,9),M(10,10),M(10,11),M(10,12),M(10,13),M(10,14),M(10,15),M(10,16),M(10,17),M(10,18),M(10,19),M(10,20),M(10,21),M(10,22),M(10,23),M(10,24),M(10,25),M(10,26),M(10,27),M(10,28),M(10,29),M(10,30), |
|
374 |
M(11,1),M(11,2),M(11,3),M(11,4),M(11,5),M(11,6),M(11,7),M(11,8),M(11,9),M(11,10),M(11,11),M(11,12),M(11,13),M(11,14),M(11,15),M(11,16),M(11,17),M(11,18),M(11,19),M(11,20),M(11,21),M(11,22),M(11,23),M(11,24),M(11,25),M(11,26),M(11,27),M(11,28),M(11,29),M(11,30),M(11,31), |
|
375 |
}; |
|
376 |
#undef M |
|
377 |
||
378 |
enum { |
|
379 |
ACCUM_JAN = 0, |
|
380 |
ACCUM_FEB = ACCUM_JAN + 31, |
|
381 |
ACCUM_MAR = ACCUM_FEB + 29, |
|
382 |
ACCUM_APR = ACCUM_MAR + 31, |
|
383 |
ACCUM_MAY = ACCUM_APR + 30, |
|
384 |
ACCUM_JUN = ACCUM_MAY + 31, |
|
385 |
ACCUM_JUL = ACCUM_JUN + 30, |
|
386 |
ACCUM_AUG = ACCUM_JUL + 31, |
|
387 |
ACCUM_SEP = ACCUM_AUG + 31, |
|
388 |
ACCUM_OCT = ACCUM_SEP + 30, |
|
389 |
ACCUM_NOV = ACCUM_OCT + 31, |
|
390 |
ACCUM_DEC = ACCUM_NOV + 30, |
|
391 |
}; |
|
392 |
||
393 |
static const uint16 _accum_days_for_month[] = { |
|
394 |
ACCUM_JAN,ACCUM_FEB,ACCUM_MAR,ACCUM_APR, |
|
395 |
ACCUM_MAY,ACCUM_JUN,ACCUM_JUL,ACCUM_AUG, |
|
396 |
ACCUM_SEP,ACCUM_OCT,ACCUM_NOV,ACCUM_DEC, |
|
397 |
}; |
|
398 |
||
399 |
||
400 |
void ConvertDayToYMD(YearMonthDay *ymd, uint16 date) |
|
401 |
{ |
|
402 |
uint yr = date / (365+365+365+366); |
|
403 |
uint rem = date % (365+365+365+366); |
|
404 |
uint x; |
|
405 |
||
406 |
yr *= 4; |
|
407 |
||
408 |
if (rem >= 366) { |
|
409 |
rem--; |
|
410 |
do { |
|
411 |
rem -= 365; |
|
412 |
yr++; |
|
413 |
} while (rem >= 365); |
|
414 |
if (rem >= 31+28) rem++; |
|
415 |
} |
|
416 |
||
417 |
ymd->year = yr; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
418 |
|
0 | 419 |
x = _month_date_from_year_day[rem]; |
420 |
ymd->month = x >> 5; |
|
421 |
ymd->day = x & 0x1F; |
|
422 |
} |
|
423 |
||
424 |
// year is a number between 0..? |
|
425 |
// month is a number between 0..11 |
|
426 |
// day is a number between 1..31 |
|
427 |
uint ConvertYMDToDay(uint year, uint month, uint day) |
|
428 |
{ |
|
429 |
uint rem; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
430 |
|
0 | 431 |
// day in the year |
432 |
rem = _accum_days_for_month[month] + day - 1; |
|
433 |
||
434 |
// remove feb 29 from year 1,2,3 |
|
435 |
if (year & 3) rem += (year & 3) * 365 + (rem < 31+29); |
|
436 |
||
437 |
// base date. |
|
438 |
return (year >> 2) * (365+365+365+366) + rem; |
|
439 |
} |
|
440 |
||
441 |
// convert a date on the form |
|
970
24abd02b1092
(svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents:
959
diff
changeset
|
442 |
// 1920 - 2090 (MAX_YEAR_END_REAL) |
0 | 443 |
// 192001 - 209012 |
444 |
// 19200101 - 20901231 |
|
445 |
// or if > 2090 and below 65536, treat it as a daycount |
|
446 |
// returns -1 if no conversion was possible |
|
447 |
uint ConvertIntDate(uint date) |
|
448 |
{ |
|
449 |
uint year, month = 0, day = 1; |
|
450 |
||
970
24abd02b1092
(svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents:
959
diff
changeset
|
451 |
if (IS_INT_INSIDE(date, 1920, MAX_YEAR_END_REAL + 1)) { |
0 | 452 |
year = date - 1920; |
453 |
} else if (IS_INT_INSIDE(date, 192001, 209012+1)) { |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
454 |
month = date % 100 - 1; |
0 | 455 |
year = date / 100 - 1920; |
456 |
} else if (IS_INT_INSIDE(date, 19200101, 20901231+1)) { |
|
457 |
day = date % 100; date /= 100; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
458 |
month = date % 100 - 1; |
0 | 459 |
year = date / 100 - 1920; |
460 |
} else if (IS_INT_INSIDE(date, 2091, 65536)) |
|
461 |
return date; |
|
462 |
else |
|
463 |
return (uint)-1; |
|
464 |
||
465 |
// invalid ranges? |
|
466 |
if (month >= 12 || !IS_INT_INSIDE(day, 1, 31+1)) return (uint)-1; |
|
467 |
||
468 |
return ConvertYMDToDay(year, month, day); |
|
469 |
} |
|
470 |
||
471 |
typedef struct LandscapePredefVar { |
|
472 |
StringID names[NUM_CARGO]; |
|
473 |
byte weights[NUM_CARGO]; |
|
474 |
StringID sprites[NUM_CARGO]; |
|
475 |
||
476 |
uint16 initial_cargo_payment[NUM_CARGO]; |
|
477 |
byte transit_days_table_1[NUM_CARGO]; |
|
478 |
byte transit_days_table_2[NUM_CARGO]; |
|
479 |
||
480 |
byte railwagon_by_cargo[3][NUM_CARGO]; |
|
481 |
||
482 |
byte road_veh_by_cargo_start[NUM_CARGO]; |
|
483 |
byte road_veh_by_cargo_count[NUM_CARGO]; |
|
484 |
} LandscapePredefVar; |
|
485 |
||
486 |
#include "table/landscape_const.h" |
|
487 |
||
488 |
||
489 |
// Calculate constants that depend on the landscape type. |
|
490 |
void InitializeLandscapeVariables(bool only_constants) |
|
491 |
{ |
|
492 |
const LandscapePredefVar *lpd; |
|
493 |
int i; |
|
494 |
StringID str; |
|
495 |
||
496 |
lpd = &_landscape_predef_var[_opt.landscape]; |
|
497 |
||
498 |
memcpy(_cargoc.ai_railwagon, lpd->railwagon_by_cargo, sizeof(lpd->railwagon_by_cargo)); |
|
499 |
memcpy(_cargoc.ai_roadveh_start, lpd->road_veh_by_cargo_start,sizeof(lpd->road_veh_by_cargo_start)); |
|
500 |
memcpy(_cargoc.ai_roadveh_count, lpd->road_veh_by_cargo_count,sizeof(lpd->road_veh_by_cargo_count)); |
|
501 |
||
502 |
for(i=0; i!=NUM_CARGO; i++) { |
|
503 |
_cargoc.sprites[i] = lpd->sprites[i]; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
504 |
|
0 | 505 |
str = lpd->names[i]; |
506 |
_cargoc.names_s[i] = str; |
|
507 |
_cargoc.names_p[i] = (str += 0x20); |
|
508 |
_cargoc.names_long_s[i] = (str += 0x20); |
|
509 |
_cargoc.names_long_p[i] = (str += 0x20); |
|
510 |
_cargoc.names_short[i] = (str += 0x20); |
|
511 |
_cargoc.weights[i] = lpd->weights[i]; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
512 |
|
0 | 513 |
if (!only_constants) { |
514 |
_cargo_payment_rates[i] = lpd->initial_cargo_payment[i]; |
|
515 |
_cargo_payment_rates_frac[i] = 0; |
|
516 |
} |
|
517 |
||
518 |
_cargoc.transit_days_1[i] = lpd->transit_days_table_1[i]; |
|
519 |
_cargoc.transit_days_2[i] = lpd->transit_days_table_2[i]; |
|
520 |
} |
|
521 |
} |
|
522 |
||
523 |
||
524 |
void OnNewDay_Train(Vehicle *v); |
|
525 |
void OnNewDay_RoadVeh(Vehicle *v); |
|
526 |
void OnNewDay_Aircraft(Vehicle *v); |
|
527 |
void OnNewDay_Ship(Vehicle *v); |
|
1095 | 528 |
static void OnNewDay_EffectVehicle(Vehicle *v) { /* empty */ } |
0 | 529 |
void OnNewDay_DisasterVehicle(Vehicle *v); |
530 |
||
531 |
typedef void OnNewVehicleDayProc(Vehicle *v); |
|
532 |
||
533 |
static OnNewVehicleDayProc * _on_new_vehicle_day_proc[] = { |
|
534 |
OnNewDay_Train, |
|
535 |
OnNewDay_RoadVeh, |
|
536 |
OnNewDay_Ship, |
|
537 |
OnNewDay_Aircraft, |
|
538 |
OnNewDay_EffectVehicle, |
|
539 |
OnNewDay_DisasterVehicle, |
|
540 |
}; |
|
541 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
542 |
void EnginesDailyLoop(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
543 |
void DisasterDailyLoop(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
544 |
void PlayersMonthlyLoop(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
545 |
void EnginesMonthlyLoop(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
546 |
void TownsMonthlyLoop(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
547 |
void IndustryMonthlyLoop(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
548 |
void StationMonthlyLoop(void); |
0 | 549 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
550 |
void PlayersYearlyLoop(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
551 |
void TrainsYearlyLoop(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
552 |
void RoadVehiclesYearlyLoop(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
553 |
void AircraftYearlyLoop(void); |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
554 |
void ShipsYearlyLoop(void); |
0 | 555 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
556 |
void WaypointsDailyLoop(void); |
0 | 557 |
|
558 |
||
559 |
static const uint16 _autosave_months[] = { |
|
560 |
0, // never |
|
561 |
0xFFF, // every month |
|
562 |
0x249, // every 3 months |
|
563 |
0x041, // every 6 months |
|
564 |
0x001, // every 12 months |
|
565 |
}; |
|
566 |
||
1537
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
567 |
/** |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
568 |
* Runs the day_proc of 'amount' vehicles. |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
569 |
*/ |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
570 |
static void RunVehicleDayProc(uint amount) |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
571 |
{ |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
572 |
Vehicle *v; |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
573 |
VehicleID ctr; |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
574 |
uint i; |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
575 |
|
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
576 |
ctr = _vehicle_id_ctr_day; |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
577 |
|
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
578 |
/* If the CTR is already over the size of the pool, don't even run the for-loop */ |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
579 |
if (ctr >= GetVehiclePoolSize()) { |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
580 |
_vehicle_id_ctr_day += amount; |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
581 |
return; |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
582 |
} |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
583 |
|
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
584 |
for (i = 0; i < amount; i++, ctr++) { |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
585 |
/* Skip non-existing vehicles */ |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
586 |
if (ctr >= GetVehiclePoolSize()) { |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
587 |
_vehicle_id_ctr_day += amount; |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
588 |
return; |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
589 |
} |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
590 |
|
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
591 |
v = GetVehicle(ctr); |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
592 |
if (v->type != 0) |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
593 |
_on_new_vehicle_day_proc[v->type - 0x10](v); |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
594 |
} |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
595 |
|
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
596 |
_vehicle_id_ctr_day = ctr; |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
597 |
} |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
598 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
599 |
void IncreaseDate(void) |
0 | 600 |
{ |
1537
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
601 |
uint32 total_vehicles = (1 << _vehicle_pool.block_size_bits) * _vehicle_pool.max_blocks; |
0 | 602 |
YearMonthDay ymd; |
603 |
||
604 |
if (_game_mode == GM_MENU) { |
|
605 |
_tick_counter++; |
|
606 |
return; |
|
607 |
} |
|
608 |
||
1537
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
609 |
RunVehicleDayProc(total_vehicles / DAY_TICKS); |
0 | 610 |
|
611 |
/* increase day, and check if a new day is there? */ |
|
612 |
_tick_counter++; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
613 |
|
1537
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
614 |
_date_fract++; |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
615 |
if (_date_fract < DAY_TICKS) |
0 | 616 |
return; |
1537
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
617 |
_date_fract = 0; |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
618 |
|
0 | 619 |
/* yeah, increse day counter and call various daily loops */ |
620 |
_date++; |
|
621 |
||
1537
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
622 |
/* We have a hole because of rounding errors, between the last vehicle checked and the max amount |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
623 |
* of vehicles.. correct for that problem here */ |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
624 |
RunVehicleDayProc(total_vehicles - _vehicle_id_ctr_day); |
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
625 |
|
517b9b9cfaa0
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
626 |
assert(_vehicle_id_ctr_day == total_vehicles); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
627 |
_vehicle_id_ctr_day = 0; |
105 | 628 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
629 |
TextMessageDailyLoop(); |
0 | 630 |
|
631 |
DisasterDailyLoop(); |
|
395
788a9bba0889
(svn r587) -newgrf: Rename all /Checkpoint/i tokens to 'Waypoint's. The name actually makes some sense and is also compatible with TTDPatch (pasky).
darkvater
parents:
387
diff
changeset
|
632 |
WaypointsDailyLoop(); |
0 | 633 |
|
634 |
if (_game_mode != GM_MENU) { |
|
635 |
InvalidateWindowWidget(WC_STATUS_BAR, 0, 0); |
|
636 |
EnginesDailyLoop(); |
|
637 |
} |
|
638 |
||
639 |
/* check if we entered a new month? */ |
|
640 |
ConvertDayToYMD(&ymd, _date); |
|
641 |
if ((byte)ymd.month == _cur_month) |
|
642 |
return; |
|
643 |
_cur_month = ymd.month; |
|
644 |
||
645 |
/* yes, call various monthly loops */ |
|
646 |
if (_game_mode != GM_MENU) { |
|
647 |
if (HASBIT(_autosave_months[_opt.autosave], _cur_month)) { |
|
648 |
_do_autosave = true; |
|
649 |
RedrawAutosave(); |
|
650 |
} |
|
651 |
||
652 |
PlayersMonthlyLoop(); |
|
653 |
EnginesMonthlyLoop(); |
|
654 |
TownsMonthlyLoop(); |
|
655 |
IndustryMonthlyLoop(); |
|
656 |
StationMonthlyLoop(); |
|
690
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
657 |
#ifdef ENABLE_NETWORK |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
658 |
if (_network_server) |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
659 |
NetworkServerMonthlyLoop(); |
3afcad69d4f7
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
660 |
#endif /* ENABLE_NETWORK */ |
0 | 661 |
} |
662 |
||
663 |
/* check if we entered a new year? */ |
|
664 |
if ((byte)ymd.year == _cur_year) |
|
665 |
return; |
|
666 |
_cur_year = ymd.year; |
|
667 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
668 |
/* yes, call various yearly loops */ |
0 | 669 |
|
670 |
PlayersYearlyLoop(); |
|
671 |
TrainsYearlyLoop(); |
|
672 |
RoadVehiclesYearlyLoop(); |
|
673 |
AircraftYearlyLoop(); |
|
674 |
ShipsYearlyLoop(); |
|
785
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
770
diff
changeset
|
675 |
#ifdef ENABLE_NETWORK |
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
770
diff
changeset
|
676 |
if (_network_server) |
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
770
diff
changeset
|
677 |
NetworkServerYearlyLoop(); |
bba7b3b35dec
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
770
diff
changeset
|
678 |
#endif /* ENABLE_NETWORK */ |
0 | 679 |
|
998
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
988
diff
changeset
|
680 |
/* check if we reached end of the game (31 dec 2050) */ |
c90459c24842
(svn r1496) -Fix: highscore no longer crashes in network games with a dedicated server. At the end of the game (can only be set by the server) the highscore is shown for the top5 companies of that game
darkvater
parents:
988
diff
changeset
|
681 |
if (_cur_year == _patches.ending_date - MAX_YEAR_BEGIN_REAL) { |
983
4765bf636f6b
(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:
970
diff
changeset
|
682 |
ShowEndGameChart(); |
970
24abd02b1092
(svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents:
959
diff
changeset
|
683 |
/* check if we reached 2090 (MAX_YEAR_END_REAL), that's the maximum year. */ |
983
4765bf636f6b
(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:
970
diff
changeset
|
684 |
} else if (_cur_year == (MAX_YEAR_END + 1)) { |
286
b22e852634e4
(svn r292) -Fix: [1030275] 'Service at' orders ignored after 2090. After 2090 year is reset to 1. Jan 2090, so most of the time, last service was in the future and no service ensured.
darkvater
parents:
271
diff
changeset
|
685 |
Vehicle *v; |
970
24abd02b1092
(svn r1465) -Fix: [1099101] starting year patch goes out of range. Clamped year between 1920-2090 as wel as adding defines for it.
darkvater
parents:
959
diff
changeset
|
686 |
_cur_year = MAX_YEAR_END; |
0 | 687 |
_date = 62093; |
286
b22e852634e4
(svn r292) -Fix: [1030275] 'Service at' orders ignored after 2090. After 2090 year is reset to 1. Jan 2090, so most of the time, last service was in the future and no service ensured.
darkvater
parents:
271
diff
changeset
|
688 |
FOR_ALL_VEHICLES(v) { |
b22e852634e4
(svn r292) -Fix: [1030275] 'Service at' orders ignored after 2090. After 2090 year is reset to 1. Jan 2090, so most of the time, last service was in the future and no service ensured.
darkvater
parents:
271
diff
changeset
|
689 |
v->date_of_last_service -= 365; // 1 year is 365 days long |
b22e852634e4
(svn r292) -Fix: [1030275] 'Service at' orders ignored after 2090. After 2090 year is reset to 1. Jan 2090, so most of the time, last service was in the future and no service ensured.
darkvater
parents:
271
diff
changeset
|
690 |
} |
1595
fda318dddab5
(svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents:
1542
diff
changeset
|
691 |
|
fda318dddab5
(svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents:
1542
diff
changeset
|
692 |
/* Because the _date wraps here, and text-messages expire by game-days, we have to clean out |
fda318dddab5
(svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents:
1542
diff
changeset
|
693 |
* all of them if the date is set back, else those messages will hang for ever */ |
fda318dddab5
(svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents:
1542
diff
changeset
|
694 |
InitTextMessage(); |
0 | 695 |
} |
696 |
||
697 |
if (_patches.auto_euro) |
|
698 |
CheckSwitchToEuro(); |
|
699 |
||
700 |
/* XXX: check if year 2050 was reached */ |
|
701 |
} |
|
702 |
||
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
703 |
int FindFirstBit(uint32 value) |
0 | 704 |
{ |
826 | 705 |
// This is much faster than the one that was before here. |
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
706 |
// Created by Darkvater.. blame him if it is wrong ;) |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
707 |
// Btw, the macro FINDFIRSTBIT is better to use when your value is |
826 | 708 |
// not more than 128. |
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
709 |
byte i = 0; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
710 |
if (value & 0xffff0000) { value >>= 16; i += 16; } |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
711 |
if (value & 0x0000ff00) { value >>= 8; i += 8; } |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
712 |
if (value & 0x000000f0) { value >>= 4; i += 4; } |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
713 |
if (value & 0x0000000c) { value >>= 2; i += 2; } |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
714 |
if (value & 0x00000002) { i += 1; } |
0 | 715 |
return i; |
716 |
} |
|
717 |
||
1217
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
718 |
//!We're writing an own sort algorithm here, as |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
719 |
//!qsort isn't stable |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
720 |
//!Since the number of elements will be low, a |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
721 |
//!simple bubble sort will have to do :) |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
722 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
723 |
void bubblesort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)) |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
724 |
{ |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
725 |
uint i,k; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
726 |
void *buffer = malloc(size); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
727 |
char *start = base; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
728 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
729 |
nmemb--; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
730 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
731 |
for (i = 0; i < nmemb; i++) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
732 |
for (k = 0; k < nmemb; k++) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
733 |
void *a, *b; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
734 |
a = start + size * k; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
735 |
b = start + size * (k + 1); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
736 |
if (compar(a, b) > 0) { |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
737 |
memcpy(buffer, a, size); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
738 |
memcpy(a, b, size); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
739 |
memcpy(b, buffer, size); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
740 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
741 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
742 |
} |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
743 |
|
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
744 |
free(buffer); |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
745 |
buffer = NULL; |
59c024cfaf54
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
746 |
} |
0 | 747 |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
748 |
static void Save_NAME(void) |
0 | 749 |
{ |
750 |
int i; |
|
751 |
||
1375
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
752 |
for (i = 0; i != lengthof(_name_array); ++i) { |
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
753 |
if (_name_array[i][0] != '\0') { |
0 | 754 |
SlSetArrayIndex(i); |
1375
00a24560f025
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
755 |
SlArray(_name_array[i], strlen(_name_array[i]), SLE_UINT8); |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
756 |
} |
0 | 757 |
} |
758 |
} |
|
759 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
760 |
static void Load_NAME(void) |
0 | 761 |
{ |
762 |
int index; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
763 |
|
0 | 764 |
while ((index = SlIterateArray()) != -1) { |
765 |
SlArray(_name_array[index],SlGetFieldLength(),SLE_UINT8); |
|
766 |
} |
|
767 |
} |
|
768 |
||
1881
435d39bd6ee0
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1812
diff
changeset
|
769 |
static const SaveLoad _game_opt_desc[] = { |
0 | 770 |
// added a new difficulty option (town attitude) in version 4 |
771 |
SLE_CONDARR(GameOptions,diff, SLE_FILE_I16 | SLE_VAR_I32, 17, 0, 3), |
|
772 |
SLE_CONDARR(GameOptions,diff, SLE_FILE_I16 | SLE_VAR_I32, 18, 4, 255), |
|
773 |
SLE_VAR(GameOptions,diff_level, SLE_UINT8), |
|
774 |
SLE_VAR(GameOptions,currency, SLE_UINT8), |
|
775 |
SLE_VAR(GameOptions,kilometers, SLE_UINT8), |
|
776 |
SLE_VAR(GameOptions,town_name, SLE_UINT8), |
|
777 |
SLE_VAR(GameOptions,landscape, SLE_UINT8), |
|
778 |
SLE_VAR(GameOptions,snow_line, SLE_UINT8), |
|
779 |
SLE_VAR(GameOptions,autosave, SLE_UINT8), |
|
780 |
SLE_VAR(GameOptions,road_side, SLE_UINT8), |
|
781 |
SLE_END() |
|
782 |
}; |
|
783 |
||
784 |
// Save load game options |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
785 |
static void SaveLoad_OPTS(void) |
0 | 786 |
{ |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
787 |
SlObject(&_opt, _game_opt_desc); |
0 | 788 |
} |
789 |
||
790 |
||
791 |
static const SaveLoadGlobVarList _date_desc[] = { |
|
792 |
{&_date, SLE_UINT16, 0, 255}, |
|
793 |
{&_date_fract, SLE_UINT16, 0, 255}, |
|
794 |
{&_tick_counter, SLE_UINT16, 0, 255}, |
|
795 |
{&_vehicle_id_ctr_day, SLE_UINT16, 0, 255}, |
|
796 |
{&_age_cargo_skip_counter, SLE_UINT8, 0, 255}, |
|
797 |
{&_avail_aircraft, SLE_UINT8, 0, 255}, |
|
1175
a4bdf4c26d32
(svn r1677) Forgot to change the save/load size for 3 variables
tron
parents:
1121
diff
changeset
|
798 |
{&_cur_tileloop_tile, SLE_FILE_U16 | SLE_VAR_U32, 0, 5}, |
a4bdf4c26d32
(svn r1677) Forgot to change the save/load size for 3 variables
tron
parents:
1121
diff
changeset
|
799 |
{&_cur_tileloop_tile, SLE_UINT32, 6, 255}, |
0 | 800 |
{&_disaster_delay, SLE_UINT16, 0, 255}, |
801 |
{&_station_tick_ctr, SLE_UINT16, 0, 255}, |
|
206 | 802 |
{&_random_seeds[0][0], SLE_UINT32, 0, 255}, |
803 |
{&_random_seeds[0][1], SLE_UINT32, 0, 255}, |
|
1526
2b5571c8c32f
(svn r2030) -Fix: Save _cur_town_ctr with all its bits to prevent desyncs
celestar
parents:
1517
diff
changeset
|
804 |
{&_cur_town_ctr, SLE_FILE_U8 | SLE_VAR_U32, 0, 9}, |
2b5571c8c32f
(svn r2030) -Fix: Save _cur_town_ctr with all its bits to prevent desyncs
celestar
parents:
1517
diff
changeset
|
805 |
{&_cur_town_ctr, SLE_UINT32, 10, 255}, |
0 | 806 |
{&_cur_player_tick_index, SLE_FILE_U8 | SLE_VAR_UINT, 0, 255}, |
807 |
{&_next_competitor_start, SLE_FILE_U16 | SLE_VAR_UINT, 0, 255}, |
|
808 |
{&_trees_tick_ctr, SLE_UINT8, 0, 255}, |
|
809 |
{&_pause, SLE_UINT8, 4, 255}, |
|
1529
3a8196d15b01
(svn r2033) - Fix: Fix some more desync by saving the town growth frequency iterator _cur_town_iter. Needed to bump a svg revision for that thanks to the braindead SlGlob thing, or at least I don't know how to do it without bumping it.
pasky
parents:
1526
diff
changeset
|
810 |
{&_cur_town_iter, SLE_UINT32, 11, 255}, |
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
811 |
{NULL, 0, 0, 0} |
0 | 812 |
}; |
813 |
||
814 |
// Save load date related variables as well as persistent tick counters |
|
815 |
// XXX: currently some unrelated stuff is just put here |
|
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
816 |
static void SaveLoad_DATE(void) |
0 | 817 |
{ |
818 |
SlGlobList(_date_desc); |
|
819 |
} |
|
820 |
||
821 |
||
822 |
static const SaveLoadGlobVarList _view_desc[] = { |
|
1175
a4bdf4c26d32
(svn r1677) Forgot to change the save/load size for 3 variables
tron
parents:
1121
diff
changeset
|
823 |
{&_saved_scrollpos_x, SLE_FILE_I16 | SLE_VAR_INT, 0, 5}, |
a4bdf4c26d32
(svn r1677) Forgot to change the save/load size for 3 variables
tron
parents:
1121
diff
changeset
|
824 |
{&_saved_scrollpos_x, SLE_INT32, 6, 255}, |
a4bdf4c26d32
(svn r1677) Forgot to change the save/load size for 3 variables
tron
parents:
1121
diff
changeset
|
825 |
{&_saved_scrollpos_y, SLE_FILE_I16 | SLE_VAR_INT, 0, 5}, |
a4bdf4c26d32
(svn r1677) Forgot to change the save/load size for 3 variables
tron
parents:
1121
diff
changeset
|
826 |
{&_saved_scrollpos_y, SLE_INT32, 6, 255}, |
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
827 |
{&_saved_scrollpos_zoom, SLE_UINT8, 0, 255}, |
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
828 |
{NULL, 0, 0, 0} |
0 | 829 |
}; |
830 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
831 |
static void SaveLoad_VIEW(void) |
0 | 832 |
{ |
833 |
SlGlobList(_view_desc); |
|
834 |
} |
|
835 |
||
1218 | 836 |
static uint32 _map_dim_x; |
837 |
static uint32 _map_dim_y; |
|
838 |
||
839 |
static const SaveLoadGlobVarList _map_dimensions[] = { |
|
840 |
{&_map_dim_x, SLE_UINT32, 6, 255}, |
|
841 |
{&_map_dim_y, SLE_UINT32, 6, 255}, |
|
842 |
{NULL, 0, 0, 0} |
|
843 |
}; |
|
844 |
||
845 |
static void Save_MAPSIZE(void) |
|
846 |
{ |
|
1219
1163c59b8650
(svn r1723) Save the map size in tiles, not number of bits
tron
parents:
1218
diff
changeset
|
847 |
_map_dim_x = MapSizeX(); |
1163c59b8650
(svn r1723) Save the map size in tiles, not number of bits
tron
parents:
1218
diff
changeset
|
848 |
_map_dim_y = MapSizeY(); |
1218 | 849 |
SlGlobList(_map_dimensions); |
850 |
} |
|
851 |
||
852 |
static void Load_MAPSIZE(void) |
|
853 |
{ |
|
1219
1163c59b8650
(svn r1723) Save the map size in tiles, not number of bits
tron
parents:
1218
diff
changeset
|
854 |
uint bits_x = 0; |
1163c59b8650
(svn r1723) Save the map size in tiles, not number of bits
tron
parents:
1218
diff
changeset
|
855 |
uint bits_y = 0; |
1163c59b8650
(svn r1723) Save the map size in tiles, not number of bits
tron
parents:
1218
diff
changeset
|
856 |
|
1218 | 857 |
SlGlobList(_map_dimensions); |
1219
1163c59b8650
(svn r1723) Save the map size in tiles, not number of bits
tron
parents:
1218
diff
changeset
|
858 |
|
1163c59b8650
(svn r1723) Save the map size in tiles, not number of bits
tron
parents:
1218
diff
changeset
|
859 |
for (; _map_dim_x > 1; _map_dim_x >>= 1) ++bits_x; |
1163c59b8650
(svn r1723) Save the map size in tiles, not number of bits
tron
parents:
1218
diff
changeset
|
860 |
for (; _map_dim_y > 1; _map_dim_y >>= 1) ++bits_y; |
1163c59b8650
(svn r1723) Save the map size in tiles, not number of bits
tron
parents:
1218
diff
changeset
|
861 |
|
1163c59b8650
(svn r1723) Save the map size in tiles, not number of bits
tron
parents:
1218
diff
changeset
|
862 |
InitMap(bits_x, bits_y); |
1218 | 863 |
} |
864 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
865 |
static void SaveLoad_MAPT(void) |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
866 |
{ |
695
5f5be150296f
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
690
diff
changeset
|
867 |
SlArray(_map_type_and_height, MapSize(), SLE_UINT8); |
0 | 868 |
} |
869 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
870 |
static void SaveLoad_MAP2(void) |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
871 |
{ |
817
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
785
diff
changeset
|
872 |
if (_sl.version < 5) { |
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
785
diff
changeset
|
873 |
/* In those versions the _map2 was 8 bits */ |
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
785
diff
changeset
|
874 |
SlArray(_map2, MapSize(), SLE_FILE_U8 | SLE_VAR_U16); |
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
785
diff
changeset
|
875 |
} else { |
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
785
diff
changeset
|
876 |
SlArray(_map2, MapSize(), SLE_UINT16); |
238bbdaa228b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
785
diff
changeset
|
877 |
} |
0 | 878 |
} |
879 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
880 |
static void SaveLoad_M3LO(void) |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
881 |
{ |
695
5f5be150296f
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
690
diff
changeset
|
882 |
SlArray(_map3_lo, MapSize(), SLE_UINT8); |
0 | 883 |
} |
884 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
885 |
static void SaveLoad_M3HI(void) |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
886 |
{ |
695
5f5be150296f
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
690
diff
changeset
|
887 |
SlArray(_map3_hi, MapSize(), SLE_UINT8); |
0 | 888 |
} |
889 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
890 |
static void SaveLoad_MAPO(void) |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
891 |
{ |
695
5f5be150296f
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
690
diff
changeset
|
892 |
SlArray(_map_owner, MapSize(), SLE_UINT8); |
0 | 893 |
} |
894 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
895 |
static void SaveLoad_MAP5(void) |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
896 |
{ |
695
5f5be150296f
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
690
diff
changeset
|
897 |
SlArray(_map5, MapSize(), SLE_UINT8); |
0 | 898 |
} |
899 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
900 |
static void SaveLoad_MAPE(void) |
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
901 |
{ |
695
5f5be150296f
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
690
diff
changeset
|
902 |
SlArray(_map_extra_bits, MapSize() / 4, SLE_UINT8); |
0 | 903 |
} |
904 |
||
905 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
906 |
static void Save_CHTS(void) |
0 | 907 |
{ |
908 |
byte count = sizeof(_cheats)/sizeof(Cheat); |
|
909 |
Cheat* cht = (Cheat*) &_cheats; |
|
910 |
Cheat* cht_last = &cht[count]; |
|
911 |
||
912 |
SlSetLength(count*2); |
|
913 |
for(; cht != cht_last; cht++) { |
|
914 |
SlWriteByte(cht->been_used); |
|
915 |
SlWriteByte(cht->value); |
|
916 |
} |
|
917 |
} |
|
918 |
||
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1024
diff
changeset
|
919 |
static void Load_CHTS(void) |
0 | 920 |
{ |
921 |
Cheat* cht = (Cheat*) &_cheats; |
|
922 |
||
923 |
uint count = SlGetFieldLength()/2; |
|
924 |
for(; count; count--, cht++) |
|
925 |
{ |
|
926 |
cht->been_used = (byte)SlReadByte(); |
|
927 |
cht->value = (byte)SlReadByte(); |
|
928 |
} |
|
929 |
} |
|
930 |
||
931 |
||
932 |
const ChunkHandler _misc_chunk_handlers[] = { |
|
1218 | 933 |
{ 'MAPS', Save_MAPSIZE, Load_MAPSIZE, CH_RIFF }, |
0 | 934 |
{ 'MAPT', SaveLoad_MAPT, SaveLoad_MAPT, CH_RIFF }, |
935 |
{ 'MAP2', SaveLoad_MAP2, SaveLoad_MAP2, CH_RIFF }, |
|
936 |
{ 'M3LO', SaveLoad_M3LO, SaveLoad_M3LO, CH_RIFF }, |
|
937 |
{ 'M3HI', SaveLoad_M3HI, SaveLoad_M3HI, CH_RIFF }, |
|
938 |
{ 'MAPO', SaveLoad_MAPO, SaveLoad_MAPO, CH_RIFF }, |
|
939 |
{ 'MAP5', SaveLoad_MAP5, SaveLoad_MAP5, CH_RIFF }, |
|
940 |
{ 'MAPE', SaveLoad_MAPE, SaveLoad_MAPE, CH_RIFF }, |
|
941 |
||
942 |
{ 'NAME', Save_NAME, Load_NAME, CH_ARRAY}, |
|
943 |
{ 'DATE', SaveLoad_DATE, SaveLoad_DATE, CH_RIFF}, |
|
944 |
{ 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, CH_RIFF}, |
|
945 |
{ 'OPTS', SaveLoad_OPTS, SaveLoad_OPTS, CH_RIFF}, |
|
946 |
{ 'CHTS', Save_CHTS, Load_CHTS, CH_RIFF | CH_LAST} |
|
947 |
}; |