Added config serialization of various ai contexts.
This commit is contained in:
parent
97967b4a3b
commit
54ddcc51ba
5 changed files with 74 additions and 7 deletions
|
@ -223,6 +223,17 @@ void readonly_context_impl::on_readonly_context_create() {
|
|||
}
|
||||
|
||||
|
||||
config side_context_impl::to_side_context_config() const
|
||||
{
|
||||
return config();
|
||||
}
|
||||
|
||||
config readwrite_context_impl::to_readwrite_context_config() const
|
||||
{
|
||||
return config();
|
||||
}
|
||||
|
||||
|
||||
config readonly_context_impl::to_readonly_context_config() const
|
||||
{
|
||||
config cfg;
|
||||
|
|
|
@ -136,6 +136,12 @@ public:
|
|||
virtual side_context& get_side_context() = 0;
|
||||
|
||||
|
||||
/**
|
||||
* serialize this context to config
|
||||
*/
|
||||
virtual config to_side_context_config() const = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Get the value of the recursion counter
|
||||
*/
|
||||
|
@ -384,6 +390,12 @@ public:
|
|||
|
||||
virtual game_info& get_info_w() = 0;
|
||||
|
||||
|
||||
/**
|
||||
* serialize this context to config
|
||||
*/
|
||||
virtual config to_readwrite_context_config() const = 0;
|
||||
|
||||
};
|
||||
|
||||
//proxies
|
||||
|
@ -423,6 +435,13 @@ public:
|
|||
return target_->get_recursion_count();
|
||||
}
|
||||
|
||||
|
||||
virtual config to_side_context_config() const
|
||||
{
|
||||
return target_->to_side_context_config();
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
side_context *target_;
|
||||
};
|
||||
|
@ -918,6 +937,13 @@ public:
|
|||
{
|
||||
return target_->get_recursion_count();
|
||||
}
|
||||
|
||||
|
||||
virtual config to_readwrite_context_config() const
|
||||
{
|
||||
return target_->to_readwrite_context_config();
|
||||
}
|
||||
|
||||
private:
|
||||
readwrite_context *target_;
|
||||
};
|
||||
|
@ -926,7 +952,7 @@ private:
|
|||
//implementation
|
||||
class side_context_impl : public side_context {
|
||||
public:
|
||||
side_context_impl(side_number side)
|
||||
side_context_impl(side_number side, const config &/*cfg*/)
|
||||
: side_(side), recursion_counter_(0)
|
||||
{
|
||||
}
|
||||
|
@ -952,6 +978,9 @@ public:
|
|||
|
||||
virtual int get_recursion_count() const;
|
||||
|
||||
|
||||
virtual config to_side_context_config() const;
|
||||
|
||||
private:
|
||||
side_number side_;
|
||||
recursion_counter recursion_counter_;
|
||||
|
@ -1432,7 +1461,7 @@ public:
|
|||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
readwrite_context_impl(readonly_context &context)
|
||||
readwrite_context_impl(readonly_context &context, const config &/*cfg*/)
|
||||
: recursion_counter_(context.get_recursion_count())
|
||||
{
|
||||
init_readonly_context_proxy(context);
|
||||
|
@ -1452,6 +1481,9 @@ public:
|
|||
|
||||
virtual int get_recursion_count() const;
|
||||
|
||||
|
||||
virtual config to_readwrite_context_config() const;
|
||||
|
||||
private:
|
||||
recursion_counter recursion_counter_;
|
||||
};
|
||||
|
|
|
@ -379,5 +379,9 @@ void default_ai_context_impl::clear_additional_targets() const
|
|||
additional_targets_.clear();
|
||||
}
|
||||
|
||||
config default_ai_context_impl::to_default_ai_context_config() const
|
||||
{
|
||||
return config();
|
||||
}
|
||||
|
||||
} //of namespace ai
|
||||
|
|
|
@ -171,6 +171,10 @@ public:
|
|||
|
||||
virtual int rate_terrain(const unit& u, const map_location& loc) const = 0;
|
||||
|
||||
|
||||
virtual config to_default_ai_context_config() const = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -246,6 +250,10 @@ public:
|
|||
return target_->suitable_keep(leader_location,leader_paths);
|
||||
}
|
||||
|
||||
virtual config to_default_ai_context_config() const
|
||||
{
|
||||
return target_->to_default_ai_context_config();
|
||||
}
|
||||
|
||||
private:
|
||||
default_ai_context *target_;
|
||||
|
@ -258,7 +266,7 @@ public:
|
|||
int count_free_hexes_in_castle(const map_location& loc, std::set<map_location> &checked_hexes);
|
||||
|
||||
|
||||
default_ai_context_impl(readwrite_context &context)
|
||||
default_ai_context_impl(readwrite_context &context, const config &/*cfg*/)
|
||||
: recursion_counter_(context.get_recursion_count()),additional_targets_()
|
||||
{
|
||||
init_readwrite_context_proxy(context);
|
||||
|
@ -301,6 +309,8 @@ public:
|
|||
virtual const map_location& suitable_keep( const map_location& leader_location, const paths& leader_paths );
|
||||
|
||||
|
||||
virtual config to_default_ai_context_config() const;
|
||||
|
||||
private:
|
||||
recursion_counter recursion_counter_;
|
||||
mutable std::vector<target> additional_targets_;//@todo: refactor this
|
||||
|
|
|
@ -63,7 +63,7 @@ holder::holder( side_number side, const config &cfg )
|
|||
void holder::init( side_number side )
|
||||
{
|
||||
if (side_context_ == NULL) {
|
||||
side_context_ = new side_context_impl(side);//@todo 1.7.3 add config
|
||||
side_context_ = new side_context_impl(side,cfg_);
|
||||
} else {
|
||||
side_context_->set_side(side);
|
||||
}
|
||||
|
@ -72,10 +72,10 @@ void holder::init( side_number side )
|
|||
readonly_context_->on_readonly_context_create();
|
||||
}
|
||||
if (readwrite_context_ == NULL){
|
||||
readwrite_context_ = new readwrite_context_impl(*readonly_context_);//@todo 1.7.3 add config
|
||||
readwrite_context_ = new readwrite_context_impl(*readonly_context_,cfg_);
|
||||
}
|
||||
if (default_ai_context_ == NULL){
|
||||
default_ai_context_ = new default_ai_context_impl(*readwrite_context_);//@todo 1.7.3 add config
|
||||
default_ai_context_ = new default_ai_context_impl(*readwrite_context_,cfg_);
|
||||
}
|
||||
if (!this->ai_){
|
||||
ai_ = boost::shared_ptr<ai_composite>(new ai_composite(*default_ai_context_,cfg_));
|
||||
|
@ -147,10 +147,20 @@ config holder::to_config() const
|
|||
} else {
|
||||
config cfg = ai_->to_config();
|
||||
cfg["version"] = "10703";
|
||||
if (this->side_context_!=NULL) {
|
||||
cfg.merge_with(this->side_context_->to_side_context_config());
|
||||
}
|
||||
if (this->readonly_context_!=NULL) {
|
||||
cfg.merge_with(this->readonly_context_->to_readonly_context_config());
|
||||
}
|
||||
return cfg;//@todo 1.7.3: include all other upper contexts
|
||||
if (this->readwrite_context_!=NULL) {
|
||||
cfg.merge_with(this->readwrite_context_->to_readwrite_context_config());
|
||||
}
|
||||
if (this->default_ai_context_!=NULL) {
|
||||
cfg.merge_with(this->default_ai_context_->to_default_ai_context_config());
|
||||
}
|
||||
|
||||
return cfg;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue