fixed initialization of flag for wrap-around levels in EM engine
[rocksndiamonds.git] / src / game_em / cave.c
1 /* 2000-08-10T16:43:50Z
2  *
3  * cave data structures
4  */
5
6 #include "main_em.h"
7
8
9 struct LevelInfo_EM native_em_level;
10
11 void setLevelInfoToDefaults_EM(void)
12 {
13   int i, j, x, y;
14
15   native_em_level.file_version = FILE_VERSION_EM_ACTUAL;
16   native_em_level.cav = &cav;
17
18   game_em.lev = &lev;
19   for (i = 0; i < MAX_PLAYERS; i++)
20     game_em.ply[i] = &ply[i];
21
22   cav.width  = 64;
23   cav.height = 32;
24
25   for (i = 0; i < MAX_PLAYERS; i++)
26   {
27     cav.player_x[i] = -1;
28     cav.player_y[i] = -1;
29   }
30
31   cav.time_seconds      = 0;
32   cav.gems_needed       = 0;
33
34   cav.eater_score       = 0;
35   cav.alien_score       = 0;
36   cav.bug_score         = 0;
37   cav.tank_score        = 0;
38   cav.slurp_score       = 0;
39   cav.nut_score         = 0;
40   cav.emerald_score     = 0;
41   cav.diamond_score     = 0;
42   cav.dynamite_score    = 0;
43   cav.key_score         = 0;
44   cav.lenses_score      = 0;
45   cav.magnify_score     = 0;
46   cav.exit_score        = 0;
47
48   cav.android_move_time = 0;
49   cav.android_clone_time= 0;
50   cav.ball_time         = 0;
51   cav.amoeba_time       = 0;
52   cav.wonderwall_time   = 0;
53   cav.wheel_time        = 0;
54   cav.wheel_x           = 0;
55   cav.wheel_y           = 0;
56   cav.lenses_time       = 0;
57   cav.magnify_time      = 0;
58   cav.wind_time         = 0;
59   cav.wind_direction    = 0;
60
61   cav.num_ball_arrays   = 8;
62
63   cav.testmode          = FALSE;
64   cav.teamwork          = FALSE;
65   cav.infinite          = TRUE;
66
67   cav.ball_random       = FALSE;
68   cav.ball_active       = FALSE;
69   cav.wonderwall_active = FALSE;
70   cav.wheel_active      = FALSE;
71   cav.lenses_active     = FALSE;
72   cav.magnify_active    = FALSE;
73
74   for (i = 0; i < 8; i++)
75     for (j = 0; j < 9; j++)
76       cav.eater_array[i][j] = Cblank;
77
78   for (i = 0; i < 8; i++)
79     for (j = 0; j < 8; j++)
80       cav.ball_array[i][j] = Cblank;
81
82   for (i = 0; i < GAME_TILE_MAX; i++)
83     cav.android_array[i] = Cblank;
84
85   for (x = 0; x < CAVE_WIDTH; x++)
86     for (y = 0; y < CAVE_HEIGHT; y++)
87       cav.cave[x][y] = Cblank;
88 }
89
90
91 /* load cave
92  * 
93  * completely initializes the level structure, ready for a game
94  */
95
96 #define MAX_EM_LEVEL_SIZE               16384
97
98 boolean LoadNativeLevel_EM(char *filename, boolean level_info_only)
99 {
100   unsigned char raw_leveldata[MAX_EM_LEVEL_SIZE];
101   int raw_leveldata_length;
102   int file_version;
103   File *file;
104
105   /* always start with reliable default values */
106   setLevelInfoToDefaults_EM();
107
108   if (!(file = openFile(filename, MODE_READ)))
109   {
110     if (!level_info_only)
111       Error(ERR_WARN, "cannot open level '%s' -- using empty level", filename);
112
113     return FALSE;
114   }
115
116   raw_leveldata_length = readFile(file, raw_leveldata, 1, MAX_EM_LEVEL_SIZE);
117
118   closeFile(file);
119
120   if (raw_leveldata_length <= 0)
121   {
122     Error(ERR_WARN, "cannot read level '%s' -- using empty level", filename);
123
124     return FALSE;
125   }
126
127   file_version = cleanup_em_level(raw_leveldata, raw_leveldata_length,filename);
128
129   if (file_version == FILE_VERSION_EM_UNKNOWN)
130   {
131     Error(ERR_WARN, "unknown EM level '%s' -- using empty level", filename);
132
133     return FALSE;
134   }
135
136   convert_em_level(raw_leveldata, file_version);
137   prepare_em_level();
138
139   return TRUE;
140 }