39 #include <boost/lexical_cast.hpp>
46 #define DBG_AI_GOAL LOG_STREAM(debug, log_ai_goal)
47 #define LOG_AI_GOAL LOG_STREAM(info, log_ai_goal)
48 #define ERR_AI_GOAL LOG_STREAM(err, log_ai_goal)
60 LOG_AI_GOAL <<
"side " <<
get_side() <<
" : " <<
" created goal with name=[" <<
cfg_[
"name"] <<
"]" << std::endl;
70 ERR_AI_GOAL <<
"side " <<
get_side() <<
" : " <<
" tried to create goal with name=[" <<
cfg_[
"name"] <<
"], but the [" <<
cfg_[
"engine"] <<
"] engine did not recognize that type of goal. " << std::endl;
103 return cfg_[
"engine"];
130 if (!
cfg_[
"engine"].empty() &&
cfg_[
"engine"] !=
"cpp") {
138 }
catch (boost::bad_lexical_cast){
152 if (!criteria)
return;
158 LOG_AI_GOAL <<
"found explicit target unit at ... " << u.get_location() <<
" with value: " <<
value() <<
"\n";
159 *target_list =
target(u.get_location(),
value(), target::TYPE::EXPLICIT);
177 if (!
cfg_[
"engine"].empty() &&
cfg_[
"engine"] !=
"cpp") {
185 }
catch (boost::bad_lexical_cast){
204 std::set<map_location>
items;
208 LOG_AI_GOAL <<
"found explicit target location ... " << loc <<
" with value: " <<
value() << std::endl;
209 *target_list =
target(loc,
value(), target::TYPE::EXPLICIT);
226 if (!
cfg_[
"engine"].empty() &&
cfg_[
"engine"] !=
"cpp") {
234 }
catch (boost::bad_lexical_cast){
235 ERR_AI_GOAL <<
"bad value of protect_goal"<<std::endl;
242 }
catch (boost::bad_lexical_cast){
243 ERR_AI_GOAL <<
"bad protection radius of protect_goal"<<std::endl;
264 goal_type =
"protect_unit";
266 goal_type =
"protect_location";
270 LOG_AI_GOAL <<
"skipping " << goal_type <<
" goal - not active" << std::endl;
276 LOG_AI_GOAL <<
"skipping " << goal_type <<
" goal - no criteria given" << std::endl;
284 std::set<map_location>
items;
287 for (
const unit &u : units)
291 DBG_AI_GOAL <<
"side " <<
get_side() <<
": in " << goal_type <<
": " << u.get_location() <<
" should be protected\n";
292 items.insert(u.get_location());
298 DBG_AI_GOAL <<
"side " <<
get_side() <<
": seaching for threats in "+goal_type+
" goal" << std::endl;
302 for (
const unit &u : units)
306 !u.invisible(u.get_location()))
308 DBG_AI_GOAL <<
"side " <<
get_side() <<
": in " << goal_type <<
": found threat target. " << u.get_location() <<
" is a threat to "<< loc <<
'\n';
309 *target_list =
target(u.get_location(),
311 radius_, target::TYPE::THREAT);
323 , protect_unit_(protect_unit)
335 code_ = cfg[
"code"].str();
339 ERR_AI_GOAL <<
"side " <<
get_side() <<
" : Error creating Lua goal (missing code= key)" << std::endl;
355 std::vector < target > targets = *(l_obj->get());
362 ERR_AI_GOAL <<
"A Lua goal returned a target of an unknown type (\"" << e.
value() <<
"\"; unfortunately, the engine cannot recover from this error. As a result, all targets returned by the goal have been lost.\n";
372 ERR_AI_GOAL <<
"Error: Attempt to double-register goal " << name << std::endl;
virtual side_number get_side() const
Get the side number.
virtual void add_targets(std::back_insert_iterator< std::vector< target > > target_list)
virtual void add_targets(std::back_insert_iterator< std::vector< target > > target_list)
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
boost::shared_ptr< lua_ai_action_handler > handler_
static lg::log_domain log_ai_goal("ai/goal")
target_location_goal(readonly_context &context, const config &cfg)
bool is_enemy(int n) const
static factory_map & get_list()
goal(readonly_context &context, const config &cfg)
const std::vector< std::string > items
const config & child_or_empty(const std::string &key) const
Returns the first child with the given key, or an empty config if there is none.
To lexical_cast(From value)
Lexical cast converts one type to another.
const char * value() const
Lua object(value) wrapper implementation.
Variant for storing WML attributes.
virtual std::string get_engine() const
boost::shared_ptr< terrain_filter > filter_ptr_
A small explanation about what's going on here: Each action has access to two game_info objects First...
size_t distance_between(const map_location &a, const map_location &b)
Function which gives the number of hexes between two tiles (i.e.
filter_context * filter_con
virtual void add_targets(std::back_insert_iterator< std::vector< target > > target_list)
Managing the AIs lifecycle - headers.
lua_goal(readonly_context &context, const config &cfg)
virtual config to_config() const
virtual bool is_active(const std::string &time_of_day, const std::string &turns) const
Encapsulates the map of the game.
virtual std::string get_id() const
bool redeploy(const config &cfg)
virtual void add_targets(std::back_insert_iterator< std::vector< target > > target_list)
virtual void add_targets(std::back_insert_iterator< std::vector< target > > target_list)
ai::lua_ai_action_handler * create_lua_ai_action_handler(char const *code, ai::lua_ai_context &context)
boost::shared_ptr< terrain_filter > filter_ptr_
GLuint const GLchar * name
virtual const team & current_team() const
const attribute_value * get(const std::string &key) const
Returns a pointer to the attribute with the given key or nullptr if it does not exist.
virtual std::string get_name() const
tformula< unsigned > radius_
The radius of the circle.
bool has_attribute(const std::string &key) const
protect_goal(readonly_context &context, const config &cfg, bool protect_unit)
bool find(E event, F functor)
Tests whether an event handler is available.
config & child(const std::string &key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
A variable-expanding proxy for the config class.
Standard logging facilities (interface).
target_unit_goal(readonly_context &context, const config &cfg)
bool is_duplicate(const std::string &name)
game_lua_kernel * lua_kernel
Container associating units to locations.
A config object defines a single node in a WML file, with access to child nodes.
GLsizei const GLcharARB ** string
void init_readonly_context_proxy(readonly_context &target)