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

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