Formation.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /*
  2. * V-Gears
  3. * Copyright (C) 2022 V-Gears Team
  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 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <string>
  19. #include "common/TypeDefine.h"
  20. #include "data/GameData.h"
  21. /**
  22. * An enemy formation
  23. */
  24. struct Formation{
  25. /**
  26. * Battle layouts.
  27. */
  28. enum class Layout{
  29. /**
  30. * Normal fight.
  31. */
  32. NORMAL = 0,
  33. /**
  34. * Preemptive attack.
  35. *
  36. * Enemies are on their back, they bars are empty. When attacked, or
  37. * after a certain time, they turn and their bars start to fill.
  38. */
  39. PREEMPTIVE,
  40. /**
  41. * Back attack.
  42. *
  43. * Players are on their back, they bars are empty. When attacked, or
  44. * after a certain time, they turn and their bars start to fill.
  45. * Player rows are reversed.
  46. */
  47. BACK_ATTACK,
  48. /**
  49. * Side attack.
  50. *
  51. * Players in both sides, enemies in center, facing one or other
  52. * direction. Change command disabled.
  53. */
  54. SIDE_ATTACK,
  55. /**
  56. * Enemies in both sides, player in center, front row, facing one or the
  57. * other direction. Change command disabled. Unescapable until one of
  58. * the sides is cleared.
  59. */
  60. PINCER_ATTACK,
  61. /**
  62. * Locked position fight.
  63. *
  64. * Like a normal one, but all players in the front row. Change command
  65. * disabled.
  66. */
  67. LOCKED
  68. };
  69. /**
  70. * Each enemy in the formation.
  71. */
  72. struct Enemy{
  73. /**
  74. * Enemy ID.
  75. */
  76. unsigned int id;
  77. /**
  78. * Enemy X position.
  79. */
  80. int x;
  81. /**
  82. * Enemy Y position.
  83. */
  84. int y;
  85. /**
  86. * Enemy Z position.
  87. */
  88. int z;
  89. /**
  90. * Enemy row.
  91. */
  92. unsigned int row;
  93. /**
  94. * Cover flags.
  95. *
  96. * These flags are used in conjunction with row to determine if a target
  97. * can be selected as the target of a short-range attack. The
  98. * determination of this is worked out in this way: An enemy exists in
  99. * row 1 and another in row 2. If the enemy in row 1 shares a cover flag
  100. * with the enemy in row 2 then the enemy in row 2 cannot be targeted
  101. * until all enemies in row 1 that share a cover flag with the row 2
  102. * enemy are defeated. It works like this. Two active enemies exist, A
  103. * and B.
  104. *
  105. * If ((B's row > A's row) and (B's flags AND A's flags) > 0)
  106. * then enemy B cannot be targeted by short-range attacks.
  107. *
  108. * For any enemies A and B.
  109. *
  110. * Example:
  111. * Consider the Battery Cap x6 battle in the forest between Nibelheim
  112. * and Rocket Town. Their cover flags (in binary) are:
  113. *
  114. * Row 1: 00100
  115. * Row 2: 00110 01100
  116. * Row 3: 00011 00100 11000
  117. *
  118. * The battery caps in row 2 cannot be targeted by a short-range attack
  119. * until the one in row 1 has been defeated because they share the 0x4
  120. * cover flag. Once row 1 has been cleared:
  121. *
  122. * Row 2: 00110 01100
  123. * Row 3: 00011 00100 11000
  124. *
  125. * The battery cap on left in row 2 covers the left two in row 3 because
  126. * it shares flag 0x4 with the one in the middle and flag 0x2 with the
  127. * one on the far left. As long as it is active these in row 3 cannot be
  128. * targeted. Similarly, the battery cap on the right in row 2 shares the
  129. * 0x4 flag with the middle of row 3 and the 0x8 flag with the far right
  130. * of row 3 so these cannot be targeted until the right side of row 2 is
  131. * defeated. It is also necessary to note that because row 1 does not
  132. * share any flags with the extreme right and left of row 3, they can be
  133. * targeted if the corresponding enemy in row 2 is defeated even if the
  134. * row 1 enemy is still active. Also of note is that enemies in the same
  135. * row that share cover flags are not considered.
  136. */
  137. char cover[5];
  138. /**
  139. * Indicates if the enemy is initially visible.
  140. */
  141. bool visible;
  142. /**
  143. * Indicates initial direction facing if players get a side attack.
  144. */
  145. int direction;
  146. /**
  147. * Indicates if the enemy is targeteable.
  148. */
  149. bool targeteable;
  150. /**
  151. * @todo Understand and document.
  152. */
  153. bool main_script_active;
  154. /**
  155. * Constructor.
  156. *
  157. * Initializes to default values.
  158. */
  159. Enemy():
  160. id(0), x(0), y(0), z(0), row(0), visible(true),
  161. direction(0), targeteable(true), main_script_active(true)
  162. {
  163. for (int c = 0; c < 5; c ++) cover[c] = '0';
  164. }
  165. };
  166. /**
  167. * Position for a camera.
  168. */
  169. struct Camera{
  170. /**
  171. * X position.
  172. */
  173. int x;
  174. /**
  175. * Y position.
  176. */
  177. int y;
  178. /**
  179. * z position.
  180. */
  181. int z;
  182. /**
  183. * X direction.
  184. */
  185. int d_x;
  186. /**
  187. * Y direction.
  188. */
  189. int d_y;
  190. /**
  191. * z direction.
  192. */
  193. int d_z;
  194. /**
  195. * Constructor.
  196. *
  197. * Initializes to default values.
  198. */
  199. Camera(): x(0), y(0), z(0), d_x(0), d_y(0), d_z(0){}
  200. };
  201. /**
  202. * Formation ID.
  203. */
  204. unsigned int id;
  205. /**
  206. * When all enemies are defeated, begin battle with this ID without ending
  207. * battle scene.
  208. */
  209. int next_formation;
  210. /**
  211. * Difficulty to escape.
  212. */
  213. float escape_counter;
  214. /**
  215. * Indicates if the battle can be escaped.
  216. */
  217. bool escapable;
  218. /**
  219. * If true, the victory pose will be played after the battle.
  220. */
  221. bool skip_victory_pose;
  222. /**
  223. * If true, spoils (item, ap, money...) will not be obtained after the
  224. * battle.
  225. *
  226. * The spoil screens will not be displayed.
  227. */
  228. bool skip_spoils;
  229. /**
  230. * If false, this battle can never be preemtied.
  231. */
  232. bool preemptive_disabled;
  233. /**
  234. * Battle layout.
  235. */
  236. Layout layout;
  237. /**
  238. * The enemies in the formation.
  239. */
  240. std::vector<Enemy> enemies;
  241. /**
  242. * Location ID.
  243. *
  244. * Must be set, except for formations referenced by other formation's
  245. * {@see next_formation} or {@see next_arena_formation_candidates}. In those
  246. * cases, it can be -1.
  247. */
  248. int location;
  249. /**
  250. * Location name.
  251. *
  252. * Never used, it's to have descriptive XML files.
  253. */
  254. std::string location_name;
  255. /**
  256. * Camera positions.
  257. */
  258. std::vector<Camera> camera_positions;
  259. /**
  260. * Index of the initial camera position.
  261. */
  262. int initial_camera_position;
  263. /**
  264. * Indicates if the formation is an arena battle.
  265. */
  266. bool is_arena_battle;
  267. /**
  268. * For arena battles, candidates for the next formation.
  269. */
  270. std::vector<int> next_arena_formation_candidates;
  271. /**
  272. * Constructor.
  273. *
  274. * Initializes to default values.
  275. */
  276. Formation():
  277. id(0), next_formation(-1), escape_counter(0.0f), escapable(true), skip_victory_pose(false),
  278. skip_spoils(false), preemptive_disabled(false), layout(Layout::NORMAL), location(-1),
  279. location_name(""), initial_camera_position(0),is_arena_battle(false)
  280. {
  281. enemies.clear();
  282. camera_positions.clear();
  283. next_arena_formation_candidates.clear();
  284. }
  285. };