1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
… | |
… | |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <funcpoint.h> |
|
|
26 | |
25 | |
27 | /* |
26 | /* |
28 | * This code is no longer highly inefficient 8) |
27 | * This code is no longer highly inefficient 8) |
29 | */ |
28 | */ |
30 | |
29 | |
… | |
… | |
216 | * button reacts to the (eventual) change of state. |
215 | * button reacts to the (eventual) change of state. |
217 | */ |
216 | */ |
218 | void |
217 | void |
219 | update_button (object *op) |
218 | update_button (object *op) |
220 | { |
219 | { |
221 | object *ab, *tmp, *head; |
|
|
222 | int tot, any_down = 0, old_value = op->value; |
220 | int any_down = 0, old_value = op->value; |
223 | oblinkpt *obp = 0; |
221 | oblinkpt *obp = 0; |
224 | objectlink *ol; |
222 | objectlink *ol; |
225 | |
223 | |
226 | obp = get_button_links (op); |
224 | obp = get_button_links (op); |
227 | /* LOG(llevDebug, "update_button: %s (%d)\n", op->name, op->count); */ |
|
|
228 | if (obp) |
225 | if (obp) |
229 | for (ol = obp->link; ol; ol = ol->next) |
226 | for (ol = obp->link; ol; ol = ol->next) |
230 | { |
227 | { |
231 | if (!ol->ob) |
228 | if (!ol->ob) |
232 | { |
229 | { |
233 | LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name); |
230 | LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name); |
234 | continue; |
231 | continue; |
235 | } |
232 | } |
236 | |
233 | |
237 | tmp = ol->ob; |
234 | object *tmp = ol->ob; |
|
|
235 | |
238 | if (tmp->type == BUTTON) |
236 | if (tmp->type == BUTTON) |
239 | { |
237 | { |
|
|
238 | sint32 total = 0; |
|
|
239 | |
240 | for (ab = tmp->above, tot = 0; ab; ab = ab->above) |
240 | for (object *ab = tmp->above; ab; ab = ab->above) |
|
|
241 | /* Basically, if the move_type matches that on what the |
|
|
242 | * button wants, we count it. The second check is so that |
|
|
243 | * objects who don't move (swords, etc) will count. Note that |
|
|
244 | * this means that more work is needed to make buttons |
|
|
245 | * that are only triggered by flying objects. |
|
|
246 | */ |
|
|
247 | if ((ab->move_type & tmp->move_on) || ab->move_type == 0) |
|
|
248 | total += ab->head_ ()->total_weight (); |
|
|
249 | |
|
|
250 | tmp->value = total >= tmp->weight; |
|
|
251 | |
|
|
252 | any_down = any_down || tmp->value; |
|
|
253 | } |
|
|
254 | else if (tmp->type == PEDESTAL) |
|
|
255 | { |
|
|
256 | tmp->value = 0; |
|
|
257 | |
|
|
258 | for (object *ab = tmp->above; ab; ab = ab->above) |
241 | { |
259 | { |
242 | head = ab->head_ (); |
260 | object *head = ab->head_ (); |
243 | |
|
|
244 | /* Basically, if the move_type matches that on what the |
|
|
245 | * button wants, we count it. The second check is so that |
|
|
246 | * objects who don't move (swords, etc) will count. Note that |
|
|
247 | * this means that more work is needed to make buttons |
|
|
248 | * that are only triggered by flying objects. |
|
|
249 | */ |
|
|
250 | if ((head->move_type & tmp->move_on) || head->move_type == 0) |
|
|
251 | tot += head->total_weight (); |
|
|
252 | } |
|
|
253 | |
|
|
254 | tmp->value = tot >= tmp->weight ? 1 : 0; |
|
|
255 | } |
|
|
256 | else if (tmp->type == PEDESTAL) |
|
|
257 | { |
|
|
258 | tmp->value = 0; |
|
|
259 | |
|
|
260 | for (ab = tmp->above; ab; ab = ab->above) |
|
|
261 | { |
|
|
262 | head = ab->head_ (); |
|
|
263 | |
261 | |
264 | /* Same note regarding move_type for buttons above apply here. */ |
262 | /* Same note regarding move_type for buttons above apply here. */ |
265 | if (((head->move_type & tmp->move_on) || ab->move_type == 0) && |
263 | if (((ab->move_type & tmp->move_on) || ab->move_type == 0) |
266 | (head->race == tmp->slaying || |
264 | && (head->race == tmp->slaying |
267 | ((head->type == SPECIAL_KEY) && (head->slaying == tmp->slaying)) || |
265 | || (head->type == SPECIAL_KEY && head->slaying == tmp->slaying) |
268 | (!strcmp (tmp->slaying, "player") && head->type == PLAYER))) |
266 | || (tmp->slaying == shstr_player && head->type == PLAYER))) |
269 | tmp->value = 1; |
267 | tmp->value = 1; |
270 | } |
268 | } |
271 | } |
|
|
272 | |
269 | |
273 | any_down = any_down || tmp->value; |
270 | any_down = any_down || tmp->value; |
|
|
271 | } |
274 | } |
272 | } |
275 | |
273 | |
276 | if (any_down) /* If any other buttons were down, force this to remain down */ |
274 | if (any_down) /* If any other buttons were down, force this to remain down */ |
277 | op->value = 1; |
275 | op->value = 1; |
|
|
276 | |
|
|
277 | //LOG(llevDebug, "update_button: %s (%d, %d=%d)\n", &op->name, op->count, op->value, old_value); |
278 | |
278 | |
279 | /* If this button hasn't changed, don't do anything */ |
279 | /* If this button hasn't changed, don't do anything */ |
280 | if (op->value != old_value) |
280 | if (op->value != old_value) |
281 | { |
281 | { |
282 | SET_ANIMATION (op, op->value); |
282 | SET_ANIMATION (op, op->value); |
… | |
… | |
376 | |
376 | |
377 | /* Round up any sacrifices. Altars don't make change either */ |
377 | /* Round up any sacrifices. Altars don't make change either */ |
378 | if (NROF_SACRIFICE (altar) % (*sacrifice)->value) |
378 | if (NROF_SACRIFICE (altar) % (*sacrifice)->value) |
379 | number++; |
379 | number++; |
380 | |
380 | |
381 | *sacrifice = decrease_ob_nr (*sacrifice, number); |
381 | if (!(*sacrifice)->decrease (number)) |
|
|
382 | *sacrifice = 0; |
382 | } |
383 | } |
383 | else |
384 | else |
384 | *sacrifice = decrease_ob_nr (*sacrifice, NROF_SACRIFICE (altar)); |
385 | if (!(*sacrifice)->decrease (NROF_SACRIFICE (altar))) |
|
|
386 | *sacrifice = 0; |
385 | |
387 | |
386 | if (altar->msg) |
388 | if (altar->msg) |
387 | new_info_map (NDI_BLACK, altar->map, altar->msg); |
389 | new_info_map (NDI_BLACK, altar->map, altar->msg); |
388 | |
390 | |
389 | return 1; |
391 | return 1; |
… | |
… | |
426 | int push = 0, tot = 0; |
428 | int push = 0, tot = 0; |
427 | int in_movement = op->stats.wc || op->speed; |
429 | int in_movement = op->stats.wc || op->speed; |
428 | |
430 | |
429 | switch (op->type) |
431 | switch (op->type) |
430 | { |
432 | { |
431 | case TRIGGER_BUTTON: |
433 | case TRIGGER_BUTTON: |
432 | if (op->weight > 0) |
434 | if (op->weight > 0) |
433 | { |
435 | { |
434 | if (cause) |
436 | if (cause) |
435 | { |
437 | { |
436 | for (tmp = op->above; tmp; tmp = tmp->above) |
438 | for (tmp = op->above; tmp; tmp = tmp->above) |
437 | /* Comment reproduced from update_buttons(): */ |
439 | /* Comment reproduced from update_buttons(): */ |
438 | /* Basically, if the move_type matches that on what the |
440 | /* Basically, if the move_type matches that on what the |
439 | * button wants, we count it. The second check is so that |
441 | * button wants, we count it. The second check is so that |
440 | * objects that don't move (swords, etc) will count. Note that |
442 | * objects that don't move (swords, etc) will count. Note that |
441 | * this means that more work is needed to make buttons |
443 | * this means that more work is needed to make buttons |
442 | * that are only triggered by flying objects. |
444 | * that are only triggered by flying objects. |
|
|
445 | */ |
|
|
446 | if ((tmp->move_type & op->move_on) || tmp->move_type == 0) |
|
|
447 | tot += tmp->head_ ()->total_weight (); |
|
|
448 | |
|
|
449 | if (tot >= op->weight) |
|
|
450 | push = 1; |
|
|
451 | |
|
|
452 | if (op->stats.ac == push) |
|
|
453 | return 0; |
|
|
454 | |
|
|
455 | op->stats.ac = push; |
|
|
456 | if (NUM_ANIMATIONS (op) > 1) |
|
|
457 | { |
|
|
458 | SET_ANIMATION (op, push); |
|
|
459 | update_object (op, UP_OBJ_FACE); |
|
|
460 | } |
|
|
461 | |
|
|
462 | if (in_movement || !push) |
|
|
463 | return 0; |
|
|
464 | } |
|
|
465 | trigger_move (op, push); |
|
|
466 | } |
|
|
467 | |
|
|
468 | return 0; |
|
|
469 | |
|
|
470 | case TRIGGER_PEDESTAL: |
|
|
471 | if (cause) |
|
|
472 | { |
|
|
473 | for (tmp = op->above; tmp; tmp = tmp->above) |
|
|
474 | { |
|
|
475 | object *head = tmp->head_ (); |
|
|
476 | |
|
|
477 | /* See comment in TRIGGER_BUTTON about move_types */ |
|
|
478 | if (((head->move_type & op->move_on) || head->move_type == 0) |
|
|
479 | && (head->race == op->slaying || (!strcmp (op->slaying, "player") && head->type == PLAYER))) |
|
|
480 | { |
|
|
481 | push = 1; |
|
|
482 | break; |
|
|
483 | } |
|
|
484 | } |
|
|
485 | |
|
|
486 | if (op->stats.ac == push) |
|
|
487 | return 0; |
|
|
488 | |
|
|
489 | op->stats.ac = push; |
|
|
490 | |
|
|
491 | if (NUM_ANIMATIONS (op) > 1) |
|
|
492 | { |
|
|
493 | SET_ANIMATION (op, push); |
|
|
494 | update_object (op, UP_OBJ_FACE); |
|
|
495 | } |
|
|
496 | |
|
|
497 | update_object (op, UP_OBJ_FACE); |
|
|
498 | |
|
|
499 | if (in_movement || !push) |
|
|
500 | return 0; |
|
|
501 | } |
|
|
502 | |
|
|
503 | trigger_move (op, push); |
|
|
504 | return 0; |
|
|
505 | |
|
|
506 | case TRIGGER_ALTAR: |
|
|
507 | if (cause) |
|
|
508 | { |
|
|
509 | if (in_movement) |
|
|
510 | return 0; |
|
|
511 | |
|
|
512 | if (operate_altar (op, &cause)) |
|
|
513 | { |
|
|
514 | if (NUM_ANIMATIONS (op) > 1) |
|
|
515 | { |
|
|
516 | SET_ANIMATION (op, 1); |
|
|
517 | update_object (op, UP_OBJ_FACE); |
|
|
518 | } |
|
|
519 | |
|
|
520 | if (op->last_sp >= 0) |
|
|
521 | { |
|
|
522 | trigger_move (op, 1); |
|
|
523 | if (op->last_sp > 0) |
|
|
524 | op->last_sp = -op->last_sp; |
|
|
525 | } |
|
|
526 | else |
|
|
527 | { |
|
|
528 | /* for trigger altar with last_sp, the ON/OFF |
|
|
529 | * status (-> +/- value) is "simulated": |
443 | */ |
530 | */ |
444 | if ((tmp->move_type & op->move_on) || tmp->move_type == 0) |
531 | op->value = !op->value; |
445 | tot += tmp->head_ ()->total_weight (); |
532 | trigger_move (op, 1); |
446 | |
533 | op->last_sp = -op->last_sp; |
447 | if (tot >= op->weight) |
534 | op->value = !op->value; |
448 | push = 1; |
|
|
449 | |
|
|
450 | if (op->stats.ac == push) |
|
|
451 | return 0; |
|
|
452 | |
|
|
453 | op->stats.ac = push; |
|
|
454 | if (NUM_ANIMATIONS (op) > 1) |
|
|
455 | { |
|
|
456 | SET_ANIMATION (op, push); |
|
|
457 | update_object (op, UP_OBJ_FACE); |
|
|
458 | } |
535 | } |
459 | |
536 | |
460 | if (in_movement || !push) |
537 | return cause == NULL; |
461 | return 0; |
|
|
462 | } |
538 | } |
463 | trigger_move (op, push); |
|
|
464 | } |
539 | else |
465 | |
|
|
466 | return 0; |
|
|
467 | |
|
|
468 | case TRIGGER_PEDESTAL: |
|
|
469 | if (cause) |
|
|
470 | { |
|
|
471 | for (tmp = op->above; tmp; tmp = tmp->above) |
|
|
472 | { |
|
|
473 | object *head = tmp->head_ (); |
|
|
474 | |
|
|
475 | /* See comment in TRIGGER_BUTTON about move_types */ |
|
|
476 | if (((head->move_type & op->move_on) || head->move_type == 0) |
|
|
477 | && (head->race == op->slaying || (!strcmp (op->slaying, "player") && head->type == PLAYER))) |
|
|
478 | { |
|
|
479 | push = 1; |
|
|
480 | break; |
|
|
481 | } |
|
|
482 | } |
|
|
483 | |
|
|
484 | if (op->stats.ac == push) |
|
|
485 | return 0; |
540 | return 0; |
486 | |
541 | } |
487 | op->stats.ac = push; |
542 | else |
488 | |
543 | { |
489 | if (NUM_ANIMATIONS (op) > 1) |
544 | if (NUM_ANIMATIONS (op) > 1) |
490 | { |
545 | { |
491 | SET_ANIMATION (op, push); |
546 | SET_ANIMATION (op, 0); |
492 | update_object (op, UP_OBJ_FACE); |
547 | update_object (op, UP_OBJ_FACE); |
493 | } |
548 | } |
494 | |
549 | |
495 | update_object (op, UP_OBJ_FACE); |
|
|
496 | |
|
|
497 | if (in_movement || !push) |
|
|
498 | return 0; |
|
|
499 | } |
|
|
500 | |
|
|
501 | trigger_move (op, push); |
|
|
502 | return 0; |
|
|
503 | |
|
|
504 | case TRIGGER_ALTAR: |
|
|
505 | if (cause) |
|
|
506 | { |
|
|
507 | if (in_movement) |
|
|
508 | return 0; |
|
|
509 | |
|
|
510 | if (operate_altar (op, &cause)) |
|
|
511 | { |
|
|
512 | if (NUM_ANIMATIONS (op) > 1) |
|
|
513 | { |
|
|
514 | SET_ANIMATION (op, 1); |
|
|
515 | update_object (op, UP_OBJ_FACE); |
|
|
516 | } |
|
|
517 | |
|
|
518 | if (op->last_sp >= 0) |
|
|
519 | { |
|
|
520 | trigger_move (op, 1); |
|
|
521 | if (op->last_sp > 0) |
|
|
522 | op->last_sp = -op->last_sp; |
|
|
523 | } |
|
|
524 | else |
|
|
525 | { |
|
|
526 | /* for trigger altar with last_sp, the ON/OFF |
|
|
527 | * status (-> +/- value) is "simulated": |
|
|
528 | */ |
|
|
529 | op->value = !op->value; |
|
|
530 | trigger_move (op, 1); |
|
|
531 | op->last_sp = -op->last_sp; |
|
|
532 | op->value = !op->value; |
|
|
533 | } |
|
|
534 | |
|
|
535 | return cause == NULL; |
|
|
536 | } |
|
|
537 | else |
|
|
538 | return 0; |
|
|
539 | } |
|
|
540 | else |
|
|
541 | { |
|
|
542 | if (NUM_ANIMATIONS (op) > 1) |
|
|
543 | { |
|
|
544 | SET_ANIMATION (op, 0); |
|
|
545 | update_object (op, UP_OBJ_FACE); |
|
|
546 | } |
|
|
547 | |
|
|
548 | /* If trigger_altar has "last_sp > 0" set on the map, |
550 | /* If trigger_altar has "last_sp > 0" set on the map, |
549 | * it will push the connected value only once per sacrifice. |
551 | * it will push the connected value only once per sacrifice. |
550 | * Otherwise (default), the connected value will be |
552 | * Otherwise (default), the connected value will be |
551 | * pushed twice: First by sacrifice, second by reset! -AV |
553 | * pushed twice: First by sacrifice, second by reset! -AV |
552 | */ |
554 | */ |
553 | if (!op->last_sp) |
555 | if (!op->last_sp) |
554 | trigger_move (op, 0); |
556 | trigger_move (op, 0); |
555 | else |
557 | else |
556 | { |
558 | { |
557 | op->stats.wc = 0; |
559 | op->stats.wc = 0; |
558 | op->value = !op->value; |
560 | op->value = !op->value; |
559 | op->set_speed (0); |
561 | op->set_speed (0); |
560 | } |
562 | } |
561 | } |
563 | } |
562 | return 0; |
564 | return 0; |
563 | |
565 | |
564 | case TRIGGER: |
566 | case TRIGGER: |
565 | if (cause) |
567 | if (cause) |
566 | { |
568 | { |
567 | if (in_movement) |
569 | if (in_movement) |
568 | return 0; |
570 | return 0; |
569 | |
571 | |
570 | push = 1; |
572 | push = 1; |
571 | } |
573 | } |
572 | |
574 | |
573 | if (NUM_ANIMATIONS (op) > 1) |
575 | if (NUM_ANIMATIONS (op) > 1) |
574 | { |
576 | { |
575 | SET_ANIMATION (op, push); |
577 | SET_ANIMATION (op, push); |
576 | update_object (op, UP_OBJ_FACE); |
578 | update_object (op, UP_OBJ_FACE); |
577 | } |
579 | } |
578 | |
580 | |
579 | trigger_move (op, push); |
581 | trigger_move (op, push); |
580 | return 1; |
582 | return 1; |
581 | |
583 | |
582 | default: |
584 | default: |
583 | LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); |
585 | LOG (llevDebug, "Unknown trigger type: %s (%d)\n", &op->name, op->type); |
584 | return 0; |
586 | return 0; |
585 | } |
587 | } |
586 | } |
588 | } |
587 | |
589 | |
588 | void |
590 | void |
589 | add_button_link (object *button, maptile *map, int connected) |
591 | add_button_link (object *button, maptile *map, int connected) |
… | |
… | |
808 | |
810 | |
809 | // FALL THROUGH |
811 | // FALL THROUGH |
810 | case 5: // kill all alives |
812 | case 5: // kill all alives |
811 | if (!tmp->flag [FLAG_PRECIOUS]) |
813 | if (!tmp->flag [FLAG_PRECIOUS]) |
812 | { |
814 | { |
813 | get_archetype ("burnout")->insert_at (tmp, source); |
815 | archetype::get (shstr_burnout)->insert_at (tmp, source); |
814 | tmp->destroy (); |
816 | tmp->destroy (true); |
815 | } |
817 | } |
816 | break; |
818 | break; |
817 | |
819 | |
818 | default: |
820 | default: |
819 | break; |
821 | break; |
… | |
… | |
893 | // and we have to set the value to 0 |
895 | // and we have to set the value to 0 |
894 | |
896 | |
895 | if (match && trig->last_sp) // match == having |
897 | if (match && trig->last_sp) // match == having |
896 | { |
898 | { |
897 | if (trig->last_heal) |
899 | if (trig->last_heal) |
898 | decrease_ob (match); |
900 | match->decrease (); |
899 | |
901 | |
900 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
902 | trig->value = (pl == op ? 1 : 0); // 1 if matching player entered, and 0 if he left |
901 | push_button (trig); |
903 | push_button (trig); |
902 | } |
904 | } |
903 | else if (!match && !trig->last_sp) // match == not having |
905 | else if (!match && !trig->last_sp) // match == not having |