/* * Calculate the weight of the given object. This will recursively follow * and calculate the weight of any containers. * * Note: It is possible to end up with an incorrect weight if some part * of the code messes with a contained object and doesn't update the * container's weight. */ int weight(struct obj *obj) { int wt = objects[obj->otyp].oc_weight; if (obj->otyp == LARGE_BOX && obj->spe == 1) /* Schroedinger's Cat */ wt += mons[PM_HOUSECAT].cwt; if (Is_container(obj) || obj->otyp == STATUE) { struct obj *contents; int cwt = 0; if (obj->otyp == STATUE && obj->corpsenm >= LOW_PM) wt = (int)obj->quan * ((int)mons[obj->corpsenm].cwt * 3 / 2); for (contents=obj->cobj; contents; contents=contents->nobj) cwt += weight(contents); /* * The weight of bags of holding is calculated as the weight * of the bag plus the weight of the bag's contents modified * as follows: * * Bag status Weight of contents * ---------- ------------------ * cursed 2x * blessed x/4 + 1 * otherwise x/2 + 1 * * The macro DELTA_CWT in pickup.c also implements these * weight equations. * * Note: The above checks are performed in the given order. * this means that if an object is both blessed and * cursed (not supposed to happen), it will be treated * as cursed. */ if (obj->otyp == BAG_OF_HOLDING) cwt = obj->cursed ? (cwt * 2) : (1 + (cwt / (obj->blessed ? 4 : 2))); return wt + cwt; } if (obj->otyp == CORPSE && obj->corpsenm >= LOW_PM) { long long_wt = obj->quan * (long) mons[obj->corpsenm].cwt; wt = (long_wt > LARGEST_INT) ? LARGEST_INT : (int)long_wt; if (obj->oeaten) wt = eaten_stat(wt, obj); return wt; } else if (obj->oclass == FOOD_CLASS && obj->oeaten) { return eaten_stat((int)obj->quan * wt, obj); } else if (obj->oclass == COIN_CLASS) return (int)((obj->quan + 50L) / 100L); else if (obj->otyp == HEAVY_IRON_BALL && obj->owt != 0) return (int)(obj->owt); /* kludge for "very" heavy iron ball */ return wt ? wt*(int)obj->quan : ((int)obj->quan + 1)>>1; }
static int dog_nutrition_value(struct monst *mtmp, struct obj *obj, boolean set_meating) { int nutrit; /* * It is arbitrary that the pet takes the same length of time to eat * as a human, but gets more nutritional value. */ if (obj->oclass == FOOD_CLASS) { if (obj->otyp == CORPSE) { if (set_meating) mtmp->meating = 3 + (mons[obj->corpsenm].cwt >> 6); nutrit = mons[obj->corpsenm].cnutrit; } else { if (set_meating) mtmp->meating = objects[obj->otyp].oc_delay; nutrit = objects[obj->otyp].oc_nutrition; } switch (mtmp->data->msize) { case MZ_TINY: nutrit *= 8; break; case MZ_SMALL: nutrit *= 6; break; default: case MZ_MEDIUM: nutrit *= 5; break; case MZ_LARGE: nutrit *= 4; break; case MZ_HUGE: nutrit *= 3; break; case MZ_GIGANTIC: nutrit *= 2; break; } if (obj->oeaten) { mtmp->meating = eaten_stat(mtmp->meating, obj); nutrit = eaten_stat(nutrit, obj); } } else if (obj->oclass == COIN_CLASS) {