Backported: Fixed loading ai parameters.
MP side defination now overwrites era values (bug #12171)
This commit is contained in:
parent
e2fbc584c9
commit
ed2d47b6c3
4 changed files with 93 additions and 25 deletions
|
@ -14,6 +14,8 @@ Version 1.4.4+svn:
|
|||
* miscellaneous and bug fixes:
|
||||
* Fixed OOS bug when giving control and having move in undo stack.
|
||||
* Fixed crash when ai moves units next to level 0 hiden unit (bug #12252)
|
||||
* Fixed loading ai parameters. MP side defination now overwrites
|
||||
era values (bug #12171)
|
||||
|
||||
Version 1.4.4:
|
||||
* language and i18n:
|
||||
|
|
23
src/ai.cpp
23
src/ai.cpp
|
@ -266,9 +266,10 @@ bool ai::recruit_usage(const std::string& usage)
|
|||
const std::string& name = i->second.id();
|
||||
// If usage is empty consider any unit.
|
||||
if (i->second.usage() == usage || usage == "") {
|
||||
if (recruits.count(name) == 0)
|
||||
continue;
|
||||
found = true;
|
||||
if(recruits.count(name)
|
||||
&& current_team().gold() - i->second.cost() > min_gold
|
||||
if(current_team().gold() - i->second.cost() > min_gold
|
||||
&& not_recommended_units_.count(name) == 0)
|
||||
{
|
||||
LOG_AI << "recommending '" << name << "'\n";
|
||||
|
@ -287,6 +288,12 @@ bool ai::recruit_usage(const std::string& usage)
|
|||
} else {
|
||||
WRN_AI << "Trying to recruit a: " << usage
|
||||
<< " but no unit of that type (usage=) is available.\n";
|
||||
|
||||
if (usage != "")
|
||||
{
|
||||
return current_team().remove_recruitment_pattern_entry(usage);
|
||||
// remove this recruitment pattern and try again
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1761,12 +1768,12 @@ void ai::do_recruitment()
|
|||
|
||||
// If there is no recruitment_pattern use "" which makes us consider
|
||||
// any unit available.
|
||||
if (options.empty()) {
|
||||
options.push_back("");
|
||||
}
|
||||
// Buy units as long as we have room and can afford it.
|
||||
while(recruit_usage(options[rand()%options.size()])) {
|
||||
}
|
||||
do {
|
||||
if (options.empty()) {
|
||||
options.push_back("");
|
||||
}
|
||||
// Buy units as long as we have room and can afford it.
|
||||
}while(recruit_usage(options[rand()%options.size()]));
|
||||
}
|
||||
|
||||
void ai::move_leader_to_goals( const move_map& enemy_dstsrc)
|
||||
|
|
75
src/team.cpp
75
src/team.cpp
|
@ -78,7 +78,7 @@ team::team_info::team_info(const config& cfg) :
|
|||
income(cfg["income"]),
|
||||
income_per_village(),
|
||||
can_recruit(),
|
||||
global_recruitment_pattern(),
|
||||
global_recruitment_pattern(utils::split(cfg["global_recruitment_pattern"])),
|
||||
recruitment_pattern(utils::split(cfg["recruitment_pattern"])),
|
||||
enemies(),
|
||||
team_name(cfg["team_name"]),
|
||||
|
@ -100,6 +100,8 @@ team::team_info::team_info(const config& cfg) :
|
|||
villages_per_scout(),
|
||||
leader_value(0.0),
|
||||
village_value(0.0),
|
||||
aggression_(0.5),
|
||||
caution_(0.25),
|
||||
targets(),
|
||||
share_maps(false),
|
||||
share_view(false),
|
||||
|
@ -111,10 +113,11 @@ team::team_info::team_info(const config& cfg) :
|
|||
{
|
||||
config global_ai_params;
|
||||
const config::child_list& ai_parameters = cfg.get_children("ai");
|
||||
for(config::child_list::const_iterator aiparam = ai_parameters.begin(); aiparam != ai_parameters.end(); ++aiparam) {
|
||||
for(config::child_list::const_reverse_iterator aiparam = ai_parameters.rbegin(); aiparam != ai_parameters.rend(); ++aiparam) {
|
||||
ai_params.push_back(**aiparam);
|
||||
|
||||
if((**aiparam)["turns"].empty() && (**aiparam)["time_of_day"].empty()) {
|
||||
// LOG_NG << "Global ai entry: " << **aiparam << "\n";
|
||||
global_ai_params.append(**aiparam);
|
||||
}
|
||||
}
|
||||
|
@ -190,7 +193,8 @@ team::team_info::team_info(const config& cfg) :
|
|||
|
||||
std::string scouts_val = cfg["villages_per_scout"];
|
||||
|
||||
if(scouts_val.empty()) {
|
||||
if(scouts_val.empty()
|
||||
) {
|
||||
scouts_val = global_ai_params["villages_per_scout"];
|
||||
}
|
||||
|
||||
|
@ -202,7 +206,8 @@ team::team_info::team_info(const config& cfg) :
|
|||
|
||||
std::string leader_val = cfg["leader_value"];
|
||||
|
||||
if(leader_val.empty()) {
|
||||
if(leader_val.empty()
|
||||
) {
|
||||
leader_val = global_ai_params["leader_value"];
|
||||
}
|
||||
|
||||
|
@ -214,7 +219,8 @@ team::team_info::team_info(const config& cfg) :
|
|||
|
||||
std::string village_val = cfg["village_value"];
|
||||
|
||||
if(village_val.empty()) {
|
||||
if(village_val.empty()
|
||||
) {
|
||||
village_val = global_ai_params["village_value"];
|
||||
}
|
||||
|
||||
|
@ -224,16 +230,48 @@ team::team_info::team_info(const config& cfg) :
|
|||
village_value = atof(village_val.c_str());
|
||||
}
|
||||
|
||||
std::string aggression_val = cfg["aggression"];
|
||||
|
||||
if(aggression_val.empty()
|
||||
) {
|
||||
aggression_val = global_ai_params["aggression"];
|
||||
}
|
||||
|
||||
if(aggression_val.empty()) {
|
||||
aggression_ = 0.5;
|
||||
} else {
|
||||
aggression_ = atof(aggression_val.c_str());
|
||||
}
|
||||
|
||||
std::string caution_val = cfg["caution"];
|
||||
|
||||
if(caution_val.empty()
|
||||
) {
|
||||
caution_val = global_ai_params["caution"];
|
||||
}
|
||||
|
||||
if(caution_val.empty()) {
|
||||
caution_ = 1.0;
|
||||
} else {
|
||||
caution_ = atof(caution_val.c_str());
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::string> recruits = utils::split(cfg["recruit"]);
|
||||
for(std::vector<std::string>::const_iterator i = recruits.begin(); i != recruits.end(); ++i) {
|
||||
can_recruit.insert(*i);
|
||||
}
|
||||
|
||||
if(recruitment_pattern.empty()) {
|
||||
if(recruitment_pattern.empty()
|
||||
) {
|
||||
recruitment_pattern =
|
||||
utils::split(global_ai_params["recruitment_pattern"]);
|
||||
LOG_NG << "Recruitment pattern: " << global_ai_params["recruitment_pattern"] << "\n";
|
||||
} else {
|
||||
LOG_NG << "Recruitment pattern from side: " << cfg["recruitment_pattern"] << "\n";
|
||||
}
|
||||
|
||||
|
||||
/* // Default recruitment pattern is to buy 2 fighters for every 1 archer
|
||||
if(recruitment_pattern.empty()) {
|
||||
recruitment_pattern.push_back("fighter");
|
||||
|
@ -314,6 +352,8 @@ void team::team_info::write(config& cfg) const
|
|||
cfg["villages_per_scout"] = str_cast(villages_per_scout);
|
||||
cfg["leader_value"] = str_cast(leader_value);
|
||||
cfg["village_value"] = str_cast(village_value);
|
||||
cfg["aggression"] = str_cast(aggression_);
|
||||
cfg["caution"] = str_cast(caution_);
|
||||
|
||||
for(std::vector<target>::const_iterator tg = targets.begin(); tg != targets.end(); ++tg) {
|
||||
tg->write(cfg.add_child("target"));
|
||||
|
@ -329,10 +369,21 @@ void team::team_info::write(config& cfg) const
|
|||
|
||||
cfg["recruit"] = can_recruit_str.str();
|
||||
|
||||
std::stringstream global_recruit_pattern_str;
|
||||
for(std::vector<std::string>::const_iterator p = global_recruitment_pattern.begin();
|
||||
p != global_recruitment_pattern.end(); ++p) {
|
||||
if(p != global_recruitment_pattern.begin())
|
||||
global_recruit_pattern_str << ",";
|
||||
|
||||
global_recruit_pattern_str << *p;
|
||||
}
|
||||
|
||||
cfg["global_recruitment_pattern"] = global_recruit_pattern_str.str();
|
||||
|
||||
std::stringstream recruit_pattern_str;
|
||||
std::vector<std::string> rp = global_recruitment_pattern;
|
||||
for(std::vector<std::string>::const_iterator p = rp.begin(); p != rp.end(); ++p) {
|
||||
if(p != rp.begin())
|
||||
for(std::vector<std::string>::const_iterator p = recruitment_pattern.begin();
|
||||
p != recruitment_pattern.end(); ++p) {
|
||||
if(p != recruitment_pattern.begin())
|
||||
recruit_pattern_str << ",";
|
||||
|
||||
recruit_pattern_str << *p;
|
||||
|
@ -359,8 +410,6 @@ team::team(const config& cfg, int gold) :
|
|||
countdown_time_(0),
|
||||
action_bonus_count_(0),
|
||||
aiparams_(),
|
||||
aggression_(0.0),
|
||||
caution_(0.0),
|
||||
enemies_(),
|
||||
seen_(),
|
||||
ally_shroud_(),
|
||||
|
@ -461,8 +510,8 @@ void team::set_time_of_day(int turn, const time_of_day& tod)
|
|||
info_.recruitment_pattern = utils::split(aiparams_["recruitment_pattern"]);
|
||||
if (info_.recruitment_pattern.empty())
|
||||
info_.recruitment_pattern = info_.global_recruitment_pattern;
|
||||
aggression_ = lexical_cast_default<double>(aiparams_["aggression"],0.5);
|
||||
caution_ = lexical_cast_default<double>(aiparams_["caution"],0.25);
|
||||
info_.aggression_ = lexical_cast_default<double>(aiparams_["aggression"],0.5);
|
||||
info_.caution_ = lexical_cast_default<double>(aiparams_["caution"],0.25);
|
||||
}
|
||||
|
||||
bool team::calculate_enemies(size_t index) const
|
||||
|
|
18
src/team.hpp
18
src/team.hpp
|
@ -105,6 +105,8 @@ public:
|
|||
|
||||
int villages_per_scout;
|
||||
double leader_value, village_value;
|
||||
//cached values for ai parameters
|
||||
double aggression_, caution_;
|
||||
|
||||
std::vector<target> targets;
|
||||
|
||||
|
@ -160,6 +162,16 @@ public:
|
|||
std::set<std::string>& recruits() { return info_.can_recruit; }
|
||||
const std::vector<std::string>& recruitment_pattern() const
|
||||
{ return info_.recruitment_pattern; }
|
||||
bool remove_recruitment_pattern_entry(const std::string& key)
|
||||
{
|
||||
std::vector<std::string>::iterator itor = std::find(info_.recruitment_pattern.begin(),
|
||||
info_.recruitment_pattern.end(),
|
||||
key);
|
||||
if (itor == info_.recruitment_pattern.end())
|
||||
return false;
|
||||
info_.recruitment_pattern.erase(itor);
|
||||
return true;
|
||||
}
|
||||
const std::string& name() const
|
||||
{ return info_.name; }
|
||||
const std::string& save_id() const { return info_.save_id; }
|
||||
|
@ -195,8 +207,8 @@ public:
|
|||
seen_[index] = true;
|
||||
}
|
||||
|
||||
double aggression() const { return aggression_; }
|
||||
double caution() const { return caution_; }
|
||||
double aggression() const { return info_.aggression_; }
|
||||
double caution() const { return info_.caution_; }
|
||||
|
||||
team_info::CONTROLLER controller() const { return info_.controller; }
|
||||
bool is_human() const { return info_.controller == team_info::HUMAN; }
|
||||
|
@ -295,8 +307,6 @@ private:
|
|||
|
||||
config aiparams_;
|
||||
|
||||
//cached values for ai parameters
|
||||
double aggression_, caution_;
|
||||
|
||||
bool calculate_enemies(size_t index) const;
|
||||
bool calculate_is_enemy(size_t index) const;
|
||||
|
|
Loading…
Add table
Reference in a new issue