[Init]

RunTrigger ( "_Mission_Win" )
RunTrigger ( "_Client_Activate" )

Delay ( 5000 )

RunTrigger ( "King_of_the_Hill" )
RunTrigger ( "_Army_Activate" )
RunTrigger ( "_All_Units_Capture_Activate" )

HALT
[_Mission_Win]

SET @num_client = MP_GetClientNum ( )

LABEL BEGIN

SET @flag = -2

SET @i = 0

LABEL FOR

IF ( @i < @num_client ) THEN

   SET @valid = MP_IsClientValid ( @i )

   IF ( @valid = "TRUE" ) THEN

      SET @army = MP_GetClientArmy ( @i )
      SET @check = MP_GetClientArmyType ( @i )

      SetWorkArmy ( ARMY , @army )

      IF ( @check = "COMPUTER" ) THEN

         SET @units = GetNUnits ( ARMY , @army , HUMAN )
         SET @units_tech = GetNUnits ( ARMY , @army , ALL , NOT_EMPTY , OK_WEAPON , OK_ENGINE , AND_TANK , AND_SPG , AND_ARMOREDCAR , AND_ARTILLERY , AND_HMG , AND_FLAK , AND_CAR )

         ADD ( @units , @units_tech )

      ELSE

         SET @units = GetNUnits ( ARMY , @army , HUMAN , CREW )

      ENDIF

      IF ( @units = 0 ) THEN

         GOTO END

      ENDIF

      SET @ally = MP_GetClientAlliance ( @i )

      IF ( @flag = -2 ) THEN

         SET @winner = @i

         SET @flag = @ally

         GOTO END

      ENDIF

      IF ( @flag != -1 AND @flag = @ally ) THEN

         GOTO END

      ENDIF

      DELAY ( 5000 )

      GOTO BEGIN

   ENDIF

   LABEL END

   DELAY ( 100 )

   ADD ( @i , 1 )

   GOTO FOR

ENDIF

IF ( @flag = -2 ) THEN

   HALT

ENDIF

IF ( @flag = -1 ) THEN

   MP_ClientWin ( @winner )

   HALT

ENDIF

MP_AllianceWin ( @flag )

HALT
[_Client_Activate]

SET @num_client = MP_GetClientNum ( )

SET @client = 0

LABEL _FOR

IF ( @client < @num_client ) THEN

   SET @valid = MP_IsClientValid ( @client )

   IF ( @valid = "TRUE" ) THEN

      SET @ally = MP_GetClientAlliance ( @client )

      RunTriggerInstance ( "_Client_FOW" , @client , @client , @ally )      

      RunTriggerInstance ( "_Client_Fail" , @client , @client )

   ENDIF

   DELAY ( 100 )

   ADD ( @client , 1 )

   GOTO _FOR

ENDIF

HALT
[_Client_FOW]

Param IN @client
Param IN @ally

SET @num_client = MP_GetClientNum ( )

LABEL BEGIN

SET @i = 0

LABEL FOR

IF ( @i < @num_client ) THEN

   SET @valid = MP_IsClientValid ( @i )

   IF ( @valid = "TRUE" ) THEN

      SET @army = MP_GetClientArmy ( @i )

      SetWorkArmy ( ARMY , @army )

      SET @units = GetNUnits ( ARMY , @army , HUMAN , CREW )

      IF ( @units != 0 AND @i = @client ) THEN

         DELAY ( 5000 )

         GOTO BEGIN

      ENDIF

      IF ( @units = 0 ) THEN

         GOTO END

      ENDIF


      SET @new_ally = MP_GetClientAlliance ( @i )

      IF ( @ally = -1 OR @new_ally != @ally ) THEN

         GOTO END

      ENDIF

      DELAY ( 5000 )

      GOTO BEGIN

   ENDIF

   LABEL END

   DELAY ( 100 )

   ADD ( @i , 1 )

   GOTO FOR

ENDIF

MP_ClientChangeFogOfWar ( @client , DISABLE )

HALT
[_Client_Fail]

Param IN @client

LABEL BEGIN

SET @valid = MP_IsClientValid ( @client )

IF ( @valid = "TRUE" ) THEN

   SET @army = MP_GetClientArmy ( @client )

   SetWorkArmy ( ARMY , @army )

   SET @units = GetNUnits ( ARMY , @army , HUMAN , CREW )

   IF ( @units = 0 ) THEN

      MP_ClientFail ( @client )

      HALT

   ENDIF

   DELAY ( 5000 )

   GOTO BEGIN

ENDIF

HALT
[_Army_Attack_Flag]

PARAM IN @army

SetWorkArmy ( ARMY , @army )

SET @enemy_army = GetArmy ( ARMY , @army , ENEMY )

SET @group_name = StringMerge ( "_Attack_Group" , @army )
SET @group_name_vehicle = StringMerge ( "_Attack_Group_Vehicle" , @army )
SET @group_name_infantry = StringMerge ( "_Attack_Group_Infantry" , @army )
SET @rect = "Rect_Flag"


LABEL _BEGIN

SET @num = GetNUnits ( ARMY , @army , HUMAN , CREW )
SET @active = GetNUnits ( ARMY , @army , ALL , NOT_DEFEND )
SET @num_enemy = GetNUnits ( ARMY , @enemy_army , ALL , NOT_EMPTY , VISIBLE )

IF ( @num = 0 ) THEN

   HALT

ENDIF

SetWorkArmy ( ARMY , @army )

CreateGroupObject ( GROUP , @group_name_vehicle , ARMY , @army , ALL , 100 , AND_SPG , AND_ARMOREDCAR , AND_TANK , AND_FLAK )

CreateGroupObject ( GROUP , @group_name_infantry , ARMY , @army , HUMAN , 100 )

RunCommand ( GROUP , @group_name_infantry , STORM , RECT , @rect )
 
Delay ( 30000 )

RunCommand ( GROUP , @group_name_vehicle , ATTACK , RECT , @rect )

Delay ( 30000 )

GOTO _BEGIN
[_Army_Activate]

SET @num_clients = MP_GetClientNum ( )

SET @client = 0

LABEL _BEGIN

IF ( @client >= @num_clients ) THEN

   HALT

ENDIF

SET @valid = MP_IsClientValid ( @client )

SET @check = MP_GetClientArmyType ( @client )

IF ( @valid = "TRUE" AND @check = "COMPUTER" ) THEN

   SET @army = MP_GetClientArmy ( @client )

   RunTriggerInstance ( "_Recon_Activate_Infantry" , @army , @army )      
   RunTriggerInstance ( "_Recon_Activate_Vehicle" , @army , @army )      

   Delay ( 5000 )

   RunTriggerInstance ( "_Army_Attack_Flag" , @army , @army )      

ENDIF

ADD ( @client , 1 )

DELAY ( 300 )

GOTO _BEGIN
[_Recon_Unit]

PARAM IN @army   
PARAM IN @unit
PARAM IN @name

SetWorkArmy ( ARMY , @army )

LABEL _BEGIN

SET @num = GetNUnits ( UNIT , @unit , ALL , NOT_EMPTY , OK_ENGINE )

IF ( @num = 0 ) THEN

   HALT

ENDIF

CreateRectForRecon ( RECT , @name , ARMY , @army , 256 )

RunCommand ( UNIT , @unit , STORM , RECT , @name )

SET @num = GetNUnits ( ARMY , @army , ARTILLERY , OK_WEAPON )

IF ( @num = 0 ) THEN

   Delay ( 120000 )

   GOTO _BEGIN

ENDIF

Delay ( 90000 )

RunCommand ( UNIT , @unit , DEFEND )

HALT
[_Recon_Activate_Vehicle]

PARAM IN @army

SET @recon_group = StringMerge ( "_Recon_Group_Vehicle" , @army )

SetWorkArmy ( ARMY , @army )


LABEL _BEGIN

SET @num = GetNUnits ( ARMY , @army , ALL , AND_ARMOREDCAR , OK_ENGINE )

IF ( @num > 0 ) THEN

   CreateGroupObject ( GROUP , @recon_group , ARMY , @army , ALL , 2 , AND_ARMOREDCAR , OK_ENGINE )

   SET @i = 1

   GOTO _ARMOREDCAR_BEGIN

ENDIF

HALT


LABEL _ARMOREDCAR_BEGIN

   IF ( @i > @num ) THEN

      GOTO _ARMOREDCAR

   ENDIF

   SET @unitID = GetUnitID ( GROUP , @recon_group , @i )

   SET @unit_name = GetString ( @unitID )

   RunTriggerInstance ( "_Recon_Unit" , @unit_name , @army , @unitID , @unit_name )

   ADD ( @i , 1 )

   Delay ( 500 )

GOTO _ARMOREDCAR_BEGIN


LABEL _ARMOREDCAR

   SET @num = GetNUnits ( GROUP , @recon_group , ALL , AND_ARMOREDCAR , OK_ENGINE )

   IF ( @num = 0 ) THEN

      GOTO _BEGIN

   ENDIF

   Delay ( 30000 )

GOTO _ARMOREDCAR
[_Recon_Activate_Infantry]

PARAM IN @army

SET @recon_group = StringMerge ( "_Recon_Group_Infantry" , @army )

SetWorkArmy ( ARMY , @army )


LABEL _BEGIN

SET @num = GetNUnits ( ARMY , @army , ALL , SOLDIER )

IF ( @num > 0 ) THEN

   CreateGroupObject ( GROUP , @recon_group , ARMY , @army , ALL , 4 , SOLDIER )

   SET @i = 1

   GOTO _SOLDIER_BEGIN

ENDIF

HALT

LABEL _SOLDIER_BEGIN

   IF ( @i > @num ) THEN

      GOTO _SOLDIER

   ENDIF

   SET @unitID = GetUnitID ( GROUP , @recon_group , @i )

   SET @unit_name = GetString ( @unitID )

   RunTriggerInstance ( "_Recon_Unit" , @unit_name , @army , @unitID , @unit_name )

   ADD ( @i , 1 )

   Delay ( 500 )

GOTO _SOLDIER_BEGIN


LABEL _SOLDIER

   SET @num = GetNUnits ( GROUP , @recon_group , ALL , SOLDIER )

   IF ( @num = 0 ) THEN

      GOTO _BEGIN

   ENDIF

   Delay ( 30000 )

GOTO _SOLDIER
[_All_Units_Capture_Activate]

SET @all_army = GetArmy ( ARMY , 1 , ALL )

SET @group = StringMerge ( "_Group_Capture" , "_Army" )

SetWorkArmy ( ARMY , @all_army )
 
CreateGroupObject ( GROUP , @group ,  ARMY , @all_army , ALL , 100 , OK_WEAPON , AND_TANK , AND_SPG , AND_ARMOREDCAR , AND_ARTILLERY , AND_HMG , AND_FLAK )

SET @num = GetNUnits ( GROUP , @group , ALL ) 

SET @i = 1

LABEL BEGIN

IF ( @i > @num ) THEN

   HALT

ENDIF

SET @unitID = GetUnitID ( GROUP , @group , @i )
SET @unit_name = GetString ( @unitID )

RunTriggerInstance ( "_Capture_Unit" , @unitID , @unitID , @unit_name )

ADD ( @i , 1 )

Delay ( 100 )

GOTO BEGIN
[_Capture_Unit]

PARAM IN @unit
PARAM IN @name

SET @all_army = GetArmy ( ARMY , 1 , ALL )
SET @comp_army = GetArmy ( ARMY , 1 , COMPUTER )

LABEL BEGIN

SetWorkArmy ( ARMY , @all_army )

SET @active = GetNUnits ( UNIT , @unit , ALL , OK_WEAPON , AND_TANK , AND_SPG , AND_ARMOREDCAR , AND_ARTILLERY , AND_HMG , AND_FLAK )

IF ( @active = 0 ) THEN

	HALT

ENDIF

SET @active = GetNUnits ( UNIT , @unit , ALL , NOT_EMPTY )

IF ( @active = 0 ) THEN

	CreateRectByObject ( RECT , @name , -1 , UNIT , @unit , ALL , 20 , EMPTY )

	SetWorkArmy ( ARMY , @comp_army )

	CreateGroupByRect ( GROUP , @name , ARMY , @comp_army , HUMAN , 4 , RECT , @name , SOLDIER )

	SET @check = GetNUnits ( GROUP , @name , HUMAN )

	IF ( @check > 0 ) THEN

		RunCommand ( GROUP , @name , IN_CREW , UNIT , @unit )

	ENDIF

ENDIF

Delay ( 15000 )

GOTO BEGIN
[King_of_the_Hill]
BannerCreate ( POINT , "Flag" , "Flag" ,  -1 )

//---------------инициализация необходимых служебных переменных
// SET @@Timerwork  - нужна для проверки работал ли таймер
// SET @@Army_Timer = "Null" - присваеваю значение отличное от тех что будут использоваться в проверках для первого перехода

Label Marker0
SET @@Timerwork =  "False"
SET @@Army_Timer = "Null"

Label Marker1
Delay 500

//------Проверка какой из альянсов находится в районе флага.
Set @ClientsA = 0
Set @ClientsB = 1 
//set @ArmyA  = MP_GetClientArmy ( @ClientA )
//set @ArmyB  = MP_GetClientArmy ( @ClientB )
set @@A = GetNUnitsInArea ( Alliance , @ClientsA  , HUMAN , "Rect_Flag" , NOT_OLD_CREW , NO_PANIC )
set @@B = GetNUnitsInArea ( Alliance , @ClientsB  , HUMAN , "Rect_Flag" , NOT_OLD_CREW , NO_PANIC )
////определяем номер альянса каждого клиента, понадобиться для создания флагов с нужным параметром/////


//////////////////////////////////////////////////////////////////////////////////
////------Ветка проверок для 1Альянса (пока для первой армии. если она в ректе)///
//////////////////////////////////////////////////////////////////////////////////

///////--Модуль 1 по армии А.---
 IF  ( @@A > 0 AND @@B = 0 ) THEN   
   
     IF  ( @@Timerwork = "True" ) THEN 
   
        IF  ( @@Army_Timer = "TimerA" ) THEN
       
           GOTO MarkerA

        ELSE 

           StopTimer ( "GUI" )
           SetTimer ( "GUI" , 900 , REVERSE )
           Delay 500 
           StartTimer ( "GUI" )	 
           SendBriefingMessage ( "ArmyA_king_Hill" , "Projector" , 3000 )

////определение альянса клиента и создание  флага нужного альянса A ////////

//BannerDestroy ( "Neitral" )
//BannerDestroy ( "TeamB" )
//BannerDestroy ( "TeamA" ) 
//BannerCreate ( POINT , "Flag" , "TeamA" ,  @ally_type_A )

BannerChangeAlliance ( "Flag" , @ClientsA )

////определение цвета клиента и создание  флага нужного цвета A -конец-////////
           SET @@Army_Timer = "TimerA"	   
           Delay 500
           GOTO Marker1 

        ENDIF	

     ELSE 

        SetTimer ( "GUI" , 900 , REVERSE )
        Delay 500 
        StartTimer ( "GUI" )	 
        SET @@Army_Timer = "TimerA"
        SET @@Timerwork =  "True"
      SendBriefingMessage ( "ArmyA_king_Hill" , "Projector" , 3000 )
////определение альянса клиента и создание  флага нужного альянса B ////////

BannerChangeAlliance ( "Flag" , @ClientsA )

////определение альянса клиента и создание  флага нужного альянса B -конец-////////
Label MarkerA
        Delay 1000
        SET @work = TimerIsWork ( "GUI" )
        
           IF ( @work = "True" ) THEN

           GOTO Marker1 

           ELSE         
           
           SendBriefingMessage ( "ArmyA_WIN" , "Projector"  , 5000 )
           Delay 6000
           MP_AllianceWin ( @ClientsA )
           Halt
           ENDIF


     ENDIF

 ENDIF
/////////////////////////////////////////////////////////////////////////////////
////------Ветка проверок для 2Альянса (пока для второй армии. если она в ректе)//
/////////////////////////////////////////////////////////////////////////////////

///////--Модуль 1 по армии В.---
 IF  ( @@A = 0 AND @@B > 0 ) THEN   
   
     IF  ( @@Timerwork = "True" ) THEN 
   
        IF  ( @@Army_Timer = "TimerB" ) THEN
       
           GOTO MarkerB

        ELSE 

           StopTimer ( "GUI" )
           SetTimer ( "GUI" , 900 , REVERSE )
           Delay 500 
           StartTimer ( "GUI" )	 
             SendBriefingMessage ( "ArmyB_king_Hill" , "Projector" , 3000 )
////определение цвета клиента и создание  флага нужного цвета B ////////

BannerChangeAlliance ( "Flag" , @ClientsB )

////определение цвета клиента и создание  флага нужного цвета B -конец-////////
           SET @@Army_Timer = "TimerB"	   
           Delay 500
           GOTO Marker1 

        ENDIF	

     ELSE 

        SetTimer ( "GUI" , 900 , REVERSE )
        Delay 500 
        StartTimer ( "GUI" )	 
        SET @@Army_Timer = "TimerB"
        SET @@Timerwork =  "True"
       SendBriefingMessage ( "ArmyB_king_Hill" , "Projector" , 3000 )
////определение цвета клиента и создание  флага нужного цвета B ////////

BannerChangeAlliance ( "Flag" , @ClientsB )

////определение цвета клиента и создание  флага нужного цвета B -конец-////////
Label MarkerB
        Delay 1000
        SET @work = TimerIsWork ( "GUI" )
        
           IF ( @work = "True" ) THEN

           GOTO Marker1 

           ELSE         
           SendBriefingMessage ( "ArmyB_WIN" , "Projector" , 3000 )           
           Delay 6000
           MP_AllianceWin ( @ClientsB )
           Halt 
           ENDIF


     ENDIF

 ENDIF

//////////////////////////////////////////////////////////////////////
////------Ветка проверок для ситуации , когда обе армии в ректе./////
////////////////////////////////////////////////////////////////////


 IF ( @@A > 0 AND @@B > 0 ) THEN

     IF  ( @@Timerwork != "True" ) THEN 

         Delay 1000
         GOTO Marker1

     ELSE

        PauseTimer ( "GUI" , ON )
Label Marker3
        Delay 1000  

//////////////////////////CallTrigger ( "Black_box" )
Set @ClientsA = 0
Set @ClientsB = 1 
set @@A = GetNUnitsInArea ( Alliance , @ClientsA  , ALL , "Rect_Flag" , NOT_EMPTY , OK_WEAPON , OK_ENGINE , NO_PANIC )
set @@B = GetNUnitsInArea ( Alliance , @ClientsB  , ALL , "Rect_Flag" , NOT_EMPTY , OK_WEAPON , OK_ENGINE , NO_PANIC )
////определяем номер альянса каждого клиента, понадобиться для создания флагов с нужным параметром/////



////////////------начало блока проверок модуль3-------
///-------модуль 2 по армии А . таймер стоит на паузе . выясняется какая из армий останется в ректе

           IF  ( @@A > 0 AND @@B = 0 ) THEN   

               IF  ( @@Army_Timer = "TimerA" ) THEN
   
                  PauseTimer ( "GUI" , OFF )
                  Delay 500
                  GOTO Marker1
         
               ELSE

                  StopTimer ( "GUI" )
                  SetTimer ( "GUI" , 900 , REVERSE )
                  StartTimer ( "GUI" )	 
                  SendBriefingMessage ( "ArmyA_king_Hill" , "Projector" , 3000 )
////определение цвета клиента и создание  флага нужного цвета A ////////

BannerChangeAlliance ( "Flag" , @ClientsA )

////определение цвета клиента и создание  флага нужного цвета A -конец-////////
                  SET @@Army_Timer = "TimerA"	   
                  Delay 500
                  GOTO Marker1 

               ENDIF

           ENDIF
///-------модуль 2 по армии В . таймер стоит на паузе . выясняется какая из армий останется в ректе
 
            IF  ( @@A = 0 AND @@B > 0 ) THEN   

                IF  ( @@Army_Timer = "TimerB" ) THEN
   
                   PauseTimer ( "GUI" , OFF )
                   Delay 500
                   GOTO Marker1
         
                ELSE

                   StopTimer ( "GUI" )
                   SetTimer ( "GUI" , 900 , REVERSE )
                   StartTimer ( "GUI" )	 
                   SendBriefingMessage ( "ArmyB_king_Hill" , "Projector" , 3000 )
////определение цвета клиента и создание  флага нужного цвета B ////////

BannerChangeAlliance ( "Flag" , @ClientsB )

////определение цвета клиента и создание  флага нужного цвета B -конец-////////
                   SET @@Army_Timer = "TimerB"	   
                   Delay 500
                   GOTO Marker1 

                ENDIF

            ENDIF

///-------модуль 2 по обоим армиям . таймер стоит на паузе . выясняется какая из армий останется в ректе

            IF  ( @@A = 0 AND @@B = 0 ) THEN   
Label Marker4
                StopTimer ( "GUI" ) 

                  BannerChangeAlliance ( "Flag" , -1 )

                Delay 5000
                GOTO Marker0

            ENDIF
///-------Обе армии пока в ректе-------

            IF  ( @@A > 0 AND @@B > 0 ) THEN   

                Delay 4000
                GOTO Marker3

            ENDIF

////////////-------конец блока проверок модуль3-------

     ENDIF

 ENDIF
//////////////////////////////////////////////////////////////////////////////////
////------Ветка проверок для 1Альянса (пока для первой армии. если она в ректе)///
//////////////////////////////////////////////////////////////////////////////////


 IF  ( @@A = 0 AND @@B = 0 ) THEN  
  
  Delay 1000
  GOTO Marker4
 ENDIF

Halt
