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. */
| 978 | * existing hatch timer. Pass 0L for random hatch time. |
| 979 | */ |
| 980 | void |
| 981 | attach_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 */ |
| 1008 | void |
no test coverage detected