added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
authorHenek
Tue, 21 Dec 2010 02:17:45 +0100
changeset 4590 d9fed5a816e9
parent 4586 4ba4f021070f
child 4592 b1fe47b11b99
added MapHasBorder function for lua and finnished Random Weapons gameplay, might still change though
hedgewars/uScript.pas
share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua
--- a/hedgewars/uScript.pas	Mon Dec 20 21:45:10 2010 +0300
+++ b/hedgewars/uScript.pas	Tue Dec 21 02:17:45 2010 +0100
@@ -1082,6 +1082,18 @@
         lua_pushstring(L, str2pchar(Pathz[ptData]));
     lc_getdatapath:= 1
 end;
+
+function lc_maphasborder(L : Plua_State) : LongInt; Cdecl;
+begin
+    if lua_gettop(L) <> 0 then
+        begin
+        LuaError('Lua: Wrong number of parameters passed to MapHasBorder!');
+        lua_pushnil(L);
+        end
+    else
+        lua_pushboolean(L, hasBorder);
+    lc_maphasborder:= 1
+end;
 ///////////////////
 
 procedure ScriptPrintStack;
@@ -1492,6 +1504,7 @@
 lua_register(luaState, 'GetRandom', @lc_getrandom);
 lua_register(luaState, 'SetWind', @lc_setwind);
 lua_register(luaState, 'GetDataPath', @lc_getdatapath);
+lua_register(luaState, 'MapHasBorder', @lc_maphasborder);
 
 
 ScriptClearStack; // just to be sure stack is empty
--- a/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua	Mon Dec 20 21:45:10 2010 +0300
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Random_Weapon.lua	Tue Dec 21 02:17:45 2010 +0100
@@ -1,17 +1,29 @@
+loadfile(GetDataPath() .. "Scripts/Locale.lua")()
+
 local weapons = { amGrenade, amClusterBomb, amBazooka, amBee, amShotgun,
             amMine, amDEagle, amDynamite, amFirePunch, amWhip, amPickHammer,
-            amBaseballBat, amAirAttack, amMineStrike, amTeleport, amMortar, amCake,
-            amSeduction, amWatermelon, amHellishBomb, amNapalm, amDrill, amBallgun,
-            amRCPlane, amSniperRifle, amMolotov, amBirdy, amBlowTorch,
-            amGasBomb, amFlamethrower, amSMine, amHammer, amDrillStrike }
+            amBaseballBat, amTeleport, amMortar, amCake, amSeduction,
+            amWatermelon, amHellishBomb, amDrill, amBallgun, amRCPlane,
+            amSniperRifle, amMolotov, amBirdy, amBlowTorch, amGasBomb,
+            amFlamethrower, amSMine, amHammer, amSnowball }
 
-local lastRound = -1
-local weapon = 0
+local airweapons = { amAirAttack, amMineStrike, amNapalm, amDrillStrike }
+
 
 function onGameInit()
     GameFlags = band(bor(GameFlags, gfResetWeps), bnot(gfInfAttack + gfPerHogAmmo))
 end
 
+function onGameStart()
+    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()
     SetAmmo(amSkip, 9, 0, 0, 0)
 
@@ -31,12 +43,12 @@
     for i, w in pairs(weapons) do
         SetAmmo(w, 0, 0, 0, 1)
     end
+
+    for i, w in pairs(airweapons) do
+        SetAmmo(w, 0, 0, 0, 1)
+    end
 end
 
 function onNewTurn()
-    if lastRound ~= TotalRounds then
-        weapon = GetRandom(table.maxn(weapons)) + 1
-        lastRound = TotalRounds
-    end
-    AddAmmo(CurrentHedgehog, weapons[weapon])
+    AddAmmo(CurrentHedgehog, weapons[GetRandom(table.maxn(weapons)) + 1])
 end