share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua
changeset 10088 6d4cd54dd343
parent 10083 b20f9481e5cb
child 10096 51d6b80ba43c
equal deleted inserted replaced
10087:5ba891578621 10088:6d4cd54dd343
   110 					[amInvulnerable]=true, [amLaserSight]=true, [amVampiric]=true,
   110 					[amInvulnerable]=true, [amLaserSight]=true, [amVampiric]=true,
   111 					[amLowGravity]=true, [amExtraDamage]=true, [amExtraTime]=true,
   111 					[amLowGravity]=true, [amExtraDamage]=true, [amExtraTime]=true,
   112 					[amLandGun]=true, [amSwitch]=true, [amRubber]=true, [amIceGun]=true,
   112 					[amLandGun]=true, [amSwitch]=true, [amRubber]=true, [amIceGun]=true,
   113 					}
   113 					}
   114 
   114 
   115 local wepArray = 	{}
   115 local wepArray = {}
   116 
   116 
   117 local atkChoices = {}
   117 local atkChoices = {}
   118 local utilChoices = {}
   118 local utilChoices = {}
   119 
   119 
   120 local currHog
   120 local currHog
   123 local switchStage = 0
   123 local switchStage = 0
   124 
   124 
   125 local lastWep = amNothing
   125 local lastWep = amNothing
   126 local shotsFired = 0
   126 local shotsFired = 0
   127 
   127 
   128 local probability = {1,20,30,60,100,200,400,600,1000000};
   128 local probability = {1,2,5,10,20,50,200,500,1000000};
   129 local atktot = 0
   129 local atktot = 0
   130 local utiltot = 0
   130 local utiltot = 0
   131 local maxWep = 56 -- game crashes if you exceed supported #
   131 local maxWep = 56 -- game crashes if you exceed supported #
   132 
   132 
   133 local someHog = nil -- just for looking up the weps
   133 local someHog = nil -- just for looking up the weps
   156     for i = 1,maxWep do
   156     for i = 1,maxWep do
   157         setGearValue(gear,i,0)
   157         setGearValue(gear,i,0)
   158     end
   158     end
   159     for w,c in pairs(wepArray) do
   159     for w,c in pairs(wepArray) do
   160         if c == 9 then
   160         if c == 9 then
   161             setGearValue(gear,w,100)
   161             setGearValue(gear,w,1)
   162         end
   162         end
   163 	end
   163 	end
   164 
   164 
   165 	setGearValue(gear,amSkip,100)
   165 	setGearValue(gear,amSkip,100)
   166    
   166    
   167     local r = 0
   167     local r = 0
   168     if atktot > 0 then
   168     if atktot > 0 then
   169         r = GetRandom(atktot)+1
   169         r = GetRandom(atktot)+1
   170         for w,c in pairs(atkChoices) do
   170         for w,c in pairs(atkChoices) do
   171             WriteLnToConsole(' c: '..c..' w:'..w..' r:'..r)
   171             --WriteLnToConsole('     c: '..c..' w:'..w..' r:'..r)
   172             if c >= r then
   172             if c >= r then
   173                 setGearValue(gear,w,1)
   173                 setGearValue(gear,w,1)
   174                 break
   174                 break
   175             end
   175             end
   176         end
   176         end
   177     end
   177     end
   178     if utiltot > 0 then
   178     if utiltot > 0 then
   179         r = GetRandom(utiltot)+1
   179         r = GetRandom(utiltot)+1
   180         for w,c in pairs(utilChoices) do
   180         for w,c in pairs(utilChoices) do
       
   181             --WriteLnToConsole('util c: '..c..' w:'..w..' r:'..r)
   181             if c >= r then
   182             if c >= r then
   182                 setGearValue(gear,w,1)
   183                 setGearValue(gear,w,1)
   183                 break
   184                 break
   184             end
   185             end
   185         end
   186         end
   234 
   235 
   235 function onGameStart()
   236 function onGameStart()
   236     utilChoices[amSkip] = 0
   237     utilChoices[amSkip] = 0
   237     local c = 0
   238     local c = 0
   238     for i = 1,maxWep do
   239     for i = 1,maxWep do
       
   240         atkChoices[i] = 0
       
   241         utilChoices[i] = 0
   239         if i ~= 7 then
   242         if i ~= 7 then
   240             wepArray[i] = 0
   243             wepArray[i] = 0
   241             c = GetAmmoCount(someHog, i)
   244             c = GetAmmoCount(someHog, i)
   242             if c > 8 then c = 9 end
   245             if c > 8 then c = 9 end
   243             wepArray[i] = c
   246             wepArray[i] = c
   244             if c < 9 and c > 0 then
   247             if c < 9 and c > 0 then
   245                 if atkWeps[i] then
   248                 if atkWeps[i] then
       
   249                     --WriteLnToConsole('a    c: '..c..' w:'..i)
   246                     atktot = atktot + probability[c]
   250                     atktot = atktot + probability[c]
   247                     atkChoices[i] = atktot
   251                     atkChoices[i] = atktot
   248                 elseif utilWeps[i] then
   252                 elseif utilWeps[i] then
       
   253                     --WriteLnToConsole('u    c: '..c..' w:'..i)
   249                     utiltot = utiltot + probability[c]
   254                     utiltot = utiltot + probability[c]
   250                     utilChoices[i] = utiltot
   255                     utilChoices[i] = utiltot
   251                 end
   256                 end
   252             end
   257             end
   253         end
   258         end
   254     end
   259     end
   255 
   260 
   256     WriteLnToConsole('utiltot:'..utiltot..' atktot:'..atktot)
   261     --WriteLnToConsole('utiltot:'..utiltot..' atktot:'..atktot)
   257         
   262         
   258 	ShowMission	(
   263 	ShowMission	(
   259 				loc("HIGHLANDER"),
   264 				loc("HIGHLANDER"),
   260 				loc("Not all hogs are born equal."),
   265 				loc("Not all hogs are born equal."),
   261 
   266