misc.c
author glx
Mon, 24 Sep 2007 03:08:47 +0000
branch0.5
changeset 5545 f42dc59a45f5
parent 5415 a7e0e4e75be2
permissions -rw-r--r--
(svn r11153) [0.5] -Fix [FS#1251]: incorrect usage of {G} tag in slovak translation
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1881
diff changeset
     4
#include "openttd.h"
2308
4ed48829d8e8 (svn r2832) Missing #include
tron
parents: 2295
diff changeset
     5
#include "currency.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2159
diff changeset
     6
#include "functions.h"
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2484
diff changeset
     7
#include "news.h"
2191
cb4985f271ae (svn r2706) Fix !WITH_NETWORK build
tron
parents: 2186
diff changeset
     8
#include "player.h"
1375
f13d8247928c (svn r1879) Revise name handling, no functional changes
tron
parents: 1328
diff changeset
     9
#include "string.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 500
diff changeset
    10
#include "table/strings.h"
1914
5ede46fd496f (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1891
diff changeset
    11
#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
    12
#include "map.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "vehicle.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
#include "saveload.h"
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 826
diff changeset
    15
#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
    16
#include "vehicle_gui.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2112
diff changeset
    17
#include "variables.h"
2706
d31bd0aa0096 (svn r3250) -Fix: AIs weren't uninitialized when a new game was loaded
truelight
parents: 2685
diff changeset
    18
#include "ai/ai.h"
3616
7ba7353d6561 (svn r4513) Codechange : Assemble a bit the scattered parts of Cargo types.
belugas
parents: 3355
diff changeset
    19
#include "table/landscape_const.h"
4261
2ec8f5a9747b (svn r5887) -Cleanup: move date related functions, defines and variables to date.[ch]
rubidium
parents: 3977
diff changeset
    20
#include "date.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
1328
e069d2db0e4c (svn r1832) Next byte -> char iteration: custom names
tron
parents: 1313
diff changeset
    22
char _name_array[512][32];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
2073
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 2063
diff changeset
    24
#ifndef MERSENNE_TWISTER
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 2063
diff changeset
    25
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 507
diff changeset
    26
#ifdef RANDOM_DEBUG
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 507
diff changeset
    27
#include "network_data.h"
1120
ea3bf8bc6678 (svn r1621) -Fix: fixed some compiler warnings for the random-debug-switch
truelight
parents: 1095
diff changeset
    28
uint32 DoRandom(int line, const char *file)
2073
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 2063
diff changeset
    29
#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
    30
uint32 Random(void)
2073
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 2063
diff changeset
    31
#endif // RANDOM_DEBUG
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 507
diff changeset
    32
{
1121
b0dbb4c15e12 (svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents: 1120
diff changeset
    33
b0dbb4c15e12 (svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents: 1120
diff changeset
    34
uint32 s;
b0dbb4c15e12 (svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents: 1120
diff changeset
    35
uint32 t;
b0dbb4c15e12 (svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents: 1120
diff changeset
    36
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 507
diff changeset
    37
#ifdef RANDOM_DEBUG
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 507
diff changeset
    38
	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
    39
		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
    40
#endif
32fcaaf9f4ef (svn r266) -Fix: hopefully fixed the desync problem nicely (and reverted the
truelight
parents: 256
diff changeset
    41
1121
b0dbb4c15e12 (svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents: 1120
diff changeset
    42
	s = _random_seeds[0][0];
b0dbb4c15e12 (svn r1622) -Fix: variables can't be defined after a statement.. (Igor2Code)
truelight
parents: 1120
diff changeset
    43
	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
    44
	_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
    45
	return _random_seeds[0][1] = ROR(s, 3) - 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
}
2073
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 2063
diff changeset
    47
#endif // MERSENNE_TWISTER
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
2073
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 2063
diff changeset
    49
#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
    50
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
    51
{
2484
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2430
diff changeset
    52
	return GB(DoRandom(line, file), 0, 16) * max >> 16;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 507
diff changeset
    53
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 507
diff changeset
    54
#else
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    55
uint RandomRange(uint max)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
{
2484
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2430
diff changeset
    57
	return GB(Random(), 0, 16) * max >> 16;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    58
}
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 507
diff changeset
    59
#endif
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    60
2073
899419c9b997 (svn r2583) Move OS specific code out of misc.c
ludde
parents: 2063
diff changeset
    61
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
    62
uint32 InteractiveRandom(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    63
{
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 201
diff changeset
    64
	uint32 t = _random_seeds[1][1];
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 201
diff changeset
    65
	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
    66
	_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
    67
	return _random_seeds[1][1] = ROR(s, 3) - 1;
206
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 201
diff changeset
    68
}
7f8c26d8526b (svn r207) -Codechange: randomizer handling
signde
parents: 201
diff changeset
    69
239
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 206
diff changeset
    70
uint InteractiveRandomRange(uint max)
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 206
diff changeset
    71
{
2484
8e0c88a833fb (svn r3010) Get rid of quite some dubious casts, either by using GB(), proper types or just removing them
tron
parents: 2430
diff changeset
    72
	return GB(InteractiveRandom(), 0, 16) * max >> 16;
239
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 206
diff changeset
    73
}
23958632a582 (svn r240) -Fix: desync on subsidy generation
signde
parents: 206
diff changeset
    74
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
    75
void InitializeVehicles(void);
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1538
diff changeset
    76
void InitializeWaypoints(void);
4347
79b04c2cef95 (svn r6048) -Codechange: all InitializeXXX are plural, just not Depot
truelight
parents: 4344
diff changeset
    77
void InitializeDepots(void);
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2828
diff changeset
    78
void InitializeEngines(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
    79
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
    80
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
    81
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
    82
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
    83
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
    84
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
    85
void InitializeIndustries(void);
3622
e1c16777dacb (svn r4520) -Fix: Did last commit in the wrong branch. Repair and shame on me.
celestar
parents: 3617
diff changeset
    86
void InitializeMainGui(void);
2051
44b6b091beb3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2050
diff changeset
    87
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
    88
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
    89
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
    90
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
    91
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
    92
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
    93
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
    94
static void InitializeCheats(void);
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
    95
void InitializeNPF(void);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
2828
996de8e891c7 (svn r3376) -Codechange: made enums for GenerateWorld and InitializeGame 'mode'
truelight
parents: 2706
diff changeset
    97
void InitializeGame(int mode, uint size_x, uint size_y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    98
{
2051
44b6b091beb3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2050
diff changeset
    99
	AllocateMap(size_x, size_y);
44b6b091beb3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2050
diff changeset
   100
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 826
diff changeset
   101
	AddTypeToEngines(); // make sure all engines have a type
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 900
diff changeset
   102
1914
5ede46fd496f (svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents: 1891
diff changeset
   103
	SetObjectToPlace(SPR_CURSOR_ZZZ, 0, 0, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
	_pause = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
	_fast_forward = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
	_tick_counter = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
	_date_fract = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
	_cur_tileloop_tile = 0;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 179
diff changeset
   110
2828
996de8e891c7 (svn r3376) -Codechange: made enums for GenerateWorld and InitializeGame 'mode'
truelight
parents: 2706
diff changeset
   111
	if ((mode & IG_DATE_RESET) == IG_DATE_RESET) {
4295
66d2c96579a6 (svn r5928) -Cleanup: remove ConvertIntDate and use ConvertYMDToDate as ConvertIntDate was only called with Years.
rubidium
parents: 4285
diff changeset
   112
		SetDate(ConvertYMDToDate(_patches.starting_year, 0, 1));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
2848
cb4b1cc0bf65 (svn r3396) - Autoreplace changes:
peter1138
parents: 2828
diff changeset
   115
	InitializeEngines();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
	InitializeVehicles();
1542
2ca6d1624e6d (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1538
diff changeset
   117
	InitializeWaypoints();
4347
79b04c2cef95 (svn r6048) -Codechange: all InitializeXXX are plural, just not Depot
truelight
parents: 4344
diff changeset
   118
	InitializeDepots();
1024
9b06b01490a4 (svn r1525) -Codechange: rewrote the _order_array, now it can be made dynamic.
truelight
parents: 1009
diff changeset
   119
	InitializeOrders();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
	InitNewsItemStructs();
2051
44b6b091beb3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2050
diff changeset
   122
	InitializeLandscape();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
	InitializeClearLand();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
	InitializeRailGui();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
	InitializeRoadGui();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
	InitializeAirportGui();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
	InitializeDockGui();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
	InitializeTowns();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   129
	InitializeTrees();
988
2482369a61ff (svn r1486) -Codechange: moved all 'signs' stuff to signs.c/h and prepared it for
truelight
parents: 983
diff changeset
   130
	InitializeSigns();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
	InitializeStations();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
	InitializeIndustries();
3622
e1c16777dacb (svn r4520) -Fix: Did last commit in the wrong branch. Repair and shame on me.
celestar
parents: 3617
diff changeset
   133
	InitializeMainGui();
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 179
diff changeset
   134
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
	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
   136
	InitializeVehiclesGuiList();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
	InitializeTrains();
1247
01711347f9ac (svn r1751) - Feature: New PathFinder (NPF).
matthijs
parents: 1245
diff changeset
   138
	InitializeNPF();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
2706
d31bd0aa0096 (svn r3250) -Fix: AIs weren't uninitialized when a new game was loaded
truelight
parents: 2685
diff changeset
   140
	AI_Initialize();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   141
	InitializePlayers();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   142
	InitializeCheats();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   144
	InitTextEffects();
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 507
diff changeset
   145
	InitTextMessage();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   146
	InitializeAnimatedTiles();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
	InitializeLandscapeVariables(false);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
	ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
4862
b45c1e638e7f (svn r6788) - Codechange: Add and use a function to test if a string ID is a custom name.
peter1138
parents: 4383
diff changeset
   153
bool IsCustomName(StringID id)
b45c1e638e7f (svn r6788) - Codechange: Add and use a function to test if a string ID is a custom name.
peter1138
parents: 4383
diff changeset
   154
{
b45c1e638e7f (svn r6788) - Codechange: Add and use a function to test if a string ID is a custom name.
peter1138
parents: 4383
diff changeset
   155
	return GB(id, 11, 5) == 15;
b45c1e638e7f (svn r6788) - Codechange: Add and use a function to test if a string ID is a custom name.
peter1138
parents: 4383
diff changeset
   156
}
b45c1e638e7f (svn r6788) - Codechange: Add and use a function to test if a string ID is a custom name.
peter1138
parents: 4383
diff changeset
   157
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   158
void DeleteName(StringID id)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
{
4862
b45c1e638e7f (svn r6788) - Codechange: Add and use a function to test if a string ID is a custom name.
peter1138
parents: 4383
diff changeset
   160
	if (IsCustomName(id)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   161
		memset(_name_array[id & 0x1FF], 0, sizeof(_name_array[id & 0x1FF]));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4862
diff changeset
   165
char *GetName(char *buff, StringID id, const char* last)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
{
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4862
diff changeset
   167
	return strecpy(buff, _name_array[id & ~0x600], last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   168
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   169
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
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
   171
static void InitializeCheats(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   172
{
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 179
diff changeset
   173
	memset(&_cheats, 0, sizeof(Cheats));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
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
   177
static void InitializeNameMgr(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   178
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   179
	memset(_name_array, 0, sizeof(_name_array));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
1328
e069d2db0e4c (svn r1832) Next byte -> char iteration: custom names
tron
parents: 1313
diff changeset
   182
StringID RealAllocateName(const char *name, byte skip, bool check_double)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   183
{
1375
f13d8247928c (svn r1879) Revise name handling, no functional changes
tron
parents: 1328
diff changeset
   184
	char (*free_item)[lengthof(*_name_array)] = NULL;
f13d8247928c (svn r1879) Revise name handling, no functional changes
tron
parents: 1328
diff changeset
   185
	char (*i)[lengthof(*_name_array)];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   186
1375
f13d8247928c (svn r1879) Revise name handling, no functional changes
tron
parents: 1328
diff changeset
   187
	for (i = _name_array; i != endof(_name_array); ++i) {
f13d8247928c (svn r1879) Revise name handling, no functional changes
tron
parents: 1328
diff changeset
   188
		if ((*i)[0] == '\0') {
f13d8247928c (svn r1879) Revise name handling, no functional changes
tron
parents: 1328
diff changeset
   189
			if (free_item == NULL) free_item = i;
f13d8247928c (svn r1879) Revise name handling, no functional changes
tron
parents: 1328
diff changeset
   190
		} 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
   191
			_error_message = STR_0132_CHOSEN_NAME_IN_USE_ALREADY;
f13d8247928c (svn r1879) Revise name handling, no functional changes
tron
parents: 1328
diff changeset
   192
			return 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   193
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   194
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
1375
f13d8247928c (svn r1879) Revise name handling, no functional changes
tron
parents: 1328
diff changeset
   196
	if (free_item != NULL) {
f13d8247928c (svn r1879) Revise name handling, no functional changes
tron
parents: 1328
diff changeset
   197
		ttd_strlcpy(*free_item, name, lengthof(*free_item));
f13d8247928c (svn r1879) Revise name handling, no functional changes
tron
parents: 1328
diff changeset
   198
		return (free_item - _name_array) | 0x7800 | (skip << 8);
f13d8247928c (svn r1879) Revise name handling, no functional changes
tron
parents: 1328
diff changeset
   199
	} else {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
		_error_message = STR_0131_TOO_MANY_NAMES_DEFINED;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
		return 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   205
void ConvertNameArray(void)
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   206
{
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   207
	uint i;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   208
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   209
	for (i = 0; i < lengthof(_name_array); i++) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   210
		const char *strfrom = _name_array[i];
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   211
		char tmp[sizeof(*_name_array)];
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   212
		char *strto = tmp;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   213
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   214
		for (; *strfrom != '\0'; strfrom++) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   215
			WChar c = (byte)*strfrom;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   216
			switch (c) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   217
				case 0xA4: c = 0x20AC; break; // Euro
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   218
				case 0xA6: c = 0x0160; break; // S with caron
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   219
				case 0xA8: c = 0x0161; break; // s with caron
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   220
				case 0xB4: c = 0x017D; break; // Z with caron
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   221
				case 0xB8: c = 0x017E; break; // z with caron
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   222
				case 0xBC: c = 0x0152; break; // OE ligature
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   223
				case 0xBD: c = 0x0153; break; // oe ligature
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   224
				case 0xBE: c = 0x0178; break; // Y with diaresis
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   225
				default: break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   226
			}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   227
			if (strto + Utf8CharLen(c) > lastof(tmp)) break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   228
			strto += Utf8Encode(strto, c);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   229
		}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   230
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   231
		/* Terminate the new string and copy it back to the name array */
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   232
		*strto = '\0';
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   233
		memcpy(_name_array[i], tmp, sizeof(*_name_array));
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   234
	}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   235
}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5016
diff changeset
   236
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
// Calculate constants that depend on the landscape type.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
void InitializeLandscapeVariables(bool only_constants)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
{
3616
7ba7353d6561 (svn r4513) Codechange : Assemble a bit the scattered parts of Cargo types.
belugas
parents: 3355
diff changeset
   240
	const CargoTypesValues *lpd;
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   241
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
	StringID str;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
3616
7ba7353d6561 (svn r4513) Codechange : Assemble a bit the scattered parts of Cargo types.
belugas
parents: 3355
diff changeset
   244
	lpd = &_cargo_types_base_values[_opt.landscape];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2861
diff changeset
   246
	for (i = 0; i != NUM_CARGO; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
		_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
   248
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
		str = lpd->names[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
		_cargoc.names_s[i] = str;
2112
b94d4c1a0ab9 (svn r2622) Fix: remove _cargoc.names_p, it was never used.
ludde
parents: 2090
diff changeset
   251
		_cargoc.names_long[i] = (str += 0x40);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
		_cargoc.names_short[i] = (str += 0x20);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
		_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
   254
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
		if (!only_constants) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
			_cargo_payment_rates[i] = lpd->initial_cargo_payment[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
			_cargo_payment_rates_frac[i] = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   259
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
		_cargoc.transit_days_1[i] = lpd->transit_days_table_1[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
		_cargoc.transit_days_2[i] = lpd->transit_days_table_2[i];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   265
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 105
diff changeset
   267
int FindFirstBit(uint32 value)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
{
5415
a7e0e4e75be2 (svn r8179) -Backport from trunk (r8065, r8101, r8119, r8123, r8140, r8150):
Darkvater
parents: 5108
diff changeset
   269
	// The macro FIND_FIRST_BIT is better to use when your value is
a7e0e4e75be2 (svn r8179) -Backport from trunk (r8065, r8101, r8119, r8123, r8140, r8150):
Darkvater
parents: 5108
diff changeset
   270
	// not more than 128.
116
ca4332a9ec1d (svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents: 105
diff changeset
   271
	byte i = 0;
5415
a7e0e4e75be2 (svn r8179) -Backport from trunk (r8065, r8101, r8119, r8123, r8140, r8150):
Darkvater
parents: 5108
diff changeset
   272
a7e0e4e75be2 (svn r8179) -Backport from trunk (r8065, r8101, r8119, r8123, r8140, r8150):
Darkvater
parents: 5108
diff changeset
   273
	if (value == 0) return 0;
a7e0e4e75be2 (svn r8179) -Backport from trunk (r8065, r8101, r8119, r8123, r8140, r8150):
Darkvater
parents: 5108
diff changeset
   274
a7e0e4e75be2 (svn r8179) -Backport from trunk (r8065, r8101, r8119, r8123, r8140, r8150):
Darkvater
parents: 5108
diff changeset
   275
	if ((value & 0x0000ffff) == 0) { value >>= 16; i += 16; }
a7e0e4e75be2 (svn r8179) -Backport from trunk (r8065, r8101, r8119, r8123, r8140, r8150):
Darkvater
parents: 5108
diff changeset
   276
	if ((value & 0x000000ff) == 0) { value >>= 8;  i += 8;  }
a7e0e4e75be2 (svn r8179) -Backport from trunk (r8065, r8101, r8119, r8123, r8140, r8150):
Darkvater
parents: 5108
diff changeset
   277
	if ((value & 0x0000000f) == 0) { value >>= 4;  i += 4;  }
a7e0e4e75be2 (svn r8179) -Backport from trunk (r8065, r8101, r8119, r8123, r8140, r8150):
Darkvater
parents: 5108
diff changeset
   278
	if ((value & 0x00000003) == 0) { value >>= 2;  i += 2;  }
a7e0e4e75be2 (svn r8179) -Backport from trunk (r8065, r8101, r8119, r8123, r8140, r8150):
Darkvater
parents: 5108
diff changeset
   279
	if ((value & 0x00000001) == 0) { i += 1; }
a7e0e4e75be2 (svn r8179) -Backport from trunk (r8065, r8101, r8119, r8123, r8140, r8150):
Darkvater
parents: 5108
diff changeset
   280
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
	return i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
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
   285
static void Save_NAME(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
1375
f13d8247928c (svn r1879) Revise name handling, no functional changes
tron
parents: 1328
diff changeset
   289
	for (i = 0; i != lengthof(_name_array); ++i) {
f13d8247928c (svn r1879) Revise name handling, no functional changes
tron
parents: 1328
diff changeset
   290
		if (_name_array[i][0] != '\0') {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
			SlSetArrayIndex(i);
4321
b763b7007162 (svn r5974) -Codechange: added casts all around the place to make Windows 64bit happy (michi_cc)
truelight
parents: 4300
diff changeset
   292
			SlArray(_name_array[i], (uint)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
   293
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
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
   297
static void Load_NAME(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
	int index;
201
c40d343115f8 (svn r202) -Codechange: I missed some files with trailing spaces.. this should be
truelight
parents: 179
diff changeset
   300
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
	while ((index = SlIterateArray()) != -1) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
		SlArray(_name_array[index],SlGetFieldLength(),SLE_UINT8);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   304
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   305
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   306
static const SaveLoadGlobVarList _date_desc[] = {
4383
3dcf52b1efd9 (svn r6136) -Fix: _cur_year wasn't converting when reading pre-31 savegames, causing nasty desyncs
truelight
parents: 4347
diff changeset
   307
	SLEG_CONDVAR(_date,                   SLE_FILE_U16 | SLE_VAR_I32,  0,  30),
3dcf52b1efd9 (svn r6136) -Fix: _cur_year wasn't converting when reading pre-31 savegames, causing nasty desyncs
truelight
parents: 4347
diff changeset
   308
	SLEG_CONDVAR(_date,                   SLE_INT32,                  31, SL_MAX_VERSION),
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   309
	    SLEG_VAR(_date_fract,             SLE_UINT16),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   310
	    SLEG_VAR(_tick_counter,           SLE_UINT16),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   311
	    SLEG_VAR(_vehicle_id_ctr_day,     SLE_UINT16),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   312
	    SLEG_VAR(_age_cargo_skip_counter, SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   313
	    SLEG_VAR(_avail_aircraft,         SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   314
	SLEG_CONDVAR(_cur_tileloop_tile,      SLE_FILE_U16 | SLE_VAR_U32,  0, 5),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   315
	SLEG_CONDVAR(_cur_tileloop_tile,      SLE_UINT32,                  6, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   316
	    SLEG_VAR(_disaster_delay,         SLE_UINT16),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   317
	    SLEG_VAR(_station_tick_ctr,       SLE_UINT16),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   318
	    SLEG_VAR(_random_seeds[0][0],     SLE_UINT32),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   319
	    SLEG_VAR(_random_seeds[0][1],     SLE_UINT32),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   320
	SLEG_CONDVAR(_cur_town_ctr,           SLE_FILE_U8  | SLE_VAR_U32,  0, 9),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   321
	SLEG_CONDVAR(_cur_town_ctr,           SLE_UINT32,                 10, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   322
	    SLEG_VAR(_cur_player_tick_index,  SLE_FILE_U8  | SLE_VAR_U32),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   323
	    SLEG_VAR(_next_competitor_start,  SLE_FILE_U16 | SLE_VAR_U32),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   324
	    SLEG_VAR(_trees_tick_ctr,         SLE_UINT8),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   325
	SLEG_CONDVAR(_pause,                  SLE_UINT8,                   4, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   326
	SLEG_CONDVAR(_cur_town_iter,          SLE_UINT32,                 11, SL_MAX_VERSION),
3046
f81bee40701f (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3033
diff changeset
   327
	    SLEG_END()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
// Save load date related variables as well as persistent tick counters
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
// 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
   332
static void SaveLoad_DATE(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
	SlGlobList(_date_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
static const SaveLoadGlobVarList _view_desc[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   339
	SLEG_CONDVAR(_saved_scrollpos_x,    SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   340
	SLEG_CONDVAR(_saved_scrollpos_x,    SLE_INT32,                  6, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   341
	SLEG_CONDVAR(_saved_scrollpos_y,    SLE_FILE_I16 | SLE_VAR_I32, 0, 5),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   342
	SLEG_CONDVAR(_saved_scrollpos_y,    SLE_INT32,                  6, SL_MAX_VERSION),
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   343
	    SLEG_VAR(_saved_scrollpos_zoom, SLE_UINT8),
3046
f81bee40701f (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3033
diff changeset
   344
	    SLEG_END()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   345
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
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
   347
static void SaveLoad_VIEW(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
	SlGlobList(_view_desc);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   351
1218
353a7773bc3c (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1217
diff changeset
   352
static uint32 _map_dim_x;
353a7773bc3c (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1217
diff changeset
   353
static uint32 _map_dim_y;
353a7773bc3c (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1217
diff changeset
   354
353a7773bc3c (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1217
diff changeset
   355
static const SaveLoadGlobVarList _map_dimensions[] = {
3046
f81bee40701f (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3033
diff changeset
   356
	SLEG_CONDVAR(_map_dim_x, SLE_UINT32, 6, SL_MAX_VERSION),
f81bee40701f (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3033
diff changeset
   357
	SLEG_CONDVAR(_map_dim_y, SLE_UINT32, 6, SL_MAX_VERSION),
f81bee40701f (svn r3626) - Merge the SlGlobVarList (global variables) and SaveLoad (offset in struct, variable determined runtime) structs. The only difference between these two is the last element that either holds the address or the offset in the struct. Which one to take is determined by which function is called; SlObject or SlGlobList.
Darkvater
parents: 3033
diff changeset
   358
	    SLEG_END()
1218
353a7773bc3c (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1217
diff changeset
   359
};
353a7773bc3c (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1217
diff changeset
   360
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
   361
static void Save_MAPS(void)
1218
353a7773bc3c (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1217
diff changeset
   362
{
1219
6a1f8d818d58 (svn r1723) Save the map size in tiles, not number of bits
tron
parents: 1218
diff changeset
   363
	_map_dim_x = MapSizeX();
6a1f8d818d58 (svn r1723) Save the map size in tiles, not number of bits
tron
parents: 1218
diff changeset
   364
	_map_dim_y = MapSizeY();
1218
353a7773bc3c (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1217
diff changeset
   365
	SlGlobList(_map_dimensions);
353a7773bc3c (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1217
diff changeset
   366
}
353a7773bc3c (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1217
diff changeset
   367
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
   368
static void Load_MAPS(void)
1218
353a7773bc3c (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1217
diff changeset
   369
{
353a7773bc3c (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1217
diff changeset
   370
	SlGlobList(_map_dimensions);
2051
44b6b091beb3 (svn r2560) Fix: various minor code changes.
ludde
parents: 2050
diff changeset
   371
	AllocateMap(_map_dim_x, _map_dim_y);
1218
353a7773bc3c (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1217
diff changeset
   372
}
353a7773bc3c (svn r1722) -Feature: Bigger maps - anyone?
tron
parents: 1217
diff changeset
   373
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   374
static void Load_MAPT(void)
2050
947934d248c5 (svn r2559) Cleaned up new saveload code for the map
ludde
parents: 2049
diff changeset
   375
{
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   376
	uint size = MapSize();
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   377
	uint i;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   378
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   379
	for (i = 0; i != size;) {
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   380
		byte buf[4096];
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   381
		uint j;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   382
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   383
		SlArray(buf, lengthof(buf), SLE_UINT8);
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   384
		for (j = 0; j != lengthof(buf); j++) _m[i++].type_height = buf[j];
817
4f9377b7fd2b (svn r1288) -Codechange: changed _map2 to an uint16. It is still saved and loaded as
truelight
parents: 785
diff changeset
   385
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   388
static void Save_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
   389
{
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   390
	uint size = MapSize();
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   391
	uint i;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   392
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   393
	SlSetLength(size);
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   394
	for (i = 0; i != size;) {
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   395
		byte buf[4096];
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   396
		uint j;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   397
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   398
		for (j = 0; j != lengthof(buf); j++) buf[j] = _m[i++].type_height;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   399
		SlArray(buf, lengthof(buf), SLE_UINT8);
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   400
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
2360
09e42e4ee139 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2308
diff changeset
   403
static void Load_MAP1(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
   404
{
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   405
	uint size = MapSize();
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   406
	uint i;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   407
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   408
	for (i = 0; i != size;) {
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   409
		byte buf[4096];
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   410
		uint j;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   411
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   412
		SlArray(buf, lengthof(buf), SLE_UINT8);
2360
09e42e4ee139 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2308
diff changeset
   413
		for (j = 0; j != lengthof(buf); j++) _m[i++].m1 = buf[j];
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   414
	}
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   415
}
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   416
2360
09e42e4ee139 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2308
diff changeset
   417
static void Save_MAP1(void)
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   418
{
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   419
	uint size = MapSize();
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   420
	uint i;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   421
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   422
	SlSetLength(size);
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   423
	for (i = 0; i != size;) {
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   424
		byte buf[4096];
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   425
		uint j;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   426
2360
09e42e4ee139 (svn r2886) Rename the "owner" attribute to "m1", because when it stores an owner it is accessed by [GS]etOwner anyway and when it doesn't store an owner, but arbitrary data, accessing a field called "owner" is confusing.
tron
parents: 2308
diff changeset
   427
		for (j = 0; j != lengthof(buf); j++) buf[j] = _m[i++].m1;
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   428
		SlArray(buf, lengthof(buf), SLE_UINT8);
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   429
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
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
   432
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
   433
{
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
   434
	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
   435
	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
   436
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
   437
	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
   438
		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
   439
		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
   440
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
   441
		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
   442
			/* In those versions the m2 was 8 bits */
2685
00111d5ca47f (svn r3227) -Codechange: [Savegame] removed 'minor' version, and renamed 'major' version to just: version.
truelight
parents: 2548
diff changeset
   443
			CheckSavegameVersion(5) ? SLE_FILE_U8 | SLE_VAR_U16 : SLE_UINT16
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
   444
		);
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
   445
		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
   446
	}
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
   447
}
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
   448
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
   449
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
   450
{
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
   451
	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
   452
	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
   453
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
   454
	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
   455
	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
   456
		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
   457
		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
   458
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
   459
		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
   460
		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
   461
	}
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
   462
}
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
   463
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   464
static void Load_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
   465
{
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   466
	uint size = MapSize();
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   467
	uint i;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   468
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   469
	for (i = 0; i != size;) {
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   470
		byte buf[4096];
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   471
		uint j;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   472
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   473
		SlArray(buf, lengthof(buf), SLE_UINT8);
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   474
		for (j = 0; j != lengthof(buf); j++) _m[i++].m3 = buf[j];
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   475
	}
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
   476
}
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
   477
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   478
static void Save_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
   479
{
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   480
	uint size = MapSize();
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   481
	uint i;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   482
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   483
	SlSetLength(size);
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   484
	for (i = 0; i != size;) {
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   485
		byte buf[4096];
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   486
		uint j;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   487
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   488
		for (j = 0; j != lengthof(buf); j++) buf[j] = _m[i++].m3;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   489
		SlArray(buf, lengthof(buf), SLE_UINT8);
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   490
	}
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
   491
}
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
   492
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   493
static void Load_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
   494
{
2295
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   495
	uint size = MapSize();
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   496
	uint i;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   497
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   498
	for (i = 0; i != size;) {
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   499
		byte buf[4096];
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   500
		uint j;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   501
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   502
		SlArray(buf, lengthof(buf), SLE_UINT8);
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   503
		for (j = 0; j != lengthof(buf); j++) _m[i++].m4 = buf[j];
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   504
	}
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   505
}
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   506
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   507
static void Save_MAP4(void)
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   508
{
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   509
	uint size = MapSize();
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   510
	uint i;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   511
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   512
	SlSetLength(size);
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   513
	for (i = 0; i != size;) {
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   514
		byte buf[4096];
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   515
		uint j;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   516
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   517
		for (j = 0; j != lengthof(buf); j++) buf[j] = _m[i++].m4;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   518
		SlArray(buf, lengthof(buf), SLE_UINT8);
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   519
	}
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   520
}
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   521
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   522
static void Load_MAP5(void)
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   523
{
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   524
	uint size = MapSize();
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   525
	uint i;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   526
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   527
	for (i = 0; i != size;) {
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   528
		byte buf[4096];
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   529
		uint j;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   530
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   531
		SlArray(buf, lengthof(buf), SLE_UINT8);
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   532
		for (j = 0; j != lengthof(buf); j++) _m[i++].m5 = buf[j];
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   533
	}
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   534
}
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   535
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   536
static void Save_MAP5(void)
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   537
{
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   538
	uint size = MapSize();
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   539
	uint i;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   540
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   541
	SlSetLength(size);
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   542
	for (i = 0; i != size;) {
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   543
		byte buf[4096];
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   544
		uint j;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   545
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   546
		for (j = 0; j != lengthof(buf); j++) buf[j] = _m[i++].m5;
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   547
		SlArray(buf, lengthof(buf), SLE_UINT8);
af67e1ea8687 (svn r2819) Make variables, which are exclusive for internal use of the save/load code, static in saveload.c
tron
parents: 2293
diff changeset
   548
	}
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
   549
}
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
   550
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
   551
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
   552
{
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
   553
	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
   554
	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
   555
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   556
	for (i = 0; i != size;) {
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   557
		uint8 buf[1024];
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   558
		uint j;
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
   559
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   560
		SlArray(buf, lengthof(buf), SLE_UINT8);
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   561
		for (j = 0; j != lengthof(buf); j++) {
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   562
			_m[i++].extra = GB(buf[j], 0, 2);
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   563
			_m[i++].extra = GB(buf[j], 2, 2);
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   564
			_m[i++].extra = GB(buf[j], 4, 2);
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   565
			_m[i++].extra = GB(buf[j], 6, 2);
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
   566
		}
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
   567
	}
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
   568
}
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
   569
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
   570
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
   571
{
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
   572
	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
   573
	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
   574
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   575
	SlSetLength(size / 4);
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
   576
	for (i = 0; i != size;) {
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   577
		uint8 buf[1024];
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
   578
		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
   579
3977
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   580
		for (j = 0; j != lengthof(buf); j++) {
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   581
			buf[j]  = _m[i++].extra << 0;
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   582
			buf[j] |= _m[i++].extra << 2;
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   583
			buf[j] |= _m[i++].extra << 4;
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   584
			buf[j] |= _m[i++].extra << 6;
edb5b94e2094 (svn r5155) - Remove the bridge branch merge (revision r5070)
tron
parents: 3933
diff changeset
   585
		}
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
   586
		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
   587
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
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
   591
static void Save_CHTS(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
	byte count = sizeof(_cheats)/sizeof(Cheat);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   594
	Cheat* cht = (Cheat*) &_cheats;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
	Cheat* cht_last = &cht[count];
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
2951
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2861
diff changeset
   597
	SlSetLength(count * 2);
2db3adee7736 (svn r3510) Fiddle with whitespace and parentheses
tron
parents: 2861
diff changeset
   598
	for (; cht != cht_last; cht++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   599
		SlWriteByte(cht->been_used);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   600
		SlWriteByte(cht->value);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   601
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   602
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   603
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
   604
static void Load_CHTS(void)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   605
{
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   606
	Cheat* cht = (Cheat*)&_cheats;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   607
	uint count = SlGetFieldLength() / 2;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   608
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   609
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   610
	for (i = 0; i < count; i++) {
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   611
		cht[i].been_used = SlReadByte();
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
   612
		cht[i].value     = SlReadByte();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   613
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   614
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   615
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   617
const ChunkHandler _misc_chunk_handlers[] = {
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   618
	{ 'MAPS', Save_MAPS,     Load_MAPS,     CH_RIFF },
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   619
	{ 'MAPT', Save_MAPT,     Load_MAPT,     CH_RIFF },
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   620
	{ 'MAPO', Save_MAP1,     Load_MAP1,     CH_RIFF },
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   621
	{ 'MAP2', Save_MAP2,     Load_MAP2,     CH_RIFF },
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   622
	{ 'M3LO', Save_MAP3,     Load_MAP3,     CH_RIFF },
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   623
	{ 'M3HI', Save_MAP4,     Load_MAP4,     CH_RIFF },
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   624
	{ 'MAP5', Save_MAP5,     Load_MAP5,     CH_RIFF },
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   625
	{ 'MAPE', Save_MAPE,     Load_MAPE,     CH_RIFF },
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   627
	{ 'NAME', Save_NAME,     Load_NAME,     CH_ARRAY},
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
	{ 'DATE', SaveLoad_DATE, SaveLoad_DATE, CH_RIFF},
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
	{ 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, CH_RIFF},
4344
5d0e40cd67b9 (svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents: 4326
diff changeset
   630
	{ 'CHTS', Save_CHTS,     Load_CHTS,     CH_RIFF | CH_LAST}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
};