ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/button.C
(Generate patch)

Comparing deliantra/server/common/button.C (file contents):
Revision 1.41 by root, Wed Apr 9 14:36:47 2008 UTC vs.
Revision 1.46 by root, Sun May 4 18:24:11 2008 UTC

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 */
218void 217void
219update_button (object *op) 218update_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 != NULL; ab = ab->above) 240 for (object *ab = tmp->above; ab; ab = ab->above)
241 /* Bug? The pedestal code below looks for the head of
242 * the object, this bit doesn't. I'd think we should check
243 * for head here also. Maybe it also makese sense to
244 * make the for ab=tmp->above loop common, and alter
245 * behaviour based on object within that loop?
246 */
247
248 /* Basically, if the move_type matches that on what the 241 /* Basically, if the move_type matches that on what the
249 * button wants, we count it. The second check is so that 242 * button wants, we count it. The second check is so that
250 * objects don't move (swords, etc) will count. Note that 243 * objects who don't move (swords, etc) will count. Note that
251 * this means that more work is needed to make buttons 244 * this means that more work is needed to make buttons
252 * that are only triggered by flying objects. 245 * that are only triggered by flying objects.
253 */ 246 */
254 if ((ab->move_type & tmp->move_on) || ab->move_type == 0) 247 if ((ab->move_type & tmp->move_on) || ab->move_type == 0)
255 tot += ab->weight * (ab->nrof ? ab->nrof : 1) + ab->carrying; 248 total += ab->head_ ()->total_weight ();
256 249
257 tmp->value = (tot >= tmp->weight) ? 1 : 0; 250 tmp->value = total >= tmp->weight;
258 if (tmp->value) 251
259 any_down = 1; 252 any_down = any_down || tmp->value;
260 } 253 }
261 else if (tmp->type == PEDESTAL) 254 else if (tmp->type == PEDESTAL)
262 { 255 {
263 tmp->value = 0; 256 tmp->value = 0;
257
264 for (ab = tmp->above; ab != NULL; ab = ab->above) 258 for (object *ab = tmp->above; ab; ab = ab->above)
265 { 259 {
266 head = ab->head_ (); 260 object *head = ab->head_ ();
261
267 /* Same note regarding move_type for buttons above apply here. */ 262 /* Same note regarding move_type for buttons above apply here. */
268 if (((head->move_type & tmp->move_on) || ab->move_type == 0) && 263 if (((ab->move_type & tmp->move_on) || ab->move_type == 0)
269 (head->race == tmp->slaying || 264 && (head->race == tmp->slaying
270 ((head->type == SPECIAL_KEY) && (head->slaying == tmp->slaying)) || 265 || (head->type == SPECIAL_KEY && head->slaying == tmp->slaying)
271 (!strcmp (tmp->slaying, "player") && head->type == PLAYER))) 266 || (tmp->slaying == shstr_player && head->type == PLAYER)))
272 tmp->value = 1; 267 tmp->value = 1;
273 } 268 }
274 269
275 if (tmp->value) 270 any_down = any_down || tmp->value;
276 any_down = 1;
277 } 271 }
278 } 272 }
273
279 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 */
280 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);
281 278
282 /* If this button hasn't changed, don't do anything */ 279 /* If this button hasn't changed, don't do anything */
283 if (op->value != old_value) 280 if (op->value != old_value)
284 { 281 {
285 SET_ANIMATION (op, op->value); 282 SET_ANIMATION (op, op->value);
337 334
338 if ((ARCH_SACRIFICE (altar) == sacrifice->arch->archname 335 if ((ARCH_SACRIFICE (altar) == sacrifice->arch->archname
339 || ARCH_SACRIFICE (altar) == sacrifice->name 336 || ARCH_SACRIFICE (altar) == sacrifice->name
340 || ARCH_SACRIFICE (altar) == sacrifice->slaying 337 || ARCH_SACRIFICE (altar) == sacrifice->slaying
341 || strstr (query_base_name (sacrifice, 0), ARCH_SACRIFICE (altar))) 338 || strstr (query_base_name (sacrifice, 0), ARCH_SACRIFICE (altar)))
342 && NROF_SACRIFICE (altar) <= (sacrifice->nrof ? sacrifice->nrof : 1)) 339 && NROF_SACRIFICE (altar) <= sacrifice->number_of ())
343 return 1; 340 return 1;
344 } 341 }
345 342
346 return 0; 343 return 0;
347} 344}
379 376
380 /* Round up any sacrifices. Altars don't make change either */ 377 /* Round up any sacrifices. Altars don't make change either */
381 if (NROF_SACRIFICE (altar) % (*sacrifice)->value) 378 if (NROF_SACRIFICE (altar) % (*sacrifice)->value)
382 number++; 379 number++;
383 380
384 *sacrifice = decrease_ob_nr (*sacrifice, number); 381 if (!(*sacrifice)->decrease (number))
382 *sacrifice = 0;
385 } 383 }
386 else 384 else
387 *sacrifice = decrease_ob_nr (*sacrifice, NROF_SACRIFICE (altar)); 385 if (!(*sacrifice)->decrease (NROF_SACRIFICE (altar)))
386 *sacrifice = 0;
388 387
389 if (altar->msg) 388 if (altar->msg)
390 new_info_map (NDI_BLACK, altar->map, altar->msg); 389 new_info_map (NDI_BLACK, altar->map, altar->msg);
391 390
392 return 1; 391 return 1;
429 int push = 0, tot = 0; 428 int push = 0, tot = 0;
430 int in_movement = op->stats.wc || op->speed; 429 int in_movement = op->stats.wc || op->speed;
431 430
432 switch (op->type) 431 switch (op->type)
433 { 432 {
434 case TRIGGER_BUTTON: 433 case TRIGGER_BUTTON:
435 if (op->weight > 0) 434 if (op->weight > 0)
436 { 435 {
437 if (cause) 436 if (cause)
438 { 437 {
439 for (tmp = op->above; tmp; tmp = tmp->above) 438 for (tmp = op->above; tmp; tmp = tmp->above)
440 /* Comment reproduced from update_buttons(): */ 439 /* Comment reproduced from update_buttons(): */
441 /* Basically, if the move_type matches that on what the 440 /* Basically, if the move_type matches that on what the
442 * button wants, we count it. The second check is so that 441 * button wants, we count it. The second check is so that
443 * objects that don't move (swords, etc) will count. Note that 442 * objects that don't move (swords, etc) will count. Note that
444 * this means that more work is needed to make buttons 443 * this means that more work is needed to make buttons
445 * 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":
446 */ 530 */
447 531 op->value = !op->value;
448 if ((tmp->move_type & op->move_on) || tmp->move_type == 0) 532 trigger_move (op, 1);
449 { 533 op->last_sp = -op->last_sp;
450 tot += tmp->weight * (tmp->nrof ? tmp->nrof : 1) + tmp->carrying; 534 op->value = !op->value;
451 }
452 if (tot >= op->weight)
453 push = 1;
454 if (op->stats.ac == push)
455 return 0;
456 op->stats.ac = push;
457 if (NUM_ANIMATIONS (op) > 1)
458 {
459 SET_ANIMATION (op, push);
460 update_object (op, UP_OBJ_FACE);
461 } 535 }
462 if (in_movement || !push) 536
463 return 0; 537 return cause == NULL;
464 } 538 }
465 trigger_move (op, push);
466 } 539 else
467 return 0;
468
469 case TRIGGER_PEDESTAL:
470 if (cause)
471 {
472 for (tmp = op->above; tmp; tmp = tmp->above)
473 {
474 object *head = tmp->head_ ();
475
476 /* See comment in TRIGGER_BUTTON about move_types */
477 if (((head->move_type & op->move_on) || head->move_type == 0)
478 && (head->race == op->slaying || (!strcmp (op->slaying, "player") && head->type == PLAYER)))
479 {
480 push = 1;
481 break;
482 }
483 }
484
485 if (op->stats.ac == push)
486 return 0; 540 return 0;
487 541 }
488 op->stats.ac = push; 542 else
489 543 {
490 if (NUM_ANIMATIONS (op) > 1) 544 if (NUM_ANIMATIONS (op) > 1)
491 { 545 {
492 SET_ANIMATION (op, push); 546 SET_ANIMATION (op, 0);
493 update_object (op, UP_OBJ_FACE); 547 update_object (op, UP_OBJ_FACE);
494 } 548 }
495 549
496 update_object (op, UP_OBJ_FACE);
497
498 if (in_movement || !push)
499 return 0;
500 }
501
502 trigger_move (op, push);
503 return 0;
504
505 case TRIGGER_ALTAR:
506 if (cause)
507 {
508 if (in_movement)
509 return 0;
510
511 if (operate_altar (op, &cause))
512 {
513 if (NUM_ANIMATIONS (op) > 1)
514 {
515 SET_ANIMATION (op, 1);
516 update_object (op, UP_OBJ_FACE);
517 }
518
519 if (op->last_sp >= 0)
520 {
521 trigger_move (op, 1);
522 if (op->last_sp > 0)
523 op->last_sp = -op->last_sp;
524 }
525 else
526 {
527 /* for trigger altar with last_sp, the ON/OFF
528 * status (-> +/- value) is "simulated":
529 */
530 op->value = !op->value;
531 trigger_move (op, 1);
532 op->last_sp = -op->last_sp;
533 op->value = !op->value;
534 }
535
536 return cause == NULL;
537 }
538 else
539 return 0;
540 }
541 else
542 {
543 if (NUM_ANIMATIONS (op) > 1)
544 {
545 SET_ANIMATION (op, 0);
546 update_object (op, UP_OBJ_FACE);
547 }
548
549 /* If trigger_altar has "last_sp > 0" set on the map, 550 /* If trigger_altar has "last_sp > 0" set on the map,
550 * it will push the connected value only once per sacrifice. 551 * it will push the connected value only once per sacrifice.
551 * Otherwise (default), the connected value will be 552 * Otherwise (default), the connected value will be
552 * pushed twice: First by sacrifice, second by reset! -AV 553 * pushed twice: First by sacrifice, second by reset! -AV
553 */ 554 */
554 if (!op->last_sp) 555 if (!op->last_sp)
555 trigger_move (op, 0); 556 trigger_move (op, 0);
556 else 557 else
557 { 558 {
558 op->stats.wc = 0; 559 op->stats.wc = 0;
559 op->value = !op->value; 560 op->value = !op->value;
560 op->set_speed (0); 561 op->set_speed (0);
561 } 562 }
562 } 563 }
563 return 0; 564 return 0;
564 565
565 case TRIGGER: 566 case TRIGGER:
566 if (cause) 567 if (cause)
567 { 568 {
568 if (in_movement) 569 if (in_movement)
569 return 0; 570 return 0;
570 571
571 push = 1; 572 push = 1;
572 } 573 }
573 574
574 if (NUM_ANIMATIONS (op) > 1) 575 if (NUM_ANIMATIONS (op) > 1)
575 { 576 {
576 SET_ANIMATION (op, push); 577 SET_ANIMATION (op, push);
577 update_object (op, UP_OBJ_FACE); 578 update_object (op, UP_OBJ_FACE);
578 } 579 }
579 580
580 trigger_move (op, push); 581 trigger_move (op, push);
581 return 1; 582 return 1;
582 583
583 default: 584 default:
584 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);
585 return 0; 586 return 0;
586 } 587 }
587} 588}
588 589
589void 590void
590add_button_link (object *button, maptile *map, int connected) 591add_button_link (object *button, maptile *map, int connected)
809 810
810 // FALL THROUGH 811 // FALL THROUGH
811 case 5: // kill all alives 812 case 5: // kill all alives
812 if (!tmp->flag [FLAG_PRECIOUS]) 813 if (!tmp->flag [FLAG_PRECIOUS])
813 { 814 {
814 get_archetype ("burnout")->insert_at (tmp, source); 815 archetype::get (shstr_burnout)->insert_at (tmp, source);
815 tmp->destroy (); 816 tmp->destroy ();
816 } 817 }
817 break; 818 break;
818 819
819 default: 820 default:
894 // and we have to set the value to 0 895 // and we have to set the value to 0
895 896
896 if (match && trig->last_sp) // match == having 897 if (match && trig->last_sp) // match == having
897 { 898 {
898 if (trig->last_heal) 899 if (trig->last_heal)
899 decrease_ob (match); 900 match->decrease ();
900 901
901 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
902 push_button (trig); 903 push_button (trig);
903 } 904 }
904 else if (!match && !trig->last_sp) // match == not having 905 else if (!match && !trig->last_sp) // match == not having

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines