![]() |
V-Gears 0
Free Final Fantasy VII engine.
|
The entity manager. More...
#include <EntityManager.h>
Public Member Functions | |
EntityManager () | |
Constructor. More... | |
virtual | ~EntityManager () |
Destructor. More... | |
void | Input (const VGears::Event &event) override |
Handles an input event. More... | |
void | UpdateDebug () override |
Updates the entities in the manager with debug information. More... | |
void | OnResize () override |
Handles resizing events. More... | |
void | ClearField () override |
Clears all field information in the entity manager. More... | |
void | ClearBattle () override |
Clears all battle information in the entity manager. More... | |
void | ClearWorld () override |
Clears all world map information in the entity manager. More... | |
Walkmesh * | GetWalkmesh () |
Retrieves the walkmesh. More... | |
Background2D * | GetBackground2D () |
Retrieves the 2D background. More... | |
void | AddEntity (const Ogre::String &name, const Ogre::String &file_name, const Ogre::Vector3 &position, const Ogre::Degree &direction, int index) |
Adds an entity to the manager. More... | |
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, const int index) |
Adds a field entity to the manager. More... | |
void | ScriptAddEntity (const char *name, const char *file_name, const float x, const float y, const float z, const float direction, int index) |
Adds an entity to the manager. More... | |
void | AddEntityTrigger (const Ogre::String &name, const Ogre::Vector3 &point1, const Ogre::Vector3 &point2, const bool enabled) |
Adds an entity trigger to the manager. More... | |
void | AddEntityPoint (const Ogre::String &name, const Ogre::Vector3 &position, const float rotation) |
Adds an entity point to the manager. More... | |
void | AddEntityScript (const Ogre::String &name) |
Adds an entity script to the manager. More... | |
void | ScriptAddEntityScript (const char *name) |
Adds an entity script to the manager. More... | |
Entity * | GetEntity (const Ogre::String &name) const |
Retrieves an entity by name. More... | |
Entity * | GetEntityFromIndex (const int id) const |
Retrieves an entity by it's index in the field. More... | |
Entity * | GetEntityFromCharacterId (const int id) const |
Retrieves an entity by it's assigned character ID. More... | |
Entity * | ScriptGetEntity (const char *name) const |
Retrieves an entity by name. More... | |
EntityPoint * | ScriptGetEntityPoint (const char *name) const |
Retrieves an entity point by name. More... | |
void | ScriptSetPlayerEntity (const char *name) |
Sets the playable entity. More... | |
Entity * | ScriptGetPlayerEntity () const |
Retrieves the playable entity. More... | |
void | ScriptUnsetPlayerEntity () |
Unsets any playable entities. More... | |
void | ScriptPlayerLock (const bool lock) |
Locks or unlocks player control of the playable entity. More... | |
void | SetPlayerMoveRotation (const Ogre::Radian rotation) |
Sets the baseline rotation for the player controlled entity. More... | |
bool | GetRandomEncounters () |
Checks if random battle encounters are active in the field. More... | |
void | SetRandomEncounters (bool active) |
Enables or disables random encounters in the field. More... | |
float | GetEncounterRate () |
Get the encounter rate for the field. More... | |
void | SetEncounterRate (float rate) |
Sets the battle encounter rate. More... | |
bool | IsKeyOn (unsigned int key_code) |
Checks if a key is being pressed. More... | |
bool | IsKeyOff (unsigned int key_code) |
Checks if a key is not being pressed. More... | |
void | SetEntityToCharacter (const char *entity_name, unsigned int char_id) |
Assigns a character to an entity. More... | |
Entity * | GetBackground3D () const |
Retrieves the entity associated to the 3D background. More... | |
void | SetBackground3D (const Ogre::String &name, const Ogre::String &file_name) |
Sets the 3D model for the background. More... | |
![]() | |
Manager () | |
Constructor. More... | |
virtual | ~Manager () |
Destructor. More... | |
Module | GetModule () const |
Retrieves the currently selected module. More... | |
bool | IsModule (const Module module) const |
Checks the currently selected module. More... | |
bool | IsFieldModule () const |
Checks if the currently selected module is the field module. More... | |
bool | IsBattleModule () const |
Checks if the currently selected module is the battle module. More... | |
bool | IsWorldModule () const |
Checks if the currently selected module is the world module. More... | |
void | SetModule (const Module module) |
Sets the current module for the entity manager. More... | |
void | SetFieldModule () |
Sets the current module to the field mode. More... | |
void | SetBattleModule () |
Sets the current module to the battle mode. More... | |
void | SetWorldModule () |
Sets the current module to the world map mode. More... | |
void | SetPreviousModule () |
Sets the module that was loaded before a battle. More... | |
virtual void | Input (const VGears::Event &event)=0 |
Handles an input event. More... | |
void | Update () |
Called every frame, performs an update on the things controlled by the manager. More... | |
virtual void | UpdateDebug ()=0 |
Called every frame, performs an update on the things controlled by the manager. More... | |
virtual void | OnResize ()=0 |
Handles resizing events. More... | |
void | Clear () |
Clears the manager. More... | |
void | Clear (const Module module) |
Clears the manager. More... | |
virtual void | ClearField ()=0 |
Clear all field information in the manager. More... | |
virtual void | ClearBattle ()=0 |
Clear all battle information in the manager. More... | |
virtual void | ClearWorld ()=0 |
Clear all world map information in the manager. More... | |
void | ClearAll () |
Clears the manager. More... | |
void | ScriptSetPaused (const bool paused) |
Handles game pausing. More... | |
Private Member Functions | |
void | UpdateField () override |
Updates the field entities in the manager. More... | |
void | UpdateBattle () override |
Updates the battle entities in the manager. More... | |
void | UpdateWorld () override |
Updates the world map entities in the manager. More... | |
void | AddFieldOrWorldMapEntity (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, const int index) |
Adds a field entity to the manager. More... | |
void | AddBattleEntity (const Ogre::String &name, const Ogre::String &file_name, const Ogre::Vector3 &position, const Ogre::Degree &orientation, const Ogre::Vector3 &scale, const Ogre::Quaternion &root_orientation, const int index) |
Adds a battle entity to the manager. More... | |
bool | SetEntityOnWalkmesh (Entity *entity) |
Attaches an entity to the walkmesh. More... | |
bool | PerformWalkmeshMove (Entity *entity, const float speed) |
Moves an entity in the walkmesh. More... | |
bool | WalkmeshBorderCross (Entity *entity, Ogre::Vector3 &position, const Ogre::Vector2 &move_vector) |
Checks if the entity is crossing a walkmesh triangle border. More... | |
bool | CheckSolidCollisions (Entity *entity, Ogre::Vector3 &position) |
Checks for collisions of the entity with other entities. More... | |
void | SetEntityDirectionByVector (Entity *entity, const Ogre::Vector2 &vector) |
Sets an entity direction. More... | |
void | CheckTriggers (Entity *entity, const Ogre::Vector3 &position) |
Checks for entity triggers near a entity. More... | |
void | CheckEntityInteract () |
Checks if an entity can be interacted. More... | |
void | SetNextOffsetStep (Entity *entity) |
Calculates the next offset step for an entity. More... | |
void | SetNextTurnStep (Entity *entity) |
Calculates the next turn step for an entity. More... | |
void | SetNextLinearStep (Entity *entity) |
Calculates and sets the next position during a linear movement. More... | |
void | SetNextJumpStep (Entity *entity) |
Calculates and sets the next position during a jump. More... | |
void | SetNextScrollStep () |
Static Private Member Functions | |
static float | PointElevation (const Ogre::Vector2 &point, const Ogre::Vector3 &a, const Ogre::Vector3 &b, const Ogre::Vector3 &c) |
Calculates the point elevation over a plane. More... | |
static float | SideOfVector (const Ogre::Vector2 &point, const Ogre::Vector2 &p1, const Ogre::Vector2 &p2) |
Determines at which side of a line a point is. More... | |
static float | SquareDistanceToLine (const Ogre::Vector3 &point, const Ogre::Vector3 &point_a, const Ogre::Vector3 &point_b, Ogre::Vector3 &proj) |
Calculates the square distance between a point and a line. More... | |
static Ogre::Degree | GetDirectionToPoint (const Ogre::Vector3 ¤t_point, const Ogre::Vector3 &direction_point) |
Calculates the direction degree between to points. More... | |
Private Attributes | |
Walkmesh | walkmesh_ |
The map walkmesh. More... | |
Background2D | background_2d_ |
The map background. More... | |
Ogre::String | entity_table_name_ |
The entity table name. More... | |
std::vector< Entity * > | entity_ |
The list of field or world entities. More... | |
std::vector< Entity * > | battle_entity_ |
The list of battle entities. More... | |
Entity * | background_3d_ |
A 3D background. More... | |
Entity * | player_entity_ |
The player controlled entity. More... | |
Ogre::Vector3 | player_move_ |
The playable entity current movement indicator. More... | |
Ogre::Radian | player_move_rotation_ |
The playable entity current movement turn indicator. More... | |
bool | player_lock_ |
Indicates if player control is locked. More... | |
bool | player_run_ |
Indicates if the playable is being moved by running. More... | |
std::vector< EntityTrigger * > | entity_triggers_ |
List of triggers. More... | |
std::vector< EntityPoint * > | entity_points_ |
List of points. More... | |
std::vector< Ogre::String > | entity_scripts_ |
List of scripts. More... | |
Ogre::SceneNode * | scene_node_ |
The scene node. More... | |
Ogre::Entity * | grid_ |
Ogre::Entity * | axis_ |
bool | random_encounters_ |
Indicates if random encounters happen in the map. More... | |
float | encounter_rate_ |
The encounter rate of the map. More... | |
Static Private Attributes | |
static const float | SCENE_SCALE = 0.003f |
Scale factor for battle background models. More... | |
static const unsigned int | BATTLE_BACKGROUND_ID = 1000 |
Entity ID for battle background entity. More... | |
static const unsigned int | WORLD_MAP_BACKGROUND_ID = 1001 |
Entity ID for world map background entity. More... | |
Additional Inherited Members | |
![]() | |
enum | Module { FIELD = 0 , BATTLE = 1 , WORLD = 2 } |
The modules the entity manager can handle. More... | |
![]() | |
virtual void | UpdateField ()=0 |
Updates the field entities in the manager. More... | |
virtual void | UpdateBattle ()=0 |
Updates the battle entities in the manager. More... | |
virtual void | UpdateWorld ()=0 |
Updates the world map entities in the manager. More... | |
void | Update (Module module) |
Updates the entities of one module in the manager. More... | |
![]() | |
Module | module_ |
The currently selected module. More... | |
Module | prev_module_ |
The previous module. More... | |
bool | paused_ |
Indicates if the game is paused. More... | |
The entity manager.
EntityManager::EntityManager | ( | ) |
Constructor.
|
virtual |
Destructor.
|
private |
Adds a battle entity to the manager.
If the manager is not in the battle module, it will do nothing.
void EntityManager::AddEntity | ( | const Ogre::String & | name, |
const Ogre::String & | file_name, | ||
const Ogre::Vector3 & | position, | ||
const Ogre::Degree & | direction, | ||
int | index | ||
) |
Adds an entity to the manager.
The entity will be added to the EntityManager current module entity list.
void EntityManager::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, | ||
const int | index | ||
) |
Adds a field entity to the manager.
The entity will be added to the EntityManager current module entity list.
void EntityManager::AddEntityPoint | ( | const Ogre::String & | name, |
const Ogre::Vector3 & | position, | ||
const float | rotation | ||
) |
void EntityManager::AddEntityScript | ( | const Ogre::String & | name | ) |
Adds an entity script to the manager.
[in] | name | Entity script name. |
void EntityManager::AddEntityTrigger | ( | const Ogre::String & | name, |
const Ogre::Vector3 & | point1, | ||
const Ogre::Vector3 & | point2, | ||
const bool | enabled | ||
) |
Adds an entity trigger to the manager.
A trigger is a line that does something when approached or crossed. If the Battle manager is in battle mode, nothing will be done.
[in] | name | Entity trigger name. |
[in] | point1 | One point of the trigger line. |
[in] | point2 | One point of the trigger line. |
[in] | enabled | True to enable the trigger, false to leave it disabled. |
|
private |
Adds a field entity to the manager.
|
private |
Checks if an entity can be interacted.
It checks if there are entities that can be interacted with from the players current position and orientation. If there are, the most appropriate one is selected and, if it has an on_interact script, it is run. If the manager is in battle mode, it will do nothing.
|
private |
Checks for collisions of the entity with other entities.
[in] | entity | Entity to check for collisions. |
[in] | position | Position of the entity. |
|
private |
Checks for entity triggers near a entity.
If there are triggers, and the conditions are met, the appropriate trigger function will be added to the queue. This must be tested every time an entity moves. If the entity is not the playable character, is not solid or is locked, it will do nothing. If the manager is in battle mode, it will do nothing.
[in] | entity | Entity to check for nearby triggers. |
[in] | position | The position of the entity. |
|
overridevirtual |
Clears all battle information in the entity manager.
It clears any pending actions and all the battle entities.
Implements Manager.
|
overridevirtual |
Clears all field information in the entity manager.
It clears the background, the walkmesh, any pending actions and all the field entities.
Implements Manager.
|
overridevirtual |
Clears all world map information in the entity manager.
It clears the background, the walkmesh, any pending actions and all the world entities.
Implements Manager.
Background2D * EntityManager::GetBackground2D | ( | ) |
Retrieves the 2D background.
Entity * EntityManager::GetBackground3D | ( | ) | const |
Retrieves the entity associated to the 3D background.
|
staticprivate |
Calculates the direction degree between to points.
[in] | current_point | Origin point. |
[in] | direction_point | Next point in the direction. |
float EntityManager::GetEncounterRate | ( | ) |
Get the encounter rate for the field.
Entity * EntityManager::GetEntity | ( | const Ogre::String & | name | ) | const |
Retrieves an entity by name.
Only entities of the current active module will be searched.
[in] | name | Name of the entity to retrieve. |
Entity * EntityManager::GetEntityFromCharacterId | ( | const int | id | ) | const |
Retrieves an entity by it's assigned character ID.
Only entities of the current active module will be searched.
[in] | id | Character ID of the entity to retrieve. |
Entity * EntityManager::GetEntityFromIndex | ( | const int | id | ) | const |
Retrieves an entity by it's index in the field.
Only entities of the current active module will be searched.
[in] | id | Index of the entity to retrieve. |
bool EntityManager::GetRandomEncounters | ( | ) |
Checks if random battle encounters are active in the field.
Walkmesh * EntityManager::GetWalkmesh | ( | ) |
Retrieves the walkmesh.
|
overridevirtual |
bool EntityManager::IsKeyOff | ( | unsigned int | key_code | ) |
Checks if a key is not being pressed.
[in] | key_code | The code of the key to test. |
bool EntityManager::IsKeyOn | ( | unsigned int | key_code | ) |
Checks if a key is being pressed.
[in] | key_code | The code of the key to test. |
|
overridevirtual |
Handles resizing events.
Implements Manager.
|
private |
Moves an entity in the walkmesh.
If the manager is in battle mode, it will do nothing.
[in] | entity | Entity to move. |
[in] | speed | Movement speed. |
|
staticprivate |
Calculates the point elevation over a plane.
[in] | point | Point to calculate the elevation of. |
[in] | a | First point of the plane. |
[in] | b | Second point of the plane. |
[in] | c | Third point of the plane. |
void EntityManager::ScriptAddEntity | ( | const char * | name, |
const char * | file_name, | ||
const float | x, | ||
const float | y, | ||
const float | z, | ||
const float | direction, | ||
int | index | ||
) |
Adds an entity to the manager.
Simplified version of {
[in] | name | Entity name. |
[in] | file_name | Path to the entity model file. |
[in] | x | X coordinate of the entity position in the map. |
[in] | y | Y coordinate of the entity position in the map. |
[in] | z | Z coordinate of the entity position in the map. |
[in] | direction | Entity face direction. |
[in] | index | Index of the entity on the manager. |
void EntityManager::ScriptAddEntityScript | ( | const char * | name | ) |
Adds an entity script to the manager.
[in] | name | Entity script name. |
Entity * EntityManager::ScriptGetEntity | ( | const char * | name | ) | const |
Retrieves an entity by name.
Only entities of the current active module will be searched.
[in] | name | Name of the entity to retrieve. |
EntityPoint * EntityManager::ScriptGetEntityPoint | ( | const char * | name | ) | const |
Retrieves an entity point by name.
[in] | name | Name of the entity point to retrieve. |
Entity * EntityManager::ScriptGetPlayerEntity | ( | ) | const |
Retrieves the playable entity.
void EntityManager::ScriptPlayerLock | ( | const bool | lock | ) |
Locks or unlocks player control of the playable entity.
If the EntityManager is in battle mode, nothing will be done.
[in] | lock | True to lock, false to unlock. |
void EntityManager::ScriptSetPlayerEntity | ( | const char * | name | ) |
Sets the playable entity.
If no entities are found by name, no one will be assigned, the previous playable entity will remain so, and no warning will be issued. Also, if the EntityManager is in battle mode, nothing will be done.
[in] | name | Name of the entity to make playable. |
void EntityManager::ScriptUnsetPlayerEntity | ( | ) |
Unsets any playable entities.
If the EntityManager is in battle mode, nothing will be done.
void EntityManager::SetBackground3D | ( | const Ogre::String & | name, |
const Ogre::String & | file_name | ||
) |
Sets the 3D model for the background.
[in] | name | name for the background entity, for debugging purposes only. |
[in] | file_name | Path to the 3D model file. |
void EntityManager::SetEncounterRate | ( | float | rate | ) |
Sets the battle encounter rate.
[in] | rate | The encounter rate (0-1). |
|
private |
Sets an entity direction.
[in] | entity | Entity whose direction is to be set. |
[in] | vector | Direction vector. |
|
private |
Attaches an entity to the walkmesh.
It sets the triangle from the entity position coordinates. To account for multiple triangles on different levels, it uses only the X and Y coordinates, and automatically sets the Z one to the closest triangle. If the manager is in battle mode, it will do nothing.
[in] | entity | Entity to attach. |
void EntityManager::SetEntityToCharacter | ( | const char * | entity_name, |
unsigned int | char_id | ||
) |
Assigns a character to an entity.
Only entities of the currently active module can be assigned
[in] | entity_name | The entity name. |
[in] | char_id | The character ID. |
|
private |
Calculates and sets the next position during a jump.
If the manager is in battle mode, it will do nothing
[in] | entity | The jump entity. |
|
private |
Calculates and sets the next position during a linear movement.
If the manager is in battle mode, it will do nothing
[in] | entity | The moving entity. |
|
private |
Calculates the next offset step for an entity.
[in] | entity | The entity. |
|
private |
|
private |
Calculates the next turn step for an entity.
[in] | entity | The entity. |
void EntityManager::SetPlayerMoveRotation | ( | const Ogre::Radian | rotation | ) |
Sets the baseline rotation for the player controlled entity.
If the EntityManager is in battle mode, nothing will be done.
[in] | rotation | Baseline rotation. |
void EntityManager::SetRandomEncounters | ( | bool | active | ) |
Enables or disables random encounters in the field.
[in] | active | True to enable encounters, false to deactivate them. |
|
staticprivate |
Determines at which side of a line a point is.
[in] | point | The point to evaluate. |
[in] | p1 | The first point of the line. |
[in] | p2 | The second point of the line. |
|
staticprivate |
Calculates the square distance between a point and a line.
The calculated distance is the vector orthogonal to the line that passes by the point, i.e. the shortest distance.
[in] | point | The point. |
[in] | point_a | First point of the line. |
[in] | point_b | Second point of the line. |
[out] | proj | Vector representing the shortest distance. |
|
overrideprivatevirtual |
Updates the battle entities in the manager.
Implements Manager.
|
overridevirtual |
|
overrideprivatevirtual |
Updates the field entities in the manager.
Implements Manager.
|
overrideprivatevirtual |
Updates the world map entities in the manager.
Implements Manager.
|
private |
Checks if the entity is crossing a walkmesh triangle border.
[in] | entity | Entity to check. |
[in] | position | The position. |
[in] | move_vector | The move vector. |
|
private |
|
private |
The map background.
|
private |
A 3D background.
|
staticprivate |
Entity ID for battle background entity.
|
private |
The list of battle entities.
|
private |
The encounter rate of the map.
|
private |
The list of field or world entities.
|
private |
List of points.
|
private |
List of scripts.
|
private |
The entity table name.
|
private |
List of triggers.
|
private |
|
private |
The player controlled entity.
|
private |
Indicates if player control is locked.
|
private |
The playable entity current movement indicator.
Applies only for manual movement.
|
private |
The playable entity current movement turn indicator.
Applies only for manual movement.
|
private |
Indicates if the playable is being moved by running.
Applies only for manual movement.
|
private |
Indicates if random encounters happen in the map.
|
private |
The scene node.
|
staticprivate |
Scale factor for battle background models.
|
private |
The map walkmesh.
|
staticprivate |
Entity ID for world map background entity.