2 --------------------------------------------------------
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 --------------------------------------------------------
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
44 #define IDX_SELL_BTN 6
45 #define IDX_SAVE_BTN 7
46 #define IDX_EXIT_BTN 8
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));
83 stretch_blit( shop_bmp
,
92 /* looping principal */
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
115 for(i
= 0; i
< MAX_ARM_CLASS
; i
++)
118 if (i2
> MAX_ARM_CLASS
-1) i2
= -2;
121 if ( arma_tipo
[i2
].precio
>= 0)
127 if (i2
== -1 || i2
== -2)
133 } // fin proximo item
135 if (ret
== IDX_PREV_BTN
) // item anterior
140 for(i
= 0; i
< MAX_ARM_CLASS
; i
++)
143 if (i2
< -2) i2
= MAX_ARM_CLASS
-1;
147 if ( arma_tipo
[i2
].precio
>= 0)
153 if (i2
== -1 || i2
== -2)
159 } // fin item anterior
161 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
162 /* Setear informacion real */
163 if (item_idx
< 0) // es la energia o la bomba?
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
;
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
;
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...
196 sprintf(str_precio
, "N/A");
197 sprintf(str_cant
, "N/A");
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 */
212 shop_main_dlg
[IDX_SELL_BTN
].flags
= D_DISABLED
| D_EXIT
;
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 */
222 shop_main_dlg
[IDX_BUY_BTN
].flags
= D_DISABLED
| D_EXIT
;
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 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
233 if (ret
== IDX_BUY_BTN
)
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"),
244 get_config_text("OK"),
249 if (alert(get_config_text("Buy this weapon"),
252 get_config_text("Yes"),
253 get_config_text("No"),
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 */
264 /* no tiene dinero */
265 alert(get_config_text("You need more money"),
267 get_config_text("OK"),
276 if ( jugador
.dinero
>= jugador
.reparar_precio
)
278 if (jugador
.vida
>= MAX_ENERGIA
)
280 alert(get_config_text("You have the maximum"),
282 get_config_text("OK"),
287 if (alert(get_config_text("Buy"),
290 get_config_text("Yes"),
291 get_config_text("No"),
294 jugador
.vida
+= jugador
.reparar_cantidad
;
295 if (jugador
.vida
>= MAX_ENERGIA
) jugador
.vida
= MAX_ENERGIA
;
296 jugador
.dinero
-= jugador
.reparar_precio
;
302 /* no tiene dinero */
303 alert(get_config_text("You need more money"),
305 get_config_text("OK"),
313 if ( jugador
.dinero
>= jugador
.bomba_precio
)
315 if (jugador
.bombas
>= jugador
.max_bombas
)
317 alert(get_config_text("You have the maximum"),
319 get_config_text("OK"),
324 if (alert(get_config_text("Buy"),
327 get_config_text("Yes"),
328 get_config_text("No"),
331 jugador
.bombas
+= jugador
.bomba_cantidad
;
332 if (jugador
.bombas
>= jugador
.max_bombas
) jugador
.bombas
= jugador
.max_bombas
;
333 jugador
.dinero
-= jugador
.bomba_precio
;
339 /* no tiene dinero */
340 alert(get_config_text("You need more money"),
342 get_config_text("OK"),
350 if (ret
== IDX_SELL_BTN
)
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"),
363 get_config_text("Yes"),
364 get_config_text("No"),
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 */
375 if (ret
== IDX_SAVE_BTN
) // salvar
380 } // fin loop principal