1 /* GemRB - Infinity Engine Emulator
2  * Copyright (C) 2003 The GemRB Project
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  *
19  */
20 
21 #ifndef CHARANIMATIONS_H
22 #define CHARANIMATIONS_H
23 
24 #include "RGBAColor.h"
25 #include "exports.h"
26 
27 #include "Animation.h"
28 #include "Palette.h"
29 #include "TableMgr.h"
30 
31 #include <vector>
32 
33 namespace GemRB {
34 
35 #define AV_PREFIX1      0
36 #define AV_PREFIX2      1
37 #define AV_PREFIX3      2
38 #define AV_PREFIX4      3
39 #define AV_ANIMTYPE     4
40 #define AV_CIRCLESIZE   5
41 #define AV_USE_PALETTE  6
42 #define AV_SIZE         7
43 
44 #define MAX_ANIMS				19
45 
46 #define IE_ANI_ATTACK			0
47 #define IE_ANI_AWAKE			1
48 #define IE_ANI_CAST			2
49 #define IE_ANI_CONJURE			3
50 #define IE_ANI_DAMAGE			4
51 #define IE_ANI_DIE			5
52 #define IE_ANI_HEAD_TURN		6
53 #define IE_ANI_READY			7
54 #define IE_ANI_SHOOT			8
55 #define IE_ANI_TWITCH			9
56 #define IE_ANI_WALK			10
57 #define IE_ANI_ATTACK_SLASH		11
58 #define IE_ANI_ATTACK_BACKSLASH		12
59 #define IE_ANI_ATTACK_JAB		13
60 #define IE_ANI_EMERGE			14
61 #define IE_ANI_HIDE			15
62 #define IE_ANI_RUN			15 //pst has no hide, i hope
63 #define IE_ANI_SLEEP			16
64 #define IE_ANI_GET_UP			17
65 #define IE_ANI_PST_START		18
66 // NOTE: update MAX_ANIMS if you add more!
67 
68 //BG2, IWD animation types
69 #define IE_ANI_CODE_MIRROR		0
70 #define IE_ANI_ONE_FILE			1
71 #define IE_ANI_FOUR_FILES		2
72 #define IE_ANI_TWO_FILES		3
73 #define IE_ANI_CODE_MIRROR_2		4
74 #define IE_ANI_SIX_FILES_2		5    //MOGR
75 #define IE_ANI_TWENTYTWO		6
76 #define IE_ANI_BIRD				7
77 #define IE_ANI_SIX_FILES		8    //MCAR/MWYV
78 #define IE_ANI_TWO_FILES_3		9    //iwd animations
79 #define IE_ANI_TWO_FILES_2		10   //low res bg1 anim
80 #define IE_ANI_FOUR_FRAMES		11   //wyvern anims
81 #define IE_ANI_NINE_FRAMES		12   //dragon anims
82 #define IE_ANI_FRAGMENT                 13   //fragment animation
83 #define IE_ANI_FOUR_FILES_2		14 //METT
84 #define IE_ANI_CODE_MIRROR_3	15 //MSPS
85 #define IE_ANI_TWO_FILES_3B		16    //iwd animations (eg. MBBM)
86 #define IE_ANI_TWO_PIECE		17    //MAKH
87 #define IE_ANI_FOUR_FILES_3		18    //mostly civilians
88 #define IE_ANI_TWO_FILES_4		19
89 #define IE_ANI_FOUR_FRAMES_2	20    //MDEM
90 #define IE_ANI_TWO_FILES_5		21 //MMEL
91 #define IE_ANI_TWO_FILES_3C		22    //iwd animations (eg. MWDR)
92 
93 //PST animation types
94 #define IE_ANI_PST_ANIMATION_1		56   //full animation
95 #define IE_ANI_PST_GHOST		57   //no orientations
96 #define IE_ANI_PST_STAND		58   //has orientations
97 #define IE_ANI_PST_ANIMATION_2		59   //full animation std-->stc
98 #define IE_ANI_PST_ANIMATION_3		60   //full animation stc-->std
99 
100 //armour levels
101 #define IE_ANI_NO_ARMOR			0
102 #define IE_ANI_LIGHT_ARMOR		1
103 #define IE_ANI_MEDIUM_ARMOR		2
104 #define IE_ANI_HEAVY_ARMOR		3
105 
106 #define IE_ANI_WEAPON_1H		0
107 #define IE_ANI_WEAPON_2H		1
108 #define IE_ANI_WEAPON_2W		2
109 
110 #define IE_ANI_RANGED_BOW		0
111 #define IE_ANI_RANGED_XBOW		1
112 #define IE_ANI_RANGED_THROW		2
113 
114 //special flags
115 #define AV_NO_BODY_HEAT                 1
116 
117 enum PaletteType {
118 	PAL_MAIN,
119 	PAL_MAIN_2,
120 	PAL_MAIN_3,
121 	PAL_MAIN_4,
122 	PAL_MAIN_5,
123 	PAL_WEAPON,
124 	PAL_OFFHAND,
125 	PAL_HELMET,
126 	PAL_MAX
127 };
128 
129 struct AvatarStruct {
130 	/* entries from avatars.2da */
131 	unsigned int AnimID;
132 	unsigned int PaletteType;
133 	ieResRef Prefixes[4];
134 	unsigned char AnimationType;
135 	unsigned char CircleSize;
136 	char Size;
137 
138 	/* comes from bloodclr.2da */
139 	char BloodColor;
140 	unsigned int Flags;
141 
142 	/* resdata.ini entries */
143 	unsigned int WalkScale; /* 1000 / walkscale */
144 	unsigned int RunScale; /* 1000 / runscale */
145 	int Bestiary;
146 
147 	/* comes from walksnd.2da */
148 	ieResRef WalkSound;
149 	ieByte WalkSoundCount;
150 
151 	/* comes from stances.2da */
152 	unsigned char StanceOverride[MAX_ANIMS];
153 
154 	ieResRef ShadowAnimation;
155 };
156 
157 struct EquipResRefData;
158 
159 class GEM_EXPORT CharAnimations {
160 private:
161 	Animation** Anims[MAX_ANIMS][MAX_ORIENT];
162 	Animation** shadowAnimations[MAX_ANIMS][MAX_ORIENT];
163 	char HelmetRef[2];
164 	char WeaponRef[2];
165 	char OffhandRef[2];
166 public:
167 	const ieDword *Colors; //these are the custom color indices
168 	RGBModifier ColorMods[PAL_MAX*8]; // color modification effects
169 	unsigned long lastModUpdate;
170 	RGBModifier GlobalColorMod; // global color modification effect
171 
172 	bool change[PAL_MAX];
173 	PaletteHolder PartPalettes[PAL_MAX];
174 	PaletteHolder ModPartPalettes[PAL_MAX];
175 	PaletteHolder shadowPalette;
176 	unsigned int AvatarsRowNum;
177 	unsigned char ArmorType, WeaponType, RangedType;
178 	ieResRef ResRef;
179 	ieResRef PaletteResRef[5];
180 	unsigned char previousStanceID, nextStanceID, StanceID;
181 	bool autoSwitchOnEnd;
182 	bool lockPalette;
183 public:
184 	CharAnimations(unsigned int AnimID, ieDword ArmourLevel);
185 	~CharAnimations(void);
186 	static void ReleaseMemory();
187 	void SetArmourLevel(int ArmourLevel);
188 	void SetRangedType(int Ranged);
189 	void SetWeaponType(int WeaponType);
190 	void SetHelmetRef(const char* ref);
191 	void SetWeaponRef(const char* ref);
192 	void SetOffhandRef(const char* ref);
193 	void SetColors(const ieDword *Colors);
194 	void CheckColorMod();
195 	void SetupColors(PaletteType type);
196 	void LockPalette(const ieDword *Colors);
197 
198 	// returns an array of animations of size GetTotalPartCount()
199 	Animation** GetAnimation(unsigned char Stance, unsigned char Orient);
200 	int GetTotalPartCount() const;
201 	const int* GetZOrder(unsigned char Orient);
202 	Animation** GetShadowAnimation(unsigned char Stance, unsigned char Orient);
203 
204 	// returns Palette for a given part (unlocked)
205 	PaletteHolder GetPartPalette(int part); // TODO: clean this up
206 	PaletteHolder GetShadowPalette() const;
207 
208 public: //attribute functions
209 	static int GetAvatarsCount();
210 	static AvatarStruct *GetAvatarStruct(int RowNum);
211 	unsigned int GetAnimationID() const;
212 	int GetCircleSize() const;
213 	int NoPalette() const;
214 	int GetAnimType() const;
215 	int GetSize() const;
216 	int GetBloodColor() const;
217 	unsigned int GetFlags() const;
218 	const ieResRef &GetWalkSound() const;
219 	int GetWalkSoundCount() const;
220 	const ieResRef &GetArmourLevel(int ArmourLevel) const;
221 	void PulseRGBModifiers();
222 	void DebugDump();
223 private:
224 	void DropAnims();
225 	void InitAvatarsTable();
226 	int GetActorPartCount() const;
227 	void AddPSTSuffix(char *dest, unsigned char AnimID,
228 		unsigned char& Cycle, unsigned char Orient);
229 	void AddFFSuffix(char *dest, unsigned char AnimID,
230 		unsigned char& Cycle, unsigned char Orient, int Part);
231 	void AddFF2Suffix(char *dest, unsigned char AnimID,
232 		unsigned char& Cycle, unsigned char Orient, int Part) const;
233 	void AddHLSuffix(char *dest, unsigned char AnimID,
234 		unsigned char& Cycle, unsigned char Orient);
235 	void AddNFSuffix(char *dest, unsigned char AnimID,
236 		unsigned char& Cycle, unsigned char Orient, int Part);
237 	void AddVHR2Suffix(char *dest, unsigned char AnimID,
238 		unsigned char& Cycle, unsigned char Orient);
239 	void AddVHRSuffix(char *dest, unsigned char AnimID,
240 		unsigned char& Cycle, unsigned char Orient, EquipResRefData*& equip);
241 	void AddVHR3Suffix(char *dest, unsigned char AnimID,
242 		unsigned char& Cycle, unsigned char Orient);
243 	void GetVHREquipmentRef(char *dest, unsigned char& Cycle,
244 		const char* equipRef, bool offhand, EquipResRefData* equip);
245 	void AddSixSuffix(char *dest, unsigned char AnimID,
246 		unsigned char& Cycle, unsigned char Orient);
247 	void AddTwoPieceSuffix(char *dest, unsigned char AnimID,
248 		unsigned char& Cycle, unsigned char Orient, int Part);
249 	void AddMHRSuffix(char *dest, unsigned char AnimID,
250 		unsigned char& Cycle, unsigned char Orient, EquipResRefData*& equip);
251 	void GetMHREquipmentRef(char *dest, unsigned char& Cycle,
252 		const char* equipRef, bool offhand, EquipResRefData* equip);
253 	void AddMMRSuffix(char *dest, unsigned char AnimID,
254 		unsigned char& Cycle, unsigned char Orient, bool mirror);
255 	void AddMMR2Suffix(char *dest, unsigned char AnimID,
256 		unsigned char& Cycle, unsigned char Orient);
257 	void AddTwoFileSuffix(char *dest, unsigned char AnimID,
258 		unsigned char& Cycle, unsigned char Orient);
259 	void AddTwoFiles5Suffix(char *dest, unsigned char AnimID,
260 		unsigned char& Cycle, unsigned char Orient);
261 	void AddLRSuffix(char *dest, unsigned char AnimID,
262 		unsigned char& Cycle, unsigned char Orient, EquipResRefData*& equip);
263 	void AddLRSuffix2( char *dest, unsigned char StanceID,
264 		unsigned char& Cycle, unsigned char Orient, EquipResRefData *&EquipData);
265 	void GetLREquipmentRef(char *dest, unsigned char& Cycle,
266 		const char* equipRef, bool offhand, EquipResRefData* equip);
267 	void AddLR2Suffix(char *dest, unsigned char AnimID,
268 		unsigned char& Cycle, unsigned char Orient);
269 	void AddLR3Suffix(char *dest, unsigned char AnimID,
270 		unsigned char& Cycle, unsigned char Orient);
271 	void GetAnimResRef(unsigned char AnimID, unsigned char Orient,
272 		char *dest, unsigned char& Cycle, int Part, EquipResRefData*& equip);
273 	void GetEquipmentResRef(const char* equipRef, bool offhand,
274 		char *dest, unsigned char& Cycle, EquipResRefData* equip);
275 	unsigned char MaybeOverrideStance(unsigned char stance) const;
276 	void MaybeUpdateMainPalette(Animation**);
277 };
278 
279 }
280 
281 #endif
282