Standardize hidden mission achievement in new Lua library "Achievements"
authorWuzzy <Wuzzy2@mail.ru>
Tue, 17 Jul 2018 16:45:34 +0200
changeset 13501 cbda0f842364
parent 13500 b5f8864a38d3
child 13502 65c348d6c1fa
Standardize hidden mission achievement in new Lua library "Achievements"
ChangeLog.txt
share/hedgewars/Data/Missions/Challenge/User_Mission_-_RCPlane_Challenge.lua
share/hedgewars/Data/Missions/Challenge/User_Mission_-_That_Sinking_Feeling.lua
share/hedgewars/Data/Missions/Scenario/User_Mission_-_Bamboo_Thicket.lua
share/hedgewars/Data/Missions/Scenario/User_Mission_-_Dangerous_Ducklings.lua
share/hedgewars/Data/Scripts/Achievements.lua
--- a/ChangeLog.txt	Tue Jul 17 14:20:58 2018 +0200
+++ b/ChangeLog.txt	Tue Jul 17 16:45:34 2018 +0200
@@ -55,6 +55,7 @@
  + New call: GetAmmo(ammoType): Returns ammo configuration (corresponds to SetAmmo)
  + New parameter: SetAmmoTexts: 5th param. showExtra: Set to false to hide texts like “Not yet available”
  + New parameter: ShowMission: 6th param. forceDisplay: Set to true to prevent this particular mission panel to be hidden manually by player
+ + New Lua library: Achievements
  * Changed global: lfCurrentHog becomes lfCurHogCrate
  * Fixed variable: TotalRounds was -1 (instead of 0) in first real round after hog placement phase
  * AI sometimes intentionally shot hedgehogs with aihDoesntMatter set
--- a/share/hedgewars/Data/Missions/Challenge/User_Mission_-_RCPlane_Challenge.lua	Tue Jul 17 14:20:58 2018 +0200
+++ b/share/hedgewars/Data/Missions/Challenge/User_Mission_-_RCPlane_Challenge.lua	Tue Jul 17 16:45:34 2018 +0200
@@ -1,4 +1,5 @@
 HedgewarsScriptLoad("/Scripts/Locale.lua")
+HedgewarsScriptLoad("/Scripts/Achievements.lua")
 
 local player = nil
 local RCGear = nil
@@ -424,7 +425,7 @@
 			end
 			if(planesUsed == 1) then
 				SendStat(siCustomAchievement, loc("Congratulations! You have truly mastered this challenge! Don't forget to save the demo."))
-				SendStat(siCustomAchievement, string.format(loc("Achievement gotten: %s"), loc("Prestigious Pilot")))
+				awardAchievement(loc("Prestigious Pilot"), nil, false)
 			end
 
 			ShowMission     (
--- a/share/hedgewars/Data/Missions/Challenge/User_Mission_-_That_Sinking_Feeling.lua	Tue Jul 17 14:20:58 2018 +0200
+++ b/share/hedgewars/Data/Missions/Challenge/User_Mission_-_That_Sinking_Feeling.lua	Tue Jul 17 16:45:34 2018 +0200
@@ -1,6 +1,7 @@
 
 
 HedgewarsScriptLoad("/Scripts/Locale.lua")
+HedgewarsScriptLoad("/Scripts/Achievements.lua")
 
 local player
 local hh = {}
@@ -241,8 +242,7 @@
 				SendStat(siCustomAchievement, string.format(loc("You saved %d of 8 Hapless Hogs."), hhLeft))
 
 				if hhLeft == 8 then
-					AddCaption(string.format(loc("Achievement gotten: %s"), loc("Lively Lifeguard")) ,0xffba00ff,capgrpMessage2)
-					SendStat(siCustomAchievement, loc("You have obtained an achievement: Lively Lifeguard"))
+					awardAchievement(loc("Lively Lifeguard"))
 				end
 				EndGame()
 
--- a/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Bamboo_Thicket.lua	Tue Jul 17 14:20:58 2018 +0200
+++ b/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Bamboo_Thicket.lua	Tue Jul 17 16:45:34 2018 +0200
@@ -1,5 +1,6 @@
 
 HedgewarsScriptLoad("/Scripts/Locale.lua")
+HedgewarsScriptLoad("/Scripts/Achievements.lua")
 
 local player = nil 
 local enemy = nil
@@ -81,9 +82,7 @@
 		ShowMission(loc("Bamboo Thicket"), loc("MISSION SUCCESSFUL"), loc("Congratulations!"), 0, 0)
 		
 		if (turnNumber < 6) and (firedShell == false) then
-			local achievementString = string.format(loc("Achievement gotten: %s"), loc("Energetic Engineer"))
-			AddCaption(achievementString, 0xffba00ff, capgrpMessage2)
-			SendStat(siCustomAchievement, achievementString)
+			awardAchievement(loc("Energetic Engineer"))
 		end
 
 	elseif gear == player then
--- a/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Dangerous_Ducklings.lua	Tue Jul 17 14:20:58 2018 +0200
+++ b/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Dangerous_Ducklings.lua	Tue Jul 17 16:45:34 2018 +0200
@@ -1,5 +1,6 @@
 
 HedgewarsScriptLoad("/Scripts/Locale.lua")
+HedgewarsScriptLoad("/Scripts/Achievements.lua")
 
 local player = nil -- This variable will point to the hog's gear
 local instructor = nil
@@ -136,9 +137,7 @@
 		elseif (gear == instructor) and (GetY(gear) > WaterLine) then
 			HogSay(player, loc("See ya!"), SAY_THINK)
 			TurnTimeLeft = 3000
-			local achievementString = string.format(loc("Achievement gotten: %s"), loc("Naughty Ninja"))
-			AddCaption(achievementString, 0xffba00ff, capgrpMessage2)
-			SendStat(siCustomAchievement, achievementString)
+			awardAchievement(loc("Naughty Ninja"))
 			DismissTeam(loc("Blue Team"))
 			gameWon = true
 		elseif gear == enemy then
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Scripts/Achievements.lua	Tue Jul 17 16:45:34 2018 +0200
@@ -0,0 +1,15 @@
+HedgewarsScriptLoad("/Scripts/Locale.lua")
+
+function awardAchievement(name, statMessage, capgrp)
+	local achievementString = string.format(loc("Achievement gotten: %s"), name)
+	if capgrp == nil then
+		captionType = capgrpMessage2
+	end
+	if capgrp ~= false then
+		AddCaption(achievementString, 0xFFBA00FF, capgrpMessage2)
+	end
+	if not statMessage then
+		statMessage = achievementString
+	end
+	SendStat(siCustomAchievement, statMessage)
+end