Make highlander configurable using weapons, commit weaponset mimicking old values
authornemo
Mon, 27 Jan 2014 23:44:28 -0500
changeset 10083 b20f9481e5cb
parent 10082 2f7b7992258f
child 10084 83156a03e574
Make highlander configurable using weapons, commit weaponset mimicking old values
QTfrontend/hwconsts.cpp.in
QTfrontend/weapons.h
share/hedgewars/Data/Scripts/Multiplayer/Highlander.cfg
share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua
--- a/QTfrontend/hwconsts.cpp.in	Mon Jan 27 23:42:20 2014 -0500
+++ b/QTfrontend/hwconsts.cpp.in	Mon Jan 27 23:44:28 2014 -0500
@@ -67,6 +67,9 @@
         << qMakePair(QString("One of Everything"), QString(
             AMMOLINE_ONEEVERY_QT AMMOLINE_ONEEVERY_PROB
             AMMOLINE_ONEEVERY_DELAY AMMOLINE_ONEEVERY_CRATE ))
+        << qMakePair(QString("Highlander"), QString(
+            AMMOLINE_HIGHLANDER_QT AMMOLINE_HIGHLANDER_PROB
+            AMMOLINE_HIGHLANDER_DELAY AMMOLINE_HIGHLANDER_CRATE ))
         ;
 
 unsigned int colors[] = HW_TEAMCOLOR_ARRAY;
--- a/QTfrontend/weapons.h	Mon Jan 27 23:42:20 2014 -0500
+++ b/QTfrontend/weapons.h	Mon Jan 27 23:44:28 2014 -0500
@@ -62,6 +62,11 @@
 #define AMMOLINE_ONEEVERY_DELAY "00000000000000000000000000000000000000000000000000000000"
 #define AMMOLINE_ONEEVERY_CRATE "11111101111111111111111111111111111111111111111111111111"
 
+#define AMMOLINE_HIGHLANDER_QT    "11111191111111111111119111111111111111111111111111101101"
+#define AMMOLINE_HIGHLANDER_PROB  "00000000000000000000000000000000000000000000000000000000"
+#define AMMOLINE_HIGHLANDER_DELAY "00000000000000000000000000000000000000000000000000000000"
+#define AMMOLINE_HIGHLANDER_CRATE "00000000000000000000000000000000000000000000000000000000"
+
 //When adding new weapons also insert one element in cDefaultAmmos list (hwconsts.cpp.in)
 
 
--- a/share/hedgewars/Data/Scripts/Multiplayer/Highlander.cfg	Mon Jan 27 23:42:20 2014 -0500
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Highlander.cfg	Mon Jan 27 23:44:28 2014 -0500
@@ -1,2 +1,2 @@
 Default
-locked
+Highlander
--- a/share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua	Mon Jan 27 23:42:20 2014 -0500
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Highlander.lua	Mon Jan 27 23:44:28 2014 -0500
@@ -90,29 +90,33 @@
 HedgewarsScriptLoad("/Scripts/Locale.lua")
 HedgewarsScriptLoad("/Scripts/Tracker.lua")
 
-local airWeapons = 	{amAirAttack, amMineStrike, amNapalm, amDrillStrike --[[,amPiano]]}
-
-local atkArray = 	{
-					amBazooka, amBee, amMortar, amDrill, --[[amSnowball,]]
-					amGrenade, amClusterBomb, amMolotov, amWatermelon, amHellishBomb, amGasBomb,
-					amShotgun, amDEagle, amFlamethrower, amSniperRifle, amSineGun, amIceGun,
-					amFirePunch, amWhip, amBaseballBat, --[[amKamikaze,]] amSeduction, --[[amHammer,]]
-					amMine, amDynamite, amCake, amBallgun, amRCPlane, amSMine,
-					amRCPlane, amSMine,
-					amBirdy
+-- These define weps allowed by the script. At present Tardis and Resurrection is banned for example
+-- These were arbitrarily defined out-of-order in initial script, so that was preserved here, resulting 
+-- in a moderately odd syntax.
+local atkWeps = 	{
+					[amBazooka]=true, [amBee]=true, [amMortar]=true, [amDrill]=true, [amSnowball]=true,
+                    [amGrenade]=true, [amClusterBomb]=true, [amMolotov]=true, [amWatermelon]=true,
+                    [amHellishBomb]=true, [amGasBomb]=true, [amShotgun]=true, [amDEagle]=true,
+                    [amFlamethrower]=true, [amSniperRifle]=true, [amSineGun]=true, 
+					[amFirePunch]=true, [amWhip]=true, [amBaseballBat]=true, [amKamikaze]=true,
+                    [amSeduction]=true, [amHammer]=true, [amMine]=true, [amDynamite]=true, [amCake]=true,
+                    [amBallgun]=true, [amSMine]=true, [amRCPlane]=true, [amBirdy]=true, [amKnife]=true,
+                    [amAirAttack]=true, [amMineStrike]=true, [amNapalm]=true, [amDrillStrike]=true, [amPiano]=true
 					}
 
-local utilArray = 	{
-					amBlowTorch, amPickHammer, amGirder, amPortalGun,
-					amRope, amParachute, amTeleport, amJetpack,
-					amInvulnerable, amLaserSight, --[[amVampiric,]]
-					amLowGravity, amExtraDamage, --[[amExtraTime,]]
-					amLandGun
-					--[[,amTardis, amResurrector, amSwitch]]
+local utilWeps =  {
+					[amBlowTorch]=true, [amPickHammer]=true, [amGirder]=true, [amPortalGun]=true,
+					[amRope]=true, [amParachute]=true, [amTeleport]=true, [amJetpack]=true,
+					[amInvulnerable]=true, [amLaserSight]=true, [amVampiric]=true,
+					[amLowGravity]=true, [amExtraDamage]=true, [amExtraTime]=true,
+					[amLandGun]=true, [amSwitch]=true, [amRubber]=true, [amIceGun]=true,
 					}
 
 local wepArray = 	{}
 
+local atkChoices = {}
+local utilChoices = {}
+
 local currHog
 local lastHog
 local started = false
@@ -121,6 +125,13 @@
 local lastWep = amNothing
 local shotsFired = 0
 
+local probability = {1,20,30,60,100,200,400,600,1000000};
+local atktot = 0
+local utiltot = 0
+local maxWep = 56 -- game crashes if you exceed supported #
+
+local someHog = nil -- just for looking up the weps
+
 function CheckForWeaponSwap()
 	if GetCurAmmoType() ~= lastWep then
 		shotsFired = 0
@@ -142,20 +153,37 @@
 end
 
 function StartingSetUp(gear)
-
-	for i = 1, #wepArray do
-		setGearValue(gear,wepArray[i],0)
+    for i = 1,maxWep do
+        setGearValue(gear,i,0)
+    end
+    for w,c in pairs(wepArray) do
+        if c == 9 then
+            setGearValue(gear,w,100)
+        end
 	end
 
-	setGearValue(gear,amKamikaze,100)
 	setGearValue(gear,amSkip,100)
-
-	i = 1 + GetRandom(#atkArray)
-	setGearValue(gear,atkArray[i],1)
-
-	i = 1 + GetRandom(#utilArray)
-	setGearValue(gear,utilArray[i],1)
-
+   
+    local r = 0
+    if atktot > 0 then
+        r = GetRandom(atktot)+1
+        for w,c in pairs(atkChoices) do
+            WriteLnToConsole(' c: '..c..' w:'..w..' r:'..r)
+            if c >= r then
+                setGearValue(gear,w,1)
+                break
+            end
+        end
+    end
+    if utiltot > 0 then
+        r = GetRandom(utiltot)+1
+        for w,c in pairs(utilChoices) do
+            if c >= r then
+                setGearValue(gear,w,1)
+                break
+            end
+        end
+    end
 end
 
 --[[function SaveWeapons(gear)
@@ -169,11 +197,9 @@
 end]]
 
 function ConvertValues(gear)
-
-	for i = 1, #wepArray do
-		AddAmmo(gear, wepArray[i], getGearValue(gear,wepArray[i]) )
-	end
-
+    for w,c in pairs(wepArray) do
+		AddAmmo(gear, w, getGearValue(gear,w) )
+    end
 end
 
 -- this is called when a hog dies
@@ -181,18 +207,17 @@
 
 	if CurrentHedgehog ~= nil then
 
-		for i = 1, #wepArray do
-			val = getGearValue(gear,wepArray[i])
+        for w,c in pairs(wepArray) do
+			val = getGearValue(gear,w)
 			if val ~= 0 then
-
-				setGearValue(CurrentHedgehog, wepArray[i], val)
+				setGearValue(CurrentHedgehog, w, val)
 
 				-- if you are using multi-shot weapon, gimme one more
-				if (GetCurAmmoType()  == wepArray[i]) and (shotsFired ~= 0) then
-					AddAmmo(CurrentHedgehog, wepArray[i], val+1)
+				if (GetCurAmmoType() == w) and (shotsFired ~= 0) then
+					AddAmmo(CurrentHedgehog, w, val+1)
 				-- assign ammo as per normal
 				else
-					AddAmmo(CurrentHedgehog, wepArray[i], val)
+					AddAmmo(CurrentHedgehog, w, val)
 				end
 
 			end
@@ -208,7 +233,28 @@
 end
 
 function onGameStart()
+    utilChoices[amSkip] = 0
+    local c = 0
+    for i = 1,maxWep do
+        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
+                    atktot = atktot + probability[c]
+                    atkChoices[i] = atktot
+                elseif utilWeps[i] then
+                    utiltot = utiltot + probability[c]
+                    utilChoices[i] = utiltot
+                end
+            end
+        end
+    end
 
+    WriteLnToConsole('utiltot:'..utiltot..' atktot:'..atktot)
+        
 	ShowMission	(
 				loc("HIGHLANDER"),
 				loc("Not all hogs are born equal."),
@@ -220,27 +266,8 @@
 				"", 4, 4000
 				)
 
-	if MapHasBorder() == false then
-       	for i, w in pairs(airWeapons) do
-            table.insert(atkArray, w)
-        end
-	end
-
-	for i, w in pairs(atkArray) do
-        table.insert(wepArray, w)
-	end
-
-	for i, w in pairs(utilArray) do
-        table.insert(wepArray, w)
-	end
-
-	table.insert(wepArray, amSkip)
-	table.insert(wepArray, amKamikaze)
-
 	runOnGears(StartingSetUp)
 	runOnGears(ConvertValues)
-
-
 end
 
 function CheckForHogSwitch()
@@ -296,6 +323,7 @@
 
 	if (GetGearType(gear) == gtHedgehog) then
 		trackGear(gear)
+        if someHog == nil then someHog = gear end
 	end
 
 end
@@ -308,8 +336,3 @@
 	end
 
 end
-
-function onAmmoStoreInit()
-	-- no, you can't set your own ammo scheme
-end
-