Entity.h 36 KB

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