1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_button_c = |
|
|
4 | * "$Id: button.C,v 1.8 2006/09/11 20:28:37 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
|
|
7 | /* |
1 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
9 | |
3 | |
10 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
11 | Copyright (C) 1992 Frank Tore Johansen |
5 | Copyright (C) 1992 Frank Tore Johansen |
… | |
… | |
22 | |
16 | |
23 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
20 | |
27 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
28 | */ |
22 | */ |
29 | |
23 | |
30 | #include <global.h> |
24 | #include <global.h> |
31 | #include <funcpoint.h> |
25 | #include <funcpoint.h> |
32 | |
26 | |
… | |
… | |
193 | * the connection was 'state' or 'released'. So that you can activate objects |
187 | * the connection was 'state' or 'released'. So that you can activate objects |
194 | * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly. |
188 | * who have FLAG_ACTIVATE_ON_PUSH/RELEASE set properly. |
195 | * |
189 | * |
196 | */ |
190 | */ |
197 | void |
191 | void |
198 | activate_connection (mapstruct *map, long connection, bool state) |
192 | activate_connection (maptile *map, long connection, bool state) |
199 | { |
193 | { |
200 | if (INVOKE_MAP (TRIGGER, map, ARG_INT64 (connection), ARG_INT (state))) |
194 | if (INVOKE_MAP (TRIGGER, map, ARG_INT64 (connection), ARG_INT (state))) |
201 | return; |
195 | return; |
202 | |
196 | |
203 | oblinkpt *obp = get_connection_links (map, connection); |
197 | oblinkpt *obp = get_connection_links (map, connection); |
… | |
… | |
287 | /* |
281 | /* |
288 | * Updates every button on the map (by calling update_button() for them). |
282 | * Updates every button on the map (by calling update_button() for them). |
289 | */ |
283 | */ |
290 | |
284 | |
291 | void |
285 | void |
292 | update_buttons (mapstruct *m) |
286 | update_buttons (maptile *m) |
293 | { |
287 | { |
294 | objectlink *ol; |
288 | objectlink *ol; |
295 | oblinkpt *obp; |
289 | oblinkpt *obp; |
296 | |
290 | |
297 | for (obp = m->buttons; obp; obp = obp->next) |
291 | for (obp = m->buttons; obp; obp = obp->next) |
… | |
… | |
364 | return 1; |
358 | return 1; |
365 | } |
359 | } |
366 | return 0; |
360 | return 0; |
367 | } |
361 | } |
368 | |
362 | |
369 | |
|
|
370 | /* |
363 | /* |
371 | * operate_altar checks if sacrifice was accepted and removes sacrificed |
364 | * operate_altar checks if sacrifice was accepted and removes sacrificed |
372 | * objects. If sacrifice was succeed return 1 else 0. Might be better to |
365 | * objects. If sacrifice was succeed return 1 else 0. Might be better to |
373 | * call check_altar_sacrifice (above) than depend on the return value, |
366 | * call check_altar_sacrifice (above) than depend on the return value, |
374 | * since operate_altar will remove the sacrifice also. |
367 | * since operate_altar will remove the sacrifice also. |
375 | * |
368 | * |
376 | * If this function returns 1, '*sacrifice' is modified to point to the |
369 | * If this function returns 1, '*sacrifice' is modified to point to the |
377 | * remaining sacrifice, or is set to NULL if the sacrifice was used up. |
370 | * remaining sacrifice, or is set to NULL if the sacrifice was used up. |
378 | */ |
371 | */ |
379 | |
|
|
380 | int |
372 | int |
381 | operate_altar (object *altar, object **sacrifice) |
373 | operate_altar (object *altar, object **sacrifice) |
382 | { |
374 | { |
383 | |
|
|
384 | if (!altar->map) |
375 | if (!altar->map) |
385 | { |
376 | { |
386 | LOG (llevError, "BUG: operate_altar(): altar has no map\n"); |
377 | LOG (llevError, "BUG: operate_altar(): altar has no map\n"); |
387 | return 0; |
378 | return 0; |
388 | } |
379 | } |
… | |
… | |
401 | int number = NROF_SACRIFICE (altar) / (*sacrifice)->value; |
392 | int number = NROF_SACRIFICE (altar) / (*sacrifice)->value; |
402 | |
393 | |
403 | /* Round up any sacrifices. Altars don't make change either */ |
394 | /* Round up any sacrifices. Altars don't make change either */ |
404 | if (NROF_SACRIFICE (altar) % (*sacrifice)->value) |
395 | if (NROF_SACRIFICE (altar) % (*sacrifice)->value) |
405 | number++; |
396 | number++; |
|
|
397 | |
406 | *sacrifice = decrease_ob_nr (*sacrifice, number); |
398 | *sacrifice = decrease_ob_nr (*sacrifice, number); |
407 | } |
399 | } |
408 | else |
400 | else |
409 | *sacrifice = decrease_ob_nr (*sacrifice, NROF_SACRIFICE (altar)); |
401 | *sacrifice = decrease_ob_nr (*sacrifice, NROF_SACRIFICE (altar)); |
410 | |
402 | |
411 | if (altar->msg) |
403 | if (altar->msg) |
412 | new_info_map (NDI_BLACK, altar->map, altar->msg); |
404 | new_info_map (NDI_BLACK, altar->map, altar->msg); |
|
|
405 | |
413 | return 1; |
406 | return 1; |
414 | } |
407 | } |
415 | |
408 | |
416 | void |
409 | void |
417 | trigger_move (object *op, int state) /* 1 down and 0 up */ |
410 | trigger_move (object *op, int state) /* 1 down and 0 up */ |
… | |
… | |
602 | return 0; |
595 | return 0; |
603 | } |
596 | } |
604 | } |
597 | } |
605 | |
598 | |
606 | void |
599 | void |
607 | add_button_link (object *button, mapstruct *map, int connected) |
600 | add_button_link (object *button, maptile *map, int connected) |
608 | { |
601 | { |
609 | oblinkpt *obp; |
602 | oblinkpt *obp; |
610 | objectlink *ol = get_objectlink (); |
603 | objectlink *ol = get_objectlink (); |
611 | |
604 | |
612 | if (!map) |
605 | if (!map) |
… | |
… | |
682 | |
675 | |
683 | /* |
676 | /* |
684 | * Gets the objectlink for this connection from the map. |
677 | * Gets the objectlink for this connection from the map. |
685 | */ |
678 | */ |
686 | oblinkpt * |
679 | oblinkpt * |
687 | get_connection_links (mapstruct *map, long connection) |
680 | get_connection_links (maptile *map, long connection) |
688 | { |
681 | { |
689 | for (oblinkpt * obp = map->buttons; obp; obp = obp->next) |
682 | for (oblinkpt * obp = map->buttons; obp; obp = obp->next) |
690 | if (obp->value == connection) |
683 | if (obp->value == connection) |
691 | return obp; |
684 | return obp; |
692 | return 0; |
685 | return 0; |
… | |
… | |
878 | /* This does a minimal check of the button link consistency for object |
871 | /* This does a minimal check of the button link consistency for object |
879 | * map. All it really does it much sure the object id link that is set |
872 | * map. All it really does it much sure the object id link that is set |
880 | * matches what the object has. |
873 | * matches what the object has. |
881 | */ |
874 | */ |
882 | void |
875 | void |
883 | verify_button_links (const mapstruct *map) |
876 | verify_button_links (const maptile *map) |
884 | { |
877 | { |
885 | oblinkpt *obp; |
878 | oblinkpt *obp; |
886 | objectlink *ol; |
879 | objectlink *ol; |
887 | |
880 | |
888 | if (!map) |
881 | if (!map) |