The Battle for Wesnoth  1.15.0+dev
race.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 "utils/name_generator.hpp"
19 
20 #include <array>
21 #include <memory>
22 
23 class unit_race
24 {
25 public:
27  static const std::string s_female;
28  static const std::string s_male;
29 
30 
31  explicit unit_race(const config& cfg);
32 
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_; }
39 
40  std::string generate_name(GENDER gender) const;
41  const name_generator& generator(GENDER gender) const;
42 
43  bool uses_global_traits() const;
44 
47  unsigned int num_traits() const;
48  const std::string& undead_variation() const { return undead_variation_; }
49 
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  */
63  std::string get_icon_path_stem() const;
64 
65  /// Dummy race used when a race is not yet known.
66  static const unit_race null_race;
67 
68 private:
69  /// Only used to construct null_race.
70  unit_race();
71 
72  const config cfg_;
73 
74  std::string id_;
75  std::string icon_;
76  std::array<t_string, NUM_GENDERS> name_;
79  unsigned int ntraits_;
80  std::array<std::shared_ptr<name_generator>, NUM_GENDERS> name_generator_;
81 
85  std::string undead_variation_;
86 };
87 
89 const std::string& gender_string(unit_race::GENDER gender);
90 
91 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:141
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:80
unsigned int ntraits_
Definition: race.hpp:79
const std::string & id() const
Definition: race.hpp:34
std::string undead_variation_
Definition: race.hpp:85
const config::const_child_itors & additional_topics() const
Definition: race.cpp:123
const name_generator & generator(GENDER gender) const
Definition: race.cpp:108
const std::string & editor_icon() const
Definition: race.hpp:35
const std::string & gender_string(unit_race::GENDER gender)
Definition: race.cpp:131
const t_string & description() const
Definition: race.hpp:38
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:66
const t_string & plural_name() const
Definition: race.hpp:37
std::array< t_string, NUM_GENDERS > name_
Definition: race.hpp:76
t_string description_
Definition: race.hpp:78
const config::const_child_itors & additional_traits() const
Definition: race.cpp:118
unsigned int num_traits() const
Definition: race.cpp:128
boost::iterator_range< const_child_iterator > const_child_itors
Definition: config.hpp:238
const config & get_cfg() const
Definition: race.hpp:33
config::const_child_itors topics_
Definition: race.hpp:83
std::string id_
Definition: race.hpp:74
std::string icon_
Definition: race.hpp:75
bool uses_global_traits() const
Definition: race.cpp:113
const config cfg_
Definition: race.hpp:72
t_string plural_name_
Definition: race.hpp:77
unit_race()
Only used to construct null_race.
Definition: race.cpp:47
config::const_child_itors traits_
Definition: race.hpp:82
std::string get_icon_path_stem() const
Gets this race&#39;s icon path without state/size suffix and extension.
Definition: race.cpp:150
std::map< std::string, unit_race > race_map
Definition: race.hpp:91
bool global_traits_
Definition: race.hpp:84
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:92
const std::string & undead_variation() const
Definition: race.hpp:48
std::string generate_name(GENDER gender) const
Definition: race.cpp:103