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.228 by root, Sat May 3 11:14:50 2008 UTC vs.
Revision 1.233 by root, Tue May 6 18:47:32 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;
948 height = 3; 951 height = 3;
949 nodrop = 1; 952 nodrop = 1;
950 953
951 alloc (); 954 alloc ();
952 in_memory = MAP_ACTIVE; 955 in_memory = MAP_ACTIVE;
956 }
957
958 ~freed_map ()
959 {
960 destroy ();
953 } 961 }
954} freed_map; // freed objects are moved here to avoid crashes 962} freed_map; // freed objects are moved here to avoid crashes
955 963
956void 964void
957object::do_destroy () 965object::do_destroy ()
1285 * of areas of callers (eg, anything that uses find_free_spot would now 1293 * of areas of callers (eg, anything that uses find_free_spot would now
1286 * need extra work 1294 * need extra work
1287 */ 1295 */
1288 if (!xy_normalise (m, op->x, op->y)) 1296 if (!xy_normalise (m, op->x, op->y))
1289 { 1297 {
1290 op->destroy (1); 1298 op->head_ ()->destroy (1);// remove head_ once all tail object destroyers found
1291 return 0; 1299 return 0;
1292 } 1300 }
1293 1301
1294 if (object *more = op->more) 1302 if (object *more = op->more)
1295 if (!insert_ob_in_map (more, m, originator, flag)) 1303 if (!insert_ob_in_map (more, m, originator, flag))
1582 } 1590 }
1583 else 1591 else
1584 { 1592 {
1585 decrease (nr); 1593 decrease (nr);
1586 1594
1587 object *op = object_create_clone (this); 1595 object *op = deep_clone ();
1588 op->nrof = nr; 1596 op->nrof = nr;
1589 return op; 1597 return op;
1590 } 1598 }
1591} 1599}
1592 1600
1813 LOG (llevError, "Present_arch called outside map.\n"); 1821 LOG (llevError, "Present_arch called outside map.\n");
1814 return NULL; 1822 return NULL;
1815 } 1823 }
1816 1824
1817 for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above) 1825 for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above)
1818 if (tmp->arch == at) 1826 if (tmp->arch->archname == at->archname)
1819 return tmp; 1827 return tmp;
1820 1828
1821 return NULL; 1829 return NULL;
1822} 1830}
1823 1831
1887 * The first matching object is returned, or NULL if none. 1895 * The first matching object is returned, or NULL if none.
1888 */ 1896 */
1889object * 1897object *
1890present_arch_in_ob (const archetype *at, const object *op) 1898present_arch_in_ob (const archetype *at, const object *op)
1891{ 1899{
1892 for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below) 1900 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1893 if (tmp->arch == at) 1901 if (tmp->arch->archname == at->archname)
1894 return tmp; 1902 return tmp;
1895 1903
1896 return NULL; 1904 return NULL;
1897} 1905}
1898 1906
2307 2315
2308/* 2316/*
2309 * create clone from object to another 2317 * create clone from object to another
2310 */ 2318 */
2311object * 2319object *
2312object_create_clone (object *asrc) 2320object::deep_clone ()
2313{ 2321{
2322 assert (("deep_clone called on non-head object", is_head ()));
2323
2314 object *dst = 0; 2324 object *dst = clone ();
2315 2325
2316 if (!asrc)
2317 return 0;
2318
2319 object *src = asrc->head_ ();
2320
2321 object *prev = 0; 2326 object *prev = dst;
2322 for (object *part = src; part; part = part->more) 2327 for (object *part = this->more; part; part = part->more)
2323 { 2328 {
2324 object *tmp = part->clone (); 2329 object *tmp = part->clone ();
2325
2326 tmp->x -= src->x;
2327 tmp->y -= src->y;
2328
2329 if (!part->head)
2330 {
2331 dst = tmp;
2332 tmp->head = 0;
2333 }
2334 else
2335 tmp->head = dst; 2330 tmp->head = dst;
2336
2337 tmp->more = 0;
2338
2339 if (prev)
2340 prev->more = tmp; 2331 prev->more = tmp;
2341
2342 prev = tmp; 2332 prev = tmp;
2343 } 2333 }
2344 2334
2345 for (object *item = src->inv; item; item = item->below) 2335 for (object *item = inv; item; item = item->below)
2346 insert_ob_in_ob (object_create_clone (item), dst); 2336 insert_ob_in_ob (item->deep_clone (), dst);
2347 2337
2348 return dst; 2338 return dst;
2349} 2339}
2350 2340
2351/* This returns the first object in who's inventory that 2341/* This returns the first object in who's inventory that

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines