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

Function start_timer

src/timeout.c:2246–2292  ·  view source on GitHub ↗

* Start a timer. Return TRUE if successful. */

Source from the content-addressed store, hash-verified

2244 * Start a timer. Return TRUE if successful.
2245 */
2246boolean
2247start_timer(
2248 long when,
2249 short kind,
2250 short func_index,
2251 anything *arg)
2252{
2253 timer_element *gnu, *dup;
2254
2255 if (kind <= TIMER_NONE || kind >= NUM_TIMER_KINDS
2256 || func_index < 0 || func_index >= NUM_TIME_FUNCS)
2257 panic("start_timer (%s: %d)", kind_name(kind), (int) func_index);
2258
2259 /* fail if <arg> already has a <func_index> timer running */
2260 for (dup = gt.timer_base; dup; dup = dup->next)
2261 if (dup->kind == kind
2262 && dup->func_index == func_index
2263 && dup->arg.a_void == arg->a_void)
2264 break;
2265 if (dup) {
2266 char idbuf[QBUFSZ];
2267
2268#ifdef VERBOSE_TIMER
2269 Sprintf(idbuf, "%s timer", timeout_funcs[func_index].name);
2270#else
2271 Sprintf(idbuf, "%s timer (%d)", kind_name(kind), (int) func_index);
2272#endif
2273 impossible("Attempted to start duplicate %s, aborted.", idbuf);
2274 return FALSE;
2275 }
2276
2277 gnu = (timer_element *) alloc(sizeof *gnu);
2278 (void) memset((genericptr_t) gnu, 0, sizeof *gnu);
2279 gnu->next = 0;
2280 gnu->tid = svt.timer_id++;
2281 gnu->timeout = svm.moves + when;
2282 gnu->kind = kind;
2283 gnu->needs_fixup = 0;
2284 gnu->func_index = func_index;
2285 gnu->arg = *arg;
2286 insert_timer(gnu);
2287
2288 if (kind == TIMER_OBJECT) /* increment object's timed count */
2289 (arg->a_obj)->timed++;
2290
2291 return TRUE;
2292}
2293
2294/*
2295 * Remove the timer from the current list and free it up. Return the time

Callers 15

l_obj_timer_startFunction · 0.85
revive_monFunction · 0.85
readobjnamFunction · 0.85
nhl_timer_start_atFunction · 0.85
disturb_buried_zombiesFunction · 0.85
attach_egg_hatch_timeoutFunction · 0.85
begin_burnFunction · 0.85
obj_split_timersFunction · 0.85
bury_an_objFunction · 0.85
start_corpse_timeoutFunction · 0.85
start_glob_timeoutFunction · 0.85

Calls 5

kind_nameFunction · 0.85
insert_timerFunction · 0.85
impossibleFunction · 0.70
allocFunction · 0.70
panicFunction · 0.50

Tested by

no test coverage detected