The Battle for Wesnoth  1.13.4+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 - 2016 by Andrius Silinskas <[email protected]>
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 #ifndef FLG_MANAGER_HPP_INCLUDED
15 #define FLG_MANAGER_HPP_INCLUDED
16 
17 #include "widgets/combo.hpp"
18 
19 #include <string>
20 #include <vector>
21 
22 class config;
23 namespace rand_rng { class mt_rng; }
24 
25 namespace ng {
26 
27 const std::string random_enemy_picture("units/random-dice.png");
28 
29 std::string get_RC_suffix(const std::string& unit_color, const std::string& color);
30 
31 /// FLG stands for faction, leader and gender.
33 {
34 public:
35  flg_manager(const std::vector<const config*>& era_factions,
36  const config& side, const bool faction_lock, const bool leader_lock,
37  const bool saved_game);
38  ~flg_manager();
39 
40  void set_current_faction(const unsigned index);
41  void set_current_faction(const std::string& id);
42  void set_current_faction(const config& faction)
43  { set_current_faction(faction_index(faction)); }
44 
45  void set_current_leader(const unsigned index);
46  void set_current_leader(const std::string& leader);
47 
48  void set_current_gender(const unsigned index);
49  void set_current_gender(const std::string& gender);
50 
51  // Update the status of combo: items, selection and whether
52  // it should be enabled or not.
53  void reset_leader_combo(gui::combo& combo_leader, const std::string& color) const;
54  void reset_gender_combo(gui::combo& combo_gender, const std::string& color) const;
55 
56  bool is_random_faction();
57  void resolve_random(rand_rng::mt_rng & rng, const std::vector<std::string> & avoid); //Second Argument is a list of faction ids we don't want to match, used to implement random faction modes. If it is not possible to resolve then we just proceed anyways rather than give an error.
58 
59  // Picks the first faction with the greater amount of data
60  // matching the criteria.
61  int find_suitable_faction() const;
62 
63  const std::vector<const config*>& choosable_factions() const
64  { return choosable_factions_; }
65  const std::vector<std::string>& choosable_leaders() const
66  { return choosable_leaders_; }
67  const std::vector<std::string>& choosable_genders() const
68  { return choosable_genders_; }
69  const config& current_faction() const
70  { return *current_faction_; }
71  const std::string& current_leader() const
72  { return current_leader_; }
73  const std::string& current_gender() const
74  { return current_gender_; }
75 
76  const config* default_leader_cfg() const
77  { return default_leader_cfg_; }
78 
79  int current_faction_index() const;
80 
81 private:
82  flg_manager(const flg_manager&);
83  void operator=(const flg_manager&);
84 
91 
92  // Append leaders from a given faction
93  // to a choosable factions.
94  void append_leaders_from_faction(const config* faction);
95 
96  int faction_index(const config& faction) const;
97  /// returns -1 if no leader with that name was found
98  int leader_index(const std::string& leader) const;
99  /// returns -1 if no gender with that name was found
100  int gender_index(const std::string& gender) const;
101 
103  { return leader_index(current_leader_); }
105  { return gender_index(current_gender_); }
106 
107  const std::vector<const config*>& era_factions_;
108 
109  const config& side_;
110 
111  const bool use_map_settings_;
112  const bool saved_game_;
113  const bool has_no_recruits_;
114 
115  const bool faction_lock_;
116  const bool leader_lock_;
117 
118  // All factions which could be played by a side (including Random).
119  std::vector<const config*> available_factions_;
120  std::vector<std::string> available_leaders_;
121  std::vector<std::string> available_genders_;
122 
123  std::vector<const config*> choosable_factions_;
124  std::vector<std::string> choosable_leaders_;
125  std::vector<std::string> choosable_genders_;
126 
130 
134  static std::vector<std::string> get_original_recruits(const config& cfg);
135  static const config& get_default_faction(const config& cfg);
136 };
137 
138 } // end namespace ng
139 
140 #endif
const config * default_leader_cfg_
const std::vector< const config * > & choosable_factions() const
Definition: flg_manager.hpp:63
std::string default_leader_type_
void set_current_faction(const config &faction)
Definition: flg_manager.hpp:42
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:65
const config & side_
void set_current_leader(const unsigned index)
int faction_index(const config &faction) const
void update_available_factions()
void set_current_gender(const unsigned index)
void operator=(const flg_manager &)
FLG stands for faction, leader and gender.
Definition: flg_manager.hpp:32
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_
void reset_leader_combo(gui::combo &combo_leader, const std::string &color) const
int current_gender_index() const
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:46
void append_leaders_from_faction(const config *faction)
const std::string & current_gender() const
Definition: flg_manager.hpp:73
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 use_map_settings_
const bool has_no_recruits_
void reset_gender_combo(gui::combo &combo_gender, const std::string &color) const
std::string current_leader_
GLuint color
Definition: glew.h:5801
std::string get_RC_suffix(const std::string &unit_color, const std::string &color)
Definition: flg_manager.cpp:38
int current_faction_index() const
int find_suitable_faction() const
void set_current_faction(const unsigned index)
std::string current_gender_
std::vector< std::string > choosable_genders_
const config * default_leader_cfg() const
Definition: flg_manager.hpp:76
static std::vector< std::string > get_original_recruits(const config &cfg)
GLuint index
Definition: glew.h:1782
const bool saved_game_
const config & current_faction() const
Definition: flg_manager.hpp:69
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:71
const std::vector< std::string > & choosable_genders() const
Definition: flg_manager.hpp:67
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
void update_available_leaders()
void resolve_random(rand_rng::mt_rng &rng, const std::vector< std::string > &avoid)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503
std::vector< std::string > available_leaders_
void update_choosable_factions()
std::vector< std::string > choosable_leaders_
const config * current_faction_