Imported contents: kraptor_final_apr_03_2004.tar.gz
[kraptor.git] / src / data.c
blob2eb37ba1d1d93035b950761f6722d2e1b0aaf7d4
1 // --------------------------------------------------------
2 // data.c
3 // --------------------------------------------------------
4 // Copyright (c) Kronoman
5 // En memoria de mi querido padre
6 // --------------------------------------------------------
7 // Esto se encarga de cargar y poner en memoria
8 // los datos leidos de disco.
9 // --------------------------------------------------------
10 #ifndef DATA_C
11 #define DATA_C
13 #include <stdio.h>
14 #include <string.h>
15 #include "allegro.h"
17 #include "data.h"
18 #include "error.h"
19 #include "global.h"
20 #include "jugador.h"
21 #include "enemigo.h"
22 #include "pmask.h"
23 #include "sombras.h"
24 #include "datafind.h"
25 #include "explos.h"
26 #include "mapa.h"
27 #include "partic.h"
28 #include "menu.h"
29 #include "shopping.h"
30 #include "humo.h"
31 #include "ia.h"
32 #include "premio.h"
33 #include "filedata.h"
34 #include "bomba.h"
36 /* Globales */
38 /* Este datafile contiene los datos principales del juego
39 tales como el script de secuencia de niveles,
40 graficos de menues, paleta de juego, armamento,
41 enemigos, sprites del jugador, premios, sonidos
42 Se carga al inicio del programa, y se descarga al salir
44 DATAFILE *krapmain = NULL;
46 /* Cada fondo y mapa de juego esta puesto por separado
47 en un DAT para evitar sobrecarga de memoria.
48 Este datafile es cargado y descargado a medida que pasan
49 los niveles.
50 Contiene el fondo (600x4000) y el mapa de juego
52 DATAFILE *datmapa = NULL;
54 /* Esto contiene los graficos para los menues */
55 DATAFILE *datmenu = NULL;
57 /* globales internas */
58 static int byte_acumulado = 0; /* auxiliar para contar bytes leidos (no necesario) */
60 /* Funcion interna callback, que muestra cuanto se ha leido...
61 en la esquina superior izquierda, usando colores
62 del GUI para el texto
63 La primera vez que es llamado (byte_acumulado == 0) dibuja una caja de texto
64 Esta dise~ado para no atrasar mucho la carga */
65 static void cargar_callback(DATAFILE *d)
67 if (byte_acumulado <= 0)
69 byte_acumulado = 0;
70 /* fondo */
71 rectfill(screen, 0,0,SCREEN_W-1, (text_height(font)+5)*2, gui_bg_color);
72 /* sombra (negro) */
73 rectfill(screen, 5,5,SCREEN_W-5, (text_height(font)+10)*2, makecol(0,0,0));
74 /* borde */
75 rect(screen, 0,0,SCREEN_W-1, (text_height(font)+5)*2, gui_fg_color);
78 byte_acumulado += d->size;
79 text_mode(gui_bg_color);
80 textprintf(screen, font, 2, 2, gui_fg_color, "Wait please, loading...");
81 textprintf(screen, font, 2, text_height(font)+4, gui_fg_color, "-> %d", byte_acumulado);
85 /* Esta funcion carga los datos principales del juego en memoria,
86 es decir, paletas, jugador, enemigo, IA, armamento
87 Afecta a *krapmain
88 MUESTRA UN MENSAJE DE CARGA EN PANTALLA! [ESQUINA SUP-IZQ]
90 void cargar_datos_principales()
92 DATAFILE *p = NULL; /* puntero de busqueda */
93 int i, i2; /* para los fors */
94 char tmpstr[1024], tmpstr2[1024]; /* uso general */
96 if (krapmain != NULL) unload_datafile(krapmain);
97 if (datmenu != NULL) unload_datafile(datmenu);
99 set_color_conversion(COLORCONV_TOTAL | COLORCONV_KEEP_TRANS);
101 /* colores para el callback que muestra el progreso de la carga */
102 gui_fg_color = makecol(255,255,255);
103 gui_bg_color = makecol(0,0,0);
104 byte_acumulado = 0; /* contador para mostrar progreso */
106 /* primero, trato de cargar SOLO la paleta de juego,
107 esto es para poder convertir las imagenes a los bpp adecuados */
108 krapmain = krono_load_datafile_object("krapmain.dat", "pal_game");
109 if (krapmain == NULL) levantar_error("ERROR: no existe pal_game en krapmain.dat");
111 /* copiar la paleta a RAM ... */
112 memcpy(pal_game, krapmain->dat, sizeof(PALETTE));
114 /* Paletas de colores y mapas de transparencias... [ya estan cargadas, hago calculos...] */
115 set_palette(pal_game); /* la seteo, la precisa la sombra... */
117 /* Crear mapa de transparencia de 8 bits */
118 create_trans_table(&tabla_transparencia, pal_game, 128,128,128, NULL);
119 color_map = &tabla_transparencia; /* la rutina de sombras la precisa! */
121 /* Crear mapa RGB de 8 bits */
122 create_rgb_table(&tabla_RGB, pal_game, NULL);
123 rgb_map = &tabla_RGB;
125 /* Crear mapa para 'quemado' del fondo */
126 create_color_table(&tabla_quemado,
127 pal_game,
128 crear_mapa_quemazon,
129 NULL);
131 /* ya no preciso mas la paleta en RAM */
132 unload_datafile_object(krapmain);
133 krapmain = NULL;
135 /* Cargo el cache de inteligencia artificial */
136 hacer_chache_ia("ia.dat");
138 /* Ahora si, cargar TODO el archivo de datos */
139 gui_bg_color = makecol(0,0,0); gui_fg_color = makecol(255,255,255); // colores para la info de carga
140 krapmain = krono_load_datafile_callback("krapmain.dat", cargar_callback);
141 if (krapmain == NULL) levantar_error("ERROR: no se pudo cargar krapmain.dat");
143 /* DEBUG: falta ajustar datafile al modo de video actual */
144 fixup_datafile(krapmain);
146 p = find_datafile_object(krapmain, "gamescript");
147 if (p == NULL) levantar_error("ERROR: el gamescript no esta definido en krapmain.dat");
149 set_config_data((char *)p->dat, p->size);
152 /* obtener la cinematica de introduccion al primer nivel */
153 sprintf(game_intro_cine, "%s", get_config_string("game_intro", "cine", "null"));
155 /* obtener la cinematica de game over */
156 sprintf(game_over_cine, "%s", get_config_string("game_over", "cine", "null"));
158 /* font para el 'hud' */
159 p = find_datafile_object(krapmain, "hud_font");
160 if (p == NULL)
161 hud_font = font_backup;
162 else
163 hud_font = (FONT *)p->dat;
165 /* Cargar explosiones, particulas, sonidos y sprite quemador en cache */
166 for (i = 0; i < 3; i++)
168 sprintf(tmpstr,"explo_bmp_%d", i);
169 p = find_datafile_object_type(krapmain, tmpstr, DAT_BITMAP);
170 if (p == NULL) levantar_error("ERROR: falta un objeto explo_bmp_[0..2]");
171 explo_cache_bmp[i] = (BITMAP *)p->dat;
173 sprintf(tmpstr,"explo_snd_%d", i);
174 p = find_datafile_object_type(krapmain, tmpstr, DAT_SAMPLE);
175 if (p == NULL) levantar_error("ERROR: falta un objeto explo_snd_[0..2]");
176 explo_cache_snd[i] = (SAMPLE *)p->dat;
177 explo_cache_snd[i]->priority = 30; /* prioridad baja a las explosiones */
179 sprintf(tmpstr,"chispa_%d", i);
180 p = find_datafile_object_type(krapmain, tmpstr, DAT_BITMAP);
181 if (p == NULL) levantar_error("ERROR: falta un objeto chispa_[0..2]");
182 particula_cache_bmp[i] = (BITMAP *)p->dat;
184 sprintf(tmpstr,"burn_%d", i);
185 p = find_datafile_object_type(krapmain, tmpstr, DAT_BITMAP);
186 if (p == NULL) levantar_error("ERROR: falta un objeto burn_[0..2]");
187 burn_cache_bmp[i] = (BITMAP *)p->dat;
190 // Cargar humo en cache
191 p = find_datafile_object_type(krapmain, "humo", DAT_BITMAP);
192 if (p == NULL)
193 humo_spr = NULL;
194 else
195 humo_spr = (BITMAP *)p->dat;
198 /* Script del jugador a partir de aqui */
200 p = find_datafile_object(krapmain, "jugador");
201 if (p == NULL) levantar_error("ERROR: el jugador no esta definido en krapmain.dat");
203 set_config_data((char *)p->dat, p->size);
205 /* Cargar sprites del jugador */
206 for (i = 0; i < 3; i++)
208 sprintf(tmpstr,"spr_%d", i);
210 p = find_datafile_object_type(krapmain, get_config_string("jugador", tmpstr, "null"), DAT_BITMAP);
211 if (p == NULL) levantar_error("ERROR: en el jugador: spr_* no esta definido en krapmain.dat");
212 jugador.spr[i] = (BITMAP *)p->dat;
214 jugador.spr[i+3] = create_bitmap(jugador.spr[i]->w * 0.8, jugador.spr[i]->h * 0.8);
215 hacer_sombra(jugador.spr[i], jugador.spr[i+3]);
218 /* dinero y bombas al iniciar un nuevo juego */
219 jugador.init_money = get_config_int("JUGADOR","init_money", 0);
220 jugador.init_bombas = get_config_int("JUGADOR","init_bombas", 0);
222 /* reparacion de la nave */
223 jugador.reparar_cantidad = get_config_int("JUGADOR_REPARAR","cantidad", 10);
224 jugador.reparar_precio = get_config_int("JUGADOR_REPARAR","precio" , 1);
225 sprintf(jugador.reparar_desc,"%s", get_config_string("JUGADOR_REPARAR", "desc", "Fix the ship") );
227 p = find_datafile_object_type(krapmain, get_config_string("JUGADOR_REPARAR", "bmp", "null"), DAT_BITMAP);
228 if (p == NULL)
229 jugador.reparar_bmp = NULL;
230 else
231 jugador.reparar_bmp = (BITMAP *)p->dat;
233 /* bombas especiales de la nave */
234 jugador.bomba_cantidad = get_config_int("JUGADOR_BOMBA_ESPECIAL","cantidad", 10);
235 jugador.bomba_precio = get_config_int("JUGADOR_BOMBA_ESPECIAL","precio" , 10);
236 jugador.max_bombas = get_config_int("JUGADOR_BOMBA_ESPECIAL","max_ammo" , 5);
237 sprintf(jugador.bomba_desc,"%s", get_config_string("JUGADOR_BOMBA_ESPECIAL", "desc", "Special bomb") );
239 p = find_datafile_object_type(krapmain, get_config_string("JUGADOR_BOMBA_ESPECIAL", "bmp", "null"), DAT_BITMAP);
240 if (p == NULL)
241 jugador.bomba_bmp = NULL;
242 else
243 jugador.bomba_bmp = (BITMAP *)p->dat;
245 p = find_datafile_object_type(krapmain, get_config_string("JUGADOR_BOMBA_ESPECIAL", "bomba_sonido", "null"), DAT_SAMPLE);
246 if (p == NULL)
247 bomba_sonido = NULL;
248 else
249 bomba_sonido = (SAMPLE *)p->dat;
252 /* mascara de colision del jugador */
253 jugador.mask = create_allegro_pmask(jugador.spr[1]);
256 /* Armamento del jugador */
257 for (i=0; i < MAX_ARM_CLASS; i++)
259 sprintf(tmpstr,"ARMA_%d", i);
261 arma_tipo[i].arma = NULL;
262 p = find_datafile_object_type(krapmain, get_config_string(tmpstr, "arma", "null"), DAT_BITMAP);
263 if (p != NULL ) arma_tipo[i].arma = (BITMAP *)p->dat;
265 sprintf(arma_tipo[i].desc,"%s", get_config_string(tmpstr, "desc", "null"));
266 sprintf(arma_tipo[i].desc_short,"%s", get_config_string(tmpstr, "desc_short", "null"));
267 arma_tipo[i].desc[2048] = '\0';
268 arma_tipo[i].desc_short[20] = '\0';
270 arma_tipo[i].precio = get_config_int(tmpstr, "precio", -1);
271 arma_tipo[i].cant_ammo = get_config_int(tmpstr, "cant_ammo", 0);
272 arma_tipo[i].cant_ammo_max = get_config_int(tmpstr, "cant_ammo_max", 0);
274 arma_tipo[i].spr = NULL;
275 p = find_datafile_object_type(krapmain, get_config_string(tmpstr, "spr", "null"), DAT_BITMAP);
276 if (p != NULL) arma_tipo[i].spr = (BITMAP *)p->dat;
278 arma_tipo[i].mask = NULL;
280 if (arma_tipo[i].spr != NULL)
282 arma_tipo[i].mask = create_allegro_pmask(arma_tipo[i].spr);
285 arma_tipo[i].snd[0] = NULL;
286 p = find_datafile_object_type(krapmain, get_config_string(tmpstr, "snd_0", "null"), DAT_SAMPLE);
287 if (p != NULL)
289 arma_tipo[i].snd[0] = (SAMPLE *)p->dat;
290 arma_tipo[i].snd[0]->priority = 140; /* prioridad */
293 arma_tipo[i].snd[1] = NULL;
294 p = find_datafile_object_type(krapmain, get_config_string(tmpstr, "snd_1", "null"), DAT_SAMPLE);
295 if (p != NULL)
297 arma_tipo[i].snd[1] = (SAMPLE *)p->dat;
298 arma_tipo[i].snd[1]->priority = 50; /* prioridad */
301 arma_tipo[i].vx = ftofix(get_config_float(tmpstr,"vx", 0.0));
302 arma_tipo[i].vy = ftofix(get_config_float(tmpstr,"vy", 0.0));
303 arma_tipo[i].vida = get_config_int(tmpstr,"vida", -1);
304 arma_tipo[i].punch = get_config_int(tmpstr,"punch", 0);
305 arma_tipo[i].firerate = get_config_int(tmpstr,"firerate", 0);
306 arma_tipo[i].t = get_config_int(tmpstr,"t", 0);
308 /* Estela del disparo... */
309 arma_tipo[i].est_vida[0] = get_config_int(tmpstr, "est_vida_min", 0);
310 arma_tipo[i].est_vida[1] = get_config_int(tmpstr, "est_vida_max", 0);
311 arma_tipo[i].est_cant[0] = get_config_int(tmpstr, "est_cant_min", 0);
312 arma_tipo[i].est_cant[1] = get_config_int(tmpstr, "est_cant_max", 0);
314 arma_tipo[i].est_color[0][0] = get_config_int(tmpstr, "est_color_r_min", 0);
315 arma_tipo[i].est_color[0][1] = get_config_int(tmpstr, "est_color_r_max", 0);
316 arma_tipo[i].est_color[1][0] = get_config_int(tmpstr, "est_color_g_min", 0);
317 arma_tipo[i].est_color[1][1] = get_config_int(tmpstr, "est_color_g_max", 0);
318 arma_tipo[i].est_color[2][0] = get_config_int(tmpstr, "est_color_b_min", 0);
319 arma_tipo[i].est_color[2][1] = get_config_int(tmpstr, "est_color_b_max", 0);
321 arma_tipo[i].est_dx[0] = get_config_int(tmpstr, "est_dx_min", 0);
322 arma_tipo[i].est_dx[1] = get_config_int(tmpstr, "est_dx_max", 0);
324 arma_tipo[i].est_dy[0] = get_config_int(tmpstr, "est_dy_min", 0);
325 arma_tipo[i].est_dy[1] = get_config_int(tmpstr, "est_dy_max", 0);
327 arma_tipo[i].est_tipo[0] = get_config_int(tmpstr, "est_tipo_min", 0);
328 arma_tipo[i].est_tipo[1] = get_config_int(tmpstr, "est_tipo_max", 0);
330 arma_tipo[i].est_rad[0] = get_config_int(tmpstr, "est_rad_min", 1);
331 arma_tipo[i].est_rad[1] = get_config_int(tmpstr, "est_rad_max", 2);
333 arma_tipo[i].est_transp = get_config_int(tmpstr, "est_transp", 0);
336 /* Cargar premios */
337 p = find_datafile_object(krapmain, "premios");
338 if (p == NULL) levantar_error("ERROR: los premios no estan definidos en krapmain.dat");
339 set_config_data((char *)p->dat, p->size);
341 for (i = 0; i < MAX_PREMIO_CLASS; i++)
343 sprintf(tmpstr,"PREMIO_%d", i);
344 premio_class[i].premiar = get_config_int(tmpstr,"premiar", -666);
345 premio_class[i].cantidad = get_config_int(tmpstr,"cantidad", 0);
346 premio_class[i].vida = get_config_int(tmpstr,"vida", 0);
348 // Obtener bitmap
349 p = find_datafile_object_type(krapmain, get_config_string(tmpstr, "sprite", "null"), DAT_BITMAP);
350 if (p != NULL)
351 premio_class[i].sprite = (BITMAP *)p->dat;
352 else
353 premio_class[i].sprite = NULL;
355 // obtener sonido
356 p = find_datafile_object_type(krapmain, get_config_string(tmpstr, "sonido", "null"), DAT_SAMPLE);
357 if (p != NULL)
358 premio_class[i].sonido = (SAMPLE *)p->dat;
359 else
360 premio_class[i].sonido = NULL;
364 /* Script de enemigos a partir de aqui */
366 /* Cargar clases de enemigos */
367 p = find_datafile_object(krapmain, "enemigos");
368 if (p == NULL) levantar_error("ERROR: los enemigos no estan definidos en krapmain.dat");
369 set_config_data((char *)p->dat, p->size);
371 /* Cargar enemigos, tipo de IA que le corresponde, y tipos de armas */
372 for (i=0; i < MAX_E_CLASS; i++)
375 /* Seccion ENEMIGO_n */
376 sprintf(tmpstr,"ENEMIGO_%d", i);
378 enem_t[i].vida = get_config_int(tmpstr,"vida", -1);
380 enem_t[i].peso = get_config_int(tmpstr,"peso", 0);
382 enem_t[i].dinero = get_config_int(tmpstr,"dinero", 0);
384 /* premios que suelta el enemigo */
385 enem_t[i].premio_idx = get_config_int(tmpstr,"premio_idx", -1);
386 enem_t[i].premio_prob = get_config_int(tmpstr,"premio_prob", -1);
388 enem_t[i].spr_delay = get_config_int(tmpstr,"spr_delay", 10); //delay de animacion
390 // bytecodes de tipo de IA
391 enem_t[i].ia_node = buscar_lista_ia(get_config_string(tmpstr,"tipo_ia","null"));
392 enem_t[i].ia_azar = get_config_int(tmpstr,"ia_azar", 0); // ia azaroza?
393 enem_t[i].ia_boss = get_config_int(tmpstr,"ia_boss", 0); // ia boss?
395 // cargar los sprites de animacion del enemigo
396 for (i2 = 0; i2<4; i2++)
398 enem_t[i].spr[i2] = NULL;
399 sprintf(tmpstr2, "spr_%d", i2);
400 p = find_datafile_object_type(krapmain, get_config_string(tmpstr, tmpstr2, "null"), DAT_BITMAP);
401 // intentar con spr, si no existe spr_0
402 if (i2 == 0 && p == NULL) p = find_datafile_object_type(krapmain, get_config_string(tmpstr, "spr", "null"), DAT_BITMAP);
403 // cuando es el primer sprite, se obvia si no existe, en caso contrario, el resto se asigna al primero
404 if (p != NULL)
405 { enem_t[i].spr[i2] = (BITMAP *)p->dat; }
406 else
408 if (i2 == 0)
409 { enem_t[i].spr[i2] = NULL; } // no hay sprite inicial
410 else
411 { enem_t[i].spr[i2] = enem_t[i].spr[0]; } // si no existe, tomo el primero
414 enem_t[i].mask[i2] = NULL;
415 if (enem_t[i].spr[i2] != NULL) /* sombra y mascara de colision */
417 enem_t[i].spr_shadow[i2] = create_bitmap(enem_t[i].spr[i2]->w * 0.8, enem_t[i].spr[i2]->h * 0.8);
418 hacer_sombra(enem_t[i].spr[i2] , enem_t[i].spr_shadow[i2]); // sombra
419 enem_t[i].mask[i2] = create_allegro_pmask(enem_t[i].spr[i2]); // mascara de colision
423 /*------ Seccion ARMA_n ------*/
424 sprintf(tmpstr,"ARMA_%d", i);
426 arma_ene[i].spr = NULL;
427 p = find_datafile_object_type(krapmain, get_config_string(tmpstr, "spr", "null"), DAT_BITMAP);
428 if (p != NULL) arma_ene[i].spr = (BITMAP *)p->dat;
430 arma_ene[i].mask = NULL;
432 if (arma_ene[i].spr != NULL)
434 arma_ene[i].mask = create_allegro_pmask(arma_ene[i].spr);
437 arma_ene[i].snd[0] = NULL;
438 arma_ene[i].snd[1] = NULL;
440 p = find_datafile_object_type(krapmain, get_config_string(tmpstr, "snd_0", "null"), DAT_SAMPLE);
441 if (p != NULL)
443 arma_ene[i].snd[0] = (SAMPLE *)p->dat;
444 arma_ene[i].snd[0]->priority = 100; /* prioridad */
447 p = find_datafile_object_type(krapmain, get_config_string(tmpstr, "snd_1", "null"), DAT_SAMPLE);
448 if (p != NULL)
450 arma_ene[i].snd[1] = (SAMPLE *)p->dat;
451 arma_ene[i].snd[1]->priority = 40; /* prioridad */
454 arma_ene[i].vx = ftofix(get_config_float(tmpstr,"vx", 0.0));
455 arma_ene[i].vy = ftofix(get_config_float(tmpstr,"vy", 0.0));
456 arma_ene[i].vida = get_config_int(tmpstr,"vida", -1);
457 arma_ene[i].punch = get_config_int(tmpstr,"punch", 0);
458 arma_ene[i].t = get_config_int(tmpstr,"t", 0);
460 /* Estela del disparo... */
461 arma_ene[i].est_vida[0] = get_config_int(tmpstr, "est_vida_min", 0);
462 arma_ene[i].est_vida[1] = get_config_int(tmpstr, "est_vida_max", 0);
463 arma_ene[i].est_cant[0] = get_config_int(tmpstr, "est_cant_min", 0);
464 arma_ene[i].est_cant[1] = get_config_int(tmpstr, "est_cant_max", 0);
466 arma_ene[i].est_color[0][0] = get_config_int(tmpstr, "est_color_r_min", 0);
467 arma_ene[i].est_color[0][1] = get_config_int(tmpstr, "est_color_r_max", 0);
468 arma_ene[i].est_color[1][0] = get_config_int(tmpstr, "est_color_g_min", 0);
469 arma_ene[i].est_color[1][1] = get_config_int(tmpstr, "est_color_g_max", 0);
470 arma_ene[i].est_color[2][0] = get_config_int(tmpstr, "est_color_b_min", 0);
471 arma_ene[i].est_color[2][1] = get_config_int(tmpstr, "est_color_b_max", 0);
473 arma_ene[i].est_dx[0] = get_config_int(tmpstr, "est_dx_min", 100);
474 arma_ene[i].est_dx[1] = get_config_int(tmpstr, "est_dx_max", 100);
476 arma_ene[i].est_dy[0] = get_config_int(tmpstr, "est_dy_min", 0);
477 arma_ene[i].est_dy[1] = get_config_int(tmpstr, "est_dy_max", 0);
479 arma_ene[i].est_tipo[0] = get_config_int(tmpstr, "est_tipo_min", 0);
480 arma_ene[i].est_tipo[1] = get_config_int(tmpstr, "est_tipo_max", 0);
482 arma_ene[i].est_rad[0] = get_config_int(tmpstr, "est_rad_min", 1);
483 arma_ene[i].est_rad[1] = get_config_int(tmpstr, "est_rad_max", 2);
485 arma_ene[i].est_transp = get_config_int(tmpstr, "est_transp", 0);
489 // Fondo del shopping
490 p = find_datafile_object_type(krapmain, "shop_bmp", DAT_BITMAP);
491 if (p == NULL)
492 shop_bmp = NULL;
493 else
494 shop_bmp = (BITMAP *)p->dat;
497 /* cargar los items del menu principal */
498 if (datmenu != NULL) unload_datafile(datmenu);
499 gui_bg_color = makecol(0,0,0); gui_fg_color = makecol(255,255,255); // colores para la info de carga
500 datmenu = krono_load_datafile_callback("krapmnu.dat", cargar_callback);
501 if (datmenu == NULL) levantar_error("ERROR: no se pudo abrir 'krapmnu.dat'");
503 /* paleta de colores */
504 p = find_datafile_object(datmenu, "main_menu_pal");
505 if (p == NULL) levantar_error("ERROR: no se pudo obtener 'main_menu_pal'");
507 /* copiar la paleta a RAM ... */
508 memcpy(pal_menu_main, p->dat, sizeof(PALETTE));
510 /* cargar archivo de ayuda (texto) */
511 p = find_datafile_object(datmenu, "help_txt");
512 if (p == NULL)
513 { texto_ayuda_juego = NULL; }
514 else
516 texto_ayuda_juego = (char *)p->dat;
517 /* esto es necesario, sino, no tiene fin la cadena! */
518 texto_ayuda_juego[p->size - 1] = '\0';
521 /* acerca de... */
522 p = find_datafile_object(datmenu, "about_txt");
523 if (p == NULL)
524 { texto_acerca_de_juego = NULL; }
525 else
527 texto_acerca_de_juego = (char *)p->dat;
528 /* esto es necesario, sino, no tiene fin la cadena! */
529 texto_acerca_de_juego[p->size - 1] = '\0';
532 /* imagen de acerca de... */
533 p = find_datafile_object_type(datmenu, "about_bmp", DAT_BITMAP);
534 if (p == NULL)
535 acerca_de_bmp = NULL;
536 else
537 acerca_de_bmp = (BITMAP *)p->dat;
539 /* cargo el bitmap de fondo */
540 p = find_datafile_object_type(datmenu, "main_menu_bmp", DAT_BITMAP);
541 if (p == NULL) levantar_error("ERROR: no existe 'main_menu_bmp' en 'krapmnu.dat'");
543 bmp_menu_main = (BITMAP *)p->dat;
545 /* fin de los items del menu */
547 /* DEBUG: en caso necesario agregar mas datos necesarios aqui */
553 Esta funcion puede hacer 2 cosas:
554 - verificar si el proximo nivel existe
555 - o verificar si existe y cargar el nivel especificado en RAM
557 parametros:
558 nivel => nivel a cargar
559 solo_verificar => 0 indica que cargue el nivel en RAM,
560 -1 que solo verifique
561 SIEMPRE son cargados los datos basicos del nivel (cinematicas, titulo)
563 devuelve 0 si funciona, -1 si falla (el nivel no existe, o el archivo no existe)
565 SI SE VA A CARGAR EL NIVEL:
566 MUESTRA UN MENSAJE DE CARGA EN PANTALLA! [ESQUINA SUP-IZQ]
568 Nota: grilla de nivel/enemigos se guarda en enteros Intel 32 bits, para zafar en
569 todas las plataformas
571 int cargar_nivel(int nivel, int solo_verificar)
573 DATAFILE *p = NULL; /* puntero de busqueda */
574 PACKFILE *fp; // para leer las grillas
575 int xx, yy; // para leer las grillas
576 char tmpstr[1024]; // uso general
577 char tmpstr2[1024];
579 if (krapmain == NULL) return -1;
581 p = find_datafile_object(krapmain, "gamescript");
582 if (p == NULL) levantar_error("ERROR: el gamescript no esta definido en krapmain.dat");
584 set_config_data((char *)p->dat, p->size);
586 sprintf(tmpstr,"nivel_%d", nivel);
588 /* cargar siempre la info basica del nivel... (si no, las cinematicas no andan! )*/
589 sprintf(info_nivel.level_dat, "%s", get_config_string(tmpstr, "level_dat", "null"));
590 sprintf(info_nivel.cine_in, "%s", get_config_string(tmpstr, "cine_in", "null"));
591 sprintf(info_nivel.cine_out, "%s", get_config_string(tmpstr, "cine_out", "null"));
592 sprintf(info_nivel.texto, "%s", get_config_string(tmpstr, "texto", "null"));
593 sprintf(info_nivel.titulo, "%s", get_config_string(tmpstr, "titulo", "null"));
594 info_nivel.clima_c = get_config_int(tmpstr, "clima_c", 0);
595 info_nivel.clima_t = get_config_int(tmpstr, "clima_t", 0);
596 info_nivel.clima_d = get_config_int(tmpstr, "clima_d", 0);
598 info_nivel.musica = NULL; /* por ahora, no se si hay musica... */
600 /* Debo SOLO verificar si el nivel existe? */
601 if (solo_verificar) return !exists(info_nivel.level_dat);
603 /* ------ Cargar realmente en RAM el archivo... ------ */
605 /* colores para el callback que muestra el progreso de la carga */
606 gui_fg_color = makecol(255,255,255);
607 gui_bg_color = makecol(0,0,0);
608 byte_acumulado = 0; /* contador para mostrar progreso */
610 if (datmapa != NULL)
612 unload_datafile(datmapa);
613 datmapa = NULL;
615 gui_bg_color = makecol(0,0,0); gui_fg_color = makecol(255,255,255); // colores para la info de carga
616 datmapa = krono_load_datafile_callback(info_nivel.level_dat, cargar_callback);
617 if (datmapa == NULL) return -1; /* fallo la carga del nivel */
619 /* copiarse las grillas */
620 sprintf(tmpstr2, "%s#mapa_g", info_nivel.level_dat); // cargar el mapa_g
621 fp = pack_fopen(tmpstr2, F_READ);
622 if (fp == NULL) levantar_error("ERROR: no existe mapa_g en el nivel!");
623 for (xx =0; xx < W_FONDO / W_GR; xx++)
624 for (yy =0; yy < H_FONDO / H_GR; yy++)
625 mapa_g[xx][yy] = pack_igetl(fp);
627 pack_fclose(fp);
629 // grilla de enemigos, con soporte para varias dificultades
630 sprintf(tmpstr2, "%s#enem_g_%d", info_nivel.level_dat, nivel_de_dificultad);
631 fp = pack_fopen(tmpstr2, F_READ);
632 if (fp == NULL)
634 sprintf(tmpstr2, "%s#enem_g", info_nivel.level_dat );
635 fp = pack_fopen(tmpstr2, F_READ);
636 if (fp == NULL) levantar_error("ERROR: no existe enem_g en el nivel!");
639 for (xx =0; xx < W_FONDO / W_GR; xx++)
640 for (yy =0; yy < H_FONDO / H_GR; yy++)
641 enem_g[xx][yy] = pack_igetl(fp);
643 pack_fclose(fp);
645 /* obtener el fondo y ajustar dimensiones en un mapa nuevo...
646 esto ayuda a conservar espacio en disco,
647 para demos, permitiendo usar un fondo mas chico en disco! */
649 p = find_datafile_object(datmapa, "mapa_fondo");
650 if (p == NULL) levantar_error("ERROR: no existe mapa_fondo en el nivel!");
652 mapa_fondo = create_bitmap(W_FONDO, H_FONDO); /* acordarse de liberar esto luego... en game.c */
654 if (mapa_fondo == NULL) levantar_error("ERROR: data.c:cargar_nivel()\nInsuficiente memoria RAM para cargar el mapa del nivel!\n(~2.3MB requeridos!)");
656 stretch_blit((BITMAP *)p->dat, mapa_fondo, 0, 0,
657 ((BITMAP *)p->dat)->w, ((BITMAP *)p->dat)->h,
658 0, 0,
659 mapa_fondo->w, mapa_fondo->h);
661 /* Tomo la musica del juego */
662 info_nivel.musica = NULL;
663 p = find_datafile_object(datmapa, "musica");
664 if (p != NULL) info_nivel.musica = (DUH *)p->dat;
666 return 0; /* Todo bien, negrita... */
669 #endif