FLG manager: initially select the default faction
Turns out that this is enforced by C++ unit tests (which haven't run
successfully in Travis for a couple of months).
The tests started to fail in commit d864a89a15
when random factions
were set to always be the first in the list
(and therefore always initially selected).
This commit is contained in:
parent
de5a622626
commit
bd705671df
3 changed files with 20 additions and 3 deletions
|
@ -21,6 +21,8 @@
|
|||
#include "mt_rng.hpp"
|
||||
#include "units/types.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
static lg::log_domain log_mp_connect_engine("mp/connect/engine");
|
||||
#define LOG_MP LOG_STREAM(info, log_mp_connect_engine)
|
||||
#define ERR_MP LOG_STREAM(err, log_mp_connect_engine)
|
||||
|
@ -81,7 +83,7 @@ flg_manager::flg_manager(const std::vector<const config*>& era_factions,
|
|||
|
||||
update_available_factions();
|
||||
|
||||
set_current_faction(0);
|
||||
select_default_faction();
|
||||
}
|
||||
|
||||
void flg_manager::set_current_faction(const unsigned index)
|
||||
|
@ -433,6 +435,21 @@ void flg_manager::update_choosable_genders()
|
|||
}
|
||||
}
|
||||
|
||||
void flg_manager::select_default_faction()
|
||||
{
|
||||
const config::attribute_value& default_faction = get_default_faction(side_)["faction"];
|
||||
auto default_faction_it = std::find_if(choosable_factions_.begin(), choosable_factions_.end(),
|
||||
[&default_faction](const config* faction) {
|
||||
return (*faction)["id"] == default_faction;
|
||||
});
|
||||
|
||||
if(default_faction_it != choosable_factions_.end()) {
|
||||
set_current_faction(default_faction_it - choosable_factions_.begin());
|
||||
} else {
|
||||
set_current_faction(0u);
|
||||
}
|
||||
}
|
||||
|
||||
int flg_manager::find_suitable_faction() const
|
||||
{
|
||||
std::vector<std::string> find;
|
||||
|
|
|
@ -94,6 +94,8 @@ private:
|
|||
// Append leaders from a given faction to a choosable factions.
|
||||
void append_leaders_from_faction(const config* faction);
|
||||
|
||||
void select_default_faction();
|
||||
|
||||
int faction_index(const config& faction) const;
|
||||
/// returns -1 if no leader with that name was found
|
||||
int leader_index(const std::string& leader) const;
|
||||
|
|
|
@ -172,7 +172,6 @@ BOOST_AUTO_TEST_CASE( flg_map_settings )
|
|||
side["previous_recruits"] = "Elvish Archer";
|
||||
side_engine.reset(create_side_engine(side, connect_engine.get()));
|
||||
//BOOST_CHECK_EQUAL( side_engine->flg().choosable_factions().size(), 1 );
|
||||
BOOST_CHECK_EQUAL( side_engine->flg().current_faction()["id"], "Custom" );
|
||||
BOOST_CHECK_EQUAL( side_engine->new_config()["previous_recruits"],
|
||||
"Elvish Archer" );
|
||||
|
||||
|
@ -352,7 +351,6 @@ BOOST_AUTO_TEST_CASE( flg_no_map_settings )
|
|||
side["previous_recruits"] = "Elvish Archer";
|
||||
side_engine.reset(create_side_engine(side, connect_engine.get()));
|
||||
BOOST_CHECK( side_engine->flg().choosable_factions().size() > 1 );
|
||||
BOOST_CHECK_EQUAL( side_engine->flg().current_faction()["id"], "Custom" );
|
||||
BOOST_CHECK_EQUAL( side_engine->new_config()["previous_recruits"],
|
||||
"Elvish Archer" );
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue