… | |
… | |
217 | } |
217 | } |
218 | |
218 | |
219 | return 0; |
219 | return 0; |
220 | } |
220 | } |
221 | |
221 | |
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 |
222 | //-GPL |
250 | |
223 | |
251 | void |
224 | void |
252 | maptile::set_object_flag (int flag, int value) |
225 | maptile::set_object_flag (int flag, int value) |
253 | { |
226 | { |
… | |
… | |
448 | * map archetype. Mimic that behaviour. |
421 | * map archetype. Mimic that behaviour. |
449 | */ |
422 | */ |
450 | width = 16; |
423 | width = 16; |
451 | height = 16; |
424 | height = 16; |
452 | timeout = 300; |
425 | timeout = 300; |
453 | max_nrof = 1000; // 1000 items of anything |
426 | max_items = MAX_ITEM_PER_ACTION; |
454 | max_volume = 2000000; // 2m³ |
427 | max_volume = 2000000; // 2m³ |
455 | } |
428 | } |
456 | |
429 | |
457 | maptile::maptile (int w, int h) |
430 | maptile::maptile (int w, int h) |
458 | { |
431 | { |
… | |
… | |
1027 | */ |
1000 | */ |
1028 | void |
1001 | void |
1029 | mapspace::update_ () |
1002 | mapspace::update_ () |
1030 | { |
1003 | { |
1031 | object *last = 0; |
1004 | object *last = 0; |
1032 | uint8 flags = P_UPTODATE, anywhere = 0; |
1005 | uint8 flags = P_UPTODATE; |
1033 | sint8 light = 0; |
1006 | sint8 light = 0; |
1034 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1007 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
|
|
1008 | uint64_t volume = 0; |
|
|
1009 | uint32_t items = 0; |
|
|
1010 | object *anywhere = 0; |
|
|
1011 | uint8_t middle_visibility = 0; |
1035 | |
1012 | |
1036 | //object *middle = 0; |
1013 | //object *middle = 0; |
1037 | //object *top = 0; |
1014 | //object *top = 0; |
1038 | //object *floor = 0; |
1015 | //object *floor = 0; |
1039 | // this seems to generate better code than using locals, above |
1016 | // this seems to generate better code than using locals, above |
1040 | object *&top = faces_obj[0] = 0; |
1017 | object *&top = faces_obj[0] = 0; |
1041 | object *&middle = faces_obj[1] = 0; |
1018 | object *&middle = faces_obj[1] = 0; |
1042 | object *&floor = faces_obj[2] = 0; |
1019 | object *&floor = faces_obj[2] = 0; |
|
|
1020 | |
|
|
1021 | object::flags_t allflags; // all flags of all objects or'ed together |
1043 | |
1022 | |
1044 | for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1023 | for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1045 | { |
1024 | { |
1046 | // Lights are additive, up to MAX_LIGHT_RADIUS, see los.C) |
1025 | // Lights are additive, up to MAX_LIGHT_RADIUS, see los.C) |
1047 | light += tmp->glow_radius; |
1026 | light += tmp->glow_radius; |
… | |
… | |
1052 | * 3 times each time the player moves, because many of the |
1031 | * 3 times each time the player moves, because many of the |
1053 | * functions the move_player calls eventualy call this. |
1032 | * functions the move_player calls eventualy call this. |
1054 | * |
1033 | * |
1055 | * Always put the player down for drawing. |
1034 | * Always put the player down for drawing. |
1056 | */ |
1035 | */ |
1057 | if (!tmp->invisible) |
1036 | if (expect_true (!tmp->invisible)) |
1058 | { |
1037 | { |
1059 | if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER))) |
1038 | if (expect_false (tmp->type == PLAYER || tmp->flag [FLAG_MONSTER])) |
1060 | top = tmp; |
1039 | top = tmp; |
1061 | else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1040 | else if (expect_false (tmp->flag [FLAG_IS_FLOOR])) |
1062 | { |
1041 | { |
1063 | /* If we got a floor, that means middle and top were below it, |
1042 | /* If we got a floor, that means middle and top were below it, |
1064 | * so should not be visible, so we clear them. |
1043 | * so should not be visible, so we clear them. |
1065 | */ |
1044 | */ |
1066 | middle = 0; |
1045 | middle = 0; |
1067 | top = 0; |
1046 | top = 0; |
1068 | floor = tmp; |
1047 | floor = tmp; |
|
|
1048 | volume = 0; |
|
|
1049 | items = 0; |
1069 | } |
1050 | } |
1070 | /* Flag anywhere have high priority */ |
1051 | else |
1071 | else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) |
|
|
1072 | { |
1052 | { |
|
|
1053 | if (expect_true (!tmp->flag [FLAG_NO_PICK])) |
|
|
1054 | { |
|
|
1055 | ++items; |
|
|
1056 | volume += tmp->volume (); |
|
|
1057 | } |
|
|
1058 | |
|
|
1059 | /* Flag anywhere have high priority */ |
|
|
1060 | if (expect_false (tmp->flag [FLAG_SEE_ANYWHERE])) |
|
|
1061 | anywhere = tmp; |
|
|
1062 | |
|
|
1063 | /* Find the highest visible face around. If equal |
|
|
1064 | * visibilities, we still want the one nearer to the |
|
|
1065 | * top |
|
|
1066 | */ |
|
|
1067 | if (expect_false (::faces [tmp->face].visibility >= middle_visibility)) |
|
|
1068 | { |
|
|
1069 | middle_visibility = ::faces [tmp->face].visibility; |
1073 | middle = tmp; |
1070 | middle = tmp; |
1074 | anywhere = 1; |
1071 | } |
1075 | } |
1072 | } |
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 | } |
1073 | } |
1090 | |
1074 | |
1091 | move_slow |= tmp->move_slow; |
1075 | move_slow |= tmp->move_slow; |
1092 | move_block |= tmp->move_block; |
1076 | move_block |= tmp->move_block; |
1093 | move_on |= tmp->move_on; |
1077 | move_on |= tmp->move_on; |
1094 | move_off |= tmp->move_off; |
1078 | move_off |= tmp->move_off; |
1095 | move_allow |= tmp->move_allow; |
1079 | move_allow |= tmp->move_allow; |
1096 | |
1080 | |
1097 | if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) flags |= P_BLOCKSVIEW; |
1081 | allflags |= tmp->flag; |
1098 | if (QUERY_FLAG (tmp, FLAG_NO_MAGIC)) flags |= P_NO_MAGIC; |
1082 | |
1099 | if (tmp->type == PLAYER) flags |= P_PLAYER; |
1083 | if (tmp->type == PLAYER) flags |= P_PLAYER; |
1100 | if (tmp->type == SAFE_GROUND) flags |= P_SAFE; |
1084 | 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 | } |
1085 | } |
|
|
1086 | |
|
|
1087 | // FLAG_SEE_ANYWHERE takes precedence |
|
|
1088 | if (anywhere) |
|
|
1089 | middle = anywhere; |
|
|
1090 | |
|
|
1091 | // ORing all flags together and checking them here is much faster |
|
|
1092 | if (allflags [FLAG_BLOCKSVIEW]) flags |= P_BLOCKSVIEW; |
|
|
1093 | if (allflags [FLAG_NO_MAGIC] ) flags |= P_NO_MAGIC; |
|
|
1094 | if (allflags [FLAG_ALIVE] ) flags |= P_IS_ALIVE; |
|
|
1095 | if (allflags [FLAG_DAMNED] ) flags |= P_NO_CLERIC; |
1104 | |
1096 | |
1105 | this->light = min (light, MAX_LIGHT_RADIUS); |
1097 | this->light = min (light, MAX_LIGHT_RADIUS); |
1106 | this->flags_ = flags; |
1098 | this->flags_ = flags; |
1107 | this->move_block = move_block & ~move_allow; |
1099 | this->move_block = move_block & ~move_allow; |
1108 | this->move_on = move_on; |
1100 | this->move_on = move_on; |
1109 | this->move_off = move_off; |
1101 | this->move_off = move_off; |
1110 | this->move_slow = move_slow; |
1102 | this->move_slow = move_slow; |
|
|
1103 | this->volume_ = (volume + 1023) / 1024; |
|
|
1104 | this->items_ = upos_min (items, 65535); // assume nrof <= 2**31 |
1111 | |
1105 | |
1112 | /* At this point, we have a floor face (if there is a floor), |
1106 | /* 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 |
1107 | * and the floor is set - we are not going to touch it at |
1114 | * this point. |
1108 | * this point. |
1115 | * middle contains the highest visibility face. |
1109 | * middle contains the highest visibility face. |
… | |
… | |
1181 | faces_obj [1] = middle; |
1175 | faces_obj [1] = middle; |
1182 | faces_obj [2] = floor; |
1176 | faces_obj [2] = floor; |
1183 | #endif |
1177 | #endif |
1184 | } |
1178 | } |
1185 | |
1179 | |
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 * |
1180 | maptile * |
1198 | maptile::tile_available (int dir, bool load) |
1181 | maptile::tile_available (int dir, bool load) |
1199 | { |
1182 | { |
1200 | if (tile_path[dir]) |
1183 | if (tile_path[dir]) |
1201 | { |
1184 | { |
… | |
… | |
1586 | if (pick && pick->is_head ()) |
1569 | if (pick && pick->is_head ()) |
1587 | return pick->head_ (); |
1570 | return pick->head_ (); |
1588 | } |
1571 | } |
1589 | |
1572 | |
1590 | // instead of crashing in the unlikely(?) case, try to return *something* |
1573 | // instead of crashing in the unlikely(?) case, try to return *something* |
1591 | return archetype::find ("bug"); |
1574 | return archetype::find (shstr_bug); |
1592 | } |
1575 | } |
1593 | |
1576 | |
1594 | //-GPL |
1577 | //-GPL |
1595 | |
1578 | |
1596 | void |
1579 | void |