--[[ $Id: give_aux.lua 87 2004-06-28 14:18:58Z mitsu $ Created for Intets Hevn 0.3.0 by Kjell Heskestad. Contains helper functions for m_give.lua. For regular use you shouldn't have to touch this file. ]] -- Checks whether supplied object's tvals and/or svals match what is given in supplied table. function check_type_table(table, o_ptr) if(table[o_ptr.tval]) then if(table[o_ptr.tval].sval) then if(o_ptr.sval == table[o_ptr.tval].sval) then -- both tval and sval match return TRUE, table[o_ptr.tval].response, table[o_ptr.tval].action else -- tval matches, but sval doesn't return FALSE end else -- tval matches, sval not set return TRUE, table[o_ptr.tval].response, table[o_ptr.tval].action end else return FALSE -- tval not set end end -- Checks if an object's status matches what is given in supplied table. function check_status_table(table, o_ptr) local status = check_item_status(o_ptr); if(table[status]) then return TRUE, table[status].response, table[status].action end return FALSE end -- Print a random response. function print_monster_reaction(response, m_ptr) if(response) then msg_print(format("%s %s", cap_first(monster_desc(m_ptr, 0)), rand_item(response))) end; end -- Check type and status tables, and act according to them. function check_tables(m_idx, item, table) local o_ptr = get_object(item); local tval_match, sval_match, status_match = FALSE; if(getn(table.type_table) > 0) then tval_match, response, action = check_type_table(table.type_table, o_ptr); end if(getn(table.status_table) > 0) and (tval_match == FALSE) then status_match, response, action = check_status_table(table.status_table, o_ptr); end local m_ptr = monster(m_idx); if(tval_match == TRUE) or (status_match == TRUE) then print_monster_reaction(response, m_ptr); action(m_ptr); inven_item_increase(item, -1); inven_item_optimize(item); else print_monster_reaction(table.default_response, m_ptr); end end