The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
flg_manager.hpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2013 - 2025
3 by Andrius Silinskas <silinskas.andrius@gmail.com>
4 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY.
12
13 See the COPYING file for more details.
14*/
15
16#pragma once
17
18#include "gui/sort_order.hpp"
19
20#include <string>
21#include <vector>
22
23class config;
24namespace randomness { class mt_rng; }
25
26namespace ng {
27
28const std::string random_enemy_picture("units/random-dice.png");
29
30// TODO: use this for more [era] stuff
31// TODO: move this somewhere more general
33{
34 /** Parses an [era] tag. */
35 explicit era_metadata(const config& cfg);
36
37 /** The order to display factions when a player selects their leader. */
38 sort_order::type faction_sort_order;
39};
40
41/** FLG stands for faction, leader and gender. */
43{
44public:
45 flg_manager(const era_metadata& era_info, const std::vector<const config*>& era_factions,
46 const config& side, bool lock_settings, bool use_map_settings, bool saved_game);
47
48 void set_current_faction(const unsigned index);
49 void set_current_faction(const std::string& id);
50 void set_current_faction(const config& faction)
52
53 void set_current_leader(const unsigned index);
54 void set_current_leader(const std::string& leader);
55
56 void set_current_gender(const unsigned index);
57 void set_current_gender(const std::string& gender);
58
59 bool is_random_faction();
60
61 // Second Argument is a list of faction ids we don't want to match, used to implement random faction modes.
62 // If it is not possible to resolve then we just proceed anyways rather than give an error.
63 void resolve_random(randomness::mt_rng & rng, const std::vector<std::string> & avoid);
64
65 bool is_saved_game() const
66 {
67 return saved_game_;
68 }
69
70 // Picks the first faction with the greater amount of data
71 // matching the criteria.
72 int find_suitable_faction() const;
73
74 const std::vector<const config*>& choosable_factions() const
75 { return choosable_factions_; }
76 const std::vector<std::string>& choosable_leaders() const
77 { return choosable_leaders_; }
78 const std::vector<std::string>& choosable_genders() const
79 { return choosable_genders_; }
80 const config& current_faction() const
81 { return *current_faction_; }
82 const std::string& current_leader() const
83 { return current_leader_; }
84 const std::string& current_gender() const
85 { return current_gender_; }
86
87 int current_faction_index() const;
88
93 bool leader_lock() const
94 { return leader_lock_; }
95
96 const era_metadata& era_info() const
97 {
98 return era_info_;
99 }
100
101private:
102 flg_manager(const flg_manager&) = delete;
104
111
112 // Append leaders from a given faction to a choosable factions.
113 void append_leaders_from_faction(const config* faction);
114
116
117 int faction_index(const config& faction) const;
118 /** returns -1 if no leader with that name was found */
119 int leader_index(const std::string& leader) const;
120 /** returns -1 if no gender with that name was found */
121 int gender_index(const std::string& gender) const;
122
124
125 const std::vector<const config*>& era_factions_;
126
127 // not sure how reilable the content of this field is, it's currently only used for debugging info.
128 const int side_num_;
130
131 const std::string original_faction_;
132 const std::vector<std::string> original_recruit_;
133 const bool saved_game_;
135
138
139 // All factions which could be played by a side (including Random).
140 std::vector<const config*> available_factions_;
141 std::vector<std::string> available_leaders_;
142 std::vector<std::string> available_genders_;
143
144 std::vector<const config*> choosable_factions_;
145 std::vector<std::string> choosable_leaders_;
146 std::vector<std::string> choosable_genders_;
147
149 std::string current_leader_;
150 std::string current_gender_;
151
154
155 static const config& get_default_faction(const config& cfg);
156};
157
158} // end namespace ng
A config object defines a single node in a WML file, with access to child nodes.
Definition config.hpp:157
FLG stands for faction, leader and gender.
void update_available_factions()
const era_metadata & era_info() const
const bool faction_from_recruit_
void update_choosable_leaders()
void update_choosable_factions()
std::string default_leader_type_
const std::vector< const config * > & choosable_factions() const
void update_available_leaders()
const std::vector< std::string > original_recruit_
std::string current_leader_
const bool has_no_recruits_
const std::vector< std::string > & choosable_leaders() const
void update_available_genders()
void set_current_faction(const unsigned index)
void set_current_faction(const config &faction)
void select_default_faction()
const std::string & current_gender() const
const std::string & current_leader() const
void resolve_random(randomness::mt_rng &rng, const std::vector< std::string > &avoid)
const era_metadata & era_info_
std::vector< std::string > choosable_leaders_
std::vector< std::string > choosable_genders_
std::vector< std::string > available_genders_
bool is_saved_game() const
flg_manager(const flg_manager &)=delete
int current_gender_index() const
int current_leader_index() const
void update_choosable_genders()
const config & current_faction() const
const config * current_faction_
int faction_index(const config &faction) const
flg_manager & operator=(const flg_manager &)=delete
const std::string original_faction_
void set_current_leader(const unsigned index)
bool leader_lock() const
int leader_index(const std::string &leader) const
returns -1 if no leader with that name was found
const std::vector< std::string > & choosable_genders() const
int gender_index(const std::string &gender) const
returns -1 if no gender with that name was found
int current_faction_index() const
static const config & get_default_faction(const config &cfg)
const bool saved_game_
std::string default_leader_gender_
std::vector< const config * > available_factions_
std::vector< const config * > choosable_factions_
void set_current_gender(const unsigned index)
void append_leaders_from_faction(const config *faction)
const std::vector< const config * > & era_factions_
std::string current_gender_
int find_suitable_faction() const
const int side_num_
std::vector< std::string > available_leaders_
const config * cfg
const std::string random_enemy_picture("units/random-dice.png")
sort_order::type faction_sort_order
The order to display factions when a player selects their leader.