ScummVM API documentation
griffon.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  * Originally written by Syn9 in FreeBASIC with SDL
21  * http://syn9.thehideoutgames.com/index_backup.php
22  *
23  * Ported to plain C for GCW-Zero handheld by Dmitry Smagin
24  * http://github.com/dmitrysmagin/griffon_legend
25  *
26  *
27  * Programming/Graphics: Daniel "Syn9" Kennedy
28  * Music/Sound effects: David Turner
29  *
30  * Beta testing and gameplay design help:
31  * Deleter, Cha0s, Aether Fox, and Kiz
32  *
33  */
34 
35 #ifndef GRIFFON_GRIFFON_H
36 #define GRIFFON_GRIFFON_H
37 
38 #include "common/scummsys.h"
39 #include "common/error.h"
40 #include "common/events.h"
41 #include "common/random.h"
42 #include "engines/engine.h"
43 
44 #include "audio/mixer.h"
45 
46 #include "graphics/managed_surface.h"
47 
48 namespace Griffon {
49 
50 class Console;
51 
52 #define kSoundHandles 16
53 #define kMaxNPC 32
54 #define kMaxFloat 32
55 #define kMaxSpell 32
56 
57 // spells
58 enum {
59  kSpellIce = 0,
60  kSpellSteel,
61  kSpellWood,
62  kSpellRock,
63  kSpellFire
64 };
65 
66 // inventory items
67 enum {
68  kInvFlask = 0,
69  kInvDoubleFlask,
70  kInvShock,
71  kInvNormalKey,
72  kInvMasterKey
73 };
74 
75 enum {
76  kSndBite = 0,
77  kSndCrystal,
78  kSndDoor,
79  kSndEnemyHit,
80  kSndIce,
81  kSndLever,
82  kSndLightning,
83  kSndMetalHit,
84  kSndPowerUp,
85  kSndRocks,
86  kSndSwordHit,
87  kSndThrow,
88  kSndChest,
89  kSndFire,
90  kSndBeep
91 };
92 
93 // in game scripts
94 enum {
95  kScriptFlask = 0, // get flask
96  kScriptMasterKey = 2, // find master key
97  kScriptFindCrystal = 3, // find crystal
98  kScriptFindShield = 4, // find shield - obj 8
99  kScriptFindSword = 5, // find sword - obj 9
100  kScriptKeyChest = 6, // regular key chest
101  kScriptBlueFlask = 7, // blue flask
102  kScriptGardenMasterKey = 8, // garden's master key
103  kScriptLightningBomb = 9, // lightning bomb
104  kScriptBlueFlaskChest = 10, // blue flask chest
105  kScriptLightningChest = 11, // lightning chest
106  kScriptArmourChest = 12, // armour chest
107  kScriptCitadelMasterKey = 13, // citadel master key
108  kScriptEndOfGame = 14, // end of game
109  kScriptGetSword3 = 15, // get sword3
110  kScriptShield3 = 16, // shield3
111  kScriptArmour3 = 17, // armour3
112  kScriptKeyChest1 = 20, // key chest 1
113  kScriptLever = 60 // lever
114 };
115 
116 // monsters
117 enum {
118  kMonsterBabyDragon = 1, // baby dragon
119  kMonsterOneWing = 2, // one wing
120  kMonsterBoss1 = 3, // boss 1
121  kMonsterBlackKnight = 4, // black knight
122  kMonsterFireHydra = 5, // fire hydra
123  kMonsterRedDragon = 6, // red dragon
124  kMonsterPriest = 7, // priest
125  kMonsterYellowDragon = 8, // yellow fire dragon
126  kMonsterTwoWing = 9, // two wing
127  kMonsterDragon2 = 10, // dragon2
128  kMonsterFinalBoss = 11, // final boss
129  kMonsterBatKitty = 12 // bat kitty
130 };
131 
132 // engine actions
133 enum GriffonActions {
134  kGriffonLeft,
135  kGriffonRight,
136  kGriffonUp,
137  kGriffonDown,
138  kGriffonAttack,
139  kGriffonInventory,
140  kGriffonMenu,
141  kGriffonConfirm,
142  kGriffonCutsceneSpeedUp
143 };
144 
145 #define kEpsilon 0.001
146 
147 struct Player {
148  float px;
149  float py;
150  float opx;
151  float opy;
152  int walkDir;
153  float walkFrame;
154  float walkSpeed;
155  float attackFrame;
156  float attackSpeed;
157 
158  int hp;
159  int maxHp;
160  float hpflash;
161  int hpflashb;
162  int level;
163  int maxLevel;
164  int sword;
165  int shield;
166  int armour;
167  int foundSpell[5];
168  float spellCharge[5];
169  int inventory[5];
170  float attackStrength;
171  float spellStrength;
172  int spellDamage;
173  int swordDamage;
174 
175  int exp;
176  int nextLevel;
177 
178  int pause;
179 
180  float itemselshade;
181  int ysort;
182 
183  void reset();
184 };
185 
186 struct BodySection {
187  float x;
188  float y;
189  int parentID;
190  int isbase;
191  int sprite;
192  int bonelength; // the 'bone' that connects the body sections
193 };
194 
195 struct NPC {
196  float x;
197  float y;
198  int spriteset;
199  int x1; // patrol area
200  int y1;
201  int x2;
202  int y2;
203  int attitude;
204  int hp;
205 
206  int maxhp;
207  int item1;
208  int item2;
209  int item3;
210  int script;
211  float frame;
212  float frame2; // end boss specific
213  int cframe;
214  bool onMap; // is this npc set to be genned in the mapfile
215 
216  int ticks;
217  int pause;
218  int shake;
219 
220  int movementmode;
221  int walkdir;
222  float walkspd;
223  int movingdir;
224  bool moving;
225 
226  bool attacking;
227  float attackframe;
228  int cattackframe;
229  float attackspd;
230  int attackdelay;
231  int attacknext;
232  int attackattempt;
233 
234  int spellDamage;
235  int attackDamage;
236 
237 
238  // one wing and firehydra specific
239  BodySection bodysection[31];
240  float swayAngle;
241  float swaySpeed;
242  float headTargetX[4];
243  float headTargetY[4];
244  int castPause;
245 
246  // firehydra specific
247  int attacknext2[4];
248  bool attacking2[4];
249  int attackframe2[4];
250 
251  // dragon2 specific
252  float floating;
253 };
254 
255 struct Spell {
256  int spellnum;
257  float homex;
258  float homey;
259  float enemyx;
260  float enemyy;
261 
262  float frame;
263 
264  int damagewho; // 0 = npc, 1 = player
265 
266  // for earthslide
267  float rocky[9]; // CHECKME: Looks unused
268  int rockimg[9];
269  int rockdeflect[9];
270 
271  float strength;
272 
273  // fire
274  int legalive[5];
275 
276  // spell 6 specific
277  float fireballs[7][4]; // x,y,targetx, targety
278  int nfballs;
279  int ballon[7];
280 
281  int npc;
282 };
283 
284 struct AnimSet {
285  int x; // xyloc on spriteimageset
286  int y;
287  int xofs; // the actual place to paste the sprite in reference to the bodypart loc on screen
288  int yofs;
289  int w; // w/h of the sprite in the imageset
290  int h;
291 };
292 
293 struct DataChunk {
294  byte *data;
295  int size;
296 };
297 
299  float framesLeft;
300  float x;
301  float y;
302  int col;
303  char *text;
304 };
305 
307  float framesLeft;
308  float x;
309  float y;
310  int ico;
311 };
312 
314  float x;
315  float y;
316  bool completed;
317 };
318 
319 struct Config {
320  bool music;
321  int musicVol;
322  bool effects;
323  int effectsVol;
324 };
325 
327  int nFrames;
328  int xTiles;
329  int yTiles;
330  int speed;
331  int type;
332  int script;
333 };
334 
335 enum {
336  kGameModeIntro,
337  kGameModePlay,
338  kGameModeNewGame,
339  kGameModeLoadGame
340 };
341 
342 class GriffonEngine : public Engine {
343 public:
344  GriffonEngine(OSystem *syst);
345  ~GriffonEngine() override;
346 
347  Common::Error run() override;
348  void syncSoundSettings() override;
349 
350 private:
351  Common::RandomSource *_rnd;
352  bool _shouldQuit;
353  int _gameMode;
354 
355  Console *_console;
356 
357 private:
358 
359  // combat.cpp
360  void attack();
361  void castSpell(int spellnum, float homex, float homey, float enemyx, float enemyy, int damagewho);
362  void checkHit();
363  void damageNPC(int npcnum, int damage, int spell);
364  void damagePlayer(int damage);
365 
366  // cutscenes.cpp
367  void showLogos();
368  void intro();
369  void endOfGame();
370  void theEnd();
371 
372  // dialogs.cpp
373  void title(int mode);
374  void configMenu();
375  void saveLoadNew();
376  void renderSaveStates();
377 
378  // draw.cpp
379  void drawAnims(int Layer);
380  void drawHud();
381  void drawNPCs(int mode);
382  void drawOver(int modx, int mody);
383  void drawPlayer();
384  void drawView();
385  void swash();
386 
387  // engine.cpp
388  float RND();
389 
390  void mainLoop();
391  void updateEngine();
392  void newGame();
393 
394  // gfx.cpp
395  void addFloatIcon(int ico, float xloc, float yloc);
396  void addFloatText(const char *stri, float xloc, float yloc, int col);
397  void eventText(const char *stri);
398  void drawLine(Graphics::ManagedSurface *buffer, int x1, int y1, int x2, int y2, int col);
399  void drawString(Graphics::ManagedSurface *buffer, const char *stri, int xloc, int yloc, int col);
400  void drawProgress(int w, int wm);
401 
402  // input.cpp
403  void checkInputs();
404  void handleWalking();
405  void checkTrigger();
406  void processTrigger(int trignum);
407 
408  // logic.cpp
409  void updateAnims();
410  void updateY();
411  void updateNPCs();
412  void updateSpells();
413  void updateSpellsUnder();
414 
415  // resources.cpp
416  void initialize();
417  Graphics::ManagedSurface *loadImage(const char *name, bool colorkey = false);
418  void loadMap(int mapnum);
419  void loadAnims();
420  void loadFont();
421  void loadItemImgs();
422  void loadTiles();
423  void loadTriggers();
424  void loadObjectDB();
425 
426  // saveload.cpp
427  Common::String getSaveStateName(int slot) const override;
428  int loadPlayer(int slotnum);
429  Common::Error loadGameState(int slot) override;
430  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
431  Common::Error loadGameStream(Common::SeekableReadStream *file) override;
432  Common::Error saveGameStream(Common::WriteStream *file, bool isAutosave) override;
433 
434  // sound.cpp
435  void setChannelVolume(int channel, int volume);
436  int getSoundHandle();
437  int playSound(DataChunk *chunk, bool looped = false);
438  void pauseSoundChannel(int channel);
439  void haltSoundChannel(int channel);
440  void resumeSoundChannel(int channel);
441  bool isSoundChannelPlaying(int channel);
442  void setupAudio();
443  void updateMusic();
444 
445  // Common engine overrides
446  void pauseEngineIntern(bool pause) override;
447  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override { return true; }
448  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override { return _gameMode == kGameModePlay; }
449  int getAutosaveSlot() const override { return 4; }
450  bool hasFeature(EngineFeature f) const override;
451 
452 private:
453  Graphics::ManagedSurface *_video, *_videoBuffer, *_videoBuffer2, *_videoBuffer3;
454 
455  // system
456  Graphics::ManagedSurface *_titleImg, *_titleImg2, *_inventoryImg;
457  Graphics::ManagedSurface *_logosImg, *_theEndImg;
458  Common::Event _event;
459 
460  Graphics::ManagedSurface *_mapBg, *_clipBg, *_clipBg2;
461  unsigned int _clipSurround[4][4];
462 
463  float _animSpeed; // CHECKME: it seems to always be 0.5
464  int _rampData[40][24];
465 
466  int _curMap;
467  Graphics::ManagedSurface *_fontChr[224][5]; // 256 - 32
468  Graphics::ManagedSurface *_itemImg[21], *_windowImg;
469  Graphics::ManagedSurface *_spellImg;
470 
471  bool _itemSelOn;
472  int _curItem, _itemTicks;
473  float _itemyloc;
474  bool _selEnemyOn;
475  int _curEnemy;
476  bool _forcePause;
477  bool _roomLock; // set to disable any room jumps while in the room
478  int _scriptFlag[100][10], _saveSlot; // script, flag
479 
480  // timer related - move to local later
481  int _ticks, _ticksPassed, _nextTicks, _ticksAtPauseStart;
482  float _fp, _fps, _fpsr; // CHECKME: _fp and _fps seems to be integers
483  int _secsInGame, _secStart;
484 
485  Graphics::ManagedSurface *mapImg[4];
486 
487  Common::Rect rcSrc, rcDest;
488 
489  // -----------special case
490  bool _dontDrawOver; // used in map24 so that the candles don't draw over the boss, default set to 0
491 
492  // saveload info
493  Graphics::ManagedSurface *_saveLoadImg;
494 
495  // post info
496  float _postInfo[21][3];
497  int _postInfoNbr;
498 
499  // cloud info
500  Graphics::ManagedSurface *_cloudImg;
501  float _cloudAngle;
502  int _cloudsOn;
503 
504  // spell info
505  Spell _spellInfo[kMaxSpell];
506 
507  // player info
508  Player _player;
509  Player _playera;
510  bool _movingUp, _movingDown, _movingLeft, _movingRight;
511  bool _attacking;
512  int _asecstart;
513 
514  // tile info
515  Graphics::ManagedSurface *_tiles[4];
516  int _tileinfo[3][40][24][3]; // maplayer, x, y, tiledata (tile, tilelayer)
517 
518  // animation info
519  Graphics::ManagedSurface *_anims[100];
520  // id number 0&1 = players
521  Graphics::ManagedSurface *_animsAttack[100];
522  // attack anims
523  AttackOffsetStruct _playerAttackOfs[4][16];
524 
525  FloatTextStruct _floatText[kMaxFloat];
526  FloatIconStruct _floatIcon[kMaxFloat];
527 
528  // special for animset2
529  AnimSet _animSet2[7], _animSet9[7];
530 
531  // object info
532  float _objectFrame[256][2];
533  int _lastObj;
534  // frame!, curframe
535  ObjectInfoStruct _objectInfo[33];
536 
537  int _objectTile[33][9][3][3][2];
538  // [objnum] [frame] [x] [y] [tile/layer]
539  int _objectMap[21][15];
540 
541  int _objectMapFull[1000][21][15];
542  // [mapnum] x, y set to 1 to make this objmap spot stay at -1
543 
544  // trigger info
545  int _triggers[10000][9];
546  // [map#][index], [var]
547  // map#,x,y
548  int _triggerLoc[320][240], _triggerNbr;
549 
550  // npc info
551  NPC _npcInfo[kMaxNPC];
552  int _lastNpc;
553 
554  // music info
555  DataChunk *_musicGardens1, *_musicGardens2, *_musicGardens3, *_musicGardens4, *_musicBoss, *_musicMenu, *_musicEndOfGame;
556  int _musicChannel, _menuChannel;
557  bool _playingBoss, _playingGardens;
558 
559  DataChunk *_sfx[15];
560  Audio::SoundHandle _handles[kSoundHandles];
561  Audio::Mixer *_mixer;
562 
563  // set to 1 for normal key, set to 2 for master, set to 0 if unlocked
564  int _roomLocks[201], _lockType;
565  int _roomToUnlock;
566 
567  bool _canUseKey;
568  bool _saidLocked;
569  bool _saidJammed;
570 
571  // ysort
572  int _ysort[2401], _lasty, _firsty;
573 
574  bool _pmenu;
575 
576  Config config;
577  void saveConfig();
578 };
579 
580 }
581 
582 #endif // GRIFFON_GRIFFON_H
Definition: managed_surface.h:51
Definition: griffon.h:319
Definition: str.h:59
EngineFeature
Definition: engine.h:250
Definition: stream.h:77
Definition: error.h:84
Definition: random.h:44
Definition: griffon.h:342
Definition: rect.h:144
Definition: stream.h:745
Definition: griffon.h:186
Definition: console.h:27
Definition: mixer.h:49
Definition: mixer.h:59
Definition: griffon.h:147
Definition: console.h:35
Definition: ustr.h:57
Definition: griffon.h:298
Definition: events.h:198
Definition: griffon.h:326
Definition: griffon.h:255
Definition: system.h:175
Definition: griffon.h:306
Definition: engine.h:143
Definition: griffon.h:313
Definition: griffon.h:195
Definition: griffon.h:293
Definition: griffon.h:284