1 /*
2  * Seven Kingdoms: Ancient Adversaries
3  *
4  * Copyright 1997,1998 Enlight Software Ltd.
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  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 //Filename    : OSPRTRES.H
22 //Description : Header file of Object Sprite resource
23 
24 #ifndef __OSPRTRES_H
25 #define __OSPRTRES_H
26 
27 #ifndef __ALL_H
28 #include <ALL.h>
29 #endif
30 
31 #ifndef __ORESDB_H
32 #include <ORESDB.h>
33 #endif
34 
35 //-------- Define struct SpriteRec ----------//
36 
37 struct SpriteRec
38 {
39 	enum { CODE_LEN=8, RECNO_LEN=5, COUNT_LEN=5, SPRITE_PARA_LEN=2, DAMAGE_LEN=3, TURN_RES_LEN=2 };
40 
41 	char sprite_code[CODE_LEN];
42 
43 	char sprite_type;
44 	char sprite_sub_type;
45 
46 	char need_turning;
47 	char turn_resolution[TURN_RES_LEN];
48 
49 	char loc_width[SPRITE_PARA_LEN];
50 	char loc_height[SPRITE_PARA_LEN];
51 
52 	char speed[SPRITE_PARA_LEN];
53 	char frames_per_step[SPRITE_PARA_LEN];
54 	char max_rain_slowdown[SPRITE_PARA_LEN];
55 	char max_snow_slowdown[SPRITE_PARA_LEN];
56 	char lightning_damage[DAMAGE_LEN];
57 	// ###### begin Gilbert 21/8 #######//
58 	char remap_bitmap_flag;
59 	// ###### end Gilbert 21/8 #######//
60 
61 	char first_move_recno[RECNO_LEN];
62 	char move_count[COUNT_LEN];
63 };
64 
65 //----- Define struct SpriteActionRec ------//
66 
67 struct SpriteActionRec
68 {
69 	enum { NAME_LEN=8, ACTION_LEN=2, DIR_ID_LEN=2, RECNO_LEN=5, COUNT_LEN=2 };
70 
71 	char sprite_name[NAME_LEN];
72 	char action[ACTION_LEN];
73 	char dir_id[DIR_ID_LEN];
74 	char first_frame_recno[RECNO_LEN];
75 	char frame_count[COUNT_LEN];
76 };
77 
78 //----- Define struct SpriteMove ------//
79 
80 struct SpriteMove
81 {
82 	short first_frame_recno;		// first frame recno to frame_array.
83 	char  frame_count;				// no. of frames in the movement
84 };
85 
86 //----- Define struct SpriteAttack ------//
87 
88 struct SpriteAttack
89 {
90 	short first_frame_recno;		// first frame recno to frame_array.
91 	char  frame_count;				// no. of frames in the movement
92 	char  attack_delay;		      // no. of frames should be delayed between attack motions. (i.e. when one motion is complete, it will delay <delay_frames> before move on to the next action motion in the cycle
93 };
94 
95 //----- Define struct SpriteStop ------//
96 
97 struct SpriteStop
98 {
99 	short frame_recno;		// frame recno to frame_array.
100 	char	frame_count;
101 };
102 
103 //----- Define struct SpriteDie ------//
104 
105 struct SpriteDie
106 {
107 	short first_frame_recno;		// first frame recno to frame_array.
108 	char  frame_count;				// no. of frames in the movement
109 };
110 
111 //----- Define struct SpriteGuard ------//
112 
113 struct SpriteGuardStop
114 {
115 	short first_frame_recno;		// first frame recno to frame_array.
116 	char	frame_count;
117 };
118 
119 //----- Define struct SpriteGuard ------//
120 
121 struct SpriteGuardMove
122 {
123 	short first_frame_recno;		// first frame recno to frame_array.
124 	char  frame_count;				// no. of frames in the movement
125 };
126 
127 //---------- Define struct SpriteInfo -----------//
128 struct SubSpriteInfo;
129 
130 struct SpriteInfo
131 {
132 public:
133 	enum { CODE_LEN=8 };
134 
135 	char 			 sprite_code[CODE_LEN+1];
136 
137 	char			 sprite_type;
138 	char			 sprite_sub_type;
139 
140 	char 			 need_turning;
141 	char			 turn_resolution;
142 
143 	short			 loc_width;			// no. of locations it takes horizontally and vertically
144 	short 		 loc_height;
145 
146 	int 			 speed;					// based on UnitRes, can be upgraded during the game.
147 	int				 frames_per_step;
148 	int				 max_rain_slowdown;
149 	int				 max_snow_slowdown;
150 	int				 lightning_damage;
151 	// ###### begin Gilbert 21/8 #######//
152 	char			 remap_bitmap_flag;
153 	// ###### end Gilbert 21/8 #######//
154 	int				 max_speed;				// original speed
155 	char			 can_guard_flag;            // bit0= standing guard, bit1=moving guard
156 
157 	int  			 loaded_count;			// if it >= 1, it has been loaded into the memory
158 	ResourceDb	 res_bitmap;			// frame bitmap resource
159 
160 	// move_array[24] to cater upward and downward directions for projectile
161 	// and also 16-direction movement for weapons
162 	SpriteMove 	 move_array[3*MAX_SPRITE_DIR_TYPE];
163 	SpriteAttack attack_array[MAX_UNIT_ATTACK_TYPE][MAX_SPRITE_DIR_TYPE];
164 	SpriteStop	 stop_array[3*MAX_SPRITE_DIR_TYPE];
165 	SpriteDie	 die;
166 	SpriteGuardStop guard_stop_array[MAX_SPRITE_DIR_TYPE];
167 	SpriteGuardMove guard_move_array[MAX_SPRITE_DIR_TYPE];
168 
169 	int			sub_sprite_count;
170 	SubSpriteInfo	*sub_sprite_info;
171 
172 public:
173 	~SpriteInfo();
174 
175 	void			 load_bitmap_res();
176 	void			 free_bitmap_res();
177 
is_loadedSpriteInfo178 	int			 is_loaded()		{ return loaded_count>0; }
179 	SpriteInfo *get_sub_sprite(int i);
180 	SubSpriteInfo *get_sub_sprite_info(int i);
can_stand_guardSpriteInfo181 	int			 can_stand_guard()  { return can_guard_flag & 1;}
can_move_guardSpriteInfo182 	int			 can_move_guard()  { return can_guard_flag & 2;};
183 
184 	int 			 travel_days(int travelDistance);
185 };
186 
187 //------ Define struct SubSpriteRec ---------//
188 
189 struct SubSpriteRec
190 {
191 	enum { CODE_LEN=8, SUB_NO_LEN=3, OFFSET_LEN=3, RECNO_LEN=3 };
192 	char sprite_code[CODE_LEN];
193 	char sub_no[SUB_NO_LEN];
194 	char sub_sprite_code[CODE_LEN];
195 	char offset_x[OFFSET_LEN];
196 	char offset_y[OFFSET_LEN];
197 	char sprite_id[RECNO_LEN];
198 	char sub_sprite_id[RECNO_LEN];
199 };
200 
201 // ------ Define struct SubSpriteInfo ---------//
202 
203 struct SubSpriteInfo
204 {
205 	SpriteInfo *sprite_info;
206 	short sprite_id;
207 	short offset_x;
208 	short offset_y;
209 };
210 
211 
212 //---------- Define class SpriteRes ------------//
213 
214 class SpriteRes
215 {
216 public:
217 	char init_flag;
218 	int  sprite_info_count;
219 
220 private:
221 	SpriteInfo* sprite_info_array;
222 	SubSpriteInfo *sub_sprite_info_array;
223 
224 public:
SpriteRes()225 	SpriteRes() 	{ init_flag=0; }
226 
227 	void	init();
228 	void  deinit();
229 
230 	void	update_speed();
231 
232 	#ifdef DYNARRAY_DEBUG_ELEMENT_ACCESS
233 		SpriteInfo* operator[](int recNo);
234 	#else
235 		SpriteInfo* operator[](int recNo)   { return sprite_info_array+recNo-1; }
236 	#endif
237 
238 private:
239 	void	load_sprite_info();
240 	void	load_sub_sprite_info();
241 };
242 
243 extern SpriteRes sprite_res;
244 
245 //----------------------------------------------//
246 
247 #endif
248 
249