ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/map.C
(Generate patch)

Comparing deliantra/server/common/map.C (file contents):
Revision 1.89 by root, Fri Feb 16 22:16:16 2007 UTC vs.
Revision 1.96 by root, Thu Mar 15 14:23:02 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines