| 1053 | * Adjust hero attributes as necessary. |
| 1054 | */ |
| 1055 | staticfn struct obj * |
| 1056 | addinv_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); |
no test coverage detected