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 player.h - The player header file. */
12 //
13 // (c) Copyright 1998-2019 by Lutz Sammer, Jimmy Salmon and 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 __PLAYER_H__
31 #define __PLAYER_H__
32
33 //@{
34
35 /*----------------------------------------------------------------------------
36 -- Includes
37 ----------------------------------------------------------------------------*/
38
39 #include <string>
40
41 //Wyrmgus start
42 #include <map>
43 #include <tuple>
44
45 //Wyrmgus start
46 #include "character.h" // because of "MaxCharacterTitles"
47 #include "color.h"
48 //Wyrmgus end
49 #include "icons.h"
50 //Wyrmgus start
51 #include "item.h"
52 #include "time/date.h"
53 #include "ui/ui.h" // for the UI fillers
54 //Wyrmgus end
55 #include "upgrade/upgrade_structs.h"
56 #include "vec2i.h"
57
58 /*----------------------------------------------------------------------------
59 -- Definitons
60 ----------------------------------------------------------------------------*/
61
62 #define STORE_OVERALL 0
63 #define STORE_BUILDING 1
64 #define STORE_BOTH 2
65
66 #define SPEEDUP_FACTOR 100
67
68 #define DefaultTradeCost 30
69
70 /*----------------------------------------------------------------------------
71 -- Declarations
72 ----------------------------------------------------------------------------*/
73
74 class CAge;
75 class CCalendar;
76 class CCharacter;
77 class CCivilization;
78 class CCurrency;
79 class CDeity;
80 class CDeityDomain;
81 class CDynasty;
82 class CFile;
83 class CGraphic;
84 class CLanguage;
85 class CProvince;
86 class CPlane;
87 class CPlayerQuestObjective;
88 class CQuest;
89 class CReligion;
90 class CSite;
91 class CUnit;
92 class CUnitType;
93 class PlayerAi;
94 //Wyrmgus start
95 class CFiller;
96 class LuaCallback;
97 //Wyrmgus end
98 struct lua_State;
99
100 /*----------------------------------------------------------------------------
101 -- Player type
102 ----------------------------------------------------------------------------*/
103
104 enum _diplomacy_ {
105 DiplomacyAllied, /// Ally with opponent
106 DiplomacyNeutral, /// Don't attack be neutral
107 DiplomacyEnemy, /// Attack opponent
108 //Wyrmgus start
109 DiplomacyOverlord, /// Become overlord to other player
110 DiplomacyVassal, /// Become vassal to other player
111 //Wyrmgus end
112 DiplomacyCrazy /// Ally and attack opponent
113 }; /// Diplomacy states for CommandDiplomacy
114
115 /// Player structure
116 class CPlayer
117 {
118 public:
119 int Index; /// player as number
120 std::string Name; /// name of non computer
121
122 int Type; /// type of player (human,computer,...)
123 int Race; /// race of player (orc,human,...)
124 int Faction; /// faction of the player
125 CReligion *Religion; /// religion of the player
126 CDynasty *Dynasty; /// ruling dynasty of the player
127 CAge *Age; /// The current age the player/faction is in
128 std::string AiName; /// AI for computer
129
130 // friend enemy detection
131 int Team; /// team of player
132
133 Vec2i StartPos; /// map tile start position
134 //Wyrmgus start
135 int StartMapLayer; /// map tile start map layer
136
137 CPlayer *Overlord; /// overlord of this player
138 std::vector<CPlayer *> Vassals; /// vassals of this player
139 //Wyrmgus end
140
141 //Wyrmgus start
142 // inline void SetStartView(const Vec2i &pos) { StartPos = pos; }
SetStartView(const Vec2i & pos,int z)143 inline void SetStartView(const Vec2i &pos, int z) { StartPos = pos; StartMapLayer = z; }
144 //Wyrmgus end
145
146 int Resources[MaxCosts]; /// resources in overall store
147 int MaxResources[MaxCosts]; /// max resources can be stored
148 int StoredResources[MaxCosts];/// resources in store buildings (can't exceed MaxResources)
149 int LastResources[MaxCosts]; /// last values for revenue
150 int Incomes[MaxCosts]; /// income of the resources
151 int Revenue[MaxCosts]; /// income rate of the resources
152 //Wyrmgus start
153 int Prices[MaxCosts]; /// price of each resource
154 int ResourceDemand[MaxCosts]; /// demand for the resources
155 int StoredResourceDemand[MaxCosts]; /// stored demand for the resources (converted into a trade action when reaches 100)
156
157 int TradeCost; /// cost of trading
158 //Wyrmgus end
159
160 int SpeedResourcesHarvest[MaxCosts]; /// speed factor for harvesting resources
161 int SpeedResourcesReturn[MaxCosts]; /// speed factor for returning resources
162 int SpeedBuild; /// speed factor for building
163 int SpeedTrain; /// speed factor for training
164 int SpeedUpgrade; /// speed factor for upgrading
165 int SpeedResearch; /// speed factor for researching
166
167 std::map<const CUnitType *, int> UnitTypesCount; /// total units of unit-type
168 std::map<const CUnitType *, int> UnitTypesUnderConstructionCount; /// total under construction units of unit-type
169 std::map<const CUnitType *, int> UnitTypesAiActiveCount; /// total units of unit-type that have their AI set to active
170 std::map<const CUnitType *, std::vector<CUnit *>> UnitsByType; /// units owned by this player for each type
171 std::map<const CUnitType *, std::vector<CUnit *>> AiActiveUnitsByType; /// AI active units owned by this player for each type
172 std::vector<CUnit *> Heroes; /// hero units owned by this player
173 std::vector<CDeity *> Deities; /// deities chosen by this player
174 std::vector<CQuest *> AvailableQuests; /// quests available to this player
175 std::vector<CQuest *> CurrentQuests; /// quests being pursued by this player
176 std::vector<CQuest *> CompletedQuests; /// quests completed by this player
177 std::vector<CPlayerQuestObjective *> QuestObjectives; /// Objectives of the player's current quests
178 std::vector<std::pair<CUpgrade *, int>> Modifiers; /// Modifiers affecting the player, and until which cycle it should last
179 std::vector<int> AutosellResources;
180 //Wyrmgus end
181
182 bool AiEnabled; /// handle AI on local computer
183 //Wyrmgus start
184 bool Revealed; /// Whether the player has been revealed (i.e. after losing the last town hall)
185 //Wyrmgus end
186 PlayerAi *Ai; /// Ai structure pointer
187
188 int NumBuildings; /// # buildings
189 //Wyrmgus start
190 int NumBuildingsUnderConstruction; /// # buildings under construction
191 int NumTownHalls;
192 //Wyrmgus end
193 int Supply; /// supply available/produced
194 int Demand; /// demand of player
195
196 int UnitLimit; /// # food units allowed
197 int BuildingLimit; /// # buildings allowed
198 int TotalUnitLimit; /// # total unit number allowed
199
200 int Score; /// Points for killing ...
201 int TotalUnits;
202 int TotalBuildings;
203 int TotalResources[MaxCosts];
204 int TotalRazings;
205 int TotalKills; /// How many units killed
206 //Wyrmgus start
207 int UnitTypeKills[UnitTypeMax]; /// total killed units of unit-type
208 //Wyrmgus end
209
210 //Wyrmgus start
211 int LostTownHallTimer; /// The timer for when the player lost the last town hall (to make the player's units be revealed)
212 int HeroCooldownTimer; /// The cooldown timer for recruiting heroes
213 //Wyrmgus end
214
215 IntColor Color; /// color of units on minimap
216
217 CUnitColors UnitColors; /// Unit colors for new units
218
219 std::vector<CUnit *> FreeWorkers; /// Container for free workers
220 //Wyrmgus start
221 std::vector<CUnit *> LevelUpUnits; /// Container for units with available level up upgrades
222 //Wyrmgus end
223
224 // Upgrades/Allows:
225 CAllow Allow; /// Allowed for player
226 CUpgradeTimers UpgradeTimers; /// Timer for the upgrades
227
228 /// Change player name
229 void SetName(const std::string &name);
230
231 //Wyrmgus start
232 void SetCivilization(int civilization);
233 void SetFaction(const CFaction *faction);
234 void SetRandomFaction();
235 void SetDynasty(CDynasty *dynasty);
236 void CheckAge();
237 void SetAge(CAge *age);
238 CCurrency *GetCurrency() const;
239 void ShareUpgradeProgress(CPlayer &player, CUnit &unit);
240 bool IsPlayerColorUsed(int color);
241 bool HasUpgradeClass(const int upgrade_class) const;
242 bool HasSettlement(const CSite *settlement) const;
243 bool HasSettlementNearWaterZone(int water_zone) const;
244 CSite *GetNearestSettlement(const Vec2i &pos, int z, const Vec2i &size) const;
245 bool HasUnitBuilder(const CUnitType *type, const CSite *settlement = nullptr) const;
246 bool HasUpgradeResearcher(const CUpgrade *upgrade) const;
247 bool CanFoundFaction(CFaction *faction, bool pre = false);
248 bool CanChooseDynasty(CDynasty *dynasty, bool pre = false);
249 bool CanRecruitHero(const CCharacter *character, bool ignore_neutral = false) const;
250 bool UpgradeRemovesExistingUpgrade(const CUpgrade *upgrade, bool ignore_lower_priority = false) const;
251 std::string GetFactionTitleName() const;
252 std::string GetCharacterTitleName(int title_type, int gender) const;
253 void GetWorkerLandmasses(std::vector<int>& worker_landmasses, const CUnitType *building); /// Builds a vector with worker landmasses; the building is the structure to be built by the worker in question
254 std::vector<CUpgrade *> GetResearchableUpgrades();
255 //Wyrmgus end
256
257 /// Clear turn related player data
258 void Clear();
259
260 std::vector<CUnit *>::const_iterator UnitBegin() const;
261 std::vector<CUnit *>::iterator UnitBegin();
262 std::vector<CUnit *>::const_iterator UnitEnd() const;
263 std::vector<CUnit *>::iterator UnitEnd();
264
265 CUnit &GetUnit(int index) const;
266 int GetUnitCount() const;
267
268 void AddUnit(CUnit &unit);
269 void RemoveUnit(CUnit &unit);
270 void UpdateFreeWorkers();
271 //Wyrmgus start
272 void PerformResourceTrade();
273 bool HasMarketUnit() const;
274 CUnit *GetMarketUnit() const;
275 std::vector<int> GetAutosellResources() const;
276 void AutosellResource(const int resource);
277 void UpdateLevelUpUnits();
278 void UpdateQuestPool();
279 void AvailableQuestsChanged();
280 void UpdateCurrentQuests();
281 void AcceptQuest(CQuest *quest);
282 void CompleteQuest(CQuest *quest);
283 void FailQuest(CQuest *quest, std::string fail_reason = "");
284 void RemoveCurrentQuest(CQuest *quest);
285 bool CanAcceptQuest(CQuest *quest);
286 bool HasCompletedQuest(CQuest *quest);
287 std::string HasFailedQuest(CQuest *quest);
288 void AddModifier(CUpgrade *modifier, int cycles);
289 void RemoveModifier(CUpgrade *modifier);
290 bool AtPeace() const;
291 //Wyrmgus end
292
293 /// Get a resource of the player
294 int GetResource(const int resource, const int type);
295 /// Adds/subtracts some resources to/from the player store
296 void ChangeResource(const int resource, const int value, const bool store = false);
297 /// Set a resource of the player
298 void SetResource(const int resource, const int value, const int type = STORE_OVERALL);
299 /// Check, if there enough resources for action.
300 bool CheckResource(const int resource, const int value);
301 //Wyrmgus start
302 /// Increase resource price
303 void IncreaseResourcePrice(const int resource);
304 /// Decrease resource price
305 void DecreaseResourcePrice(const int resource);
306 /// Converges prices with another player
307 int ConvergePricesWith(CPlayer &player, int max_convergences);
308 /// Get the resource price
309 int GetResourcePrice(const int resource) const;
310 /// Get the effective resource demand for the player, given the current prices
311 int GetEffectiveResourceDemand(const int resource) const;
312
313 int GetEffectiveResourceSellPrice(const int resource, int traded_quantity = 100) const;
314 int GetEffectiveResourceBuyPrice(const int resource, int traded_quantity = 100) const;
315
316 /// Get the total price difference between this player and another one
317 int GetTotalPriceDifferenceWith(const CPlayer &player) const;
318 /// Get the trade potential between this player and another one
319 int GetTradePotentialWith(const CPlayer &player) const;
320 //Wyrmgus end
321
322 /// Returns count of specified unittype
323 int GetUnitTotalCount(const CUnitType &type) const;
324 /// Check if the unit-type didn't break any unit limits and supply/demand
325 int CheckLimits(const CUnitType &type) const;
326
327 /// Check if enough resources are available for costs
328 int CheckCosts(const int *costs, bool notify = true) const;
329 /// Check if enough resources are available for a new unit-type
330 //Wyrmgus start
331 // int CheckUnitType(const CUnitType &type) const;
332 int CheckUnitType(const CUnitType &type, bool hire = false) const;
333 //Wyrmgus end
334
335 /// Add costs to the resources
336 void AddCosts(const int *costs);
337 /// Add costs for an unit-type to the resources
338 //Wyrmgus start
339 // void AddUnitType(const CUnitType &type);
340 void AddUnitType(const CUnitType &type, bool hire = false);
341 //Wyrmgus end
342 /// Add a factor of costs to the resources
343 void AddCostsFactor(const int *costs, int factor);
344 /// Remove costs from the resources
345 void SubCosts(const int *costs);
346 /// Remove costs for an unit-type from the resources
347 //Wyrmgus start
348 // void SubUnitType(const CUnitType &type);
349 void SubUnitType(const CUnitType &type, bool hire = false);
350 //Wyrmgus end
351 /// Remove a factor of costs from the resources
352 void SubCostsFactor(const int *costs, int factor);
353
354 //Wyrmgus start
355 void GetUnitTypeCosts(const CUnitType *type, int *type_costs, bool hire = false, bool ignore_one = false) const;
356 int GetUnitTypeCostsMask(const CUnitType *type, bool hire = false) const;
357 void GetUpgradeCosts(const CUpgrade *upgrade, int *upgrade_costs);
358 int GetUpgradeCostsMask(const CUpgrade *upgrade) const;
359
360 void SetUnitTypeCount(const CUnitType *type, int quantity);
361 void ChangeUnitTypeCount(const CUnitType *type, int quantity);
362 int GetUnitTypeCount(const CUnitType *type) const;
363
364 void SetUnitTypeUnderConstructionCount(const CUnitType *type, int quantity);
365 void ChangeUnitTypeUnderConstructionCount(const CUnitType *type, int quantity);
366 int GetUnitTypeUnderConstructionCount(const CUnitType *type) const;
367
368 void SetUnitTypeAiActiveCount(const CUnitType *type, int quantity);
369 void ChangeUnitTypeAiActiveCount(const CUnitType *type, int quantity);
370 int GetUnitTypeAiActiveCount(const CUnitType *type) const;
371
372 void IncreaseCountsForUnit(CUnit *unit, bool type_change = false);
373 void DecreaseCountsForUnit(CUnit *unit, bool type_change = false);
374 //Wyrmgus end
375
376 /// Does the player have units of that type
377 int HaveUnitTypeByType(const CUnitType &type) const;
378 /// Does the player have units of that type
379 int HaveUnitTypeByIdent(const std::string &ident) const;
380
381 /// Notify player about a problem
382 //Wyrmgus start
383 // void Notify(int type, const Vec2i &pos, const char *fmt, ...) const PRINTF_VAARG_ATTRIBUTE(4, 5); // Don't forget to count this
384 void Notify(int type, const Vec2i &pos, int z, const char *fmt, ...) const PRINTF_VAARG_ATTRIBUTE(5, 6); // Don't forget to count this
385 //Wyrmgus end
386 /// Notify player about a problem
387 void Notify(const char *fmt, ...) const PRINTF_VAARG_ATTRIBUTE(2, 3); // Don't forget to count this
388
389
390 /**
391 ** Check if the player index is an enemy
392 */
IsEnemy(const int index)393 bool IsEnemy(const int index) const
394 {
395 return (Index != index && (Enemy & (1 << index)) != 0);
396 }
397
398 bool IsEnemy(const CPlayer &player) const;
399 bool IsEnemy(const CUnit &unit) const;
400 bool IsAllied(const CPlayer &player) const;
401 bool IsAllied(const CUnit &unit) const;
402 bool IsVisionSharing() const;
403 bool IsSharedVision(const CPlayer &player) const;
404 bool IsSharedVision(const CUnit &unit) const;
405 bool IsBothSharedVision(const CPlayer &player) const;
406 bool IsBothSharedVision(const CUnit &unit) const;
407 bool IsTeamed(const CPlayer &player) const;
408 bool IsTeamed(const CUnit &unit) const;
409 //Wyrmgus start
410 bool IsOverlordOf(const CPlayer &player, bool include_indirect = false) const;
411 bool IsVassalOf(const CPlayer &player, bool include_indirect = false) const;
412 bool HasContactWith(const CPlayer &player) const;
413 bool HasNeutralFactionType() const;
414 bool HasBuildingAccess(const CPlayer &player, int button_action = -1) const;
415 bool HasHero(const CCharacter *hero) const;
416 //Wyrmgus end
417
418 void SetDiplomacyNeutralWith(const CPlayer &player);
419 void SetDiplomacyAlliedWith(const CPlayer &player);
420 //Wyrmgus start
421 // void SetDiplomacyEnemyWith(const CPlayer &player);
422 void SetDiplomacyEnemyWith(CPlayer &player);
423 //Wyrmgus end
424 void SetDiplomacyCrazyWith(const CPlayer &player);
425
426 void ShareVisionWith(const CPlayer &player);
427 void UnshareVisionWith(const CPlayer &player);
428
429 //Wyrmgus start
430 void SetOverlord(CPlayer *player);
431 //Wyrmgus end
432
433 void Init(/* PlayerTypes */ int type);
434 void Save(CFile &file) const;
435 void Load(lua_State *l);
436
437 private:
438 std::vector<CUnit *> Units; /// units of this player
439 unsigned int Enemy; /// enemy bit field for this player
440 unsigned int Allied; /// allied bit field for this player
441 unsigned int SharedVision; /// shared vision bit field
442 };
443
444 //Wyrmgus start
445 enum GovernmentTypes {
446 GovernmentTypeNoGovernmentType,
447 GovernmentTypeMonarchy,
448 GovernmentTypeRepublic,
449 GovernmentTypeTheocracy,
450
451 MaxGovernmentTypes
452 };
453
454 enum FactionTypes {
455 FactionTypeNoFactionType,
456 FactionTypeTribe,
457 FactionTypePolity,
458 FactionTypeMercenaryCompany,
459 FactionTypeHolyOrder,
460 FactionTypeTradingCompany,
461
462 MaxFactionTypes
463 };
464
465 enum FactionTiers {
466 FactionTierNoFactionTier,
467 FactionTierBarony,
468 FactionTierCounty,
469 FactionTierDuchy,
470 FactionTierGrandDuchy,
471 FactionTierKingdom,
472 FactionTierEmpire,
473
474 MaxFactionTiers
475 };
476
477 enum ForceTypes {
478 LandForceType,
479 NavalForceType,
480 AirForceType,
481
482 MaxForceTypes
483 };
484
485 enum WordTypes {
486 WordTypeNoun,
487 WordTypeVerb,
488 WordTypeAdjective,
489 WordTypePronoun,
490 WordTypeAdverb,
491 WordTypeConjunction,
492 WordTypeAdposition,
493 WordTypeArticle,
494 WordTypeNumeral,
495 WordTypeAffix,
496
497 MaxWordTypes
498 };
499
500 enum ArticleTypes {
501 ArticleTypeNoArticle,
502 ArticleTypeDefinite,
503 ArticleTypeIndefinite,
504
505 MaxArticleTypes
506 };
507
508 enum GrammaticalCases {
509 GrammaticalCaseNoCase,
510 GrammaticalCaseNominative,
511 GrammaticalCaseAccusative,
512 GrammaticalCaseDative,
513 GrammaticalCaseGenitive,
514
515 MaxGrammaticalCases
516 };
517
518 enum GrammaticalNumbers {
519 GrammaticalNumberNoNumber,
520 GrammaticalNumberSingular,
521 GrammaticalNumberPlural,
522
523 MaxGrammaticalNumbers
524 };
525
526 enum GrammaticalPersons {
527 GrammaticalPersonFirstPerson,
528 GrammaticalPersonSecondPerson,
529 GrammaticalPersonThirdPerson,
530
531 MaxGrammaticalPersons
532 };
533
534 enum GrammaticalGenders {
535 GrammaticalGenderNoGender,
536 GrammaticalGenderMasculine,
537 GrammaticalGenderFeminine,
538 GrammaticalGenderNeuter,
539
540 MaxGrammaticalGenders
541 };
542
543 enum GrammaticalTenses {
544 GrammaticalTenseNoTense,
545 GrammaticalTensePresent,
546 GrammaticalTensePast,
547 GrammaticalTenseFuture,
548
549 MaxGrammaticalTenses
550 };
551
552 enum GrammaticalMoods {
553 GrammaticalMoodIndicative,
554 GrammaticalMoodSubjunctive,
555
556 MaxGrammaticalMoods
557 };
558
559 enum ComparisonDegrees {
560 ComparisonDegreePositive,
561 ComparisonDegreeComparative,
562 ComparisonDegreeSuperlative,
563
564 MaxComparisonDegrees
565 };
566
567 enum AffixTypes {
568 AffixTypePrefix,
569 AffixTypeSuffix,
570 AffixTypeInfix,
571
572 MaxAffixTypes
573 };
574
575 enum WordJunctionTypes {
576 WordJunctionTypeNoWordJunction,
577 WordJunctionTypeCompound,
578 WordJunctionTypeSeparate,
579
580 MaxWordJunctionTypes
581 };
582
583 class CForceTemplate
584 {
585 public:
CForceTemplate()586 CForceTemplate() :
587 ForceType(-1), Priority(100), Weight(1)
588 {
589 }
590
591 int ForceType;
592 int Priority;
593 int Weight;
594 std::vector<std::pair<int, int>> Units; /// Vector containing each unit class belonging to the force template, and the respective quantity
595 };
596
597 class CAiBuildingTemplate
598 {
599 public:
CAiBuildingTemplate()600 CAiBuildingTemplate() :
601 UnitClass(-1), Priority(100),
602 PerSettlement(false)
603 {
604 }
605
606 int UnitClass; /// Building's unit class
607 int Priority;
608 bool PerSettlement; /// Whether the building should be constructed for each settlement
609 };
610
611 class CFaction
612 {
613 public:
614 ~CFaction();
615
616 int GetUpgradePriority(const CUpgrade *upgrade) const;
617 int GetForceTypeWeight(int force_type) const;
618 CCurrency *GetCurrency() const;
619 std::vector<CForceTemplate *> GetForceTemplates(int force_type) const;
620 std::vector<CAiBuildingTemplate *> GetAiBuildingTemplates() const;
621 std::vector<std::string> &GetShipNames();
622
623 std::string Ident; /// faction name
624 std::string Name;
625 std::string Description; /// faction description
626 std::string Quote; /// faction quote
627 std::string Background; /// faction background
628 std::string FactionUpgrade; /// faction upgrade applied when the faction is set
629 std::string Adjective; /// adjective pertaining to the faction
630 std::string DefaultAI = "land-attack";
631 int ID = -1; /// faction ID
632 CCivilization *Civilization = nullptr; /// faction civilization
633 int Type = FactionTypeNoFactionType; /// faction type (i.e. tribe or polity)
634 int DefaultTier = FactionTierBarony; /// default faction tier
635 int DefaultGovernmentType = GovernmentTypeMonarchy; /// default government type
636 int ParentFaction = -1; /// parent faction of this faction
637 bool Playable = true; /// faction playability
638 bool DefiniteArticle = false; /// whether the faction's name should be preceded by a definite article (e.g. "the Netherlands")
639 IconConfig Icon; /// Faction's icon
640 CCurrency *Currency = nullptr; /// The faction's currency
641 CDeity *HolyOrderDeity = nullptr; /// deity this faction belongs to, if it is a holy order
642 LuaCallback *Conditions = nullptr;
643 std::vector<int> Colors; /// faction colors
644 std::vector<CFaction *> DevelopsFrom; /// from which factions can this faction develop
645 std::vector<CFaction *> DevelopsTo; /// to which factions this faction can develop
646 std::vector<CDynasty *> Dynasties; /// which dynasties are available to this faction
647 std::string Titles[MaxGovernmentTypes][MaxFactionTiers]; /// this faction's title for each government type and faction tier
648 std::string MinisterTitles[MaxCharacterTitles][MaxGenders][MaxGovernmentTypes][MaxFactionTiers]; /// this faction's minister title for each minister type and government type
649 std::map<const CUpgrade *, int> UpgradePriorities; /// Priority for each upgrade
650 std::map<int, IconConfig> ButtonIcons; /// icons for button actions
651 std::map<int, int> ClassUnitTypes; /// the unit type slot of a particular class for a particular faction
652 std::map<int, int> ClassUpgrades; /// the upgrade slot of a particular class for a particular faction
653 std::vector<std::string> ProvinceNames; /// Province names for the faction
654 std::vector<std::string> ShipNames; /// Ship names for the faction
655 std::vector<CSite *> Cores; /// Core sites of this faction (required to found it)
656 std::vector<CSite *> Sites; /// Sites used for this faction if it needs a randomly-generated settlement
657 std::map<int, std::vector<CForceTemplate *>> ForceTemplates; /// Force templates, mapped to each force type
658 std::map<int, int> ForceTypeWeights; /// Weights for each force type
659 std::vector<CAiBuildingTemplate *> AiBuildingTemplates; /// AI building templates
660 std::map<std::tuple<CDate, CDate, int>, CCharacter *> HistoricalMinisters; /// historical ministers of the faction (as well as heads of state and government), mapped to the beginning and end of the rule, and the enum of the title in question
661 std::map<std::string, std::map<CDate, bool>> HistoricalUpgrades; /// historical upgrades of the faction, with the date of change
662 std::map<int, int> HistoricalTiers; /// dates in which this faction's tier changed; faction tier mapped to year
663 std::map<int, int> HistoricalGovernmentTypes; /// dates in which this faction's government type changed; government type mapped to year
664 std::map<std::pair<CDate, CFaction *>, int> HistoricalDiplomacyStates; /// dates in which this faction's diplomacy state to another faction changed; diplomacy state mapped to year and faction
665 std::map<std::pair<CDate, int>, int> HistoricalResources; /// dates in which this faction's storage of a particular resource changed; resource quantities mapped to date and resource
666 std::vector<std::pair<CDate, std::string>> HistoricalCapitals; /// historical capitals of the faction; the values are: date and settlement ident
667 std::vector<CFiller> UIFillers;
668
669 std::string Mod; /// To which mod (or map), if any, this faction belongs
670 };
671
672 class CDynasty
673 {
674 public:
CDynasty()675 CDynasty() :
676 ID(-1), Civilization(-1),
677 DynastyUpgrade(nullptr), Conditions(nullptr)
678 {
679 }
680
681 ~CDynasty();
682
683 std::string Ident; /// dynasty name
684 std::string Name;
685 std::string Description; /// dynasty description
686 std::string Quote; /// dynasty quote
687 std::string Background; /// dynasty background
688 CUpgrade *DynastyUpgrade; /// dynasty upgrade applied when the dynasty is set
689 int ID; /// dynasty ID
690 int Civilization; /// dynasty civilization
691 IconConfig Icon; /// Dynasty's icon
692 LuaCallback *Conditions;
693 std::vector<CFaction *> Factions; /// to which factions is this dynasty available
694 };
695
696 class LanguageWord
697 {
698 public:
LanguageWord()699 LanguageWord() :
700 Type(-1), Gender(-1), GrammaticalNumber(-1),
701 Language(nullptr), DerivesFrom(nullptr),
702 Archaic(false),
703 Uncountable(false),
704 ArticleType(-1),
705 Number(-1)
706 {
707 }
708
709 bool HasMeaning(const std::string &meaning);
710 std::string GetNounInflection(int grammatical_number, int grammatical_case, int word_junction_type = -1);
711 std::string GetVerbInflection(int grammatical_number, int grammatical_person, int grammatical_tense, int grammatical_mood);
712 std::string GetAdjectiveInflection(int comparison_degree, int article_type = -1, int grammatical_case = -1, int grammatical_number = -1, int grammatical_gender = -1);
713 std::string GetParticiple(int grammatical_tense);
714 void RemoveFromVector(std::vector<LanguageWord *>& word_vector);
715
716 std::string Word; /// Word name / ID.
717 CLanguage *Language; /// The language the word belongs to
718 int Type; /// Word type
719 int Gender; /// What is the gender of the noun or article (Masculine, Feminine or Neuter)
720 int GrammaticalNumber; /// Grammatical number (i.e. whether the word is necessarily plural or not)
721 bool Archaic; /// Whether the word is archaic (whether it is used in current speech)
722 std::map<std::tuple<int, int>, std::string> NumberCaseInflections; /// For nouns, mapped to grammatical number and grammatical case
723 std::map<std::tuple<int, int, int, int>, std::string> NumberPersonTenseMoodInflections; /// For verbs, mapped to grammatical number, grammatical person, grammatical tense and grammatical mood
724 std::string ComparisonDegreeCaseInflections[MaxComparisonDegrees][MaxGrammaticalCases]; /// For adjectives
725 std::string Participles[MaxGrammaticalTenses]; /// For verbs
726 std::vector<std::string> Meanings; /// Meanings of the word in English.
727 LanguageWord *DerivesFrom; /// From which word does this word derive
728 std::vector<LanguageWord *> DerivesTo; /// Which words derive from this word
729 LanguageWord *CompoundElements[MaxAffixTypes]; /// From which compound elements is this word formed
730 std::vector<LanguageWord *> CompoundElementOf[MaxAffixTypes]; /// Which words are formed from this word as a compound element
731
732 // noun-specific variables
733 bool Uncountable; /// Whether the noun is uncountable or not.
734
735 //pronoun and article-specific variables
736 std::string Nominative; /// Nominative case for the pronoun (if any)
737 std::string Accusative; /// Accusative case for the pronoun (if any)
738 std::string Dative; /// Dative case for the pronoun (if any)
739 std::string Genitive; /// Genitive case for the pronoun (if any)
740
741 //article-specific variables
742 int ArticleType; /// Which article type this article belongs to
743
744 //numeral-specific variables
745 int Number;
746
747 std::string Mod; /// To which mod (or map), if any, this word belongs
748 };
749
750 class CLanguage
751 {
752 public:
CLanguage()753 CLanguage() :
754 UsedByCivilizationOrFaction(false),
755 DialectOf(nullptr)
756 {
757 }
758
759 LanguageWord *GetWord(const std::string word, int word_type, std::vector<std::string>& word_meanings) const;
760 std::string GetArticle(int gender, int grammatical_case, int article_type, int grammatical_number);
761 std::string GetNounEnding(int grammatical_number, int grammatical_case, int word_junction_type = -1);
762 std::string GetAdjectiveEnding(int article_type, int grammatical_case, int grammatical_number, int grammatical_gender);
763 void RemoveWord(LanguageWord *word);
764
765 std::string Ident; /// Ident of the language
766 std::string Name; /// Name of the language
767 std::string Family; /// Family of the language
768 std::string NounEndings[MaxGrammaticalNumbers][MaxGrammaticalCases][MaxWordJunctionTypes];
769 std::string AdjectiveEndings[MaxArticleTypes][MaxGrammaticalCases][MaxGrammaticalNumbers][MaxGrammaticalGenders];
770 bool UsedByCivilizationOrFaction;
771 CLanguage *DialectOf; /// Of which language this is a dialect of (if at all); dialects inherit the words from the parent language unless specified otherwise
772 std::vector<CLanguage *> Dialects; /// Dialects of this language
773 std::vector<LanguageWord *> LanguageWords; /// Words of the language
774 std::map<std::string, std::vector<std::string>> NameTranslations; /// Name translations; possible translations mapped to the name to be translated
775 };
776 //Wyrmgus end
777
778 /**
779 ** Races for the player
780 ** Mapped with #PlayerRaces to a symbolic name.
781 */
782 class PlayerRace
783 {
784 public:
PlayerRace()785 PlayerRace()
786 {
787 memset(Visible, 0, sizeof(Visible));
788 //Wyrmgus start
789 memset(Playable, 0, sizeof(Playable));
790 //Wyrmgus end
791 }
792
793 void Clean();
794 //Wyrmgus start
795 int GetFactionIndexByName(const std::string &faction_ident) const;
796 CFaction *GetFaction(const std::string &faction_ident) const;
797 CDynasty *GetDynasty(const std::string &dynasty_ident) const;
798 CLanguage *GetLanguage(const std::string &language_ident) const;
799 int GetCivilizationClassUnitType(int civilization, int class_id);
800 int GetCivilizationClassUpgrade(int civilization, int class_id);
801 int GetFactionClassUnitType(int faction, int class_id);
802 int GetFactionClassUpgrade(int faction, int class_id);
803 CLanguage *GetCivilizationLanguage(int civilization);
804 std::vector<CFiller> GetCivilizationUIFillers(int civilization);
805 std::vector<CFiller> GetFactionUIFillers(int faction);
806 std::string TranslateName(const std::string &name, CLanguage *language);
807 //Wyrmgus end
808
809 public:
810 bool Visible[MAX_RACES]; /// race should be visible in pulldown
811 std::string Name[MAX_RACES]; /// race names
812 std::string Display[MAX_RACES]; /// text to display in pulldown
813 //Wyrmgus start
814 bool Playable[MAX_RACES]; /// civilization is playable?
815 std::string Species[MAX_RACES]; /// civilization's species (i.e. human)
816 std::string DefaultColor[MAX_RACES]; /// name of the civilization's default color (used for the encyclopedia, tech tree, etc.)
817 std::string CivilizationUpgrades[MAX_RACES];
818 std::map<int, int> CivilizationClassUnitTypes[MAX_RACES]; /// the unit type slot of a particular class for a particular civilization
819 std::map<int, int> CivilizationClassUpgrades[MAX_RACES]; /// the upgrade slot of a particular class for a particular civilization
820 std::map<int, IconConfig> ButtonIcons[MAX_RACES]; /// icons for button actions
821 std::vector<CFaction *> Factions; /// factions
822 std::vector<int> DevelopsFrom[MAX_RACES]; /// from which civilizations this civilization develops
823 std::vector<int> DevelopsTo[MAX_RACES]; /// to which civilizations this civilization develops
824 std::vector<CFiller> CivilizationUIFillers[MAX_RACES];
825 std::vector<CLanguage *> Languages; /// languages
826 std::vector<CDynasty *> Dynasties; /// dynasties
827 //Wyrmgus end
828 };
829
830
831 enum PlayerRacesOld {
832 PlayerRaceHuman = 0, /// belongs to human
833 PlayerRaceOrc = 1 /// belongs to orc
834 };
835
836 /**
837 ** Types for the player
838 **
839 ** #PlayerNeutral
840 **
841 ** This player is controlled by the computer doing nothing.
842 **
843 ** #PlayerNobody
844 **
845 ** This player is unused. Nobody controls this player.
846 **
847 ** #PlayerComputer
848 **
849 ** This player is controlled by the computer. CPlayer::AiNum
850 ** selects the AI strategy.
851 **
852 ** #PlayerPerson
853 **
854 ** This player is contolled by a person. This can be the player
855 ** sitting on the local computer or player playing over the
856 ** network.
857 **
858 ** #PlayerRescuePassive
859 **
860 ** This player does nothing, the game pieces just sit in the game
861 ** (being passive)... when a person player moves next to a
862 ** PassiveRescue unit/building, then it is "rescued" and becomes
863 ** part of that persons team. If the city center is rescued, than
864 ** all units of this player are rescued.
865 **
866 ** #PlayerRescueActive
867 **
868 ** This player is controlled by the computer. CPlayer::AiNum
869 ** selects the AI strategy. Until it is rescued it plays like
870 ** an ally. The first person which reaches units of this player,
871 ** can rescue them. If the city center is rescued, than all units
872 ** of this player are rescued.
873 */
874 enum PlayerTypes {
875 PlayerNeutral = 2, /// neutral
876 PlayerNobody = 3, /// unused slot
877 PlayerComputer = 4, /// computer player
878 PlayerPerson = 5, /// human player
879 PlayerRescuePassive = 6, /// rescued passive
880 PlayerRescueActive = 7 /// rescued active
881 };
882
883 #define PlayerNumNeutral (PlayerMax - 1) /// this is the neutral player slot
884
885 /**
886 ** Notify types. Noties are send to the player.
887 */
888 enum NotifyType {
889 NotifyRed, /// Red alram
890 NotifyYellow, /// Yellow alarm
891 NotifyGreen /// Green alarm
892 };
893
894 /*----------------------------------------------------------------------------
895 -- Variables
896 ----------------------------------------------------------------------------*/
897
898 extern int NumPlayers; /// How many player slots used
899 extern CPlayer Players[PlayerMax]; /// All players
900 extern CPlayer *ThisPlayer; /// Player on local computer
901 extern bool NoRescueCheck; /// Disable rescue check
902 //Wyrmgus start
903 //extern std::vector<CColor> PlayerColorsRGB[PlayerMax]; /// Player colors
904 //extern std::vector<IntColor> PlayerColors[PlayerMax]; /// Player colors
905 //extern std::string PlayerColorNames[PlayerMax]; /// Player color names
906 extern std::vector<CColor> PlayerColorsRGB[PlayerColorMax]; /// Player colors
907 extern std::vector<IntColor> PlayerColors[PlayerColorMax]; /// Player colors
908 extern std::string PlayerColorNames[PlayerColorMax]; /// Player color names
909 extern std::vector<int> ConversiblePlayerColors; /// Conversible player colors
910
911 extern std::map<std::string, int> FactionStringToIndex;
912 extern std::map<std::string, int> DynastyStringToIndex;
913
914 extern bool LanguageCacheOutdated;
915 //Wyrmgus end
916
917 extern PlayerRace PlayerRaces; /// Player races
918
919 /**
920 ** Which indexes to replace with player color
921 */
922 extern int PlayerColorIndexStart;
923 extern int PlayerColorIndexCount;
924
925 /*----------------------------------------------------------------------------
926 -- Functions
927 ----------------------------------------------------------------------------*/
928
929 /// Init players
930 extern void InitPlayers();
931 /// Clean up players
932 extern void CleanPlayers();
933 /// Save players
934 extern void SavePlayers(CFile &file);
935
936 /// Create a new player
937 extern void CreatePlayer(int type);
938
939 //Wyrmgus start
940 extern CPlayer *GetFactionPlayer(const CFaction *faction);
941 extern CPlayer *GetOrAddFactionPlayer(const CFaction *faction);
942 //Wyrmgus end
943
944 /// Initialize the computer opponent AI
945 extern void PlayersInitAi();
946 /// Called each game cycle for player handlers (AI)
947 extern void PlayersEachCycle();
948 /// Called each second for a given player handler (AI)
949 extern void PlayersEachSecond(int player);
950 //Wyrmgus start
951 /// Called each half minute for a given player handler (AI)
952 extern void PlayersEachHalfMinute(int player);
953 /// Called each minute for a given player handler (AI)
954 extern void PlayersEachMinute(int player);
955 //Wyrmgus end
956
957 /// Change current color set to new player of the sprite
958 //Wyrmgus start
959 //extern void GraphicPlayerPixels(CPlayer &player, const CGraphic &sprite);
960 extern void GraphicPlayerPixels(int player, const CGraphic &sprite);
961 //Wyrmgus end
962
963 /// Output debug information for players
964 extern void DebugPlayers();
965
966 void FreePlayerColors();
967
968 /// register ccl features
969 extern void PlayerCclRegister();
970
971 /// Allowed to select multiple units, maybe not mine
CanSelectMultipleUnits(const CPlayer & player)972 inline bool CanSelectMultipleUnits(const CPlayer &player) { return &player == ThisPlayer || ThisPlayer->IsTeamed(player); }
973
974 //Wyrmgus start
975 extern void SetFactionStringToIndex(const std::string &faction_name, int faction_id);
976 extern void NetworkSetFaction(int player, const std::string &faction_name);
977 extern int GetPlayerColorIndexByName(const std::string &player_color_name);
978 extern std::string GetFactionTypeNameById(int faction_type);
979 extern int GetFactionTypeIdByName(const std::string &faction_type);
980 extern std::string GetGovernmentTypeNameById(int government_type);
981 extern int GetGovernmentTypeIdByName(const std::string &government_type);
982 extern std::string GetForceTypeNameById(int force_type);
983 extern int GetForceTypeIdByName(const std::string &force_type);
984 extern std::string GetWordTypeNameById(int word_type);
985 extern int GetWordTypeIdByName(const std::string &word_type);
986 extern std::string GetArticleTypeNameById(int article_type);
987 extern int GetArticleTypeIdByName(const std::string &article_type);
988 extern std::string GetGrammaticalCaseNameById(int grammatical_case);
989 extern int GetGrammaticalCaseIdByName(const std::string &grammatical_case);
990 extern std::string GetGrammaticalNumberNameById(int grammatical_number);
991 extern int GetGrammaticalNumberIdByName(const std::string &grammatical_number);
992 extern std::string GetGrammaticalPersonNameById(int grammatical_person);
993 extern int GetGrammaticalPersonIdByName(const std::string &grammatical_person);
994 extern std::string GetGrammaticalGenderNameById(int grammatical_gender);
995 extern int GetGrammaticalGenderIdByName(const std::string &grammatical_gender);
996 extern std::string GetGrammaticalTenseNameById(int grammatical_tense);
997 extern int GetGrammaticalTenseIdByName(const std::string &grammatical_tense);
998 extern std::string GetGrammaticalMoodNameById(int grammatical_mood);
999 extern int GetGrammaticalMoodIdByName(const std::string &grammatical_mood);
1000 extern std::string GetComparisonDegreeNameById(int comparison_degree);
1001 extern int GetComparisonDegreeIdByName(const std::string &comparison_degree);
1002 extern std::string GetAffixTypeNameById(int affix_type);
1003 extern int GetAffixTypeIdByName(const std::string &affix_type);
1004 extern std::string GetWordJunctionTypeNameById(int word_junction_type);
1005 extern int GetWordJunctionTypeIdByName(const std::string &word_junction_type);
1006 extern bool IsNameValidForWord(const std::string &word_name);
1007
1008 /*----------------------------------------------------------------------------
1009 -- Variables
1010 ----------------------------------------------------------------------------*/
1011
1012 extern std::map<std::string, CLanguage *> LanguageIdentToPointer;
1013 //Wyrmgus end
1014
1015 //@}
1016
1017 #endif // !__PLAYER_H__
1018