Fix #9834 error after reloading after taking village (#9842)

* Fix #9834 error after reloading after taking village

* improve error handling in case of an invalid undo action type

* f p

* f p
This commit is contained in:
gfgtdf 2025-02-04 05:34:01 +01:00 committed by GitHub
parent dabe7f8ffe
commit 0fd40d286c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

@ -215,6 +215,8 @@ struct take_village_step : undo_action
}
};
static auto reg_undo_take_village_step = undo_action_container::subaction_factory<take_village_step>();
}
game_events::pump_result_t get_village(const map_location& loc, int side, bool *action_timebonus, bool fire_event)
{

View File

@ -21,6 +21,7 @@
#include "variable.hpp" // vconfig
#include "game_data.hpp"
#include "units/unit.hpp"
#include "utils/general.hpp"
#include "utils/ranges.hpp"
#include "sound.hpp"
@ -65,8 +66,11 @@ void undo_action_container::add(t_step_ptr&& action)
void undo_action_container::read(const config& cfg)
{
for(const config& step : cfg.child_range("step")) {
auto& factory = get_factories()[step["type"]];
add(factory(step));
if(auto* factory = utils::find(get_factories(), step["type"].str())) {
add(factory->second(step));
} else {
throw config::error("Invalid undo action type: '" + step["type"].str() + "'");
}
}
}
void undo_action_container::write(config& cfg)