EntityManager.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef ENTITY_MANAGER_H
  2. #define ENTITY_MANAGER_H
  3. #include <OgreSingleton.h>
  4. #include "Background2D.h"
  5. #include "Entity.h"
  6. #include "EntityPoint.h"
  7. #include "EntityTrigger.h"
  8. #include "Event.h"
  9. #include "Walkmesh.h"
  10. class EntityManager : public Ogre::Singleton< EntityManager >
  11. {
  12. public:
  13. EntityManager();
  14. virtual ~EntityManager();
  15. void Input(const QGears::Event& event);
  16. void Update();
  17. void UpdateDebug();
  18. void OnResize();
  19. void Clear();
  20. void ScriptSetPaused( const bool paused );
  21. Walkmesh* GetWalkmesh();
  22. Background2D* GetBackground2D();
  23. void AddEntity( const Ogre::String& name, const Ogre::String& file_name, const Ogre::Vector3& position, const Ogre::Degree& direction );
  24. void AddEntity( const Ogre::String& name, const Ogre::String& file_name, const Ogre::Vector3& position, const Ogre::Degree& rotation, const Ogre::Vector3& scale, const Ogre::Quaternion& root_orientation );
  25. void ScriptAddEntity( const char* name, const char* file_name, const float x, const float y, const float z, const float direction );
  26. void AddEntityTrigger( const Ogre::String& name, const Ogre::Vector3& point1, const Ogre::Vector3& point2, const bool enabled );
  27. void AddEntityPoint( const Ogre::String& name, const Ogre::Vector3& position, const float rotation );
  28. void AddEntityScript( const Ogre::String& name );
  29. void ScriptAddEntityScript( const char* name );
  30. Entity* GetEntity( const Ogre::String& name ) const;
  31. Entity* ScriptGetEntity( const char* name ) const;
  32. EntityPoint* ScriptGetEntityPoint( const char* name ) const;
  33. void ScriptSetPlayerEntity( const char* name );
  34. void ScriptUnsetPlayerEntity();
  35. void ScriptPlayerLock( const bool lock );
  36. void SetPlayerMoveRotation( const Ogre::Radian rotation );
  37. /**
  38. * Checks if random battle encounters are active in the field.
  39. *
  40. * @return True random battles can occur, false otherwise.
  41. */
  42. bool GetRandomEncounters();
  43. /**
  44. * Enables or disables random encounters in the field.
  45. *
  46. * @param active[in] True to enable encounters, false to deactivate
  47. * them.
  48. */
  49. void SetRandomEncounters(bool active);
  50. /**
  51. * Get the encounter rate for the field.
  52. *
  53. * @return The encounter rate, between 0 and 1 (both included).
  54. */
  55. float GetEncounterRate();
  56. /**
  57. * Sets the battle encounter rate.
  58. *
  59. * @param rate[in] The encounter rate (max. 1).
  60. */
  61. void SetEncounterRate(float rate);
  62. /**
  63. * Starts a battle.
  64. *
  65. * @TODO
  66. * @param formation[in] The enemy formation to fight.
  67. * @return True if the battle victory conditions are met, false\
  68. * otherwise.
  69. */
  70. //bool StartBattle(unsigned int formation);
  71. void StartBattle(unsigned int formation);
  72. private:
  73. // movement
  74. bool SetEntityOnWalkmesh( Entity* entity );
  75. bool PerformWalkmeshMove( Entity* entity, const float speed );
  76. bool WalkmeshBorderCross( Entity* entity, Ogre::Vector3& position, const Ogre::Vector2& move_vector );
  77. bool CheckSolidCollisions( Entity* entity, Ogre::Vector3& position );
  78. void SetEntityDirectionByVector( Entity* entity, const Ogre::Vector2& vector );
  79. void CheckTriggers( Entity* entity, Ogre::Vector3& position );
  80. void CheckEntityInteract();
  81. void SetNextOffsetStep( Entity* entity );
  82. void SetNextTurnStep( Entity* entity );
  83. void SetNextLinearStep( Entity* entity );
  84. void SetNextJumpStep( Entity* entity );
  85. void SetNextScrollStep();
  86. private:
  87. bool m_Paused;
  88. Walkmesh m_Walkmesh;
  89. Background2D m_Background2D;
  90. Ogre::String m_EntityTableName;
  91. std::vector< Entity* > m_Entity;
  92. Entity* m_PlayerEntity;
  93. Ogre::Vector3 m_PlayerMove;
  94. Ogre::Radian m_PlayerMoveRotation;
  95. bool m_PlayerLock;
  96. bool m_PlayerRun;
  97. std::vector< EntityTrigger* > m_EntityTriggers;
  98. std::vector< EntityPoint* > m_EntityPoints;
  99. std::vector< Ogre::String > m_EntityScripts;
  100. Ogre::SceneNode* m_SceneNode;
  101. Ogre::Entity* m_Grid;
  102. Ogre::Entity* m_Axis;
  103. // TODO battle formations
  104. bool random_encounters_;
  105. float encounter_rate_;
  106. };
  107. #endif // ENTITY_MANAGER_H