41 #define DBG_AI_GOAL LOG_STREAM(debug, log_ai_goal)
42 #define LOG_AI_GOAL LOG_STREAM(info, log_ai_goal)
43 #define ERR_AI_GOAL LOG_STREAM(err, log_ai_goal)
63 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. ";
92 return cfg_[
"engine"];
115 if (!
cfg_[
"engine"].empty() &&
cfg_[
"engine"] !=
"cpp") {
132 if (!criteria)
return;
138 LOG_AI_GOAL <<
"found explicit target unit at ... " << u.get_location() <<
" with value: " <<
value();
139 *target_list =
target(u.get_location(),
value(), ai_target::type::xplicit);
154 if (!
cfg_[
"engine"].empty() &&
cfg_[
"engine"] !=
"cpp") {
176 std::set<map_location> items;
180 LOG_AI_GOAL <<
"found explicit target location ... " << loc <<
" with value: " <<
value();
181 *target_list =
target(loc,
value(), ai_target::type::xplicit);
196 if (!
cfg_[
"engine"].empty() &&
cfg_[
"engine"] !=
"cpp") {
220 std::string goal_type;
222 goal_type =
"protect_unit";
224 goal_type =
"protect_location";
228 LOG_AI_GOAL <<
"skipping " << goal_type <<
" goal - not active";
234 LOG_AI_GOAL <<
"skipping " << goal_type <<
" goal - no criteria given";
242 std::set<map_location> items;
245 for (
const unit &u : units)
251 && (!u.invisible(u.get_location()) || u.is_visible_to_team(
current_team(),
false)))
253 DBG_AI_GOAL <<
"side " <<
get_side() <<
": in " << goal_type <<
": " << u.get_location() <<
" should be protected";
254 items.insert(u.get_location());
264 for (
const unit &u : units)
268 !u.invisible(u.get_location()))
270 DBG_AI_GOAL <<
"side " <<
get_side() <<
": in " << goal_type <<
": found threat target. " << u.get_location() <<
" is a threat to "<< loc;
271 *target_list =
target(u.get_location(),
273 radius_, ai_target::type::threat);
283 , protect_unit_(protect_unit)
295 code_ = cfg[
"code"].str();
310 std::shared_ptr<lua_object<std::vector<target>>> l_obj = std::make_shared<lua_object<std::vector<target>>>();
313 handler_->handle(
c, empty_cfg,
true, l_obj);
315 std::vector < target > targets = *(l_obj->get());
327 ERR_AI_GOAL <<
"Error: Attempt to double-register goal " << name;
static factory_map & get_list()
bool is_duplicate(const std::string &name)
bool redeploy(const config &cfg)
virtual config to_config() const
virtual std::string get_engine() const
virtual std::string get_name() const
virtual std::string get_id() const
goal(readonly_context &context, const config &cfg)
virtual void add_targets(std::back_insert_iterator< std::vector< target >> target_list)
lua_goal(readonly_context &context, const config &cfg)
std::shared_ptr< lua_ai_action_handler > handler_
virtual void add_targets(std::back_insert_iterator< std::vector< target >> target_list)
std::shared_ptr< terrain_filter > filter_ptr_
protect_goal(readonly_context &context, const config &cfg, bool protect_unit)
virtual void add_targets(std::back_insert_iterator< std::vector< target >> target_list)
virtual const team & current_team() const override
virtual bool is_active(const std::string &time_of_day, const std::string &turns) const override
void init_readonly_context_proxy(readonly_context &target)
virtual side_number get_side() const override
Get the side number.
std::shared_ptr< terrain_filter > filter_ptr_
target_location_goal(readonly_context &context, 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)
target_unit_goal(readonly_context &context, const config &cfg)
Variant for storing WML attributes.
A config object defines a single node in a WML file, with access to child nodes.
const config & child_or_empty(config_key_type key) const
Returns the first child with the given key, or an empty config if there is none.
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
bool has_attribute(config_key_type key) const
const attribute_value * get(config_key_type key) const
Returns a pointer to the attribute with the given key or nullptr if it does not exist.
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
virtual const unit_map & units() const override
Container associating units to locations.
This class represents a single unit of a specific type.
A variable-expanding proxy for the config class.
std::size_t distance_between(const map_location &a, const map_location &b)
Function which gives the number of hexes between two tiles (i.e.
Standard logging facilities (interface).
Lua object(value) wrapper implementation.
A small explanation about what's going on here: Each action has access to two game_info objects First...
static lg::log_domain log_ai_goal("ai/goal")
static std::unique_ptr< class sdl_event_handler > handler_
game_lua_kernel * lua_kernel
filter_context * filter_con
Encapsulates the map of the game.