share/hedgewars/Data/Scripts/TargetPractice.lua
changeset 13098 d3e9f3423ef3
parent 13065 a297e06d1607
child 13099 071dcdf33f86
equal deleted inserted replaced
13097:03d065fc60dc 13098:d3e9f3423ef3
    31 	map = ,
    31 	map = ,
    32 	theme = ,
    32 	theme = ,
    33 	time = ,
    33 	time = ,
    34 	ammoType = ,
    34 	ammoType = ,
    35 	gearType = ,
    35 	gearType = ,
       
    36 	secondaryGearType = ,
    36 	targets = {
    37 	targets = {
    37 		{ x = , y = },
    38 		{ x = , y = },
    38 		{ x = , y = },
    39 		{ x = , y = },
    39 		-- etc.
    40 		-- etc.
    40 	},
    41 	},
    62 local end_timer = 1000
    63 local end_timer = 1000
    63 local game_lost = false
    64 local game_lost = false
    64 local time_goal = 0
    65 local time_goal = 0
    65 local total_targets
    66 local total_targets
    66 local targets
    67 local targets
       
    68 local gearsInGameCount = 0
       
    69 local gearsInGame = {}
    67 
    70 
    68 --[[
    71 --[[
    69 TrainingMission(params)
    72 TrainingMission(params)
    70 
    73 
    71 This function sets up the *entire* training mission and needs one argument: params.
    74 This function sets up the *entire* training mission and needs one argument: params.
    74 	- missionTitle:	the name of the mission
    77 	- missionTitle:	the name of the mission
    75 	- map:		the name map to be used
    78 	- map:		the name map to be used
    76 	- theme:	the name of the theme (does not need to be a standalone theme)
    79 	- theme:	the name of the theme (does not need to be a standalone theme)
    77 	- time:		the time limit in milliseconds
    80 	- time:		the time limit in milliseconds
    78 	- ammoType:	the ammo type of the weapon to be used
    81 	- ammoType:	the ammo type of the weapon to be used
    79 	- gearType:	the gear type of the gear which is fired (used to count shots)
    82 	- gearType:	the gear type of the gear which is fired (used to count shots and re-center camera)
    80 	- targets:	The coordinates of where the targets will be spawned.
    83 	- targets:	The coordinates of where the targets will be spawned.
    81 			It is a table containing tables containing coordinates of format
    84 			It is a table containing tables containing coordinates of format
    82 			{ x=value, y=value }. The targets will be spawned in the same
    85 			{ x=value, y=value }. The targets will be spawned in the same
    83 			order as specified the coordinate tables appear. Example:
    86 			order as specified the coordinate tables appear. Example:
    84 				targets = {
    87 				targets = {
    95 	- hogHat:	hat of the hedgehog (default: "NoHat")
    98 	- hogHat:	hat of the hedgehog (default: "NoHat")
    96 	- hogName:	name of the hedgehog (default: "Trainee")
    99 	- hogName:	name of the hedgehog (default: "Trainee")
    97 	- teamName:	name of the hedgehog’s team (default: "Training Team")
   100 	- teamName:	name of the hedgehog’s team (default: "Training Team")
    98 	- teamGrave:	name of the hedgehog’s grave
   101 	- teamGrave:	name of the hedgehog’s grave
    99 	- teamFlag:	name of the team’s flag (default: "cm_crosshair")
   102 	- teamFlag:	name of the team’s flag (default: "cm_crosshair")
       
   103 	- secGearType:	cluster of projectile gear (if present) (used to re-center camera)
   100 	- clanColor:	color of the (only) clan (default: 0xFF0204, which is a red tone)
   104 	- clanColor:	color of the (only) clan (default: 0xFF0204, which is a red tone)
   101 	- goalText:	A short string explaining the goal of the mission
   105 	- goalText:	A short string explaining the goal of the mission
   102 			(default: "Destroy all targets within the time!")
   106 			(default: "Destroy all targets within the time!")
   103 	- shootText:	A string which says how many times the player shot, “%d” is replaced
   107 	- shootText:	A string which says how many times the player shot, “%d” is replaced
   104 			by the number of shots. (default: "You have shot %d times.")
   108 			by the number of shots. (default: "You have shot %d times.")
   197 				generateStats()
   201 				generateStats()
   198 				EndGame()
   202 				EndGame()
   199 			else
   203 			else
   200 				TurnTimeLeft = time_goal
   204 				TurnTimeLeft = time_goal
   201 			end
   205 			end
   202 	        end_timer = end_timer - 20
   206 	   	     end_timer = end_timer - 20
       
   207 		end
       
   208 
       
   209 		for gear, _ in pairs(gearsInGame) do
       
   210 			if band(GetState(gear), gstDrowning) ~= 0 then
       
   211 				-- Re-center camera on hog if projectile gears drown
       
   212 				gearsInGame[gear] = nil
       
   213 				gearsInGameCount = gearsInGameCount - 1
       
   214 				if gearsInGameCount == 0 and GetHealth(CurrentHedgehog) then
       
   215 					FollowGear(CurrentHedgehog)
       
   216 				end
       
   217 			end
   203 		end
   218 		end
   204 	end
   219 	end
   205 
   220 
   206 	_G.onGearAdd = function(gear)
   221 	_G.onGearAdd = function(gear)
   207 		if GetGearType(gear) == params.gearType then
   222 		if GetGearType(gear) == params.gearType or (params.secGearType and GetGearType(gear) == params.secGearType) then
   208 			shots = shots + 1
   223 			shots = shots + 1
       
   224 			gearsInGameCount = gearsInGameCount + 1
       
   225 			gearsInGame[gear] = true
   209 		end
   226 		end
   210 	end
   227 	end
   211 
   228 
   212 	_G.onGearDamage = function(gear, damage)
   229 	_G.onGearDamage = function(gear, damage)
   213 		if GetGearType(gear) == gtTarget then
   230 		if GetGearType(gear) == gtTarget then
   250 			local x, y = GetGearPosition(newTarget)
   267 			local x, y = GetGearPosition(newTarget)
   251 			local success = PlaceSprite(x, y + 24, sprAmGirder, 0, 0xFFFFFFFF, false, false, false)
   268 			local success = PlaceSprite(x, y + 24, sprAmGirder, 0, 0xFFFFFFFF, false, false, false)
   252 			if not success then
   269 			if not success then
   253 				WriteLnToConsole("ERROR: Failed to spawn girder under respawned target!")
   270 				WriteLnToConsole("ERROR: Failed to spawn girder under respawned target!")
   254 			end
   271 			end
       
   272 		elseif gearsInGame[gear] then
       
   273 			gearsInGame[gear] = nil
       
   274 			gearsInGameCount = gearsInGameCount - 1
       
   275 			if gearsInGameCount == 0 and GetHealth(CurrentHedgehog) then
       
   276 				-- Re-center camera to hog after all projectile gears were destroyed
       
   277 				FollowGear(CurrentHedgehog)
       
   278 			end
   255 		end
   279 		end
   256 	end
   280 	end
   257 
   281 
   258 	_G.generateStats = function()
   282 	_G.generateStats = function()
   259 		local accuracy = (scored/shots)*100
   283 		local accuracy = (scored/shots)*100