The Battle for Wesnoth  1.17.0-dev
race.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2021
3  by David White <dave@whitevine.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 #pragma once
17 
18 #include "config.hpp"
19 #include "utils/name_generator.hpp"
20 
21 #include <array>
22 #include <memory>
23 
24 class unit_race
25 {
26 public:
28  static const std::string s_female;
29  static const std::string s_male;
30 
31 
32  explicit unit_race(const config& cfg);
33 
34  const config& get_cfg() const { return cfg_; }
35  const std::string& id() const { return id_; }
36  const std::string& editor_icon() const { return icon_; }
37  const t_string& name(GENDER gender=MALE) const { return name_[gender]; }
38  const t_string& plural_name() const { return plural_name_; }
39  const t_string& description() const { return description_; }
40 
41  std::string generate_name(GENDER gender) const;
42  const name_generator& generator(GENDER gender) const;
43 
44  bool uses_global_traits() const;
45 
48  unsigned int num_traits() const;
49  const std::string& undead_variation() const { return undead_variation_; }
50 
51  /**
52  * Gets this race's icon path without state/size suffix and extension.
53  *
54  * This doesn't return the full path. Its output looks something like this:
55  * @c icons/unit-groups/race_elf
56  *
57  * This is because this output is used in the editor for a GUI1 button's icon,
58  * and GUI1 automatically appends the state extension, such as "_30-pressed.png"
59  *
60  * If a custom icon has been provided, that is used. Else, it checks if an
61  * appropriate icon exists in icons/unit-groups/. If not, a generic custom race
62  * icon will be used.
63  */
64  std::string get_icon_path_stem() const;
65 
66  const std::string& help_taxonomy() const { return help_taxonomy_; }
67 
68  /** Dummy race used when a race is not yet known. */
69  static const unit_race null_race;
70 
71 private:
72  /** Only used to construct null_race. */
73  unit_race();
74 
75  const config cfg_;
76 
77  std::string id_;
78  std::string icon_;
79  std::array<t_string, NUM_GENDERS> name_;
82  unsigned int ntraits_;
83  std::array<std::shared_ptr<name_generator>, NUM_GENDERS> name_generator_;
84 
88  std::string undead_variation_;
89  std::string help_taxonomy_;
90 };
91 
93 const std::string& gender_string(unit_race::GENDER gender);
94 
95 typedef std::map<std::string,unit_race> race_map;
unit_race::GENDER string_gender(const std::string &str, unit_race::GENDER def=unit_race::MALE)
Definition: race.cpp:152
static const std::string s_male
Standard string id (not translatable) for MALE.
Definition: race.hpp:29
std::array< std::shared_ptr< name_generator >, NUM_GENDERS > name_generator_
Definition: race.hpp:83
unsigned int ntraits_
Definition: race.hpp:82
const std::string & id() const
Definition: race.hpp:35
std::string undead_variation_
Definition: race.hpp:88
const config::const_child_itors & additional_topics() const
Definition: race.cpp:134
const name_generator & generator(GENDER gender) const
Definition: race.cpp:119
const std::string & editor_icon() const
Definition: race.hpp:36
const std::string & gender_string(unit_race::GENDER gender)
Definition: race.cpp:142
const t_string & description() const
Definition: race.hpp:39
Definitions for the interface to Wesnoth Markup Language (WML).
const t_string & name(GENDER gender=MALE) const
Definition: race.hpp:37
static const std::string s_female
Standard string id (not translatable) for FEMALE.
Definition: race.hpp:28
static const unit_race null_race
Dummy race used when a race is not yet known.
Definition: race.hpp:69
const t_string & plural_name() const
Definition: race.hpp:38
std::array< t_string, NUM_GENDERS > name_
Definition: race.hpp:79
t_string description_
Definition: race.hpp:81
const config::const_child_itors & additional_traits() const
Definition: race.cpp:129
unsigned int num_traits() const
Definition: race.cpp:139
boost::iterator_range< const_child_iterator > const_child_itors
Definition: config.hpp:206
const config & get_cfg() const
Definition: race.hpp:34
config::const_child_itors topics_
Definition: race.hpp:86
std::string id_
Definition: race.hpp:77
std::string icon_
Definition: race.hpp:78
bool uses_global_traits() const
Definition: race.cpp:124
const std::string & help_taxonomy() const
Definition: race.hpp:66
const config cfg_
Definition: race.hpp:75
t_string plural_name_
Definition: race.hpp:80
unit_race()
Only used to construct null_race.
Definition: race.cpp:51
std::string help_taxonomy_
Definition: race.hpp:89
config::const_child_itors traits_
Definition: race.hpp:85
std::string get_icon_path_stem() const
Gets this race&#39;s icon path without state/size suffix and extension.
Definition: race.cpp:161
std::map< std::string, unit_race > race_map
Definition: race.hpp:95
bool global_traits_
Definition: race.hpp:87
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:61
const std::string & undead_variation() const
Definition: race.hpp:49
std::string generate_name(GENDER gender) const
Definition: race.cpp:114