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 upgrade_structs.h - The upgrade/allow header file. */
12 //
13 //      (c) Copyright 1999-2019 by Vladi Belperchinov-Shabanski,
14 //		Jimmy Salmon and Andrettin
15 //
16 //      This program is free software; you can redistribute it and/or modify
17 //      it under the terms of the GNU General Public License as published by
18 //      the Free Software Foundation; only version 2 of the License.
19 //
20 //      This program is distributed in the hope that it will be useful,
21 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
22 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 //      GNU General Public License for more details.
24 //
25 //      You should have received a copy of the GNU General Public License
26 //      along with this program; if not, write to the Free Software
27 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 //      02111-1307, USA.
29 //
30 
31 #ifndef __UPGRADE_STRUCTS_H__
32 #define __UPGRADE_STRUCTS_H__
33 
34 /*----------------------------------------------------------------------------
35 --  Includes
36 ----------------------------------------------------------------------------*/
37 
38 #include "data_type.h"
39 //Wyrmgus start
40 #include "item.h"
41 //Wyrmgus end
42 #include "resource.h"
43 
44 #include <vector>
45 
46 /*----------------------------------------------------------------------------
47 --  Defines
48 ----------------------------------------------------------------------------*/
49 
50 /*----------------------------------------------------------------------------
51 --  Declarations
52 ----------------------------------------------------------------------------*/
53 
54 class CCharacter;
55 class CDeityDomain;
56 class CDependency;
57 class CIcon;
58 class CSchoolOfMagic;
59 class CUniqueItem;
60 class CUnitType;
61 class CUpgradeModifier;
62 class CVariable;
63 struct lua_State;
64 
65 /**
66 **  These are the current stats of a unit. Upgraded or downgraded.
67 */
68 class CUnitStats
69 {
70 public:
CUnitStats()71 	CUnitStats() : Variables(nullptr)
72 	{
73 		memset(Costs, 0, sizeof(Costs));
74 		memset(Storing, 0, sizeof(Storing));
75 		memset(ImproveIncomes, 0, sizeof(ImproveIncomes));
76 		memset(ResourceDemand, 0, sizeof(ResourceDemand));
77 	}
78 	~CUnitStats();
79 
80 	const CUnitStats &operator = (const CUnitStats &rhs);
81 
82 	bool operator == (const CUnitStats &rhs) const;
83 	bool operator != (const CUnitStats &rhs) const;
84 
85  	int GetPrice() const;
86 	int GetUnitStock(CUnitType *unit_type) const;
87 	void SetUnitStock(CUnitType *unit_type, int quantity);
88 	void ChangeUnitStock(CUnitType *unit_type, int quantity);
89 public:
90 	CVariable *Variables;           /// user defined variable.
91 	int Costs[MaxCosts];            /// current costs of the unit
92 	int Storing[MaxCosts];          /// storage increasing
93 	int ImproveIncomes[MaxCosts];   /// Gives player an improved income
94 	int ResourceDemand[MaxCosts];	/// Resource demand
95 	std::map<CUnitType *, int> UnitStock;	/// Units in stock
96 };
97 
98 /**
99 **  The main useable upgrades.
100 */
101 class CUpgrade : public CDataType
102 {
103 public:
104 	CUpgrade(const std::string &ident);
105 	~CUpgrade();
106 
107 	static CUpgrade *New(const std::string &ident);
108 	static CUpgrade *Get(const std::string &ident);
109 
110 	virtual void ProcessConfigData(const CConfigData *config_data) override;
111 
112 	void SetIcon(CIcon *icon);
113 
114 	std::string Name;                 /// upgrade label
115 	//Wyrmgus start
116 	int Class = -1;					/// upgrade class (i.e. siege weapon projectile I)
117 	int Civilization = -1;			/// which civilization this upgrade belongs to, if any
118 	int Faction = -1;				/// which faction this upgrade belongs to, if any
119 	std::string Description;		/// Description of the upgrade
120 	std::string Quote;				/// Quote of the upgrade
121 	std::string Background;			/// Encyclopedia entry for the upgrade
122 	std::string EffectsString;		/// Effects string of the upgrade
123 	std::string RequirementsString;	/// Requirements string of the upgrade
124 	bool Ability = false;
125 	bool Weapon = false;
126 	bool Shield = false;
127 	bool Boots = false;
128 	bool Arrows = false;
129 	bool MagicPrefix = false;
130 	bool MagicSuffix = false;
131 	bool RunicAffix = false;
132 	bool UniqueOnly = false;		/// Whether (if this is a literary work) this should appear only on unique items (used, for instance, if a book has no copies of its text)
133 	bool ItemPrefix[MaxItemClasses];
134 	bool ItemSuffix[MaxItemClasses];
135 	bool IncompatibleAffixes[UpgradeMax];
136 	std::vector<int> WeaponClasses;		/// If isn't empty, one of these weapon classes will need to be equipped for the upgrade to be applied
137 	std::vector<std::string> Epithets;	/// Epithets when a character has a certain trait
138 	CUnitType *Item = nullptr;
139 	//Wyrmgus end
140 	int   ID = 0;						/// numerical id
141 	int   Costs[MaxCosts];				/// costs for the upgrade
142 	int   ScaledCosts[MaxCosts];		/// scaled costs for the upgrade
143 	//Wyrmgus start
144 	int GrandStrategyProductionEfficiencyModifier[MaxCosts];	/// Production modifier for a particular resource for grand strategy mode
145 	int MaxLimit = 1;					/// Maximum amount of times this upgrade can be acquired as an individual upgrade
146 	int MagicLevel = 0;					/// Magic level of an affix
147 	int Work = -1;						/// Form in which was inscribed (i.e. scroll or book), if is a literary work
148 	int Year = 0;						/// Year of publication, if is a literary work
149 	CCharacter *Author = nullptr;		/// Author of this literary work (if it is one)
150 	std::vector<CUpgradeModifier *> UpgradeModifiers;	/// Upgrade modifiers for this upgrade
151 	std::vector<CUniqueItem *> UniqueItems;	/// Unique items who form a part of this set upgrade
152 	std::vector<CUnitType *> ScaledCostUnits;	/// Units for which the upgrade's costs are scaled
153 	std::vector<CDeityDomain *> DeityDomains;	/// Deity domains to which this ability belongs
154 	std::vector<CSchoolOfMagic *> SchoolsOfMagic;	/// Schools of magic to which this ability belongs
155 	std::vector<CCharacter *> Characters;	/// Characters who appear in this literary work (if it is one)
156 	//Wyrmgus end
157 	// TODO: not used by buttons
158 	CIcon *Icon = nullptr;					/// icon to display to the user
159 	CDependency *Predependency = nullptr;
160 	CDependency *Dependency = nullptr;
161 };
162 
163 /**
164 **  Allow what a player can do. Every #CPlayer has an own allow struct.
165 **
166 **  This could allow/disallow units, actions or upgrades.
167 **
168 **  Values are:
169 **    @li `A' -- allowed,
170 **    @li `F' -- forbidden,
171 **    @li `R' -- acquired, perhaps other values
172 **    @li `Q' -- acquired but forbidden (does it make sense?:))
173 **    @li `E' -- enabled, allowed by level but currently forbidden
174 **    @li `X' -- fixed, acquired can't be disabled
175 */
176 class CAllow
177 {
178 public:
CAllow()179 	CAllow() { this->Clear(); }
180 
Clear()181 	void Clear()
182 	{
183 		memset(Units, 0, sizeof(Units));
184 		memset(Upgrades, 0, sizeof(Upgrades));
185 	}
186 
187 	int  Units[UnitTypeMax];        /// maximum amount of units allowed
188 	char Upgrades[UpgradeMax];      /// upgrades allowed/disallowed
189 };
190 
191 /**
192 **  Upgrade timer used in the player structure.
193 **  Every player has an own UpgradeTimers struct.
194 */
195 class CUpgradeTimers
196 {
197 public:
CUpgradeTimers()198 	CUpgradeTimers() { this->Clear(); }
199 
Clear()200 	void Clear()
201 	{
202 		memset(Upgrades, 0, sizeof(Upgrades));
203 	}
204 
205 	/**
206 	**  all 0 at the beginning, all upgrade actions do increment values in
207 	**  this struct.
208 	*/
209 	int Upgrades[UpgradeMax];       /// counter for each upgrade
210 };
211 
212 /*----------------------------------------------------------------------------
213 --  Variables
214 ----------------------------------------------------------------------------*/
215 
216 extern std::vector<CUpgrade *> AllUpgrades;  /// the main user usable upgrades
217 
218 #endif
219