… | |
… | |
344 | } |
344 | } |
345 | |
345 | |
346 | /* link_multipart_objects go through all the objects on the map looking |
346 | /* link_multipart_objects go through all the objects on the map looking |
347 | * for objects whose arch says they are multipart yet according to the |
347 | * for objects whose arch says they are multipart yet according to the |
348 | * info we have, they only have the head (as would be expected when |
348 | * info we have, they only have the head (as would be expected when |
349 | * they are saved). We do have to look for the old maps that did save |
349 | * they are saved). |
350 | * the more sections and not re-add sections for them. |
|
|
351 | */ |
350 | */ |
352 | void |
351 | void |
353 | maptile::link_multipart_objects () |
352 | maptile::link_multipart_objects () |
354 | { |
353 | { |
355 | if (!spaces) |
354 | if (!spaces) |
356 | return; |
355 | return; |
357 | |
356 | |
358 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
357 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
359 | for (object *tmp = ms->bot; tmp; ) |
358 | for (object *tmp = ms->bot; tmp; tmp = tmp->above) |
360 | { |
359 | { |
361 | object *above = tmp->above; |
|
|
362 | |
|
|
363 | /* already multipart - don't do anything more */ |
360 | /* already multipart - don't do anything more */ |
364 | if (!tmp->head && !tmp->more) |
361 | if (!tmp->head && !tmp->more) |
365 | { |
362 | { |
366 | /* If there is nothing more to this object, this for loop |
363 | /* If there is nothing more to this object, this for loop |
367 | * won't do anything. |
364 | * won't do anything. |
… | |
… | |
389 | * the coding is simpler to just to it here with each part. |
386 | * the coding is simpler to just to it here with each part. |
390 | */ |
387 | */ |
391 | insert_ob_in_map (op, op->map, tmp, INS_NO_MERGE | INS_ABOVE_FLOOR_ONLY | INS_NO_WALK_ON); |
388 | insert_ob_in_map (op, op->map, tmp, INS_NO_MERGE | INS_ABOVE_FLOOR_ONLY | INS_NO_WALK_ON); |
392 | } |
389 | } |
393 | } |
390 | } |
394 | |
|
|
395 | tmp = above; |
|
|
396 | } |
391 | } |
397 | } |
392 | } |
398 | |
393 | |
399 | /* |
394 | /* |
400 | * Loads (ands parses) the objects into a given map from the specified |
395 | * Loads (ands parses) the objects into a given map from the specified |
… | |
… | |
408 | coroapi::cede_every (1000); // cede once in a while |
403 | coroapi::cede_every (1000); // cede once in a while |
409 | |
404 | |
410 | switch (f.kw) |
405 | switch (f.kw) |
411 | { |
406 | { |
412 | case KW_arch: |
407 | case KW_arch: |
413 | if (object *op = object::read (f)) |
408 | if (object *op = object::read (f, this)) |
414 | { |
409 | { |
415 | if (op->inv) |
410 | if (op->inv) |
416 | sum_weight (op); |
411 | sum_weight (op); |
417 | |
412 | |
418 | insert_ob_in_map (op, this, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); |
413 | insert_ob_in_map (op, this, op, INS_NO_MERGE | INS_NO_WALK_ON | INS_ON_TOP | INS_MAP_LOAD); |
… | |
… | |
458 | } |
453 | } |
459 | |
454 | |
460 | bool |
455 | bool |
461 | maptile::_save_objects (object_freezer &f, int flags) |
456 | maptile::_save_objects (object_freezer &f, int flags) |
462 | { |
457 | { |
463 | static int cede_count = 0; |
458 | coroapi::cede (); |
464 | |
459 | |
465 | if (flags & IO_HEADER) |
460 | if (flags & IO_HEADER) |
466 | _save_header (f); |
461 | _save_header (f); |
467 | |
462 | |
468 | if (!spaces) |
463 | if (!spaces) |
469 | return false; |
464 | return false; |
470 | |
465 | |
471 | for (int i = 0; i < size (); ++i) |
466 | for (int i = 0; i < size (); ++i) |
472 | { |
467 | { |
473 | #if 0 // temporarily disabled for improved(?) stability, schmorp #TODO#d#//D |
|
|
474 | if (cede_count >= 500) |
|
|
475 | { |
|
|
476 | cede_count = 0; |
|
|
477 | coroapi::cede (); |
|
|
478 | } |
|
|
479 | #endif |
|
|
480 | |
|
|
481 | int unique = 0; |
468 | int unique = 0; |
482 | for (object *op = spaces [i].bot; op; op = op->above) |
469 | for (object *op = spaces [i].bot; op; op = op->above) |
483 | { |
470 | { |
484 | // count per-object, but cede only when modification-safe |
|
|
485 | cede_count++; |
|
|
486 | |
|
|
487 | if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR]) |
471 | if (op->flag [FLAG_UNIQUE] && op->flag [FLAG_IS_FLOOR]) |
488 | unique = 1; |
472 | unique = 1; |
489 | |
473 | |
490 | if (!op->can_map_save ()) |
474 | if (!op->can_map_save ()) |
491 | continue; |
475 | continue; |
… | |
… | |
497 | } |
481 | } |
498 | else if (flags & IO_OBJECTS) |
482 | else if (flags & IO_OBJECTS) |
499 | op->write (f); |
483 | op->write (f); |
500 | } |
484 | } |
501 | } |
485 | } |
|
|
486 | |
|
|
487 | coroapi::cede (); |
502 | |
488 | |
503 | return true; |
489 | return true; |
504 | } |
490 | } |
505 | |
491 | |
506 | bool |
492 | bool |
… | |
… | |
1079 | void |
1065 | void |
1080 | mapspace::update_ () |
1066 | mapspace::update_ () |
1081 | { |
1067 | { |
1082 | object *tmp, *last = 0; |
1068 | object *tmp, *last = 0; |
1083 | uint8 flags = P_UPTODATE, light = 0, anywhere = 0; |
1069 | uint8 flags = P_UPTODATE, light = 0, anywhere = 0; |
1084 | facetile *top, *floor, *middle; |
|
|
1085 | object *top_obj, *floor_obj, *middle_obj; |
|
|
1086 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1070 | MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0; |
1087 | |
1071 | |
1088 | middle = blank_face; |
1072 | //object *middle = 0; |
1089 | top = blank_face; |
1073 | //object *top = 0; |
1090 | floor = blank_face; |
1074 | //object *floor = 0; |
1091 | |
1075 | // this seems to generate better code than using locals, above |
1092 | middle_obj = 0; |
1076 | object *&top = faces_obj[0] = 0; |
1093 | top_obj = 0; |
1077 | object *&middle = faces_obj[1] = 0; |
1094 | floor_obj = 0; |
1078 | object *&floor = faces_obj[2] = 0; |
1095 | |
1079 | |
1096 | for (tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1080 | for (tmp = bot; tmp; last = tmp, tmp = tmp->above) |
1097 | { |
1081 | { |
1098 | /* This could be made additive I guess (two lights better than |
1082 | /* This could be made additive I guess (two lights better than |
1099 | * one). But if so, it shouldn't be a simple additive - 2 |
1083 | * one). But if so, it shouldn't be a simple additive - 2 |
… | |
… | |
1112 | * Always put the player down for drawing. |
1096 | * Always put the player down for drawing. |
1113 | */ |
1097 | */ |
1114 | if (!tmp->invisible) |
1098 | if (!tmp->invisible) |
1115 | { |
1099 | { |
1116 | if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER))) |
1100 | if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER))) |
1117 | { |
|
|
1118 | top = tmp->face; |
|
|
1119 | top_obj = tmp; |
1101 | top = tmp; |
1120 | } |
|
|
1121 | else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1102 | else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1122 | { |
1103 | { |
1123 | /* If we got a floor, that means middle and top were below it, |
1104 | /* If we got a floor, that means middle and top were below it, |
1124 | * so should not be visible, so we clear them. |
1105 | * so should not be visible, so we clear them. |
1125 | */ |
1106 | */ |
1126 | middle = blank_face; |
1107 | middle = 0; |
1127 | top = blank_face; |
1108 | top = 0; |
1128 | floor = tmp->face; |
|
|
1129 | floor_obj = tmp; |
1109 | floor = tmp; |
1130 | } |
1110 | } |
1131 | /* Flag anywhere have high priority */ |
1111 | /* Flag anywhere have high priority */ |
1132 | else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) |
1112 | else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) |
1133 | { |
1113 | { |
1134 | middle = tmp->face; |
|
|
1135 | |
|
|
1136 | middle_obj = tmp; |
1114 | middle = tmp; |
1137 | anywhere = 1; |
1115 | anywhere = 1; |
1138 | } |
1116 | } |
1139 | /* Find the highest visible face around. If equal |
1117 | /* Find the highest visible face around. If equal |
1140 | * visibilities, we still want the one nearer to the |
1118 | * visibilities, we still want the one nearer to the |
1141 | * top |
1119 | * top |
1142 | */ |
1120 | */ |
1143 | else if (middle == blank_face || (tmp->face->visibility > middle->visibility && !anywhere)) |
1121 | else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere)) |
1144 | { |
|
|
1145 | middle = tmp->face; |
|
|
1146 | middle_obj = tmp; |
1122 | middle = tmp; |
1147 | } |
|
|
1148 | } |
1123 | } |
1149 | |
1124 | |
1150 | if (tmp == tmp->above) |
1125 | if (tmp == tmp->above) |
1151 | { |
1126 | { |
1152 | LOG (llevError, "Error in structure of map\n"); |
1127 | LOG (llevError, "Error in structure of map\n"); |
… | |
… | |
1187 | * middle face. This should not happen, as we already have the |
1162 | * middle face. This should not happen, as we already have the |
1188 | * else statement above so middle should not get set. OTOH, it |
1163 | * else statement above so middle should not get set. OTOH, it |
1189 | * may be possible for the faces to match but be different objects. |
1164 | * may be possible for the faces to match but be different objects. |
1190 | */ |
1165 | */ |
1191 | if (top == middle) |
1166 | if (top == middle) |
1192 | middle = blank_face; |
1167 | middle = 0; |
1193 | |
1168 | |
1194 | /* There are three posibilities at this point: |
1169 | /* There are three posibilities at this point: |
1195 | * 1) top face is set, need middle to be set. |
1170 | * 1) top face is set, need middle to be set. |
1196 | * 2) middle is set, need to set top. |
1171 | * 2) middle is set, need to set top. |
1197 | * 3) neither middle or top is set - need to set both. |
1172 | * 3) neither middle or top is set - need to set both. |
… | |
… | |
1202 | /* Once we get to a floor, stop, since we already have a floor object */ |
1177 | /* Once we get to a floor, stop, since we already have a floor object */ |
1203 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1178 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
1204 | break; |
1179 | break; |
1205 | |
1180 | |
1206 | /* If two top faces are already set, quit processing */ |
1181 | /* If two top faces are already set, quit processing */ |
1207 | if ((top != blank_face) && (middle != blank_face)) |
1182 | if (top && middle) |
1208 | break; |
1183 | break; |
1209 | |
1184 | |
1210 | /* Only show visible faces */ |
1185 | /* Only show visible faces */ |
1211 | if (!tmp->invisible) |
1186 | if (!tmp->invisible) |
1212 | { |
1187 | { |
1213 | /* Fill in top if needed */ |
1188 | /* Fill in top if needed */ |
1214 | if (top == blank_face) |
1189 | if (!top) |
1215 | { |
1190 | { |
1216 | top = tmp->face; |
|
|
1217 | top_obj = tmp; |
1191 | top = tmp; |
1218 | if (top == middle) |
1192 | if (top == middle) |
1219 | middle = blank_face; |
1193 | middle = 0; |
1220 | } |
1194 | } |
1221 | else |
1195 | else |
1222 | { |
1196 | { |
1223 | /* top is already set - we should only get here if |
1197 | /* top is already set - we should only get here if |
1224 | * middle is not set |
1198 | * middle is not set |
1225 | * |
1199 | * |
1226 | * Set the middle face and break out, since there is nothing |
1200 | * Set the middle face and break out, since there is nothing |
1227 | * more to fill in. We don't check visiblity here, since |
1201 | * more to fill in. We don't check visiblity here, since |
1228 | * |
1202 | * |
1229 | */ |
1203 | */ |
1230 | if (tmp->face != top) |
1204 | if (tmp != top) |
1231 | { |
1205 | { |
1232 | middle = tmp->face; |
|
|
1233 | middle_obj = tmp; |
1206 | middle = tmp; |
1234 | break; |
1207 | break; |
1235 | } |
1208 | } |
1236 | } |
1209 | } |
1237 | } |
1210 | } |
1238 | } |
1211 | } |
1239 | |
1212 | |
1240 | if (middle == floor) |
1213 | if (middle == floor) |
1241 | middle = blank_face; |
1214 | middle = 0; |
1242 | |
1215 | |
1243 | if (top == middle) |
1216 | if (top == middle) |
1244 | middle = blank_face; |
1217 | middle = 0; |
1245 | |
1218 | |
1246 | faces [0] = top; faces_obj [0] = top != blank_face ? top_obj : 0; |
1219 | #if 0 |
1247 | faces [1] = middle; faces_obj [1] = middle != blank_face ? middle_obj : 0; |
1220 | faces_obj [0] = top; |
1248 | faces [2] = floor; faces_obj [2] = floor != blank_face ? floor_obj : 0; |
1221 | faces_obj [1] = middle; |
|
|
1222 | faces_obj [2] = floor; |
|
|
1223 | #endif |
1249 | } |
1224 | } |
1250 | |
1225 | |
1251 | uint64 |
1226 | uint64 |
1252 | mapspace::volume () const |
1227 | mapspace::volume () const |
1253 | { |
1228 | { |
… | |
… | |
1673 | return default_region; |
1648 | return default_region; |
1674 | |
1649 | |
1675 | return ::region::default_region (); |
1650 | return ::region::default_region (); |
1676 | } |
1651 | } |
1677 | |
1652 | |
|
|
1653 | /* picks a random object from a style map. |
|
|
1654 | * Redone by MSW so it should be faster and not use static |
|
|
1655 | * variables to generate tables. |
|
|
1656 | */ |
|
|
1657 | object * |
|
|
1658 | maptile::pick_random_object () const |
|
|
1659 | { |
|
|
1660 | /* while returning a null object will result in a crash, that |
|
|
1661 | * is actually preferable to an infinite loop. That is because |
|
|
1662 | * most servers will automatically restart in case of crash. |
|
|
1663 | * Change the logic on getting the random space - shouldn't make |
|
|
1664 | * any difference, but this seems clearer to me. |
|
|
1665 | */ |
|
|
1666 | for (int i = 1000; --i;) |
|
|
1667 | { |
|
|
1668 | object *pick = at (rndm (width), rndm (height)).bot; |
1678 | |
1669 | |
|
|
1670 | // do not prefer big monsters just because they are big. |
|
|
1671 | if (pick && pick->head_ () == pick) |
|
|
1672 | return pick->head_ (); |
|
|
1673 | } |
|
|
1674 | |
|
|
1675 | // instead of crashing in the unlikely(?) case, try to return *something* |
|
|
1676 | return get_archetype ("blocked"); |
|
|
1677 | } |
|
|
1678 | |