… | |
… | |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <unistd.h> |
24 | #include <unistd.h> |
25 | |
25 | |
26 | #include "global.h" |
26 | #include "global.h" |
27 | |
|
|
28 | #include "loader.h" |
27 | #include "loader.h" |
29 | |
|
|
30 | #include "path.h" |
28 | #include "path.h" |
31 | |
29 | |
32 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
30 | /* This rolls up wall, blocks_magic, blocks_view, etc, all into |
33 | * one function that just returns a P_.. value (see map.h) |
31 | * one function that just returns a P_.. value (see map.h) |
34 | * it will also do map translation for tiled maps, returning |
32 | * it will also do map translation for tiled maps, returning |
… | |
… | |
260 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
258 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
261 | for (object *tmp = ms->bot; tmp; tmp = tmp->above) |
259 | for (object *tmp = ms->bot; tmp; tmp = tmp->above) |
262 | tmp->flag [flag] = value; |
260 | tmp->flag [flag] = value; |
263 | } |
261 | } |
264 | |
262 | |
|
|
263 | void |
|
|
264 | maptile::post_load_original () |
|
|
265 | { |
|
|
266 | if (!spaces) |
|
|
267 | return; |
|
|
268 | |
|
|
269 | set_object_flag (FLAG_OBJ_ORIGINAL); |
|
|
270 | |
|
|
271 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
|
|
272 | for (object *tmp = ms->bot; tmp; tmp = tmp->above) |
|
|
273 | INVOKE_OBJECT (RESET, tmp); |
|
|
274 | } |
|
|
275 | |
265 | /* link_multipart_objects go through all the objects on the map looking |
276 | /* link_multipart_objects go through all the objects on the map looking |
266 | * for objects whose arch says they are multipart yet according to the |
277 | * for objects whose arch says they are multipart yet according to the |
267 | * info we have, they only have the head (as would be expected when |
278 | * info we have, they only have the head (as would be expected when |
268 | * they are saved). |
279 | * they are saved). |
269 | */ |
280 | */ |
… | |
… | |
641 | case KW_sky: thawer.get (sky); break; |
652 | case KW_sky: thawer.get (sky); break; |
642 | |
653 | |
643 | case KW_per_player: thawer.get (per_player); break; |
654 | case KW_per_player: thawer.get (per_player); break; |
644 | case KW_per_party: thawer.get (per_party); break; |
655 | case KW_per_party: thawer.get (per_party); break; |
645 | case KW_no_reset: thawer.get (no_reset); break; |
656 | case KW_no_reset: thawer.get (no_reset); break; |
|
|
657 | case KW_no_drop: thawer.get (no_drop); break; |
646 | |
658 | |
647 | case KW_region: default_region = region::find (thawer.get_str ()); break; |
659 | case KW_region: default_region = region::find (thawer.get_str ()); break; |
648 | case KW_shopitems: shopitems = parse_shop_string (thawer.get_str ()); break; |
660 | case KW_shopitems: shopitems = parse_shop_string (thawer.get_str ()); break; |
649 | |
661 | |
650 | // old names new names |
662 | // old names new names |
… | |
… | |
700 | |
712 | |
701 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
713 | if (QUERY_FLAG (op, FLAG_IS_FLOOR) && QUERY_FLAG (op, FLAG_UNIQUE)) |
702 | unique = 1; |
714 | unique = 1; |
703 | |
715 | |
704 | if (op->head_ () == op && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
716 | if (op->head_ () == op && (QUERY_FLAG (op, FLAG_UNIQUE) || unique)) |
705 | { |
|
|
706 | op->destroy_inv (false); |
|
|
707 | op->destroy (); |
717 | op->destroy (); |
708 | } |
|
|
709 | |
718 | |
710 | op = above; |
719 | op = above; |
711 | } |
720 | } |
712 | } |
721 | } |
713 | } |
722 | } |
… | |
… | |
724 | MAP_OUT (swap_time); |
733 | MAP_OUT (swap_time); |
725 | MAP_OUT (reset_time); |
734 | MAP_OUT (reset_time); |
726 | MAP_OUT (reset_timeout); |
735 | MAP_OUT (reset_timeout); |
727 | MAP_OUT (fixed_resettime); |
736 | MAP_OUT (fixed_resettime); |
728 | MAP_OUT (no_reset); |
737 | MAP_OUT (no_reset); |
|
|
738 | MAP_OUT (no_drop); |
729 | MAP_OUT (difficulty); |
739 | MAP_OUT (difficulty); |
730 | |
740 | |
731 | if (default_region) MAP_OUT2 (region, default_region->name); |
741 | if (default_region) MAP_OUT2 (region, default_region->name); |
732 | |
742 | |
733 | if (shopitems) |
743 | if (shopitems) |
… | |
… | |
800 | |
810 | |
801 | op->flag [FLAG_REMOVED] = true; |
811 | op->flag [FLAG_REMOVED] = true; |
802 | |
812 | |
803 | object *head = op->head_ (); |
813 | object *head = op->head_ (); |
804 | if (op == head) |
814 | if (op == head) |
805 | { |
|
|
806 | op->destroy_inv (false); |
|
|
807 | op->destroy (); |
815 | op->destroy (); |
808 | } |
|
|
809 | else if (head->map != op->map) |
816 | else if (head->map != op->map) |
810 | { |
817 | { |
811 | LOG (llevDebug, "bad luck for object crossing map borders: %s", head->debug_desc ()); |
818 | LOG (llevDebug, "bad luck for object crossing map borders: %s", head->debug_desc ()); |
812 | head->destroy (); |
819 | head->destroy (); |
813 | } |
820 | } |
814 | } |
821 | } |
815 | |
822 | |
816 | sfree (spaces, size ()), spaces = 0; |
823 | sfree0 (spaces, size ()); |
817 | } |
824 | } |
818 | |
825 | |
819 | if (buttons) |
826 | if (buttons) |
820 | free_objectlinkpt (buttons), buttons = 0; |
827 | free_objectlinkpt (buttons), buttons = 0; |
821 | |
828 | |
822 | sfree (regions, size ()); regions = 0; |
829 | sfree0 (regions, size ()); |
823 | delete [] regionmap; regionmap = 0; |
830 | delete [] regionmap; regionmap = 0; |
824 | } |
831 | } |
825 | |
832 | |
826 | void |
833 | void |
827 | maptile::clear_header () |
834 | maptile::clear_header () |
… | |
… | |
981 | |
988 | |
982 | if (QUERY_FLAG (op, FLAG_GENERATOR)) |
989 | if (QUERY_FLAG (op, FLAG_GENERATOR)) |
983 | { |
990 | { |
984 | total_exp += op->stats.exp; |
991 | total_exp += op->stats.exp; |
985 | |
992 | |
986 | if (archetype *at = type_to_archetype (GENERATE_TYPE (op))) |
993 | if (archetype *at = op->other_arch) |
|
|
994 | { |
987 | total_exp += at->stats.exp * 8; |
995 | total_exp += at->stats.exp * 8; |
988 | |
|
|
989 | monster_cnt++; |
996 | monster_cnt++; |
|
|
997 | } |
|
|
998 | |
|
|
999 | for (object *inv = op->inv; inv; inv = inv->below) |
|
|
1000 | { |
|
|
1001 | total_exp += op->stats.exp * 8; |
|
|
1002 | monster_cnt++; |
|
|
1003 | } |
990 | } |
1004 | } |
991 | } |
1005 | } |
992 | |
1006 | |
993 | avgexp = (double) total_exp / monster_cnt; |
1007 | avgexp = (double) total_exp / monster_cnt; |
994 | |
1008 | |
… | |
… | |
1033 | else |
1047 | else |
1034 | darkness = new_level; |
1048 | darkness = new_level; |
1035 | |
1049 | |
1036 | /* All clients need to get re-updated for the change */ |
1050 | /* All clients need to get re-updated for the change */ |
1037 | update_all_map_los (this); |
1051 | update_all_map_los (this); |
|
|
1052 | |
1038 | return 1; |
1053 | return 1; |
1039 | } |
1054 | } |
1040 | |
1055 | |
1041 | /* |
1056 | /* |
1042 | * This function updates various attributes about a specific space |
1057 | * This function updates various attributes about a specific space |
… | |
… | |
1045 | * through, etc) |
1060 | * through, etc) |
1046 | */ |
1061 | */ |
1047 | void |
1062 | void |
1048 | mapspace::update_ () |
1063 | mapspace::update_ () |
1049 | { |
1064 | { |
1050 | object *tmp, *last = 0; |
1065 | object *last = 0; |
1051 | uint8 flags = P_UPTODATE, light = 0, anywhere = 0; |
1066 | uint8 flags = P_UPTODATE, light = 0, anywhere = 0; |
1052 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1067 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1053 | |
1068 | |
1054 | //object *middle = 0; |
1069 | //object *middle = 0; |
1055 | //object *top = 0; |
1070 | //object *top = 0; |
… | |
… | |
1057 | // this seems to generate better code than using locals, above |
1072 | // this seems to generate better code than using locals, above |
1058 | object *&top = faces_obj[0] = 0; |
1073 | object *&top = faces_obj[0] = 0; |
1059 | object *&middle = faces_obj[1] = 0; |
1074 | object *&middle = faces_obj[1] = 0; |
1060 | object *&floor = faces_obj[2] = 0; |
1075 | object *&floor = faces_obj[2] = 0; |
1061 | |
1076 | |
1062 | for (tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1077 | for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1063 | { |
1078 | { |
1064 | /* This could be made additive I guess (two lights better than |
1079 | /* This could be made additive I guess (two lights better than |
1065 | * one). But if so, it shouldn't be a simple additive - 2 |
1080 | * one). But if so, it shouldn't be a simple additive - 2 |
1066 | * light bulbs do not illuminate twice as far as once since |
1081 | * light bulbs do not illuminate twice as far as once since |
1067 | * it is a dissapation factor that is cubed. |
1082 | * it is a dissapation factor that is cubed. |
1068 | */ |
1083 | */ |
1069 | if (tmp->glow_radius > light) |
|
|
1070 | light = tmp->glow_radius; |
1084 | light = max (light, tmp->glow_radius); |
1071 | |
1085 | |
1072 | /* This call is needed in order to update objects the player |
1086 | /* This call is needed in order to update objects the player |
1073 | * is standing in that have animations (ie, grass, fire, etc). |
1087 | * is standing in that have animations (ie, grass, fire, etc). |
1074 | * However, it also causes the look window to be re-drawn |
1088 | * However, it also causes the look window to be re-drawn |
1075 | * 3 times each time the player moves, because many of the |
1089 | * 3 times each time the player moves, because many of the |
… | |
… | |
1094 | else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) |
1108 | else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) |
1095 | { |
1109 | { |
1096 | middle = tmp; |
1110 | middle = tmp; |
1097 | anywhere = 1; |
1111 | anywhere = 1; |
1098 | } |
1112 | } |
|
|
1113 | |
1099 | /* Find the highest visible face around. If equal |
1114 | /* Find the highest visible face around. If equal |
1100 | * visibilities, we still want the one nearer to the |
1115 | * visibilities, we still want the one nearer to the |
1101 | * top |
1116 | * top |
1102 | */ |
1117 | */ |
1103 | else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere)) |
1118 | else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere)) |
… | |
… | |
1152 | * 1) top face is set, need middle to be set. |
1167 | * 1) top face is set, need middle to be set. |
1153 | * 2) middle is set, need to set top. |
1168 | * 2) middle is set, need to set top. |
1154 | * 3) neither middle or top is set - need to set both. |
1169 | * 3) neither middle or top is set - need to set both. |
1155 | */ |
1170 | */ |
1156 | |
1171 | |
1157 | for (tmp = last; tmp; tmp = tmp->below) |
1172 | for (object *tmp = last; tmp; tmp = tmp->below) |
1158 | { |
1173 | { |
1159 | /* Once we get to a floor, stop, since we already have a floor object */ |
1174 | /* Once we get to a floor, stop, since we already have a floor object */ |
1160 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1175 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1161 | break; |
1176 | break; |
1162 | |
1177 | |
… | |
… | |
1565 | } |
1580 | } |
1566 | |
1581 | |
1567 | object * |
1582 | object * |
1568 | maptile::insert (object *op, int x, int y, object *originator, int flags) |
1583 | maptile::insert (object *op, int x, int y, object *originator, int flags) |
1569 | { |
1584 | { |
1570 | if (!op->flag [FLAG_REMOVED]) |
|
|
1571 | op->remove (); |
|
|
1572 | |
|
|
1573 | return insert_ob_in_map_at (op, this, originator, flags, x, y); |
1585 | return insert_ob_in_map_at (op, this, originator, flags, x, y); |
1574 | } |
1586 | } |
1575 | |
1587 | |
1576 | region * |
1588 | region * |
1577 | maptile::region (int x, int y) const |
1589 | maptile::region (int x, int y) const |
… | |
… | |
1587 | |
1599 | |
1588 | return ::region::default_region (); |
1600 | return ::region::default_region (); |
1589 | } |
1601 | } |
1590 | |
1602 | |
1591 | /* picks a random object from a style map. |
1603 | /* picks a random object from a style map. |
1592 | * Redone by MSW so it should be faster and not use static |
|
|
1593 | * variables to generate tables. |
|
|
1594 | */ |
1604 | */ |
1595 | object * |
1605 | object * |
1596 | maptile::pick_random_object () const |
1606 | maptile::pick_random_object (rand_gen &gen) const |
1597 | { |
1607 | { |
1598 | /* while returning a null object will result in a crash, that |
1608 | /* while returning a null object will result in a crash, that |
1599 | * is actually preferable to an infinite loop. That is because |
1609 | * is actually preferable to an infinite loop. That is because |
1600 | * most servers will automatically restart in case of crash. |
1610 | * most servers will automatically restart in case of crash. |
1601 | * Change the logic on getting the random space - shouldn't make |
1611 | * Change the logic on getting the random space - shouldn't make |
1602 | * any difference, but this seems clearer to me. |
1612 | * any difference, but this seems clearer to me. |
1603 | */ |
1613 | */ |
1604 | for (int i = 1000; --i;) |
1614 | for (int i = 1000; --i;) |
1605 | { |
1615 | { |
1606 | object *pick = at (rndm (width), rndm (height)).bot; |
1616 | object *pick = at (gen (width), gen (height)).bot; |
1607 | |
1617 | |
1608 | // do not prefer big monsters just because they are big. |
1618 | // do not prefer big monsters just because they are big. |
1609 | if (pick && pick->head_ () == pick) |
1619 | if (pick && pick->is_head ()) |
1610 | return pick->head_ (); |
1620 | return pick->head_ (); |
1611 | } |
1621 | } |
1612 | |
1622 | |
1613 | // instead of crashing in the unlikely(?) case, try to return *something* |
1623 | // instead of crashing in the unlikely(?) case, try to return *something* |
1614 | return get_archetype ("blocked"); |
1624 | return archetype::find ("bug"); |
1615 | } |
1625 | } |
1616 | |
1626 | |
1617 | void |
1627 | void |
1618 | maptile::play_sound (faceidx sound, int x, int y) const |
1628 | maptile::play_sound (faceidx sound, int x, int y) const |
1619 | { |
1629 | { |