… | |
… | |
949 | nodrop = 1; |
949 | nodrop = 1; |
950 | |
950 | |
951 | alloc (); |
951 | alloc (); |
952 | in_memory = MAP_ACTIVE; |
952 | in_memory = MAP_ACTIVE; |
953 | } |
953 | } |
|
|
954 | |
|
|
955 | ~freed_map () |
|
|
956 | { |
|
|
957 | destroy (); |
|
|
958 | } |
954 | } freed_map; // freed objects are moved here to avoid crashes |
959 | } freed_map; // freed objects are moved here to avoid crashes |
955 | |
960 | |
956 | void |
961 | void |
957 | object::do_destroy () |
962 | object::do_destroy () |
958 | { |
963 | { |
… | |
… | |
1582 | } |
1587 | } |
1583 | else |
1588 | else |
1584 | { |
1589 | { |
1585 | decrease (nr); |
1590 | decrease (nr); |
1586 | |
1591 | |
1587 | object *op = object_create_clone (this); |
1592 | object *op = deep_clone (); |
1588 | op->nrof = nr; |
1593 | op->nrof = nr; |
1589 | return op; |
1594 | return op; |
1590 | } |
1595 | } |
1591 | } |
1596 | } |
1592 | |
1597 | |
… | |
… | |
1813 | LOG (llevError, "Present_arch called outside map.\n"); |
1818 | LOG (llevError, "Present_arch called outside map.\n"); |
1814 | return NULL; |
1819 | return NULL; |
1815 | } |
1820 | } |
1816 | |
1821 | |
1817 | for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above) |
1822 | for (object *tmp = m->at (x, y).bot; tmp; tmp = tmp->above) |
1818 | if (tmp->arch == at) |
1823 | if (tmp->arch->archname == at->archname) |
1819 | return tmp; |
1824 | return tmp; |
1820 | |
1825 | |
1821 | return NULL; |
1826 | return NULL; |
1822 | } |
1827 | } |
1823 | |
1828 | |
… | |
… | |
1887 | * The first matching object is returned, or NULL if none. |
1892 | * The first matching object is returned, or NULL if none. |
1888 | */ |
1893 | */ |
1889 | object * |
1894 | object * |
1890 | present_arch_in_ob (const archetype *at, const object *op) |
1895 | present_arch_in_ob (const archetype *at, const object *op) |
1891 | { |
1896 | { |
1892 | for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below) |
1897 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1893 | if (tmp->arch == at) |
1898 | if (tmp->arch->archname == at->archname) |
1894 | return tmp; |
1899 | return tmp; |
1895 | |
1900 | |
1896 | return NULL; |
1901 | return NULL; |
1897 | } |
1902 | } |
1898 | |
1903 | |
… | |
… | |
2307 | |
2312 | |
2308 | /* |
2313 | /* |
2309 | * create clone from object to another |
2314 | * create clone from object to another |
2310 | */ |
2315 | */ |
2311 | object * |
2316 | object * |
2312 | object_create_clone (object *asrc) |
2317 | object::deep_clone () |
2313 | { |
2318 | { |
|
|
2319 | assert (("deep_clone called on non-head object", is_head ())); |
|
|
2320 | |
2314 | object *dst = 0; |
2321 | object *dst = clone (); |
2315 | |
2322 | |
2316 | if (!asrc) |
|
|
2317 | return 0; |
|
|
2318 | |
|
|
2319 | object *src = asrc->head_ (); |
|
|
2320 | |
|
|
2321 | object *prev = 0; |
2323 | object *prev = dst; |
2322 | for (object *part = src; part; part = part->more) |
2324 | for (object *part = this->more; part; part = part->more) |
2323 | { |
2325 | { |
2324 | object *tmp = part->clone (); |
2326 | 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; |
2327 | tmp->head = dst; |
2336 | |
|
|
2337 | tmp->more = 0; |
|
|
2338 | |
|
|
2339 | if (prev) |
|
|
2340 | prev->more = tmp; |
2328 | prev->more = tmp; |
2341 | |
|
|
2342 | prev = tmp; |
2329 | prev = tmp; |
2343 | } |
2330 | } |
2344 | |
2331 | |
2345 | for (object *item = src->inv; item; item = item->below) |
2332 | for (object *item = inv; item; item = item->below) |
2346 | insert_ob_in_ob (object_create_clone (item), dst); |
2333 | insert_ob_in_ob (item->deep_clone (), dst); |
2347 | |
2334 | |
2348 | return dst; |
2335 | return dst; |
2349 | } |
2336 | } |
2350 | |
2337 | |
2351 | /* This returns the first object in who's inventory that |
2338 | /* This returns the first object in who's inventory that |