The Battle for Wesnoth  1.13.10+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
flg_manager.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 - 2017 by Andrius Silinskas <silinskas.andrius@gmail.com>
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 
15 #pragma once
16 
17 #include <string>
18 #include <vector>
19 
20 class config;
21 namespace randomness { class mt_rng; }
22 
23 namespace ng {
24 
25 const std::string random_enemy_picture("units/random-dice.png");
26 
27 /// FLG stands for faction, leader and gender.
29 {
30 public:
31  flg_manager(const std::vector<const config*>& era_factions,
32  const config& side, const bool faction_lock, const bool leader_lock, const bool saved_game);
33 
34  void set_current_faction(const unsigned index);
35  void set_current_faction(const std::string& id);
36  void set_current_faction(const config& faction)
37  { set_current_faction(faction_index(faction)); }
38 
39  void set_current_leader(const unsigned index);
40  void set_current_leader(const std::string& leader);
41 
42  void set_current_gender(const unsigned index);
43  void set_current_gender(const std::string& gender);
44 
45  bool is_random_faction();
46 
47  // Second Argument is a list of faction ids we don't want to match, used to implement random faction modes.
48  // If it is not possible to resolve then we just proceed anyways rather than give an error.
49  void resolve_random(randomness::mt_rng & rng, const std::vector<std::string> & avoid);
50 
51  bool is_saved_game() const
52  {
53  return saved_game_;
54  }
55 
56  // Picks the first faction with the greater amount of data
57  // matching the criteria.
58  int find_suitable_faction() const;
59 
60  const std::vector<const config*>& choosable_factions() const
61  { return choosable_factions_; }
62  const std::vector<std::string>& choosable_leaders() const
63  { return choosable_leaders_; }
64  const std::vector<std::string>& choosable_genders() const
65  { return choosable_genders_; }
66  const config& current_faction() const
67  { return *current_faction_; }
68  const std::string& current_leader() const
69  { return current_leader_; }
70  const std::string& current_gender() const
71  { return current_gender_; }
72 
73  const config* default_leader_cfg() const
74  { return default_leader_cfg_; }
75 
76  int current_faction_index() const;
77 
79  { return leader_index(current_leader_); }
81  { return gender_index(current_gender_); }
82 
83 private:
84  flg_manager(const flg_manager&) = delete;
85  void operator=(const flg_manager&) = delete;
86 
93 
94  // Append leaders from a given faction to a choosable factions.
95  void append_leaders_from_faction(const config* faction);
96 
97  int faction_index(const config& faction) const;
98  /// returns -1 if no leader with that name was found
99  int leader_index(const std::string& leader) const;
100  /// returns -1 if no gender with that name was found
101  int gender_index(const std::string& gender) const;
102 
103  const std::vector<const config*>& era_factions_;
104 
105  const config& side_;
106 
107  const bool saved_game_;
108  const bool has_no_recruits_;
109 
110  const bool faction_lock_;
111  const bool leader_lock_;
112 
113  // All factions which could be played by a side (including Random).
114  std::vector<const config*> available_factions_;
115  std::vector<std::string> available_leaders_;
116  std::vector<std::string> available_genders_;
117 
118  std::vector<const config*> choosable_factions_;
119  std::vector<std::string> choosable_leaders_;
120  std::vector<std::string> choosable_genders_;
121 
125 
129 
130  static std::vector<std::string> get_original_recruits(const config& cfg);
131  static const config& get_default_faction(const config& cfg);
132 };
133 
134 } // end namespace ng
const config * default_leader_cfg_
const std::vector< const config * > & choosable_factions() const
Definition: flg_manager.hpp:60
std::string default_leader_type_
bool is_saved_game() const
Definition: flg_manager.hpp:51
std::vector< char_t > string
size_t index(const utf8::string &str, const size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:71
void set_current_faction(const config &faction)
Definition: flg_manager.hpp:36
bool is_random_faction()
static const config & get_default_faction(const config &cfg)
const std::vector< std::string > & choosable_leaders() const
Definition: flg_manager.hpp:62
void resolve_random(randomness::mt_rng &rng, const std::vector< std::string > &avoid)
const config & side_
void set_current_leader(const unsigned index)
int faction_index(const config &faction) const
void update_available_factions()
void operator=(const flg_manager &)=delete
void set_current_gender(const unsigned index)
FLG stands for faction, leader and gender.
Definition: flg_manager.hpp:28
int leader_index(const std::string &leader) const
returns -1 if no leader with that name was found
std::string default_leader_gender_
const bool leader_lock_
int current_gender_index() const
Definition: flg_manager.hpp:80
flg_manager(const std::vector< const config * > &era_factions, const config &side, const bool faction_lock, const bool leader_lock, const bool saved_game)
Definition: flg_manager.cpp:31
void append_leaders_from_faction(const config *faction)
const std::string & current_gender() const
Definition: flg_manager.hpp:70
std::vector< const config * > available_factions_
std::vector< const config * > choosable_factions_
int gender_index(const std::string &gender) const
returns -1 if no gender with that name was found
const bool has_no_recruits_
std::string current_leader_
int current_faction_index() const
int find_suitable_faction() const
void set_current_faction(const unsigned index)
Definition: flg_manager.cpp:87
std::string current_gender_
std::vector< std::string > choosable_genders_
const config * default_leader_cfg() const
Definition: flg_manager.hpp:73
static std::vector< std::string > get_original_recruits(const config &cfg)
const bool saved_game_
const config & current_faction() const
Definition: flg_manager.hpp:66
const std::vector< const config * > & era_factions_
const std::string random_enemy_picture("units/random-dice.png")
const std::string & current_leader() const
Definition: flg_manager.hpp:68
const std::vector< std::string > & choosable_genders() const
Definition: flg_manager.hpp:64
void update_available_genders()
void update_choosable_genders()
const bool faction_lock_
void update_choosable_leaders()
std::vector< std::string > available_genders_
int current_leader_index() const
Definition: flg_manager.hpp:78
void update_available_leaders()
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:93
std::vector< std::string > available_leaders_
void update_choosable_factions()
std::vector< std::string > choosable_leaders_
const config * current_faction_