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