MCPcopy Index your code
hub / github.com/NetHack/NetHack / obj_absorb

Function obj_absorb

src/mkobj.c:3701–3754  ·  view source on GitHub ↗

* Causes one object to absorb another, increasing weight * accordingly. Frees obj2; obj1 remains and is returned. */

Source from the content-addressed store, hash-verified

3699 * accordingly. Frees obj2; obj1 remains and is returned.
3700 */
3701struct obj *
3702obj_absorb(struct obj **obj1, struct obj **obj2)
3703{
3704 struct obj *otmp1, *otmp2;
3705 int o1wt, o2wt;
3706 long agetmp;
3707
3708 /* don't let people dumb it up */
3709 if (obj1 && obj2) {
3710 otmp1 = *obj1;
3711 otmp2 = *obj2;
3712 if (otmp1 && otmp2 && otmp1 != otmp2) {
3713 globby_bill_fixup(otmp1, otmp2);
3714 if (otmp1->bknown != otmp2->bknown)
3715 otmp1->bknown = otmp2->bknown = 0;
3716 if (otmp1->rknown != otmp2->rknown)
3717 otmp1->rknown = otmp2->rknown = 0;
3718 if (otmp1->greased != otmp2->greased)
3719 otmp1->greased = otmp2->greased = 0;
3720 if (otmp1->orotten || otmp2->orotten)
3721 otmp1->orotten = otmp2->orotten = 1;
3722 o1wt = otmp1->oeaten ? otmp1->oeaten : otmp1->owt;
3723 o2wt = otmp2->oeaten ? otmp2->oeaten : otmp2->owt;
3724 /* averaging the relative ages is less likely to overflow
3725 than averaging the absolute ages directly */
3726 agetmp = (((svm.moves - otmp1->age) * o1wt
3727 + (svm.moves - otmp2->age) * o2wt)
3728 / (o1wt + o2wt));
3729 /* convert relative age back to absolute age */
3730 otmp1->age = svm.moves - agetmp;
3731 otmp1->owt += o2wt;
3732 if (otmp1->oeaten || otmp2->oeaten)
3733 otmp1->oeaten = o1wt + o2wt;
3734 otmp1->quan = 1L;
3735 if (otmp1->globby && otmp2->globby) {
3736 /* average (not weighted, no pun intended) the two globs'
3737 shrink timers and use that to give otmp1 a new timer */
3738 long tm1 = stop_timer(SHRINK_GLOB, obj_to_any(otmp1)),
3739 tm2 = stop_timer(SHRINK_GLOB, obj_to_any(otmp2));
3740
3741 tm1 = ((tm1 ? tm1 : 25L) + (tm2 ? tm2 : 25L) + 1L) / 2L;
3742 start_glob_timeout(otmp1, tm1);
3743 }
3744 /* get rid of second glob, return augmented first one */
3745 obj_extract_self(otmp2);
3746 dealloc_obj(otmp2);
3747 *obj2 = (struct obj *) 0;
3748 return otmp1;
3749 }
3750 }
3751
3752 impossible("obj_absorb: not called with two actual objects");
3753 return (struct obj *) 0;
3754}
3755
3756/*
3757 * Causes the heavier object to absorb the lighter object in

Callers 2

mergedFunction · 0.85
obj_meldFunction · 0.85

Calls 7

globby_bill_fixupFunction · 0.85
stop_timerFunction · 0.85
obj_to_anyFunction · 0.85
start_glob_timeoutFunction · 0.85
obj_extract_selfFunction · 0.85
dealloc_objFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected