… | |
… | |
150 | // blocks anything but wizards. |
150 | // blocks anything but wizards. |
151 | |
151 | |
152 | if (tmp->flag [FLAG_ALIVE] |
152 | if (tmp->flag [FLAG_ALIVE] |
153 | && tmp->head_ () != ob |
153 | && tmp->head_ () != ob |
154 | && tmp != ob |
154 | && tmp != ob |
155 | && tmp->type != DOOR |
155 | && tmp->type != DOOR) |
156 | && !tmp->flag [FLAG_WIZPASS]) |
|
|
157 | return 1; |
156 | return 1; |
158 | } |
157 | } |
159 | } |
158 | } |
160 | |
159 | |
161 | return 0; |
160 | return 0; |
… | |
… | |
217 | } |
216 | } |
218 | |
217 | |
219 | return 0; |
218 | return 0; |
220 | } |
219 | } |
221 | |
220 | |
222 | /* When the map is loaded, load_object does not actually insert objects |
|
|
223 | * into inventory, but just links them. What this does is go through |
|
|
224 | * and insert them properly. |
|
|
225 | * The object 'container' is the object that contains the inventory. |
|
|
226 | * This is needed so that we can update the containers weight. |
|
|
227 | */ |
|
|
228 | static void |
|
|
229 | fix_container (object *container) |
|
|
230 | { |
|
|
231 | object *tmp = container->inv, *next; |
|
|
232 | |
|
|
233 | container->inv = 0; |
|
|
234 | while (tmp) |
|
|
235 | { |
|
|
236 | next = tmp->below; |
|
|
237 | if (tmp->inv) |
|
|
238 | fix_container (tmp); |
|
|
239 | |
|
|
240 | insert_ob_in_ob (tmp, container); |
|
|
241 | tmp = next; |
|
|
242 | } |
|
|
243 | |
|
|
244 | // go through and calculate what all the containers are carrying. |
|
|
245 | //TODO: remove |
|
|
246 | container->update_weight (); |
|
|
247 | } |
|
|
248 | |
|
|
249 | //-GPL |
221 | //-GPL |
250 | |
222 | |
251 | void |
223 | void |
252 | maptile::set_object_flag (int flag, int value) |
224 | maptile::set_object_flag (int flag, int value) |
253 | { |
225 | { |
… | |
… | |
268 | set_object_flag (FLAG_OBJ_ORIGINAL); |
240 | set_object_flag (FLAG_OBJ_ORIGINAL); |
269 | |
241 | |
270 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
242 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
271 | for (object *tmp = ms->bot; tmp; tmp = tmp->above) |
243 | for (object *tmp = ms->bot; tmp; tmp = tmp->above) |
272 | INVOKE_OBJECT (RESET, tmp); |
244 | INVOKE_OBJECT (RESET, tmp); |
|
|
245 | } |
|
|
246 | |
|
|
247 | void |
|
|
248 | maptile::post_load () |
|
|
249 | { |
|
|
250 | #if 0 |
|
|
251 | if (!spaces) |
|
|
252 | return; |
|
|
253 | |
|
|
254 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
|
|
255 | for (object *tmp = ms->bot; tmp; tmp = tmp->above) |
|
|
256 | ; // nop |
|
|
257 | #endif |
273 | } |
258 | } |
274 | |
259 | |
275 | //+GPL |
260 | //+GPL |
276 | |
261 | |
277 | /* link_multipart_objects go through all the objects on the map looking |
262 | /* link_multipart_objects go through all the objects on the map looking |
… | |
… | |
448 | * map archetype. Mimic that behaviour. |
433 | * map archetype. Mimic that behaviour. |
449 | */ |
434 | */ |
450 | width = 16; |
435 | width = 16; |
451 | height = 16; |
436 | height = 16; |
452 | timeout = 300; |
437 | timeout = 300; |
453 | max_nrof = 1000; // 1000 items of anything |
438 | max_items = MAX_ITEM_PER_ACTION; |
454 | max_volume = 2000000; // 2m³ |
439 | max_volume = 2000000; // 2m³ |
455 | } |
440 | } |
456 | |
441 | |
457 | maptile::maptile (int w, int h) |
442 | maptile::maptile (int w, int h) |
458 | { |
443 | { |
… | |
… | |
644 | case KW_shopgreed: thawer.get (shopgreed); break; |
629 | case KW_shopgreed: thawer.get (shopgreed); break; |
645 | case KW_shopmin: thawer.get (shopmin); break; |
630 | case KW_shopmin: thawer.get (shopmin); break; |
646 | case KW_shopmax: thawer.get (shopmax); break; |
631 | case KW_shopmax: thawer.get (shopmax); break; |
647 | case KW_shoprace: thawer.get (shoprace); break; |
632 | case KW_shoprace: thawer.get (shoprace); break; |
648 | case KW_outdoor: thawer.get (outdoor); break; |
633 | case KW_outdoor: thawer.get (outdoor); break; |
649 | case KW_temp: thawer.get (temp); break; |
|
|
650 | case KW_pressure: thawer.get (pressure); break; |
|
|
651 | case KW_humid: thawer.get (humid); break; |
|
|
652 | case KW_windspeed: thawer.get (windspeed); break; |
|
|
653 | case KW_winddir: thawer.get (winddir); break; |
|
|
654 | case KW_sky: thawer.get (sky); break; |
|
|
655 | |
634 | |
656 | case KW_per_player: thawer.get (per_player); break; |
635 | case KW_per_player: thawer.get (per_player); break; |
657 | case KW_per_party: thawer.get (per_party); break; |
636 | case KW_per_party: thawer.get (per_party); break; |
658 | case KW_no_reset: thawer.get (no_reset); break; |
637 | case KW_no_reset: thawer.get (no_reset); break; |
659 | case KW_no_drop: thawer.get (no_drop); break; |
638 | case KW_no_drop: thawer.get (no_drop); break; |
… | |
… | |
728 | //-GPL |
707 | //-GPL |
729 | |
708 | |
730 | bool |
709 | bool |
731 | maptile::_save_header (object_freezer &freezer) |
710 | maptile::_save_header (object_freezer &freezer) |
732 | { |
711 | { |
733 | #define MAP_OUT(k) freezer.put (KW_ ## k, k) |
712 | #define MAP_OUT(k) freezer.put (KW(k), k) |
734 | #define MAP_OUT2(k,v) freezer.put (KW_ ## k, v) |
713 | #define MAP_OUT2(k,v) freezer.put (KW(k), v) |
735 | |
714 | |
736 | MAP_OUT2 (arch, "map"); |
715 | MAP_OUT2 (arch, CS(map)); |
737 | |
716 | |
738 | if (name) MAP_OUT (name); |
717 | if (name) MAP_OUT (name); |
739 | MAP_OUT (swap_time); |
718 | MAP_OUT (swap_time); |
740 | MAP_OUT (reset_time); |
719 | MAP_OUT (reset_time); |
741 | MAP_OUT (reset_timeout); |
720 | MAP_OUT (reset_timeout); |
… | |
… | |
749 | MAP_OUT (shopgreed); |
728 | MAP_OUT (shopgreed); |
750 | MAP_OUT (shopmin); |
729 | MAP_OUT (shopmin); |
751 | MAP_OUT (shopmax); |
730 | MAP_OUT (shopmax); |
752 | if (shoprace) MAP_OUT (shoprace); |
731 | if (shoprace) MAP_OUT (shoprace); |
753 | |
732 | |
754 | MAP_OUT (darkness); |
|
|
755 | MAP_OUT (width); |
733 | MAP_OUT (width); |
756 | MAP_OUT (height); |
734 | MAP_OUT (height); |
757 | MAP_OUT (enter_x); |
735 | MAP_OUT (enter_x); |
758 | MAP_OUT (enter_y); |
736 | MAP_OUT (enter_y); |
759 | |
737 | MAP_OUT (darkness); |
760 | if (msg) freezer.put (KW_msg , KW_endmsg , msg); |
|
|
761 | if (maplore) freezer.put (KW_maplore, KW_endmaplore, maplore); |
|
|
762 | |
|
|
763 | MAP_OUT (outdoor); |
738 | MAP_OUT (outdoor); |
764 | MAP_OUT (temp); |
739 | |
765 | MAP_OUT (pressure); |
740 | if (msg) freezer.put (KW(msg) , KW(endmsg) , msg); |
766 | MAP_OUT (humid); |
741 | if (maplore) freezer.put (KW(maplore), KW(endmaplore), maplore); |
767 | MAP_OUT (windspeed); |
|
|
768 | MAP_OUT (winddir); |
|
|
769 | MAP_OUT (sky); |
|
|
770 | |
742 | |
771 | MAP_OUT (per_player); |
743 | MAP_OUT (per_player); |
772 | MAP_OUT (per_party); |
744 | MAP_OUT (per_party); |
773 | |
745 | |
774 | if (tile_path [0]) MAP_OUT2 (tile_path_1, tile_path [0]); |
746 | if (tile_path [0]) MAP_OUT2 (tile_path_1, tile_path [0]); |
775 | if (tile_path [1]) MAP_OUT2 (tile_path_2, tile_path [1]); |
747 | if (tile_path [1]) MAP_OUT2 (tile_path_2, tile_path [1]); |
776 | if (tile_path [2]) MAP_OUT2 (tile_path_3, tile_path [2]); |
748 | if (tile_path [2]) MAP_OUT2 (tile_path_3, tile_path [2]); |
777 | if (tile_path [3]) MAP_OUT2 (tile_path_4, tile_path [3]); |
749 | if (tile_path [3]) MAP_OUT2 (tile_path_4, tile_path [3]); |
778 | |
750 | |
779 | freezer.put (this); |
751 | freezer.put (this); |
780 | freezer.put (KW_end); |
752 | freezer.put (KW(end)); |
781 | |
753 | |
782 | return true; |
754 | return true; |
783 | } |
755 | } |
784 | |
756 | |
785 | bool |
757 | bool |
… | |
… | |
870 | |
842 | |
871 | clear (); |
843 | clear (); |
872 | } |
844 | } |
873 | |
845 | |
874 | /* decay and destroy perishable items in a map */ |
846 | /* decay and destroy perishable items in a map */ |
|
|
847 | // TODO: should be done regularly, not on map load? |
875 | void |
848 | void |
876 | maptile::do_decay_objects () |
849 | maptile::do_decay_objects () |
877 | { |
850 | { |
878 | if (!spaces) |
851 | if (!spaces) |
879 | return; |
852 | return; |
… | |
… | |
926 | || mat & M_LIQUID |
899 | || mat & M_LIQUID |
927 | || (mat & M_IRON && rndm (1, 5) == 1) |
900 | || (mat & M_IRON && rndm (1, 5) == 1) |
928 | || (mat & M_GLASS && rndm (1, 2) == 1) |
901 | || (mat & M_GLASS && rndm (1, 2) == 1) |
929 | || ((mat & M_STONE || mat & M_ADAMANT) && rndm (1, 10) == 1) |
902 | || ((mat & M_STONE || mat & M_ADAMANT) && rndm (1, 10) == 1) |
930 | || ((mat & M_SOFT_METAL || mat & M_BONE) && rndm (1, 3) == 1) |
903 | || ((mat & M_SOFT_METAL || mat & M_BONE) && rndm (1, 3) == 1) |
931 | || (mat & M_ICE && temp > 32)) |
904 | //|| (mat & M_ICE && temp > 32) |
|
|
905 | ) |
932 | destroy = 1; |
906 | destroy = 1; |
933 | } |
907 | } |
934 | |
908 | |
935 | /* adjust overall chance below */ |
909 | /* adjust overall chance below */ |
936 | if (destroy && rndm (0, 1)) |
910 | if (destroy && rndm (0, 1)) |
… | |
… | |
1027 | */ |
1001 | */ |
1028 | void |
1002 | void |
1029 | mapspace::update_ () |
1003 | mapspace::update_ () |
1030 | { |
1004 | { |
1031 | object *last = 0; |
1005 | object *last = 0; |
1032 | uint8 flags = P_UPTODATE, anywhere = 0; |
1006 | uint8 flags = P_UPTODATE; |
1033 | sint8 light = 0; |
1007 | sint8 light = 0; |
1034 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1008 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
|
|
1009 | uint64_t volume = 0; |
|
|
1010 | uint32_t items = 0; |
|
|
1011 | object *anywhere = 0; |
|
|
1012 | uint8_t middle_visibility = 0; |
1035 | |
1013 | |
1036 | //object *middle = 0; |
1014 | //object *middle = 0; |
1037 | //object *top = 0; |
1015 | //object *top = 0; |
1038 | //object *floor = 0; |
1016 | //object *floor = 0; |
1039 | // this seems to generate better code than using locals, above |
1017 | // this seems to generate better code than using locals, above |
1040 | object *&top = faces_obj[0] = 0; |
1018 | object *&top = faces_obj[0] = 0; |
1041 | object *&middle = faces_obj[1] = 0; |
1019 | object *&middle = faces_obj[1] = 0; |
1042 | object *&floor = faces_obj[2] = 0; |
1020 | object *&floor = faces_obj[2] = 0; |
|
|
1021 | |
|
|
1022 | object::flags_t allflags; // all flags of all objects or'ed together |
1043 | |
1023 | |
1044 | for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1024 | for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1045 | { |
1025 | { |
1046 | // Lights are additive, up to MAX_LIGHT_RADIUS, see los.C) |
1026 | // Lights are additive, up to MAX_LIGHT_RADIUS, see los.C) |
1047 | light += tmp->glow_radius; |
1027 | light += tmp->glow_radius; |
… | |
… | |
1052 | * 3 times each time the player moves, because many of the |
1032 | * 3 times each time the player moves, because many of the |
1053 | * functions the move_player calls eventualy call this. |
1033 | * functions the move_player calls eventualy call this. |
1054 | * |
1034 | * |
1055 | * Always put the player down for drawing. |
1035 | * Always put the player down for drawing. |
1056 | */ |
1036 | */ |
1057 | if (!tmp->invisible) |
1037 | if (expect_true (!tmp->invisible)) |
1058 | { |
1038 | { |
1059 | if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER))) |
1039 | if (expect_false (tmp->type == PLAYER || tmp->flag [FLAG_MONSTER])) |
1060 | top = tmp; |
1040 | top = tmp; |
1061 | else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1041 | else if (expect_false (tmp->flag [FLAG_IS_FLOOR])) |
1062 | { |
1042 | { |
1063 | /* If we got a floor, that means middle and top were below it, |
1043 | /* If we got a floor, that means middle and top were below it, |
1064 | * so should not be visible, so we clear them. |
1044 | * so should not be visible, so we clear them. |
1065 | */ |
1045 | */ |
1066 | middle = 0; |
1046 | middle = 0; |
1067 | top = 0; |
1047 | top = 0; |
1068 | floor = tmp; |
1048 | floor = tmp; |
|
|
1049 | volume = 0; |
|
|
1050 | items = 0; |
1069 | } |
1051 | } |
1070 | /* Flag anywhere have high priority */ |
1052 | else |
1071 | else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) |
|
|
1072 | { |
1053 | { |
|
|
1054 | if (expect_true (!tmp->flag [FLAG_NO_PICK])) |
|
|
1055 | { |
|
|
1056 | ++items; |
|
|
1057 | volume += tmp->volume (); |
|
|
1058 | } |
|
|
1059 | |
|
|
1060 | /* Flag anywhere have high priority */ |
|
|
1061 | if (expect_false (tmp->flag [FLAG_SEE_ANYWHERE])) |
|
|
1062 | anywhere = tmp; |
|
|
1063 | |
|
|
1064 | /* Find the highest visible face around. If equal |
|
|
1065 | * visibilities, we still want the one nearer to the |
|
|
1066 | * top |
|
|
1067 | */ |
|
|
1068 | if (expect_false (::faces [tmp->face].visibility >= middle_visibility)) |
|
|
1069 | { |
|
|
1070 | middle_visibility = ::faces [tmp->face].visibility; |
1073 | middle = tmp; |
1071 | middle = tmp; |
1074 | anywhere = 1; |
1072 | } |
1075 | } |
1073 | } |
1076 | |
|
|
1077 | /* Find the highest visible face around. If equal |
|
|
1078 | * visibilities, we still want the one nearer to the |
|
|
1079 | * top |
|
|
1080 | */ |
|
|
1081 | else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere)) |
|
|
1082 | middle = tmp; |
|
|
1083 | } |
|
|
1084 | |
|
|
1085 | if (tmp == tmp->above) |
|
|
1086 | { |
|
|
1087 | LOG (llevError, "Error in structure of map\n"); |
|
|
1088 | exit (-1); |
|
|
1089 | } |
1074 | } |
1090 | |
1075 | |
1091 | move_slow |= tmp->move_slow; |
1076 | move_slow |= tmp->move_slow; |
1092 | move_block |= tmp->move_block; |
1077 | move_block |= tmp->move_block; |
1093 | move_on |= tmp->move_on; |
1078 | move_on |= tmp->move_on; |
1094 | move_off |= tmp->move_off; |
1079 | move_off |= tmp->move_off; |
1095 | move_allow |= tmp->move_allow; |
1080 | move_allow |= tmp->move_allow; |
1096 | |
1081 | |
1097 | if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) flags |= P_BLOCKSVIEW; |
1082 | allflags |= tmp->flag; |
1098 | if (QUERY_FLAG (tmp, FLAG_NO_MAGIC)) flags |= P_NO_MAGIC; |
1083 | |
1099 | if (tmp->type == PLAYER) flags |= P_PLAYER; |
1084 | if (tmp->type == PLAYER) flags |= P_PLAYER; |
1100 | if (tmp->type == SAFE_GROUND) flags |= P_SAFE; |
1085 | if (tmp->type == SAFE_GROUND) flags |= P_SAFE; |
1101 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) flags |= P_IS_ALIVE; |
|
|
1102 | if (QUERY_FLAG (tmp, FLAG_DAMNED)) flags |= P_NO_CLERIC; |
|
|
1103 | } |
1086 | } |
|
|
1087 | |
|
|
1088 | // FLAG_SEE_ANYWHERE takes precedence |
|
|
1089 | if (anywhere) |
|
|
1090 | middle = anywhere; |
|
|
1091 | |
|
|
1092 | // ORing all flags together and checking them here is much faster |
|
|
1093 | if (allflags [FLAG_BLOCKSVIEW]) flags |= P_BLOCKSVIEW; |
|
|
1094 | if (allflags [FLAG_NO_MAGIC] ) flags |= P_NO_MAGIC; |
|
|
1095 | if (allflags [FLAG_ALIVE] ) flags |= P_IS_ALIVE; |
|
|
1096 | if (allflags [FLAG_DAMNED] ) flags |= P_NO_CLERIC; |
1104 | |
1097 | |
1105 | this->light = min (light, MAX_LIGHT_RADIUS); |
1098 | this->light = min (light, MAX_LIGHT_RADIUS); |
1106 | this->flags_ = flags; |
1099 | this->flags_ = flags; |
1107 | this->move_block = move_block & ~move_allow; |
1100 | this->move_block = move_block & ~move_allow; |
1108 | this->move_on = move_on; |
1101 | this->move_on = move_on; |
1109 | this->move_off = move_off; |
1102 | this->move_off = move_off; |
1110 | this->move_slow = move_slow; |
1103 | this->move_slow = move_slow; |
|
|
1104 | this->volume_ = (volume + 1023) / 1024; |
|
|
1105 | this->items_ = upos_min (items, 65535); // assume nrof <= 2**31 |
1111 | |
1106 | |
1112 | /* At this point, we have a floor face (if there is a floor), |
1107 | /* At this point, we have a floor face (if there is a floor), |
1113 | * and the floor is set - we are not going to touch it at |
1108 | * and the floor is set - we are not going to touch it at |
1114 | * this point. |
1109 | * this point. |
1115 | * middle contains the highest visibility face. |
1110 | * middle contains the highest visibility face. |
… | |
… | |
1181 | faces_obj [1] = middle; |
1176 | faces_obj [1] = middle; |
1182 | faces_obj [2] = floor; |
1177 | faces_obj [2] = floor; |
1183 | #endif |
1178 | #endif |
1184 | } |
1179 | } |
1185 | |
1180 | |
1186 | uint64 |
|
|
1187 | mapspace::volume () const |
|
|
1188 | { |
|
|
1189 | uint64 vol = 0; |
|
|
1190 | |
|
|
1191 | for (object *op = top; op && !op->flag [FLAG_NO_PICK]; op = op->below) |
|
|
1192 | vol += op->volume (); |
|
|
1193 | |
|
|
1194 | return vol; |
|
|
1195 | } |
|
|
1196 | |
|
|
1197 | maptile * |
1181 | maptile * |
1198 | maptile::tile_available (int dir, bool load) |
1182 | maptile::tile_available (int dir, bool load) |
1199 | { |
1183 | { |
1200 | if (tile_path[dir]) |
1184 | if (tile_path[dir]) |
1201 | { |
1185 | { |
… | |
… | |
1586 | if (pick && pick->is_head ()) |
1570 | if (pick && pick->is_head ()) |
1587 | return pick->head_ (); |
1571 | return pick->head_ (); |
1588 | } |
1572 | } |
1589 | |
1573 | |
1590 | // instead of crashing in the unlikely(?) case, try to return *something* |
1574 | // instead of crashing in the unlikely(?) case, try to return *something* |
1591 | return archetype::find ("bug"); |
1575 | return archetype::find (shstr_bug); |
1592 | } |
1576 | } |
1593 | |
1577 | |
1594 | //-GPL |
1578 | //-GPL |
1595 | |
1579 | |
1596 | void |
1580 | void |