Author: suokko
Date: Tue Sep 16 21:26:36 2008
New Revision: 29497
URL: http://svn.gna.org/viewcvs/wesnoth?rev=29497&view=rev
Log:
Fix forever loop if AI has too much gold when recruiting
Modified:
trunk/src/ai.cpp
trunk/src/ai.hpp
trunk/src/formula_ai.cpp
Modified: trunk/src/ai.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai.cpp?rev=29497&r1=29496&r2=29497&view=diff
==============================================================================
--- trunk/src/ai.cpp (original)
+++ trunk/src/ai.cpp Tue Sep 16 21:26:36 2008
@@ -298,7 +298,7 @@
avoid_(),
unit_stats_cache_(),
attack_depth_(0),
- recruiting_prefered_(false),
+ recruiting_prefered_(0),
master_(info_.master)
{
info_.master = false;
@@ -970,10 +970,13 @@
void ai::evaluate_recruiting_value(unit_map::iterator leader)
{
- ERR_AI << current_team().num_pos_recruits_to_force() << "\n";
+ if (recruiting_prefered_ == 2)
+ {
+ recruiting_prefered_ = 0;
+ return;
+ }
if (current_team().num_pos_recruits_to_force()< 0.01f)
{
- ERR_AI << "Recruiting force code disabled\n";
return;
}
@@ -987,7 +990,7 @@
const float gold = current_team().gold();
const float unit_price = current_team().average_recruit_price();
recruiting_prefered_ = (gold/unit_price) - free_slots >
current_team().num_pos_recruits_to_force();
- ERR_AI << "recruiting prefered: " << (recruiting_prefered_?"yes":"no")
<<
+ DBG_AI << "recruiting prefered: " << (recruiting_prefered_?"yes":"no")
<<
" units to recruit: " << (gold/unit_price) <<
" unit_price: " << unit_price <<
" free slots: " << free_slots <<
@@ -1134,9 +1137,12 @@
if (map_.is_keep(leader->first))
{
- do_recruitment();
- if (recruiting_prefered_)
+ if (do_recruitment())
{
+ do_move();
+ return;
+ } else if (recruiting_prefered_){
+ recruiting_prefered_ = 2;
do_move();
return;
}
@@ -1926,14 +1932,16 @@
if (options.empty()) {
options.push_back("");
}
+ bool ret = false;
// Buy units as long as we have room and can afford it.
while (recruit_usage(options[rand()%options.size()])) {
+ ret = true;
options = current_team().recruitment_pattern();
if (options.empty()) {
options.push_back("");
}
}
- return true;
+ return ret;
}
void ai::move_leader_to_goals( const move_map& enemy_dstsrc)
@@ -2399,7 +2407,7 @@
if(itor == ais.end())
{
LOG_AI << "manager did not find AI - creating..." << std::endl ;
- ai_obj.reset(create_ai(ai_algo, ai_info));
+ ai_obj = create_ai(ai_algo, ai_info);
LOG_AI << "Asking newly created AI if it wants to be managed." <<
std::endl ;
if( ai_obj->manager_manage_ai() )
{
Modified: trunk/src/ai.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai.hpp?rev=29497&r1=29496&r2=29497&view=diff
==============================================================================
--- trunk/src/ai.hpp (original)
+++ trunk/src/ai.hpp Tue Sep 16 21:26:36 2008
@@ -378,7 +378,7 @@
const std::map<gamemap::location,paths>& possible_moves,
const std::multimap<gamemap::location,gamemap::location>&
enemy_dstsrc) const;
- bool recruiting_prefered_;
+ int recruiting_prefered_;
protected:
bool master_;
};
Modified: trunk/src/formula_ai.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/formula_ai.cpp?rev=29497&r1=29496&r2=29497&view=diff
==============================================================================
--- trunk/src/formula_ai.cpp (original)
+++ trunk/src/formula_ai.cpp Tue Sep 16 21:26:36 2008
@@ -1637,14 +1637,16 @@
vars.push_back(var);
}
+ bool ret = false;
for(std::vector<variant>::const_iterator i = vars.begin(); i !=
vars.end(); ++i) {
if(!i->is_string()) {
return false;
}
if(!recruit(i->as_string())) {
- return true;
- }
+ return ret;
+ }
+ ret = true;
}
return do_recruitment();
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits