Clone of Bael'Zharon's Respite @ https://github.com/boardwalk/bzr

MotionTable.cpp 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Bael'Zharon's Respite
  3. * Copyright (C) 2014 Daniel Skorupski
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include "resource/MotionTable.h"
  19. #include "BinReader.h"
  20. enum class CombatStyle : uint32_t
  21. {
  22. kUndef = 0x0000,
  23. kUnarmed = 0x0001,
  24. kOneHanded = 0x0002,
  25. kOneHandedAndShield = 0x0004,
  26. kTwoHanded = 0x0008,
  27. kBow = 0x0010,
  28. kCrossbow = 0x0020,
  29. kSling = 0x0040,
  30. kThrownWeapon = 0x0080,
  31. kDualWield = 0x0100,
  32. kMagic = 0x0200,
  33. kAtlatl = 0x0400,
  34. kThrownShield = 0x0800,
  35. kReserved1 = 0x1000,
  36. kReserved2 = 0x2000,
  37. kReserved3 = 0x4000,
  38. kReserved4 = 0x8000,
  39. kStubbornMagic = 0x00010000,
  40. kStubbornProjectile = 0x00020000,
  41. kStubbornMelee = 0x00040000,
  42. kStubbornMissile = 0x00080000,
  43. kAllMelee = 0x010f,
  44. kAllMissile = 0x0cf0,
  45. kAllMagic = 0x0200,
  46. kAll = 0xffff,
  47. };
  48. MotionTable::MotionTable(uint32_t id, const void* data, size_t size) : ResourceImpl{id}
  49. {
  50. BinReader reader(data, size);
  51. uint32_t resourceId = reader.readInt();
  52. assert(resourceId == id);
  53. UNUSED(resourceId);
  54. /*defaultStyle*/ reader.readInt();
  55. uint32_t numStyles = reader.readInt();
  56. for(uint32_t i = 0; i < numStyles; i++)
  57. {
  58. reader.readInt();
  59. reader.readInt();
  60. }
  61. uint32_t numCycles = reader.readInt();
  62. cycles.reserve(numCycles);
  63. for(uint32_t i = 0; i < numCycles; i++)
  64. {
  65. uint32_t key = reader.readInt();
  66. assert(cycles.find(key) == cycles.end());
  67. read(reader, cycles[key]);
  68. }
  69. uint32_t numModifiers = reader.readInt();
  70. modifiers.reserve(numModifiers);
  71. for(uint32_t i = 0; i < numModifiers; i++)
  72. {
  73. uint32_t key = reader.readInt();
  74. assert(modifiers.find(key) == modifiers.end());
  75. read(reader, modifiers[key]);
  76. }
  77. uint32_t numLinks = reader.readInt();
  78. links.reserve(numLinks);
  79. for(uint32_t i = 0; i < numLinks; i++)
  80. {
  81. uint32_t outerKey = reader.readInt();
  82. assert(links.find(outerKey) == links.end());
  83. auto& innerLinks = links[outerKey];
  84. uint32_t numInnerLinks = reader.readInt();
  85. innerLinks.reserve(numInnerLinks);
  86. for(uint32_t j = 0; j < numInnerLinks; j++)
  87. {
  88. uint32_t innerKey = reader.readInt();
  89. assert(innerLinks.find(innerKey) == innerLinks.end());
  90. read(reader, innerLinks[innerKey]);
  91. }
  92. }
  93. assert(reader.remaining() == 0);
  94. }