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

AnimationHook.cpp 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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/AnimationHook.h"
  19. #include "BinReader.h"
  20. #include "util.h"
  21. enum class AnimationHookType : uint32_t
  22. {
  23. kNoOp = 0x0000,
  24. kSound = 0x0001,
  25. kSoundTable = 0x0002,
  26. kAttack = 0x0003,
  27. kAnimDone = 0x0004,
  28. kReplaceObject = 0x0005,
  29. kEthereal = 0x0006,
  30. kTransparentPart = 0x0007,
  31. kLuminous = 0x0008,
  32. kLuminousPart = 0x0009,
  33. kDiffuse = 0x000a,
  34. kDiffusePart = 0x000b,
  35. kScale = 0x000c,
  36. kCreateParticle = 0x000d,
  37. kDestroyParticle = 0x000e,
  38. kStopParticle = 0x000f,
  39. kNoDraw = 0x0010,
  40. kDefaultScript = 0x0011,
  41. kDefaultScriptPart = 0x0012,
  42. kCallPES = 0x0013,
  43. kTransparent = 0x0014,
  44. kSoundTweaked = 0x0015,
  45. kSetOmega = 0x0016,
  46. kTextureVelocity = 0x0017,
  47. kTextureVelocityPart = 0x0018,
  48. kSetLight = 0x0019,
  49. kCreateBlockingParticle = 0x001a
  50. };
  51. void read(BinReader& reader, unique_ptr<AnimationHook>& hook)
  52. {
  53. AnimationHookType hookType = static_cast<AnimationHookType>(reader.readInt());
  54. // only apply this hook when playing this frame
  55. // 1 = forward, -1 = backward, 0 = both
  56. uint32_t hookDir = reader.readInt();
  57. assert(hookDir == 0 || hookDir == 1 || hookDir == 0xFFFFFFFF);
  58. switch(hookType)
  59. {
  60. case AnimationHookType::kSound:
  61. {
  62. SoundHook* h = new SoundHook();
  63. hook.reset(h);
  64. h->soundId = reader.readInt();
  65. }
  66. break;
  67. case AnimationHookType::kSoundTable:
  68. {
  69. SoundTableHook* h = new SoundTableHook();
  70. hook.reset(h);
  71. h->soundType = reader.readInt();
  72. }
  73. break;
  74. case AnimationHookType::kAttack:
  75. {
  76. AttackHook* h = new AttackHook();
  77. hook.reset(h);
  78. h->partIndex = reader.readInt();
  79. h->leftX = reader.readFloat();
  80. h->leftY = reader.readFloat();
  81. h->rightX = reader.readFloat();
  82. h->rightY = reader.readFloat();
  83. h->radius = reader.readFloat();
  84. h->height = reader.readFloat();
  85. }
  86. break;
  87. case AnimationHookType::kReplaceObject:
  88. {
  89. ReplaceObjectHook* h = new ReplaceObjectHook();
  90. hook.reset(h);
  91. h->partIndex = reader.readShort();
  92. h->partId = reader.readShort();
  93. }
  94. break;
  95. case AnimationHookType::kEthereal:
  96. {
  97. EtherealHook* h = new EtherealHook();
  98. hook.reset(h);
  99. h->ethereal = (reader.readInt() != 0);
  100. }
  101. break;
  102. case AnimationHookType::kTransparentPart:
  103. {
  104. TransparentPartHook* h = new TransparentPartHook();
  105. hook.reset(h);
  106. h->partIndex = reader.readInt();
  107. h->start = reader.readFloat();
  108. h->end = reader.readFloat();
  109. h->time = reader.readFloat();
  110. }
  111. break;
  112. case AnimationHookType::kScale:
  113. {
  114. ScaleHook* h = new ScaleHook();
  115. hook.reset(h);
  116. h->end = reader.readFloat();
  117. h->time = reader.readFloat();
  118. }
  119. break;
  120. case AnimationHookType::kCreateParticle:
  121. {
  122. CreateParticleHook* h = new CreateParticleHook();
  123. hook.reset(h);
  124. h->emitterInfoId = reader.readInt();
  125. h->partIndex = reader.readInt();
  126. read(reader, h->position);
  127. read(reader, h->rotation);
  128. h->emitterId = reader.readInt();
  129. }
  130. break;
  131. case AnimationHookType::kDestroyParticle:
  132. {
  133. DestroyParticleHook* h = new DestroyParticleHook();
  134. hook.reset(h);
  135. h->emitterId = reader.readInt();
  136. }
  137. break;
  138. case AnimationHookType::kStopParticle:
  139. {
  140. StopParticleHook* h = new StopParticleHook();
  141. hook.reset(h);
  142. h->emitterId = reader.readInt();
  143. }
  144. break;
  145. case AnimationHookType::kNoDraw:
  146. {
  147. NoDrawHook* h = new NoDrawHook();
  148. hook.reset(h);
  149. h->noDraw = (reader.readInt() != 0);
  150. }
  151. break;
  152. case AnimationHookType::kDefaultScript:
  153. {
  154. DefaultScriptHook* h = new DefaultScriptHook();
  155. hook.reset(h);
  156. }
  157. break;
  158. case AnimationHookType::kCallPES:
  159. {
  160. CallPESHook* h = new CallPESHook();
  161. hook.reset(h);
  162. h->pesId = reader.readInt();
  163. h->pause = reader.readFloat();
  164. }
  165. break;
  166. case AnimationHookType::kTransparent:
  167. {
  168. TransparentHook* h = new TransparentHook();
  169. hook.reset(h);
  170. h->start = reader.readFloat();
  171. h->end = reader.readFloat();
  172. h->time = reader.readFloat();
  173. }
  174. break;
  175. case AnimationHookType::kSoundTweaked:
  176. {
  177. SoundTweakedHook* h = new SoundTweakedHook();
  178. hook.reset(h);
  179. h->soundId = reader.readInt();
  180. h->priority = reader.readFloat();
  181. h->probability = reader.readFloat();
  182. h->volume = reader.readFloat();
  183. }
  184. break;
  185. case AnimationHookType::kSetOmega:
  186. {
  187. SetOmegaHook* h = new SetOmegaHook();
  188. hook.reset(h);
  189. read(reader, h->axis);
  190. }
  191. break;
  192. case AnimationHookType::kTextureVelocity:
  193. {
  194. TextureVelocityHook* h = new TextureVelocityHook();
  195. hook.reset(h);
  196. h->uSpeed = reader.readFloat();
  197. h->vSpeed = reader.readFloat();
  198. }
  199. break;
  200. case AnimationHookType::kSetLight:
  201. {
  202. SetLightHook* h = new SetLightHook();
  203. hook.reset(h);
  204. h->lightsOn = (reader.readInt() != 0);
  205. }
  206. break;
  207. case AnimationHookType::kCreateBlockingParticle:
  208. {
  209. CreateBlockingParticleHook* h = new CreateBlockingParticleHook();
  210. hook.reset(h);
  211. h->emitterInfoId = reader.readInt();
  212. h->partIndex = reader.readInt();
  213. read(reader, h->position);
  214. read(reader, h->rotation);
  215. h->emitterId = reader.readInt();
  216. }
  217. break;
  218. default:
  219. throw runtime_error("Unknown hookType in animation frame");
  220. }
  221. hook->hookDir = hookDir;
  222. }