The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
aspect_attacks.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 - 2017 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 #ifdef _MSC_VER
26 #pragma warning(push)
27 //silence "inherits via dominance" warnings
28 #pragma warning(disable:4250)
29 #endif
30 
31 namespace ai {
32 
33 
34 namespace ai_default_rca {
35 
36 class aspect_attacks_base : public typesafe_aspect<attacks_vector> {
37 public:
38  aspect_attacks_base(readonly_context &context, const config &cfg, const std::string &id);
39 
40 
41  virtual ~aspect_attacks_base() {}
42 
43 
44  virtual void recalculate() const;
45 
46 
47  virtual bool is_allowed_attacker(const unit& u) const = 0;
48  virtual bool is_allowed_enemy(const unit& u) const = 0;
49 
50 
51 protected:
52  std::shared_ptr<attacks_vector> analyze_targets() const;
53 
54  void do_attack_analysis(const map_location& loc,
55  const move_map& srcdst, const move_map& dstsrc,
56  const move_map& fullmove_srcdst, const move_map& fullmove_dstsrc,
57  const move_map& enemy_srcdst, const move_map& enemy_dstsrc,
58  const map_location* tiles, bool* used_locations,
59  std::vector<map_location>& units,
60  std::vector<attack_analysis>& result,
61  attack_analysis& cur_analysis,
62  const team &current_team) const;
63  static int rate_terrain(const unit& u, const map_location& loc);
64 };
65 
67 public:
68  aspect_attacks(readonly_context &context, const config &cfg, const std::string &id);
69  virtual ~aspect_attacks() {}
70 
71  virtual bool is_allowed_attacker(const unit& u) const;
72  virtual bool is_allowed_enemy(const unit& u) const;
73  virtual config to_config() const;
74 private:
75  std::shared_ptr<unit_filter> filter_own_, filter_enemy_;
76 };
77 
78 } // end of namespace testing_ai_default
79 
82  std::shared_ptr<unit_filter> filter_own_, filter_enemy_;
84 };
85 
87 public:
88  aspect_attacks_lua(readonly_context &context, const config &cfg, const std::string &id, std::shared_ptr<lua_ai_context>& l_ctx);
89  virtual ~aspect_attacks_lua() {}
90 
91  virtual bool is_allowed_attacker(const unit& u) const;
92  virtual bool is_allowed_enemy(const unit& u) const;
93  virtual config to_config() const;
94  virtual void recalculate() const;
95 private:
96  std::shared_ptr<lua_ai_action_handler> handler_;
97  mutable std::shared_ptr<lua_object<aspect_attacks_lua_filter> > obj_;
99  const config params_;
100 };
101 
102 } // end of namespace ai
103 
104 #ifdef _MSC_VER
105 #pragma warning(pop)
106 #endif
std::vector< char_t > string
aspect_attacks_lua(readonly_context &context, const config &cfg, const std::string &id, std::shared_ptr< lua_ai_context > &l_ctx)
This class represents a single unit of a specific type.
Definition: unit.hpp:101
std::shared_ptr< attacks_vector > analyze_targets() const
aspect_attacks_base(readonly_context &context, const config &cfg, const std::string &id)
virtual config to_config() const
virtual config to_config() const
std::shared_ptr< unit_filter > filter_enemy_
std::multimap< map_location, map_location > move_map
The standard way in which a map of possible moves is recorded.
Definition: game_info.hpp:45
This class stores all the data for a single 'side' (in game nomenclature).
Definition: team.hpp:44
A small explanation about what'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_
std::shared_ptr< unit_filter > filter_enemy_
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 map_location *tiles, bool *used_locations, std::vector< map_location > &units, std::vector< attack_analysis > &result, attack_analysis &cur_analysis, const team &current_team) const
virtual bool is_allowed_enemy(const unit &u) const
aspect_attacks(readonly_context &context, const config &cfg, const std::string &id)
Encapsulates the map of the game.
Definition: location.hpp:40
virtual bool is_allowed_attacker(const unit &u) const =0
virtual const team & current_team() const override
Definition: contexts.hpp:536
virtual bool is_allowed_attacker(const unit &u) const
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
virtual bool is_allowed_attacker(const unit &u) const
virtual void recalculate() const
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
virtual bool is_allowed_enemy(const unit &u) const
std::shared_ptr< lua_object< aspect_attacks_lua_filter > > obj_
static int rate_terrain(const unit &u, const map_location &loc)
unit_map * units
Definition: resources.cpp:34