From 62207df0eae66fee49ee4f1164a8add438f3b838 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Mon, 3 Apr 2017 02:32:16 -0400 Subject: [PATCH] Add fallback_human() action to the Lua AI Just like the FormulaAI fallback() function, this temporarily transfers control of the side to a human player. --- src/ai/lua/core.cpp | 6 ++++++ src/menu_events.hpp | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ai/lua/core.cpp b/src/ai/lua/core.cpp index e12bf211f9b9a..a1cba22b24f5c 100644 --- a/src/ai/lua/core.cpp +++ b/src/ai/lua/core.cpp @@ -344,6 +344,11 @@ static int cfun_ai_check_recall(lua_State *L) return ai_recall(L, false); } +static int cfun_ai_fallback_human(lua_State* L) +{ + throw fallback_ai_to_human_exception(); +} + // Goals and targets @@ -971,6 +976,7 @@ static int impl_ai_get(lua_State* L) { "stopunit_attacks", &cfun_ai_execute_stopunit_attacks }, { "stopunit_moves", &cfun_ai_execute_stopunit_moves }, { "synced_command", &cfun_ai_execute_synced_command }, + { "fallback_human", &cfun_ai_fallback_human}, { nullptr, nullptr } }; for (const luaL_Reg* p = mutating_callbacks; p->name; ++p) { if(m == p->name) { diff --git a/src/menu_events.hpp b/src/menu_events.hpp index b0a1c989af0ac..b23260fc1fb60 100644 --- a/src/menu_events.hpp +++ b/src/menu_events.hpp @@ -19,6 +19,7 @@ #include "chat_events.hpp" #include "floating_textbox.hpp" #include "units/map.hpp" +#include "lua_jailbreak_exception.hpp" #include @@ -35,7 +36,7 @@ namespace events { class mouse_handler; } -struct fallback_ai_to_human_exception {}; +struct fallback_ai_to_human_exception : public lua_jailbreak_exception {IMPLEMENT_LUA_JAILBREAK_EXCEPTION(fallback_ai_to_human_exception)}; namespace events {