ScummVM API documentation
tt_npc_script.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 #ifndef TITANIC_TT_NPC_SCRIPT_H
23 #define TITANIC_TT_NPC_SCRIPT_H
24 
25 #include "titanic/support/simple_file.h"
26 #include "titanic/true_talk/tt_script_base.h"
27 #include "titanic/true_talk/script_support.h"
28 
29 namespace Titanic {
30 
31 #define DIALS_ARRAY_COUNT 10
32 
33 class CGameManager;
34 class CPetControl;
35 class TTroomScript;
36 
37 struct TTnpcData {
38 private:
39  int _array[136];
40 public:
41  TTnpcData();
42  int &operator[](int idx) { return _array[idx]; }
43  int *getSlot(int idx) { return &_array[16 + idx * 4]; }
44  void resetFlags();
45 
46  void copyData();
47 };
48 
49 class TTnpcScriptBase : public TTscriptBase {
50 protected:
51  int _field54;
52  int _val2;
53 public:
54  int _charId;
55 public:
56  TTnpcScriptBase(int charId, const char *charClass, int v2,
57  const char *charName, int v3, int val2, int v4,
58  int v5, int v6, int v7);
59 
63  virtual int chooseResponse(const TTroomScript *roomScript, const TTsentence *sentence, uint tag) = 0;
64 
68  virtual int process(const TTroomScript *roomScript, const TTsentence *sentence) = 0;
69 
70  virtual int proc8() const = 0;
71 
75  virtual ScriptChangedResult scriptChanged(uint id) = 0;
76 
80  virtual ScriptChangedResult scriptChanged(const TTroomScript *roomScript, uint id) = 0;
81 
82  virtual int proc11() const = 0;
83  virtual int proc12() const = 0;
84 
85  int charId() const { return _charId; }
86 };
87 
88 class TTnpcScript : public TTnpcScriptBase {
89 private:
90  int translateByArray(int id);
91 protected:
92  static TTsentenceEntries *_defaultEntries;
93 protected:
95  int _valuesPerResponse;
97  TTscriptMappings _mappings;
98  TTsentenceEntries _entries;
99  TTtagMappings _tagMappings;
100  TTwordEntries _words;
101  TThandleQuoteEntries _quotes;
102  int _entryCount;
103  int _field68;
104  int _field6C;
105  int _rangeResetCtr;
106  int _currentDialNum;
107  int _dialDelta;
108  int _field7C;
109  const char *_itemStringP;
110  int _dialValues[DIALS_ARRAY_COUNT];
111  TTnpcData _data;
112  bool _field2CC;
113 protected:
117  void loadResponses(const char *name, int valuesPerResponse = 1);
118 
122  void loadRanges(const char *name);
123 
127  void resetFlags();
128 
132  void setupDials(int dial1, int dial2, int dial3);
133 
134  static int getRoom54(int roomId);
135 
139  int getValue(int testNum) const;
140 
144  uint getRandomNumber(int max) const;
145 
149  uint getRandomBit() const {
150  return getRandomNumber(2) - 1;
151  }
152 
156  uint getDialogueId(uint tagId);
157 
161  static CPetControl *getPetControl(CGameManager *gameManager);
162 
166  void addRange(uint id, const Common::Array<uint> &values, bool isRandom, bool isSequential);
167 
171  TTscriptRange *findRange(uint id);
172 
176  int processEntries(const TTsentenceEntries *entries, uint entryCount, const TTroomScript *roomScript, const TTsentence *sentence);
177 
181  int processEntries(const TTroomScript *roomScript, const TTsentence *sentence) {
182  return processEntries(&_entries, _entryCount, roomScript, sentence);
183  }
184 
185  bool defaultProcess(const TTroomScript *roomScript, const TTsentence *sentence);
186 
187  void checkItems(const TTroomScript *roomScript, const TTsentence *sentence);
188 
192  bool addRandomResponse(bool flag);
193 
197  void updateCurrentDial(bool changeDial);
198 
199  bool fn10(bool flag);
200 
201  static bool sentence2C(const TTsentence *sentence);
202 
206  bool getStateValue() const;
207 
211  void getAssignedRoom(int *roomNum, int *floorNum, int *elevatorNum) const;
212 
216  void setResponseFromArray(int index, int id);
217 public:
218  static void init();
219  static void deinit();
220 public:
221  TTnpcScript(int charId, const char *charClass, int v2,
222  const char *charName, int v3, int val2, int v4,
223  int v5, int v6, int v7);
224 
225  void addResponse(int id) override;
226 
232  int chooseResponse(const TTroomScript *roomScript, const TTsentence *sentence, uint tag) override;
233 
237  int process(const TTroomScript *roomScript, const TTsentence *sentence) override;
238 
239  int proc8() const override;
240 
244  ScriptChangedResult scriptChanged(uint id) override {
245  return SCR_2;
246  }
247 
251  ScriptChangedResult scriptChanged(const TTroomScript *roomScript, uint id) override {
252  return SCR_2;
253  }
254 
255  int proc11() const override;
256  int proc12() const override;
257 
262  virtual void selectResponse(int id);
263 
268  virtual bool handleWord(uint id) const;
269 
270  virtual int handleQuote(const TTroomScript *roomScript, const TTsentence *sentence,
271  uint tag1, uint tag2, uint remainder);
272 
276  virtual bool isQuoteDialled() const { return false; }
277 
283  virtual uint getRangeValue(uint id);
284 
288  virtual void resetRange(int id);
289 
293  virtual int updateState(uint oldId, uint newId, int index);
294 
298  virtual int preResponse(uint id);
299 
303  virtual uint getDialsBitset() const { return 0; }
304 
305  virtual const TTscriptMapping *getMapping(int index);
306  virtual int doSentenceEntry(int val1, const int *srcIdP, const TTroomScript *roomScript, const TTsentence *sentence);
307 
311  virtual void postResponse(int v1, const TTsentenceEntry *entry, const TTroomScript *roomScript, const TTsentence *sentence) {}
312 
313  virtual void save(SimpleFile *file);
314  virtual void load(SimpleFile *file);
315  virtual void saveBody(SimpleFile *file);
316  virtual void loadBody(SimpleFile *file);
317 
321  virtual int getRangesCount() const;
322 
326  virtual void setDialRegion(int dialNum, int region);
327 
331  virtual void setDial(int dialNum, int value);
332 
336  virtual int getDialRegion(int dialNum) const;
337 
344  virtual int getDialLevel(uint dialNum, bool randomizeFlag = true);
345 
349  virtual bool randomResponse(uint index);
350 
351  virtual uint translateId(uint id) const;
352 
353  void preLoad();
354 
358  ScriptChangedResult notifyScript(TTroomScript *roomScript, int id) {
359  return scriptChanged(roomScript, id);
360  }
361 };
362 
363 } // End of namespace Titanic
364 
365 #endif /* TITANIC_TT_NPC_SCRIPT_H */
Definition: tt_npc_script.h:49
Definition: script_support.h:105
Definition: script_support.h:65
int processEntries(const TTroomScript *roomScript, const TTsentence *sentence)
Definition: tt_npc_script.h:181
Definition: array.h:52
Definition: tt_room_script.h:61
Definition: script_support.h:143
ScriptChangedResult scriptChanged(const TTroomScript *roomScript, uint id) override
Definition: tt_npc_script.h:251
virtual uint getDialsBitset() const
Definition: tt_npc_script.h:303
virtual void postResponse(int v1, const TTsentenceEntry *entry, const TTroomScript *roomScript, const TTsentence *sentence)
Definition: tt_npc_script.h:311
Definition: script_support.h:90
Definition: simple_file.h:49
uint getRandomBit() const
Definition: tt_npc_script.h:149
Definition: tt_sentence.h:49
Definition: tt_npc_script.h:88
Definition: script_support.h:98
Definition: tt_npc_script.h:37
ScriptChangedResult scriptChanged(uint id) override
Definition: tt_npc_script.h:244
Definition: game_manager.h:48
Definition: arm.h:30
virtual bool isQuoteDialled() const
Definition: tt_npc_script.h:276
Definition: script_support.h:118
Definition: script_support.h:130
ScriptChangedResult notifyScript(TTroomScript *roomScript, int id)
Definition: tt_npc_script.h:358
Definition: tt_script_base.h:38
Definition: pet_control.h:45
Definition: script_support.h:52