1. Are you planning to upload your awesome map to Hive? Please review the rules here.
    Dismiss Notice
  2. Find your way through the deepest dungeon in the 18th Mini Mapping Contest Poll.
    Dismiss Notice
  3. A brave new world lies beyond the seven seas. Join the 34th Modeling Contest today!
    Dismiss Notice
  4. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
Hive 3 Remoosed BETA - NOW LIVE. Go check it out at BETA Hive Workshop! Post your feedback in this new forum BETA Feedback.
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Trigger Viewer

Tiriath Civil War - Telgarde - V2.2.w3x
Variables
Variables
Initialization
Red Base Cam
Sniper Screenshot
German Fortifications
Testing
Quest Copy
Day and Time
Melee Initialization
ObjectiveHelp
Colors
Player Messages Copy
Zoom Out
Timer
Music Triggering
Year Month Counter
YearTimer
Variables Copy
For Impory
Buildings/Units
Mine Copy
Mine
Oil Barrel
Upgrade
Battlestation Red
Upgrade Copy
fighter
Retire
Salvage
PowerPlantDeath
PowerPlantDeath Copy
Activate Red Guard
Summon Custodian Guard
Activate Waffen SS
Factory Pages 2
Factory Pages 2 Copy
Barracks Next Page
Barracks Previous Page
Upgrades
GameTick Copy
Initializer Copy
Radio Tower Recordings
Endurance Doctrine Upgrade
Innovative Doctrine Upgrade
Scorched Earth Doctrine Upgrade
Facist Ideology Upgrade
Communist Ideology Upgrade
Regressive Notions Upgrade
Monarchist Ideology Upgrade
Capitalist Ideology Upgrade
Capitalist Ideology Upgrade Copy
Civilian Structures
Civilian Add Red
Civilian Add Blue
Civilian Add Red Copy 2
Civilian Add Red Copy 3
Civilian Upgrade Red
Civilian Upgrade Blue
Civilian Sub Red
Civilian Sub Blue
Civilian Sub Red Copy 2
Civilian Sub Red Copy 3
Civilian Sub Red Doub
Civilian Sub Blue Doub
Income Intalization
Money
Mine Copy Copy
Oil Fields
Civilian Add Red Copy
Civilian Add Blue Copy
Civilian Add Blue Copy Copy
Civilian Add Blue Copy Copy 2
Civilian Upgrade Red Copy
Civilian Upgrade Blue Copy
Civilian Sub Red Copy
Civilian Sub Blue Copy
Civilian Sub Red Copy Copy
Civilian Sub Red Copy Copy 2
Civilian Sub Red Doub Copy
Civilian Sub Blue Doub Copy
Income Intalization Copy
Oil
Requirements
Unit Indexer System
Unit Indexer
-------------------------
Paratrooper System
Drop
New Retreat System
Cowardice
Red Retreat
Orange Retreat
Grey Retreat
Green Retreat
Dont Shoot Cowards
Cavalry Charge
Cavalry Charge
Charge End
Knockback System
Tank Crew System
Bail Out
Bail Out Copy
Bail Out Copy 2
Bail Out Copy 3
Capture cast
Capture debugg
Squad Formation
JASS Globals
Squad Setup
Squad Movement
Regroup
Regroup wait
Squad Reinforce
Squad Trained
Selection Thingie
Deselection Thingie
Unload
Squad Order Target
Squad Order No Target
Squad Order Point
Squad Death Ctrl
Crew Regroup
Summon Companion
Artillery Crew
Generate Squads
Mercenaries
Testing
German Rifleman Copy
German Rifleman Copy 2
German Reinforcement Activation
German Rifleman Move
German Rifleman Move Copy 3
Enemy Attacks Halt
Zambies
Zombie Timer
German Rifleman
German Rifleman Copy 3
German Rifleman Move Copy
German Rifleman Move Copy 3 Copy
Mini Mission Fun
Intercepting Troops 1
Intercepting Troops 2
Intercepting Troops 2 Copy
Cancel Counter Attack 1
Enter map-specific custom script code below. This text will be included in the map script after variables are declared and before any trigger code.
function EnemyTroops takes nothing returns boolean
    return IsUnitEnemy( GetFilterUnit(), ConvertedPlayer( udg_AI_PlayerNumber ) ) and IsUnitAliveBJ( GetFilterUnit() ) //and GetConvertedPlayerId(GetOwningPlayer(GetFilterUnit())) < 6
endfunction

// ********************************************************************
// checks if the unit type is a captain of the batalion
// returns array index defined in initialization, otherwise returns 0
function IsCaptain takes integer captain returns integer
    local integer i = 1
    loop
        if ( captain == udg_BattalionCaptain[i] ) then
            return i
        endif
        exitwhen i > udg_NrTypes
        set i = i + 1
    endloop
    return 0
endfunction
// ********************************************************************
// returns captain unit of the batalion
function GetCaptain takes group batalion returns unit
    local unit captain
    local group tempgroup = CreateGroup()
    call GroupAddGroup(batalion,tempgroup)
    loop
        set captain = FirstOfGroup(tempgroup)
        exitwhen LoadInteger(udg_hashtable, GetHandleId(captain), 1) == 1 // or captain == null
        call GroupRemoveUnit( tempgroup, captain )
    endloop
    call DestroyGroup(tempgroup)
    set tempgroup = null
    return captain
endfunction
// ********************************************************************
// checks if batalion has all his units
function IsComplete takes unit captain returns boolean
    local integer battallionIndex = LoadInteger(udg_hashtable, GetHandleId(captain), 0)
    if ( battallionIndex == 0 ) then
        return true
    endif
    if ( CountUnitsInGroup( udg_Battallion[battallionIndex] ) == udg_BattalionSize[IsCaptain(GetUnitTypeId( captain ))] +1 ) then
        return true
    else
        return false
    endif
endfunction
// ********************************************************************
function GetOrderAbility takes integer batalionOrder, integer caster returns integer
    local integer i = 1
    loop
        exitwhen i == 30
        if ( batalionOrder == udg_BattalionSpellOrderID[i] and caster == udg_BattalionSpellCaster[i] ) then
            return i
        endif
        set i = i + 1        
    endloop
    return 0
endfunction

function GetBatalionAbility takes integer batalionSpell returns integer
    local integer i = 1
    loop
        exitwhen i == 30
        if ( batalionSpell == udg_BattalionSpellAbility[i] ) then
            return i
        endif
        set i = i + 1        
    endloop
    return 0
endfunction
Name Type Is Array Initial Value
AI_AttackGroup group Yes
AI_Defenders group Yes
AI_Movement group Yes
AI_Player_Copy player No
AI_PlayerNumber integer No 0
BatalionHash_Beast integer No 9
BatalionHash_Crew integer No 8
BatalionHash_Guards integer No 6
BatalionHash_Order integer No 2
BatalionHash_Summonable integer No 7
BatalionHash_TargetUnit integer No 5
BatalionHash_TargetX integer No 3
BatalionHash_TargetY integer No 4
BattalionCaptain unitcode Yes
BattalionGoldCost integer Yes
BattalionPowerCost integer Yes
BattalionSize integer Yes
BattalionSpellAbility abilcode Yes
BattalionSpellCaster unitcode Yes
BattalionSpellOrderID integer Yes
BattalionSpellOrderString string Yes
BattalionTimer real Yes
BattalionTroop unitcode Yes
Battallion group Yes
BattallionCount integer No
BattallionIndex integer No
BattallionLimit integer No 330
BattallionQueued group No
BattallionRegroup real No 700.00
BuildBool boolean No
BuildingCount integer No 0
CaptureCountTotal integer Yes
captureId integer No
CaptureStarted boolean No
CaptureTimer timer Yes
CaptureTimerWindow timerdialog Yes
CapturingPlayer player Yes
CavalryGroup group No
check boolean No
ClsR_Ability abilcode No
ClsR_AbilityLevels integer No
ClsR_AbilityOrder ordercode No
ClsR_AreaOfEffect real Yes
ClsR_Caster unit Yes
ClsR_casterOwner player Yes
ClsR_Counter integer Yes
ClsR_Counter2 integer Yes
ClsR_CountRockets boolean No
ClsR_DamagePerRocket real Yes
ClsR_DelayPerWave real No
ClsR_Dummy unitcode No
ClsR_Facing real Yes
ClsR_FacingZ real Yes
ClsR_FirstWaveDelay real No
ClsR_Hashtable hashtable No
ClsR_HitTargetOnly boolean No
ClsR_Last integer No
ClsR_lastX real Yes
ClsR_lastY real Yes
ClsR_lastZ real Yes
ClsR_Level integer Yes
ClsR_MakeUnitExplode boolean No
ClsR_mapBorder real Yes
ClsR_MaxIndex integer No
ClsR_Next integer Yes
ClsR_NoTarget boolean No
ClsR_posX real Yes
ClsR_posY real Yes
ClsR_posZ real Yes
ClsR_PreferTargetUnit boolean No
ClsR_Prev integer Yes
ClsR_realTimer real Yes
ClsR_realTimer2 real Yes
ClsR_Recyclable integer No
ClsR_Recycle integer Yes
ClsR_Rocket unit Yes
ClsR_RocketAttackType attacktype No
ClsR_RocketDamageType damagetype No
ClsR_rocketModel effect Yes
ClsR_RocketsCollisionSize real No
ClsR_RocketsCount integer Yes
ClsR_RocketsCrashHeight real No
ClsR_RocketsDamageRange real Yes
ClsR_RocketsExpirationTime real No
ClsR_RocketsInterval real No
ClsR_RocketsMaxFacingVariation real No
ClsR_RocketsMaxPitchVariation real No
ClsR_RocketsMinFacingVariation real No
ClsR_RocketsMinPitchVariation real No
ClsR_RocketsModel string No
ClsR_RocketsPerSecond integer No
ClsR_RocketsPerWave integer No
ClsR_RocketsSize real No
ClsR_RocketsSpawnHeightBonus real No
ClsR_RocketsSpawnOffset real No
ClsR_RocketsSpeedBase real Yes
ClsR_RocketsTurnAcceleration real Yes
ClsR_RocketsUnitsHeightBonus real No
ClsR_Stage integer Yes
ClsR_Target unit Yes
ClsR_targetCollision real Yes
ClsR_targetType integer Yes
ClsR_tempGroup group No
ClsR_Timer timer No
ClsR_ZLocator location No
Count integer Yes
cpAttacker player Yes
cpId integer No
cpNotified integer Yes
cpOwner player Yes
cpPointsGroup group No
cpProgress integer Yes
cpUnit unit Yes
cpVAR_CaptureMessage string No
cpVAR_CaptureRate integer No
cpVAR_CaptureReq integer No
cpVAR_ControlPointIncGold integer Yes
cpVAR_ControlPointIncLumber integer Yes
cpVAR_ControlPointType unitcode Yes
cpVAR_ControlPointTypeId integer No
cpVAR_FloatOffset real No
cpVAR_IncomeRate real No
cpVAR_NotifierCooldown integer No
cpVAR_PlayerColour string Yes
cpVAR_PointLostMessage string No
cpVAR_Range real No
cpVAR_SystemStyle integer No
cpVAR_WarningMessage string No
DefendingPlayer player Yes
DidBuild boolean No
DummySystems unit No
ETG_Angle real No
ETG_BuffAbilityBurn abilcode No
ETG_BuffAbilityPoison abilcode No
ETG_BurnDamageBase real No
ETG_BurnDamagePerLevel real No
ETG_BurnDurationBase real No
ETG_BurnDurationPerLevel real No
ETG_DissapateModel string No
ETG_Dummy unitcode No
ETG_Explodeables group No
ETG_ExplosionDamageBase real No
ETG_ExplosionDamagePerLevel real No
ETG_ExplosionModel string No
ETG_FireModel string No
ETG_GasCloudAOE real No
ETG_GasCloudDurationBase real No
ETG_GasCloudDurationPerLevel real No
ETG_GasHeadsBase integer No
ETG_GasHeadsPerLevel integer No
ETG_GasModel string No
ETG_GasProjectileFlyHeight real No
ETG_GasProjectileModel string No
ETG_GasProjectileScale real No
ETG_GasSpeed real No
ETG_GasSpreadBase real No
ETG_GasSpreadPerLevel real No
ETG_GasSpreadSpeed integer No
ETG_Group group No
ETG_Hash hashtable No
ETG_HeightMultiplyer real No
ETG_i integervar No
ETG_MinRange real No
ETG_PoisonDamageBase real No
ETG_PoisonDamagePerLevel real No
ETG_PoisonDurationBase real No
ETG_PoisonDurationPerLevel real No
ETG_PoisonModel string No
ETG_RealCache real Yes
ETG_RockModel string No
ETG_Spell abilcode No
ETG_Spell2 abilcode No
ETG_SpreadRandomiser real No
ETG_TempGroup group No
ETG_TempInteger integer No
ETG_TempPoint location No
ETG_TempPoint2 location No
ETG_TempReal real No
ETG_TempU unit No
ETG_TempU2 unit No
ETG_U unit No
ETG_UHandle integer No
ETG_UHandleC integer No
ETG_VolcanicProjectileScale real No
ETG_VolcanicRockAoeBase real No
ETG_VolcanicRockAoePerLevel real No
Faction1Income integer No
Faction2Income integer No
Faction3Income integer No
Faction4Income integer No
Gold hashtable No
handle integer No
hashtable hashtable No
Income_timer timer No
KB integervar No
KB_Angle real Yes
KB_Distance real Yes
KB_Group group Yes
KB_Int integer No
KB_Off boolean Yes
KB_Point location Yes
KB_Skip integer No
KB_Spam integer Yes
KB_Speed real Yes
KB_Target unit Yes
KB_Times integer No
LastBuilder unit No UnitNull
LastBuilderHandle handle No
NrTypes integer No 50
Owner hashtable No
OwningPlayer player No
Players force No
Players_Copy player Yes
PointRotate location No
Production hashtable No
Selected1 group Yes
Status integer Yes
STESYS_CheckGroup group No
STESYS_DefaultVision integer No
STESYS_Loop_Integer integer No
STESYS_PERIODIC_TIMEOUT real No
STESYS_SightAbility abilcode No
STESYS_TempBool boolean Yes
STESYS_TempGroup group Yes
STESYS_TempInteger integer Yes
STESYS_TempLoc location Yes
STESYS_TempPlayer player No
STESYS_TempReal real Yes
STESYS_TempVis fogmodifier Yes
STESYS_TempVis1 fogmodifier Yes
STESYS_TempVis2 fogmodifier Yes
STESYS_TempVis3 fogmodifier Yes
STESYS_TempVis4 fogmodifier Yes
STESYS_TempVis5 fogmodifier Yes
STESYS_TimeDay real No
STESYS_TimeNight real No
STESYS_Trigger trigger Yes
STESYS_Unit unit Yes
STESYS_VisionInteger integer No
Summon integer No 6
target unit No
TempBuilding unit No
tempCaptureRate integer No
TempCommander unit No
tempForce force No
TempGroiup group No
TempHero unit No
tempId integer No
Tempint integer No
tempInt integer No
tempLoc location No
tempLoc2 location No
Tempplayer player No
TempPoint location No
Temppoint location No
Temppoint01 location No
TempRealX real No
tempString string No
tempUGAllies group No
tempUGEnemies group No
tempUGPerPlayer group Yes
Tempunit unit No
testIndex integer No
testValue integer No
timer real No
Town handle No
Towns hashtable No
TownUnit unit No UnitNull
TranslatePlayerNumber integer No 5
TurnTime integer No 120
UDex integer No
UDexGen integer No
UDexNext integer Yes
UDexPrev integer Yes
UDexRecycle integer No
UDexUnits unit Yes
UDexWasted integer No
UNITDATA_Hash hashtable No
UNITDATA_SIGHTDAY integer No
UNITDATA_SIGHTNIGHT integer No
UNITDATA_UnitType unitcode No
UNITDATA_UnitTypeInteger integer No
UnitIndexerEnabled boolean No
UnitIndexEvent real No
UnitIndexLock integer Yes
Unittype unitcode No
Red Base Cam
  Events
    Map initialization
  Conditions
  Actions
    Camera - .Apply. gg_cam_Red_Base_Cam for Player 1 (Red) over 0 seconds
    Camera - .Apply. gg_cam_Green_Base_Cam for Player 23 (Emerald) over 0 seconds
    Camera - .Apply. gg_cam_Grey_Base_Cam for Player 9 (Gray) over 0 seconds
    Camera - .Apply. gg_cam_Orange_Base_Cam for Player 6 (Orange) over 0 seconds
Sniper Screenshot
  Events
    Map initialization
  Conditions
  Actions
    Cinematic - Turn cinematic mode On for (All players)
    Camera - .Apply. gg_cam_Camera_001 for Player 1 (Red) over 1.00 seconds
German Fortifications
  Events
    Map initialization
  Conditions
  Actions
    Cinematic - Turn cinematic mode On for (All players)
    Camera - .Apply. gg_cam_German_Fortifications for Player 1 (Red) over 1.00 seconds
    Unit Group - Pick every unit in (Units in Region_004 <gen>) and do (Actions)
      Loop - Actions
        Unit - Order (Picked unit) to Attack-Move To.(Center of Region_005 <gen>)
Testing
  Events
    Time - Elapsed game time is 2.00 seconds
  Conditions
  Actions
    Player - Add 1000 to Player 1 (Red).Current gold
    Player - Add 1000 to Player 1 (Red).Current lumber
Quest Copy
  Events
    Time - Elapsed game time is 0.01 seconds
  Conditions
  Actions
    Quest - Create a Optional quest titled Changelog with the description V.2- Revamped Terrain- Revamped Units, Models and Tech Tree- Revamped Retreat System and added a proper Cavalry Charge ability., using icon path ReplaceableTextures\CommandButtons\BTNScrollOfHaste.blp
    Quest - Create a Required quest titled Commands with the description zoom out = zooms the camera out, using icon path ReplaceableTextures\CommandButtons\BTNAvatarOff.blp
Day and Time
  Events
    Map initialization
  Conditions
  Actions
    Game - Set the time of day to 6.00
    Environment - Set sky to war3mapImported\SummerSphereCT2.mdx (skymodelstring)
    Custom script: call SetDayNightModels("war3mapImported\\DNCAnimated2.mdx","war3mapImported\\DNCAnimated2.mdx")
Default melee game initialization for all players
Melee Initialization
  Events
    Map initialization
  Conditions
  Actions
    Sound - Play war3mapImported\Violet Evergarden OST- Track 38- The Storm.mp3 (musictheme).
    Sound - Play Soundtrack9 <gen>
ObjectiveHelp
  Events
    Map initialization
  Conditions
  Actions
    Quest - Create a Required quest titled Assitance/Help with the description Households provide credit income, credits are used to hire, purchase or construct anything.Oil Fields provide oil income, oil is used for ground, air and naval vehicles.To increase income in any of these, build more households and/or oil fields., using icon path ReplaceableTextures\CommandButtons\BTNCallToArms.blp
Colors
  Events
    Map initialization
  Conditions
  Actions
    Player - Change color of Player 2 (Blue) to Red, Changing color of existing units
    Player - Change color of Player 7 (Green) to Orange, Changing color of existing units
    Player - Change color of Player 10 (Light Blue) to Gray, Changing color of existing units
    Player - Change color of Player 24 (Peanut) to Emerald, Changing color of existing units
Player Messages Copy
  Events
    Time - Elapsed game time is 5 seconds
  Conditions
  Actions
    Quest - Display to (All players) the Hint message: To increase credit income, build households.
    Wait 5.00 seconds
    Quest - Display to (All players) the Hint message: To increase oil income, build oil fields.
    Wait 5.00 seconds
    Quest - Display to (All players) the Hint message: To zoom out, type "zoom out" in chat.
Zoom Out
  Events
    Player - Player 1 (Red) types a chat message containing zoom out (stringnoformat) as An exact match
    Player - Player 6 (Orange) types a chat message containing zoom out (stringnoformat) as An exact match
    Player - Player 9 (Gray) types a chat message containing zoom out (stringnoformat) as An exact match
    Player - Player 23 (Emerald) types a chat message containing zoom out (stringnoformat) as An exact match
  Conditions
  Actions
    Camera - Set (Triggering player)'s camera Height Offset to 1000.00 over 1.00 seconds
Timer
  Events
    Time - Elapsed game time is 0.10 seconds
  Conditions
  Actions
    Countdown Timer - Start (Last started timer) as a Repeating timer that will expire in 20.00 seconds
    Countdown Timer - Create a timer window for (Last started timer) with title Oil/Credit Income
    Countdown Timer - Change the color of the title for (Last created timer window) to (50.00%, 80.00%, 50.00%) with 0% transparency
    Countdown Timer - Show (Last created timer window)
Music Triggering
  Events
  Conditions
  Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        (Random integer number between 1 and 10) Greater than 8
      Then - Actions
        Sound - Play war3mapImported\slavank2.mp3 (musictheme).
        Wait 157.00 seconds
        Trigger - Run Music_Triggering <gen> (checking conditions)
      Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            (Random integer number between 1 and 8) Greater than 6
          Then - Actions
            Sound - Play war3mapImported\belarmia.mp3 (musictheme).
            Wait 154.00 seconds
            Trigger - Run Music_Triggering <gen> (checking conditions)
          Else - Actions
            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              If - Conditions
                (Random integer number between 1 and 6) Greater than 4
              Then - Actions
                Sound - Play war3mapImported\yabloch1.mp3 (musictheme).
                Wait 171.00 seconds
                Trigger - Run Music_Triggering <gen> (checking conditions)
              Else - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  If - Conditions
                    (Random integer number between 1 and 4) Greater than 2
                  Then - Actions
                    Sound - Play war3mapImported\preobr.mp3 (musictheme).
                    Wait 127.00 seconds
                    Trigger - Run Music_Triggering <gen> (checking conditions)
                  Else - Actions
                    Sound - Play war3mapImported\tachank1.mp3 (musictheme).
                    Wait 127.00 seconds
                    Trigger - Run Music_Triggering <gen> (checking conditions)
scope YearTimer initializer Init

   public function Timer takes nothing returns nothing
        local integer y = 0
        local integer m
        local string now = "Year "
       
        call TimerDialogSetRealTimeRemaining(turndisplay, turn_time)
        set month = month + 1
       
        set m = month
        loop
            exitwhen m < 12
            set m = m - 12
            set y = y + 1
        endloop
        set now = now + I2S(y + 1) + ", Month " + I2S(m + 1)
        call TimerDialogSetTitle(turndisplay, now)
       
        // GAME TICK OCCURS
       
        //call ForForce(players, function PlayerTick)
        call ForForce(GetPlayersAll(), function PlayerTick)
    endfunction

    public function Actions takes nothing returns nothing
        call TimerStart(turn, turn_time, true, function Timer)
        call TimerDialogSetTitle(turndisplay, "Year 0, Month 0")
        call TimerDialogSetRealTimeRemaining(turndisplay, turn_time)
        call TimerDialogDisplay(turndisplay, true)
    endfunction

    //===========================================================================
    private function Init takes nothing returns nothing
        set yeartimer = CreateTrigger(  )
       
        set turn = CreateTimer()
        set turndisplay = CreateTimerDialog(turn)
       
        //call TriggerRegisterTimerEvent(t, 0, false)
        //call TriggerAddAction( yeartimer, function Actions )
    endfunction

endscope
 
Mine Copy
  Events
    Unit - A unit Begins construction
  Conditions
    (Unit-type of (Constructing structure)) Equal to Land Mine
  Actions
    Unit - Create 1.Land Mine for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing (Random angle) degrees
    Unit - Remove (Triggering unit) from the game
Mine
  Events
    Unit - A unit Begins construction
  Conditions
    (Unit-type of (Constructing structure)) Equal to Land Mine
  Actions
    Unit - Create 1.Land Mine for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing (Random angle) degrees
    Unit - Remove (Triggering unit) from the game
Oil Barrel
  Events
    Unit - A unit Finishes construction
  Conditions
    (Unit-type of (Triggering unit)) Equal to Oil Barrel
  Actions
    Unit - Change ownership of (Triggering unit) to Neutral Passive and Change color
Upgrade
  Events
    Unit - A unit Finishes casting an ability
  Conditions
    (Ability being cast) Equal to
  Actions
    Unit - Replace (Triggering unit) with a using The new unit's max life and mana
Battlestation Red
  Events
    Unit - A unit enters (Entire map)
  Conditions
    (Unit-type of (Triggering unit)) Equal to
    (Owner of (Triggering unit)) Equal to Player 1 (Red)
  Actions
    Sound - Play Superweapon <gen>
    Game - Display to (All players) the text: The Iron Imperialists have constructed a |c00FF7F00X-55 Warlord|r! Beware!
    Player - Make Unavailable for training/construction by Player 1 (Red)
Upgrade Copy
  Events
    Unit - A unit Finishes casting an ability
  Conditions
    (Ability being cast) Equal to
  Actions
    Unit - Create 2. for Player 1 (Red) at (Position of (Triggering unit)) facing Default building facing degrees
fighter
  Events
    Unit - A unit Is attacked
  Conditions
    Or - Any (Conditions) are true
      Conditions
        (Unit-type of (Attacking unit)) Equal to Biplane (Standard)
        (Unit-type of (Attacking unit)) Equal to |c007d7d7dMesserschmitt Bf 109|r (German)
        (Unit-type of (Attacking unit)) Equal to |c00FF0000Yakovlev Yak-9|r (Russian)
        (Unit-type of (Attacking unit)) Equal to |c007d7d7dJunkers Ju 87 Stuka|r (German)
        (Unit-type of (Attacking unit)) Equal to |c00FF7F00Supermarine Spitfire|r (English)
  Actions
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        ((Attacked unit) is alive) Equal to True
      Then - Actions
        Wait 1.00 seconds
        Unit - Order (Attacking unit) to Move To.(Random point in (Region centered at (Position of (Attacking unit)) with size (1000.00, 1000.00)))
        Wait 3.00 seconds
        Unit - Order (Attacking unit) to Attack.(Attacked unit)
      Else - Actions
Retire
  Events
    Unit - A unit Finishes casting an ability
  Conditions
    (Ability being cast) Equal to Retire
  Actions
    Unit - Remove (Triggering unit) from the game
Salvage
  Events
    Unit - A unit Finishes casting an ability
  Conditions
    (Ability being cast) Equal to Salvage
  Actions
    Player - Add 10 to (Owner of (Triggering unit)).Current gold
    Player - Add 10 to (Owner of (Triggering unit)).Current lumber
    Unit - Kill (Triggering unit)
PowerPlantDeath
  Events
    Unit - A unit Dies
  Conditions
    (Unit-type of (Dying unit)) Equal to Oil Barrel
  Actions
    Unit - Create 1.Oil Barrel Explosion for Neutral Passive at (Position of (Dying unit)) facing Default building facing degrees
    Unit - Kill (Last created unit)
PowerPlantDeath Copy
  Events
    Unit - A unit Dies
  Conditions
    (Unit-type of (Dying unit)) Equal to Land Mine
  Actions
    Unit - Create 1.Mine Explosion for Neutral Passive at (Position of (Dying unit)) facing Default building facing degrees
    Unit - Kill (Last created unit)
Activate Red Guard
  Events
    Unit - A unit Begins casting an ability
  Conditions
    (Ability being cast) Equal to |c00FF0000Activate Red Guard|r (Trigger)
  Actions
    Unit - Create 12.|c00FF0000Red Army Infantry|r (Russian) for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing Default building facing degrees
    Unit - Create 1.|c00FF0000T-34/76|r (Russian) for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing Default building facing degrees
    Unit - Create 6.|c00FF0000Red Army Anti-Tank Rifleman|r (Russian) for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing Default building facing degrees
    Unit - Create 4.|c00FF0000Red Army Shock Troop|r (Russian) for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing Default building facing degrees
    Player - Add -70 to (Owner of (Triggering unit)).Current gold
    Player - Add -50 to (Owner of (Triggering unit)).Current lumber
Summon Custodian Guard
  Events
    Unit - A unit Begins casting an ability
  Conditions
    (Ability being cast) Equal to |c007d7d7dSummon Custodian Guard|r (Trigger)
  Actions
    Unit - Create 12.|c007d7d7dDeutschland Landsknecht|r (German) for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing Default building facing degrees
    Unit - Create 3.|c007d7d7dDeutschland Ironclad HMG|r (Mobile) (German) for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing Default building facing degrees
    Unit - Create 1.|c007d7d7dDeutschland Ironclad Officer|r (German) for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing Default building facing degrees
    Player - Add -60 to (Owner of (Triggering unit)).Current gold
    Player - Add -40 to (Owner of (Triggering unit)).Current lumber
Activate Waffen SS
  Events
    Unit - A unit Begins casting an ability
  Conditions
    (Ability being cast) Equal to |c007d7d7dActivate Waffen SS|r (Trigger)
  Actions
    Unit - Create 12.|c007d7d7dWehrmacht Waffen SS|r (Assault STG) (German) for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing Default building facing degrees
    Unit - Create 3.|c007d7d7dWehrmacht Panzerschreck|r (German) for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing Default building facing degrees
    Player - Add -60 to (Owner of (Triggering unit)).Current gold
    Player - Add -40 to (Owner of (Triggering unit)).Current lumber
Factory Pages 2
  Events
    Unit - A unit Finishes casting an ability
  Conditions
    (Ability being cast) Equal to Next Page (Starter Factory 2.0)
  Actions
    Unit - Replace (Triggering unit) with a Military Factory (Page 2) using The old unit's relative life and mana
Factory Pages 2 Copy
  Events
    Unit - A unit Finishes casting an ability
  Conditions
    (Ability being cast) Equal to Previous Page (Starter Factory 2.0)
  Actions
    Unit - Replace (Triggering unit) with a Military Factory using The old unit's relative life and mana
Barracks Next Page
  Events
    Unit - A unit Finishes casting an ability
  Conditions
    (Ability being cast) Equal to Next Page (Starter Barracks 2.0)
  Actions
    Unit - Replace (Triggering unit) with a Regiment Barracks (Page 2) using The old unit's relative life and mana
Barracks Previous Page
  Events
    Unit - A unit Finishes casting an ability
  Conditions
    (Ability being cast) Equal to Previous Page (Starter Barracks 2.0)
  Actions
    Unit - Replace (Triggering unit) with a Regiment Barracks using The old unit's relative life and mana
scope GameTick initializer Init

    globals
        trigger gametick
   
        private integer cgol = 0
        private integer cpro = 0
        private integer pid = 0
       
        private constant integer TICK_CONSUMERS = 0
        private constant integer TICK_PRODUCERS = 1
        private constant integer TICK_UPKEEP = 2
       
        private integer tick = 0
    endglobals

    private function GetMineResources takes nothing returns boolean
        local integer pid = GetUnitTypeId(GetFilterUnit())
        return pid == 'h00H' or pid == 'h00E'
    endfunction

    private function GetMine takes nothing returns boolean
        local integer pid = GetUnitTypeId(GetFilterUnit())
        return not (pid == 'h00H' or pid == 'h00E')
    endfunction

    private function MakeUnit takes player p, integer kind, integer size, location at, integer town returns nothing
        local integer total_units = LoadInteger(towns, town, towns_units)
        local unit u = CreateUnitAtLoc(p, kind, at, Rad2Deg(GetRandomReal(-bj_PI, bj_PI)))
        local integer id = GetHandleId(u)
       
        call SaveInteger(towns, town, towns_units, total_units + size)
       
        call SaveInteger(towns, id, 0, town)
        call SaveInteger(towns, id, 1, size)
       
        set u = null
    endfunction
   
    private function InfirmaryPick takes nothing returns boolean
        if IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE) or IsUnitType(GetFilterUnit(), UNIT_TYPE_DEAD) then
            return false
        endif
        if GetUnitStatePercent(GetFilterUnit(), UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE) > 95 then
            return false
        endif        
        return true
    endfunction
   
    private function RepairBuilding takes unit u, real percent returns nothing
        local real hp = GetUnitState(u, UNIT_STATE_LIFE)
        local real heal = hp * percent
       
        if hp / GetUnitState(u, UNIT_STATE_MAX_LIFE) <= 0.95 then
            call SetUnitState(u, UNIT_STATE_LIFE, hp + heal)
            call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Items\\ResourceItems\\ResourceEffectTarget.mdl", GetUnitX(u), GetUnitY(u)))
        endif
    endfunction
   
    private function InfirmaryHeal takes nothing returns nothing
        local unit u = GetEnumUnit()
        local real hp = GetUnitState(u, UNIT_STATE_LIFE)
        local real heal = 15.0
       
        call SetUnitState(u, UNIT_STATE_LIFE, hp + heal)
        call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\ReplenishMana\\SpiritTouchTarget.mdl", GetUnitX(u), GetUnitY(u)))
       
        set u = null
    endfunction

    private function ActionTick takes nothing returns nothing
        local unit bu = GetEnumUnit()
        local player p = GetOwningPlayer(bu)
        local integer bh = GetHandleId(bu)
        local integer bid = GetBuildId(bu)
        local integer town = LoadInteger(towns, bid, 0)
        local integer a = LoadInteger(actions, bh, 0)
        //local integer total_units = LoadInteger(towns, town, towns_units)
        local integer units = GetUnitSlotsLeft(town)
        local location loc = GetUnitLoc(bu)
        local boolean repeat = LoadBoolean(actions, bh, 0)
        local integer cur = LoadInteger(actions, bh, 1)
        local integer max = LoadInteger(actions, bh, 2)
        local boolean done = false
        local group infir = null
       
        if a == ACTION_REST then
            //call DisplayTextToForce(GetPlayersAll(), GetUnitName(bu) + " is resting!")
        elseif a == ACTION_SWORDSMEN then // Swordsmen, 3g cost
            set units = min(units, 2)
            loop
                exitwhen units <= 0 or cgol < 3
               
                call MakeUnit(p, 'h001', 1, loc, town)
               
                set cgol = cgol - 3
                set units = units - 1
                set done = true
            endloop
        elseif a == ACTION_BOWMEN then // Bowmen, 6g cost
            set units = min(units, 2)
            loop
                exitwhen units <= 0 or cgol < 6
               
                call MakeUnit(p, 'h00M', 1, loc, town)
               
                set cgol = cgol - 6
                set units = units - 1
                set done = true
            endloop
        elseif a == ACTION_BARD then // Bard, 15g cost
            if cgol >= 15 and units > 0 then
                call MakeUnit(p, 'h00S', 1, loc, town)
                set cgol = cgol - 15
                set done = true
            endif
        elseif a == ACTION_UPGRADE_GUARD_TOWER then
            if cpro >= 12 then
                set cur = cur + 1
                set cpro = cpro - 12
               
                if cur == max then
                    set bu = SwitchBuild(bu, 'h00K')
                    set bh = GetHandleId(bu)
                    set done = true
                else
                    call DisplayAction(bu, GetOwningPlayer(bu))
                endif
            endif
        elseif a == ACTION_ENGINEER then
            if cgol >= 20 and units > 0 then
                call MakeUnit(p, 'h00V', 1, loc, town)
                set cgol = cgol - 20
                set done = true
            endif
        elseif a == ACTION_TREBUCHET then
            if cgol >= 30 and cpro >= 14 then
                set cur = cur + 1
                set cgol = cgol - 30
                set cpro = cpro - 14
                if cur >= max then
                    call CreateUnitAtLoc(Player(PLAYER_NEUTRAL_PASSIVE), 'h00W', loc, Rad2Deg(GetRandomReal(-bj_PI, bj_PI)))
                    set done = true
                else
                    call DisplayAction(bu, GetOwningPlayer(bu))
                endif
            endif
        elseif a == ACTION_RAIDER then
            if cgol >= 8 and units > 0 then
                set cgol = cgol - 8
                call MakeUnit(p, 'h00X', 2, loc, town)
                set done = true
            endif
        elseif a == ACTION_MERCENARY then
            set units = min(units, 3)
            loop
                exitwhen units <= 0 or cgol < 4
               
                call MakeUnit(p, 'h00Y', 1, loc, town)
               
                set cgol = cgol - 4
                set units = units - 1
                set done = true
            endloop
        endif
       
        if GetUnitTypeId(bu) == 'h00Q' then
            if cgol >= 10 then
                set cgol = cgol - 10
                set infir = CreateGroup()
               
                call GroupEnumUnitsInRangeOfLoc(infir, loc, 200, Condition(function InfirmaryPick))
                call ForGroup(infir, function InfirmaryHeal)
               
                call DestroyGroup(infir)
                set infir = null
            endif
        endif
       
        call SaveInteger(actions, bh, 1, cur)
       
        if done == true then
            if not repeat then
                call Actions_SetBuildingAction(bu, ACTION_REST)
            endif
            call SaveInteger(actions, bh, 1, 0) // cur
            call SaveInteger(actions, bh, 2, 0) // max
            call DisplayAction(bu, GetOwningPlayer(bu))
        endif
       
        call RemoveLocation(loc)
        set loc = null
        set bu = null
    endfunction
   
    private function TownUpgrade takes unit u, integer town returns nothing
        local real health = GetUnitStatePercent(u, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE) / 100.0
        local location loc = GetUnitLoc(u)
        local real facing = GetUnitFacing(u)
        local integer ohid = GetHandleId(u)
        local integer otid = GetUnitTypeId(u)
        local integer tid = 0
        local unit new = null
        local group all = LoadGroupHandle(towns, GetPlayerId(GetOwningPlayer(u)), 0)
        local group tws = LoadGroupHandle(towns, GetPlayerId(GetOwningPlayer(u)), 1)
       
        if otid == 'h007' then
            set tid = 'h008'
        elseif otid == 'h008' then
            set tid = 'h00N'
        else
            set tid = 'h007'
        endif
       
        call GroupRemoveUnit(all, u)
        call GroupRemoveUnit(tws, u)
        call RemoveUnit(u)
        set new = CreateUnit(GetOwningPlayer(u), tid, GetLocationX(loc), GetLocationY(loc), facing)
       
        call GroupAddUnit(all, new)
        call GroupAddUnit(tws, new)
        call RemoveSavedInteger(townid, ohid, 0)
        call SaveInteger(townid, GetHandleId(new), 0, town)
        call SaveUnitHandle(townid, town, 0, new)
        call SetUnitState(new, UNIT_STATE_LIFE, health * GetUnitState(new, UNIT_STATE_MAX_LIFE))
       
        call RemoveLocation(loc)
        set loc = null
        set new = null
    endfunction

    private function TownTick takes nothing returns nothing
        local unit tu = GetEnumUnit()
        local integer id = GetHandleId(tu)
        local integer town = GetTownId(tu)
        local integer bt = GetUnitTypeId(tu)
        local boolean built = LoadBoolean(towns, town, towns_built)
        local integer a = LoadInteger(actions, id, 0)
        local boolean repeat = LoadBoolean(actions, id, 0)
        local location loc = GetUnitLoc(tu)
        local integer cur = LoadInteger(actions, id, 1)
        local integer max = LoadInteger(actions, id, 2)
       
        set cur = cur + 1
       
        call SaveInteger(actions, id, 1, cur)
       
        if a == ACTION_SETTLE then
            if cur >= max then
                call Actions_SetBuildingAction(tu, ACTION_REST)
                call DisplayTag(tu, GetOwningPlayer(tu), "|CFF90FF90New settlers!")
                call MakeUnit(GetOwningPlayer(tu), 'h00D', 1, loc, town)
                call SaveInteger(towns, town, towns_units, LoadInteger(towns, town, towns_units) - 1)
            else
                call DisplayAction(tu, GetOwningPlayer(tu))
            endif
        elseif a == ACTION_UPGRADE_TOWN then
            if bt == 'h006'  and cpro >= 20 then
                set cpro = cpro - 20
                call DisplayAction(tu, GetOwningPlayer(tu))
            elseif bt == 'h007' and cpro >= 30 then
                set cpro = cpro - 30
                call DisplayAction(tu, GetOwningPlayer(tu))
            elseif bt == 'h008' and cpro >= 40 then
                set cpro = cpro - 40
                call DisplayAction(tu, GetOwningPlayer(tu))
            else
                set cur = cur - 1
            endif
           
            if cur >= max then
                call Actions_SetBuildingAction(tu, ACTION_REST)
                call TownUpgrade(tu, town)
            endif
        elseif a == ACTION_DEFENDING then
            call RepairBuilding(tu, 0.03)
            call DisplayAction(tu, GetOwningPlayer(tu))
        elseif a == ACTION_BEGIN_DEFENDING then
            if cur >= max then
                call Actions_SetBuildingAction(tu, ACTION_DEFENDING)
            endif
            call DisplayAction(tu, GetOwningPlayer(tu))
        elseif a == ACTION_SCOUT and cgol >= 5 and GetUnitSlotsLeft(town) > 0 then
            call Actions_SetBuildingAction(tu, ACTION_REST)
            set cgol = cgol - 5
            call MakeUnit(GetOwningPlayer(tu), 'h00Z', 1, loc, town)
        endif
       
        call SaveInteger(actions, id, 1, cur)
       
        /*if not repeat and a != 0 then
            call SaveInteger(actions, id, 0, 0)
            call DisplayAction(tu, GetOwningPlayer(tu))
        endif*/

           
        call RemoveLocation(loc)
        set loc = null
        set tu = null
    endfunction

    private function BuildingTick takes nothing returns nothing
        local unit bu = GetEnumUnit()
        local integer bid = GetBuildId(bu)
        local integer town = LoadInteger(towns, bid, 0)
        local integer bt = GetUnitTypeId(bu)
        local boolean built = LoadBoolean(towns, bid, 1)
        local boolean town_upgrading = IsTownUpgrading(town)
        local boolean town_settling = LoadInteger(actions, GetHandleId(GetTownUnit(town)), 0) == ACTION_SETTLE
        local boolean town_defending = IsTownDefending(town)
       
        if built then
            if tick == TICK_UPKEEP then
                if bt == 'h00C' then                // HOVEL
                    set cgol = cgol - 2
                elseif bt == 'h00F' then            // BARRACKS
                    set cgol = cgol - 2
                elseif bt == 'h00E' then            // WORKSHOP
                    set cgol = cgol - 1
                elseif bt == 'h00P' then            // MUSICIANS GUILD
                    set cgol = cgol - 3
                elseif bt == 'h00J' then            // WATCH TOWER
                    set cgol = cgol - 1
                elseif bt == 'h00K' then            // GUARD TOWER
                    set cgol = cgol - 3
                elseif bt == 'h00G' then            // ENGINEERS GUILD
                    set cgol = cgol - 10
                    set cpro = cpro - 6
                elseif bt == 'h00I' then            // STABLES
                    set cgol = cgol - 5
                    set cpro = cpro - 2
                elseif bt == 'h00O' then            // MERCENARY POST
                    set cgol = cgol - 20
                endif
            elseif tick == TICK_CONSUMERS and (not (town_upgrading or (town_defending and bt != 'h00Q'))) then
                if bt == 'h00F' then                // BARRACKS
                    call ActionTick()
                elseif bt == 'h00P' then            // MUSICIANS GUILD
                    call ActionTick()
                elseif bt == 'h00J' then            // WATCH TOWER
                    call ActionTick()
                elseif bt == 'h00G' then            // ENGINEERS' GUILD
                    call ActionTick()
                elseif bt == 'h00I' then            // STABLES
                    call ActionTick()
                elseif bt == 'h00O' then            // MERCENARY POST
                    call ActionTick()
                elseif bt == 'h00Q' then            // INFIRMARY
                    call ActionTick()
                endif
            elseif tick == TICK_PRODUCERS and (not (town_settling or town_defending)) then
                // Produce only if the town is not currently settling or fortifying.
                if bt == 'h00H' then                // MARKET (gold)
                    set cgol = cgol + market_gold
                    call DestroyEffect(AddSpecialEffect("UI\\Feedback\\GoldCredit\\GoldCredit.mdl", GetUnitX(bu), GetUnitY(bu)))
                elseif bt == 'h00E' then            // WORKSHOP (production)
                    set cpro = cpro + workshop_prod
                endif
            endif
           
            if town_defending then
                call RepairBuilding(bu, 0.05)
            endif
        endif
       
        set bu = null
    endfunction

    private function PlayerTick takes nothing returns nothing
        local player p = GetEnumPlayer()
        local integer id = GetPlayerId(p)
        // Save old values for delta calc.
        local integer ogol = GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD)
        local integer opro = GetPlayerState(p, PLAYER_STATE_RESOURCE_LUMBER)
        // Delta
        local integer dgol
        local integer dpro
        local group builds = LoadGroupHandle(towns, id, 0)
       
        set pid = id
        set cgol = GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) + base_income_gold
        set cpro = GetPlayerState(p, PLAYER_STATE_RESOURCE_LUMBER) + base_income_prod
       
        // Run all production buildings first, then run resource consumers.
       
        set tick = TICK_PRODUCERS
        call ForGroup(builds, function BuildingTick)
        set tick = TICK_UPKEEP
        call ForGroup(builds, function BuildingTick)
        set tick = TICK_CONSUMERS
        call ForGroup(builds, function BuildingTick)
        call ForGroup(LoadGroupHandle(towns, id, 1), function TownTick)
       
        // Add remaining resources.
       
        call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, cgol)
        call SetPlayerState(p, PLAYER_STATE_RESOURCE_LUMBER, cpro)
       
        // Find resource delta.
        set dgol = cgol - ogol
        set dpro = cpro - opro
       
        // Inform player how much they made.
        call DisplayTimedTextToPlayer(p, 0, 0, 5.0, "|CFFFDC689==[ |CFF00AEEFFACTION INCOME |CFFFDC689]==")
        if dgol > 0 then
            call DisplayTimedTextToPlayer(p, 0, 0, 5.0, "   |CFFFFF200Gold: |CFF00FF00+" + I2S(dgol))
        else
            call DisplayTimedTextToPlayer(p, 0, 0, 5.0, "   |CFFFFF200Gold: |CFFED1C24" + I2S(dgol))
        endif
        if dpro > 0 then
            call DisplayTimedTextToPlayer(p, 0, 0, 5.0, "   |CFFFF8A00Production:  |CFF00FF00+" + I2S(dpro))
        else
            call DisplayTimedTextToPlayer(p, 0, 0, 5.0, "   |CFFFF8A00Production:  |CFFED1C24" + I2S(dpro))
        endif
       
        set p = null
        set builds = null
    endfunction

    public function Timer takes nothing returns nothing
        local integer y = 0
        local integer m
        local string now = "Year "
       
        call TimerDialogSetRealTimeRemaining(turndisplay, turn_time)
        set month = month + 1
       
        set m = month
        loop
            exitwhen m < 12
            set m = m - 12
            set y = y + 1
        endloop
        set now = now + I2S(y + 1) + ", Month " + I2S(m + 1)
        call TimerDialogSetTitle(turndisplay, now)
       
        // GAME TICK OCCURS
       
        //call ForForce(players, function PlayerTick)
        call ForForce(GetPlayersAll(), function PlayerTick)
    endfunction

    public function Actions takes nothing returns nothing
        call TimerStart(turn, turn_time, true, function Timer)
        call TimerDialogSetTitle(turndisplay, "Year 0, Month 0")
        call TimerDialogSetRealTimeRemaining(turndisplay, turn_time)
        call TimerDialogDisplay(turndisplay, true)
    endfunction

    //===========================================================================
    private function Init takes nothing returns nothing
        set gametick = CreateTrigger(  )
       
        set turn = CreateTimer()
        set turndisplay = CreateTimerDialog(turn)
       
        //call TriggerRegisterTimerEvent(t, 0, false)
        //call TriggerAddAction( gametick, function Actions )
    endfunction

endscope
Create Demolish ability for buildings and Retire ability for units
Pillager who steals, TREBUCHETS are neutral units, and can be controlled by engineers to move or attack. Engineer ability that prevents trebuchet destruction (costs 5p per turn)
globals
    boolean DEBUGGING = false

    hashtable townid
    hashtable towns
    integer month = 0
    integer towns_num = 0
    integer towns_owned = 1
    integer towns_hovels = 2
    integer towns_units = 3
    integer towns_built = 4
    integer towns_tag = 5
    integer towns_name = 6
   
    integer hovel_units = 4
   
    integer market_gold = 5
    integer workshop_prod = 3
    real turn_time = 15.0
   
    integer base_income_gold = 4
    integer base_income_prod = 2
    integer base_gold = 0 // originally 10
    integer base_prod = 20 // originally 4
   
    timer turn
    timerdialog turndisplay
   
    hashtable s2b
    integer array buildings[12]
    hashtable bcost
    hashtable max_buildings
   
    hashtable actions
   
    integer nexttownid = 9999
    integer nextbuildid = 99999
   
    constant integer BUILDING_CONSTRUCTING = 0
    constant integer BUILDING_COMPLETED = 1
    constant integer BUILDING_REMOVE = 2
   
    constant integer ACTION_REST = 0
    constant integer ACTION_SWORDSMEN = 1
    constant integer ACTION_BOWMEN = 2
    constant integer ACTION_SETTLE = 3
    constant integer ACTION_BARD = 4
    constant integer ACTION_UPGRADE_GUARD_TOWER = 5
    constant integer ACTION_UPGRADE_TOWN = 6
    constant integer ACTION_ENGINEER = 7
    constant integer ACTION_TREBUCHET = 8
    constant integer ACTION_RAIDER = 9
    constant integer ACTION_MERCENARY = 10
    constant integer ACTION_BEGIN_DEFENDING = 11
    constant integer ACTION_DEFENDING = 12
    constant integer ACTION_SCOUT = 13
    // Special value.
    constant integer ACTION_OLD = 999
endglobals

function GetNextBuildId takes nothing returns integer
    set nextbuildid = nextbuildid + 1
    return nextbuildid
endfunction

function GetBuildUnit takes integer id returns unit
    return LoadUnitHandle(townid, id, 10)
endfunction

function GetBuildId takes unit build returns integer
    return LoadInteger(townid, GetHandleId(build), 10)
endfunction

function GetNextTownId takes nothing returns integer
    set nexttownid = nexttownid + 1
    return nexttownid
endfunction

function GetTownUnit takes integer id returns unit
    return LoadUnitHandle(townid, id, 0)
endfunction

function GetTownId takes unit town returns integer
    return LoadInteger(townid, GetHandleId(town), 0)
endfunction

function IsTown takes unit u returns boolean
    return HaveSavedInteger(townid, GetHandleId(u), 0)
endfunction

function GetOwnerId takes unit u returns integer
    return LoadInteger(towns, GetBuildId(u), 0)
endfunction

function GetUnitOwnerId takes unit u returns integer
    return LoadInteger(towns, GetHandleId(u), 0)
endfunction

function IsTownUpgrading takes integer town returns boolean
    local integer tid = GetHandleId(GetTownUnit(town))
    return LoadInteger(actions, tid, 0) == ACTION_UPGRADE_TOWN
endfunction

function IsTownDefending takes integer town returns boolean
    local integer tid = GetHandleId(GetTownUnit(town))
    return LoadInteger(actions, tid, 0) == ACTION_DEFENDING
endfunction

function HasOwningTown takes unit u returns boolean
    return HaveSavedInteger(towns, GetBuildId(u), 0)
endfunction

function HasUnitOwningTown takes unit u returns boolean
    return HaveSavedInteger(towns, GetHandleId(u), 0)
endfunction

function min takes integer one, integer two returns integer
    if one > two then
        return two
    else
        return one
    endif
endfunction

function SwitchBuild takes unit from, integer to returns unit
    local integer id = GetBuildId(from)
    local integer town = GetOwnerId(from)
    local real facing = GetUnitFacing(from)
    local location loc = GetUnitLoc(from)
    local unit u = null
    local group g = LoadGroupHandle(towns, town, towns_owned)
    local boolean repeat = false
    local real health = GetUnitStatePercent(from, UNIT_STATE_LIFE, UNIT_STATE_MAX_LIFE) / 100.0
   
    // Transfer repeat, clear action.
   
    call RemoveSavedInteger(actions, GetHandleId(from), 0)
    set repeat = LoadBoolean(actions, GetHandleId(from), 0)
    call RemoveSavedBoolean(actions, GetHandleId(from), 0)
   
    // Cleanup old unit.
   
    call RemoveSavedInteger(townid, GetHandleId(from), 10)
    call RemoveSavedInteger(towns, GetHandleId(from), 0)
    call RemoveSavedBoolean(towns, GetHandleId(from), 1)
    call GroupRemoveUnit(g, from)
    call GroupRemoveUnit(LoadGroupHandle(towns, GetPlayerId(GetOwningPlayer(from)), 0), from)
    call RemoveUnit(from)
   
    set u = CreateUnit(GetOwningPlayer(from), to, GetLocationX(loc), GetLocationY(loc), facing)
   
    call SetUnitState(from, UNIT_STATE_LIFE, health * GetUnitState(from, UNIT_STATE_MAX_LIFE))
   
    call SaveBoolean(actions, GetHandleId(u), 0, repeat)
   
    call SaveInteger(towns, GetHandleId(u), 0, town)
    call SaveBoolean(towns, GetHandleId(u), 1, true)
    call GroupAddUnit(g, u)
    call SaveUnitHandle(townid, id, 10, u)
    call SaveInteger(townid, GetHandleId(u), 10, id)
    call GroupAddUnit(LoadGroupHandle(towns, GetPlayerId(GetOwningPlayer(u)), 0), u)
   
    call RemoveLocation(loc)
    set loc = null
    set g = null
    return u
endfunction

function DisplayTag takes unit u, player p, string s returns nothing
    local texttag txt
    local location loc = GetUnitLoc(u)
    local integer uh = GetHandleId(u)
   
    if HaveSavedHandle(towns, uh, 11) then
        if not HaveSavedHandle(towns, GetHandleId(LoadTextTagHandle(towns, uh, 11)), 0) then
            call DestroyTextTag(LoadTextTagHandle(towns, uh, 11))
        endif
        call RemoveSavedHandle(towns, uh, 11)
    endif
   
    set txt = CreateTextTag()
    call SaveTextTagHandle(towns, uh, 11, txt)
   
    //call SetTextTagText(txt, "", 0.020)
    call SetTextTagPos(txt, GetLocationX(loc) - 32, GetLocationY(loc), 0.023)
    call SetTextTagLifespan(txt, 1.5)
    call SetTextTagVisibility(txt, true)
    call SetTextTagFadepoint(txt, 0.3)
    call SetTextTagPermanent(txt, false)
    call SetTextTagVelocity(txt, 0, 0.012)
   
    if GetLocalPlayer() == p then
        call SetTextTagText(txt, s, 0.020)
    endif
   
    set txt = null
    call RemoveLocation(loc)
    set loc = null
endfunction

function SetTownName takes unit t, string n returns nothing
    local integer id = GetTownId(t)
    local texttag tag// = LoadTextTagHandle(towns, id, towns_tag)
    local location loc = GetUnitLoc(t)
   
    call SaveStr(towns, id, towns_name, n)
   
    if HaveSavedHandle(towns, id, towns_tag) then
        call RemoveSavedHandle(towns, GetHandleId(LoadTextTagHandle(towns, id, towns_tag)), 0)
        call DestroyTextTag(LoadTextTagHandle(towns, id, towns_tag))
        call RemoveSavedHandle(towns, id, towns_tag)
    endif
    set tag = CreateTextTag()
    call SaveTextTagHandle(towns, id, towns_tag, tag)
    call SaveUnitHandle(towns, GetHandleId(tag), 0, t)
   
    call SetTextTagPermanent(tag, true)
    call SetTextTagVisibility(tag, true)
    call SetTextTagPos(tag, GetLocationX(loc) - 64, GetLocationY(loc), 200.0)
    call SetTextTagText(tag, GetPlayerColorString(GetOwningPlayer(t)) + n, 0.03)
   
    call RemoveLocation(loc)
    set loc = null
    set tag = null
endfunction

function InitTown takes unit t returns nothing
    local integer tid = GetNextTownId()
    local integer pid = GetPlayerId(GetOwningPlayer(t))
   
    // Save town id.
    call SaveUnitHandle(townid, tid, 0, t)
    call SaveInteger(townid, GetHandleId(t), 0, tid)
   
    //call SaveTextTagHandle(towns, tid, towns_tag, CreateTextTag())
    call SaveGroupHandle(towns, tid, towns_owned, CreateGroup())
    call SaveBoolean(towns, tid, towns_built, true)
   
    call GroupAddUnit(LoadGroupHandle(towns, pid, 0), t)
    call GroupAddUnit(LoadGroupHandle(towns, pid, 1), t)
   
    call SaveInteger(actions, GetHandleId(t), 0, ACTION_REST)
   
    call SetTownName(t, "Settlement")
endfunction

function DisplayAction takes unit u, player p returns nothing
    local integer act = LoadInteger(actions, GetHandleId(u), 0)
    local string name = LoadStr(actions, act, 0)
    local integer cur = LoadInteger(actions, GetHandleId(u), 1)
    local integer max = LoadInteger(actions, GetHandleId(u), 2)
   
    if LoadBoolean(actions, GetHandleId(u), 0) then
        set name = name + "|CFFFFF200*|r"
    endif
   
    if max > 0 then
        set name = name + " |CFFC69C6D(" + I2S(cur) + " / " + I2S(max) + ")"
    endif
   
    call DisplayTag(u, p, name)
endfunction

function MaxUnits takes integer town returns integer
    return LoadInteger(towns, town, towns_hovels) * hovel_units
endfunction

function GetUnitSlotsLeft takes integer town returns integer
    return MaxUnits(town) - LoadInteger(towns, town, towns_units)
endfunction

scope Beginning initializer Init

    private function InitUnit takes nothing returns nothing
        if GetUnitTypeId(GetEnumUnit()) == 'h006' then
            call InitTown(GetEnumUnit())
            call SetTownName(GetEnumUnit(), "Home")
        endif
    endfunction

    private function InitBuildSpells takes nothing returns nothing
        set buildings[0] = 'h00H'   // Market
        set buildings[1] = 'h00C'   // Hovel
        set buildings[2] = 'h00F'   // Barracks
        set buildings[3] = 'h00G'   // Engineers' Guild
        set buildings[4] = 'h00O'   // Mercenary Post
        set buildings[5] = 'h00I'   // Stables
        set buildings[6] = 'h00K'   // Guard Tower
        set buildings[7] = 'h00J'   // Watch Tower
        set buildings[8] = 'h00Q'   // Infirmary
        set buildings[9] = 'h00P'   // Musicians Guild
        set buildings[10] = 'h00E'  // Workshop
        // All build spells are mapped here.
        call SaveInteger(s2b, 'A00O', 0, 'h00H')
        call SaveInteger(s2b, 'A00I', 0, 'h00E')
        call SaveInteger(s2b, 'A00H', 0, 'h00C')
        call SaveInteger(s2b, 'A00P', 0, 'h00F')
        call SaveInteger(s2b, 'A00Z', 0, 'h00P')
        call SaveInteger(s2b, 'A016', 0, 'h00J')
        call SaveInteger(s2b, 'A01C', 0, 'h00G')
        call SaveInteger(s2b, 'A01P', 0, 'h00I')
        call SaveInteger(s2b, 'A01S', 0, 'h00O')
        call SaveInteger(s2b, 'A01X', 0, 'h00Q')
    endfunction

    private function InitBuildingCosts takes nothing returns nothing
        // Specified production requirement.
        // Child 0 is gold, child 1 is production.
        call SaveInteger(bcost, 'h00H', 1, 3)   // Market
        call SaveInteger(bcost, 'h00E', 1, 6)   // Workshop
        call SaveInteger(bcost, 'h00C', 1, 10)   // Hovel
        call SaveInteger(bcost, 'h00F', 1, 10)  // Barracks
        call SaveInteger(bcost, 'h00P', 1, 20)  // Musicians Guild
        call SaveInteger(bcost, 'h00J', 1, 15)  // Tower
        call SaveInteger(bcost, 'h00G', 1, 40)  // Engineers' Guild
        call SaveInteger(bcost, 'h00I', 1, 30)  // Stables
        call SaveInteger(bcost, 'h00O', 1, 25)  // Mercenary Post
        call SaveInteger(bcost, 'h00Q', 1, 50)  // Infirmary
    endfunction

    private function InitPlayers takes nothing returns nothing
        if not DEBUGGING then
            call SetPlayerState(GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, base_gold)
            call SetPlayerState(GetEnumPlayer(), PLAYER_STATE_RESOURCE_LUMBER, base_prod)
        else
            call SetPlayerState(GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, 99999)
            call SetPlayerState(GetEnumPlayer(), PLAYER_STATE_RESOURCE_LUMBER, 99999)
        endif
       
        // All player buildings
        call SaveGroupHandle(towns, GetPlayerId(GetEnumPlayer()), 0, CreateGroup())
        // Just towns
        call SaveGroupHandle(towns, GetPlayerId(GetEnumPlayer()), 1, CreateGroup())
       
        call SetPlayerAbilityAvailable(GetEnumPlayer(), 'A00S', false)
        call SetPlayerAbilityAvailable(GetEnumPlayer(), 'A01U', false)
    endfunction

    private function InitActions takes nothing returns nothing
        /*
        Map actions to the following criteria:
            * Action name (shows up above the building when clicked) (colored)
            * Action id (integer)
        Spell mapped to the action id.
        */

        // REST / STANDBY
        call SaveStr(actions, 0, 0, "|CFFBD8CBFResting|r")
        call SaveInteger(actions, 'A00R', 0, ACTION_REST)
        call SaveStr(actions, 1, 0, "|CFFED1C24Swordsmen|r")
        call SaveInteger(actions, 'A00M', 0, ACTION_SWORDSMEN)
        call SaveStr(actions, 2, 0, "|CFFED1C24Bowmen|r")
        call SaveInteger(actions, 'A00W', 0, ACTION_BOWMEN)
        call SaveStr(actions, 3, 0, "|CFF00AEEFSettlers|r")
        call SaveInteger(actions, 'A00X', 0, ACTION_SETTLE)
        call SaveStr(actions, 4, 0, "|CFF00AEEFBard|r")
        call SaveInteger(actions, 'A010', 0, ACTION_BARD)
        call SaveStr(actions, 5, 0, "|CFF6DCFF6Upgrading|r")
        call SaveInteger(actions, 'A01D', 0, ACTION_UPGRADE_GUARD_TOWER)
        call SaveStr(actions, 6, 0, "|CFF6DCFF6Upgrading|r")
        call SaveInteger(actions, 'A01E', 0, ACTION_UPGRADE_TOWN)
        call SaveInteger(actions, 'A01F', 0, ACTION_UPGRADE_TOWN)
        call SaveInteger(actions, 'A01G', 0, ACTION_UPGRADE_TOWN)
        call SaveStr(actions, 7, 0, "|CFFBD8CBFEngineer|r")
        call SaveInteger(actions, 'A01N', 0, ACTION_ENGINEER)
        call SaveStr(actions, 8, 0, "|CFF00A99DTrebuchet|R")
        call SaveInteger(actions, 'A01O', 0, ACTION_TREBUCHET)
        call SaveStr(actions, 9, 0, "|CFFFDC689Raider|R")
        call SaveInteger(actions, 'A01Q', 0, ACTION_RAIDER)
        call SaveStr(actions, 10, 0, "|CFFC69C6DMercenary|r")
        call SaveInteger(actions, 'A01R', 0, ACTION_MERCENARY)
        call SaveStr(actions, 11, 0, "|CFFC69C6DFortifying|r")
        call SaveInteger(actions, 'A01V', 0, ACTION_BEGIN_DEFENDING)
        call SaveStr(actions, 12, 0, "|CFFED145BFortified|r")
        call SaveStr(actions, 13, 0, "|CFF008400Scout|R")
        call SaveInteger(actions, 'A01Y', 0, ACTION_SCOUT)
    endfunction
   
    private function InitMaxBuildings takes nothing returns nothing
        call SaveInteger(max_buildings, 'h006', 0, 3)
        call SaveInteger(max_buildings, 'h007', 0, 5)
        call SaveInteger(max_buildings, 'h008', 0, 7)
        call SaveInteger(max_buildings, 'h00N', 0, 10)
    endfunction

    private function Actions takes nothing returns nothing
        local group allu = CreateGroup()
       
        call ForForce(GetPlayersAll(), function InitPlayers)
       
        call GroupEnumUnitsInRect(allu, GetPlayableMapRect(), null)
        call ForGroup(allu, function InitUnit)
       
        call DestroyGroup(allu)
        set allu = null
    endfunction

    //===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddAction(t, function Actions)
        call TriggerRegisterTimerEvent(t, 0, false)
       
        set townid = InitHashtable()
        set towns = InitHashtable()
       
        set s2b = InitHashtable()
        call InitBuildSpells()
       
        set bcost = InitHashtable()
        call InitBuildingCosts()
       
        set actions = InitHashtable()
        call InitActions()
       
        set max_buildings = InitHashtable()
        call InitMaxBuildings()
       
        call SetTimeOfDay(9.0)
        //local trigger t = CreateTrigger()
        //call TriggerAddAction( t, function Trig_Initializer_Actions )
    endfunction

endscope
Radio Tower Recordings
  Events
    Unit - A unit Stops casting an ability
  Conditions
    (Ability being cast) Equal to Radio Scan (Real)
  Actions
    Sound - Play Recording <gen>
Endurance Doctrine Upgrade
  Events
    Unit - A unit Finishes research
  Conditions
    (Researched tech-type) Equal to R002 (techcode)
  Actions
    Player - Set the max research level of R001 (techcode) to 0 for (Owner of (Triggering unit))
    Player - Set the max research level of R00H (techcode) to 0 for (Owner of (Triggering unit))
    Player - Set the max research level of R000 (techcode) to 0 for (Owner of (Triggering unit))
Innovative Doctrine Upgrade
  Events
    Unit - A unit Finishes research
  Conditions
    (Researched tech-type) Equal to R001 (techcode)
  Actions
    Player - Set the max research level of R000 (techcode) to 0 for (Owner of (Triggering unit))
    Player - Set the max research level of R002 (techcode) to 0 for (Owner of (Triggering unit))
Scorched Earth Doctrine Upgrade
  Events
    Unit - A unit Finishes research
  Conditions
    (Researched tech-type) Equal to R000 (techcode)
  Actions
    Player - Set the max research level of R001 (techcode) to 0 for (Owner of (Triggering unit))
    Player - Set the max research level of R002 (techcode) to 0 for (Owner of (Triggering unit))
    Player - Set the max research level of R00H (techcode) to 0 for (Owner of (Triggering unit))
Facist Ideology Upgrade
  Events
    Unit - A unit Finishes research
  Conditions
    (Researched tech-type) Equal to R00K (techcode)
  Actions
    Player - Set the max research level of R00M (techcode) to 0 for (Owner of (Triggering unit))
    Player - Set the max research level of R00L (techcode) to 0 for (Owner of (Triggering unit))
    Player - Set the max research level of R00J (techcode) to 0 for (Owner of (Triggering unit))
    Player - Limit training of |c007d7d7dWehrmacht Sniper|r (German) to 5 for (Owner of (Triggering unit))
    Player - Limit training of |c007d7d7dTiger I|r (German) (HE Rounds) to 7 for (Owner of (Triggering unit))
    Unit - Add |c007d7d7dActivate Waffen SS|r (Trigger) to (Triggering unit)
Communist Ideology Upgrade
  Events
    Unit - A unit Finishes research
  Conditions
    (Researched tech-type) Equal to R00J (techcode)
  Actions
    Player - Set the max research level of R00M (techcode) to 0 for (Owner of (Triggering unit))
    Player - Set the max research level of R00L (techcode) to 0 for (Owner of (Triggering unit))
    Player - Set the max research level of R00K (techcode) to 0 for (Owner of (Triggering unit))
    Player - Limit training of |c00FF0000Red Army Sniper|r (Russian) to 5 for (Owner of (Triggering unit))
    Unit - Add |c00FF0000Activate Red Guard|r (Trigger) to (Triggering unit)
Regressive Notions Upgrade
  Events
    Unit - A unit Finishes research
  Conditions
    (Researched tech-type) Equal to R00H (techcode)
  Actions
    Player - Set the max research level of R00C (techcode) to 0 for (Owner of (Triggering unit))
    Unit - Add |c007d7d7dSummon Custodian Guard|r (Trigger) to (Triggering unit)
    Unit - Remove |c007d7d7dActivate Waffen SS|r (Trigger) from (Triggering unit)
Monarchist Ideology Upgrade
  Events
    Unit - A unit Finishes research
  Conditions
    (Researched tech-type) Equal to R00L (techcode)
  Actions
    Player - Set the max research level of R00M (techcode) to 0 for (Owner of (Triggering unit))
    Player - Set the max research level of R00K (techcode) to 0 for (Owner of (Triggering unit))
    Player - Set the max research level of R00J (techcode) to 0 for (Owner of (Triggering unit))
Capitalist Ideology Upgrade
  Events
    Unit - A unit Finishes research
  Conditions
    (Researched tech-type) Equal to R00M (techcode)
  Actions
    Player - Set the max research level of R00L (techcode) to 0 for (Owner of (Triggering unit))
    Player - Set the max research level of R00K (techcode) to 0 for (Owner of (Triggering unit))
    Player - Set the max research level of R00J (techcode) to 0 for (Owner of (Triggering unit))
Capitalist Ideology Upgrade Copy
  Events
    Unit - A unit Finishes research
  Conditions
    (Researched tech-type) Equal to R00C (techcode)
  Actions
    Player - Set the max research level of R00H (techcode) to 0 for (Owner of (Triggering unit))
Civilian Add Red
  Events
    Unit - A unit owned by Player 1 (Red).Finishes construction
  Conditions
    (Unit-type of (Constructed structure)) Equal to Household
  Actions
    Set VariableSet Faction1Income = (Faction1Income + 5)
Civilian Add Blue
  Events
    Unit - A unit owned by Player 6 (Orange).Finishes construction
  Conditions
    (Unit-type of (Constructed structure)) Equal to Household
  Actions
    Set VariableSet Faction2Income = (Faction2Income + 5)
Civilian Add Red Copy 2
  Events
    Unit - A unit owned by Player 9 (Gray).Finishes construction
  Conditions
    (Unit-type of (Constructed structure)) Equal to Household
  Actions
    Set VariableSet Faction3Income = (Faction3Income + 5)
Civilian Add Red Copy 3
  Events
    Unit - A unit owned by Player 23 (Emerald).Finishes construction
  Conditions
    (Unit-type of (Constructed structure)) Equal to Household
  Actions
    Set VariableSet Faction4Income = (Faction4Income + 5)
Civilian Upgrade Red
  Events
    Unit - A unit owned by Player 1 (Red).Finishes an upgrade
  Conditions
    (Unit-type of (Triggering unit)) Equal to |c00FF7F00Mark I Infantry Tank|r (English)
  Actions
    Set VariableSet Faction1Income = (Faction1Income + 5)
Civilian Upgrade Blue
  Events
    Unit - A unit owned by Player 12 (Brown).Finishes an upgrade
  Conditions
    (Unit-type of (Triggering unit)) Equal to
  Actions
    Set VariableSet Faction2Income = (Faction2Income + 5)
Civilian Sub Red
  Events
    Unit - A unit owned by Player 1 (Red).Dies
  Conditions
    (Unit-type of (Triggering unit)) Equal to Household
  Actions
    Set VariableSet Faction1Income = (Faction1Income - 5)
Civilian Sub Blue
  Events
    Unit - A unit owned by Player 6 (Orange).Dies
  Conditions
    (Unit-type of (Triggering unit)) Equal to Household
  Actions
    Set VariableSet Faction2Income = (Faction2Income - 5)
Civilian Sub Red Copy 2
  Events
    Unit - A unit owned by Player 9 (Gray).Dies
  Conditions
    (Unit-type of (Triggering unit)) Equal to Household
  Actions
    Set VariableSet Faction3Income = (Faction3Income - 5)
Civilian Sub Red Copy 3
  Events
    Unit - A unit owned by Player 23 (Emerald).Dies
  Conditions
    (Unit-type of (Triggering unit)) Equal to Household
  Actions
    Set VariableSet Faction4Income = (Faction4Income - 5)
Civilian Sub Red Doub
  Events
    Unit - A unit owned by Player 1 (Red).Dies
  Conditions
    (Unit-type of (Triggering unit)) Equal to |c00FF7F00Mark I Infantry Tank|r (English)
  Actions
    Set VariableSet Faction1Income = (Faction1Income - 10)
Civilian Sub Blue Doub
  Events
    Unit - A unit owned by Player 12 (Brown).Dies
  Conditions
    (Unit-type of (Triggering unit)) Equal to
  Actions
    Set VariableSet Faction2Income = (Faction2Income - 10)
Make sure to create a group of marines and a tank for the Fearless Rebellion at the center, and order them to move on point to capture.

This forces blue to up their game immediately, however the forces at the center should not be powerful.
Income Intalization
  Events
    Map initialization
  Conditions
  Actions
    Set VariableSet Faction1Income = 20
    Set VariableSet Faction2Income = 20
    Set VariableSet Faction3Income = 20
    Set VariableSet Faction4Income = 20
    Player - Set Player 1 (Red).Current gold to 70
    Player - Set Player 6 (Orange).Current gold to 70
    Player - Set Player 23 (Emerald).Current gold to 70
    Player - Set Player 9 (Gray).Current gold to 70
Money
  Events
    Time - Every 20.00 seconds of game time
  Conditions
  Actions
    Player - Add Faction1Income to Player 1 (Red).Current gold
    Player - Add Faction2Income to Player 6 (Orange).Current gold
    Player - Add Faction3Income to Player 9 (Gray).Current gold
    Player - Add Faction4Income to Player 23 (Emerald).Current gold
    If (OwningPlayer Equal to Player 1 (Red)) then do (Add Faction1Income to Player 1 (Red).Current gold) else do (Do nothing)
    If (OwningPlayer Equal to Player 6 (Orange)) then do (Add Faction2Income to Player 6 (Orange).Current gold) else do (Do nothing)
    If (OwningPlayer Equal to Player 9 (Gray)) then do (Add Faction3Income to Player 9 (Gray).Current gold) else do (Do nothing)
    If (OwningPlayer Equal to Player 23 (Emerald)) then do (Add Faction4Income to Player 23 (Emerald).Current gold) else do (Do nothing)
Mine Copy Copy
  Events
    Unit - A unit Begins construction
  Conditions
    (Unit-type of (Constructing structure)) Equal to Camp Fire
  Actions
    Unit - Create 1.Camp Fire for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing (Random angle) degrees
    Unit - Remove (Triggering unit) from the game
Civilian Add Red Copy
  Events
    Unit - A unit owned by Player 1 (Red).Finishes construction
  Conditions
    (Unit-type of (Constructed structure)) Equal to Oil Field
  Actions
    Set VariableSet Faction1Income = (Faction1Income + 5)
Civilian Add Blue Copy
  Events
    Unit - A unit owned by Player 6 (Orange).Finishes construction
  Conditions
    (Unit-type of (Constructed structure)) Equal to Oil Field
  Actions
    Set VariableSet Faction2Income = (Faction2Income + 5)
Civilian Add Blue Copy Copy
  Events
    Unit - A unit owned by Player 9 (Gray).Finishes construction
  Conditions
    (Unit-type of (Constructed structure)) Equal to Oil Field
  Actions
    Set VariableSet Faction3Income = (Faction3Income + 5)
Civilian Add Blue Copy Copy 2
  Events
    Unit - A unit owned by Player 23 (Emerald).Finishes construction
  Conditions
    (Unit-type of (Constructed structure)) Equal to Oil Field
  Actions
    Set VariableSet Faction4Income = (Faction4Income + 5)
Civilian Upgrade Red Copy
  Events
    Unit - A unit owned by Player 1 (Red).Finishes an upgrade
  Conditions
    (Unit-type of (Triggering unit)) Equal to |c00FF7F00Mark I Infantry Tank|r (English)
  Actions
    Set VariableSet Faction1Income = (Faction1Income + 5)
Civilian Upgrade Blue Copy
  Events
    Unit - A unit owned by Player 12 (Brown).Finishes an upgrade
  Conditions
    (Unit-type of (Triggering unit)) Equal to
  Actions
    Set VariableSet Faction2Income = (Faction2Income + 5)
Civilian Sub Red Copy
  Events
    Unit - A unit owned by Player 1 (Red).Dies
  Conditions
    (Unit-type of (Triggering unit)) Equal to Oil Field
  Actions
    Set VariableSet Faction1Income = (Faction1Income - 5)
Civilian Sub Blue Copy
  Events
    Unit - A unit owned by Player 6 (Orange).Dies
  Conditions
    (Unit-type of (Triggering unit)) Equal to Oil Field
  Actions
    Set VariableSet Faction2Income = (Faction2Income - 5)
Civilian Sub Red Copy Copy
  Events
    Unit - A unit owned by Player 9 (Gray).Dies
  Conditions
    (Unit-type of (Triggering unit)) Equal to Oil Field
  Actions
    Set VariableSet Faction3Income = (Faction3Income - 5)
Civilian Sub Red Copy Copy 2
  Events
    Unit - A unit owned by Player 23 (Emerald).Dies
  Conditions
    (Unit-type of (Triggering unit)) Equal to Oil Field
  Actions
    Set VariableSet Faction4Income = (Faction4Income - 5)
Civilian Sub Red Doub Copy
  Events
    Unit - A unit owned by Player 1 (Red).Dies
  Conditions
    (Unit-type of (Triggering unit)) Equal to |c00FF7F00Mark I Infantry Tank|r (English)
  Actions
    Set VariableSet Faction1Income = (Faction1Income - 10)
Civilian Sub Blue Doub Copy
  Events
    Unit - A unit owned by Player 12 (Brown).Dies
  Conditions
    (Unit-type of (Triggering unit)) Equal to
  Actions
    Set VariableSet Faction2Income = (Faction2Income - 10)
Make sure to create a group of marines and a tank for the Fearless Rebellion at the center, and order them to move on point to capture.

This forces blue to up their game immediately, however the forces at the center should not be powerful.
Income Intalization Copy
  Events
    Map initialization
  Conditions
  Actions
    Set VariableSet Faction1Income = 20
    Set VariableSet Faction2Income = 20
    Set VariableSet Faction3Income = 20
    Set VariableSet Faction4Income = 20
    Player - Set Player 1 (Red).Current lumber to 70
    Player - Set Player 6 (Orange).Current lumber to 70
    Player - Set Player 9 (Gray).Current lumber to 70
    Player - Set Player 23 (Emerald).Current lumber to 70
Oil
  Events
    Time - Every 20.00 seconds of game time
  Conditions
  Actions
    Player - Add Faction1Income to Player 1 (Red).Current lumber
    Player - Add Faction2Income to Player 6 (Orange).Current lumber
    Player - Add Faction3Income to Player 9 (Gray).Current lumber
    Player - Add Faction4Income to Player 23 (Emerald).Current lumber
    If (OwningPlayer Equal to Player 1 (Red)) then do (Add Faction1Income to Player 1 (Red).Current lumber) else do (Do nothing)
    If (OwningPlayer Equal to Player 6 (Orange)) then do (Add Faction2Income to Player 6 (Orange).Current lumber) else do (Do nothing)
    If (OwningPlayer Equal to Player 9 (Gray)) then do (Add Faction3Income to Player 9 (Gray).Current lumber) else do (Do nothing)
    If (OwningPlayer Equal to Player 23 (Emerald)) then do (Add Faction4Income to Player 23 (Emerald).Current lumber) else do (Do nothing)
Unit Indexer gives you an array-safe (1-8190) custom value for units, eliminating the need for hashtables to store unit-specific data.
Just use "Set MyArrayData[(Custom value of Unit)] = (Some data)".
--------
If you want to get the unit assigned to an index (reverse lookup) use "UDexUnits[(Index)]".
--------
If you want to detect when an index is created or when it is released, use "UnitIndexEvent Equal to 1.00" (created) or "UnitIndexEvent Equal to 2.00" (released). The index being created/released is called "UDex".
--------
You can enable/disable Unit Indexer to protect some of your undesirable units from being indexed like this:

Trigger - Turn off Unit Indexer <gen>
Unit - Create 1 Dummy for (Triggering player) at TempPoint facing 0.00 degrees
Trigger - Turn on Unit Indexer <gen>
--------
If you want to use a Map Initialization trigger that uses custom value of units, to make sure that UnitIndexer initializes first, use the event "UnitIndexEvent Equal to 3.00". Otherwise the custom value of units may be zero.
--------
Advanced:
--------
If you want to lock the index of a unit, use "Set UnitIndexLock[(Index)] = (UnitIndexLock[(Index)] + 1)". This will prevent the index from being recycled. If you want to unlock it and allow it to be recycled, run the Unit Indexer <gen> trigger.

Note: Make sure if you add a lock that you will eventually remove the lock, otherwise the index will never be recycled.
Unit Indexer
  Events
    Map initialization
  Conditions
  Actions
    Custom script: call ExecuteFunc("InitializeUnitIndexer")
    Custom script: endfunction
    Custom script:
    Custom script: function ClearUnitIndex takes nothing returns nothing
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        (Custom value of UDexUnits[UDex]) Equal to 0
      Then - Actions
        Set VariableSet UnitIndexLock[UDex] = (UnitIndexLock[UDex] - 1)
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            UnitIndexLock[UDex] Equal to 0
          Then - Actions
            Set VariableSet UDexNext[UDexPrev[UDex]] = UDexNext[UDex]
            Set VariableSet UDexPrev[UDexNext[UDex]] = UDexPrev[UDex]
            Set VariableSet UDexPrev[UDex] = 0
            Set VariableSet UnitIndexEvent = 0.00
            Set VariableSet UnitIndexEvent = 2.00
            Set VariableSet UnitIndexEvent = 0.00
            Set VariableSet UDexUnits[UDex] = No unit
            Set VariableSet UDexNext[UDex] = UDexRecycle
            Set VariableSet UDexRecycle = UDex
          Else - Actions
      Else - Actions
    Custom script: endfunction
    Custom script:
    Custom script: function IndexUnit takes nothing returns boolean
    Custom script: local integer pdex = udg_UDex
    Custom script: local integer ndex
    -------- - --------
    -------- You can customize the following block - if conditions are false the (Matching unit) won't be indexed. --------
    -------- - --------
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        UnitIndexerEnabled Equal to True
        (Custom value of (Matching unit)) Equal to 0
      Then - Actions
        Set VariableSet UDexWasted = (UDexWasted + 1)
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            UDexWasted Equal to 32
          Then - Actions
            Set VariableSet UDexWasted = 0
            Set VariableSet UDex = UDexNext[0]
            Custom script: loop
            Custom script: exitwhen udg_UDex == 0
            Custom script: set ndex = udg_UDexNext[udg_UDex]
            Custom script: call ClearUnitIndex()
            Custom script: set udg_UDex = ndex
            Custom script: endloop
          Else - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            UDexRecycle Equal to 0
          Then - Actions
            Set VariableSet UDex = (UDexGen + 1)
            Set VariableSet UDexGen = UDex
          Else - Actions
            Set VariableSet UDex = UDexRecycle
            Set VariableSet UDexRecycle = UDexNext[UDex]
        Set VariableSet UDexUnits[UDex] = (Matching unit)
        Unit - Set the custom value of UDexUnits[UDex] to UDex
        Set VariableSet UDexPrev[UDexNext[0]] = UDex
        Set VariableSet UDexNext[UDex] = UDexNext[0]
        Set VariableSet UDexNext[0] = UDex
        Set VariableSet UnitIndexLock[UDex] = 1
        Set VariableSet UnitIndexEvent = 0.00
        Set VariableSet UnitIndexEvent = 1.00
        Set VariableSet UnitIndexEvent = 0.00
        Custom script: set udg_UDex = pdex
      Else - Actions
    Custom script: return false
    Custom script: endfunction
    Custom script:
    Custom script: function InitializeUnitIndexer takes nothing returns nothing
    Custom script: local integer i = 16
    Custom script: local boolexpr b = Filter(function IndexUnit)
    Custom script: local region re = CreateRegion()
    Custom script: local trigger t = GetTriggeringTrigger()
    Custom script: local rect r = GetWorldBounds()
    Custom script: call RegionAddRect(re, r)
    Custom script: call TriggerRegisterEnterRegion(t, re, b)
    Custom script: call TriggerClearActions(t)
    Custom script: call TriggerAddAction(t, function ClearUnitIndex)
    Set VariableSet UnitIndexerEnabled = True
    Custom script: loop
    Custom script: set i = i - 1
    Custom script: call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, Player(i), b)
    Custom script: exitwhen i == 0
    Custom script: endloop
    Custom script: call RemoveRect(r)
    Custom script: set re = null
    Custom script: set r = null
    Custom script: set t = null
    Custom script: set b = null
    Set VariableSet UnitIndexEvent = 3.00
    Set VariableSet UnitIndexEvent = 0.00
Drop
  Events
    Unit - A unit Begins casting an ability
  Conditions
    (Ability being cast) Equal to Unload (Plane)
  Actions
    Unit - Pause (Transporting unit)
Cowardice
  Events
    Unit - A unit Is attacked
  Conditions
    (Life of (Triggering unit)) Equal to 10
  Actions
Red Retreat
  Events
    Unit - A unit Begins casting an ability
  Conditions
    (Owner of (Triggering unit)) Equal to Player 1 (Red)
    (Ability being cast) Equal to Retreat
  Actions
    Unit - Change ownership of (Triggering unit) to Player 2 (Blue) and Retain color
    Unit - Order (Triggering unit) to Move To.(Center of Region_000 <gen>)
    Wait 10.00 seconds
    Unit - Change ownership of (Triggering unit) to Player 1 (Red) and Retain color
Orange Retreat
  Events
    Unit - A unit Begins casting an ability
  Conditions
    (Owner of (Triggering unit)) Equal to Player 6 (Orange)
    (Ability being cast) Equal to Retreat
  Actions
    Unit - Change ownership of (Triggering unit) to Player 7 (Green) and Retain color
    Unit - Order (Triggering unit) to Move To.(Center of Region_001 <gen>)
    Wait 10.00 seconds
    Unit - Change ownership of (Triggering unit) to Player 6 (Orange) and Retain color
Grey Retreat
  Events
    Unit - A unit Begins casting an ability
  Conditions
    (Owner of (Triggering unit)) Equal to Player 9 (Gray)
    (Ability being cast) Equal to Retreat
  Actions
    Unit - Change ownership of (Triggering unit) to Player 10 (Light Blue) and Retain color
    Unit - Order (Triggering unit) to Move To.(Center of Region_002 <gen>)
    Wait 10.00 seconds
    Unit - Change ownership of (Triggering unit) to Player 9 (Gray) and Retain color
Green Retreat
  Events
    Unit - A unit Begins casting an ability
  Conditions
    (Owner of (Triggering unit)) Equal to Player 23 (Emerald)
    (Ability being cast) Equal to Retreat
  Actions
    Unit - Change ownership of (Triggering unit) to Player 24 (Peanut) and Retain color
    Unit - Order (Triggering unit) to Move To.(Center of Region_003 <gen>)
    Wait 10.00 seconds
    Unit - Change ownership of (Triggering unit) to Player 23 (Emerald) and Retain color
Dont Shoot Cowards
  Events
    Map initialization
  Conditions
  Actions
    Set VariableSet TranslatePlayerNumber = 1
    For each (Integer A) from 1 to 24, do (Actions)
      Loop - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            ((Player((Integer A))) slot status) Equal to Is playing
          Then - Actions
            Player - Change color of (Player(((Integer A) + TranslatePlayerNumber))) to (Color of (Player((Integer A)))), Changing color of existing units
            Player - Set name of (Player(((Integer A) + TranslatePlayerNumber))) to (Name of (Player((Integer A))))
            Player - Hide (Player(((Integer A) + TranslatePlayerNumber))) in the post-game score screen
            Player - Make (Player((Integer A))) treat (Player(((Integer A) + TranslatePlayerNumber))) as an Ally with shared vision
            Player - Make (Player(((Integer A) + TranslatePlayerNumber))) treat (Player((Integer A))) as an Ally with shared vision
            AI - Ignore the guard positions of all (Player(((Integer A) + TranslatePlayerNumber))) units
          Else - Actions
            Player - Hide (Player((Integer A))) in the post-game score screen
Adds bonus damage to Cavalry Charge.
Cavalry Charge
  Events
    Unit - A unit Starts the effect of an ability
  Conditions
    (Ability being cast) Equal to Cavalry Charge (Trigger)
  Actions
    Unit Group - Add (Triggering unit) to CavalryGroup
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        (Current order of (Triggering unit)) Not equal to (Order(attack))
      Then - Actions
        Unit - Add Spell Book to (Triggering unit)
      Else - Actions
Remove bonus damage and Charge buff from cavalry on attack.
Charge End
  Events
    Unit - A unit Is attacked
  Conditions
    ((Attacking unit) is in CavalryGroup.) Equal to True
  Actions
    Unit - Remove Berserk buff from (Attacking unit)
    Unit - Remove Spell Book from (Attacking unit)
    Unit Group - Remove (Attacking unit) from CavalryGroup.
    Set VariableSet KB_Int = (Player number of (Owner of (Attacking unit)))
    -------- -------------------------------------------------------------------------------------------------------- --------
    -------- Picking units around --------
    -------- -------------------------------------------------------------------------------------------------------- --------
    Set VariableSet TempPoint = (Position of (Triggering unit))
    Set VariableSet KB_Group[KB_Int] = (Units within 50.00 of TempPoint.)
    Custom script: call RemoveLocation(udg_TempPoint)
    Unit Group - Pick every unit in KB_Group[KB_Int] and do (Actions)
      Loop - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            ((Picked unit) is alive) Equal to True
            ((Picked unit) belongs to an enemy of (Owner of (Attacking unit)).) Equal to True
            ((Picked unit) is A flying unit) Equal to False
            ((Picked unit) is A structure) Equal to False
            ((Picked unit) is Mechanical) Equal to False
            ((Picked unit) is A sapper) Equal to False
            (Unit-type of (Picked unit)) Not equal to Lancer Cavalry (Standard)
            (Unit-type of (Picked unit)) Not equal to Lancer Cavalry (Standard)
          Then - Actions
            Unit - Order DummySystems to Human Mountain King - Storm Bolt.(Triggering unit)
          Else - Actions
            Unit Group - Remove (Picked unit) from KB_Group[KB_Int].
    -------- -------------------------------------------------------------------------------------------------------- --------
    -------- Checking if units are around --------
    -------- -------------------------------------------------------------------------------------------------------- --------
    If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      If - Conditions
        (Number of units in KB_Group[KB_Int]) Greater than 0
      Then - Actions
        -------- -------------------------------------------------------------------------------------------------------- --------
        -------- Setting KB_Point --------
        -------- -------------------------------------------------------------------------------------------------------- --------
        Set VariableSet KB_Point[0] = (Position of (Attacking unit))
        Unit Group - Pick every unit in KB_Group[KB_Int] and do (Actions)
          Loop - Actions
            -------- -------------------------------------------------------------------------------------------------------- --------
            -------- Knockback Effect --------
            -------- -------------------------------------------------------------------------------------------------------- --------
            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              If - Conditions
                KB_Skip Equal to 0
              Then - Actions
                Trigger - Turn on Knockback_System <gen>
              Else - Actions
            Set VariableSet KB_Skip = (KB_Skip + 1)
            Set VariableSet KB_Times = (KB_Times + 1)
            Set VariableSet KB_Off[KB_Times] = True
            -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------- --------
            Set VariableSet KB_Target[KB_Times] = (Picked unit)
            Unit - Pause KB_Target[KB_Times]
            Set VariableSet KB_Point[1] = (Position of KB_Target[KB_Times])
            Set VariableSet KB_Angle[KB_Times] = (Angle from KB_Point[0] to KB_Point[1])
            Set VariableSet KB_Distance[KB_Times] = 125.00
            Set VariableSet KB_Speed[KB_Times] = (KB_Distance[KB_Times] / 20.00)
            Set VariableSet KB_Spam[KB_Times] = 10
            Custom script: call RemoveLocation(udg_KB_Point[1])
        -------- -------------------------------------------------------------------------------------------------------- --------
        -------- Removing KB_Point --------
        -------- -------------------------------------------------------------------------------------------------------- --------
        Custom script: call RemoveLocation(udg_KB_Point[0])
      Else - Actions
        -------- -------------------------------------------------------------------------------------------------------- --------
        -------- If units are not around, destroy group to avoid leaks. --------
        -------- -------------------------------------------------------------------------------------------------------- --------
        Custom script: call DestroyGroup(udg_KB_Group[udg_KB_Int])
By: NFWar
Knockback System
  Events
    Time - Every 0.03 seconds of game time
  Conditions
  Actions
    For each (Integer KB) from 1 to KB_Times, do (Actions)
      Loop - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            KB_Off[KB] Equal to True
          Then - Actions
            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              If - Conditions
                KB_Distance[KB] Less than or equal to 0.00
              Then - Actions
                -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------- --------
                -------- Do not forget to unpause. --------
                -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------- --------
                Unit - Unpause KB_Target[KB]
                Set VariableSet KB_Off[KB] = False
                -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------- --------
                -------- Index recycling. Do not touch. --------
                -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------- --------
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  If - Conditions
                    KB Less than KB_Times
                  Then - Actions
                    Set VariableSet KB_Off[KB] = KB_Off[KB_Times]
                    Set VariableSet KB_Target[KB] = KB_Target[KB_Times]
                    Set VariableSet KB_Distance[KB] = KB_Distance[KB_Times]
                    Set VariableSet KB_Speed[KB] = KB_Speed[KB_Times]
                    Set VariableSet KB_Spam[KB] = KB_Spam[KB_Times]
                    Set VariableSet KB_Angle[KB] = KB_Angle[KB_Times]
                  Else - Actions
                Set VariableSet KB_Times = (KB_Times - 1)
                Set VariableSet KB = (KB - 1)
                Set VariableSet KB_Skip = (KB_Skip - 1)
                -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------- --------
                -------- If no spells are running, turn off this trigger. --------
                -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------- --------
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  If - Conditions
                    KB_Times Equal to 0
                  Then - Actions
                    Trigger - Turn off (This trigger)
                  Else - Actions
              Else - Actions
                -------- Set up points to move knockbacked unit --------
                Set VariableSet KB_Point[2] = (Position of KB_Target[KB])
                Set VariableSet KB_Point[3] = (KB_Point[2] offset by KB_Speed[KB] towards KB_Angle[KB] degrees.)
                -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------- --------
                -------- Move unit, if it is in the playable map area where it can walk --------
                -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------- --------
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  If - Conditions
                    (Terrain pathing at KB_Point[3] of type Walkability is off) Equal to True
                    ((Playable map area) contains KB_Point[3]) Not equal to True
                  Then - Actions
                    Set VariableSet KB_Distance[KB] = 0.00
                  Else - Actions
                    -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------- --------
                    -------- Move unit with function to creep camp after knockback, if it is a creep. Instant move action applies a unit new location and creeps stay where they are. --------
                    -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------- --------
                    Custom script: call SetUnitX(udg_KB_Target[udg_KB], GetLocationX(udg_KB_Point[3]))
                    Custom script: call SetUnitY(udg_KB_Target[udg_KB], GetLocationY(udg_KB_Point[3]))
                Set VariableSet KB_Distance[KB] = (KB_Distance[KB] - KB_Speed[KB])
                Set VariableSet KB_Spam[KB] = (KB_Spam[KB] + 1)
                -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------- --------
                -------- Special effect every 5 times the unit is moved. --------
                -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------- --------
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  If - Conditions
                    KB_Spam[KB] Greater than or equal to 5
                  Then - Actions
                    Set VariableSet KB_Spam[KB] = 0
                    Special Effect - Create a special effect at KB_Point[3] using Objects\Spawnmodels\Undead\ImpaleTargetDust\ImpaleTargetDust.mdl
                    Special Effect - Destroy (Last created special effect)
                  Else - Actions
                -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------- --------
                -------- Remove leaks after movement process! --------
                -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------- --------
                Custom script: call RemoveLocation(udg_KB_Point[2])
                Custom script: call RemoveLocation(udg_KB_Point[3])
          Else - Actions
Bail Out
  Events
    Unit - A unit Finishes casting an ability
  Conditions
    (Ability being cast) Equal to Bail Out!
    (Owner of (Triggering unit)) Equal to Player 1 (Red)
  Actions
    Unit - Order (Casting unit) to Hold Position.
    Unit - Change ownership of (Casting unit) to Neutral Passive and Change color
    Unit - Create 1.Industrial Worker (Standard) for Player 1 (Red) at (Position of (Triggering unit)) facing Default building facing degrees
Bail Out Copy
  Events
    Unit - A unit Finishes casting an ability
  Conditions
    (Ability being cast) Equal to Bail Out!
    (Owner of (Triggering unit)) Equal to Player 23 (Emerald)
  Actions
    Unit - Change ownership of (Casting unit) to Neutral Passive and Change color
    Unit - Create 1.Industrial Worker (Standard) for Player 23 (Emerald) at (Position of (Triggering unit)) facing Default building facing degrees
Bail Out Copy 2
  Events
    Unit - A unit Finishes casting an ability
  Conditions
    (Ability being cast) Equal to Bail Out!
    (Owner of (Triggering unit)) Equal to Player 9 (Gray)
  Actions
    Unit - Change ownership of (Casting unit) to Neutral Passive and Change color
    Unit - Create 1.Industrial Worker (Standard) for Player 9 (Gray) at (Position of (Triggering unit)) facing Default building facing degrees
Bail Out Copy 3
  Events
    Unit - A unit Finishes casting an ability
  Conditions
    (Ability being cast) Equal to Bail Out!
    (Owner of (Triggering unit)) Equal to Player 6 (Orange)
  Actions
    Unit - Change ownership of (Casting unit) to Neutral Passive and Change color
    Unit - Create 1.Industrial Worker (Standard) for Player 6 (Orange) at (Position of (Triggering unit)) facing Default building facing degrees
Capture cast
  Events
    Unit - A unit Starts the effect of an ability
  Conditions
    (Ability being cast) Equal to Capture
  Actions
    Unit - Change ownership of (Target unit of ability being cast) to (Owner of (Casting unit)) and Change color
    Unit - Remove (Casting unit) from the game
    -------- --------
Capture debugg
  Events
    Unit - A unit Begins casting an ability
  Conditions
    (Ability being cast) Equal to Capture
    ((Target unit of ability being cast) is A structure) Equal to True
  Actions
    Unit - Order (Casting unit) to Stop.
    -------- --------
For transferring variables between maps. Copy this first, then copy the custom script code under "SquadTestMap" at the top!
JASS Globals
  Events
  Conditions
  Actions
    Set VariableSet AI_AttackGroup[12] = AI_AttackGroup[12]
    Set VariableSet AI_Movement[0] = AI_Movement[0]
    Set VariableSet AI_Player_Copy = AI_Player_Copy
    Set VariableSet AI_PlayerNumber = AI_PlayerNumber
    Set VariableSet BatalionHash_Beast = 9
    Set VariableSet BatalionHash_Crew = 8
    Set VariableSet BatalionHash_Guards = 6
    Set VariableSet BatalionHash_Order = 2
    Set VariableSet BatalionHash_Summonable = 7
    Set VariableSet BatalionHash_TargetUnit = 5
    Set VariableSet BatalionHash_TargetX = 3
    Set VariableSet BatalionHash_TargetY = 4
    Set VariableSet BattalionTimer[6] = 0.00
    Set VariableSet Battallion[100] = Battallion[100]
    Set VariableSet BattallionCount = 0
    Set VariableSet BattallionIndex = 0
    Set VariableSet BattallionLimit = 330
    Set VariableSet BattallionQueued = BattallionQueued
    Set VariableSet BattallionRegroup = 700.00
    Set VariableSet BattalionSpellCaster[0] = No unit-type
    Set VariableSet BattalionSpellAbility[0] = BattalionSpellAbility[0]
    Set VariableSet BattalionSpellOrderID[0] = BattalionSpellOrderID[0]
    Set VariableSet BattalionSpellOrderString[0] = BattalionSpellOrderString[0]
    Set VariableSet check = False
    Set VariableSet handle = 0
    Set VariableSet Players = Players
    Set VariableSet Selected1[12] = Selected1[12]
    Set VariableSet Status[50] = 0
    Set VariableSet Summon = 6
    Set VariableSet target = target
    Set VariableSet TempCommander = TempCommander
    Set VariableSet TempGroiup = TempGroiup
    Set VariableSet TempHero = TempHero
    Set VariableSet Tempint = 0
    Set VariableSet Tempplayer = Tempplayer
    Set VariableSet Temppoint = Temppoint
    Set VariableSet TempPoint = TempPoint
    Set VariableSet Temppoint01 = Temppoint01
    Set VariableSet TempRealX = TempRealX
    Set VariableSet Tempunit = Tempunit
    Set VariableSet timer = 0.00
    Set VariableSet TranslatePlayerNumber = 0
    Set VariableSet Unittype = Unittype
Add squad unit types here. Set "battalion" arrays and NrTypes to the total number of squad types.
Battalion Captain - Used to indigate what unit is a Captain
Battalion Captain - Used to indigate what unit is a Captain
Squad Setup
  Events
    Map initialization
  Conditions
  Actions
    Set VariableSet TranslatePlayerNumber = 1
    For each (Integer A) from 1 to 6, do (Actions)
      Loop - Actions
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          If - Conditions
            ((Player((Integer A))) slot status) Equal to Is playing
          Then - Actions
            Player - Change color of (Player(((Integer A) + TranslatePlayerNumber))) to (Color of (Player((Integer A)))), Changing color of existing units
            Player - Set name of (Player(((Integer A) + TranslatePlayerNumber))) to (Name of (Player((Integer A))))
            Player - Hide (Player(((Integer A) + TranslatePlayerNumber))) in the post-game score screen
            Player - Make (Player((Integer A))) treat (Player(((Integer A) + TranslatePlayerNumber))) as an Ally with shared vision
            Player - Make (Player(((Integer A) + TranslatePlayerNumber))) treat (Player((Integer A))) as an Ally with shared vision
            AI - Ignore the guard positions of all (Player(((Integer A) + TranslatePlayerNumber))) units
          Else - Actions
            Player - Hide (Player((Integer A))) in the post-game score screen
    Hashtable - Create a hashtable
    Set VariableSet hashtable = (Last created hashtable)
    -------- Russian Rifleman --------
    Set VariableSet BattalionCaptain[1] = |c00FF7F00Crown Infantry|r (English)
    Set VariableSet BattalionTroop[1] =
    Set VariableSet BattalionGoldCost[1] = 20
    Set VariableSet BattalionPowerCost[1] = 5
    Set VariableSet BattalionSize[1] = 5
    -------- Artillery --------
    Set VariableSet BattalionCaptain[2] =
    Set VariableSet BattalionTroop[2] = |c007d7d7d105mm Howitzer Field Cannon|r (Immobile) (German)
    Set VariableSet BattalionSize[2] = 2
    Set VariableSet Status[2] = BatalionHash_Crew
    -------- German Rifleman --------
    Set VariableSet BattalionCaptain[3] = |c007d7d7dSd.Kfz 222 Armoured Car|r (German)
    Set VariableSet BattalionTroop[3] = |c007d7d7d105mm Howitzer Field Cannon|r (Mobile) (German)
    Set VariableSet BattalionGoldCost[3] = 20
    Set VariableSet BattalionPowerCost[3] = 5
    Set VariableSet BattalionSize[3] = 5
Keeps units marching in relatively proper formations because the squad system cannot use default movement for everything.

Use unit point values for their rank in squads (like melee in front, lower number, and ranged in the back, higher number)
function Selection takes nothing returns boolean
    return ( IsUnitSelected(GetFilterUnit(), GetOwningPlayer(GetOrderedUnit())) == true )
endfunction

function Trig_Move_to_point_Compy_Conditions takes nothing returns boolean
    if ( IsUnitType(GetOrderedUnit(), UNIT_TYPE_STRUCTURE) == false ) then
        if ( GetIssuedOrderId() == 851971 or GetIssuedOrderId() == 851986 or GetIssuedOrderId() == 851983  ) then
                //call BJDebugMsg(OrderId2String( GetIssuedOrderId() ))
            return true
        endif
    endif
    return false
endfunction

function Trig_Move_to_point_Compy_Actions takes nothing returns nothing
    local real orderX = GetOrderPointX()
    local real orderY = GetOrderPointY()
    local integer order = GetIssuedOrderId()
    local integer counter = 0
    local integer counter1 = 0
    local integer counter2 = 0
    local integer index
    local integer min
    local real Xpos
    local real Ypos
    local real XposUnit
    local real YposUnit
    local real minX = 100000.0
    local real minY = 100000.0
    local real maxX = -100000.0
    local real maxY = -100000.0
    local real angle
    local unit wanderer
    local unit array units
    local unit array swap
    local group tempgroup = CreateGroup()

    if ( GetPlayerController(GetOwningPlayer(GetOrderedUnit())) == MAP_CONTROL_USER ) then
        set tempgroup = GetUnitsOfPlayerMatching(GetOwningPlayer(GetOrderedUnit()), Condition(function Selection))
    endif
    if ( IsUnitGroupEmptyBJ(udg_AI_Movement[GetConvertedPlayerId(GetOwningPlayer(GetOrderedUnit()))]) == false ) then
        call GroupAddGroup( udg_AI_Movement[GetConvertedPlayerId(GetOwningPlayer(GetOrderedUnit()))], tempgroup)
    endif
    if ( CountUnitsInGroup(tempgroup) < 2 ) then
        call DestroyGroup(tempgroup)
        call GroupClear(udg_AI_Movement[GetConvertedPlayerId(GetOwningPlayer(GetOrderedUnit()))])
        call EnableTrigger( GetTriggeringTrigger() )
        return
    endif
    loop
        set wanderer = FirstOfGroup(tempgroup)
        exitwhen wanderer == null
        if ( GetUnitX(wanderer) < minX ) then
            set minX = GetUnitX(wanderer)
        endif
        if ( GetUnitY(wanderer) < minY ) then
            set minY = GetUnitY(wanderer)
        endif
        if ( GetUnitX(wanderer) > maxX ) then
            set maxX = GetUnitX(wanderer)
        endif
        if ( GetUnitY(wanderer) > maxY ) then
            set maxY = GetUnitY(wanderer)
        endif
        call GroupRemoveUnit( tempgroup, wanderer )
        set Xpos = minX + (maxX - minX )/2
        set Ypos = minY + (maxY - minY )/2
    endloop
    if ( GetPlayerController(GetOwningPlayer(GetOrderedUnit())) == MAP_CONTROL_USER ) then
        set tempgroup = GetUnitsOfPlayerMatching(GetOwningPlayer(GetOrderedUnit()), Condition(function Selection))
    endif
    if ( IsUnitGroupEmptyBJ(udg_AI_Movement[GetConvertedPlayerId(GetOwningPlayer(GetOrderedUnit()))]) == false ) then
        call GroupAddGroup( udg_AI_Movement[GetConvertedPlayerId(GetOwningPlayer(GetOrderedUnit()))], tempgroup)
    endif
    call GroupClear(udg_AI_Movement[GetConvertedPlayerId(GetOwningPlayer(GetOrderedUnit()))])
    loop
        set wanderer = FirstOfGroup(tempgroup)
        exitwhen wanderer == null
        set units[counter] = wanderer
        call GroupRemoveUnit( tempgroup, wanderer )        
        set counter = counter + 1
    endloop    
    if not (minX <= orderX and orderX <= maxX and minY <= orderY and orderY <= maxY) or GetPlayerController(GetOwningPlayer(GetOrderedUnit())) == MAP_CONTROL_COMPUTER then
        set angle = Atan2(orderY - Ypos, orderX - Xpos)
     //call BJDebugMsg(I2S(counter))
        //sort of
        //call BJDebugMsg("start sorting")
loop
    exitwhen counter1 >= counter
    set counter2 = counter1
    set index = counter1
    set min = GetUnitPointValue( units[counter1] )
    loop
        exitwhen counter2 >= counter
        if GetUnitPointValue( units[counter2] ) < min then
            set min = GetUnitPointValue( units[counter2] )
            set index = counter2
        endif
        //call BJDebugMsg("counting")
        set counter2 = counter2 + 1
    endloop
    //call BJDebugMsg("preswap")
    //call BJDebugMsg(I2S(GetUnitPointValue( units[0] )))
    set wanderer = units[index]
        //call BJDebugMsg(I2S(GetUnitPointValue( wanderer )))
    //set units[index] = null
    set units[index] = units[counter1]
    //set units[counter1] = null
    set units[counter1] = wanderer
    set counter1 = counter1 + 1
   // call BJDebugMsg("swap")
            //call BJDebugMsg(I2S(GetUnitPointValue( units[0] )))
endloop

        //if ( RAbsBJ(Sin(Deg2Rad(GetUnitFacing( FirstOfGroup(tempgroup)))) - Sin(angle)) > 1 ) then
        //    call BJDebugMsg(R2S(RAbsBJ(Deg2Rad(GetUnitFacing( FirstOfGroup(tempgroup))))))
        //    call BJDebugMsg("switching")
        //    set tempgroup = InvertGroup( tempgroup )
        //endif
    if (counter == 2 ) then
        call DisableTrigger( GetTriggeringTrigger() )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[0]
        set XposUnit = orderX + 000.0*(Cos(angle)) + 150.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY + 000.0*(Sin(angle)) + 150.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[1]
        set XposUnit = orderX + 000.0*(Cos(angle)) + 150.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY + 000.0*(Sin(angle)) + 150.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )  
        call EnableTrigger( GetTriggeringTrigger() )
    elseif (counter == 4 ) then
        call DisableTrigger( GetTriggeringTrigger() )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[0]
        set XposUnit = orderX + 100.0*(Cos(angle)) + 150.0*(Cos(angle -3.14159265/2))
        set YposUnit = orderY + 100.0*(Sin(angle)) + 150.0*(Sin(angle -3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[1]
        set XposUnit = orderX + 100.0*(Cos(angle)) + 150.0*(Cos(angle+ 3.14159265/2))
        set YposUnit = orderY + 100.0*(Sin(angle)) + 150.0*(Sin(angle+ 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[2]
        set XposUnit = orderX - 100.0*(Cos(angle)) + 150.0*(Cos(angle -3.14159265/2))
        set YposUnit = orderY - 100.0*(Sin(angle)) + 150.0*(Sin(angle -3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[3]
        set XposUnit = orderX - 100.0*(Cos(angle)) + 150.0*(Cos(angle+ 3.14159265/2))
        set YposUnit = orderY - 100.0*(Sin(angle)) + 150.0*(Sin(angle+ 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )        
        call EnableTrigger( GetTriggeringTrigger() )      
    elseif (counter == 3 ) then
        call DisableTrigger( GetTriggeringTrigger() )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[0]
        set XposUnit = orderX + 100.0*(Cos(angle)) + 150.0*(Cos(angle+ -3.14159265/2))
        set YposUnit = orderY + 100.0*(Sin(angle)) + 150.0*(Sin(angle+ -3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[1]
        set XposUnit = orderX + 100.0*(Cos(angle)) + 150.0*(Cos(angle+ 3.14159265/2))
        set YposUnit = orderY + 100.0*(Sin(angle)) + 150.0*(Sin(angle+ 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[2]
        set XposUnit = orderX - 100.0*(Cos(angle))
        set YposUnit = orderY - 100.0*(Sin(angle))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call EnableTrigger( GetTriggeringTrigger() )      
    elseif (counter == 5 ) then
        call DisableTrigger( GetTriggeringTrigger() )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[0]
        set XposUnit = orderX + 100.0*(Cos(angle)) + 300.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY + 100.0*(Sin(angle)) + 300.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[1]
        set XposUnit = orderX + 100.0*(Cos(angle))
        set YposUnit = orderY + 100.0*(Sin(angle))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[2]
        set XposUnit = orderX + 100.0*(Cos(angle)) + 300.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY + 100.0*(Sin(angle)) + 300.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[3]
        set XposUnit = orderX - 100.0*(Cos(angle)) + 150.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 100.0*(Sin(angle)) + 150.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[4]
        set XposUnit = orderX - 100.0*(Cos(angle)) + 150.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 100.0*(Sin(angle)) + 150.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )        
        call EnableTrigger( GetTriggeringTrigger() )
    elseif (counter == 6 ) then
        call DisableTrigger( GetTriggeringTrigger() )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[0]
        set XposUnit = orderX + 100.0*(Cos(angle)) + 300.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY + 100.0*(Sin(angle)) + 200.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[1]
        set XposUnit = orderX + 100.0*(Cos(angle))
        set YposUnit = orderY + 100.0*(Sin(angle))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[2]
        set XposUnit = orderX + 100.0*(Cos(angle)) + 300.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY + 100.0*(Sin(angle)) + 300.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[3]
        set XposUnit = orderX - 100.0*(Cos(angle)) + 300.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 100.0*(Sin(angle)) + 300.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[4]
        set XposUnit = orderX - 100.0*(Cos(angle))
        set YposUnit = orderY - 100.0*(Sin(angle))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[5]
        set XposUnit = orderX - 100.0*(Cos(angle)) + 300.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 100.0*(Sin(angle)) + 300.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )        
        call EnableTrigger( GetTriggeringTrigger() )
   elseif (counter == 7 ) then
        call DisableTrigger( GetTriggeringTrigger() )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[0]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 300.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 300.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[1]
        set XposUnit = orderX + 200.0*(Cos(angle))
        set YposUnit = orderY + 200.0*(Sin(angle))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[2]
        set XposUnit = orderX + 100.0*(Cos(angle)) + 300.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY + 100.0*(Sin(angle)) + 300.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[3]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 300.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 300.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[4]
        set XposUnit = orderX - 00.0*(Cos(angle))
        set YposUnit = orderY - 00.0*(Sin(angle))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[5]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 300.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 300.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[6]
        set XposUnit = orderX - 200.0*(Cos(angle))
        set YposUnit = orderY - 200.0*(Sin(angle))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )        
        call EnableTrigger( GetTriggeringTrigger() )
   elseif (counter == 8 ) then
        call DisableTrigger( GetTriggeringTrigger() )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[0]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 300.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 300.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[1]
        set XposUnit = orderX + 200.0*(Cos(angle))
        set YposUnit = orderY + 200.0*(Sin(angle))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[2]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 300.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 300.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[3]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 300.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 300.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[4]
        set XposUnit = orderX - 00.0*(Cos(angle))
        set YposUnit = orderY - 00.0*(Sin(angle))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[5]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 300.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 300.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[6]
        set XposUnit = orderX - 200.0*(Cos(angle)) + 150.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 200.0*(Sin(angle)) + 150.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[7]
        set XposUnit = orderX - 200.0*(Cos(angle)) + 150.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 200.0*(Sin(angle)) + 150.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )        
        call EnableTrigger( GetTriggeringTrigger() )      
   elseif (counter == 9 ) then
        call DisableTrigger( GetTriggeringTrigger() )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[0]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 300.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 300.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[1]
        set XposUnit = orderX + 200.0*(Cos(angle))
        set YposUnit = orderY + 200.0*(Sin(angle))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[2]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 300.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 300.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[3]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 300.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 300.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[4]
        set XposUnit = orderX - 00.0*(Cos(angle))
        set YposUnit = orderY - 00.0*(Sin(angle))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[5]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 300.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 300.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[6]
        set XposUnit = orderX - 200.0*(Cos(angle)) + 300.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 200.0*(Sin(angle)) + 300.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[7]
        set XposUnit = orderX - 200.0*(Cos(angle))
        set YposUnit = orderY - 200.0*(Sin(angle))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )  
        call TriggerWaitForSound(null, 0)
        set wanderer = units[8]
        set XposUnit = orderX - 200.0*(Cos(angle)) + 300.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 200.0*(Sin(angle)) + 300.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )  
        call EnableTrigger( GetTriggeringTrigger() )
   elseif (counter == 10 ) then
        call DisableTrigger( GetTriggeringTrigger() )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[0]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 450.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 450.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[1]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 150.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 150.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[2]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 150.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 150.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[3]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 450.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 450.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )        
        call TriggerWaitForSound(null, 0)
        set wanderer = units[4]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 450.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 450.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[5]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 150.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 150.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[6]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 150.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 150.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[7]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 450.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 450.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )        
        call TriggerWaitForSound(null, 0)
        set wanderer = units[8]
        set XposUnit = orderX - 200.0*(Cos(angle)) + 150.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 200.0*(Sin(angle)) + 150.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[9]
        set XposUnit = orderX - 200.0*(Cos(angle)) + 150.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 200.0*(Sin(angle)) + 150.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )  
        call EnableTrigger( GetTriggeringTrigger() )
   elseif (counter == 11 ) then
        call DisableTrigger( GetTriggeringTrigger() )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[0]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 450.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 450.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[1]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 150.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 150.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[2]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 150.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 150.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[3]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 450.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 450.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )        
        call TriggerWaitForSound(null, 0)
        set wanderer = units[4]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 450.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 450.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[5]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 150.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 150.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[6]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 150.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 150.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[7]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 450.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 450.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )        
        call TriggerWaitForSound(null, 0)
        set wanderer = units[8]
        set XposUnit = orderX - 200.0*(Cos(angle)) + 300.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 200.0*(Sin(angle)) + 300.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[9]
        set XposUnit = orderX - 200.0*(Cos(angle))
        set YposUnit = orderY - 200.0*(Sin(angle))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )  
        call TriggerWaitForSound(null, 0)
        set wanderer = units[10]
        set XposUnit = orderX - 200.0*(Cos(angle)) + 300.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 200.0*(Sin(angle)) + 300.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )  
        call EnableTrigger( GetTriggeringTrigger() )
   elseif (counter == 12 ) then
        call DisableTrigger( GetTriggeringTrigger() )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[0]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 450.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 450.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[1]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 150.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 150.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[2]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 150.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 150.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[3]
        set XposUnit = orderX + 200.0*(Cos(angle)) + 450.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY + 200.0*(Sin(angle)) + 450.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )        
        call TriggerWaitForSound(null, 0)
        set wanderer = units[4]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 450.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 450.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[5]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 150.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 100.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[6]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 150.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 150.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[7]
        set XposUnit = orderX - 00.0*(Cos(angle)) + 450.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 00.0*(Sin(angle)) + 450.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )        
        call TriggerWaitForSound(null, 0)
        set wanderer = units[8]
        set XposUnit = orderX - 200.0*(Cos(angle)) + 450.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 200.0*(Sin(angle)) + 450.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)
        set wanderer = units[9]
        set XposUnit = orderX - 200.0*(Cos(angle)) + 150.0*(Cos(angle - 3.14159265/2))
        set YposUnit = orderY - 200.0*(Sin(angle)) + 150.0*(Sin(angle - 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)        
        set wanderer = units[10]
        set XposUnit = orderX - 200.0*(Cos(angle)) + 150.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 200.0*(Sin(angle)) + 150.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )
        call TriggerWaitForSound(null, 0)        
        set wanderer = units[11]
        set XposUnit = orderX - 200.0*(Cos(angle)) + 450.0*(Cos(angle + 3.14159265/2))
        set YposUnit = orderY - 200.0*(Sin(angle)) + 450.0*(Sin(angle + 3.14159265/2))
        call IssuePointOrderById( wanderer, order, XposUnit, YposUnit )          
        call EnableTrigger( GetTriggeringTrigger() )
    endif
    endif
    set wanderer = null
    //call GroupClear(udg_AI_Movement[GetConvertedPlayerId(GetOwningPlayer(GetOrderedUnit()))])
    call DestroyGroup(tempgroup)
endfunction

//===========================================================================
function InitTrig_Squad_Movement takes nothing returns nothing
    set gg_trg_Squad_Movement = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Squad_Movement, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddCondition( gg_trg_Squad_Movement, Condition(function Trig_Move_to_point_Compy_Conditions) )
    call TriggerAddAction( gg_trg_Squad_Movement, function Trig_Move_to_point_Compy_Actions )
endfunction

 
Makes wandering units belonging to a squad return if straying too far. After catching the wanderer, run a regroup wait trigger. This trigger may be potentially demanding and should not have leaks.
function Trig_Regroup_Actions takes nothing returns nothing
    local real Xpos
    local real Ypos
    local integer order
    local integer i = 1
    local unit wanderer
    local unit commander
    local unit target
    local group batalion = CreateGroup()
    loop
        exitwhen i > udg_BattallionCount
        if ( not ( IsUnitGroupEmptyBJ( udg_Battallion[i] ) ) ) then
            set commander = GetCaptain(udg_Battallion[i])
            call GroupAddGroup( udg_Battallion[i], batalion )
            loop
                set wanderer = FirstOfGroup(batalion)
                exitwhen (wanderer == null)
                set Xpos = GetUnitX(wanderer) - GetUnitX(commander)
                set Ypos = GetUnitY(wanderer) - GetUnitY(commander)
                if ( SquareRoot( Xpos*Xpos + Ypos*Ypos ) >= udg_BattallionRegroup and not (IsUnitInGroup(wanderer, udg_BattallionQueued ) ) ) then
                    set udg_Tempunit = wanderer
                    set udg_TempCommander = commander
                    call IssuePointOrder( wanderer, "move", GetUnitX(commander), GetUnitY(commander) )
                    call TriggerExecute( gg_trg_Regroup_wait )
                endif
                call GroupRemoveUnit(batalion, wanderer)
                set wanderer = null
            endloop
            call GroupClear( batalion )
            set commander = null
        endif
        set i = i + 1
    endloop
    //call DestroyGroup( batalion )
endfunction

//===========================================================================
function InitTrig_Regroup takes nothing returns nothing
    set gg_trg_Regroup = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Regroup, 2.0)
    call TriggerAddAction( gg_trg_Regroup, function Trig_Regroup_Actions )
endfunction

 
Orders a wandering unit to have the same order as the leader's current order.
function Trig_Regroup_wait_Actions takes nothing returns nothing
    local unit wanderer = udg_Tempunit
    local unit commander = udg_TempCommander
    local unit target
    local real Xpos
    local real Ypos
    local integer order
    local integer battallionIndex = LoadInteger(udg_hashtable, GetHandleId(commander), 0)
    call IssuePointOrder( wanderer, "move", GetUnitX(commander), GetUnitY(commander) )
    call GroupAddUnit( udg_BattallionQueued, wanderer )
    loop
        set commander = GetCaptain( udg_Battallion[battallionIndex] )
        set Xpos = GetUnitX(wanderer) - GetUnitX(commander)
        set Ypos = GetUnitY(wanderer) - GetUnitY(commander)        
        exitwhen ( SquareRoot( Xpos*Xpos + Ypos*Ypos ) <= 150 or IsUnitDeadBJ( wanderer ) or IsUnitDeadBJ( commander ) )
        call IssuePointOrder(wanderer, "move", GetUnitX(commander), GetUnitY(commander) )
        call TriggerSleepAction( 0.5 )
    endloop
    set Xpos = LoadReal( udg_hashtable, GetHandleId(commander) , udg_BatalionHash_TargetX)
    set Ypos = LoadReal( udg_hashtable, GetHandleId(commander) , udg_BatalionHash_TargetY)
    set order = LoadInteger( udg_hashtable, GetHandleId(commander), udg_BatalionHash_Order )
    set target = LoadUnitHandle( udg_hashtable, GetHandleId(commander), udg_BatalionHash_TargetUnit )
    if ( order != 0 and GetUnitCurrentOrder(commander) != String2OrderIdBJ("") ) then
        if ( target == null ) then
            //call BJDebugMsg("pointing")
            call IssuePointOrderById(wanderer, order, Xpos, Ypos )
        else
            //call BJDebugMsg("acquiring")
            call IssueTargetOrderById(wanderer, order, target )
        endif
    endif
    set target = null
    call GroupRemoveUnit( udg_BattallionQueued, wanderer )
endfunction

//===========================================================================
function InitTrig_Regroup_wait takes nothing returns nothing
    set gg_trg_Regroup_wait = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Regroup_wait, function Trig_Regroup_wait_Actions )
endfunction

 
Reinforce a squad to the full strength or less if not enough resources.
function Trig_Battalion_reinforce_Conditions takes nothing returns boolean
    if ( GetSpellAbilityId() == 'A002' and LoadInteger(udg_hashtable, GetHandleId(GetSpellTargetUnit()), 1) == 1 and LoadInteger(udg_hashtable, GetHandleId(GetSpellTargetUnit()), udg_Summon) == 0) then
        return true
    else
        return false
    endif
endfunction

function Trig_Battalion_reinforce_Actions takes nothing returns nothing
    local integer captain = IsCaptain(GetUnitTypeId(GetSpellTargetUnit()))
    local integer battallionIndex = LoadInteger(udg_hashtable, GetHandleId(GetSpellTargetUnit()), 0)
    local integer size = CountUnitsInGroup(udg_Battallion[battallionIndex])
    local location temppoint1 = GetUnitLoc(GetSpellTargetUnit())
    local unit reinforcedUnit = GetSpellTargetUnit()
    loop
        exitwhen size > udg_BattalionSize[captain]
        if ( GetPlayerState(GetOwningPlayer(reinforcedUnit), PLAYER_STATE_RESOURCE_GOLD) >= udg_BattalionGoldCost[captain] and GetPlayerState(GetOwningPlayer(reinforcedUnit), PLAYER_STATE_RESOURCE_LUMBER) >= udg_BattalionPowerCost[captain] ) then
            //call BJDebugMsg("reinforcing")
            call SetPlayerState(GetOwningPlayer(reinforcedUnit), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(GetOwningPlayer(reinforcedUnit), PLAYER_STATE_RESOURCE_GOLD) - udg_BattalionGoldCost[captain])
            call SetPlayerState(GetOwningPlayer(reinforcedUnit), PLAYER_STATE_RESOURCE_LUMBER, GetPlayerState(GetOwningPlayer(reinforcedUnit), PLAYER_STATE_RESOURCE_LUMBER) - udg_BattalionPowerCost[captain])
            set bj_lastCreatedUnit = CreateUnitAtLoc(ConvertedPlayer( GetConvertedPlayerId(GetOwningPlayer(reinforcedUnit)) + udg_TranslatePlayerNumber ), udg_BattalionTroop[captain], temppoint1, bj_UNIT_FACING)
            call SetUnitColor( GetLastCreatedUnit(), GetPlayerColor(GetOwningPlayer(reinforcedUnit)) )
            call GroupAddUnit( udg_Battallion[battallionIndex], GetLastCreatedUnit() )
            call SaveInteger( udg_hashtable, GetHandleId(GetLastCreatedUnit()),  0, battallionIndex )
            call RemoveGuardPosition( GetLastCreatedUnit() )
            call IssueTargetOrder( GetLastCreatedUnit(), "move", reinforcedUnit )
        else
            call DisplayTextToForce( GetForceOfPlayer(GetOwningPlayer(GetSpellTargetUnit())), "|cffffcc00Not enough resources to reinforce.|r" )
            call RemoveLocation(temppoint1)
            return
        endif
        set size = size + 1
    endloop
    call RemoveLocation(temppoint1)
    set reinforcedUnit = null
endfunction

//===========================================================================
function InitTrig_Squad_Reinforce takes nothing returns nothing
    set gg_trg_Squad_Reinforce = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Squad_Reinforce, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Squad_Reinforce, Condition( function Trig_Battalion_reinforce_Conditions ) )
    call TriggerAddAction( gg_trg_Squad_Reinforce, function Trig_Battalion_reinforce_Actions )
endfunction
Create units accompanying a created squad leader.
function Trig_Battalion_train_Conditions takes nothing returns boolean
    if ( IsCaptain(GetUnitTypeId(GetTrainedUnit())) > 0 ) then
        set udg_Tempunit = GetTrainedUnit()
        return true
    endif
    return false
endfunction

function Trig_Battalion_train_Actions takes nothing returns nothing
    local unit trigger_unit = udg_Tempunit
    local integer captain = IsCaptain(GetUnitTypeId(trigger_unit))
    local integer batallionIndex = 1
    local integer size = 1
    local boolean found = false
    local location temppoint1 = GetUnitLoc(trigger_unit)
    local location temppoint2
    loop
        exitwhen batallionIndex > 8911 or found == true
        if ( IsUnitGroupEmptyBJ(udg_Battallion[batallionIndex]) == true ) then
            call GroupAddUnit( udg_Battallion[batallionIndex], trigger_unit )
            call SaveInteger( udg_hashtable, GetHandleId(trigger_unit),  0, batallionIndex )
            call SaveInteger( udg_hashtable, GetHandleId(trigger_unit), 1, 1 )
           
            if ( udg_Status[captain] > 0 ) then
                call SaveInteger( udg_hashtable, GetHandleId(trigger_unit), udg_Summon, udg_Status[captain] )
            endif
           
            loop
                exitwhen size > udg_BattalionSize[captain] / 2 + 1 or udg_Status[captain] == udg_BatalionHash_Guards
                set temppoint2 = PolarProjectionBJ(temppoint1, GetRandomReal(0, 50.00), GetRandomDirectionDeg() )
                set bj_lastCreatedUnit = CreateUnitAtLoc(ConvertedPlayer( GetConvertedPlayerId(GetOwningPlayer(trigger_unit)) + udg_TranslatePlayerNumber ), udg_BattalionTroop[captain], temppoint2, bj_UNIT_FACING)
                call SetUnitColor( GetLastCreatedUnit(), GetPlayerColor(GetOwningPlayer(trigger_unit)) )
                call SaveInteger( udg_hashtable, GetHandleId(GetLastCreatedUnit()),  0, batallionIndex )
                call GroupAddUnit( udg_Battallion[batallionIndex], GetLastCreatedUnit() )
                call RemoveGuardPosition( GetLastCreatedUnit() )
                //call IssueTargetOrder( GetLastCreatedUnit(), "move", GetTrainedUnit() )

                //if ( udg_Status[captain] == udg_BatalionHash_Summonable ) then
                //    call SaveInteger( udg_hashtable, GetHandleId(GetLastCreatedUnit()), udg_Summon, udg_BatalionHash_Summonable )
                //    call UnitApplyTimedLife( GetLastCreatedUnit(), 'BTLF', 20 )
                //endif
               
                if ( udg_Status[captain] > 0 ) then
                    call SaveInteger( udg_hashtable, GetHandleId(GetLastCreatedUnit()), udg_Summon, udg_Status[captain] )
                    if ( udg_Status[captain] == udg_BatalionHash_Summonable ) then
                        call UnitApplyTimedLife( GetLastCreatedUnit(), 'BTLF', 20 )
                    endif
                endif
               
                set size = size + 1
            endloop
            set found = true
        endif
        set batallionIndex = batallionIndex + 1
    endloop
    set udg_BattallionCount = udg_BattallionCount + 1
    call RemoveLocation(temppoint1)
    call RemoveLocation(temppoint2)
endfunction

//===========================================================================
function InitTrig_Squad_Trained takes nothing returns nothing
    set gg_trg_Squad_Trained = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Squad_Trained, EVENT_PLAYER_UNIT_TRAIN_FINISH )
    call TriggerAddCondition( gg_trg_Squad_Trained, Condition( function Trig_Battalion_train_Conditions ) )
    call TriggerAddAction( gg_trg_Squad_Trained, function Trig_Battalion_train_Actions )
endfunction

 
Memorize currently selected units to preserve selection if one of the selected leaders falls in battle.
Selection Thingie
  Events
    Player - Player 1 (Red) Selects a unit
    Player - Player 2 (Blue) Selects a unit
    Player - Player 3 (Teal) Selects a unit
    Player - Player 4 (Purple) Selects a unit
    Player - Player 5 (Yellow) Selects a unit
    Player - Player 6 (Orange) Selects a unit
  Conditions
    (Load 0 of (Key (Triggering unit).) from hashtable.) Greater than 0
    (Load 1 of (Key (Triggering unit).) from hashtable.) Equal to 1
    ((Triggering player) controller) Equal to User
    ((Triggering unit) is A Hero) Equal to False
    ((Triggering unit) is Mechanical) Equal to False
    ((Triggering unit) is Summoned) Equal to False