Clone of UAS2 @ https://github.com/drudgedance/uas2

cSpell.cpp 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * This file is part of UAS2.
  3. *
  4. * UAS2 is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * UAS2 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. * You should have received a copy of the GNU General Public License
  14. * along with UASv1; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /**
  18. * @file cSpell.cpp
  19. * Implements the cSpells class.
  20. */
  21. #include "cSpell.h"
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char THIS_FILE[]=__FILE__;
  25. #define new DEBUG_NEW
  26. #endif
  27. cSpell *cSpell::m_lpcHashTable[3000];
  28. cSpellComp *cSpellComp::m_lpcHashTable[200];
  29. /**
  30. * Erases all spells from the spell hash list.
  31. */
  32. void cSpell::Hash_Erase()
  33. {
  34. cSpell *pcSpell, *pcPrevSpell;
  35. for ( int i = 0; i < 3000; ++i )
  36. {
  37. pcSpell = m_lpcHashTable[i];
  38. while ( pcSpell )
  39. {
  40. pcPrevSpell = pcSpell;
  41. pcSpell = pcSpell->m_pcNext;
  42. Hash_Remove( pcPrevSpell );
  43. }
  44. }
  45. }
  46. /**
  47. * Removes a spell from the spell hash list.
  48. *
  49. * @param *pcSpell - A pointer to the spell to be removed.
  50. */
  51. void cSpell::Hash_Remove( cSpell *pcSpell )
  52. {
  53. SAFEDELETE( pcSpell )
  54. }
  55. /**
  56. * Finds a spell.
  57. *
  58. * This function is called when a particular spell needs to be found.
  59. * The search is performed by searching for the spell's spell ID.
  60. *
  61. * @param dwSpellID - The spell's spell ID.
  62. *
  63. * @return *cSpell - A pointer to the spell.
  64. */
  65. cSpell *cSpell::FindSpell( DWORD dwSpellID )
  66. {
  67. cSpell *pcSpell;
  68. for ( int i = 0; i < 3000; ++i )
  69. {
  70. pcSpell = m_lpcHashTable[i];
  71. while ( pcSpell )
  72. {
  73. if ( pcSpell->m_dwSpellID )
  74. {
  75. if ( dwSpellID == pcSpell->m_dwSpellID )
  76. return pcSpell;
  77. }
  78. pcSpell = pcSpell->m_pcNext;
  79. }
  80. }
  81. return NULL;
  82. }
  83. BYTE cSpell::GetWindup( )
  84. {
  85. cSpellComp *pcComp = cSpellComp::FindComp( m_dwLevel );
  86. if (!pcComp)
  87. return 0x70;
  88. return pcComp->m_dwAnimID & 0xFF;
  89. }
  90. int cSpell::GetWindupDelay( )
  91. {
  92. cSpellComp *pcComp = cSpellComp::FindComp( m_dwLevel );
  93. if (!pcComp)
  94. return 10;
  95. return pcComp->m_flChargeID * 10 - pcComp->m_flChargeID + 1;
  96. }
  97. BYTE cSpell::GetCastAnim( )
  98. {
  99. int iComp;
  100. if (m_dwComponents[5] == 0)
  101. {
  102. iComp = m_dwComponents[4] - m_dwComponents[0] + 1;
  103. cSpellComp *pcComp = cSpellComp::FindComp( iComp );
  104. return pcComp->m_dwAnimID & 0xFF;
  105. }
  106. else if (m_dwComponents[6] == 0)
  107. {
  108. iComp = m_dwComponents[5] - m_dwComponents[0] + 2;
  109. cSpellComp *pcComp = cSpellComp::FindComp( iComp );
  110. return pcComp->m_dwAnimID & 0xFF;
  111. }
  112. else if (m_dwComponents[7] == 0)
  113. {
  114. if (m_dwLevel != 0)
  115. {
  116. iComp = m_dwComponents[6] - m_dwComponents[0] + m_dwLevel;
  117. cSpellComp *pcComp = cSpellComp::FindComp( iComp );
  118. return pcComp->m_dwAnimID & 0xFF;
  119. }
  120. }
  121. else
  122. {
  123. if (m_dwLevel != 0)
  124. {
  125. iComp = m_dwComponents[7] - m_dwComponents[0] + m_dwLevel;
  126. cSpellComp *pcComp = cSpellComp::FindComp( iComp );
  127. return pcComp->m_dwAnimID & 0xFF;
  128. }
  129. }
  130. return 0x33;
  131. }
  132. int cSpell::GetCastAnimDelay( )
  133. {
  134. int iComp;
  135. if (m_dwComponents[5] == 0)
  136. {
  137. iComp = m_dwComponents[4] - m_dwComponents[0] + 1;
  138. cSpellComp *pcComp = cSpellComp::FindComp( iComp );
  139. return pcComp->m_flChargeID * 10;
  140. }
  141. else if (m_dwComponents[6] == 0)
  142. {
  143. iComp = m_dwComponents[5] - m_dwComponents[0] + 2;
  144. cSpellComp *pcComp = cSpellComp::FindComp( iComp );
  145. return pcComp->m_flChargeID * 10;
  146. }
  147. else if (m_dwComponents[7] == 0)
  148. {
  149. if (m_dwLevel != 0)
  150. {
  151. iComp = m_dwComponents[6] - m_dwComponents[0] + m_dwLevel;
  152. cSpellComp *pcComp = cSpellComp::FindComp( iComp );
  153. return pcComp->m_flChargeID * 10;
  154. }
  155. }
  156. else
  157. {
  158. if (m_dwLevel != 0)
  159. {
  160. iComp = m_dwComponents[7] - m_dwComponents[0] + m_dwLevel;
  161. cSpellComp *pcComp = cSpellComp::FindComp( iComp );
  162. return pcComp->m_flChargeID * 10;
  163. }
  164. }
  165. return 20;
  166. }
  167. cMessage cSpell::GetCastWords( )
  168. {
  169. cMessage cmSpellWords;
  170. char szWords[14];
  171. cSpellComp *pcComp1, *pcComp2, *pcComp3;
  172. int iComp;
  173. static BYTE bSpellWords[] = {
  174. 0x37, 0x00, 0x00, 0x00,
  175. 0x0E, 0x00, 0x5A, 0x6F,
  176. 0x6A, 0x61, 0x6B, 0x20,
  177. 0x51, 0x75, 0x61, 0x66,
  178. 0x65, 0x74, 0x68, 0x00,
  179. };
  180. if (m_dwLevel != 0)
  181. {
  182. if (m_dwComponents[5] == 0)
  183. {
  184. iComp = m_dwComponents[1] - m_dwComponents[0] + 1;
  185. pcComp1 = cSpellComp::FindComp( iComp );
  186. iComp = m_dwComponents[2] - m_dwComponents[0] + 1;
  187. pcComp2 = cSpellComp::FindComp( iComp );
  188. iComp = m_dwComponents[3] - m_dwComponents[0] + 1;
  189. pcComp3 = cSpellComp::FindComp( iComp );
  190. }
  191. else if (m_dwComponents[6] == 0)
  192. {
  193. iComp = m_dwComponents[2] - m_dwComponents[0] + 2;
  194. pcComp1 = cSpellComp::FindComp( iComp );
  195. iComp = m_dwComponents[3] - m_dwComponents[0] + 2;
  196. pcComp2 = cSpellComp::FindComp( iComp );
  197. iComp = m_dwComponents[4] - m_dwComponents[0] + 2;
  198. pcComp3 = cSpellComp::FindComp( iComp );
  199. }
  200. else
  201. {
  202. if (m_dwLevel != 0)
  203. {
  204. iComp = m_dwComponents[2] - m_dwComponents[0] + m_dwLevel;
  205. pcComp1 = cSpellComp::FindComp( iComp );
  206. iComp = m_dwComponents[4] - m_dwComponents[0] + m_dwLevel;
  207. pcComp2 = cSpellComp::FindComp( iComp );
  208. iComp = m_dwComponents[5] - m_dwComponents[0] + m_dwLevel;
  209. pcComp3 = cSpellComp::FindComp( iComp );
  210. }
  211. }
  212. wsprintf( szWords, "%s %s%s", pcComp1->m_strWords.c_str(), pcComp2->m_strWords.c_str(), pcComp3->m_strWords.c_str() );
  213. CopyMemory( &bSpellWords[6], &szWords, 14 );
  214. }
  215. cmSpellWords.pasteData(bSpellWords,20);
  216. return cmSpellWords;
  217. }
  218. void cSpellComp::Hash_Erase()
  219. {
  220. cSpellComp *pcComp, *pcPrevComp;
  221. for ( int i = 0; i < 200; ++i )
  222. {
  223. pcComp = m_lpcHashTable[i];
  224. while ( pcComp )
  225. {
  226. pcPrevComp = pcComp;
  227. pcComp = pcComp->m_pcNext;
  228. Hash_Remove( pcPrevComp );
  229. }
  230. }
  231. }
  232. void cSpellComp::Hash_Remove( cSpellComp *pcComp )
  233. {
  234. SAFEDELETE( pcComp )
  235. }
  236. cSpellComp *cSpellComp::FindComp( DWORD dwCompID )
  237. {
  238. cSpellComp *pcComp;
  239. for ( int i = 0; i < 200; ++i )
  240. {
  241. pcComp = m_lpcHashTable[i];
  242. while ( pcComp )
  243. {
  244. if ( pcComp->m_dwCompID )
  245. {
  246. if ( dwCompID == pcComp->m_dwCompID )
  247. return pcComp;
  248. }
  249. pcComp = pcComp->m_pcNext;
  250. }
  251. }
  252. return NULL;
  253. }