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.44 by root, Mon Apr 21 23:35:24 2008 UTC vs.
Revision 1.45 by root, Tue Apr 22 01:06:22 2008 UTC

215 * button reacts to the (eventual) change of state. 215 * button reacts to the (eventual) change of state.
216 */ 216 */
217void 217void
218update_button (object *op) 218update_button (object *op)
219{ 219{
220 object *ab, *tmp, *head;
221 int tot, any_down = 0, old_value = op->value; 220 int any_down = 0, old_value = op->value;
222 oblinkpt *obp = 0; 221 oblinkpt *obp = 0;
223 objectlink *ol; 222 objectlink *ol;
224 223
225 obp = get_button_links (op); 224 obp = get_button_links (op);
226 /* LOG(llevDebug, "update_button: %s (%d)\n", op->name, op->count); */
227 if (obp) 225 if (obp)
228 for (ol = obp->link; ol; ol = ol->next) 226 for (ol = obp->link; ol; ol = ol->next)
229 { 227 {
230 if (!ol->ob) 228 if (!ol->ob)
231 { 229 {
232 LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name); 230 LOG (llevDebug, "Internal error in update_button (%s).\n", &op->name);
233 continue; 231 continue;
234 } 232 }
235 233
236 tmp = ol->ob; 234 object *tmp = ol->ob;
235
237 if (tmp->type == BUTTON) 236 if (tmp->type == BUTTON)
238 { 237 {
238 sint32 total = 0;
239
239 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)
240 { 259 {
241 head = ab->head_ (); 260 object *head = ab->head_ ();
242
243 /* Basically, if the move_type matches that on what the
244 * button wants, we count it. The second check is so that
245 * objects who don't move (swords, etc) will count. Note that
246 * this means that more work is needed to make buttons
247 * that are only triggered by flying objects.
248 */
249 if ((head->move_type & tmp->move_on) || head->move_type == 0)
250 tot += head->total_weight ();
251 }
252
253 tmp->value = tot >= tmp->weight ? 1 : 0;
254 }
255 else if (tmp->type == PEDESTAL)
256 {
257 tmp->value = 0;
258
259 for (ab = tmp->above; ab; ab = ab->above)
260 {
261 head = ab->head_ ();
262 261
263 /* Same note regarding move_type for buttons above apply here. */ 262 /* Same note regarding move_type for buttons above apply here. */
264 if (((head->move_type & tmp->move_on) || ab->move_type == 0) && 263 if (((ab->move_type & tmp->move_on) || ab->move_type == 0)
265 (head->race == tmp->slaying || 264 && (head->race == tmp->slaying
266 ((head->type == SPECIAL_KEY) && (head->slaying == tmp->slaying)) || 265 || (head->type == SPECIAL_KEY && head->slaying == tmp->slaying)
267 (!strcmp (tmp->slaying, "player") && head->type == PLAYER))) 266 || (tmp->slaying == shstr_player && head->type == PLAYER)))
268 tmp->value = 1; 267 tmp->value = 1;
269 } 268 }
270 }
271 269
272 any_down = any_down || tmp->value; 270 any_down = any_down || tmp->value;
271 }
273 } 272 }
274 273
275 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 */
276 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);
277 278
278 /* If this button hasn't changed, don't do anything */ 279 /* If this button hasn't changed, don't do anything */
279 if (op->value != old_value) 280 if (op->value != old_value)
280 { 281 {
281 SET_ANIMATION (op, op->value); 282 SET_ANIMATION (op, op->value);
427 int push = 0, tot = 0; 428 int push = 0, tot = 0;
428 int in_movement = op->stats.wc || op->speed; 429 int in_movement = op->stats.wc || op->speed;
429 430
430 switch (op->type) 431 switch (op->type)
431 { 432 {
432 case TRIGGER_BUTTON: 433 case TRIGGER_BUTTON:
433 if (op->weight > 0) 434 if (op->weight > 0)
434 { 435 {
435 if (cause) 436 if (cause)
436 { 437 {
437 for (tmp = op->above; tmp; tmp = tmp->above) 438 for (tmp = op->above; tmp; tmp = tmp->above)
438 /* Comment reproduced from update_buttons(): */ 439 /* Comment reproduced from update_buttons(): */
439 /* Basically, if the move_type matches that on what the 440 /* Basically, if the move_type matches that on what the
440 * button wants, we count it. The second check is so that 441 * button wants, we count it. The second check is so that
441 * objects that don't move (swords, etc) will count. Note that 442 * objects that don't move (swords, etc) will count. Note that
442 * this means that more work is needed to make buttons 443 * this means that more work is needed to make buttons
443 * 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":
444 */ 530 */
445 if ((tmp->move_type & op->move_on) || tmp->move_type == 0) 531 op->value = !op->value;
446 tot += tmp->head_ ()->total_weight (); 532 trigger_move (op, 1);
447 533 op->last_sp = -op->last_sp;
448 if (tot >= op->weight) 534 op->value = !op->value;
449 push = 1;
450
451 if (op->stats.ac == push)
452 return 0;
453
454 op->stats.ac = push;
455 if (NUM_ANIMATIONS (op) > 1)
456 {
457 SET_ANIMATION (op, push);
458 update_object (op, UP_OBJ_FACE);
459 } 535 }
460 536
461 if (in_movement || !push) 537 return cause == NULL;
462 return 0;
463 } 538 }
464 trigger_move (op, push);
465 } 539 else
466
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)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines