Browse Source

Fixed the flags of the enemies of the battle formations

- The visible, targetable, active and direction flags were always set, because of the order of the operations. They are read from their bits.
- The targetable value of the enemies of the game had no initial value.
- Added a test for the flags.
- Noted in the TODO that the game doesn't apply the flags yet.
Iñigo Valentin 4 days ago
parent
commit
c2a7452a86

+ 21 - 0
doc/TODO.md

@@ -145,3 +145,24 @@ The fonts are built by the installer from WINDOW.BIN (see `WindowFonts`) and dra
 The console command `/resolution <width> <height> [full screen]` leaves menus, fields, the world map and battles broken. Screenshots (`/screenshot`) work. It doesn't seem new: the resize functions (`CmdResolution`, `GameFrameListener::windowResized` and the `OnResize` of the managers and widgets) are the same as before the code reorganization, but it hasn't been compared in the game with an older build.
 The console command `/resolution <width> <height> [full screen]` leaves menus, fields, the world map and battles broken. Screenshots (`/screenshot`) work. It doesn't seem new: the resize functions (`CmdResolution`, `GameFrameListener::windowResized` and the `OnResize` of the managers and widgets) are the same as before the code reorganization, but it hasn't been compared in the game with an older build.
 
 
 To check, not verified: whether `windowResized` is called at all when the size is changed with `Ogre::RenderWindow::resize` or `setFullscreen`, and not by the window system. Several `OnResize` functions are also empty (battle, world map, dialogs).
 To check, not verified: whether `windowResized` is called at all when the size is changed with `Ogre::RenderWindow::resize` or `setFullscreen`, and not by the window system. Several `OnResize` functions are also empty (battle, world map, dialogs).
+
+## Battle: the formation flags of the enemies are not applied
+
+Each enemy of a formation has the flags visible, targetable and main script active (`visible`, `targeteable` and
+`main_script_active` in the formation files). In the original data all of them are set for 2057 of the 2401 enemies,
+and the cleared ones are mostly enemies that join the battle later: Bizarro Sephiroth's parts, Mighty Grunt, Pyramid,
+the arms of the Guardian, etc. (199 invisible in 83 formations, 212 untargetable in 95 and 186 inactive in 85). The
+installer writes them, but the engine ignores them, so all the enemies are in the battle from the start.
+
+To apply them:
+
+- Hide the models of the invisible enemies when the battle starts, and mark them as hidden for the AI
+  (`combatant.hidden` in `battle_ui.lua`).
+- Leave the untargetable enemies out of the target selection.
+- Give no turns to the inactive enemies until a script activates them.
+
+Before that, check in the AI scripts of those formations how each hidden or inactive enemy is activated. This is not
+checked yet. A hidden enemy counts as alive (`is_defeated`), so a battle can't be won if the AI doesn't support what
+reveals it. The AI can already hide and reveal enemies (bit 14 of the status fields, `ai_write_actor`).
+
+The meaning of the `direction` flag (cleared for 95 enemies) is not verified, and the engine doesn't read it.

+ 6 - 5
src/installer/formats/BattleSceneConverter.cpp

@@ -364,11 +364,12 @@ namespace{
         enemy.row = data.row;
         enemy.row = data.row;
         for (int cover = 0; cover < 5; cover ++)
         for (int cover = 0; cover < 5; cover ++)
             enemy.cover[cover] = Has(data.cover_flags, 1u << cover) ? '1' : '0';
             enemy.cover[cover] = Has(data.cover_flags, 1u << cover) ? '1' : '0';
-        // TODO: These are always true: the comparisons are done before the bits are added.
-        enemy.visible = (data.flags == data.flags | 0x01);
-        enemy.direction = ((data.flags == data.flags | 0x02) ? 1 : 0);
-        enemy.targeteable = (data.flags == data.flags | 0x08);
-        enemy.main_script_active = (data.flags == data.flags | 0x10);
+        // All the bits are set for most enemies. The ones that join the battle later have them
+        // clear.
+        enemy.visible = Has(data.flags, 0x01);
+        enemy.direction = Has(data.flags, 0x02) ? 1 : 0;
+        enemy.targeteable = Has(data.flags, 0x08);
+        enemy.main_script_active = Has(data.flags, 0x10);
         return enemy;
         return enemy;
     }
     }
 
 

+ 2 - 0
src/modules/battle/Enemy.cpp

@@ -45,6 +45,7 @@ Enemy::Enemy(const unsigned int id):
   pos_(Ogre::Vector3(0, 0, 0)),
   pos_(Ogre::Vector3(0, 0, 0)),
   front_(false),
   front_(false),
   visible_(false),
   visible_(false),
+  targeteable_(false),
   active_(false),
   active_(false),
   cover_("00000")
   cover_("00000")
 {
 {
@@ -79,6 +80,7 @@ Enemy::Enemy(
   pos_(pos),
   pos_(pos),
   front_(front),
   front_(front),
   visible_(visible),
   visible_(visible),
+  targeteable_(targeteable),
   active_(active),
   active_(active),
   cover_(cover)
   cover_(cover)
 {
 {

+ 18 - 0
test/installer/formats/BattleScene.cpp

@@ -106,6 +106,24 @@ BOOST_AUTO_TEST_CASE(TestBattleSceneFormations){
     BOOST_CHECK_EQUAL(std::string(formations[1].enemies[0].cover, 5), "10001");
     BOOST_CHECK_EQUAL(std::string(formations[1].enemies[0].cover, 5), "10001");
 }
 }
 
 
+BOOST_AUTO_TEST_CASE(TestBattleSceneFormationEnemyFlags){
+    auto scene = EmptyScene();
+    for (auto& formation : scene->formation) for (auto& enemy : formation) enemy.id = 0xFFFF;
+    // An enemy with all the flags, and one with only the direction.
+    scene->formation[0][0].id = 1;
+    scene->formation[0][0].flags = 0xFFFFFFFF;
+    scene->formation[0][1].id = 2;
+    scene->formation[0][1].flags = 0xFFFFFFE6;
+    const std::vector<Formation> formations = BattleSceneConverter::Formations(*scene);
+    BOOST_REQUIRE_EQUAL(formations[0].enemies.size(), 2u);
+    const Formation::Enemy& full = formations[0].enemies[0];
+    BOOST_CHECK(full.visible && full.targeteable && full.main_script_active);
+    BOOST_CHECK_EQUAL(full.direction, 1);
+    const Formation::Enemy& waiting = formations[0].enemies[1];
+    BOOST_CHECK(!waiting.visible && !waiting.targeteable && !waiting.main_script_active);
+    BOOST_CHECK_EQUAL(waiting.direction, 1);
+}
+
 BOOST_AUTO_TEST_CASE(TestBattleSceneAiScripts){
 BOOST_AUTO_TEST_CASE(TestBattleSceneAiScripts){
     // The block of the second enemy at 6 bytes from the AI section: two scripts after 32 bytes.
     // The block of the second enemy at 6 bytes from the AI section: two scripts after 32 bytes.
     std::vector<u8> bytes(0x0E80 + 6 + 32 + 6, 0xFF);
     std::vector<u8> bytes(0x0E80 + 6 + 32 + 6, 0xFF);