lua api: SetWeapon(ammoType)
authorsheepluva
Thu, 12 Jun 2014 20:47:11 +0200
changeset 10289 c3a77ff02a23
parent 10288 7bf02127262c
child 10290 42efccba0711
lua api: SetWeapon(ammoType)
hedgewars/uScript.pas
share/hedgewars/Data/Maps/TrophyRace/map.lua
share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/journey.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert02.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice02.lua
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/moon02.lua
share/hedgewars/Data/Missions/Training/Basic_Training_-_Bazooka.lua
share/hedgewars/Data/Missions/Training/Basic_Training_-_Cluster_Bomb.lua
share/hedgewars/Data/Missions/Training/Basic_Training_-_Grenade.lua
share/hedgewars/Data/Missions/Training/Basic_Training_-_Shotgun.lua
share/hedgewars/Data/Missions/Training/Basic_Training_-_Sniper_Rifle.lua
share/hedgewars/Data/Scripts/Multiplayer/Frenzy.lua
share/hedgewars/Data/Scripts/Multiplayer/Racer.lua
share/hedgewars/Data/Scripts/Multiplayer/The_Specialists.lua
--- a/hedgewars/uScript.pas	Thu Jun 12 19:40:45 2014 +0200
+++ b/hedgewars/uScript.pas	Thu Jun 12 20:47:11 2014 +0200
@@ -354,6 +354,21 @@
     lc_parsecommand:= 0;
 end;
 
+function lc_setweapon(L : Plua_State) : LongInt; Cdecl;
+var at: LongInt;
+const
+    call = 'SetWeapon';
+    params = 'ammoType';
+begin
+    if CheckLuaParameterCount(L, 1, call, params) then
+        begin
+        at:= LuaToAmmoTypeOrd(L, 1, call, params);
+        if at >= 0 then
+            ParseCommand('setweap ' + char(at), true, true);
+        end;
+    lc_setweapon:= 0;
+end;
+
 function lc_showmission(L : Plua_State) : LongInt; Cdecl;
 begin
     if CheckLuaParameterCount(L, 5, 'ShowMission', 'caption, subcaption, text, icon, time') then
@@ -1126,8 +1141,8 @@
                lua_pushinteger(L, vgear^.Uid);
                end
             end
-            else
-                lua_pushnil(L)
+        else
+            lua_pushnil(L)
         end
     else
         lua_pushnil(L);
@@ -2590,30 +2605,30 @@
     ScriptSetInteger(EnumToStr(spr), ord(spr));
 
 
-ScriptSetInteger('gstDrowning'       ,$00000001);
-ScriptSetInteger('gstHHDriven'       ,$00000002);
-ScriptSetInteger('gstMoving'         ,$00000004);
-ScriptSetInteger('gstAttacked'       ,$00000008);
-ScriptSetInteger('gstAttacking'      ,$00000010);
-ScriptSetInteger('gstCollision'      ,$00000020);
-ScriptSetInteger('gstHHChooseTarget' ,$00000040);
-ScriptSetInteger('gstHHJumping'      ,$00000100);
-ScriptSetInteger('gsttmpFlag'        ,$00000200);
-ScriptSetInteger('gstHHThinking'     ,$00000800);
-ScriptSetInteger('gstNoDamage'       ,$00001000);
-ScriptSetInteger('gstHHHJump'        ,$00002000);
-ScriptSetInteger('gstAnimation'      ,$00004000);
-ScriptSetInteger('gstHHDeath'        ,$00008000);
-ScriptSetInteger('gstWinner'         ,$00010000);
-ScriptSetInteger('gstWait'           ,$00020000);
-ScriptSetInteger('gstNotKickable'    ,$00040000);
-ScriptSetInteger('gstLoser'          ,$00080000);
-ScriptSetInteger('gstHHGone'         ,$00100000);
-ScriptSetInteger('gstInvisible'      ,$00200000);
+ScriptSetInteger('gstDrowning'      , gstDrowning);
+ScriptSetInteger('gstHHDriven'      , gstHHDriven);
+ScriptSetInteger('gstMoving'        , gstMoving);
+ScriptSetInteger('gstAttacked'      , gstAttacked);
+ScriptSetInteger('gstAttacking'     , gstAttacking);
+ScriptSetInteger('gstCollision'     , gstCollision);
+ScriptSetInteger('gstHHChooseTarget', gstHHChooseTarget);
+ScriptSetInteger('gstHHJumping'     , gstHHJumping);
+ScriptSetInteger('gsttmpFlag'       , gsttmpFlag);
+ScriptSetInteger('gstHHThinking'    , gstHHThinking);
+ScriptSetInteger('gstNoDamage'      , gstNoDamage);
+ScriptSetInteger('gstHHHJump'       , gstHHHJump);
+ScriptSetInteger('gstAnimation'     , gstAnimation);
+ScriptSetInteger('gstHHDeath'       , gstHHDeath);
+ScriptSetInteger('gstWinner'        , gstWinner);
+ScriptSetInteger('gstWait'          , gstWait);
+ScriptSetInteger('gstNotKickable'   , gstNotKickable);
+ScriptSetInteger('gstLoser'         , gstLoser);
+ScriptSetInteger('gstHHGone'        , gstHHGone);
+ScriptSetInteger('gstInvisible'     , gstInvisible);
 
 // ai hints
-ScriptSetInteger('aihUsualProcessing' ,$00000000);
-ScriptSetInteger('aihDoesntMatter'    ,$00000001);
+ScriptSetInteger('aihUsualProcessing', aihUsualProcessing);
+ScriptSetInteger('aihDoesntMatter'   , aihDoesntMatter);
 
 // land flags
 ScriptSetInteger('lfIndestructible', lfIndestructible);
@@ -2724,6 +2739,7 @@
 lua_register(luaState, _P'GetGravity', @lc_getgravity);
 lua_register(luaState, _P'SetGravity', @lc_setgravity);
 lua_register(luaState, _P'SetWaterLine', @lc_setwaterline);
+lua_register(luaState, _P'SetWeapon', @lc_setweapon);
 
 lua_register(luaState, _P'SetGearAIHints', @lc_setaihintsongear);
 lua_register(luaState, _P'HedgewarsScriptLoad', @lc_hedgewarsscriptload);
--- a/share/hedgewars/Data/Maps/TrophyRace/map.lua	Thu Jun 12 19:40:45 2014 +0200
+++ b/share/hedgewars/Data/Maps/TrophyRace/map.lua	Thu Jun 12 20:47:11 2014 +0200
@@ -101,7 +101,7 @@
     if CurrentHedgehog ~= nil then
         SetGearVelocity(CurrentHedgehog, 1, 0)
         SetGearPosition(CurrentHedgehog, start_area[1] + start_area[3] / 2, start_area[2] + start_area[4] / 2)
-        ParseCommand("setweap " .. string.char(amRope))
+        SetWeapon(amRope)
         lasthog = CurrentHedgehog
     end
 end
--- a/share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/journey.lua	Thu Jun 12 19:40:45 2014 +0200
+++ b/share/hedgewars/Data/Missions/Campaign/A_Classic_Fairytale/journey.lua	Thu Jun 12 20:47:11 2014 +0200
@@ -268,7 +268,7 @@
 end
 
 function TargetPrincess()
-  ParseCommand("setweap " .. string.char(amDEagle))
+  SetWeapon(amDEagle)
   SetGearMessage(cyborg, gmUp)
   return true
 end
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert02.lua	Thu Jun 12 19:40:45 2014 +0200
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert02.lua	Thu Jun 12 20:47:11 2014 +0200
@@ -100,7 +100,7 @@
 end
 
 function onNewTurn()
-	ParseCommand("setweap " .. string.char(amRope))
+	SetWeapon(amRope)
 end
 
 function onGameTick()
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice02.lua	Thu Jun 12 19:40:45 2014 +0200
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/ice02.lua	Thu Jun 12 20:47:11 2014 +0200
@@ -116,7 +116,7 @@
 	if not hero.dead and CurrentHedgehog == ally.gear and challengeStarted then
 		heroLost()
 	elseif not hero.dead and CurrentHedgehog == hero.gear and challengeStarted then
-		ParseCommand("setweap " .. string.char(amJetpack))
+		SetWeapon(amJetpack)
 	end
 end
 
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/moon02.lua	Thu Jun 12 19:40:45 2014 +0200
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/moon02.lua	Thu Jun 12 20:47:11 2014 +0200
@@ -98,7 +98,7 @@
 			if GetAmmoCount(hero.gear, amRope) == 0  then
 				lose()
 			end
-			ParseCommand("setweap " .. string.char(amRope))
+			SetWeapon(amRope)
 			TurnTimeLeft = runner.places[currentPosition].turnTime + previousTimeLeft
 			previousTimeLeft = 0
 		end
--- a/share/hedgewars/Data/Missions/Training/Basic_Training_-_Bazooka.lua	Thu Jun 12 19:40:45 2014 +0200
+++ b/share/hedgewars/Data/Missions/Training/Basic_Training_-_Bazooka.lua	Thu Jun 12 20:47:11 2014 +0200
@@ -112,7 +112,7 @@
 end
 
 function onNewTurn()
-	ParseCommand("setweap " .. string.char(amBazooka))
+	SetWeapon(amBazooka)
 end
 
 -- This function is called every game tick.
--- a/share/hedgewars/Data/Missions/Training/Basic_Training_-_Cluster_Bomb.lua	Thu Jun 12 19:40:45 2014 +0200
+++ b/share/hedgewars/Data/Missions/Training/Basic_Training_-_Cluster_Bomb.lua	Thu Jun 12 20:47:11 2014 +0200
@@ -84,7 +84,7 @@
 end
 
 function onNewTurn()
-	ParseCommand("setweap " .. string.char(amClusterBomb))
+	SetWeapon(amClusterBomb)
 end
 
 --function onGearAdd(gear)
--- a/share/hedgewars/Data/Missions/Training/Basic_Training_-_Grenade.lua	Thu Jun 12 19:40:45 2014 +0200
+++ b/share/hedgewars/Data/Missions/Training/Basic_Training_-_Grenade.lua	Thu Jun 12 20:47:11 2014 +0200
@@ -107,7 +107,7 @@
 end
 
 function onNewTurn()
-	ParseCommand("setweap " .. string.char(amGrenade))
+	SetWeapon(amGrenade)
 end
 
 -- This function is called every game tick.
--- a/share/hedgewars/Data/Missions/Training/Basic_Training_-_Shotgun.lua	Thu Jun 12 19:40:45 2014 +0200
+++ b/share/hedgewars/Data/Missions/Training/Basic_Training_-_Shotgun.lua	Thu Jun 12 20:47:11 2014 +0200
@@ -50,7 +50,7 @@
 end
 
 function onNewTurn()
-	ParseCommand("setweap " .. string.char(amShotgun))
+	SetWeapon(amShotgun)
 end
 
 -- This function is called before the game loads its
--- a/share/hedgewars/Data/Missions/Training/Basic_Training_-_Sniper_Rifle.lua	Thu Jun 12 19:40:45 2014 +0200
+++ b/share/hedgewars/Data/Missions/Training/Basic_Training_-_Sniper_Rifle.lua	Thu Jun 12 20:47:11 2014 +0200
@@ -51,7 +51,7 @@
 end
 
 function onNewTurn()
-	ParseCommand("setweap " .. string.char(amSniperRifle))
+	SetWeapon(amSniperRifle)
 end
 
 -- This function is called before the game loads its
--- a/share/hedgewars/Data/Scripts/Multiplayer/Frenzy.lua	Thu Jun 12 19:40:45 2014 +0200
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Frenzy.lua	Thu Jun 12 20:47:11 2014 +0200
@@ -90,25 +90,25 @@
 function ChangeWep(s)
 
 	if s == 0 then
-		ParseCommand("setweap " .. string.char(amBazooka))
+		SetWeapon(amBazooka)
 	elseif s == 1 then
-		ParseCommand("setweap " .. string.char(amGrenade))
+		SetWeapon(amGrenade)
 	elseif s == 2 then
-		ParseCommand("setweap " .. string.char(amShotgun))
+		SetWeapon(amShotgun)
 	elseif s == 3 then
-		ParseCommand("setweap " .. string.char(amFirePunch))
+		SetWeapon(amFirePunch)
 	elseif s == 4 then
-		ParseCommand("setweap " .. string.char(amMine))
+		SetWeapon(amMine)
 	elseif s == 5 then
-		ParseCommand("setweap " .. string.char(amTeleport))
+		SetWeapon(amTeleport)
 	elseif s == 6 then
-		ParseCommand("setweap " .. string.char(amBlowTorch))
+		SetWeapon(amBlowTorch)
 	elseif s == 7 then
-		ParseCommand("setweap " .. string.char(amJetpack))
+		SetWeapon(amJetpack)
 	elseif s == 8 then
-		ParseCommand("setweap " .. string.char(amMolotov))
+		SetWeapon(amMolotov)
 	elseif s == 9 then
-		ParseCommand("setweap " .. string.char(amLowGravity))
+		SetWeapon(amLowGravity)
 	end
 
 end
--- a/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Thu Jun 12 19:40:45 2014 +0200
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Thu Jun 12 20:47:11 2014 +0200
@@ -574,7 +574,7 @@
                         loc("NOT ENOUGH WAYPOINTS"),
                         loc("Place more waypoints using the 'Air Attack' weapon."), 2, 4000)
                         AddAmmo(CurrentHedgehog, amAirAttack, 4000)
-            ParseCommand("setweap " .. string.char(amAirAttack))
+            SetWeapon(amAirAttack)
                 end
         end
 
--- a/share/hedgewars/Data/Scripts/Multiplayer/The_Specialists.lua	Thu Jun 12 19:40:45 2014 +0200
+++ b/share/hedgewars/Data/Scripts/Multiplayer/The_Specialists.lua	Thu Jun 12 20:47:11 2014 +0200
@@ -243,7 +243,7 @@
 					AddAmmo(CurrentHedgehog, amSwitch, 1)
 
 				elseif switchStage == 2 then
-					ParseCommand("setweap " .. string.char(amSwitch))
+					SetWeapon(amSwitch)
 				elseif switchStage == 3 then
 					SetGearMessage(CurrentHedgehog,gmAttack)
 				elseif switchStage == 4 then