I am creating a c++ sdl based rpg game engine, and my goal is to be able to replicate a Final Fantasy with my engine. I was reading though AI scripts and saw a big script of Ozma super boss from Final Fantasy IX and got me curious, could this be implemented as a Lua script for example?

Function Ozma_Init
   set phase1attacklist = [ Doomsday ; Flare ; Meteor ; Holy ; Flare Star ; Death ]
   set phase1attackmplist = [ 16 ; 47 ; 40 ; 36 ; 0 ; 26 ]
   set phase2attacklist = [ Curse ; LV4 Holy ; LV5 Death ; Curaga ; Esuna ; Mini ]
   set phase2attackmplist = [ 0 ; 22 ; 20 ; 20 ; 22 ; 8 ]

Function Ozma_Loop
   if ( !InitFlag )
      set InitFlag = 1
      set SV_FunctionEnemy[ENABLE_SHADOW_FLAG] = 0
      set SV_FunctionEnemy[CURRENT_ATB] = SV_FunctionEnemy[MAX_ATB] - 1
      if ( ( SV_PlayerTeam & 1 ) && ( 1[LEVEL] % 4 == 0 ) )
         set lv4characters | = 1
      if ( ( SV_PlayerTeam & 2 ) && ( 2[LEVEL] % 4 == 0 ) )
         set lv4characters | = 2
      if ( ( SV_PlayerTeam & 4 ) && ( 4[LEVEL] % 4 == 0 ) )
         set lv4characters | = 4
      if ( ( SV_PlayerTeam & 8 ) && ( 8[LEVEL] % 4 == 0 ) )
         set lv4characters | = 8
      if ( ( SV_PlayerTeam & 1 ) && ( 1[LEVEL] % 5 == 0 ) )
         set lv5characters | = 1
      if ( ( SV_PlayerTeam & 2 ) && ( 2[LEVEL] % 5 == 0 ) )
         set lv5characters | = 2
      if ( ( SV_PlayerTeam & 4 ) && ( 4[LEVEL] % 5 == 0 ) )
         set lv5characters | = 4
      if ( ( SV_PlayerTeam & 8 ) && ( 8[LEVEL] % 5 == 0 ) )
         set lv5characters | = 8
      if ( FriendlyMonster_Complete )
         set SV_FunctionEnemy[ABSORB_ELEMENTS] &= ~SHADOW
         set SV_FunctionEnemy[WEAK_ELEMENTS] | = SHADOW
         BattleDialog( "The spiritual power raised the attack range." )
         Wait( 60 )
   if ( ReplenishATBStep == 0 )
      if ( GetAttacker == SV_FunctionEnemy )
         set ReplenishATBStep = 1
   elseif ( ReplenishATBStep == 1 )
      if ( GetAttacker == SV_FunctionEnemy )
         set ReplenishATBStep = 1
      else
         set ReplenishATBStep = 2
         set SV_FunctionEnemy[CURRENT_ATB] = SV_FunctionEnemy[MAX_ATB] - 1
   elseif ( ReplenishATBStep == 2 )
      if ( GetAttacker == SV_FunctionEnemy )
         set ReplenishATBStep = 1
   if ( SV_FunctionEnemy[HP] <= 10000 )
      while ( IsAttacking != 0 )
         Wait( 1 )
      RunBattleCode( Disable ATB )
      while ( GetBattleState != BATTLE_STATE_PAUSE )
         Wait( 1 )
      set SV_Target = SV_FunctionEnemy
      RunBattleCode( Run Camera, 9 )
      AttackSpecial( Death )
      set SV_FunctionEnemy[STAND_ANIMATION] = 1
      while ( IsAttacking != 0 )
         Wait( 1 )
      set SV_FunctionEnemy[DEFEATED_ON] = 1
      set Ozma_Defeated = TRUE
      RunBattleCode( End Battle, Victory )
      return
   Wait( 1 )
   loop


Function Ozma_ATB
   set phaseswitch = ~phaseswitch & 1
   if ( phaseswitch )
      set phase1selectedattack = RandomAttack( phase1attacklist )
      if ( phase1selectedattack == Doomsday )
         set SV_Target = ( SV_PlayerTeam | SV_EnemyTeam )
      elseif ( phase1selectedattack == Flare )
         set SV_Target = RandomInTeam( WithoutMatching( SV_PlayerTeam[CURRENT_STATUS], PETRIFY | DEATH | KO | REFLECT) & WithoutMatching( SV_PlayerTeam[AUTO_STATUS], REFLECT) )
      elseif ( phase1selectedattack == Meteor )
         set SV_Target = SV_PlayerTeam
      elseif ( phase1selectedattack == Holy )
      ...