Enemy.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears 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. #pragma once
  16. #include <tuple>
  17. #include <OgreString.h>
  18. #include "ScriptManager.h"
  19. /**
  20. * Any enemy in a battle.
  21. */
  22. class Enemy{
  23. public:
  24. struct Element{
  25. /**
  26. * The element ID.
  27. */
  28. unsigned int id;
  29. /**
  30. * Damage modification factor when attacked by the element.
  31. *
  32. * 1 means normal damage taken.
  33. * 0 means no damage taken.
  34. * [0-1] means reduced damage.
  35. * [1-10) means extended damage.
  36. * (-10-0) means recovery
  37. * >10 means death.
  38. * <-10 means full recovery.
  39. */
  40. float factor;
  41. };
  42. /**
  43. * Enemy attack data.
  44. */
  45. struct Attack{
  46. /**
  47. * Attack ID.
  48. */
  49. unsigned int id;
  50. /**
  51. * Camera ID to use during the attack.
  52. *
  53. * -1 to not move the camera.
  54. */
  55. int camera;
  56. };
  57. /**
  58. * Data for drop and steal items.
  59. */
  60. struct Item{
  61. /**
  62. * Item ID.
  63. */
  64. unsigned int id;
  65. /**
  66. * Steal or drop rate.
  67. */
  68. float rate;
  69. };
  70. /**
  71. * Status immunity.
  72. */
  73. struct Immunity{
  74. /**
  75. * Status ID.
  76. */
  77. unsigned int status;
  78. /**
  79. * Immunity rate.
  80. *
  81. * 0 or lower means no immunity, 1 or higher completely immune. Values between 0 and 1
  82. * indicate resistance.
  83. */
  84. float rate;
  85. };
  86. /**
  87. * Constructor.
  88. *
  89. * @param[in] id Enemy ID.
  90. */
  91. Enemy(const unsigned int id);
  92. /**
  93. * Constructor.
  94. *
  95. * @param[in] id Enemy ID.
  96. * @param[in] pos Enemy position (x, y, z).
  97. * @param[in] front True to set the enemy in the front row, false for back row.
  98. * @param[in] visible Indicates enemy visibility.
  99. * @param[in] targeteable Indicates if the enemy can be targeted.
  100. * @param[in] active Indicates whether the enemy main script is active or not.
  101. * @param[in] cover Cover binary flags string.
  102. */
  103. Enemy(
  104. const unsigned int id, const Ogre::Vector3 pos, const bool front, const bool visible,
  105. const bool targeteable, const bool active, const std::string cover
  106. );
  107. /**
  108. * Destructor.
  109. */
  110. virtual ~Enemy();
  111. /**
  112. * Retrieves the enemy ID.
  113. *
  114. * @return The enemy ID, or -1 if it's not loaded.
  115. */
  116. const int GetId() const;
  117. /**
  118. * Sets the enemy ID.
  119. *
  120. * @param[in] id The enemy ID.
  121. */
  122. void SetId(const int id);
  123. /**
  124. * Retrieves the enemy model.
  125. *
  126. * The model name is the filename of the .mesh file, without extension.
  127. *
  128. * @return The enemy model.
  129. */
  130. const std::string GetModel() const;
  131. /**
  132. * Sets the enemy model.
  133. *
  134. * The model name must be the filename of the .mesh file, without extension.
  135. *
  136. * @param[in] model The enemy model name.
  137. */
  138. void SetModel(const std::string model);
  139. /**
  140. * Retrieves the enemy name.
  141. *
  142. * @return The enemy name.
  143. */
  144. const std::string GetName() const;
  145. /**
  146. * Sets the enemy name.
  147. *
  148. * @param[in] name The enemy name.
  149. */
  150. void SetName(const Ogre::String& name);
  151. /**
  152. * Retrieves the enemy level.
  153. *
  154. * @return The enemy level.
  155. */
  156. unsigned int GetLevel() const;
  157. /**
  158. * Sets the enemy level.
  159. *
  160. * @param[in] level The enemy level.
  161. */
  162. void SetLevel(const unsigned int level);
  163. /**
  164. * Retrieves the AP gain upon defeating the enemy.
  165. *
  166. * @return The AP gain.
  167. */
  168. unsigned int GetAp() const;
  169. /**
  170. * Sets the AP gain upon defeating the enemy.
  171. *
  172. * @param[in] ap The AP gain.
  173. */
  174. void SetAp(unsigned int ap);
  175. /**
  176. * Retrieves the EXP gain upon defeating the enemy.
  177. *
  178. * @return The EXP gain.
  179. */
  180. unsigned int GetExp() const;
  181. /**
  182. * Sets the EXP gain upon defeating the enemy.
  183. *
  184. * @param[in] exp The EXP gain.
  185. */
  186. void SetExp(const unsigned int exp);
  187. /**
  188. * Retrieves the money gain upon defeating the enemy.
  189. *
  190. * @return The money gain.
  191. */
  192. unsigned int GetMoney() const;
  193. /**
  194. * Sets the money gain upon defeating the enemy.
  195. *
  196. * @param[in] money The money gain.
  197. */
  198. void SetMoney(const unsigned int money);
  199. /**
  200. * Retrieves the enemy animation IDs.
  201. *
  202. * @return The list of animation IDs
  203. */
  204. std::vector<unsigned int> GetAnimations() const;
  205. /**
  206. * Adds an animation for the enemy.
  207. *
  208. * @param[in] animation Animation ID.
  209. */
  210. void AddAnimation(const unsigned int animation);
  211. /**
  212. * Retrieves the enemy attacks.
  213. *
  214. * @return The list of attacks.
  215. */
  216. std::vector<Attack> GetAttacks() const;
  217. /**
  218. * Adds an attack for the enemy.
  219. *
  220. * @param[in] attack Attack to add.
  221. */
  222. void AddAttack(const Attack attack);
  223. /**
  224. * Retrieves the enemy possible item drops.
  225. *
  226. * @return List of items that can be dropped by the enemy.
  227. */
  228. std::vector<Item> GetDrop() const;
  229. /**
  230. * Adds an item drop for the enemy.
  231. *
  232. * @param[in] item The dropable item.
  233. */
  234. void AddDrop(const Item item);
  235. /**
  236. * Retrieves the list of the enemy elemental affinities.
  237. *
  238. * @return The list of elemental affinities.
  239. */
  240. std::vector<Element> GetElements() const;
  241. /**
  242. * Adds an elemental affinity to the monster.
  243. *
  244. * @param[in] element Elemental affinity.
  245. */
  246. void AddElement(const Element element);
  247. /**
  248. * Retrieves the list of status immunities.
  249. *
  250. * @return The list of status immunities.
  251. */
  252. std::vector<Immunity> GetImmunities() const;
  253. /**
  254. * Adds an immunity to the monster.
  255. *
  256. * @param[in] immunity The immunity to add.
  257. */
  258. void AddImmunity(const Immunity immunity);
  259. /**
  260. * Retrieves the list of attacks that can be used during the manipulated state.
  261. *
  262. * The first attack of the list is also the attack the enemy will use when in berserkr
  263. * state. If the list is empty, the enemy can't be manipulated or berserkred.
  264. *
  265. * @return List of IDs of attacks usable during manipulation
  266. */
  267. std::vector<unsigned int> GetManipulateAttacks() const;
  268. /**
  269. * Adds an attack usable during manipulation.
  270. *
  271. * @param[in] attack ID of the attack.
  272. */
  273. void AddManipulateAttack(const unsigned int attack);
  274. /**
  275. * Retrieves the enemy possible item stelas.
  276. *
  277. * @return List of items that can be stolen from the enemy.
  278. */
  279. std::vector<Item> GetSteal() const;
  280. /**
  281. * Adds an item steal to the enemy.
  282. *
  283. * @param[in] item The stealableitem.
  284. */
  285. void AddSteal(const Item item);
  286. /**
  287. * Retrieves the ID of the item the monster can be morphed into.
  288. *
  289. * @return ID of the item the enemy can be morphed into, -1 if none.
  290. */
  291. unsigned int GetMorph() const;
  292. /**
  293. * Sets the ID of the item the monster can be morphed into.
  294. *
  295. * @param[in] morph ID of the item the enemy can be morphed into, -1 if none.
  296. */
  297. void SetMorph(const int morph);
  298. /**
  299. * Retrieves the multiplier for the damage the enemy receives when attacked from the back.
  300. *
  301. * @return Back attack damage multiplier.
  302. */
  303. float GetBackDamage() const;
  304. /**
  305. * Sets the multiplier for the damage the enemy receives when attacked from the back.
  306. *
  307. * @param[in] back_damage Back attack damage multiplier, 0 or positive.
  308. */
  309. void SetBackDamage(const float back_damage);
  310. /**
  311. * Retrieves the enemy's strength stat.
  312. *
  313. * @return The strength stat.
  314. */
  315. unsigned int GetStr() const;
  316. /**
  317. * Sets the enemy's strength stat.
  318. *
  319. * @param[in] str The strength stat.
  320. */
  321. void SetStr(const unsigned int str);
  322. /**
  323. * Retrieves the enemy's defense stat.
  324. *
  325. * @return The defense stat.
  326. */
  327. unsigned int GetDef() const;
  328. /**
  329. * Sets the enemy's defense stat.
  330. *
  331. * @param[in] def The defense stat.
  332. */
  333. void SetDef(const unsigned int def);
  334. /**
  335. * Retrieves the enemy's magic stat.
  336. *
  337. * @return The magic stat.
  338. */
  339. unsigned int GetMag() const;
  340. /**
  341. * Sets the enemy's magic stat.
  342. *
  343. * @param[in] mag The magic stat.
  344. */
  345. void SetMag(const unsigned int mag);
  346. /**
  347. * Retrieves the enemy's spirit stat.
  348. *
  349. * @return The spirit stat.
  350. */
  351. unsigned int GetSpr() const;
  352. /**
  353. * Sets the enemy's spirit stat.
  354. *
  355. * @param[in] spr The spirit stat.
  356. */
  357. void SetSpr(const unsigned int spr);
  358. /**
  359. * Retrieves the enemy's dexterity stat.
  360. *
  361. * @return The dexterity stat.
  362. */
  363. unsigned int GetDex() const;
  364. /**
  365. * Sets the enemy's dexterity stat.
  366. *
  367. * @param[in] dex The dexterity stat.
  368. */
  369. void SetDex(const unsigned int dex);
  370. /**
  371. * Retrieves the enemy's luck stat.
  372. *
  373. * @return The luck stat.
  374. */
  375. unsigned int GetLck() const;
  376. /**
  377. * Sets the enemy's luck stat.
  378. *
  379. * @param[in] lck The luck stat.
  380. */
  381. void SetLck(const unsigned int lck);
  382. /**
  383. * Retrieves the enemy's evasion stat.
  384. *
  385. * @return The evasion stat.
  386. */
  387. unsigned int GetEva() const;
  388. /**
  389. * Sets the enemy's evasion stat.
  390. *
  391. * @param[in] eva The evasion stat.
  392. */
  393. void SetEva(const unsigned int eva);
  394. /**
  395. * Retrieves the enemy's magic evasion stat.
  396. *
  397. * @return The magic evasion stat.
  398. */
  399. unsigned int GetMeva() const;
  400. /**
  401. * Sets the enemy's magic evasion stat.
  402. *
  403. * @param[in] meva The magic evasion stat.
  404. */
  405. void SetMeva(const unsigned int meva);
  406. /**
  407. * Retrieves the enemy's current HP.
  408. *
  409. * @return The current HP.
  410. */
  411. unsigned int GetHp() const;
  412. /**
  413. * Sets the enemy's current HP.
  414. *
  415. * If set to higher then max HP reported by {@see GetHpMax()}, it will be capped to that
  416. * value.
  417. *
  418. * @param[in] hp The current HP.
  419. */
  420. void SetHp(const unsigned int hp);
  421. /**
  422. * Retrieves the enemy's max HP.
  423. *
  424. * @return The max HP.
  425. */
  426. unsigned int GetHpMax() const;
  427. /**
  428. * Sets the enemy's max HP.
  429. *
  430. * If the new max HP is higher than the current HP, the current HP will be set to the new
  431. * max HP.
  432. *
  433. * @param[in] hp_max The max HP stat.
  434. */
  435. void SetHpMax(const unsigned int hp_max);
  436. /**
  437. * Retrieves the enemy's current MP.
  438. *
  439. * @return The current MP.
  440. */
  441. unsigned int GetMp() const;
  442. /**
  443. * Sets the enemy's current MP.
  444. *
  445. * If set to higher then max MP reported by {@see GetMpMax()}, it will be capped to that
  446. * value.
  447. *
  448. * @param[in] mp The current MP.
  449. */
  450. void SetMp(const unsigned int mp);
  451. /**
  452. * Retrieves the enemy's max MP.
  453. *
  454. * @return The max MP.
  455. */
  456. unsigned int GetMpMax() const;
  457. /**
  458. * Sets the enemy's max MP.
  459. *
  460. * If the new max MP is higher than the current MP, the current MP will be set to the new
  461. * max MP.
  462. *
  463. * @param[in] mp_max The max MP stat.
  464. */
  465. void SetMpMax(const unsigned int mp_max);
  466. /**
  467. * Retrieves the enemy position in the battlefield.
  468. *
  469. * @return The enemy position (x, y, z).
  470. */
  471. Ogre::Vector3& GetPos();
  472. /**
  473. * Sets the enemy position in the battlefield.
  474. *
  475. * @param[in] pos The enemy position (x, y, z).
  476. */
  477. void SetPos(const Ogre::Vector3 &pos);
  478. /**
  479. * Retrieves the enemy position.
  480. *
  481. * @return The X, Y and Z coordinates for Lua scripts.
  482. */
  483. std::tuple<float, float, float> ScriptGetPos() const;
  484. /**
  485. * Checks if the enemy is in the front row.
  486. *
  487. * @return True if the enemy is in the front row. false if not.
  488. */
  489. bool IsFront() const;
  490. /**
  491. * Sets the enemy in or out the front row.
  492. *
  493. * @param[in] front True to set the enemy in the front row, false for the back row.
  494. */
  495. void SetFront(bool front);
  496. /**
  497. * Checks the enemy visibility.
  498. *
  499. * @return True if the enemy is visible, false if not.
  500. */
  501. bool IsVisible() const;
  502. /**
  503. * Toggles the enemy visibility.
  504. *
  505. * @param[in] visible True to make the enemy visible, false to make it invisible.
  506. */
  507. void SetVisible(bool visible);
  508. /**
  509. * Checks whether the enemy can be targeted.
  510. *
  511. * @return True if the enemy can be targeted, false if not.
  512. */
  513. bool IsTargeteable() const;
  514. /**
  515. * Determines whether the enemy can be targeted.
  516. *
  517. * @param[in] targeteable True to allow targeting the enemy false to prevent it.
  518. */
  519. void SetTargeteable(bool targeteable);
  520. /**
  521. * Checks whether the enemy's main script is active.
  522. *
  523. * @return True if the script is active, false if not.
  524. */
  525. bool IsActive() const;
  526. /**
  527. * Activates or deactivates the enemy main script.
  528. *
  529. * @param[in] active True to activate the script, false to deactivate it.
  530. */
  531. void SetActive(bool active);
  532. /**
  533. * Retrieves the flags for enemy covering.
  534. *
  535. * {@see https://wiki.ffrtt.ru/index.php/FF7/Battle/Battle_Scenes#Binary_.22Cover_Flags.22}
  536. * for more info about cover flags.
  537. *
  538. * @return A string with five 0s or 1s indicating the cover flags.
  539. */
  540. std::string GetCover() const;
  541. /**
  542. * Sets the flags for enemy covering.
  543. *
  544. * {@see https://wiki.ffrtt.ru/index.php/FF7/Battle/Battle_Scenes#Binary_.22Cover_Flags.22}
  545. * for more info about cover flags.
  546. *
  547. * @param[in] cover A string with five 0s or 1s indicating the cover flags.
  548. */
  549. void SetCover(std::string cover);
  550. /**
  551. * Retrieves the number of attacks of the enemy.
  552. *
  553. * To be used from Lua scripts.
  554. *
  555. * @return The number of attacks.
  556. */
  557. int ScriptGetAttackCount();
  558. /**
  559. * Retrieves an attack.
  560. *
  561. * To be used from Lua scripts.
  562. *
  563. * @param[in] index The index of the attack to retrieve. Must be lower than reported by
  564. * {@see ScriptGetAttackCount}.
  565. * @return The ID of the attack in the specified index, or -1 if no such attack exists.
  566. */
  567. int ScriptGetAttack(const unsigned int index);
  568. /**
  569. * Retrieves the camera for an attack.
  570. *
  571. * To be used from Lua scripts.
  572. *
  573. * @param[in] index The index of the attack to retrieve. Must be lower than reported by
  574. * {@see ScriptGetAttackCount}.
  575. * @return The ID of camera associated to the attack. -1 if no such attack exists or if it
  576. * doesn't have an specific camera associated.
  577. */
  578. int ScriptGetCameraForAttack(const unsigned int index);
  579. private:
  580. /**
  581. * Reads enemy data from the xml file.
  582. */
  583. void ReadFromXml();
  584. /**
  585. * The enemy ID.
  586. */
  587. int id_;
  588. /**
  589. * NAme of the enemy model file.
  590. */
  591. std::string model_;
  592. /**
  593. * The name of the enemy.
  594. */
  595. Ogre::String name_;
  596. /**
  597. * The enemy level.
  598. */
  599. unsigned int level_;
  600. /**
  601. * EXP given upon defeating the enemy.
  602. */
  603. unsigned int exp_;
  604. /**
  605. * AP given upon defeating the enemy.
  606. */
  607. unsigned int ap_;
  608. /**
  609. * Money given upon defeating the enemy.
  610. */
  611. unsigned int money_;
  612. /**
  613. * List of animations.
  614. */
  615. std::vector<unsigned int> animations_;
  616. /**
  617. * Elemental affinities.
  618. */
  619. std::vector<Element> elements_;
  620. /**
  621. * Status immunities and resistances.
  622. */
  623. std::vector<Immunity> immunities_;
  624. /**
  625. * Enemy attacks.
  626. */
  627. std::vector<Attack> attacks_;
  628. /**
  629. * List of attacks that can be used while manipulated.
  630. *
  631. * The first one is also the one used in berserkr. If empty, it means the enemy can't be
  632. * manipulated or berserkd.
  633. */
  634. std::vector<unsigned int> manipulate_attacks_;
  635. /**
  636. * List of the items that can be stolen from the enemy.
  637. */
  638. std::vector<Item> steal_;
  639. /**
  640. * List of the items that can be dropped from the enemy.
  641. */
  642. std::vector<Item> drop_;
  643. /**
  644. * ID of the item the enemy can be morphed into. -1 if none..
  645. */
  646. int morph_;
  647. /**
  648. * Multiplier for back damage.
  649. */
  650. float back_damage_;
  651. /**
  652. * Enemy strength stat.
  653. */
  654. unsigned int str_;
  655. /**
  656. * Enemy defense stat.
  657. */
  658. unsigned int def_;
  659. /**
  660. * Enemy magic stat.
  661. */
  662. unsigned int mag_;
  663. /**
  664. * Enemy spirit stat.
  665. */
  666. unsigned int spr_;
  667. /**
  668. * Enemy dexterity stat.
  669. */
  670. unsigned int dex_;
  671. /**
  672. * Enemy luck stat.
  673. */
  674. unsigned int lck_;
  675. /**
  676. * Enemy evasion stat.
  677. */
  678. unsigned int eva_;
  679. /**
  680. * Enemy magic evasion stat.
  681. */
  682. unsigned int meva_;
  683. /**
  684. * Enemy's current HP.
  685. */
  686. unsigned int hp_;
  687. /**
  688. * Enemy's current MP.
  689. */
  690. unsigned int mp_;
  691. /**
  692. * Enemy's max HP.
  693. */
  694. unsigned int hp_max_;
  695. /**
  696. * Enemy's max MP.
  697. */
  698. unsigned int mp_max_;
  699. /**
  700. * Enemy position in the battlefield (x, y, z).
  701. */
  702. Ogre::Vector3 pos_;
  703. /**
  704. * Indicates if the enmy is in the frontline.
  705. */
  706. bool front_;
  707. /**
  708. * Indicates if the enemy is visible.
  709. */
  710. bool visible_;
  711. /**
  712. * Indicates if the enemy can be targeted.
  713. */
  714. bool targeteable_;
  715. /**
  716. * Indicates if the enemy's main script is active.
  717. */
  718. bool active_;
  719. /**
  720. * Cover binary flags.
  721. */
  722. std::string cover_;
  723. };