Entity.h 39 KB

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