Advertisement
Guest User

Untitled

a guest
Aug 24th, 2010
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 74.19 KB | None | 0 0
  1. //============================================================================
  2. //  common.ai
  3. //============================================================================
  4. native DebugS               takes string str                            returns nothing
  5. native DebugFI              takes string str, integer val               returns nothing
  6. native DebugUnitID          takes string str, integer val               returns nothing
  7. native DisplayText          takes integer p, string str                 returns nothing
  8. native DisplayTextI         takes integer p, string str, integer val    returns nothing
  9. native DoAiScriptDebug      takes nothing                               returns boolean
  10.  
  11. native GetAiPlayer          takes nothing                               returns integer
  12. native GetHeroId            takes nothing                               returns integer
  13. native GetHeroLevelAI       takes nothing                               returns integer
  14.  
  15. native GetUnitCount         takes integer unitid                        returns integer
  16. native GetPlayerUnitTypeCount takes player p, integer unitid            returns integer
  17. native GetUnitCountDone     takes integer unitid                        returns integer
  18. native GetTownUnitCount     takes integer id, integer tn, boolean dn    returns integer
  19. native GetUnitGoldCost      takes integer unitid                        returns integer
  20. native GetUnitWoodCost      takes integer unitid                        returns integer
  21.  
  22. native GetMinesOwned        takes nothing                               returns integer
  23. native GetGoldOwned         takes nothing                               returns integer
  24. native TownWithMine         takes nothing                               returns integer
  25. native TownHasMine          takes integer townid                        returns boolean
  26. native TownHasHall          takes integer townid                        returns boolean
  27.  
  28. native GetUpgradeLevel      takes integer id                            returns integer
  29. native GetUpgradeGoldCost   takes integer id                            returns integer
  30. native GetUpgradeWoodCost   takes integer id                            returns integer
  31. native GetNextExpansion     takes nothing                               returns integer
  32. native GetMegaTarget        takes nothing                               returns unit
  33. native GetBuilding          takes player p                              returns unit
  34. native GetEnemyPower        takes nothing                               returns integer
  35. native SetAllianceTarget    takes unit id                               returns nothing
  36. native GetAllianceTarget    takes nothing                               returns unit
  37.  
  38. native SetProduce           takes integer qty, integer id, integer town returns boolean
  39. native Unsummon             takes unit unitid                           returns nothing
  40. native SetExpansion         takes unit peon, integer id                 returns boolean
  41. native SetUpgrade           takes integer id                            returns boolean
  42. native SetHeroLevels        takes code func                             returns nothing
  43. native SetNewHeroes         takes boolean state                         returns nothing
  44. native PurchaseZeppelin     takes nothing                               returns nothing
  45.  
  46. native MergeUnits           takes integer qty, integer a, integer b, integer make returns boolean
  47.  
  48. native SetCampaignAI        takes nothing                               returns nothing
  49. native SetMeleeAI           takes nothing                               returns nothing
  50. native SetTargetHeroes      takes boolean state                         returns nothing
  51. native SetPeonsRepair       takes boolean state                         returns nothing
  52. native SetHeroesFlee        takes boolean state                         returns nothing
  53. native SetWatchMegaTargets  takes boolean state                         returns nothing
  54. native SetIgnoreInjured     takes boolean state                         returns nothing
  55. native SetHeroesTakeItems   takes boolean state                         returns nothing
  56. native SetUnitsFlee         takes boolean state                         returns nothing
  57. native SetGroupsFlee        takes boolean state                         returns nothing
  58. native SetSlowChopping      takes boolean state                         returns nothing
  59. native SetCaptainChanges    takes boolean allow                         returns nothing
  60. native SetSmartArtillery    takes boolean state                         returns nothing
  61. native SetReplacementCount  takes integer qty                           returns nothing
  62. native GroupTimedLife       takes boolean allow                         returns nothing
  63. native RemoveInjuries       takes nothing                               returns nothing
  64. native RemoveSiege          takes nothing                               returns nothing
  65.  
  66. native InitAssault          takes nothing                               returns nothing
  67. native AddAssault           takes integer qty, integer id               returns boolean
  68. native AddDefenders         takes integer qty, integer id               returns boolean
  69.  
  70. native GetCreepCamp         takes integer min, integer max, boolean flyers_ok returns unit
  71.  
  72. native StartGetEnemyBase    takes nothing                               returns nothing
  73. native WaitGetEnemyBase     takes nothing                               returns boolean
  74. native GetEnemyBase         takes nothing                               returns unit
  75. native GetExpansionFoe      takes nothing                               returns unit
  76. native GetEnemyExpansion    takes nothing                               returns unit
  77. native GetExpansionX        takes nothing                               returns integer
  78. native GetExpansionY        takes nothing                               returns integer
  79. native SetStagePoint        takes real x, real y                        returns nothing
  80. native AttackMoveKill       takes unit target                           returns nothing
  81. native AttackMoveXY         takes integer x, integer y                  returns nothing
  82. native SuicidePlayer        takes player id, boolean check_full         returns boolean
  83. native CaptainInCombat      takes boolean attack_captain                returns boolean
  84. native IsTowered            takes unit target                           returns boolean
  85.  
  86. native ClearHarvestAI       takes nothing                               returns nothing
  87. native HarvestGold          takes integer town, integer peons           returns nothing
  88. native HarvestWood          takes integer town, integer peons           returns nothing
  89. native GetExpansionPeon     takes nothing                               returns unit
  90.  
  91. native StopGathering        takes nothing                               returns nothing
  92. native AddGuardPost         takes integer id, real x, real y            returns nothing
  93. native FillGuardPosts       takes nothing                               returns nothing
  94. native ReturnGuardPosts     takes nothing                               returns nothing
  95. native CreateCaptains       takes nothing                               returns nothing
  96. native SetCaptainHome       takes integer which, real x, real y         returns nothing
  97. native ShiftTownSpot        takes real x, real y                        returns nothing
  98. native TeleportCaptain      takes real x, real y                        returns nothing
  99. native ClearCaptainTargets  takes nothing                               returns nothing
  100. native CaptainAttack        takes real x, real y                        returns nothing
  101. native CaptainVsUnits       takes player id                             returns nothing
  102. native CaptainVsPlayer      takes player id                             returns nothing
  103. native CaptainGoHome        takes nothing                               returns nothing
  104. native CaptainIsHome        takes nothing                               returns boolean
  105. native CaptainIsFull        takes nothing                               returns boolean
  106. native CaptainIsEmpty       takes nothing                               returns boolean
  107. native CaptainGroupSize     takes nothing                               returns integer
  108. native CaptainReadiness     takes nothing                               returns integer
  109. native CaptainRetreating    takes nothing                               returns boolean
  110. native CaptainReadinessHP   takes nothing                               returns integer
  111. native CaptainReadinessMa   takes nothing                               returns integer
  112. native CaptainAtGoal        takes nothing                               returns boolean
  113. native CreepsOnMap          takes nothing                               returns boolean
  114. native SuicideUnit          takes integer count, integer unitid         returns nothing
  115. native SuicideUnitEx        takes integer ct, integer uid, integer pid  returns nothing
  116. native StartThread          takes code func                             returns nothing
  117. native Sleep                takes real seconds                          returns nothing
  118. native UnitAlive            takes unit id                               returns boolean
  119. native IgnoredUnits         takes integer unitid                        returns integer
  120. native TownThreated         takes nothing                               returns boolean
  121.  
  122. native CommandsWaiting      takes nothing                               returns integer
  123. native GetLastCommand       takes nothing                               returns integer
  124. native GetLastData          takes nothing                               returns integer
  125. native PopLastCommand       takes nothing                               returns nothing
  126.  
  127. //============================================================================
  128. //  Globals for all AI scripts
  129. //============================================================================
  130. globals
  131.  
  132.     //--------------------------------------------------------------------
  133.     //  HUMANS
  134.     //--------------------------------------------------------------------
  135.  
  136.     // human heroes
  137.     constant integer ARCHMAGE           = 'Hamg'
  138.     constant integer PALADIN            = 'Hpal'
  139.     constant integer MTN_KING           = 'Hmkg'
  140.  
  141.     // human hero abilities
  142.     constant integer AVATAR             = 'AHav'
  143.     constant integer BASH               = 'AHbh'
  144.     constant integer THUNDER_BOLT       = 'AHtb'
  145.     constant integer THUNDER_CLAP       = 'AHtc'
  146.  
  147.     constant integer DEVOTION_AURA      = 'AHad'
  148.     constant integer DIVINE_SHIELD      = 'AHds'
  149.     constant integer HOLY_BOLT          = 'AHhb'
  150.     constant integer RESURRECTION       = 'AHre'
  151.  
  152.     constant integer BLIZZARD           = 'AHbz'
  153.     constant integer BRILLIANCE_AURA    = 'AHab'
  154.     constant integer MASS_TELEPORT      = 'AHmt'
  155.     constant integer WATER_ELEMENTAL    = 'AHwe'
  156.  
  157.     // special human heroes
  158.     constant integer JAINA              = 'Hjai'
  159.     constant integer MURADIN            = 'Hmbr'
  160.  
  161.     // human units                      
  162.     constant integer COPTER             = 'hgyr'
  163.     constant integer ELEMENTAL          = 'hwat'
  164.     constant integer FOOTMAN            = 'hfoo'
  165.     constant integer FOOTMEN            =  FOOTMAN
  166.     constant integer GRYPHON            = 'hgry'
  167.     constant integer KNIGHT             = 'hkni'
  168.     constant integer MORTAR             = 'hmtm'
  169.     constant integer PEASANT            = 'hpea'
  170.     constant integer PRIEST             = 'hmpr'
  171.     constant integer RIFLEMAN           = 'hrif'
  172.     constant integer RIFLEMEN           =  RIFLEMAN
  173.     constant integer SORCERESS          = 'hsor'
  174.     constant integer TANK               = 'hmtt'
  175.     constant integer MILITIA            = 'hmil'
  176.  
  177.     // human buildings
  178.     constant integer AVIARY             = 'hgra'
  179.     constant integer BARRACKS           = 'hbar'
  180.     constant integer BLACKSMITH         = 'hbla'
  181.     constant integer CANNON_TOWER       = 'hctw'
  182.     constant integer CASTLE             = 'hcas'
  183.     constant integer CHURCH             = 'htws'
  184.     constant integer MAGE_TOWER         =  CHURCH
  185.     constant integer GUARD_TOWER        = 'hgtw'
  186.     constant integer HOUSE              = 'hhou'
  187.     constant integer HUMAN_ALTAR        = 'halt'
  188.     constant integer KEEP               = 'hkee'
  189.     constant integer LUMBER_MILL        = 'hlum'
  190.     constant integer SANCTUM            = 'hars'
  191.     constant integer TOWN_HALL          = 'htow'
  192.     constant integer WATCH_TOWER        = 'hwtw'
  193.     constant integer WORKSHOP           = 'harm'
  194.  
  195.     // human upgrades
  196.     constant integer UPG_MELEE          = 'Rhme'
  197.     constant integer UPG_RANGED         = 'Rhra'
  198.     constant integer UPG_ARTILLERY      = 'Rhaa'
  199.     constant integer UPG_ARMOR          = 'Rhar'
  200.     constant integer UPG_GOLD           = 'Rhmi'
  201.     constant integer UPG_MASONRY        = 'Rhac'
  202.     constant integer UPG_SIGHT          = 'Rhss'
  203.     constant integer UPG_DEFEND         = 'Rhde'
  204.     constant integer UPG_BREEDING       = 'Rhan'
  205.     constant integer UPG_PRAYING        = 'Rhpt'
  206.     constant integer UPG_SORCERY        = 'Rhst'
  207.     constant integer UPG_LEATHER        = 'Rhla'
  208.     constant integer UPG_GUN_RANGE      = 'Rhri'
  209.     constant integer UPG_WOOD           = 'Rhlh'
  210.     constant integer UPG_SENTINEL       = 'Rhse'
  211.     constant integer UPG_SCATTER        = 'Rhsr'
  212.     constant integer UPG_BOMBS          = 'Rhgb'
  213.     constant integer UPG_HAMMERS        = 'Rhhb'
  214.  
  215.     //--------------------------------------------------------------------
  216.     //  ORCS
  217.     //--------------------------------------------------------------------
  218.  
  219.     // orc heroes
  220.     constant integer BLADE_MASTER       = 'Obla'
  221.     constant integer FAR_SEER           = 'Ofar'
  222.     constant integer TAUREN_CHIEF       = 'Otch'
  223.  
  224.     // special orc heroes
  225.     constant integer GROM               = 'Ogrh'
  226.     constant integer THRALL             = 'Othr'
  227.  
  228.     // orc hero abilities
  229.     constant integer CRITICAL_STRIKE    = 'AOcr'
  230.     constant integer MIRROR_IMAGE       = 'AOmi'
  231.     constant integer BLADE_STORM        = 'AOww'
  232.     constant integer WIND_WALK          = 'AOwk'
  233.  
  234.     constant integer CHAIN_LIGHTNING    = 'AOcl'
  235.     constant integer EARTHQUAKE         = 'AOeq'
  236.     constant integer FAR_SIGHT          = 'AOfs'
  237.     constant integer SPIRIT_WOLF        = 'AOsf'
  238.  
  239.     constant integer ENDURANE_AURA      = 'AOae'
  240.     constant integer REINCARNATION      = 'AOre'
  241.     constant integer SHOCKWAVE          = 'AOsh'
  242.     constant integer WAR_STOMP          = 'AOws'
  243.  
  244.     // orc units
  245.     constant integer GUARDIAN           = 'oang'
  246.     constant integer CATAPULT           = 'ocat'
  247.     constant integer WITCH_DOCTOR       = 'odoc'
  248.     constant integer GRUNT              = 'ogru'
  249.     constant integer HEAD_HUNTER        = 'ohun'
  250.     constant integer KODO_BEAST         = 'okod'
  251.     constant integer PEON               = 'opeo'
  252.     constant integer RAIDER             = 'orai'
  253.     constant integer SHAMAN             = 'oshm'
  254.     constant integer TAUREN             = 'otau'
  255.     constant integer WYVERN             = 'owyv'
  256.  
  257.     // orc buildings
  258.     constant integer ORC_ALTAR          = 'oalt'
  259.     constant integer ORC_BARRACKS       = 'obar'
  260.     constant integer BESTIARY           = 'obea'
  261.     constant integer FORGE              = 'ofor'
  262.     constant integer FORTRESS           = 'ofrt'
  263.     constant integer GREAT_HALL         = 'ogre'
  264.     constant integer LODGE              = 'osld'
  265.     constant integer STRONGHOLD         = 'ostr'
  266.     constant integer BURROW             = 'otrb'
  267.     constant integer TOTEM              = 'otto'
  268.     constant integer ORC_WATCH_TOWER    = 'owtw'
  269.  
  270.     // orc upgrades
  271.     constant integer UPG_ORC_MELEE      = 'Rome'
  272.     constant integer UPG_ORC_RANGED     = 'Rora'
  273.     constant integer UPG_ORC_ARTILLERY  = 'Roaa'
  274.     constant integer UPG_ORC_ARMOR      = 'Roar'
  275.     constant integer UPG_ORC_WAR_DRUMS  = 'Rwdm'
  276.     constant integer UPG_ORC_PILLAGE    = 'Ropg'
  277.     constant integer UPG_ORC_BERSERK    = 'Robs'
  278.     constant integer UPG_ORC_PULVERIZE  = 'Rows'
  279.     constant integer UPG_ORC_ENSNARE    = 'Roen'
  280.     constant integer UPG_ORC_WYVERNS    = 'Rowt'
  281.     constant integer UPG_ORC_VENOM      = 'Rovs'
  282.     constant integer UPG_ORC_DOCS       = 'Rowd'
  283.     constant integer UPG_ORC_SHAMAN     = 'Rost'
  284.     constant integer UPG_ORC_SPIKES     = 'Rosp'
  285.     constant integer UPG_ORC_REGEN      = 'Rotr'
  286.  
  287.     // Warcraft 2 orc units
  288.     constant integer OGRE_MAGI          = 'nomg'
  289.     constant integer ORC_DRAGON         = 'nrwm'
  290.     constant integer SAPPER             = 'ngsp'
  291.     constant integer ZEPPLIN            = 'nzep'
  292.     constant integer ZEPPELIN           =  ZEPPLIN
  293.     constant integer W2_WARLOCK         = 'nw2w'
  294.     constant integer PIG_FARM           = 'npgf'
  295.  
  296.     // special orc units
  297.     constant integer CHAOS_GRUNT        = 'nchg'
  298.     constant integer CHAOS_WARLOCK      = 'nchw'
  299.     constant integer CHAOS_RAIDER       = 'nchr'
  300.     constant integer CHAOS_PEON         = 'ncpn'
  301.     constant integer CHAOS_KODO         = 'nckb'
  302.  
  303.     //--------------------------------------------------------------------
  304.     //  UNDEAD
  305.     //--------------------------------------------------------------------
  306.  
  307.     // undead heroes
  308.     constant integer DEATH_KNIGHT       = 'Udea'
  309.     constant integer DREAD_LORD         = 'Udre'
  310.     constant integer LICH               = 'Ulic'
  311.  
  312.     // special undead heroes
  313.     constant integer MALGANIS           = 'Umal'
  314.     constant integer TICHONDRIUS        = 'Utic'
  315.     constant integer PIT_LORD           = 'Npld'
  316.  
  317.     // undead hero abilities
  318.     constant integer SLEEP              = 'AUsl'
  319.     constant integer VAMP_AURA          = 'AUav'
  320.     constant integer CARRION_SWARM      = 'AUcs'
  321.     constant integer INFERNO            = 'AUin'
  322.  
  323.     constant integer DARK_RITUAL        = 'AUdr'
  324.     constant integer DEATH_DECAY        = 'AUdd'
  325.     constant integer FROST_ARMOR        = 'AUfa'
  326.     constant integer FROST_NOVA         = 'AUfn'
  327.  
  328.     constant integer ANIM_DEAD          = 'AUan'
  329.     constant integer DEATH_COIL         = 'AUdc'
  330.     constant integer DEATH_PACT         = 'AUdp'
  331.     constant integer UNHOLY_AURA        = 'AUau'
  332.  
  333.     // undead units
  334.     constant integer ABOMINATION        = 'uabo'
  335.     constant integer ACOLYTE            = 'uaco'
  336.     constant integer BANSHEE            = 'uban'
  337.     constant integer PIT_FIEND          = 'ucry'
  338.     constant integer CRYPT_FIEND        =  PIT_FIEND
  339.     constant integer FROST_WYRM         = 'ufro'
  340.     constant integer GARGOYLE           = 'ugar'
  341.     constant integer GARGOYLE_MORPH     = 'ugrm'
  342.     constant integer GHOUL              = 'ugho'
  343.     constant integer MEAT_WAGON         = 'umtw'
  344.     constant integer NECRO              = 'unec'
  345.     constant integer SKEL_WARRIOR       = 'uske'
  346.     constant integer SHADE              = 'ushd'
  347.  
  348.     // undead buildings
  349.     constant integer UNDEAD_MINE        = 'ugol'
  350.     constant integer UNDEAD_ALTAR       = 'uaod'
  351.     constant integer BONEYARD           = 'ubon'
  352.     constant integer GARG_SPIRE         = 'ugsp'
  353.     constant integer NECROPOLIS_1       = 'unpl'    // normal
  354.     constant integer NECROPOLIS_2       = 'unp1'    // upgraded once
  355.     constant integer NECROPOLIS_3       = 'unp2'    // full upgrade
  356.     constant integer SAC_PIT            = 'usap'
  357.     constant integer CRYPT              = 'usep'
  358.     constant integer SLAUGHTERHOUSE     = 'uslh'
  359.     constant integer DAMNED_TEMPLE      = 'utod'
  360.     constant integer ZIGGURAT_1         = 'uzig'    // normal
  361.     constant integer ZIGGURAT_2         = 'uzg1'    // upgraded
  362.     constant integer GRAVEYARD          = 'ugrv'
  363.  
  364.     // undead upgrades
  365.     constant integer UPG_UNHOLY_STR     = 'Rume'
  366.     constant integer UPG_CR_ATTACK      = 'Rura'
  367.     constant integer UPG_UNHOLY_ARMOR   = 'Ruar'
  368.     constant integer UPG_CANNIBALIZE    = 'Ruac'
  369.     constant integer UPG_GHOUL_FRENZY   = 'Rugf'
  370.     constant integer UPG_FIEND_WEB      = 'Ruwb'
  371.     constant integer UPG_ABOM           = 'Ruab'
  372.     constant integer UPG_STONE_FORM     = 'Rusf'
  373.     constant integer UPG_NECROS         = 'Rune'
  374.     constant integer UPG_BANSHEE        = 'Ruba'
  375.     constant integer UPG_MEAT_WAGON     = 'Rump'
  376.     constant integer UPG_WYRM_BREATH    = 'Rufb'
  377.     constant integer UPG_SKEL_LIFE      = 'Rusl'
  378.     constant integer UPG_SACRIFICE      = 'Rurs'
  379.     constant integer UPG_ABOM_EXPL      = 'Ruax'
  380.     constant integer UPG_CR_ARMOR       = 'Rucr'
  381.     constant integer UPG_PLAGUE         = 'Rupc'
  382.  
  383.     //--------------------------------------------------------------------
  384.     //  ELVES
  385.     //--------------------------------------------------------------------
  386.  
  387.     // elf heroes
  388.     constant integer DEMON_HUNTER       = 'Edem'
  389.     constant integer DEMON_HUNTER_M     = 'Edmm'
  390.     constant integer KEEPER             = 'Ekee'
  391.     constant integer MOON_CHICK         = 'Emoo'
  392.     constant integer MOON_BABE          =  MOON_CHICK
  393.     constant integer MOON_HONEY         =  MOON_CHICK
  394.  
  395.     // special elf heroes
  396.     constant integer SYLVANUS           = 'Hvwd'
  397.     constant integer CENARIUS           = 'Ecen'
  398.  
  399.     // elf hero abilities
  400.     constant integer FORCE_NATURE       = 'AEfn'
  401.     constant integer ENT_ROOTS          = 'AEer'
  402.     constant integer THORNS_AURA        = 'AEah'
  403.     constant integer TRANQUILITY        = 'AEtq'
  404.  
  405.     constant integer EVASION            = 'AEev'
  406.     constant integer IMMOLATION         = 'AEim'
  407.     constant integer MANA_BURN          = 'AEmb'
  408.     constant integer METAMORPHOSIS      = 'AEme'
  409.  
  410.     constant integer SEARING_ARROWS     = 'AHfa'
  411.     constant integer SCOUT              = 'AEst'
  412.     constant integer STARFALL           = 'AEsf'
  413.     constant integer TRUESHOT           = 'AEar'
  414.  
  415.     // elf units
  416.     constant integer WISP               = 'ewsp'
  417.     constant integer ARCHER             = 'earc'
  418.     constant integer DRUID_TALON        = 'edot'
  419.     constant integer DRUID_TALON_M      = 'edtm'
  420.     constant integer BALLISTA           = 'ebal'
  421.     constant integer DRUID_CLAW         = 'edoc'
  422.     constant integer DRUID_CLAW_M       = 'edcm'
  423.     constant integer DRYAD              = 'edry'
  424.     constant integer HIPPO              = 'ehip'
  425.     constant integer HIPPO_RIDER        = 'ehpr'
  426.     constant integer HUNTRESS           = 'esen'
  427.     constant integer CHIMAERA           = 'echm'
  428.     constant integer ENT                = 'efon'
  429.  
  430.     // special elf units
  431.     constant integer HIGH_ARCHER        = 'nhea'
  432.     constant integer HIGH_FOOTMAN       = 'hcth'
  433.     constant integer HIGH_FOOTMEN       =  HIGH_FOOTMAN
  434.     constant integer HIGH_SWORDMAN      = 'hhes'
  435.     constant integer DRAGON_HAWK        = 'nws1'
  436.     constant integer CORRUPT_TREANT     = 'nenc'
  437.     constant integer POISON_TREANT      = 'nenp'
  438.     constant integer PLAGUE_TREANT      = 'nepl'
  439.     constant integer SHANDRIS           = 'eshd'
  440.  
  441.     // elf buildings
  442.     constant integer ANCIENT_LORE       = 'eaoe'
  443.     constant integer ANCIENT_WAR        = 'eaom'
  444.     constant integer ANCIENT_WIND       = 'eaow'
  445.     constant integer TREE_AGES          = 'etoa'
  446.     constant integer TREE_ETERNITY      = 'etoe'
  447.     constant integer TREE_LIFE          = 'etol'
  448.     constant integer ANCIENT_PROTECT    = 'etrp'
  449.     constant integer ELF_ALTAR          = 'eate'
  450.     constant integer BEAR_DEN           = 'edol'
  451.     constant integer CHIMAERA_ROOST     = 'edos'
  452.     constant integer HUNTERS_HALL       = 'edob'
  453.     constant integer MOON_WELL          = 'emow'
  454.     constant integer ELF_MINE           = 'egol'
  455.  
  456.     // special elf buildings
  457.     constant integer ELF_FARM           = 'nefm'
  458.     constant integer ELF_GUARD_TOWER    = 'negt'
  459.     constant integer HIGH_SKY           = 'negm'
  460.     constant integer HIGH_EARTH         = 'negf'
  461.     constant integer HIGH_TOWER         = 'negt'
  462.     constant integer ELF_HIGH_BARRACKS  = 'nheb'
  463.     constant integer CORRUPT_LIFE       = 'nctl'
  464.     constant integer CORRUPT_WELL       = 'ncmw'
  465.     constant integer CORRUPT_PROTECTOR  = 'ncap'
  466.     constant integer CORRUPT_WAR        = 'ncaw'
  467.  
  468.     // elf upgrades
  469.     constant integer UPG_STR_MOON       = 'Resm'
  470.     constant integer UPG_STR_WILD       = 'Resw'
  471.     constant integer UPG_MOON_ARMOR     = 'Rema'
  472.     constant integer UPG_HIDES          = 'Rerh'
  473.     constant integer UPG_ULTRAVISION    = 'Reuv'
  474.     constant integer UPG_BLESSING       = 'Renb'
  475.     constant integer UPG_SCOUT          = 'Resc'
  476.     constant integer UPG_GLAIVE         = 'Remg'
  477.     constant integer UPG_BOWS           = 'Reib'
  478.     constant integer UPG_MARKSMAN       = 'Remk'
  479.     constant integer UPG_DRUID_TALON    = 'Redt'
  480.     constant integer UPG_DRUID_CLAW     = 'Redc'
  481.     constant integer UPG_ABOLISH        = 'Resi'
  482.     constant integer UPG_CHIM_ACID      = 'Recb'
  483.     constant integer UPG_HIPPO_TAME     = 'Reht'
  484.     constant integer UPG_BOLT           = 'Repd'
  485.  
  486.     //--------------------------------------------------------------------
  487.     // Neutral
  488.     //--------------------------------------------------------------------
  489.     constant integer DEMON_GATE         = 'ndmg'
  490.     constant integer FELLHOUND          = 'nfel'
  491.     constant integer INFERNAL           = 'ninf'
  492.     constant integer DOOMGUARD          = 'nbal'
  493.     constant integer SATYR              = 'nsty'
  494.     constant integer TRICKSTER          = 'nsat'
  495.     constant integer SHADOWDANCER       = 'nsts'
  496.     constant integer SOULSTEALER        = 'nstl'
  497.     constant integer HELLCALLER         = 'nsth'
  498.     constant integer SKEL_ARCHER        = 'nska'
  499.     constant integer SKEL_MARKSMAN      = 'nskm'
  500.     constant integer SKEL_BURNING       = 'nskf'
  501.     constant integer SKEL_GIANT         = 'nskg'
  502.     constant integer FURBOLG            = 'nfrl'
  503.     constant integer FURBOLG_TRACKER    = 'nfrb'
  504.     constant integer FURBOLG_SHAMAN     = 'nfrs'
  505.     constant integer FURBOLG_CHAMP      = 'nfrg'
  506.     constant integer FURBOLG_ELDER      = 'nfre'
  507.  
  508.     //--------------------------------------------------------------------
  509.     constant integer M1                 =    60
  510.     constant integer M2                 =  2*60
  511.     constant integer M3                 =  3*60
  512.     constant integer M4                 =  4*60
  513.     constant integer M5                 =  5*60
  514.     constant integer M6                 =  6*60
  515.     constant integer M7                 =  7*60
  516.     constant integer M8                 =  8*60
  517.     constant integer M9                 =  9*60
  518.     constant integer M10                = 10*60
  519.     constant integer M11                = 11*60
  520.     constant integer M12                = 12*60
  521.     constant integer M13                = 13*60
  522.     constant integer M14                = 14*60
  523.     constant integer M15                = 15*60
  524.  
  525.     constant integer EASY               = 1
  526.     constant integer NORMAL             = 2
  527.     constant integer HARD               = 3
  528.     constant integer INSANE             = 4
  529.  
  530.     constant integer ATTACK_CAPTAIN     = 1
  531.     constant integer DEFENSE_CAPTAIN    = 2
  532.     constant integer BOTH_CAPTAINS      = 3
  533.  
  534.     constant integer BUILD_UNIT         = 1
  535.     constant integer BUILD_UPGRADE      = 2
  536.     constant integer BUILD_EXPAND       = 3
  537.  
  538.     //--------------------------------------------------------------------
  539.  
  540.     player  ai_player
  541.  
  542.     integer sleep_seconds
  543.     integer total_gold              = 0
  544.     integer total_wood              = 0
  545.     integer gold_buffer             = 0 // usually for potion money
  546.     integer difficulty              = NORMAL
  547.     integer racial_farm             = 'hhou'
  548.     integer hero_id                 = 'Hamg'
  549.     integer hero_id2                = 'Hmkg'
  550.     integer array skills1
  551.     integer array skills2
  552.     integer max_hero_level          = 0
  553.  
  554.     integer array harass_qty
  555.     integer array harass_max
  556.     integer array harass_units
  557.     integer harass_length           = 0
  558.  
  559.     integer array defense_qty
  560.     integer array defense_units
  561.     integer defense_length          = 0
  562.  
  563.     integer array build_qty
  564.     integer array build_type
  565.     integer array build_item
  566.     integer array build_town
  567.     integer build_length            = 0
  568.  
  569.     integer campaign_gold_peons     = 5
  570.     integer campaign_wood_peons     = 3
  571.     integer campaign_basics_speed   = 5
  572.  
  573.     boolean harvest_town1           = true
  574.     boolean harvest_town2           = true
  575.     boolean harvest_town3           = true
  576.     boolean do_campaign_farms       = true
  577.     boolean two_heroes              = false
  578.     boolean allow_air_creeps        = false
  579.     boolean take_exp                = false
  580.     boolean allow_signal_abort      = false
  581.     boolean ready_for_zeppelin      = true
  582.     boolean get_zeppelin            = false
  583.  
  584.     boolean build_campaign_attackers = true
  585.  
  586.     boolean do_debug_cheats         = false
  587.     boolean trace_on                = true
  588. endglobals
  589.  
  590. //============================================================================
  591. function Trace takes string message returns nothing
  592.     if trace_on then
  593.         call DisplayText(GetAiPlayer(),message)
  594.     endif
  595. endfunction
  596.  
  597. //============================================================================
  598. function TraceI takes string message, integer val returns nothing
  599.     if trace_on then
  600.         call DisplayTextI(GetAiPlayer(),message,val)
  601.     endif
  602. endfunction
  603.  
  604. //============================================================================
  605. function InitAI takes nothing returns nothing
  606.     set ai_player = Player(GetAiPlayer())
  607.     set sleep_seconds = 0
  608.     call StopGathering()
  609. endfunction
  610.  
  611. //============================================================================
  612. function StandardAI takes code heroes, code peons, code attacks returns nothing
  613.     call InitAI()
  614.     call SetTargetHeroes(true)
  615.     call SetMeleeAI()
  616.     call SetHeroesFlee(true)
  617.     call SetWatchMegaTargets(true)
  618.     call SetHeroesTakeItems(true)
  619.     call SetIgnoreInjured(true)
  620.     call SetUnitsFlee(true)
  621.     call SetGroupsFlee(true)
  622.     call SetPeonsRepair(true)
  623.     call CreateCaptains()
  624.     call SetSmartArtillery(true)
  625.     call SetHeroLevels(heroes)
  626.     call Sleep(0.1)
  627.     call StartThread(peons)
  628.     call StartThread(attacks)
  629. endfunction
  630.  
  631. //============================================================================
  632. //  Utility Functions
  633. //============================================================================
  634. function SuicideSleep takes integer seconds returns nothing
  635.     set sleep_seconds = sleep_seconds - seconds
  636.     loop
  637.         exitwhen seconds <= 0
  638.         exitwhen allow_signal_abort and CommandsWaiting() != 0
  639.  
  640.         if seconds >= 5 then
  641.             call Sleep(5)
  642.             set seconds = seconds - 5
  643.         else
  644.             call Sleep(seconds)
  645.             set seconds = 0
  646.         endif
  647.     endloop
  648. endfunction
  649.  
  650. //============================================================================
  651. function WaitForSignal takes nothing returns integer
  652.     local integer cmd
  653.     loop
  654.         exitwhen CommandsWaiting() != 0
  655.         call Sleep(2)
  656.     endloop
  657.  
  658.     set cmd = GetLastCommand()
  659.     call PopLastCommand()
  660.     return cmd
  661. endfunction
  662.  
  663. //============================================================================
  664. function GetMinorCreep takes nothing returns unit
  665.     return GetCreepCamp(0,9,false)
  666. endfunction
  667.  
  668. //============================================================================
  669. function GetMajorCreep takes nothing returns unit
  670.     return GetCreepCamp(10,100,allow_air_creeps)
  671. endfunction
  672.  
  673. //============================================================================
  674. function GetGold takes nothing returns integer
  675.     return GetPlayerState(ai_player,PLAYER_STATE_RESOURCE_GOLD)
  676. endfunction
  677.  
  678. //============================================================================
  679. function GetWood takes nothing returns integer
  680.     return GetPlayerState(ai_player,PLAYER_STATE_RESOURCE_LUMBER)
  681. endfunction
  682.  
  683. //============================================================================
  684. function InitBuildArray takes nothing returns nothing
  685.     set build_length = 0
  686. endfunction
  687.  
  688. //============================================================================
  689. function InitAssaultGroup takes nothing returns nothing
  690.     set harass_length = 0
  691. endfunction
  692.  
  693. //============================================================================
  694. function InitDefenseGroup takes nothing returns nothing
  695.     set defense_length = 0
  696. endfunction
  697.  
  698. //============================================================================
  699. function InitMeleeGroup takes nothing returns nothing
  700.     call InitAssaultGroup()
  701.     call RemoveInjuries()
  702.     call RemoveSiege()
  703. endfunction
  704.  
  705. //============================================================================
  706. function PrepFullSuicide takes nothing returns nothing
  707.     call InitAssaultGroup()
  708.     call InitDefenseGroup()
  709.     set campaign_gold_peons = 0
  710.     set campaign_wood_peons = 0
  711. endfunction
  712.  
  713. //============================================================================
  714. function SetReplacements takes integer easy, integer med, integer hard returns nothing
  715.     if difficulty == EASY then
  716.         call SetReplacementCount(easy)
  717.     elseif difficulty == NORMAL then
  718.         call SetReplacementCount(med)
  719.     else
  720.         call SetReplacementCount(hard)
  721.     endif
  722. endfunction
  723.  
  724. //============================================================================
  725. function StartTownBuilder takes code func returns nothing
  726.     call StartThread(func)
  727. endfunction
  728.  
  729. //============================================================================
  730. function SetBuildAll takes integer t, integer qty, integer unitid, integer town returns nothing
  731.     if qty > 0 then
  732.         set build_qty[build_length] = qty
  733.         set build_type[build_length] = t
  734.         set build_item[build_length] = unitid
  735.         set build_town[build_length] = town
  736.         set build_length = build_length + 1
  737.     endif
  738. endfunction
  739.  
  740. //============================================================================
  741. function SetBuildUnit takes integer qty, integer unitid returns nothing
  742.     call SetBuildAll(BUILD_UNIT,qty,unitid,-1)
  743. endfunction
  744.  
  745. //============================================================================
  746. function SetBuildUnitEx takes integer easy, integer med, integer hard, integer unitid returns nothing
  747.     if difficulty == EASY then
  748.         call SetBuildAll(BUILD_UNIT,easy,unitid,-1)
  749.     elseif difficulty == NORMAL then
  750.         call SetBuildAll(BUILD_UNIT,med,unitid,-1)
  751.     else
  752.         call SetBuildAll(BUILD_UNIT,hard,unitid,-1)
  753.     endif
  754. endfunction
  755.  
  756. //============================================================================
  757. function SecondaryTown takes integer town, integer qty, integer unitid returns nothing
  758.     call SetBuildAll(BUILD_UNIT,qty,unitid,town)
  759. endfunction
  760.  
  761. //============================================================================
  762. function SecTown takes integer town, integer qty, integer unitid returns nothing
  763.     call SetBuildAll(BUILD_UNIT,qty,unitid,town)
  764. endfunction
  765.  
  766. //============================================================================
  767. function SetBuildUpgr takes integer qty, integer unitid returns nothing
  768.     call SetBuildAll(BUILD_UPGRADE,qty,unitid,-1)
  769. endfunction
  770.  
  771. //============================================================================
  772. function SetBuildUpgrEx takes integer easy, integer med, integer hard, integer unitid returns nothing
  773.     if difficulty == EASY then
  774.         call SetBuildAll(BUILD_UPGRADE,easy,unitid,-1)
  775.     elseif difficulty == NORMAL then
  776.         call SetBuildAll(BUILD_UPGRADE,med,unitid,-1)
  777.     else
  778.         call SetBuildAll(BUILD_UPGRADE,hard,unitid,-1)
  779.     endif
  780. endfunction
  781.  
  782. //============================================================================
  783. function SetBuildExpa takes integer qty, integer unitid returns nothing
  784.     call SetBuildAll(BUILD_EXPAND,qty,unitid,-1)
  785. endfunction
  786.  
  787. //============================================================================
  788. function StartUpgrade takes integer level, integer upgid returns boolean
  789.     local integer gold_cost
  790.     local integer wood_cost
  791.  
  792.     if GetUpgradeLevel(upgid) >= level then
  793.         return true
  794.     endif
  795.  
  796.     set gold_cost = GetUpgradeGoldCost(upgid)
  797.     if total_gold < gold_cost then
  798.         return false
  799.     endif
  800.  
  801.     set wood_cost = GetUpgradeWoodCost(upgid)
  802.     if total_wood < wood_cost then
  803.         return false
  804.     endif
  805.  
  806.     return SetUpgrade(upgid)
  807. endfunction
  808.  
  809. //============================================================================
  810. function BuildFactory takes integer unitid returns nothing
  811.     if GetGold() > 1000 and GetWood() > 500 then
  812.         call SetBuildUnit( 2, unitid )
  813.     else
  814.         call SetBuildUnit( 1, unitid )
  815.     endif
  816. endfunction
  817.  
  818. //============================================================================
  819. function HallsCompleted takes integer unitid returns boolean
  820.     return GetUnitCount(unitid) == GetUnitCountDone(unitid)
  821. endfunction
  822.  
  823. //============================================================================
  824. function GuardSecondary takes integer townid, integer qty, integer unitid returns nothing
  825.     if TownHasHall(townid) and TownHasMine(townid) then
  826.         call SecondaryTown( townid, qty, unitid )
  827.     endif
  828. endfunction
  829.  
  830. //============================================================================
  831. function GetUnitCountEx takes integer unitid, boolean only_done, integer townid returns integer
  832.     if townid == -1 then
  833.         if only_done then
  834.             return GetUnitCountDone(unitid)
  835.         else
  836.             return GetUnitCount(unitid)
  837.         endif
  838.     else
  839.         return GetTownUnitCount(unitid,townid,only_done)
  840.     endif
  841. endfunction
  842.  
  843. //============================================================================
  844. function TownCountEx takes integer unitid, boolean only_done, integer townid returns integer
  845.  
  846.     local integer have_qty = GetUnitCountEx(unitid,only_done,townid)
  847.  
  848.     if unitid == TOWN_HALL then
  849.         set have_qty = have_qty + GetUnitCountEx(KEEP,false,townid) + GetUnitCountEx(CASTLE,false,townid)
  850.     elseif unitid == KEEP then
  851.         set have_qty = have_qty  + GetUnitCountEx(CASTLE,false,townid)
  852.  
  853.     elseif unitid == WATCH_TOWER then
  854.         set have_qty = have_qty + GetUnitCountEx(GUARD_TOWER,false,townid) + GetUnitCountEx(CANNON_TOWER,false,townid)
  855.  
  856.     elseif unitid == PEASANT then
  857.         set have_qty = have_qty + GetUnitCountEx(MILITIA,false,townid)
  858.  
  859.     elseif unitid == GREAT_HALL then
  860.         set have_qty = have_qty + GetUnitCountEx(STRONGHOLD,false,townid) + GetUnitCountEx(FORTRESS,false,townid)
  861.     elseif unitid == STRONGHOLD then
  862.         set have_qty = have_qty + GetUnitCountEx(FORTRESS,false,townid)
  863.  
  864.     elseif unitid == NECROPOLIS_1 then
  865.         set have_qty = have_qty + GetUnitCountEx(NECROPOLIS_2,false,townid) + GetUnitCountEx(NECROPOLIS_3,false,townid)
  866.     elseif unitid == NECROPOLIS_2 then
  867.         set have_qty = have_qty + GetUnitCountEx(NECROPOLIS_3,false,townid)
  868.  
  869.     elseif unitid == ZIGGURAT_1 then
  870.         set have_qty = have_qty + GetUnitCountEx(ZIGGURAT_2,false,townid)
  871.  
  872.     elseif unitid == GARGOYLE then
  873.         set have_qty = have_qty + GetUnitCountEx(GARGOYLE_MORPH,false,townid)
  874.  
  875.     elseif unitid == TREE_LIFE then
  876.         set have_qty = have_qty + GetUnitCountEx(TREE_AGES,false,townid) + GetUnitCountEx(TREE_ETERNITY,false,townid)
  877.     elseif unitid == TREE_AGES then
  878.         set have_qty = have_qty + GetUnitCountEx(TREE_ETERNITY,false,townid)
  879.  
  880.     elseif unitid == DRUID_TALON then
  881.         set have_qty = have_qty + GetUnitCountEx(DRUID_TALON_M,false,townid)
  882.     elseif unitid == DRUID_TALON_M then
  883.         set have_qty = have_qty + GetUnitCountEx(DRUID_TALON,only_done,townid)
  884.  
  885.     elseif unitid == DRUID_CLAW then
  886.         set have_qty = have_qty + GetUnitCountEx(DRUID_CLAW_M,false,townid)
  887.     elseif unitid == DRUID_CLAW_M then
  888.         set have_qty = have_qty + GetUnitCountEx(DRUID_CLAW,only_done,townid)
  889.     endif
  890.  
  891.     return have_qty
  892. endfunction
  893.  
  894. //============================================================================
  895. function TownCountDone takes integer base returns integer
  896.     return TownCountEx(base,true,-1)
  897. endfunction
  898.  
  899. //============================================================================
  900. function TownCount takes integer base returns integer
  901.     return TownCountEx(base,false,-1)
  902. endfunction
  903.  
  904. //============================================================================
  905. function BasicExpansion takes boolean build_it, integer unitid returns nothing
  906.     if build_it and GetGold() < 2000 and HallsCompleted(unitid) then
  907.         call SetBuildExpa( TownCount(unitid)+1, unitid )
  908.     endif
  909. endfunction
  910.  
  911. //============================================================================
  912. function UpgradeAll takes integer baseid, integer newid returns nothing
  913.     call SetBuildUnit( TownCountDone(baseid), newid )
  914. endfunction
  915.  
  916. //============================================================================
  917. function TownCountTown takes integer base, integer townid returns integer
  918.     return TownCountEx(base,false,townid)
  919. endfunction
  920.  
  921. //============================================================================
  922. //  FoodPool
  923. //============================================================================
  924. function FoodPool takes integer food, boolean weak, integer id1, integer use1, boolean strong, integer id2, integer use2 returns nothing
  925.     if strong then
  926.         call SetBuildUnit( (food - use1 * TownCount(id1)) / use2, id2 )
  927.     elseif weak then
  928.         call SetBuildUnit( (food - use2 * TownCount(id2)) / use1, id1 )
  929.     endif
  930. endfunction
  931.  
  932. //============================================================================
  933. //  MeleeTownHall
  934. //============================================================================
  935. function MeleeTownHall takes integer townid, integer unitid returns nothing
  936.     if TownHasMine(townid) and not TownHasHall(townid) then
  937.         call SecondaryTown ( townid, 1, unitid )
  938.     endif
  939. endfunction
  940.  
  941. //============================================================================
  942. function WaitForUnits takes integer unitid, integer qty returns nothing
  943.     loop
  944.         exitwhen TownCountDone(unitid) == qty
  945.         call Sleep(2)
  946.     endloop
  947. endfunction
  948.  
  949. //============================================================================
  950. function StartUnit takes integer ask_qty, integer unitid, integer town returns boolean
  951.     local integer have_qty
  952.     local integer need_qty
  953.     local integer afford_gold
  954.     local integer afford_wood
  955.     local integer afford_qty
  956.     local integer gold_cost
  957.     local integer wood_cost
  958.  
  959.     //------------------------------------------------------------------------
  960.     // if we have all we're asking for then make nothing
  961.     //
  962.     if town == -1 then
  963.         set have_qty = TownCount(unitid)
  964.     else
  965.         set have_qty = TownCountTown(unitid,town)
  966.     endif
  967.  
  968.     if have_qty >= ask_qty then
  969.         return true
  970.     endif
  971.     set need_qty = ask_qty - have_qty
  972.  
  973.     //------------------------------------------------------------------------
  974.     // limit the qty we're requesting to the amount of resources available
  975.     //
  976.     set gold_cost = GetUnitGoldCost(unitid)
  977.     set wood_cost = GetUnitWoodCost(unitid)
  978.  
  979.     if gold_cost == 0 then
  980.         set afford_gold = need_qty
  981.     else
  982.         set afford_gold = total_gold / gold_cost
  983.     endif
  984.     if afford_gold < need_qty then
  985.         set afford_qty = afford_gold
  986.     else
  987.         set afford_qty = need_qty
  988.     endif
  989.  
  990.     if wood_cost == 0 then
  991.         set afford_wood = need_qty
  992.     else
  993.         set afford_wood = total_wood / wood_cost
  994.     endif
  995.     if afford_wood < afford_qty then
  996.         set afford_qty = afford_wood
  997.     endif
  998.  
  999.     // if we're waiting on gold/wood; pause build orders
  1000.     if afford_qty < 1 then
  1001.         return false
  1002.     endif
  1003.  
  1004.     //------------------------------------------------------------------------
  1005.     // whether we make right now what we're requesting or not, assume we will
  1006.     // and deduct the cost of the units from our fake gold total right away
  1007.     //
  1008.     set total_gold = total_gold - gold_cost * need_qty
  1009.     set total_wood = total_wood - wood_cost * need_qty
  1010.  
  1011.     if total_gold < 0 then
  1012.         set total_gold = 0
  1013.     endif
  1014.     if total_wood < 0 then
  1015.         set total_wood = 0
  1016.     endif
  1017.  
  1018.     //------------------------------------------------------------------------
  1019.     // give the AI a chance to make the units (it may not be able to right now
  1020.     // but that doesn't stop us from trying other units after this as long
  1021.     // as we have enough money to make this AND the needed, unbuilt ones)
  1022.     //
  1023.     return SetProduce(afford_qty,unitid,town)
  1024. endfunction
  1025.  
  1026. //============================================================================
  1027. function WaitForTown takes integer towns, integer townid returns nothing
  1028.     local integer i = 0
  1029.     loop
  1030.         call Sleep(10)
  1031.         exitwhen TownCount(townid) >= towns
  1032.         set i = i + 1
  1033.         exitwhen i == 12
  1034.     endloop
  1035. endfunction
  1036.  
  1037. //============================================================================
  1038. function StartExpansion takes integer qty, integer hall returns boolean
  1039.     local integer count
  1040.     local integer town
  1041.     local unit    peon
  1042.     local integer gold_cost
  1043.  
  1044.     set count = TownCount(hall)
  1045.     if count >= qty then
  1046.         return true
  1047.     endif
  1048.  
  1049.     set town = GetNextExpansion()
  1050.     if town == -1 then
  1051.         return true
  1052.     endif
  1053.  
  1054.     set take_exp = true
  1055.  
  1056.     set gold_cost = GetUnitGoldCost(hall)
  1057.     if gold_cost > total_gold then
  1058.         return false
  1059.     endif
  1060.     set total_gold = total_gold - gold_cost
  1061.  
  1062.     if GetExpansionFoe() != null then
  1063.         return true
  1064.     endif
  1065.  
  1066.     set peon = GetExpansionPeon()
  1067.     if peon != null then
  1068.         return SetExpansion(peon,hall)
  1069.     endif
  1070.  
  1071.     return true
  1072. endfunction
  1073.  
  1074. //============================================================================
  1075. function OneBuildLoop takes nothing returns nothing
  1076.     local integer index = 0
  1077.     local integer qty
  1078.     local integer id
  1079.     local integer tp
  1080.  
  1081.     set total_gold   = GetGold() - gold_buffer
  1082.     set total_wood   = GetWood()
  1083.  
  1084.     loop
  1085.         exitwhen index == build_length
  1086.  
  1087.         set qty  = build_qty[index]
  1088.         set id   = build_item[index]
  1089.         set tp   = build_type[index]
  1090.  
  1091.         //--------------------------------------------------------------------
  1092.         if tp == BUILD_UNIT then
  1093.             if not StartUnit(qty,id,build_town[index]) then
  1094.                 return
  1095.             endif
  1096.  
  1097.         //--------------------------------------------------------------------
  1098.         elseif tp == BUILD_UPGRADE then
  1099.             call StartUpgrade(qty,id)
  1100.  
  1101.         //--------------------------------------------------------------------
  1102.         else // tp == BUILD_EXPAND
  1103.             if not StartExpansion(qty,id) then
  1104.                 return
  1105.             endif
  1106.         endif
  1107.  
  1108.         set index = index + 1
  1109.     endloop
  1110. endfunction
  1111.  
  1112. //============================================================================
  1113. function StaggerSleep takes real base, real spread returns nothing
  1114.     call Sleep(base + spread * I2R(GetAiPlayer()) / I2R(GetPlayers()))
  1115. endfunction
  1116.  
  1117. //============================================================================
  1118. function BuildLoop takes nothing returns nothing
  1119.     call OneBuildLoop()
  1120.     call StaggerSleep(1,2)
  1121.     loop
  1122.         call OneBuildLoop()
  1123.         call Sleep(2)
  1124.     endloop
  1125. endfunction
  1126.  
  1127. //============================================================================
  1128. function StartBuildLoop takes nothing returns nothing
  1129.     call StartThread(function BuildLoop)
  1130. endfunction
  1131.  
  1132. //============================================================================
  1133. function SetInitialWave takes integer seconds returns nothing
  1134.     set sleep_seconds = seconds
  1135. endfunction
  1136.  
  1137. //============================================================================
  1138. function AddSleepSeconds takes integer seconds returns nothing
  1139.     set sleep_seconds = sleep_seconds + seconds
  1140. endfunction
  1141.  
  1142. //============================================================================
  1143. function SleepForever takes nothing returns nothing
  1144.     loop
  1145.         call Sleep(100)
  1146.     endloop
  1147. endfunction
  1148.  
  1149. //============================================================================
  1150. function PlayGame takes nothing returns nothing
  1151.     call StartBuildLoop()
  1152.     call SleepForever()
  1153. endfunction
  1154.  
  1155. //============================================================================
  1156. function Conversions takes integer desire, integer unitid returns nothing
  1157.     if unitid == HIPPO_RIDER then
  1158.         call MergeUnits(desire,ARCHER,HIPPO,HIPPO_RIDER)
  1159.     endif
  1160. endfunction
  1161.  
  1162. //============================================================================
  1163. function SetAssaultGroup takes integer qty, integer max, integer unitid returns nothing
  1164.     call Conversions(max,unitid)
  1165.  
  1166.     if qty <= 0 and TownCountDone(unitid) == 0 then
  1167.         return
  1168.     endif
  1169.     set harass_qty[harass_length] = qty
  1170.     set harass_max[harass_length] = max
  1171.     set harass_units[harass_length] = unitid
  1172.     set harass_length = harass_length + 1
  1173. endfunction
  1174.  
  1175. //============================================================================
  1176. function Interleave3 takes integer e1, integer m1, integer h1, integer u1, integer e2, integer m2, integer h2, integer u2, integer e3, integer m3, integer h3, integer u3 returns nothing
  1177.     local integer i1 = 1
  1178.     local integer i2 = 1
  1179.     local integer i3 = 1
  1180.     local integer q1
  1181.     local integer q2
  1182.     local integer q3
  1183.  
  1184.     if difficulty == EASY then
  1185.         set q1 = e1
  1186.         set q2 = e2
  1187.         set q3 = e3
  1188.     elseif difficulty == NORMAL then
  1189.         set q1 = m1
  1190.         set q2 = m2
  1191.         set q3 = m3
  1192.     else // difficulty == HARD
  1193.         set q1 = h1
  1194.         set q2 = h2
  1195.         set q3 = h3
  1196.     endif
  1197.  
  1198.     loop
  1199.         exitwhen q1<=0 and q2<=0 and q3<=0
  1200.  
  1201.         if q1 > 0 then
  1202.             call SetAssaultGroup(i1,i1,u1)
  1203.             set q1 = q1 - 1
  1204.             set i1 = i1 + 1
  1205.         endif
  1206.  
  1207.         if q2 > 0 then
  1208.             call SetAssaultGroup(i2,i2,u2)
  1209.             set q2 = q2 - 1
  1210.             set i2 = i2 + 1
  1211.         endif
  1212.  
  1213.         if q3 > 0 then
  1214.             call SetAssaultGroup(i3,i3,u3)
  1215.             set q3 = q3 - 1
  1216.             set i3 = i3 + 1
  1217.         endif
  1218.     endloop
  1219. endfunction
  1220.  
  1221. //============================================================================
  1222. function SetMeleeGroup takes integer unitid returns nothing
  1223.     if unitid == hero_id then
  1224.         call SetAssaultGroup(1,9,unitid)
  1225.     else
  1226.         call SetAssaultGroup((TownCountDone(unitid)*3)/4,12,unitid)
  1227.     endif
  1228. endfunction
  1229.  
  1230. //============================================================================
  1231. function CampaignDefender takes integer level, integer qty, integer unitid returns nothing
  1232.     if qty > 0 and difficulty >= level then
  1233.         set defense_qty[defense_length] = qty
  1234.         set defense_units[defense_length] = unitid
  1235.         set defense_length = defense_length + 1
  1236.         call Conversions(qty,unitid)
  1237.         call SetBuildUnit(qty,unitid)
  1238.     endif
  1239. endfunction
  1240.  
  1241. //============================================================================
  1242. function CampaignDefenderEx takes integer easy, integer med, integer hard, integer unitid returns nothing
  1243.     if difficulty == EASY then
  1244.         call CampaignDefender(EASY,easy,unitid)
  1245.     elseif difficulty == NORMAL then
  1246.         call CampaignDefender(NORMAL,med,unitid)
  1247.     else
  1248.         call CampaignDefender(HARD,hard,unitid)
  1249.     endif
  1250. endfunction
  1251.  
  1252. //============================================================================
  1253. function CampaignAttacker takes integer level, integer qty, integer unitid returns nothing
  1254.     if qty > 0 and difficulty >= level then
  1255.         call SetAssaultGroup(qty,qty,unitid)
  1256.     endif
  1257. endfunction
  1258.  
  1259. //============================================================================
  1260. function CampaignAttackerEx takes integer easy, integer med, integer hard, integer unitid returns nothing
  1261.     if difficulty == EASY then
  1262.         call CampaignAttacker(EASY,easy,unitid)
  1263.     elseif difficulty == NORMAL then
  1264.         call CampaignAttacker(NORMAL,med,unitid)
  1265.     else
  1266.         call CampaignAttacker(HARD,hard,unitid)
  1267.     endif
  1268. endfunction
  1269.  
  1270. //============================================================================
  1271. function FormGroup takes integer seconds, boolean testReady returns nothing
  1272.     local integer index
  1273.     local integer count
  1274.     local integer unitid
  1275.     local integer desire
  1276.     local integer readyPercent
  1277.  
  1278.     // normally test for CaptainReadiness() of 50%
  1279.     if testReady == true then
  1280.         set readyPercent = 50
  1281.     else
  1282.         set readyPercent = 0
  1283.     endif
  1284.  
  1285.     loop
  1286.         call SuicideSleep(seconds)
  1287.         call InitAssault()
  1288.  
  1289.         set index = 0
  1290.         loop
  1291.             exitwhen index == harass_length
  1292.  
  1293.             set unitid = harass_units[index]
  1294.             set desire = harass_max[index]
  1295.             set count  = TownCountDone(unitid)
  1296.  
  1297.             call Conversions(desire,unitid)
  1298.  
  1299.             if count >= desire then
  1300.                 call AddAssault(desire,unitid)
  1301.             else
  1302.                 set desire = harass_qty[index]
  1303.  
  1304.                 if count < desire then
  1305.                     call AddAssault(desire,unitid)
  1306.                 else
  1307.                     call AddAssault(count,unitid)
  1308.                 endif
  1309.             endif
  1310.  
  1311.             set index = index + 1
  1312.         endloop
  1313.  
  1314.         // time out and send group anyway if time has already expired
  1315.         exitwhen sleep_seconds < -60
  1316.         exitwhen CaptainInCombat(true)
  1317.         exitwhen CaptainIsFull() and CaptainReadiness() >= readyPercent
  1318.     endloop
  1319. endfunction
  1320.  
  1321. //============================================================================
  1322. function WavePrepare takes integer unitid returns integer
  1323.     if unitid=='ebal' or unitid=='hgry' or unitid=='hkni' or unitid=='ocat' or unitid=='uabo' or unitid=='umtw' or unitid=='otau' or unitid=='nfel' then
  1324.         return 50
  1325.     endif
  1326.     if unitid=='hmtt' or unitid=='echm' or unitid=='ufro' or unitid=='etrp' or unitid=='ninf' then
  1327.         return 80
  1328.     endif
  1329.     return 40
  1330. endfunction
  1331.  
  1332. //============================================================================
  1333. function PrepTime takes nothing returns integer
  1334.     local integer unitid
  1335.     local integer missing
  1336.     local integer prep
  1337.     local integer count
  1338.     local integer largest = 30
  1339.     local integer index = 0
  1340.  
  1341.     loop
  1342.         exitwhen index == harass_length
  1343.  
  1344.         set unitid  = harass_units[index]
  1345.         set missing = harass_qty[index] + IgnoredUnits(unitid) - TownCount(unitid)
  1346.         set prep    = WavePrepare(unitid) * missing
  1347.  
  1348.         if prep > largest then
  1349.             set largest = prep
  1350.         endif
  1351.  
  1352.         set index = index + 1
  1353.     endloop
  1354.  
  1355.     return largest
  1356. endfunction
  1357.  
  1358. //============================================================================
  1359. function SuicideOnPlayer takes integer seconds, player p returns nothing
  1360.     local integer wave_prep = PrepTime()
  1361.     local integer save_peons
  1362.     local integer save_length
  1363.  
  1364.     set save_length = harass_length
  1365.     set harass_length = 0
  1366.  
  1367.     call AddSleepSeconds(seconds)
  1368.     if sleep_seconds-wave_prep > 0 then
  1369.         call SuicideSleep(sleep_seconds-wave_prep)
  1370.     endif
  1371.  
  1372.     set harass_length = save_length
  1373.  
  1374.     if harass_length < 1 then
  1375.         return
  1376.     endif
  1377.  
  1378.     set save_peons = campaign_wood_peons
  1379.     set campaign_wood_peons = 0
  1380.     loop
  1381.         exitwhen allow_signal_abort and CommandsWaiting() != 0
  1382.  
  1383.         loop
  1384.             exitwhen allow_signal_abort and CommandsWaiting() != 0
  1385.  
  1386.             call FormGroup(5, true)
  1387.             exitwhen sleep_seconds <= 0
  1388.         endloop
  1389.  
  1390.         exitwhen SuicidePlayer(p,sleep_seconds >= -60)
  1391.         call SuicideSleep(5)
  1392.     endloop
  1393.  
  1394.     set campaign_wood_peons = save_peons
  1395.     set harass_length = 0
  1396.  
  1397.     loop
  1398.         exitwhen allow_signal_abort and CommandsWaiting() != 0
  1399.  
  1400.         exitwhen CaptainInCombat(true)
  1401.         exitwhen CaptainIsEmpty()
  1402.         call SuicideSleep(10)
  1403.         exitwhen sleep_seconds < -300
  1404.     endloop
  1405.  
  1406.     loop
  1407.         exitwhen allow_signal_abort and CommandsWaiting() != 0
  1408.  
  1409.         exitwhen CaptainIsEmpty()
  1410.         call SuicideSleep(10)
  1411.         exitwhen sleep_seconds < -300
  1412.     endloop
  1413. endfunction
  1414.  
  1415. //============================================================================
  1416. function SuicideUntilSignal takes integer seconds, player p returns nothing
  1417.     local integer save
  1418.     local integer wave_prep = PrepTime()
  1419.  
  1420.     loop
  1421.         call AddSleepSeconds(seconds)
  1422.         if sleep_seconds-wave_prep > 0 then
  1423.             call SuicideSleep(sleep_seconds-wave_prep)
  1424.         endif
  1425.  
  1426.         set save = campaign_wood_peons
  1427.         set campaign_wood_peons = 0
  1428.         loop
  1429.             loop
  1430.                 call FormGroup(5, true)
  1431.                 exitwhen sleep_seconds <= 0
  1432.                 exitwhen CommandsWaiting() != 0
  1433.             endloop
  1434.             exitwhen SuicidePlayer(p,sleep_seconds >= -60)
  1435.             exitwhen CommandsWaiting() != 0
  1436.             call SuicideSleep(3)
  1437.         endloop
  1438.         set campaign_wood_peons = save
  1439.  
  1440.         loop
  1441.             exitwhen CaptainIsEmpty()
  1442.             exitwhen CommandsWaiting() != 0
  1443.             call SuicideSleep(5)
  1444.         endloop
  1445.         exitwhen CommandsWaiting() != 0
  1446.     endloop
  1447. endfunction
  1448.  
  1449. //============================================================================
  1450. function SuicideUnitA takes integer unitid returns nothing
  1451.     if unitid != 0 then
  1452.         call SuicideUnit(1,unitid)
  1453.     endif
  1454.     call Sleep(0.1)
  1455. endfunction
  1456.  
  1457. //============================================================================
  1458. function SuicideUnits takes integer u1, integer u2, integer u3, integer u4, integer u5, integer u6, integer u7, integer u8, integer u9, integer uA returns nothing
  1459.     call PrepFullSuicide()
  1460.     loop
  1461.         call SuicideUnitA(u1)
  1462.         call SuicideUnitA(u2)
  1463.         call SuicideUnitA(u3)
  1464.         call SuicideUnitA(u4)
  1465.         call SuicideUnitA(u5)
  1466.         call SuicideUnitA(u6)
  1467.         call SuicideUnitA(u7)
  1468.         call SuicideUnitA(u8)
  1469.         call SuicideUnitA(u9)
  1470.         call SuicideUnitA(uA)
  1471.     endloop
  1472. endfunction
  1473.  
  1474. //============================================================================
  1475. function SuicideOnPlayerEx takes integer easy, integer med, integer hard, player p returns nothing
  1476.     if difficulty == EASY then
  1477.         call SuicideOnPlayer(easy,p)
  1478.     elseif difficulty == NORMAL then
  1479.         call SuicideOnPlayer(med,p)
  1480.     else
  1481.         call SuicideOnPlayer(hard,p)
  1482.     endif
  1483. endfunction
  1484.  
  1485. //============================================================================
  1486. function ForeverSuicideOnPlayer takes integer seconds, player p returns nothing
  1487.     local integer length = harass_length
  1488.     loop
  1489.         exitwhen allow_signal_abort and CommandsWaiting() != 0
  1490.         call SuicideOnPlayer(seconds,p)
  1491.         set harass_length = length
  1492.     endloop
  1493. endfunction
  1494.  
  1495. //============================================================================
  1496. function SleepInCombat takes nothing returns nothing
  1497.     local integer count = 0
  1498.     loop
  1499.         loop
  1500.             exitwhen not CaptainInCombat(true)  // goal is cleared
  1501.             call SuicideSleep(1)
  1502.         endloop
  1503.  
  1504.         set count = count + 1
  1505.         exitwhen count >= 8
  1506.     endloop
  1507. endfunction
  1508.  
  1509. //============================================================================
  1510. function CommonSleepUntilTargetDead takes unit target, boolean reform returns nothing
  1511.     loop
  1512.         exitwhen CaptainRetreating()
  1513.         exitwhen CaptainReadinessHP() <= 40
  1514.  
  1515.         exitwhen not UnitAlive(target)  // target killed
  1516.         call AttackMoveKill(target)
  1517.  
  1518.         call SuicideSleep(3)
  1519.  
  1520.         if reform and sleep_seconds < -40 then
  1521.             if CaptainInCombat(true) then
  1522.                 set sleep_seconds = sleep_seconds + 5
  1523.             else
  1524.                 set sleep_seconds = 0
  1525.                 call FormGroup(1,false)
  1526.             endif
  1527.         endif
  1528.     endloop
  1529. endfunction
  1530.  
  1531. //============================================================================
  1532. function SleepUntilTargetDead takes unit target returns nothing
  1533.     call CommonSleepUntilTargetDead(target,false)
  1534. endfunction
  1535.  
  1536. //============================================================================
  1537. function ReformUntilTargetDead takes unit target returns nothing
  1538.     call CommonSleepUntilTargetDead(target,true)
  1539. endfunction
  1540.  
  1541. //============================================================================
  1542. function SleepUntilAtGoal takes nothing returns nothing
  1543.     loop
  1544.         exitwhen CaptainRetreating()
  1545.         exitwhen CaptainAtGoal()        // reached goal
  1546.         exitwhen CaptainIsHome()        // failed to path and returned home
  1547.         exitwhen CaptainIsEmpty()       // all units died
  1548.         call SuicideSleep(3)
  1549.     endloop
  1550. endfunction
  1551.  
  1552. //============================================================================
  1553. function AttackMoveKillA takes unit target returns nothing
  1554.     if target == null then
  1555.         call SuicideSleep(3)
  1556.         return
  1557.     endif
  1558.  
  1559.     call AttackMoveKill(target)
  1560.     call ReformUntilTargetDead(target)
  1561.     call SleepInCombat()
  1562. endfunction
  1563.  
  1564. //============================================================================
  1565. function AttackMoveXYA takes integer x, integer y returns nothing
  1566.     call AttackMoveXY(x,y)
  1567.     call SleepUntilAtGoal()
  1568.     call SleepInCombat()
  1569. endfunction
  1570.  
  1571. //============================================================================
  1572. function MinorCreepAttack takes nothing returns nothing
  1573.     local unit target = GetMinorCreep()
  1574.     call SetAllianceTarget(target)
  1575.     call FormGroup(3, true)
  1576.     call AttackMoveKillA(target)
  1577. endfunction
  1578.  
  1579. //============================================================================
  1580. function MajorCreepAttack takes nothing returns nothing
  1581.     local unit target = GetMajorCreep()
  1582.     call SetAllianceTarget(target)
  1583.     call FormGroup(3,true)
  1584.     call AttackMoveKillA(target)
  1585. endfunction
  1586.  
  1587. //============================================================================
  1588. function AnyPlayerAttack takes nothing returns nothing
  1589.     local unit hall
  1590.  
  1591.     set hall = GetEnemyExpansion()
  1592.     if hall == null then
  1593.         call StartGetEnemyBase()
  1594.         loop
  1595.             exitwhen not WaitGetEnemyBase()
  1596.             call SuicideSleep(1)
  1597.         endloop
  1598.         set hall = GetEnemyBase()
  1599.     endif
  1600.  
  1601.     call SetAllianceTarget(hall)
  1602.     call FormGroup(3,true)
  1603.     call AttackMoveKillA(hall)
  1604. endfunction
  1605.  
  1606. //============================================================================
  1607. function ExpansionAttack takes nothing returns nothing
  1608.     local unit creep = GetExpansionFoe()
  1609.     local integer x
  1610.  
  1611.     call FormGroup(3, true)
  1612.     if creep == null then
  1613.         set x = GetExpansionX()
  1614.         if x != -1 then
  1615.             call AttackMoveXYA(x,GetExpansionY())
  1616.         endif
  1617.     else
  1618.         call AttackMoveKillA(creep)
  1619.     endif
  1620. endfunction
  1621.  
  1622. //============================================================================
  1623. //  AddSiege
  1624. //============================================================================
  1625. function AddSiege takes nothing returns nothing
  1626.     call SetAssaultGroup( 0, 9, SHADE       )
  1627.     call SetAssaultGroup( 0, 9, MEAT_WAGON  )
  1628.     call SetAssaultGroup( 0, 9, MORTAR      )
  1629.     call SetAssaultGroup( 0, 9, TANK        )
  1630.     call SetAssaultGroup( 0, 9, BALLISTA    )
  1631.     call SetAssaultGroup( 0, 9, CATAPULT    )
  1632. endfunction
  1633.  
  1634. //============================================================================
  1635. //  SingleMeleeAttack
  1636. //============================================================================
  1637. function SingleMeleeAttack takes boolean needs_exp, boolean has_siege, boolean major_ok, boolean air_units returns nothing
  1638.     local boolean can_siege
  1639.     local real daytime
  1640.     local unit hall
  1641.     local unit mega
  1642.     local unit creep
  1643.     local unit common
  1644.  
  1645.     if TownThreated() then
  1646.         call Sleep(2)
  1647.         return
  1648.     endif
  1649.  
  1650.     // purchase zeppelins
  1651.     //
  1652.     if get_zeppelin and GetGold() > 300 and GetWood() > 100 then
  1653.         call PurchaseZeppelin()
  1654.         set get_zeppelin = false
  1655.         set ready_for_zeppelin = false
  1656.         return
  1657.     endif
  1658.     set ready_for_zeppelin = true
  1659.  
  1660.     // coordinate with allies
  1661.     //
  1662.     set common = GetAllianceTarget()
  1663.     if common != null then
  1664.         if GetMegaTarget() != null then
  1665.             call AddSiege()
  1666.         endif
  1667.         call FormGroup(3,true)
  1668.         call AttackMoveKillA(common)
  1669.         call SetAllianceTarget(null)
  1670.         return
  1671.     endif
  1672.  
  1673.     // take expansions as needed
  1674.     //
  1675.     if needs_exp then
  1676.         set creep = GetExpansionFoe()
  1677.         if creep != null then
  1678.             call SetAllianceTarget(creep)
  1679.             call FormGroup(3,true)
  1680.             call AttackMoveKillA(creep)
  1681.             call Sleep(20)
  1682.             set take_exp = false
  1683.             return
  1684.         endif
  1685.     endif
  1686.  
  1687.     // all-out attack if the player is down
  1688.     //
  1689.     set mega = GetMegaTarget()
  1690.     if mega != null then
  1691.         call AddSiege()
  1692.         call FormGroup(3,true)
  1693.         call AttackMoveKillA(mega)
  1694.         return
  1695.     endif
  1696.  
  1697.     // deny player an expansion
  1698.     //
  1699.     set hall = GetEnemyExpansion()
  1700.     set daytime = GetFloatGameState(GAME_STATE_TIME_OF_DAY)
  1701.     set can_siege = has_siege and (air_units or (daytime>=4 and daytime<=12))
  1702.  
  1703.     if hall!=null and (can_siege or not IsTowered(hall)) then
  1704.         call AddSiege()
  1705.         call SetAllianceTarget(hall)
  1706.         call FormGroup(3,true)
  1707.         call AttackMoveKillA(hall)
  1708.         return
  1709.     endif
  1710.  
  1711.     // attack player's main base when siege is available
  1712.     //
  1713.     if can_siege then
  1714.         call AddSiege()
  1715.         call AnyPlayerAttack()
  1716.         return
  1717.     endif
  1718.  
  1719.     // nothing better to do, so kill a creep camp
  1720.     //
  1721.     if major_ok then
  1722.         call MajorCreepAttack()
  1723.         return
  1724.     endif
  1725.  
  1726.     call MinorCreepAttack()
  1727. endfunction
  1728.  
  1729. //============================================================================
  1730. function GetZeppelin takes nothing returns nothing
  1731.     if ready_for_zeppelin then
  1732.         set get_zeppelin = true
  1733.     endif
  1734. endfunction
  1735.  
  1736. //============================================================================
  1737. function FoodUsed takes nothing returns integer
  1738.     return GetPlayerState(ai_player,PLAYER_STATE_RESOURCE_FOOD_USED)
  1739. endfunction
  1740.  
  1741. //============================================================================
  1742. function FoodAvail takes integer base returns integer
  1743.     return GetFoodMade(racial_farm) * TownCount(racial_farm) + GetFoodMade(base) * TownCount(base)
  1744. endfunction
  1745.  
  1746. //============================================================================
  1747. function BuildAttackers takes nothing returns nothing
  1748.     local integer index = 0
  1749.     local integer unitid
  1750.     local integer desire
  1751.     local integer count
  1752.  
  1753.     loop
  1754.         exitwhen index == harass_length
  1755.  
  1756.         set unitid = harass_units[index]
  1757.         set desire = harass_qty[index] + IgnoredUnits(unitid)
  1758.         set count  = TownCount(unitid)
  1759.  
  1760.         if count != desire then
  1761.             if not StartUnit(desire,unitid,-1) then
  1762.                 return
  1763.             endif
  1764.         endif
  1765.  
  1766.         set index = index + 1
  1767.     endloop
  1768. endfunction
  1769.  
  1770. //============================================================================
  1771. function BuildDefenders takes nothing returns nothing
  1772.     local integer index = 0
  1773.     local integer unitid
  1774.     local integer qty
  1775.     loop
  1776.         exitwhen index == defense_length
  1777.  
  1778.         set unitid = defense_units[index]
  1779.         set qty = defense_qty[index]
  1780.  
  1781.         call Conversions(qty,unitid)
  1782.         call AddDefenders(qty,unitid)
  1783.  
  1784.         set index = index + 1
  1785.     endloop
  1786. endfunction
  1787.  
  1788. //============================================================================
  1789. function CampaignBasicsA takes nothing returns nothing
  1790.     local integer food_each = GetFoodMade(racial_farm)
  1791.     local integer on_wood
  1792.  
  1793.     call ClearHarvestAI()
  1794.  
  1795.     if CaptainInCombat(false) then
  1796.         set on_wood = 0
  1797.     else
  1798.         set on_wood = campaign_wood_peons
  1799.     endif
  1800.  
  1801.     call HarvestGold(0,campaign_gold_peons)
  1802.     call HarvestWood(0,on_wood)
  1803.  
  1804.     if harvest_town1 then
  1805.         call HarvestGold(1,campaign_gold_peons)
  1806.         call HarvestWood(1,on_wood)
  1807.     endif
  1808.  
  1809.     if harvest_town2 then
  1810.         call HarvestGold(2,campaign_gold_peons)
  1811.         call HarvestWood(2,on_wood)
  1812.     endif
  1813.  
  1814.     if harvest_town3 then
  1815.         call HarvestGold(3,campaign_gold_peons)
  1816.         call HarvestWood(3,on_wood)
  1817.     endif
  1818.  
  1819.     if do_campaign_farms and FoodUsed()+food_each-1 > food_each*(TownCount(racial_farm)+1) then
  1820.         call StartUnit(TownCount(racial_farm)+1,racial_farm,-1)
  1821.     endif
  1822.  
  1823.     if build_campaign_attackers then
  1824.         call BuildAttackers()
  1825.     endif
  1826.  
  1827.     if not CaptainInCombat(false) then
  1828.         call BuildDefenders()
  1829.     endif
  1830.  
  1831.     call FillGuardPosts()
  1832.     call ReturnGuardPosts()
  1833. endfunction
  1834.  
  1835. //============================================================================
  1836. function CampaignBasics takes nothing returns nothing
  1837.     call Sleep(1)
  1838.     call CampaignBasicsA()
  1839.     call StaggerSleep(1,5)
  1840.     loop
  1841.         call CampaignBasicsA()
  1842.         call Sleep(campaign_basics_speed)
  1843.     endloop
  1844. endfunction
  1845.  
  1846. //============================================================================
  1847. function CampaignAI takes integer farms, code heroes returns nothing
  1848.     if GetGameDifficulty() == MAP_DIFFICULTY_EASY then
  1849.         set difficulty = EASY
  1850.  
  1851.         call SetTargetHeroes(false)
  1852.         call SetUnitsFlee(false)
  1853.  
  1854.     elseif GetGameDifficulty() == MAP_DIFFICULTY_NORMAL then
  1855.         set difficulty = NORMAL
  1856.  
  1857.         call SetTargetHeroes(false)
  1858.         call SetUnitsFlee(false)
  1859.  
  1860.     elseif GetGameDifficulty() == MAP_DIFFICULTY_HARD then
  1861.         set difficulty = HARD
  1862.  
  1863.         call SetPeonsRepair(true)
  1864.     else
  1865.         set difficulty = INSANE
  1866.     endif
  1867.  
  1868.     call InitAI()
  1869.     call InitBuildArray()
  1870.     call InitAssaultGroup()
  1871.     call CreateCaptains()
  1872.  
  1873.     call SetNewHeroes(false)
  1874.     if heroes != null then
  1875.         call SetHeroLevels(heroes)
  1876.     endif
  1877.  
  1878.     call SetHeroesFlee(false)
  1879.     call SetGroupsFlee(false)
  1880.     call SetSlowChopping(true)
  1881.     call GroupTimedLife(false)
  1882.     call SetCampaignAI()
  1883.     call Sleep(0.1)
  1884.  
  1885.     set racial_farm = farms
  1886.     call StartThread(function CampaignBasics)
  1887.     call StartBuildLoop()
  1888. endfunction
  1889.  
  1890. //============================================================================
  1891. function UnsummonAll takes nothing returns nothing
  1892.     local unit bldg
  1893.     loop
  1894.         set bldg = GetBuilding(ai_player)
  1895.         exitwhen bldg==null
  1896.         call Unsummon(bldg)
  1897.         call Sleep(2)
  1898.     endloop
  1899. endfunction
  1900.  
  1901. //============================================================================
  1902. //  SkillArrays
  1903. //============================================================================
  1904. function SkillArrays takes nothing returns integer
  1905.     local integer level = GetHeroLevelAI()
  1906.  
  1907.     if level > max_hero_level then
  1908.         set max_hero_level = level
  1909.     endif
  1910.  
  1911.     if GetHeroId() == hero_id then
  1912.         return skills1[level]
  1913.     else
  1914.         return skills2[level]
  1915.     endif
  1916. endfunction
  1917.  
  1918. //============================================================================
  1919. //  AwaitMeleeHeroes
  1920. //============================================================================
  1921. function AwaitMeleeHeroes takes nothing returns nothing
  1922.     if GetUnitCountDone(hero_id2) > 0 then
  1923.         set two_heroes = true
  1924.     endif
  1925.     loop
  1926.         exitwhen GetUnitCountDone(hero_id)>0 and (take_exp or (not two_heroes or GetUnitCountDone(hero_id2)>0))
  1927.         call Sleep(1)
  1928.     endloop
  1929. endfunction
  1930.  
  1931. //============================================================================
  1932. //  PickMeleeHero
  1933. //============================================================================
  1934. function PickMeleeHero takes race raceid returns integer
  1935.     local integer hero_roll = GetRandomInt(1,10)
  1936.  
  1937.     //------------------------------------------------------------------------
  1938.     if raceid == RACE_HUMAN then
  1939.     //------------------------------------------------------------------------
  1940.         if hero_roll == 1 then
  1941.             set hero_id  = MTN_KING
  1942.             set hero_id2 = ARCHMAGE
  1943.  
  1944.         elseif hero_roll <= 4 then
  1945.             set hero_id  = MTN_KING
  1946.             set hero_id2 = PALADIN
  1947.  
  1948.         elseif hero_roll <= 7 then
  1949.             set hero_id  = ARCHMAGE
  1950.             set hero_id2 = PALADIN
  1951.         else
  1952.             set hero_id  = PALADIN
  1953.             set hero_id2 = ARCHMAGE
  1954.         endif
  1955.  
  1956.     //------------------------------------------------------------------------
  1957.     elseif raceid == RACE_ORC then
  1958.     //------------------------------------------------------------------------
  1959.         if hero_roll == 1 then
  1960.             set hero_id  = BLADE_MASTER
  1961.             set hero_id2 = TAUREN_CHIEF
  1962.  
  1963.         elseif hero_roll <= 4 then
  1964.             set hero_id  = BLADE_MASTER
  1965.             set hero_id2 = FAR_SEER
  1966.  
  1967.         elseif hero_roll <= 7 then
  1968.             set hero_id  = FAR_SEER
  1969.             set hero_id2 = TAUREN_CHIEF
  1970.         else
  1971.             set hero_id  = TAUREN_CHIEF
  1972.             set hero_id2 = FAR_SEER
  1973.         endif
  1974.  
  1975.     //------------------------------------------------------------------------
  1976.     elseif raceid == RACE_NIGHTELF then
  1977.     //------------------------------------------------------------------------
  1978.         if hero_roll == 1 then
  1979.             set hero_id  = DEMON_HUNTER
  1980.             set hero_id2 = MOON_BABE
  1981.  
  1982.         elseif hero_roll <= 4 then
  1983.             set hero_id  = MOON_CHICK
  1984.             set hero_id2 = KEEPER
  1985.  
  1986.         elseif hero_roll <= 7 then
  1987.             set hero_id  = KEEPER
  1988.             set hero_id2 = DEMON_HUNTER
  1989.         else
  1990.             set hero_id  = DEMON_HUNTER
  1991.             set hero_id2 = KEEPER
  1992.         endif
  1993.  
  1994.     //------------------------------------------------------------------------
  1995.     elseif raceid == RACE_UNDEAD then
  1996.     //------------------------------------------------------------------------
  1997.         if hero_roll == 1 then
  1998.             set hero_id  = DREAD_LORD
  1999.             set hero_id2 = LICH
  2000.  
  2001.         elseif hero_roll <= 4 then
  2002.             set hero_id  = LICH
  2003.             set hero_id2 = DEATH_KNIGHT
  2004.  
  2005.         elseif hero_roll <= 7 then
  2006.             set hero_id  = DEATH_KNIGHT
  2007.             set hero_id2 = DREAD_LORD
  2008.         else
  2009.             set hero_id  = DREAD_LORD
  2010.             set hero_id2 = DEATH_KNIGHT
  2011.         endif
  2012.     else
  2013.         set hero_id = 0
  2014.     endif
  2015.  
  2016.     return hero_id
  2017. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement