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

Merge branch 'feature/battle_module' into develop

Iñigo Valentin 13 цаг өмнө
parent
commit
36d74bfd76

+ 57 - 1
data/data/screens/battle/battle_fx.lua

@@ -1583,6 +1583,62 @@ UiContainer.BattleFx = {
         return true
     end,
 
+    --- Models of the thrown things (the shuriken of the effects of magic.lgp).
+    THROW_MESH = "common_shuriken01",
+    THROW_TIME = 0.9,
+    THROW_SIZE = 14,
+
+    --- A thing flies from the thrower to the targets, spinning.
+    --
+    -- @param on_hit Called when it arrives to the first target.
+    -- @param on_end Called when it has finished.
+    play_throw = function(self, side, actor, target_group, targets, mesh, delay, on_hit, on_end)
+        local from = UiContainer.BattleUi:get_entity(side, actor)
+        local list = {}
+        for _, index in ipairs(targets or {}) do
+            local to = UiContainer.BattleUi:get_entity(target_group, index)
+            if to ~= nil then list[#list + 1] = to end
+        end
+        if from == nil or #list == 0 or not self.models_available then
+            on_hit()
+            on_end()
+            return
+        end
+        local x0, y0, z0 = from:get_position()
+        z0 = z0 + 1.2
+        local hit, arrived = false, 0
+        -- Weapons are models of the characters, bigger than the ones of the effects.
+        local is_weapon = mesh ~= nil and string.find(mesh, "characters/", 1, true) ~= nil
+        -- One thing flies to each target.
+        for _, to in ipairs(list) do
+            local x1, y1, z1 = to:get_position()
+            z1 = z1 + 1.0
+            local landed = false
+            self:spawn_piece({
+                mesh = mesh or self.THROW_MESH, x = x0, y = y0, z = z0, blend = Entity.BLEND_NORMAL, rx = 90,
+                life = self.THROW_TIME, delay = delay or 0,
+                update = function(piece, u, entity)
+                    -- A small arc.
+                    local arc = math.sin(u * math.pi) * 0.6
+                    entity:set_position(x0 + (x1 - x0) * u, y0 + (y1 - y0) * u, z0 + (z1 - z0) * u + arc)
+                    local size = is_weapon and 0.0039 or self.THROW_SIZE * self.MODEL_UNIT
+                    entity:set_scale(size, size, size)
+                    -- It flies straight, without spinning.
+                    if is_weapon then entity:set_model_rotation(0, 0, 0)
+                    else entity:set_model_rotation(90, 90, 0) end
+                    entity:set_alpha(1)
+                    if u >= 1 and not landed then
+                        landed = true
+                        -- The hit lands when the first one arrives, it ends with the last.
+                        if not hit then hit = true on_hit() end
+                        arrived = arrived + 1
+                        if arrived == #list then on_end() end
+                    end
+                end,
+            })
+        end
+    end,
+
     --- Shows the effects screen and clears everything.
     show = function(self)
         self:clear()
@@ -1617,7 +1673,7 @@ UiContainer.BattleFx = {
         -- Spells: JO_P02, grows and pulses.
         [0] = {texture = "battle_fx/common_jo_b02.png", tint = {1, 1, 1}, radius = 10, base = 10, height = 20},
         -- Limits: JO_P01, a flare that is narrow at the bottom.
-        [1] = {texture = "battle_fx/common_jo_b03.png", tint = {1, 1, 1}, radius = 10, base = 4.5, height = 11},
+        [1] = {texture = "battle_fx/common_jo_b03.png", tint = {1, 1, 1}, radius = 10, base = 4.5, height = 28.5},
         -- Enemy skills: JO_P03, shrinks toward the caster.
         [2] = {texture = "battle_fx/common_jo_b04.png", tint = {1, 1, 1}, radius = 10, base = 10, height = 20},
         -- Summons: JO_P02 with sparkles.

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 609 - 53
data/data/scripts/battle/battle_ui.lua


+ 26 - 4
data/data/scripts/debug_data.lua

@@ -65,7 +65,7 @@ Characters[0].armor.materia = {
     [3] = {id = 26, ap = 120000},  -- MP Turbo
     [4] = {id = 53, ap = 100000},  -- Restore
     [5] = {id = 35, ap = 200000},  -- Quadra Magic
-    [6] = {id = 52, ap = 100000},  -- Lightning
+    [6] = {id = 39, ap = 100000},  -- Throw mastered: Coin (Tifa has Throw level 1)
 }
 -- Attack commands to test: Double Cut gives 2x-Cut (AP below 100000) or 4x-Cut (100000 or more), and Slash-All
 -- gives Slash-All (AP below 130000) or Flash (130000 or more). Cloud has Double Cut (4x-Cut) paired with Steal
@@ -86,7 +86,7 @@ Characters[3].armor.materia = {}
 -- Time 65 (Haste, Slow, Stop), Destruct 68 (DeBarrier, DeSpell, Death). Cloud already has Barrier
 -- (62) in his armor.
 Characters[0].weapon.materia[2] = {id = 36, ap = 100000} -- Steal (mastered: Mug). Use ap = 0 for plain Steal.
-Characters[0].weapon.materia[3] = {id = 37, ap = 100000} -- Sense
+Characters[0].weapon.materia[3] = {id = 41, ap = 0} -- Deathblow (D.blow), instead of Sense (37)
 Characters[2].armor.materia[2] = {id = 68, ap = 100000}
 Characters[2].armor.materia[3] = {id = 57, ap = 100000}
 -- Limit bars to test the Limit command: everybody has the first limit and a bar of about 85% (217 of 255).
@@ -102,6 +102,26 @@ Characters[0].limit.current = 4
 Characters[0].limit.learned[4] = Characters[0].limit.learned[4] or {}
 Characters[0].limit.learned[4][1] = true
 Characters[0].limit.bar = 255
+-- One kill from limit level 2 (120 kills): the first enemy he defeats teaches him Blade Beam.
+Characters[0].kills = 119
+-- Barret (Mindblow) and Red XIII (Lunatic High): limit level 1 with the two techniques and a full bar. The ids
+-- are in begin_menu.lua option 7 (party Barret, Red XIII, Aerith). Their other levels: Barret 2 Grenade Bomb and
+-- Hammerblow, 3 Satellite Beam; Red XIII 2 Blood Fang and Stardust Ray, 3 Howling Moon (on himself) and Earth Rave.
+for _, c in ipairs({1, 4}) do
+    Characters[c].limit.current = 1
+    Characters[c].limit.learned[1] = Characters[c].limit.learned[1] or {}
+    Characters[c].limit.learned[1][1] = true
+    Characters[c].limit.learned[1][2] = true
+    Characters[c].limit.bar = 255
+    Characters[c].stats.hp.current = 99999
+    Characters[c].stats.mp.current = 99999
+end
+-- Aerith: limit level 3 (Planet Protector and Pulse of Life), with a full bar.
+Characters[3].limit.current = 3
+Characters[3].limit.learned[3] = Characters[3].limit.learned[3] or {}
+Characters[3].limit.learned[3][1] = true
+Characters[3].limit.learned[3][2] = true
+Characters[3].limit.bar = 255
 -- Summons: Choco/Mog 74, Shiva 75, Ifrit 76, Ramuh 77, Titan 78, Odin 79, Leviathan 80, Bahamut 81,
 -- Kjata 82, Alexander 83, Phoenix 84, Neo Bahamut 85, Hades 86, Typhoon 87, Bahamut ZERO 88,
 -- Knights of Round 89, Master Summon 90. They cost between 14 and 250 MP.
@@ -116,7 +136,7 @@ for i = 1, 24 do -- E. Skill list
     end
 end
 Characters[2].weapon.materia[2] = {id = 77, ap = 100000} -- Ramuh
-Characters[2].weapon.materia[3] = {id = 74, ap = 100000} -- Choco/Mog
+Characters[2].weapon.materia[3] = {id = 40, ap = 0} -- Morph, instead of Choco/Mog (74)
 Characters[2].weapon.materia[4] = {id = 14, ap = 130000} -- Slash-All (Flash)
 Characters[2].weapon.materia[6] = {id = 16, ap = 40000} -- Cover (100%: takes the attacks for allies with critical HP)
 Characters[2].armor.materia[4] = {id = 39, ap = 0} -- Throw (level 1; mastered it is Coin)
@@ -124,7 +144,9 @@ Characters[3].weapon.materia[0] = {id = 39, ap = 100000} -- Throw mastered: Aeri
 -- Double commands: Aerith W-Magic (with Fire and Restore to cast), Tifa W-Item, Cloud W-Summon (instead of Mega All, with Shiva).
 Characters[3].weapon.materia[1] = {id = 19, ap = 100000} -- W-Magic
 Characters[3].armor.materia[0] = {id = 49, ap = 100000} -- Fire
-Characters[3].armor.materia[1] = {id = 53, ap = 100000} -- Restore
+Characters[3].armor.materia[1] = {id = 53, ap = 100000}
+Characters[3].armor.materia[2] = {id = 43, ap = 0} -- Mime
+Characters[2].weapon.materia[5] = {id = 42, ap = 0} -- Manipulate
 Characters[2].armor.materia[5] = {id = 21, ap = 100000} -- W-Item
 Characters[0].weapon.materia[5] = {id = 20, ap = 100000} -- W-Summon
 Inventory.add_item(129, 3) -- Mythril Saber (to throw)

+ 9 - 0
doc/TODO.md

@@ -23,3 +23,12 @@ First step: play the scene with log level 3 and look at the time between the `di
 1/256 of a pixel per frame, sign of the speed) has not been checked against the original game. The far
 layer of mds5_4 has no such opcodes and still scrolls with the rest, and it is not known why it should
 not.
+
+## Battle: special limits
+
+Not done yet (kernel data in ff7.exe, ids 170-176, see `get_special_limit` in `battle_ui.lua`):
+
+- Cait Sith's Slots and Dice (additional effects 8 and 15, formula 6 with power 255): they need a small
+  interactive piece and the random effects of the reels.
+- Vincent's transformations (additional effect 3 with modifiers 0 to 3): they change the model, the
+  stats and the commands during the battle.

+ 8 - 2
src/core/ScriptManagerBinds.h

@@ -342,13 +342,19 @@ void ScriptManager::InitBinds(){
       "get_drop_rate", &Enemy::ScriptGetDropRate,
       "get_steal_count", &Enemy::ScriptGetStealCount,
       "get_steal_id", &Enemy::ScriptGetStealId,
-      "get_steal_rate", &Enemy::ScriptGetStealRate
+      "get_steal_rate", &Enemy::ScriptGetStealRate,
+      "get_morph", [](const Enemy& enemy){return static_cast<int>(enemy.GetMorph());},
+      "get_manip_count", [](const Enemy& enemy){return static_cast<int>(enemy.GetManipulateAttacks().size());},
+      "get_manip_attack", [](const Enemy& enemy, const int index){
+          const std::vector<unsigned int> attacks = enemy.GetManipulateAttacks();
+          if (index < 0 || index >= static_cast<int>(attacks.size())) return -1;
+          return static_cast<int>(attacks[index]);
+      }
       // TODO: Implement cover flags.
       // TODO: Implement immunities
       // TODO: Implement elements
       // TODO: Implement stealable items
       // TODO: Implement manipulability status and attacks.
-      // TODO: Implement morph item
     );
 
     // Commands for the audio manager.

+ 5 - 1
src/core/XmlEnemyFile.cpp

@@ -84,7 +84,11 @@ void XmlEnemyFile::LoadEnemy(Enemy& enemy){
         else if (
           node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "manipulate"
         ){
-            // TODO
+            // Attacks that can be used when the enemy is manipulated. No attacks means it can't be.
+            for (TiXmlNode* node_atk = node->FirstChild(); node_atk != nullptr; node_atk = node_atk->NextSibling()){
+                if (node_atk->Type() != TiXmlNode::TINYXML_ELEMENT || node_atk->ValueStr() != "attack") continue;
+                enemy.AddManipulateAttack(GetInt(node_atk, "id"));
+            }
         }
         else if (node->Type() == TiXmlNode::TINYXML_ELEMENT && node->ValueStr() == "ai"){
             // AI scripts, as hexadecimal bytecode.

+ 19 - 8
src/installer/InstallLog.cpp

@@ -34,23 +34,33 @@ class InstallLog::Tee : public std::streambuf{
         /**
          * Writes directly to the original stream, without capturing it.
          */
-        void WriteOriginal(const std::string& text){original_->sputn(text.data(), text.size());}
+        void WriteOriginal(const std::string& text){
+            std::lock_guard<std::mutex> lock(mutex_);
+            original_->sputn(text.data(), text.size());
+        }
 
     protected:
 
         int_type overflow(int_type c) override{
             if (c == traits_type::eof()) return traits_type::not_eof(c);
-            original_->sputc(static_cast<char>(c));
-            if (c == '\n'){
-                std::string line;
-                line.swap(line_);
-                if (!line.empty()) log_.AddCaptured(line);
+            // The streams are written from several threads (Ogre's worker threads, the audio conversions), so
+            // the line buffer and the original buffer are only touched with the lock. The line is sent to the
+            // log without it, since the log may write to the streams again.
+            std::string line;
+            {
+                std::lock_guard<std::mutex> lock(mutex_);
+                original_->sputc(static_cast<char>(c));
+                if (c == '\n') line.swap(line_);
+                else line_ += static_cast<char>(c);
             }
-            else line_ += static_cast<char>(c);
+            if (!line.empty()) log_.AddCaptured(line);
             return c;
         }
 
-        int sync() override{return original_->pubsync();}
+        int sync() override{
+            std::lock_guard<std::mutex> lock(mutex_);
+            return original_->pubsync();
+        }
 
     private:
 
@@ -58,6 +68,7 @@ class InstallLog::Tee : public std::streambuf{
         InstallLog& log_;
         std::streambuf* original_;
         std::string line_;
+        std::mutex mutex_;
 };
 
 InstallLog::InstallLog(): counts_{0, 0, 0}{}

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно