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

Function addinv_core0

src/invent.c:1055–1148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1053 * Adjust hero attributes as necessary.
1054 */
1055staticfn struct obj *
1056addinv_core0(
1057 struct obj *obj, struct obj *other_obj,
1058 boolean update_perm_invent)
1059{
1060 struct obj *otmp, *prev;
1061 int saved_otyp = (int) obj->otyp; /* for panic */
1062 boolean obj_was_thrown;
1063
1064 if (obj->where != OBJ_FREE)
1065 panic("addinv: obj not free");
1066 if (obj->how_lost == LOST_EXPLODING)
1067 return (struct obj *) NULL;
1068
1069 /* normally addtobill() clears no_charge when items in a shop are
1070 picked up, but won't do so if the shop has become untended */
1071 obj->no_charge = 0; /* should not be set in hero's invent */
1072 if (Has_contents(obj))
1073 picked_container(obj); /* clear no_charge */
1074 obj_was_thrown = (obj->how_lost == LOST_THROWN);
1075 obj->how_lost = LOST_NONE;
1076
1077 if (gl.loot_reset_justpicked) {
1078 gl.loot_reset_justpicked = FALSE;
1079 reset_justpicked(gi.invent);
1080 }
1081
1082 addinv_core1(obj); /* handle most side effects of carrying obj */
1083
1084 /* for addinv_before(); if something has been removed and is now being
1085 reinserted, try to put it in the same place instead of merging or
1086 placing at end; for thrown-and-return weapon with !fixinv setting */
1087 if (other_obj) {
1088 for (otmp = gi.invent; otmp; otmp = otmp->nobj) {
1089 if (otmp->nobj == other_obj) {
1090 obj->nobj = other_obj;
1091 otmp->nobj = obj;
1092 obj->where = OBJ_INVENT;
1093 goto added;
1094 }
1095 }
1096 }
1097
1098 /* merge with quiver in preference to any other inventory slot
1099 in case quiver and wielded weapon are both eligible; adding
1100 extra to quivered stack is more useful than to wielded one */
1101 if (uquiver && merged(&uquiver, &obj)) {
1102 obj = uquiver;
1103 if (!obj)
1104 panic("addinv: null obj after quiver merge otyp=%d", saved_otyp);
1105 goto added;
1106 }
1107 /* merge if possible; find end of chain in the process */
1108 for (prev = 0, otmp = gi.invent; otmp; prev = otmp, otmp = otmp->nobj)
1109 if (merged(&otmp, &obj)) {
1110 obj = otmp;
1111 if (!obj)
1112 panic("addinv: null obj after merge otyp=%d", saved_otyp);

Callers 3

addinvFunction · 0.85
addinv_beforeFunction · 0.85
hold_another_objectFunction · 0.85

Calls 12

picked_containerFunction · 0.85
reset_justpickedFunction · 0.85
addinv_core1Function · 0.85
mergedFunction · 0.85
assigninvletFunction · 0.85
reorder_inventFunction · 0.85
throwing_weaponFunction · 0.85
setuqwepFunction · 0.85
addinv_core2Function · 0.85
carry_obj_effectsFunction · 0.85
update_inventoryFunction · 0.85
panicFunction · 0.50

Tested by

no test coverage detected