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)
65 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. ";
94 return cfg_[
"engine"];
117 if (!
cfg_[
"engine"].empty() &&
cfg_[
"engine"] !=
"cpp") {
134 if (!criteria)
return;
140 LOG_AI_GOAL <<
"found explicit target unit at ... " << u.get_location() <<
" with value: " <<
value();
141 *target_list =
target(u.get_location(),
value(), ai_target::type::xplicit);
156 if (!
cfg_[
"engine"].empty() &&
cfg_[
"engine"] !=
"cpp") {
178 std::set<map_location> items;
198 if (!
cfg_[
"engine"].empty() &&
cfg_[
"engine"] !=
"cpp") {
222 std::string goal_type;
224 goal_type =
"protect_unit";
226 goal_type =
"protect_location";
230 LOG_AI_GOAL <<
"skipping " << goal_type <<
" goal - not active";
236 LOG_AI_GOAL <<
"skipping " << goal_type <<
" goal - no criteria given";
244 std::set<map_location> items;
247 for (
const unit &u : units)
253 && (!u.invisible(u.get_location()) || u.is_visible_to_team(
current_team(),
false)))
255 DBG_AI_GOAL <<
"side " <<
get_side() <<
": in " << goal_type <<
": " << u.get_location() <<
" should be protected";
256 items.insert(u.get_location());
266 for (
const unit &u : units)
270 !u.invisible(u.get_location()))
272 DBG_AI_GOAL <<
"side " <<
get_side() <<
": in " << goal_type <<
": found threat target. " << u.get_location() <<
" is a threat to "<<
loc;
273 *target_list =
target(u.get_location(),
275 radius_, ai_target::type::threat);
285 , protect_unit_(protect_unit)
297 code_ = cfg[
"code"].str();
312 std::shared_ptr<lua_object<std::vector<target>>> l_obj = std::make_shared<lua_object<std::vector<target>>>();
315 handler_->handle(
c, empty_cfg,
true, l_obj);
317 std::vector < target > targets = *(l_obj->get());
329 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
auto * find(Container &container, const Value &value)
Convenience wrapper for using find on a container without needing to comare to end()
Encapsulates the map of the game.