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 #include "common/text-to-speech.h"
59 
60 #include "wage/debugger.h"
61 
62 struct ADGameDescription;
63 
64 namespace Common {
65 struct Event;
66 }
67 
68 namespace Graphics {
69 class MacDialog;
70 }
71 
72 namespace Audio {
73 class PCSpeaker;
74 }
75 
76 namespace Wage {
77 
78 class Console;
79 class Chr;
80 class Designed;
81 class Dialog;
82 class Gui;
83 class Obj;
84 class Scene;
85 class World;
86 
87 typedef Common::Array<Obj *> ObjArray;
88 typedef Common::Array<Chr *> ChrArray;
89 typedef Common::List<Obj *> ObjList;
90 typedef Common::List<Chr *> ChrList;
91 
92 #define STORAGESCENE "STORAGE@"
93 
94 enum {
95  kDebugSound = 1,
96  kDebugLoading,
97 };
98 
99 enum OperandType {
100  OBJ = 0,
101  CHR = 1,
102  SCENE = 2,
103  NUMBER = 3,
104  STRING = 4,
105  CLICK_INPUT = 5,
106  TEXT_INPUT = 6,
107  UNKNOWN = 100
108 };
109 
110 enum Directions {
111  NORTH = 0,
112  SOUTH = 1,
113  EAST = 2,
114  WEST = 3
115 };
116 
117 enum Resolution {
118  GF_RES800 = 1 << 0,
119  GF_RES1024 = 1 << 1
120 };
121 
123 const char *getIndefiniteArticle(const Common::String &word);
124 const char *prependGenderSpecificPronoun(int gender);
125 const char *getGenderSpecificPronoun(int gender, bool capitalize);
126 bool isStorageScene(const Common::String &name);
127 
128 class WageEngine : public Engine {
129  friend class Dialog;
130 public:
131  WageEngine(OSystem *syst, const ADGameDescription *gameDesc);
132  ~WageEngine() override;
133 
134  bool hasFeature(EngineFeature f) const override;
135 
136  Common::Error run() override;
137 
138  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
139  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
140 
141  const char *getGameFile() const;
142  void processTurn(Common::String *textInput, Designed *clickInput);
143  void regen();
144 
145  const char *getTargetName() { return _targetName.c_str(); }
146  bool pollEvent(Common::Event &event);
147 
148 private:
149  bool loadWorld(Common::MacResManager *resMan);
150  void performInitialSetup();
151  void wearObjs(Chr *chr);
152  void processTurnInternal(Common::String *textInput, Designed *clickInput);
153  void performCombatAction(Chr *npc, Chr *player);
154  int getValidMoveDirections(Chr *npc);
155  void performAttack(Chr *attacker, Chr *victim, Obj *weapon);
156  void performMagic(Chr *attacker, Chr *victim, Obj *magicalObject);
157  void performMove(Chr *chr, int validMoves);
158  void performOffer(Chr *attacker, Chr *victim);
159  void performTake(Chr *npc, Obj *obj);
160  void decrementUses(Obj *obj);
161  bool attackHit(Chr *attacker, Chr *victim, Obj *weapon, int targetIndex);
162  void performHealingMagic(Chr *chr, Obj *magicalObject);
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  void doClose();
191 
192 public:
193  Common::RandomSource *_rnd;
194 
195  Gui *_gui;
196  World *_world;
197 
198  Scene *_lastScene;
199  int _loopCount;
200  int _turn;
201  Chr *_monster;
202  Chr *_running;
203  Obj *_offer;
204  int _aim;
205  int _opponentAim;
206  bool _temporarilyHidden;
207  bool _isGameOver;
208  bool _commandWasQuick;
209  bool _restartRequested = false;
210 
211  bool _shouldQuit;
212  int _defaultSaveSlot = -1;
213  Common::String _defaultSaveDescritpion;
214 
215  Common::String _inputText;
216 
217  Common::List<int> _soundQueue;
218  Common::String _soundToPlay;
219  Audio::PCSpeaker *_speaker;
220 
221  void playSound(Common::String soundName, bool blocking = true);
222  void playStartupSound(byte *stream, uint32 size, int divisor);
223  void updateSoundTimerForScene(Scene *scene, bool firstTime);
224  void setMenu(Common::String soundName);
225  void appendText(const char *str);
226  void sayText(const Common::U32String &str, Common::TextToSpeechManager::Action action = Common::TextToSpeechManager::INTERRUPT_NO_REPEAT) const;
227  void sayText(const Common::String &str, Common::TextToSpeechManager::Action action = Common::TextToSpeechManager::INTERRUPT_NO_REPEAT) const;
228  Obj *getOffer();
229  Chr *getMonster();
230  void processEvents();
231  Scene *getSceneByName(Common::String &location);
232  void onMove(Designed *what, Designed *from, Designed *to);
233  void encounter(Chr *player, Chr *chr);
234  void redrawScene();
235  void saveGame();
236 
237  uint32 getFeatures();
238 
239  Common::Error loadGameState(int slot) override;
240  Common::Error saveGameState(int slot, const Common::String &desc, bool isAutosave = false) override;
241  bool scummVMSaveLoadDialog(bool isSave);
242 
243 private:
244  int getSceneIndex(Scene *scene) const;
245  Obj *getObjByOffset(int offset, int objBaseOffset) const;
246  Chr *getChrById(int resId) const;
247  Chr *getChrByOffset(int offset, int chrBaseOffset) const;
248  Scene *getSceneById(int id) const;
249  Scene *getSceneByOffset(int offset) const;
250  int saveGame(const Common::String &fileName, const Common::String &descriptionString);
251  int loadGame(int slotId);
252 
253  void resetState();
254  void restart();
255 
256 private:
257  const ADGameDescription *_gameDescription;
258 
259  Common::MacResManager *_resManager;
260 
261  Audio::SoundHandle _soundHandle;
262 };
263 
264 extern WageEngine *g_wage;
265 
266 } // End of namespace Wage
267 
268 #endif
Definition: macresman.h:126
Definition: world.h:61
Definition: str.h:59
EngineFeature
Definition: engine.h:282
Definition: error.h:81
Definition: advancedDetector.h:164
Definition: random.h:44
Definition: rect.h:536
Definition: stream.h:745
Definition: wage.h:128
Definition: mixer.h:49
Definition: ustr.h:57
Definition: entities.h:232
Definition: events.h:218
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: gui.h:124
Definition: entities.h:301
Definition: debugger.h:28
Definition: entities.h:131
Definition: system.h:166
Definition: entities.h:112
Definition: engine.h:149
Definition: pcspk.h:36
Definition: system.h:39