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.94 by root, Mon Mar 12 01:13:10 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);
1079void 1075void
1080mapspace::update_ () 1076mapspace::update_ ()
1081{ 1077{
1082 object *tmp, *last = 0; 1078 object *tmp, *last = 0;
1083 uint8 flags = P_UPTODATE, light = 0, anywhere = 0; 1079 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; 1080 MoveType move_block = 0, move_slow = 0, move_on = 0, move_off = 0, move_allow = 0;
1087 1081
1088 middle = blank_face; 1082 //object *middle = 0;
1089 top = blank_face; 1083 //object *top = 0;
1090 floor = blank_face; 1084 //object *floor = 0;
1091 1085 // this seems to generate better code than using locals, above
1092 middle_obj = 0; 1086 object *&top = faces_obj[0];
1093 top_obj = 0; 1087 object *&middle = faces_obj[1];
1094 floor_obj = 0; 1088 object *&floor = faces_obj[2];
1095 1089
1096 for (tmp = bot; tmp; last = tmp, tmp = tmp->above) 1090 for (tmp = bot; tmp; last = tmp, tmp = tmp->above)
1097 { 1091 {
1098 /* This could be made additive I guess (two lights better than 1092 /* This could be made additive I guess (two lights better than
1099 * 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
1112 * Always put the player down for drawing. 1106 * Always put the player down for drawing.
1113 */ 1107 */
1114 if (!tmp->invisible) 1108 if (!tmp->invisible)
1115 { 1109 {
1116 if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER))) 1110 if ((tmp->type == PLAYER || QUERY_FLAG (tmp, FLAG_MONSTER)))
1117 {
1118 top = tmp->face;
1119 top_obj = tmp; 1111 top = tmp;
1120 }
1121 else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 1112 else if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
1122 { 1113 {
1123 /* 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,
1124 * so should not be visible, so we clear them. 1115 * so should not be visible, so we clear them.
1125 */ 1116 */
1126 middle = blank_face; 1117 middle = 0;
1127 top = blank_face; 1118 top = 0;
1128 floor = tmp->face;
1129 floor_obj = tmp; 1119 floor = tmp;
1130 } 1120 }
1131 /* Flag anywhere have high priority */ 1121 /* Flag anywhere have high priority */
1132 else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE)) 1122 else if (QUERY_FLAG (tmp, FLAG_SEE_ANYWHERE))
1133 { 1123 {
1134 middle = tmp->face;
1135
1136 middle_obj = tmp; 1124 middle = tmp;
1137 anywhere = 1; 1125 anywhere = 1;
1138 } 1126 }
1139 /* Find the highest visible face around. If equal 1127 /* Find the highest visible face around. If equal
1140 * visibilities, we still want the one nearer to the 1128 * visibilities, we still want the one nearer to the
1141 * top 1129 * top
1142 */ 1130 */
1143 else if (middle == blank_face || (tmp->face->visibility > middle->visibility && !anywhere)) 1131 else if (!middle || (::faces [tmp->face].visibility > ::faces [middle->face].visibility && !anywhere))
1144 {
1145 middle = tmp->face;
1146 middle_obj = tmp; 1132 middle = tmp;
1147 }
1148 } 1133 }
1149 1134
1150 if (tmp == tmp->above) 1135 if (tmp == tmp->above)
1151 { 1136 {
1152 LOG (llevError, "Error in structure of map\n"); 1137 LOG (llevError, "Error in structure of map\n");
1187 * middle face. This should not happen, as we already have the 1172 * middle face. This should not happen, as we already have the
1188 * else statement above so middle should not get set. OTOH, it 1173 * else statement above so middle should not get set. OTOH, it
1189 * 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.
1190 */ 1175 */
1191 if (top == middle) 1176 if (top == middle)
1192 middle = blank_face; 1177 middle = 0;
1193 1178
1194 /* There are three posibilities at this point: 1179 /* There are three posibilities at this point:
1195 * 1) top face is set, need middle to be set. 1180 * 1) top face is set, need middle to be set.
1196 * 2) middle is set, need to set top. 1181 * 2) middle is set, need to set top.
1197 * 3) neither middle or top is set - need to set both. 1182 * 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 */ 1187 /* Once we get to a floor, stop, since we already have a floor object */
1203 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) 1188 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR))
1204 break; 1189 break;
1205 1190
1206 /* If two top faces are already set, quit processing */ 1191 /* If two top faces are already set, quit processing */
1207 if ((top != blank_face) && (middle != blank_face)) 1192 if (top && middle)
1208 break; 1193 break;
1209 1194
1210 /* Only show visible faces */ 1195 /* Only show visible faces */
1211 if (!tmp->invisible) 1196 if (!tmp->invisible)
1212 { 1197 {
1213 /* Fill in top if needed */ 1198 /* Fill in top if needed */
1214 if (top == blank_face) 1199 if (!top)
1215 { 1200 {
1216 top = tmp->face;
1217 top_obj = tmp; 1201 top = tmp;
1218 if (top == middle) 1202 if (top == middle)
1219 middle = blank_face; 1203 middle = 0;
1220 } 1204 }
1221 else 1205 else
1222 { 1206 {
1223 /* top is already set - we should only get here if 1207 /* top is already set - we should only get here if
1224 * middle is not set 1208 * middle is not set
1225 * 1209 *
1226 * Set the middle face and break out, since there is nothing 1210 * Set the middle face and break out, since there is nothing
1227 * more to fill in. We don't check visiblity here, since 1211 * more to fill in. We don't check visiblity here, since
1228 * 1212 *
1229 */ 1213 */
1230 if (tmp->face != top) 1214 if (tmp != top)
1231 { 1215 {
1232 middle = tmp->face;
1233 middle_obj = tmp; 1216 middle = tmp;
1234 break; 1217 break;
1235 } 1218 }
1236 } 1219 }
1237 } 1220 }
1238 } 1221 }
1239 1222
1240 if (middle == floor) 1223 if (middle == floor)
1241 middle = blank_face; 1224 middle = 0;
1242 1225
1243 if (top == middle) 1226 if (top == middle)
1244 middle = blank_face; 1227 middle = 0;
1245 1228
1246 faces [0] = top; faces_obj [0] = top != blank_face ? top_obj : 0; 1229#if 0
1247 faces [1] = middle; faces_obj [1] = middle != blank_face ? middle_obj : 0; 1230 faces_obj [0] = top;
1248 faces [2] = floor; faces_obj [2] = floor != blank_face ? floor_obj : 0; 1231 faces_obj [1] = middle;
1232 faces_obj [2] = floor;
1233#endif
1249} 1234}
1250 1235
1251uint64 1236uint64
1252mapspace::volume () const 1237mapspace::volume () const
1253{ 1238{
1673 return default_region; 1658 return default_region;
1674 1659
1675 return ::region::default_region (); 1660 return ::region::default_region ();
1676} 1661}
1677 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 */
1667object *
1668maptile::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;
1678 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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines