share/hedgewars/Data/Scripts/SpeedShoppa.lua
changeset 14485 208359558642
parent 14480 2113296b7a29
child 14583 50f511588635
equal deleted inserted replaced
14484:4e5280a9e782 14485:208359558642
    43 					}
    43 					}
    44 				There must be at least 1 crate.
    44 				There must be at least 1 crate.
    45 
    45 
    46 	optional fields:
    46 	optional fields:
    47 	- missionTitle:		the name of the mission (optional but highly recommended) (default: "Speed Shoppa")
    47 	- missionTitle:		the name of the mission (optional but highly recommended) (default: "Speed Shoppa")
    48 	- hogHat:		hat of the hedgehog (default: "NoHat")
       
    49 	- hogName:		name of the hedgehog (default: "Roper")
       
    50 	- teamName:		name of the hedgehog’s team (default: "Shoppers")
       
    51 	- teamGrave:		name of the hedgehog’s grave (default: "Statue")
       
    52 	- teamFlag:		name of the team’s flag (default: "cm_shoppa")
       
    53 	- clanColor:		color of the (only) clan (default: -1, default first clan color)
    48 	- clanColor:		color of the (only) clan (default: -1, default first clan color)
    54 	- goalText:		A short string explaining the goal of the mission
    49 	- goalText:		A short string explaining the goal of the mission
    55 				(default: "Use your rope to collect all crates as fast as possible.")
    50 				(default: "Use your rope to collect all crates as fast as possible.")
    56 	- faceLeft:		If true, the hog faces to the left initially, if false, it faces to the right.
    51 	- faceLeft:		If true, the hog faces to the left initially, if false, it faces to the right.
    57 				(default: false (=right))
    52 				(default: false (=right))
    72 local startTime, endTime
    67 local startTime, endTime
    73 
    68 
    74 local crates
    69 local crates
    75 
    70 
    76 function SpeedShoppaMission(params)
    71 function SpeedShoppaMission(params)
    77 	if params.hogHat == nil then params.hogHat = "NoHat" end
       
    78 	if params.hogName == nil then params.hogName = loc("Roper") end
       
    79 	if params.teamName == nil then params.teamName = loc("Shoppers") end
       
    80 	if params.goalText == nil then params.goalText = loc("Use your rope to collect all crates as fast as possible.") end
    72 	if params.goalText == nil then params.goalText = loc("Use your rope to collect all crates as fast as possible.") end
    81 	if params.missionTitle == nil then params.missionTitle = loc("Speed Shoppa") end
    73 	if params.missionTitle == nil then params.missionTitle = loc("Speed Shoppa") end
    82 	if params.clanColor == nil then params.clanColor = -1 end
    74 	if params.clanColor == nil then params.clanColor = -1 end
    83 	if params.teamGrave == nil then params.teamGrave = "Statue" end
       
    84 	if params.teamFlag == nil then params.teamFlag = "cm_shoppa" end
       
    85 	if params.extra_onGameInit == nil then params.extra_onGameInit = function() end end
    75 	if params.extra_onGameInit == nil then params.extra_onGameInit = function() end end
    86 	if params.extra_onGameStart == nil then params.extra_onGameStart = function() end end
    76 	if params.extra_onGameStart == nil then params.extra_onGameStart = function() end end
    87 	if params.faceLeft == nil then params.faceLeft = false end
    77 	if params.faceLeft == nil then params.faceLeft = false end
    88 
    78 
    89 	crates = params.crates
    79 	crates = params.crates
    99 		Map = params.map
    89 		Map = params.map
   100 		-- Disable Sudden Death
    90 		-- Disable Sudden Death
   101 		WaterRise = 0
    91 		WaterRise = 0
   102 		HealthDecrease = 0
    92 		HealthDecrease = 0
   103 	
    93 	
   104 		AddTeam(params.teamName, params.clanColor, params.teamGrave, "Castle", "Default", params.teamFlag)
    94 		AddMissionTeam(params.clanColor)
   105 		playerHog = AddHog(params.hogName, 0, 1, params.hogHat)
    95 		playerHog = AddMissionHog(1)
   106 		HogTurnLeft(playerHog, params.faceLeft)
    96 		HogTurnLeft(playerHog, params.faceLeft)
   107 		
    97 		
   108 		SetGearPosition(playerHog, params.hog_x, params.hog_y)
    98 		SetGearPosition(playerHog, params.hog_x, params.hog_y)
   109 
    99 
   110 		params.extra_onGameInit()
   100 		params.extra_onGameInit()
   117 	_G.onGameStart = function()
   107 	_G.onGameStart = function()
   118 		SendHealthStatsOff()
   108 		SendHealthStatsOff()
   119 		local append = getReadableChallengeRecord("TimeRecord")
   109 		local append = getReadableChallengeRecord("TimeRecord")
   120 		ShowMission(params.missionTitle, loc("Challenge"), params.goalText .. "|" .. append, -amRope, 5000)
   110 		ShowMission(params.missionTitle, loc("Challenge"), params.goalText .. "|" .. append, -amRope, 5000)
   121 		-- <crates collected>/<total number of crates>
   111 		-- <crates collected>/<total number of crates>
   122 		SetTeamLabel(params.teamName, string.format(loc("%d/%d"), cratesCollected, #crates))
   112 		SetTeamLabel(GetHogTeamName(playerHog), string.format(loc("%d/%d"), cratesCollected, #crates))
   123 		for i=1,#crates do
   113 		for i=1,#crates do
   124 			spawnCrate(crates[i].x, crates[i].y)
   114 			spawnCrate(crates[i].x, crates[i].y)
   125 		end
   115 		end
   126 		params.extra_onGameStart()
   116 		params.extra_onGameStart()
   127 	end
   117 	end
   132 	end
   122 	end
   133 	_G.onGearDelete = function(gear)
   123 	_G.onGearDelete = function(gear)
   134 		if GetGearType(gear) == gtCase and not hogHurt and not timeOut then
   124 		if GetGearType(gear) == gtCase and not hogHurt and not timeOut then
   135 			cratesCollected = cratesCollected + 1
   125 			cratesCollected = cratesCollected + 1
   136 			-- <crates collected>/<total number of crates>
   126 			-- <crates collected>/<total number of crates>
   137 			SetTeamLabel(params.teamName, string.format(loc("%d/%d"), cratesCollected, #crates))
   127 			SetTeamLabel(GetHogTeamName(playerHog), string.format(loc("%d/%d"), cratesCollected, #crates))
   138 			PlaySound(sndShotgunReload)
   128 			PlaySound(sndShotgunReload)
   139 			if cratesCollected == #crates then
   129 			if cratesCollected == #crates then
   140 				endTime = TurnTimeLeft
   130 				endTime = TurnTimeLeft
   141 				finalize()
   131 				finalize()
   142 			else
   132 			else
   173 				SetState(playerHog, band(GetState(playerHog), bnot(gstHHDriven)))
   163 				SetState(playerHog, band(GetState(playerHog), bnot(gstHHDriven)))
   174 				AddCaption(loc("Challenge completed!"))
   164 				AddCaption(loc("Challenge completed!"))
   175 				SendStat(siGameResult, loc("Challenge completed!"))
   165 				SendStat(siGameResult, loc("Challenge completed!"))
   176 				SendStat(siPointType, loc("milliseconds"))
   166 				SendStat(siPointType, loc("milliseconds"))
   177 				local time = startTime - endTime
   167 				local time = startTime - endTime
   178 				SendStat(siPlayerKills, tostring(time), params.teamName)
   168 				SendStat(siPlayerKills, tostring(time), GetHogTeamName(playerHog))
   179 				SendStat(siCustomAchievement, string.format(loc("You have finished the challenge in %.3f s."), (time/1000)))
   169 				SendStat(siCustomAchievement, string.format(loc("You have finished the challenge in %.3f s."), (time/1000)))
   180 				SetTurnTimeLeft(0)
   170 				SetTurnTimeLeft(0)
   181 				updateChallengeRecord("TimeRecord", time)
   171 				updateChallengeRecord("TimeRecord", time)
   182 			else
   172 			else
   183 				SendStat(siGameResult, loc("Challenge failed!"))
   173 				SendStat(siGameResult, loc("Challenge failed!"))
   184 				SendStat(siPointType, loc("crate(s)"))
   174 				SendStat(siPointType, loc("crate(s)"))
   185 				SendStat(siPlayerKills, tostring(cratesCollected), params.teamName)
   175 				SendStat(siPlayerKills, tostring(cratesCollected), GetHogTeamName(playerHog))
   186 				SendStat(siCustomAchievement, string.format(loc("You have collected %d out of %d crate(s)."), cratesCollected, #crates))
   176 				SendStat(siCustomAchievement, string.format(loc("You have collected %d out of %d crate(s)."), cratesCollected, #crates))
   187 			end
   177 			end
   188 			gameEnded = true
   178 			gameEnded = true
   189 			EndGame()
   179 			EndGame()
   190 		end
   180 		end