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

Function split_mon

src/potion.c:2872–2915  ·  view source on GitHub ↗

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) */

Source from the content-addressed store, hash-verified

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) */
2872struct monst *
2873split_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. */
2918void

Callers 10

dositFunction · 0.85
potionhitFunction · 0.85
potionbreatheFunction · 0.85
passiveFunction · 0.85
passivemmFunction · 0.85
minliquid_coreFunction · 0.85
trapeffect_rust_trapFunction · 0.85
drownFunction · 0.85
passiveumFunction · 0.85
domonabilityFunction · 0.85

Calls 7

s_suffixFunction · 0.85
mon_namFunction · 0.85
cloneuFunction · 0.85
YouFunction · 0.85
clone_monFunction · 0.85
MonnamFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected