From 171e8284cd8bf18a5ebaf6f2565732bc2af3359e Mon Sep 17 00:00:00 2001 From: Pasi Kallinen Date: Wed, 22 Apr 2015 08:58:04 +0300 Subject: [PATCH] Unify monster gender setting --- include/extern.h | 1 + src/mon.c | 22 +++++++++++++++------- src/sp_lev.c | 10 ++-------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/include/extern.h b/include/extern.h index 05f7aa244..f651976bb 100644 --- a/include/extern.h +++ b/include/extern.h @@ -1308,6 +1308,7 @@ E boolean FDECL(hideunder, (struct monst*)); E void FDECL(hide_monst, (struct monst *)); E void FDECL(mon_animal_list, (BOOLEAN_P)); E int FDECL(select_newcham_form, (struct monst *)); +E void FDECL(mgender_from_permonts, (struct monst *, struct permonst *)); E int FDECL(newcham, (struct monst *,struct permonst *,BOOLEAN_P,BOOLEAN_P)); E int FDECL(can_be_hatched, (int)); E int FDECL(egg_type_from_parent, (int,BOOLEAN_P)); diff --git a/src/mon.c b/src/mon.c index ead8f1544..3a2fc402b 100644 --- a/src/mon.c +++ b/src/mon.c @@ -2745,6 +2745,20 @@ int mndx; return polyok(mdat) ? mdat : 0; } +void +mgender_from_permonst(mtmp, mdat) +struct monst *mtmp; +struct permonst *mdat; +{ + if(is_male(mdat)) { + if(mtmp->female) mtmp->female = FALSE; + } else if (is_female(mdat)) { + if(!mtmp->female) mtmp->female = TRUE; + } else if (!is_neuter(mdat)) { + if(!rn2(10)) mtmp->female = !mtmp->female; + } +} + /* make a chameleon take on another shape, or a polymorph target (possibly self-infliced) become a different monster; returns 1 if it actually changes form */ @@ -2784,13 +2798,7 @@ boolean msg; /* "The oldmon turns into a newmon!" */ } else if (mvitals[monsndx(mdat)].mvflags & G_GENOD) return(0); /* passed in mdat is genocided */ - if(is_male(mdat)) { - if(mtmp->female) mtmp->female = FALSE; - } else if (is_female(mdat)) { - if(!mtmp->female) mtmp->female = TRUE; - } else if (!is_neuter(mdat)) { - if(!rn2(10)) mtmp->female = !mtmp->female; - } + mgender_from_permonst(mtmp, mdat); if (In_endgame(&u.uz) && is_mplayer(olddata) && has_mname(mtmp)) { /* mplayers start out as "Foo the Bar", but some of the diff --git a/src/sp_lev.c b/src/sp_lev.c index 3acac5032..b7faf4a68 100644 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -1499,14 +1499,8 @@ struct mkroom *croom; if ((mndx != NON_PM) && (&mons[mndx] != mtmp->data)) { struct permonst *mdat = &mons[mndx]; struct permonst *olddata = mtmp->data; - /* this code duplicated from newcham() */ - if(is_male(mdat)) { - if(mtmp->female) mtmp->female = FALSE; - } else if (is_female(mdat)) { - if(!mtmp->female) mtmp->female = TRUE; - } else if (!is_neuter(mdat)) { - if(!rn2(10)) mtmp->female = !mtmp->female; - } + + mgender_from_permonst(mtmp, mdat); set_mon_data(mtmp, mdat, 0); if (emits_light(olddata) != emits_light(mtmp->data)) { /* used to give light, now doesn't, or vice versa,