share/hedgewars/Data/Scripts/TargetPractice.lua
changeset 14480 208359558642
parent 14475 2113296b7a29
child 14526 797e3f441c14
equal deleted inserted replaced
14479:4e5280a9e782 14480:208359558642
    41 	},
    41 	},
    42 
    42 
    43 	wind = ,
    43 	wind = ,
    44 	solidLand = ,
    44 	solidLand = ,
    45 	artillery = ,
    45 	artillery = ,
    46 	hogHat = ,
       
    47 	hogName = ,
       
    48 	teamName = ,
       
    49 	teamGrave = ,
       
    50 	clanColor = ,
    46 	clanColor = ,
    51 	goalText = ,
    47 	goalText = ,
    52 	shootText =
    48 	shootText =
    53 }
    49 }
    54 TargetPracticeMission(params)
    50 TargetPracticeMission(params)
    94 
    90 
    95 	optional fields:
    91 	optional fields:
    96 	- wind:		the initial wind (-100 to 100) (default: 0 (no wind))
    92 	- wind:		the initial wind (-100 to 100) (default: 0 (no wind))
    97 	- solidLand:	weather the terrain is indestructible (default: false)
    93 	- solidLand:	weather the terrain is indestructible (default: false)
    98 	- artillery:	if true, the hog can’t move (default: false)
    94 	- artillery:	if true, the hog can’t move (default: false)
    99 	- hogHat:	hat of the hedgehog (default: "NoHat")
       
   100 	- hogName:	name of the hedgehog (default: "Trainee")
       
   101 	- teamName:	name of the hedgehog’s team (default: "Training Team")
       
   102 	- teamGrave:	name of the hedgehog’s grave
       
   103 	- teamFlag:	name of the team’s flag (default: "cm_crosshair")
       
   104 	- secGearType:	cluster of projectile gear (if present) (used to re-center camera)
    95 	- secGearType:	cluster of projectile gear (if present) (used to re-center camera)
   105 	- clanColor:	color of the (only) clan (default: -1, default first clan color)
    96 	- clanColor:	color of the (only) clan (default: -1, default first clan color)
   106 	- goalText:	A short string explaining the goal of the mission
    97 	- goalText:	A short string explaining the goal of the mission
   107 			(default: "Destroy all targets within the time!")
    98 			(default: "Destroy all targets within the time!")
   108 	- shootText:	A string which says how many times the player shot, “%d” is replaced
    99 	- shootText:	A string which says how many times the player shot, “%d” is replaced
   113 local getTargetsScore = function()
   104 local getTargetsScore = function()
   114 	return scored * math.ceil(6000/#targets)
   105 	return scored * math.ceil(6000/#targets)
   115 end
   106 end
   116 
   107 
   117 function TargetPracticeMission(params)
   108 function TargetPracticeMission(params)
   118 	if params.hogHat == nil then params.hogHat = "NoHat" end
       
   119 	if params.hogName == nil then params.hogName = loc("Trainee") end
       
   120 	if params.teamName == nil then params.teamName = loc("Training Team") end
       
   121 	if params.goalText == nil then params.goalText = loc("Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.") end
   109 	if params.goalText == nil then params.goalText = loc("Eliminate all targets before your time runs out.|You have unlimited ammo for this mission.") end
   122 	if params.shootText == nil then params.shootText = loc("You have shot %d times.") end
   110 	if params.shootText == nil then params.shootText = loc("You have shot %d times.") end
   123 	if params.clanColor == nil then params.clanColor = -1 end
   111 	if params.clanColor == nil then params.clanColor = -1 end
   124 	if params.teamGrave == nil then params.teamGrave= "Statue" end
       
   125 	if params.teamFlag == nil then params.teamFlag = "cm_crosshair" end
       
   126 	if params.wind == nil then params.wind = 0 end
   112 	if params.wind == nil then params.wind = 0 end
   127 
   113 
   128 	local solid, artillery
   114 	local solid, artillery
   129 	if params.solidLand == true then solid = gfSolidLand else solid = 0 end
   115 	if params.solidLand == true then solid = gfSolidLand else solid = 0 end
   130 	if params.artillery == true then artillery = gfArtillery else artillery = 0 end
   116 	if params.artillery == true then artillery = gfArtillery else artillery = 0 end
   158 		WaterRise = 0
   144 		WaterRise = 0
   159 		HealthDecrease = 0
   145 		HealthDecrease = 0
   160 
   146 
   161 		SetWind(params.wind)
   147 		SetWind(params.wind)
   162 
   148 
   163 		AddTeam(loc(params.teamName), params.clanColor, params.teamGrave, "Flowerhog", "Default", params.teamFlag)
   149 		AddMissionTeam(params.clanColor)
   164 
   150 
   165 		player = AddHog(loc(params.hogName), 0, 1, params.hogHat)
   151 		player = AddMissionHog(1)
   166 		SetGearPosition(player, params.hog_x, params.hog_y)
   152 		SetGearPosition(player, params.hog_x, params.hog_y)
   167 	end
   153 	end
   168 
   154 
   169 	_G.onGameStart = function()
   155 	_G.onGameStart = function()
   170 		SendHealthStatsOff()
   156 		SendHealthStatsOff()
   171 		local recordInfo = getReadableChallengeRecord("Highscore")
   157 		local recordInfo = getReadableChallengeRecord("Highscore")
   172 		ShowMission(params.missionTitle, loc("Aiming practice"), params.goalText .. "|" .. recordInfo, -params.ammoType, 5000)
   158 		ShowMission(params.missionTitle, loc("Aiming practice"), params.goalText .. "|" .. recordInfo, -params.ammoType, 5000)
   173 		SetTeamLabel(params.teamName, "0")
   159 		SetTeamLabel(GetHogTeamName(player), "0")
   174 		spawnTarget()
   160 		spawnTarget()
   175 	end
   161 	end
   176 
   162 
   177 	_G.onNewTurn = function()
   163 	_G.onNewTurn = function()
   178 		SetWeapon(params.ammoType)
   164 		SetWeapon(params.ammoType)
   238 	end
   224 	end
   239 
   225 
   240 	_G.onGearDamage = function(gear, damage)
   226 	_G.onGearDamage = function(gear, damage)
   241 		if GetGearType(gear) == gtTarget then
   227 		if GetGearType(gear) == gtTarget then
   242 			scored = scored + 1
   228 			scored = scored + 1
   243 			SetTeamLabel(params.teamName, tostring(getTargetsScore()))
   229 			SetTeamLabel(GetHogTeamName(player), tostring(getTargetsScore()))
   244 			if scored < total_targets then
   230 			if scored < total_targets then
   245 				AddCaption(string.format(loc("Targets left: %d"), (total_targets-scored)), capcolDefault, capgrpMessage)
   231 				AddCaption(string.format(loc("Targets left: %d"), (total_targets-scored)), capcolDefault, capgrpMessage)
   246 				spawnTarget()
   232 				spawnTarget()
   247 			else
   233 			else
   248 				if not game_lost then
   234 				if not game_lost then
   297 		local end_score_overall
   283 		local end_score_overall
   298 		if not game_lost then
   284 		if not game_lost then
   299 			local end_score_time = math.ceil(time_goal/(params.time/6000))
   285 			local end_score_time = math.ceil(time_goal/(params.time/6000))
   300 			local end_score_accuracy = math.ceil(accuracy * 60)
   286 			local end_score_accuracy = math.ceil(accuracy * 60)
   301 			end_score_overall = end_score_time + end_score_targets + end_score_accuracy
   287 			end_score_overall = end_score_time + end_score_targets + end_score_accuracy
   302 			SetTeamLabel(params.teamName, tostring(end_score_overall))
   288 			SetTeamLabel(GetHogTeamName(player), tostring(end_score_overall))
   303 
   289 
   304 			SendStat(siGameResult, loc("You have finished the target practice!"))
   290 			SendStat(siGameResult, loc("You have finished the target practice!"))
   305 
   291 
   306 			SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), scored, total_targets, end_score_targets))
   292 			SendStat(siCustomAchievement, string.format(loc("You have destroyed %d of %d targets (+%d points)."), scored, total_targets, end_score_targets))
   307 			SendStat(siCustomAchievement, string.format(params.shootText, shots))
   293 			SendStat(siCustomAchievement, string.format(params.shootText, shots))
   316 				SendStat(siCustomAchievement, string.format(loc("Your accuracy was %.1f%%."), accuracy))
   302 				SendStat(siCustomAchievement, string.format(loc("Your accuracy was %.1f%%."), accuracy))
   317 			end
   303 			end
   318 			end_score_overall = end_score_targets
   304 			end_score_overall = end_score_targets
   319 		end
   305 		end
   320 		SendStat(siPointType, loc("point(s)"))
   306 		SendStat(siPointType, loc("point(s)"))
   321 		SendStat(siPlayerKills, tostring(end_score_overall), loc(params.teamName))
   307 		SendStat(siPlayerKills, tostring(end_score_overall), GetHogTeamName(player))
   322 		-- Update highscore
   308 		-- Update highscore
   323 		updateChallengeRecord("Highscore", end_score_overall)
   309 		updateChallengeRecord("Highscore", end_score_overall)
   324 	end
   310 	end
   325 end
   311 end