Эх сурвалжийг харах

Attack models can be loaded in battle via console.

Iñigo Valentin 3 жил өмнө
parent
commit
03ac814a70

+ 35 - 0
src/core/BattleManager.cpp

@@ -45,6 +45,8 @@ ConfigVar cv_debug_battle_axis("debug_battle_axis", "Draw debug battle axis", "f
 
 const float BattleManager::ENEMY_SCALE = 0.0032f;
 
+const float BattleManager::ATTACK_SCALE = 0.0032f;
+
 const float BattleManager::PARTY_SCALE = 0.0039f;
 
 const float BattleManager::SCENE_SCALE = 0.0012f;
@@ -197,6 +199,39 @@ Enemy* BattleManager::ScriptGetEnemy(const unsigned int index){
     return &enemies_[index];
 }
 
+void BattleManager::AddAttackModel(
+  const unsigned int id, const std::string model, const Ogre::Vector3 pos,
+  const Ogre::Degree orientation, const std::string animation
+){
+    if (module_ != Module::BATTLE){
+        LOG_ERROR(
+          "Tried to add an attack model to the BattleManager,"
+          + " but the manager was not in battle mode."
+        );
+        return;
+    }
+    //Enemy* enemy = new Enemy(id, pos, front, visible, targeteable, active, cover);
+    //enemies_.push_back(*enemy);
+    EntityManager::getSingleton().AddEntity(
+      model + "_" + std::to_string(id), "attacks/" + model + ".mesh", pos, orientation,
+      Ogre::Vector3(ENEMY_SCALE, ENEMY_SCALE, ENEMY_SCALE), Ogre::Quaternion(1, 1, 0, 0), id
+    );
+    EntityManager::getSingleton().GetEntity(model + "_" + std::to_string(id))
+      ->SetRotation(orientation);
+    EntityManager::getSingleton().GetEntity(model + "_" + std::to_string(id))
+      ->ScriptSetDefaultAnimation(animation.c_str());
+}
+
+void BattleManager::ScriptAddAttackModel(
+  const unsigned int id, const char* model, const float x, const float y, const float z,
+  const int orientation, const char* animation
+){
+    AddAttackModel(
+      id, std::string(model), Ogre::Vector3(x, y, z),
+      Ogre::Degree(orientation), std::string(animation)
+    );
+}
+
 void BattleManager::AddCamera(
   const unsigned int id, const Ogre::Vector3 pos, const Ogre::Vector3 dir
 ){

+ 38 - 3
src/core/BattleManager.h

@@ -251,9 +251,39 @@ class BattleManager : public Manager, public Ogre::Singleton<BattleManager>{
         Enemy* ScriptGetEnemy(const unsigned int index);
 
         /**
-         * Loads enemy info from the enemy XML enemy file.
-         */
-        void Load();
+         * Adds an attack model to the battle.
+         *
+         * @param[in] id Attack model ID.
+         * @param[in] model Model name, without path or extension.
+         * @param[in] pos Model position.
+         * @param[in] orientation Model orientation.
+         * @param[in] animation Initial animation name for the model. If empty or null, the first
+         * available animation will be used.
+         */
+        void AddAttackModel(
+          const unsigned int id, const std::string model, const Ogre::Vector3 pos,
+          const Ogre::Degree orientation, const std::string animation
+        );
+
+        /**
+         * Adds an attack model to the battle.
+         *
+         * Simplified version of {@see AddAttackModel}, to be used from Lua scripts.
+         *
+         * @param[in] id Attack model ID.
+         * @param[in] model Model name, without path or extension.
+         * @param[in] x Model position, X coordinate.
+         * @param[in] y Model position, Y coordinate.
+         * @param[in] z Model position, Z coordinate.
+         * @param[in] orientation Model orientation.
+         * @param[in] animation Initial animation name for the model. If empty or null, the first
+         * available animation will be used.
+         */
+        void ScriptAddAttackModel(
+          const unsigned int id, const char* model, const float x, const float y, const float z,
+          const int orientation, const char* animation
+        );
+
 
         /**
          * Sets the battle layout.
@@ -376,6 +406,11 @@ class BattleManager : public Manager, public Ogre::Singleton<BattleManager>{
          */
         static const float SCENE_SCALE;
 
+        /**
+         * Scale factor for battle attack and spell models.
+         */
+        static const float ATTACK_SCALE;
+
         /**
          * The scene node.
          */

+ 7 - 0
src/core/ScriptManagerBinds.h

@@ -276,6 +276,13 @@ void ScriptManager::InitBinds(){
             "get_enemy",
             (Enemy*(BattleManager::*)(const unsigned int)) &BattleManager::ScriptGetEnemy
           )
+          .def(
+            "add_attack_model",
+            (void(BattleManager::*)(
+              const unsigned int, const char*, const float,
+              const float, const float, const int, const char*
+            )) &BattleManager::ScriptAddAttackModel
+          )
     ];
 
     // Commands for enemy handling.

+ 1 - 1
src/installer/data/AbFile.cpp

@@ -82,7 +82,7 @@ std::string AbFile::DecompileScript(u32 offset){
                     ab_file_.readU8();
                     break;
                 case 0xAA: // Unpause camera, no parameters.
-                    line << "    unpause_macera()";
+                    line << "    unpause_camera()";
                     break;
                 case 0xAD:
                      // Set effect, four parameters: