The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
attack_type.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
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 #ifndef UNIT_ATTACK_TYPE_H_INCLUDED
15 #define UNIT_ATTACK_TYPE_H_INCLUDED
16 
17 #include "map/location.hpp"
18 #include "util.hpp"
19 #include "tstring.hpp"
20 #include "config.hpp"
21 #include <string>
22 #include <vector>
23 
24 class unit_ability_list;
25 
26 //the 'attack type' is the type of attack, how many times it strikes,
27 //and how much damage it does.
29 {
30 public:
31 
32  explicit attack_type(const config& cfg);
33  /** Default implementation, but defined out-of-line for efficiency reasons. */
34  ~attack_type();
35  const t_string& name() const { return description_; }
36  const std::string& id() const { return id_; }
37  const std::string& type() const { return type_; }
38  const std::string& icon() const { return icon_; }
39  const std::string& range() const { return range_; }
40  int min_range() const { return min_range_; }
41  int max_range() const { return max_range_; }
43  int accuracy() const { return accuracy_; }
44  int parry() const { return parry_; }
45  int damage() const { return damage_; }
46  int num_attacks() const { return num_attacks_; }
47  double attack_weight() const { return attack_weight_; }
48  double defense_weight() const { return defense_weight_; }
49  const config specials() const { return specials_; }
50 
52  // void set_id(const std::string& value) { return id = value; }
53  void set_type(const std::string& value) { type_ = value; }
54  void set_icon(const std::string& value) { icon_ = value; }
55  void set_range(const std::string& value) { range_ = value; }
56  // void set_min_range(int value) { min_range_ = value; }
57  // void set_max_range(int value) { max_range_ = value; }
58  void set_accuracy(int value) { accuracy_ = value; }
59  void set_parry(int value) { parry_ = value; }
60  void set_damage(int value) { damage_ = value; }
65 
66 
67  // In unit_abilities.cpp:
68 
69  bool get_special_bool(const std::string& special, bool simple_check=false) const;
70  unit_ability_list get_specials(const std::string& special) const;
71  std::vector<std::pair<t_string, t_string> > special_tooltips(std::vector<bool> *active_list=nullptr) const;
72  std::string weapon_specials(bool only_active=false, bool is_backstab=false) const;
73  void set_specials_context(const map_location& unit_loc, const map_location& other_loc,
74  bool attacking, const attack_type *other_attack) const;
75  void set_specials_context(const map_location& loc, bool attacking = true) const;
77 
78  /// Calculates the number of attacks this weapon has, considering specials.
79  void modified_attacks(bool is_backstab, unsigned & min_attacks,
80  unsigned & max_attacks) const;
81  /// Returns the damage per attack of this weapon, considering specials.
82  int modified_damage(bool is_backstab) const;
83 
84  // In unit_types.cpp:
85 
86  bool matches_filter(const config& filter) const;
87  bool apply_modification(const config& cfg);
88  bool describe_modification(const config& cfg,std::string* description);
89 
90  int movement_used() const { return movement_used_; }
92 
93  void write(config& cfg) const;
94  inline config to_config() const { config c; write(c); return c; }
95 
96 private:
97  // In unit_abilities.cpp:
98 
99  // Configured as a bit field, in case that is useful.
101  bool special_active(const config& special, AFFECTS whom,
102  bool include_backstab=true) const;
103 
104  // Used via set_specials_context() to control which specials are
105  // considered active.
107  mutable bool is_attacker_;
108  mutable const attack_type* other_attack_;
109  mutable bool is_for_listing_;
110 
117  int damage_;
121 
124  int parry_;
126 };
127 #endif
const t_string & name() const
Definition: attack_type.hpp:35
bool apply_modification(const config &cfg)
Modifies *this using the specifications in cfg, but only if *this matches cfg viewed as a filter...
std::string icon_
std::string type_
bool matches_filter(const config &filter) const
Returns whether or not *this matches the given filter.
void set_specials_context(const map_location &unit_loc, const map_location &other_loc, bool attacking, const attack_type *other_attack) const
Sets the context under which specials will be checked for being active.
Definition: abilities.cpp:677
attack_type(const config &cfg)
Definition: attack_type.cpp:40
double attack_weight() const
Definition: attack_type.hpp:47
int modified_damage(bool is_backstab) const
Returns the damage per attack of this weapon, considering specials.
Definition: abilities.cpp:743
int max_range() const
Definition: attack_type.hpp:41
int movement_used() const
Definition: attack_type.hpp:90
void set_specials_context_for_listing() const
Definition: abilities.cpp:704
map_location other_loc_
void set_num_attacks(int value)
Definition: attack_type.hpp:61
std::string weapon_specials(bool only_active=false, bool is_backstab=false) const
Returns a comma-separated string of active names for the specials of *this.
Definition: abilities.cpp:649
int parry() const
Definition: attack_type.hpp:44
int accuracy() const
Definition: attack_type.hpp:43
const std::string & icon() const
Definition: attack_type.hpp:38
Definitions for the interface to Wesnoth Markup Language (WML).
int num_attacks() const
Definition: attack_type.hpp:46
double defense_weight_
bool get_special_bool(const std::string &special, bool simple_check=false) const
Returns whether or not *this has a special with a tag or id equal to special.
Definition: abilities.cpp:552
void set_name(const t_string &value)
Definition: attack_type.hpp:51
void write(config &cfg) const
GLsizei const GLfloat * value
Definition: glew.h:1817
double attack_weight_
std::string range_
config to_config() const
Definition: attack_type.hpp:94
config specials_
const config specials() const
Definition: attack_type.hpp:49
Templates and utility-routines for strings and numbers.
const std::string & id() const
Definition: attack_type.hpp:36
const std::string & type() const
Definition: attack_type.hpp:37
void set_defense_weight(double value)
Definition: attack_type.hpp:63
void set_specials(config value)
Definition: attack_type.hpp:64
bool special_active(const config &special, AFFECTS whom, bool include_backstab=true) const
Returns whether or not the given special is active for the specified unit, based on the current conte...
Definition: abilities.cpp:865
t_string description_
Encapsulates the map of the game.
Definition: location.hpp:38
void set_damage(int value)
Definition: attack_type.hpp:60
bool is_for_listing_
const std::string & range() const
Definition: attack_type.hpp:39
void modified_attacks(bool is_backstab, unsigned &min_attacks, unsigned &max_attacks) const
Calculates the number of attacks this weapon has, considering specials.
Definition: abilities.cpp:717
~attack_type()
Default implementation, but defined out-of-line for efficiency reasons.
Definition: attack_type.cpp:72
unit_ability_list get_specials(const std::string &special) const
Returns the currently active specials as an ability list, given the current context (see set_specials...
Definition: abilities.cpp:587
int damage() const
Definition: attack_type.hpp:45
std::string accuracy_parry_description() const
Definition: attack_type.cpp:76
bool describe_modification(const config &cfg, std::string *description)
Trimmed down version of apply_modification(), with no modifications actually made.
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glew.h:3448
void set_range(const std::string &value)
Definition: attack_type.hpp:55
void set_parry(int value)
Definition: attack_type.hpp:59
std::string id_
void set_icon(const std::string &value)
Definition: attack_type.hpp:54
int min_range() const
Definition: attack_type.hpp:40
#define c
Definition: glew.h:12743
double defense_weight() const
Definition: attack_type.hpp:48
void set_movement_used(int value)
Definition: attack_type.hpp:91
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
const attack_type * other_attack_
void set_accuracy(int value)
Definition: attack_type.hpp:58
GLsizei const GLcharARB ** string
Definition: glew.h:4503
map_location self_loc_
void set_attack_weight(double value)
Definition: attack_type.hpp:62
std::vector< std::pair< t_string, t_string > > special_tooltips(std::vector< bool > *active_list=nullptr) const
Returns a vector of names and descriptions for the specials of *this.
Definition: abilities.cpp:612
void set_type(const std::string &value)
Definition: attack_type.hpp:53