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 Wage {
73 
74 class Console;
75 class Chr;
76 class Designed;
77 class Dialog;
78 class Gui;
79 class Obj;
80 class Scene;
81 class World;
82 
83 typedef Common::Array<Obj *> ObjArray;
84 typedef Common::Array<Chr *> ChrArray;
85 typedef Common::List<Obj *> ObjList;
86 typedef Common::List<Chr *> ChrList;
87 
88 #define STORAGESCENE "STORAGE@"
89 
90 enum OperandType {
91  OBJ = 0,
92  CHR = 1,
93  SCENE = 2,
94  NUMBER = 3,
95  STRING = 4,
96  CLICK_INPUT = 5,
97  TEXT_INPUT = 6,
98  UNKNOWN = 100
99 };
100 
101 enum Directions {
102  NORTH = 0,
103  SOUTH = 1,
104  EAST = 2,
105  WEST = 3
106 };
107 
108 // our engine debug levels
109 enum {
110  kWageDebugExample = 1 << 0,
111  kWageDebugExample2 = 1 << 1
112  // next new level must be 1 << 2 (4)
113  // the current limitation is 32 debug levels (1 << 31 is the last one)
114 };
115 
116 enum Resolution {
117  GF_RES800 = 1 << 0,
118  GF_RES1024 = 1 << 1
119 };
120 
122 const char *getIndefiniteArticle(const Common::String &word);
123 const char *prependGenderSpecificPronoun(int gender);
124 const char *getGenderSpecificPronoun(int gender, bool capitalize);
125 bool isStorageScene(const Common::String &name);
126 
127 class WageEngine : public Engine {
128  friend class Dialog;
129 public:
130  WageEngine(OSystem *syst, const ADGameDescription *gameDesc);
131  ~WageEngine() override;
132 
133  bool hasFeature(EngineFeature f) const override;
134 
135  Common::Error run() override;
136 
137  bool canLoadGameStateCurrently(Common::U32String *msg = nullptr) override;
138  bool canSaveGameStateCurrently(Common::U32String *msg = nullptr) override;
139 
140  const char *getGameFile() const;
141  void processTurn(Common::String *textInput, Designed *clickInput);
142  void regen();
143 
144  const char *getTargetName() { return _targetName.c_str(); }
145  bool pollEvent(Common::Event &event);
146 
147 private:
148  bool loadWorld(Common::MacResManager *resMan);
149  void performInitialSetup();
150  void wearObjs(Chr *chr);
151  void processTurnInternal(Common::String *textInput, Designed *clickInput);
152  void performCombatAction(Chr *npc, Chr *player);
153  int getValidMoveDirections(Chr *npc);
154  void performAttack(Chr *attacker, Chr *victim, Obj *weapon);
155  void performMagic(Chr *attacker, Chr *victim, Obj *magicalObject);
156  void performMove(Chr *chr, int validMoves);
157  void performOffer(Chr *attacker, Chr *victim);
158  void performTake(Chr *npc, Obj *obj);
159  void decrementUses(Obj *obj);
160  bool attackHit(Chr *attacker, Chr *victim, Obj *weapon, int targetIndex);
161  void performHealingMagic(Chr *chr, Obj *magicalObject);
162 
163  void doClose();
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 public:
192  Common::RandomSource *_rnd;
193 
194  Gui *_gui;
195  World *_world;
196 
197  Scene *_lastScene;
198  int _loopCount;
199  int _turn;
200  Chr *_monster;
201  Chr *_running;
202  Obj *_offer;
203  int _aim;
204  int _opponentAim;
205  bool _temporarilyHidden;
206  bool _isGameOver;
207  bool _commandWasQuick;
208  bool _restartRequested = false;
209 
210  bool _shouldQuit;
211  int _defaultSaveSlot = -1;
212  Common::String _defaultSaveDescritpion;
213 
214  Common::String _inputText;
215 
216  Common::List<int> _soundQueue;
217  Common::String _soundToPlay;
218 
219  void playSound(Common::String soundName);
220  void updateSoundTimerForScene(Scene *scene, bool firstTime);
221  void setMenu(Common::String soundName);
222  void appendText(const char *str);
223  void sayText(const Common::U32String &str, Common::TextToSpeechManager::Action action = Common::TextToSpeechManager::INTERRUPT_NO_REPEAT) const;
224  void sayText(const Common::String &str, Common::TextToSpeechManager::Action action = Common::TextToSpeechManager::INTERRUPT_NO_REPEAT) const;
225  void gameOver();
226  bool saveDialog();
227  void aboutDialog();
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 } // End of namespace Wage
265 
266 #endif
Definition: macresman.h:126
Definition: world.h:61
Definition: str.h:59
EngineFeature
Definition: engine.h:260
Definition: error.h:81
Definition: advancedDetector.h:164
Definition: random.h:44
Definition: rect.h:524
Definition: stream.h:745
Definition: wage.h:127
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:146