share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua
changeset 13455 f38b72d64157
parent 13280 7ed4ab32f351
child 13456 7d69c5605a9d
equal deleted inserted replaced
13454:57de4f050891 13455:f38b72d64157
     1 --------------------------------
     1 --------------------------------
     2 -- HIGHLANDER / HOGS OF WAR
     2 -- HIGHLANDER / HOGS OF WAR
     3 -- by mikade
     3 -- by mikade
     4 --------------------------------
     4 --------------------------------
     5 
       
     6 -- Ancient changelog:
       
     7 
       
     8 -----------
       
     9 --0.1
       
    10 -----------
       
    11 
       
    12 -- concept test
       
    13 
       
    14 -----------
       
    15 --0.2
       
    16 -----------
       
    17 
       
    18 -- remove tardis till Henek fixes his tracker
       
    19 -- change wep crates to health crates
       
    20 -- reset arb turntimevalue
       
    21 -- include randomOrder
       
    22 -- Until fixed .17 methods come out, remove switches and resurrector
       
    23 -- on request, removed kamikaze and piano weapons
       
    24 -- provisional fixing of bugs that can't actually be fixed yet
       
    25 
       
    26 -----------
       
    27 --0.3
       
    28 -----------
       
    29 
       
    30 -- meh, update incorrect display
       
    31 -- may change this in the future to have switches
       
    32 -- but for now people are used to it without, so~
       
    33 
       
    34 -- mudball is now counted as a utility
       
    35 
       
    36 -----------
       
    37 --0.3b
       
    38 -----------
       
    39 
       
    40 -- cleaned up code and got rid of unneccessary vars
       
    41 -- mudball is a weapon again
       
    42 -- landgun is now a utility
       
    43 -- extra time, vampirism utility removed
       
    44 -- hammer wep removed
       
    45 -- all hogs have kamikaze
       
    46 
       
    47 -----------
       
    48 --0.3c
       
    49 -----------
       
    50 
       
    51 -- restructured some code
       
    52 -- added napalm (whoops) to list of possible weapons you can get
       
    53 -- hogs no longer recieve airstrike-related weps on border maps
       
    54 
       
    55 -----------
       
    56 --0.4
       
    57 -----------
       
    58 -- fix same name/blank weapon transfer bug (issue 541)
       
    59 -- show next hog ammo set in full (issue 312)
       
    60 -- allow mid-kill multi-shot weapon transfers (issue 503)
       
    61 -- allow users to configure hog health
       
    62 -- remove 'switched to' message
       
    63 -- remove some extraeneous code
       
    64 -- add more whitespace
       
    65 -- break everything
       
    66 
       
    67 -----------
       
    68 --0.4b
       
    69 -----------
       
    70 -- as per request, add ice-gun
       
    71 
     5 
    72 -------------------------
     6 -------------------------
    73 -- ideas for the future
     7 -- ideas for the future
    74 -------------------------
     8 -------------------------
    75 -- add structure
     9 -- add structure
    76 -- allow switcher, resurrector
    10 -- allow switcher, resurrector
    77 -- add abuse
       
    78 -- nerf teleport
    11 -- nerf teleport
    79 -- allow more customization
       
    80 -- poison hogs using the default team? :/
       
    81 -- balance weapon distribution across entire team / all teams
    12 -- balance weapon distribution across entire team / all teams
    82 -- add other inequalities/bonuses like... ???
    13 -- add other inequalities/bonuses like... ???
    83 -- some hogs start off with an extra 25 health?
    14 -- * some hogs start off with an extra 25 health?
    84 -- some hogs start off poisoned?
    15 -- * some hogs start off poisoned?
    85 -- some hogs start off with a rope and 2 drills but die after their turn?
    16 -- * some hogs start off with a rope and 2 drills but die after their turn?
    86 
    17 
    87 -------------------------------
    18 ------------------
    88 -- derp, script follows
    19 -- script follows
    89 -------------------------------
    20 ------------------
    90 
    21 
    91 HedgewarsScriptLoad("/Scripts/Locale.lua")
    22 HedgewarsScriptLoad("/Scripts/Locale.lua")
    92 HedgewarsScriptLoad("/Scripts/Tracker.lua")
    23 HedgewarsScriptLoad("/Scripts/Tracker.lua")
    93 HedgewarsScriptLoad("/Scripts/Params.lua")
    24 HedgewarsScriptLoad("/Scripts/Params.lua")
    94 
    25 
    95 -- These define weps allowed by the script.
    26 -- These define weps allowed by the script.
    96 -- These were arbitrarily defined out-of-order in initial script, so that was preserved here, resulting 
    27 -- These were arbitrarily defined out-of-order in initial script, so that was preserved here, resulting 
    97 -- in a moderately odd syntax.
    28 -- in a moderately odd syntax.
    98 local atkWeps = 	{
    29 local atkWeps = {
    99 					[amBazooka]=true, [amBee]=true, [amMortar]=true, [amDrill]=true, [amSnowball]=true,
    30 	[amBazooka]=true, [amBee]=true, [amMortar]=true, [amDrill]=true, [amSnowball]=true,
   100                     [amGrenade]=true, [amClusterBomb]=true, [amMolotov]=true, [amWatermelon]=true,
    31 	[amGrenade]=true, [amClusterBomb]=true, [amMolotov]=true, [amWatermelon]=true,
   101                     [amHellishBomb]=true, [amGasBomb]=true, [amShotgun]=true, [amDEagle]=true,
    32 	[amHellishBomb]=true, [amGasBomb]=true, [amShotgun]=true, [amDEagle]=true,
   102                     [amFlamethrower]=true, [amSniperRifle]=true, [amSineGun]=true, [amMinigun]=true,
    33 	[amFlamethrower]=true, [amSniperRifle]=true, [amSineGun]=true, [amMinigun]=true,
   103 					[amFirePunch]=true, [amWhip]=true, [amBaseballBat]=true, [amKamikaze]=true,
    34 	[amFirePunch]=true, [amWhip]=true, [amBaseballBat]=true, [amKamikaze]=true,
   104                     [amSeduction]=true, [amHammer]=true, [amMine]=true, [amDynamite]=true, [amCake]=true,
    35 	[amSeduction]=true, [amHammer]=true, [amMine]=true, [amDynamite]=true, [amCake]=true,
   105                     [amBallgun]=true, [amSMine]=true, [amRCPlane]=true, [amBirdy]=true, [amKnife]=true,
    36 	[amBallgun]=true, [amSMine]=true, [amRCPlane]=true, [amBirdy]=true, [amKnife]=true,
   106                     [amAirAttack]=true, [amMineStrike]=true, [amNapalm]=true, [amDrillStrike]=true, [amPiano]=true, [amAirMine] = true,
    37 	[amAirAttack]=true, [amMineStrike]=true, [amNapalm]=true, [amDrillStrike]=true, [amPiano]=true, [amAirMine] = true,
   107                     [amDuck]=true,
    38 	[amDuck]=true,
   108 					}
    39 }
   109 
    40 
   110 local utilWeps =  {
    41 local utilWeps =  {
   111 					[amBlowTorch]=true, [amPickHammer]=true, [amGirder]=true, [amPortalGun]=true,
    42 	[amBlowTorch]=true, [amPickHammer]=true, [amGirder]=true, [amPortalGun]=true,
   112 					[amRope]=true, [amParachute]=true, [amTeleport]=true, [amJetpack]=true,
    43 	[amRope]=true, [amParachute]=true, [amTeleport]=true, [amJetpack]=true,
   113 					[amInvulnerable]=true, [amLaserSight]=true, [amVampiric]=true,
    44 	[amInvulnerable]=true, [amLaserSight]=true, [amVampiric]=true,
   114 					[amLowGravity]=true, [amExtraDamage]=true, [amExtraTime]=true,
    45 	[amLowGravity]=true, [amExtraDamage]=true, [amExtraTime]=true,
   115 					[amLandGun]=true, [amRubber]=true, [amIceGun]=true,
    46 	[amLandGun]=true, [amRubber]=true, [amIceGun]=true,
   116 					}
    47 }
   117 
    48 
   118 -- Intentionally left out:
    49 -- Intentionally left out:
   119 -- * Resurrector (guaranteed to screw up the game)
    50 -- * Resurrector (guaranteed to screw up the game)
   120 -- * Time Box
    51 -- * Time Box
   121 -- * Switch Hedgehog (not sure why)
    52 -- * Switch Hedgehog (not sure why)
   157 turn by killing enemies in a clever way.
    88 turn by killing enemies in a clever way.
   158 We need to distinguish between your current inventory and the “reset inventory”,
    89 We need to distinguish between your current inventory and the “reset inventory”,
   159 that is, the state to which your inventory will get reset in the next turn.
    90 that is, the state to which your inventory will get reset in the next turn.
   160 
    91 
   161 No Multi-Use (default):
    92 No Multi-Use (default):
   162     If you kill a hog who owns a weapon you currently have in your reset inventory,
    93 	If you kill a hog who owns a weapon you currently have in your reset inventory,
   163     but not your inventory, you DO NOT get this weapon again.
    94 	but not your inventory, you DO NOT get this weapon again.
   164 
    95 
   165 Multi-Use:
    96 Multi-Use:
   166     If you kill a hog who owns a weapon you currently have in your reset inventory,
    97 	If you kill a hog who owns a weapon you currently have in your reset inventory,
   167     but not your inventory, you DO get this weapon.
    98 	but not your inventory, you DO get this weapon.
   168 
    99 
   169 Example 1:
   100 Example 1:
   170     You have a ballgun, and use it to kill a hog who also owns a ballgun.
   101 	You have a ballgun, and use it to kill a hog who also owns a ballgun.
   171     No Multi-Use: You will NOT get another ballgun, since it's in your
   102 	No Multi-Use: You will NOT get another ballgun, since it's in your
   172                   reset inventory.
   103 	reset inventory.
   173     Multi-Use: You get another ballgun.
   104 	Multi-Use: You get another ballgun.
   174 
   105 
   175 Example 2:
   106 Example 2:
   176     You have a grenade and a bazooka in your inventory. You use the bazooka
   107 	You have a grenade and a bazooka in your inventory. You use the bazooka
   177     to kill a hedgehog who owns a grenade.
   108 	to kill a hedgehog who owns a grenade.
   178     In both ammo limit modes, you do NOT win any ammo since you already have
   109 	In both ammo limit modes, you do NOT win any ammo since you already have
   179     a grenade in your inventory (not just your reset inventory), and the
   110 	a grenade in your inventory (not just your reset inventory), and the
   180     rule “no more than 1 ammo per type” applies.
   111 	rule “no more than 1 ammo per type” applies.
   181 ]]
   112 ]]
   182 local multiUse = false
   113 local multiUse = false
   183 
   114 
   184 function onParameters()
   115 function onParameters()
   185     parseParams()
   116 	parseParams()
   186     multiUse = params["multiuse"] == "true"
   117 	multiUse = params["multiuse"] == "true"
   187     loyal = params["loyal"] == "true"
   118 	loyal = params["loyal"] == "true"
   188 end
   119 end
   189 
   120 
   190 function CheckForWeaponSwap()
   121 function CheckForWeaponSwap()
   191 	if GetCurAmmoType() ~= lastWep then
   122 	if GetCurAmmoType() ~= lastWep then
   192 		shotsFired = 0
   123 		shotsFired = 0
   206 	CheckForWeaponSwap()
   137 	CheckForWeaponSwap()
   207 	shotsFired = shotsFired + 1
   138 	shotsFired = shotsFired + 1
   208 end
   139 end
   209 
   140 
   210 function StartingSetUp(gear)
   141 function StartingSetUp(gear)
   211     for i = 0, AmmoTypeMax do
   142 	for i = 0, AmmoTypeMax do
   212         if i ~= amNothing then
   143 		if i ~= amNothing then
   213             setGearValue(gear,i,0)
   144 			setGearValue(gear,i,0)
   214         end
   145 		end
   215     end
   146 	end
   216     for w,c in pairs(wepArray) do
   147 	for w,c in pairs(wepArray) do
   217         if c == 9 and (atkWeps[w] or utilWeps[w])  then
   148 		if c == 9 and (atkWeps[w] or utilWeps[w])  then
   218             setGearValue(gear,w,1)
   149 			setGearValue(gear,w,1)
   219         end
   150 		end
   220 	end
   151 	end
   221 
   152 
   222 	setGearValue(gear,amSkip,100)
   153 	setGearValue(gear,amSkip,100)
   223    
   154    
   224     local r = 0
   155 	local r = 0
   225     if atktot > 0 then
   156 	if atktot > 0 then
   226         r = GetRandom(atktot)+1
   157 		r = GetRandom(atktot)+1
   227         for i = 0, AmmoTypeMax do
   158 		for i = 0, AmmoTypeMax do
   228             if i ~= amNothing then
   159 			if i ~= amNothing then
   229                 if atkChoices[i] >= r then
   160 				if atkChoices[i] >= r then
   230                     setGearValue(gear,i,1)
   161 					setGearValue(gear,i,1)
   231                     break
   162 					break
   232                 end
   163 				end
   233             end
   164 			end
   234         end
   165 		end
   235     end
   166 	end
   236     if utiltot > 0 then
   167 	if utiltot > 0 then
   237         r = GetRandom(utiltot)+1
   168 		r = GetRandom(utiltot)+1
   238         for i = 0, AmmoTypeMax do
   169 		for i = 0, AmmoTypeMax do
   239             if i ~= amNothing then
   170 			if i ~= amNothing then
   240                 if utilChoices[i] >= r then
   171 				if utilChoices[i] >= r then
   241                     setGearValue(gear,i,1)
   172 					setGearValue(gear,i,1)
   242                     break
   173 					break
   243                 end
   174 				end
   244             end
   175 			end
   245         end
   176 		end
   246     end
   177 	end
   247 end
   178 end
   248 
       
   249 --[[function SaveWeapons(gear)
       
   250 -- er, this has no 0 check so presumably if you use a weapon then when it saves  you wont have it
       
   251 
       
   252 	for i = 1, (#wepArray) do
       
   253 		setGearValue(gear, wepArray[i], GetAmmoCount(gear, wepArray[i]) )
       
   254 		 --AddAmmo(gear, wepArray[i], getGearValue(gear,wepArray[i]) )
       
   255 	end
       
   256 
       
   257 end]]
       
   258 
   179 
   259 function ConvertValues(gear)
   180 function ConvertValues(gear)
   260     for w,c in pairs(wepArray) do
   181 	for w,c in pairs(wepArray) do
   261 		AddAmmo(gear, w, getGearValue(gear,w) )
   182 		AddAmmo(gear, w, getGearValue(gear,w) )
   262     end
   183 	end
   263 end
   184 end
   264 
   185 
   265 -- this is called when a hog dies
   186 -- this is called when a hog dies
   266 function TransferWeps(gear)
   187 function TransferWeps(gear)
   267 
   188 
   268 	if CurrentHedgehog ~= nil and CurrentHedgehog ~= gear and (not loyal or (GetHogClan(CurrentHedgehog) ~= GetHogClan(gear))) then
   189 	if CurrentHedgehog ~= nil and CurrentHedgehog ~= gear and (not loyal or (GetHogClan(CurrentHedgehog) ~= GetHogClan(gear))) then
   269 
   190 
   270         local x,y,color
   191 		local x,y,color
   271         local vgear
   192 		local vgear
   272         local vgtX, vgtY, vgtdX, vgtdY, vgtAngle, vgtFrame, vgtFrameTicks, vgtState, vgtTimer, vgtTint
   193 		local vgtX, vgtY, vgtdX, vgtdY, vgtAngle, vgtFrame, vgtFrameTicks, vgtState, vgtTimer, vgtTint
   273         local dspl = IsHogLocal(CurrentHedgehog)
   194 		local dspl = IsHogLocal(CurrentHedgehog)
   274         local ammolist = ''
   195 		local ammolist = ''
   275 
   196 
   276         if dspl then
   197 		if dspl then
   277             x,y = GetGearPosition(CurrentHedgehog)
   198 			x,y = GetGearPosition(CurrentHedgehog)
   278             color = GetClanColor(GetHogClan(CurrentHedgehog))
   199 			color = GetClanColor(GetHogClan(CurrentHedgehog))
   279         end
   200 		end
   280 
   201 
   281         for w,c in pairs(wepArray) do
   202 		for w,c in pairs(wepArray) do
   282 			val = getGearValue(gear,w)
   203 			val = getGearValue(gear,w)
   283 			if val ~= 0 and (multiUse or (wepArray[w] ~= 9 and getGearValue(CurrentHedgehog, w) == 0))  then
   204 			if val ~= 0 and (multiUse or (wepArray[w] ~= 9 and getGearValue(CurrentHedgehog, w) == 0))  then
   284 				setGearValue(CurrentHedgehog, w, val)
   205 				setGearValue(CurrentHedgehog, w, val)
   285 
   206 
   286 				-- if you are using multi-shot weapon, gimme one more
   207 				-- if you are using multi-shot weapon, gimme one more
   288 					AddAmmo(CurrentHedgehog, w, val+1)
   209 					AddAmmo(CurrentHedgehog, w, val+1)
   289 				-- assign ammo as per normal
   210 				-- assign ammo as per normal
   290 				else
   211 				else
   291 					AddAmmo(CurrentHedgehog, w, val)
   212 					AddAmmo(CurrentHedgehog, w, val)
   292 				end
   213 				end
   293                 if dspl then
   214 				if dspl then
   294                     if ammolist == '' then
   215 					if ammolist == '' then
   295                         ammolist = GetAmmoName(w)
   216 						ammolist = GetAmmoName(w)
   296                     else
   217 					else
   297                         ammolist = ammolist .. ' • ' .. GetAmmoName(w)
   218 						ammolist = ammolist .. ' • ' .. GetAmmoName(w)
   298                     end
   219 					end
   299                     x = x + 2
   220 					x = x + 2
   300                     y = y + 32
   221 					y = y + 32
   301                     vgear = AddVisualGear(x, y, vgtAmmo, 0, true)
   222 					vgear = AddVisualGear(x, y, vgtAmmo, 0, true)
   302                     if vgear ~= nil then
   223 					if vgear ~= nil then
   303                         vgtX,vgtY,vgtdX,vgtdY,vgtAngle,vgtFrame,vgtFrameTicks,vgtState,vgtTimer,vgtTint = GetVisualGearValues(vgear)
   224 						vgtX,vgtY,vgtdX,vgtdY,vgtAngle,vgtFrame,vgtFrameTicks,vgtState,vgtTimer,vgtTint = GetVisualGearValues(vgear)
   304                         vgtFrame = w
   225 						vgtFrame = w
   305                         SetVisualGearValues(vgear,vgtX,vgtY,vgtdX,vgtdY,vgtAngle,vgtFrame,vgtFrameTicks,vgtState,vgtTimer,vgtTint)
   226 						SetVisualGearValues(vgear,vgtX,vgtY,vgtdX,vgtdY,vgtAngle,vgtFrame,vgtFrameTicks,vgtState,vgtTimer,vgtTint)
   306                     end
   227 					end
   307                 end
   228 				end
   308 
   229 
   309 			end
   230 			end
   310 		end
   231 		end
   311 
   232 
   312         if dspl and ammolist ~= '' then
   233 		if dspl and ammolist ~= '' then
   313             PlaySound(sndShotgunReload);
   234 			PlaySound(sndShotgunReload);
   314             AddCaption(ammolist, color, capgrpAmmoinfo)
   235 			AddCaption(ammolist, color, capgrpAmmoinfo)
   315         end
   236 		end
   316 	end
   237 	end
   317 
   238 
   318 end
   239 end
   319 
   240 
   320 function onGameInit()
   241 function onGameInit()
   334 		Goals = Goals .. loc("No Multi-Use: Once you used an ammo, you can’t take it again in this turn")
   255 		Goals = Goals .. loc("No Multi-Use: Once you used an ammo, you can’t take it again in this turn")
   335 	end
   256 	end
   336 end
   257 end
   337 
   258 
   338 function onGameStart()
   259 function onGameStart()
   339     utilChoices[amSkip] = 0
   260 	utilChoices[amSkip] = 0
   340     local c = 0
   261 	local c = 0
   341     for i = 0, AmmoTypeMax do
   262 	for i = 0, AmmoTypeMax do
   342         if i ~= amNothing then
   263 		if i ~= amNothing then
   343             atkChoices[i] = 0
   264 			atkChoices[i] = 0
   344             utilChoices[i] = 0
   265 			utilChoices[i] = 0
   345             if i ~= 7 then
   266 			if i ~= 7 then
   346                 wepArray[i] = 0
   267 				wepArray[i] = 0
   347                 c = GetAmmoCount(someHog, i)
   268 				c = GetAmmoCount(someHog, i)
   348                 if c > 8 then c = 9 end
   269 				if c > 8 then
   349                 wepArray[i] = c
   270 					c = 9
   350                 if c < 9 and c > 0 then
   271 				end
   351                     if atkWeps[i] then
   272 				wepArray[i] = c
   352                         --WriteLnToConsole('a    c: '..c..' w:'..i)
   273 				if c < 9 and c > 0 then
   353                         atktot = atktot + probability[c]
   274 					if atkWeps[i] then
   354                         atkChoices[i] = atktot
   275 						atktot = atktot + probability[c]
   355                     elseif utilWeps[i] then
   276 						atkChoices[i] = atktot
   356                         --WriteLnToConsole('u    c: '..c..' w:'..i)
   277 					elseif utilWeps[i] then
   357                             utiltot = utiltot + probability[c]
   278 						utiltot = utiltot + probability[c]
   358                         utilChoices[i] = utiltot
   279 						utilChoices[i] = utiltot
   359                     end
   280 					end
   360                 end
   281 				end
   361             end
   282 			end
   362         end
   283 		end
   363     end
   284 	end
   364 
       
   365     --WriteLnToConsole('utiltot:'..utiltot..' atktot:'..atktot)
       
   366         
       
   367 
   285 
   368 	runOnGears(StartingSetUp)
   286 	runOnGears(StartingSetUp)
   369 	runOnGears(ConvertValues)
   287 	runOnGears(ConvertValues)
   370 end
   288 end
   371 
   289 
   400 
   318 
   401 function onNewTurn()
   319 function onNewTurn()
   402 	CheckForHogSwitch()
   320 	CheckForHogSwitch()
   403 end
   321 end
   404 
   322 
   405 --function onGameTick20()
       
   406 --CheckForHogSwitch()
       
   407 -- if we use gfPerHogAmmo is this even needed? Err, well, weapons reset, so... yes?
       
   408 -- orrrr, should we rather call the re-assignment of weapons onNewTurn()? probably not because
       
   409 -- then you cant switch hogs... unless we add a thing in onSwitch or whatever
       
   410 -- ye, that is probably better actually, but I'll add that when/if I add switch
       
   411 --end
       
   412 
       
   413 --[[function onHogHide(gear)
       
   414 	-- waiting for Henek
       
   415 end
       
   416 
       
   417 function onHogRestore(gear)
       
   418 	-- waiting for Henek
       
   419 end]]
       
   420 
       
   421 function onGearAdd(gear)
   323 function onGearAdd(gear)
   422 
       
   423 	--if GetGearType(gear) == gtSwitcher then
       
   424 	--	SaveWeapons(CurrentHedgehog)
       
   425 	--end
       
   426 
   324 
   427 	if (GetGearType(gear) == gtHedgehog) then
   325 	if (GetGearType(gear) == gtHedgehog) then
   428 		trackGear(gear)
   326 		trackGear(gear)
   429         if someHog == nil then someHog = gear end
   327 		if someHog == nil then
       
   328 			someHog = gear
       
   329 		end
   430 	end
   330 	end
   431 
   331 
   432 end
   332 end
   433 
   333 
   434 function onGearDelete(gear)
   334 function onGearDelete(gear)
   435 
   335 
   436 	if (GetGearType(gear) == gtHedgehog) then --or (GetGearType(gear) == gtResurrector) then
   336 	if (GetGearType(gear) == gtHedgehog) then
   437 		TransferWeps(gear)
   337 		TransferWeps(gear)
   438 		trackDeletion(gear)
   338 		trackDeletion(gear)
   439 	end
   339 	end
   440 
   340 
   441 end
   341 end