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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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?
  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 or 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.
  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. typedef enum {
  55. OP_WEAPON_PISTOLS = 0, //!< Add standard pistols (2)
  56. OP_WEAPON_SHOTGUN = 1, //!< Add shotgun (1)
  57. OP_WEAPON_AUTOPISTOLS = 2, //!< Add automatic pistols (2)
  58. OP_WEAPON_UZIS = 3, //!< Add uzis (2)
  59. OP_WEAPON_HARPOON = 4, //!< Add harpoon gun (1)
  60. OP_WEAPON_M16 = 5, //!< Add M16 (1)
  61. OP_WEAPON_ROCKET = 6, //!< Add grenade launcher (1)
  62. OP_AMMO_PISTOLS = 7, //!< No effect, infinite ammo
  63. OP_AMMO_SHOTGUN = 8, //!< Add 2 shells
  64. OP_AMMO_AUTOPISTOLS = 9, //!< Add 2 shells
  65. OP_AMMO_UZIS = 10, //!< Add 2 shells
  66. OP_AMMO_HARPOON = 11, //!< Add 2 harpoons
  67. OP_AMMO_M16 = 12, //!< Add 2 shells
  68. OP_AMMO_ROCKET = 13, //!< Add 1 grenade
  69. OP_ITEM_FLARE = 14, //!< Add 1 flare
  70. OP_ITEM_MEDI = 15, //!< Add 1 small MediPack
  71. OP_ITEM_BIGMEDI = 16, //!< Add 1 big MediPack
  72. OP_ITEM_PICKUP1 = 17, //!< Add Pickup Item 1
  73. OP_ITEM_PICKUP2 = 18, //!< Add Pickup Item 2
  74. OP_ITEM_PUZZLE1 = 19, //!< Add Puzzle Item 1
  75. OP_ITEM_PUZZLE2 = 20, //!< Add Puzzle Item 2
  76. OP_ITEM_PUZZLE3 = 21, //!< Add Puzzle Item 3
  77. OP_ITEM_PUZZLE4 = 22, //!< Add Puzzle Item 4
  78. OP_ITEM_KEY1 = 23, //!< Add Key Item 1
  79. OP_ITEM_KEY2 = 24, //!< Add Key Item 2
  80. OP_ITEM_KEY3 = 25, //!< Add Key Item 3
  81. OP_ITEM_KEY4 = 26, //!< Add Key Item 4
  82. OP_ITEM_UNKNOWN = 27
  83. } ScriptItem;
  84. Script();
  85. ~Script();
  86. int load(const char *file);
  87. unsigned int levelCount();
  88. std::string getLevelName(unsigned int i);
  89. std::string getLevelFilename(unsigned int i);
  90. unsigned int cutsceneCount();
  91. std::string getCutsceneFilename(unsigned int i);
  92. unsigned int titleCount();
  93. std::string getTitleFilename(unsigned int i);
  94. unsigned int videoCount();
  95. std::string getVideoFilename(unsigned int i);
  96. unsigned int gameStringCount();
  97. std::string getGameString(unsigned int i);
  98. unsigned int pcStringCount();
  99. std::string getPCString(unsigned int i);
  100. std::string getPuzzleString(unsigned int i, unsigned int j);
  101. std::string getPickupString(unsigned int i, unsigned int j);
  102. std::string getKeyString(unsigned int i, unsigned int j);
  103. void registerScriptHandler(ScriptOpCode op, std::function<int (bool, uint16_t)> func);
  104. int runScript(unsigned int level);
  105. private:
  106. typedef enum {
  107. S_DemoVersion = (1 << 0), //!< Don't load a MAIN.SFX
  108. S_TitleDisabled = (1 << 1), //!< If set, game has no title screen
  109. S_CheatModeCheckDisabled = (1 << 2), //!< Disable flare/step/rotate/jump sequence
  110. S_NoInputTimeout = (1 << 3), //!< If set don't timeout input to start demo
  111. S_LoadSaveDisabled = (1 << 4), //!< Don't allow load/save
  112. S_ScreenSizingDisabled = (1 << 5), //!< Don't change screen resolution
  113. S_LockOutOptionRing = (1 << 6), //!< No option ring while in level
  114. S_DOZYCheatEnabled = (1 << 7), //!< DOZY flying cheat
  115. S_UseSecurityTag = (1 << 8), //!< Strings XORed with cypherCode
  116. S_Unknown = (1 << 9), //!< Usually set, no known effect
  117. S_SelectAnyLevel = (1 << 10), //!< Level selectable in Title
  118. S_EnableCheatCode = (1 << 11) //!< No known effect
  119. } ScriptFlag;
  120. void readStringPackage(BinaryFile &f, std::vector<std::string> &v, unsigned int n);
  121. const bool opcodeHasOperand[OP_UNKNOWN] {
  122. true, true, true, true, true, true,
  123. false, true, true, false, true, false,
  124. true, false, false, false, true, true,
  125. true, true, true, false, false
  126. };
  127. // Header
  128. uint32_t version;
  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;
  147. uint8_t cypherCode;
  148. uint8_t language;
  149. uint16_t secretTrack;
  150. // Strings
  151. std::vector<std::string> levelNames; // numLevels
  152. std::vector<std::string> pictureFilenames; // numPictures
  153. std::vector<std::string> titleFilenames; // numTitles
  154. std::vector<std::string> fmvFilenames; // numFMVs
  155. std::vector<std::string> levelFilenames; // numLevels
  156. std::vector<std::string> cutsceneFilenames; // numCutscenes
  157. std::vector<std::vector<uint16_t>> script; // numLevels + 1
  158. uint16_t numGameStrings;
  159. std::vector<std::string> gameStrings; // numGameStrings, 89
  160. std::vector<std::string> pcStrings; // 41
  161. std::vector<std::vector<std::string>> puzzles; // 4 * numLevels
  162. std::vector<std::vector<std::string>> pickups; // 2 * numLevels
  163. std::vector<std::vector<std::string>> keys; // 4 * numLevels
  164. std::function<int (bool, uint16_t)> scriptHandlers[OP_UNKNOWN];
  165. };
  166. #endif