Use an absolute directory under /usr/share/games/ for game data
[kraptor.git] / src / main.c
blob3629bf62a2be5e403dc7a869747e015bea21b803
1 // --------------------------------------------------------
2 // Kraptor - Call of the freedom
3 // --------------------------------------------------------
4 // main.c
5 // --------------------------------------------------------
6 // Copyright (c) 2002-2004, Kronoman
7 // En memoria de mi querido padre
8 // --------------------------------------------------------
9 // Este modulo es el 'arranque' del programa
10 // Inicia el video, carga los datos, etc...
11 // --------------------------------------------------------
12 // Ultima revision: 18/ENERO/2004
14 #ifndef MAIN_C
15 #define MAIN_C
17 // --------------------------------------------------------
18 // Inclusiones
19 // --------------------------------------------------------
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <allegro.h>
24 #include <aldumb.h> /* DUMB: musica MOD, XM, etc */
25 #include "main.h"
26 #include "error.h"
27 #include "game.h"
28 #include "data.h"
29 #include "jugador.h"
30 #include "global.h"
31 #include "menu.h"
32 #include "mapa.h"
33 #include "config.h"
36 int main(int argc, char *argv[] )
38 int i1; // para el for de los parametros
39 int rx = 640, ry = 480; // para permitir que el usuario elija la resolucion
40 int vid_card = GFX_AUTODETECT; // placa de video por defecto
41 char *home;
43 int snd = TRUE; // quiere sonido
44 lenguaje[0]='e';
45 lenguaje[1]='s';
46 lenguaje[2]= '\0';
48 /* Iniciar Allegro y el hardware */
49 allegro_init();
50 atexit(&dumb_exit);
52 home = getenv("HOME");
53 if (home != NULL)
55 char str[4096];
56 snprintf(str, sizeof(str), "%s/.kraptor.cfg", home);
57 set_config_file("/etc/kraptor/kraptor.cfg");
58 override_config_file(str);
60 else
62 set_config_file("kraptor.cfg");
65 setenv("ALLEGRO", "/usr/share/games/kraptor/",0); /* Dirty hack so that allegro searches for language.dat in the proper directory */
67 /* setear allegro al idioma configurado, default = en (ingles) */
68 strncpy(lenguaje, get_config_string("system", "language", "en"), 2);
69 reload_config_texts(lenguaje);
71 /* configuracion de DUMB, por default, CASI la mas baja (1), la mas baja es 0 :^) */
72 dumb_resampling_quality = get_config_int("sound", "dumb_resampling_quality", 1);
73 dumb_it_max_to_mix = get_config_int("sound", "dumb_it_max_to_mix", 8);
75 /* registro los IT, XM y S3M para cargarlos con DUMB */
76 dumb_register_dat_it(DUMB_DAT_IT);
77 dumb_register_dat_xm(DUMB_DAT_XM);
78 dumb_register_dat_s3m(DUMB_DAT_S3M);
81 srand(time(0));
82 if (install_timer() != 0) levantar_error("ERROR: Fallo el inicio del temporizador!");
83 if (install_keyboard() != 0) levantar_error("ERROR: Imposible acceder al teclado!");
85 install_mouse(); /* Tambien uso el mouse para los menus! */
87 // --------------------------------------------------------
88 // Interpretar parametros
89 // --------------------------------------------------------
90 for (i1=1; i1<argc; i1++) {
92 // -steroids (modo 'rapido', el scroll pasa 5 veces mas rapido!)
93 if (stricmp(argv[i1], "-steroids") == 0) scroll_mapa_speed = 5;
95 // -crazy_speed (modo 'super rapido', el scroll pasa 10 veces mas rapido!)
96 if (stricmp(argv[i1], "-crazy_speed") == 0) scroll_mapa_speed = 10;
98 // -kronoman (cheat: modo DIOS - no muere nunca)
99 if (stricmp(argv[i1], "-kronoman") == 0) cheat_god_mode = TRUE;
101 // -safe (modo seguro, video pedorro y sin sonido)
102 if (stricmp(argv[i1], "-safe") == 0) { rx = 320; ry = 200; snd = FALSE; vid_card = GFX_SAFE; }
104 // video: modo en ventana (solo algunas plataformas)
105 if (stricmp(argv[i1], "-windowscreen")== 0) vid_card = GFX_AUTODETECT_WINDOWED;
106 // video: modo en pantalla completa
107 if (stricmp(argv[i1], "-fullscreen") == 0) vid_card = GFX_AUTODETECT_FULLSCREEN;
109 // video: video automatico
110 if (stricmp(argv[i1], "-autoscreen") == 0) vid_card = GFX_AUTODETECT;
113 // video: -320x200 (320x200)
114 if (stricmp(argv[i1], "-320x200") == 0) { rx = 320; ry = 200; }
116 // video: -320x240 (320x240)
117 if (stricmp(argv[i1], "-320x240") == 0) { rx = 320; ry = 240; }
119 // video: -640x480 (640x480)
120 if (stricmp(argv[i1], "-640x480") == 0) { rx = 640; ry = 480; }
122 // video: -800x600 (800x600)
123 if (stricmp(argv[i1], "-800x600") == 0) { rx = 800; ry = 600; }
125 // video: -1024x768 (1024x768)
126 if (stricmp(argv[i1], "-1024x768") == 0) { rx = 1024; ry = 768; }
128 // -nosound - sin sonido
129 if (stricmp(argv[i1], "-nosound") == 0) { snd=FALSE; }
131 // ayuda
132 if (stricmp(argv[i1],"-h")==0 || stricmp(argv[i1],"-?") == 0 || stricmp(argv[i1],"--h") == 0 || stricmp(argv[i1],"/?") == 0)
134 /* DEBUG: falta mostrar la ayuda!!! */
135 exit(0);
138 // DEBUG: falta un -v para la version! */
140 } // fin for
143 /* Iniciar video */
144 set_color_depth(8); /* setear a 8bpp, en otros modos, no ANDA! */
146 // DEBUG: probar con GFX_SAFE que tambien intenta setear el rx, ry, pero anda mejor en Linux
147 if (set_gfx_mode(vid_card, rx, ry, 0, 0))
148 if (set_gfx_mode(GFX_SAFE, rx, ry, 0, 0))
149 if (set_gfx_mode(GFX_SAFE, 640, 480, 0, 0))
150 if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0))
151 levantar_error("ERROR: imposible utilizar algun modo grafico de 8bpp!");
153 // chequear el 'depth' de color (porque GFX_SAFE puede meter otro que no sea 8bpp)
154 // if (bitmap_color_depth(screen) != 8); levantar_error("ERROR: el modo grafico no es de 8bpp!");
156 clear(screen);
157 textout(screen, font,"Wait... loading...",0,SCREEN_H - text_height(font)*2, makecol(255,255,255));
159 // textout(screen, font,"Espere... iniciando programa...",0,0, makecol(255,255,255));
160 // textout(screen, font,"Si el juego se detiene aqui, intente reiniciarlo con el parametro -nosound.",0,SCREEN_H - text_height(font)*2 , makecol(255,255,255));
161 // textout(screen, font,"Utilize el parametro -h para mas informacion.",0,SCREEN_H - text_height(font), makecol(255,255,255));
163 set_teclado_default();
165 /* DEBUG: Joystick! wow!! */
166 install_joystick(JOY_TYPE_AUTODETECT);
168 // SONIDO
169 // reserve_voices(8, 0); // 8 voces de sonido
171 // volumen por voz (def: 2, maximo volumen: 0)
172 // set_volume_per_voice(1); // puede causar distorsion, ojo! causa DISTORSION!
174 if (snd)
176 if (install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) == -1)
177 { levantar_error("ERROR: no se puede configurar el sonido.\nPara desactivarlo use el parametro -nosound!");}
179 driver_de_sonido = TRUE;
181 else
183 install_sound(DIGI_NONE, MIDI_NONE, NULL);
184 quiere_snd = FALSE;
185 quiere_musica = FALSE;
186 driver_de_sonido = FALSE;
187 } // sin sonido
189 // volumen al mango
190 set_volume(255,-1);
192 // instalo colision de mascaras [IMPORTANTE]
193 install_pmask();
195 // Hacer backup del font default
196 font_backup = font;
198 cargar_datos_principales(); /* Cargar datos del programa */
200 // cargar configuracion especifica de Kraptor
201 cargar_configuracion();
203 /* menu principal */
204 realizar_menu_principal();
206 // aqui salvar la configuracion especifica de Kraptor!!!
207 salvar_configuracion();
209 return 0;
211 END_OF_MAIN();
213 #endif