Bazooka/Grenade Training: Make weapon selection detection future-proof
authorWuzzy <Wuzzy2@mail.ru>
Sun, 11 Mar 2018 21:38:08 +0100
changeset 13165 89a6b862e692
parent 13163 a4d257f4b3e0
child 13168 0e7eddfbce8a
Bazooka/Grenade Training: Make weapon selection detection future-proof The old check relied on hardcoded slot IDs for the weapons, which is not good.
share/hedgewars/Data/Missions/Training/Basic_Training_-_Bazooka.lua
share/hedgewars/Data/Missions/Training/Basic_Training_-_Grenade.lua
--- a/share/hedgewars/Data/Missions/Training/Basic_Training_-_Bazooka.lua	Sun Mar 11 12:08:49 2018 +0100
+++ b/share/hedgewars/Data/Missions/Training/Basic_Training_-_Bazooka.lua	Sun Mar 11 21:38:08 2018 +0100
@@ -199,19 +199,6 @@
 	end
 end
 
-function onSetWeapon(ammoType)
-	if ammoType == amBazooka and not weaponSelected and gamePhase == 1 then
-		newGamePhase()
-		weaponSelected = true
-	end
-end
-function onSlot(msgParam)
-	if msgParam == 0 and not weaponSelected and gamePhase == 1 then
-		newGamePhase()
-		weaponSelected = true
-	end
-end
-
 function onHogAttack(ammoType)
 	if ammoType == amBazooka then
 		HideMission()
@@ -278,6 +265,11 @@
 		PlaySound(sndMissed, hog)
 		missedTauntTimer = -1
 	end
+
+	if not weaponSelected and gamePhase == 1 and GetCurAmmoType() == amBazooka then
+		newGamePhase()
+		weaponSelected = true
+	end
 end
 
 function onAmmoStoreInit()
--- a/share/hedgewars/Data/Missions/Training/Basic_Training_-_Grenade.lua	Sun Mar 11 12:08:49 2018 +0100
+++ b/share/hedgewars/Data/Missions/Training/Basic_Training_-_Grenade.lua	Sun Mar 11 21:38:08 2018 +0100
@@ -171,15 +171,8 @@
 	end
 end
 
-function onSetWeapon(ammoType)
-	if ammoType == amGrenade and not weaponSelected and gamePhase == 1 then
-		newGamePhase()
-		weaponSelected = true
-	end
-end
-
-function onSlot(msgParam)
-	if msgParam <= 1 and not weaponSelected and gamePhase == 1 then
+function onGameTick20()
+	if not weaponSelected and gamePhase == 1 and GetCurAmmoType() == amGrenade then
 		newGamePhase()
 		weaponSelected = true
 	end