share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua
changeset 12302 f7919a4df898
parent 12206 1e3ab1e634f8
child 12308 82951b9b3c2f
equal deleted inserted replaced
12301:46e1e25fec5e 12302:f7919a4df898
   127 local shotsFired = 0
   127 local shotsFired = 0
   128 
   128 
   129 local probability = {1,2,5,10,20,50,200,500,1000000};
   129 local probability = {1,2,5,10,20,50,200,500,1000000};
   130 local atktot = 0
   130 local atktot = 0
   131 local utiltot = 0
   131 local utiltot = 0
   132 local maxWep = 58 -- game crashes if you exceed supported #
       
   133 
   132 
   134 local someHog = nil -- just for looking up the weps
   133 local someHog = nil -- just for looking up the weps
   135 
   134 
   136 local mode = nil
   135 local mode = nil
   137 
   136 
   159 	CheckForWeaponSwap()
   158 	CheckForWeaponSwap()
   160 	shotsFired = shotsFired + 1
   159 	shotsFired = shotsFired + 1
   161 end
   160 end
   162 
   161 
   163 function StartingSetUp(gear)
   162 function StartingSetUp(gear)
   164     for i = 1,maxWep do
   163     for i = 0, AmmoTypeMax do
   165         setGearValue(gear,i,0)
   164         if i ~= amNothing then
       
   165             setGearValue(gear,i,0)
       
   166         end
   166     end
   167     end
   167     for w,c in pairs(wepArray) do
   168     for w,c in pairs(wepArray) do
   168         if c == 9 and (atkWeps[w] or utilWeps[w])  then
   169         if c == 9 and (atkWeps[w] or utilWeps[w])  then
   169             setGearValue(gear,w,1)
   170             setGearValue(gear,w,1)
   170         end
   171         end
   173 	setGearValue(gear,amSkip,100)
   174 	setGearValue(gear,amSkip,100)
   174    
   175    
   175     local r = 0
   176     local r = 0
   176     if atktot > 0 then
   177     if atktot > 0 then
   177         r = GetRandom(atktot)+1
   178         r = GetRandom(atktot)+1
   178         for i = 1,maxWep do
   179         for i = 0, AmmoTypeMax do
   179         --for w,c in pairs(atkChoices) do
   180             if i ~= amNothing then
   180             --WriteLnToConsole('     c: '..c..' w:'..w..' r:'..r)
   181                 if atkChoices[i] >= r then
   181             if atkChoices[i] >= r then
   182                     setGearValue(gear,i,1)
   182                 setGearValue(gear,i,1)
   183                     break
   183                 break
   184                 end
   184             end
   185             end
   185         end
   186         end
   186     end
   187     end
   187     if utiltot > 0 then
   188     if utiltot > 0 then
   188         r = GetRandom(utiltot)+1
   189         r = GetRandom(utiltot)+1
   189         for i = 1,maxWep do
   190         for i = 0, AmmoTypeMax do
   190        -- for w,c in pairs(utilChoices) do
   191             if i ~= amNothing then
   191             --WriteLnToConsole('util c: '..c..' w:'..w..' r:'..r)
   192                 if utilChoices[i] >= r then
   192             if utilChoices[i] >= r then
   193                     setGearValue(gear,i,1)
   193                 setGearValue(gear,i,1)
   194                     break
   194                 break
   195                 end
   195             end
   196             end
   196         end
   197         end
   197     end
   198     end
   198 end
   199 end
   199 
   200 
   277 end
   278 end
   278 
   279 
   279 function onGameStart()
   280 function onGameStart()
   280     utilChoices[amSkip] = 0
   281     utilChoices[amSkip] = 0
   281     local c = 0
   282     local c = 0
   282     for i = 1,maxWep do
   283     for i = 0, AmmoTypeMax do
   283         atkChoices[i] = 0
   284         if i ~= amNothing then
   284         utilChoices[i] = 0
   285             atkChoices[i] = 0
   285         if i ~= 7 then
   286             utilChoices[i] = 0
   286             wepArray[i] = 0
   287             if i ~= 7 then
   287             c = GetAmmoCount(someHog, i)
   288                 wepArray[i] = 0
   288             if c > 8 then c = 9 end
   289                 c = GetAmmoCount(someHog, i)
   289             wepArray[i] = c
   290                 if c > 8 then c = 9 end
   290             if c < 9 and c > 0 then
   291                 wepArray[i] = c
   291                 if atkWeps[i] then
   292                 if c < 9 and c > 0 then
   292                     --WriteLnToConsole('a    c: '..c..' w:'..i)
   293                     if atkWeps[i] then
   293                     atktot = atktot + probability[c]
   294                         --WriteLnToConsole('a    c: '..c..' w:'..i)
   294                     atkChoices[i] = atktot
   295                         atktot = atktot + probability[c]
   295                 elseif utilWeps[i] then
   296                         atkChoices[i] = atktot
   296                     --WriteLnToConsole('u    c: '..c..' w:'..i)
   297                     elseif utilWeps[i] then
   297                     utiltot = utiltot + probability[c]
   298                         --WriteLnToConsole('u    c: '..c..' w:'..i)
   298                     utilChoices[i] = utiltot
   299                             utiltot = utiltot + probability[c]
       
   300                         utilChoices[i] = utiltot
       
   301                     end
   299                 end
   302                 end
   300             end
   303             end
   301         end
   304         end
   302     end
   305     end
   303 
   306