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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*!
  2. * \file include/Script.h
  3. * \brief Game 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.
  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. ~Script();
  87. int load(const char *file);
  88. unsigned int levelCount();
  89. std::string getLevelName(unsigned int i);
  90. std::string getLevelFilename(unsigned int i);
  91. unsigned int pictureCount();
  92. std::string getPictureFilename(unsigned int i);
  93. unsigned int cutsceneCount();
  94. std::string getCutsceneFilename(unsigned int i);
  95. unsigned int titleCount();
  96. std::string getTitleFilename(unsigned int i);
  97. unsigned int videoCount();
  98. std::string getVideoFilename(unsigned int i);
  99. unsigned int gameStringCount();
  100. std::string getGameString(unsigned int i);
  101. unsigned int pcStringCount();
  102. std::string getPCString(unsigned int i);
  103. std::string getPuzzleString(unsigned int i, unsigned int j);
  104. std::string getPickupString(unsigned int i, unsigned int j);
  105. std::string getKeyString(unsigned int i, unsigned int j);
  106. void registerScriptHandler(ScriptOpCode op, std::function<int (bool, uint16_t)> func);
  107. int runScript(unsigned int level);
  108. private:
  109. typedef enum {
  110. S_DemoVersion = (1 << 0), //!< Don't load a MAIN.SFX
  111. S_TitleDisabled = (1 << 1), //!< If set, game has no title screen
  112. S_CheatModeCheckDisabled = (1 << 2), //!< Disable flare/step/rotate/jump sequence
  113. S_NoInputTimeout = (1 << 3), //!< If set don't timeout input to start demo
  114. S_LoadSaveDisabled = (1 << 4), //!< Don't allow load/save
  115. S_ScreenSizingDisabled = (1 << 5), //!< Don't change screen resolution
  116. S_LockOutOptionRing = (1 << 6), //!< No option ring while in level
  117. S_DOZYCheatEnabled = (1 << 7), //!< DOZY flying cheat
  118. S_UseSecurityTag = (1 << 8), //!< Strings XORed with cypherCode
  119. S_Unknown = (1 << 9), //!< Usually set, no known effect
  120. S_SelectAnyLevel = (1 << 10), //!< Level selectable in Title
  121. S_EnableCheatCode = (1 << 11) //!< No known effect
  122. } ScriptFlag;
  123. void readStringPackage(BinaryFile &f, std::vector<std::string> &v, unsigned int n);
  124. void readScriptPackage(BinaryFile &f, std::vector<std::vector<uint16_t>> &v, unsigned int n);
  125. const bool opcodeHasOperand[OP_UNKNOWN] {
  126. true, true, true, true, true, true,
  127. false, true, true, false, true, false,
  128. true, false, false, false, true, true,
  129. true, true, true, false, false
  130. };
  131. // Header
  132. uint32_t version; // Always 3, for TR2/3 on PC and PSX
  133. std::string description;
  134. // Gameflow data
  135. uint32_t firstOption;
  136. int32_t titleReplace;
  137. uint32_t onDeathDemoMode;
  138. uint32_t onDeathInGame;
  139. uint32_t noInputTime;
  140. uint32_t onDemoInterrupt;
  141. uint32_t onDemoEnd;
  142. uint16_t numLevels;
  143. uint16_t numPictures;
  144. uint16_t numTitles;
  145. uint16_t numFMVs;
  146. uint16_t numCutscenes;
  147. uint16_t numDemos;
  148. uint16_t titleTrack;
  149. int16_t singleLevel;
  150. uint16_t flags; // See ScriptFlag enum
  151. uint8_t cypherCode;
  152. uint8_t language; // See ScriptLanguage enum
  153. uint16_t secretTrack;
  154. uint16_t numPCStrings;
  155. uint16_t numGameStrings;
  156. // Strings
  157. std::vector<std::string> levelNames; // numLevels
  158. std::vector<std::string> pictureFilenames; // numPictures
  159. std::vector<std::string> titleFilenames; // numTitles
  160. std::vector<std::string> fmvFilenames; // numFMVs
  161. std::vector<std::string> levelFilenames; // numLevels
  162. std::vector<std::string> cutsceneFilenames; // numCutscenes
  163. std::vector<std::vector<uint16_t>> script; // numLevels + 1
  164. std::vector<std::string> gameStrings; // numGameStrings
  165. std::vector<std::string> pcStrings; // 41 for TR2/3 on PC; 80 for TR2 on PSX
  166. std::vector<std::vector<std::string>> puzzles; // 4 * numLevels
  167. std::vector<std::vector<std::string>> pickups; // 2 * numLevels
  168. std::vector<std::vector<std::string>> keys; // 4 * numLevels
  169. std::function<int (bool, uint16_t)> scriptHandlers[OP_UNKNOWN];
  170. };
  171. #endif