]> granicus.if.org Git - nethack/commitdiff
couple of new routines (trunk only)
authornethack.rankin <nethack.rankin>
Thu, 20 Nov 2003 04:40:46 +0000 (04:40 +0000)
committernethack.rankin <nethack.rankin>
Thu, 20 Nov 2003 04:40:46 +0000 (04:40 +0000)
     Groundwork for forthcoming stethoscope fix:  add an object list
traveral routine (there must be something like this already, but I
couldn't find it...) and a couple of timer access routines.

include/extern.h
src/invent.c
src/timeout.c

index 720a83d74a1fb05ece7c554f893951c50354fa97..05f459f2a557ed79f82a1f036006bb230fb494fb 100644 (file)
@@ -787,6 +787,7 @@ E void FDECL(freeinv, (struct obj *));
 E void FDECL(delallobj, (int,int));
 E void FDECL(delobj, (struct obj *));
 E struct obj *FDECL(sobj_at, (int,int,int));
+E struct obj *FDECL(nxtobj, (struct obj *,int,BOOLEAN_P));
 E struct obj *FDECL(carrying, (int));
 E boolean NDECL(have_lizard);
 E struct obj *FDECL(o_on, (unsigned int,struct obj *));
@@ -2004,10 +2005,12 @@ E void FDECL(end_burn, (struct obj *, BOOLEAN_P));
 E void NDECL(do_storms);
 E boolean FDECL(start_timer, (long, SHORT_P, SHORT_P, genericptr_t));
 E long FDECL(stop_timer, (SHORT_P, genericptr_t));
+E long FDECL(peek_timer, (SHORT_P,genericptr_t));
 E void NDECL(run_timers);
 E void FDECL(obj_move_timers, (struct obj *, struct obj *));
 E void FDECL(obj_split_timers, (struct obj *, struct obj *));
 E void FDECL(obj_stop_timers, (struct obj *));
+E boolean FDECL(obj_has_timer, (struct obj *,SHORT_P));
 E void FDECL(spot_stop_timers, (XCHAR_P,XCHAR_P,SHORT_P));
 E long FDECL(spot_time_expires, (XCHAR_P,XCHAR_P,SHORT_P));
 E long FDECL(spot_time_left, (XCHAR_P,XCHAR_P,SHORT_P));
index 07822ba6f92d7485dea0fd49d9a0ae23ba3bb0d2..ceb632f3e577fd66cd35d8a5f4a8b15e598be6ba 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)invent.c   3.4     2003/05/25      */
+/*     SCCS Id: @(#)invent.c   3.4     2003/11/18      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -563,16 +563,36 @@ register struct obj *obj;
        obfree(obj, (struct obj *) 0);  /* frees contents also */
 }
 
+/* try to find a particular type of object at designated map location */
 struct obj *
-sobj_at(n,x,y)
-register int n, x, y;
+sobj_at(otyp, x, y)
+int otyp;
+int x, y;
 {
        register struct obj *otmp;
 
-       for(otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere)
-               if(otmp->otyp == n)
-                   return(otmp);
-       return((struct obj *)0);
+       for (otmp = level.objects[x][y]; otmp; otmp = otmp->nexthere)
+           if (otmp->otyp == otyp) break;
+
+       return otmp;
+}
+
+/* sobj_at(&c) traversal -- find next object of specified type */
+struct obj *
+nxtobj(obj, type, by_nexthere)
+struct obj *obj;
+int type;
+boolean by_nexthere;
+{
+       register struct obj *otmp;
+
+       otmp = obj;     /* start with the object after this one */
+       do {
+           otmp = !by_nexthere ? otmp->nobj : otmp->nexthere;
+           if (!otmp) break;
+       } while (otmp->otyp != type);
+
+       return otmp;
 }
 
 struct obj *
index 93c15737723e0ff845e66f8eb146ad2f484d5045..78d2e1ca2ed20d389be70ffaf9dbf274e0343b3b 100644 (file)
@@ -1,4 +1,4 @@
-/*     SCCS Id: @(#)timeout.c  3.4     2002/12/17      */
+/*     SCCS Id: @(#)timeout.c  3.4     2003/11/18      */
 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -1242,6 +1242,9 @@ do_storms()
  *             timer would have gone off.  If no timer is found, return 0.
  *             If an object, decrement the object's timer count.
  *
+ *     long peek_timer(short func_index, genericptr_t arg)
+ *             Return time specified timer will go off (0 if no such timer).
+ *
  *     void run_timers(void)
  *             Call timers that have timed out.
  *
@@ -1271,6 +1274,9 @@ do_storms()
  *
  *     void obj_stop_timers(struct obj *obj)
  *             Stop all timers attached to obj.
+ *
+ *     boolean obj_has_timer(struct obj *object, short timer_type)
+ *             Check whether object has a timer of type timer_type.
  */
 
 #ifdef WIZARD
@@ -1482,7 +1488,24 @@ genericptr_t arg;
        free((genericptr_t) doomed);
        return timeout;
     }
-    return 0;
+    return 0L;
+}
+
+/*
+ * Find the timeout of specified timer; return 0 if none.
+ */
+long
+peek_timer(type, arg)
+    short type;
+    genericptr_t arg;
+{
+    timer_element *curr;
+
+    for (curr = timer_base; curr; curr = curr->next) {
+       if (curr->func_index == type && curr->arg == arg)
+           return curr->timeout;
+    }
+    return 0L;
 }
 
 
@@ -1555,6 +1578,20 @@ obj_stop_timers(obj)
     obj->timed = 0;
 }
 
+/*
+ * Check whether object has a timer of type timer_type.
+ */
+boolean
+obj_has_timer(object, timer_type)
+    struct obj *object;
+    short timer_type;
+{
+    long timeout = peek_timer(timer_type, (genericptr_t)object);
+
+    return (boolean)(timeout != 0L);
+}
+
+
 /*
  * Stop all timers of index func_index at this spot.
  *