* Split stack so that its size gets reduced by num. The quantity num is * put in the object structure delivered by this call. The returned object * has its wornmask cleared and is positioned just following the original * in the nobj chain (and nexthere chain when on the floor). */
| 454 | * in the nobj chain (and nexthere chain when on the floor). |
| 455 | */ |
| 456 | struct obj * |
| 457 | splitobj(struct obj *obj, long num) |
| 458 | { |
| 459 | struct obj *otmp; |
| 460 | |
| 461 | /* can't split containers */ |
| 462 | if (obj->cobj || num <= 0L || obj->quan <= num) |
| 463 | panic("splitobj [cobj=%s num=%ld quan=%ld]", |
| 464 | obj->cobj ? "non-empty container" : "(null)", num, obj->quan); |
| 465 | |
| 466 | otmp = newobj(); |
| 467 | *otmp = *obj; /* copies whole structure */ |
| 468 | otmp->oextra = (struct oextra *) 0; |
| 469 | otmp->o_id = nextoid(obj, otmp); |
| 470 | otmp->timed = 0; /* not timed, yet */ |
| 471 | otmp->lamplit = 0; /* ditto */ |
| 472 | otmp->owornmask = 0L; /* new object isn't worn */ |
| 473 | obj->quan -= num; |
| 474 | obj->owt = weight(obj); |
| 475 | otmp->quan = num; |
| 476 | otmp->owt = weight(otmp); /* -= obj->owt ? */ |
| 477 | otmp->lua_ref_cnt = 0; |
| 478 | otmp->pickup_prev = 0; |
| 479 | |
| 480 | svc.context.objsplit.parent_oid = obj->o_id; |
| 481 | svc.context.objsplit.child_oid = otmp->o_id; |
| 482 | obj->nobj = otmp; |
| 483 | /* Only set nexthere when on the floor; nexthere is also used |
| 484 | as a back pointer to the container object when contained. |
| 485 | For either case, otmp's nexthere pointer is already pointing |
| 486 | at the right thing. */ |
| 487 | if (obj->where == OBJ_FLOOR) |
| 488 | obj->nexthere = otmp; /* insert into chain: obj -> otmp -> next */ |
| 489 | /* lua isn't tracking the split off portion even if it happens to |
| 490 | be tracking the original */ |
| 491 | if (otmp->where == OBJ_LUAFREE) |
| 492 | otmp->where = OBJ_FREE; |
| 493 | if (obj->unpaid) |
| 494 | splitbill(obj, otmp); |
| 495 | copy_oextra(otmp, obj); |
| 496 | if (has_omid(otmp)) |
| 497 | free_omid(otmp); /* only one association with m_id */ |
| 498 | if (obj->timed) |
| 499 | obj_split_timers(obj, otmp); |
| 500 | if (obj_sheds_light(obj)) |
| 501 | obj_split_light_source(obj, otmp); |
| 502 | return otmp; |
| 503 | } |
| 504 | |
| 505 | /* return the value of context.ident and then increment it to be ready for |
| 506 | its next use; used to be simple += 1 so that every value from 1 to N got |
no test coverage detected