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

Function hatch_egg

src/timeout.c:1016–1189  ·  view source on GitHub ↗

timer callback routine: hatch the given egg */

Source from the content-addressed store, hash-verified

1014
1015/* timer callback routine: hatch the given egg */
1016void
1017hatch_egg(anything *arg, long timeout)
1018{
1019 struct obj *egg;
1020 struct monst *mon, *mon2;
1021 coord cc;
1022 coordxy x, y;
1023 boolean yours, silent, knows_egg = FALSE;
1024 boolean cansee_hatchspot = FALSE;
1025 int i, mnum, hatchcount = 0;
1026
1027 egg = arg->a_obj;
1028 /* sterilized while waiting */
1029 if (egg->corpsenm == NON_PM)
1030 return;
1031
1032 mon = mon2 = (struct monst *) 0;
1033 mnum = big_to_little(egg->corpsenm);
1034 /* The identity of one's father is learned, not innate */
1035 yours = (egg->spe || (!flags.female && carried(egg) && !rn2(2)));
1036 silent = (timeout != svm.moves); /* hatched while away */
1037
1038 /* only can hatch when in INVENT, FLOOR, MINVENT;
1039 get_obj_location() will fail for MIGRATING, also for CONTAINED
1040 and BURIED when the flags for those aren't included in the call */
1041 if (get_obj_location(egg, &x, &y, 0)) {
1042 hatchcount = rnd((int) egg->quan);
1043 cansee_hatchspot = cansee(x, y) && !silent;
1044 if (!(mons[mnum].geno & G_UNIQ)
1045 && !(svm.mvitals[mnum].mvflags & (G_GENOD | G_EXTINCT))) {
1046 for (i = hatchcount; i > 0; i--) {
1047 if (!enexto(&cc, x, y, &mons[mnum])
1048 || !(mon = makemon(&mons[mnum], cc.x, cc.y,
1049 NO_MINVENT | MM_NOMSG)))
1050 break;
1051 /* tame if your own egg hatches while you're on the
1052 same dungeon level, or any dragon egg which hatches
1053 while it's in your inventory */
1054 if ((yours && !silent)
1055 || (carried(egg) && mon->data->mlet == S_DRAGON)) {
1056 if (tamedog(mon, (struct obj *) 0, FALSE)) {
1057 if (carried(egg) && mon->data->mlet != S_DRAGON)
1058 mon->mtame = 20;
1059 }
1060 }
1061 if (svm.mvitals[mnum].mvflags & G_EXTINCT)
1062 break; /* just made last one */
1063 mon2 = mon; /* in case makemon() fails on 2nd egg */
1064 }
1065 if (!mon)
1066 mon = mon2;
1067 hatchcount -= i;
1068 egg->quan -= (long) hatchcount;
1069 }
1070#if 0
1071 /*
1072 * We could possibly hatch while migrating, but the code isn't
1073 * set up for it...

Callers

nothing calls this directly

Calls 15

big_to_littleFunction · 0.85
rn2Function · 0.85
get_obj_locationFunction · 0.85
rndFunction · 0.85
enextoFunction · 0.85
makemonFunction · 0.85
tamedogFunction · 0.85
makepluralFunction · 0.85
m_monnamFunction · 0.85
anFunction · 0.85
You_feelFunction · 0.85
locomotionFunction · 0.85

Tested by

no test coverage detected