* Start a timer. Return TRUE if successful. */
| 2244 | * Start a timer. Return TRUE if successful. |
| 2245 | */ |
| 2246 | boolean |
| 2247 | start_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 |
no test coverage detected