author | ludde |
Sat, 16 Jul 2005 20:58:04 +0000 | |
changeset 2084 | d67790a49f78 |
parent 2078 | 94c05035e2ce |
child 2086 | dbe5faa270e0 |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1881
diff
changeset
|
2 |
#include "openttd.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" |
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
6 |
#include "table/sprites.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
|
7 |
#include "map.h" |
0 | 8 |
#include "vehicle.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" |
1752
cdbfb2f23e72
(svn r2256) - Fix: Trains cannot find a depot when they are in a tunnel. (glx)
matthijs
parents:
1595
diff
changeset
|
15 |
#include "vehicle_gui.h" |
0 | 16 |
|
1093
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 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
|
18 |
extern void InitNewsItemStructs(void); |
0 | 19 |
|
1328
e069d2db0e4c
(svn r1832) Next byte -> char iteration: custom names
tron
parents:
1313
diff
changeset
|
20 |
char _name_array[512][32]; |
0 | 21 |
|
500
ef288590e096
(svn r793) Merge INLINE -> inline replacement (revision 376)
tron
parents:
410
diff
changeset
|
22 |
static inline uint32 ROR(uint32 x, int n) |
0 | 23 |
{ |
24 |
return (x >> n) + (x << ((sizeof(x)*8)-n)); |
|
25 |
} |
|
26 |
||
2073 | 27 |
#ifndef MERSENNE_TWISTER |
28 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
29 |
#ifdef RANDOM_DEBUG |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
30 |
#include "network_data.h" |
1120
ea3bf8bc6678
(svn r1621) -Fix: fixed some compiler warnings for the random-debug-switch
truelight
parents:
1095
diff
changeset
|
31 |
uint32 DoRandom(int line, const char *file) |
2073 | 32 |
#else // RANDOM_DEBUG |
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
|
33 |
uint32 Random(void) |
2073 | 34 |
#endif // RANDOM_DEBUG |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
35 |
{ |
1121
b0dbb4c15e12
(svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents:
1120
diff
changeset
|
36 |
|
b0dbb4c15e12
(svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents:
1120
diff
changeset
|
37 |
uint32 s; |
b0dbb4c15e12
(svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents:
1120
diff
changeset
|
38 |
uint32 t; |
b0dbb4c15e12
(svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents:
1120
diff
changeset
|
39 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
40 |
#ifdef RANDOM_DEBUG |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
41 |
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
|
42 |
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
|
43 |
#endif |
32fcaaf9f4ef
(svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents:
256
diff
changeset
|
44 |
|
1121
b0dbb4c15e12
(svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents:
1120
diff
changeset
|
45 |
s = _random_seeds[0][0]; |
b0dbb4c15e12
(svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents:
1120
diff
changeset
|
46 |
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
|
47 |
_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
|
48 |
return _random_seeds[0][1] = ROR(s, 3) - 1; |
0 | 49 |
} |
2073 | 50 |
#endif // MERSENNE_TWISTER |
0 | 51 |
|
2073 | 52 |
#if defined(RANDOM_DEBUG) && !defined(MERSENNE_TWISTER) |
1120
ea3bf8bc6678
(svn r1621) -Fix: fixed some compiler warnings for the random-debug-switch
truelight
parents:
1095
diff
changeset
|
53 |
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
|
54 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
55 |
return (uint16)DoRandom(line, file) * max >> 16; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
56 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
57 |
#else |
0 | 58 |
uint RandomRange(uint max) |
59 |
{ |
|
60 |
return (uint16)Random() * max >> 16; |
|
61 |
} |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
62 |
#endif |
0 | 63 |
|
2073 | 64 |
|
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
|
65 |
uint32 InteractiveRandom(void) |
0 | 66 |
{ |
206 | 67 |
uint32 t = _random_seeds[1][1]; |
68 |
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
|
69 |
_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
|
70 |
return _random_seeds[1][1] = ROR(s, 3) - 1; |
206 | 71 |
} |
72 |
||
239 | 73 |
uint InteractiveRandomRange(uint max) |
74 |
{ |
|
75 |
return (uint16)InteractiveRandom() * max >> 16; |
|
76 |
} |
|
77 |
||
0 | 78 |
void SetDate(uint date) |
79 |
{ |
|
80 |
YearMonthDay ymd; |
|
81 |
ConvertDayToYMD(&ymd, _date = date); |
|
82 |
_cur_year = ymd.year; |
|
83 |
_cur_month = ymd.month; |
|
764
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
695
diff
changeset
|
84 |
#ifdef ENABLE_NETWORK |
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
695
diff
changeset
|
85 |
_network_last_advertise_date = 0; |
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
695
diff
changeset
|
86 |
#endif /* ENABLE_NETWORK */ |
0 | 87 |
} |
88 |
||
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
|
89 |
void InitializeVehicles(void); |
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1538
diff
changeset
|
90 |
void InitializeWaypoints(void); |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1309
diff
changeset
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
void InitializeIndustries(void); |
2051 | 102 |
void InitializeLandscape(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
|
103 |
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
|
104 |
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
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
static void InitializeCheats(void); |
1247 | 110 |
void InitializeNPF(void); |
0 | 111 |
|
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
|
112 |
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
|
113 |
void GenerateClearTile(void); |
0 | 114 |
|
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
|
115 |
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
|
116 |
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
|
117 |
void GenerateTowns(void); |
0 | 118 |
|
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
|
119 |
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
|
120 |
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
|
121 |
void GenerateTrees(void); |
0 | 122 |
|
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
|
123 |
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
|
124 |
|
2051 | 125 |
void InitializeGame(uint size_x, uint size_y) |
0 | 126 |
{ |
2051 | 127 |
uint i; |
128 |
||
129 |
AllocateMap(size_x, size_y); |
|
130 |
||
842 | 131 |
// Initialize the autoreplace array. Needs to be cleared between each game |
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
|
132 |
for (i = 0; i < lengthof(_autoreplace_array); i++) |
842 | 133 |
_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
|
134 |
|
1178
ce85710f92ff
(svn r1680) Feature: Replace train GUI now remembers the railtype selected in the dropdown menu
bjarni
parents:
1175
diff
changeset
|
135 |
_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
|
136 |
|
842 | 137 |
AddTypeToEngines(); // make sure all engines have a type |
915 | 138 |
|
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
139 |
SetObjectToPlace(SPR_CURSOR_ZZZ, 0, 0, 0); |
0 | 140 |
|
141 |
_pause = 0; |
|
142 |
_fast_forward = 0; |
|
143 |
_tick_counter = 0; |
|
144 |
_date_fract = 0; |
|
145 |
_cur_tileloop_tile = 0; |
|
146 |
_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
|
147 |
|
0 | 148 |
{ |
149 |
uint starting = ConvertIntDate(_patches.starting_date); |
|
150 |
if ( starting == (uint)-1) starting = 10958; |
|
151 |
SetDate(starting); |
|
152 |
} |
|
153 |
||
154 |
InitializeVehicles(); |
|
1542
2ca6d1624e6d
(svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents:
1538
diff
changeset
|
155 |
InitializeWaypoints(); |
1313
bba6afb8a995
(svn r1817) -Codechange: Moved depot-functions to depot.c
truelight
parents:
1309
diff
changeset
|
156 |
InitializeDepot(); |
1024
9b06b01490a4
(svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents:
1009
diff
changeset
|
157 |
InitializeOrders(); |
0 | 158 |
|
159 |
InitNewsItemStructs(); |
|
2051 | 160 |
InitializeLandscape(); |
0 | 161 |
InitializeClearLand(); |
162 |
InitializeRail(); |
|
163 |
InitializeRailGui(); |
|
164 |
InitializeRoad(); |
|
165 |
InitializeRoadGui(); |
|
166 |
InitializeAirportGui(); |
|
167 |
InitializeDock(); |
|
168 |
InitializeDockGui(); |
|
169 |
InitializeTowns(); |
|
170 |
InitializeTrees(); |
|
988
2482369a61ff
(svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents:
983
diff
changeset
|
171 |
InitializeSigns(); |
0 | 172 |
InitializeStations(); |
173 |
InitializeIndustries(); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
174 |
|
0 | 175 |
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
|
176 |
InitializeVehiclesGuiList(); |
0 | 177 |
InitializeTrains(); |
1247 | 178 |
InitializeNPF(); |
0 | 179 |
|
180 |
InitializePlayers(); |
|
181 |
InitializeCheats(); |
|
182 |
||
183 |
InitTextEffects(); |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
184 |
InitTextMessage(); |
0 | 185 |
InitializeAnimatedTiles(); |
186 |
||
187 |
InitializeLandscapeVariables(false); |
|
188 |
||
189 |
ResetObjectToPlace(); |
|
190 |
} |
|
191 |
||
2051 | 192 |
void GenerateWorld(int mode, uint size_x, uint size_y) |
0 | 193 |
{ |
194 |
int i; |
|
195 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
196 |
// Make sure everything is done via OWNER_NONE |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
197 |
_current_player = OWNER_NONE; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
198 |
|
0 | 199 |
_generating_world = true; |
2051 | 200 |
InitializeGame(size_x, size_y); |
1914
5ede46fd496f
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
201 |
SetObjectToPlace(SPR_CURSOR_ZZZ, 0, 0, 0); |
0 | 202 |
|
203 |
// Must start economy early because of the costs. |
|
204 |
StartupEconomy(); |
|
205 |
||
206 |
// Don't generate landscape items when in the scenario editor. |
|
207 |
if (mode == 1) { |
|
208 |
// empty world in scenario editor |
|
209 |
ConvertGroundTilesIntoWaterTiles(); |
|
210 |
} else { |
|
211 |
GenerateLandscape(); |
|
212 |
GenerateClearTile(); |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
213 |
|
0 | 214 |
// only generate towns, tree and industries in newgame mode. |
215 |
if (mode == 0) { |
|
216 |
GenerateTowns(); |
|
217 |
GenerateTrees(); |
|
218 |
GenerateIndustries(); |
|
219 |
GenerateUnmovables(); |
|
220 |
} |
|
221 |
} |
|
222 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
223 |
// These are probably pointless when inside the scenario editor. |
0 | 224 |
StartupPlayers(); |
225 |
StartupEngines(); |
|
226 |
StartupDisasters(); |
|
227 |
_generating_world = false; |
|
228 |
||
229 |
// No need to run the tile loop in the scenario editor. |
|
230 |
if (mode != 1) { |
|
231 |
for(i=0x500; i!=0; i--) |
|
232 |
RunTileLoop(); |
|
233 |
} |
|
234 |
||
235 |
ResetObjectToPlace(); |
|
236 |
} |
|
237 |
||
238 |
void DeleteName(StringID id) |
|
239 |
{ |
|
240 |
if ((id & 0xF800) == 0x7800) { |
|
241 |
memset(_name_array[id & 0x1FF], 0, sizeof(_name_array[id & 0x1FF])); |
|
242 |
} |
|
243 |
} |
|
244 |
||
1328
e069d2db0e4c
(svn r1832) Next byte -> char iteration: custom names
tron
parents:
1313
diff
changeset
|
245 |
char *GetName(int id, char *buff) |
0 | 246 |
{ |
1375
f13d8247928c
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
247 |
return strecpy(buff, _name_array[id & ~0x600], NULL); |
0 | 248 |
} |
249 |
||
250 |
||
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
|
251 |
static void InitializeCheats(void) |
0 | 252 |
{ |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
253 |
memset(&_cheats, 0, sizeof(Cheats)); |
0 | 254 |
} |
255 |
||
256 |
||
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
|
257 |
static void InitializeNameMgr(void) |
0 | 258 |
{ |
259 |
memset(_name_array, 0, sizeof(_name_array)); |
|
260 |
} |
|
261 |
||
1328
e069d2db0e4c
(svn r1832) Next byte -> char iteration: custom names
tron
parents:
1313
diff
changeset
|
262 |
StringID RealAllocateName(const char *name, byte skip, bool check_double) |
0 | 263 |
{ |
1375
f13d8247928c
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
264 |
char (*free_item)[lengthof(*_name_array)] = NULL; |
f13d8247928c
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
265 |
char (*i)[lengthof(*_name_array)]; |
0 | 266 |
|
1375
f13d8247928c
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
267 |
for (i = _name_array; i != endof(_name_array); ++i) { |
f13d8247928c
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
268 |
if ((*i)[0] == '\0') { |
f13d8247928c
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
269 |
if (free_item == NULL) free_item = i; |
f13d8247928c
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
270 |
} 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
|
271 |
_error_message = STR_0132_CHOSEN_NAME_IN_USE_ALREADY; |
f13d8247928c
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
272 |
return 0; |
0 | 273 |
} |
274 |
} |
|
275 |
||
1375
f13d8247928c
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
276 |
if (free_item != NULL) { |
f13d8247928c
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
277 |
ttd_strlcpy(*free_item, name, lengthof(*free_item)); |
f13d8247928c
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
278 |
return (free_item - _name_array) | 0x7800 | (skip << 8); |
f13d8247928c
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
279 |
} else { |
0 | 280 |
_error_message = STR_0131_TOO_MANY_NAMES_DEFINED; |
281 |
return 0; |
|
282 |
} |
|
283 |
} |
|
284 |
||
285 |
||
286 |
#define M(a,b) ((a<<5)|b) |
|
287 |
static const uint16 _month_date_from_year_day[] = { |
|
288 |
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), |
|
289 |
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), |
|
290 |
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), |
|
291 |
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), |
|
292 |
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), |
|
293 |
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), |
|
294 |
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), |
|
295 |
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), |
|
296 |
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), |
|
297 |
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), |
|
298 |
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), |
|
299 |
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), |
|
300 |
}; |
|
301 |
#undef M |
|
302 |
||
303 |
enum { |
|
304 |
ACCUM_JAN = 0, |
|
305 |
ACCUM_FEB = ACCUM_JAN + 31, |
|
306 |
ACCUM_MAR = ACCUM_FEB + 29, |
|
307 |
ACCUM_APR = ACCUM_MAR + 31, |
|
308 |
ACCUM_MAY = ACCUM_APR + 30, |
|
309 |
ACCUM_JUN = ACCUM_MAY + 31, |
|
310 |
ACCUM_JUL = ACCUM_JUN + 30, |
|
311 |
ACCUM_AUG = ACCUM_JUL + 31, |
|
312 |
ACCUM_SEP = ACCUM_AUG + 31, |
|
313 |
ACCUM_OCT = ACCUM_SEP + 30, |
|
314 |
ACCUM_NOV = ACCUM_OCT + 31, |
|
315 |
ACCUM_DEC = ACCUM_NOV + 30, |
|
316 |
}; |
|
317 |
||
318 |
static const uint16 _accum_days_for_month[] = { |
|
319 |
ACCUM_JAN,ACCUM_FEB,ACCUM_MAR,ACCUM_APR, |
|
320 |
ACCUM_MAY,ACCUM_JUN,ACCUM_JUL,ACCUM_AUG, |
|
321 |
ACCUM_SEP,ACCUM_OCT,ACCUM_NOV,ACCUM_DEC, |
|
322 |
}; |
|
323 |
||
324 |
||
325 |
void ConvertDayToYMD(YearMonthDay *ymd, uint16 date) |
|
326 |
{ |
|
327 |
uint yr = date / (365+365+365+366); |
|
328 |
uint rem = date % (365+365+365+366); |
|
329 |
uint x; |
|
330 |
||
331 |
yr *= 4; |
|
332 |
||
333 |
if (rem >= 366) { |
|
334 |
rem--; |
|
335 |
do { |
|
336 |
rem -= 365; |
|
337 |
yr++; |
|
338 |
} while (rem >= 365); |
|
339 |
if (rem >= 31+28) rem++; |
|
340 |
} |
|
341 |
||
342 |
ymd->year = yr; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
343 |
|
0 | 344 |
x = _month_date_from_year_day[rem]; |
345 |
ymd->month = x >> 5; |
|
346 |
ymd->day = x & 0x1F; |
|
347 |
} |
|
348 |
||
349 |
// year is a number between 0..? |
|
350 |
// month is a number between 0..11 |
|
351 |
// day is a number between 1..31 |
|
352 |
uint ConvertYMDToDay(uint year, uint month, uint day) |
|
353 |
{ |
|
354 |
uint rem; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
355 |
|
0 | 356 |
// day in the year |
357 |
rem = _accum_days_for_month[month] + day - 1; |
|
358 |
||
359 |
// remove feb 29 from year 1,2,3 |
|
360 |
if (year & 3) rem += (year & 3) * 365 + (rem < 31+29); |
|
361 |
||
362 |
// base date. |
|
363 |
return (year >> 2) * (365+365+365+366) + rem; |
|
364 |
} |
|
365 |
||
366 |
// 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
|
367 |
// 1920 - 2090 (MAX_YEAR_END_REAL) |
0 | 368 |
// 192001 - 209012 |
369 |
// 19200101 - 20901231 |
|
370 |
// or if > 2090 and below 65536, treat it as a daycount |
|
371 |
// returns -1 if no conversion was possible |
|
372 |
uint ConvertIntDate(uint date) |
|
373 |
{ |
|
374 |
uint year, month = 0, day = 1; |
|
375 |
||
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
|
376 |
if (IS_INT_INSIDE(date, 1920, MAX_YEAR_END_REAL + 1)) { |
0 | 377 |
year = date - 1920; |
378 |
} 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
|
379 |
month = date % 100 - 1; |
0 | 380 |
year = date / 100 - 1920; |
381 |
} else if (IS_INT_INSIDE(date, 19200101, 20901231+1)) { |
|
382 |
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
|
383 |
month = date % 100 - 1; |
0 | 384 |
year = date / 100 - 1920; |
385 |
} else if (IS_INT_INSIDE(date, 2091, 65536)) |
|
386 |
return date; |
|
387 |
else |
|
388 |
return (uint)-1; |
|
389 |
||
390 |
// invalid ranges? |
|
391 |
if (month >= 12 || !IS_INT_INSIDE(day, 1, 31+1)) return (uint)-1; |
|
392 |
||
393 |
return ConvertYMDToDay(year, month, day); |
|
394 |
} |
|
395 |
||
396 |
typedef struct LandscapePredefVar { |
|
397 |
StringID names[NUM_CARGO]; |
|
398 |
byte weights[NUM_CARGO]; |
|
399 |
StringID sprites[NUM_CARGO]; |
|
400 |
||
401 |
uint16 initial_cargo_payment[NUM_CARGO]; |
|
402 |
byte transit_days_table_1[NUM_CARGO]; |
|
403 |
byte transit_days_table_2[NUM_CARGO]; |
|
404 |
||
405 |
byte railwagon_by_cargo[3][NUM_CARGO]; |
|
406 |
||
407 |
byte road_veh_by_cargo_start[NUM_CARGO]; |
|
408 |
byte road_veh_by_cargo_count[NUM_CARGO]; |
|
409 |
} LandscapePredefVar; |
|
410 |
||
411 |
#include "table/landscape_const.h" |
|
412 |
||
413 |
||
414 |
// Calculate constants that depend on the landscape type. |
|
415 |
void InitializeLandscapeVariables(bool only_constants) |
|
416 |
{ |
|
417 |
const LandscapePredefVar *lpd; |
|
418 |
int i; |
|
419 |
StringID str; |
|
420 |
||
421 |
lpd = &_landscape_predef_var[_opt.landscape]; |
|
422 |
||
423 |
memcpy(_cargoc.ai_railwagon, lpd->railwagon_by_cargo, sizeof(lpd->railwagon_by_cargo)); |
|
424 |
memcpy(_cargoc.ai_roadveh_start, lpd->road_veh_by_cargo_start,sizeof(lpd->road_veh_by_cargo_start)); |
|
425 |
memcpy(_cargoc.ai_roadveh_count, lpd->road_veh_by_cargo_count,sizeof(lpd->road_veh_by_cargo_count)); |
|
426 |
||
427 |
for(i=0; i!=NUM_CARGO; i++) { |
|
428 |
_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
|
429 |
|
0 | 430 |
str = lpd->names[i]; |
431 |
_cargoc.names_s[i] = str; |
|
432 |
_cargoc.names_p[i] = (str += 0x20); |
|
2084
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2078
diff
changeset
|
433 |
_cargoc.names_long[i] = (str += 0x20); |
d67790a49f78
(svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents:
2078
diff
changeset
|
434 |
// _cargoc.names_long_p[i] = (str += 0x20); |
0 | 435 |
_cargoc.names_short[i] = (str += 0x20); |
436 |
_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
|
437 |
|
0 | 438 |
if (!only_constants) { |
439 |
_cargo_payment_rates[i] = lpd->initial_cargo_payment[i]; |
|
440 |
_cargo_payment_rates_frac[i] = 0; |
|
441 |
} |
|
442 |
||
443 |
_cargoc.transit_days_1[i] = lpd->transit_days_table_1[i]; |
|
444 |
_cargoc.transit_days_2[i] = lpd->transit_days_table_2[i]; |
|
445 |
} |
|
446 |
} |
|
447 |
||
448 |
||
449 |
void OnNewDay_Train(Vehicle *v); |
|
450 |
void OnNewDay_RoadVeh(Vehicle *v); |
|
451 |
void OnNewDay_Aircraft(Vehicle *v); |
|
452 |
void OnNewDay_Ship(Vehicle *v); |
|
1095 | 453 |
static void OnNewDay_EffectVehicle(Vehicle *v) { /* empty */ } |
0 | 454 |
void OnNewDay_DisasterVehicle(Vehicle *v); |
455 |
||
456 |
typedef void OnNewVehicleDayProc(Vehicle *v); |
|
457 |
||
458 |
static OnNewVehicleDayProc * _on_new_vehicle_day_proc[] = { |
|
459 |
OnNewDay_Train, |
|
460 |
OnNewDay_RoadVeh, |
|
461 |
OnNewDay_Ship, |
|
462 |
OnNewDay_Aircraft, |
|
463 |
OnNewDay_EffectVehicle, |
|
464 |
OnNewDay_DisasterVehicle, |
|
465 |
}; |
|
466 |
||
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
|
467 |
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
|
468 |
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
|
469 |
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
|
470 |
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
|
471 |
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
|
472 |
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
|
473 |
void StationMonthlyLoop(void); |
0 | 474 |
|
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
|
475 |
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
|
476 |
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
|
477 |
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
|
478 |
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
|
479 |
void ShipsYearlyLoop(void); |
0 | 480 |
|
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
|
481 |
void WaypointsDailyLoop(void); |
0 | 482 |
|
483 |
||
484 |
static const uint16 _autosave_months[] = { |
|
485 |
0, // never |
|
486 |
0xFFF, // every month |
|
487 |
0x249, // every 3 months |
|
488 |
0x041, // every 6 months |
|
489 |
0x001, // every 12 months |
|
490 |
}; |
|
491 |
||
1537
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
492 |
/** |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
493 |
* Runs the day_proc of 'amount' vehicles. |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
494 |
*/ |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
495 |
static void RunVehicleDayProc(uint amount) |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
496 |
{ |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
497 |
Vehicle *v; |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
498 |
VehicleID ctr; |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
499 |
uint i; |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
500 |
|
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
501 |
ctr = _vehicle_id_ctr_day; |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
502 |
|
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
503 |
/* If the CTR is already over the size of the pool, don't even run the for-loop */ |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
504 |
if (ctr >= GetVehiclePoolSize()) { |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
505 |
_vehicle_id_ctr_day += amount; |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
506 |
return; |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
507 |
} |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
508 |
|
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
509 |
for (i = 0; i < amount; i++, ctr++) { |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
510 |
/* Skip non-existing vehicles */ |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
511 |
if (ctr >= GetVehiclePoolSize()) { |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
512 |
_vehicle_id_ctr_day += amount; |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
513 |
return; |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
514 |
} |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
515 |
|
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
516 |
v = GetVehicle(ctr); |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
517 |
if (v->type != 0) |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
518 |
_on_new_vehicle_day_proc[v->type - 0x10](v); |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
519 |
} |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
520 |
|
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
521 |
_vehicle_id_ctr_day = ctr; |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
522 |
} |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
523 |
|
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
|
524 |
void IncreaseDate(void) |
0 | 525 |
{ |
1537
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
526 |
uint32 total_vehicles = (1 << _vehicle_pool.block_size_bits) * _vehicle_pool.max_blocks; |
0 | 527 |
YearMonthDay ymd; |
528 |
||
529 |
if (_game_mode == GM_MENU) { |
|
530 |
_tick_counter++; |
|
531 |
return; |
|
532 |
} |
|
533 |
||
1537
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
534 |
RunVehicleDayProc(total_vehicles / DAY_TICKS); |
0 | 535 |
|
536 |
/* increase day, and check if a new day is there? */ |
|
537 |
_tick_counter++; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
538 |
|
1537
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
539 |
_date_fract++; |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
540 |
if (_date_fract < DAY_TICKS) |
0 | 541 |
return; |
1537
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
542 |
_date_fract = 0; |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
543 |
|
0 | 544 |
/* yeah, increse day counter and call various daily loops */ |
545 |
_date++; |
|
546 |
||
1537
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
547 |
/* We have a hole because of rounding errors, between the last vehicle checked and the max amount |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
548 |
* of vehicles.. correct for that problem here */ |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
549 |
RunVehicleDayProc(total_vehicles - _vehicle_id_ctr_day); |
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
550 |
|
edd70cde5f84
(svn r2041) -Fix: not all vehicles did get a day_proc call (because of rounding errors)
truelight
parents:
1529
diff
changeset
|
551 |
assert(_vehicle_id_ctr_day == total_vehicles); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
552 |
_vehicle_id_ctr_day = 0; |
105 | 553 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
507
diff
changeset
|
554 |
TextMessageDailyLoop(); |
0 | 555 |
|
556 |
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
|
557 |
WaypointsDailyLoop(); |
0 | 558 |
|
559 |
if (_game_mode != GM_MENU) { |
|
560 |
InvalidateWindowWidget(WC_STATUS_BAR, 0, 0); |
|
561 |
EnginesDailyLoop(); |
|
562 |
} |
|
563 |
||
564 |
/* check if we entered a new month? */ |
|
565 |
ConvertDayToYMD(&ymd, _date); |
|
566 |
if ((byte)ymd.month == _cur_month) |
|
567 |
return; |
|
568 |
_cur_month = ymd.month; |
|
569 |
||
570 |
/* yes, call various monthly loops */ |
|
571 |
if (_game_mode != GM_MENU) { |
|
572 |
if (HASBIT(_autosave_months[_opt.autosave], _cur_month)) { |
|
573 |
_do_autosave = true; |
|
574 |
RedrawAutosave(); |
|
575 |
} |
|
576 |
||
577 |
PlayersMonthlyLoop(); |
|
578 |
EnginesMonthlyLoop(); |
|
579 |
TownsMonthlyLoop(); |
|
580 |
IndustryMonthlyLoop(); |
|
581 |
StationMonthlyLoop(); |
|
690
9f449a6b133e
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
582 |
#ifdef ENABLE_NETWORK |
9f449a6b133e
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
583 |
if (_network_server) |
9f449a6b133e
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
584 |
NetworkServerMonthlyLoop(); |
9f449a6b133e
(svn r1131) -Add: [Network] Autoclean_companies (set it with 'set autoclean_companies on/off').
truelight
parents:
679
diff
changeset
|
585 |
#endif /* ENABLE_NETWORK */ |
0 | 586 |
} |
587 |
||
588 |
/* check if we entered a new year? */ |
|
589 |
if ((byte)ymd.year == _cur_year) |
|
590 |
return; |
|
591 |
_cur_year = ymd.year; |
|
592 |
||
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
593 |
/* yes, call various yearly loops */ |
0 | 594 |
|
595 |
PlayersYearlyLoop(); |
|
596 |
TrainsYearlyLoop(); |
|
597 |
RoadVehiclesYearlyLoop(); |
|
598 |
AircraftYearlyLoop(); |
|
599 |
ShipsYearlyLoop(); |
|
785
e9ca2bcc9c8f
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
770
diff
changeset
|
600 |
#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
|
601 |
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
|
602 |
NetworkServerYearlyLoop(); |
e9ca2bcc9c8f
(svn r1252) -Add: [Network] With 'set restart_game_date' you can set the date for in
truelight
parents:
770
diff
changeset
|
603 |
#endif /* ENABLE_NETWORK */ |
0 | 604 |
|
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
|
605 |
/* 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
|
606 |
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
|
607 |
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
|
608 |
/* 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
|
609 |
} 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
|
610 |
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
|
611 |
_cur_year = MAX_YEAR_END; |
0 | 612 |
_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
|
613 |
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
|
614 |
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
|
615 |
} |
1595
b1a8323c1024
(svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents:
1542
diff
changeset
|
616 |
|
b1a8323c1024
(svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents:
1542
diff
changeset
|
617 |
/* Because the _date wraps here, and text-messages expire by game-days, we have to clean out |
b1a8323c1024
(svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents:
1542
diff
changeset
|
618 |
* all of them if the date is set back, else those messages will hang for ever */ |
b1a8323c1024
(svn r2099) -Fix: no longer chat-messages hang when the game wraps around 2090
truelight
parents:
1542
diff
changeset
|
619 |
InitTextMessage(); |
0 | 620 |
} |
621 |
||
622 |
if (_patches.auto_euro) |
|
623 |
CheckSwitchToEuro(); |
|
624 |
||
625 |
/* XXX: check if year 2050 was reached */ |
|
626 |
} |
|
627 |
||
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
628 |
int FindFirstBit(uint32 value) |
0 | 629 |
{ |
826 | 630 |
// 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
|
631 |
// 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
|
632 |
// Btw, the macro FINDFIRSTBIT is better to use when your value is |
826 | 633 |
// not more than 128. |
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
634 |
byte i = 0; |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
635 |
if (value & 0xffff0000) { value >>= 16; i += 16; } |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
636 |
if (value & 0x0000ff00) { value >>= 8; i += 8; } |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
637 |
if (value & 0x000000f0) { value >>= 4; i += 4; } |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
638 |
if (value & 0x0000000c) { value >>= 2; i += 2; } |
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
105
diff
changeset
|
639 |
if (value & 0x00000002) { i += 1; } |
0 | 640 |
return i; |
641 |
} |
|
642 |
||
1217
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
643 |
//!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
|
644 |
//!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
|
645 |
//!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
|
646 |
//!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
|
647 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
648 |
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
|
649 |
{ |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
650 |
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
|
651 |
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
|
652 |
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
|
653 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
654 |
nmemb--; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
655 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
656 |
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
|
657 |
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
|
658 |
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
|
659 |
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
|
660 |
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
|
661 |
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
|
662 |
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
|
663 |
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
|
664 |
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
|
665 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
666 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
667 |
} |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
668 |
|
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
669 |
free(buffer); |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
670 |
buffer = NULL; |
ab9f02a224ab
(svn r1721) -Feature: It is now possible to build multiple road stations (up to 8) on
celestar
parents:
1178
diff
changeset
|
671 |
} |
0 | 672 |
|
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
|
673 |
static void Save_NAME(void) |
0 | 674 |
{ |
675 |
int i; |
|
676 |
||
1375
f13d8247928c
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
677 |
for (i = 0; i != lengthof(_name_array); ++i) { |
f13d8247928c
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
678 |
if (_name_array[i][0] != '\0') { |
0 | 679 |
SlSetArrayIndex(i); |
1375
f13d8247928c
(svn r1879) Revise name handling, no functional changes
tron
parents:
1328
diff
changeset
|
680 |
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
|
681 |
} |
0 | 682 |
} |
683 |
} |
|
684 |
||
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
|
685 |
static void Load_NAME(void) |
0 | 686 |
{ |
687 |
int index; |
|
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
688 |
|
0 | 689 |
while ((index = SlIterateArray()) != -1) { |
690 |
SlArray(_name_array[index],SlGetFieldLength(),SLE_UINT8); |
|
691 |
} |
|
692 |
} |
|
693 |
||
1881
023a134a4b12
(svn r2387) - CodeChange: made the saveload code more readable and also removed the 'byte' saveload arrays which means you can save an array of more than 255 elements, or bigger structs than 255 bytes. This doesn't yet solve the problem that a chunk can be a maximum of 16384 big.
Darkvater
parents:
1812
diff
changeset
|
694 |
static const SaveLoad _game_opt_desc[] = { |
0 | 695 |
// added a new difficulty option (town attitude) in version 4 |
696 |
SLE_CONDARR(GameOptions,diff, SLE_FILE_I16 | SLE_VAR_I32, 17, 0, 3), |
|
697 |
SLE_CONDARR(GameOptions,diff, SLE_FILE_I16 | SLE_VAR_I32, 18, 4, 255), |
|
698 |
SLE_VAR(GameOptions,diff_level, SLE_UINT8), |
|
699 |
SLE_VAR(GameOptions,currency, SLE_UINT8), |
|
700 |
SLE_VAR(GameOptions,kilometers, SLE_UINT8), |
|
701 |
SLE_VAR(GameOptions,town_name, SLE_UINT8), |
|
702 |
SLE_VAR(GameOptions,landscape, SLE_UINT8), |
|
703 |
SLE_VAR(GameOptions,snow_line, SLE_UINT8), |
|
704 |
SLE_VAR(GameOptions,autosave, SLE_UINT8), |
|
705 |
SLE_VAR(GameOptions,road_side, SLE_UINT8), |
|
706 |
SLE_END() |
|
707 |
}; |
|
708 |
||
709 |
// 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
|
710 |
static void SaveLoad_OPTS(void) |
0 | 711 |
{ |
201
c40d343115f8
(svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents:
179
diff
changeset
|
712 |
SlObject(&_opt, _game_opt_desc); |
0 | 713 |
} |
714 |
||
715 |
||
716 |
static const SaveLoadGlobVarList _date_desc[] = { |
|
717 |
{&_date, SLE_UINT16, 0, 255}, |
|
718 |
{&_date_fract, SLE_UINT16, 0, 255}, |
|
719 |
{&_tick_counter, SLE_UINT16, 0, 255}, |
|
720 |
{&_vehicle_id_ctr_day, SLE_UINT16, 0, 255}, |
|
721 |
{&_age_cargo_skip_counter, SLE_UINT8, 0, 255}, |
|
722 |
{&_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
|
723 |
{&_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
|
724 |
{&_cur_tileloop_tile, SLE_UINT32, 6, 255}, |
0 | 725 |
{&_disaster_delay, SLE_UINT16, 0, 255}, |
726 |
{&_station_tick_ctr, SLE_UINT16, 0, 255}, |
|
206 | 727 |
{&_random_seeds[0][0], SLE_UINT32, 0, 255}, |
728 |
{&_random_seeds[0][1], SLE_UINT32, 0, 255}, |
|
1526
93edd03da666
(svn r2030) -Fix: Save _cur_town_ctr with all its bits to prevent desyncs
celestar
parents:
1517
diff
changeset
|
729 |
{&_cur_town_ctr, SLE_FILE_U8 | SLE_VAR_U32, 0, 9}, |
93edd03da666
(svn r2030) -Fix: Save _cur_town_ctr with all its bits to prevent desyncs
celestar
parents:
1517
diff
changeset
|
730 |
{&_cur_town_ctr, SLE_UINT32, 10, 255}, |
0 | 731 |
{&_cur_player_tick_index, SLE_FILE_U8 | SLE_VAR_UINT, 0, 255}, |
732 |
{&_next_competitor_start, SLE_FILE_U16 | SLE_VAR_UINT, 0, 255}, |
|
733 |
{&_trees_tick_ctr, SLE_UINT8, 0, 255}, |
|
734 |
{&_pause, SLE_UINT8, 4, 255}, |
|
1529
be4a2259d2ff
(svn r2033) - Fix: Fix some more desync by saving the town growth frequency iterator _cur_town_iter. Needed to bump a svg revision for that thanks to the braindead SlGlob thing, or at least I don't know how to do it without bumping it.
pasky
parents:
1526
diff
changeset
|
735 |
{&_cur_town_iter, SLE_UINT32, 11, 255}, |
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
736 |
{NULL, 0, 0, 0} |
0 | 737 |
}; |
738 |
||
739 |
// Save load date related variables as well as persistent tick counters |
|
740 |
// 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
|
741 |
static void SaveLoad_DATE(void) |
0 | 742 |
{ |
743 |
SlGlobList(_date_desc); |
|
744 |
} |
|
745 |
||
746 |
||
747 |
static const SaveLoadGlobVarList _view_desc[] = { |
|
1175
d43ab7ccdc16
(svn r1677) Forgot to change the save/load size for 3 variables
tron
parents:
1121
diff
changeset
|
748 |
{&_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
|
749 |
{&_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
|
750 |
{&_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
|
751 |
{&_saved_scrollpos_y, SLE_INT32, 6, 255}, |
179
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
752 |
{&_saved_scrollpos_zoom, SLE_UINT8, 0, 255}, |
003096efeb9d
(svn r180) -Fix: some more warning fixes for C99 (Tron)
darkvater
parents:
164
diff
changeset
|
753 |
{NULL, 0, 0, 0} |
0 | 754 |
}; |
755 |
||
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_VIEW(void) |
0 | 757 |
{ |
758 |
SlGlobList(_view_desc); |
|
759 |
} |
|
760 |
||
1218 | 761 |
static uint32 _map_dim_x; |
762 |
static uint32 _map_dim_y; |
|
763 |
||
764 |
static const SaveLoadGlobVarList _map_dimensions[] = { |
|
765 |
{&_map_dim_x, SLE_UINT32, 6, 255}, |
|
766 |
{&_map_dim_y, SLE_UINT32, 6, 255}, |
|
767 |
{NULL, 0, 0, 0} |
|
768 |
}; |
|
769 |
||
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
770 |
static void Save_MAPS(void) |
1218 | 771 |
{ |
1219
6a1f8d818d58
(svn r1723) Save the map size in tiles, not number of bits
tron
parents:
1218
diff
changeset
|
772 |
_map_dim_x = MapSizeX(); |
6a1f8d818d58
(svn r1723) Save the map size in tiles, not number of bits
tron
parents:
1218
diff
changeset
|
773 |
_map_dim_y = MapSizeY(); |
1218 | 774 |
SlGlobList(_map_dimensions); |
775 |
} |
|
776 |
||
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
777 |
static void Load_MAPS(void) |
1218 | 778 |
{ |
779 |
SlGlobList(_map_dimensions); |
|
2051 | 780 |
AllocateMap(_map_dim_x, _map_dim_y); |
1218 | 781 |
} |
782 |
||
0 | 783 |
|
2050
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
784 |
static void SaveLoad_MapByte(byte *m) |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
785 |
{ |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
786 |
uint size = MapSize(), i; |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
787 |
byte buf[4096]; |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
788 |
if (_sl.save) { |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
789 |
SlSetLength(size); |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
790 |
for(;size;size -= lengthof(buf)) { |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
791 |
for (i = 0; i != lengthof(buf); i++) { buf[i] = *m; m += sizeof(Tile); } |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
792 |
SlArray(buf, lengthof(buf), SLE_UINT8); |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
793 |
} |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
794 |
} else { |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
795 |
for(;size;size -= lengthof(buf)) { |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
796 |
SlArray(buf, lengthof(buf), SLE_UINT8); |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
797 |
for (i = 0; i != lengthof(buf); i++) { *m = buf[i]; m += sizeof(Tile); } |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
798 |
} |
817
4f9377b7fd2b
(svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents:
785
diff
changeset
|
799 |
} |
0 | 800 |
} |
801 |
||
2050
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
802 |
static void SaveLoad_MAPT(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
|
803 |
{ |
2050
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
804 |
SaveLoad_MapByte(&_m[0].type_height); |
0 | 805 |
} |
806 |
||
2050
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
807 |
static void SaveLoad_MAPO(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
|
808 |
{ |
2050
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
809 |
SaveLoad_MapByte(&_m[0].owner); |
0 | 810 |
} |
811 |
||
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
812 |
static void Load_MAP2(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
|
813 |
{ |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
814 |
uint size = MapSize(); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
815 |
uint i; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
816 |
|
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
817 |
for (i = 0; i != size;) { |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
818 |
uint16 buf[4096]; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
819 |
uint j; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
820 |
|
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
821 |
SlArray(buf, lengthof(buf), |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
822 |
/* In those versions the m2 was 8 bits */ |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
823 |
_sl.version < 5 ? SLE_FILE_U8 | SLE_VAR_U16 : SLE_UINT16 |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
824 |
); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
825 |
for (j = 0; j != lengthof(buf); j++) _m[i++].m2 = buf[j]; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
826 |
} |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
827 |
} |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
828 |
|
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
829 |
static void Save_MAP2(void) |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
830 |
{ |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
831 |
uint size = MapSize(); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
832 |
uint i; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
833 |
|
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
834 |
SlSetLength(size * sizeof(_m[0].m2)); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
835 |
for (i = 0; i != size;) { |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
836 |
uint16 buf[4096]; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
837 |
uint j; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
838 |
|
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
839 |
for (j = 0; j != lengthof(buf); j++) buf[j] = _m[i++].m2; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
840 |
SlArray(buf, lengthof(buf), SLE_UINT16); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
841 |
} |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
842 |
} |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
843 |
|
2050
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
844 |
static void SaveLoad_MAP3(void) |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
845 |
{ |
2050
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
846 |
SaveLoad_MapByte(&_m[0].m3); |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
847 |
} |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
848 |
|
2050
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
849 |
static void SaveLoad_MAP4(void) |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
850 |
{ |
2050
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
851 |
SaveLoad_MapByte(&_m[0].m4); |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
852 |
} |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
853 |
|
2050
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
854 |
static void SaveLoad_MAP5(void) |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
855 |
{ |
2050
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
856 |
SaveLoad_MapByte(&_m[0].m5); |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
857 |
} |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
858 |
|
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
859 |
static void Load_MAPE(void) |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
860 |
{ |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
861 |
uint size = MapSize(); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
862 |
uint i; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
863 |
|
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
864 |
for (i = 0; i != size;) { |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
865 |
uint8 buf[1024]; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
866 |
uint j; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
867 |
|
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
868 |
SlArray(buf, lengthof(buf), SLE_UINT8); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
869 |
for (j = 0; j != lengthof(buf); j++) { |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
870 |
_m[i++].extra = GB(buf[j], 0, 2); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
871 |
_m[i++].extra = GB(buf[j], 2, 2); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
872 |
_m[i++].extra = GB(buf[j], 4, 2); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
873 |
_m[i++].extra = GB(buf[j], 6, 2); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
874 |
} |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
875 |
} |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
876 |
} |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
877 |
|
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
878 |
static void Save_MAPE(void) |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
879 |
{ |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
880 |
uint size = MapSize(); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
881 |
uint i; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
882 |
|
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
883 |
SlSetLength(size / 4); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
884 |
for (i = 0; i != size;) { |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
885 |
uint8 buf[1024]; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
886 |
uint j; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
887 |
|
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
888 |
for (j = 0; j != lengthof(buf); j++) { |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
889 |
buf[j] = _m[i++].extra << 0; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
890 |
buf[j] |= _m[i++].extra << 2; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
891 |
buf[j] |= _m[i++].extra << 4; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
892 |
buf[j] |= _m[i++].extra << 6; |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
893 |
} |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
894 |
SlArray(buf, lengthof(buf), SLE_UINT8); |
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
895 |
} |
0 | 896 |
} |
897 |
||
898 |
||
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
|
899 |
static void Save_CHTS(void) |
0 | 900 |
{ |
901 |
byte count = sizeof(_cheats)/sizeof(Cheat); |
|
902 |
Cheat* cht = (Cheat*) &_cheats; |
|
903 |
Cheat* cht_last = &cht[count]; |
|
904 |
||
905 |
SlSetLength(count*2); |
|
906 |
for(; cht != cht_last; cht++) { |
|
907 |
SlWriteByte(cht->been_used); |
|
908 |
SlWriteByte(cht->value); |
|
909 |
} |
|
910 |
} |
|
911 |
||
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
|
912 |
static void Load_CHTS(void) |
0 | 913 |
{ |
914 |
Cheat* cht = (Cheat*) &_cheats; |
|
915 |
||
916 |
uint count = SlGetFieldLength()/2; |
|
917 |
for(; count; count--, cht++) |
|
918 |
{ |
|
919 |
cht->been_used = (byte)SlReadByte(); |
|
920 |
cht->value = (byte)SlReadByte(); |
|
921 |
} |
|
922 |
} |
|
923 |
||
924 |
||
925 |
const ChunkHandler _misc_chunk_handlers[] = { |
|
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
926 |
{ 'MAPS', Save_MAPS, Load_MAPS, CH_RIFF }, |
2050
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
927 |
{ 'MAPT', SaveLoad_MAPT, SaveLoad_MAPT, CH_RIFF }, |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
928 |
{ 'MAPO', SaveLoad_MAPO, SaveLoad_MAPO, CH_RIFF }, |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
929 |
{ 'MAP2', Save_MAP2, Load_MAP2, CH_RIFF }, |
2050
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
930 |
{ 'M3LO', SaveLoad_MAP3, SaveLoad_MAP3, CH_RIFF }, |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
931 |
{ 'M3HI', SaveLoad_MAP4, SaveLoad_MAP4, CH_RIFF }, |
947934d248c5
(svn r2559) Cleaned up new saveload code for the map
ludde
parents:
2049
diff
changeset
|
932 |
{ 'MAP5', SaveLoad_MAP5, SaveLoad_MAP5, CH_RIFF }, |
2049
ad0d49c916d4
(svn r2558) Change the internal map format from 7 arrays to one array of structs, this doesn't change the saved format for now. It's a stepping stone for further changes.
tron
parents:
1999
diff
changeset
|
933 |
{ 'MAPE', Save_MAPE, Load_MAPE, CH_RIFF }, |
0 | 934 |
|
935 |
{ 'NAME', Save_NAME, Load_NAME, CH_ARRAY}, |
|
936 |
{ 'DATE', SaveLoad_DATE, SaveLoad_DATE, CH_RIFF}, |
|
937 |
{ 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, CH_RIFF}, |
|
938 |
{ 'OPTS', SaveLoad_OPTS, SaveLoad_OPTS, CH_RIFF}, |
|
939 |
{ 'CHTS', Save_CHTS, Load_CHTS, CH_RIFF | CH_LAST} |
|
940 |
}; |