Author: crab
Date: Mon Apr 13 14:13:10 2009
New Revision: 34856

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34856&view=rev
Log:
Fix bug with console ai being sometimes constructed with incorrect side number

Modified:
    trunk/src/ai_manager.cpp
    trunk/src/ai_manager.hpp

Modified: trunk/src/ai_manager.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai_manager.cpp?rev=34856&r1=34855&r2=34856&view=diff
==============================================================================
--- trunk/src/ai_manager.cpp (original)
+++ trunk/src/ai_manager.cpp Mon Apr 13 14:13:10 2009
@@ -55,10 +55,10 @@
 }
 
 
-void ai_holder::init()
+void ai_holder::init( int side )
 {
        LOG_AI_MANAGER << describe_ai() << "Preparing to create new managed 
master AI" << std::endl;
-       this->ai_ = create_ai();
+       this->ai_ = create_ai(side);
        if (this->ai_ == NULL) {
                ERR_AI_MANAGER << describe_ai()<<"AI lazy initialization 
error!" << std::endl;
        }
@@ -75,14 +75,19 @@
 }
 
 
+ai_interface& ai_holder::get_ai_ref( int side )
+{
+       if (this->ai_ == NULL) {
+               this->init(side);
+       }
+       assert(this->ai_ != NULL);
+
+       return *this->ai_;
+}
+
 ai_interface& ai_holder::get_ai_ref()
 {
-       if (this->ai_ == NULL) {
-               this->init();
-       }
-       assert(this->ai_ != NULL);
-
-       return *this->ai_;
+       return get_ai_ref(this->side_);
 }
 
 
@@ -174,10 +179,11 @@
        return true;
 }
 
-ai_interface* ai_holder::create_ai()
-{
+ai_interface* ai_holder::create_ai( int side )
+{
+       assert (side > 0);
        //@note: ai_params and ai_algorithm_type are supposed to be set before 
calling init(  );
-       return ai_manager::create_transient_ai(ai_algorithm_type_,side_,true);
+       return ai_manager::create_transient_ai(ai_algorithm_type_,side,true);
 
 }
 
@@ -713,16 +719,14 @@
 ai_interface& ai_manager::get_command_ai( int side )
 {
        ai_holder& ai_holder = get_command_ai_holder(side);
-       ai_interface& ai = ai_holder.get_ai_ref();
-       ai.set_side(side);
+       ai_interface& ai = ai_holder.get_ai_ref(side);
        return ai;
 }
 
 ai_interface& ai_manager::get_fallback_ai( int side )
 {
        ai_holder& ai_holder = get_fallback_ai_holder(side);
-       ai_interface& ai = ai_holder.get_ai_ref();
-       ai.set_side(side);
+       ai_interface& ai = ai_holder.get_ai_ref(side);
        return ai;
 }
 

Modified: trunk/src/ai_manager.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/ai_manager.hpp?rev=34856&r1=34855&r2=34856&view=diff
==============================================================================
--- trunk/src/ai_manager.hpp (original)
+++ trunk/src/ai_manager.hpp Mon Apr 13 14:13:10 2009
@@ -36,11 +36,12 @@
 public:
        ai_holder(int side, const std::string& ai_algorithm_type);
 
-       void init();
+       void init( int side );
 
        virtual ~ai_holder();
 
        ai_interface& get_ai_ref();
+       ai_interface& get_ai_ref( int side );
 
        const std::string& get_ai_algorithm_type() const;
        void set_ai_algorithm_type(const std::string& ai_algorithm_type);
@@ -75,7 +76,7 @@
        std::vector<config> ai_parameters_;
        int side_;
 
-       ai_interface* create_ai();
+       ai_interface* create_ai( int side );
 };
 
 /**


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to