Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/gamestate/modifiers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
35 changes: 35 additions & 0 deletions src/gamestate/system_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions src/gamestate/system_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> lua_on_daily_tick;
std::vector<int> lua_on_battle_end;
std::vector<int> lua_on_battle_tick;
Expand Down
4 changes: 0 additions & 4 deletions src/gui/gui_modifier_tooltips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading