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  kDebugImGui = 1,
96  kDebugSound,
97  kDebugLoading,
98 };
99 
100 enum OperandType {
101  OBJ = 0,
102  CHR = 1,
103  SCENE = 2,
104  NUMBER = 3,
105  STRING = 4,
106  CLICK_INPUT = 5,
107  TEXT_INPUT = 6,
108  UNKNOWN = 100
109 };
110 
111 enum Directions {
112  NORTH = 0,
113  SOUTH = 1,
114  EAST = 2,
115  WEST = 3
116 };
117 
118 enum Resolution {
119  GF_RES800 = 1 << 0,
120  GF_RES1024 = 1 << 1
121 };
122 
124 const char *getIndefiniteArticle(const Common::String &word);
125 const char *prependGenderSpecificPronoun(int gender);
126 const char *getGenderSpecificPronoun(int gender, bool capitalize);
127 bool isStorageScene(const Common::String &name);
128 
129 class WageEngine : public Engine {
130  friend class Dialog;
131 public:
132  WageEngine(OSystem *syst, const ADGameDescription *gameDesc);
133  ~WageEngine() override;
134 
135  bool hasFeature(EngineFeature f) const override;
136 
137  Common::Error run() override;
138 
139  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
140  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
141 
142  const char *getGameFile() const;
143  void processTurn(Common::String *textInput, Designed *clickInput);
144  void regen();
145 
146  const char *getTargetName() { return _targetName.c_str(); }
147  bool pollEvent(Common::Event &event);
148 
149 private:
150  bool loadWorld(Common::MacResManager *resMan);
151  void performInitialSetup();
152  void wearObjs(Chr *chr);
153  void processTurnInternal(Common::String *textInput, Designed *clickInput);
154  void performCombatAction(Chr *npc, Chr *player);
155  int getValidMoveDirections(Chr *npc);
156  void performAttack(Chr *attacker, Chr *victim, Obj *weapon);
157  void performMagic(Chr *attacker, Chr *victim, Obj *magicalObject);
158  void performMove(Chr *chr, int validMoves);
159  void performOffer(Chr *attacker, Chr *victim);
160  void performTake(Chr *npc, Obj *obj);
161  void decrementUses(Obj *obj);
162  bool attackHit(Chr *attacker, Chr *victim, Obj *weapon, int targetIndex);
163  void performHealingMagic(Chr *chr, Obj *magicalObject);
164 
165 public:
166  void takeObj(Obj *obj);
167 
168  bool handleMoveCommand(Directions dir, const char *dirName);
169  bool handleLookCommand();
170  Common::String *getGroundItemsList(Scene *scene);
171  void appendObjNames(Common::String &str, const ObjArray &objs);
172  bool handleInventoryCommand();
173  bool handleStatusCommand();
174  bool handleRestCommand();
175  bool handleAcceptCommand();
176 
177  bool handleTakeCommand(const char *target);
178  bool handleDropCommand(const char *target);
179  bool handleAimCommand(const char *target);
180  bool handleWearCommand(const char *target);
181  bool handleOfferCommand(const char *target);
182 
183  void wearObj(Obj *o, int pos);
184 
185  bool tryAttack(const Obj *weapon, const Common::String &input);
186  bool handleAttack(Obj *weapon);
187 
188  void printPlayerCondition(Chr *player);
189  const char *getPercentMessage(double percent);
190 
191  void doClose();
192 
193 public:
194  Common::RandomSource *_rnd;
195 
196  Gui *_gui;
197  World *_world;
198 
199  Scene *_lastScene;
200  int _loopCount;
201  int _turn;
202  Chr *_monster;
203  Chr *_running;
204  Obj *_offer;
205  int _aim;
206  int _opponentAim;
207  bool _temporarilyHidden;
208  bool _isGameOver;
209  bool _commandWasQuick;
210  bool _restartRequested = false;
211 
212  bool _shouldQuit;
213  int _defaultSaveSlot = -1;
214  Common::String _defaultSaveDescritpion;
215 
216  Common::String _inputText;
217 
218  Common::List<int> _soundQueue;
219  Common::String _soundToPlay;
220  Audio::PCSpeaker *_speaker;
221 
222  void playSound(Common::String soundName, bool blocking = true);
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:258
Definition: error.h:81
Definition: advancedDetector.h:164
Definition: random.h:44
Definition: rect.h:524
Definition: stream.h:745
Definition: wage.h:129
Definition: mixer.h:49
Definition: ustr.h:57
Definition: entities.h:231
Definition: events.h:210
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:163
Definition: entities.h:111
Definition: engine.h:144
Definition: pcspk.h:34
Definition: system.h:38