/** * \brief Calls the on_ability_used() method of a Lua equipment item. * * Does nothing if the method is not defined. * * \param item An equipment item. * \param ability_name The ability just used. */ void LuaContext::item_on_ability_used(EquipmentItem& item, const std::string& ability_name) { if (!userdata_has_field(item, "on_ability_used")) { return; } push_item(l, item); on_ability_used(ability_name); lua_pop(l, 1); }
/** * \brief Calls the on_npc_collision_fire() method of a Lua equipment item. * * Does nothing if the method is not defined. * * \param item An equipment item. * \param npc An NPC. */ void LuaContext::item_on_npc_collision_fire(EquipmentItem& item, Npc& npc) { if (!userdata_has_field(item, "on_npc_collision_fire")) { return; } push_item(l, item); on_npc_collision_fire(npc); lua_pop(l, 1); }
/** * \brief Calls the on_obtained() method of a Lua equipment item. * * Does nothing if the method is not defined. * * \param item An equipment item. * \param treasure The treasure just obtained. */ void LuaContext::item_on_obtained(EquipmentItem& item, const Treasure& treasure) { if (!userdata_has_field(item, "on_obtained")) { return; } push_item(l, item); on_obtained(treasure); lua_pop(l, 1); }
/** * \brief Calls the on_map_changed() method of a Lua equipment item. * * Does nothing if the method is not defined. * * \param item An equipment item. * \param map A map. */ void LuaContext::item_on_map_changed(EquipmentItem& item, Map& map) { if (!userdata_has_field(item, "on_map_changed")) { return; } push_item(l, item); on_map_changed(map); lua_pop(l, 1); }
/** * \brief Calls the on_game_over_finished() method of a Lua game. * * Does nothing if the method is not defined. * * \param game A game. */ void LuaContext::game_on_game_over_finished(Game& game) { if (!userdata_has_field(game.get_savegame(), "on_game_over_finished")) { return; } push_game(l, game.get_savegame()); on_game_over_finished(); lua_pop(l, 1); }
/** * \brief Calls the on_amount_changed() method of a Lua equipment item. * * Does nothing if the method is not defined. * * \param item An equipment item. * \param amount The amount of this item. */ void LuaContext::item_on_amount_changed(EquipmentItem& item, int amount) { if (!userdata_has_field(item, "on_amount_changed")) { return; } push_item(l, item); on_amount_changed(amount); lua_pop(l, 1); }
/** * \brief Calls the on_ability_used() method of a Lua equipment item. * * Does nothing if the method is not defined. * * \param item An equipment item. * \param ability The ability just used. */ void LuaContext::item_on_ability_used(EquipmentItem& item, Ability ability) { if (!userdata_has_field(item, "on_ability_used")) { return; } push_item(l, item); on_ability_used(ability); lua_pop(l, 1); }
/** * \brief Calls the on_using() method of a Lua equipment item. * * Does nothing if the method is not defined. * * \param item An equipment item. */ void LuaContext::item_on_using(EquipmentItem& item) { if (!userdata_has_field(item, "on_using")) { return; } push_item(l, item); on_using(); lua_pop(l, 1); }
/** * \brief Calls the on_changed() method of a Lua game. * * Does nothing if the method is not defined. * * \param game A game. * \param map The new active map. */ void LuaContext::game_on_map_changed(Game& game, Map& map) { if (!userdata_has_field(game.get_savegame(), "on_map_changed")) { return; } push_game(l, game.get_savegame()); on_map_changed(map); lua_pop(l, 1); }
/** * \brief Calls the on_npc_interaction() method of a Lua equipment item. * * Does nothing if the method is not defined. * * \param item An equipment item. * \param npc An NPC. */ void LuaContext::item_on_npc_interaction(EquipmentItem& item, Npc& npc) { if (!userdata_has_field(item, "on_npc_interaction")) { return; } push_item(l, item); on_npc_interaction(npc); lua_pop(l, 1); }
/** * \brief Calls the on_suspended() method of a Lua equipment item. * * Does nothing if the method is not defined. * * \param item An equipment item. * \param suspended true if the game is suspended. */ void LuaContext::item_on_suspended(EquipmentItem& item, bool suspended) { if (!userdata_has_field(item, "on_suspended")) { return; } push_item(l, item); on_suspended(suspended); lua_pop(l, 1); }
/** * \brief Calls the on_finished() method of a Lua equipment item. * * Does nothing if the method is not defined. * * \param item An equipment item. */ void LuaContext::item_on_finished(EquipmentItem& item) { push_item(l, item); if (userdata_has_field(item, "on_finished")) { on_finished(); } remove_timers(-1); // Stop timers and menus associated to this item. remove_menus(-1); lua_pop(l, 1); }
/** * \brief Calls the on_frame_changed() method of a Lua sprite. * * Does nothing if the method is not defined. * * \param sprite A sprite whose frame has just changed. * \param animation Name of the current animation. * \param frame The new frame. */ void LuaContext::sprite_on_frame_changed(Sprite& sprite, const std::string& animation, int frame) { if (!userdata_has_field(sprite, "on_frame_changed")) { return; } push_sprite(l, sprite); on_frame_changed(animation, frame); lua_pop(l, 1); }
/** * \brief Calls the on_pickable_movement_changed() method of a Lua equipment item. * * Does nothing if the method is not defined. * * \param item An equipment item. * \param pickable The instance of pickable item whose movement has changed. * \param movement The movement. */ void LuaContext::item_on_pickable_movement_changed(EquipmentItem& item, Pickable& pickable, Movement& movement) { if (!userdata_has_field(item, "on_pickable_movement_changed")) { return; } push_item(l, item); on_pickable_movement_changed(pickable, movement); lua_pop(l, 1); }
/** * \brief Calls the on_dialog_finished() method of a Lua game. * * Does nothing if the method is not defined. * * \param game A game. * \param dialog The dialog just finished. */ void LuaContext::game_on_dialog_finished(Game& game, const Dialog& dialog) { if (!userdata_has_field(game.get_savegame(), "on_dialog_finished")) { return; } push_game(l, game.get_savegame()); on_dialog_finished(dialog); lua_pop(l, 1); }
/** * \brief Calls the on_animation_finished() method of a Lua sprite. * * Does nothing if the method is not defined. * * \param sprite A sprite whose animation has just finished. * \param animation Name of the animation finished. */ void LuaContext::sprite_on_animation_finished(Sprite& sprite, const std::string& animation) { if (!userdata_has_field(sprite, "on_animation_finished")) { return; } push_sprite(l, sprite); on_animation_finished(animation); lua_pop(l, 1); }
/** * \brief Calls the on_pickable_created() method of a Lua equipment item. * * Does nothing if the method is not defined. * * \param item An equipment item. * \param pickable The instance of pickable item that has just appeared. */ void LuaContext::item_on_pickable_created(EquipmentItem& item, Pickable& pickable) { if (!userdata_has_field(item, "on_pickable_created")) { return; } push_item(l, item); on_pickable_created(pickable); lua_pop(l, 1); }
/** * \brief Calls the on_npc_interaction_item() method of a Lua equipment item. * * Does nothing if the method is not defined. * * \param item The equipment item linked to the NPC. * \param npc An NPC. * \param item_used The equipment item used. * \return true if an interaction occurred. */ bool LuaContext::item_on_npc_interaction_item(EquipmentItem& item, Npc& npc, EquipmentItem& item_used) { if (!userdata_has_field(item, "on_npc_interaction_item")) { return false; } push_item(l, item); bool result = on_npc_interaction_item(npc, item_used); lua_pop(l, 1); return result; }
/** * \brief Calls the on_game_over_started() method of a Lua game. * * Does nothing if the method is not defined. * * \param game A game. * \return true if the game:on_game_over_started() method is defined. */ bool LuaContext::game_on_game_over_started(Game& game) { if (!userdata_has_field(game.get_savegame(), "on_game_over_started")) { return false; } push_game(l, game.get_savegame()); bool exists = on_game_over_started(); lua_pop(l, 1); return exists; }
/** * \brief Calls the on_draw() method of a Lua game if it is defined. * * Also calls the method on its menus. * * \param game A game. * \param dst_surface The destination surface. */ void LuaContext::game_on_draw(Game& game, Surface& dst_surface) { if (!game.get_savegame().is_known_to_lua()) { return; } push_game(l, game.get_savegame()); if (userdata_has_field(game.get_savegame(), "on_draw")) { on_draw(dst_surface); } menus_on_draw(-1, dst_surface); lua_pop(l, 1); }
/** * \brief Calls the on_dialog_started() method of a Lua game. * * Does nothing if the method is not defined. * * \param game A game. * \param dialog The dialog just started. * \param info_ref Lua ref to the info parameter to pass to the method, * or LUA_REFNIL. * \return true if the game:on_dialog_started() method is defined. */ bool LuaContext::game_on_dialog_started(Game& game, const Dialog& dialog, int info_ref) { if (!userdata_has_field(game.get_savegame(), "on_dialog_started")) { return false; } push_game(l, game.get_savegame()); bool exists = on_dialog_started(dialog, info_ref); lua_pop(l, 1); return exists; }
/** * \brief Calls the on_update() method of a Lua equipment item. * * Does nothing if the method is not defined. * * \param item An equipment item. */ void LuaContext::item_on_update(EquipmentItem& item) { // This particular method is tried so often that we want to save optimize // the std::string construction. static const std::string method_name = "on_update"; if (!userdata_has_field(item, method_name)) { return; } push_item(l, item); on_update(); lua_pop(l, 1); }
/** * \brief Calls the on_finished() method of a Lua game if it is defined. * * Also stops timers and menus associated to the game. * * \param game A game. */ void LuaContext::game_on_finished(Game& game) { if (!game.get_savegame().is_known_to_lua()) { return; } push_game(l, game.get_savegame()); if (userdata_has_field(game.get_savegame(), "on_finished")) { on_finished(); } remove_timers(-1); // Stop timers and menus associated to this game. remove_menus(-1); lua_pop(l, 1); }
/** * \brief Calls the on_update() method of a Lua game if it is defined. * * Also calls the method on its menus. * * \param game A game. */ void LuaContext::game_on_update(Game& game) { if (!game.get_savegame().is_known_to_lua()) { return; } push_game(l, game.get_savegame()); // This particular method is tried so often that we want to save optimize // the std::string construction. static const std::string method_name = "on_update"; if (userdata_has_field(game.get_savegame(), method_name)) { on_update(); } menus_on_update(-1); lua_pop(l, 1); }
/** * \brief Calls the on_command_released() method of a Lua game if it exists. * * Also notifies the menus of the game if the game itself does not handle the * event. * * \param game A game. * \param command The command released. * \return \c true if the event was handled and should stop being propagated. */ bool LuaContext::game_on_command_released(Game& game, GameCommands::Command command) { if (!game.get_savegame().is_known_to_lua()) { return false; } bool handled = false; push_game(l, game.get_savegame()); if (userdata_has_field(game.get_savegame(), "on_command_released")) { handled = on_command_released(command); } if (!handled) { handled = menus_on_command_released(-1, command); } lua_pop(l, 1); return handled; }