Entity.h 34 KB

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