mksobj(): create a specific type of object; result is always non-Null */
| 1176 | |
| 1177 | /* mksobj(): create a specific type of object; result is always non-Null */ |
| 1178 | struct obj * |
| 1179 | mksobj(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; |
no test coverage detected