The Battle for Wesnoth  1.19.7+dev
aspect_attacks.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2024
3  by Yurii Chernyi <terraninfo@terraninfo.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 /**
17  * Aspect: attacks
18  * @file
19  */
20 
21 #pragma once
22 
23 #include "ai/composite/aspect.hpp"
24 #include "units/filter.hpp"
25 
26 namespace ai {
27 
28 namespace ai_default_rca {
29 
30 class aspect_attacks_base : public typesafe_aspect<attacks_vector> {
31 public:
32  aspect_attacks_base(readonly_context &context, const config &cfg, const std::string &id);
33 
34  virtual ~aspect_attacks_base() {}
35 
36  virtual void recalculate() const;
37 
38  virtual bool is_allowed_attacker(const unit& u) const = 0;
39  virtual bool is_allowed_enemy(const unit& u) const = 0;
40 
41 protected:
42  std::shared_ptr<attacks_vector> analyze_targets() const;
43 
45  const move_map& srcdst,
46  const move_map& dstsrc,
47  const move_map& fullmove_srcdst,
48  const move_map& fullmove_dstsrc,
49  const move_map& enemy_srcdst,
50  const move_map& enemy_dstsrc,
51  const std::array<map_location, 6>& tiles,
52  std::array<bool, 6>& used_locations,
53  std::vector<map_location>& units,
54  std::vector<attack_analysis>& result,
55  attack_analysis& cur_analysis,
56  const team& current_team) const;
57 
58  static int rate_terrain(const unit& u, const map_location& loc);
59 };
60 
62 public:
63  aspect_attacks(readonly_context &context, const config &cfg, const std::string &id);
64  virtual ~aspect_attacks() {}
65 
66  virtual bool is_allowed_attacker(const unit& u) const;
67  virtual bool is_allowed_enemy(const unit& u) const;
68  virtual config to_config() const;
69 private:
70  std::shared_ptr<unit_filter> filter_own_, filter_enemy_;
71 };
72 
73 } // end of namespace testing_ai_default
74 
76  lua_State* lua;
77  std::shared_ptr<unit_filter> filter_own_, filter_enemy_;
79 };
80 
82 public:
83  aspect_attacks_lua(readonly_context &context, const config &cfg, const std::string &id, std::shared_ptr<lua_ai_context>& l_ctx);
84  virtual ~aspect_attacks_lua() {}
85 
86  virtual bool is_allowed_attacker(const unit& u) const;
87  virtual bool is_allowed_enemy(const unit& u) const;
88  virtual config to_config() const;
89  virtual void recalculate() const;
90 private:
91  std::shared_ptr<lua_ai_action_handler> handler_;
92  mutable std::shared_ptr<lua_object<aspect_attacks_lua_filter>> obj_;
93  std::string code_;
94  const config params_;
95 };
96 
97 } // end of namespace ai
map_location loc
Definition: move.cpp:172
std::shared_ptr< attacks_vector > analyze_targets() const
virtual bool is_allowed_enemy(const unit &u) const =0
void do_attack_analysis(const map_location &loc, const move_map &srcdst, const move_map &dstsrc, const move_map &fullmove_srcdst, const move_map &fullmove_dstsrc, const move_map &enemy_srcdst, const move_map &enemy_dstsrc, const std::array< map_location, 6 > &tiles, std::array< bool, 6 > &used_locations, std::vector< map_location > &units, std::vector< attack_analysis > &result, attack_analysis &cur_analysis, const team &current_team) const
aspect_attacks_base(readonly_context &context, const config &cfg, const std::string &id)
static int rate_terrain(const unit &u, const map_location &loc)
virtual bool is_allowed_attacker(const unit &u) const =0
std::shared_ptr< unit_filter > filter_own_
virtual bool is_allowed_attacker(const unit &u) const
virtual bool is_allowed_enemy(const unit &u) const
std::shared_ptr< unit_filter > filter_enemy_
aspect_attacks(readonly_context &context, const config &cfg, const std::string &id)
virtual config to_config() const
virtual bool is_allowed_enemy(const unit &u) const
std::shared_ptr< lua_object< aspect_attacks_lua_filter > > obj_
virtual bool is_allowed_attacker(const unit &u) const
virtual void recalculate() const
aspect_attacks_lua(readonly_context &context, const config &cfg, const std::string &id, std::shared_ptr< lua_ai_context > &l_ctx)
std::shared_ptr< lua_ai_action_handler > handler_
virtual const team & current_team() const override
Definition: contexts.hpp:450
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:75
This class represents a single unit of a specific type.
Definition: unit.hpp:133
A small explanation about what's going on here: Each action has access to two game_info objects First...
Definition: actions.cpp:59
std::multimap< map_location, map_location > move_map
The standard way in which a map of possible moves is recorded.
Definition: game_info.hpp:43
std::shared_ptr< unit_filter > filter_own_
std::shared_ptr< unit_filter > filter_enemy_
Encapsulates the map of the game.
Definition: location.hpp:45