ai/composite/aspect.cpp

Go to the documentation of this file.
00001 /* $Id: aspect.cpp 52533 2012-01-07 02:35:17Z shadowmaster $ */
00002 /*
00003    Copyright (C) 2009 - 2012 by Yurii Chernyi <terraninfo@terraninfo.net>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 /**
00017  * @file
00018  */
00019 
00020 #include "aspect.hpp"
00021 #include "../manager.hpp"
00022 #include "../../log.hpp"
00023 
00024 namespace ai {
00025 
00026 static lg::log_domain log_ai_aspect("ai/aspect");
00027 #define DBG_AI_ASPECT LOG_STREAM(debug, log_ai_aspect)
00028 #define LOG_AI_ASPECT LOG_STREAM(info, log_ai_aspect)
00029 #define WRN_AI_ASPECT LOG_STREAM(warn, log_ai_aspect)
00030 #define ERR_AI_ASPECT LOG_STREAM(err, log_ai_aspect)
00031 
00032 aspect::aspect(readonly_context &context, const config &cfg, const std::string &id):
00033     valid_(false), valid_variant_(false), valid_lua_(false), cfg_(cfg),
00034     invalidate_on_turn_start_(cfg["invalidate_on_turn_start"].to_bool(true)),
00035     invalidate_on_tod_change_(cfg["invalidate_on_tod_change"].to_bool(true)),
00036     invalidate_on_gamestate_change_(cfg["invalidate_on_gamestate_change"].to_bool()),
00037     invalidate_on_minor_gamestate_change_(cfg["invalidate_on_minor_gamestate_change"].to_bool()),
00038     engine_(cfg["engine"]), name_(cfg["name"]), id_(id)
00039     {
00040         DBG_AI_ASPECT << "creating new aspect: engine=["<<engine_<<"], name=["<<name_<<"], id=["<<id_<<"]"<< std::endl;
00041         init_readonly_context_proxy(context);
00042         redeploy(cfg,id);
00043     }
00044 
00045 
00046 aspect::~aspect()
00047     {
00048         if (invalidate_on_turn_start_) {
00049             manager::remove_turn_started_observer(this);
00050         }
00051         if (invalidate_on_tod_change_) {
00052             ///@todo 1.9 add tod_changed_observer
00053             //manager::remove_tod_changed_observer(this);
00054         }
00055         if (invalidate_on_gamestate_change_) {
00056             manager::remove_gamestate_observer(this);
00057         }
00058         if (invalidate_on_minor_gamestate_change_) {
00059             ///@todo 1.9 add minor_gamestate_change_observer
00060             //manager::remove_minor_gamestate_observer(this);
00061         }
00062     }
00063 
00064 lg::log_domain& aspect::log()
00065 {
00066     return log_ai_aspect;
00067 }
00068 
00069 void aspect::on_create()
00070 {
00071 }
00072 
00073 bool aspect::redeploy(const config &cfg, const std::string& /*id*/)
00074 {
00075     if (invalidate_on_turn_start_) {
00076         manager::remove_turn_started_observer(this);
00077     }
00078     if (invalidate_on_tod_change_) {
00079         ///@todo 1.9 add tod_changed_observer
00080         //manager::remove_tod_changed_observer(this);
00081     }
00082     if (invalidate_on_gamestate_change_) {
00083         manager::remove_gamestate_observer(this);
00084     }
00085     if (invalidate_on_minor_gamestate_change_) {
00086         ///@todo 1.9 add minor_gamestate_change_observer
00087         //manager::remove_minor_gamestate_observer(this);
00088     }
00089 
00090     valid_ = false;
00091     valid_variant_ =false;
00092     valid_lua_ = false;
00093     cfg_ = cfg;
00094     invalidate_on_turn_start_ = cfg["invalidate_on_turn_start"].to_bool(true);
00095     invalidate_on_tod_change_ = cfg["invalidate_on_tod_change"].to_bool(true);
00096     invalidate_on_gamestate_change_ = cfg["invalidate_on_gamestate_change"].to_bool();
00097     invalidate_on_minor_gamestate_change_ = cfg["invalidate_on_minor_gamestate_change"].to_bool();
00098     engine_ = cfg["engine"].str();
00099     name_ = cfg["name"].str();
00100     id_ = cfg["id"].str();
00101     DBG_AI_ASPECT << "redeploying aspect: engine=["<<engine_<<"], name=["<<name_<<"], id=["<<id_<<"]"<< std::endl;
00102     if (invalidate_on_turn_start_) {
00103         manager::add_turn_started_observer(this);
00104     }
00105     if (invalidate_on_tod_change_) {
00106         ///@todo 1.9 add tod_changed_observer
00107         //manager::add_tod_changed_observer(this);
00108     }
00109     if (invalidate_on_gamestate_change_) {
00110         manager::add_gamestate_observer(this);
00111     }
00112     if (invalidate_on_minor_gamestate_change_) {
00113         ///@todo 1.9 add minor_gamestate_change_observer
00114         //manager::add_minor_gamestate_observer(this);
00115     }
00116     return true;
00117 }
00118 
00119 config aspect::to_config() const
00120 {
00121     config cfg;
00122     cfg["invalidate_on_turn_start"] = invalidate_on_turn_start_;
00123     cfg["invalidate_on_tod_change"] = invalidate_on_tod_change_;
00124     cfg["invalidate_on_gamestate_change"] = invalidate_on_gamestate_change_;
00125     cfg["invalidate_on_minor_gamestate_change"] = invalidate_on_minor_gamestate_change_;
00126     cfg["engine"] = engine_;
00127     cfg["name"] = name_;
00128     cfg["id"] = id_;
00129     return cfg;
00130 }
00131 
00132 
00133 bool aspect::delete_all_facets()
00134 {
00135     return false;
00136 }
00137 
00138 known_aspect::known_aspect(const std::string &name)
00139     : name_(name)
00140 {
00141 }
00142 
00143 const std::string& known_aspect::get_name() const
00144 {
00145     return name_;
00146 }
00147 
00148 known_aspect::~known_aspect()
00149 {
00150 }
00151 
00152 } //end of namespace ai
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Wed May 23 2012 01:02:30 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs