Remove static label from game functions
[kraptor.git] / src / shopping.c
blob4a0bd7941ffee3bb1a2d62aea9317ba525ef3115
1 /*
2 --------------------------------------------------------
3 shopping.c
4 --------------------------------------------------------
5 Sistema de shopping de Kraptor
7 NOTAS: TODOS LOS TEXTOS DEL MENU ESTAN EN *INGLES*
8 PARA PODER TRADUCIRLOS AUTOMATICAMENTE
9 CON EL ENGINE DE TRADUCCION.
10 USAR MENUES Y DIALOGOS *LOCALES* PARA QUE AL
11 ENTRAR/SALIR DE SCOPE, (CADA VEZ QUE SE LLAMA LA FUNCION)
12 SE TRADUZCAN AUTOMATICAMENTE AL LENGUAJE ORIGINAL.
13 --------------------------------------------------------
16 #include <allegro.h>
17 #include <stdio.h>
18 #include "guitrans.h"
19 #include "guiprocs.h"
20 #include "shopping.h"
21 #include "jugador.h"
22 #include "savedlg.h"
24 // Imagen de fondo
25 BITMAP *shop_bmp = NULL;
29 Esta funcion es la principal
30 Muestra el shop en pantalla y comienza todo.
31 Llamar con la paleta de juego ya seteada.
33 void do_shopping_principal()
35 /* variables que se muestran en el dialogo */
36 char str_cant[256], str_money[256], str_desc[2048], str_precio[256];
37 int ret = 0; /* respuesta del dialogo */
38 int item_idx = -2; /* indice del item mostrado, -1 = energia, -2 = bomba */
40 /* indices de items importantes en el dialogo */
41 #define IDX_PREV_BTN 3
42 #define IDX_NEXT_BTN 4
43 #define IDX_BUY_BTN 5
44 #define IDX_SELL_BTN 6
45 #define IDX_SAVE_BTN 7
46 #define IDX_EXIT_BTN 8
47 #define IDX_DESC 9
48 #define IDX_BMP 10
49 #define IDX_MONEY 12
50 #define IDX_CANT 14
51 #define IDX_PRICE 16
53 DIALOG shop_main_dlg[] =
55 /* (proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
56 { xbox_proc, 0, 0, 320, 192, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
57 { xbox_proc, 76, 4, 240, 184, 0, 0, 0, 0, 1, 0, NULL, NULL, NULL },
58 { xbox_proc, 84, 8, 228, 160, 0, 0, 0, 0, 1, 0, NULL, NULL, NULL },
59 { xbutton_proc, 4, 4, 32, 16, 0, 0, 0, D_EXIT, 0, 0, "<<", NULL, NULL },
60 { xbutton_proc, 40, 4, 32, 16, 0, 0, 0, D_EXIT, 0, 0, ">>", NULL, NULL },
61 { xbutton_proc, 4, 28, 68, 24, 0, 0, 0, D_EXIT, 0, 0, "Buy", NULL, NULL },
62 { xbutton_proc, 4, 60, 68, 24, 0, 0, 0, D_EXIT, 0, 0, "Sell", NULL, NULL },
63 { xbutton_proc, 4, 116, 68, 44, 0, 0, 0, D_EXIT, 0, 0, "Save", NULL, NULL },
64 { xbutton_proc, 4, 168, 68, 20, 0, 0, 0, D_EXIT, 0, 0, "OK", NULL, NULL },
65 { xtextbox_proc, 200, 12, 108, 124, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
66 { xbitmap_proc, 88, 12, 108, 124, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
67 { xtext_proc, 88, 172, 68, 12, 0, 0, 0, 0, 0, 0, "Money", NULL, NULL },
68 { xtext_proc, 160, 172, 148, 12, 0, 0, 0, 0, 0, 0, "1234567890", NULL, NULL },
69 { xtext_proc, 88, 140, 68, 12, 0, 0, 0, 0, 0, 0, "Amount", NULL, NULL },
70 { xtext_proc, 160, 140, 148, 12, 0, 0, 0, 0, 0, 0, "1234567890", NULL, NULL },
71 { xtext_proc, 88, 152, 68, 12, 0, 0, 0, 0, 0, 0, "Price", NULL, NULL },
72 { xtext_proc, 160, 152, 148, 12, 0, 0, 0, 0, 0, 0, "1234567890", NULL, NULL },
73 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
76 traducir_DIALOG_dp(shop_main_dlg);
77 centre_dialog(shop_main_dlg);
78 set_dialog_color(shop_main_dlg, makecol(0,0,0), makecol(255,255,255));
81 clear(screen);
82 if (shop_bmp != NULL)
83 stretch_blit( shop_bmp,
84 screen,
85 0, 0,
86 shop_bmp->w,
87 shop_bmp->h,
88 0, 0,
89 SCREEN_W,
90 SCREEN_H); // Fondo
92 /* looping principal */
93 ret = 0;
94 while (ret != IDX_EXIT_BTN)
96 /* setear variables a mostrar */
97 sprintf(str_cant," %9d",0);
98 sprintf(str_money,"$ %9d", jugador.dinero);
99 sprintf(str_desc, get_config_text("Unknown"));
100 sprintf(str_precio,"$ %9d", 0);
101 shop_main_dlg[IDX_MONEY].dp = (void *)str_money; /* dinero del jugador */
103 shop_main_dlg[IDX_DESC].dp = (void *)str_desc; /* descripcion */
104 shop_main_dlg[IDX_BMP].dp = NULL; /* bitmap */
105 shop_main_dlg[IDX_CANT].dp = (void *)str_cant; /* cantidad que tiene */
106 shop_main_dlg[IDX_PRICE].dp = (void *)str_precio; /* precio */
110 if (ret == IDX_NEXT_BTN) // proximo item
112 int i, i2;
113 i2 = item_idx;
115 for(i = 0; i < MAX_ARM_CLASS; i++)
117 i2++;
118 if (i2 > MAX_ARM_CLASS-1) i2 = -2;
119 if (i2 > -1)
121 if ( arma_tipo[i2].precio >= 0)
123 item_idx = i2;
124 break;
127 if (i2 == -1 || i2 == -2)
129 item_idx = i2;
130 break;
133 } // fin proximo item
135 if (ret == IDX_PREV_BTN) // item anterior
137 int i, i2;
138 i2 = item_idx;
140 for(i = 0; i < MAX_ARM_CLASS; i++)
142 i2--;
143 if (i2 < -2) i2 = MAX_ARM_CLASS-1;
145 if (i2 > -1)
147 if ( arma_tipo[i2].precio >= 0)
149 item_idx = i2;
150 break;
153 if (i2 == -1 || i2 == -2)
155 item_idx = i2;
156 break;
159 } // fin item anterior
161 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
162 /* Setear informacion real */
163 if (item_idx < 0) // es la energia o la bomba?
165 if (item_idx == -1)
167 /* item - energia */
168 shop_main_dlg[IDX_DESC].dp = (void *)jugador.reparar_desc;
170 sprintf(str_precio,"$ %9d x %4d", jugador.reparar_precio, jugador.reparar_cantidad);
172 sprintf(str_cant,"%4d / %4d", jugador.vida, MAX_ENERGIA);
174 shop_main_dlg[IDX_BMP].dp = (void *)jugador.reparar_bmp;
177 if (item_idx == -2)
179 /* item - bomba */
180 shop_main_dlg[IDX_DESC].dp = (void *)jugador.bomba_desc;
182 sprintf(str_precio,"$ %9d x %4d", jugador.bomba_precio, jugador.bomba_cantidad);
184 sprintf(str_cant,"%4d / %4d", jugador.bombas, jugador.max_bombas);
186 shop_main_dlg[IDX_BMP].dp = (void *)jugador.bomba_bmp;
189 else
190 { /* arma */
191 shop_main_dlg[IDX_BMP].dp = (void *)arma_tipo[item_idx].arma;
192 shop_main_dlg[IDX_DESC].dp = (void *)arma_tipo[item_idx].desc;
193 // si es el arma 0, es infinita...
194 if (item_idx == 0)
196 sprintf(str_precio, "N/A");
197 sprintf(str_cant, "N/A");
199 else // arma normal
201 sprintf(str_precio,"$ %9d x %4d", arma_tipo[item_idx].precio, arma_tipo[item_idx].cant_ammo);
202 sprintf(str_cant,"%4d / %4d", jugador.arma[item_idx], arma_tipo[item_idx].cant_ammo_max );
208 if (item_idx < -2) item_idx = -2;
210 /* desabilita el boton 'vender' si es la energia, bombas o el arma 0 */
211 if (item_idx <= 0)
212 shop_main_dlg[IDX_SELL_BTN].flags = D_DISABLED | D_EXIT;
213 else
215 shop_main_dlg[IDX_SELL_BTN].flags = D_EXIT;
216 /* desabilita el boton 'vender' si no tiene suficiente para vender */
217 if (jugador.arma[item_idx] < arma_tipo[item_idx].cant_ammo) shop_main_dlg[IDX_SELL_BTN].flags = D_DISABLED | D_EXIT;
220 /* desabilita el boton 'comprar' si es el arma 0 */
221 if (item_idx == 0)
222 shop_main_dlg[IDX_BUY_BTN].flags = D_DISABLED | D_EXIT;
223 else
224 shop_main_dlg[IDX_BUY_BTN].flags = D_EXIT;
226 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
227 set_mouse_sprite(NULL); /* acomoda puntero del mouse para que se ajuste a los colores */
229 ret = do_dialog(shop_main_dlg, ret); /* mostrar dialogo */
231 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
232 /* comprar */
233 if (ret == IDX_BUY_BTN)
235 if (item_idx > -1)
237 /* comprar armamento */
238 if ( jugador.dinero >= arma_tipo[item_idx].precio ) // tiene la plata?
240 if (jugador.arma[item_idx] + arma_tipo[item_idx].cant_ammo > arma_tipo[item_idx].cant_ammo_max) // tiene espacio para mas?
242 alert(get_config_text("You reached the maximum capacity of load"),
243 NULL, NULL,
244 get_config_text("OK"),
245 NULL, 0, 0);
247 else
249 if (alert(get_config_text("Buy this weapon"),
250 NULL,
251 NULL,
252 get_config_text("Yes"),
253 get_config_text("No"),
254 0, 0) == 1)
256 jugador.arma[item_idx] += arma_tipo[item_idx].cant_ammo;
257 jugador.dinero -= arma_tipo[item_idx].precio;
258 jugador.arma_actual = item_idx; /* arma seleccionada */
262 else
264 /* no tiene dinero */
265 alert(get_config_text("You need more money"),
266 NULL, NULL,
267 get_config_text("OK"),
268 NULL, 0, 0);
271 else
273 if (item_idx == -1)
275 /* compro energia */
276 if ( jugador.dinero >= jugador.reparar_precio )
278 if (jugador.vida >= MAX_ENERGIA)
280 alert(get_config_text("You have the maximum"),
281 NULL, NULL,
282 get_config_text("OK"),
283 NULL, 0, 0);
285 else
287 if (alert(get_config_text("Buy"),
288 NULL,
289 NULL,
290 get_config_text("Yes"),
291 get_config_text("No"),
292 0, 0) == 1)
294 jugador.vida += jugador.reparar_cantidad;
295 if (jugador.vida >= MAX_ENERGIA) jugador.vida = MAX_ENERGIA;
296 jugador.dinero -= jugador.reparar_precio;
300 else
302 /* no tiene dinero */
303 alert(get_config_text("You need more money"),
304 NULL, NULL,
305 get_config_text("OK"),
306 NULL, 0, 0);
310 if (item_idx == -2)
312 /* compro bombas */
313 if ( jugador.dinero >= jugador.bomba_precio )
315 if (jugador.bombas >= jugador.max_bombas)
317 alert(get_config_text("You have the maximum"),
318 NULL, NULL,
319 get_config_text("OK"),
320 NULL, 0, 0);
322 else
324 if (alert(get_config_text("Buy"),
325 NULL,
326 NULL,
327 get_config_text("Yes"),
328 get_config_text("No"),
329 0, 0) == 1)
331 jugador.bombas += jugador.bomba_cantidad;
332 if (jugador.bombas >= jugador.max_bombas) jugador.bombas = jugador.max_bombas;
333 jugador.dinero -= jugador.bomba_precio;
337 else
339 /* no tiene dinero */
340 alert(get_config_text("You need more money"),
341 NULL, NULL,
342 get_config_text("OK"),
343 NULL, 0, 0);
347 } // fin comprar
349 /* vender */
350 if (ret == IDX_SELL_BTN)
352 char tmp[512];
353 sprintf(tmp, "$ %d", arma_tipo[item_idx].precio/2);
355 if (item_idx > -1) /* la energia no se puede vender.. sorry.. */
357 /* vender armamento */
358 if (jugador.arma[item_idx] >= arma_tipo[item_idx].cant_ammo) // solo si tiene suficiente
360 if (alert(get_config_text("Sell this weapon"),
361 get_config_text("Price"),
362 tmp,
363 get_config_text("Yes"),
364 get_config_text("No"),
365 0, 0) == 1)
367 jugador.arma[item_idx] -= arma_tipo[item_idx].cant_ammo;
368 jugador.dinero += arma_tipo[item_idx].precio / 2;
369 jugador.arma_actual = 0; /* arma 0 seleccionada, esto para evitar un bug al vender armas */
373 } // fin vender
375 if (ret == IDX_SAVE_BTN) // salvar
377 salvar_juego_menu();
378 } // fin salvar
380 } // fin loop principal