ScummVM API documentation
game.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  */
21 
22 /*
23  * This code is based on the CRAB engine
24  *
25  * Copyright (c) Arvind Raja Yadav
26  *
27  * Licensed under MIT
28  *
29  */
30 
31 #ifndef CRAB_GAME_H
32 #define CRAB_GAME_H
33 
34 #include "crab/GameClock.h"
35 #include "crab/gamestate_container.h"
36 #include "crab/event/GameEventInfo.h"
37 #include "crab/event/gameeventmanager.h"
38 #include "crab/ui/DevConsole.h"
39 #include "crab/ui/hud.h"
40 #include "crab/ui/map.h"
41 
42 namespace Crab {
43 
44 class Game : public GameState {
45 private:
46  enum State {
47  STATE_GAME,
48  STATE_MAP,
49  STATE_PAUSE,
50  STATE_CHARACTER,
51  STATE_JOURNAL,
52  STATE_INVENTORY,
53  STATE_HELP,
54  STATE_LOSE_MENU,
55  STATE_LOSE_LOAD
56  } _state;
57 
58  enum SaveGameType {
59  SAVEGAME_NORMAL, // Save the game normally when user uses the save menu
60  SAVEGAME_EVENT, // Auto-save the game at certain points using events
61  SAVEGAME_EXIT, // Auto-save the game on exit
62  SAVEGAME_QUICK // You can use quick-save and quick-load keys
63  };
64 
65  // These things don't need to be saved
66  bool _isInited;
70  pyrodactyl::ui::DebugConsole _debugConsole;
71 
72  // These things need to be saved
78 
79  // Keeps track of the time player has spent in the game
80  GameClock _clock;
81 
82  // The name of the auto save and quick save files
83  struct SaveFile {
84  bool _autoSlot;
85  Common::String _auto1, _auto2, _autoQuit, _quick, _ironman;
86 
87  SaveFile() : _auto1("autoSave 1"), _auto2("autoSave 2"), _autoQuit("autoSave"), _quick("Quick Save") { _autoSlot = false; }
88 
89  void load(rapidxml::xml_node<char> *node) {
90  loadStr(_auto1, "auto_1", node);
91  loadStr(_auto2, "auto_2", node);
92  loadStr(_autoQuit, "quit", node);
93  loadStr(_quick, "quick", node);
94  }
95  } _savefile;
96 
97  static void quit(bool &shouldChangeState, GameStateID &newStateId, const GameStateID &newStateVal);
98 
99  bool applyResult();
100  void applyResult(LevelResult result);
101 
102  // Load a level
103  bool loadLevel(const Common::String &id, int playerX = -1, int playerY = -1);
104 
105  void toggleState(const State &s);
106 
107  // A nice simple function for saving games
108  void createSaveGame(const SaveGameType &savetype);
109 
110  Common::String fullPath(const Common::String &filename) {
111  Common::String res = "CRAB_" + filename;
112  res += g_engine->_filePath->_saveExt;
113  return res;
114  }
115 
116  // Load the current player image
117  void playerImg() {
118  _hud.playerImg(g_engine->_eventStore->_img[_info.playerImg()]);
119  }
120 
121 public:
122  Game() : _isInited(false), _state(STATE_GAME) {}
123 
124  void init(const Common::Path &filename);
125 
126  void startNewGame();
127  void loadGame();
128 
129  void handleEvents(Common::Event &event, bool &shouldChangeState, GameStateID &newStateId);
130 #if 0
131  void handleEvents(SDL_Event &Event, bool &ShouldChangeState, GameStateID &NewStateID);
132 #endif
133  void internalEvents(bool &shouldChangeState, GameStateID &newStateId);
134  void draw();
135 
136  bool loadState(Common::SeekableReadStream *stream);
137 
138  // Raw function to save game to file - generally, using the CreateSaveGame function is recommended
139  void saveState(Common::SeekableWriteStream *stream);
140 
141  void autoSave() {
142  createSaveGame(SAVEGAME_EXIT);
143  }
144 
145  void setUI();
146 };
147 
148 } // End of namespace Crab
149 
150 #endif // CRAB_GAME_H
Definition: DevConsole.h:43
Definition: gameeventmanager.h:47
Definition: str.h:59
Definition: ParagraphData.h:40
Definition: array.h:52
Definition: LevelResult.h:44
Definition: path.h:52
Definition: map.h:46
Definition: GameEventInfo.h:44
Definition: gamestate_container.h:46
Definition: stream.h:745
Engine * g_engine
Definition: hud.h:59
Definition: game.h:44
Definition: events.h:199
Definition: triggerset.h:40
Definition: moveeffect.h:37
Definition: level.h:45
Definition: stream.h:351
Definition: GameClock.h:39