… | |
… | |
404 | coroapi::cede_every (1000); // cede once in a while |
404 | coroapi::cede_every (1000); // cede once in a while |
405 | |
405 | |
406 | switch (f.kw) |
406 | switch (f.kw) |
407 | { |
407 | { |
408 | case KW_arch: |
408 | case KW_arch: |
409 | if (object *op = object::read (f)) |
409 | if (object *op = object::read (f, this)) |
410 | { |
410 | { |
411 | if (op->inv) |
411 | if (op->inv) |
412 | sum_weight (op); |
412 | sum_weight (op); |
413 | |
413 | |
414 | insert_ob_in_map (op, this, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); |
414 | insert_ob_in_map (op, this, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); |
… | |
… | |
1075 | void |
1075 | void |
1076 | mapspace::update_ () |
1076 | mapspace::update_ () |
1077 | { |
1077 | { |
1078 | object *tmp, *last = 0; |
1078 | object *tmp, *last = 0; |
1079 | uint8 flags = P_UPTODATE, light = 0, anywhere = 0; |
1079 | uint8 flags = P_UPTODATE, light = 0, anywhere = 0; |
1080 | facetile *top, *floor, *middle; |
|
|
1081 | object *top_obj, *floor_obj, *middle_obj; |
|
|
1082 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1080 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1083 | |
1081 | |
1084 | middle = blank_face; |
1082 | //object *middle = 0; |
1085 | top = blank_face; |
1083 | //object *top = 0; |
1086 | floor = blank_face; |
1084 | //object *floor = 0; |
1087 | |
1085 | // this seems to generate better code than using locals, above |
1088 | middle_obj = 0; |
1086 | object *&top = faces_obj[0] = 0; |
1089 | top_obj = 0; |
1087 | object *&middle = faces_obj[1] = 0; |
1090 | floor_obj = 0; |
1088 | object *&floor = faces_obj[2] = 0; |
1091 | |
1089 | |
1092 | for (tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1090 | for (tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1093 | { |
1091 | { |
1094 | /* This could be made additive I guess (two lights better than |
1092 | /* This could be made additive I guess (two lights better than |
1095 | * one). But if so, it shouldn't be a simple additive - 2 |
1093 | * one). But if so, it shouldn't be a simple additive - 2 |
… | |
… | |
1108 | * Always put the player down for drawing. |
1106 | * Always put the player down for drawing. |
1109 | */ |
1107 | */ |
1110 | if (!tmp->invisible) |
1108 | if (!tmp->invisible) |
1111 | { |
1109 | { |
1112 | if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER))) |
1110 | if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER))) |
1113 | { |
|
|
1114 | top = tmp->face; |
|
|
1115 | top_obj = tmp; |
1111 | top = tmp; |
1116 | } |
|
|
1117 | else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1112 | else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1118 | { |
1113 | { |
1119 | /* If we got a floor, that means middle and top were below it, |
1114 | /* If we got a floor, that means middle and top were below it, |
1120 | * so should not be visible, so we clear them. |
1115 | * so should not be visible, so we clear them. |
1121 | */ |
1116 | */ |
1122 | middle = blank_face; |
1117 | middle = 0; |
1123 | top = blank_face; |
1118 | top = 0; |
1124 | floor = tmp->face; |
|
|
1125 | floor_obj = tmp; |
1119 | floor = tmp; |
1126 | } |
1120 | } |
1127 | /* Flag anywhere have high priority */ |
1121 | /* Flag anywhere have high priority */ |
1128 | else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) |
1122 | else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) |
1129 | { |
1123 | { |
1130 | middle = tmp->face; |
|
|
1131 | |
|
|
1132 | middle_obj = tmp; |
1124 | middle = tmp; |
1133 | anywhere = 1; |
1125 | anywhere = 1; |
1134 | } |
1126 | } |
1135 | /* Find the highest visible face around. If equal |
1127 | /* Find the highest visible face around. If equal |
1136 | * visibilities, we still want the one nearer to the |
1128 | * visibilities, we still want the one nearer to the |
1137 | * top |
1129 | * top |
1138 | */ |
1130 | */ |
1139 | else if (middle == blank_face || (tmp->face->visibility > middle->visibility && !anywhere)) |
1131 | else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere)) |
1140 | { |
|
|
1141 | middle = tmp->face; |
|
|
1142 | middle_obj = tmp; |
1132 | middle = tmp; |
1143 | } |
|
|
1144 | } |
1133 | } |
1145 | |
1134 | |
1146 | if (tmp == tmp->above) |
1135 | if (tmp == tmp->above) |
1147 | { |
1136 | { |
1148 | LOG (llevError, "Error in structure of map\n"); |
1137 | LOG (llevError, "Error in structure of map\n"); |
… | |
… | |
1183 | * middle face. This should not happen, as we already have the |
1172 | * middle face. This should not happen, as we already have the |
1184 | * else statement above so middle should not get set. OTOH, it |
1173 | * else statement above so middle should not get set. OTOH, it |
1185 | * may be possible for the faces to match but be different objects. |
1174 | * may be possible for the faces to match but be different objects. |
1186 | */ |
1175 | */ |
1187 | if (top == middle) |
1176 | if (top == middle) |
1188 | middle = blank_face; |
1177 | middle = 0; |
1189 | |
1178 | |
1190 | /* There are three posibilities at this point: |
1179 | /* There are three posibilities at this point: |
1191 | * 1) top face is set, need middle to be set. |
1180 | * 1) top face is set, need middle to be set. |
1192 | * 2) middle is set, need to set top. |
1181 | * 2) middle is set, need to set top. |
1193 | * 3) neither middle or top is set - need to set both. |
1182 | * 3) neither middle or top is set - need to set both. |
… | |
… | |
1198 | /* Once we get to a floor, stop, since we already have a floor object */ |
1187 | /* Once we get to a floor, stop, since we already have a floor object */ |
1199 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1188 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1200 | break; |
1189 | break; |
1201 | |
1190 | |
1202 | /* If two top faces are already set, quit processing */ |
1191 | /* If two top faces are already set, quit processing */ |
1203 | if ((top != blank_face) && (middle != blank_face)) |
1192 | if (top && middle) |
1204 | break; |
1193 | break; |
1205 | |
1194 | |
1206 | /* Only show visible faces */ |
1195 | /* Only show visible faces */ |
1207 | if (!tmp->invisible) |
1196 | if (!tmp->invisible) |
1208 | { |
1197 | { |
1209 | /* Fill in top if needed */ |
1198 | /* Fill in top if needed */ |
1210 | if (top == blank_face) |
1199 | if (!top) |
1211 | { |
1200 | { |
1212 | top = tmp->face; |
|
|
1213 | top_obj = tmp; |
1201 | top = tmp; |
1214 | if (top == middle) |
1202 | if (top == middle) |
1215 | middle = blank_face; |
1203 | middle = 0; |
1216 | } |
1204 | } |
1217 | else |
1205 | else |
1218 | { |
1206 | { |
1219 | /* top is already set - we should only get here if |
1207 | /* top is already set - we should only get here if |
1220 | * middle is not set |
1208 | * middle is not set |
1221 | * |
1209 | * |
1222 | * Set the middle face and break out, since there is nothing |
1210 | * Set the middle face and break out, since there is nothing |
1223 | * more to fill in. We don't check visiblity here, since |
1211 | * more to fill in. We don't check visiblity here, since |
1224 | * |
1212 | * |
1225 | */ |
1213 | */ |
1226 | if (tmp->face != top) |
1214 | if (tmp != top) |
1227 | { |
1215 | { |
1228 | middle = tmp->face; |
|
|
1229 | middle_obj = tmp; |
1216 | middle = tmp; |
1230 | break; |
1217 | break; |
1231 | } |
1218 | } |
1232 | } |
1219 | } |
1233 | } |
1220 | } |
1234 | } |
1221 | } |
1235 | |
1222 | |
1236 | if (middle == floor) |
1223 | if (middle == floor) |
1237 | middle = blank_face; |
1224 | middle = 0; |
1238 | |
1225 | |
1239 | if (top == middle) |
1226 | if (top == middle) |
1240 | middle = blank_face; |
1227 | middle = 0; |
1241 | |
1228 | |
1242 | faces [0] = top; faces_obj [0] = top != blank_face ? top_obj : 0; |
1229 | #if 0 |
1243 | faces [1] = middle; faces_obj [1] = middle != blank_face ? middle_obj : 0; |
1230 | faces_obj [0] = top; |
1244 | faces [2] = floor; faces_obj [2] = floor != blank_face ? floor_obj : 0; |
1231 | faces_obj [1] = middle; |
|
|
1232 | faces_obj [2] = floor; |
|
|
1233 | #endif |
1245 | } |
1234 | } |
1246 | |
1235 | |
1247 | uint64 |
1236 | uint64 |
1248 | mapspace::volume () const |
1237 | mapspace::volume () const |
1249 | { |
1238 | { |
… | |
… | |
1669 | return default_region; |
1658 | return default_region; |
1670 | |
1659 | |
1671 | return ::region::default_region (); |
1660 | return ::region::default_region (); |
1672 | } |
1661 | } |
1673 | |
1662 | |
|
|
1663 | /* picks a random object from a style map. |
|
|
1664 | * Redone by MSW so it should be faster and not use static |
|
|
1665 | * variables to generate tables. |
|
|
1666 | */ |
|
|
1667 | object * |
|
|
1668 | maptile::pick_random_object () const |
|
|
1669 | { |
|
|
1670 | /* while returning a null object will result in a crash, that |
|
|
1671 | * is actually preferable to an infinite loop. That is because |
|
|
1672 | * most servers will automatically restart in case of crash. |
|
|
1673 | * Change the logic on getting the random space - shouldn't make |
|
|
1674 | * any difference, but this seems clearer to me. |
|
|
1675 | */ |
|
|
1676 | for (int i = 1000; --i;) |
|
|
1677 | { |
|
|
1678 | object *pick = at (rndm (width), rndm (height)).bot; |
1674 | |
1679 | |
|
|
1680 | // do not prefer big monsters just because they are big. |
|
|
1681 | if (pick && pick->head_ () == pick) |
|
|
1682 | return pick->head_ (); |
|
|
1683 | } |
|
|
1684 | |
|
|
1685 | // instead of crashing in the unlikely(?) case, try to return *something* |
|
|
1686 | return get_archetype ("blocked"); |
|
|
1687 | } |
|
|
1688 | |