… | |
… | |
564 | } |
564 | } |
565 | |
565 | |
566 | this->speed = speed; |
566 | this->speed = speed; |
567 | |
567 | |
568 | if (has_active_speed ()) |
568 | if (has_active_speed ()) |
569 | activate (false); |
569 | activate (); |
570 | else |
570 | else |
571 | deactivate (false); |
571 | deactivate (); |
572 | } |
572 | } |
573 | |
573 | |
574 | /* |
574 | /* |
575 | * update_object() updates the the map. |
575 | * update_object() updates the the map. |
576 | * It takes into account invisible objects (and represent squares covered |
576 | * It takes into account invisible objects (and represent squares covered |
… | |
… | |
624 | return; |
624 | return; |
625 | } |
625 | } |
626 | |
626 | |
627 | mapspace &m = op->ms (); |
627 | mapspace &m = op->ms (); |
628 | |
628 | |
629 | if (m.flags_ & P_NEED_UPDATE) |
629 | if (!(m.flags_ & P_UPTODATE)) |
630 | /* nop */; |
630 | /* nop */; |
631 | else if (action == UP_OBJ_INSERT) |
631 | else if (action == UP_OBJ_INSERT) |
632 | { |
632 | { |
633 | // this is likely overkill, TODO: revisit (schmorp) |
633 | // this is likely overkill, TODO: revisit (schmorp) |
634 | if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW)) |
634 | if ((QUERY_FLAG (op, FLAG_BLOCKSVIEW) && !(m.flags_ & P_BLOCKSVIEW)) |
… | |
… | |
643 | /* 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 |
644 | * to have move_allow right now. |
644 | * to have move_allow right now. |
645 | */ |
645 | */ |
646 | || ((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 |
647 | || 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) |
648 | m.flags_ = P_NEED_UPDATE; |
648 | m.flags_ = 0; |
649 | } |
649 | } |
650 | /* if the object is being removed, we can't make intelligent |
650 | /* if the object is being removed, we can't make intelligent |
651 | * decisions, because remove_ob can't really pass the object |
651 | * decisions, because remove_ob can't really pass the object |
652 | * that is being removed. |
652 | * that is being removed. |
653 | */ |
653 | */ |
654 | else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) |
654 | else if (action == UP_OBJ_CHANGE || action == UP_OBJ_REMOVE) |
655 | m.flags_ = P_NEED_UPDATE; |
655 | m.flags_ = 0; |
656 | else if (action == UP_OBJ_FACE) |
656 | else if (action == UP_OBJ_FACE) |
657 | /* Nothing to do for that case */ ; |
657 | /* Nothing to do for that case */ ; |
658 | else |
658 | else |
659 | LOG (llevError, "update_object called with invalid action: %d\n", action); |
659 | LOG (llevError, "update_object called with invalid action: %d\n", action); |
660 | |
660 | |
661 | if (op->more) |
661 | if (op->more) |
662 | update_object (op->more, action); |
662 | update_object (op->more, action); |
663 | } |
663 | } |
664 | |
664 | |
665 | object::vector object::objects; // not yet used |
|
|
666 | object *object::first; |
665 | object *object::first; |
667 | |
666 | |
668 | object::object () |
667 | object::object () |
669 | { |
668 | { |
670 | SET_FLAG (this, FLAG_REMOVED); |
669 | SET_FLAG (this, FLAG_REMOVED); |
… | |
… | |
703 | |
702 | |
704 | prev = 0; |
703 | prev = 0; |
705 | next = 0; |
704 | next = 0; |
706 | } |
705 | } |
707 | |
706 | |
|
|
707 | bool |
|
|
708 | object::active () const |
|
|
709 | { |
|
|
710 | return active_next || active_prev || this == active_objects; |
|
|
711 | } |
|
|
712 | |
708 | void |
713 | void |
709 | object::activate (bool recursive) |
714 | object::activate () |
710 | { |
715 | { |
|
|
716 | /* If already on active list, don't do anything */ |
|
|
717 | if (active ()) |
|
|
718 | return; |
|
|
719 | |
711 | if (has_active_speed ()) |
720 | if (has_active_speed ()) |
712 | { |
721 | { |
713 | /* If already on active list, don't do anything */ |
|
|
714 | if (active_next || active_prev || this == active_objects) |
|
|
715 | return; |
|
|
716 | |
|
|
717 | /* process_events() expects us to insert the object at the beginning |
722 | /* process_events() expects us to insert the object at the beginning |
718 | * of the list. */ |
723 | * of the list. */ |
719 | active_next = active_objects; |
724 | active_next = active_objects; |
720 | |
725 | |
721 | if (active_next) |
726 | if (active_next) |
722 | active_next->active_prev = this; |
727 | active_next->active_prev = this; |
723 | |
728 | |
724 | active_objects = this; |
729 | active_objects = this; |
725 | } |
730 | } |
|
|
731 | } |
726 | |
732 | |
727 | if (recursive) |
733 | void |
|
|
734 | object::activate_recursive () |
|
|
735 | { |
|
|
736 | activate (); |
|
|
737 | |
728 | for (object *op = inv; op; op = op->above) |
738 | for (object *op = inv; op; op = op->below) |
729 | op->activate (1); |
739 | op->activate_recursive (); |
730 | } |
740 | } |
731 | |
741 | |
732 | /* This function removes object 'op' from the list of active |
742 | /* This function removes object 'op' from the list of active |
733 | * objects. |
743 | * objects. |
734 | * This should only be used for style maps or other such |
744 | * This should only be used for style maps or other such |
… | |
… | |
736 | * in play chewing up cpu time getting processed. |
746 | * in play chewing up cpu time getting processed. |
737 | * The reverse of this is to call update_ob_speed, which |
747 | * The reverse of this is to call update_ob_speed, which |
738 | * 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. |
739 | */ |
749 | */ |
740 | void |
750 | void |
741 | object::deactivate (bool recursive) |
751 | object::deactivate () |
742 | { |
752 | { |
743 | /* If not on the active list, nothing needs to be done */ |
753 | /* If not on the active list, nothing needs to be done */ |
744 | if (!active_next && !active_prev && this != active_objects) |
754 | if (!active ()) |
745 | return; |
755 | return; |
746 | |
756 | |
747 | if (active_prev == 0) |
757 | if (active_prev == 0) |
748 | { |
758 | { |
749 | active_objects = active_next; |
759 | active_objects = active_next; |
… | |
… | |
757 | active_next->active_prev = active_prev; |
767 | active_next->active_prev = active_prev; |
758 | } |
768 | } |
759 | |
769 | |
760 | active_next = 0; |
770 | active_next = 0; |
761 | active_prev = 0; |
771 | active_prev = 0; |
|
|
772 | } |
762 | |
773 | |
763 | if (recursive) |
774 | void |
|
|
775 | object::deactivate_recursive () |
|
|
776 | { |
764 | for (object *op = inv; op; op = op->above) |
777 | for (object *op = inv; op; op = op->below) |
|
|
778 | op->deactivate_recursive (); |
|
|
779 | |
765 | op->deactivate (1); |
780 | deactivate (); |
|
|
781 | } |
|
|
782 | |
|
|
783 | void |
|
|
784 | object::set_flag_inv (int flag, int value) |
|
|
785 | { |
|
|
786 | for (object *op = inv; op; op = op->below) |
|
|
787 | { |
|
|
788 | op->flag [flag] = value; |
|
|
789 | op->set_flag_inv (flag, value); |
|
|
790 | } |
766 | } |
791 | } |
767 | |
792 | |
768 | /* |
793 | /* |
769 | * Remove and free all objects in the inventory of the given object. |
794 | * Remove and free all objects in the inventory of the given object. |
770 | * object.c ? |
795 | * object.c ? |
… | |
… | |
855 | freed_map->name = "/internal/freed_objects_map"; |
880 | freed_map->name = "/internal/freed_objects_map"; |
856 | freed_map->width = 3; |
881 | freed_map->width = 3; |
857 | freed_map->height = 3; |
882 | freed_map->height = 3; |
858 | |
883 | |
859 | freed_map->alloc (); |
884 | freed_map->alloc (); |
|
|
885 | freed_map->in_memory = MAP_IN_MEMORY; |
860 | } |
886 | } |
861 | |
887 | |
862 | map = freed_map; |
888 | map = freed_map; |
863 | x = 1; |
889 | x = 1; |
864 | y = 1; |
890 | y = 1; |
… | |
… | |
971 | else if (map) |
997 | else if (map) |
972 | { |
998 | { |
973 | if (type == PLAYER) |
999 | if (type == PLAYER) |
974 | { |
1000 | { |
975 | --map->players; |
1001 | --map->players; |
976 | map->last_access = runtime; |
1002 | map->touch (); |
977 | } |
1003 | } |
978 | |
1004 | |
|
|
1005 | map->dirty = true; |
979 | |
1006 | |
980 | /* link the object above us */ |
1007 | /* link the object above us */ |
981 | if (above) |
1008 | if (above) |
982 | above->below = below; |
1009 | above->below = below; |
983 | else |
1010 | else |
… | |
… | |
1056 | } |
1083 | } |
1057 | |
1084 | |
1058 | /* last == NULL if there are no objects on this space */ |
1085 | /* last == NULL if there are no objects on this space */ |
1059 | //TODO: this makes little sense, why only update the topmost object? |
1086 | //TODO: this makes little sense, why only update the topmost object? |
1060 | if (!last) |
1087 | if (!last) |
1061 | map->at (x, y).flags_ = P_NEED_UPDATE; |
1088 | map->at (x, y).flags_ = 0; |
1062 | else |
1089 | else |
1063 | update_object (last, UP_OBJ_REMOVE); |
1090 | update_object (last, UP_OBJ_REMOVE); |
1064 | |
1091 | |
1065 | if (flag [FLAG_BLOCKSVIEW] || glow_radius) |
1092 | if (flag [FLAG_BLOCKSVIEW] || glow_radius) |
1066 | update_all_los (map, x, y); |
1093 | update_all_los (map, x, y); |
… | |
… | |
1187 | { |
1214 | { |
1188 | /* The part may be on a different map. */ |
1215 | /* The part may be on a different map. */ |
1189 | |
1216 | |
1190 | object *more = op->more; |
1217 | object *more = op->more; |
1191 | |
1218 | |
1192 | /* We really need the caller to normalize coordinates - if |
1219 | /* We really need the caller to normalise coordinates - if |
1193 | * we set the map, that doesn't work if the location is within |
1220 | * we set the map, that doesn't work if the location is within |
1194 | * a map and this is straddling an edge. So only if coordinate |
1221 | * a map and this is straddling an edge. So only if coordinate |
1195 | * is clear wrong do we normalize it. |
1222 | * is clear wrong do we normalise it. |
1196 | */ |
1223 | */ |
1197 | if (OUT_OF_REAL_MAP (more->map, more->x, more->y)) |
1224 | if (OUT_OF_REAL_MAP (more->map, more->x, more->y)) |
1198 | more->map = get_map_from_coord (m, &more->x, &more->y); |
1225 | more->map = get_map_from_coord (m, &more->x, &more->y); |
1199 | else if (!more->map) |
1226 | else if (!more->map) |
1200 | { |
1227 | { |
… | |
… | |
1360 | |
1387 | |
1361 | if (op->type == PLAYER) |
1388 | if (op->type == PLAYER) |
1362 | { |
1389 | { |
1363 | op->contr->do_los = 1; |
1390 | op->contr->do_los = 1; |
1364 | ++op->map->players; |
1391 | ++op->map->players; |
1365 | op->map->last_access = runtime; |
1392 | op->map->touch (); |
1366 | } |
1393 | } |
|
|
1394 | |
|
|
1395 | op->map->dirty = true; |
1367 | |
1396 | |
1368 | /* If we have a floor, we know the player, if any, will be above |
1397 | /* If we have a floor, we know the player, if any, will be above |
1369 | * it, so save a few ticks and start from there. |
1398 | * it, so save a few ticks and start from there. |
1370 | */ |
1399 | */ |
1371 | if (!(flag & INS_MAP_LOAD)) |
1400 | if (!(flag & INS_MAP_LOAD)) |
… | |
… | |
1377 | * visible to others on this map. But update_all_los is really |
1406 | * visible to others on this map. But update_all_los is really |
1378 | * an inefficient way to do this, as it means los for all players |
1407 | * an inefficient way to do this, as it means los for all players |
1379 | * on the map will get recalculated. The players could very well |
1408 | * on the map will get recalculated. The players could very well |
1380 | * be far away from this change and not affected in any way - |
1409 | * be far away from this change and not affected in any way - |
1381 | * this should get redone to only look for players within range, |
1410 | * this should get redone to only look for players within range, |
1382 | * or just updating the P_NEED_UPDATE for spaces within this area |
1411 | * or just updating the P_UPTODATE for spaces within this area |
1383 | * of effect may be sufficient. |
1412 | * of effect may be sufficient. |
1384 | */ |
1413 | */ |
1385 | if (op->map->darkness && (op->glow_radius != 0)) |
1414 | if (op->map->darkness && (op->glow_radius != 0)) |
1386 | update_all_los (op->map, op->x, op->y); |
1415 | update_all_los (op->map, op->x, op->y); |
1387 | |
1416 | |
… | |
… | |
1425 | { |
1454 | { |
1426 | object *tmp, *tmp1; |
1455 | object *tmp, *tmp1; |
1427 | |
1456 | |
1428 | /* first search for itself and remove any old instances */ |
1457 | /* first search for itself and remove any old instances */ |
1429 | |
1458 | |
1430 | for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
1459 | for (tmp = op->ms ().bot; tmp; tmp = tmp->above) |
1431 | if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */ |
1460 | if (!strcmp (tmp->arch->name, arch_string)) /* same archetype */ |
1432 | tmp->destroy (); |
1461 | tmp->destroy (); |
1433 | |
1462 | |
1434 | tmp1 = arch_to_object (archetype::find (arch_string)); |
1463 | tmp1 = arch_to_object (archetype::find (arch_string)); |
1435 | |
1464 | |
… | |
… | |
1758 | |
1787 | |
1759 | /* The objects have to be checked from top to bottom. |
1788 | /* The objects have to be checked from top to bottom. |
1760 | * Hence, we first go to the top: |
1789 | * Hence, we first go to the top: |
1761 | */ |
1790 | */ |
1762 | |
1791 | |
1763 | for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp && tmp->above; tmp = tmp->above) |
1792 | for (tmp = op->ms ().bot; tmp && tmp->above; tmp = tmp->above) |
1764 | { |
1793 | { |
1765 | /* Trim the search when we find the first other spell effect |
1794 | /* Trim the search when we find the first other spell effect |
1766 | * this helps performance so that if a space has 50 spell objects, |
1795 | * this helps performance so that if a space has 50 spell objects, |
1767 | * we don't need to check all of them. |
1796 | * we don't need to check all of them. |
1768 | */ |
1797 | */ |
… | |
… | |
1826 | * The first matching object is returned, or NULL if none. |
1855 | * The first matching object is returned, or NULL if none. |
1827 | */ |
1856 | */ |
1828 | object * |
1857 | object * |
1829 | present_arch (const archetype *at, maptile *m, int x, int y) |
1858 | present_arch (const archetype *at, maptile *m, int x, int y) |
1830 | { |
1859 | { |
1831 | if (m == NULL || out_of_map (m, x, y)) |
1860 | if (!m || out_of_map (m, x, y)) |
1832 | { |
1861 | { |
1833 | LOG (llevError, "Present_arch called outside map.\n"); |
1862 | LOG (llevError, "Present_arch called outside map.\n"); |
1834 | return NULL; |
1863 | return NULL; |
1835 | } |
1864 | } |
1836 | |
1865 | |
1837 | for (object *tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
1866 | for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above) |
1838 | if (tmp->arch == at) |
1867 | if (tmp->arch == at) |
1839 | return tmp; |
1868 | return tmp; |
1840 | |
1869 | |
1841 | return NULL; |
1870 | return NULL; |
1842 | } |
1871 | } |
… | |
… | |
1853 | { |
1882 | { |
1854 | LOG (llevError, "Present called outside map.\n"); |
1883 | LOG (llevError, "Present called outside map.\n"); |
1855 | return NULL; |
1884 | return NULL; |
1856 | } |
1885 | } |
1857 | |
1886 | |
1858 | for (object *tmp = GET_MAP_OB (m, x, y); tmp != NULL; tmp = tmp->above) |
1887 | for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above) |
1859 | if (tmp->type == type) |
1888 | if (tmp->type == type) |
1860 | return tmp; |
1889 | return tmp; |
1861 | |
1890 | |
1862 | return NULL; |
1891 | return NULL; |
1863 | } |
1892 | } |
… | |
… | |
2595 | object::flag_desc (char *desc, int len) const |
2624 | object::flag_desc (char *desc, int len) const |
2596 | { |
2625 | { |
2597 | char *p = desc; |
2626 | char *p = desc; |
2598 | bool first = true; |
2627 | bool first = true; |
2599 | |
2628 | |
|
|
2629 | *p = 0; |
|
|
2630 | |
2600 | for (int i = 0; i < NUM_FLAGS; i++) |
2631 | for (int i = 0; i < NUM_FLAGS; i++) |
2601 | { |
2632 | { |
2602 | if (len <= 10) // magic constant! |
2633 | if (len <= 10) // magic constant! |
2603 | { |
2634 | { |
2604 | snprintf (p, len, ",..."); |
2635 | snprintf (p, len, ",..."); |
2605 | break; |
2636 | break; |
2606 | } |
2637 | } |
2607 | |
2638 | |
2608 | if (flag[i]) |
2639 | if (flag [i]) |
2609 | { |
2640 | { |
2610 | int cnt = snprintf (p, len, "%s%d", first ? "" : ",", i); |
2641 | int cnt = snprintf (p, len, "%s%d", first ? "" : ",", i); |
2611 | len -= cnt; |
2642 | len -= cnt; |
2612 | p += cnt; |
2643 | p += cnt; |
2613 | first = false; |
2644 | first = false; |
… | |
… | |
2615 | } |
2646 | } |
2616 | |
2647 | |
2617 | return desc; |
2648 | return desc; |
2618 | } |
2649 | } |
2619 | |
2650 | |
2620 | // return a suitable string describing an objetc in enough detail to find it |
2651 | // return a suitable string describing an object in enough detail to find it |
2621 | const char * |
2652 | const char * |
2622 | object::debug_desc (char *info) const |
2653 | object::debug_desc (char *info) const |
2623 | { |
2654 | { |
2624 | char flagdesc[512]; |
2655 | char flagdesc[512]; |
2625 | char info2[256 * 4]; |
2656 | char info2[256 * 4]; |
… | |
… | |
2642 | } |
2673 | } |
2643 | |
2674 | |
2644 | const char * |
2675 | const char * |
2645 | object::debug_desc () const |
2676 | object::debug_desc () const |
2646 | { |
2677 | { |
2647 | static char info[256 * 3]; |
2678 | static char info[256 * 4]; |
2648 | return debug_desc (info); |
2679 | return debug_desc (info); |
2649 | } |
2680 | } |
2650 | |
2681 | |