# HG changeset patch # User Wuzzy # Date 1492880305 -7200 # Node ID f7919a4df8986cdeb25d0177ee2ee554e6362b0f # Parent 46e1e25fec5e4f6b0dd8632479e0b7bcef2f8d65 Replace hardcoded max. ammo index in Highlander with AmmoTypeMax diff -r 46e1e25fec5e -r f7919a4df898 share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua --- a/share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua Sat Apr 22 18:36:57 2017 +0200 +++ b/share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua Sat Apr 22 18:58:25 2017 +0200 @@ -129,7 +129,6 @@ local probability = {1,2,5,10,20,50,200,500,1000000}; local atktot = 0 local utiltot = 0 -local maxWep = 58 -- game crashes if you exceed supported # local someHog = nil -- just for looking up the weps @@ -161,8 +160,10 @@ end function StartingSetUp(gear) - for i = 1,maxWep do - setGearValue(gear,i,0) + for i = 0, AmmoTypeMax do + if i ~= amNothing then + setGearValue(gear,i,0) + end end for w,c in pairs(wepArray) do if c == 9 and (atkWeps[w] or utilWeps[w]) then @@ -175,23 +176,23 @@ local r = 0 if atktot > 0 then r = GetRandom(atktot)+1 - for i = 1,maxWep do - --for w,c in pairs(atkChoices) do - --WriteLnToConsole(' c: '..c..' w:'..w..' r:'..r) - if atkChoices[i] >= r then - setGearValue(gear,i,1) - break + for i = 0, AmmoTypeMax do + if i ~= amNothing then + if atkChoices[i] >= r then + setGearValue(gear,i,1) + break + end end end end if utiltot > 0 then r = GetRandom(utiltot)+1 - for i = 1,maxWep do - -- for w,c in pairs(utilChoices) do - --WriteLnToConsole('util c: '..c..' w:'..w..' r:'..r) - if utilChoices[i] >= r then - setGearValue(gear,i,1) - break + for i = 0, AmmoTypeMax do + if i ~= amNothing then + if utilChoices[i] >= r then + setGearValue(gear,i,1) + break + end end end end @@ -279,23 +280,25 @@ function onGameStart() utilChoices[amSkip] = 0 local c = 0 - for i = 1,maxWep do - atkChoices[i] = 0 - utilChoices[i] = 0 - if i ~= 7 then - wepArray[i] = 0 - c = GetAmmoCount(someHog, i) - if c > 8 then c = 9 end - wepArray[i] = c - if c < 9 and c > 0 then - if atkWeps[i] then - --WriteLnToConsole('a c: '..c..' w:'..i) - atktot = atktot + probability[c] - atkChoices[i] = atktot - elseif utilWeps[i] then - --WriteLnToConsole('u c: '..c..' w:'..i) - utiltot = utiltot + probability[c] - utilChoices[i] = utiltot + for i = 0, AmmoTypeMax do + if i ~= amNothing then + atkChoices[i] = 0 + utilChoices[i] = 0 + if i ~= 7 then + wepArray[i] = 0 + c = GetAmmoCount(someHog, i) + if c > 8 then c = 9 end + wepArray[i] = c + if c < 9 and c > 0 then + if atkWeps[i] then + --WriteLnToConsole('a c: '..c..' w:'..i) + atktot = atktot + probability[c] + atkChoices[i] = atktot + elseif utilWeps[i] then + --WriteLnToConsole('u c: '..c..' w:'..i) + utiltot = utiltot + probability[c] + utilChoices[i] = utiltot + end end end end