The Battle for Wesnoth  1.15.2+dev
terrain.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://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 #pragma once
16 
17 #include "config.hpp"
18 #include "terrain/translation.hpp"
19 #include "utils/math.hpp"
20 
22 {
23 public:
24 
25  explicit terrain_type();
26  explicit terrain_type(const config& cfg);
27  explicit terrain_type(const terrain_type& base, const terrain_type& overlay);
28 
29  const std::string& icon_image() const { return icon_image_; }
30  const std::string& minimap_image() const { return minimap_image_; }
31  const std::string& minimap_image_overlay() const { return minimap_image_overlay_; }
32  const std::string& editor_image() const { return editor_image_; }
33  const t_string& name() const { return name_; }
34  const t_string& editor_name() const { return editor_name_.empty() ? description() : editor_name_; }
35  const t_string& description() const { return description_.empty() ? name_ : description_; }
36  const t_string& help_topic_text() const { return help_topic_text_; }
37  const std::string& id() const { return id_; }
38 
39  bool hide_help() const { return hide_help_; }
40  bool hide_in_editor() const { return hide_in_editor_; }
41  bool hide_if_impassable() const { return hide_if_impassable_; }
42 
43  //the character representing this terrain
45 
46  /**
47  * The underlying type of the terrain.
48  *
49  * Whether "underlying" means "only the types used in [movetype]" is determined
50  * by the terrain.cfg file, rather than the .cpp code - in 1.14, the terrain.cfg
51  * file uses only the [movetype] terrains in its alias lists.
52  */
53  const t_translation::ter_list& mvt_type() const { return mvt_type_; }
54  const t_translation::ter_list& def_type() const { return def_type_; }
56  const t_translation::ter_list& union_type() const { return union_type_; }
57 
58  /**
59  * Returns true if a terrain has no underlying types other than itself,
60  * in respect of either union, movement or defense.
61  *
62  * If this returns false, then @underlying must be non-empty.
63  *
64  * This function is to encapsulate the logic of whether such a terrain
65  * is represented by a empty list, or whether it's represented by a list
66  * including only itself; so that a refactor can switch between these two
67  * possible implementations.
68  *
69  * This is not related to whether the terrain has an overlay. For example,
70  * Gg^Uf (flat with old mushrooms) is indivisible (it's only Tt), although
71  * Gg^Tf (flat with new mushrooms) can be divided (in to Gt and Tt).
72  *
73  * \todo: should this document vision_type() too?
74  *
75  * @a id the terrain
76  * @a underlying the corresponding mvt_type(), def_type() or union_type()
77  */
79  return (underlying.empty()
80  || (underlying.size() == 1 && underlying.front() == id));
81  }
82 
83  /**
84  * Returns true if this terrain has no underlying types other than itself.
85  *
86  * \todo what about a terrain where is_mvt_indivisible() != is_def_indivisible()?
87  */
88  bool is_indivisible() const {
89  return (union_type_.empty()
90  || (union_type_.size() == 1 && union_type_.front() == number_));
91  }
92  bool is_mvt_indivisible() const {
93  return (mvt_type_.empty()
94  || (mvt_type_.size() == 1 && mvt_type_.front() == number_));
95  }
96 
97  /**
98  * True if this object represents some sentinel values.
99  *
100  * \todo number_ should never be NONE_TERRAIN
101  * \todo there's two different VOID_TERRAINS - see the comment attached to
102  * the definition of VOID_TERRAIN.
103  *
104  * \todo unclear what this should mean, so replace it with a clearly-named
105  * successor.
106  */
107  bool is_nonnull() const { return (number_ != t_translation::NONE_TERRAIN) &&
109  /// Returns the light (lawful) bonus for this terrain when the time of day
110  /// gives a @a base bonus.
111  int light_bonus(int base) const
112  {
114  }
115 
116  int unit_height_adjust() const { return height_adjust_; }
117  double unit_submerge() const { return submerge_; }
118 
119  int gives_healing() const { return heals_; }
120  bool is_village() const { return village_; }
121  bool is_castle() const { return castle_; }
122  bool is_keep() const { return keep_; }
123 
124  //these descriptions are shown for the terrain in the mouse over
125  //depending on the owner or the village
130 
131  const std::string& editor_group() const { return editor_group_; }
132  void set_editor_group(const std::string& str) { editor_group_ = str; }
133 
134  bool is_overlay() const { return overlay_; }
135  bool is_combined() const { return combined_; }
136 
139 
140  /**
141  * Returns true if all most of the data matches. The ones that don't need to match:
142  * - editor_group_
143  * - icon_image_
144  * - description_
145  * - help_topic_text_
146  * - income_description_ , ~ally_ , ~enemy_, ~own_
147  * - hide_if_impassable_
148  *
149  * The intention seems to be to allow additional [terrain_type] tags to add
150  * compatible definitions to multiple addon-specific editor groups. For
151  * this purpose the description strings aren't too important, and
152  * hide_if_impassable_ seems trivial.
153  */
154  bool operator==(const terrain_type& other) const;
155 private:
156 
157  /** The image used as symbol icon */
158  std::string icon_image_;
159 
160  /** The image used in the minimap */
161  std::string minimap_image_;
163 
164  /**
165  * The image used in the editor palette if not defined in WML it will be
166  * initialized with the value of minimap_image_
167  */
168  std::string editor_image_;
169  std::string id_;
174 
175  //the 'number' is the number that represents this
176  //terrain type. The 'type' is a list of the 'underlying types'
177  //of the terrain. This may simply be the same as the number.
178  //This is the internal number used, WML still uses character strings.
184 
187 
188  double submerge_;
190 
194  int heals_;
195 
200 
201  std::string editor_group_;
202 
204 
208 };
bool is_indivisible() const
Returns true if this terrain has no underlying types other than itself.
Definition: terrain.hpp:88
bool height_adjust_set_
Definition: terrain.hpp:186
std::string minimap_image_overlay_
Definition: terrain.hpp:162
bool is_mvt_indivisible() const
Definition: terrain.hpp:92
const t_translation::ter_list & mvt_type() const
The underlying type of the terrain.
Definition: terrain.hpp:53
bool is_castle() const
Definition: terrain.hpp:121
t_translation::terrain_code editor_default_base_
Definition: terrain.hpp:206
const terrain_code NONE_TERRAIN
Definition: translation.hpp:59
const t_string & description() const
Definition: terrain.hpp:35
t_translation::ter_list mvt_type_
Definition: terrain.hpp:180
bool is_overlay() const
Definition: terrain.hpp:134
t_translation::ter_list def_type_
Definition: terrain.hpp:182
t_string name_
Definition: terrain.hpp:170
std::string id_
Definition: terrain.hpp:169
bool hide_in_editor_
Definition: terrain.hpp:207
double unit_submerge() const
Definition: terrain.hpp:117
t_string income_description_
Definition: terrain.hpp:196
std::string editor_image_
The image used in the editor palette if not defined in WML it will be initialized with the value of m...
Definition: terrain.hpp:168
bool operator==(const terrain_type &other) const
Returns true if all most of the data matches.
Definition: terrain.cpp:303
bool combined_
Definition: terrain.hpp:205
bool hide_help_
Definition: terrain.hpp:207
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
Definition: translation.hpp:50
static bool is_indivisible(t_translation::terrain_code id, const t_translation::ter_list &underlying)
Returns true if a terrain has no underlying types other than itself, in respect of either union...
Definition: terrain.hpp:78
const t_string & income_description() const
Definition: terrain.hpp:126
const std::string & editor_image() const
Definition: terrain.hpp:32
Definitions for the interface to Wesnoth Markup Language (WML).
t_string description_
Definition: terrain.hpp:172
bool hide_help() const
Definition: terrain.hpp:39
t_string income_description_own_
Definition: terrain.hpp:199
std::string editor_group_
Definition: terrain.hpp:201
bool is_nonnull() const
True if this object represents some sentinel values.
Definition: terrain.hpp:107
const terrain_code VOID_TERRAIN
VOID_TERRAIN is used for shrouded hexes.
bool is_village() const
Definition: terrain.hpp:120
int light_bonus(int base) const
Returns the light (lawful) bonus for this terrain when the time of day gives a base bonus...
Definition: terrain.hpp:111
const t_string & editor_name() const
Definition: terrain.hpp:34
t_translation::terrain_code default_base() const
Definition: terrain.hpp:137
bool is_combined() const
Definition: terrain.hpp:135
t_string income_description_ally_
Definition: terrain.hpp:197
int unit_height_adjust() const
Definition: terrain.hpp:116
bool hide_if_impassable() const
Definition: terrain.hpp:41
bool submerge_set_
Definition: terrain.hpp:189
const t_translation::ter_list & vision_type() const
Definition: terrain.hpp:55
General math utility functions.
int gives_healing() const
Definition: terrain.hpp:119
int max_light_
Definition: terrain.hpp:192
double submerge_
Definition: terrain.hpp:188
int height_adjust_
Definition: terrain.hpp:185
bool is_keep() const
Definition: terrain.hpp:122
t_translation::terrain_code number_
Definition: terrain.hpp:179
t_translation::ter_list union_type_
Definition: terrain.hpp:183
t_translation::ter_list vision_type_
Definition: terrain.hpp:181
t_translation::terrain_code terrain_with_default_base() const
Definition: terrain.cpp:296
t_translation::terrain_code number() const
Definition: terrain.hpp:44
const t_string & income_description_own() const
Definition: terrain.hpp:129
const t_string & income_description_enemy() const
Definition: terrain.hpp:128
bool hide_if_impassable_
Definition: terrain.hpp:207
const t_translation::ter_list & union_type() const
Definition: terrain.hpp:56
const std::string & minimap_image() const
Definition: terrain.hpp:30
std::string minimap_image_
The image used in the minimap.
Definition: terrain.hpp:161
bool castle_
Definition: terrain.hpp:203
bool hide_in_editor() const
Definition: terrain.hpp:40
bool village_
Definition: terrain.hpp:203
const t_string & name() const
Definition: terrain.hpp:33
t_string income_description_enemy_
Definition: terrain.hpp:198
int light_modification_
Definition: terrain.hpp:191
void set_editor_group(const std::string &str)
Definition: terrain.hpp:132
bool empty() const
Definition: tstring.hpp:182
bool overlay_
Definition: terrain.hpp:205
int min_light_
Definition: terrain.hpp:193
const t_translation::ter_list & def_type() const
Definition: terrain.hpp:54
const std::string & id() const
Definition: terrain.hpp:37
std::vector< terrain_code > ter_list
Definition: translation.hpp:78
const t_string & income_description_ally() const
Definition: terrain.hpp:127
int bounded_add(int base, int increment, int max_sum, int min_sum=0)
Returns base + increment, but will not increase base above max_sum, nor decrease it below min_sum...
Definition: math.hpp:46
t_string help_topic_text_
Definition: terrain.hpp:173
std::string icon_image_
The image used as symbol icon.
Definition: terrain.hpp:158
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:68
const std::string & minimap_image_overlay() const
Definition: terrain.hpp:31
const t_string & help_topic_text() const
Definition: terrain.hpp:36
const std::string & editor_group() const
Definition: terrain.hpp:131
const std::string & icon_image() const
Definition: terrain.hpp:29
t_string editor_name_
Definition: terrain.hpp:171