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