… | |
… | |
448 | * map archetype. Mimic that behaviour. |
448 | * map archetype. Mimic that behaviour. |
449 | */ |
449 | */ |
450 | width = 16; |
450 | width = 16; |
451 | height = 16; |
451 | height = 16; |
452 | timeout = 300; |
452 | timeout = 300; |
453 | max_nrof = 1000; // 1000 items of anything |
453 | max_items = MAX_ITEM_PER_ACTION; |
454 | max_volume = 2000000; // 2m³ |
454 | max_volume = 2000000; // 2m³ |
455 | } |
455 | } |
456 | |
456 | |
457 | maptile::maptile (int w, int h) |
457 | maptile::maptile (int w, int h) |
458 | { |
458 | { |
… | |
… | |
1027 | */ |
1027 | */ |
1028 | void |
1028 | void |
1029 | mapspace::update_ () |
1029 | mapspace::update_ () |
1030 | { |
1030 | { |
1031 | object *last = 0; |
1031 | object *last = 0; |
1032 | uint8 flags = P_UPTODATE, anywhere = 0; |
1032 | uint8 flags = P_UPTODATE; |
1033 | sint8 light = 0; |
1033 | sint8 light = 0; |
1034 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1034 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
|
|
1035 | uint64_t volume = 0; |
|
|
1036 | uint32_t items = 0; |
|
|
1037 | object *anywhere = 0; |
1035 | |
1038 | |
1036 | //object *middle = 0; |
1039 | //object *middle = 0; |
1037 | //object *top = 0; |
1040 | //object *top = 0; |
1038 | //object *floor = 0; |
1041 | //object *floor = 0; |
1039 | // this seems to generate better code than using locals, above |
1042 | // this seems to generate better code than using locals, above |
1040 | object *&top = faces_obj[0] = 0; |
1043 | object *&top = faces_obj[0] = 0; |
1041 | object *&middle = faces_obj[1] = 0; |
1044 | object *&middle = faces_obj[1] = 0; |
1042 | object *&floor = faces_obj[2] = 0; |
1045 | object *&floor = faces_obj[2] = 0; |
|
|
1046 | |
|
|
1047 | object::flags_t allflags; // all flags of all objects or'ed together |
1043 | |
1048 | |
1044 | for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1049 | for (object *tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1045 | { |
1050 | { |
1046 | // Lights are additive, up to MAX_LIGHT_RADIUS, see los.C) |
1051 | // Lights are additive, up to MAX_LIGHT_RADIUS, see los.C) |
1047 | light += tmp->glow_radius; |
1052 | light += tmp->glow_radius; |
… | |
… | |
1052 | * 3 times each time the player moves, because many of the |
1057 | * 3 times each time the player moves, because many of the |
1053 | * functions the move_player calls eventualy call this. |
1058 | * functions the move_player calls eventualy call this. |
1054 | * |
1059 | * |
1055 | * Always put the player down for drawing. |
1060 | * Always put the player down for drawing. |
1056 | */ |
1061 | */ |
1057 | if (!tmp->invisible) |
1062 | if (expect_true (!tmp->invisible)) |
1058 | { |
1063 | { |
1059 | if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER))) |
1064 | if (tmp->type == PLAYER || tmp->flag [FLAG_MONSTER]) |
1060 | top = tmp; |
1065 | top = tmp; |
1061 | else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1066 | else |
1062 | { |
1067 | { |
|
|
1068 | if (expect_false (tmp->flag [FLAG_IS_FLOOR])) |
|
|
1069 | { |
1063 | /* If we got a floor, that means middle and top were below it, |
1070 | /* If we got a floor, that means middle and top were below it, |
1064 | * so should not be visible, so we clear them. |
1071 | * so should not be visible, so we clear them. |
1065 | */ |
1072 | */ |
1066 | middle = 0; |
1073 | middle = 0; |
1067 | top = 0; |
1074 | top = 0; |
1068 | floor = tmp; |
1075 | floor = tmp; |
|
|
1076 | volume = 0; |
|
|
1077 | items = 0; |
|
|
1078 | } |
|
|
1079 | else |
|
|
1080 | { |
|
|
1081 | if (expect_true (!tmp->flag [FLAG_NO_PICK])) |
|
|
1082 | { |
|
|
1083 | ++items; |
|
|
1084 | volume += tmp->volume (); |
|
|
1085 | } |
|
|
1086 | |
|
|
1087 | /* Flag anywhere have high priority */ |
|
|
1088 | if (expect_false (tmp->flag [FLAG_SEE_ANYWHERE])) |
|
|
1089 | anywhere = tmp; |
|
|
1090 | /* Find the highest visible face around. If equal |
|
|
1091 | * visibilities, we still want the one nearer to the |
|
|
1092 | * top |
|
|
1093 | */ |
|
|
1094 | else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility)) |
|
|
1095 | middle = tmp; |
|
|
1096 | } |
1069 | } |
1097 | } |
1070 | /* Flag anywhere have high priority */ |
|
|
1071 | else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) |
|
|
1072 | { |
|
|
1073 | middle = tmp; |
|
|
1074 | anywhere = 1; |
|
|
1075 | } |
|
|
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 | } |
1098 | } |
1090 | |
1099 | |
1091 | move_slow |= tmp->move_slow; |
1100 | move_slow |= tmp->move_slow; |
1092 | move_block |= tmp->move_block; |
1101 | move_block |= tmp->move_block; |
1093 | move_on |= tmp->move_on; |
1102 | move_on |= tmp->move_on; |
1094 | move_off |= tmp->move_off; |
1103 | move_off |= tmp->move_off; |
1095 | move_allow |= tmp->move_allow; |
1104 | move_allow |= tmp->move_allow; |
1096 | |
1105 | |
1097 | if (QUERY_FLAG (tmp, FLAG_BLOCKSVIEW)) flags |= P_BLOCKSVIEW; |
1106 | allflags |= tmp->flag; |
1098 | if (QUERY_FLAG (tmp, FLAG_NO_MAGIC)) flags |= P_NO_MAGIC; |
1107 | |
1099 | if (tmp->type == PLAYER) flags |= P_PLAYER; |
1108 | if (tmp->type == PLAYER) flags |= P_PLAYER; |
1100 | if (tmp->type == SAFE_GROUND) flags |= P_SAFE; |
1109 | 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 | } |
1110 | } |
|
|
1111 | |
|
|
1112 | // FLAG_SEE_ANYWHERE takes precedence |
|
|
1113 | if (anywhere) |
|
|
1114 | middle = anywhere; |
|
|
1115 | |
|
|
1116 | // ORing all flags together and checking them here is much faster |
|
|
1117 | if (allflags [FLAG_BLOCKSVIEW]) flags |= P_BLOCKSVIEW; |
|
|
1118 | if (allflags [FLAG_NO_MAGIC] ) flags |= P_NO_MAGIC; |
|
|
1119 | if (allflags [FLAG_ALIVE] ) flags |= P_IS_ALIVE; |
|
|
1120 | if (allflags [FLAG_DAMNED] ) flags |= P_NO_CLERIC; |
1104 | |
1121 | |
1105 | this->light = min (light, MAX_LIGHT_RADIUS); |
1122 | this->light = min (light, MAX_LIGHT_RADIUS); |
1106 | this->flags_ = flags; |
1123 | this->flags_ = flags; |
1107 | this->move_block = move_block & ~move_allow; |
1124 | this->move_block = move_block & ~move_allow; |
1108 | this->move_on = move_on; |
1125 | this->move_on = move_on; |
1109 | this->move_off = move_off; |
1126 | this->move_off = move_off; |
1110 | this->move_slow = move_slow; |
1127 | this->move_slow = move_slow; |
|
|
1128 | this->volume_ = (volume + 1023) / 1024; |
|
|
1129 | this->items_ = upos_min (items, 65535); // assume nrof <= 2**31 |
1111 | |
1130 | |
1112 | /* At this point, we have a floor face (if there is a floor), |
1131 | /* 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 |
1132 | * and the floor is set - we are not going to touch it at |
1114 | * this point. |
1133 | * this point. |
1115 | * middle contains the highest visibility face. |
1134 | * middle contains the highest visibility face. |
… | |
… | |
1181 | faces_obj [1] = middle; |
1200 | faces_obj [1] = middle; |
1182 | faces_obj [2] = floor; |
1201 | faces_obj [2] = floor; |
1183 | #endif |
1202 | #endif |
1184 | } |
1203 | } |
1185 | |
1204 | |
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 * |
1205 | maptile * |
1198 | maptile::tile_available (int dir, bool load) |
1206 | maptile::tile_available (int dir, bool load) |
1199 | { |
1207 | { |
1200 | if (tile_path[dir]) |
1208 | if (tile_path[dir]) |
1201 | { |
1209 | { |
… | |
… | |
1586 | if (pick && pick->is_head ()) |
1594 | if (pick && pick->is_head ()) |
1587 | return pick->head_ (); |
1595 | return pick->head_ (); |
1588 | } |
1596 | } |
1589 | |
1597 | |
1590 | // instead of crashing in the unlikely(?) case, try to return *something* |
1598 | // instead of crashing in the unlikely(?) case, try to return *something* |
1591 | return archetype::find ("bug"); |
1599 | return archetype::find (shstr_bug); |
1592 | } |
1600 | } |
1593 | |
1601 | |
1594 | //-GPL |
1602 | //-GPL |
1595 | |
1603 | |
1596 | void |
1604 | void |