share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua
changeset 13561 cba63f72e52f
parent 13560 dc7b1a4ddded
child 13562 0ff20bb15037
equal deleted inserted replaced
13560:dc7b1a4ddded 13561:cba63f72e52f
   161 local wpCirc = {}
   161 local wpCirc = {}
   162 local wpX = {}
   162 local wpX = {}
   163 local wpY = {}
   163 local wpY = {}
   164 local wpCol = {}
   164 local wpCol = {}
   165 local wpActive = {}
   165 local wpActive = {}
   166 local wpRad = 450 --75
   166 local wpRad = 450
   167 local wpCount = 0
   167 local wpCount = 0
   168 local wpLimit = 20
   168 local wpLimit = 20
   169 
   169 
   170 local usedWeapons = {}
   170 local usedWeapons = {}
   171 
   171 
   172 local roundN
   172 local roundN
   173 local lastRound
   173 local lastRound
   174 local RoundHasChanged
   174 local RoundHasChanged
       
   175 
       
   176 local cnthhs = 0
   175 
   177 
   176 -------------------
   178 -------------------
   177 -- general methods
   179 -- general methods
   178 -------------------
   180 -------------------
   179 
   181 
   188 	end
   190 	end
   189 	numTeams = 0
   191 	numTeams = 0
   190 
   192 
   191 	for i = 0, (numhhs-1) do
   193 	for i = 0, (numhhs-1) do
   192 
   194 
   193 		z = 0
   195 		local z = 0
   194 		unfinished = true
   196 		local unfinished = true
   195 		while(unfinished == true) do
   197 		while(unfinished == true) do
   196 
   198 
   197 			newTeam = true
   199 			local newTeam = true
   198 			tempHogTeamName = GetHogTeamName(hhs[i]) -- this is the new name
   200 			local tempHogTeamName = GetHogTeamName(hhs[i]) -- this is the new name
   199 
   201 
   200 			if tempHogTeamName == teamNameArr[z] then
   202 			if tempHogTeamName == teamNameArr[z] then
   201 				newTeam = false
   203 				newTeam = false
   202 				unfinished = false
   204 				unfinished = false
   203 			end
   205 			end
   258 
   260 
   259 	trackFinished = true
   261 	trackFinished = true
   260 
   262 
   261 	for i = 0, (wpCount-1) do
   263 	for i = 0, (wpCount-1) do
   262 
   264 
   263 		g1X, g1Y = GetGearPosition(CurrentHedgehog)
   265 		local g1X, g1Y = GetGearPosition(CurrentHedgehog)
   264 		g2X, g2Y = wpX[i], wpY[i]
   266 		local g2X, g2Y = wpX[i], wpY[i]
   265 
   267 
   266 		g1X = g1X - g2X
   268 		local g1X = g1X - g2X
   267 		g1Y = g1Y - g2Y
   269 		local g1Y = g1Y - g2Y
   268 		dist = (g1X*g1X) + (g1Y*g1Y)
   270 		local dist = (g1X*g1X) + (g1Y*g1Y)
   269 
   271 
   270 		NR = (48/100*wpRad)/2
   272 		local NR = (48/100*wpRad)/2
   271 
   273 
   272 		if dist < (NR*NR) and not gameOver then
   274 		if dist < (NR*NR) and not gameOver then
   273 			wpCol[i] = GetClanColor(GetHogClan(CurrentHedgehog))
   275 			wpCol[i] = GetClanColor(GetHogClan(CurrentHedgehog))
   274 			SetVisualGearValues(wpCirc[i], wpX[i], wpY[i], 64, 64, 1, 10, 0, wpRad, 5, wpCol[i])
   276 			SetVisualGearValues(wpCirc[i], wpX[i], wpY[i], 64, 64, 1, 10, 0, wpRad, 5, wpCol[i])
   275 
   277 
   276 			wpRem = 0
   278 			local wpRem = 0
   277 			for k = 0, (wpCount-1) do
   279 			for k = 0, (wpCount-1) do
   278 				if wpActive[k] == false then
   280 				if wpActive[k] == false then
   279 					wpRem = wpRem + 1
   281 					wpRem = wpRem + 1
   280 				end
   282 				end
   281 			end
   283 			end
   306 
   308 
   307 function AdjustScores()
   309 function AdjustScores()
   308 
   310 
   309 	local bestTimeComment = loc("Did not finish")
   311 	local bestTimeComment = loc("Did not finish")
   310 
   312 
   311 	newScore = false
   313 	local newScore = false
   312 
   314 
   313 	-- update this clan's time if the new track is better
   315 	-- update this clan's time if the new track is better
   314 	for i = 0, (numTeams-1) do
   316 	for i = 0, (numTeams-1) do
   315 		if teamClan[i] == GetHogClan(CurrentHedgehog) then
   317 		if teamClan[i] == GetHogClan(CurrentHedgehog) then
   316 			if trackTime < teamScore[i] then
   318 			if trackTime < teamScore[i] then
   347 			string.format(loc("New clan record: %.1fs"), (trackTime/1000)) .. "|" ..
   349 			string.format(loc("New clan record: %.1fs"), (trackTime/1000)) .. "|" ..
   348 			string.format(loc("Winning time: %s"), bestTimeComment), 4, 4000)
   350 			string.format(loc("Winning time: %s"), bestTimeComment), 4, 4000)
   349 		end
   351 		end
   350 	else -- not any kind of new score
   352 	else -- not any kind of new score
   351 		ShowMission(loc("TechRacer"),
   353 		ShowMission(loc("TechRacer"),
   352 		loc("Track completed!"),
   354 			loc("Track completed!"),
   353 		string.format(loc("Time: %.1fs"), (trackTime/1000)) .. "|" ..
   355 			string.format(loc("Time: %.1fs"), (trackTime/1000)) .. "|" ..
   354 		string.format(loc("Winning time: %s"), bestTimeComment), -amSkip, 4000)
   356 			string.format(loc("Winning time: %s"), bestTimeComment), -amSkip, 4000)
   355 		PlaySound(sndHellish)
   357 		PlaySound(sndHellish)
   356 	end
   358 	end
   357 
   359 
   358 	for i = 0, (TeamsCount-1) do
   360 	for i = 0, (TeamsCount-1) do
   359 		if teamNameArr[i] ~= " " and teamScore[i] ~= 1000000 then
   361 		if teamNameArr[i] ~= " " and teamScore[i] ~= 1000000 then
   382 
   384 
   383 function onNewRound()
   385 function onNewRound()
   384 
   386 
   385 	roundNumber = roundNumber + 1
   387 	roundNumber = roundNumber + 1
   386 
   388 
   387 	totalComment = ""
   389 	local totalComment = ""
   388 	for i = 0, (TeamsCount-1) do
   390 	for i = 0, (TeamsCount-1) do
   389 		if teamNameArr[i] ~= " " then
   391 		if teamNameArr[i] ~= " " then
   390 			if teamScore[i] ~= 1000000 then
   392 			if teamScore[i] ~= 1000000 then
   391 				teamComment[i] = string.format(loc("%s: %.1fs"), teamNameArr[i], (teamScore[i]/1000)) .. "|"
   393 				teamComment[i] = string.format(loc("%s: %.1fs"), teamNameArr[i], (teamScore[i]/1000)) .. "|"
   392 			else
   394 			else
   499 	-- draw a ping of smoke where the fastest player was at this point
   501 	-- draw a ping of smoke where the fastest player was at this point
   500 	if (fastCount ~= 0) and (fastIndex < fastCount) then
   502 	if (fastCount ~= 0) and (fastIndex < fastCount) then
   501 
   503 
   502 		fastIndex = fastIndex + 1
   504 		fastIndex = fastIndex + 1
   503 
   505 
   504 		tempE = AddVisualGear(fastX[fastIndex], fastY[fastIndex], vgtSmoke, 0, false)
   506 		local tempE = AddVisualGear(fastX[fastIndex], fastY[fastIndex], vgtSmoke, 0, false)
   505 		g1, g2, g3, g4, g5, g6, g7, g8, g9, g10 = GetVisualGearValues(tempE)
   507 		SetVisualGearValues(tempE, nil, nil, nil, nil, nil, nil, nil, nil, nil, fastColour )
   506 		SetVisualGearValues(tempE, g1, g2, g3, g4, g5, g6, g7, g8, g9, fastColour )
       
   507 
   508 
   508 	end
   509 	end
   509 
   510 
   510 end
   511 end
   511 
   512 
   512 function BoomGirder(x,y,rot)
   513 function BoomGirder(x,y,rot)
   513 	girTime = 1
   514 	local girTime = 1
   514 	if rot < 4 then
   515 	if rot < 4 then
   515 		AddGear(x, y, gtGrenade, 0, 0, 0, girTime)
   516 		AddGear(x, y, gtGrenade, 0, 0, 0, girTime)
   516 	elseif rot == 4 then
   517 	elseif rot == 4 then
   517 		g = AddGear(x-45, y, gtGrenade, 0, 0, 0, girTime) -- needed?
   518 		AddGear(x-45, y, gtGrenade, 0, 0, 0, girTime) -- needed?
   518 		g = AddGear(x-30, y, gtGrenade, 0, 0, 0, girTime)
   519 		AddGear(x-30, y, gtGrenade, 0, 0, 0, girTime)
   519 		g = AddGear(x, y, gtGrenade, 0, 0, 0, girTime) -- needed?
   520 		AddGear(x, y, gtGrenade, 0, 0, 0, girTime) -- needed?
   520 		g = AddGear(x+30, y, gtGrenade, 0, 0, 0, girTime)
   521 		AddGear(x+30, y, gtGrenade, 0, 0, 0, girTime)
   521 		g = AddGear(x+45, y, gtGrenade, 0, 0, 0, girTime) -- needed?
   522 		AddGear(x+45, y, gtGrenade, 0, 0, 0, girTime) -- needed?
   522 	elseif rot == 5 then ------- diag
   523 	elseif rot == 5 then ------- diag
   523 		g = AddGear(x+45, y+45, gtGrenade, 0, 0, 0, girTime) --n
   524 		AddGear(x+45, y+45, gtGrenade, 0, 0, 0, girTime) --n
   524 		g = AddGear(x+30, y+30, gtGrenade, 0, 0, 0, girTime)
   525 		AddGear(x+30, y+30, gtGrenade, 0, 0, 0, girTime)
   525 		g = AddGear(x, y, gtGrenade, 0, 0, 0, girTime) -- needed?
   526 		AddGear(x, y, gtGrenade, 0, 0, 0, girTime) -- needed?
   526 		g = AddGear(x-30, y-30, gtGrenade, 0, 0, 0, girTime)
   527 		AddGear(x-30, y-30, gtGrenade, 0, 0, 0, girTime)
   527 		g = AddGear(x-45, y-45, gtGrenade, 0, 0, 0, girTime) --n
   528 		AddGear(x-45, y-45, gtGrenade, 0, 0, 0, girTime) --n
   528 	elseif rot == 6 then
   529 	elseif rot == 6 then
   529 		g = AddGear(x, y-45, gtGrenade, 0, 0, 0, girTime) -- needed?
   530 		AddGear(x, y-45, gtGrenade, 0, 0, 0, girTime) -- needed?
   530 		g = AddGear(x, y+30, gtGrenade, 0, 0, 0, girTime)
   531 		AddGear(x, y+30, gtGrenade, 0, 0, 0, girTime)
   531 		g = AddGear(x, y, gtGrenade, 0, 0, 0, girTime) -- needed?
   532 		AddGear(x, y, gtGrenade, 0, 0, 0, girTime) -- needed?
   532 		g = AddGear(x, y-30, gtGrenade, 0, 0, 0, girTime)
   533 		AddGear(x, y-30, gtGrenade, 0, 0, 0, girTime)
   533 		g = AddGear(x, y+45, gtGrenade, 0, 0, 0, girTime) -- needed?
   534 		AddGear(x, y+45, gtGrenade, 0, 0, 0, girTime) -- needed?
   534 	elseif rot == 7 then -------
   535 	elseif rot == 7 then -------
   535 		g = AddGear(x+45, y-45, gtGrenade, 0, 0, 0, girTime) --n
   536 		AddGear(x+45, y-45, gtGrenade, 0, 0, 0, girTime) --n
   536 		g = AddGear(x+30, y-30, gtGrenade, 0, 0, 0, girTime)
   537 		AddGear(x+30, y-30, gtGrenade, 0, 0, 0, girTime)
   537 		g = AddGear(x, y, gtGrenade, 0, 0, 0, girTime) -- needed?
   538 		AddGear(x, y, gtGrenade, 0, 0, 0, girTime) -- needed?
   538 		g = AddGear(x-30, y+30, gtGrenade, 0, 0, 0, girTime)
   539 		AddGear(x-30, y+30, gtGrenade, 0, 0, 0, girTime)
   539 		g = AddGear(x-45, y+45, gtGrenade, 0, 0, 0, girTime) --n
   540 		AddGear(x-45, y+45, gtGrenade, 0, 0, 0, girTime) --n
   540 	end
   541 	end
   541 end
   542 end
   542 
   543 
   543 function RemoveGear(gear)
   544 function RemoveGear(gear)
   544 	if (isATrackedGear(gear) == true) and (GetGearType(gear) ~= gtHedgehog) then
   545 	if (isATrackedGear(gear) == true) and (GetGearType(gear) ~= gtHedgehog) then
   909 	activationStage = 1
   910 	activationStage = 1
   910 
   911 
   911 	trackTime = 0
   912 	trackTime = 0
   912 
   913 
   913 	currCount = 0 -- hopefully this solves problem
   914 	currCount = 0 -- hopefully this solves problem
   914 	gTimer = 0
       
   915 
   915 
   916 	-- Set the waypoints to unactive on new round
   916 	-- Set the waypoints to unactive on new round
   917 	if not gameOver then
   917 	if not gameOver then
   918 		for i = 0,(wpCount-1) do
   918 		for i = 0,(wpCount-1) do
   919 			wpActive[i] = false
   919 			wpActive[i] = false
   953 
   953 
   954 	runOnGears(PortalEffects)
   954 	runOnGears(PortalEffects)
   955 
   955 
   956 	-- airstrike detected, convert this into a potential waypoint spot
   956 	-- airstrike detected, convert this into a potential waypoint spot
   957 	if cGear ~= nil then
   957 	if cGear ~= nil then
   958 		x,y = GetGearPosition(cGear)
   958 		local x,y = GetGearPosition(cGear)
   959 		if x > -9000 then
   959 		if x > -9000 then
   960 			x,y = GetGearTarget(cGear)
   960 			x,y = GetGearTarget(cGear)
   961 
   961 
   962 			if TestRectForObstacle(x-20, y-20, x+20, y+20, true) then
   962 			if TestRectForObstacle(x-20, y-20, x+20, y+20, true) then
   963 				AddCaption(loc("Please place the waypoint in the air and within the map boundaries"))
   963 				AddCaption(loc("Please place the waypoint in the air and within the map boundaries"))
  1080 		if (tag == 0) or (tag == 2) then -- i.e ball form
  1080 		if (tag == 0) or (tag == 2) then -- i.e ball form
  1081 			local remLife = getGearValue(gear,"life")
  1081 			local remLife = getGearValue(gear,"life")
  1082 			remLife = remLife - 1
  1082 			remLife = remLife - 1
  1083 			setGearValue(gear, "life", remLife)
  1083 			setGearValue(gear, "life", remLife)
  1084 
  1084 
       
  1085 			-- Limited range portal ball dies
  1085 			if remLife == 0 then
  1086 			if remLife == 0 then
  1086 
  1087 
       
  1088 				-- Make portal ball disappear in a puff of smoke
  1087 				local tempE = AddVisualGear(GetX(gear)+15, GetY(gear), vgtSmoke, 0, true)
  1089 				local tempE = AddVisualGear(GetX(gear)+15, GetY(gear), vgtSmoke, 0, true)
  1088 				SetVisualGearValues(tempE, nil, nil, nil, nil, nil, nil, nil, nil, nil, col)
  1090 				SetVisualGearValues(tempE, nil, nil, nil, nil, nil, nil, nil, nil, nil, col)
  1089 
  1091 
  1090 				tempE = AddVisualGear(GetX(gear)-15, GetY(gear), vgtSmoke, 0, true)
  1092 				tempE = AddVisualGear(GetX(gear)-15, GetY(gear), vgtSmoke, 0, true)
  1091 				SetVisualGearValues(tempE, nil, nil, nil, nil, nil, nil, nil, nil, nil, col)
  1093 				SetVisualGearValues(tempE, nil, nil, nil, nil, nil, nil, nil, nil, nil, col)
  1175 	end
  1177 	end
  1176 
  1178 
  1177 end
  1179 end
  1178 
  1180 
  1179 function onAttack()
  1181 function onAttack()
  1180 	at = GetCurAmmoType()
  1182 	local at = GetCurAmmoType()
  1181 
  1183 
  1182 	usedWeapons[at] = 0
  1184 	usedWeapons[at] = 0
  1183 end
  1185 end
  1184 
  1186 
  1185 function onAchievementsDeclaration()
  1187 function onAchievementsDeclaration()
  1186 	usedWeapons[amSkip] = nil
  1188 	usedWeapons[amSkip] = nil
  1187 	usedWeapons[amExtraTime] = nil
  1189 	usedWeapons[amExtraTime] = nil
  1188 
  1190 
  1189 	usedRope = usedWeapons[amRope] ~= nil
  1191 	local usedRope = usedWeapons[amRope] ~= nil
  1190 	usedPortal = usedWeapons[amPortalGun] ~= nil
  1192 	local usedPortal = usedWeapons[amPortalGun] ~= nil
  1191 	usedSaucer = usedWeapons[amJetpack] ~= nil
  1193 	local usedSaucer = usedWeapons[amJetpack] ~= nil
  1192 
  1194 
  1193 	usedWeapons[amRope] = nil
  1195 	usedWeapons[amRope] = nil
  1194 	usedWeapons[amPortalGun] = nil
  1196 	usedWeapons[amPortalGun] = nil
  1195 	usedWeapons[amJetpack] = nil
  1197 	usedWeapons[amJetpack] = nil
  1196 
  1198 
  1197 	usedOther = next(usedWeapons) ~= nil
  1199 	local usedOther = next(usedWeapons) ~= nil
  1198 
  1200 
       
  1201 	local raceType
  1199 	if usedOther then -- smth besides skip, rope, portal or saucer used
  1202 	if usedOther then -- smth besides skip, rope, portal or saucer used
  1200 		raceType = "unknown race"
  1203 		raceType = "unknown race"
  1201 	elseif usedRope and not usedPortal and not usedSaucer then
  1204 	elseif usedRope and not usedPortal and not usedSaucer then
  1202 		raceType = "rope race"
  1205 		raceType = "rope race"
  1203 	elseif not usedRope and usedPortal and not usedSaucer then
  1206 	elseif not usedRope and usedPortal and not usedSaucer then