Entity.h 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438
  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 "EntityCollision.h"
  18. #include "EntityDirection.h"
  19. #include "ScriptManager.h"
  20. /**
  21. * Action types.
  22. */
  23. enum ActionType{
  24. /**
  25. * No action.
  26. */
  27. AT_NONE,
  28. /**
  29. * Linear action.
  30. *
  31. * It starts and ends at full speed.
  32. */
  33. AT_LINEAR,
  34. /**
  35. * Smooth action.
  36. *
  37. * The action speed steadily increases when started, and it steadily
  38. * decreases before the end.
  39. */
  40. AT_SMOOTH
  41. };
  42. /**
  43. * The direction for an entity turn.
  44. */
  45. enum TurnDirection{
  46. /**
  47. * Turn clockwise.
  48. */
  49. TD_CLOCKWISE,
  50. /**
  51. * Turn anticlockwise.
  52. */
  53. TD_ANTICLOCKWISE,
  54. /**
  55. * Choose direction automatically.
  56. *
  57. * The direction in which the turn is shorter will be selected.
  58. */
  59. TD_CLOSEST
  60. };
  61. /**
  62. * Linear movement modes.
  63. */
  64. enum LinearMovement{
  65. /**
  66. * Move down.
  67. */
  68. LM_UP_TO_DOWN,
  69. /**
  70. * Move up.
  71. */
  72. LM_DOWN_TO_UP,
  73. /**
  74. * Move right.
  75. */
  76. LM_LEFT_TO_RIGHT,
  77. /**
  78. * Move left.
  79. */
  80. LM_RIGHT_TO_LEFT
  81. };
  82. /**
  83. * Any entity in a field.
  84. */
  85. class Entity{
  86. public:
  87. /**
  88. * Entity animation states.
  89. */
  90. enum AnimationState{
  91. /**
  92. * An animation has been requested.
  93. */
  94. REQUESTED_ANIMATION,
  95. /**
  96. * An animation is set to play automatically.
  97. */
  98. AUTO_ANIMATION
  99. };
  100. /**
  101. * Types of animations.
  102. */
  103. enum AnimationPlayType{
  104. /**
  105. * Default animation mode.
  106. *
  107. * @todo Same as PLAY_ONCE?
  108. */
  109. PLAY_DEFAULT,
  110. /**
  111. * Play the animation once, then stop.
  112. */
  113. PLAY_ONCE,
  114. /**
  115. * Play an animation in a continous loop.
  116. */
  117. PLAY_LOOPED
  118. };
  119. /**
  120. * Entity state.
  121. */
  122. enum State{
  123. /**
  124. * No state.
  125. *
  126. * The entity has not been placed or it has been removed.
  127. */
  128. NONE,
  129. /**
  130. * The entity is attached to the walkmesh.
  131. */
  132. WALKMESH,
  133. /**
  134. * The entity is in the middle of a linear movement.
  135. */
  136. LINEAR,
  137. /**
  138. * The entity is in the middle of a jump.
  139. */
  140. JUMP,
  141. /**
  142. * The entity has completed an action and needs to be reattached
  143. * to the walkmesh before continuing execution.
  144. */
  145. NEEDS_TO_REATTACH
  146. };
  147. /**
  148. * Constructor.
  149. *
  150. * @param[in] name Entity name.
  151. * @param[in] node Scene node to which the entity should be attached.
  152. */
  153. Entity(const Ogre::String& name, Ogre::SceneNode* node);
  154. /**
  155. * Destructor.
  156. */
  157. virtual ~Entity();
  158. /**
  159. * Updates the entity status.
  160. */
  161. virtual void Update();
  162. /**
  163. * Updates the entity status with debug information.
  164. */
  165. virtual void UpdateDebug();
  166. /**
  167. * Retrieves the entity name.
  168. *
  169. * @return The entity name.
  170. */
  171. const Ogre::String& GetName() const;
  172. /**
  173. * Sets the entity position.
  174. *
  175. * @param[in] position Entity's new position.
  176. */
  177. void SetPosition(const Ogre::Vector3& position);
  178. /**
  179. * Sets the entity position.
  180. *
  181. * It also resets the walkmesh triangle to reattach entity to walkmesh
  182. * again if needed.
  183. *
  184. * @param[in] x Entity's new position X coordinate.
  185. * @param[in] y Entity's new position Y coordinate.
  186. * @param[in] z Entity's new position Z coordinate.
  187. */
  188. void ScriptSetPosition(const float x, const float y, const float z);
  189. /**
  190. * Moves the entity by the specified position offset.
  191. *
  192. * @param[in] x X coordinate offset.
  193. * @param[in] y Y coordinate offset.
  194. * @param[in] z Z coordinate offset.
  195. */
  196. void ScriptMoveBy(const float x, const float y, const float z);
  197. /**
  198. * Retrieves the entity position.
  199. *
  200. * @return The entity position.
  201. */
  202. const Ogre::Vector3 GetPosition() const;
  203. /**
  204. * Retrieves the entity position.
  205. *
  206. * To be used from Lua scripts only. It doesn't return anything, but adds three values to
  207. * the stack for the X, Y and Z coordinates.
  208. */
  209. void ScriptGetPosition() const;
  210. /**
  211. * Sets the entity position.
  212. *
  213. * @param[in] position The entity new position.
  214. * @todo Offset to what?
  215. */
  216. void SetOffset(const Ogre::Vector3& position);
  217. /**
  218. * Retrieves the entity position.
  219. *
  220. * @return The entity position.
  221. * @todo Offset to what?
  222. */
  223. const Ogre::Vector3 GetOffset() const;
  224. /**
  225. * Sets the entity rotation.
  226. *
  227. * @param[in] rotation The entity rotation, in degrees.
  228. */
  229. void SetRotation(const Ogre::Degree& rotation);
  230. /**
  231. * Sets the entity rotation.
  232. *
  233. * @param[in] rotation The entity rotation (0-360).
  234. */
  235. void ScriptSetRotation(const float rotation);
  236. /**
  237. * Retrieves the entity rotation.
  238. *
  239. * @return The entity rotation, in degrees.
  240. */
  241. Ogre::Degree GetRotation() const;
  242. /**
  243. * Retrieves the entity rotation.
  244. *
  245. * @return The entity rotation (0-360).
  246. */
  247. float ScriptGetRotation() const;
  248. /**
  249. * Sets the entity scale.
  250. *
  251. * @param[in] scale Three dimensional scale.
  252. */
  253. virtual void setScale(const Ogre::Vector3 &scale);
  254. /**
  255. * Sets the entity index in the field.
  256. *
  257. * @param[in] index Index of the entity.
  258. */
  259. void SetIndex(const int index);
  260. /**
  261. * Retrieves the entity index in the field.
  262. *
  263. * @return Index of the entity.
  264. */
  265. int GetIndex();
  266. /**
  267. * Sets the entity's absolute orientation.
  268. *
  269. * @param[in] root_orientation The entity's new orientation.
  270. */
  271. virtual void setRootOrientation(
  272. const Ogre::Quaternion &root_orientation
  273. );
  274. /**
  275. * Retrieves the entity's height.
  276. *
  277. * @return The entity's height.
  278. */
  279. float GetHeight() const;
  280. /**
  281. * Sets the entity collision height and updates its debug proxies.
  282. *
  283. * @param[in] height Height in map units.
  284. */
  285. void SetHeight(const float height);
  286. /**
  287. * Sets the orientation of the debug collision proxies.
  288. *
  289. * @param[in] orientation Proxy orientation relative to the entity.
  290. */
  291. void SetCollisionDebugOrientation(const Ogre::Quaternion& orientation);
  292. /**
  293. * Sets the entity's solid radius.
  294. *
  295. * The solid radius is used to detect collisions.
  296. *
  297. * @param[in] radius The solid radius.
  298. * @todo Is it in pixels?
  299. */
  300. void SetSolidRadius(const float radius);
  301. /**
  302. * Retrieves the entity's solid radius.
  303. *
  304. * The solid radius is used to detect collisions.
  305. *
  306. * @return The solid radius.
  307. * @todo Is it in pixels?
  308. */
  309. float GetSolidRadius() const;
  310. /**
  311. * Makes the entity solid or non-solid.
  312. *
  313. * Solid entities can produce collisions.
  314. *
  315. * @param[in] solid True to make the entity solid, false otherwise.
  316. */
  317. void SetSolid(const bool solid);
  318. /**
  319. * Checks if the entity is solid.
  320. *
  321. * Solid entities can produce collisions.
  322. *
  323. * @return True if the entity is solid, false otherwise.
  324. */
  325. bool IsSolid() const;
  326. /**
  327. * Sets the entity talk radius.
  328. *
  329. * The talk radius is the maximum distance at which an entity can be
  330. * talked to or interacted with.
  331. *
  332. * @param[in] radius The talk radius.
  333. * @todo Is it in pixels?
  334. */
  335. void SetTalkRadius(const float radius);
  336. /**
  337. * Retrieves the entity talk radius.
  338. *
  339. * The talk radius is the maximum distance at which an entity can be
  340. * talked to or interacted with.
  341. *
  342. * @return The talk radius.
  343. * @todo Is it in pixels?
  344. */
  345. float GetTalkRadius() const;
  346. /**
  347. * Sets an entity as talkable or non-talkable.
  348. *
  349. * Talkable units can be talked to or interacted with.
  350. *
  351. * @param[in] talkable True to make the entity talkable, false to make
  352. * it non-talkable.
  353. */
  354. void SetTalkable(const bool talkable);
  355. /**
  356. * Checks if an entity is talkable or non-talkable.
  357. *
  358. * Talkable units can be talked to or interacted with.
  359. *
  360. * @return True if the entity is talkable, false if it's not.
  361. */
  362. bool IsTalkable() const;
  363. /**
  364. * Makes the entity visible or invisible.
  365. *
  366. * Invisible entities can't be interacted with.
  367. *
  368. * @param[in] visible True to make the unit visible, false to make it
  369. * invisible.
  370. */
  371. virtual void SetVisible(const bool visible) = 0;
  372. /**
  373. * Checks if the entity is visible or invisible.
  374. *
  375. * Invisible entities can't be interacted with.
  376. *
  377. * @return True if the unit is visible, false if it's invisible.
  378. */
  379. virtual bool IsVisible() const = 0;
  380. /**
  381. * Sets the entity's state.
  382. *
  383. * @param[in] state The entity's state.
  384. */
  385. void SetState(const State state);
  386. /**
  387. * Retrieves the entity's state.
  388. *
  389. * @return The entity's state.
  390. */
  391. State GetState() const;
  392. /**
  393. * Sets the entity's automatic movement speed.
  394. *
  395. * @param[in] speed Automatic movement speed.
  396. * @todo Describe where this speed is used, and max and mins or
  397. * references.
  398. */
  399. void SetMoveAutoSpeed(const float speed);
  400. /**
  401. * Retrieves the entity's automatic movement speed.
  402. *
  403. * @return Automatic movement speed.
  404. * @todo Describe where this speed is used, and max and mins or
  405. * references.
  406. */
  407. float GetMoveAutoSpeed() const;
  408. /**
  409. * Sets the entity's walking movement speed.
  410. *
  411. * @param[in] speed Walking speed.
  412. * @todo Describe where this speed is used, and max and mins or
  413. * references.
  414. */
  415. void SetMoveWalkSpeed(const float speed);
  416. /**
  417. * Retrieves the entity's walking speed.
  418. *
  419. * @return Walking speed.
  420. * @todo Describe where this speed is used, and max and mins or
  421. * references.
  422. */
  423. float GetMoveWalkSpeed() const;
  424. /**
  425. * Sets the entity's running movement speed.
  426. *
  427. * @param[in] speed Running speed.
  428. * @todo Describe where this speed is used, and max and mins or
  429. * references.
  430. */
  431. void SetMoveRunSpeed(const float speed);
  432. /**
  433. * Retrieves the entity's running speed.
  434. *
  435. * @return Running speed.
  436. * @todo Describe where this speed is used, and max and mins or
  437. * references.
  438. */
  439. float GetMoveRunSpeed() const;
  440. /**
  441. * Sets the entity's movement destination position.
  442. *
  443. * @param[in] target The destination position.
  444. */
  445. void SetMovePosition(const Ogre::Vector3& target);
  446. /**
  447. * Retrieves the entity's movement destination position.
  448. *
  449. * @return The destination position.
  450. */
  451. const Ogre::Vector3& GetMovePosition() const;
  452. /**
  453. * Retrieves the distance to destination.
  454. *
  455. * It's the distance between the entity's current position and it's
  456. * current movement destination point.
  457. *
  458. * @return The distance to destination.
  459. * @todo Verify this description. Also, indicate units (pixels?).
  460. */
  461. float GetMoveStopDistance() const;
  462. /**
  463. * Sets the destination triangle in the walkmesh.
  464. *
  465. * Sets the units destination to one of the walkmesh triangles. The
  466. * movement will stop once the unit enters the triangle.
  467. *
  468. * @param[in] triangle Destination triangle in the walkmesh.
  469. */
  470. void SetMoveTriangleId(const int triangle);
  471. /**
  472. * Sets the destination triangle in the walkmesh.
  473. *
  474. * @return Destination triangle in the walkmesh.
  475. */
  476. int GetMoveTriangleId() const;
  477. /**
  478. * Enables or disables autorotation while the entity is moving.
  479. *
  480. * @param[in] rotate If true, the entity will rotate automatically
  481. * while moving. If false, the entity will not rotate.
  482. */
  483. void SetMoveAutoRotation(const bool rotate);
  484. /**
  485. * Checks if the unit can autorotate while it's moving.
  486. *
  487. * @return If true, the entity will rotate automatically while moving.
  488. * If false, the entity will not rotate.
  489. */
  490. bool GetMoveAutoRotation() const;
  491. /**
  492. * Enables or disables autoanimation while the entity is moving.
  493. *
  494. * @param[in] animate If true, the entity will animate automatically
  495. * while moving. If false, the entity will not animate.
  496. */
  497. void SetMoveAutoAnimation(const bool animate);
  498. /**
  499. * Checks if the unit can autoanimate while it's moving.
  500. *
  501. * @return If true, the entity will animate automatically while moving.
  502. * If false, the entity will not animate.
  503. */
  504. bool GetMoveAutoAnimation() const;
  505. /**
  506. * Retrieves the entity's walk animation name.
  507. *
  508. * @return The walk animation name.
  509. */
  510. const Ogre::String& GetMoveAnimationWalkName() const;
  511. /**
  512. * Retrieves the entity's run animation name.
  513. *
  514. * @return The run animation name.
  515. */
  516. const Ogre::String& GetMoveAnimationRunName() const;
  517. /**
  518. * Makes the entity move to a point in the map.
  519. *
  520. * @param[in] x X coordinate of the destination point.
  521. * @param[in] y Y coordinate of the destination point.
  522. */
  523. void ScriptMoveToPosition(const float x, const float y);
  524. /**
  525. * Makes the unit move towards another in the map.
  526. *
  527. * @param[in] entity entity to move towards.
  528. */
  529. void ScriptMoveToEntity(Entity* entity);
  530. /**
  531. * Waits for entity's movement to end.
  532. *
  533. * @return Always -1.
  534. */
  535. int ScriptMoveSync();
  536. /**
  537. * Waits for the jump to finish.
  538. *
  539. * @return Always -1.
  540. */
  541. int ScriptJumpSync();
  542. /**
  543. * Cancels the entity's current movement.
  544. *
  545. * It also clears the movement sync queue.
  546. */
  547. void UnsetMove();
  548. /**
  549. * Linearly moves the entity.
  550. *
  551. * @param[in] x X coordinate of the destination point.
  552. * @param[in] y Y coordinate of the destination point.
  553. * @param[in] z Z coordinate of the destination point.
  554. * @param[in] movement Movement direction.
  555. * @param[in] animation Movement animation.
  556. * @param[in] orientation Orientation during the animation.
  557. * @param[in] dest_triangle Triangle to place the entity after the
  558. * linear movement.
  559. */
  560. void ScriptLinearToPosition(
  561. const float x, const float y, const float z, const LinearMovement movement,
  562. const char* animation, const float orientation, const int dest_triangle
  563. );
  564. /**
  565. * Adds the unit linear movement to the sync queue.
  566. *
  567. * @return Always -1.
  568. * @todo Properly describe this.
  569. */
  570. int ScriptLinearSync();
  571. /**
  572. * Linearly moves the entity.
  573. *
  574. * @param[in] end Destination point.
  575. * @param[in] movement Movement direction.
  576. * @param[in] animation Movement animation.
  577. * @param[in] orientation Orientation during the animation.
  578. * @param[in] dest_triangle Triangle to place the entity after the
  579. * linear movement.
  580. */
  581. void SetLinear(
  582. const Ogre::Vector3& end, const LinearMovement movement,
  583. const Ogre::String& animation, const float orientation, const int dest_triangle
  584. );
  585. /**
  586. * Cancels the entity's current linear movement.
  587. *
  588. * It also clears the movement sync queue.
  589. */
  590. void UnsetLinear();
  591. /**
  592. * Retrieves the entity's current linear movement.
  593. *
  594. * @return Current linear movement.
  595. */
  596. LinearMovement GetLinearMovement() const;
  597. /**
  598. * Retrieves the starting point of the current linear movement.
  599. *
  600. * @return Starting point.
  601. */
  602. const Ogre::Vector3& GetLinearStart() const;
  603. /**
  604. * Retrieves the ending point of the current linear movement.
  605. *
  606. * @return Ending point.
  607. */
  608. const Ogre::Vector3& GetLinearEnd() const;
  609. /**
  610. * Retrieves the ending triangle of the current linear movement.
  611. *
  612. * @return Ending triangle.
  613. */
  614. const int GetLinearDestTriangle() const;
  615. /**
  616. * Makes the unit jump to a point in the field.
  617. *
  618. * @param[in] x X coordinate of the jump destination point.
  619. * @param[in] y Y coordinate of the jump destination point.
  620. * @param[in] z Maximum height of the jump.
  621. * @param[in] seconds Jump duration.
  622. * @param[in] dest_triangle Triangle to place the entity after the
  623. * jump.
  624. */
  625. void ScriptJumpToPosition(
  626. const float x, const float y, const float z, const float seconds, const int dest_triangle
  627. );
  628. /**
  629. * Makes the unit jump to a point in the field.
  630. *
  631. * @param[in] jump_to The jump destination point.
  632. * @param[in] seconds Jump duration.
  633. * @param[in] dest_triangle Triangle to place the entity after the
  634. * jump.
  635. */
  636. void SetJump(const Ogre::Vector3& jump_to, const float seconds, const int dest_triangle);
  637. /**
  638. * Cancels the entity's current jump.
  639. *
  640. * It also clears the movement sync queue.
  641. */
  642. void UnsetJump();
  643. /**
  644. * Retrieves the starting point of the current jump.
  645. *
  646. * @return Starting point.
  647. */
  648. const Ogre::Vector3& GetJumpStart() const;
  649. /**
  650. * Retrieves the ending point of the current jump.
  651. *
  652. * @return Ending point.
  653. */
  654. const Ogre::Vector3& GetJumpEnd() const;
  655. /**
  656. * Gets the total duration of the jump.
  657. *
  658. * @return Jump total duration, in seconds.
  659. */
  660. float GetJumpSeconds() const;
  661. /**
  662. * Sets the current duration of the jump.
  663. *
  664. * @param[in] seconds Jump current duration, in seconds.
  665. */
  666. void SetJumpCurrentSeconds(const float seconds);
  667. /**
  668. * Gets the current duration of the jump.
  669. *
  670. * @return Jump current duration, in seconds.
  671. */
  672. float GetJumpCurrentSeconds() const;
  673. /**
  674. * Retrieves the ending triangle of the current jump.
  675. *
  676. * @return Ending triangle.
  677. */
  678. const int GetJumpDestTriangle() const;
  679. /**
  680. * @todo Understand and document.
  681. *
  682. * @param[in] x X coordinate of the destination point.
  683. * @param[in] y Y coordinate of the destination point.
  684. * @param[in] z Z coordinate of the destination point.
  685. * @param[in] type Type of action.
  686. * @param[in] seconds Duration of the action, in seconds.
  687. */
  688. void ScriptOffsetToPosition(
  689. const float x, const float y, const float z,
  690. const ActionType type, const float seconds
  691. );
  692. /**
  693. * @todo Understand and document.
  694. *
  695. * @return Always -1.
  696. */
  697. int ScriptOffsetSync();
  698. /**
  699. * @todo Understand and document.
  700. */
  701. void UnsetOffset();
  702. /**
  703. * @todo Understand and document.
  704. *
  705. * @return Starting position.
  706. */
  707. const Ogre::Vector3& GetOffsetPositionStart() const;
  708. /**
  709. * @todo Understand and document.
  710. *
  711. * @return Ending position.
  712. */
  713. const Ogre::Vector3& GetOffsetPositionEnd() const;
  714. /**
  715. * @todo Understand and document.
  716. *
  717. * @return The action type.
  718. */
  719. ActionType GetOffsetType() const;
  720. /**
  721. * @todo Understand and document.
  722. *
  723. * @return Action total duration in seconds.
  724. */
  725. float GetOffsetSeconds() const;
  726. /**
  727. * @todo Understand and document.
  728. *
  729. * @param[in] seconds Action current duration in seconds.
  730. */
  731. void SetOffsetCurrentSeconds(const float seconds);
  732. /**
  733. * @todo Understand and document.
  734. *
  735. * @return Action current duration in seconds.
  736. */
  737. float GetOffsetCurrentSeconds() const;
  738. /**
  739. * Makes the entity turn to a fixed direction.
  740. *
  741. * @param[in] direction Final direction to turn the entity's to.
  742. * @param[in] turn_direction Direction of the turn.
  743. * @param[in] turn_type Turn mode.
  744. * @param[in] seconds Total turn duration, in seconds.
  745. */
  746. void ScriptTurnToDirection(
  747. const float direction, const TurnDirection turn_direction,
  748. const ActionType turn_type, const float seconds
  749. );
  750. /**
  751. * Makes the entity turn towards another entity.
  752. *
  753. * @param[in] entity Entity to turn to.
  754. * @param[in] turn_direction Direction of the turn.
  755. * @param[in] seconds Total turn duration, in seconds.
  756. */
  757. void ScriptTurnToEntity(
  758. Entity* entity, const TurnDirection turn_direction,
  759. const float seconds
  760. );
  761. /**
  762. * Adds the entity's turn to the sync queue.
  763. *
  764. * @return Always -1.
  765. * @todo Properly describe this.
  766. */
  767. int ScriptTurnSync();
  768. /**
  769. * Makes the entity turn towards a point or another entity.
  770. *
  771. * @param[in] direction_to Final direction to turn the entity's to.
  772. * @param[in] entity Entity to turn to.
  773. * @param[in] turn_direction Direction of the turn.
  774. * @param[in] turn_type Turn mode.
  775. * @param[in] seconds Total turn duration, in seconds.
  776. * @todo What if the point
  777. */
  778. void SetTurn(
  779. const Ogre::Degree& direction_to, Entity* entity, const TurnDirection turn_direction,
  780. const ActionType turn_type, const float seconds
  781. );
  782. /**
  783. * Cancels the entity's current jump.
  784. *
  785. * It also clears the movement sync queue.
  786. */
  787. void UnsetTurn();
  788. /**
  789. * Calculates the turn angle.
  790. *
  791. * If the turn direction is {@see TD_CLOSEST}, the result is the
  792. * smallest angle between the two orientations. Otherwise, is the angle
  793. * in the specified turn direction.
  794. *
  795. * @param[in] start Starting angle.
  796. * @param[in] end Ending angle.
  797. * @return[in] Calculated turn angle.
  798. */
  799. Ogre::Degree CalculateTurnAngle(const Ogre::Degree& start, const Ogre::Degree& end) const;
  800. /**
  801. * Retrieves the turn staring orientation.
  802. *
  803. * @return The turn starting orientation.
  804. */
  805. Ogre::Degree GetTurnDirectionStart() const;
  806. /**
  807. * Retrieves the turn ending orientation.
  808. *
  809. * @return The turn ending orientation.
  810. */
  811. Ogre::Degree GetTurnDirectionEnd() const;
  812. /**
  813. * Retrieves the turn type.
  814. *
  815. * @return The turn type.
  816. */
  817. ActionType GetTurnType() const;
  818. /**
  819. * Retrieves the turn total duration.
  820. *
  821. * @return The turn total duration, in seconds.
  822. */
  823. float GetTurnSeconds() const;
  824. /**
  825. * Sets the turn current duration.
  826. *
  827. * @param[in] seconds The turn current duration, in seconds.
  828. */
  829. void SetTurnCurrentSeconds(const float seconds);
  830. /**
  831. * Retrieves the turn current duration.
  832. *
  833. * @return The turn current duration, in seconds.
  834. */
  835. float GetTurnCurrentSeconds() const;
  836. /**
  837. * Sets the animation speed.
  838. *
  839. * @param[in] speed The animation speed.
  840. * @todo Indicate units, max and mins, or references.
  841. */
  842. void ScriptSetAnimationSpeed(const float speed);
  843. /**
  844. * Retrieves the entity's default animation name.
  845. *
  846. * @return The default animation name.
  847. */
  848. const Ogre::String& GetDefaultAnimationName() const;
  849. /**
  850. * Retrieves the entity's current animation name.
  851. *
  852. * @return The current animation name.
  853. */
  854. const Ogre::String& GetCurrentAnimationName() const;
  855. /**
  856. * Retrieves the entity's current animation state.
  857. *
  858. * @return The current animation state.
  859. */
  860. AnimationState GetAnimationState() const;
  861. /**
  862. * Plays one of the entity's animations.
  863. *
  864. * @param[in] animation Name of the animation to play.
  865. * @param[in] state The animation initial state.
  866. * @param[in] play_type The animation play type, to play it once or in
  867. * a loop.
  868. * @param[in] start Animation starting point in time, in seconds.
  869. * @param[in] end Animation ending point in time, in seconds.
  870. */
  871. virtual void PlayAnimation(
  872. const Ogre::String& animation, AnimationState state,
  873. AnimationPlayType play_type, const float start, const float end
  874. ) = 0;
  875. /**
  876. * Resumes an animation.
  877. *
  878. * @param[in] animation Name of the animation to resume.
  879. */
  880. virtual void PlayAnimationContinue(const Ogre::String& animation) = 0;
  881. /**
  882. * Updates the animation state.
  883. *
  884. * @param[in] delta The animation delta.
  885. */
  886. virtual void UpdateAnimation(const float delta) = 0;
  887. /**
  888. * Plays one of the entity's animations.
  889. *
  890. * @param[in] name Name of the animation to play.
  891. */
  892. void ScriptPlayAnimation(const char* name);
  893. /**
  894. * Stops one of the entity's animations.
  895. *
  896. * @param[in] name Name of the animation to stop.
  897. */
  898. void ScriptPlayAnimationStop(const char* name);
  899. /**
  900. * Plays one of the entity's animations.
  901. *
  902. * @param[in] name Name of the animation to play.
  903. * @param[in] start Animation starting point in time, in seconds.
  904. * @param[in] end Animation ending point in time, in seconds.
  905. */
  906. void ScriptPlayAnimation(const char* name, const float start, const float end);
  907. /**
  908. * Stops one of the entity's animations.
  909. *
  910. * @param[in] name Name of the animation to stop.
  911. * @param[in] start Animation starting point in time, in seconds.
  912. * @param[in] end Animation ending point in time, in seconds.
  913. */
  914. void ScriptPlayAnimationStop(const char* name, const float start, const float end);
  915. /**
  916. * Sets the default animation of the entity.
  917. *
  918. * @param[in] animation Name of the default animation.
  919. */
  920. void ScriptSetDefaultAnimation(const char* animation);
  921. /**
  922. * Adds the entity's animation to the sync queue.
  923. *
  924. * @return Always -1.
  925. * @todo Properly describe this.
  926. */
  927. int ScriptAnimationSync();
  928. /**
  929. * Assigns the entity as a character.
  930. *
  931. * Marks the entity as a character, and assigns a character name and ID. If the ID is
  932. * passed as a negative number, the entity will no longer be considered a character.
  933. *
  934. * @param[in] char_id The character name.
  935. */
  936. void SetCharacter(int char_id);
  937. /**
  938. * Checks if the entity is a character.
  939. *
  940. * An entity is not a character until {@see SetCharacter} has been called.
  941. *
  942. * @return True if the entity is a character, false otherwise.
  943. */
  944. bool IsCharacter();
  945. /**
  946. * Retrieves the entity's character ID.
  947. *
  948. * @return The character ID, or a negative value if the entity is not a character.
  949. */
  950. int GetCharacterId();
  951. /**
  952. * Checks if the entity is a line.
  953. *
  954. * @return True if the entity is a line, false otherwise.
  955. */
  956. bool IsLine();
  957. protected:
  958. /**
  959. * The name of the entity.
  960. */
  961. Ogre::String name_;
  962. /**
  963. * The scene node the entity is attached to.
  964. */
  965. Ogre::SceneNode* scene_node_;
  966. /**
  967. * The entity's model.
  968. */
  969. Ogre::SceneNode* model_node_;
  970. /**
  971. * The entity's root node.
  972. */
  973. Ogre::SceneNode* model_root_node_;
  974. /**
  975. * The entity's height.
  976. */
  977. float height_;
  978. /**
  979. * The entity's direction node.
  980. */
  981. Ogre::SceneNode* direction_node_;
  982. /**
  983. * The entity's direction.
  984. */
  985. EntityDirection* direction_;
  986. /**
  987. * The entity's collision node.
  988. */
  989. Ogre::SceneNode* solid_collision_node_;
  990. /**
  991. * The entity's collision.
  992. */
  993. EntityCollision* solid_collision_;
  994. /**
  995. * The entity's solid radius.
  996. */
  997. float solid_radius_;
  998. /**
  999. * Indicates it the entity is solid and can handle collisions.
  1000. */
  1001. bool solid_;
  1002. /**
  1003. * The entity's talk collision node.
  1004. */
  1005. Ogre::SceneNode* talk_collision_node_;
  1006. /**
  1007. * The entity's talk collision.
  1008. */
  1009. EntityCollision* talk_collision_;
  1010. /**
  1011. * The radius at which the entity can be interacted with.
  1012. */
  1013. float talk_radius_;
  1014. /**
  1015. * Indicates if the entity can be interacted with.
  1016. */
  1017. bool talkable_;
  1018. /**
  1019. * Entity's movement status.
  1020. */
  1021. State state_;
  1022. /**
  1023. * Entity's movement sync queue.
  1024. */
  1025. std::vector<ScriptId> sync_;
  1026. /**
  1027. * The entity's automatic movement speed.
  1028. */
  1029. float move_auto_speed_;
  1030. /**
  1031. * The entity's walking speed.
  1032. */
  1033. float move_walk_speed_;
  1034. /**
  1035. * The entity's running speed.
  1036. */
  1037. float move_run_speed_;
  1038. /**
  1039. * The entity's movement destination point.
  1040. */
  1041. Ogre::Vector3 move_position_;
  1042. /**
  1043. * The entity's movement destination entity.
  1044. */
  1045. Entity* move_entity_;
  1046. /**
  1047. * Distance between the entity and it's movement destination point.
  1048. */
  1049. float move_stop_distance_;
  1050. /**
  1051. * Entity's movement destination triangle ID.
  1052. */
  1053. int move_triangle_id_;
  1054. /**
  1055. * Indicates if the entity can rotate while moving.
  1056. */
  1057. bool move_auto_rotation_;
  1058. /**
  1059. * Indicates if the entity can animate while moving.
  1060. */
  1061. bool move_auto_animation_;
  1062. /**
  1063. * The name of the entity's walk animation.
  1064. */
  1065. Ogre::String move_animation_walk_;
  1066. /**
  1067. * The name of the entity's run animation.
  1068. */
  1069. Ogre::String move_animation_run_;
  1070. /**
  1071. * The entity's linear movement direction.
  1072. */
  1073. LinearMovement linear_movement_;
  1074. /**
  1075. * The linear movement starting point.
  1076. */
  1077. Ogre::Vector3 linear_start_;
  1078. /**
  1079. * The linear movement ending point.
  1080. */
  1081. Ogre::Vector3 linear_end_;
  1082. /**
  1083. * Triangle to set the entity on after a linear movement.
  1084. */
  1085. int linear_dest_triangle_;
  1086. /**
  1087. * The jump starting point.
  1088. */
  1089. Ogre::Vector3 jump_start_;
  1090. /**
  1091. * The jump ending point.
  1092. */
  1093. Ogre::Vector3 jump_end_;
  1094. /**
  1095. * Total jump duration.
  1096. */
  1097. float jump_seconds_;
  1098. /**
  1099. * Current jump duration.
  1100. */
  1101. float jump_current_seconds_;
  1102. /**
  1103. * Used to store solidity status before a jump.
  1104. */
  1105. bool jump_was_solid_;
  1106. /**
  1107. * Triangle to set the entity on after a jump.
  1108. */
  1109. int jump_dest_triangle_;
  1110. /**
  1111. * @todo Understand and document.
  1112. */
  1113. Ogre::Vector3 offset_position_start_;
  1114. /**
  1115. * @todo Understand and document.
  1116. */
  1117. Ogre::Vector3 offset_position_end_;
  1118. /**
  1119. * @todo Understand and document.
  1120. */
  1121. ActionType offset_type_;
  1122. /**
  1123. * @todo Understand and document.
  1124. */
  1125. float offset_seconds_;
  1126. /**
  1127. * @todo Understand and document.
  1128. */
  1129. float offset_current_seconds_;
  1130. /**
  1131. * @todo Understand and document.
  1132. */
  1133. std::vector<ScriptId> offset_sync_;
  1134. /**
  1135. * Turn movement direction.
  1136. */
  1137. TurnDirection turn_direction_;
  1138. /**
  1139. * Turn initial orientation.
  1140. */
  1141. Ogre::Degree turn_direction_start_;
  1142. /**
  1143. * Turn final orientation.
  1144. */
  1145. Ogre::Degree turn_direction_end_;
  1146. /**
  1147. * The turn destination entity.
  1148. */
  1149. Entity* turn_entity_;
  1150. /**
  1151. * The turn type.
  1152. */
  1153. ActionType turn_type_;
  1154. /**
  1155. * Total turn duration.
  1156. */
  1157. float turn_seconds_;
  1158. /**
  1159. * Current turn duration.
  1160. */
  1161. float turn_current_seconds_;
  1162. /**
  1163. * Entity's turning sync queue.
  1164. */
  1165. std::vector<ScriptId> turn_sync_;
  1166. /**
  1167. * The animation speed.
  1168. */
  1169. float animation_speed_;
  1170. /**
  1171. * The entity's current animation name.
  1172. */
  1173. Ogre::String animation_current_name_;
  1174. /**
  1175. * Entity's animation sync queue.
  1176. */
  1177. std::vector<ScriptId> animation_sync_;
  1178. /**
  1179. * The entity's current animation state.
  1180. */
  1181. AnimationState animation_state_;
  1182. /**
  1183. * The entity's current animation type.
  1184. */
  1185. AnimationPlayType animation_play_type_;
  1186. /**
  1187. * The name of the entity's default name.
  1188. */
  1189. Ogre::String animation_default_;
  1190. /**
  1191. * @todo Understand and document.
  1192. */
  1193. float animation_end_time_;
  1194. /**
  1195. * Indicates if an automation must be played automatically.
  1196. */
  1197. bool animation_auto_play_;
  1198. private:
  1199. /**
  1200. * Constructor.
  1201. */
  1202. Entity();
  1203. /**
  1204. * Calculates the angular distance to an entity.
  1205. *
  1206. * @param[in] entity Entity to calculate the angular distance to.
  1207. * @return Angular distance to the specified entity.
  1208. */
  1209. Ogre::Degree GetDirectionToEntity(Entity* entity) const;
  1210. /**
  1211. * Indicates if the entity is a playable character.
  1212. */
  1213. bool is_character_;
  1214. /**
  1215. * The ID of the playable character the entity is, if any.
  1216. */
  1217. int character_id_;
  1218. /**
  1219. * Index of the entity on the field.
  1220. */
  1221. int index_;
  1222. /**
  1223. * Indicates if the entity is a line.
  1224. */
  1225. bool is_line_;
  1226. };