diff options
author | Bardur Arantsson <bardur@scientician.net> | 2012-05-09 22:35:12 +0200 |
---|---|---|
committer | Bardur Arantsson <bardur@scientician.net> | 2012-05-09 22:42:46 +0200 |
commit | a5b78e910344f4277c110941145e9412a03039ef (patch) | |
tree | 30fb069716346dc67e37a40775d06bec7e755f75 | |
parent | 6ef98743b002c48fb3bf720fb07936e34926b313 (diff) |
Lua: Move Theme's "aggravate_evil" timer to C
-rw-r--r-- | lib/core/util.lua | 22 | ||||
-rw-r--r-- | lib/mods/theme/core/util.lua | 22 | ||||
-rw-r--r-- | lib/mods/theme/scpt/monsters.lua | 11 | ||||
-rw-r--r-- | src/externs.h | 6 | ||||
-rw-r--r-- | src/init2.c | 3 | ||||
-rw-r--r-- | src/lua_bind.c | 14 | ||||
-rw-r--r-- | src/util.c | 7 | ||||
-rw-r--r-- | src/util.pkg | 26 |
8 files changed, 28 insertions, 83 deletions
diff --git a/lib/core/util.lua b/lib/core/util.lua index 048b0d0f..7729ac35 100644 --- a/lib/core/util.lua +++ b/lib/core/util.lua @@ -71,28 +71,6 @@ function msg_print(c, m) end end --- better timer add function -__timers_callback_max = 0 - -function new_timer(t) - assert(t.delay > 0, "no timer delay") - assert(t.enabled, "no timer enabled state") - assert(t.callback, "no timer callback") - - local timer - if type(t.callback) == "function" then - setglobal("__timers_callback_"..__timers_callback_max, t.callback) - timer = %new_timer("__timers_callback_"..__timers_callback_max, t.delay) - __timers_callback_max = __timers_callback_max + 1 - else - timer = %new_timer(t.callback, t.delay) - end - - timer.enabled = t.enabled - - return timer -end - -- displays a scrolling list function display_list(y, x, h, w, title, list, begin, sel, sel_color) diff --git a/lib/mods/theme/core/util.lua b/lib/mods/theme/core/util.lua index 048b0d0f..7729ac35 100644 --- a/lib/mods/theme/core/util.lua +++ b/lib/mods/theme/core/util.lua @@ -71,28 +71,6 @@ function msg_print(c, m) end end --- better timer add function -__timers_callback_max = 0 - -function new_timer(t) - assert(t.delay > 0, "no timer delay") - assert(t.enabled, "no timer enabled state") - assert(t.callback, "no timer callback") - - local timer - if type(t.callback) == "function" then - setglobal("__timers_callback_"..__timers_callback_max, t.callback) - timer = %new_timer("__timers_callback_"..__timers_callback_max, t.delay) - __timers_callback_max = __timers_callback_max + 1 - else - timer = %new_timer(t.callback, t.delay) - end - - timer.enabled = t.enabled - - return timer -end - -- displays a scrolling list function display_list(y, x, h, w, title, list, begin, sel, sel_color) diff --git a/lib/mods/theme/scpt/monsters.lua b/lib/mods/theme/scpt/monsters.lua index cbadf1d6..6c0cc197 100644 --- a/lib/mods/theme/scpt/monsters.lua +++ b/lib/mods/theme/scpt/monsters.lua @@ -62,15 +62,6 @@ end -- cast dispel evil with 0 damage every 10 turns -TIMER_AGGRAVATE_EVIL = new_timer -{ - ["enabled"] = FALSE, - ["delay"] = 10, - ["callback"] = function() - dispel_evil(0) - end, -} - add_hooks{ [HOOK_GAME_START] = function() @@ -80,7 +71,7 @@ add_hooks{ (player_has_corruption(CORRUPT_BALROG_STRENGTH) ~= TRUE) and (player_has_corruption(CORRUPT_BALROG_FORM) ~= TRUE)) then -- "Proper" Maiar aggravate evil beings - TIMER_AGGRAVATE_EVIL.enabled = TRUE + timer_aggravate_evil_enable() -- Good beings (except swans, GWoPs, Wyrm Spirits, and some joke uniques) are coaligned with Maiar monst_al_add(MSTATUS_FRIEND, {25, 29, 45, 97, 109, 147, 225, 335, 346, 443, 581, 629, 699, 853, 984, 1007, 1017}, {21}) diff --git a/src/externs.h b/src/externs.h index e89341a4..e281437e 100644 --- a/src/externs.h +++ b/src/externs.h @@ -1737,7 +1737,6 @@ extern int test_monster_name(cptr name); extern int test_mego_name(cptr name); extern int test_item_name(cptr name); extern char msg_box(cptr text, int y, int x); -extern timer_type *new_timer(cptr callback, s32b delay); extern timer_type *new_timer_c(void (*callback)(), s32b delay); extern void del_timer(timer_type *t_ptr); extern int get_keymap_mode(); @@ -2061,6 +2060,11 @@ extern void lua_display_list(int y, int x, int h, int w, cptr title, list_type * extern void increase_mana(int delta); +extern timer_type *TIMER_AGGRAVATE_EVIL; + +void timer_aggravate_evil_enable(); +void timer_aggravate_evil_callback(); + /* skills.c */ extern void dump_skills(FILE *fff); extern s16b find_skill(cptr name); diff --git a/src/init2.c b/src/init2.c index 38de672a..b30764f9 100644 --- a/src/init2.c +++ b/src/init2.c @@ -1978,6 +1978,9 @@ static errr init_misc(void) TIMER_INERTIA_CONTROL = new_timer_c(meta_inertia_control_timer_callback, 10); + TIMER_AGGRAVATE_EVIL = + new_timer_c(timer_aggravate_evil_callback, + 10); return 0; } diff --git a/src/lua_bind.c b/src/lua_bind.c index 19fbf529..67073061 100644 --- a/src/lua_bind.c +++ b/src/lua_bind.c @@ -548,3 +548,17 @@ void increase_mana(int delta) sprintf(buf, "increase_mana(%d)", delta); exec_lua(buf); } + +timer_type *TIMER_AGGRAVATE_EVIL = 0; + +void timer_aggravate_evil_enable() +{ + TIMER_AGGRAVATE_EVIL->enabled = TRUE; +} + +void timer_aggravate_evil_callback() +{ + dispel_evil(0); +} + + @@ -4434,13 +4434,6 @@ static timer_type *new_timer_init(s32b delay) return t_ptr; } -timer_type *new_timer(cptr callback, s32b delay) -{ - timer_type *t_ptr = new_timer_init(delay); - t_ptr->callback = string_make(callback); - return t_ptr; -} - timer_type *new_timer_c(void (*callback)(), s32b delay) { timer_type *t_ptr = new_timer_init(delay); diff --git a/src/util.pkg b/src/util.pkg index a730ee9a..2c6f0d87 100644 --- a/src/util.pkg +++ b/src/util.pkg @@ -2325,27 +2325,6 @@ struct timer_type cptr callback; }; -/** @fn *new_timer(cptr callback, s32b delay) - * @brief Create a timer with callback "callback" and delay "delay".\n - * @param callback String \n the callback associated with the timer. - * @brief Callback - * @param delay Number \n the delay associated with the timer. - * @brief Delay - * @return timer_type \n The new timer. - * @note - * The timer's countdown is also set to "delay". The timer is disabled. - * @note (see file util.c) - */ -extern timer_type *new_timer(cptr callback, s32b delay); - -/** @fn del_timer(timer_type *t_ptr) - * @brief Delete timer "t_ptr".\n - * @param *t_ptr timer_type \n the timer to be deleted. - * @brief Timer - * @note (see file util.c) - */ -extern void del_timer(timer_type *t_ptr); - /* * Lists */ @@ -2434,3 +2413,8 @@ extern void lite_spot(int y, int x); * Mimicry */ extern s16b resolve_mimic_name(cptr name); + +/** + * Timers + */ +void timer_aggravate_evil_enable(); |