Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Script.h 7.7KB

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