1 //       _________ __                 __
2 //      /   _____//  |_____________ _/  |______     ____  __ __  ______
3 //      \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
4 //      /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ |
5 //     /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
6 //             \/                  \/          \//_____/            \/
7 //  ______________________                           ______________________
8 //                        T H E   W A R   B E G I N S
9 //         Stratagus - A free fantasy real time strategy game engine
10 //
11 /**@name character.h - The character header file. */
12 //
13 //      (c) Copyright 2015-2019 by Andrettin
14 //
15 //      This program is free software; you can redistribute it and/or modify
16 //      it under the terms of the GNU General Public License as published by
17 //      the Free Software Foundation; only version 2 of the License.
18 //
19 //      This program is distributed in the hope that it will be useful,
20 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
21 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 //      GNU General Public License for more details.
23 //
24 //      You should have received a copy of the GNU General Public License
25 //      along with this program; if not, write to the Free Software
26 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 //      02111-1307, USA.
28 //
29 
30 #ifndef __CHARACTER_H__
31 #define __CHARACTER_H__
32 
33 /*----------------------------------------------------------------------------
34 --  Includes
35 ----------------------------------------------------------------------------*/
36 
37 #include "data_type.h"
38 #include "icons.h"
39 #include "item.h"
40 #include "time/date.h"
41 
42 #include <vector>
43 #include <tuple>
44 
45 /*----------------------------------------------------------------------------
46 --  Declarations
47 ----------------------------------------------------------------------------*/
48 
49 class CCalendar;
50 class CCivilization;
51 class CDeity;
52 class CDeityDomain;
53 class CDependency;
54 class CFaction;
55 class CFile;
56 class CHistoricalLocation;
57 class CMapTemplate;
58 class CLanguage;
59 class CPersistentItem;
60 class CProvince;
61 class CQuest;
62 class CReligion;
63 class CSite;
64 class CUnitType;
65 class CUnit;
66 class CUpgrade;
67 class LuaCallback;
68 
69 /**
70 **  Indexes into gender array.
71 */
72 enum Genders {
73 	NoGender,
74 	MaleGender,
75 	FemaleGender,
76 	AsexualGender, //i.e. slimes reproduce asexually
77 
78 	MaxGenders
79 };
80 
81 enum Attributes {
82 	StrengthAttribute,
83 	DexterityAttribute,
84 	IntelligenceAttribute,
85 	CharismaAttribute,
86 
87 	MaxAttributes
88 };
89 
90 /**
91 **  Indexes into character title array.
92 */
93 enum CharacterTitles {
94 	CharacterTitleHeadOfState, // also used for titulars to aristocratic titles which were formal only; for example: the French duke of Orléans did not rule over Orléans, but here we consider the "head of state" title to also encompass such cases
95 	CharacterTitleHeadOfGovernment,
96 	CharacterTitleEducationMinister,
97 	CharacterTitleFinanceMinister,
98 	CharacterTitleForeignMinister,
99 	CharacterTitleIntelligenceMinister,
100 	CharacterTitleInteriorMinister,
101 	CharacterTitleJusticeMinister,
102 	CharacterTitleWarMinister,
103 
104 	CharacterTitleGovernor,
105 	CharacterTitleMayor,
106 
107 	MaxCharacterTitles
108 };
109 
110 class CCharacter : public CDataType
111 {
112 public:
CCharacter()113 	CCharacter()
114 	{
115 		memset(Attributes, 0, sizeof(Attributes));
116 	}
117 
118 	static CCharacter *GetCharacter(const std::string &ident, const bool should_find = true);
119 	static CCharacter *GetOrAddCharacter(const std::string &ident);
120 	static void ClearCharacters();
121 	static void GenerateCharacterHistory();		/// Generates history for characters
122 	static void ResetCharacterHistory();		/// Removes generated history data from characters
123 
124 	static std::vector<CCharacter *> Characters;
125 	static std::map<std::string, CCharacter *> CharactersByIdent;
126 
127 	~CCharacter();
128 
129 	virtual void ProcessConfigData(const CConfigData *config_data) override;
130 	void GenerateHistory();
131 	void ResetHistory();
132 	void SaveHistory();
133 	void GenerateMissingDates();
134 	int GetMartialAttribute() const;
135 	int GetAttributeModifier(int attribute) const;
136 	CReligion *GetReligion() const;
137 	CLanguage *GetLanguage() const;
138 	CCalendar *GetCalendar() const;
139 	bool IsParentOf(const std::string &child_full_name) const;
140 	bool IsChildOf(const std::string &parent_full_name) const;
141 	bool IsSiblingOf(const std::string &sibling_full_name) const;
142 	bool IsItemEquipped(const CPersistentItem *item) const;
143 	bool IsUsable() const;
144 	bool CanAppear(bool ignore_neutral = false) const;
145 	bool CanWorship() const;
146 	bool HasMajorDeity() const;
147 	std::string GetFullName() const;
148 	IconConfig GetIcon() const;
149 	CPersistentItem *GetItem(CUnit &item) const;
150 	void UpdateAttributes();
151 	void SaveHistory(CFile &file);		/// Save generated history data for the character
152 
153 	CDate BirthDate;			/// Date in which the character was born
154 	CDate StartDate;			/// Date in which the character historically starts being active
155 	CDate DeathDate;			/// Date in which the character historically died
156 	CCivilization *Civilization = nullptr;	/// Culture to which the character belongs
157 	CFaction *Faction = nullptr;	/// Faction to which the character belongs
158 	int Gender = 0;				/// Character's gender
159 	int Level = 0;				/// Character's level
160 	int ExperiencePercent = 0;	/// Character's experience, as a percentage of the experience required to level up
161 	bool ViolentDeath = false;	/// If historical death was violent
162 	bool Custom = false;		/// Whether this character is a custom hero
163 	bool Initialized = false;	/// Whether the character has already been initialized
164 	std::string Name;			/// Given name of the character
165 	std::string ExtraName;		/// Extra given names of the character (used if necessary to differentiate from existing heroes)
166 	std::string FamilyName;		/// Name of the character's family
167 	std::string Description;	/// Description of the character from an in-game universe perspective
168 	std::string Background;		/// Description of the character from a perspective outside of the game's universe
169 	std::string Quote;			/// A quote relating to the character
170 	std::string HairVariation;	/// Name of the character's hair variation
171 	IconConfig Icon;					/// Character's icon
172 	IconConfig HeroicIcon;				/// Character's heroic icon (level 3 and upper)
173 	CUnitType *Type = nullptr;
174 	CUpgrade *Trait = nullptr;
175 	CDeity *Deity = nullptr;			/// The deity which the character is (if it is a deity)
176 	CCharacter *Father = nullptr;		/// Character's father
177 	CCharacter *Mother = nullptr;		/// Character's mother
178 	LuaCallback *Conditions = nullptr;
179 	CDependency *Predependency = nullptr;
180 	CDependency *Dependency = nullptr;
181 	std::vector<CPersistentItem *> EquippedItems[MaxItemSlots];	/// Equipped items of the character, per slot
182 	std::vector<CCharacter *> Children;	/// Children of the character
183 	std::vector<CCharacter *> Siblings;	/// Siblings of the character
184 	std::vector<CFaction *> Factions;	/// Factions for which this character is available; if empty, this means all factions of the character's civilization can recruit them
185 	std::vector<CDeity *> Deities;		/// Deities chosen by this character to worship
186 	std::vector<CDeity *> GeneratedDeities;		/// Deities picked during history generation for this character to worship
187 	std::vector<CDeityDomain *> PreferredDeityDomains;	/// Preferred deity domains for the character, used to generate deities for it if any are lacking
188 	std::vector<CUpgrade *> Abilities;
189 	std::vector<CUpgrade *> ReadWorks;
190 	std::vector<CUpgrade *> ConsumedElixirs;
191 	std::vector<CUpgrade *> AuthoredWorks;	/// Literary works of which this character is the author
192 	std::vector<CUpgrade *> LiteraryAppearances;	/// Literary works in which this character appears
193 	std::vector<CQuest *> QuestsInProgress;	/// Quests in progress, only for playable, custom characters
194 	std::vector<CQuest *> QuestsCompleted;	/// Quests completed, only for playable, custom characters
195 	std::vector<CPersistentItem *> Items;
196 	int Attributes[MaxAttributes];
197 	std::vector<CUnitType *> ForbiddenUpgrades;	/// which unit types this character is forbidden to upgrade to
198 	std::vector<std::pair<CDate, CFaction *>> HistoricalFactions;	/// historical locations of the character; the values are: date, faction
199 	std::vector<CHistoricalLocation *> HistoricalLocations;	/// historical locations of the character
200 	std::vector<std::tuple<CDate, CDate, CFaction *, int>> HistoricalTitles;	/// historical titles of the character, the first element is the beginning date of the term, the second one the end date, the third the faction it pertains to (if any, if not then it is null), and the fourth is the character title itself (from the character title enums)
201 	std::vector<std::tuple<int, int, CProvince *, int>> HistoricalProvinceTitles;
202 };
203 
204 /*----------------------------------------------------------------------------
205 -- Variables
206 ----------------------------------------------------------------------------*/
207 
208 extern std::map<std::string, CCharacter *> CustomHeroes;
209 extern CCharacter *CurrentCustomHero;
210 extern bool LoadingPersistentHeroes;
211 
212 /*----------------------------------------------------------------------------
213 -- Functions
214 ----------------------------------------------------------------------------*/
215 
216 extern int GetAttributeVariableIndex(int attribute);
217 extern CCharacter *GetCustomHero(const std::string &hero_ident);
218 extern void SaveHero(CCharacter *hero);
219 extern void SaveHeroes();
220 extern void HeroAddQuest(const std::string &hero_ident, const std::string &quest_ident);
221 extern void HeroCompleteQuest(const std::string &hero_ident, const std::string &quest_ident);
222 extern void SaveCustomHero(const std::string &hero_ident);
223 extern void DeleteCustomHero(const std::string &hero_ident);
224 extern void SetCurrentCustomHero(const std::string &hero_ident);
225 extern std::string GetCurrentCustomHero();
226 extern void ChangeCustomHeroCivilization(const std::string &hero_name, const std::string &civilization_ident, const std::string &new_hero_name, const std::string &new_hero_family_name);
227 extern bool IsNameValidForCustomHero(const std::string &hero_name, const std::string &hero_family_name);
228 extern std::string GetGenderNameById(int gender);
229 extern int GetGenderIdByName(const std::string &gender);
230 extern std::string GetCharacterTitleNameById(int title);
231 extern int GetCharacterTitleIdByName(const std::string &title);
232 extern bool IsMinisterialTitle(int title);
233 extern void CharacterCclRegister();
234 
235 #endif
236