1 /*
2  * Holotz's Castle
3  * Copyright (C) 2004 Juan Carlos Seijo P�rez
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the Free
7  * Software Foundation; either version 2 of the License, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc., 59
17  * Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Juan Carlos Seijo P�rez
20  * jacob@mainreactor.net
21  */
22 
23 /** Theme for Holotz's castle. Loads several resources as floors
24  * breaks, ladders, bars and characters.
25  * @file    HCTheme.h
26  * @author  Juan Carlos Seijo P�rez
27  * @date    01/06/2004
28  * @version 0.0.1 - 01/06/2004 - First version.
29  */
30 
31 #ifndef _HCTHEME_INCLUDED
32 #define _HCTHEME_INCLUDED
33 
34 #include <unistd.h>
35 #include <JLib/Util/JFile.h>
36 #include <JLib/Graphics/JImage.h>
37 #include <JLib/Graphics/JImageSprite.h>
38 #include <HCUtil.h>
39 
40 /** Type of floor image. Used to build dinamically the map.
41  */
42 enum HCFloorDrawType
43 {
44 	HCFDT_C = 0,                 /**< Corner with 3 neighbours. */
45 	HCFDT_C1,                    /**< DL corner. */
46 	HCFDT_C1DL,                  /**< DL corner with DL neighbours. */
47 	HCFDT_C3,                    /**< DR corner. */
48 	HCFDT_C3DR,                  /**< DR corner with DL neighbours. */
49 	HCFDT_C7,                    /**< UL corner. */
50 	HCFDT_C7UL,                  /**< UL corner with UR neighbours. */
51 	HCFDT_C9,                    /**< UR corner. */
52 	HCFDT_C9UR,                  /**< UR corner with UR neighbours. */
53 	HCFDT_CU,                    /**< C7 or C9 with U neighbour. */
54 	HCFDT_CD,                    /**< C1 or C3 with D neighbour. */
55 	HCFDT_CL,                    /**< C1 or C7 with L neighbour. */
56 	HCFDT_CR,                    /**< C3 or C9 with R neighbour. */
57 	HCFDT_S2,                    /**< D side. */
58 	HCFDT_S4,                    /**< L side. */
59 	HCFDT_S6,                    /**< R side. */
60 	HCFDT_S8,                    /**< U side. */
61 	HCFDT_SH,                    /**< U or D sides with U or D neighbour, respectively*/
62 	HCFDT_SV,                    /**< L or R sides with L or R neighbour, respectively*/
63 	HCFDT_I,                     /**< Inner part of the cell. */
64 	HCFDT_COUNT,                 /**< Number of floor part types. */
65 };
66 
67 /** Break sprite types.
68  */
69 enum HCBreakDrawType
70 {
71 	HCBDT_NORMAL = 0,
72 	HCBDT_BREAKING,
73 	HCBDT_BROKEN,
74 	HCBDT_COUNT,
75 };
76 
77 /** Object sprite types.
78  */
79 enum HCObjectDrawType
80 {
81 	HCODT_NORMAL = 0,
82 	HCODT_ACQUIRED,
83 	HCODT_COUNT,
84 };
85 
86 /** Rope image types.
87  */
88 enum HCRopeDrawType
89 {
90 	HCRDT_TOP = 0,
91 	HCRDT_MIDDLE,
92 	HCRDT_EDGE,
93 	HCRDT_COUNT,
94 };
95 
96 /** Character sprite types. Must be the same as
97  * HCCharacterState but is placed here to avoid circular references between
98  * the files.
99  */
100 enum HCCharacterDrawType
101 {
102 	HCCDT_STOP = 0,                       /**< Stopped state. */
103 	HCCDT_RIGHT,                          /**< Walk-right state. */
104 	HCCDT_LEFT,                           /**< Walk-left state. */
105 	HCCDT_UP,                             /**< Up state. */
106 	HCCDT_DOWN,                           /**< Down state. */
107 	HCCDT_SLIDE,                          /**< Slide state. */
108 	HCCDT_JUMP,                           /**< Jump left state. */
109 	HCCDT_JUMPLEFT,                       /**< Jump left state. */
110 	HCCDT_JUMPRIGHT,                      /**< Jump right state. */
111 	HCCDT_FALL,                           /**< Fall state. */
112 	HCCDT_DIE,                            /**< Die state. */
113 	HCCDT_HANG,                           /**< Hang state. */
114 	HCCDT_COUNT,                          /**< State count. */
115 };
116 
117 /** Text image types.
118  */
119 enum HCTextDrawType
120 {
121 	HCTDT_1 = 0,                          /**< Lower left corner */
122 	HCTDT_2,                              /**< Lower side */
123 	HCTDT_3,                              /**< Lower right corner */
124 	HCTDT_4,                              /**< Left side */
125 	HCTDT_5,                              /**< Center */
126 	HCTDT_6,                              /**< Right corner */
127 	HCTDT_7,                              /**< Upper left corner */
128 	HCTDT_8,                              /**< Up side */
129 	HCTDT_9,                              /**< Upper right corner */
130 	HCTDT_LEFT,                           /**< Lower left peak (only in dialogs) */
131 	HCTDT_RIGHT,                          /**< Lower right peak (only in dialogs) */
132 };
133 
134 /** Theme for Holotz's Castle.
135  */
136 class HCTheme
137 {
138  protected:
139 	JImage *imgFloor;                     /**< Floor images. */
140 	s32 numFloors;                        /**< Number of Floor variants. */
141 	JImage **imgContFloor;                /**< Continuous floor images. */
142 	s32 numContFloors;                    /**< Number of Continuous Floor variants. */
143 	JImageSprite **sprBreak;              /**< Break sprites. */
144 	s32 numBreaks;                        /**< Number of Break variants. */
145 	JImageSprite **sprObject;             /**< Object sprites. */
146 	s32 numObjects;                       /**< Number of Object variants. */
147 	JImage *imgBar;                       /**< Bar images. */
148 	s32 numBars;                          /**< Number of Bar variants. */
149 	JImage *imgLadder;                    /**< Ladder images. */
150 	s32 numLadders;                       /**< Number of Ladder variants. */
151 	JImage **imgRope;                     /**< Rope images. */
152 	s32 numRopes;                         /**< Number of Rope variants. */
153 	JImageSprite **sprMain;               /**< Main character sprites. */
154 	s32 numMains;                         /**< Number of Main character variants. */
155 	JImageSprite **sprGuest;              /**< Guest sprites. */
156 	s32 numGuests;                        /**< Number of guest variants. */
157 	JImageSprite **sprBall;               /**< Ball enemy sprites. */
158 	s32 numBalls;                         /**< Number of Ball variants. */
159 	JImageSprite **sprRandom;             /**< Random enemy sprites. */
160 	s32 numRandoms;                       /**< Number of Random variants. */
161 	JImageSprite **sprStatic;             /**< Static enemy sprites. */
162 	s32 numStatics;                       /**< Number of Static variants. */
163 	JImageSprite **sprMaker;              /**< Maker enemy sprites. */
164 	s32 numMakers;                        /**< Number of Maker variants. */
165 	JImageSprite **sprChaser;             /**< Chaser enemy sprites. */
166 	s32 numChasers;                       /**< Number of Chaser variants. */
167 	JImage **imgDialog;                   /**< Dialog images. */
168 	s32 numDialogs;                       /**< Number of Dialog variants. */
169 	JImage **imgNarrative;                /**< Narrative images. */
170 	s32 numNarratives;                    /**< Number of Narrative variants. */
171 
172 	char name[256];                       /**< Theme's name. */
173 
174 	/** Count the number of correlative dirs starting from 1 in the cwd.
175 	 * @return Number of correlative dirs starting from 1 in the cwd.
176 	 */
177 	s32 CountDirs();
178 
179 	/** Load floor resources.
180 	 * @return <b>true</b> if succeeded, <b>false</b> if not.
181 	 */
182 	bool LoadFloors();
183 
184 	/** Load continuous floor resources.
185 	 * @return <b>true</b> if succeeded, <b>false</b> if not.
186 	 */
187 	bool LoadContFloors();
188 
189 	/** Load break resources.
190 	 * @return <b>true</b> if succeeded, <b>false</b> if not.
191 	 */
192 	bool LoadBreaks();
193 
194 	/** Load bar resources.
195 	 * @return <b>true</b> if succeeded, <b>false</b> if not.
196 	 */
197 	bool LoadBars();
198 
199 	/** Load ladder resources.
200 	 * @return <b>true</b> if succeeded, <b>false</b> if not.
201 	 */
202 	bool LoadLadders();
203 
204 	/** Load decorative resources.
205 	 * @return <b>true</b> if succeeded, <b>false</b> if not.
206 	 */
207 	bool LoadDecos();
208 
209 	/** Load object resources.
210 	 * @return <b>true</b> if succeeded, <b>false</b> if not.
211 	 */
212 	bool LoadObjects();
213 
214 	/** Load rope resources.
215 	 * @return <b>true</b> if succeeded, <b>false</b> if not.
216 	 */
217 	bool LoadRopes();
218 
219 	/** Load main character's resources.
220 	 * @return <b>true</b> if succeeded, <b>false</b> if not.
221 	 */
222 	bool LoadChar(const char *directory, JImageSprite ** &sprArr, s32 &num);
223 
224 	/** Load character resources.
225 	 * @return <b>true</b> if succeeded, <b>false</b> if not.
226 	 */
227 	bool LoadCharacters();
228 
229 	/** Load dialog resources.
230 	 * @return <b>true</b> if succeeded, <b>false</b> if not.
231 	 */
232 	bool LoadDialogs();
233 
234 	/** Load narrative resources.
235 	 * @return <b>true</b> if succeeded, <b>false</b> if not.
236 	 */
237 	bool LoadNarratives();
238 
239  public:
240 	/** Creates an empty theme. Load() must be called in order to use it.
241 	 */
242 	HCTheme();
243 
244 	/** Returns the Floor image.
245 	 * @param  index Element to retrieve.
246 	 * @return &The Floor image.
247 	 */
Floor(s32 index)248 	JImage & Floor(s32 index) {return imgFloor[index];}
249 
250 	/** Returns the continuous Floor images.
251 	 * @param  index Element to retrieve.
252 	 * @return &The continuous Floor images.
253 	 */
ContFloor(s32 index)254 	JImage * ContFloor(s32 index) {return imgContFloor[index];}
255 
256 	/** Returns the Break sprites.
257 	 * @param  index Element to retrieve.
258 	 * @return &The Break sprites.
259 	 */
Break(s32 index)260 	JImageSprite * Break(s32 index) {return sprBreak[index];}
261 
262 	/** Returns the Object sprites. index 0 is the key.
263 	 * @param  index Element to retrieve.
264 	 * @return &The Object sprites.
265 	 */
Object(s32 index)266 	JImageSprite * Object(s32 index) {return sprObject[index];}
267 
268 	/** Returns the Bar image.
269 	 * @param  index Element to retrieve.
270 	 * @return &The Bar image.
271 	 */
Bar(s32 index)272 	JImage & Bar(s32 index) {return imgBar[index];}
273 
274 	/** Returns the Ladder image.
275 	 * @param  index Element to retrieve.
276 	 * @return &The Ladder image.
277 	 */
Ladder(s32 index)278 	JImage & Ladder(s32 index) {return imgLadder[index];}
279 
280 	/** Returns the Rope images.
281 	 * @param  index Element to retrieve.
282 	 * @return &The Rope images.
283 	 */
Rope(s32 index)284 	JImage * Rope(s32 index) {return imgRope[index];}
285 
286 	/** Returns the Main character sprites.
287 	 * @param  index Element to retrieve.
288 	 * @return The Main character sprites.
289 	 */
MainChar(s32 index)290 	JImageSprite * MainChar(s32 index) {return sprMain[index];}
291 
292 	/** Returns the Guest sprites.
293 	 * @param  index Element to retrieve.
294 	 * @return The Guest sprites.
295 	 */
Guest(s32 index)296 	JImageSprite * Guest(s32 index) {return sprGuest[index];}
297 
298 	/** Returns the Ball enemy sprites.
299 	 * @param  index Element to retrieve.
300 	 * @return The Ball enemy sprites.
301 	 */
Ball(s32 index)302 	JImageSprite * Ball(s32 index) {return sprBall[index];}
303 
304 	/** Returns the Random enemy sprites.
305 	 * @param  index Element to retrieve.
306 	 * @return The Random enemy sprites.
307 	 */
Random(s32 index)308 	JImageSprite * Random(s32 index) {return sprRandom[index];}
309 
310 	/** Returns the Static enemy sprites.
311 	 * @param  index Element to retrieve.
312 	 * @return The Static enemy sprites.
313 	 */
Static(s32 index)314 	JImageSprite * Static(s32 index) {return sprStatic[index];}
315 
316 	/** Returns the Maker enemy sprites.
317 	 * @param  index Element to retrieve.
318 	 * @return The Maker enemy sprites.
319 	 */
Maker(s32 index)320 	JImageSprite * Maker(s32 index) {return sprMaker[index];}
321 
322 	/** Returns the Chaser enemy sprites.
323 	 * @param  index Element to retrieve.
324 	 * @return The Chaser enemy sprites.
325 	 */
Chaser(s32 index)326 	JImageSprite * Chaser(s32 index) {return sprChaser[index];}
327 
328 	/** Returns the Dialog image.
329 	 * @param  index Element to retrieve.
330 	 * @return &The Dialog image.
331 	 */
Dialog(s32 index)332 	JImage * Dialog(s32 index) {return imgDialog[index];}
333 
334 	/** Returns the Narrative image.
335 	 * @param  index Element to retrieve.
336 	 * @return &The Narrative image.
337 	 */
Narrative(s32 index)338 	JImage * Narrative(s32 index) {return imgNarrative[index];}
339 
340 	/** Loads the theme. The name of the theme is the name of the directory
341 	 * containing it. The structure is:
342 	 * <pre>
343 	 * themeName1
344 	 *  `-  1
345 	 *    `- contfloor - Floor cell parts (corner, sides, interiors)
346    *      `  1
347    *      ` [2]
348 	 *      ` ...
349 	 *    `- break     - Break cell sprites
350    *      `  1
351    *      ` [2]
352 	 *      ` ...
353 	 *    `- ladder    - Ladder cell image
354    *      `  1
355    *      ` [2]
356 	 *      ` ...
357 	 *    `- bar       - Bar cell image
358    *      `  1
359    *      ` [2]
360 	 *      ` ...
361 	 *    `- object    - Objects (keys, powerups, etc.)
362    *      `  1
363    *      ` [2]
364 	 *      ` ...
365 	 *    `- deco      - Decorative images/effects
366    *      `  1
367    *      ` [2]
368 	 *      ` ...
369 	 *    `- rope      - Rope images (edge, top, middle)
370    *      `  1
371    *      ` [2]
372 	 *      ` ...
373 	 *    `- char      - Sprites for characters
374 	 *       `- main     - Sprites of main character
375    *         `  1
376    *         ` [2]
377 	 *         ` ...
378 	 *       `- ball     - Sprites of ball-like enemies
379    *         `  1
380    *         ` [2]
381 	 *         ` ...
382 	 *       `- random   - Sprites of random movement enemies
383    *         `  1
384    *         ` [2]
385 	 *         ` ...
386 	 *       `- static   - Sprites of static enemies
387    *         `  1
388    *         ` [2]
389 	 *         ` ...
390 	 *       `- maker    - Sprites of maker enemies
391    *         `  1
392    *         ` [2]
393 	 *         ` ...
394 	 *       `- chaser   - Sprites of chaser enemies
395    *         `  1
396    *         ` [2]
397 	 *         ` ...
398 	 *       `- char1    - Sprites of spare character 1
399    *         `  1
400    *         ` [2]
401 	 *         ` ...
402 	 *       `- char2    - Sprites of spare character 2
403    *         `  1
404    *         ` [2]
405 	 *         ` ...
406 	 *       `- char3    - Sprites of spare character 3
407    *         `  1
408    *         ` [2]
409 	 *         ` ...
410 	 *       `- char4    - Sprites of spare character 4
411    *         `  1
412    *         ` [2]
413 	 *         ` ...
414 	 *       `- char5    - Sprites of spare character 5
415    *         `  1
416    *         ` [2]
417 	 *         ` ...
418 	 *  `- [themeName2]
419 	 *  `- ...
420 	 *
421 	 * </pre>
422 	 * @param themeName This theme's name.
423 	 * @return <b>true</b> if succeeded, <b>false</b> if not.
424 	 */
425 	bool Load(const char *themeName);
426 
427 	/** Returns the theme name (directory containing it).
428 	 * @return Theme name (directory containing it).
429 	 */
Name()430 	const char * Name() {return name;}
431 
432 	/** Destroys the theme. Frees resources.
433 	 */
434 	void Destroy();
435 
436 	/** Number of Floor variants.
437 	 * @return The requested quantity.
438 	 */
NumFloors()439 	s32 NumFloors() {return numFloors;}
440 
441 	/** Number of Continuous Floor variants.
442 	 * @return The requested quantity.
443 	 */
NumContFloors()444 	s32 NumContFloors() {return numContFloors;}
445 
446 	/** Number of Break variants.
447 	 * @return The requested quantity.
448 	 */
NumBreaks()449 	s32 NumBreaks() {return numBreaks;}
450 
451 	/** Number of Object variants.
452 	 * @return The requested quantity.
453 	 */
NumObjects()454 	s32 NumObjects() {return numObjects;}
455 
456 	/** Number of Bar variants.
457 	 * @return The requested quantity.
458 	 */
NumBars()459 	s32 NumBars() {return numBars;}
460 
461 	/** Number of Ladder variants.
462 	 * @return The requested quantity.
463 	 */
NumLadders()464 	s32 NumLadders() {return numLadders;}
465 
466 	/** Number of Rope variants.
467 	 * @return The requested quantity.
468 	 */
NumRopes()469 	s32 NumRopes() {return numRopes;}
470 
471 	/** Number of MainChar variants.
472 	 * @return Number of MainChar variants.
473 	 */
NumMainChars()474 	s32 NumMainChars() {return numMains;}
475 
476 	/** Number of Guest variants.
477 	 * @return number of Guest variants.
478 	 */
NumGuests()479 	s32 NumGuests() {return numGuests;}
480 
481 	/** Number of Ball variants.
482 	 * @return number of Ball variants.
483 	 */
NumBalls()484 	s32 NumBalls() {return numBalls;}
485 
486 	/** Number of Random variants.
487 	 * @return number of Random variants.
488 	 */
NumRandoms()489 	s32 NumRandoms() {return numRandoms;}
490 
491 	/** Number of Static variants.
492 	 * @return number of Static variants.
493 	 */
NumStatics()494 	s32 NumStatics() {return numStatics;}
495 
496 	/** Number of Maker variants.
497 	 * @return number of Maker variants.
498 	 */
NumMakers()499 	s32 NumMakers() {return numMakers;}
500 
501 	/** Number of Chaser variants.
502 	 * @return number of Chaser variants.
503 	 */
NumChasers()504 	s32 NumChasers() {return numChasers;}
505 
506 	/** Number of Dialog variants.
507 	 * @return number of Dialog variants.
508 	 */
NumDialogs()509 	s32 NumDialogs() {return numDialogs;}
510 
511 	/** Number of Narrative variants.
512 	 * @return number of Narrative variants.
513 	 */
NumNarratives()514 	s32 NumNarratives() {return numNarratives;}
515 
516 	/** Destroys the theme. Frees resources. Allows scalar destruction.
517 	 */
~HCTheme()518 	virtual ~HCTheme() {Destroy();}
519 };
520 
521 #endif // _HCTHEME_INCLUDED
522