diff --git a/src/gamestate/modifiers.cpp b/src/gamestate/modifiers.cpp index d3f629282..e928edfdf 100644 --- a/src/gamestate/modifiers.cpp +++ b/src/gamestate/modifiers.cpp @@ -874,9 +874,6 @@ void recreate_single_land_province_modifiers(sys::state& state, prov_type provin if(state.national_definitions.has_siege) { ve_apply_modifier(state.national_definitions.has_siege, prov_valid_mask && military::province_is_under_siege(state, province)); } - if(state.national_definitions.occupied) { - ve_apply_modifier(state.national_definitions.occupied, prov_valid_mask && province::is_occupied(state, province)); - } if(state.national_definitions.blockaded) { ve_apply_modifier(state.national_definitions.blockaded, prov_valid_mask && military::province_is_blockaded(state, province)); } diff --git a/src/gamestate/system_state.cpp b/src/gamestate/system_state.cpp index f4e879766..b1f2560e0 100644 --- a/src/gamestate/system_state.cpp +++ b/src/gamestate/system_state.cpp @@ -54,6 +54,13 @@ state::state() : untrans_key_to_text_sequence(0, text::vector_backed_ci_hash(key state::~state() { quit_signaled.store(true, std::memory_order::release); + // Usually not needed if the game is quit, but if multiple scenarios are being created in the same session, the state destructor might run multiple times. Also just good practice + if(lua_ui_environment) { + lua_close(lua_ui_environment); + } + if(lua_game_loop_environment) { + lua_close(lua_game_loop_environment); + } logger_thread.join(); // wait for logger thread to quit after signalling } @@ -4288,6 +4295,34 @@ void state::on_scenario_load() { ui_state.rebel_flags.resize(world.ideology_size(), 0); + // Lua init. Save lua ui environment for later when UI is available + + lua_alice_api::set_state(this); + lua_alice_api::setup_gameloop_environment(*this); + + + + // populate the table with scripted functions from lua_combined_script (read during scenario generation). Do ui script later when UI is available + { + int status; + status = luaL_dostring(lua_game_loop_environment, lua_combined_script.c_str()); + if(status) { +#ifdef _WIN32 + OutputDebugStringA(lua_tostring(lua_game_loop_environment, -1)); +#endif + lua_settop(lua_game_loop_environment, 0); + std::abort(); + } + status = luaL_dostring(lua_game_loop_environment, lua_game_loop_script.c_str()); + if(status) { +#ifdef _WIN32 + OutputDebugStringA(lua_tostring(lua_game_loop_environment, -1)); +#endif + lua_settop(lua_game_loop_environment, 0); + std::abort(); + } + } + if(network_mode != network_mode_type::single_player) return; diff --git a/src/gamestate/system_state.hpp b/src/gamestate/system_state.hpp index 463098455..0e84ef948 100644 --- a/src/gamestate/system_state.hpp +++ b/src/gamestate/system_state.hpp @@ -795,8 +795,8 @@ struct alignas(64) state { // Lua scripting // - lua_State* lua_ui_environment; - lua_State* lua_game_loop_environment; + lua_State* lua_ui_environment = nullptr; + lua_State* lua_game_loop_environment = nullptr; std::vector lua_on_daily_tick; std::vector lua_on_battle_end; std::vector lua_on_battle_tick; diff --git a/src/gui/gui_modifier_tooltips.cpp b/src/gui/gui_modifier_tooltips.cpp index 56ae5370e..db753ff9d 100644 --- a/src/gui/gui_modifier_tooltips.cpp +++ b/src/gui/gui_modifier_tooltips.cpp @@ -330,10 +330,6 @@ void acting_modifiers_description_province(sys::state& state, text::layout_base& active_single_modifier_description(state, layout, state.national_definitions.has_siege, identation, header, nmid, military::province_is_under_siege(state, p) ? 1.f : 0.f); } - if(state.national_definitions.occupied) { - active_single_modifier_description(state, layout, state.national_definitions.occupied, identation, header, nmid, - province::is_occupied(state, p) ? 1.f : 0.f); - } if(state.national_definitions.blockaded) { active_single_modifier_description(state, layout, state.national_definitions.blockaded, identation, header, nmid, military::province_is_blockaded(state, p) ? 1.f : 0.f);