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