Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Script.cpp 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*!
  2. * \file test/Script.cpp
  3. * \brief Game script loader unit test
  4. *
  5. * \author xythobuz
  6. */
  7. #include <iostream>
  8. #include "global.h"
  9. #include "utils/strings.h"
  10. #include "Script.h"
  11. #define printStrings(cnt, acc, name) { \
  12. std::cout << name << " (" << cnt << ")" << std::endl; \
  13. for (unsigned int i = 0; i < cnt; i++) { \
  14. std::cout << " " << acc(i) << std::endl; \
  15. } \
  16. std::cout << std::endl; \
  17. }
  18. #define printStrings2D(c, cnt, acc, name) { \
  19. std::cout << name << " (" << c << "*" << cnt << ")" << std::endl; \
  20. for (unsigned int a = 0; a < cnt; a++) { \
  21. std::cout << " "; \
  22. for (unsigned int i = 0; i < c; i++) { \
  23. std::cout << acc(i, a); \
  24. if (i < (c - 1)) \
  25. std::cout << " | "; \
  26. } \
  27. std::cout << std::endl; \
  28. } \
  29. std::cout << std::endl; \
  30. }
  31. #define registerLambda(x, y) { \
  32. s.registerScriptHandler(x, [](bool hasOperand, uint16_t operand) { \
  33. std::cout << "\t" << y; \
  34. if (hasOperand) \
  35. std::cout << " (" << operand << ")"; \
  36. std::cout << std::endl; \
  37. return 0; \
  38. }); \
  39. }
  40. namespace {
  41. int test(const char *f, bool strings) {
  42. Script s;
  43. assertEqual(s.load(f), 0);
  44. if (strings) {
  45. printStrings(s.levelCount(), s.getLevelName, "Level Names");
  46. printStrings(s.levelCount(), s.getLevelFilename, "Level Filenames");
  47. printStrings(s.pictureCount(), s.getPictureFilename, "Picture Filenames");
  48. printStrings(s.cutsceneCount(), s.getCutsceneFilename, "Cutscenes");
  49. printStrings(s.titleCount(), s.getTitleFilename, "Titles");
  50. printStrings(s.videoCount(), s.getVideoFilename, "Videos");
  51. printStrings(s.gameStringCount(), s.getGameString, "Game Strings");
  52. printStrings(s.pcStringCount(), s.getPCString, "PC Strings");
  53. printStrings2D(4, s.levelCount(), s.getPuzzleString, "Puzzles");
  54. printStrings2D(2, s.levelCount(), s.getPickupString, "Pickups");
  55. printStrings2D(4, s.levelCount(), s.getKeyString, "Keys");
  56. } else {
  57. registerLambda(Script::OP_PICTURE, "Picture");
  58. registerLambda(Script::OP_PSX_TRACK, "PSX-Track");
  59. registerLambda(Script::OP_PSX_FMV, "PSX-FMV");
  60. registerLambda(Script::OP_FMV, "Show FMV");
  61. registerLambda(Script::OP_GAME, "Load level");
  62. registerLambda(Script::OP_CUT, "Cutscene");
  63. registerLambda(Script::OP_COMPLETE, "Level finished");
  64. registerLambda(Script::OP_DEMO, "Demo sequence");
  65. registerLambda(Script::OP_PSX_DEMO, "PSX-Demo");
  66. registerLambda(Script::OP_END, "End of script");
  67. registerLambda(Script::OP_TRACK, "Sound Track");
  68. registerLambda(Script::OP_SUNSET, "Sunset");
  69. registerLambda(Script::OP_LOAD_PIC, "Load picture");
  70. registerLambda(Script::OP_DEADLY_WATER, "Deadly water");
  71. registerLambda(Script::OP_REMOVE_WEAPONS, "Remove weapons");
  72. registerLambda(Script::OP_GAMECOMPLETE, "End of game!");
  73. registerLambda(Script::OP_CUTANGLE, "Cutscene angle");
  74. registerLambda(Script::OP_NOFLOOR, "No floor, fall death");
  75. registerLambda(Script::OP_STARTINV, "Inventory/Bonus");
  76. registerLambda(Script::OP_STARTANIM, "Start animation");
  77. registerLambda(Script::OP_SECRETS, "Secrets");
  78. registerLambda(Script::OP_KILLTOCOMPLETE, "Kill to complete level");
  79. registerLambda(Script::OP_REMOVE_AMMO, "Remove ammo");
  80. for (unsigned int i = 0; i < (s.levelCount() + 1); i++) {
  81. if (i == 0)
  82. std::cout << "Script for Title:" << std::endl;
  83. else
  84. std::cout << "Script for \"" << s.getLevelName(i - 1) << "\" (" << i - 1 << "):" << std::endl;
  85. int error = s.runScript(i);
  86. if (error != 0)
  87. std::cout << "Returned " << error << "..." << std::endl;
  88. std::cout << std::endl;
  89. }
  90. }
  91. return 0;
  92. }
  93. }
  94. int main(int argc, char *argv[]) {
  95. std::cout << "Tomb Raider 2:" << std::endl;
  96. char *f = fullPath("~/.OpenRaider/paks/tr2/TOMBPC.DAT", 0);
  97. int error = test(f, !((argc > 1) && (argv[1][0] == 's')));
  98. delete [] f;
  99. if (error != 0)
  100. return error;
  101. std::cout << std::endl << "Tomb Raider 3:" << std::endl;
  102. f = fullPath("~/.OpenRaider/paks/tr3/TOMBPC.DAT", 0);
  103. error = test(f, !((argc > 1) && (argv[1][0] == 's')));
  104. delete [] f;
  105. if (error != 0)
  106. return error;
  107. std::cout << std::endl << "Tomb Raider 2 PSX:" << std::endl;
  108. f = fullPath("~/.OpenRaider/paks/tr2_psx/TOMBPSX.DAT", 0);
  109. error = test(f, !((argc > 1) && (argv[1][0] == 's')));
  110. delete [] f;
  111. if (error != 0)
  112. return error;
  113. std::cout << std::endl << "Tomb Raider 3 PSX:" << std::endl;
  114. f = fullPath("~/.OpenRaider/paks/tr3_psx/TOMBPSX.DAT", 0);
  115. error = test(f, !((argc > 1) && (argv[1][0] == 's')));
  116. delete [] f;
  117. return error;
  118. }