OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
Script.h
Go to the documentation of this file.
1 
8 #ifndef _SCRIPT_H_
9 #define _SCRIPT_H_
10 
11 #include "utils/binary.h"
12 
13 #include <cstdint>
14 #include <functional>
15 #include <string>
16 #include <vector>
17 
21 class Script {
22  public:
23 
24  typedef enum {
25  S_English = 0,
26  S_French = 1,
27  S_German = 2,
31 
32  typedef enum {
33  OP_PICTURE = 0,
35  OP_PSX_FMV = 2,
36  OP_FMV = 3,
37  OP_GAME = 4,
38  OP_CUT = 5,
40  OP_DEMO = 7,
42  OP_END = 9,
43  OP_TRACK = 10,
44  OP_SUNSET = 11,
45  OP_LOAD_PIC = 12,
49  OP_CUTANGLE = 16,
50  OP_NOFLOOR = 17,
51  OP_STARTINV = 18,
52  OP_STARTANIM = 19,
53  OP_SECRETS = 20,
57  } ScriptOpCode;
58 
59  // Items for all-secrets-found go from 0 to 26,
60  // for start-inventory add 1000, so 1000 - 1026
61  // Atleast in TR2
62  typedef enum {
73  OP_AMMO_UZIS = 10,
75  OP_AMMO_M16 = 12,
78  OP_ITEM_MEDI = 15,
86  OP_ITEM_KEY1 = 23,
87  OP_ITEM_KEY2 = 24,
88  OP_ITEM_KEY3 = 25,
89  OP_ITEM_KEY4 = 26,
91  } ScriptItem;
92 
93  Script();
94 
95  int load(std::string file);
96 
97  unsigned int levelCount();
98  std::string getLevelName(unsigned int i);
99  std::string getLevelFilename(unsigned int i);
100 
101  unsigned int pictureCount();
102  std::string getPictureFilename(unsigned int i);
103 
104  unsigned int cutsceneCount();
105  std::string getCutsceneFilename(unsigned int i);
106 
107  unsigned int titleCount();
108  std::string getTitleFilename(unsigned int i);
109 
110  unsigned int videoCount();
111  std::string getVideoFilename(unsigned int i);
112 
113  unsigned int gameStringCount();
114  std::string getGameString(unsigned int i);
115 
116  unsigned int pcStringCount();
117  std::string getPCString(unsigned int i);
118 
119  std::string getPuzzleString(unsigned int i, unsigned int j);
120  std::string getPickupString(unsigned int i, unsigned int j);
121  std::string getKeyString(unsigned int i, unsigned int j);
122 
123  void registerScriptHandler(ScriptOpCode op, std::function<int (bool, uint16_t)> func);
124  int runScript(unsigned int level);
125 
126  std::string getDescription() { return description; }
127  std::string getLanguage();
128 
129  private:
130 
131  typedef enum {
132  S_DemoVersion = (1 << 0),
133  S_TitleDisabled = (1 << 1),
135  S_NoInputTimeout = (1 << 3),
136  S_LoadSaveDisabled = (1 << 4),
138  S_LockOutOptionRing = (1 << 6),
139  S_DOZYCheatEnabled = (1 << 7),
140  S_UseSecurityTag = (1 << 8),
141  S_Unknown = (1 << 9),
142  S_SelectAnyLevel = (1 << 10),
143  S_EnableCheatCode = (1 << 11)
144  } ScriptFlag;
145 
146  void readStringPackage(BinaryFile& f, std::vector<std::string>& v, unsigned int n);
147  void readScriptPackage(BinaryFile& f, std::vector<std::vector<uint16_t>>& v, unsigned int n);
148 
149  const static bool opcodeHasOperand[OP_UNKNOWN];
150 
151  // Header
152  uint32_t version; // Always 3, for TR2/3 on PC and PSX
153  std::string description;
154 
155  // Gameflow data
156  uint32_t firstOption;
157  int32_t titleReplace;
158  uint32_t onDeathDemoMode;
159  uint32_t onDeathInGame;
160  uint32_t noInputTime;
161  uint32_t onDemoInterrupt;
162  uint32_t onDemoEnd;
163  uint16_t numLevels;
164  uint16_t numPictures;
165  uint16_t numTitles;
166  uint16_t numFMVs;
167  uint16_t numCutscenes;
168  uint16_t numDemos;
169  uint16_t titleTrack;
170  int16_t singleLevel;
171  uint16_t flags; // See ScriptFlag enum
172  uint8_t cypherCode;
173  uint8_t language; // See ScriptLanguage enum
174  uint16_t secretTrack;
175 
176  uint16_t numPCStrings;
177  uint16_t numGameStrings;
178 
179  // Strings
180  std::vector<std::string> levelNames; // numLevels
181  std::vector<std::string> pictureFilenames; // numPictures
182  std::vector<std::string> titleFilenames; // numTitles
183  std::vector<std::string> fmvFilenames; // numFMVs
184  std::vector<std::string> levelFilenames; // numLevels
185  std::vector<std::string> cutsceneFilenames; // numCutscenes
186  std::vector<std::vector<uint16_t>> script; // numLevels + 1
187  std::vector<std::string> gameStrings; // numGameStrings
188  std::vector<std::string> pcStrings; // 41 for TR2/3 on PC; 80 for TR2 on PSX
189  std::vector<std::vector<std::string>> puzzles; // 4 * numLevels
190  std::vector<std::vector<std::string>> pickups; // 2 * numLevels
191  std::vector<std::vector<std::string>> keys; // 4 * numLevels
192 
193  std::function<int (bool, uint16_t)> scriptHandlers[OP_UNKNOWN];
194 };
195 
196 #endif
197 
Add 1 grenade.
Definition: Script.h:76
int32_t titleReplace
Definition: Script.h:157
ScriptItem
Definition: Script.h:62
int runScript(unsigned int level)
Definition: Script.cpp:320
Add 2 shells.
Definition: Script.h:73
unsigned int titleCount()
Definition: Script.cpp:261
uint32_t firstOption
Definition: Script.h:156
DOZY flying cheat.
Definition: Script.h:139
Start level without weapons.
Definition: Script.h:47
uint16_t numCutscenes
Definition: Script.h:167
Add standard pistols (2)
Definition: Script.h:63
uint32_t noInputTime
Definition: Script.h:160
std::vector< std::string > gameStrings
Definition: Script.h:187
Add Puzzle Item 2.
Definition: Script.h:83
std::string getTitleFilename(unsigned int i)
Definition: Script.cpp:265
uint16_t flags
Definition: Script.h:171
Unknown, nothing changes in TR2.
Definition: Script.h:46
Unknown, nothing changes in TR2. Start in Motorboat?
Definition: Script.h:44
uint32_t onDemoInterrupt
Definition: Script.h:161
uint16_t numGameStrings
Definition: Script.h:177
Display FMV.
Definition: Script.h:36
Strings XORed with cypherCode.
Definition: Script.h:140
Does not compile. PSX?
Definition: Script.h:41
uint32_t version
Definition: Script.h:152
Closes script sequence.
Definition: Script.h:42
Add Puzzle Item 4.
Definition: Script.h:85
If set, game has no title screen.
Definition: Script.h:133
Binary file reading utilities.
std::string getLevelFilename(unsigned int i)
Definition: Script.cpp:238
uint16_t numLevels
Definition: Script.h:163
std::string getLevelName(unsigned int i)
Definition: Script.cpp:233
Lara dies when her feet reach given depth.
Definition: Script.h:50
std::vector< std::vector< std::string > > keys
Definition: Script.h:191
Add uzis (2)
Definition: Script.h:66
static const bool opcodeHasOperand[OP_UNKNOWN]
Definition: Script.h:149
No option ring while in level.
Definition: Script.h:138
uint32_t onDeathInGame
Definition: Script.h:159
Add Puzzle Item 3.
Definition: Script.h:84
std::vector< std::string > pcStrings
Definition: Script.h:188
Add shotgun (1)
Definition: Script.h:64
Add M16 (1)
Definition: Script.h:68
No known effect.
Definition: Script.h:143
Add Key Item 2.
Definition: Script.h:87
Add 1 small MediPack.
Definition: Script.h:78
std::function< int(bool, uint16_t)> scriptHandlers[OP_UNKNOWN]
Definition: Script.h:193
Play soundtrack (precedes level opcode)
Definition: Script.h:43
Add grenade launcher (1)
Definition: Script.h:69
Add 2 harpoons.
Definition: Script.h:74
uint16_t titleTrack
Definition: Script.h:169
unsigned int gameStringCount()
Definition: Script.cpp:279
unsigned int pictureCount()
Definition: Script.cpp:243
Add harpoon gun (1)
Definition: Script.h:67
Display demo sequence.
Definition: Script.h:40
Display level-completion stats.
Definition: Script.h:39
uint16_t numTitles
Definition: Script.h:165
No effect, infinite ammo.
Definition: Script.h:70
std::vector< std::string > titleFilenames
Definition: Script.h:182
If set don't timeout input to start demo.
Definition: Script.h:135
std::vector< std::string > pictureFilenames
Definition: Script.h:181
int16_t singleLevel
Definition: Script.h:170
Add Key Item 4.
Definition: Script.h:89
uint32_t onDeathDemoMode
Definition: Script.h:158
void readScriptPackage(BinaryFile &f, std::vector< std::vector< uint16_t >> &v, unsigned int n)
Definition: Script.cpp:148
Add 1 big MediPack.
Definition: Script.h:79
Don't change screen resolution.
Definition: Script.h:137
std::string getPickupString(unsigned int i, unsigned int j)
Definition: Script.cpp:303
std::vector< std::string > cutsceneFilenames
Definition: Script.h:185
Match N-S orientation of Room and animated characters.
Definition: Script.h:49
uint16_t numFMVs
Definition: Script.h:166
std::string description
Definition: Script.h:153
Add 2 shells.
Definition: Script.h:75
std::string getPuzzleString(unsigned int i, unsigned int j)
Definition: Script.cpp:297
unsigned int videoCount()
Definition: Script.cpp:270
std::string getLanguage()
Definition: Script.cpp:350
uint16_t secretTrack
Definition: Script.h:174
Add Pickup Item 1.
Definition: Script.h:80
std::vector< std::string > levelFilenames
Definition: Script.h:184
Usually set, no known effect.
Definition: Script.h:141
Don't load a MAIN.SFX.
Definition: Script.h:132
Kill all enemies to finish the level.
Definition: Script.h:54
std::vector< std::string > levelNames
Definition: Script.h:180
std::vector< std::vector< uint16_t > > script
Definition: Script.h:186
std::string getDescription()
Definition: Script.h:126
Add automatic pistols (2)
Definition: Script.h:65
int load(std::string file)
Definition: Script.cpp:43
uint8_t cypherCode
Definition: Script.h:172
Display a cutscene.
Definition: Script.h:38
Add Key Item 1.
Definition: Script.h:86
std::string getKeyString(unsigned int i, unsigned int j)
Definition: Script.cpp:309
std::vector< std::vector< std::string > > pickups
Definition: Script.h:190
Add 1 flare.
Definition: Script.h:77
void readStringPackage(BinaryFile &f, std::vector< std::string > &v, unsigned int n)
Definition: Script.cpp:124
std::string getGameString(unsigned int i)
Definition: Script.cpp:283
unsigned int pcStringCount()
Definition: Script.cpp:288
Add 2 shells.
Definition: Script.h:72
std::vector< std::string > fmvFilenames
Definition: Script.h:183
Unused in TR2. Or PSX? Used in TR3.
Definition: Script.h:33
If zero, level does not account for secrets.
Definition: Script.h:53
Add Pickup Item 2.
Definition: Script.h:81
unsigned int cutsceneCount()
Definition: Script.cpp:252
Add Key Item 3.
Definition: Script.h:88
std::string getPictureFilename(unsigned int i)
Definition: Script.cpp:247
std::vector< std::vector< std::string > > puzzles
Definition: Script.h:189
Does not compile. PSX?
Definition: Script.h:34
ScriptLanguage
Definition: Script.h:24
Add 2 shells.
Definition: Script.h:71
Script()
Definition: Script.cpp:18
unsigned int levelCount()
Definition: Script.cpp:229
Add Puzzle Item 1.
Definition: Script.h:82
Don't allow load/save.
Definition: Script.h:136
ScriptFlag
Definition: Script.h:131
uint16_t numPCStrings
Definition: Script.h:176
Level selectable in Title.
Definition: Script.h:142
Disable flare/step/rotate/jump sequence.
Definition: Script.h:134
Lara starts level without ammo or medi packs.
Definition: Script.h:55
uint8_t language
Definition: Script.h:173
Does not compile. PSX? Used in TR3.
Definition: Script.h:45
std::string getCutsceneFilename(unsigned int i)
Definition: Script.cpp:256
Special animation of Lara when level starts.
Definition: Script.h:52
End of game. Show stats, start credits sequence, music ID 52 in TR2.
Definition: Script.h:48
std::string getPCString(unsigned int i)
Definition: Script.cpp:292
Does not compile. PSX?
Definition: Script.h:35
uint32_t onDemoEnd
Definition: Script.h:162
std::string getVideoFilename(unsigned int i)
Definition: Script.cpp:274
void registerScriptHandler(ScriptOpCode op, std::function< int(bool, uint16_t)> func)
Definition: Script.cpp:315
Items given to Lara at level start (+1000), or at all secrets found (+0)
Definition: Script.h:51
Start a playable level.
Definition: Script.h:37
ScriptOpCode
Definition: Script.h:32
uint16_t numPictures
Definition: Script.h:164
uint16_t numDemos
Definition: Script.h:168
Game script loader.
Definition: Script.h:21