clone a gremlin or mold (2nd arg non-null implies heat as the trigger); hit points are cut in half (odd HP stays with original) */
| 2870 | /* clone a gremlin or mold (2nd arg non-null implies heat as the trigger); |
| 2871 | hit points are cut in half (odd HP stays with original) */ |
| 2872 | struct monst * |
| 2873 | split_mon( |
| 2874 | struct monst *mon, /* monster being split */ |
| 2875 | struct monst *mtmp) /* optional attacker whose heat triggered it */ |
| 2876 | { |
| 2877 | struct monst *mtmp2; |
| 2878 | char reason[BUFSZ]; |
| 2879 | |
| 2880 | reason[0] = '\0'; |
| 2881 | if (mtmp) |
| 2882 | Sprintf(reason, " from %s heat", |
| 2883 | (mtmp == &gy.youmonst) ? the_your[1] |
| 2884 | : (const char *) s_suffix(mon_nam(mtmp))); |
| 2885 | |
| 2886 | if (mon == &gy.youmonst) { |
| 2887 | if (u.mh > u.mhmax) /* sanity precaution */ |
| 2888 | u.mh = u.mhmax; |
| 2889 | mtmp2 = (u.mh > 1) ? cloneu() : (struct monst *) 0; |
| 2890 | if (mtmp2) { |
| 2891 | /* mtmp2 has been created with mhpmax = u.mhmax, mhp = u.mh / 2, |
| 2892 | and u.mh -= mtmp2->mhp; these reductions for both max hp |
| 2893 | can't make either of them exceed corresponding current hp */ |
| 2894 | mtmp2->mhpmax = u.mhmax / 2; |
| 2895 | u.mhmax -= mtmp2->mhpmax; |
| 2896 | disp.botl = TRUE; |
| 2897 | You("multiply%s!", reason); |
| 2898 | } |
| 2899 | } else { |
| 2900 | if (mon->mhp > mon->mhpmax) /* sanity precaution */ |
| 2901 | mon->mhp = mon->mhpmax; |
| 2902 | mtmp2 = (mon->mhp > 1) ? clone_mon(mon, 0, 0) : (struct monst *) 0; |
| 2903 | if (mtmp2) { |
| 2904 | assert(mon->mhpmax >= mon->mhp); /* mon->mhpmax > 1 */ |
| 2905 | /* mtmp2 has been created with mhpmax = mon->mhpmax, |
| 2906 | mhp = mon->mhp / 2, and mon->mh -= mtmp2->mhp; |
| 2907 | dividing max by 2 can't result in it exceeding current */ |
| 2908 | mtmp2->mhpmax = mon->mhpmax / 2; |
| 2909 | mon->mhpmax -= mtmp2->mhpmax; |
| 2910 | if (canspotmon(mon)) |
| 2911 | pline("%s multiplies%s!", Monnam(mon), reason); |
| 2912 | } |
| 2913 | } |
| 2914 | return mtmp2; |
| 2915 | } |
| 2916 | |
| 2917 | /* Character becomes very fast temporarily. */ |
| 2918 | void |
no test coverage detected