… | |
… | |
276 | |
276 | |
277 | /* Note sure why the following is the case - either the object has to |
277 | /* Note sure why the following is the case - either the object has to |
278 | * be animated or have a very low speed. Is this an attempted monster |
278 | * be animated or have a very low speed. Is this an attempted monster |
279 | * check? |
279 | * check? |
280 | */ |
280 | */ |
281 | if (!QUERY_FLAG (ob1, FLAG_ANIMATE) && FABS ((ob1)->speed) > MIN_ACTIVE_SPEED) |
281 | if (!QUERY_FLAG (ob1, FLAG_ANIMATE) && ob1->has_active_speed ()) |
282 | return 0; |
282 | return 0; |
283 | |
283 | |
284 | switch (ob1->type) |
284 | switch (ob1->type) |
285 | { |
285 | { |
286 | case SCROLL: |
286 | case SCROLL: |
… | |
… | |
563 | speed = 0; |
563 | speed = 0; |
564 | } |
564 | } |
565 | |
565 | |
566 | this->speed = speed; |
566 | this->speed = speed; |
567 | |
567 | |
568 | if (FABS (speed) > MIN_ACTIVE_SPEED) |
568 | if (has_active_speed ()) |
569 | { |
569 | activate (); |
570 | /* If already on active list, don't do anything */ |
|
|
571 | if (active_next || active_prev || this == active_objects) |
|
|
572 | return; |
|
|
573 | |
|
|
574 | /* process_events() expects us to insert the object at the beginning |
|
|
575 | * of the list. */ |
|
|
576 | active_next = active_objects; |
|
|
577 | |
|
|
578 | if (active_next) |
|
|
579 | active_next->active_prev = this; |
|
|
580 | |
|
|
581 | active_objects = this; |
|
|
582 | } |
|
|
583 | else |
570 | else |
584 | { |
571 | deactivate (); |
585 | /* If not on the active list, nothing needs to be done */ |
|
|
586 | if (!active_next && !active_prev && this != active_objects) |
|
|
587 | return; |
|
|
588 | |
|
|
589 | if (!active_prev) |
|
|
590 | { |
|
|
591 | active_objects = active_next; |
|
|
592 | |
|
|
593 | if (active_next) |
|
|
594 | active_next->active_prev = 0; |
|
|
595 | } |
|
|
596 | else |
|
|
597 | { |
|
|
598 | active_prev->active_next = active_next; |
|
|
599 | |
|
|
600 | if (active_next) |
|
|
601 | active_next->active_prev = active_prev; |
|
|
602 | } |
|
|
603 | |
|
|
604 | active_next = 0; |
|
|
605 | active_prev = 0; |
|
|
606 | } |
|
|
607 | } |
572 | } |
608 | |
573 | |
609 | /* |
574 | /* |
610 | * update_object() updates the the map. |
575 | * update_object() updates the the map. |
611 | * It takes into account invisible objects (and represent squares covered |
576 | * It takes into account invisible objects (and represent squares covered |
… | |
… | |
659 | return; |
624 | return; |
660 | } |
625 | } |
661 | |
626 | |
662 | mapspace &m = op->ms (); |
627 | mapspace &m = op->ms (); |
663 | |
628 | |
664 | if (m.flags_ & P_NEED_UPDATE) |
629 | if (!(m.flags_ & P_UPTODATE)) |
665 | /* nop */; |
630 | /* nop */; |
666 | else if (action == UP_OBJ_INSERT) |
631 | else if (action == UP_OBJ_INSERT) |
667 | { |
632 | { |
668 | // this is likely overkill, TODO: revisit (schmorp) |
633 | // this is likely overkill, TODO: revisit (schmorp) |
669 | if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW)) |
634 | if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW)) |
… | |
… | |
678 | /* This isn't perfect, but I don't expect a lot of objects to |
643 | /* This isn't perfect, but I don't expect a lot of objects to |
679 | * to have move_allow right now. |
644 | * to have move_allow right now. |
680 | */ |
645 | */ |
681 | || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block |
646 | || ((m.move_block | op->move_block) & ~op->move_allow) != m.move_block |
682 | || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp) |
647 | || 1) // the above is not strong enough a test to skip updating. los maybe? TODO (Schmorp) |
683 | m.flags_ = P_NEED_UPDATE; |
648 | m.flags_ = 0; |
684 | } |
649 | } |
685 | /* if the object is being removed, we can't make intelligent |
650 | /* if the object is being removed, we can't make intelligent |
686 | * decisions, because remove_ob can't really pass the object |
651 | * decisions, because remove_ob can't really pass the object |
687 | * that is being removed. |
652 | * that is being removed. |
688 | */ |
653 | */ |
689 | else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) |
654 | else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) |
690 | m.flags_ = P_NEED_UPDATE; |
655 | m.flags_ = 0; |
691 | else if (action == UP_OBJ_FACE) |
656 | else if (action == UP_OBJ_FACE) |
692 | /* Nothing to do for that case */ ; |
657 | /* Nothing to do for that case */ ; |
693 | else |
658 | else |
694 | LOG (llevError, "update_object called with invalid action: %d\n", action); |
659 | LOG (llevError, "update_object called with invalid action: %d\n", action); |
695 | |
660 | |
696 | if (op->more) |
661 | if (op->more) |
697 | update_object (op->more, action); |
662 | update_object (op->more, action); |
698 | } |
663 | } |
699 | |
664 | |
700 | object::vector object::objects; // not yet used |
|
|
701 | object *object::first; |
665 | object *object::first; |
702 | |
666 | |
703 | object::object () |
667 | object::object () |
704 | { |
668 | { |
705 | SET_FLAG (this, FLAG_REMOVED); |
669 | SET_FLAG (this, FLAG_REMOVED); |
… | |
… | |
738 | |
702 | |
739 | prev = 0; |
703 | prev = 0; |
740 | next = 0; |
704 | next = 0; |
741 | } |
705 | } |
742 | |
706 | |
|
|
707 | bool |
|
|
708 | object::active () const |
|
|
709 | { |
|
|
710 | return active_next || active_prev || this == active_objects; |
|
|
711 | } |
|
|
712 | |
743 | void |
713 | void |
|
|
714 | object::activate () |
|
|
715 | { |
|
|
716 | /* If already on active list, don't do anything */ |
|
|
717 | if (active ()) |
|
|
718 | return; |
|
|
719 | |
|
|
720 | if (has_active_speed ()) |
|
|
721 | { |
|
|
722 | /* process_events() expects us to insert the object at the beginning |
|
|
723 | * of the list. */ |
|
|
724 | active_next = active_objects; |
|
|
725 | |
|
|
726 | if (active_next) |
|
|
727 | active_next->active_prev = this; |
|
|
728 | |
|
|
729 | active_objects = this; |
|
|
730 | } |
|
|
731 | } |
|
|
732 | |
|
|
733 | void |
744 | object::activate (bool recursive) |
734 | object::activate_recursive () |
745 | { |
735 | { |
746 | // uh, hack |
736 | activate (); |
747 | set_speed (speed); |
|
|
748 | |
737 | |
749 | if (recursive) |
|
|
750 | for (object *op = inv; op; op = op->above) |
738 | for (object *op = inv; op; op = op->above) |
751 | op->activate (1); |
739 | op->activate_recursive (); |
752 | } |
740 | } |
753 | |
741 | |
754 | /* This function removes object 'op' from the list of active |
742 | /* This function removes object 'op' from the list of active |
755 | * objects. |
743 | * objects. |
756 | * This should only be used for style maps or other such |
744 | * This should only be used for style maps or other such |
… | |
… | |
758 | * in play chewing up cpu time getting processed. |
746 | * in play chewing up cpu time getting processed. |
759 | * The reverse of this is to call update_ob_speed, which |
747 | * The reverse of this is to call update_ob_speed, which |
760 | * will do the right thing based on the speed of the object. |
748 | * will do the right thing based on the speed of the object. |
761 | */ |
749 | */ |
762 | void |
750 | void |
763 | object::deactivate (bool recursive) |
751 | object::deactivate () |
764 | { |
752 | { |
765 | /* If not on the active list, nothing needs to be done */ |
753 | /* If not on the active list, nothing needs to be done */ |
766 | if (!active_next && !active_prev && this != active_objects) |
754 | if (!active ()) |
767 | return; |
755 | return; |
768 | |
756 | |
769 | if (active_prev == 0) |
757 | if (active_prev == 0) |
770 | { |
758 | { |
771 | active_objects = active_next; |
759 | active_objects = active_next; |
… | |
… | |
779 | active_next->active_prev = active_prev; |
767 | active_next->active_prev = active_prev; |
780 | } |
768 | } |
781 | |
769 | |
782 | active_next = 0; |
770 | active_next = 0; |
783 | active_prev = 0; |
771 | active_prev = 0; |
|
|
772 | } |
784 | |
773 | |
785 | if (recursive) |
774 | void |
|
|
775 | object::deactivate_recursive () |
|
|
776 | { |
786 | for (object *op = inv; op; op = op->above) |
777 | for (object *op = inv; op; op = op->above) |
|
|
778 | op->deactivate_recursive (); |
|
|
779 | |
787 | op->deactivate (1); |
780 | deactivate (); |
788 | } |
781 | } |
789 | |
782 | |
790 | /* |
783 | /* |
791 | * Remove and free all objects in the inventory of the given object. |
784 | * Remove and free all objects in the inventory of the given object. |
792 | * object.c ? |
785 | * object.c ? |
… | |
… | |
993 | else if (map) |
986 | else if (map) |
994 | { |
987 | { |
995 | if (type == PLAYER) |
988 | if (type == PLAYER) |
996 | { |
989 | { |
997 | --map->players; |
990 | --map->players; |
998 | map->last_access = runtime; |
991 | map->touch (); |
999 | } |
992 | } |
1000 | |
993 | |
|
|
994 | map->dirty = true; |
1001 | |
995 | |
1002 | /* link the object above us */ |
996 | /* link the object above us */ |
1003 | if (above) |
997 | if (above) |
1004 | above->below = below; |
998 | above->below = below; |
1005 | else |
999 | else |
… | |
… | |
1078 | } |
1072 | } |
1079 | |
1073 | |
1080 | /* last == NULL if there are no objects on this space */ |
1074 | /* last == NULL if there are no objects on this space */ |
1081 | //TODO: this makes little sense, why only update the topmost object? |
1075 | //TODO: this makes little sense, why only update the topmost object? |
1082 | if (!last) |
1076 | if (!last) |
1083 | map->at (x, y).flags_ = P_NEED_UPDATE; |
1077 | map->at (x, y).flags_ = 0; |
1084 | else |
1078 | else |
1085 | update_object (last, UP_OBJ_REMOVE); |
1079 | update_object (last, UP_OBJ_REMOVE); |
1086 | |
1080 | |
1087 | if (flag [FLAG_BLOCKSVIEW] || glow_radius) |
1081 | if (flag [FLAG_BLOCKSVIEW] || glow_radius) |
1088 | update_all_los (map, x, y); |
1082 | update_all_los (map, x, y); |
… | |
… | |
1382 | |
1376 | |
1383 | if (op->type == PLAYER) |
1377 | if (op->type == PLAYER) |
1384 | { |
1378 | { |
1385 | op->contr->do_los = 1; |
1379 | op->contr->do_los = 1; |
1386 | ++op->map->players; |
1380 | ++op->map->players; |
1387 | op->map->last_access = runtime; |
1381 | op->map->touch (); |
1388 | } |
1382 | } |
|
|
1383 | |
|
|
1384 | op->map->dirty = true; |
1389 | |
1385 | |
1390 | /* If we have a floor, we know the player, if any, will be above |
1386 | /* If we have a floor, we know the player, if any, will be above |
1391 | * it, so save a few ticks and start from there. |
1387 | * it, so save a few ticks and start from there. |
1392 | */ |
1388 | */ |
1393 | if (!(flag & INS_MAP_LOAD)) |
1389 | if (!(flag & INS_MAP_LOAD)) |
… | |
… | |
1399 | * visible to others on this map. But update_all_los is really |
1395 | * visible to others on this map. But update_all_los is really |
1400 | * an inefficient way to do this, as it means los for all players |
1396 | * an inefficient way to do this, as it means los for all players |
1401 | * on the map will get recalculated. The players could very well |
1397 | * on the map will get recalculated. The players could very well |
1402 | * be far away from this change and not affected in any way - |
1398 | * be far away from this change and not affected in any way - |
1403 | * this should get redone to only look for players within range, |
1399 | * this should get redone to only look for players within range, |
1404 | * or just updating the P_NEED_UPDATE for spaces within this area |
1400 | * or just updating the P_UPTODATE for spaces within this area |
1405 | * of effect may be sufficient. |
1401 | * of effect may be sufficient. |
1406 | */ |
1402 | */ |
1407 | if (op->map->darkness && (op->glow_radius != 0)) |
1403 | if (op->map->darkness && (op->glow_radius != 0)) |
1408 | update_all_los (op->map, op->x, op->y); |
1404 | update_all_los (op->map, op->x, op->y); |
1409 | |
1405 | |
… | |
… | |
2610 | } |
2606 | } |
2611 | else |
2607 | else |
2612 | item = item->env; |
2608 | item = item->env; |
2613 | } |
2609 | } |
2614 | |
2610 | |
|
|
2611 | |
|
|
2612 | const char * |
|
|
2613 | object::flag_desc (char *desc, int len) const |
|
|
2614 | { |
|
|
2615 | char *p = desc; |
|
|
2616 | bool first = true; |
|
|
2617 | |
|
|
2618 | *p = 0; |
|
|
2619 | |
|
|
2620 | for (int i = 0; i < NUM_FLAGS; i++) |
|
|
2621 | { |
|
|
2622 | if (len <= 10) // magic constant! |
|
|
2623 | { |
|
|
2624 | snprintf (p, len, ",..."); |
|
|
2625 | break; |
|
|
2626 | } |
|
|
2627 | |
|
|
2628 | if (flag [i]) |
|
|
2629 | { |
|
|
2630 | int cnt = snprintf (p, len, "%s%d", first ? "" : ",", i); |
|
|
2631 | len -= cnt; |
|
|
2632 | p += cnt; |
|
|
2633 | first = false; |
|
|
2634 | } |
|
|
2635 | } |
|
|
2636 | |
|
|
2637 | return desc; |
|
|
2638 | } |
|
|
2639 | |
2615 | // return a suitable string describing an objetc in enough detail to find it |
2640 | // return a suitable string describing an object in enough detail to find it |
2616 | const char * |
2641 | const char * |
2617 | object::debug_desc (char *info) const |
2642 | object::debug_desc (char *info) const |
2618 | { |
2643 | { |
|
|
2644 | char flagdesc[512]; |
2619 | char info2[256 * 3]; |
2645 | char info2[256 * 4]; |
2620 | char *p = info; |
2646 | char *p = info; |
2621 | |
2647 | |
2622 | p += snprintf (p, 256, "%d=\"%s%s%s\"", |
2648 | p += snprintf (p, 512, "{cnt:%d,uuid:<1,%" PRIx64 ">,name:\"%s%s%s\",flags:[%s],type:%d}", |
2623 | count, |
2649 | count, uuid.seq, |
2624 | &name, |
2650 | &name, |
2625 | title ? " " : "", |
2651 | title ? "\",title:" : "", |
2626 | title ? (const char *)title : ""); |
2652 | title ? (const char *)title : "", |
|
|
2653 | flag_desc (flagdesc, 512), type); |
2627 | |
2654 | |
2628 | if (env) |
2655 | if (env) |
2629 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2656 | p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); |
2630 | |
2657 | |
2631 | if (map) |
2658 | if (map) |
… | |
… | |
2635 | } |
2662 | } |
2636 | |
2663 | |
2637 | const char * |
2664 | const char * |
2638 | object::debug_desc () const |
2665 | object::debug_desc () const |
2639 | { |
2666 | { |
2640 | static char info[256 * 3]; |
2667 | static char info[256 * 4]; |
2641 | return debug_desc (info); |
2668 | return debug_desc (info); |
2642 | } |
2669 | } |
2643 | |
2670 | |