ASA, desert02: Add achievement for escaping with all crates collected and no damage taken
authorWuzzy <Wuzzy2@mail.ru>
Sat, 29 Sep 2018 23:13:02 +0200
changeset 13821 373813316812
parent 13820 bf8c454a9f93
child 13822 419de2dea82b
ASA, desert02: Add achievement for escaping with all crates collected and no damage taken
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert02.lua
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert02.lua	Sat Sep 29 22:20:19 2018 +0200
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/desert02.lua	Sat Sep 29 23:13:02 2018 +0200
@@ -5,6 +5,7 @@
 
 HedgewarsScriptLoad("/Scripts/Locale.lua")
 HedgewarsScriptLoad("/Scripts/Animate.lua")
+HedgewarsScriptLoad("/Scripts/Achievements.lua")
 HedgewarsScriptLoad("/Missions/Campaign/A_Space_Adventure/global_functions.lua")
 
 ----------------- VARIABLES --------------------
@@ -17,6 +18,10 @@
 local goals = {
 	[dialog01] = {missionName, loc("Getting ready"), loc("Use the rope to quickly get to the surface!") .. "|" .. loc("Mines time: 1 second"), 1, 4500},
 }
+-- For an achievement/award (see below)
+local cratesCollected = 0
+local totalCrates = 0
+local damageTaken = false
 -- health crates
 healthX = 565
 health1Y = 1400
@@ -121,12 +126,25 @@
 function onGearAdd(gear)
 	if GetGearType(gear) == gtRope then
 		HideMission()
+	elseif GetGearType(gear) == gtCase then
+		totalCrates = totalCrates + 1
 	end
 end
 
 function onGearDelete(gear)
 	if gear == hero.gear then
 		hero.dead = true
+		damageTaken = true
+	end
+	-- Crate collected
+	if GetGearType(gear) == gtCase and band(GetGearMessage(gear), gmDestroy) ~= 0 then
+		cratesCollected = cratesCollected + 1
+	end
+end
+
+function onGearDamage(gear)
+	if gear == hero.gear then
+		damageTaken = true
 	end
 end
 
@@ -177,6 +195,10 @@
 			SendStat(siCustomAchievement, loc("This is a new personal best, congratulations!"))
 		end
 	end
+	-- Achievement awarded for escaping with all crates collected and no damage taken
+	if (not damageTaken) and (cratesCollected >= totalCrates) then
+		awardAchievement(loc("Better Safe Than Sorry"))
+	end
 	sendSimpleTeamRankings({teamA.name})
 	SaveCampaignVar("Mission7Won", "true")
 	checkAllMissionsCompleted()