MCPcopy Create free account
hub / github.com/NetHack/NetHack / splitobj

Function splitobj

src/mkobj.c:456–503  ·  view source on GitHub ↗

* 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). */

Source from the content-addressed store, hash-verified

454 * in the nobj chain (and nexthere chain when on the floor).
455 */
456struct obj *
457splitobj(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

Callers 15

dowieldFunction · 0.85
doquiver_coreFunction · 0.85
stealgoldFunction · 0.85
dodrinkFunction · 0.85
potion_dipFunction · 0.85
hmon_hitmon_potionFunction · 0.85
menudrop_splitFunction · 0.85
domove_fight_ironbarsFunction · 0.85
engraveFunction · 0.85
throw_objFunction · 0.85
hold_another_objectFunction · 0.85
getobjFunction · 0.85

Calls 9

nextoidFunction · 0.85
weightFunction · 0.85
splitbillFunction · 0.85
copy_oextraFunction · 0.85
obj_split_timersFunction · 0.85
obj_sheds_lightFunction · 0.85
obj_split_light_sourceFunction · 0.85
free_omidFunction · 0.70
panicFunction · 0.50

Tested by

no test coverage detected