share/hedgewars/Data/Scripts/Multiplayer/Battalion.lua
changeset 12412 ed33ef8a0fc5
child 12415 e11758f70cce
equal deleted inserted replaced
12411:edeae7661dca 12412:ed33ef8a0fc5
       
     1 --[[
       
     2   ########################################################################
       
     3   Name:      Battalion
       
     4   Made by:   Anachron 
       
     5   ########################################################################
       
     6 ]]--
       
     7 
       
     8 --[[
       
     9   
       
    10   Readme:
       
    11   https://github.com/Anachron/hw-battalion
       
    12 
       
    13   ########################################################################
       
    14 ]]--
       
    15 
       
    16 --[[
       
    17   ########################################################################
       
    18   Todo/Idea-List
       
    19   ########################################################################
       
    20 
       
    21   - Make Hogs sorted by rareness for teams with less hogs (more fair)
       
    22   - Keep first picked up unused crate utitlity until next round
       
    23   - Ship default scheme but let user overwrite it
       
    24   - Make SuddenDeathWaterRise dynamic
       
    25   - Make SuddenDeathTurns dynamic
       
    26   - Add Hog Variants like Crazy Scientist or Astronaut
       
    27 
       
    28   ########################################################################
       
    29 ]]--
       
    30 
       
    31 --[[
       
    32   ##############################################################################
       
    33   ### GENERAL SCRIPT LOADING AND VARIABLE INITIALISATION                     ###
       
    34   ##############################################################################
       
    35 ]]--
       
    36 
       
    37 HedgewarsScriptLoad("/Scripts/Locale.lua")
       
    38 HedgewarsScriptLoad("/Scripts/Tracker.lua")
       
    39 HedgewarsScriptLoad("/Scripts/Params.lua")
       
    40 
       
    41 -- List of all hog variants with belonging weapons,
       
    42 --  hitpoints, chances and more
       
    43 local variants = {}
       
    44 local varName = ""
       
    45 local newLine = ""--string.char(0x0A)
       
    46 local gmAny = 0xFFFFFFFF
       
    47 local version = "0.33"
       
    48 
       
    49 --[[
       
    50   ##############################################################################
       
    51   ### VARIANT SETUP                                                          ###
       
    52   ##############################################################################
       
    53 ]]--
       
    54 
       
    55 varName = "Pyromancer"
       
    56 variants[varName] = {}
       
    57 variants[varName]["chance"] = 7
       
    58 variants[varName]["hat"] = "Gasmask"
       
    59 variants[varName]["hp"] = 70
       
    60 variants[varName]["hogLimit"] = 2
       
    61 variants[varName]["weaponLimit"] = 1
       
    62 variants[varName]["weapons"] = {amFlamethrower, amMolotov, amWhip}
       
    63 variants[varName]["helperLimit"] = 1
       
    64 variants[varName]["helpers"] = {amRope, amParachute}
       
    65 variants[varName]["special"] = false
       
    66 
       
    67 varName = "Builder"
       
    68 variants[varName] = {}
       
    69 variants[varName]["chance"] = 10
       
    70 variants[varName]["hat"] = "constructor"
       
    71 variants[varName]["hp"] = 100
       
    72 variants[varName]["hogLimit"] = 1
       
    73 variants[varName]["weaponLimit"] = 1
       
    74 variants[varName]["weapons"] = {amDynamite, amWhip, amHammer}
       
    75 variants[varName]["helperLimit"] = 1
       
    76 variants[varName]["helpers"] = {amGirder, amBlowTorch}
       
    77 variants[varName]["special"] = false
       
    78 
       
    79 varName = "Rifleman"
       
    80 variants[varName] = {}
       
    81 variants[varName]["chance"] = 7
       
    82 variants[varName]["hat"] = "Sniper"
       
    83 variants[varName]["hp"] = 70
       
    84 variants[varName]["hogLimit"] = 2
       
    85 variants[varName]["weaponLimit"] = 1
       
    86 variants[varName]["weapons"] = {amRCPlane, amShotgun, amSniperRifle}
       
    87 variants[varName]["helperLimit"] = 1
       
    88 variants[varName]["helpers"] = {amLowGravity, amParachute}
       
    89 variants[varName]["special"] = false
       
    90 
       
    91 varName = "Warrior"
       
    92 variants[varName] = {}
       
    93 variants[varName]["chance"] = 12
       
    94 variants[varName]["hat"] = "spartan"
       
    95 variants[varName]["hp"] = 120
       
    96 variants[varName]["hogLimit"] = 2
       
    97 variants[varName]["weaponLimit"] = 1
       
    98 variants[varName]["weapons"] = {amClusterBomb, amGrenade, amBazooka}
       
    99 variants[varName]["helperLimit"] = 1
       
   100 variants[varName]["helpers"] = {amParachute, amRope}
       
   101 variants[varName]["special"] = false
       
   102 
       
   103 varName = "Chef"
       
   104 variants[varName] = {}
       
   105 variants[varName]["chance"] = 7
       
   106 variants[varName]["hat"] = "chef"
       
   107 variants[varName]["hp"] = 70
       
   108 variants[varName]["hogLimit"] = 1
       
   109 variants[varName]["weaponLimit"] = 1
       
   110 variants[varName]["weapons"] = {amCake, amKnife, amWhip}
       
   111 variants[varName]["helperLimit"] = 1
       
   112 variants[varName]["helpers"] = {amRubber, amParachute}
       
   113 variants[varName]["special"] = false
       
   114 
       
   115 varName = "Medic"
       
   116 variants[varName] = {}
       
   117 variants[varName]["chance"] = 12
       
   118 variants[varName]["hat"] = "war_desertmedic"
       
   119 variants[varName]["hp"] = 120
       
   120 variants[varName]["hogLimit"] = 1
       
   121 variants[varName]["weaponLimit"] = 1
       
   122 variants[varName]["weapons"] = {amResurrector, amMine, amGasBomb}
       
   123 variants[varName]["helperLimit"] = 1
       
   124 variants[varName]["helpers"] = {amTeleport, amParachute}
       
   125 variants[varName]["special"] = false
       
   126 
       
   127 varName = "Ninja"
       
   128 variants[varName] = {}
       
   129 variants[varName]["chance"] = 8
       
   130 variants[varName]["hat"] = "NinjaTriangle"
       
   131 variants[varName]["hp"] = 80
       
   132 variants[varName]["hogLimit"] = 2
       
   133 variants[varName]["weaponLimit"] = 1
       
   134 variants[varName]["weapons"] = {amSMine, amMine, amFirePunch}
       
   135 variants[varName]["helperLimit"] = 1
       
   136 variants[varName]["helpers"] = {amRope, amParachute}
       
   137 variants[varName]["special"] = false
       
   138 
       
   139 varName = "Athlete"
       
   140 variants[varName] = {}
       
   141 variants[varName]["chance"] = 8
       
   142 variants[varName]["hat"] = "footballhelmet"
       
   143 variants[varName]["hp"] = 80
       
   144 variants[varName]["hogLimit"] = 1
       
   145 variants[varName]["weaponLimit"] = 1
       
   146 variants[varName]["weapons"] = {amBaseballBat, amFirePunch, amSeduction}
       
   147 variants[varName]["helperLimit"] = 1
       
   148 variants[varName]["helpers"] = {amRope, amPickHammer}
       
   149 variants[varName]["special"] = false
       
   150 
       
   151 varName = "Scientist"
       
   152 variants[varName] = {}
       
   153 variants[varName]["chance"] = 7
       
   154 variants[varName]["hat"] = "doctor"
       
   155 variants[varName]["hp"] = 80
       
   156 variants[varName]["hogLimit"] = 1
       
   157 variants[varName]["weaponLimit"] = 1
       
   158 variants[varName]["weapons"] = {amPortalGun, amSineGun, amIceGun}
       
   159 variants[varName]["helperLimit"] = 1
       
   160 variants[varName]["helpers"] = {amTeleport, amJetpack}  
       
   161 variants[varName]["special"] = false
       
   162 
       
   163 varName = "Air-General"
       
   164 variants[varName] = {}
       
   165 variants[varName]["chance"] = 5
       
   166 variants[varName]["hat"] = "war_desertofficer"
       
   167 variants[varName]["hp"] = 50
       
   168 variants[varName]["hogLimit"] = 1
       
   169 variants[varName]["weaponLimit"] = 1
       
   170 variants[varName]["weapons"] = {amMineStrike, amNapalm, amAirAttack}
       
   171 variants[varName]["helperLimit"] = 1
       
   172 variants[varName]["helpers"] = {amRope, amParachute}
       
   173 variants[varName]["special"] = true
       
   174 
       
   175 varName = "Hunter"
       
   176 variants[varName] = {}
       
   177 variants[varName]["chance"] = 10
       
   178 variants[varName]["hat"] = "Skull"
       
   179 variants[varName]["hp"] = 100
       
   180 variants[varName]["hogLimit"] = 1
       
   181 variants[varName]["weaponLimit"] = 1
       
   182 variants[varName]["weapons"] = {amBee, amMortar, amDrill}
       
   183 variants[varName]["helperLimit"] = 1
       
   184 variants[varName]["helpers"] = {amRope, amParachute}
       
   185 variants[varName]["special"] = false
       
   186 
       
   187 varName = "King"
       
   188 variants[varName] = {}
       
   189 variants[varName]["chance"] = 3
       
   190 variants[varName]["hat"] = "crown"
       
   191 variants[varName]["hp"] = 60
       
   192 variants[varName]["hogLimit"] = 1
       
   193 variants[varName]["weaponLimit"] = 1
       
   194 variants[varName]["weapons"] = {amWatermelon, amHellishBomb, amBallgun}
       
   195 variants[varName]["helperLimit"] = 1
       
   196 variants[varName]["helpers"] = {amRope, amParachute}
       
   197 variants[varName]["special"] = true
       
   198 
       
   199 varName = "Knight"
       
   200 variants[varName] = {}
       
   201 variants[varName]["chance"] = 0
       
   202 variants[varName]["hat"] = "knight"
       
   203 variants[varName]["hp"] = 80
       
   204 variants[varName]["hogLimit"] = 1
       
   205 variants[varName]["weaponLimit"] = 1
       
   206 variants[varName]["weapons"] = {amShotgun, amBazooka, amMine}
       
   207 variants[varName]["helperLimit"] = 1
       
   208 variants[varName]["helpers"] = {amParachute, amRope}
       
   209 variants[varName]["special"] = true
       
   210 
       
   211 --[[
       
   212   ##############################################################################
       
   213   ### GENERAL VARIABLES USED FOR GAMEPLAY                                    ###
       
   214   ##############################################################################
       
   215 ]]--
       
   216 
       
   217 local unused = {amSnowball, amDrillStrike, amTardis}
       
   218 local lowWeaps = {amKamikaze}
       
   219 local lowTresh = 25
       
   220 
       
   221 local counter = {} -- Saves how many hogs of a variant a team has
       
   222 local group = {} -- Saves randomized variants for all teams
       
   223 local teamIndex = {} -- Temporary counter for amount of mutated hogs in team
       
   224 local teamHogs = {} -- Saves a list of all hogs belonging to a team
       
   225 local hogCount = {} -- Saves how many hogs a team has
       
   226 local teamNames = {} -- Saves all teams and names
       
   227 local hogInfo = {} -- Saves all hogs with their original values
       
   228 
       
   229 local LastHog = nil -- Last Hedgehog
       
   230 local CurHog = nil -- Current Hedgehog
       
   231 local LastTeam = nil -- Last Team
       
   232 local CurTeam = nil -- Current Team
       
   233 local TurnEnded = true -- Boolean whether current turn ended or not
       
   234 
       
   235 local mode = 'default' -- Which game type to play
       
   236 local luck = 100 -- Multiplier for bonuses like crates
       
   237 local strength = 1 -- Multiplier for more weapons
       
   238 local mutate = false -- Whether or not to mutate the hogs
       
   239 
       
   240 local highHasBonusWeps = false -- whether or not a hog got bonus weapons on current turn
       
   241 local highHasBonusHelp = false -- whether or not a hog got bonus helpers on current turn
       
   242 local highPickupCount = 1
       
   243 local highPickupSDCount = 2
       
   244 local highHelperCount = 1
       
   245 local highHelperSDCount = 1
       
   246 local highEnemyKillHPBonus = 10
       
   247 local highFriendlyKillHPBonus = 15
       
   248 local highWeapons = {} -- Saves the weapons from kills
       
   249 local highHelpers = {} -- Saves the helpers from kills
       
   250 local highSpecialBonus = {amTeleport, amJetpack}
       
   251 local highSpecialPool = {amExtraDamage, amVampiric}
       
   252 
       
   253 local kingLinkPerc = 50 -- Percentage of life to share from the team
       
   254 
       
   255 local pointsWepBase = 5 -- Game start points weapons
       
   256 local pointsHlpBase = 2 -- Game start points helpers
       
   257 local pointsKeepPerc = 80 -- Percentage of points to take to next round
       
   258 local pointsWepTurn = 5 -- Round bonus points weapons
       
   259 local pointsHlpTurn = 2 -- Round bonus points helpers
       
   260 local pointsWepMax = 25 -- Maximum points for weapons
       
   261 local pointsHlpMax = 10 -- Maximum points for helpers
       
   262 local pointsKeepSDPerc = 60 -- Percentage of points to take to next round on SD
       
   263 local pointsWepSDTurn = 7 -- Round bonus points weapons on SD
       
   264 local pointsHlpSDTurn = 3 -- Round bonus points helpers on SD
       
   265 local pointsWepSDMax = 35 -- Maximum points for weapons on SD
       
   266 local pointsHlpSDMax = 15 -- Maximum points for helpers on SD
       
   267 
       
   268 local pointsWeaponVal = {}
       
   269 pointsWeaponVal[amBazooka] = 5
       
   270 pointsWeaponVal[amShotgun] = 4
       
   271 pointsWeaponVal[amFirePunch] = 3
       
   272 pointsWeaponVal[amMine] = 5
       
   273 --pointsWeaponVal[amAirAttack] = 10
       
   274 pointsWeaponVal[amBee] = 6
       
   275 pointsWeaponVal[amClusterBomb] = 7
       
   276 pointsWeaponVal[amGrenade] = 5
       
   277 pointsWeaponVal[amDEagle] = 3
       
   278 pointsWeaponVal[amWhip] = 3
       
   279 pointsWeaponVal[amDynamite] = 7
       
   280 --pointsWeaponVal[amMineStrike] = 14
       
   281 pointsWeaponVal[amMortar] = 4
       
   282 pointsWeaponVal[amWatermelon] = 30
       
   283 pointsWeaponVal[amSniperRifle] = 3
       
   284 pointsWeaponVal[amBaseballBat] = 3
       
   285 pointsWeaponVal[amCake] = 7
       
   286 --pointsWeaponVal[amNapalm] = 11
       
   287 pointsWeaponVal[amDrill] = 6
       
   288 pointsWeaponVal[amHellishBomb] = 20
       
   289 pointsWeaponVal[amSineGun] = 4
       
   290 --pointsWeaponVal[amKamikaze] = 3
       
   291 --pointsWeaponVal[amBallgun] = 12
       
   292 --pointsWeaponVal[amPianoStrike] = 15
       
   293 pointsWeaponVal[amSnowball] = 2
       
   294 pointsWeaponVal[amMolotov] = 3
       
   295 pointsWeaponVal[amFlamethrower] = 4
       
   296 pointsWeaponVal[amRCPlane] = 7
       
   297 --pointsWeaponVal[amDrillStrike] = 12
       
   298 pointsWeaponVal[amGasBomb] = 2
       
   299 pointsWeaponVal[amHammer] = 3
       
   300 pointsWeaponVal[amSMine] = 4
       
   301 pointsWeaponVal[amAirMine] = 3
       
   302 pointsWeaponVal[amKnife] = 3
       
   303 pointsWeaponVal[amPortalGun] = 5
       
   304 --pointsWeaponVal[amIceGun] = 6
       
   305 pointsWeaponVal[amSeduction] = 2
       
   306 
       
   307 local pointsHelperVal = {}
       
   308 pointsHelperVal[amRope] = 5
       
   309 pointsHelperVal[amParachute] = 2
       
   310 --pointsHelperVal[amGirder] = 3
       
   311 pointsHelperVal[amBlowTorch] = 2
       
   312 pointsHelperVal[amLowGravity] = 3
       
   313 --pointsHelperVal[amRubber] = 4
       
   314 pointsHelperVal[amPickHammer] = 2
       
   315 pointsHelperVal[amTeleport] = 10
       
   316 pointsHelperVal[amJetpack] = 8
       
   317 
       
   318 local pointsPerTeam = {}
       
   319 local pointsToWep = {} -- List of [points] = {ammo1, ammo2}
       
   320 local pointsToHlp = {} -- List of [points] = {ammo1, ammo2}
       
   321 local wepPoints = {}
       
   322 local hlpPoints = {}
       
   323 
       
   324 local suddenDeath = false
       
   325 
       
   326 local healthCrateChance = 7
       
   327 local utilCrateChance = 9
       
   328 local weaponCrateChance = 12
       
   329 
       
   330 local healthCrateChanceSD = 12
       
   331 local utilCrateChanceSD = 16
       
   332 local weaponCrateChanceSD = 21
       
   333 
       
   334 local emptyCrateChance = 7
       
   335 local bonusCrateChance = 5
       
   336 local cratePickupGap = 35
       
   337 
       
   338 local utilities = {amInvulnerable, amVampiric, amExtraTime, amExtraDamage, amRope, amLandGun}
       
   339 local autoSelectHelpers = {amRope, amParachute}
       
   340 
       
   341 local LastWaterLine = 0 -- Saves WaterLine to make sure a water rise wont trigger highland kill
       
   342 
       
   343 local helpers = {}
       
   344 helpers[amSkip] = true
       
   345 helpers[amRope] = true
       
   346 helpers[amParachute] = true
       
   347 helpers[amBlowTorch] = true
       
   348 helpers[amGirder] = true
       
   349 helpers[amTeleport] = true
       
   350 helpers[amSwitch] = true
       
   351 helpers[amJetpack] = true
       
   352 helpers[amBirdy] = true
       
   353 helpers[amPortalGun] = true
       
   354 helpers[amResurrector] = true
       
   355 helpers[amTardis] = true
       
   356 helpers[amLandGun] = true
       
   357 helpers[amRubber] = true
       
   358 --helpers[amKamikaze] = true
       
   359 
       
   360 local posCaseAmmo    = 1
       
   361 local posCaseHealth  = 2
       
   362 local posCaseUtility = 4
       
   363 local posCaseDummy   = 8
       
   364 
       
   365 --[[
       
   366   ##############################################################################
       
   367   ### GENERAL BONUS LUA FUNCTIONS                                            ###
       
   368   ##############################################################################
       
   369 ]]--
       
   370 
       
   371 function swap(array, index1, index2)
       
   372     array[index1], array[index2] = array[index2], array[index1]
       
   373 end
       
   374 
       
   375 function shuffle(array)
       
   376     local cnt = #array
       
   377     while cnt > 1 do
       
   378         local index = GetRandom(cnt) +1
       
   379         swap(array, index, cnt)
       
   380         cnt = cnt - 1
       
   381     end
       
   382 end
       
   383 
       
   384 function table.clone(org)
       
   385   local copy = {}
       
   386   for orig_key, orig_value in pairs(org) do
       
   387       copy[orig_key] = orig_value
       
   388   end
       
   389   return copy
       
   390 end
       
   391 
       
   392 --[[
       
   393   ##############################################################################
       
   394   ### WEAPON, UTILITY AND AMMO FUNCTIONS                                     ###
       
   395   ##############################################################################
       
   396 ]]--
       
   397 
       
   398 function clearHogAmmo(hog)
       
   399   local lastNum = amRubber
       
   400 
       
   401   if amAirMine ~= nil then
       
   402     lastNum = amAirMine
       
   403   end
       
   404 
       
   405   for val=0,lastNum do
       
   406     AddAmmo(hog, val, 0)
       
   407   end
       
   408 end
       
   409 
       
   410 function autoSelectAmmo(hog, var)
       
   411   -- Check if hog has any "useful" helper, select helper, if yes
       
   412   for key, val in pairs(autoSelectHelpers) do
       
   413     if GetAmmoCount(hog, val) > 0 then
       
   414       SetWeapon(val)
       
   415       return
       
   416     end
       
   417   end
       
   418 end
       
   419 
       
   420 function AddHogAmmo(hog, ammo)
       
   421   -- Add weapons of variant
       
   422   --for key, val in pairs(variants[var]["weapons"]) do
       
   423   for key, val in pairs(ammo) do
       
   424     --AddAmmo(hog, val, 1)
       
   425     AddAmmo(hog, val, GetAmmoCount(hog, val) +1)
       
   426   end
       
   427 end
       
   428 
       
   429 function GetRandomAmmo(hog, sourceType)
       
   430   local var = getHogInfo(hog, 'variant')
       
   431   ammo = {}
       
   432   local source = ''
       
   433 
       
   434   if variants[var] == nil then
       
   435     return ammo
       
   436   end
       
   437 
       
   438   if sourceType == "weapons" then
       
   439     source = variants[var][sourceType]
       
   440     sourceLimit = variants[var]["weaponLimit"]
       
   441   elseif sourceType == "helpers" then
       
   442     source = variants[var][sourceType]
       
   443     sourceLimit = variants[var]["helperLimit"]
       
   444   elseif sourceType == 'poolWeapons' then
       
   445     if highWeapons[hog] == nil then
       
   446       highWeapons[hog] = {}
       
   447     end
       
   448     source = highWeapons[hog]
       
   449     if suddenDeath == false then
       
   450       sourceLimit = highPickupCount
       
   451     else
       
   452       sourceLimit = highPickupSDCount
       
   453     end
       
   454   elseif sourceType == 'poolHelpers' then
       
   455     if highHelpers[hog] == nil then
       
   456       highHelpers[hog] = {}
       
   457     end
       
   458     source = highHelpers[hog]
       
   459     if suddenDeath == false then
       
   460       sourceLimit = highHelperCount
       
   461     else
       
   462       sourceLimit = highHelperSDCount
       
   463     end
       
   464   else
       
   465     return ammo
       
   466   end
       
   467   
       
   468   local varAmmo = {}
       
   469   for key, val in pairs(source) do
       
   470       varAmmo[key] = val
       
   471   end
       
   472   
       
   473   -- If the amount of random weapons is equally to the amount of weapons possible
       
   474   -- We don't need to randomize
       
   475   if sourceLimit >= table.getn(source) then
       
   476     return varAmmo
       
   477   end
       
   478 
       
   479   local randIndex = 0
       
   480   local i = 0
       
   481   while i < sourceLimit and #varAmmo > 0 do
       
   482     randIndex = GetRandom(#varAmmo) +1
       
   483     ammo[i] = varAmmo[randIndex]
       
   484 
       
   485     -- Shift last value to the current index
       
   486     varAmmo[randIndex] = varAmmo[#varAmmo]
       
   487     -- And remove the last index from the array
       
   488     varAmmo[#varAmmo] = nil
       
   489     i = i +1
       
   490   end
       
   491 
       
   492   return ammo
       
   493 end
       
   494 
       
   495 function addTurnAmmo(hog)
       
   496   -- Check if hog is valid
       
   497   if hog == nil then
       
   498     return
       
   499   end
       
   500 
       
   501   -- Check if hog is alive
       
   502   local hp = GetHealth(hog)
       
   503   if hp == nil or hp <= 0 then
       
   504     return
       
   505   end
       
   506 
       
   507   -- Unless its points mode, get weapons normally by variant
       
   508   if mode ~= "points" then
       
   509     local maxHp = getHogInfo(hog, 'maxHp')
       
   510     local hpPer = div(hp * 100, maxHp)
       
   511 
       
   512     local wep = getHogInfo(hog, 'weapons')
       
   513     local hlp = getHogInfo(hog, 'helpers')
       
   514 
       
   515     if wep == nil or table.getn(wep) == 0 then
       
   516       hogInfo[hog]['weapons'] = GetRandomAmmo(hog, "weapons")
       
   517       wep = getHogInfo(hog, 'weapons')
       
   518     end
       
   519 
       
   520     if hlp == nil or table.getn(hlp) == 0 then
       
   521       hogInfo[hog]['helpers'] = GetRandomAmmo(hog, "helpers")
       
   522       hlp = getHogInfo(hog, 'helpers')
       
   523     end
       
   524 
       
   525     AddHogAmmo(hog, wep)
       
   526     AddHogAmmo(hog, hlp)
       
   527 
       
   528     if mode == 'highland' then
       
   529       local poolWeapons = GetRandomAmmo(hog, 'poolWeapons')
       
   530       local poolHelpers = GetRandomAmmo(hog, 'poolHelpers')
       
   531 
       
   532       AddHogAmmo(hog, poolWeapons)
       
   533       AddHogAmmo(hog, poolHelpers)
       
   534     end
       
   535 
       
   536     if hpPer < lowTresh or suddenDeath == true then
       
   537       AddHogAmmo(hog, lowWeaps)
       
   538     end
       
   539   -- We are on points mode, so we need to generate weapons based on points
       
   540   else
       
   541     setupPointsAmmo(hog)
       
   542   end
       
   543 
       
   544   AddAmmo(hog, amSkip, -1)
       
   545 end
       
   546 
       
   547 function setupPointsAmmo(hog)
       
   548   local teamName = getHogInfo(hog, 'team')
       
   549   local turnWepPoints = pointsPerTeam[teamName]['weapons']
       
   550   local turnHlpPoints = pointsPerTeam[teamName]['helpers']
       
   551   local weps = {}
       
   552   local help = {}
       
   553 
       
   554   local wepPointsTmp = table.clone(wepPoints)
       
   555   local wepMinPnt = wepPointsTmp[1]
       
   556   local wepMaxPnt = wepPointsTmp[#wepPointsTmp]
       
   557 
       
   558   --AddCaption("Hog: " .. hog .. " Wep: " .. turnWepPoints .. " - Hlp: " .. turnHlpPoints, GetClanColor(GetHogClan(CurHog)),  capgrpGameState)
       
   559   --WriteLnToConsole("BEFORE ## Team: " .. teamName .. " Wep: " .. pointsPerTeam[teamName]['weapons'] .. " - Hlp: " .. pointsPerTeam[teamName]['helpers'])
       
   560 
       
   561   while true do
       
   562     if turnWepPoints < wepMinPnt then
       
   563       break
       
   564     end
       
   565 
       
   566     if wepPointsTmp[#wepPointsTmp] > turnWepPoints then
       
   567       while wepPointsTmp[#wepPointsTmp] > turnWepPoints do
       
   568         table.remove(wepPointsTmp)
       
   569       end
       
   570       wepMaxPnt = turnWepPoints
       
   571     end
       
   572 
       
   573     local randPoint = wepPointsTmp[GetRandom(#wepPointsTmp) +1]
       
   574     local randWepList = pointsToWep[randPoint]
       
   575     local randWep = randWepList[GetRandom(#randWepList) +1]
       
   576 
       
   577     table.insert(weps, randWep)
       
   578     turnWepPoints = turnWepPoints -randPoint
       
   579   end
       
   580 
       
   581   local hlpPointsTmp = table.clone(hlpPoints)
       
   582   local hlpMinPnt = hlpPointsTmp[1]
       
   583   local hlpMaxPnt = hlpPointsTmp[#hlpPointsTmp]
       
   584 
       
   585   while true do
       
   586     if turnHlpPoints < hlpMinPnt then
       
   587       break
       
   588     end
       
   589 
       
   590     if hlpPointsTmp[#hlpPointsTmp] > turnHlpPoints then
       
   591       while hlpPointsTmp[#hlpPointsTmp] > turnHlpPoints do
       
   592         table.remove(hlpPointsTmp)
       
   593       end
       
   594       hlpMaxPnt = turnHlpPoints
       
   595     end
       
   596 
       
   597     local randPoint = hlpPointsTmp[GetRandom(#hlpPointsTmp) +1]
       
   598     local randHlpList = pointsToHlp[randPoint]
       
   599     local randHlp = randHlpList[GetRandom(#randHlpList) +1]
       
   600 
       
   601     table.insert(help, randHlp)
       
   602     turnHlpPoints = turnHlpPoints -randPoint
       
   603   end
       
   604 
       
   605   AddHogAmmo(hog, weps)
       
   606   AddHogAmmo(hog, help)
       
   607 
       
   608   -- Save remaining points
       
   609   pointsPerTeam[teamName]['weaponsRem'] = turnWepPoints
       
   610   pointsPerTeam[teamName]['helpersRem'] = turnHlpPoints
       
   611 
       
   612   -- Save already collected points so that they wont be "taxed"
       
   613   pointsPerTeam[teamName]['weaponsFix'] = pointsPerTeam[teamName]['weapons']
       
   614   pointsPerTeam[teamName]['helpersFix'] = pointsPerTeam[teamName]['helpers']
       
   615 
       
   616   --WriteLnToConsole("AFTER ## Team: " .. teamName .. " Wep: " .. pointsPerTeam[teamName]['weapons'] .. " - Hlp: " .. pointsPerTeam[teamName]['helpers'])
       
   617 end
       
   618 
       
   619 --[[
       
   620   ##############################################################################
       
   621   ### HOG SETUP  FUNCTIONS                                                   ###
       
   622   ##############################################################################
       
   623 ]]--
       
   624 
       
   625 function MutateHog(hog)
       
   626   local var = getHogInfo(hog, 'variant')
       
   627 
       
   628   SetHogName(hog, var)
       
   629   SetHogHat(hog, variants[var]["hat"])
       
   630 end
       
   631 
       
   632 function GetRandomVariant()
       
   633   local maxNum = 0
       
   634 
       
   635   for key, val in pairs(variants) do
       
   636     maxNum = maxNum + variants[key]["chance"]
       
   637   end
       
   638 
       
   639   local rand = GetRandom(maxNum)
       
   640   local lowBound = 0
       
   641   local highBound = 0
       
   642   local var = nil
       
   643 
       
   644   for key, val in pairs(variants) do
       
   645     highBound = lowBound + variants[key]["chance"]
       
   646     if rand <= highBound then
       
   647       var = key
       
   648       break
       
   649     end
       
   650     lowBound = highBound
       
   651   end
       
   652 
       
   653   return var
       
   654 end
       
   655 
       
   656 function addRandomVariantToTeam(team)
       
   657   if counter[team] == nil then
       
   658     counter[team] = {}
       
   659   end
       
   660 
       
   661   while true do
       
   662     local var = GetRandomVariant()
       
   663     if counter[team][var] == nil and variants[var]["hogLimit"] > 0 then
       
   664       counter[team][var] = 1
       
   665       break
       
   666     elseif counter[team][var] ~= nil and counter[team][var] < variants[var]["hogLimit"] then
       
   667       counter[team][var] = counter[team][var] +1
       
   668       break
       
   669     end
       
   670   end
       
   671 
       
   672   return var
       
   673 end
       
   674 
       
   675 function setTeamHogs(team)
       
   676   local maxHog = hogCount[team]
       
   677 
       
   678   group[team] = {}
       
   679   counter[team] = {}
       
   680 
       
   681   if mode == 'king' then
       
   682     maxHog = maxHog -1
       
   683   end
       
   684 
       
   685   for i=1,maxHog do
       
   686     table.insert(group[team], group['all'][i])
       
   687   end
       
   688 
       
   689   if mode == 'king' then
       
   690     counter[team]['King'] = 1
       
   691     table.insert(group[team], 'King')
       
   692   end
       
   693 end
       
   694 
       
   695 function countTeamHogs(hog)
       
   696   local team = GetHogTeamName(hog)
       
   697 
       
   698   if hogCount[team] == nil then
       
   699     hogCount[team] = 1
       
   700     teamHogs[team] = {}
       
   701   else
       
   702     hogCount[team] = hogCount[team] +1
       
   703   end
       
   704 
       
   705   teamHogs[team][hogCount[team]] = hog
       
   706 
       
   707   teamNames[team] = 1
       
   708 end
       
   709 
       
   710 function setHogVariant(hog)
       
   711   local team = getHogInfo(hog, 'team')
       
   712 
       
   713   if teamIndex[team] == nil then
       
   714     teamIndex[team] = 1
       
   715   else
       
   716     teamIndex[team] = teamIndex[team] +1
       
   717   end
       
   718 
       
   719   local hogNum = teamIndex[team]
       
   720   local hogVar = group[team][hogNum]
       
   721 
       
   722   hogInfo[hog]['variant'] = hogVar
       
   723   SetHealth(hog, variants[hogVar]["hp"])
       
   724 end
       
   725 
       
   726 function getHogInfo(hog, info)
       
   727   if hog == nil then
       
   728     AddCaption(loc("ERROR [getHogInfo]: Hog") .. hog .. " is nil!", 0xFFFFFFFF, capgrpMessage)
       
   729     WriteLnToConsole(loc("ERROR [getHogInfo]: Hog") .. hog .. " is nil!")
       
   730     return
       
   731   end
       
   732 
       
   733   if hogInfo[hog] == nil then
       
   734     return nil
       
   735   end
       
   736 
       
   737   return hogInfo[hog][info]
       
   738 end
       
   739 
       
   740 function setHogInfo(hog)
       
   741   if hog == nil then
       
   742     AddCaption(loc("ERROR [setHogInfo]: Hog") .. hog .. " is nil!", 0xFFFFFFFF, capgrpMessage)
       
   743     WriteLnToConsole(loc("ERROR [setHogInfo]: Hog") .. hog .. " is nil!")
       
   744     return
       
   745   end
       
   746 
       
   747   hogInfo[hog] = {}
       
   748   hogInfo[hog]['maxHp'] = GetHealth(hog)
       
   749   hogInfo[hog]['name'] = GetHogName(hog)
       
   750   hogInfo[hog]['hat'] = GetHogHat(hog)
       
   751   hogInfo[hog]['team'] = GetHogTeamName(hog)
       
   752   hogInfo[hog]['clan'] = GetHogClan(hog)
       
   753   hogInfo[hog]['clanColor'] = GetClanColor(hogInfo[hog]['clan'])
       
   754 end
       
   755 
       
   756 --[[
       
   757   ##############################################################################
       
   758   ### CRATE SPAWN AND PICKUP FUNCTIONS                                       ###
       
   759   ##############################################################################
       
   760 ]]--
       
   761 
       
   762 --[[
       
   763  : Heals either 10 (95% chance) or 15 (5% chance) hitpoints
       
   764  : Plus 10% of the hogs base hitpoints. 
       
   765  :
       
   766  : Has a 7% chance to be empty.
       
   767 ]]--
       
   768 function onHealthCratePickup()
       
   769   local factor = 2
       
   770   local msgColor = getHogInfo(CurHog, 'clanColor')
       
   771   local healHp = 0
       
   772   PlaySound(sndShotgunReload)
       
   773 
       
   774   if GetRandom(100) < emptyCrateChance then
       
   775     AddCaption(loc("empty crate"), msgColor, capgrpMessage)
       
   776     return
       
   777   elseif GetRandom(100) < bonusCrateChance then
       
   778     factor = 3
       
   779   end
       
   780 
       
   781   local var = getHogInfo(CurHog, 'variant')
       
   782   local hogHealth = GetHealth(CurHog)
       
   783   healHp = 5 * factor
       
   784 
       
   785   -- Add extra 10% of hogs base hp to heal
       
   786   healHp = healHp + div(getHogInfo(CurHog, 'maxHp'), 10)
       
   787 
       
   788   AddCaption(loc("+ ") .. healHp .. loc(" hp"), msgColor, capgrpMessage)
       
   789 
       
   790   SetEffect(CurHog, hePoisoned, 0)
       
   791   SetHealth(CurHog, hogHealth + healHp)
       
   792   local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) +cratePickupGap, vgtHealthTag, healHp, false)
       
   793   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
       
   794   SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, msgColor)
       
   795 end
       
   796 
       
   797 --[[
       
   798  : Adds either 1 (95% chance) or 2 (5% chance) random weapon(s) based on the hog variant.
       
   799  :
       
   800  : Has a 7% chance to be empty.
       
   801 ]]--
       
   802 function onWeaponCratePickup()
       
   803   local factor = 1 * strength
       
   804   local msgColor = GetClanColor(GetHogClan(CurHog))
       
   805   PlaySound(sndShotgunReload)
       
   806 
       
   807   if GetRandom(100) < emptyCrateChance then
       
   808     AddCaption(loc("empty crate"), msgColor, capgrpMessage)
       
   809     return
       
   810   elseif GetRandom(100) < bonusCrateChance then
       
   811     factor = 2 * strength
       
   812   end
       
   813 
       
   814   local randIndex
       
   815   local randAmmo
       
   816 
       
   817   if mode ~= 'points' then
       
   818     local var = getHogInfo(CurHog, 'variant')
       
   819     randIndex = GetRandom(table.getn(variants[var]["weapons"])) +1
       
   820     randAmmo = variants[var]["weapons"][randIndex]
       
   821   else
       
   822     local possibleWeapons = {}
       
   823 
       
   824     for key, val in pairs(pointsWeaponVal) do
       
   825       if val > 2 and val < 8 then
       
   826         table.insert(possibleWeapons, key)
       
   827       end
       
   828     end
       
   829 
       
   830     randIndex = GetRandom(table.getn(possibleWeapons)) +1
       
   831     randAmmo = possibleWeapons[randIndex]
       
   832   end
       
   833 
       
   834   AddCaption(loc("+ ") .. factor .. loc(" ammo"), msgColor, capgrpMessage)
       
   835 
       
   836   AddAmmo(CurHog, randAmmo, GetAmmoCount(CurHog, randAmmo) +factor)
       
   837   local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) +cratePickupGap, vgtAmmo, 0, true)
       
   838   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
       
   839   SetVisualGearValues(effect, nil, nil, nil, nil, nil, randAmmo, nil, nil, nil, msgColor)
       
   840 end
       
   841 --[[
       
   842  : Adds either 1 (95% chance) or 2 (5% chance) random helper(s) based on the hog variant.
       
   843  :
       
   844  : Has a 7% chance to be empty.
       
   845 ]]--
       
   846 function onUtilityCratePickup()
       
   847   local factor = 1 * strength
       
   848   local msgColor = GetClanColor(GetHogClan(CurHog))
       
   849   PlaySound(sndShotgunReload)
       
   850 
       
   851   if GetRandom(100) < emptyCrateChance then
       
   852     AddCaption(loc("empty crate"), msgColor, capgrpMessage)
       
   853     return
       
   854   elseif GetRandom(100) < bonusCrateChance then
       
   855     factor = 2 * strength
       
   856   end
       
   857 
       
   858   local randIndex
       
   859   local randUtility
       
   860 
       
   861   if mode ~= 'points' then
       
   862     randIndex = GetRandom(table.getn(utilities)) +1
       
   863     randUtility = utilities[randIndex]
       
   864   else
       
   865     local possibleHelpers = {}
       
   866 
       
   867     for key, val in pairs(pointsHelperVal) do
       
   868       table.insert(possibleHelpers, key)
       
   869     end
       
   870 
       
   871     randIndex = GetRandom(table.getn(possibleHelpers)) +1
       
   872     randUtility = possibleHelpers[randIndex]
       
   873   end
       
   874   
       
   875   AddCaption(loc("+ ") .. factor .. loc(" ammo"), msgColor, capgrpMessage)
       
   876 
       
   877   AddAmmo(CurHog, randUtility, GetAmmoCount(CurHog, randUtility) +factor)
       
   878   local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) +cratePickupGap, vgtAmmo, 0, true)
       
   879   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
       
   880   SetVisualGearValues(effect, nil, nil, nil, nil, nil, randUtility, nil, nil, nil, msgColor)
       
   881 end
       
   882 
       
   883 function onPickupCrate(crate)
       
   884   local pos = GetGearPos(crate)
       
   885 
       
   886   -- Check if the crate is fake
       
   887   if pos % posCaseDummy >= 1 then
       
   888     if pos % posCaseDummy == posCaseAmmo then
       
   889       onWeaponCratePickup()
       
   890     elseif pos % posCaseDummy == posCaseHealth then
       
   891       onHealthCratePickup()
       
   892     elseif pos % posCaseDummy == posCaseUtility then
       
   893       onUtilityCratePickup()
       
   894     end
       
   895   end
       
   896 end
       
   897 
       
   898 function RandomTurnEvents()
       
   899   if GetRandom(100) < weaponCrateChance then
       
   900     SpawnFakeAmmoCrate(0, 0, false, false)
       
   901     return 5000
       
   902   elseif GetRandom(100) < utilCrateChance then
       
   903     SpawnFakeUtilityCrate(0, 0, false, false)
       
   904     return 5000
       
   905   elseif GetRandom(100) < healthCrateChance then
       
   906     SpawnFakeHealthCrate(0, 0, false, false)
       
   907     return 5000
       
   908   end
       
   909   return 0
       
   910 end
       
   911 
       
   912 --[[
       
   913   ##############################################################################
       
   914   ### SUDDEN DEATH FUNCTIONS                                                 ###
       
   915   ##############################################################################
       
   916 ]]--
       
   917 
       
   918 function onSuddenDeathDamage(hog)
       
   919   local hp = GetHealth(hog)
       
   920   local maxHp = getHogInfo(hog, 'maxHp')
       
   921   local newHp = 0
       
   922   local hpDec = 0
       
   923   local hpPer = div(hp * 100, maxHp)
       
   924 
       
   925   if hp > 1 then
       
   926     local msgColor = GetClanColor(GetHogClan(hog))
       
   927     if hpPer <= 25 then
       
   928       newHp = hp -2
       
   929     elseif hpPer <= 50 then
       
   930       newHp = hp -3
       
   931     elseif hpPer <= 75 then
       
   932       newHp = hp -4
       
   933     elseif hpPer <= 100 then
       
   934       newHp = hp -5
       
   935     elseif hpPer <= 125 then
       
   936       newHp = hp -6
       
   937     elseif hpPer <= 150 then
       
   938       newHp = hp -7
       
   939     else
       
   940       newHp = div(hp * 93, 100)
       
   941     end
       
   942 
       
   943     if newHp <= 0 then
       
   944       newHp = 1
       
   945     end
       
   946 
       
   947     hpDec = hp - newHp
       
   948 
       
   949     SetHealth(hog, newHp)
       
   950     local effect = AddVisualGear(GetX(hog), GetY(hog) +cratePickupGap, vgtHealthTag, hpDec, false)
       
   951     SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, msgColor)
       
   952   end
       
   953 end
       
   954 
       
   955 function onSuddenDeathTurn()
       
   956   runOnGears(onSuddenDeathDamage)
       
   957 end
       
   958 
       
   959 function onSuddenDeath()
       
   960   suddenDeath = true
       
   961 
       
   962   healthCrateChance = healthCrateChanceSD
       
   963   utilCrateChance = utilCrateChanceSD
       
   964   weaponCrateChance = weaponCrateChanceSD
       
   965 
       
   966   if mode == 'highland' then
       
   967     highEnemyKillHPBonus = highEnemyKillHPBonus +5
       
   968     highFriendlyKillHPBonus = highFriendlyKillHPBonus +10
       
   969   end
       
   970 
       
   971   if mode ~= 'points' then
       
   972     for key, val in pairs(variants) do
       
   973       if not variants[key]["special"] then
       
   974         variants[key]["weaponLimit"] = variants[key]["weaponLimit"] +1
       
   975       end
       
   976     end
       
   977   end
       
   978 
       
   979   if mode ~= 'points' then
       
   980     for hog, val in pairs(hogInfo) do
       
   981       hogInfo[hog]['weapons'] = {}
       
   982       hogInfo[hog]['helpers'] = {}
       
   983     end
       
   984     
       
   985     runOnGears(setupHogTurn)
       
   986   end
       
   987 end
       
   988 
       
   989 --[[
       
   990   ##############################################################################
       
   991   ### GEAR TRACKING FUNCTIONS                                                ###
       
   992   ##############################################################################
       
   993 ]]--
       
   994 
       
   995 function onGearAdd(gear)
       
   996   local gearType = GetGearType(gear)
       
   997   
       
   998   if gearType == gtHedgehog then
       
   999     trackGear(gear)
       
  1000   elseif gearType == gtRCPlane then
       
  1001     -- Limit bombs to 1 until 0.9.23 is released
       
  1002     SetHealth(gear, 1)
       
  1003   elseif gearType == gtAirBomb then
       
  1004     -- gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, ImpactSounds, Tint, Damage, Boom
       
  1005     SetGearValues(gear, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 15)
       
  1006   elseif gearType == gtCake then
       
  1007     -- gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, ImpactSounds, Tint, Damage, Boom
       
  1008     SetGearValues(gear, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 50)
       
  1009   elseif gearType == gtDEagleShot then
       
  1010     -- gearUid, Angle, Power, WDTimer, Radius, Density, Karma, DirAngle, AdvBounce, ImpactSound, ImpactSounds, Tint, Damage, Boom
       
  1011     SetGearValues(gear, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 12)
       
  1012   end
       
  1013 end
       
  1014 
       
  1015 function onHighlandKill(gear)
       
  1016   local deathVar = getHogInfo(gear, 'variant')
       
  1017   local killVar = getHogInfo(CurHog, 'variant')
       
  1018   local bonAmmo = {}
       
  1019   local deathMaxHP = getHogInfo(gear, 'maxHp')
       
  1020   local curHP = GetHealth(CurHog)
       
  1021   local newHP = 0
       
  1022   local hpDiff = 0
       
  1023   local addAmmo = false
       
  1024 
       
  1025   -- Killer hog is dead! Don't do anything
       
  1026   if curHP == nil or curHP <= 0 then
       
  1027     return
       
  1028   end
       
  1029 
       
  1030   -- Killer and victim is equal! Don't do anything
       
  1031   if CurHog == gear then
       
  1032     return
       
  1033   end
       
  1034 
       
  1035   -- Hog drowned because of water, not enemy
       
  1036   if LastWaterLine ~= WaterLine then
       
  1037     return
       
  1038   end
       
  1039 
       
  1040   -- Enemy kill! Add weapons to pool and to hog
       
  1041   if getHogInfo(gear, 'clan') ~= getHogInfo(CurHog, 'clan') then
       
  1042 
       
  1043     -- Initialize weapons if required
       
  1044     if highWeapons[CurHog] == nil then
       
  1045       highWeapons[CurHog] = {}
       
  1046     end
       
  1047 
       
  1048     if highHelpers[CurHog] == nil then
       
  1049       highHelpers[CurHog] = {}
       
  1050     end
       
  1051 
       
  1052     -- If not a special hog, use the victims weapons
       
  1053     if variants[deathVar]['special'] == false then
       
  1054       bonAmmo = variants[deathVar]['weapons']
       
  1055 
       
  1056       if suddenDeath == true then
       
  1057         ammoCount = highPickupSDCount
       
  1058       else
       
  1059         ammoCount = highPickupCount
       
  1060       end
       
  1061 
       
  1062       -- Check if hog already got bonus weapons
       
  1063       if table.getn(highWeapons[CurHog]) == 0 and highHasBonusWeps == false then
       
  1064         highHasBonusWeps = true
       
  1065         addAmmo = true
       
  1066       end
       
  1067 
       
  1068       -- Pass turn bonus weapons to hog pool
       
  1069       for key, val in pairs(bonAmmo) do
       
  1070         local idx = table.getn(highWeapons[CurHog]) +1
       
  1071         highWeapons[CurHog][idx] = val
       
  1072       end
       
  1073     -- It's a special hog, use special pool
       
  1074     else
       
  1075       bonAmmo = highSpecialBonus
       
  1076 
       
  1077       ammoCount = 1
       
  1078 
       
  1079       -- Check if hog already got bonus helpers
       
  1080       if table.getn(highWeapons[CurHog]) == 0 and highHasBonusHelp == false then
       
  1081         highHasBonusHelp = true
       
  1082         addAmmo = true
       
  1083       end
       
  1084 
       
  1085       -- Pass turn bonus weapons to hog pool
       
  1086       for key, val in pairs(highSpecialPool) do
       
  1087         local idx = table.getn(highHelpers[CurHog]) +1
       
  1088         highHelpers[CurHog][idx] = val
       
  1089       end
       
  1090     end
       
  1091 
       
  1092     if addAmmo then
       
  1093       local i = 1
       
  1094       while i <= ammoCount and #bonAmmo > 0 do
       
  1095         local randAmmo = GetRandom(#bonAmmo) +1
       
  1096         local randAmmoType = bonAmmo[randAmmo]
       
  1097 
       
  1098         -- Remove the randomized weapon so it cannot be picked up twice
       
  1099         table.remove(bonAmmo, randAmmo)
       
  1100 
       
  1101         AddAmmo(CurHog, randAmmoType, GetAmmoCount(CurHog, randAmmoType) +1)
       
  1102 
       
  1103         local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) + (cratePickupGap * i), vgtAmmo, 0, true)
       
  1104         -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
       
  1105         SetVisualGearValues(effect, nil, nil, nil, nil, nil, randAmmoType, nil, nil, nil, nil)
       
  1106 
       
  1107         i = i +1
       
  1108       end
       
  1109     end
       
  1110 
       
  1111     hpDiff = div(deathMaxHP * highEnemyKillHPBonus, 100)
       
  1112     newHP = curHP + hpDiff
       
  1113     SetHealth(CurHog, newHP)
       
  1114 
       
  1115     local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) - cratePickupGap, vgtHealthTag, hpDiff, false)
       
  1116     -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
       
  1117     SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, GetClanColor(GetHogClan(CurHog)))
       
  1118   -- Friendly fire! Remove all weapons and helpers from pool
       
  1119   else
       
  1120     highWeapons[CurHog] = {}
       
  1121     highHelpers[CurHog] = {}
       
  1122 
       
  1123     hpDiff = div(deathMaxHP * highFriendlyKillHPBonus, 100)
       
  1124     newHP = curHP - hpDiff
       
  1125     if newHP > 0 then
       
  1126       SetHealth(CurHog, newHP)
       
  1127     else
       
  1128       SetHealth(CurHog, 0)
       
  1129     end
       
  1130 
       
  1131     local effect = AddVisualGear(GetX(CurHog), GetY(CurHog) - cratePickupGap, vgtHealthTag, hpDiff, false)
       
  1132     -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
       
  1133     SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, GetClanColor(GetHogClan(CurHog)))
       
  1134   end
       
  1135 end
       
  1136 
       
  1137 function onKingDeath(KingHog)
       
  1138   local team = getHogInfo(KingHog, 'team')
       
  1139   local msgColor = getHogInfo(KingHog, 'clanColor')
       
  1140 
       
  1141   AddCaption(team .. loc("s king died"), msgColor, capgrpGameState)
       
  1142   PlaySound(sndByeBye)
       
  1143   DismissTeam(team)
       
  1144 
       
  1145   -- for hog, val in pairs(hogInfo) do
       
  1146   --   if getHogInfo(hog, 'team') == team then
       
  1147   --     hp = GetHealth(hog)
       
  1148   --     if hp ~= nil and hp > 0 then
       
  1149   --       SetState(KingHog, gstHHDeath)
       
  1150   --       SetHealth(hog, 0)
       
  1151   --       SetGearValues(hog, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0)
       
  1152   --     end
       
  1153   --   end
       
  1154   -- end
       
  1155 end
       
  1156 
       
  1157 function onPointsKill(gear)
       
  1158   local deathVar = getHogInfo(gear, 'variant')
       
  1159   local killVar = getHogInfo(CurHog, 'variant')
       
  1160   local deathClan = getHogInfo(gear, 'clan')
       
  1161   local killClan = getHogInfo(CurHog, 'clan')
       
  1162   local team = getHogInfo(CurHog, 'team')
       
  1163 
       
  1164   local curHP = GetHealth(CurHog)
       
  1165 
       
  1166   -- Killer hog is dead! Don't do anything
       
  1167   if curHP == nil or curHP <= 0 then
       
  1168     return
       
  1169   end
       
  1170 
       
  1171   -- Hog drowned because of water, not enemy
       
  1172   if LastWaterLine ~= WaterLine then
       
  1173     return
       
  1174   end
       
  1175 
       
  1176   -- Same clan, friendly kill, skip
       
  1177   if killClan == deathClan then
       
  1178     return
       
  1179   end
       
  1180 
       
  1181   pointsPerTeam[team]['weapons'] = pointsPerTeam[team]['weapons'] + 2
       
  1182   pointsPerTeam[team]['helpers'] = pointsPerTeam[team]['helpers'] + 1
       
  1183 
       
  1184   local effect = AddVisualGear(GetX(CurHog) - (cratePickupGap / 2), GetY(CurHog), vgtHealthTag, 2, false)
       
  1185   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
       
  1186   SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0xFFFFFFFF)
       
  1187 
       
  1188   local effect = AddVisualGear(GetX(CurHog) + (cratePickupGap / 2), GetY(CurHog), vgtHealthTag, 1, false)
       
  1189   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
       
  1190   SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0x444444FF)
       
  1191 end
       
  1192 
       
  1193 function onGearDelete(gear)
       
  1194   trackDeletion(gear)
       
  1195 
       
  1196   if GetGearType(gear) == gtCase and band(GetGearMessage(gear), gmDestroy) ~= 0 then
       
  1197     onPickupCrate(gear)
       
  1198   end
       
  1199 
       
  1200   if GetGearType(gear) == gtHedgehog then
       
  1201     if mode ~= 'points' then
       
  1202       hogInfo[gear]['weapons'] = {}
       
  1203       hogInfo[gear]['helpers'] = {}
       
  1204     end
       
  1205 
       
  1206     -- If dying gear is a hog and mode is highland, check for kills
       
  1207     if mode == 'highland' then
       
  1208       onHighlandKill(gear)
       
  1209     -- If current hog is dying and we are on points mode, we need to save the unused weapons/helpers
       
  1210     elseif mode == 'points' and CurHog == gear then
       
  1211       savePoints(gear)
       
  1212     elseif mode == 'points' and CurHog ~= gear then
       
  1213       onPointsKill(gear)
       
  1214     end
       
  1215 
       
  1216     if mode == 'king' and getHogInfo(gear, 'variant') == 'King' then
       
  1217       onKingDeath(gear)
       
  1218     end
       
  1219   end
       
  1220 end
       
  1221 
       
  1222 --[[
       
  1223   ##############################################################################
       
  1224   ### TURN BASED FUNCTIONS                                                   ###
       
  1225   ##############################################################################
       
  1226 ]]--
       
  1227 
       
  1228 function calcKingHP()
       
  1229   local teamKings = {}
       
  1230   local teamHealth = {}
       
  1231 
       
  1232   for hog, val in pairs(hogInfo) do
       
  1233     local hp = GetHealth(hog)
       
  1234 
       
  1235     if hp ~= nil and hp > 0 then
       
  1236       local team = getHogInfo(hog, 'team')
       
  1237 
       
  1238       if teamHealth[team] == nil then
       
  1239         teamHealth[team] = 0
       
  1240       end
       
  1241 
       
  1242       if getHogInfo(hog, 'variant') == 'King' then
       
  1243         teamKings[team] = hog
       
  1244       else
       
  1245         teamHealth[team] = teamHealth[team] + hp
       
  1246       end
       
  1247     end
       
  1248   end
       
  1249 
       
  1250   for team, hog in pairs(teamKings) do
       
  1251     local hp = GetHealth(hog)
       
  1252     local newHP = div(teamHealth[team] * kingLinkPerc, 100)
       
  1253     local diff = newHP - hp
       
  1254 
       
  1255     -- Set hitpoints to 1 if no other hog is alive or only has 1 hitpoint
       
  1256     if newHP <= 0 then
       
  1257       newHP = 1
       
  1258       diff = 0
       
  1259     end
       
  1260 
       
  1261     if diff < 0 then
       
  1262       diff = -diff
       
  1263     end
       
  1264 
       
  1265     if hp ~= newHP then
       
  1266       SetHealth(hog, newHP)
       
  1267       local effect = AddVisualGear(GetX(hog), GetY(hog) - cratePickupGap, vgtHealthTag, diff, false)
       
  1268       -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
       
  1269       SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, GetClanColor(GetHogClan(hog)))
       
  1270     end
       
  1271   end
       
  1272 end
       
  1273 
       
  1274 function setupHogTurn(hog)
       
  1275   clearHogAmmo(hog)
       
  1276   addTurnAmmo(hog)
       
  1277 end
       
  1278 
       
  1279 function onTurnEnd()
       
  1280   local anyHog = nil
       
  1281   for team, val in pairs(teamNames) do
       
  1282     -- Count amount of alive hogs in team
       
  1283     local c = 0
       
  1284     for idx, hog in pairs(teamHogs[team]) do
       
  1285       if GetHealth(hog) ~= nil then
       
  1286         anyHog = hog
       
  1287         c = c + 1
       
  1288       end
       
  1289     end
       
  1290 
       
  1291     -- Only one hog left, unfreeze the hog
       
  1292     if c == 1 then
       
  1293       if GetHealth(anyHog) ~= nil then
       
  1294         SetEffect(anyHog, heFrozen, 0)
       
  1295       end
       
  1296     end
       
  1297   end
       
  1298 
       
  1299   -- When we are on points mode count remaining weapon/helper points
       
  1300   if mode == 'points' and GetHealth(CurHog) ~= nil then
       
  1301     savePoints(CurHog)
       
  1302   end
       
  1303 
       
  1304   -- Run random turn events
       
  1305   RandomTurnEvents()
       
  1306 end
       
  1307 
       
  1308 function savePoints(hog)
       
  1309   local team = getHogInfo(hog, 'team')
       
  1310   local hogWepPoints = 0
       
  1311   local hogHlpPoints = 0
       
  1312 
       
  1313   for ammoType=0,amAirMine do
       
  1314     local ammoCount = GetAmmoCount(hog, ammoType)
       
  1315 
       
  1316     if pointsWeaponVal[ammoType] ~= nil then
       
  1317       hogWepPoints = hogWepPoints + (pointsWeaponVal[ammoType] * ammoCount)
       
  1318     elseif pointsHelperVal[ammoType] ~= nil then
       
  1319       hogHlpPoints = hogHlpPoints + (pointsHelperVal[ammoType] * ammoCount)
       
  1320     end
       
  1321   end
       
  1322 
       
  1323   local wepWoTax = pointsPerTeam[team]['weaponsFix']
       
  1324   local hlpWoTax = pointsPerTeam[team]['helpersFix']
       
  1325   local wepToTax = 0
       
  1326   local hlpToTax = 0
       
  1327 
       
  1328   if hogWepPoints <= wepWoTax then
       
  1329     wepWoTax = hogWepPoints
       
  1330   else
       
  1331     wepToTax = hogWepPoints - wepWoTax
       
  1332   end
       
  1333 
       
  1334   if hogHlpPoints <= hlpWoTax then
       
  1335     hlpWoTax = hogHlpPoints
       
  1336   else
       
  1337     hlpToTax = hogHlpPoints - hlpWoTax
       
  1338   end
       
  1339 
       
  1340   if suddenDeath == false then
       
  1341     pointsPerTeam[team]['weapons'] = pointsPerTeam[team]['weaponsRem'] + wepWoTax + div(wepToTax * pointsKeepPerc, 100)
       
  1342     pointsPerTeam[team]['helpers'] = pointsPerTeam[team]['helpersRem'] + hlpWoTax + div(hlpToTax * pointsKeepPerc, 100)
       
  1343   else
       
  1344     pointsPerTeam[team]['weapons'] = pointsPerTeam[team]['weaponsRem'] + wepWoTax + div(wepToTax * pointsKeepSDPerc, 100)
       
  1345     pointsPerTeam[team]['helpers'] = pointsPerTeam[team]['helpersRem'] + hlpWoTax + div(hlpToTax * pointsKeepSDPerc, 100)
       
  1346   end
       
  1347 
       
  1348   local effect = AddVisualGear(GetX(hog) - (cratePickupGap / 2), GetY(hog), vgtHealthTag, pointsPerTeam[team]['weapons'], false)
       
  1349   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
       
  1350   SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0xFFFFFFFF)
       
  1351 
       
  1352   local effect = AddVisualGear(GetX(hog) + (cratePickupGap / 2), GetY(hog), vgtHealthTag, pointsPerTeam[team]['helpers'], false)
       
  1353   -- (vgUid, X, Y, dX, dY, Angle, Frame, FrameTicks, State, Timer, Tint)
       
  1354   SetVisualGearValues(effect, nil, nil, nil, nil, nil, nil, nil, nil, nil, 0x444444FF)
       
  1355 end
       
  1356 
       
  1357 function onPointsTurn()
       
  1358   local hogWepPoints = 0
       
  1359   local hogHlpPoints = 0
       
  1360 
       
  1361   if suddenDeath == false then
       
  1362     pointsPerTeam[LastTeam]['weapons'] = pointsPerTeam[LastTeam]['weapons'] + pointsWepTurn
       
  1363     pointsPerTeam[LastTeam]['helpers'] = pointsPerTeam[LastTeam]['helpers'] + pointsHlpTurn
       
  1364 
       
  1365     if pointsPerTeam[LastTeam]['weapons'] > pointsWepMax then
       
  1366       pointsPerTeam[LastTeam]['weapons'] = pointsWepMax
       
  1367     end
       
  1368 
       
  1369     if pointsPerTeam[LastTeam]['helpers'] > pointsHlpMax then
       
  1370       pointsPerTeam[LastTeam]['helpers'] = pointsHlpMax
       
  1371     end
       
  1372   else
       
  1373     pointsPerTeam[LastTeam]['weapons'] = pointsPerTeam[LastTeam]['weapons'] + pointsWepSDTurn
       
  1374     pointsPerTeam[LastTeam]['helpers'] = pointsPerTeam[LastTeam]['helpers'] + pointsHlpSDTurn
       
  1375 
       
  1376     if pointsPerTeam[LastTeam]['weapons'] > pointsWepSDMax then
       
  1377       pointsPerTeam[LastTeam]['weapons'] = pointsWepSDMax
       
  1378     end
       
  1379 
       
  1380     if pointsPerTeam[LastTeam]['helpers'] > pointsHlpSDMax then
       
  1381       pointsPerTeam[LastTeam]['helpers'] = pointsHlpSDMax
       
  1382     end
       
  1383   end
       
  1384 
       
  1385   -- Take the first alive hog from LastTeam and setup new weapons and helpers
       
  1386   -- Since the weapons and helpers are shared the whole team, this is sufficent
       
  1387   for idx, teamHog in pairs(teamHogs[LastTeam]) do
       
  1388     if GetHealth(teamHog) ~= nil then
       
  1389       clearHogAmmo(teamHog)
       
  1390       addTurnAmmo(teamHog)
       
  1391       break
       
  1392     end
       
  1393   end
       
  1394 end
       
  1395 
       
  1396 function onNewTurn()
       
  1397   LastHog = CurHog
       
  1398   LastTeam = CurTeam
       
  1399   CurHog = CurrentHedgehog
       
  1400   CurTeam = getHogInfo(CurHog, 'team')
       
  1401   TurnEnded = false
       
  1402 
       
  1403   if suddenDeath == true then
       
  1404     onSuddenDeathTurn()
       
  1405   else
       
  1406     AddCaption(loc("Round #") .. (TotalRounds +1).. loc(" (SD on #") .. (SuddenDeathTurns +2) .. ")", getHogInfo(CurHog, 'clanColor'),  capgrpGameState)
       
  1407   end
       
  1408 
       
  1409   -- Generate new weapons for last hog if it's still alive
       
  1410   if LastHog ~= nil and LastHog ~= CurHog then
       
  1411     if mode == 'points' then
       
  1412       onPointsTurn()
       
  1413     else
       
  1414       hogInfo[LastHog]['weapons'] = {}
       
  1415       hogInfo[LastHog]['helpers'] = {}
       
  1416       setupHogTurn(LastHog)
       
  1417     end
       
  1418   end
       
  1419 
       
  1420   -- Recalculate the kings hp if required
       
  1421   if mode == 'king' then
       
  1422     calcKingHP()
       
  1423   end
       
  1424 
       
  1425   if mode == 'highland' then
       
  1426     highHasBonusWeps = false
       
  1427     highHasBonusHelp = false
       
  1428   end
       
  1429 
       
  1430   -- Set LastWaterLine to the current water line
       
  1431   LastWaterLine = WaterLine
       
  1432 end
       
  1433 
       
  1434 function onGameTick20()
       
  1435   if TurnEnded == false and TurnTimeLeft <= 0 then
       
  1436     TurnEnded = true
       
  1437     onTurnEnd()
       
  1438   end
       
  1439 end
       
  1440 
       
  1441 --[[
       
  1442   ##############################################################################
       
  1443   ### GAME START FUNCTIONS                                                   ###
       
  1444   ##############################################################################
       
  1445 ]]--
       
  1446 
       
  1447 function onAmmoStoreInit()
       
  1448   local lastNum = amAirMine
       
  1449 
       
  1450   for val=0,lastNum do
       
  1451     SetAmmo(val, 0, 0, 0, 0)
       
  1452   end
       
  1453 end
       
  1454 
       
  1455 function onParameters()
       
  1456   parseParams()
       
  1457 
       
  1458   if params['mode'] ~= nil then
       
  1459     mode = params['mode']
       
  1460   end
       
  1461 
       
  1462   if params['mutate'] ~= nil then
       
  1463     mutate = params['mutate']
       
  1464   end
       
  1465 
       
  1466   if params['strength'] ~= nil and tonumber(params['strength']) > 0 then
       
  1467     strength = tonumber(params['strength'])
       
  1468     -- Highland
       
  1469     if mode == 'highland' then
       
  1470       highPickupCount = highPickupCount * strength
       
  1471       highPickupSDCount = highPickupSDCount * strength
       
  1472       highHelperCount = highHelperCount * strength
       
  1473       highHelperSDCount = highHelperSDCount * strength
       
  1474     -- Points
       
  1475     elseif mode == 'points' then
       
  1476       pointsWepBase = pointsWepBase * strength
       
  1477       pointsHlpBase = pointsHlpBase * strength
       
  1478       pointsWepTurn = pointsWepTurn * strength
       
  1479       pointsHlpTurn = pointsHlpTurn * strength
       
  1480       pointsWepMax = pointsWepMax * strength
       
  1481       pointsHlpMax = pointsHlpMax * strength
       
  1482       pointsWepSDTurn = pointsWepSDTurn * strength
       
  1483       pointsHlpSDTurn = pointsHlpSDTurn * strength
       
  1484       pointsWepSDMax = pointsWepSDMax * strength
       
  1485       pointsHlpSDMax = pointsHlpSDMax * strength
       
  1486     -- Either king or normal mode, change variants
       
  1487     else
       
  1488       for name, data in pairs(variants) do
       
  1489         variants[name]["weaponLimit"] = variants[name]["weaponLimit"] * strength
       
  1490         variants[name]["helperLimit"] = variants[name]["helperLimit"] * strength
       
  1491       end
       
  1492     end
       
  1493   end
       
  1494 
       
  1495   if params['luck'] ~= nil and tonumber(params['luck']) > 0 then
       
  1496     luck = tonumber(params['luck'])
       
  1497 
       
  1498     healthCrateChance = div(healthCrateChance * luck, 100)
       
  1499     utilCrateChance = div(utilCrateChance * luck, 100)
       
  1500     weaponCrateChance = div(weaponCrateChance * luck, 100)
       
  1501 
       
  1502     healthCrateChanceSD = div(healthCrateChanceSD * luck, 100)
       
  1503     utilCrateChanceSD = div(utilCrateChanceSD * luck, 100)
       
  1504     weaponCrateChanceSD = div(weaponCrateChanceSD * luck, 100)
       
  1505 
       
  1506     emptyCrateChance = div(emptyCrateChance * 100, luck)
       
  1507     bonusCrateChance = div(bonusCrateChance * luck, 100)
       
  1508   end
       
  1509 end
       
  1510 
       
  1511 function onGameStart()
       
  1512   -- If we are not on points mode, we start randomizing everything
       
  1513   if mode ~= 'points' then
       
  1514     if GetGameFlag(gfBorder) or MapHasBorder() then
       
  1515       variants["Air-General"] = nil
       
  1516       variants['Athlete'] = nil
       
  1517     end
       
  1518 
       
  1519     if mode == 'king' then
       
  1520       variants['King']['chance'] = 0
       
  1521     end
       
  1522 
       
  1523     for i=1,8 do
       
  1524       addRandomVariantToTeam("all")
       
  1525     end
       
  1526 
       
  1527     -- Translate randomized team to a flat group
       
  1528     group['all'] = {}
       
  1529     for key, val in pairs(counter["all"]) do
       
  1530       for i=1, counter["all"][key] do
       
  1531         table.insert(group['all'], key)
       
  1532       end
       
  1533     end
       
  1534 
       
  1535     -- Shuffle group for more randomness
       
  1536     shuffle(group['all'])
       
  1537   -- We are in points mode, setup other weapons
       
  1538   elseif mode == 'points' then
       
  1539     --variants['King']['chance'] = 0
       
  1540     --if variants['Air-General'] ~= nil then
       
  1541     --  variants['Air-General']['chance'] = 0
       
  1542     --end
       
  1543 
       
  1544     -- Translate [ammo] -> points to [points] -> {ammo1, ammo2}
       
  1545     for ammoType, ammoPoints in pairs(pointsWeaponVal) do
       
  1546       if pointsToWep[ammoPoints] == nil then
       
  1547         pointsToWep[ammoPoints] = {}
       
  1548       end
       
  1549 
       
  1550       table.insert(pointsToWep[ammoPoints], ammoType)
       
  1551     end
       
  1552 
       
  1553     for ammoType, ammoPoints in pairs(pointsHelperVal) do
       
  1554       if pointsToHlp[ammoPoints] == nil then
       
  1555         pointsToHlp[ammoPoints] = {}
       
  1556       end
       
  1557 
       
  1558       table.insert(pointsToHlp[ammoPoints], ammoType)
       
  1559     end
       
  1560 
       
  1561     for points, ammoList in pairs(pointsToWep) do
       
  1562       table.insert(wepPoints, points)
       
  1563     end
       
  1564 
       
  1565     for points, ammoList in pairs(pointsToHlp) do
       
  1566       table.insert(hlpPoints, points)
       
  1567     end
       
  1568 
       
  1569     table.sort(wepPoints)
       
  1570     table.sort(hlpPoints)
       
  1571 
       
  1572     -- All done, sort the table
       
  1573     --table.sort(pointsToWep)
       
  1574     --table.sort(pointsToHlp)
       
  1575   end
       
  1576 
       
  1577   -- Initial Hog Setup
       
  1578   runOnGears(countTeamHogs)
       
  1579 
       
  1580   for key, val in pairs(teamNames) do
       
  1581     if mode == 'points' then
       
  1582       pointsPerTeam[key] = {}
       
  1583       pointsPerTeam[key]['weapons'] = pointsWepBase
       
  1584       pointsPerTeam[key]['helpers'] = pointsHlpBase
       
  1585     else
       
  1586       setTeamHogs(key)
       
  1587     end
       
  1588   end
       
  1589 
       
  1590   runOnGears(setHogInfo)
       
  1591   
       
  1592   if mode ~= 'points' then
       
  1593     runOnGears(setHogVariant)
       
  1594     runOnGears(setupHogTurn)
       
  1595     if mutate ~= false and mutate ~= 'false' then
       
  1596       runOnGears(MutateHog)
       
  1597     end
       
  1598   end
       
  1599 
       
  1600   if mode == 'points' then
       
  1601     for key, val in pairs(teamNames) do
       
  1602       clearHogAmmo(teamHogs[key][1])
       
  1603       addTurnAmmo(teamHogs[key][1])
       
  1604     end
       
  1605   end
       
  1606 
       
  1607   if mode == 'king' then
       
  1608     calcKingHP()
       
  1609   end
       
  1610 
       
  1611   local txt = ''
       
  1612   local icon = 0
       
  1613 
       
  1614   if mode ~= 'points' then
       
  1615     txt = txt .. loc("Variants: Hogs will be randomized from 12 different variants|")
       
  1616     txt = txt .. loc("Weapon: Hogs will get 1 out of 3 weapons randomly each turn|")
       
  1617     txt = txt .. loc("Helper: Hogs will get 1 out of 2 helpers randomly each turn|")
       
  1618     txt = txt .. loc("Crates: Crates spawn randomly with chance of being empty|")
       
  1619     txt = txt .. loc("Hogs: Less than 25% base hp gives +Kamikaze|")
       
  1620     txt = txt .. loc("Flags: Unlimited Ammo, Per Hog Ammo|")
       
  1621   else
       
  1622     txt = txt .. loc("Crates: Crates spawn randomly with chance of being empty|")
       
  1623     txt = txt .. loc("Flags: Unlimited Ammo, Shared Team Ammo|")
       
  1624   end
       
  1625 
       
  1626   if luck ~= 100 then
       
  1627     txt = txt .. loc("Luck: ") .. luck .. loc("% (modifier for crates)|")
       
  1628   end
       
  1629 
       
  1630   if strength > 1 then
       
  1631     txt = txt .. loc("Strength: ") .. strength .. loc(" (multiplier for ammo)|")
       
  1632   end
       
  1633 
       
  1634   if mode == 'highland' then
       
  1635     txt = txt .. loc(" |")
       
  1636     txt = txt .. loc("--- Highland --- |")
       
  1637     txt = txt .. loc("Enemy kills: Collect victims weapons and + ") .. highEnemyKillHPBonus .. loc(" % of its base health|")
       
  1638     txt = txt .. loc("Friendly kills: Clears killers pool and - ") .. highFriendlyKillHPBonus .. loc(" % of its base health|")
       
  1639     txt = txt .. loc("Turns: Hogs get ") .. highPickupCount .. loc(" random weapon(s) from their pool|")
       
  1640     txt = txt .. loc("Hint: Kills wont transfer a hogs pool to the killers pool|")
       
  1641     txt = txt .. loc("Specials: Kings and Air-General drop helpers, not weapons|")
       
  1642     icon = 1 -- Target
       
  1643   elseif mode == 'king' then
       
  1644     txt = txt .. loc(" |")
       
  1645     txt = txt .. loc("--- King --- |")
       
  1646     txt = txt .. loc("Variants: The last hog of each team will be a king|")
       
  1647     txt = txt .. loc("Turns: Kings health are set to ") .. kingLinkPerc .. loc("% of the team health|")
       
  1648     icon = 0 -- Golen Crown
       
  1649   elseif mode == 'points' then
       
  1650     txt = txt .. loc(" |")
       
  1651     txt = txt .. loc("--- Points --- |")
       
  1652     txt = txt .. loc("Variants: Disables King and Air-General|")
       
  1653     txt = txt .. loc("Weapons: Every team starts with ") .. pointsWepBase .. loc(" weapon points|")
       
  1654     txt = txt .. loc("Helpers: Every team starts with ") .. pointsHlpBase .. loc(" helper points|")
       
  1655     txt = txt .. loc("Turns: Refills ") .. pointsWepTurn .. loc(" weapon and ") .. pointsHlpTurn .. loc(" helper points|")
       
  1656     txt = txt .. loc(" and randomizes weapons and helpers based on team points|")
       
  1657     icon = 4 -- Golden Star
       
  1658   else
       
  1659     icon = -amGrenade -- Grenade
       
  1660   end
       
  1661 
       
  1662   --txt = txt .. "Switch: Max. 3 times a game per team, cooldown of 5 turns|"
       
  1663   txt = txt .. loc(" |")
       
  1664   txt = txt .. loc("--- Sudden Death --- |")
       
  1665   txt = txt .. loc("Weapons: +Kamikaze, +1 for nearly every hog variant|")
       
  1666   txt = txt .. loc("Crates: Crates spawn more frequently with higher chance of bonus|")
       
  1667   txt = txt .. loc("Water: Rises by 37 per Round|")
       
  1668   txt = txt .. loc("Hogs: Loose up to 7% base hp per turn|")
       
  1669 
       
  1670   if mode == 'default' then
       
  1671     txt = txt .. loc(' |')
       
  1672     txt = txt .. loc('--- Hint ---|')
       
  1673     txt = txt .. loc('Modes: Activate highland, king or points mode by putting mode=<name>|')
       
  1674     txt = txt .. loc(' into the script params|')
       
  1675   end
       
  1676 
       
  1677   if mode == 'highland' then
       
  1678     txt = txt .. loc("Highland: Hogs get ") .. highPickupSDCount .. loc(" random weapons from their pool|")
       
  1679   end
       
  1680 
       
  1681   ShowMission(loc("Battalion v") .. version, loc("Less tools, more fun.") .. " (by Anachron)", txt, icon, 1000)
       
  1682 
       
  1683   -- Tell the user about the amount of rounds until sudden death
       
  1684   AddCaption(loc("SuddenDeathTurns set to ") .. (SuddenDeathTurns +2), 0x808080,  capgrpGameState)
       
  1685 end
       
  1686 
       
  1687 function onGameInit()
       
  1688   --[[ CONFIGURATEABLE FOR PLAYERS ]]--
       
  1689   --[[ ONCE IT HAS BEEN ADDED TO HW ]]--
       
  1690 
       
  1691   --[[ REQUIRED CONFIGURATIONS ]]--
       
  1692 
       
  1693   WaterRise = 37 -- Water rises by 37
       
  1694   HealthDecrease = 0 -- No health decrease by game, script with 7%
       
  1695   CaseFreq = 0 -- don't spawn crates
       
  1696 
       
  1697   -- Removed gfResetWeps to see weapons next turn
       
  1698   EnableGameFlags(gfInfAttack)
       
  1699   DisableGameFlags(gfResetWeps)
       
  1700 
       
  1701   if mode ~= 'points' then
       
  1702     EnableGameFlags(gfPerHogAmmo)
       
  1703   else
       
  1704     DisableGameFlags(gfPerHogAmmo)
       
  1705   end
       
  1706 end