]> granicus.if.org Git - nethack/commitdiff
Unify monster gender setting
authorPasi Kallinen <paxed@alt.org>
Wed, 22 Apr 2015 05:58:04 +0000 (08:58 +0300)
committerPasi Kallinen <paxed@alt.org>
Wed, 22 Apr 2015 05:58:04 +0000 (08:58 +0300)
include/extern.h
src/mon.c
src/sp_lev.c

index 05f7aa244f4c280fdb681bc439b45a098fb29802..f651976bbbc8564491016bc10fcb845fe5d803dc 100644 (file)
@@ -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));
index ead8f15443fda4046282e3da49a8e1ac5e5a82f9..3a2fc402b9e351ee62c2d16304127d17b47651a0 100644 (file)
--- 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
index 3acac5032814f1507d68b098fa31429ea1374bf4..b7faf4a68e1ae47b1fc5ab98a5e5f105e741da9b 100644 (file)
@@ -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,