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.88 by root, Fri Feb 16 19:43:40 2007 UTC vs.
Revision 1.96 by root, Thu Mar 15 14:23:02 2007 UTC

354{ 354{
355 if (!spaces) 355 if (!spaces)
356 return; 356 return;
357 357
358 for (mapspace *ms = spaces + size (); ms-- > spaces; ) 358 for (mapspace *ms = spaces + size (); ms-- > spaces; )
359 for (object *tmp = ms->bot; tmp; ) 359 for (object *tmp = ms->bot; tmp; tmp = tmp->above)
360 { 360 {
361 object *above = tmp->above;
362
363 /* already multipart - don't do anything more */ 361 /* already multipart - don't do anything more */
364 if (!tmp->head && !tmp->more) 362 if (!tmp->head && !tmp->more)
365 { 363 {
366 /* If there is nothing more to this object, this for loop 364 /* If there is nothing more to this object, this for loop
367 * won't do anything. 365 * won't do anything.
389 * the coding is simpler to just to it here with each part. 387 * the coding is simpler to just to it here with each part.
390 */ 388 */
391 insert_ob_in_map (op, op->map, tmp, INS_NO_MERGE | INS_ABOVE_FLOOR_ONLY | INS_NO_WALK_ON); 389 insert_ob_in_map (op, op->map, tmp, INS_NO_MERGE | INS_ABOVE_FLOOR_ONLY | INS_NO_WALK_ON);
392 } 390 }
393 } 391 }
394
395 tmp = above;
396 } 392 }
397} 393}
398 394
399/* 395/*
400 * Loads (ands parses) the objects into a given map from the specified 396 * Loads (ands parses) the objects into a given map from the specified
408 coroapi::cede_every (1000); // cede once in a while 404 coroapi::cede_every (1000); // cede once in a while
409 405
410 switch (f.kw) 406 switch (f.kw)
411 { 407 {
412 case KW_arch: 408 case KW_arch:
413 if (object *op = object::read (f)) 409 if (object *op = object::read (f, this))
414 { 410 {
415 if (op->inv) 411 if (op->inv)
416 sum_weight (op); 412 sum_weight (op);
417 413
418 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);
468 if (!spaces) 464 if (!spaces)
469 return false; 465 return false;
470 466
471 for (int i = 0; i < size (); ++i) 467 for (int i = 0; i < size (); ++i)
472 { 468 {
473#if 0 // temporarily disabled for improved(?) stability, schmorp #TODO#d#//D
474 if (cede_count >= 500) 469 if (cede_count >= 500)
475 { 470 {
476 cede_count = 0; 471 cede_count = 0;
477 coroapi::cede (); 472 coroapi::cede ();
478 } 473 }
479#endif
480 474
481 int unique = 0; 475 int unique = 0;
482 for (object *op = spaces [i].bot; op; op = op->above) 476 for (object *op = spaces [i].bot; op; op = op->above)
483 { 477 {
484 // count per-object, but cede only when modification-safe 478 // count per-object, but cede only when modification-safe
1079void 1073void
1080mapspace::update_ () 1074mapspace::update_ ()
1081{ 1075{
1082 object *tmp, *last = 0; 1076 object *tmp, *last = 0;
1083 uint8 flags = P_UPTODATE, light = 0, anywhere = 0; 1077 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; 1078 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0;
1087 1079
1088 middle = blank_face; 1080 //object *middle = 0;
1089 top = blank_face; 1081 //object *top = 0;
1090 floor = blank_face; 1082 //object *floor = 0;
1091 1083 // this seems to generate better code than using locals, above
1092 middle_obj = 0; 1084 object *&top = faces_obj[0] = 0;
1093 top_obj = 0; 1085 object *&middle = faces_obj[1] = 0;
1094 floor_obj = 0; 1086 object *&floor = faces_obj[2] = 0;
1095 1087
1096 for (tmp = bot; tmp; last = tmp, tmp = tmp->above) 1088 for (tmp = bot; tmp; last = tmp, tmp = tmp->above)
1097 { 1089 {
1098 /* This could be made additive I guess (two lights better than 1090 /* This could be made additive I guess (two lights better than
1099 * 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
1112 * Always put the player down for drawing. 1104 * Always put the player down for drawing.
1113 */ 1105 */
1114 if (!tmp->invisible) 1106 if (!tmp->invisible)
1115 { 1107 {
1116 if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER))) 1108 if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER)))
1117 {
1118 top = tmp->face;
1119 top_obj = tmp; 1109 top = tmp;
1120 }
1121 else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 1110 else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
1122 { 1111 {
1123 /* 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,
1124 * so should not be visible, so we clear them. 1113 * so should not be visible, so we clear them.
1125 */ 1114 */
1126 middle = blank_face; 1115 middle = 0;
1127 top = blank_face; 1116 top = 0;
1128 floor = tmp->face;
1129 floor_obj = tmp; 1117 floor = tmp;
1130 } 1118 }
1131 /* Flag anywhere have high priority */ 1119 /* Flag anywhere have high priority */
1132 else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) 1120 else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE))
1133 { 1121 {
1134 middle = tmp->face;
1135
1136 middle_obj = tmp; 1122 middle = tmp;
1137 anywhere = 1; 1123 anywhere = 1;
1138 } 1124 }
1139 /* Find the highest visible face around. If equal 1125 /* Find the highest visible face around. If equal
1140 * visibilities, we still want the one nearer to the 1126 * visibilities, we still want the one nearer to the
1141 * top 1127 * top
1142 */ 1128 */
1143 else if (middle == blank_face || (tmp->face->visibility > middle->visibility && !anywhere)) 1129 else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere))
1144 {
1145 middle = tmp->face;
1146 middle_obj = tmp; 1130 middle = tmp;
1147 }
1148 } 1131 }
1149 1132
1150 if (tmp == tmp->above) 1133 if (tmp == tmp->above)
1151 { 1134 {
1152 LOG (llevError, "Error in structure of map\n"); 1135 LOG (llevError, "Error in structure of map\n");
1187 * middle face. This should not happen, as we already have the 1170 * middle face. This should not happen, as we already have the
1188 * else statement above so middle should not get set. OTOH, it 1171 * else statement above so middle should not get set. OTOH, it
1189 * 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.
1190 */ 1173 */
1191 if (top == middle) 1174 if (top == middle)
1192 middle = blank_face; 1175 middle = 0;
1193 1176
1194 /* There are three posibilities at this point: 1177 /* There are three posibilities at this point:
1195 * 1) top face is set, need middle to be set. 1178 * 1) top face is set, need middle to be set.
1196 * 2) middle is set, need to set top. 1179 * 2) middle is set, need to set top.
1197 * 3) neither middle or top is set - need to set both. 1180 * 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 */ 1185 /* Once we get to a floor, stop, since we already have a floor object */
1203 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 1186 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
1204 break; 1187 break;
1205 1188
1206 /* If two top faces are already set, quit processing */ 1189 /* If two top faces are already set, quit processing */
1207 if ((top != blank_face) && (middle != blank_face)) 1190 if (top && middle)
1208 break; 1191 break;
1209 1192
1210 /* Only show visible faces */ 1193 /* Only show visible faces */
1211 if (!tmp->invisible) 1194 if (!tmp->invisible)
1212 { 1195 {
1213 /* Fill in top if needed */ 1196 /* Fill in top if needed */
1214 if (top == blank_face) 1197 if (!top)
1215 { 1198 {
1216 top = tmp->face;
1217 top_obj = tmp; 1199 top = tmp;
1218 if (top == middle) 1200 if (top == middle)
1219 middle = blank_face; 1201 middle = 0;
1220 } 1202 }
1221 else 1203 else
1222 { 1204 {
1223 /* top is already set - we should only get here if 1205 /* top is already set - we should only get here if
1224 * middle is not set 1206 * middle is not set
1225 * 1207 *
1226 * Set the middle face and break out, since there is nothing 1208 * Set the middle face and break out, since there is nothing
1227 * more to fill in. We don't check visiblity here, since 1209 * more to fill in. We don't check visiblity here, since
1228 * 1210 *
1229 */ 1211 */
1230 if (tmp->face != top) 1212 if (tmp != top)
1231 { 1213 {
1232 middle = tmp->face;
1233 middle_obj = tmp; 1214 middle = tmp;
1234 break; 1215 break;
1235 } 1216 }
1236 } 1217 }
1237 } 1218 }
1238 } 1219 }
1239 1220
1240 if (middle == floor) 1221 if (middle == floor)
1241 middle = blank_face; 1222 middle = 0;
1242 1223
1243 if (top == middle) 1224 if (top == middle)
1244 middle = blank_face; 1225 middle = 0;
1245 1226
1246 faces [0] = top; faces_obj [0] = top != blank_face ? top_obj : 0; 1227#if 0
1247 faces [1] = middle; faces_obj [1] = middle != blank_face ? middle_obj : 0; 1228 faces_obj [0] = top;
1248 faces [2] = floor; faces_obj [2] = floor != blank_face ? floor_obj : 0; 1229 faces_obj [1] = middle;
1230 faces_obj [2] = floor;
1231#endif
1249} 1232}
1250 1233
1251uint64 1234uint64
1252mapspace::volume () const 1235mapspace::volume () const
1253{ 1236{
1673 return default_region; 1656 return default_region;
1674 1657
1675 return ::region::default_region (); 1658 return ::region::default_region ();
1676} 1659}
1677 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;
1678 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