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 <OgreString.h>
  17. #include "ScriptManager.h"
  18. /**
  19. * Any enemy in a battle.
  20. */
  21. class Enemy{
  22. public:
  23. struct Element{
  24. /**
  25. * The element ID.
  26. */
  27. unsigned int id;
  28. /**
  29. * Damage modification factor when attacked by the element.
  30. *
  31. * 1 means normal damage taken.
  32. * 0 means no damage taken.
  33. * [0-1] means reduced damage.
  34. * [1-10) means extended damage.
  35. * (-10-0) means recovery
  36. * >10 means death.
  37. * <-10 means full recovery.
  38. */
  39. float factor;
  40. };
  41. /**
  42. * Enemy attack data.
  43. */
  44. struct Attack{
  45. /**
  46. * Attack ID.
  47. */
  48. unsigned int id;
  49. /**
  50. * Camera ID to use during the attack.
  51. *
  52. * -1 to not move the camera.
  53. */
  54. int camera;
  55. };
  56. /**
  57. * Data for drop and steal items.
  58. */
  59. struct Item{
  60. /**
  61. * Item ID.
  62. */
  63. unsigned int id;
  64. /**
  65. * Steal or drop rate.
  66. */
  67. float rate;
  68. };
  69. /**
  70. * Status immunity.
  71. */
  72. struct Immunity{
  73. /**
  74. * Status ID.
  75. */
  76. unsigned int status;
  77. /**
  78. * Immunity rate.
  79. *
  80. * 0 or lower means no immunity, 1 or higher completely immune. Values between 0 and 1
  81. * indicate resistance.
  82. */
  83. float rate;
  84. };
  85. /**
  86. * Constructor.
  87. *
  88. * @param[in] id Enemy ID.
  89. */
  90. Enemy(const unsigned int id);
  91. /**
  92. * Constructor.
  93. *
  94. * @param[in] id Enemy ID.
  95. * @param[in] pos Enemy position (x, y, z).
  96. * @param[in] front True to set the enemy in the front row, false for back row.
  97. * @param[in] visible Indicates enemy visibility.
  98. * @param[in] targeteable Indicates if the enemy can be targeted.
  99. * @param[in] active Indicates whether the enemy main script is active or not.
  100. * @param[in] cover Cover binary flags string.
  101. */
  102. Enemy(
  103. const unsigned int id, const Ogre::Vector3 pos, const bool front, const bool visible,
  104. const bool targeteable, const bool active, const std::string cover
  105. );
  106. /**
  107. * Destructor.
  108. */
  109. virtual ~Enemy();
  110. /**
  111. * Retrieves the enemy ID.
  112. *
  113. * @return The enemy ID, or -1 if it's not loaded.
  114. */
  115. const int GetId() const;
  116. /**
  117. * Sets the enemy ID.
  118. *
  119. * @param[in] id The enemy ID.
  120. */
  121. void SetId(const int id);
  122. /**
  123. * Retrieves the enemy model.
  124. *
  125. * The model name is the filename of the .mesh file, without extension.
  126. *
  127. * @return The enemy model.
  128. */
  129. const std::string GetModel() const;
  130. /**
  131. * Sets the enemy model.
  132. *
  133. * The model name must be the filename of the .mesh file, without extension.
  134. *
  135. * @param[in] model The enemy model name.
  136. */
  137. void SetModel(const std::string model);
  138. /**
  139. * Retrieves the enemy name.
  140. *
  141. * @return The enemy name.
  142. */
  143. const std::string GetName() const;
  144. /**
  145. * Sets the enemy name.
  146. *
  147. * @param[in] name The enemy name.
  148. */
  149. void SetName(const Ogre::String& name);
  150. /**
  151. * Retrieves the enemy level.
  152. *
  153. * @return The enemy level.
  154. */
  155. unsigned int GetLevel() const;
  156. /**
  157. * Sets the enemy level.
  158. *
  159. * @param[in] level The enemy level.
  160. */
  161. void SetLevel(const unsigned int level);
  162. /**
  163. * Retrieves the AP gain upon defeating the enemy.
  164. *
  165. * @return The AP gain.
  166. */
  167. unsigned int GetAp() const;
  168. /**
  169. * Sets the AP gain upon defeating the enemy.
  170. *
  171. * @param[in] ap The AP gain.
  172. */
  173. void SetAp(unsigned int ap);
  174. /**
  175. * Retrieves the EXP gain upon defeating the enemy.
  176. *
  177. * @return The EXP gain.
  178. */
  179. unsigned int GetExp() const;
  180. /**
  181. * Sets the EXP gain upon defeating the enemy.
  182. *
  183. * @param[in] exp The EXP gain.
  184. */
  185. void SetExp(const unsigned int exp);
  186. /**
  187. * Retrieves the money gain upon defeating the enemy.
  188. *
  189. * @return The money gain.
  190. */
  191. unsigned int GetMoney() const;
  192. /**
  193. * Sets the money gain upon defeating the enemy.
  194. *
  195. * @param[in] money The money gain.
  196. */
  197. void SetMoney(const unsigned int money);
  198. /**
  199. * Retrieves the enemy animation IDs.
  200. *
  201. * @return The list of animation IDs
  202. */
  203. std::vector<unsigned int> GetAnimations() const;
  204. /**
  205. * Adds an animation for the enemy.
  206. *
  207. * @param[in] animation Animation ID.
  208. */
  209. void AddAnimation(const unsigned int animation);
  210. /**
  211. * Retrieves the enemy attacks.
  212. *
  213. * @return The list of attacks.
  214. */
  215. std::vector<Attack> GetAttacks() const;
  216. /**
  217. * Adds an attack for the enemy.
  218. *
  219. * @param[in] attack Attack to add.
  220. */
  221. void AddAttack(const Attack attack);
  222. /**
  223. * Retrieves the enemy possible item drops.
  224. *
  225. * @return List of items that can be dropped by the enemy.
  226. */
  227. std::vector<Item> GetDrop() const;
  228. /**
  229. * Adds an item drop for the enemy.
  230. *
  231. * @param[in] item The dropable item.
  232. */
  233. void AddDrop(const Item item);
  234. /**
  235. * Retrieves the list of the enemy elemental affinities.
  236. *
  237. * @return The list of elemental affinities.
  238. */
  239. std::vector<Element> GetElements() const;
  240. /**
  241. * Adds an elemental affinity to the monster.
  242. *
  243. * @param[in] element Elemental affinity.
  244. */
  245. void AddElement(const Element element);
  246. /**
  247. * Retrieves the list of status immunities.
  248. *
  249. * @return The list of status immunities.
  250. */
  251. std::vector<Immunity> GetImmunities() const;
  252. /**
  253. * Adds an immunity to the monster.
  254. *
  255. * @param[in] immunity The immunity to add.
  256. */
  257. void AddImmunity(const Immunity immunity);
  258. /**
  259. * Retrieves the list of attacks that can be used during the manipulated state.
  260. *
  261. * The first attack of the list is also the attack the enemy will use when in berserkr
  262. * state. If the list is empty, the enemy can't be manipulated or berserkred.
  263. *
  264. * @return List of IDs of attacks usable during manipulation
  265. */
  266. std::vector<unsigned int> GetManipulateAttacks() const;
  267. /**
  268. * Adds an attack usable during manipulation.
  269. *
  270. * @param[in] attack ID of the attack.
  271. */
  272. void AddManipulateAttack(const unsigned int attack);
  273. /**
  274. * Retrieves the enemy possible item stelas.
  275. *
  276. * @return List of items that can be stolen from the enemy.
  277. */
  278. std::vector<Item> GetSteal() const;
  279. /**
  280. * Adds an item steal to the enemy.
  281. *
  282. * @param[in] item The stealableitem.
  283. */
  284. void AddSteal(const Item item);
  285. /**
  286. * Retrieves the ID of the item the monster can be morphed into.
  287. *
  288. * @return ID of the item the enemy can be morphed into, -1 if none.
  289. */
  290. unsigned int GetMorph() const;
  291. /**
  292. * Sets the ID of the item the monster can be morphed into.
  293. *
  294. * @param[in] morph ID of the item the enemy can be morphed into, -1 if none.
  295. */
  296. void SetMorph(const int morph);
  297. /**
  298. * Retrieves the multiplier for the damage the enemy receives when attacked from the back.
  299. *
  300. * @return Back attack damage multiplier.
  301. */
  302. float GetBackDamage() const;
  303. /**
  304. * Sets the multiplier for the damage the enemy receives when attacked from the back.
  305. *
  306. * @param[in] back_damage Back attack damage multiplier, 0 or positive.
  307. */
  308. void SetBackDamage(const float back_damage);
  309. /**
  310. * Retrieves the enemy's strength stat.
  311. *
  312. * @return The strength stat.
  313. */
  314. unsigned int GetStr() const;
  315. /**
  316. * Sets the enemy's strength stat.
  317. *
  318. * @param[in] str The strength stat.
  319. */
  320. void SetStr(const unsigned int str);
  321. /**
  322. * Retrieves the enemy's defense stat.
  323. *
  324. * @return The defense stat.
  325. */
  326. unsigned int GetDef() const;
  327. /**
  328. * Sets the enemy's defense stat.
  329. *
  330. * @param[in] def The defense stat.
  331. */
  332. void SetDef(const unsigned int def);
  333. /**
  334. * Retrieves the enemy's magic stat.
  335. *
  336. * @return The magic stat.
  337. */
  338. unsigned int GetMag() const;
  339. /**
  340. * Sets the enemy's magic stat.
  341. *
  342. * @param[in] mag The magic stat.
  343. */
  344. void SetMag(const unsigned int mag);
  345. /**
  346. * Retrieves the enemy's spirit stat.
  347. *
  348. * @return The spirit stat.
  349. */
  350. unsigned int GetSpr() const;
  351. /**
  352. * Sets the enemy's spirit stat.
  353. *
  354. * @param[in] spr The spirit stat.
  355. */
  356. void SetSpr(const unsigned int spr);
  357. /**
  358. * Retrieves the enemy's dexterity stat.
  359. *
  360. * @return The dexterity stat.
  361. */
  362. unsigned int GetDex() const;
  363. /**
  364. * Sets the enemy's dexterity stat.
  365. *
  366. * @param[in] dex The dexterity stat.
  367. */
  368. void SetDex(const unsigned int dex);
  369. /**
  370. * Retrieves the enemy's luck stat.
  371. *
  372. * @return The luck stat.
  373. */
  374. unsigned int GetLck() const;
  375. /**
  376. * Sets the enemy's luck stat.
  377. *
  378. * @param[in] lck The luck stat.
  379. */
  380. void SetLck(const unsigned int lck);
  381. /**
  382. * Retrieves the enemy's evasion stat.
  383. *
  384. * @return The evasion stat.
  385. */
  386. unsigned int GetEva() const;
  387. /**
  388. * Sets the enemy's evasion stat.
  389. *
  390. * @param[in] eva The evasion stat.
  391. */
  392. void SetEva(const unsigned int eva);
  393. /**
  394. * Retrieves the enemy's magic evasion stat.
  395. *
  396. * @return The magic evasion stat.
  397. */
  398. unsigned int GetMeva() const;
  399. /**
  400. * Sets the enemy's magic evasion stat.
  401. *
  402. * @param[in] meva The magic evasion stat.
  403. */
  404. void SetMeva(const unsigned int meva);
  405. /**
  406. * Retrieves the enemy's current HP.
  407. *
  408. * @return The current HP.
  409. */
  410. unsigned int GetHp() const;
  411. /**
  412. * Sets the enemy's current HP.
  413. *
  414. * If set to higher then max HP reported by {@see GetHpMax()}, it will be capped to that
  415. * value.
  416. *
  417. * @param[in] hp The current HP.
  418. */
  419. void SetHp(const unsigned int hp);
  420. /**
  421. * Retrieves the enemy's max HP.
  422. *
  423. * @return The max HP.
  424. */
  425. unsigned int GetHpMax() const;
  426. /**
  427. * Sets the enemy's max HP.
  428. *
  429. * If the new max HP is higher than the current HP, the current HP will be set to the new
  430. * max HP.
  431. *
  432. * @param[in] hp_max The max HP stat.
  433. */
  434. void SetHpMax(const unsigned int hp_max);
  435. /**
  436. * Retrieves the enemy's current MP.
  437. *
  438. * @return The current MP.
  439. */
  440. unsigned int GetMp() const;
  441. /**
  442. * Sets the enemy's current MP.
  443. *
  444. * If set to higher then max MP reported by {@see GetMpMax()}, it will be capped to that
  445. * value.
  446. *
  447. * @param[in] mp The current MP.
  448. */
  449. void SetMp(const unsigned int mp);
  450. /**
  451. * Retrieves the enemy's max MP.
  452. *
  453. * @return The max MP.
  454. */
  455. unsigned int GetMpMax() const;
  456. /**
  457. * Sets the enemy's max MP.
  458. *
  459. * If the new max MP is higher than the current MP, the current MP will be set to the new
  460. * max MP.
  461. *
  462. * @param[in] mp_max The max MP stat.
  463. */
  464. void SetMpMax(const unsigned int mp_max);
  465. /**
  466. * Retrieves the enemy position in the battlefield.
  467. *
  468. * @return The enemy position (x, y, z).
  469. */
  470. Ogre::Vector3& GetPos();
  471. /**
  472. * Sets the enemy position in the battlefield.
  473. *
  474. * @param[in] pos The enemy position (x, y, z).
  475. */
  476. void SetPos(const Ogre::Vector3 &pos);
  477. /**
  478. * Retrieves the enemy position.
  479. *
  480. * To be used from Lua scripts only. It doesn't return anything, but adds three values to
  481. * the stack for the X, Y and Z coordinates.
  482. */
  483. void 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. };