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

Function mksobj

src/mkobj.c:1178–1259  ·  view source on GitHub ↗

mksobj(): create a specific type of object; result is always non-Null */

Source from the content-addressed store, hash-verified

1176
1177/* mksobj(): create a specific type of object; result is always non-Null */
1178struct obj *
1179mksobj(int otyp, boolean init, boolean artif)
1180{
1181 struct obj *otmp;
1182 char let = objects[otyp].oc_class;
1183
1184 otmp = newobj();
1185 *otmp = cg.zeroobj;
1186 otmp->age = max(svm.moves, 1L);
1187 otmp->o_id = next_ident();
1188 otmp->quan = 1L;
1189 otmp->oclass = let;
1190 otmp->otyp = otyp;
1191 otmp->where = OBJ_FREE;
1192 unknow_object(otmp); /* set up dknown and known: non-0 for some things */
1193 otmp->corpsenm = NON_PM;
1194 otmp->lua_ref_cnt = 0;
1195 otmp->pickup_prev = 0;
1196
1197 if (init)
1198 mksobj_init(&otmp, artif);
1199
1200 /* some things must get done (corpsenm, timers) even if init = 0 */
1201 switch ((otmp->oclass == POTION_CLASS && otmp->otyp != POT_OIL)
1202 ? POT_WATER
1203 : otmp->otyp) {
1204 case CORPSE:
1205 if (otmp->corpsenm == NON_PM) {
1206 otmp->corpsenm = undead_to_corpse(rndmonnum());
1207 if (svm.mvitals[otmp->corpsenm].mvflags & (G_NOCORPSE | G_GONE))
1208 otmp->corpsenm = gu.urole.mnum;
1209 }
1210 FALLTHROUGH;
1211 /*FALLTHRU*/
1212 case STATUE:
1213 case FIGURINE:
1214 if (otmp->corpsenm == NON_PM)
1215 otmp->corpsenm = rndmonnum();
1216 if (otmp->corpsenm != NON_PM) {
1217 struct permonst *ptr = &mons[otmp->corpsenm];
1218
1219 otmp->spe = (is_neuter(ptr) ? CORPSTAT_NEUTER
1220 : is_female(ptr) ? CORPSTAT_FEMALE
1221 : is_male(ptr) ? CORPSTAT_MALE
1222 : rn2(2) ? CORPSTAT_FEMALE : CORPSTAT_MALE);
1223 }
1224 FALLTHROUGH;
1225 /*FALLTHRU*/
1226 case EGG:
1227 /* case TIN: */
1228 set_corpsenm(otmp, otmp->corpsenm);
1229 break;
1230 case BOULDER:
1231 /* next_boulder overloads corpsenm so the default value is NON_PM;
1232 since that is non-zero, the "next boulder" case in xname() would
1233 happen when it shouldn't; explicitly set it to 0 */
1234 otmp->next_boulder = 0;
1235 break;

Callers 15

fill_zooFunction · 0.85
fuzzer_savelifeFunction · 0.85
really_doneFunction · 0.85
mk_mplayer_armorFunction · 0.85
mk_mplayerFunction · 0.85
lay_an_eggFunction · 0.85
impact_arti_lightFunction · 0.85
l_obj_new_readobjnamFunction · 0.85
mhitm_ad_dgstFunction · 0.85
put_saddle_on_monFunction · 0.85
level_teleFunction · 0.85
readobjnam_postparse1Function · 0.85

Calls 11

next_identFunction · 0.85
unknow_objectFunction · 0.85
mksobj_initFunction · 0.85
undead_to_corpseFunction · 0.85
rndmonnumFunction · 0.85
rn2Function · 0.85
set_corpsenmFunction · 0.85
onameFunction · 0.85
noveltitleFunction · 0.85
mk_artifactFunction · 0.85
weightFunction · 0.85

Tested by

no test coverage detected