Skip to content

Commit

Permalink
Add fallback_human() action to the Lua AI
Browse files Browse the repository at this point in the history
Just like the FormulaAI fallback() function, this temporarily
transfers control of the side to a human player.
  • Loading branch information
CelticMinstrel committed Apr 6, 2017
1 parent 30447aa commit 62207df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/ai/lua/core.cpp
Expand Up @@ -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


Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/menu_events.hpp
Expand Up @@ -19,6 +19,7 @@
#include "chat_events.hpp"
#include "floating_textbox.hpp"
#include "units/map.hpp"
#include "lua_jailbreak_exception.hpp"

#include <vector>

Expand All @@ -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 {

Expand Down

0 comments on commit 62207df

Please sign in to comment.