* Several areas of the code made direct reassignments * to obj->corpsenm. Because some special handling is * required in certain cases, place that handling here * and call this routine in place of the direct assignment. * * If the object was a lizard or lichen corpse: * - ensure that you don't end up with some * other corpse type which has no rot-away timer. * * If the object w
| 1315 | * |
| 1316 | */ |
| 1317 | void |
| 1318 | set_corpsenm(struct obj *obj, int id) |
| 1319 | { |
| 1320 | int old_id = obj->corpsenm; |
| 1321 | long when = 0L; |
| 1322 | |
| 1323 | if (obj->timed) { |
| 1324 | if (obj->otyp == EGG) { |
| 1325 | when = stop_timer(HATCH_EGG, obj_to_any(obj)); |
| 1326 | } else { |
| 1327 | when = 0L; |
| 1328 | obj_stop_timers(obj); /* corpse or figurine */ |
| 1329 | } |
| 1330 | } |
| 1331 | /* oeaten is used to determine how much nutrition is left in |
| 1332 | multiple-bite food and also used to derive how many hit points |
| 1333 | a creature resurrected from a partly eaten corpse gets; latter |
| 1334 | is of interest when a <foo> corpse revives as a <foo> zombie |
| 1335 | in case they are defined with different mons[].cnutrit values */ |
| 1336 | if (obj->otyp == CORPSE && obj->oeaten != 0 |
| 1337 | /* when oeaten is non-zero, index old_id can't be NON_PM |
| 1338 | and divisor mons[old_id].cnutrit can't be zero */ |
| 1339 | && mons[old_id].cnutrit != mons[id].cnutrit) { |
| 1340 | /* oeaten and cnutrit are unsigned; theoretically that could |
| 1341 | be 16 bits and the calculation might overflow, so force long */ |
| 1342 | obj->oeaten = (unsigned) ((long) obj->oeaten |
| 1343 | * (long) mons[id].cnutrit |
| 1344 | / (long) mons[old_id].cnutrit); |
| 1345 | } |
| 1346 | |
| 1347 | obj->corpsenm = id; |
| 1348 | switch (obj->otyp) { |
| 1349 | case CORPSE: |
| 1350 | start_corpse_timeout(obj); |
| 1351 | obj->owt = weight(obj); |
| 1352 | break; |
| 1353 | case FIGURINE: |
| 1354 | if (obj->corpsenm != NON_PM && !dead_species(obj->corpsenm, TRUE) |
| 1355 | && (carried(obj) || mcarried(obj))) |
| 1356 | attach_fig_transform_timeout(obj); |
| 1357 | obj->owt = weight(obj); |
| 1358 | break; |
| 1359 | case EGG: |
| 1360 | if (obj->corpsenm != NON_PM && !dead_species(obj->corpsenm, TRUE)) |
| 1361 | attach_egg_hatch_timeout(obj, when); |
| 1362 | break; |
| 1363 | default: /* tin, etc. */ |
| 1364 | obj->owt = weight(obj); |
| 1365 | break; |
| 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | /* Return the number of turns after which a Rider corpse revives */ |
| 1370 | long |
no test coverage detected