Entity.h 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  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. protected:
  875. /**
  876. * The name of the entity.
  877. */
  878. Ogre::String name_;
  879. /**
  880. * The scene node the entity is attached to.
  881. */
  882. Ogre::SceneNode* scene_node_;
  883. /**
  884. * The entity's model.
  885. */
  886. Ogre::SceneNode* model_node_;
  887. /**
  888. * The entity's root node.
  889. */
  890. Ogre::SceneNode* model_root_node_;
  891. /**
  892. * The entity's height.
  893. */
  894. float height_;
  895. /**
  896. * The entity's direction node.
  897. */
  898. Ogre::SceneNode* direction_node_;
  899. /**
  900. * The entity's direction.
  901. */
  902. EntityDirection* direction_;
  903. /**
  904. * The entity's collision node.
  905. */
  906. Ogre::SceneNode* solid_collision_node_;
  907. /**
  908. * The entity's collision.
  909. */
  910. EntityCollision* solid_collision_;
  911. /**
  912. * The entity's solid radius.
  913. */
  914. float solid_radius_;
  915. /**
  916. * Indicates it the entity is solid and can handle collisions.
  917. */
  918. bool solid_;
  919. /**
  920. * The entity's talk collision node.
  921. */
  922. Ogre::SceneNode* talk_collision_node_;
  923. /**
  924. * The entity's talk collision.
  925. */
  926. EntityCollision* talk_collision_;
  927. /**
  928. * The radius at which the entity can be interacted with.
  929. */
  930. float talk_radius_;
  931. /**
  932. * Indicates if the entity can be interacted with.
  933. */
  934. bool talkable_;
  935. /**
  936. * Entity's movement status.
  937. */
  938. State state_;
  939. /**
  940. * Entity's movement sync queue.
  941. */
  942. std::vector<ScriptId> sync_;
  943. /**
  944. * The entity's automatic movement speed.
  945. */
  946. float move_auto_speed_;
  947. /**
  948. * The entity's walking speed.
  949. */
  950. float move_walk_speed_;
  951. /**
  952. * The entity's running speed.
  953. */
  954. float move_run_speed_;
  955. /**
  956. * The entity's movement destination point.
  957. */
  958. Ogre::Vector3 move_position_;
  959. /**
  960. * The entity's movement destination entity.
  961. */
  962. Entity* move_entity_;
  963. /**
  964. * Distance between the entity and it's movement destination point.
  965. */
  966. float move_stop_distance_;
  967. /**
  968. * Entity's movement destination triangle ID.
  969. */
  970. int move_triangle_id_;
  971. /**
  972. * Indicates if the entity can rotate while moving.
  973. */
  974. bool move_auto_rotation_;
  975. /**
  976. * Indicates if the entity can animate while moving.
  977. */
  978. bool move_auto_animation_;
  979. /**
  980. * The name of the entity's walk animation.
  981. */
  982. Ogre::String move_animation_walk_;
  983. /**
  984. * The name of the entity's run animation.
  985. */
  986. Ogre::String move_animation_run_;
  987. /**
  988. * The entity's linear movement direction.
  989. */
  990. LinearMovement linear_movement_;
  991. /**
  992. * The linear movement starting point.
  993. */
  994. Ogre::Vector3 linear_start_;
  995. /**
  996. * The linear movement ending point.
  997. */
  998. Ogre::Vector3 linear_end_;
  999. /**
  1000. * The jump starting point.
  1001. */
  1002. Ogre::Vector3 jump_start_;
  1003. /**
  1004. * The jump ending point.
  1005. */
  1006. Ogre::Vector3 jump_end_;
  1007. /**
  1008. * Total jump duration.
  1009. */
  1010. float jump_seconds_;
  1011. /**
  1012. * Current jump duration.
  1013. */
  1014. float jump_current_seconds_;
  1015. /**
  1016. * @todo Understand and document.
  1017. */
  1018. Ogre::Vector3 offset_position_start_;
  1019. /**
  1020. * @todo Understand and document.
  1021. */
  1022. Ogre::Vector3 offset_position_end_;
  1023. /**
  1024. * @todo Understand and document.
  1025. */
  1026. ActionType offset_type_;
  1027. /**
  1028. * @todo Understand and document.
  1029. */
  1030. float offset_seconds_;
  1031. /**
  1032. * @todo Understand and document.
  1033. */
  1034. float offset_current_seconds_;
  1035. /**
  1036. * @todo Understand and document.
  1037. */
  1038. std::vector<ScriptId> offset_sync_;
  1039. /**
  1040. * Turn movement direction.
  1041. */
  1042. TurnDirection turn_direction_;
  1043. /**
  1044. * Turn initial orientation.
  1045. */
  1046. Ogre::Degree turn_direction_start_;
  1047. /**
  1048. * Turn final orientation.
  1049. */
  1050. Ogre::Degree turn_direction_end_;
  1051. /**
  1052. * The turn destination entity.
  1053. */
  1054. Entity* turn_entity_;
  1055. /**
  1056. * The turn type.
  1057. */
  1058. ActionType turn_type_;
  1059. /**
  1060. * Total turn duration.
  1061. */
  1062. float turn_seconds_;
  1063. /**
  1064. * Current turn duration.
  1065. */
  1066. float turn_current_seconds_;
  1067. /**
  1068. * Entity's turning sync queue.
  1069. */
  1070. std::vector<ScriptId> turn_sync_;
  1071. /**
  1072. * The animation speed.
  1073. */
  1074. float animation_speed_;
  1075. /**
  1076. * The entity's current animation name.
  1077. */
  1078. Ogre::String animation_current_name_;
  1079. /**
  1080. * Entity's animation sync queue.
  1081. */
  1082. std::vector<ScriptId> animation_sync_;
  1083. /**
  1084. * The entity's current animation state.
  1085. */
  1086. AnimationState animation_state_;
  1087. /**
  1088. * The entity's current animation type.
  1089. */
  1090. AnimationPlayType animation_play_type_;
  1091. /**
  1092. * The name of the entity's default name.
  1093. */
  1094. Ogre::String animation_default_;
  1095. /**
  1096. * @todo Understand and document.
  1097. */
  1098. float animation_end_time_;
  1099. /**
  1100. * Indicates if an automation must be played automatically.
  1101. */
  1102. bool animation_auto_play_;
  1103. private:
  1104. /**
  1105. * Constructor.
  1106. */
  1107. Entity();
  1108. /**
  1109. * Calculates the angular distance to an entity.
  1110. *
  1111. * @param entity[in] Entity to calculate the angular distance to.
  1112. * @return Angular distance to the specified entity.
  1113. */
  1114. Ogre::Degree GetDirectionToEntity(Entity* entity) const;
  1115. };