43 #define DBG_AI_GOAL LOG_STREAM(debug, log_ai_goal) 44 #define LOG_AI_GOAL LOG_STREAM(info, log_ai_goal) 45 #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") {
123 value_ = v->to_double(0);
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") {
176 if (!filter_ptr_)
return;
178 std::set<map_location>
items;
179 filter_ptr_->get_locations(items);
182 LOG_AI_GOAL <<
"found explicit target location ... " << loc <<
" with value: " <<
value();
183 *target_list =
target(loc,
value(), ai_target::type::xplicit);
198 if (!
cfg_[
"engine"].empty() &&
cfg_[
"engine"] !=
"cpp") {
207 radius_ = (*v).to_int(1);
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(),
274 value_ *
static_cast<double>(radius_ - distance) /
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());
328 if (get_list().find(name) != get_list().end()) {
329 ERR_AI_GOAL <<
"Error: Attempt to double-register goal " << name;
static std::unique_ptr< class sdl_event_handler > handler_
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
virtual void add_targets(std::back_insert_iterator< std::vector< target >> target_list)
virtual const unit_map & units() const override
This class represents a single unit of a specific type.
virtual bool is_active(const std::string &time_of_day, const std::string &turns) const override
Variant for storing WML attributes.
static lg::log_domain log_ai_goal("ai/goal")
bool has_attribute(config_key_type key) const
target_location_goal(readonly_context &context, const config &cfg)
virtual std::string get_id() 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.
goal(readonly_context &context, const config &cfg)
const std::vector< std::string > items
std::shared_ptr< lua_ai_action_handler > handler_
virtual void add_targets(std::back_insert_iterator< std::vector< target >> target_list)
Lua object(value) wrapper implementation.
A small explanation about what's going on here: Each action has access to two game_info objects First...
virtual std::string get_engine() const
filter_context * filter_con
virtual void add_targets(std::back_insert_iterator< std::vector< target >> target_list)
bool is_enemy(int n) const
Managing the AIs lifecycle - headers TODO: Refactor history handling and internal commands...
lua_goal(readonly_context &context, const config &cfg)
Encapsulates the map of the game.
bool redeploy(const config &cfg)
virtual const team & current_team() const override
std::shared_ptr< terrain_filter > filter_ptr_
virtual side_number get_side() const override
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)
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.
protect_goal(readonly_context &context, const config &cfg, bool protect_unit)
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.
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.
A config object defines a single node in a WML file, with access to child nodes.
virtual std::string get_name() const
virtual config to_config() const
void init_readonly_context_proxy(readonly_context &target)