Lua: object timers

Expose object timers to lua scripts. For example:

   local o = obj.new("cockatrice egg");
   o:placeobj(5, 5);
   o:start_timer("hatch-egg", 3);

Available methods are:

- obj.has_timer("rot-corpse")
    returns true if object has attached timer, false otherwise.

- obj.peek_timer("hatch-egg")
    returns an integer value, which is the turn when the timer
    attached to the object would trigger. returns 0 if no such timer.

- obj.stop_timer("shrink-glob")
    stops attached timer, or if no timer type is given, stops all
    timers attached to the object.

- obj.start_timer("zombify-mon", 15)
    starts a timer with a trigger time in that many turns in the future.
    replaces any previous timer of the same type.

Valid timers are "rot-organic", "rot-corpse", "revive-mon",
"zombify-mon", "burn-obj", "hatch-egg", "fig-transform",
and "shrink-glob". Also "melt-ice" is recognized, but does nothing
to objects.
This commit is contained in:
Pasi Kallinen
2022-03-13 14:29:32 +02:00
parent 9e6bddac10
commit 20f214592a
4 changed files with 134 additions and 0 deletions

View File

@@ -39,6 +39,15 @@ enum timeout_types {
NUM_TIME_FUNCS
};
#define timer_is_obj(ttype) ((ttype) == ROT_ORGANIC \
|| (ttype) == ROT_CORPSE \
|| (ttype) == REVIVE_MON \
|| (ttype) == ZOMBIFY_MON \
|| (ttype) == BURN_OBJECT \
|| (ttype) == HATCH_EGG \
|| (ttype) == FIG_TRANSFORM \
|| (ttype) == SHRINK_GLOB)
/* used in timeout.c */
typedef struct fe {
struct fe *next; /* next item in chain */