Quellcode durchsuchen

The EntityManager is now set to work on either module.

Iñigo Valentin vor 3 Jahren
Ursprung
Commit
d6e017de98

+ 0 - 2
data/data/scripts/battle.lua

@@ -100,7 +100,6 @@ Battle.logic_script = {
 --
 -- @param id Battle ID.
 Battle.start = function(id)
-    print("Starting battle " .. tostring(id))
     battle_manager:start_battle(id)
     script:request_end_sync(Script.UI, "BattleUi", "show", 0)
     return 0
@@ -108,7 +107,6 @@ end
 
 --- Ends a battle.
 Battle.finish = function()
-    print("Ending battle")
     battle_manager:end_battle()
     script:request_end_sync(Script.UI, "BattleUi", "hide", 0)
     return 0

+ 7 - 6
src/core/BattleManager.cpp

@@ -170,10 +170,10 @@ void BattleManager::AddEnemy(
     }
     Enemy* enemy = new Enemy(id, pos, front, visible, targeteable, active, cover);
     enemies_.push_back(*enemy);
-    EntityManager::getSingleton().AddBattleEntity(
+    EntityManager::getSingleton().AddEntity(
       enemy->GetName() + "_" + std::to_string(enemies_.size() - 1),
       "enemies/" + enemy->GetModel() + ".mesh", enemy->GetPos(), Ogre::Degree(0),
-      Ogre::Vector3(MODEL_SCALE, MODEL_SCALE, MODEL_SCALE), id, visible, false
+      Ogre::Vector3(MODEL_SCALE, MODEL_SCALE, MODEL_SCALE), Ogre::Quaternion::IDENTITY, id
     );
 }
 
@@ -250,10 +250,11 @@ void BattleManager::SetLocation(const int id, const Ogre::String name){
         LOG_ERROR("Tried to set a location in the BattleManager, but it's not in battle mode.");
         return;
     }
-    EntityManager::getSingleton().AddBattleEntity(
+    EntityManager::getSingleton().SetBackground3D(name, "scenes/oi_grassland.mesh");
+    /**EntityManager::getSingleton().AddBattleEntity(
       "Background", "scenes/oi_grassland.mesh", Ogre::Vector3(0, 0, 0), Ogre::Degree(0),
       Ogre::Vector3(SCENE_SCALE, SCENE_SCALE, SCENE_SCALE), 999, true, true
-    );
+    );*/
 }
 
 void BattleManager::SetArenaBattle(const bool arena){
@@ -328,9 +329,9 @@ void BattleManager::LoadParty(){
                 break;
             default: continue;
         }
-        EntityManager::getSingleton().AddBattleEntity(
+        EntityManager::getSingleton().AddEntity(
           name, model, position, Ogre::Degree(0),
-          Ogre::Vector3(MODEL_SCALE, MODEL_SCALE, MODEL_SCALE), 100 + i, true
+          Ogre::Vector3(MODEL_SCALE, MODEL_SCALE, MODEL_SCALE), Ogre::Quaternion::IDENTITY, 100 + i
         );
 
         // Next position in Y axis

+ 2 - 2
src/core/BattleManager.h

@@ -236,8 +236,8 @@ class BattleManager : public Manager, public Ogre::Singleton<BattleManager>{
         /**
          * Sets the battle layout.
          *
-         * @param[in] The battle layout. {@see LAYOUT}. When one of the unknowns is specified, the
-         * normal will be applied.
+         * @param[in] layout The battle layout. {@see LAYOUT}. When one of the unknowns is
+         * specified, the normal will be applied.
          */
         void SetLayout(const LAYOUT layout);
 

+ 1 - 1
src/core/CameraManager.h

@@ -189,7 +189,7 @@ class CameraManager : public Manager, public Ogre::Singleton<CameraManager>{
          * @param[in] z Z coordinate for the camera position.
          * @param[in] d_x X coordinate of the point the camera looks at.
          * @param[in] d_y Y coordinate of the point the camera looks at.
-         * @param[in] d_y Z coordinate of the point the camera looks at.
+         * @param[in] d_z Z coordinate of the point the camera looks at.
          */
         void ScriptSetCamera(
           const int x, const int y, const int z, const int d_x, const int d_y, const int d_z

+ 7 - 7
src/core/Enemy.h

@@ -155,7 +155,7 @@ class Enemy{
          *
          * The model name must be the filename of the .mesh file, without extension.
          *
-         * @param[in] The enemy model name.
+         * @param[in] model The enemy model name.
          */
         void SetModel(const std::string model);
 
@@ -239,7 +239,7 @@ class Enemy{
         /**
          * Adds an animation for the enemy.
          *
-         * @param[in] Animation ID.
+         * @param[in] animation Animation ID.
          */
         void AddAnimation(const unsigned int animation);
 
@@ -253,14 +253,14 @@ class Enemy{
         /**
          * Adds an attack for the enemy.
          *
-         * @param[in] Attack to add.
+         * @param[in] attack Attack to add.
          */
         void AddAttack(const Attack attack);
 
         /**
          * Retrieves the enemy possible item drops.
          *
-         * @return List of items that can be droped by the enemy.
+         * @return List of items that can be dropped by the enemy.
          */
         std::vector<Item> GetDrop() const;
 
@@ -500,7 +500,7 @@ class Enemy{
          * If the new max HP is higher than the current HP, the current HP will be set to the new
          * max HP.
          *
-         * @param[in] str The strength stat.
+         * @param[in] hp_max The max HP stat.
          */
         void SetHpMax(const unsigned int hp_max);
 
@@ -534,7 +534,7 @@ class Enemy{
          * If the new max MP is higher than the current MP, the current MP will be set to the new
          * max MP.
          *
-         * @param[in] str The strength stat.
+         * @param[in] mp_max The max MP stat.
          */
         void SetMpMax(const unsigned int mp_max);
 
@@ -624,7 +624,7 @@ class Enemy{
          * {@see https://wiki.ffrtt.ru/index.php/FF7/Battle/Battle_Scenes#Binary_.22Cover_Flags.22}
          * for more info about cover flags.
          *
-         * @param[in] A string with five 0s or 1s indicating the cover flags.
+         * @param[in] cover A string with five 0s or 1s indicating the cover flags.
          */
         void SetCover(std::string cover);
 

+ 213 - 58
src/core/EntityManager.cpp

@@ -37,6 +37,12 @@ template<>EntityManager *Ogre::Singleton<EntityManager>::msSingleton = nullptr;
 ConfigVar cv_debug_grid("debug_grid", "Draw debug grid", "false");
 ConfigVar cv_debug_axis("debug_axis", "Draw debug axis", "false");
 
+const float EntityManager::SCENE_SCALE = 0.0012f;
+
+const unsigned int EntityManager::BATTLE_BACKGROUND_ID = 1000;
+
+const unsigned int EntityManager::WORLD_MAP_BACKGROUND_ID = 1001;
+
 float EntityManager::PointElevation(
   const Ogre::Vector2& point, const Ogre::Vector3& a, const Ogre::Vector3& b, const Ogre::Vector3& c
 ){
@@ -287,6 +293,10 @@ void EntityManager::UpdateField(){
 
 void EntityManager::UpdateBattle(){
     ScriptManager::getSingleton().Update(ScriptManager::BATTLE);
+    if (background_3d_ != nullptr){
+        background_3d_->Update();
+        background_3d_->PlayAnimationContinue(background_3d_->GetDefaultAnimationName());
+    }
     for (unsigned int i = 0; i < battle_entity_.size(); ++ i){
         battle_entity_[i]->Update();
         battle_entity_[i]->PlayAnimationContinue(battle_entity_[i]->GetDefaultAnimationName());
@@ -298,18 +308,90 @@ void EntityManager::UpdateWorld(){
     // TODO: Implement
 }
 
+void EntityManager::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
+){
+    if (module_ != Module::FIELD){
+        LOG_ERROR("Tried to add field or world Entity but the EntityManager is in battle mode.");
+        return;
+    }
+    Ogre::SceneNode* node = scene_node_->createChildSceneNode("Model_" + name);
+    EntityModel* entity = new EntityModel(name, file_name, node);
+    entity->SetPosition(position);
+    entity->SetRotation(rotation);
+    entity->setScale(scale);
+    entity->SetIndex(index);
+    entity->setRootOrientation(root_orientation);
+    entity_.push_back(entity);
+    ScriptManager::getSingleton().AddEntity(ScriptManager::ENTITY, entity->GetName(), entity);
+}
+
+void EntityManager::AddBattleEntity(
+  const Ogre::String& name, const Ogre::String& file_name, const Ogre::Vector3& position,
+  const Ogre::Degree& orientation, const Ogre::Vector3& scale, const int index
+){
+    if (module_ != Module::BATTLE){
+        LOG_ERROR("Tried to add battle Entity but the EntityManager is not in battle mode.");
+        return;
+    }
+    Ogre::SceneNode* node = scene_node_->createChildSceneNode("Battle_" + name);
+    EntityModel* entity = new EntityModel(name, file_name, node);
+    entity->SetPosition(position);
+    entity->SetRotation(orientation);
+    entity->setScale(scale);
+    entity->SetIndex(index);
+    entity->SetVisible(true);
+    // Backgrounds must be reoriented.
+    //if (is_background) node->setOrientation(1, 1, 0, 0);
+    battle_entity_.push_back(entity);
+    ScriptManager::getSingleton().AddEntity(ScriptManager::BATTLE, entity->GetName(), entity);
+}
+
+Entity* EntityManager::GetBackground3D() const{
+    if (IsFieldModule()){
+        LOG_WARNING("Tried to retrieve a 3D background while the EntityManager is in field mode.");
+        return nullptr;
+    }
+    return background_3d_;
+}
+
+void EntityManager::SetBackground3D(const Ogre::String& name, const Ogre::String& file_name){
+    if (IsFieldModule()){
+        LOG_ERROR("Tried to add a 3D background while the EntityManager is in field mode.");
+        return;
+    }
+    Ogre::SceneNode* node = scene_node_->createChildSceneNode("bg_" + name);
+    background_3d_ = new EntityModel(name, file_name, node);
+    background_3d_->SetPosition(Ogre::Vector3(0, 0, 0));
+    background_3d_->SetRotation(Ogre::Degree(0));
+    background_3d_->setScale(Ogre::Vector3(SCENE_SCALE, SCENE_SCALE, SCENE_SCALE));
+    background_3d_->SetIndex(IsBattleModule() ? BATTLE_BACKGROUND_ID : WORLD_MAP_BACKGROUND_ID);
+    background_3d_->SetVisible(true);
+    // Backgrounds must be reoriented.
+    node->setOrientation(1, 1, 0, 0);
+    // Probably don't need a script for the 3d background.
+    /*ScriptManager::getSingleton().AddEntity(
+      ScriptManager::BATTLE, background_3d_->GetName(), background_3d_
+    );*/
+}
+
 void EntityManager::UpdateDebug(){
     grid_->setVisible(cv_debug_grid.GetB());
     axis_->setVisible(cv_debug_axis.GetB());
-    if (module_ == Module::BATTLE)
+    if (module_ == Module::BATTLE){
+        if (background_3d_ != nullptr) background_3d_->UpdateDebug();
         for (unsigned int i = 0; i < battle_entity_.size(); ++ i) battle_entity_[i]->UpdateDebug();
+    }
     else{
         for (unsigned int i = 0; i < entity_.size(); ++ i) entity_[i]->UpdateDebug();
-        for (unsigned int i = 0; i < entity_triggers_.size(); ++ i) entity_triggers_[i]->UpdateDebug();
+        for (unsigned int i = 0; i < entity_triggers_.size(); ++ i)
+            entity_triggers_[i]->UpdateDebug();
         for (unsigned int i = 0; i < entity_points_.size(); ++ i) entity_points_[i]->UpdateDebug();
         walkmesh_.UpdateDebug();
+        background_2d_.UpdateDebug();
     }
-    background_2d_.UpdateDebug();
 }
 
 void EntityManager::OnResize(){background_2d_.OnResize();}
@@ -349,9 +431,10 @@ void EntityManager::ClearBattle(){
         Ogre::Root::getSingleton().getSceneManager("Scene")->destroyEntity(
           battle_entity_[i]->GetName()
         );
-        scene_node_->removeAndDestroyChild("Model_" + battle_entity_[i]->GetName());
+        scene_node_->removeAndDestroyChild("Battle_" + battle_entity_[i]->GetName());
     }
     battle_entity_.clear();
+    delete background_3d_;
 }
 
 void EntityManager::ClearWorld(){
@@ -375,43 +458,14 @@ void EntityManager::AddEntity(
 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, int index
+  const Ogre::Quaternion& root_orientation, const int index
 ){
-    if (module_ != Module::FIELD){
-        LOG_ERROR("Tried to add field Entity but the EntityManager is not in field mode.");
-        return;
-    }
-    Ogre::SceneNode* node = scene_node_->createChildSceneNode("Model_" + name);
-    EntityModel* entity = new EntityModel(name, file_name, node);
-    entity->SetPosition(position);
-    entity->SetRotation(rotation);
-    entity->setScale(scale);
-    entity->SetIndex(index);
-    entity->setRootOrientation(root_orientation);
-    entity_.push_back(entity);
-    ScriptManager::getSingleton().AddEntity(ScriptManager::ENTITY, entity->GetName(), entity);
-}
-
-void EntityManager::AddBattleEntity(
-  const Ogre::String& name, const Ogre::String& file_name, const Ogre::Vector3& position,
-  const Ogre::Degree& rotation, const Ogre::Vector3& scale, const int index, const int visible,
-  const bool is_background
-){
-    if (module_ != Module::BATTLE){
-        LOG_ERROR("Tried to add battle Entity but the EntityManager is not in battle mode.");
-        return;
-    }
-    Ogre::SceneNode* node = scene_node_->createChildSceneNode("Model_" + name);
-    EntityModel* entity = new EntityModel(name, file_name, node);
-    entity->SetPosition(position);
-    entity->SetRotation(rotation);
-    entity->setScale(scale);
-    entity->SetIndex(index);
-    entity->SetVisible(visible);
-    // Backgrounds must be reoriented.
-    if (is_background) node->setOrientation(1, 1, 0, 0);
-    battle_entity_.push_back(entity);
-    ScriptManager::getSingleton().AddEntity(ScriptManager::BATTLE, entity->GetName(), entity);
+    if (IsBattleModule())
+        AddBattleEntity(name, file_name, position, rotation, scale, index);
+    else
+        AddFieldOrWorldMapEntity(
+          name, file_name, position, rotation, scale, root_orientation, index
+        );
 }
 
 void EntityManager::ScriptAddEntity(
@@ -423,6 +477,10 @@ void EntityManager::AddEntityTrigger(
   const Ogre::String& name,
   const Ogre::Vector3& point1, const Ogre::Vector3& point2, const bool enabled
 ){
+    if (IsBattleModule()){
+        LOG_WARNING("Tried to add an entity trigger but the EntityManager is in battle mode.");
+        return;
+    }
     EntityTrigger* trigger = new EntityTrigger(name);
     trigger->SetPoints(point1, point2);
     trigger->SetEnabled(enabled);
@@ -433,6 +491,10 @@ void EntityManager::AddEntityTrigger(
 void EntityManager::AddEntityPoint(
   const Ogre::String& name, const Ogre::Vector3& position, const float rotation
 ){
+    if (IsBattleModule()){
+        LOG_WARNING("Tried to add an entity point but the EntityManager is in battle mode.");
+        return;
+    }
     EntityPoint* entity_point = new EntityPoint(name);
     entity_point->SetPosition(position);
     entity_point->SetRotation(rotation);
@@ -440,6 +502,7 @@ void EntityManager::AddEntityPoint(
 }
 
 void EntityManager::AddEntityScript(const Ogre::String& name){
+    // TODO: Should call to this be prevented while in battle mode?
     entity_scripts_.push_back(name);
     ScriptManager::getSingleton().AddEntity(ScriptManager::ENTITY, name, nullptr);
 }
@@ -447,20 +510,41 @@ void EntityManager::AddEntityScript(const Ogre::String& name){
 void EntityManager::ScriptAddEntityScript(const char* name){AddEntityScript(name);}
 
 Entity* EntityManager::GetEntity(const Ogre::String& name) const{
-    for (unsigned int i = 0; i < entity_.size(); ++ i)
-        if (entity_[i]->GetName() == name) return entity_[i];
+    if (IsBattleModule()){
+        for (unsigned int i = 0; i < battle_entity_.size(); ++ i)
+            if (battle_entity_[i]->GetName() == name) return battle_entity_[i];
+    }
+    else{
+        for (unsigned int i = 0; i < entity_.size(); ++ i)
+            if (entity_[i]->GetName() == name) return entity_[i];
+    }
     return nullptr;
 }
 
 Entity* EntityManager::GetEntityFromIndex(const int index) const{
-    for (unsigned int i = 0; i < entity_.size(); ++ i)
-        if (entity_[i]->GetIndex() == index) return entity_[i];
+    if (IsBattleModule()){
+        if (background_3d_ != nullptr && background_3d_->GetIndex() == index)
+            return background_3d_;
+        for (unsigned int i = 0; i < battle_entity_.size(); ++ i)
+            if (battle_entity_[i]->GetIndex() == index) return battle_entity_[i];
+    }
+    else{
+        for (unsigned int i = 0; i < entity_.size(); ++ i)
+            if (entity_[i]->GetIndex() == index) return entity_[i];
+    }
     return nullptr;
 }
 
 Entity* EntityManager::GetEntityFromCharacterId(const int id) const{
-    for (unsigned int i = 0; i < entity_.size(); ++ i)
-        if (entity_[i]->IsCharacter() && entity_[i]->GetCharacterId() == id) return entity_[i];
+    if (IsBattleModule()){
+        for (unsigned int i = 0; i < battle_entity_.size(); ++ i)
+            if (battle_entity_[i]->IsCharacter() && battle_entity_[i]->GetCharacterId() == id)
+                return battle_entity_[i];
+    }
+    else{
+        for (unsigned int i = 0; i < entity_.size(); ++ i)
+            if (entity_[i]->IsCharacter() && entity_[i]->GetCharacterId() == id) return entity_[i];
+    }
     return nullptr;
 }
 
@@ -468,7 +552,6 @@ Entity* EntityManager::ScriptGetEntity(const char* name) const{
     return GetEntity(Ogre::String(name));
 }
 
-
 EntityPoint* EntityManager::ScriptGetEntityPoint(const char* name) const{
     for (unsigned int i = 0; i < entity_points_.size(); ++ i)
         if (entity_points_[i]->GetName() == name) return entity_points_[i];
@@ -476,6 +559,10 @@ EntityPoint* EntityManager::ScriptGetEntityPoint(const char* name) const{
 }
 
 void EntityManager::ScriptSetPlayerEntity(const char* name){
+    if (IsBattleModule()){
+        LOG_WARNING("Tried to set a player entity but the EntityManager is in battle mode.");
+        return;
+    }
     for (unsigned int i = 0; i < entity_.size(); ++ i){
         if (entity_[i]->GetName() == name){
             player_entity_ = entity_[i];
@@ -487,16 +574,36 @@ void EntityManager::ScriptSetPlayerEntity(const char* name){
     }
 }
 
-Entity* EntityManager::ScriptGetPlayerEntity() const{return player_entity_;}
+Entity* EntityManager::ScriptGetPlayerEntity() const{
+    if (IsBattleModule()){
+        LOG_WARNING("Tried to set a player entity but the EntityManager is in battle mode.");
+        return nullptr;
+    }
+    return player_entity_;
+}
 
-void EntityManager::ScriptUnsetPlayerEntity(){player_entity_ = nullptr;}
+void EntityManager::ScriptUnsetPlayerEntity(){
+    if (IsBattleModule()){
+        LOG_WARNING("Tried to unset a player entity but the EntityManager is in battle mode.");
+        return;
+    }
+    player_entity_ = nullptr;
+}
 
 void EntityManager::ScriptPlayerLock(const bool lock){
+    if (IsBattleModule()){
+        LOG_WARNING("Tried to set player lock but the EntityManager is in battle mode.");
+        return;
+    }
     player_lock_ = lock;
     if (lock == true) player_move_ = Ogre::Vector3::ZERO;
 }
 
 void EntityManager::SetPlayerMoveRotation(const Ogre::Radian rotation){
+    if (IsBattleModule()){
+        LOG_WARNING("Tried to set player move rotation the EntityManager is in battle mode.");
+        return;
+    }
     player_move_rotation_ = rotation;
 }
 
@@ -511,13 +618,6 @@ void EntityManager::SetEncounterRate(float rate){
     else if (rate <= 0.0f) encounter_rate_ = 0.0f;
     else encounter_rate_ = rate;
 }
-bool EntityManager::StartBattleForResult(unsigned int formation){
-    std::cout << "[BATTLE] Start battle for result ID " << formation << "\n";
-    return true;
-}
-void EntityManager::StartBattle(unsigned int formation){
-    std::cout << "[BATTLE] Start battle ID " << formation << "\n";
-}
 
 bool EntityManager::IsKeyOn(unsigned int key_code){
     // If the player is locked, always false.
@@ -538,11 +638,33 @@ bool EntityManager::IsKeyOn(unsigned int key_code){
 bool EntityManager::IsKeyOff(unsigned int key_code){return !IsKeyOn(key_code);}
 
 void EntityManager::SetEntityToCharacter(const char* entity_name, unsigned int char_id){
-    for (unsigned int i = 0; i < entity_.size(); ++ i)
-        if (entity_[i]->GetName() == entity_name) entity_[i]->SetCharacter(char_id);
+    if (IsBattleModule()){
+        for (unsigned int i = 0; i < battle_entity_.size(); ++ i){
+            if (battle_entity_[i]->GetName() == entity_name){
+                battle_entity_[i]->SetCharacter(char_id);
+                return;
+            }
+        }
+    }
+    else{
+        for (unsigned int i = 0; i < entity_.size(); ++ i){
+            if (entity_[i]->GetName() == entity_name){
+                entity_[i]->SetCharacter(char_id);
+                return;
+            }
+        }
+    }
+    LOG_WARNING(
+      "Unabe to assigne character ID " + std::to_string(char_id) + " to entity '" + entity_name
+      + "'. No entity by that name exists."
+    );
 }
 
 bool EntityManager::SetEntityOnWalkmesh(Entity* entity){
+    if (IsBattleModule()){
+        LOG_WARNING("Tried to set entity on the walkmesh, but the EntityManager is in battle mode");
+        return false;
+    }
     Ogre::Vector3 position3 = entity->GetPosition();
     Ogre::Vector2 position2;
     position2.x = position3.x;
@@ -591,6 +713,10 @@ bool EntityManager::SetEntityOnWalkmesh(Entity* entity){
 }
 
 bool EntityManager::PerformWalkmeshMove(Entity* entity, const float speed){
+    if (IsBattleModule()){
+        LOG_WARNING("Tried to perform a walkmesh move, but the EntityManager is in battle mode");
+        return false;
+    }
     Ogre::Vector3 start_point = entity->GetPosition();
     Ogre::Vector3 move_vector = entity->GetMovePosition() - start_point;
     Ogre::Vector2 direction(move_vector.x, move_vector.y);
@@ -843,6 +969,10 @@ bool EntityManager::PerformWalkmeshMove(Entity* entity, const float speed){
 bool EntityManager::WalkmeshBorderCross(
   Entity* entity, Ogre::Vector3& position, const Ogre::Vector2& move_vector
 ){
+    if (IsBattleModule()){
+        LOG_WARNING("Tried to check for walkmesh cross, but the EntityManager is in battle mode");
+        return false;
+    }
     int current_triangle = entity->GetMoveTriangleId();
     if (current_triangle == -1) return true;
     Ogre::Vector2 pos = Ogre::Vector2(position.x, position.y);
@@ -879,6 +1009,10 @@ bool EntityManager::WalkmeshBorderCross(
 }
 
 bool EntityManager::CheckSolidCollisions(Entity* entity, Ogre::Vector3& position){
+    if (IsBattleModule()){
+        LOG_WARNING("Tried to check for solid collisions, but the EntityManager is in battle mode");
+        return false;
+    }
     if (entity->IsSolid() == false) return false;
     for (size_t i = 0; i < entity_.size(); ++ i){
         if (entity_[i]->IsSolid() == false) continue;
@@ -900,6 +1034,10 @@ bool EntityManager::CheckSolidCollisions(Entity* entity, Ogre::Vector3& position
 }
 
 void EntityManager::CheckTriggers(Entity* entity, const Ogre::Vector3& position){
+    if (IsBattleModule()){
+        LOG_WARNING("Tried to check for triggers, but the EntityManager is in battle mode");
+        return;
+    }
     if (entity->IsSolid() == false) return;
     if (player_entity_ != entity) return;
     if (player_entity_->IsSolid() == false) return;
@@ -1033,6 +1171,12 @@ void EntityManager::CheckTriggers(Entity* entity, const Ogre::Vector3& position)
 }
 
 void EntityManager::CheckEntityInteract(){
+    if (IsBattleModule()){
+        LOG_WARNING(
+          "Tried to check for entity interaction, but the EntityManager is in battle mode"
+        );
+        return;
+    }
     if (player_entity_ == NULL || player_lock_ == true || player_entity_->IsSolid() == false)
         return;
     Ogre::Degree angle_pc = player_entity_->GetRotation();
@@ -1077,6 +1221,7 @@ void EntityManager::CheckEntityInteract(){
 }
 
 void EntityManager::SetNextOffsetStep(Entity* entity){
+    // TODO: Allow this while on battle mode?
     ActionType type = entity->GetOffsetType();
     float total = entity->GetOffsetSeconds();
     float current = entity->GetOffsetCurrentSeconds();
@@ -1095,6 +1240,7 @@ void EntityManager::SetNextOffsetStep(Entity* entity){
 }
 
 void EntityManager::SetNextTurnStep(Entity* entity){
+    // TODO: Allow this while on battle mode?
     ActionType type = entity->GetTurnType();
     float total = entity->GetTurnSeconds();
     float current = entity->GetTurnCurrentSeconds();
@@ -1112,6 +1258,10 @@ void EntityManager::SetNextTurnStep(Entity* entity){
 }
 
 void EntityManager::SetNextLinearStep(Entity* entity){
+    if (IsBattleModule()){
+        LOG_WARNING("Tried to set next linear step, but the EntityManager is in battle mode");
+        return;
+    }
     bool to_end = true;
     bool is_move = false;
     Ogre::Vector3 start = entity->GetLinearStart();
@@ -1187,6 +1337,10 @@ void EntityManager::SetNextLinearStep(Entity* entity){
 }
 
 void EntityManager::SetNextJumpStep(Entity* entity){
+    if (IsBattleModule()){
+        LOG_WARNING("Tried to set next jump step, but the EntityManager is in battle mode");
+        return;
+    }
     float total = entity->GetJumpSeconds();
     float current = entity->GetJumpCurrentSeconds();
     current += Timer::getSingleton().GetGameTimeDelta();
@@ -1208,6 +1362,7 @@ void EntityManager::SetNextJumpStep(Entity* entity){
 }
 
 void EntityManager::SetNextScrollStep(){
+    // TODO: Allow this on battle mode?
     Background2D::SCROLL_TYPE type = background_2d_.GetScrollType();
     float total = background_2d_.GetScrollSeconds();
     float current = background_2d_.GetScrollCurrentSeconds();

+ 127 - 57
src/core/EntityManager.h

@@ -98,11 +98,13 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
         /**
          * 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 in the map.
+         * @param[in] position Entity position.
          * @param[in] direction Entity face direction.
-         * @param[in] index Index of the entity on the map.
+         * @param[in] index Index of the entity on the manager.
          */
         void AddEntity(
           const Ogre::String& name, const Ogre::String& file_name,
@@ -112,51 +114,34 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
         /**
          * 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.
-         * @param[in] index Index of the entity on the map.
-         */
-        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, int index
-        );
-
-        /**
-         * Adds a battle entity to the manager.
-         *
-         * If the manager is not in the battle module, it will do nothing.
+         * 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] index Index of the entity.
-         * @param[in] visible True to make the entity visible, false otherwise.
-         * @param[in] is_background Indicates if the entity is for the battle background.
+         * @param[in] root_orientation Entity orientation. Unused for battle and world map entities.
+         * @param[in] index Index of the entity on the manager.
          */
-        void AddBattleEntity(
+        void AddEntity(
           const Ogre::String& name, const Ogre::String& file_name,
           const Ogre::Vector3& position, const Ogre::Degree& rotation,
-          const Ogre::Vector3& scale, const int index, const int visible,
-          const bool is_background = false
+          const Ogre::Vector3& scale, const Ogre::Quaternion& root_orientation, const int index
         );
 
         /**
          * 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 map.
+         * @param[in] index Index of the entity on the manager.
          */
         void ScriptAddEntity(
           const char* name, const char* file_name,
@@ -166,13 +151,13 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
         /**
          * Adds an entity trigger to the manager.
          *
-         * A trigger is a line that does something when approached or crossed.
+         * 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.
+         * @param[in] enabled True to enable the trigger, false to leave it disabled.
          */
         void AddEntityTrigger(
           const Ogre::String& name, const Ogre::Vector3& point1,
@@ -182,6 +167,8 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
         /**
          * 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.
@@ -207,6 +194,8 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
         /**
          * 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.
          */
@@ -215,6 +204,8 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
         /**
          * 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.
          */
@@ -223,6 +214,8 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
         /**
          * 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.
          */
@@ -231,6 +224,8 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
         /**
          * 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.
          */
@@ -240,7 +235,8 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
          * 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.
+         * @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;
 
@@ -248,7 +244,8 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
          * 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.
+         * 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.
          */
@@ -257,18 +254,23 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
         /**
          * Retrieves the playable entity.
          *
-         * @return 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);
@@ -276,6 +278,8 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
         /**
          * 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.
          */
@@ -309,23 +313,6 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
          */
         void SetEncounterRate(float rate);
 
-        /**
-         * Starts a battle.
-         *
-         * @param[in] formation The enemy formation to fight.
-         * @return True if the battle victory conditions are met, false otherwise.
-         * @todo Implement
-         */
-        bool StartBattleForResult(unsigned int formation);
-
-        /**
-         * Starts a battle.
-         *
-         * @param[in] formation The enemy formation to fight.
-         * @todo Implement
-         */
-        void StartBattle(unsigned int formation);
-
         /**
          * Checks if a key is being pressed.
          *
@@ -345,11 +332,28 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
         /**
          * 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);
 
+        /**
+         * Retrieves the entity associated to the 3D background.
+         *
+         * @return The 3D background entity. nullptr if not set, of if the manager is in field mode.
+         */
+        Entity* GetBackground3D() const;
+
+        /**
+         * 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:
 
         /**
@@ -408,6 +412,21 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
           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.
          */
@@ -423,35 +442,75 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
          */
         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] 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 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.
+         * 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.
+         * 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.
          * @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);
 
         /**
-         * Cheks if the entity is crossing a walkmesh triangle border.
+         * 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.
+         * @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
@@ -463,7 +522,7 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
          * @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.
+         * not solid, always false. If the manager is in battle mode, it will always return false.
          */
         bool CheckSolidCollisions(Entity* entity, Ogre::Vector3& position);
 
@@ -480,7 +539,8 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
          *
          * 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.
+         * 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.
@@ -492,7 +552,8 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
          *
          * 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.
+         * has an on_interact script, it is run. If the manager is in battle mode, it will do
+         * nothing.
          */
         void CheckEntityInteract();
 
@@ -513,6 +574,8 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
         /**
          * 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);
@@ -520,6 +583,8 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
         /**
          * 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);
@@ -554,6 +619,11 @@ class EntityManager : public Manager, public Ogre::Singleton<EntityManager>{
          */
         std::vector<Entity*> battle_entity_;
 
+        /**
+         * A 3D background.
+         */
+        Entity* background_3d_;
+
         /**
          * The player controlled entity.
          */

+ 0 - 6
src/core/ScriptManagerBinds.h

@@ -196,9 +196,6 @@ void ScriptManager::InitBinds(){
             "random_encounters_on",
             (float(EntityManager::*)(bool)) &EntityManager::SetRandomEncounters
           )
-          .def("start_battle", (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle)
-          // TODO: Run? Set battle flags
-          .def("battle_run", (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle)
     ];
 
     // Entity individual point commands
@@ -258,9 +255,6 @@ void ScriptManager::InitBinds(){
             "random_encounters_on",
             (float(EntityManager::*)(bool)) &EntityManager::SetRandomEncounters
           )
-          .def("start_battle", (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle)
-          // TODO: Run? Set battle flags
-          .def("battle_run", (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle)
           .def("is_key_on", (bool(EntityManager::*)(unsigned int)) &EntityManager::IsKeyOn)
           .def("is_key_off", (bool(EntityManager::*)(unsigned int)) &EntityManager::IsKeyOff)
           .def(

+ 4 - 1
src/installer/BattleDataInstaller.h

@@ -36,7 +36,7 @@ class BattleDataInstaller{
          *
          * @param[in] input_dir Path to the directory containing the original data to parse.
          * @param[in] output_dir Path to the directory of the installation data.
-         * @param[in] res_mgt The application resource manager..
+         * @param[in] res_mgr The application resource manager..
          */
         BattleDataInstaller(
           const std::string input_dir, const std::string output_dir,
@@ -238,6 +238,9 @@ class BattleDataInstaller{
 
         /**
          * Generates all required .rsd models for a model.
+         *
+         * @param[in] model Model information.
+         * @param[in] path Output path.
          */
         void GenerateRsdFiles(Model model, std::string path);
 

+ 1 - 1
src/installer/TexFile.h

@@ -25,7 +25,7 @@ class TexFile{
         /**
          * Constructor.
          *
-         * @param[in,out] File with the tex data. The file data will not be modified, but it's
+         * @param[in,out] file File with the tex data. The file data will not be modified, but it's
          * offset will.
          */
         TexFile(File file);

+ 9 - 6
src/installer/data/DaFile.h

@@ -229,7 +229,7 @@ class DaFile{
          *
          * Stores all bone rotations for a frame.
          */
-        struct Frame {
+        struct Frame{
 
             /**
              * Number of bones in the animation frame.
@@ -251,7 +251,7 @@ class DaFile{
             /**
              * Constructor. Initializes data.
              */
-            Frame() {
+            Frame(){
                 bone_count = 0;
                 rotations = NULL;
             }
@@ -259,7 +259,7 @@ class DaFile{
             /**
              * Destructor.
              */
-            ~Frame() {
+            ~Frame(){
                 bone_count = 0;
                 delete [] rotations;
                 rotations = NULL;
@@ -267,8 +267,10 @@ class DaFile{
 
             /**
              * Sets the number of bones and initializes data arrays.
+             *
+             * @param[in] bones The number of bones.
              */
-            void SetBones(u32 bones ) {
+            void SetBones(u32 bones){
                 // Delete the old.
                 bone_count = 0;
                 delete [] rotations;
@@ -316,6 +318,7 @@ class DaFile{
          * @param[in] bytes The byte stream to read from.
          * @param[in,out] stream_bit_offset The bit at which to start reading. It will be advanced
          * by one per read bit.
+         * @param[in] bits Number of bits to read.
          * @return The read value.
          */
         int GetBitsFromStream(u8* bytes, u32 &stream_bit_offset, int bits);
@@ -326,7 +329,7 @@ class DaFile{
          * @param[in] bytes The byte stream to read from.
          * @param[in,out] stream_bit_offset The bit at which to start reading. It will be advanced
          * by one per read bit.
-         * @param How many bits to sift the read value.
+         * @param lowered_precision_bits How many bits to sift the read value.
          * @return The decoded value.
          */
         u16 GetCompressedDeltaFromStream(
@@ -336,7 +339,7 @@ class DaFile{
         /**
          * Loads the frames in an animation.
          *
-         * @param[out] Read frame data will be set here.
+         * @param[out] frame Read frame data will be set here.
          * @param[in] bones The number of bones in the animation.
          * @param[in] bit_start Bit to start reading from animation_buffer at.
          * @param[in] animation_buffer The animation data.

+ 1 - 1
src/installer/data/FF7Data.h

@@ -3073,7 +3073,7 @@ class FF7Data{
         /**
          * Retrieves a battle model code from an enemy ID.
          *
-         * @param[in] Enemy ID.
+         * @param[in] id Enemy ID.
          * @return The code for the model for the enemy, as in the filename in the .mesh file.
          */
         static std::string GetEnemyModelFromEnemyId(const unsigned int id){