Action hooks
HOOK_OPEN_PRE y, x, o_idx, o_ptr || y, x, dir + 1
HOOK_OPEN_POST y, x, o_idx, o_ptr || y, x, dir + 1
HOOK_CLOSE_PRE y, x, o_idx, o_ptr || y, x, dir
HOOK_CLOSE_POST y, x, o_idx, o_ptr || y, x, dir
HOOK_GIVE_PRE c_ptr->m_idx, item
HOOK_GIVE_POST c_ptr->m_idx, item
- HOOK_GET_PRE o_ptr, o_idx
HOOK_GET_POST o_ptr, o_idx || o_ptr, slot
- HOOK_DROP_PRE o_ptr, item
- HOOK_DROP_POST o_ptr, item
- HOOK_DROPPED_NEAR j_ptr, chance, y, x, by, bx
- HOOK_WIELD_PRE o_ptr, item
- HOOK_WIELD_NUM
- HOOK_WIELD_POST o_ptr, item
HOOK_TAKEOFF_PRE o_ptr, slot || o_ptr, item
- HOOK_TAKEOFF_POST q_ptr, item, amt, force_drop
- HOOK_ACTIVATE
- HOOK_ACTIVATE_DESC
- HOOK_ACTIVATE_POWER d_power
HOOK_IDENTIFY_POST o_ptr, item, "normal" || o_ptr, item, "full" || o_ptr, -item, "normal"
HOOK_CHAT c_ptr->m_idx
- HOOK_PLAYER_DESTROY_PRE o_ptr, amt
- HOOK_PLAYER_DESTROY_POST o_ptr, amt
- HOOK_TARGET y, x, mode, info
- HOOK_PLAYER_SCHOOL_SPELL_CAST_PRE
- HOOK_PLAYER_SCHOOL_SPELL_CAST_POST
- HOOK_SPELL_CAST_PRE
- HOOK_SPELL_CAST_POST
- HOOK_PROJECT_P_PRE_LUA who, r, y, x, dam, typ, a_rad, flags, dir
- HOOK_PROJECT_P_POST_LUA who, r, y, x, dam, typ, a_rad, flags, dir
- HOOK_ANTIMAGIC_ABSORB
HOOK_ZAP o_ptr->tval, o_ptr->sval
- HOOK_ALTER_GRID y, x, dir
Movement hooks
- HOOK_MOVE_PRE y, x, tmp + 1, do_pickup, run, disarm
- HOOK_MOVE_POST oy, ox, tmp + 1, do_pickup, run, disarm
- HOOK_MOVE_PRE_DIR
- HOOK_MOVE_OK oy, ox, tmp, do_pickup, run, disarm
- HOOK_STAY_POST
- HOOK_STAIR_PRE updown_str
- HOOK_STAIR_DO updown_str
- HOOK_STAIR_POST
- HOOK_ENTER_DUNGEON get_flag(c_ptr, FLAG_DUNGEON)
- HOOK_ENTERED_DUNGEON d_dungeon_type
- HOOK_HIT_WALL y, x, tmp + 1
- HOOK_RECALL nil
- HOOK_FORBID_TRAVEL nil
- HOOK_PLAYER_CAN_ENTER
Character hooks
- HOOK_PLAYER_USED_ENERGY
- HOOK_PLAYER_LEVEL gained
- HOOK_PLAYER_EXP amount
- HOOK_CALC_HP
- HOOK_CALC_MANA
- HOOK_CALC_BONUS
- HOOK_CALC_BONUS_BEGIN
- HOOK_CALC_BONUS_END
- HOOK_CALC_POWERS nil
- HOOK_CALC_LITE nil
- HOOK_CALC_WEIGHT
- HOOK_RECALC_SKILLS nil
- HOOK_LEARN_ABILITY d_ability
- HOOK_PLAYER_REGEN
- HOOK_BIRTH
- HOOK_BIRTH_OBJECTS
- HOOK_DIE_PRE nil
- HOOK_DIE_POST nil
- HOOK_WIELD_SLOT
- HOOK_BODY_PARTS nil
- HOOK_DISTURB
- PLAYER_TAKE_HIT
- PLAYER_TAKE_SANITY_HIT
- HOOK_BODY_CHANGE_PRE
- HOOK_BODY_CHANGE
- HOOK_BODY_CHANGE_POST
Combat hooks
- HOOK_TEST_HIT
- HOOK_CRIT_HIT_CHANCE
- HOOK_CRIT_HIT_TYPE
- HOOK_WEAP_DAM_DEALT
- HOOK_WEAP_KILLED_MON
- HOOK_INIT_COMBAT_PRE
- HOOK_INIT_COMBAT_POST
Monster hooks
- HOOK_NEW_MONSTER_PRE y, x, r_idx, ego, slp, status
HOOK_NEW_MONSTER_POST i_ptr, m_ptr->r_idx
- HOOK_MONSTER_DEATH m_idx
- HOOK_MONSTER_REMOVED i, m_ptr
- HOOK_DO_DROP_CORPSE m_ptr
HOOK_CORPSE_CREATE_PRE m_ptr->r_idx
- HOOK_CORPSE_CREATE_POST
HOOK_CREATE_DROP c_ptr->m_idx, m_ptr
- HOOK_MONSTER_AI_TARGET m_idx
- HOOK_MONSTER_AI_MOVE
- HOOK_MON_SPEAK m_idx, m_name
- HOOK_MONSTER_LEVEL
- HOOK_MON_CHANGE_FACTION_PRE m_ptr, old_faction, new_faction
- HOOK_MON_CHANGE_FACTION_POST m_ptr, old_faction, new_faction
Object hooks
- HOOK_ITEM_NAME
- HOOK_ITEM_NAME_INSERT
- HOOK_APPLY_MAGIC
- HOOK_OBJECT_DESC o_ptr, (fff != NULL) ? TRUE : FALSE, trim_down
- HOOK_OBJECT_VALUE
- HOOK_ITEM_NAME_INSERT
- HOOK_OBJECT_SIMILAR
- HOOK_OBJECT_ABSORB o_ptr,j_ptr
- HOOK_OBJECT_UNABSORB o_ptr,q_ptr
- HOOK_OBJECT_LEVEL_PRE o_ptr
- HOOK_OBJECT_LEVEL_DO o_ptr
- HOOK_OBJECT_LEVEL_POST o_ptr
- HOOK_DESTROY_PRE
- HOOK_DESTROY_POST
- HOOK_REPEAT_KEY_CHAIN_DESTROY
- HOOK_MANA_CHANGE_PRE
- HOOK_MANA_CHANGE_POST
- HOOK_MANA_USE_PRE
- HOOK_MANA_USE_POST
- HOOK_MANA_DRAIN_PRE
- HOOK_MANA_DRAIN_POST
- HOOK_MANA_CHARGE_PRE
- HOOK_MANA_CHARGE_POST
Trap hooks
- HOOK_TRAP_RANDOM_PRE
- HOOK_TRAP_RANDOM_POST
- HOOK_TRAP_MAKE_POST
- HOOK_TRAP_PLACE_PRE
- HOOK_TRAP_PLACE_POST
- HOOK_TRAP_DISARM_ATTEMPT
- HOOK_TRAP_DISARM_PRE
- HOOK_TRAP_DISARM_POST
- HOOK_TRAP_RECURSION_START
- HOOK_TRAP_RECURSION_STOP
- HOOK_TRAP_TRIP_PRE
- HOOK_TRAP_TRIP_POST
- HOOK_TRAP_MAKE_POST
God hooks
HOOK_FOLLOW_GOD god, "ask" || god, "done"
- HOOK_SACRIFICE_GOD nil
- HOOK_PIETY_CHANGE d_amt
Quest hooks
- HOOK_GEN_QUEST is_quest(dun_level)
- HOOK_QUEST_FINISH
- HOOK_QUEST_FAIL
- HOOK_INIT_QUEST
Building hooks
- HOOK_BUILDING_ACTION
- HOOK_STORE_STOCK
- HOOK_STORE_BUY
Wilderness hooks
HOOK_WILD_GEN FALSE || TRUE
- HOOK_WILD_GEN_MON hack_floor
- HOOK_WILD_SMALL_MOVE_POST nil
- HOOK_WILD_LARGE_NEW_AREA_PRE y, x
- HOOK_WILD_LARGE_NEW_AREA_POST y, x
- HOOK_WILD_LARGE_CUSTOM_GENERATOR y, x, border, corner, refresh
- HOOK_WILD_LARGE_TWEAK_GENERATOR y, x, border, corner, refresh
Chatter
BucketMan: This is useful! Thank you. Any chance we could include the variable names passed to the hook functions as well?
NerdanelVampire: I didn't know hooks had that property... I'm going to visit my parents now, but I'll look into the variable thing.
NerdanelVampire: I looked into it, and it looks like variable names are not passed, but rather their order. For example, you could call the boolean variable you can call through GAME_START new, new_game (which appears to be its "true name"), or i_like_ponies and it would all work the same. Also, since this is C, you should be able to call any number of variables up to the hook total, but if you are only interested in the variable #3 you must first mention variables #1 and #2 even if you aren't going to use them because otherwise things will get messed up.
ShrikeDeCil: I'd be more interested in knowing the number & type of the variables - not their names. (And that's what I took BucketMan to be asking about really). IOW, these are a sort of 'function', and knowing that HOOK_HARDCODED_MAX is going to have one unsigned int passed (is it? I don't know where to look!) is the goal. Sure, I can _call_ it i_like_ponies, but there are always places where you get a string when you were expecting an int, or an int instead of a boolean. Or the HOOK passes two - the first being the boolean, and the second being a count. Or something. Where are you finding the hook definitions anyway?
NerdanelVampire: Go to the source directory and do (if you're on a sensible operating system):
grep -A1 process_hooks\(HOOK *
I love grep.
One example from among the snippets that appear:
cmd1.c: if (process_hooks(HOOK_MOVE_PRE, "(d,d,d,d,d,d)", y, x, tmp + 1, cmd1.c- do_pickup, run, disarm))
I have figured out that "d" is double and "s" is short. "O" appears when there are pointers. But when there are things like "tmp + 1", I have no idea what that's supposed to be about.
Unlike a strongly typed language like C++, C is lax about types, and lua isn't typed at all. I can't say I particularly like that.
DarkGod: d=number, s=string, O=object, M=monster. As for C it's as typed as C++ IIRC, and lua is typed, but it's the values that are typed not the variables
AnonymousHero: Just a nitpick: C++ is more strongly typed than C. (There is actually some valid C code which cannot compiled without changes using a C++ compiler.)
ShrikeDeCil: Added what I could gather from Nerandel's trick with grep above to the text. That included two more hooks -
- HOOK_OBJECT_LEVEL_DO o_ptr
HOOK_ZAP o_ptr->tval, o_ptr->sval
Several of the hooks seem to be accessed in several different ways?
EtMarc: There are also a bunch of hooks who are processed by process_hooks_ret() instead. They return some value.
- HOOK_MONSTER_TAKE_HIT s_idx, m_idx, m_ptr, dam. Returns dam.
ToME Wiki