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

Function attach_egg_hatch_timeout

src/timeout.c:980–1005  ·  view source on GitHub ↗

Attach an egg hatch timeout to the given egg. * when = Time to hatch, usually only passed if re-creating an * existing hatch timer. Pass 0L for random hatch time. */

Source from the content-addressed store, hash-verified

978 * existing hatch timer. Pass 0L for random hatch time.
979 */
980void
981attach_egg_hatch_timeout(struct obj *egg, long when)
982{
983 int i;
984
985 /* stop previous timer, if any */
986 (void) stop_timer(HATCH_EGG, obj_to_any(egg));
987
988 /*
989 * Decide if and when to hatch the egg. The old hatch_it() code tried
990 * once a turn from age 151 to 200 (inclusive), hatching if it rolled
991 * a number x, 1<=x<=age, where x>150. This yields a chance of
992 * hatching > 99.9993%. Mimic that here.
993 */
994 if (!when) {
995 for (i = (MAX_EGG_HATCH_TIME - 50) + 1; i <= MAX_EGG_HATCH_TIME; i++)
996 if (rnd(i) > 150) {
997 /* egg will hatch */
998 when = (long) i;
999 break;
1000 }
1001 }
1002 if (when) {
1003 (void) start_timer(when, TIMER_OBJECT, HATCH_EGG, obj_to_any(egg));
1004 }
1005}
1006
1007/* prevent an egg from ever hatching */
1008void

Callers 4

hatch_eggFunction · 0.85
set_corpsenmFunction · 0.85
revive_eggFunction · 0.85
use_royal_jellyFunction · 0.85

Calls 4

stop_timerFunction · 0.85
obj_to_anyFunction · 0.85
rndFunction · 0.85
start_timerFunction · 0.85

Tested by

no test coverage detected