fix issues caused by empty save id
ee50171d13
broke some codes that relied on unique save ids, that is in particular the statistic code and scoped_recall_unit, so now these codes fallback to the side number if the save id is empty. (cherry-picked from commitc79e1645c8
)
This commit is contained in:
parent
a5739073ea
commit
758fe79fe2
10 changed files with 14 additions and 13 deletions
|
@ -130,7 +130,7 @@ namespace { // Helpers for get_recalls()
|
|||
std::set<std::size_t> * already_added = nullptr)
|
||||
{
|
||||
const team& leader_team = resources::gameboard->get_team(leader->side());
|
||||
const std::string& save_id = leader_team.save_id();
|
||||
const std::string& save_id = leader_team.save_id_or_number();
|
||||
|
||||
const unit_filter ufilt(vconfig(leader->recall_filter()));
|
||||
|
||||
|
@ -245,7 +245,7 @@ namespace { // Helpers for check_recall_location()
|
|||
|
||||
// Make sure the recalling unit can recall this specific unit.
|
||||
team& recall_team = (*resources::gameboard).get_team(recaller.side());
|
||||
scoped_recall_unit this_unit("this_unit", recall_team.save_id(),
|
||||
scoped_recall_unit this_unit("this_unit", recall_team.save_id_or_number(),
|
||||
recall_team.recall_list().find_index(recall_unit.id()));
|
||||
|
||||
const unit_filter ufilt(vconfig(recaller.recall_filter()));
|
||||
|
|
|
@ -474,7 +474,7 @@ WML_HANDLER_FUNCTION(recall,, cfg)
|
|||
|
||||
for(int index = 0; index < static_cast<int>(resources::gameboard->teams().size()); ++index) {
|
||||
LOG_NG << "for side " << index + 1 << "...\n";
|
||||
const std::string player_id = resources::gameboard->teams()[index].save_id();
|
||||
const std::string player_id = resources::gameboard->teams()[index].save_id_or_number();
|
||||
|
||||
if(resources::gameboard->teams()[index].recall_list().size() < 1) {
|
||||
DBG_NG << "recall list is empty when trying to recall!\n"
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace builtin_conditions {
|
|||
if(counts == default_counts && match_count) {
|
||||
break;
|
||||
}
|
||||
scoped_recall_unit auto_store("this_unit", team.save_id(), t);
|
||||
scoped_recall_unit auto_store("this_unit", team.save_id_or_number(), t);
|
||||
if(ufilt(*team.recall_list()[t])) {
|
||||
++match_count;
|
||||
}
|
||||
|
|
|
@ -45,8 +45,8 @@ REGISTER_DIALOG(statistics_dialog)
|
|||
|
||||
statistics_dialog::statistics_dialog(const team& current_team)
|
||||
: current_team_(current_team)
|
||||
, campaign_(statistics::calculate_stats(current_team.save_id()))
|
||||
, scenarios_(statistics::level_stats(current_team.save_id()))
|
||||
, campaign_(statistics::calculate_stats(current_team.save_id_or_number()))
|
||||
, scenarios_(statistics::level_stats(current_team.save_id_or_number()))
|
||||
, scenario_index_(scenarios_.size() - 1)
|
||||
, main_stat_table_()
|
||||
{
|
||||
|
|
|
@ -1147,7 +1147,7 @@ void play_controller::play_side()
|
|||
// This flag can be set by derived classes (in overridden functions).
|
||||
player_type_changed_ = false;
|
||||
|
||||
statistics::reset_turn_stats(gamestate().board_.get_team(current_side()).save_id());
|
||||
statistics::reset_turn_stats(gamestate().board_.get_team(current_side()).save_id_or_number());
|
||||
|
||||
play_side_impl();
|
||||
|
||||
|
|
|
@ -614,7 +614,7 @@ int game_lua_kernel::intf_match_unit(lua_State *L)
|
|||
WRN_LUA << "but unit to match was on recall list. ";
|
||||
WRN_LUA << "Thus the 3rd argument is ignored.\n";
|
||||
team &t = board().get_team(side);
|
||||
scoped_recall_unit auto_store("this_unit", t.save_id(), t.recall_list().find_index(u->id()));
|
||||
scoped_recall_unit auto_store("this_unit", t.save_id_or_number(), t.recall_list().find_index(u->id()));
|
||||
lua_pushboolean(L, unit_filter(filter).matches(*u, map_location()));
|
||||
return 1;
|
||||
}
|
||||
|
@ -626,7 +626,7 @@ int game_lua_kernel::intf_match_unit(lua_State *L)
|
|||
map_location loc;
|
||||
luaW_tolocation(L, 3, loc); // If argument 3 isn't a location, loc is unchanged
|
||||
team &t = board().get_team(side);
|
||||
scoped_recall_unit auto_store("this_unit", t.save_id(), t.recall_list().find_index(u->id()));
|
||||
scoped_recall_unit auto_store("this_unit", t.save_id_or_number(), t.recall_list().find_index(u->id()));
|
||||
lua_pushboolean(L, unit_filter(filter).matches(*u, loc));
|
||||
return 1;
|
||||
} else {
|
||||
|
@ -659,7 +659,7 @@ int game_lua_kernel::intf_get_recall_units(lua_State *L)
|
|||
{
|
||||
if (!filter.null()) {
|
||||
scoped_recall_unit auto_store("this_unit",
|
||||
t.save_id(), t.recall_list().find_index(u->id()));
|
||||
t.save_id_or_number(), t.recall_list().find_index(u->id()));
|
||||
if (!ufilt( *u, map_location() ))
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -139,7 +139,7 @@ bool side_filter::match_internal(const team &t) const
|
|||
}
|
||||
if(!found && ufilt_cfg["search_recall_list"].to_bool(false)) {
|
||||
for(const unit_const_ptr & u : t.recall_list()) {
|
||||
scoped_recall_unit this_unit("this_unit", t.save_id(),t.recall_list().find_index(u->id()));
|
||||
scoped_recall_unit this_unit("this_unit", t.save_id_or_number(), t.recall_list().find_index(u->id()));
|
||||
if(ufilter_->matches(*u)) {
|
||||
found = true;
|
||||
break;
|
||||
|
|
|
@ -41,7 +41,7 @@ typedef std::map<std::string,stats> team_stats_t;
|
|||
std::string get_team_save_id(const unit & u)
|
||||
{
|
||||
assert(resources::gameboard);
|
||||
return resources::gameboard->get_team(u.side()).save_id();
|
||||
return resources::gameboard->get_team(u.side()).save_id_or_number();
|
||||
}
|
||||
|
||||
struct scenario_stats
|
||||
|
|
|
@ -228,6 +228,7 @@ public:
|
|||
void last_recruit(const std::string & u_type) { last_recruit_ = u_type; }
|
||||
|
||||
const std::string& save_id() const { return info_.save_id; }
|
||||
std::string save_id_or_number() const { return info_.save_id.empty() ? std::to_string(info_.side) : info_.save_id; }
|
||||
void set_save_id(const std::string& save_id) { info_.save_id = save_id; }
|
||||
const std::string& current_player() const { return info_.current_player; }
|
||||
|
||||
|
|
|
@ -534,7 +534,7 @@ void scoped_recall_unit::activate()
|
|||
|
||||
const std::vector<team>& teams = resources::gameboard->teams();
|
||||
|
||||
std::vector<team>::const_iterator team_it = std::find_if(teams.begin(), teams.end(), [&](const team& t) { return t.save_id() == player_; });
|
||||
std::vector<team>::const_iterator team_it = std::find_if(teams.begin(), teams.end(), [&](const team& t) { return t.save_id_or_number() == player_; });
|
||||
|
||||
if(team_it != teams.end()) {
|
||||
if(team_it->recall_list().size() > recall_index_) {
|
||||
|
|
Loading…
Add table
Reference in a new issue