Example #1
0
/**
 * @brief Calls the on_update() method of a Lua game.
 * @param game A game.
 */
void LuaContext::game_on_update(Game& game) {

  push_game(l, game.get_savegame());
  on_update();
  menus_on_update(-1);
  lua_pop(l, 1);
}
Example #2
0
/**
 * @brief Calls the on_draw() method of a Lua game.
 * @param game A game.
 * @param dst_surface The destination surface.
 */
void LuaContext::game_on_draw(Game& game, Surface& dst_surface) {

  push_game(l, game.get_savegame());
  menus_on_draw(-1, dst_surface);
  on_draw(dst_surface);
  lua_pop(l, 1);
}
Example #3
0
/**
 * \brief Implementation of item:get_game().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::item_api_get_game(lua_State* l) {

  EquipmentItem& item = check_item(l, 1);

  push_game(l, item.get_savegame());
  return 1;
}
Example #4
0
/**
 * @brief Calls the on_finished() method of a Lua game.
 * @param game A game.
 */
void LuaContext::game_on_finished(Game& game) {

  push_game(l, game.get_savegame());
  on_finished();
  remove_timers(-1);  // Stop timers and menus associated to this game.
  remove_menus(-1);
  lua_pop(l, 1);
}
Example #5
0
/**
 * \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);
}
Example #6
0
/**
 * \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);
}
Example #7
0
/**
 * \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);
}
Example #8
0
/**
 * @brief Calls the on_command_released() method of a Lua game.
 * @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) {

  bool handled = false;
  push_game(l, game.get_savegame());
  handled = on_command_released(command);
  if (!handled) {
    handled = menus_on_command_released(-1, command);
  }
  lua_pop(l, 1);
  return handled;
}
Example #9
0
/**
 * @brief Notifies a Lua game that an input event has just occurred.
 *
 * The appropriate callback in the game is triggered if it exists.
 *
 * @param game A game.
 * @param event The input event to handle.
 * @return \c true if the event was handled and should stop being propagated.
 */
bool LuaContext::game_on_input(Game& game, InputEvent& event) {

  bool handled = false;
  push_game(l, game.get_savegame());
  handled = on_input(event);
  if (!handled) {
    handled = menus_on_input(-1, event);
  }
  lua_pop(l, 1);
  return handled;
}
Example #10
0
/**
 * \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;
}
Example #11
0
/**
 * \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);
}
Example #12
0
/**
 * \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;
}
Example #13
0
/**
 * \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);
}
Example #14
0
/**
 * \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);
}
Example #15
0
/**
 * \brief Implementation of sol.game.load().
 * \param l The Lua context that is calling this function.
 * \return Number of values to return to Lua.
 */
int LuaContext::game_api_load(lua_State* l) {

  const std::string& file_name = luaL_checkstring(l, 1);

  if (FileTools::get_quest_write_dir().empty()) {
    error(l, "Cannot load savegame: no write directory was specified in quest.dat");
  }

  Savegame* savegame = new Savegame(get_lua_context(l).get_main_loop(), file_name);

  RefCountable::ref(savegame);
  savegame->get_equipment().load_items();

  push_game(l, *savegame);
  RefCountable::unref(savegame);
  return 1;
}
Example #16
0
/**
 * \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;
}
Example #17
0
/**
 * \brief Notifies a Lua game that an input event has just occurred.
 *
 * The appropriate callback in the game is triggered if it exists.
 * Also notifies the menus of the game if the game itself does not handle the
 * event.
 *
 * \param game A game.
 * \param event The input event to handle.
 * \return \c true if the event was handled and should stop being propagated.
 */
bool LuaContext::game_on_input(Game& game, const InputEvent& event) {

  if (!game.get_savegame().is_known_to_lua()) {
    return false;
  }

  bool handled = false;
  push_game(l, game.get_savegame());
  if (game.get_savegame().is_with_lua_table()) {
    handled = on_input(event);
  }
  if (!handled) {
    handled = menus_on_input(-1, event);
  }
  lua_pop(l, 1);
  return handled;
}
Example #18
0
File: client.c Project: theZiz/hase
int push_thread_function(void* data)
{
	while (push_message >= 0 || push_thread_first)
	{
		if (push_thread_first)
		{
			pThreadData thread_data = push_thread_first;
			int i = 0;
			if (push_message != -2)
				for (; i < 3; i++)
				{
					int r = push_game(thread_data->player,thread_data->second_of_player,thread_data->data);
					if (r == 0)
						break;
					if (r == 2)
						return 1;
				}
			if (i == 3)
				printf("BIG PANIC at second %i!\n",thread_data->second_of_player);
			else
			{
				if (i != 0)
					printf("Little panic... %i\n",i);
				printf("Sent second %i!\n",thread_data->second_of_player);
				//PULL STACK
				SDL_mutexP(push_mutex);
				push_thread_first = push_thread_first->next;
				if (push_thread_first == NULL)
					push_thread_last = NULL;
				SDL_mutexV(push_mutex);
				free(thread_data);
			}
		}
		else
			spSleep(100000);//100ms
	}
	return 0;
}
Example #19
0
/**
 * @brief Calls the on_changed() method of a Lua game.
 * @param game A game.
 * @param map The new active map.
 */
void LuaContext::game_on_map_changed(Game& game, Map& map) {

  push_game(l, game.get_savegame());
  on_map_changed(map);
  lua_pop(l, 1);
}
Example #20
0
/**
 * @brief Calls the on_unpaused() method of a Lua game.
 * @param game A game.
 */
void LuaContext::game_on_unpaused(Game& game) {

  push_game(l, game.get_savegame());
  on_unpaused();
  lua_pop(l, 1);
}