author | tron |
Fri, 17 Dec 2004 09:01:24 +0000 | |
changeset 695 | 561b806c0477 |
parent 690 | 9f449a6b133e |
child 764 | 68b398e2b780 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
507
8aa8100b0b22
(svn r815) Include strings.h only in the files which need it.
tron
parents:
500
diff
changeset
|
3 |
#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
|
4 |
#include "map.h" |
0 | 5 |
#include "vehicle.h" |
6 |
#include "gfx.h" |
|
7 |
#include "assert.h" |
|
8 |
#include "saveload.h" |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
9 |
#include "network.h" |
690
9f449a6b133e
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
10 |
#include "network_data.h" |
9f449a6b133e
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
11 |
#include "network_server.h" |
0 | 12 |
|
13 |
extern void StartupEconomy(); |
|
14 |
extern void InitNewsItemStructs(); |
|
15 |
||
16 |
byte _name_array[512][32]; |
|
17 |
||
500
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
410
diff
changeset
|
18 |
static inline uint32 ROR(uint32 x, int n) |
0 | 19 |
{ |
20 |
return (x >> n) + (x << ((sizeof(x)*8)-n)); |
|
21 |
} |
|
22 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
23 |
/* 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
|
24 |
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
|
25 |
it completely! -- TrueLight */ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
26 |
#undef PLAYER_SEED_RANDOM |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
27 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
28 |
#ifdef RANDOM_DEBUG |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
29 |
#include "network_data.h" |
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 |
uint32 DoRandom(uint line, char *file) |
260
32fcaaf9f4ef
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
256
diff
changeset
|
32 |
#else |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
33 |
uint32 Random() |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
34 |
#endif |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
35 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
36 |
#ifdef RANDOM_DEBUG |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
37 |
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
|
38 |
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
|
39 |
#endif |
32fcaaf9f4ef
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
256
diff
changeset
|
40 |
|
32fcaaf9f4ef
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
256
diff
changeset
|
41 |
#ifdef PLAYER_SEED_RANDOM |
32fcaaf9f4ef
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
256
diff
changeset
|
42 |
if (_current_player>=MAX_PLAYERS || !_networking) { |
206 | 43 |
uint32 s = _random_seeds[0][0]; |
44 |
uint32 t = _random_seeds[0][1]; |
|
45 |
_random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7); |
|
46 |
return _random_seeds[0][1] = ROR(s, 3); |
|
47 |
} else { |
|
48 |
uint32 s = _player_seeds[_current_player][0]; |
|
49 |
uint32 t = _player_seeds[_current_player][1]; |
|
50 |
_player_seeds[_current_player][0] = s + ROR(t ^ 0x1234567F, 7); |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
51 |
DEBUG(net, 1)("[NET-Seeds] Player seed called!"); |
206 | 52 |
return _player_seeds[_current_player][1] = ROR(s, 3); |
53 |
} |
|
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
|
54 |
#else |
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
|
55 |
uint32 s = _random_seeds[0][0]; |
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
|
56 |
uint32 t = _random_seeds[0][1]; |
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
|
57 |
_random_seeds[0][0] = s + ROR(t ^ 0x1234567F, 7); |
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
|
58 |
return _random_seeds[0][1] = ROR(s, 3); |
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
|
59 |
#endif |
0 | 60 |
} |
61 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
62 |
#ifdef RANDOM_DEBUG |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
63 |
uint DoRandomRange(uint max, uint line, char *file) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
64 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
65 |
return (uint16)DoRandom(line, file) * max >> 16; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
66 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
67 |
#else |
0 | 68 |
uint RandomRange(uint max) |
69 |
{ |
|
70 |
return (uint16)Random() * max >> 16; |
|
71 |
} |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
72 |
#endif |
0 | 73 |
|
74 |
uint32 InteractiveRandom() |
|
75 |
{ |
|
206 | 76 |
uint32 t = _random_seeds[1][1]; |
77 |
uint32 s = _random_seeds[1][0]; |
|
78 |
_random_seeds[1][0] = s + ROR(t ^ 0x1234567F, 7); |
|
79 |
return _random_seeds[1][1] = ROR(s, 3); |
|
80 |
} |
|
81 |
||
239 | 82 |
uint InteractiveRandomRange(uint max) |
83 |
{ |
|
84 |
return (uint16)InteractiveRandom() * max >> 16; |
|
85 |
} |
|
86 |
||
206 | 87 |
void InitPlayerRandoms() |
88 |
{ |
|
89 |
int i; |
|
90 |
for (i=0; i<MAX_PLAYERS; i++) { |
|
91 |
_player_seeds[i][0]=InteractiveRandom(); |
|
92 |
_player_seeds[i][1]=InteractiveRandom(); |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
93 |
} |
0 | 94 |
} |
95 |
||
96 |
void SetDate(uint date) |
|
97 |
{ |
|
98 |
YearMonthDay ymd; |
|
99 |
ConvertDayToYMD(&ymd, _date = date); |
|
100 |
_cur_year = ymd.year; |
|
101 |
_cur_month = ymd.month; |
|
102 |
} |
|
103 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
104 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
105 |
// multi os compatible sleep function |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
106 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
107 |
#if defined(__AMIGA__) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
108 |
// usleep() implementation |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
109 |
# include <devices/timer.h> |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
110 |
# include <dos/dos.h> |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
111 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
112 |
static struct Device *TimerBase = NULL; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
113 |
static struct MsgPort *TimerPort = NULL; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
114 |
static struct timerequest *TimerRequest = NULL; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
115 |
#endif // __AMIGA__ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
116 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
117 |
void CSleep(int milliseconds) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
118 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
119 |
#if defined(WIN32) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
120 |
Sleep(milliseconds); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
121 |
#endif |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
122 |
#if defined(UNIX) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
123 |
#if !defined(__BEOS__) && !defined(__AMIGAOS__) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
124 |
usleep(milliseconds * 1000); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
125 |
#endif |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
126 |
#ifdef __BEOS__ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
127 |
snooze(milliseconds * 1000); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
128 |
#endif |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
129 |
#if defined(__AMIGAOS__) && !defined(__MORPHOS__) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
130 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
131 |
ULONG signals; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
132 |
ULONG TimerSigBit = 1 << TimerPort->mp_SigBit; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
133 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
134 |
// send IORequest |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
135 |
TimerRequest->tr_node.io_Command = TR_ADDREQUEST; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
136 |
TimerRequest->tr_time.tv_secs = (milliseconds * 1000) / 1000000; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
137 |
TimerRequest->tr_time.tv_micro = (milliseconds * 1000) % 1000000; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
138 |
SendIO((struct IORequest *)TimerRequest); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
139 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
140 |
if (!((signals = Wait(TimerSigBit | SIGBREAKF_CTRL_C)) & TimerSigBit) ) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
141 |
AbortIO((struct IORequest *)TimerRequest); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
142 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
143 |
WaitIO((struct IORequest *)TimerRequest); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
144 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
145 |
#endif // __AMIGAOS__ && !__MORPHOS__ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
146 |
#endif |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
147 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
148 |
|
0 | 149 |
void InitializeClearLand(); |
150 |
void InitializeRail(); |
|
151 |
void InitializeRailGui(); |
|
152 |
void InitializeRoad(); |
|
153 |
void InitializeRoadGui(); |
|
154 |
void InitializeAirportGui(); |
|
155 |
void InitializeDock(); |
|
156 |
void InitializeDockGui(); |
|
157 |
void InitializeIndustries(); |
|
158 |
void InitializeLandscape(); |
|
159 |
void InitializeTowns(); |
|
160 |
void InitializeTrees(); |
|
161 |
void InitializeStations(); |
|
410 | 162 |
static void InitializeNameMgr(); |
0 | 163 |
void InitializePlayers(); |
410 | 164 |
static void InitializeCheats(); |
0 | 165 |
|
166 |
void GenerateLandscape(); |
|
167 |
void GenerateClearTile(); |
|
168 |
||
169 |
void GenerateIndustries(); |
|
170 |
void GenerateUnmovables(); |
|
171 |
void GenerateTowns(); |
|
172 |
||
173 |
void StartupPlayers(); |
|
174 |
void StartupEngines(); |
|
175 |
void StartupDisasters(); |
|
176 |
void GenerateTrees(); |
|
177 |
||
178 |
void ConvertGroundTilesIntoWaterTiles(); |
|
179 |
||
180 |
void InitializeGame() |
|
181 |
{ |
|
182 |
SetObjectToPlace(1, 0, 0, 0); |
|
183 |
||
184 |
_pause = 0; |
|
185 |
_fast_forward = 0; |
|
186 |
_tick_counter = 0; |
|
187 |
_date_fract = 0; |
|
188 |
_cur_tileloop_tile = 0; |
|
189 |
_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
|
190 |
|
0 | 191 |
{ |
192 |
uint starting = ConvertIntDate(_patches.starting_date); |
|
193 |
if ( starting == (uint)-1) starting = 10958; |
|
194 |
SetDate(starting); |
|
195 |
} |
|
196 |
||
197 |
InitializeVehicles(); |
|
198 |
_backup_orders_tile = 0; |
|
199 |
||
200 |
InitNewsItemStructs(); |
|
201 |
InitializeLandscape(); |
|
202 |
InitializeClearLand(); |
|
203 |
InitializeRail(); |
|
204 |
InitializeRailGui(); |
|
205 |
InitializeRoad(); |
|
206 |
InitializeRoadGui(); |
|
207 |
InitializeAirportGui(); |
|
208 |
InitializeDock(); |
|
209 |
InitializeDockGui(); |
|
210 |
InitializeTowns(); |
|
211 |
InitializeTrees(); |
|
212 |
InitializeStations(); |
|
213 |
InitializeIndustries(); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
214 |
|
0 | 215 |
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
|
216 |
InitializeVehiclesGuiList(); |
0 | 217 |
InitializeTrains(); |
218 |
||
219 |
InitializePlayers(); |
|
220 |
InitializeCheats(); |
|
221 |
||
222 |
InitTextEffects(); |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
223 |
InitTextMessage(); |
0 | 224 |
InitializeAnimatedTiles(); |
225 |
||
226 |
InitializeLandscapeVariables(false); |
|
227 |
||
228 |
ResetObjectToPlace(); |
|
229 |
} |
|
230 |
||
231 |
void GenerateWorld(int mode) |
|
232 |
{ |
|
233 |
int i; |
|
234 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
235 |
// Make sure everything is done via OWNER_NONE |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
236 |
_current_player = OWNER_NONE; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
237 |
|
0 | 238 |
_generating_world = true; |
239 |
InitializeGame(); |
|
240 |
SetObjectToPlace(1, 0, 0, 0); |
|
241 |
||
242 |
// Must start economy early because of the costs. |
|
243 |
StartupEconomy(); |
|
244 |
||
245 |
// Don't generate landscape items when in the scenario editor. |
|
246 |
if (mode == 1) { |
|
247 |
// empty world in scenario editor |
|
248 |
ConvertGroundTilesIntoWaterTiles(); |
|
249 |
} else { |
|
250 |
GenerateLandscape(); |
|
251 |
GenerateClearTile(); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
252 |
|
0 | 253 |
// only generate towns, tree and industries in newgame mode. |
254 |
if (mode == 0) { |
|
255 |
GenerateTowns(); |
|
256 |
GenerateTrees(); |
|
257 |
GenerateIndustries(); |
|
258 |
GenerateUnmovables(); |
|
259 |
} |
|
260 |
} |
|
261 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
262 |
// These are probably pointless when inside the scenario editor. |
0 | 263 |
StartupPlayers(); |
264 |
StartupEngines(); |
|
265 |
StartupDisasters(); |
|
266 |
_generating_world = false; |
|
267 |
||
268 |
// No need to run the tile loop in the scenario editor. |
|
269 |
if (mode != 1) { |
|
270 |
for(i=0x500; i!=0; i--) |
|
271 |
RunTileLoop(); |
|
272 |
} |
|
273 |
||
274 |
ResetObjectToPlace(); |
|
275 |
} |
|
276 |
||
277 |
void DeleteName(StringID id) |
|
278 |
{ |
|
279 |
if ((id & 0xF800) == 0x7800) { |
|
280 |
memset(_name_array[id & 0x1FF], 0, sizeof(_name_array[id & 0x1FF])); |
|
281 |
} |
|
282 |
} |
|
283 |
||
284 |
byte *GetName(int id, byte *buff) |
|
285 |
{ |
|
286 |
byte *b; |
|
287 |
||
288 |
if (id & 0x600) { |
|
289 |
if (id & 0x200) { |
|
290 |
if (id & 0x400) { |
|
291 |
GetParamInt32(); |
|
292 |
GetParamUint16(); |
|
293 |
} else { |
|
294 |
GetParamUint16(); |
|
295 |
} |
|
296 |
} else { |
|
297 |
GetParamInt32(); |
|
298 |
} |
|
299 |
} |
|
300 |
||
301 |
b = _name_array[(id&~0x600)]; |
|
302 |
while ((*buff++ = *b++) != 0); |
|
303 |
||
304 |
return buff - 1; |
|
305 |
} |
|
306 |
||
307 |
||
410 | 308 |
static void InitializeCheats() |
0 | 309 |
{ |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
310 |
memset(&_cheats, 0, sizeof(Cheats)); |
0 | 311 |
} |
312 |
||
313 |
||
410 | 314 |
static void InitializeNameMgr() |
0 | 315 |
{ |
316 |
memset(_name_array, 0, sizeof(_name_array)); |
|
317 |
} |
|
318 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
319 |
StringID RealAllocateName(const byte *name, byte skip, bool check_double) |
0 | 320 |
{ |
321 |
int free_item = -1; |
|
322 |
const byte *names; |
|
323 |
byte *dst; |
|
324 |
int i; |
|
325 |
||
326 |
names = &_name_array[0][0]; |
|
327 |
||
328 |
for(i=0; i!=512; i++,names+=sizeof(_name_array[0])) { |
|
329 |
if (names[0] == 0) { |
|
330 |
if (free_item == -1) |
|
331 |
free_item = i; |
|
332 |
} else { |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
333 |
if (check_double && str_eq(names, name)) { |
0 | 334 |
_error_message = STR_0132_CHOSEN_NAME_IN_USE_ALREADY; |
335 |
return 0; |
|
336 |
} |
|
337 |
} |
|
338 |
} |
|
339 |
||
340 |
if (free_item < 0) { |
|
341 |
_error_message = STR_0131_TOO_MANY_NAMES_DEFINED; |
|
342 |
return 0; |
|
343 |
} |
|
344 |
||
345 |
dst=_name_array[free_item]; |
|
346 |
||
347 |
for(i=0; (dst[i] = name[i]) != 0 && ++i != 32; ) {} |
|
348 |
dst[31] = 0; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
349 |
|
0 | 350 |
return free_item | 0x7800 | (skip << 8); |
351 |
} |
|
352 |
||
353 |
const TileIndexDiff _tileoffs_by_dir[4] = { |
|
354 |
TILE_XY(-1, 0), |
|
355 |
TILE_XY(0, 1), |
|
356 |
TILE_XY(1, 0), |
|
357 |
TILE_XY(0, -1), |
|
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 |
|
442 |
// 1920 - 2090 |
|
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 |
||
451 |
if (IS_INT_INSIDE(date, 1920, 2090 + 1)) { |
|
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 |
// distance in Manhattan metric |
|
524 |
uint GetTileDist(TileIndex xy1, TileIndex xy2) |
|
525 |
{ |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
526 |
return myabs(GET_TILE_X(xy1) - GET_TILE_X(xy2)) + |
0 | 527 |
myabs(GET_TILE_Y(xy1) - GET_TILE_Y(xy2)); |
528 |
} |
|
529 |
||
530 |
// maximum distance in x _or_ y |
|
531 |
uint GetTileDist1D(TileIndex xy1, TileIndex xy2) |
|
532 |
{ |
|
533 |
return max(myabs(GET_TILE_X(xy1) - GET_TILE_X(xy2)), |
|
534 |
myabs(GET_TILE_Y(xy1) - GET_TILE_Y(xy2))); |
|
535 |
} |
|
536 |
||
537 |
uint GetTileDist1Db(TileIndex xy1, TileIndex xy2) |
|
538 |
{ |
|
539 |
int a = myabs(GET_TILE_X(xy1) - GET_TILE_X(xy2)); |
|
540 |
int b = myabs(GET_TILE_Y(xy1) - GET_TILE_Y(xy2)); |
|
541 |
||
542 |
if (a > b) |
|
543 |
return a*2+b; |
|
544 |
else |
|
545 |
return b*2+a; |
|
546 |
} |
|
547 |
||
548 |
uint GetTileDistAdv(TileIndex xy1, TileIndex xy2) |
|
549 |
{ |
|
550 |
uint a = myabs(GET_TILE_X(xy1) - GET_TILE_X(xy2)); |
|
551 |
uint b = myabs(GET_TILE_Y(xy1) - GET_TILE_Y(xy2)); |
|
552 |
return a*a+b*b; |
|
553 |
} |
|
554 |
||
555 |
bool CheckDistanceFromEdge(TileIndex tile, uint distance) |
|
556 |
{ |
|
557 |
return IS_INT_INSIDE(GET_TILE_X(tile), distance, TILE_X_MAX + 1 - distance) && |
|
558 |
IS_INT_INSIDE(GET_TILE_Y(tile), distance, TILE_Y_MAX + 1 - distance); |
|
559 |
} |
|
560 |
||
561 |
void OnNewDay_Train(Vehicle *v); |
|
562 |
void OnNewDay_RoadVeh(Vehicle *v); |
|
563 |
void OnNewDay_Aircraft(Vehicle *v); |
|
564 |
void OnNewDay_Ship(Vehicle *v); |
|
565 |
void OnNewDay_EffectVehicle(Vehicle *v) { /* empty */ } |
|
566 |
void OnNewDay_DisasterVehicle(Vehicle *v); |
|
567 |
||
568 |
typedef void OnNewVehicleDayProc(Vehicle *v); |
|
569 |
||
570 |
static OnNewVehicleDayProc * _on_new_vehicle_day_proc[] = { |
|
571 |
OnNewDay_Train, |
|
572 |
OnNewDay_RoadVeh, |
|
573 |
OnNewDay_Ship, |
|
574 |
OnNewDay_Aircraft, |
|
575 |
OnNewDay_EffectVehicle, |
|
576 |
OnNewDay_DisasterVehicle, |
|
577 |
}; |
|
578 |
||
579 |
void EnginesDailyLoop(); |
|
580 |
void DisasterDailyLoop(); |
|
581 |
void PlayersMonthlyLoop(); |
|
582 |
void EnginesMonthlyLoop(); |
|
583 |
void TownsMonthlyLoop(); |
|
584 |
void IndustryMonthlyLoop(); |
|
585 |
void StationMonthlyLoop(); |
|
586 |
||
587 |
void PlayersYearlyLoop(); |
|
588 |
void TrainsYearlyLoop(); |
|
589 |
void RoadVehiclesYearlyLoop(); |
|
590 |
void AircraftYearlyLoop(); |
|
591 |
void ShipsYearlyLoop(); |
|
592 |
||
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
|
593 |
void WaypointsDailyLoop(); |
0 | 594 |
|
595 |
||
596 |
static const uint16 _autosave_months[] = { |
|
597 |
0, // never |
|
598 |
0xFFF, // every month |
|
599 |
0x249, // every 3 months |
|
600 |
0x041, // every 6 months |
|
601 |
0x001, // every 12 months |
|
602 |
}; |
|
603 |
||
604 |
void IncreaseDate() |
|
605 |
{ |
|
606 |
int i,ctr,t; |
|
607 |
YearMonthDay ymd; |
|
608 |
||
609 |
if (_game_mode == GM_MENU) { |
|
610 |
_tick_counter++; |
|
611 |
return; |
|
612 |
} |
|
613 |
||
614 |
/*if the day changed, call the vehicle event but only update a part of the vehicles |
|
615 |
old max was i!= 12. But with that and a bigger number of vehicles (2560), per day only |
|
616 |
a part of it could be done, namely: function called max_size date_fract (uint16) / 885 x 12 ==> |
|
617 |
65536 / 885 = 74; 74x12 = 888. So max 888. Any vehicles above that were not _on_new_vehicle_day_proc'd |
|
618 |
eg. aged. |
|
619 |
So new code updates it for max vehicles. |
|
620 |
(NUM_VEHICLES / maximum number of times ctr is incremented before reset ) + 1 (to get last vehicles too) |
|
621 |
max size of _date_fract / 885 (added each tick) is number of times before ctr is reset. |
|
622 |
Calculation might look complicated, but compiler just replaces it with 35, so that's ok |
|
623 |
*/ |
|
624 |
||
625 |
ctr = _vehicle_id_ctr_day; |
|
626 |
for(i=0; i!=(NUM_VEHICLES / ((1<<sizeof(_date_fract)*8) / 885)) + 1 && ctr != lengthof(_vehicles); i++) { |
|
627 |
Vehicle *v = &_vehicles[ctr++]; |
|
628 |
if ((t=v->type) != 0) |
|
629 |
_on_new_vehicle_day_proc[t - 0x10](v); |
|
630 |
} |
|
631 |
_vehicle_id_ctr_day = ctr; |
|
632 |
||
633 |
/* increase day, and check if a new day is there? */ |
|
634 |
_tick_counter++; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
635 |
|
0 | 636 |
if ( (_date_fract += 885) >= 885) |
637 |
return; |
|
638 |
||
639 |
/* yeah, increse day counter and call various daily loops */ |
|
640 |
_date++; |
|
641 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
642 |
_vehicle_id_ctr_day = 0; |
105 | 643 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
644 |
TextMessageDailyLoop(); |
0 | 645 |
|
646 |
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
|
647 |
WaypointsDailyLoop(); |
0 | 648 |
|
649 |
if (_game_mode != GM_MENU) { |
|
650 |
InvalidateWindowWidget(WC_STATUS_BAR, 0, 0); |
|
651 |
EnginesDailyLoop(); |
|
652 |
} |
|
653 |
||
654 |
/* check if we entered a new month? */ |
|
655 |
ConvertDayToYMD(&ymd, _date); |
|
656 |
if ((byte)ymd.month == _cur_month) |
|
657 |
return; |
|
658 |
_cur_month = ymd.month; |
|
659 |
||
660 |
/* yes, call various monthly loops */ |
|
661 |
if (_game_mode != GM_MENU) { |
|
662 |
if (HASBIT(_autosave_months[_opt.autosave], _cur_month)) { |
|
663 |
_do_autosave = true; |
|
664 |
RedrawAutosave(); |
|
665 |
} |
|
666 |
||
667 |
PlayersMonthlyLoop(); |
|
668 |
EnginesMonthlyLoop(); |
|
669 |
TownsMonthlyLoop(); |
|
670 |
IndustryMonthlyLoop(); |
|
671 |
StationMonthlyLoop(); |
|
690
9f449a6b133e
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
672 |
#ifdef ENABLE_NETWORK |
9f449a6b133e
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
673 |
if (_network_server) |
9f449a6b133e
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
674 |
NetworkServerMonthlyLoop(); |
9f449a6b133e
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
675 |
#endif /* ENABLE_NETWORK */ |
0 | 676 |
} |
677 |
||
678 |
/* check if we entered a new year? */ |
|
679 |
if ((byte)ymd.year == _cur_year) |
|
680 |
return; |
|
681 |
_cur_year = ymd.year; |
|
682 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
683 |
/* yes, call various yearly loops */ |
0 | 684 |
|
685 |
PlayersYearlyLoop(); |
|
686 |
TrainsYearlyLoop(); |
|
687 |
RoadVehiclesYearlyLoop(); |
|
688 |
AircraftYearlyLoop(); |
|
689 |
ShipsYearlyLoop(); |
|
690 |
||
691 |
/* check if we reached 2090, that's the maximum year. */ |
|
692 |
if (_cur_year == 171) { |
|
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
|
693 |
Vehicle *v; |
0 | 694 |
_cur_year = 170; |
695 |
_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
|
696 |
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
|
697 |
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
|
698 |
} |
0 | 699 |
} |
700 |
||
701 |
if (_patches.auto_euro) |
|
702 |
CheckSwitchToEuro(); |
|
703 |
||
704 |
/* XXX: check if year 2050 was reached */ |
|
705 |
} |
|
706 |
||
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
707 |
int FindFirstBit(uint32 value) |
0 | 708 |
{ |
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
709 |
// This is much faster then the one that was before here. |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
710 |
// 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
|
711 |
// Btw, the macro FINDFIRSTBIT is better to use when your value is |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
712 |
// not more then 128. |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
713 |
byte i = 0; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
714 |
if (value & 0xffff0000) { value >>= 16; i += 16; } |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
715 |
if (value & 0x0000ff00) { value >>= 8; i += 8; } |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
716 |
if (value & 0x000000f0) { value >>= 4; i += 4; } |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
717 |
if (value & 0x0000000c) { value >>= 2; i += 2; } |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
718 |
if (value & 0x00000002) { i += 1; } |
0 | 719 |
return i; |
720 |
} |
|
721 |
||
722 |
||
723 |
extern uint SafeTileAdd(uint tile, int add, const char *exp, const char *file, int line) |
|
724 |
{ |
|
725 |
int x = GET_TILE_X(tile) + (signed char)(add & 0xFF); |
|
726 |
int y = GET_TILE_Y(tile) + ((((0x8080 + add)>>8) & 0xFF) - 0x80); |
|
727 |
||
728 |
if (x < 0 || y < 0 || x >= TILES_X || y >= TILES_Y) { |
|
729 |
char buf[512]; |
|
730 |
||
731 |
sprintf(buf, "TILE_ADD(%s) when adding 0x%.4X and %d failed", exp, tile, add); |
|
732 |
#if !defined(_DEBUG) || !defined(_MSC_VER) |
|
733 |
printf("%s\n", buf); |
|
734 |
#else |
|
735 |
_assert(buf, (char*)file, line); |
|
736 |
#endif |
|
737 |
} |
|
738 |
||
739 |
assert(TILE_XY(x,y) == TILE_MASK(tile + add)); |
|
740 |
||
741 |
return TILE_XY(x,y); |
|
742 |
} |
|
743 |
||
744 |
static void Save_NAME() |
|
745 |
{ |
|
746 |
int i; |
|
747 |
byte *b = _name_array[0]; |
|
748 |
||
749 |
for(i=0; i!=lengthof(_name_array); i++,b+=sizeof(_name_array[0])) { |
|
750 |
if (*b) { |
|
751 |
SlSetArrayIndex(i); |
|
752 |
SlArray(b, strlen(b), SLE_UINT8); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
753 |
} |
0 | 754 |
} |
755 |
} |
|
756 |
||
757 |
static void Load_NAME() |
|
758 |
{ |
|
759 |
int index; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
760 |
|
0 | 761 |
while ((index = SlIterateArray()) != -1) { |
762 |
SlArray(_name_array[index],SlGetFieldLength(),SLE_UINT8); |
|
763 |
} |
|
764 |
} |
|
765 |
||
766 |
static const byte _game_opt_desc[] = { |
|
767 |
// added a new difficulty option (town attitude) in version 4 |
|
768 |
SLE_CONDARR(GameOptions,diff, SLE_FILE_I16 | SLE_VAR_I32, 17, 0, 3), |
|
769 |
SLE_CONDARR(GameOptions,diff, SLE_FILE_I16 | SLE_VAR_I32, 18, 4, 255), |
|
770 |
SLE_VAR(GameOptions,diff_level, SLE_UINT8), |
|
771 |
SLE_VAR(GameOptions,currency, SLE_UINT8), |
|
772 |
SLE_VAR(GameOptions,kilometers, SLE_UINT8), |
|
773 |
SLE_VAR(GameOptions,town_name, SLE_UINT8), |
|
774 |
SLE_VAR(GameOptions,landscape, SLE_UINT8), |
|
775 |
SLE_VAR(GameOptions,snow_line, SLE_UINT8), |
|
776 |
SLE_VAR(GameOptions,autosave, SLE_UINT8), |
|
777 |
SLE_VAR(GameOptions,road_side, SLE_UINT8), |
|
778 |
SLE_END() |
|
779 |
}; |
|
780 |
||
781 |
// Save load game options |
|
782 |
static void SaveLoad_OPTS() |
|
783 |
{ |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
784 |
SlObject(&_opt, _game_opt_desc); |
0 | 785 |
} |
786 |
||
787 |
||
788 |
static const SaveLoadGlobVarList _date_desc[] = { |
|
789 |
{&_date, SLE_UINT16, 0, 255}, |
|
790 |
{&_date_fract, SLE_UINT16, 0, 255}, |
|
791 |
{&_tick_counter, SLE_UINT16, 0, 255}, |
|
792 |
{&_vehicle_id_ctr_day, SLE_UINT16, 0, 255}, |
|
793 |
{&_age_cargo_skip_counter, SLE_UINT8, 0, 255}, |
|
794 |
{&_avail_aircraft, SLE_UINT8, 0, 255}, |
|
795 |
{&_cur_tileloop_tile, SLE_UINT16, 0, 255}, |
|
796 |
{&_disaster_delay, SLE_UINT16, 0, 255}, |
|
797 |
{&_station_tick_ctr, SLE_UINT16, 0, 255}, |
|
206 | 798 |
{&_random_seeds[0][0], SLE_UINT32, 0, 255}, |
799 |
{&_random_seeds[0][1], SLE_UINT32, 0, 255}, |
|
0 | 800 |
{&_cur_town_ctr, SLE_UINT8, 0, 255}, |
801 |
{&_cur_player_tick_index, SLE_FILE_U8 | SLE_VAR_UINT, 0, 255}, |
|
802 |
{&_next_competitor_start, SLE_FILE_U16 | SLE_VAR_UINT, 0, 255}, |
|
803 |
{&_trees_tick_ctr, SLE_UINT8, 0, 255}, |
|
804 |
{&_pause, SLE_UINT8, 4, 255}, |
|
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
805 |
{NULL, 0, 0, 0} |
0 | 806 |
}; |
807 |
||
808 |
// Save load date related variables as well as persistent tick counters |
|
809 |
// XXX: currently some unrelated stuff is just put here |
|
810 |
static void SaveLoad_DATE() |
|
811 |
{ |
|
812 |
SlGlobList(_date_desc); |
|
813 |
} |
|
814 |
||
815 |
||
816 |
static const SaveLoadGlobVarList _view_desc[] = { |
|
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
817 |
{&_saved_scrollpos_x, SLE_FILE_I16 | SLE_VAR_INT, 0, 255}, |
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
818 |
{&_saved_scrollpos_y, SLE_FILE_I16 | SLE_VAR_INT, 0, 255}, |
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
819 |
{&_saved_scrollpos_zoom, SLE_UINT8, 0, 255}, |
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
820 |
{NULL, 0, 0, 0} |
0 | 821 |
}; |
822 |
||
823 |
static void SaveLoad_VIEW() |
|
824 |
{ |
|
825 |
SlGlobList(_view_desc); |
|
826 |
} |
|
827 |
||
828 |
static void SaveLoad_MAPT() { |
|
695
561b806c0477
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
690
diff
changeset
|
829 |
SlArray(_map_type_and_height, MapSize(), SLE_UINT8); |
0 | 830 |
} |
831 |
||
832 |
static void SaveLoad_MAP2() { |
|
695
561b806c0477
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
690
diff
changeset
|
833 |
SlArray(_map2, MapSize(), SLE_UINT8); |
0 | 834 |
} |
835 |
||
836 |
static void SaveLoad_M3LO() { |
|
695
561b806c0477
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
690
diff
changeset
|
837 |
SlArray(_map3_lo, MapSize(), SLE_UINT8); |
0 | 838 |
} |
839 |
||
840 |
static void SaveLoad_M3HI() { |
|
695
561b806c0477
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
690
diff
changeset
|
841 |
SlArray(_map3_hi, MapSize(), SLE_UINT8); |
0 | 842 |
} |
843 |
||
844 |
static void SaveLoad_MAPO() { |
|
695
561b806c0477
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
690
diff
changeset
|
845 |
SlArray(_map_owner, MapSize(), SLE_UINT8); |
0 | 846 |
} |
847 |
||
848 |
static void SaveLoad_MAP5() { |
|
695
561b806c0477
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
690
diff
changeset
|
849 |
SlArray(_map5, MapSize(), SLE_UINT8); |
0 | 850 |
} |
851 |
||
852 |
static void SaveLoad_MAPE() { |
|
695
561b806c0477
(svn r1144) Don't rely on sizeof() to determine the map size, use MapSize() instead
tron
parents:
690
diff
changeset
|
853 |
SlArray(_map_extra_bits, MapSize() / 4, SLE_UINT8); |
0 | 854 |
} |
855 |
||
856 |
||
857 |
static void Save_CHTS() |
|
858 |
{ |
|
859 |
byte count = sizeof(_cheats)/sizeof(Cheat); |
|
860 |
Cheat* cht = (Cheat*) &_cheats; |
|
861 |
Cheat* cht_last = &cht[count]; |
|
862 |
||
863 |
SlSetLength(count*2); |
|
864 |
for(; cht != cht_last; cht++) { |
|
865 |
SlWriteByte(cht->been_used); |
|
866 |
SlWriteByte(cht->value); |
|
867 |
} |
|
868 |
} |
|
869 |
||
870 |
static void Load_CHTS() |
|
871 |
{ |
|
872 |
Cheat* cht = (Cheat*) &_cheats; |
|
873 |
||
874 |
uint count = SlGetFieldLength()/2; |
|
875 |
for(; count; count--, cht++) |
|
876 |
{ |
|
877 |
cht->been_used = (byte)SlReadByte(); |
|
878 |
cht->value = (byte)SlReadByte(); |
|
879 |
} |
|
880 |
} |
|
881 |
||
882 |
||
883 |
const ChunkHandler _misc_chunk_handlers[] = { |
|
884 |
{ 'MAPT', SaveLoad_MAPT, SaveLoad_MAPT, CH_RIFF }, |
|
885 |
{ 'MAP2', SaveLoad_MAP2, SaveLoad_MAP2, CH_RIFF }, |
|
886 |
{ 'M3LO', SaveLoad_M3LO, SaveLoad_M3LO, CH_RIFF }, |
|
887 |
{ 'M3HI', SaveLoad_M3HI, SaveLoad_M3HI, CH_RIFF }, |
|
888 |
{ 'MAPO', SaveLoad_MAPO, SaveLoad_MAPO, CH_RIFF }, |
|
889 |
{ 'MAP5', SaveLoad_MAP5, SaveLoad_MAP5, CH_RIFF }, |
|
890 |
{ 'MAPE', SaveLoad_MAPE, SaveLoad_MAPE, CH_RIFF }, |
|
891 |
||
892 |
{ 'NAME', Save_NAME, Load_NAME, CH_ARRAY}, |
|
893 |
{ 'DATE', SaveLoad_DATE, SaveLoad_DATE, CH_RIFF}, |
|
894 |
{ 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, CH_RIFF}, |
|
895 |
{ 'OPTS', SaveLoad_OPTS, SaveLoad_OPTS, CH_RIFF}, |
|
896 |
{ 'CHTS', Save_CHTS, Load_CHTS, CH_RIFF | CH_LAST} |
|
897 |
}; |