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

Comparing deliantra/server/common/object.C (file contents):
Revision 1.233 by root, Tue May 6 18:47:32 2008 UTC vs.
Revision 1.240 by root, Wed May 7 13:40:30 2008 UTC

406 op->update_weight (); 406 op->update_weight ();
407 407
408 sum += op->total_weight (); 408 sum += op->total_weight ();
409 } 409 }
410 410
411 sum = weight_adjust (this, sum); 411 sum = weight_adjust_for (this, sum);
412 412
413 if (sum != carrying) 413 if (sum != carrying)
414 { 414 {
415 carrying = sum; 415 carrying = sum;
416 416
904 * drop on that space. 904 * drop on that space.
905 */ 905 */
906 if (!drop_to_ground 906 if (!drop_to_ground
907 || !map 907 || !map
908 || map->in_memory != MAP_ACTIVE 908 || map->in_memory != MAP_ACTIVE
909 || map->nodrop 909 || map->no_drop
910 || ms ().move_block == MOVE_ALL) 910 || ms ().move_block == MOVE_ALL)
911 { 911 {
912 while (inv) 912 while (inv)
913 { 913 {
914 inv->destroy_inv (false); 914 inv->destroy_inv (false);
943 943
944static struct freed_map : maptile 944static struct freed_map : maptile
945{ 945{
946 freed_map () 946 freed_map ()
947 { 947 {
948 path = "<freed objects map>"; 948 path = "<freed objects map>";
949 name = "/internal/freed_objects_map"; 949 name = "/internal/freed_objects_map";
950 width = 3; 950 width = 3;
951 height = 3; 951 height = 3;
952 nodrop = 1; 952 no_drop = 1;
953 no_reset = 1;
953 954
954 alloc (); 955 alloc ();
955 in_memory = MAP_ACTIVE; 956 in_memory = MAP_ACTIVE;
956 } 957 }
957 958
1056 if (object *pl = visible_to ()) 1057 if (object *pl = visible_to ())
1057 esrv_del_item (pl->contr, count); 1058 esrv_del_item (pl->contr, count);
1058 flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed 1059 flag [FLAG_REMOVED] = true; // hack around the issue of visible_to checking flag_removed
1059 1060
1060 adjust_weight (env, -total_weight ()); 1061 adjust_weight (env, -total_weight ());
1061
1062 *(above ? &above->below : &env->inv) = below;
1063
1064 if (below)
1065 below->above = above;
1066 1062
1067 /* we set up values so that it could be inserted into 1063 /* we set up values so that it could be inserted into
1068 * the map, but we don't actually do that - it is up 1064 * the map, but we don't actually do that - it is up
1069 * to the caller to decide what we want to do. 1065 * to the caller to decide what we want to do.
1070 */ 1066 */
1071 map = env->map; 1067 map = env->map;
1072 x = env->x; 1068 x = env->x;
1073 y = env->y; 1069 y = env->y;
1070
1071 // make sure cmov optimisation is applicable
1072 *(above ? &above->below : &env->inv) = below;
1073 *(below ? &below->above : &above ) = above; // &above is just a dummy
1074
1074 above = 0; 1075 above = 0;
1075 below = 0; 1076 below = 0;
1076 env = 0; 1077 env = 0;
1077 1078
1078 /* NO_FIX_PLAYER is set when a great many changes are being 1079 /* NO_FIX_PLAYER is set when a great many changes are being
1108 1109
1109 esrv_del_item (pl->contr, count); 1110 esrv_del_item (pl->contr, count);
1110 } 1111 }
1111 1112
1112 /* link the object above us */ 1113 /* link the object above us */
1113 if (above) 1114 // re-link, make sure compiler can easily use cmove
1114 above->below = below; 1115 *(above ? &above->below : &ms.top) = below;
1115 else 1116 *(below ? &below->above : &ms.bot) = above;
1116 ms.top = below; /* we were top, set new top */
1117
1118 /* Relink the object below us, if there is one */
1119 if (below)
1120 below->above = above;
1121 else
1122 {
1123 /* Nothing below, which means we need to relink map object for this space
1124 * use translated coordinates in case some oddness with map tiling is
1125 * evident
1126 */
1127 if (GET_MAP_OB (map, x, y) != this)
1128 LOG (llevError, "remove_ob: GET_MAP_OB does not return object to be removed even though it appears to be on the bottom? %s\n", debug_desc ());
1129
1130 ms.bot = above; /* goes on above it. */
1131 }
1132 1117
1133 above = 0; 1118 above = 0;
1134 below = 0; 1119 below = 0;
1135 1120
1136 if (map->in_memory == MAP_SAVING) 1121 if (map->in_memory == MAP_SAVING)
1283 * just 'op' otherwise 1268 * just 'op' otherwise
1284 */ 1269 */
1285object * 1270object *
1286insert_ob_in_map (object *op, maptile *m, object *originator, int flag) 1271insert_ob_in_map (object *op, maptile *m, object *originator, int flag)
1287{ 1272{
1288 assert (!op->flag [FLAG_FREED]);
1289
1290 op->remove (); 1273 op->remove ();
1291 1274
1292 /* Ideally, the caller figures this out. However, it complicates a lot 1275 /* Ideally, the caller figures this out. However, it complicates a lot
1293 * of areas of callers (eg, anything that uses find_free_spot would now 1276 * of areas of callers (eg, anything that uses find_free_spot would now
1294 * need extra work 1277 * need extra work
1312 */ 1295 */
1313 if (op->nrof && !(flag & INS_NO_MERGE)) 1296 if (op->nrof && !(flag & INS_NO_MERGE))
1314 for (object *tmp = ms.bot; tmp; tmp = tmp->above) 1297 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
1315 if (object::can_merge (op, tmp)) 1298 if (object::can_merge (op, tmp))
1316 { 1299 {
1317 // TODO: we atcually want to update tmp, not op, 1300 // TODO: we actually want to update tmp, not op,
1318 // but some caller surely breaks when we return tmp 1301 // but some caller surely breaks when we return tmp
1319 // from here :/ 1302 // from here :/
1320 op->nrof += tmp->nrof; 1303 op->nrof += tmp->nrof;
1321 tmp->destroy (1); 1304 tmp->destroy (1);
1322 } 1305 }
1327 if (!QUERY_FLAG (op, FLAG_ALIVE)) 1310 if (!QUERY_FLAG (op, FLAG_ALIVE))
1328 CLEAR_FLAG (op, FLAG_NO_STEAL); 1311 CLEAR_FLAG (op, FLAG_NO_STEAL);
1329 1312
1330 if (flag & INS_BELOW_ORIGINATOR) 1313 if (flag & INS_BELOW_ORIGINATOR)
1331 { 1314 {
1332 if (originator->map != op->map || originator->x != op->x || originator->y != op->y) 1315 if (originator->map != op->map || originator->x != op->x || originator->y != op->y || !originator->is_on_map ())
1333 { 1316 {
1334 LOG (llevError, "insert_ob_in_map called with INS_BELOW_ORIGINATOR when originator not on same space!\n"); 1317 LOG (llevError, "insert_ob_in_map called with INS_BELOW_ORIGINATOR when originator not on same space!\n");
1335 abort (); 1318 abort ();
1336 } 1319 }
1337 1320
1338 op->above = originator; 1321 op->above = originator;
1339 op->below = originator->below; 1322 op->below = originator->below;
1340
1341 if (op->below)
1342 op->below->above = op;
1343 else
1344 ms.bot = op;
1345
1346 /* since *below* originator, no need to update top */
1347 originator->below = op; 1323 originator->below = op;
1324
1325 *(op->below ? &op->below->above : &ms.bot) = op;
1348 } 1326 }
1349 else 1327 else
1350 { 1328 {
1351 object *top, *floor = NULL; 1329 object *floor = 0;
1352 1330 object *top = ms.top;
1353 top = ms.bot;
1354 1331
1355 /* If there are other objects, then */ 1332 /* If there are other objects, then */
1356 if (top) 1333 if (top)
1357 { 1334 {
1358 object *last = 0;
1359
1360 /* 1335 /*
1361 * If there are multiple objects on this space, we do some trickier handling. 1336 * If there are multiple objects on this space, we do some trickier handling.
1362 * We've already dealt with merging if appropriate. 1337 * We've already dealt with merging if appropriate.
1363 * Generally, we want to put the new object on top. But if 1338 * Generally, we want to put the new object on top. But if
1364 * flag contains INS_ABOVE_FLOOR_ONLY, once we find the last 1339 * flag contains INS_ABOVE_FLOOR_ONLY, once we find the last
1367 * once we get to them. This reduces the need to traverse over all of 1342 * once we get to them. This reduces the need to traverse over all of
1368 * them when adding another one - this saves quite a bit of cpu time 1343 * them when adding another one - this saves quite a bit of cpu time
1369 * when lots of spells are cast in one area. Currently, it is presumed 1344 * when lots of spells are cast in one area. Currently, it is presumed
1370 * that flying non pickable objects are spell objects. 1345 * that flying non pickable objects are spell objects.
1371 */ 1346 */
1372 for (top = ms.bot; top; top = top->above) 1347 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
1373 { 1348 {
1374 if (QUERY_FLAG (top, FLAG_IS_FLOOR) || QUERY_FLAG (top, FLAG_OVERLAY_FLOOR)) 1349 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) || QUERY_FLAG (tmp, FLAG_OVERLAY_FLOOR))
1375 floor = top; 1350 floor = tmp;
1376 1351
1377 if (QUERY_FLAG (top, FLAG_NO_PICK) && (top->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (top, FLAG_IS_FLOOR)) 1352 if (QUERY_FLAG (tmp, FLAG_NO_PICK) && (tmp->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (tmp, FLAG_IS_FLOOR))
1378 { 1353 {
1379 /* We insert above top, so we want this object below this */ 1354 /* We insert above top, so we want this object below this */
1380 top = top->below; 1355 top = tmp->below;
1381 break; 1356 break;
1382 } 1357 }
1383 1358
1384 last = top; 1359 top = tmp;
1385 } 1360 }
1386
1387 /* Don't want top to be NULL, so set it to the last valid object */
1388 top = last;
1389 1361
1390 /* We let update_position deal with figuring out what the space 1362 /* We let update_position deal with figuring out what the space
1391 * looks like instead of lots of conditions here. 1363 * looks like instead of lots of conditions here.
1392 * makes things faster, and effectively the same result. 1364 * makes things faster, and effectively the same result.
1393 */ 1365 */
1400 */ 1372 */
1401 if (!(flag & INS_ON_TOP) 1373 if (!(flag & INS_ON_TOP)
1402 && ms.flags () & P_BLOCKSVIEW 1374 && ms.flags () & P_BLOCKSVIEW
1403 && (op->face && !faces [op->face].visibility)) 1375 && (op->face && !faces [op->face].visibility))
1404 { 1376 {
1377 object *last;
1378
1405 for (last = top; last != floor; last = last->below) 1379 for (last = top; last != floor; last = last->below)
1406 if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) 1380 if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT))
1407 break; 1381 break;
1408 1382
1409 /* Check to see if we found the object that blocks view, 1383 /* Check to see if we found the object that blocks view,
1417 } /* If objects on this space */ 1391 } /* If objects on this space */
1418 1392
1419 if (flag & INS_ABOVE_FLOOR_ONLY) 1393 if (flag & INS_ABOVE_FLOOR_ONLY)
1420 top = floor; 1394 top = floor;
1421 1395
1422 /* Top is the object that our object (op) is going to get inserted above. 1396 // insert object above top, or bottom-most if top = 0
1423 */
1424
1425 /* First object on this space */
1426 if (!top) 1397 if (!top)
1427 { 1398 {
1399 op->below = 0;
1428 op->above = ms.bot; 1400 op->above = ms.bot;
1429
1430 if (op->above)
1431 op->above->below = op;
1432
1433 op->below = 0;
1434 ms.bot = op; 1401 ms.bot = op;
1402
1403 *(op->above ? &op->above->below : &ms.top) = op;
1435 } 1404 }
1436 else 1405 else
1437 { /* get inserted into the stack above top */ 1406 {
1438 op->above = top->above; 1407 op->above = top->above;
1439
1440 if (op->above)
1441 op->above->below = op; 1408 top->above = op;
1442 1409
1443 op->below = top; 1410 op->below = top;
1444 top->above = op; 1411 *(op->above ? &op->above->below : &ms.top) = op;
1445 } 1412 }
1446 1413 }
1447 if (!op->above)
1448 ms.top = op;
1449 } /* else not INS_BELOW_ORIGINATOR */
1450 1414
1451 if (op->type == PLAYER) 1415 if (op->type == PLAYER)
1452 { 1416 {
1453 op->contr->do_los = 1; 1417 op->contr->do_los = 1;
1454 ++op->map->players; 1418 ++op->map->players;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines