now Random Weapons will show the weapon you will get during the other players turns
authorHenek
Mon, 11 Apr 2011 00:35:53 +0200
changeset 5138 f991f87969ff
parent 5137 b6140f35735f
child 5139 090a8b8d1083
now Random Weapons will show the weapon you will get during the other players turns not tested online yet, would be happy if someone could and report to me results
share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua
share/hedgewars/Data/Scripts/Tracker.lua
--- a/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua	Sun Apr 10 17:25:34 2011 -0400
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua	Mon Apr 11 00:35:53 2011 +0200
@@ -1,32 +1,59 @@
+-- Random Weapons, example for gameplay scripts
+
+-- Load the library for localisation ("loc" function)
 loadfile(GetDataPath() .. "Scripts/Locale.lua")()
 
+-- Load the gear tracker
+loadfile(GetDataPath() .. "Scripts/Tracker.lua")()
+
+-- List of available weapons
 local weapons = { amGrenade, amClusterBomb, amBazooka, amBee, amShotgun,
             amMine, amDEagle, amDynamite, amFirePunch, amWhip, amPickHammer,
             amBaseballBat, amTeleport, amMortar, amCake, amSeduction,
             amWatermelon, amHellishBomb, amDrill, amBallgun, amRCPlane,
             amSniperRifle, amMolotov, amBirdy, amBlowTorch, amGasBomb,
-            amFlamethrower, amSMine, amHammer, amSnowball, amTardis, amStructure }
+            amFlamethrower, amSMine, amHammer }
 
+-- List of weapons that attack from the air
 local airweapons = { amAirAttack, amMineStrike, amNapalm, amDrillStrike }
 
+-- Function that assigns the team their weapon
+-- Due to the fact that the gameplay uses reset weapons and no inf attack there is no point in limiting the ammo count
+function assignWeapon(hog)
+    -- Get the ammo for this hog's team
+    local ammo = getTeamValue(GetHogTeamName(hog), "ammo")
+    -- If there is no ammo, get a random one from the list and store it
+    if ammo == nil then
+        ammo = weapons[GetRandom(table.maxn(weapons)) + 1]
+        setTeamValue(GetHogTeamName(hog), "ammo", ammo)
+    end
+    -- Add the ammo for the hog
+    AddAmmo(hog, ammo)
+end
 
 function onGameInit()
+    -- Limit flags that can be set, but allow game schemes to be used
     GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack + gfPerHogAmmo))
+    -- Set a custom game goal that will show together with the scheme ones
     Goals = loc("Each turn you get one random weapon")
 end
 
 function onGameStart()
+    -- Initialize the tracking of hogs and teams
+    trackTeams()
+    -- Add air weapons to the game if the border is not active
     if MapHasBorder() == false then
         for i, w in pairs(airweapons) do
             table.insert(weapons, w)
         end
     end
-    --ShowMission(loc("Random Weapons"), loc("A game of luck"), loc("There has been a mix-up with your gear and now you|have to utilize whatever is coming your way!"), -amSkip, 0)
 end
 
 function onAmmoStoreInit()
+    -- Allow skip at all times
     SetAmmo(amSkip, 9, 0, 0, 0)
 
+    -- Let utilities be available through crates
     SetAmmo(amParachute, 0, 1, 0, 1)
     SetAmmo(amGirder, 0, 1, 0, 2)
     SetAmmo(amSwitch, 0, 1, 0, 1)
@@ -40,15 +67,32 @@
     SetAmmo(amPortalGun, 0, 1, 0, 1)
     SetAmmo(amResurrector, 0, 1, 0, 1)
 
+    -- Allow weapons to be used
     for i, w in pairs(weapons) do
         SetAmmo(w, 0, 0, 0, 1)
     end
 
+    -- Allow air weapons to be used
     for i, w in pairs(airweapons) do
         SetAmmo(w, 0, 0, 0, 1)
     end
 end
 
 function onNewTurn()
-    AddAmmo(CurrentHedgehog, weapons[GetRandom(table.maxn(weapons)) + 1])
+    -- Give every team their weapons, so one can plan during anothers turn
+    runOnGears(assignWeapon)
+    -- Set the current teams weapons to nil so they will get new after the turn has ended
+    setTeamValue(GetHogTeamName(CurrentHedgehog), "ammo", nil)
 end
+
+function onGearAdd(gear)
+    -- Catch hedgehogs for the tracker
+    if GetGearType(gear) == gtHedgehog then
+        trackGear(gear)
+    end
+end
+
+function onGearDelete(gear)
+    -- Remove hogs that are gone
+    trackDeletion(gear)
+end
--- a/share/hedgewars/Data/Scripts/Tracker.lua	Sun Apr 10 17:25:34 2011 -0400
+++ b/share/hedgewars/Data/Scripts/Tracker.lua	Mon Apr 11 00:35:53 2011 +0200
@@ -274,15 +274,3 @@
         end
     end
 end
-
-function numGears()
-    return table.maxn(gears)
-end
-
-function numTeams()
-    num = 0
-    for team, hogs in pairs(teams) do
-        num = num + 1
-    end
-    return num
-end