/
flg_manager.hpp
138 lines (105 loc) · 4.39 KB
/
flg_manager.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
Copyright (C) 2013 - 2015 by Andrius Silinskas <silinskas.andrius@gmail.com>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef FLG_MANAGER_HPP_INCLUDED
#define FLG_MANAGER_HPP_INCLUDED
#include "widgets/combo.hpp"
#include <string>
#include <vector>
class config;
namespace rand_rng { class mt_rng; }
namespace ng {
const std::string random_enemy_picture("units/random-dice.png");
std::string get_RC_suffix(const std::string& unit_color, const std::string& color);
/// FLG stands for faction, leader and gender.
class flg_manager
{
public:
flg_manager(const std::vector<const config*>& era_factions,
const config& side, const bool faction_lock, const bool leader_lock,
const bool saved_game);
~flg_manager();
void set_current_faction(const unsigned index);
void set_current_faction(const std::string& id);
void set_current_faction(const config& faction)
{ set_current_faction(faction_index(faction)); }
void set_current_leader(const unsigned index);
void set_current_leader(const std::string& leader);
void set_current_gender(const unsigned index);
void set_current_gender(const std::string& gender);
// Update the status of combo: items, selection and whether
// it should be enabled or not.
void reset_leader_combo(gui::combo& combo_leader, const std::string& color) const;
void reset_gender_combo(gui::combo& combo_gender, const std::string& color) const;
bool is_random_faction();
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.
// Picks the first faction with the greater amount of data
// matching the criteria.
int find_suitable_faction() const;
const std::vector<const config*>& choosable_factions() const
{ return choosable_factions_; }
const std::vector<std::string>& choosable_leaders() const
{ return choosable_leaders_; }
const std::vector<std::string>& choosable_genders() const
{ return choosable_genders_; }
const config& current_faction() const
{ return *current_faction_; }
const std::string& current_leader() const
{ return current_leader_; }
const std::string& current_gender() const
{ return current_gender_; }
const config* default_leader_cfg() const
{ return default_leader_cfg_; }
int current_faction_index() const;
private:
flg_manager(const flg_manager&);
void operator=(const flg_manager&);
void update_available_factions();
void update_available_leaders();
void update_available_genders();
void update_choosable_factions();
void update_choosable_leaders();
void update_choosable_genders();
// Append leaders from a given faction
// to a choosable factions.
void append_leaders_from_faction(const config* faction);
int faction_index(const config& faction) const;
/// returns -1 if no leader with that name was found
int leader_index(const std::string& leader) const;
/// returns -1 if no gender with that name was found
int gender_index(const std::string& gender) const;
int current_leader_index() const
{ return leader_index(current_leader_); }
int current_gender_index() const
{ return gender_index(current_gender_); }
const std::vector<const config*>& era_factions_;
const config& side_;
const bool use_map_settings_;
const bool saved_game_;
const bool has_no_recruits_;
const bool faction_lock_;
const bool leader_lock_;
// All factions which could be played by a side (including Random).
std::vector<const config*> available_factions_;
std::vector<std::string> available_leaders_;
std::vector<std::string> available_genders_;
std::vector<const config*> choosable_factions_;
std::vector<std::string> choosable_leaders_;
std::vector<std::string> choosable_genders_;
const config* current_faction_;
std::string current_leader_;
std::string current_gender_;
std::string default_leader_type_;
std::string default_leader_gender_;
const config* default_leader_cfg_;
};
} // end namespace ng
#endif