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

Function merged

src/invent.c:813–948  ·  view source on GitHub ↗

merge obj with otmp and delete obj if types agree */

Source from the content-addressed store, hash-verified

811
812/* merge obj with otmp and delete obj if types agree */
813int
814merged(struct obj **potmp, struct obj **pobj)
815{
816 struct obj *otmp = *potmp, *obj = *pobj;
817 boolean discovered = FALSE;
818
819 if (mergable(otmp, obj)) {
820 /* Approximate age: we do it this way because if we were to
821 * do it "accurately" (merge only when ages are identical)
822 * we'd wind up never merging any corpses.
823 * otmp->age = otmp->age*(1-proportion) + obj->age*proportion;
824 *
825 * Don't do the age manipulation if lit. We would need
826 * to stop the burn on both items, then merge the age,
827 * then restart the burn. Glob ages are averaged in the
828 * absorb routine, which uses weight rather than quantity
829 * to adjust for proportion (glob quantity is always 1).
830 */
831 if (!obj->lamplit && !obj->globby)
832 otmp->age = ((otmp->age * otmp->quan) + (obj->age * obj->quan))
833 / (otmp->quan + obj->quan);
834
835 if (!otmp->globby)
836 otmp->quan += obj->quan;
837 /* temporary special case for gold objects!!!! */
838 if (otmp->oclass == COIN_CLASS)
839 otmp->owt = weight(otmp), otmp->bknown = 0;
840 /* and puddings!!!1!!one! */
841 else if (!Is_pudding(otmp))
842 otmp->owt = weight(otmp);
843 if (!has_oname(otmp) && has_oname(obj))
844 otmp = *potmp = oname(otmp, ONAME(obj), ONAME_SKIP_INVUPD);
845 obj_extract_self(obj);
846
847 if (obj->pickup_prev && otmp->where == OBJ_INVENT)
848 otmp->pickup_prev = 1;
849
850 /* really should merge the timeouts */
851 if (obj->lamplit)
852 obj_merge_light_sources(obj, otmp);
853 if (obj->timed)
854 obj_stop_timers(obj); /* follows lights */
855
856 /* objects can be identified by comparing them (unless Blind,
857 but that is handled in mergable()); the object becomes
858 identified in a particular dimension if either object was
859 previously identified in that dimension, and if the
860 identification states don't match, one of them must have
861 previously been identified */
862 if (obj->known != otmp->known) {
863 otmp->known = 1;
864 discovered = TRUE;
865 }
866 if (obj->rknown != otmp->rknown) {
867 otmp->rknown = 1;
868 if (otmp->oerodeproof)
869 discovered = TRUE;
870 }

Callers 7

addinv_core0Function · 0.85
stackobjFunction · 0.85
doorganize_coreFunction · 0.85
unsplitobjFunction · 0.85
add_to_minvFunction · 0.85
add_to_containerFunction · 0.85
zapyourselfFunction · 0.85

Calls 13

mergableFunction · 0.85
weightFunction · 0.85
onameFunction · 0.85
obj_extract_selfFunction · 0.85
obj_merge_light_sourcesFunction · 0.85
obj_stop_timersFunction · 0.85
setnotwornFunction · 0.85
setwornFunction · 0.85
pudding_merge_messageFunction · 0.85
obj_absorbFunction · 0.85
obfreeFunction · 0.85
impossibleFunction · 0.70

Tested by

no test coverage detected