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) 57 LOG_AI_GOAL <<
"side " <<
get_side() <<
" : " <<
" created goal with name=[" <<
cfg_[
"name"] <<
"]" << std::endl;
67 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;
100 return cfg_[
"engine"];
127 if (!
cfg_[
"engine"].empty() &&
cfg_[
"engine"] !=
"cpp") {
133 value_ = v->to_double(0);
144 if (!criteria)
return;
150 LOG_AI_GOAL <<
"found explicit target unit at ... " << u.get_location() <<
" with value: " << value() <<
"\n";
151 *target_list =
target(u.get_location(), value(), target::TYPE::EXPLICIT);
169 if (!
cfg_[
"engine"].empty() &&
cfg_[
"engine"] !=
"cpp") {
189 if (!filter_ptr_)
return;
191 std::set<map_location>
items;
192 filter_ptr_->get_locations(items);
195 LOG_AI_GOAL <<
"found explicit target location ... " << loc <<
" with value: " <<
value() << std::endl;
196 *target_list =
target(loc,
value(), target::TYPE::EXPLICIT);
213 if (!
cfg_[
"engine"].empty() &&
cfg_[
"engine"] !=
"cpp") {
222 radius_ = (*v).to_int(1);
239 std::string goal_type;
241 goal_type =
"protect_unit";
243 goal_type =
"protect_location";
247 LOG_AI_GOAL <<
"skipping " << goal_type <<
" goal - not active" << std::endl;
253 LOG_AI_GOAL <<
"skipping " << goal_type <<
" goal - no criteria given" << std::endl;
261 std::set<map_location>
items;
264 for (
const unit &u : units)
270 && (!u.invisible(u.get_location()) || u.is_visible_to_team(
current_team(),
false)))
272 DBG_AI_GOAL <<
"side " <<
get_side() <<
": in " << goal_type <<
": " << u.get_location() <<
" should be protected\n";
273 items.insert(u.get_location());
279 DBG_AI_GOAL <<
"side " <<
get_side() <<
": searching for threats in "+goal_type+
" goal" << std::endl;
283 for (
const unit &u : units)
287 !u.invisible(u.get_location()))
289 DBG_AI_GOAL <<
"side " <<
get_side() <<
": in " << goal_type <<
": found threat target. " << u.get_location() <<
" is a threat to "<< loc <<
'\n';
290 *target_list =
target(u.get_location(),
291 value_ *
static_cast<double>(radius_ - distance) /
292 radius_, target::TYPE::THREAT);
304 , protect_unit_(protect_unit)
316 code_ = cfg[
"code"].str();
320 ERR_AI_GOAL <<
"side " <<
get_side() <<
" : Error creating Lua goal (missing code= key)" << std::endl;
331 std::shared_ptr<lua_object<std::vector<target>>> l_obj = std::make_shared<lua_object<std::vector<target>>>();
335 std::vector < target > targets = *(l_obj->get());
342 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";
351 if (get_list().
find(name) != get_list().end()) {
352 ERR_AI_GOAL <<
"Error: Attempt to double-register goal " << name << std::endl;
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)
std::shared_ptr< lua_ai_action_handler > handler_
const std::vector< std::string > items
virtual void add_targets(std::back_insert_iterator< std::vector< target >> target_list)
Lua object(value) wrapper implementation.
static const char * name(const std::vector< SDL_Joystick *> &joysticks, const std::size_t index)
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)
const char * value() const noexcept
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)
bool find(E event, F functor)
Tests whether an event handler is available.
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)