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

Function save_mtraits

src/mkobj.c:2156–2195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2154}
2155
2156staticfn struct obj *
2157save_mtraits(struct obj *obj, struct monst *mtmp)
2158{
2159 if (mtmp->ispriest)
2160 forget_temple_entry(mtmp); /* EPRI() */
2161 if (!has_omonst(obj))
2162 newomonst(obj);
2163 if (has_omonst(obj)) {
2164 int baselevel = mtmp->data->mlevel; /* mtmp->data is valid ptr */
2165 struct monst *mtmp2 = OMONST(obj);
2166
2167 *mtmp2 = *mtmp;
2168 mtmp2->mextra = (struct mextra *) 0;
2169 mtmp2->mnum = monsndx(mtmp->data);
2170 /* invalidate pointers */
2171 /* m_id is needed to know if this is a revived quest leader */
2172 /* but m_id must be cleared when loading bones */
2173 mtmp2->nmon = (struct monst *) 0;
2174 mtmp2->data = (struct permonst *) 0;
2175 mtmp2->minvent = (struct obj *) 0;
2176 MON_NOWEP(mtmp2); /* mtmp2->mw = (struct obj *) 0; */
2177 if (mtmp->mextra)
2178 copy_mextra(mtmp2, mtmp);
2179 /* if mtmp is a long worm with segments, its saved traits will
2180 be one without any segments */
2181 mtmp2->wormno = 0;
2182 /* mtmp might have been killed by repeated life draining; make sure
2183 mtmp2 can survive if revived ('baselevel' will be 0 for 1d4 mon) */
2184 if (mtmp2->mhpmax <= baselevel)
2185 mtmp2->mhpmax = baselevel + 1;
2186 /* mtmp is assumed to be dead but we don't kill it or its saved
2187 traits, just force those to have a sane value for current HP */
2188 if (mtmp2->mhp > mtmp2->mhpmax)
2189 mtmp2->mhp = mtmp2->mhpmax;
2190 if (mtmp2->mhp < 1)
2191 mtmp2->mhp = 0;
2192 mtmp2->mstate &= ~MON_DETACH;
2193 }
2194 return obj;
2195}
2196
2197/* returns a pointer to a new monst structure based on
2198 * the one contained within the obj.

Callers 1

mkcorpstatFunction · 0.85

Calls 3

forget_temple_entryFunction · 0.85
copy_mextraFunction · 0.85
newomonstFunction · 0.70

Tested by

no test coverage detected