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.43 by root, Mon Apr 21 06:35:26 2008 UTC vs.
Revision 1.45 by root, Tue Apr 22 01:06:22 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; 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);
428 int push = 0, tot = 0; 428 int push = 0, tot = 0;
429 int in_movement = op->stats.wc || op->speed; 429 int in_movement = op->stats.wc || op->speed;
430 430
431 switch (op->type) 431 switch (op->type)
432 { 432 {
433 case TRIGGER_BUTTON: 433 case TRIGGER_BUTTON:
434 if (op->weight > 0) 434 if (op->weight > 0)
435 { 435 {
436 if (cause) 436 if (cause)
437 { 437 {
438 for (tmp = op->above; tmp; tmp = tmp->above) 438 for (tmp = op->above; tmp; tmp = tmp->above)
439 /* Comment reproduced from update_buttons(): */ 439 /* Comment reproduced from update_buttons(): */
440 /* Basically, if the move_type matches that on what the 440 /* Basically, if the move_type matches that on what the
441 * button wants, we count it. The second check is so that 441 * button wants, we count it. The second check is so that
442 * objects that don't move (swords, etc) will count. Note that 442 * objects that don't move (swords, etc) will count. Note that
443 * this means that more work is needed to make buttons 443 * this means that more work is needed to make buttons
444 * 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":
445 */ 530 */
446 if ((tmp->move_type & op->move_on) || tmp->move_type == 0) 531 op->value = !op->value;
447 tot += tmp->head_ ()->total_weight (); 532 trigger_move (op, 1);
448 533 op->last_sp = -op->last_sp;
449 if (tot >= op->weight) 534 op->value = !op->value;
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 } 535 }
461 536
462 if (in_movement || !push) 537 return cause == NULL;
463 return 0;
464 } 538 }
465 trigger_move (op, push);
466 } 539 else
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; 540 return 0;
488 541 }
489 op->stats.ac = push; 542 else
490 543 {
491 if (NUM_ANIMATIONS (op) > 1) 544 if (NUM_ANIMATIONS (op) > 1)
492 { 545 {
493 SET_ANIMATION (op, push); 546 SET_ANIMATION (op, 0);
494 update_object (op, UP_OBJ_FACE); 547 update_object (op, UP_OBJ_FACE);
495 } 548 }
496 549
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":
530 */
531 op->value = !op->value;
532 trigger_move (op, 1);
533 op->last_sp = -op->last_sp;
534 op->value = !op->value;
535 }
536
537 return cause == NULL;
538 }
539 else
540 return 0;
541 }
542 else
543 {
544 if (NUM_ANIMATIONS (op) > 1)
545 {
546 SET_ANIMATION (op, 0);
547 update_object (op, UP_OBJ_FACE);
548 }
549
550 /* If trigger_altar has "last_sp > 0" set on the map, 550 /* If trigger_altar has "last_sp > 0" set on the map,
551 * it will push the connected value only once per sacrifice. 551 * it will push the connected value only once per sacrifice.
552 * Otherwise (default), the connected value will be 552 * Otherwise (default), the connected value will be
553 * pushed twice: First by sacrifice, second by reset! -AV 553 * pushed twice: First by sacrifice, second by reset! -AV
554 */ 554 */
555 if (!op->last_sp) 555 if (!op->last_sp)
556 trigger_move (op, 0); 556 trigger_move (op, 0);
557 else 557 else
558 { 558 {
559 op->stats.wc = 0; 559 op->stats.wc = 0;
560 op->value = !op->value; 560 op->value = !op->value;
561 op->set_speed (0); 561 op->set_speed (0);
562 } 562 }
563 } 563 }
564 return 0; 564 return 0;
565 565
566 case TRIGGER: 566 case TRIGGER:
567 if (cause) 567 if (cause)
568 { 568 {
569 if (in_movement) 569 if (in_movement)
570 return 0; 570 return 0;
571 571
572 push = 1; 572 push = 1;
573 } 573 }
574 574
575 if (NUM_ANIMATIONS (op) > 1) 575 if (NUM_ANIMATIONS (op) > 1)
576 { 576 {
577 SET_ANIMATION (op, push); 577 SET_ANIMATION (op, push);
578 update_object (op, UP_OBJ_FACE); 578 update_object (op, UP_OBJ_FACE);
579 } 579 }
580 580
581 trigger_move (op, push); 581 trigger_move (op, push);
582 return 1; 582 return 1;
583 583
584 default: 584 default:
585 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);
586 return 0; 586 return 0;
587 } 587 }
588} 588}
589 589
590void 590void
591add_button_link (object *button, maptile *map, int connected) 591add_button_link (object *button, maptile *map, int connected)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines