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.230 by root, Sun May 4 08:25:32 2008 UTC vs.
Revision 1.242 by elmex, Wed May 7 21:00:02 2008 UTC

354 return 0; 354 return 0;
355} 355}
356 356
357// adjust weight per container type ("of holding") 357// adjust weight per container type ("of holding")
358static sint32 358static sint32
359weight_adjust (object *op, sint32 weight) 359weight_adjust_for (object *op, sint32 weight)
360{ 360{
361 return op->type == CONTAINER 361 return op->type == CONTAINER
362 ? lerp (weight, 0, 100, 0, 100 - op->stats.Str) 362 ? lerp (weight, 0, 100, 0, 100 - op->stats.Str)
363 : weight; 363 : weight;
364} 364}
370static void 370static void
371adjust_weight (object *op, sint32 weight) 371adjust_weight (object *op, sint32 weight)
372{ 372{
373 while (op) 373 while (op)
374 { 374 {
375 // adjust by actual difference to account for rounding errors
376 // i.e. (w2 - w1) / f != w2 / f - w1 / f and the latter is correct
375 weight = weight_adjust (op, weight); 377 weight = weight_adjust_for (op, op->carrying)
378 - weight_adjust_for (op, op->carrying - weight);
376 379
377 if (!weight) 380 if (!weight)
378 return; 381 return;
379 382
380 op->carrying += weight; 383 op->carrying += weight;
403 op->update_weight (); 406 op->update_weight ();
404 407
405 sum += op->total_weight (); 408 sum += op->total_weight ();
406 } 409 }
407 410
408 sum = weight_adjust (this, sum); 411 sum = weight_adjust_for (this, sum);
409 412
410 if (sum != carrying) 413 if (sum != carrying)
411 { 414 {
412 carrying = sum; 415 carrying = sum;
413 416
901 * drop on that space. 904 * drop on that space.
902 */ 905 */
903 if (!drop_to_ground 906 if (!drop_to_ground
904 || !map 907 || !map
905 || map->in_memory != MAP_ACTIVE 908 || map->in_memory != MAP_ACTIVE
906 || map->nodrop 909 || map->no_drop
907 || ms ().move_block == MOVE_ALL) 910 || ms ().move_block == MOVE_ALL)
908 { 911 {
909 while (inv) 912 while (inv)
910 { 913 {
911 inv->destroy_inv (false); 914 inv->destroy_inv (false);
940 943
941static struct freed_map : maptile 944static struct freed_map : maptile
942{ 945{
943 freed_map () 946 freed_map ()
944 { 947 {
945 path = "<freed objects map>"; 948 path = "<freed objects map>";
946 name = "/internal/freed_objects_map"; 949 name = "/internal/freed_objects_map";
947 width = 3; 950 width = 3;
948 height = 3; 951 height = 3;
949 nodrop = 1; 952 no_drop = 1;
953 no_reset = 1;
950 954
951 alloc (); 955 alloc ();
952 in_memory = MAP_ACTIVE; 956 in_memory = MAP_ACTIVE;
953 } 957 }
954 958
1053 if (object *pl = visible_to ()) 1057 if (object *pl = visible_to ())
1054 esrv_del_item (pl->contr, count); 1058 esrv_del_item (pl->contr, count);
1055 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
1056 1060
1057 adjust_weight (env, -total_weight ()); 1061 adjust_weight (env, -total_weight ());
1058
1059 *(above ? &above->below : &env->inv) = below;
1060
1061 if (below)
1062 below->above = above;
1063 1062
1064 /* we set up values so that it could be inserted into 1063 /* we set up values so that it could be inserted into
1065 * 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
1066 * to the caller to decide what we want to do. 1065 * to the caller to decide what we want to do.
1067 */ 1066 */
1068 map = env->map; 1067 map = env->map;
1069 x = env->x; 1068 x = env->x;
1070 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
1071 above = 0; 1075 above = 0;
1072 below = 0; 1076 below = 0;
1073 env = 0; 1077 env = 0;
1074 1078
1075 /* 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
1105 1109
1106 esrv_del_item (pl->contr, count); 1110 esrv_del_item (pl->contr, count);
1107 } 1111 }
1108 1112
1109 /* link the object above us */ 1113 /* link the object above us */
1110 if (above) 1114 // re-link, make sure compiler can easily use cmove
1111 above->below = below; 1115 *(above ? &above->below : &ms.top) = below;
1112 else 1116 *(below ? &below->above : &ms.bot) = above;
1113 ms.top = below; /* we were top, set new top */
1114
1115 /* Relink the object below us, if there is one */
1116 if (below)
1117 below->above = above;
1118 else
1119 {
1120 /* Nothing below, which means we need to relink map object for this space
1121 * use translated coordinates in case some oddness with map tiling is
1122 * evident
1123 */
1124 if (GET_MAP_OB (map, x, y) != this)
1125 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 ());
1126
1127 ms.bot = above; /* goes on above it. */
1128 }
1129 1117
1130 above = 0; 1118 above = 0;
1131 below = 0; 1119 below = 0;
1132 1120
1133 if (map->in_memory == MAP_SAVING) 1121 if (map->in_memory == MAP_SAVING)
1280 * just 'op' otherwise 1268 * just 'op' otherwise
1281 */ 1269 */
1282object * 1270object *
1283insert_ob_in_map (object *op, maptile *m, object *originator, int flag) 1271insert_ob_in_map (object *op, maptile *m, object *originator, int flag)
1284{ 1272{
1285 assert (!op->flag [FLAG_FREED]);
1286
1287 op->remove (); 1273 op->remove ();
1288 1274
1289 /* Ideally, the caller figures this out. However, it complicates a lot 1275 /* Ideally, the caller figures this out. However, it complicates a lot
1290 * 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
1291 * need extra work 1277 * need extra work
1292 */ 1278 */
1293 if (!xy_normalise (m, op->x, op->y)) 1279 if (!xy_normalise (m, op->x, op->y))
1294 { 1280 {
1295 op->destroy (1); 1281 op->head_ ()->destroy (1);// remove head_ once all tail object destroyers found
1296 return 0; 1282 return 0;
1297 } 1283 }
1298 1284
1299 if (object *more = op->more) 1285 if (object *more = op->more)
1300 if (!insert_ob_in_map (more, m, originator, flag)) 1286 if (!insert_ob_in_map (more, m, originator, flag))
1309 */ 1295 */
1310 if (op->nrof && !(flag & INS_NO_MERGE)) 1296 if (op->nrof && !(flag & INS_NO_MERGE))
1311 for (object *tmp = ms.bot; tmp; tmp = tmp->above) 1297 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
1312 if (object::can_merge (op, tmp)) 1298 if (object::can_merge (op, tmp))
1313 { 1299 {
1314 // TODO: we atcually want to update tmp, not op, 1300 // TODO: we actually want to update tmp, not op,
1315 // but some caller surely breaks when we return tmp 1301 // but some caller surely breaks when we return tmp
1316 // from here :/ 1302 // from here :/
1317 op->nrof += tmp->nrof; 1303 op->nrof += tmp->nrof;
1318 tmp->destroy (1); 1304 tmp->destroy (1);
1319 } 1305 }
1330 { 1316 {
1331 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");
1332 abort (); 1318 abort ();
1333 } 1319 }
1334 1320
1321 if (!originator->is_on_map ())
1322 LOG (llevDebug | logBacktrace, "insert_ob_in_map(%s) called with INS_BELOW_ORIGINATOR when originator '%s' not on map",
1323 op->debug_desc (), originator->debug_desc ());
1324
1335 op->above = originator; 1325 op->above = originator;
1336 op->below = originator->below; 1326 op->below = originator->below;
1337
1338 if (op->below)
1339 op->below->above = op;
1340 else
1341 ms.bot = op;
1342
1343 /* since *below* originator, no need to update top */
1344 originator->below = op; 1327 originator->below = op;
1328
1329 *(op->below ? &op->below->above : &ms.bot) = op;
1345 } 1330 }
1346 else 1331 else
1347 { 1332 {
1348 object *top, *floor = NULL; 1333 object *floor = 0;
1349 1334 object *top = ms.top;
1350 top = ms.bot;
1351 1335
1352 /* If there are other objects, then */ 1336 /* If there are other objects, then */
1353 if (top) 1337 if (top)
1354 { 1338 {
1355 object *last = 0;
1356
1357 /* 1339 /*
1358 * If there are multiple objects on this space, we do some trickier handling. 1340 * If there are multiple objects on this space, we do some trickier handling.
1359 * We've already dealt with merging if appropriate. 1341 * We've already dealt with merging if appropriate.
1360 * Generally, we want to put the new object on top. But if 1342 * Generally, we want to put the new object on top. But if
1361 * flag contains INS_ABOVE_FLOOR_ONLY, once we find the last 1343 * flag contains INS_ABOVE_FLOOR_ONLY, once we find the last
1364 * once we get to them. This reduces the need to traverse over all of 1346 * once we get to them. This reduces the need to traverse over all of
1365 * them when adding another one - this saves quite a bit of cpu time 1347 * them when adding another one - this saves quite a bit of cpu time
1366 * when lots of spells are cast in one area. Currently, it is presumed 1348 * when lots of spells are cast in one area. Currently, it is presumed
1367 * that flying non pickable objects are spell objects. 1349 * that flying non pickable objects are spell objects.
1368 */ 1350 */
1369 for (top = ms.bot; top; top = top->above) 1351 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
1370 { 1352 {
1371 if (QUERY_FLAG (top, FLAG_IS_FLOOR) || QUERY_FLAG (top, FLAG_OVERLAY_FLOOR)) 1353 if (QUERY_FLAG (tmp, FLAG_IS_FLOOR) || QUERY_FLAG (tmp, FLAG_OVERLAY_FLOOR))
1372 floor = top; 1354 floor = tmp;
1373 1355
1374 if (QUERY_FLAG (top, FLAG_NO_PICK) && (top->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (top, FLAG_IS_FLOOR)) 1356 if (QUERY_FLAG (tmp, FLAG_NO_PICK) && (tmp->move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) && !QUERY_FLAG (tmp, FLAG_IS_FLOOR))
1375 { 1357 {
1376 /* We insert above top, so we want this object below this */ 1358 /* We insert above top, so we want this object below this */
1377 top = top->below; 1359 top = tmp->below;
1378 break; 1360 break;
1379 } 1361 }
1380 1362
1381 last = top; 1363 top = tmp;
1382 } 1364 }
1383
1384 /* Don't want top to be NULL, so set it to the last valid object */
1385 top = last;
1386 1365
1387 /* We let update_position deal with figuring out what the space 1366 /* We let update_position deal with figuring out what the space
1388 * looks like instead of lots of conditions here. 1367 * looks like instead of lots of conditions here.
1389 * makes things faster, and effectively the same result. 1368 * makes things faster, and effectively the same result.
1390 */ 1369 */
1397 */ 1376 */
1398 if (!(flag & INS_ON_TOP) 1377 if (!(flag & INS_ON_TOP)
1399 && ms.flags () & P_BLOCKSVIEW 1378 && ms.flags () & P_BLOCKSVIEW
1400 && (op->face && !faces [op->face].visibility)) 1379 && (op->face && !faces [op->face].visibility))
1401 { 1380 {
1381 object *last;
1382
1402 for (last = top; last != floor; last = last->below) 1383 for (last = top; last != floor; last = last->below)
1403 if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT)) 1384 if (QUERY_FLAG (last, FLAG_BLOCKSVIEW) && (last->type != EXIT))
1404 break; 1385 break;
1405 1386
1406 /* Check to see if we found the object that blocks view, 1387 /* Check to see if we found the object that blocks view,
1414 } /* If objects on this space */ 1395 } /* If objects on this space */
1415 1396
1416 if (flag & INS_ABOVE_FLOOR_ONLY) 1397 if (flag & INS_ABOVE_FLOOR_ONLY)
1417 top = floor; 1398 top = floor;
1418 1399
1419 /* Top is the object that our object (op) is going to get inserted above. 1400 // insert object above top, or bottom-most if top = 0
1420 */
1421
1422 /* First object on this space */
1423 if (!top) 1401 if (!top)
1424 { 1402 {
1403 op->below = 0;
1425 op->above = ms.bot; 1404 op->above = ms.bot;
1426
1427 if (op->above)
1428 op->above->below = op;
1429
1430 op->below = 0;
1431 ms.bot = op; 1405 ms.bot = op;
1406
1407 *(op->above ? &op->above->below : &ms.top) = op;
1432 } 1408 }
1433 else 1409 else
1434 { /* get inserted into the stack above top */ 1410 {
1435 op->above = top->above; 1411 op->above = top->above;
1436
1437 if (op->above)
1438 op->above->below = op; 1412 top->above = op;
1439 1413
1440 op->below = top; 1414 op->below = top;
1441 top->above = op; 1415 *(op->above ? &op->above->below : &ms.top) = op;
1442 } 1416 }
1443 1417 }
1444 if (!op->above)
1445 ms.top = op;
1446 } /* else not INS_BELOW_ORIGINATOR */
1447 1418
1448 if (op->type == PLAYER) 1419 if (op->type == PLAYER)
1449 { 1420 {
1450 op->contr->do_los = 1; 1421 op->contr->do_los = 1;
1451 ++op->map->players; 1422 ++op->map->players;
1818 LOG (llevError, "Present_arch called outside map.\n"); 1789 LOG (llevError, "Present_arch called outside map.\n");
1819 return NULL; 1790 return NULL;
1820 } 1791 }
1821 1792
1822 for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above) 1793 for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above)
1823 if (tmp->arch == at) 1794 if (tmp->arch->archname == at->archname)
1824 return tmp; 1795 return tmp;
1825 1796
1826 return NULL; 1797 return NULL;
1827} 1798}
1828 1799
1892 * The first matching object is returned, or NULL if none. 1863 * The first matching object is returned, or NULL if none.
1893 */ 1864 */
1894object * 1865object *
1895present_arch_in_ob (const archetype *at, const object *op) 1866present_arch_in_ob (const archetype *at, const object *op)
1896{ 1867{
1897 for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below) 1868 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1898 if (tmp->arch == at) 1869 if (tmp->arch->archname == at->archname)
1899 return tmp; 1870 return tmp;
1900 1871
1901 return NULL; 1872 return NULL;
1902} 1873}
1903 1874
2446{ 2417{
2447 char flagdesc[512]; 2418 char flagdesc[512];
2448 char info2[256 * 4]; 2419 char info2[256 * 4];
2449 char *p = info; 2420 char *p = info;
2450 2421
2451 p += snprintf (p, 512, "{cnt:%d,uuid:%s,name:\"%s\"%s%s,flags:[%s],type:%d}", 2422 p += snprintf (p, 512, "{cnt:%d,uuid:%s,name:\"%s\"%s%s%s,flags:[%s],type:%d}",
2452 count, 2423 count,
2453 uuid.c_str (), 2424 uuid.c_str (),
2454 &name, 2425 &name,
2455 title ? "\",title:\"" : "", 2426 title ? ",title:\"" : "",
2456 title ? (const char *)title : "", 2427 title ? (const char *)title : "",
2428 title ? "\"" : "",
2457 flag_desc (flagdesc, 512), type); 2429 flag_desc (flagdesc, 512), type);
2458 2430
2459 if (!flag[FLAG_REMOVED] && env) 2431 if (!flag[FLAG_REMOVED] && env)
2460 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2)); 2432 p += snprintf (p, 256, "(in %s)", env->debug_desc (info2));
2461 2433

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines