ScummVM API documentation
wage.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  * MIT License:
21  *
22  * Copyright (c) 2009 Alexei Svitkine, Eugene Sandulenko
23  *
24  * Permission is hereby granted, free of charge, to any person
25  * obtaining a copy of this software and associated documentation
26  * files (the "Software"), to deal in the Software without
27  * restriction, including without limitation the rights to use,
28  * copy, modify, merge, publish, distribute, sublicense, and/or sell
29  * copies of the Software, and to permit persons to whom the
30  * Software is furnished to do so, subject to the following
31  * conditions:
32  *
33  * The above copyright notice and this permission notice shall be
34  * included in all copies or substantial portions of the Software.
35  *
36  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
37  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
38  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
39  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
40  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
41  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
42  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
43  * OTHER DEALINGS IN THE SOFTWARE.
44  *
45  */
46 
47 #ifndef WAGE_WAGE_H
48 #define WAGE_WAGE_H
49 
50 #include "engines/engine.h"
51 #include "audio/mixer.h"
52 #include "common/debug.h"
53 #include "common/endian.h"
54 #include "common/rect.h"
55 #include "common/macresman.h"
56 #include "common/random.h"
57 #include "common/timer.h"
58 
59 #include "wage/debugger.h"
60 
61 struct ADGameDescription;
62 
63 namespace Common {
64 struct Event;
65 }
66 
67 namespace Graphics {
68 class MacDialog;
69 }
70 
71 namespace Wage {
72 
73 class Console;
74 class Chr;
75 class Designed;
76 class Dialog;
77 class Gui;
78 class Obj;
79 class Scene;
80 class World;
81 
82 typedef Common::Array<Obj *> ObjArray;
83 typedef Common::Array<Chr *> ChrArray;
84 typedef Common::List<Obj *> ObjList;
85 typedef Common::List<Chr *> ChrList;
86 
87 #define STORAGESCENE "STORAGE@"
88 
89 enum OperandType {
90  OBJ = 0,
91  CHR = 1,
92  SCENE = 2,
93  NUMBER = 3,
94  STRING = 4,
95  CLICK_INPUT = 5,
96  TEXT_INPUT = 6,
97  UNKNOWN = 100
98 };
99 
100 enum Directions {
101  NORTH = 0,
102  SOUTH = 1,
103  EAST = 2,
104  WEST = 3
105 };
106 
107 // our engine debug levels
108 enum {
109  kWageDebugExample = 1 << 0,
110  kWageDebugExample2 = 1 << 1
111  // next new level must be 1 << 2 (4)
112  // the current limitation is 32 debug levels (1 << 31 is the last one)
113 };
114 
115 enum Resolution {
116  GF_RES800 = 1 << 0,
117  GF_RES1024 = 1 << 1
118 };
119 
121 const char *getIndefiniteArticle(const Common::String &word);
122 const char *prependGenderSpecificPronoun(int gender);
123 const char *getGenderSpecificPronoun(int gender, bool capitalize);
124 bool isStorageScene(const Common::String &name);
125 
126 class WageEngine : public Engine {
127  friend class Dialog;
128 public:
129  WageEngine(OSystem *syst, const ADGameDescription *gameDesc);
130  ~WageEngine() override;
131 
132  bool hasFeature(EngineFeature f) const override;
133 
134  Common::Error run() override;
135 
136  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
137  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
138 
139  const char *getGameFile() const;
140  void processTurn(Common::String *textInput, Designed *clickInput);
141  void regen();
142 
143  const char *getTargetName() { return _targetName.c_str(); }
144  bool pollEvent(Common::Event &event);
145 
146 private:
147  bool loadWorld(Common::MacResManager *resMan);
148  void performInitialSetup();
149  void wearObjs(Chr *chr);
150  void processTurnInternal(Common::String *textInput, Designed *clickInput);
151  void performCombatAction(Chr *npc, Chr *player);
152  int getValidMoveDirections(Chr *npc);
153  void performAttack(Chr *attacker, Chr *victim, Obj *weapon);
154  void performMagic(Chr *attacker, Chr *victim, Obj *magicalObject);
155  void performMove(Chr *chr, int validMoves);
156  void performOffer(Chr *attacker, Chr *victim);
157  void performTake(Chr *npc, Obj *obj);
158  void decrementUses(Obj *obj);
159  bool attackHit(Chr *attacker, Chr *victim, Obj *weapon, int targetIndex);
160  void performHealingMagic(Chr *chr, Obj *magicalObject);
161 
162  void doClose();
163 
164 public:
165  void takeObj(Obj *obj);
166 
167  bool handleMoveCommand(Directions dir, const char *dirName);
168  bool handleLookCommand();
169  Common::String *getGroundItemsList(Scene *scene);
170  void appendObjNames(Common::String &str, const ObjArray &objs);
171  bool handleInventoryCommand();
172  bool handleStatusCommand();
173  bool handleRestCommand();
174  bool handleAcceptCommand();
175 
176  bool handleTakeCommand(const char *target);
177  bool handleDropCommand(const char *target);
178  bool handleAimCommand(const char *target);
179  bool handleWearCommand(const char *target);
180  bool handleOfferCommand(const char *target);
181 
182  void wearObj(Obj *o, int pos);
183 
184  bool tryAttack(const Obj *weapon, const Common::String &input);
185  bool handleAttack(Obj *weapon);
186 
187  void printPlayerCondition(Chr *player);
188  const char *getPercentMessage(double percent);
189 
190 public:
191  Common::RandomSource *_rnd;
192 
193  Gui *_gui;
194  World *_world;
195 
196  Scene *_lastScene;
197  int _loopCount;
198  int _turn;
199  Chr *_monster;
200  Chr *_running;
201  Obj *_offer;
202  int _aim;
203  int _opponentAim;
204  bool _temporarilyHidden;
205  bool _isGameOver;
206  bool _commandWasQuick;
207  bool _restartRequested = false;
208 
209  bool _shouldQuit;
210  int _defaultSaveSlot = -1;
211  Common::String _defaultSaveDescritpion;
212 
213  Common::String _inputText;
214 
215  Common::List<int> _soundQueue;
216  Common::String _soundToPlay;
217 
218  void playSound(Common::String soundName);
219  void updateSoundTimerForScene(Scene *scene, bool firstTime);
220  void setMenu(Common::String soundName);
221  void appendText(const char *str);
222  void gameOver();
223  bool saveDialog();
224  void aboutDialog();
225  Obj *getOffer();
226  Chr *getMonster();
227  void processEvents();
228  Scene *getSceneByName(Common::String &location);
229  void onMove(Designed *what, Designed *from, Designed *to);
230  void encounter(Chr *player, Chr *chr);
231  void redrawScene();
232  void saveGame();
233 
234  uint32 getFeatures();
235 
236  Common::Error loadGameState(int slot) override;
237  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
238  bool scummVMSaveLoadDialog(bool isSave);
239 
240 private:
241  int getSceneIndex(Scene *scene) const;
242  Obj *getObjByOffset(int offset, int objBaseOffset) const;
243  Chr *getChrById(int resId) const;
244  Chr *getChrByOffset(int offset, int chrBaseOffset) const;
245  Scene *getSceneById(int id) const;
246  Scene *getSceneByOffset(int offset) const;
247  int saveGame(const Common::String &fileName, const Common::String &descriptionString);
248  int loadGame(int slotId);
249 
250  void restart();
251 
252 private:
253  const ADGameDescription *_gameDescription;
254 
255  Common::MacResManager *_resManager;
256 
257  Audio::SoundHandle _soundHandle;
258 };
259 
260 } // End of namespace Wage
261 
262 #endif
Definition: macresman.h:125
Definition: world.h:61
Definition: str.h:59
EngineFeature
Definition: engine.h:253
Definition: error.h:84
Definition: advancedDetector.h:163
Definition: random.h:44
Definition: rect.h:144
Definition: stream.h:745
Definition: wage.h:126
Definition: mixer.h:49
Definition: ustr.h:57
Definition: entities.h:231
Definition: events.h:199
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: gui.h:116
Definition: entities.h:300
Definition: debugger.h:28
Definition: entities.h:130
Definition: system.h:161
Definition: entities.h:111
Definition: engine.h:144