OUNITATB.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. /*
  2. * Seven Kingdoms: Ancient Adversaries
  3. *
  4. * Copyright 1997,1998 Enlight Software Ltd.
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. //Filename : OUNITAAT.CPP
  21. //Description : Object UnitArray - table for attacking
  22. #include <OUNIT.h>
  23. #ifdef NO_DEBUG_UNIT
  24. #undef err_when
  25. #undef err_here
  26. #undef err_if
  27. #undef err_else
  28. #undef err_now
  29. #define err_when(cond)
  30. #define err_here()
  31. #define err_if(cond)
  32. #define err_else
  33. #define err_now(msg)
  34. #undef DEBUG
  35. #endif
  36. //------------------------------------------------------------------------------//
  37. // the codes in this file is used to return a pair of offset. Adding the offsets
  38. // with a target location, the attacker can find a suitable space to attack the
  39. // target.
  40. //------------------------------------------------------------------------------//
  41. static char attack_x_offset11[ATTACK_DIR][8] // target size 1x1
  42. = { { -1, -1, -1, 0, 0, 1, 1, 1},
  43. { -1, 0, -1, 1, -1, 1, 0, 1},
  44. { 0, 1, -1, 1, -1, 1, -1, 0},
  45. { 1, 1, 0, 1, -1, 0, -1, -1},
  46. { 1, 1, 1, 0, 0, -1, -1, -1},
  47. { 1, 0, 1, -1, 1, -1, 0, -1},
  48. { 0, -1, 1, -1, 1, -1, 1, 0},
  49. { -1, -1, 0, -1, 1, 0, 1, 1}};
  50. static char attack_x_offset12[ATTACK_DIR][10] // target size 1x2
  51. = { { -1, -1, -1, -1, 0, 0, 1, 1, 1, 1},
  52. { -1, -1, 0, -1, 1, -1, 1, 0, 1, 1},
  53. { 0, 1, -1, 1, -1, 1, -1, 1, -1, 0},
  54. { 1, 1, 0, 1, -1, 1, -1, 0, -1, -1},
  55. { 1, 1, 1, 1, 0, 0, -1, -1, -1, -1},
  56. { 1, 1, 0, 1, -1, 1, -1, 0, -1, -1},
  57. { 0, -1, 1, -1, 1, -1, 1, -1, 1, 0},
  58. { -1, -1, 0, -1, 1, -1, 1, 0, 1, 1}};
  59. static char attack_x_offset13[ATTACK_DIR][12] // target size 1x3
  60. = { { -1, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 1},
  61. { -1, -1, 0, -1, 1, -1, 1, -1, 1, 0, 1, 1},
  62. { 0, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 0},
  63. { 1, 1, 0, 1, -1, 1, -1, 1, -1, 0, -1, -1},
  64. { 1, 1, 1, 1, 1, 0, 0, -1, -1, -1, -1, -1},
  65. { 1, 1, 0, 1, -1, 1, -1, 1, -1, 0, -1, -1},
  66. { 0, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0},
  67. { -1, -1, 0, -1, 1, -1, 1, -1, 1, 0, 1, 1}};
  68. static char attack_x_offset14[ATTACK_DIR][14] // target size 1x4
  69. = { { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 1, 1},
  70. { -1, -1, 0, -1, 1, -1, 1, -1, 1, -1, 1, 0, 1, 1},
  71. { 0, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 0},
  72. { 1, 1, 0, 1, -1, 1, -1, 1, -1, 1, -1, 0, -1, -1},
  73. { 1, 1, 1, 1, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
  74. { 1, 1, 0, 1, -1, 1, -1, 1, -1, 1, -1, 0, -1, -1},
  75. { 0, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0},
  76. { -1, -1, 0, -1, 1, -1, 1, -1, 1, -1, 1, 0, 1, 1}};
  77. static char attack_x_offset21[ATTACK_DIR][10] // target size 2x1
  78. = { { -1, -1, -1, 0, 0, 1, 1, 2, 2, 2},
  79. { -1, 0, -1, 1, -1, 2, 0, 2, 1, 2},
  80. { 0, 1, -1, 2, -1, 2, -1, 2, 0, 1},
  81. { 2, 1, 2, 0, 2, -1, 1, -1, 0, -1},
  82. { 2, 2, 2, 1, 1, 0, 0, -1, -1, -1},
  83. { 2, 1, 2, 0, 2, -1, 1, -1, 0, -1},
  84. { 0, 1, -1, 2, -1, 2, -1, 2, 0, 1},
  85. { -1, 0, -1, 1, -1, 2, 0, 2, 1, 2}};
  86. static char attack_x_offset22[ATTACK_DIR][12] // target size 2x2
  87. = { { -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2},
  88. { -1, 0, -1, 1, -1, 2, -1, 2, 0, 2, 1, 2},
  89. { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
  90. { 2, 2, 1, 2, 0, 2, -1, 1, -1, 0, -1, -1},
  91. { 2, 2, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1},
  92. { 2, 1, 2, 0, 2, -1, 2, -1, 1, -1, 0, -1},
  93. { 1, 0, 2, -1, 2, -1, 2, -1, 2, -1, 1, 0},
  94. { -1, -1, 0, -1, 1, -1, 2, 0, 2, 1, 2, 2}};
  95. static char attack_x_offset23[ATTACK_DIR][14] // target size 2x3
  96. = { { -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2, 2},
  97. { -1, -1, 0, -1, 1, -1, 2, -1, 2, 0, 2, 1, 2, 2},
  98. { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
  99. { 2, 2, 1, 2, 0, 2, -1, 2, -1, 1, -1, 0, -1, -1},
  100. { 2, 2, 2, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1},
  101. { 2, 2, 1, 2, 0, 2, -1, 2, -1, 1, -1, 0, -1, -1},
  102. { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
  103. { -1, -1, 0, -1, 1, -1, 2, -1, 2, 0, 2, 1, 2, 2}};
  104. static char attack_x_offset24[ATTACK_DIR][16] // target size 2x4
  105. = { { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2, 2, 2},
  106. { -1, -1, 0, -1, 1, -1, 2, -1, 2, -1, 2, 0, 2, 1, 2, 2},
  107. { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
  108. { 2, 2, 1, 2, 0, 2, -1, 2, -1, 2, -1, 1, -1, 0, -1, -1},
  109. { 2, 2, 2, 2, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
  110. { 2, 2, 1, 2, 0, 2, -1, 2, -1, 2, -1, 1, -1, 0, -1, -1},
  111. { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
  112. { -1, -1, 0, -1, 1, -1, 2, -1, 2, -1, 2, 0, 2, 1, 2, 2}};
  113. static char attack_x_offset31[ATTACK_DIR][12] // target size 3x1
  114. = { { -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3},
  115. { -1, 0, -1, 1, -1, 2, 0, 3, 1, 3, 2, 3},
  116. { 1, 2, 0, 3, -1, 3, -1, 3, -1, 2, 0, 1},
  117. { 3, 2, 3, 1, 3, 0, 2, -1, 1, -1, 0, -1},
  118. { 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1},
  119. { 3, 2, 3, 1, 3, 0, 2, -1, 1, -1, 0, -1},
  120. { 1, 0, 2, -1, 3, -1, 3, -1, 3, 0, 2, 1},
  121. { -1, 0, -1, 1, -1, 2, 0, 3, 1, 3, 2, 3}};
  122. static char attack_x_offset32[ATTACK_DIR][14] // target size 3x2
  123. = { { -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3},
  124. { -1, 0, -1, 1, -1, 2, -1, 3, 0, 3, 1, 3, 2, 3},
  125. { 1, 2, 0, 3, -1, 3, -1, 3, -1, 3, -1, 2, 0, 1},
  126. { 3, 2, 3, 1, 3, 0, 3, -1, 2, -1, 1, -1, 0, -1},
  127. { 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1},
  128. { 3, 2, 3, 1, 3, 0, 3, -1, 2, -1, 1, -1, 0, -1},
  129. { 1, 0, 2, -1, 3, -1, 3, -1, 3, -1, 3, 0, 2, 1},
  130. { -1, 0, -1, 1, -1, 2, -1, 3, 0, 3, 1, 3, 2, 3}};
  131. static char attack_x_offset33[ATTACK_DIR][16] // target size 3x3
  132. = { { -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3},
  133. { -1, 0, -1, 1, -1, 2, -1, 3, -1, 3, 0, 3, 1, 3, 2, 3},
  134. { 1, 2, 0, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 2, 0, 1},
  135. { 3, 3, 2, 3, 1, 3, 0, 3, -1, 2, -1, 1, -1, 0, -1, -1},
  136. { 3, 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1},
  137. { 3, 2, 3, 1, 3, 0, 3, -1, 3, -1, 2, -1, 1, -1, 0, -1},
  138. { 1, 0, 2, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, 0, 2, 1},
  139. { -1, -1, 0, -1, 1, -1, 2, -1, 3, 0, 3, 1, 3, 2, 3, 3}};
  140. static char attack_x_offset34[ATTACK_DIR][18] // target size 3x4
  141. = { { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3},
  142. { -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 3, 0, 3, 1, 3, 2, 3, 3},
  143. { 1, 2, 0, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 2, 0, 1},
  144. { 3, 3, 2, 3, 1, 3, 0, 3, -1, 3, -1, 2, -1, 1, -1, 0, -1, -1},
  145. { 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
  146. { 3, 3, 2, 3, 1, 3, 0, 3, -1, 3, -1, 2, -1, 1, -1, 0, -1, -1},
  147. { 1, 0, 2, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, 0, 2, 1},
  148. { -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 3, 0, 3, 1, 3, 2, 3, 3}};
  149. static char attack_x_offset41[ATTACK_DIR][14] // target size 4x1
  150. = { { -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4},
  151. { -1, 0, -1, 1, -1, 2, 0, 3, 1, 4, 2, 4, 3, 4},
  152. { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
  153. { 4, 3, 4, 2, 4, 1, 3, 0, 2, -1, 1, -1, 0, -1},
  154. { 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1},
  155. { 4, 3, 4, 2, 4, 1, 3, 0, 2, -1, 1, -1, 0, -1},
  156. { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
  157. { -1, 0, -1, 1, -1, 2, 0, 3, 1, 4, 2, 4, 3, 4}};
  158. static char attack_x_offset42[ATTACK_DIR][16] // target size 4x2
  159. = { { -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4},
  160. { -1, 0, -1, 1, -1, 2, -1, 3, 0, 4, 1, 4, 2, 4, 3, 4},
  161. { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
  162. { 4, 3, 4, 2, 4, 1, 4, 0, 3, -1, 2, -1, 1, -1, 0, -1},
  163. { 4, 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1},
  164. { 4, 3, 4, 2, 4, 1, 4, 0, 3, -1, 2, -1, 1, -1, 0, -1},
  165. { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
  166. { -1, 0, -1, 1, -1, 2, -1, 3, 0, 4, 1, 4, 2, 4, 3, 4}};
  167. static char attack_x_offset43[ATTACK_DIR][18] // target size 4x3
  168. = { { -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4},
  169. { -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4},
  170. { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
  171. { 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1},
  172. { 4, 4, 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1},
  173. { 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1},
  174. { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
  175. { -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4}};
  176. static char attack_x_offset44[ATTACK_DIR][20] // target size 4x4
  177. = { { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4},
  178. { -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4},
  179. { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
  180. { 4, 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1, -1},
  181. { 4, 4, 4, 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
  182. { 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1},
  183. { 2, 1, 3, 0, 4, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, -1, 3, 0, 2, 1},
  184. { -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4, 4}};
  185. static char attack_y_offset11[ATTACK_DIR][8] // target size 1x1
  186. = { { 0, 1, -1, 1, -1, 1, -1, 0},
  187. { 1, 1, 0, 1, -1, 0, -1, -1},
  188. { 1, 1, 1, 0, 0, -1, -1, -1},
  189. { 1, 0, 1, -1, 1, -1, 0, -1},
  190. { 0, -1, 1, -1, 1, -1, 1, 0},
  191. { -1, -1, 0, -1, 1, 0, 1, 1},
  192. { -1, -1, -1, 0, 0, 1, 1, 1},
  193. { -1, 0, -1, 1, -1, 1, 0, 1}};
  194. static char attack_y_offset12[ATTACK_DIR][10] // target size 1x2
  195. = { { 0, 1, -1, 2, -1, 2, -1, 2, 0, 1},
  196. { 2, 1, 2, 0, 2, -1, 1, -1, 0, -1},
  197. { 2, 2, 2, 1, 1, 0, 0, -1, -1, -1},
  198. { 2, 1, 2, 0, 2, -1, 1, -1, 0, -1},
  199. { 0, 1, -1, 2, -1, 2, -1, 2, 0, 1},
  200. { -1, 0, -1, 1, -1, 2, 0, 2, 1, 2},
  201. { -1, -1, -1, 0, 0, 1, 1, 2, 2, 2},
  202. { -1, 0, -1, 1, -1, 2, 0, 2, 1, 2}};
  203. static char attack_y_offset13[ATTACK_DIR][12] // target size 1x3
  204. = { { 1, 2, 0, 3, -1, 3, -1, 3, -1, 2, 0, 1},
  205. { 3, 2, 3, 1, 3, 0, 2, -1, 1, -1, 0, -1},
  206. { 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1},
  207. { 3, 2, 3, 1, 3, 0, 2, -1, 1, -1, 0, -1},
  208. { 1, 0, 2, -1, 3, -1, 3, -1, 3, 0, 2, 1},
  209. { -1, 0, -1, 1, -1, 2, 0, 3, 1, 3, 2, 3},
  210. { -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3},
  211. { -1, 0, -1, 1, -1, 2, 0, 3, 1, 3, 2, 3}};
  212. static char attack_y_offset14[ATTACK_DIR][14] // target size 1x4
  213. = { { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
  214. { 4, 3, 4, 2, 4, 1, 3, 0, 2, -1, 1, -1, 0, -1},
  215. { 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1},
  216. { 4, 3, 4, 2, 4, 1, 3, 0, 2, -1, 1, -1, 0, -1},
  217. { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
  218. { -1, 0, -1, 1, -1, 2, 0, 3, 1, 4, 2, 4, 3, 4},
  219. { -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4},
  220. { -1, 0, -1, 1, -1, 2, 0, 3, 1, 4, 2, 4, 3, 4}};
  221. static char attack_y_offset21[ATTACK_DIR][10] // target size 2x1
  222. = { { 0, 1, -1, 1, -1, 1, -1, 1, -1, 0},
  223. { 1, 1, 0, 1, -1, 1, -1, 0, -1, -1},
  224. { 1, 1, 1, 1, 0, 0, -1, -1, -1, -1},
  225. { 1, 1, 0, 1, -1, 1, -1, 0, -1, -1},
  226. { 0, -1, 1, -1, 1, -1, 1, -1, 1, 0},
  227. { -1, -1, 0, -1, 1, -1, 1, 0, 1, 1},
  228. { -1, -1, -1, -1, 0, 0, 1, 1, 1, 1},
  229. { -1, -1, 0, -1, 1, -1, 1, 0, 1, 1}};
  230. static char attack_y_offset22[ATTACK_DIR][12] // target size 2x2
  231. = { { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
  232. { 2, 2, 1, 2, 0, 2, -1, 1, -1, 0, -1, -1},
  233. { 2, 2, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1},
  234. { 2, 1, 2, 0, 2, -1, 2, -1, 1, -1, 0, -1},
  235. { 1, 0, 2, -1, 2, -1, 2, -1, 2, -1, 1, 0},
  236. { -1, -1, 0, -1, 1, -1, 2, 0, 2, 1, 2, 2},
  237. { -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2},
  238. { -1, 0, -1, 1, -1, 2, -1, 2, 0, 2, 1, 2}};
  239. static char attack_y_offset23[ATTACK_DIR][14] // target size 2x3
  240. = { { 1, 2, 0, 3, -1, 3, -1, 3, -1, 3, -1, 2, 0, 1},
  241. { 3, 2, 3, 1, 3, 0, 3, -1, 2, -1, 1, -1, 0, -1},
  242. { 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1},
  243. { 3, 2, 3, 1, 3, 0, 3, -1, 2, -1, 1, -1, 0, -1},
  244. { 1, 0, 2, -1, 3, -1, 3, -1, 3, -1, 3, 0, 2, 1},
  245. { -1, 0, -1, 1, -1, 2, -1, 3, 0, 3, 1, 3, 2, 3},
  246. { -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3},
  247. { -1, 0, -1, 1, -1, 2, -1, 3, 0, 3, 1, 3, 2, 3}};
  248. static char attack_y_offset24[ATTACK_DIR][16] // target size 2x4
  249. = { { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
  250. { 4, 3, 4, 2, 4, 1, 4, 0, 3, -1, 2, -1, 1, -1, 0, -1},
  251. { 4, 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1},
  252. { 4, 3, 4, 2, 4, 1, 4, 0, 3, -1, 2, -1, 1, -1, 0, -1},
  253. { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
  254. { -1, 0, -1, 1, -1, 2, -1, 3, 0, 4, 1, 4, 2, 4, 3, 4},
  255. { -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4},
  256. { -1, 0, -1, 1, -1, 2, -1, 3, 0, 4, 1, 4, 2, 4, 3, 4}};
  257. static char attack_y_offset31[ATTACK_DIR][12] // target size 3x1
  258. = { { 0, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 0},
  259. { 1, 1, 0, 1, -1, 1, -1, 1, -1, 0, -1, -1},
  260. { 1, 1, 1, 1, 1, 0, 0, -1, -1, -1, -1, -1},
  261. { 1, 1, 0, 1, -1, 1, -1, 1, -1, 0, -1, -1},
  262. { 0, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0},
  263. { -1, -1, 0, -1, 1, -1, 1, -1, 1, 0, 1, 1},
  264. { -1, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 1},
  265. { -1, -1, 0, -1, 1, -1, 1, -1, 1, 0, 1, 1}};
  266. static char attack_y_offset32[ATTACK_DIR][14] // target size 3x2
  267. = { { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
  268. { 2, 2, 1, 2, 0, 2, -1, 2, -1, 1, -1, 0, -1, -1},
  269. { 2, 2, 2, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1},
  270. { 2, 2, 1, 2, 0, 2, -1, 2, -1, 1, -1, 0, -1, -1},
  271. { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
  272. { -1, -1, 0, -1, 1, -1, 2, -1, 2, 0, 2, 1, 2, 2},
  273. { -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2, 2},
  274. { -1, -1, 0, -1, 1, -1, 2, -1, 2, 0, 2, 1, 2, 2}};
  275. static char attack_y_offset33[ATTACK_DIR][16] // target size 3x3
  276. = { { 1, 2, 0, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 2, 0, 1},
  277. { 3, 3, 2, 3, 1, 3, 0, 3, -1, 2, -1, 1, -1, 0, -1, -1},
  278. { 3, 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1},
  279. { 3, 2, 3, 1, 3, 0, 3, -1, 3, -1, 2, -1, 1, -1, 0, -1},
  280. { 1, 0, 2, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, 0, 2, 1},
  281. { -1, -1, 0, -1, 1, -1, 2, -1, 3, 0, 3, 1, 3, 2, 3, 3},
  282. { -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3},
  283. { -1, 0, -1, 1, -1, 2, -1, 3, -1, 3, 0, 3, 1, 3, 2, 3}};
  284. static char attack_y_offset34[ATTACK_DIR][18] // target size 3x4
  285. = { { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
  286. { 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1},
  287. { 4, 4, 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1},
  288. { 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1},
  289. { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
  290. { -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4},
  291. { -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4},
  292. { -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4}};
  293. static char attack_y_offset41[ATTACK_DIR][14] // target size 4x1
  294. = { { 0, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 0},
  295. { 1, 1, 0, 1, -1, 1, -1, 1, -1, 1, -1, 0, -1, -1},
  296. { 1, 1, 1, 1, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
  297. { 1, 1, 0, 1, -1, 1, -1, 1, -1, 1, -1, 0, -1, -1},
  298. { 0, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0},
  299. { -1, -1, 0, -1, 1, -1, 1, -1, 1, -1, 1, 0, 1, -1},
  300. { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 1, 1},
  301. { -1, -1, 0, -1, 1, -1, 1, -1, 1, -1, 1, 0, 1, 1}};
  302. static char attack_y_offset42[ATTACK_DIR][16] // target size 4x2
  303. = { { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
  304. { 2, 2, 1, 2, 0, 2, -1, 2, -1, 2, -1, 1, -1, 0, -1, -1},
  305. { 2, 2, 2, 2, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
  306. { 2, 2, 1, 2, 0, 2, -1, 2, -1, 2, -1, 1, -1, 0, -1, -1},
  307. { 0, 1, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, -1, 2, 0, 1},
  308. { -1, -1, 0, -1, 1, -1, 2, -1, 2, -1, 2, 0, 2, 1, 2, 2},
  309. { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 2, 2, 2, 2},
  310. { -1, -1, 0, -1, 1, -1, 2, -1, 2, -1, 2, 0, 2, 1, 2, 2}};
  311. static char attack_y_offset43[ATTACK_DIR][18] // target size 4x3
  312. = { { 1, 2, 0, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 2, 0, 1},
  313. { 3, 3, 2, 3, 1, 3, 0, 3, -1, 3, -1, 2, -1, 1, -1, 0, -1, -1},
  314. { 3, 3, 3, 3, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
  315. { 3, 3, 2, 3, 1, 3, 0, 3, -1, 3, -1, 2, -1, 1, -1, 0, -1, -1},
  316. { 1, 0, 2, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, -1, 3, 0, 2, 1},
  317. { -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 3, 0, 3, 1, 3, 2, 3, 3},
  318. { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3},
  319. { -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 3, 0, 3, 1, 3, 2, 3, 3}};
  320. static char attack_y_offset44[ATTACK_DIR][20] // target size 4x4
  321. = { { 1, 2, 0, 3, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, 0, 3, 1, 2},
  322. { 4, 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1, -1},
  323. { 4, 4, 4, 4, 4, 4, 3, 3, 2, 2, 1, 1, 0, 0, -1, -1, -1, -1, -1, -1},
  324. { 4, 3, 4, 2, 4, 1, 4, 0, 4, -1, 4, -1, 3, -1, 2, -1, 1, -1, 0, -1},
  325. { 2, 1, 3, 0, 4, -1, 4, -1, 4, -1, 4, -1, 4, -1, 4, -1, 3, 0, 2, 1},
  326. { -1, -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4, 4},
  327. { -1, -1, -1, -1, -1, -1, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4},
  328. { -1, 0, -1, 1, -1, 2, -1, 3, -1, 4, -1, 4, 0, 4, 1, 4, 2, 4, 3, 4}};
  329. //--------- Begin of function UnitArray::get_target_x_offset ---------//
  330. // return x offset
  331. //
  332. // <int> targetWidth - width of the target
  333. // <int> targetHeight - height of the target
  334. // <char> curDir - the direction of attacker to the target
  335. //
  336. char* UnitArray::get_target_x_offset(int targetWidth, int targetHeight, char curDir)
  337. {
  338. err_when(curDir<0 || curDir>ATTACK_DIR);
  339. int targetType = targetWidth*10 + targetHeight;
  340. switch(targetType)
  341. {
  342. case 11: return attack_x_offset11[curDir];
  343. case 12: return attack_x_offset12[curDir];
  344. case 13: return attack_x_offset13[curDir];
  345. case 14: return attack_x_offset14[curDir];
  346. case 21: return attack_x_offset21[curDir];
  347. case 22: return attack_x_offset22[curDir];
  348. case 23: return attack_x_offset23[curDir];
  349. case 24: return attack_x_offset24[curDir];
  350. case 31: return attack_x_offset31[curDir];
  351. case 32: return attack_x_offset32[curDir];
  352. case 33: return attack_x_offset33[curDir];
  353. case 34: return attack_x_offset34[curDir];
  354. case 41: return attack_x_offset41[curDir];
  355. case 42: return attack_x_offset42[curDir];
  356. case 43: return attack_x_offset43[curDir];
  357. case 44: return attack_x_offset44[curDir];
  358. }
  359. err_here();
  360. return NULL;
  361. }
  362. //----------- End of function UnitArray::get_target_x_offset -----------//
  363. //--------- Begin of function UnitArray::get_target_y_offset ---------//
  364. // return y offset
  365. //
  366. // <int> targetWidth - width of the target
  367. // <int> targetHeight - height of the target
  368. // <char> curDir - the direction of attacker to the target
  369. //
  370. char* UnitArray::get_target_y_offset(int targetWidth, int targetHeight, char curDir)
  371. {
  372. err_when(curDir<0 || curDir>ATTACK_DIR);
  373. int targetType = targetWidth*10 + targetHeight;
  374. switch(targetType)
  375. {
  376. case 11: return attack_y_offset11[curDir];
  377. case 12: return attack_y_offset12[curDir];
  378. case 13: return attack_y_offset13[curDir];
  379. case 14: return attack_y_offset14[curDir];
  380. case 21: return attack_y_offset21[curDir];
  381. case 22: return attack_y_offset22[curDir];
  382. case 23: return attack_y_offset23[curDir];
  383. case 24: return attack_y_offset24[curDir];
  384. case 31: return attack_y_offset31[curDir];
  385. case 32: return attack_y_offset32[curDir];
  386. case 33: return attack_y_offset33[curDir];
  387. case 34: return attack_y_offset34[curDir];
  388. case 41: return attack_y_offset41[curDir];
  389. case 42: return attack_y_offset42[curDir];
  390. case 43: return attack_y_offset43[curDir];
  391. case 44: return attack_y_offset44[curDir];
  392. }
  393. err_here();
  394. return NULL;
  395. }
  396. //----------- End of function UnitArray::get_target_y_offset -----------//