| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026 |
- /*
- * Copyright (C) 2022 The V-Gears Team
- *
- * This file is part of V-Gears
- *
- * V-Gears is free software: you can redistribute it and/or modify it under
- * terms of the GNU General Public License as published by the Free Software
- * Foundation, version 3.0 (GPLv3) of the License.
- *
- * V-Gears is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
- #pragma once
- #include <chrono>
- #include <set>
- #include <map>
- #include <utility>
- #include <vector>
- #include <OgreSingleton.h>
- #include "engine/graphics/Background2D.h"
- #include "Entity.h"
- #include "EntityPoint.h"
- #include "EntityTrigger.h"
- #include "engine/Event.h"
- #include "engine/Manager.h"
- #include "engine/graphics/MoviePlayer.h"
- #include "engine/graphics/ScreenFade.h"
- #include "Walkmesh.h"
- class EntityModel;
- /**
- * The entity manager.
- */
- class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
- public:
- /**
- * Constructor.
- */
- EntityManager();
- /**
- * Destructor.
- */
- virtual ~EntityManager();
- /**
- * Limits a scripted movement step to its remaining distance.
- *
- * @param[in] distance Distance to the target.
- * @param[in] stop_distance Desired distance from the target.
- * @param[in] max_step Maximum distance to move this frame.
- * @return Distance to move this frame.
- */
- static float ScriptedMoveStep(float distance, float stop_distance, float max_step);
- /**
- * Decides whether an entity is a better target to interact with than the best one so far.
- *
- * The one the player faces more directly wins. If the angles are the same, the nearest
- * one does.
- *
- * @param[in] angle Angle in degrees between where the player faces and the candidate.
- * @param[in] distance Squared distance to the candidate.
- * @param[in] best_angle Angle of the best candidate so far, or the largest one allowed.
- * @param[in] best_distance Squared distance to the best candidate so far.
- * @return True if the candidate is better.
- */
- static bool IsBetterInteractionTarget(
- float angle, float distance, float best_angle, float best_distance
- );
- /**
- * Retrieves how close to a line an entity has to be to trigger it.
- *
- * It's the solid radius of the entity, unless a script has made it too small, as scripts
- * do while a scene is playing. Lines couldn't be triggered at all then.
- *
- * @param[in] solid_radius Solid radius of the entity.
- * @return The distance to the line from which it triggers.
- */
- static float TriggerReach(float solid_radius);
- /**
- * Checks if the edge of the walkmesh stops an entity.
- *
- * It stops the player and the characters that wander. The characters that a script walks
- * to a position are not stopped: the original game lets them walk off the walkmesh.
- *
- * @param[in] is_player Whether the entity is the player.
- * @param[in] scripted_move Whether a script asked the entity to walk to a position.
- * @return True if the edge of the walkmesh blocks the entity.
- */
- static bool WalkmeshEdgeBlocks(bool is_player, bool scripted_move);
- /**
- * Handles an input event.
- *
- * @param[in] event Event to handle.
- */
- void Input(const VGears::Event& event) override;
- /**
- * Updates the entities in the manager with debug information.
- *
- * It's automatically called from {@see Update}.
- */
- void UpdateDebug() override;
- /**
- * Handles resizing events
- */
- void OnResize() override;
- /**
- * Clears all field information in the entity manager.
- *
- * It clears the background, the walkmesh, any pending actions and all the field entities.
- */
- void ClearField() override;
- /**
- * Clears all battle information in the entity manager.
- *
- * It clears any pending actions and all the battle entities.
- */
- void ClearBattle() override;
- /**
- * Removes a battle entity, for example one made for a visual effect.
- *
- * If the manager is not in the battle module, or the entity doesn't exist, it will do
- * nothing.
- *
- * @param[in] name Entity name.
- */
- void RemoveBattleEntity(const Ogre::String& name);
- /**
- * Removes a world map entity (like a pole that was added while playing).
- *
- * If the manager is not in the world module, or the entity doesn't exist, it will do nothing.
- *
- * @param[in] name Entity name.
- */
- void RemoveWorldMapEntity(const Ogre::String& name);
- /**
- * Clears all world map information in the entity manager.
- *
- * It clears the background, the walkmesh, any pending actions and all the world entities.
- */
- void ClearWorld() override;
- /**
- * Retrieves the walkmesh.
- *
- * @return The walkmesh.
- */
- Walkmesh* GetWalkmesh();
- /**
- * Checks a proposed world-map position against managed solid entities.
- *
- * @param[in] moving_entity Entity being moved.
- * @param[in] position Proposed base position in world-map coordinates.
- * @return True if the entity would overlap another solid entity.
- */
- bool IsWorldPositionBlocked(
- const Entity* moving_entity, const Ogre::Vector3& position
- ) const;
- /**
- * Retrieves the 2D background.
- *
- * @return The 2D background.
- */
- Background2D* GetBackground2D();
- /**
- * Retrieves the coloured fade of the screen.
- *
- * @return The screen fade.
- */
- ScreenFade* GetScreenFade();
- /**
- * Retrieves the movie player.
- *
- * @return The movie player.
- */
- MoviePlayer* GetMoviePlayer();
- /**
- * Adds an entity to the manager.
- *
- * The entity will be added to the EntityManager current module entity list.
- *
- * @param[in] name Entity name.
- * @param[in] file_name Path to the entity model file.
- * @param[in] position Entity position.
- * @param[in] direction Entity face direction.
- * @param[in] index Index of the entity on the manager.
- */
- void AddEntity(
- const Ogre::String& name, const Ogre::String& file_name,
- const Ogre::Vector3& position, const Ogre::Degree& direction, int index
- );
- /**
- * Adds a field entity to the manager.
- *
- * The entity will be added to the EntityManager current module entity list.
- *
- * @param[in] name Entity name.
- * @param[in] file_name Path to the entity model file.
- * @param[in] position Entity position.
- * @param[in] rotation Entity face direction.
- * @param[in] scale Entity scale.
- * @param[in] root_orientation Entity orientation. Unused for battle and world map entities.
- * @param[in] index Index of the entity on the manager.
- */
- 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 managed world-map entity using an explicit resource group.
- *
- * @param[in] name Entity name.
- * @param[in] file_name Mesh resource name.
- * @param[in] position Initial position.
- * @param[in] rotation Initial rotation.
- * @param[in] scale Initial scale.
- * @param[in] resource_group Ogre resource group containing the mesh.
- * @return The managed entity, or nullptr if the manager is not in world mode.
- */
- EntityModel* AddWorldMapEntity(
- const Ogre::String& name, const Ogre::String& file_name,
- const Ogre::Vector3& position, const Ogre::Degree& rotation,
- const Ogre::Vector3& scale, const Ogre::String& resource_group
- );
- /**
- * Adds an entity to the manager.
- *
- * Simplified version of {@see AddEntity}, to be called from Lua scripts.
- *
- * @param[in] name Entity name.
- * @param[in] file_name Path to the entity model file.
- * @param[in] x X coordinate of the entity position in the map.
- * @param[in] y Y coordinate of the entity position in the map.
- * @param[in] z Z coordinate of the entity position in the map.
- * @param[in] direction Entity face direction.
- * @param[in] index Index of the entity on the manager.
- */
- 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 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.
- *
- * @param[in] name Entity trigger name.
- * @param[in] point1 One point of the trigger line.
- * @param[in] point2 One point of the trigger line.
- * @param[in] enabled True to enable the trigger, false to leave it disabled.
- */
- void AddEntityTrigger(
- const Ogre::String& name, const Ogre::Vector3& point1,
- const Ogre::Vector3& point2, const bool enabled
- );
- /**
- * Adds an entity point to the manager.
- *
- * If the Battle manager is in battle mode, nothing will be done.
- *
- * @param[in] name Entity point name.
- * @param[in] position Entity point position.
- * @param[in] rotation The point orientation.
- */
- void AddEntityPoint(
- const Ogre::String& name, const Ogre::Vector3& position, const float rotation
- );
- /**
- * Adds an entity script to the manager.
- *
- * @param[in] name Entity script name.
- */
- void AddEntityScript(const Ogre::String& name);
- /**
- * Adds an entity script to the manager.
- *
- * @param[in] name Entity script name.
- */
- void ScriptAddEntityScript(const char* name);
- /**
- * Retrieves an entity by name.
- *
- * Only entities of the current active module will be searched.
- *
- * @param[in] name Name of the entity to retrieve.
- * @return The entity by the specified name, or nullptr if there is no one.
- */
- Entity* GetEntity(const Ogre::String& name) const;
- /**
- * Retrieves an entity by it's index in the field.
- *
- * Only entities of the current active module will be searched.
- *
- * @param[in] id Index of the entity to retrieve.
- * @return The entity with the ID, or nullptr if there is no one.
- */
- Entity* GetEntityFromIndex(const int id) const;
- /**
- * Retrieves an entity by it's assigned character ID.
- *
- * Only entities of the current active module will be searched.
- *
- * @param[in] id Character ID of the entity to retrieve.
- * @return The entity assigned to the character, or nullptr if there is no one.
- */
- Entity* GetEntityFromCharacterId(const int id) const;
- /**
- * Retrieves an entity by name.
- *
- * Only entities of the current active module will be searched.
- *
- * @param[in] name Name of the entity to retrieve.
- * @return The entity by the specified name, or nullptr if there is no one.
- */
- Entity* ScriptGetEntity(const char* name) const;
- /**
- * Retrieves an entity point by name.
- *
- * @param[in] name Name of the entity point to retrieve.
- * @return The entity point by the specified name, or nullptr if there is no one or the
- * manager is in battle mode.
- */
- EntityPoint* ScriptGetEntityPoint(const char* name) const;
- /**
- * 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.
- *
- * @param[in] name Name of the entity to make playable.
- */
- void ScriptSetPlayerEntity(const char* name);
- void ScriptPlacePlayerAtFieldEntry(
- const float x, const float y, const int triangle_id, const float direction
- );
- /**
- * Retrieves the playable entity.
- *
- * @return The playable entity, or nullptr if it's not defined or the EntityManager is in
- * battle mode.
- */
- Entity* ScriptGetPlayerEntity() const;
- /**
- * Unsets any playable entities.
- *
- * If the EntityManager is in battle mode, nothing will be done.
- */
- void ScriptUnsetPlayerEntity();
- /**
- * Locks or unlocks player control of the playable entity.
- *
- * If the EntityManager is in battle mode, nothing will be done.
- *
- * @param[in] lock True to lock, false to unlock.
- */
- void ScriptPlayerLock(const bool lock);
- /**
- * Sets if the player can slide along the walls (SLIP in the field scripts).
- *
- * When it is off, a move of the player that is blocked by a wall is not turned into a
- * move along the wall. It is on by default and when a field is loaded.
- *
- * @param[in] slip True to let the player slide.
- */
- void ScriptSetPlayerSlip(const bool slip);
- /**
- * Retrieves the height of a point of a walkmesh triangle.
- *
- * @param[in] triangle The triangle.
- * @param[in] x X coordinate of the point.
- * @param[in] y Y coordinate of the point.
- * @param[in] fallback Value returned if there is no such triangle.
- * @return The height of the triangle at the point.
- */
- float GetTriangleHeight(int triangle, float x, float y, float fallback) const;
- /**
- * Sets if the player moves running by default.
- *
- * If true, the player runs unless the run key is held, which makes it walk. If false (the
- * default), the player walks unless the run key is held. To be called from Lua scripts
- * (movement setting of the config menu).
- *
- * @param[in] run True to run by default, false to walk by default.
- */
- void SetPlayerDefaultRun(const bool run);
- /**
- * Checks if the player movement is locked.
- *
- * @return True if it is locked.
- */
- bool IsPlayerLocked() const;
- /**
- * Sets the baseline rotation for the player controlled entity.
- *
- * If the EntityManager is in battle mode, nothing will be done.
- *
- * @param[in] rotation Baseline rotation.
- * @todo Verify this description.
- */
- void SetPlayerMoveRotation(const Ogre::Radian rotation);
- /**
- * Gets the multiplier of the random encounter rate (the encounter_multiplier cvar).
- *
- * @return The multiplier. 0 prevents random encounters.
- */
- float GetEncounterMultiplier() const;
- /**
- * Checks if the random encounter checks are logged (the debug_encounters cvar).
- *
- * @return True if they are logged.
- */
- bool IsDebugEncounters() const;
- /**
- * Enables or disables random encounters in the field.
- *
- * @param[in] active True to enable encounters, false to deactivate them.
- */
- void SetRandomEncounters(bool active);
- /**
- * Removes the random encounter tables of the field.
- */
- void ClearEncounterTables();
- /**
- * Hides the entities of the field or world map, while a battle takes place.
- *
- * Only the visible ones are hidden. They are shown again with
- * {@see ShowFieldEntities}.
- */
- void HideFieldEntities();
- /**
- * Shows the entities hidden by {@see HideFieldEntities}.
- */
- void ShowFieldEntities();
- /**
- * Adds a random encounter table to the field.
- *
- * @param[in] id Table ID (1 or 2).
- * @param[in] rate Encounter rate, as in the original game (24 is very low, 240 is high).
- * @param[in] battles Standard encounters, pairs of battle ID and probability (out of 64).
- * @param[in] specials Special encounters, with the same format.
- */
- void AddEncounterTable(
- const int id, const int rate, const std::vector<std::pair<int, int>>& battles,
- const std::vector<std::pair<int, int>>& specials
- );
- /**
- * Selects the encounter table to use.
- *
- * To be called from Lua scripts.
- *
- * @param[in] id Table ID (1 or 2). If it doesn't exist, no encounters happen.
- */
- void ScriptSetEncounterTable(const int id);
- /**
- * Picks the battle of a random encounter from the current encounter table.
- *
- * To be called from Lua scripts, also used by the engine.
- *
- * @return The battle ID, -1 if the field has no encounters.
- */
- int ScriptRollEncounterBattle() const;
- /**
- * Checks if a key is being pressed.
- *
- * @param[in] key_code The code of the key to test.
- * @return True if the key is being pressed, false otherwise.
- */
- bool IsKeyOn(unsigned int key_code);
- /**
- * Checks if a key is not being pressed.
- *
- * @param[in] key_code The code of the key to test.
- * @return False if the key is being pressed, true otherwise.
- */
- bool IsKeyOff(unsigned int key_code);
- /**
- * Checks if a script has asked for the Start button a moment ago.
- *
- * The scenes that use Start for their own ends (blin70_3, to end the choice of the party)
- * ask for it every frame, so the pause menu must not open with the same press.
- *
- * @return True if a script is asking for the Start button.
- */
- bool IsStartKeyRead() const;
- /**
- * Moves the line of a line entity (SLINE).
- *
- * @param[in] name Name of the entity.
- * @param[in] x1 First vertex of the line.
- * @param[in] y1 First vertex of the line.
- * @param[in] z1 First vertex of the line.
- * @param[in] x2 Second vertex of the line.
- * @param[in] y2 Second vertex of the line.
- * @param[in] z2 Second vertex of the line.
- */
- void ScriptSetLine(
- const char* name, const float x1, const float y1, const float z1, const float x2,
- const float y2, const float z2
- );
- /**
- * Assigns a character to an entity.
- *
- * Only entities of the currently active module can be assigned
- *
- * @param[in] entity_name The entity name.
- * @param[in] char_id The character ID.
- */
- void SetEntityToCharacter(const char* entity_name, unsigned int char_id);
- /**
- * Sets the 3D model for the background.
- *
- * @param[in] name name for the background entity, for debugging purposes only.
- * @param[in] file_name Path to the 3D model file.
- */
- void SetBackground3D(const Ogre::String& name, const Ogre::String& file_name);
- private:
- /**
- * Calculates the point elevation over a plane.
- *
- * @param[in] point Point to calculate the elevation of.
- * @param[in] a First point of the plane.
- * @param[in] b Second point of the plane.
- * @param[in] c Third point of the plane.
- * @return The elevation of the point.
- */
- static float PointElevation(
- const Ogre::Vector2& point,
- const Ogre::Vector3& a, const Ogre::Vector3& b, const Ogre::Vector3& c
- );
- /**
- * Determines at which side of a line a point is.
- *
- * @param[in] point The point to evaluate.
- * @param[in] p1 The first point of the line.
- * @param[in] p2 The second point of the line.
- * @return A negative value if the point is on the "left" of the line vector, a positive
- * value if the point is on the "right" of the vector line, or 0 if the point is part of
- * the line. "Left" and "right" are determined by going from p1 to p2.
- */
- static float SideOfVector(
- const Ogre::Vector2& point, const Ogre::Vector2& p1, const Ogre::Vector2& p2
- );
- /**
- * 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.
- *
- * @param[in] point The point.
- * @param[in] point_a First point of the line.
- * @param[in] point_b Second point of the line.
- * @param[out] proj Vector representing the shortest distance.
- * @return The distance from the point to the line.
- */
- static float SquareDistanceToLine(
- const Ogre::Vector3& point, const Ogre::Vector3& point_a, const Ogre::Vector3& point_b,
- Ogre::Vector3& proj
- );
- /**
- * Calculates the direction degree between to points.
- *
- * @param[in] current_point Origin point.
- * @param[in] direction_point Next point in the direction.
- * @return Degrees between the two points
- */
- static Ogre::Degree GetDirectionToPoint(
- const Ogre::Vector3& current_point, const Ogre::Vector3& direction_point
- );
- /**
- * Scale factor for battle background models.
- */
- static const float SCENE_SCALE;
- /**
- * Entity ID for battle background entity.
- */
- static const unsigned int BATTLE_BACKGROUND_ID;
- /**
- * Entity ID for world map background entity.
- */
- static const unsigned int WORLD_MAP_BACKGROUND_ID;
- /**
- * Updates the field entities in the manager.
- */
- void UpdateField() override;
- /**
- * Updates the battle entities in the manager.
- */
- void UpdateBattle() override;
- /**
- * Updates the world map entities in the manager.
- */
- void UpdateWorld() override;
- /**
- * Adds a field entity to the manager.
- *
- * @param[in] name Entity name.
- * @param[in] file_name Path to the entity model file.
- * @param[in] position Entity position in the map.
- * @param[in] rotation Entity face direction.
- * @param[in] scale Entity scale.
- * @param[in] root_orientation Map orientation. Unused for world map entities.
- * @param[in] index Index of the entity on the map.
- */
- 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 battle entity to the manager.
- *
- * If the manager is not in the battle module, it will do nothing.
- *
- * @param[in] name Entity name.
- * @param[in] file_name Path to the entity model file.
- * @param[in] position Entity position.
- * @param[in] orientation Entity face direction.
- * @param[in] scale Entity scale.
- * @param[in] root_orientation The node orientation.
- * @param[in] index Index of the entity.
- */
- 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
- );
- /**
- * 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.
- *
- * @param[in] entity Entity to attach.
- * @return True if the entity was assigned to a walkmesh triangle, false if the entity is
- * not in a triangle or if the manager is in battle mode.
- */
- bool SetEntityOnWalkmesh(Entity* entity);
- /**
- * Moves an entity in the walkmesh.
- *
- * If the manager is in battle mode, it will do nothing.
- *
- * @param[in] entity Entity to move.
- * @param[in] speed Movement speed.
- * @param[in] delta_time Time elapsed for this movement step.
- * @return True if the movement was possible and the entity was moved, false otherwise.
- * If the manager is in battle mode, it will always return false.
- */
- bool PerformWalkmeshMove(Entity* entity, const float speed, const float delta_time);
- /**
- * Checks if the entity is crossing a walkmesh triangle border.
- *
- * @param[in] entity Entity to check.
- * @param[in] position The position. @todo document more.
- * @param[in] move_vector The move vector. @todo document more.
- * @return True if the entity is crossing a triangle border, false otherwise. If the manager
- * is in battle mode, it will always return false.
- */
- bool WalkmeshBorderCross(
- Entity* entity, Ogre::Vector3& position, const Ogre::Vector2& move_vector
- );
- /**
- * Checks for collisions of the entity with other entities.
- *
- * @param[in] entity Entity to check for collisions.
- * @param[in] position Position of the entity.
- * @return True if the entity is colliding with another, false otherwise. If the entity is
- * not solid, always false. If the manager is in battle mode, it will always return false.
- */
- bool CheckSolidCollisions(Entity* entity, Ogre::Vector3& position);
- /**
- * 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.
- *
- * @param[in] entity Entity to check for nearby triggers.
- * @param[in] position The position of the entity.
- */
- void CheckTriggers(Entity* entity, const Ogre::Vector3& position);
- /**
- * 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.
- */
- void CheckEntityInteract();
- /**
- * Runs the contact script (script 2) of the entities that the player touches.
- *
- * The script of an entity that the original game runs when the player collides with it
- * (the old man of condor1 starts his conversation that way, and only after it can be
- * talked to). It runs once for each touch.
- */
- void CheckEntityContacts();
- /**
- * Calculates the next offset step for an entity.
- *
- * @param[in] entity The entity.
- */
- void SetNextOffsetStep(Entity* entity);
- /**
- * Calculates the next turn step for an entity
- *
- * @param[in] entity The entity.
- */
- void SetNextTurnStep(Entity* entity);
- /**
- * Calculates and sets the next position during a linear movement.
- *
- * If the manager is in battle mode, it will do nothing
- *
- * @param[in] entity The moving entity.
- */
- void SetNextLinearStep(Entity* entity);
- /**
- * Calculates and sets the next position during a jump.
- *
- * If the manager is in battle mode, it will do nothing
- *
- * @param[in] entity The jump entity.
- */
- void SetNextJumpStep(Entity* entity);
- /**
- * @todo Understand and document.
- */
- void SetNextScrollStep();
- /**
- * The map walkmesh.
- */
- Walkmesh walkmesh_;
- /**
- * The map background
- */
- Background2D background_2d_;
- /**
- * The movie player. It has to be created before the screen fade, which is drawn over it.
- */
- MoviePlayer movie_player_;
- /**
- * The coloured fade of the screen. It has to be created after the background, because the
- * fade must be drawn over it.
- */
- ScreenFade screen_fade_;
- /**
- * The entity table name.
- */
- Ogre::String entity_table_name_;
- /**
- * The list of field or world entities.
- */
- std::vector<Entity*> entity_;
- /**
- * The list of battle entities.
- */
- std::vector<Entity*> battle_entity_;
- /**
- * A 3D background.
- */
- Entity* background_3d_;
- /**
- * The player controlled entity.
- */
- Entity* player_entity_;
- /**
- * The playable entity current movement indicator.
- *
- * Applies only for manual movement.
- */
- Ogre::Vector3 player_move_;
- /**
- * The playable entity current movement turn indicator.
- *
- * Applies only for manual movement.
- */
- Ogre::Radian player_move_rotation_;
- /**
- * Indicates if player control is locked.
- */
- bool player_lock_;
- /**
- * Indicates if the player slides along the walls (see ScriptSetPlayerSlip).
- */
- bool player_slip_ = true;
- /**
- * Indicates if the playable is being moved by running.
- *
- * Applies only for manual movement.
- */
- bool player_run_;
- /// After entering a field from the world map, the walk keys that were held are ignored until
- /// they are released, so the player starts standing still.
- bool ignore_held_walk_ = false;
- /// Entities that the player is touching.
- std::set<const Entity*> entities_in_contact_;
- /// Last time that a script asked for the Start button.
- std::chrono::steady_clock::time_point start_key_read_time_;
- /**
- * Indicates if the player runs by default, and the run key makes it walk instead.
- */
- bool player_default_run_ = false;
- /**
- * List of triggers.
- */
- std::vector<EntityTrigger*> entity_triggers_;
- /**
- * List of points.
- */
- std::vector<EntityPoint*> entity_points_;
- /**
- * List of scripts.
- */
- std::vector<Ogre::String> entity_scripts_;
- /**
- * The scene node.
- */
- Ogre::SceneNode* scene_node_;
- /**
- * @todo Understand and document.
- */
- Ogre::Entity* grid_;
- /**
- * @todo Understand and document.
- */
- Ogre::Entity* axis_;
- /**
- * Indicates if random encounters happen in the map.
- */
- bool random_encounters_;
- /**
- * The encounter rate of the map.
- */
- float encounter_rate_;
- /**
- * Random encounter table of a field.
- */
- struct EncounterTable{
- /**
- * Encounter rate, as in the original game.
- */
- int rate;
- /**
- * Standard encounters: battle ID and probability (out of 64).
- */
- std::vector<std::pair<int, int>> battles;
- /**
- * Special encounters: battle ID and probability (out of 64).
- */
- std::vector<std::pair<int, int>> specials;
- };
- /**
- * Random encounter tables of the field, by ID.
- */
- std::map<int, EncounterTable> encounter_tables_;
- /**
- * Entities that were visible before a battle, hidden while it lasts.
- */
- std::vector<Entity*> entities_hidden_by_battle_;
- /**
- * ID of the encounter table in use.
- */
- int encounter_table_;
- /**
- * Distance walked by the player since the last step.
- */
- float encounter_distance_;
- /**
- * Position of the player in the last frame, to know how much it has walked.
- */
- Ogre::Vector3 encounter_last_position_;
- /**
- * Indicates if {@see encounter_last_position_} is valid.
- */
- bool encounter_last_position_valid_;
- /**
- * Steps that must be taken before encounters can happen again.
- */
- int encounter_safe_steps_;
- /**
- * Accumulated chance of a random encounter, out of 256 * 256. It grows while walking.
- */
- int encounter_accumulator_ = 0;
- /**
- * Last random battle, which is not repeated twice in a row. -1 if none.
- */
- int encounter_last_battle_ = -1;
- /**
- * Counts the steps of the player and starts random encounters.
- *
- * @param[in] walked True if the player was moved by the player's input in this frame.
- */
- void UpdateEncounters(const bool walked);
- };
|