share/hedgewars/Data/Scripts/Multiplayer/Racer.lua
changeset 6253 d73317579ae4
parent 5923 ae8cfd039ab2
child 7139 a47fd17ba463
equal deleted inserted replaced
6252:8d598aa498b0 6253:d73317579ae4
     1 
     1 
     2 ------------------------------------------
     2 ------------------------------------------
     3 -- RACER 0.4
     3 -- RACER 0.5
     4 -- map-independant racing script
     4 -- map-independant racing script
     5 -- by mikade
     5 -- by mikade
     6 -----------------------------------------
     6 -----------------------------------------
     7 
     7 
     8 -----------------------------------
     8 -----------------------------------
    50 -------
    50 -------
    51 
    51 
    52 -- update user feedback
    52 -- update user feedback
    53 -- add more sounds
    53 -- add more sounds
    54 
    54 
       
    55 -------
       
    56 -- 0.5
       
    57 -------
       
    58 
       
    59 -- fix ghost disappearing if hog falls in water or somehow dies
       
    60 -- lengthen ghost tracking interval to improve performance on slower machines
       
    61 -- increase waypoint limit to 8
       
    62 -- allow for persistent showmission information
       
    63 
    55 -----------------------------
    64 -----------------------------
    56 -- SCRIPT BEGINS
    65 -- SCRIPT BEGINS
    57 -----------------------------
    66 -----------------------------
    58 
    67 
    59 loadfile(GetDataPath() .. "Scripts/Locale.lua")()
    68 loadfile(GetDataPath() .. "Scripts/Locale.lua")()
   114 local wpY = {}
   123 local wpY = {}
   115 local wpCol = {}
   124 local wpCol = {}
   116 local wpActive = {}
   125 local wpActive = {}
   117 local wpRad = 450 --75
   126 local wpRad = 450 --75
   118 local wpCount = 0
   127 local wpCount = 0
   119 local wpLimit = 5
   128 local wpLimit = 8
       
   129 
       
   130 local roundN
       
   131 local lastRound
       
   132 local RoundHasChanged
   120 
   133 
   121 -------------------
   134 -------------------
   122 -- general methods
   135 -- general methods
   123 -------------------
   136 -------------------
   124 
   137 
   315 	end
   328 	end
   316 
   329 
   317 
   330 
   318 end
   331 end
   319 
   332 
       
   333 function onNewRound()
       
   334 
       
   335 	roundNumber = roundNumber + 1
       
   336 
       
   337 	totalComment = ""
       
   338 	for i = 0, (TeamsCount-1) do
       
   339 			if teamNameArr[i] ~= " " then				-- teamScore[teamClan[i]]
       
   340 				teamComment[i] = teamNameArr[i] .. ": " .. (teamScore[i]/1000) .. loc("s|")
       
   341 				totalComment = totalComment .. teamComment[i]
       
   342 			elseif teamNameArr[i] == " " then
       
   343 				teamComment[i] = "|"
       
   344 			end
       
   345 	end
       
   346 
       
   347 	ShowMission(	loc("RACER"),
       
   348 					loc("STATUS UPDATE"),
       
   349 					loc("Rounds Complete: ") .. roundNumber .. "/" .. roundLimit .. "|" .. " " .. "|" ..
       
   350 					loc("Best Team Times: ") .. "|" .. totalComment, 0, 4000)
       
   351 
       
   352 	-- end game if its at round limit
       
   353 	if roundNumber == roundLimit then
       
   354 		for i = 0, (numhhs-1) do
       
   355 			if GetHogClan(hhs[i]) ~= bestClan then
       
   356 				SetEffect(hhs[i], heResurrectable, false)
       
   357 				SetHealth(hhs[i],0)
       
   358 			end
       
   359 		end
       
   360 		gameOver = true
       
   361 		TurnTimeLeft = 1
       
   362 	end
       
   363 
       
   364 end
       
   365 
   320 function CheckForNewRound()
   366 function CheckForNewRound()
   321 
   367 
   322 	if GetHogClan(CurrentHedgehog) == firstClan then
   368 	-------------
   323 
   369 	------ new
   324 		roundNumber = roundNumber + 1
   370 	-------------
   325 
   371 
   326 		totalComment = ""
   372 	--[[turnN = turnN + 1
   327 		for i = 0, (TeamsCount-1) do
   373 	if gameBegun == false then
   328 				if teamNameArr[i] ~= " " then				-- teamScore[teamClan[i]]
   374 		if turnN == 2 then
   329 					teamComment[i] = teamNameArr[i] .. ": " .. (teamScore[i]/1000) .. loc("s|")
       
   330 					totalComment = totalComment .. teamComment[i]
       
   331 				elseif teamNameArr[i] == " " then
       
   332 					teamComment[i] = "|"
       
   333 				end
       
   334 		end
       
   335 
       
   336 		ShowMission(	loc("RACER"),
       
   337 				loc("STATUS UPDATE"),
       
   338 				loc("Rounds Complete: ") .. roundNumber .. "/" .. roundLimit .. "|" .. " " .. "|" ..
       
   339 				loc("Best Team Times: ") .. "|" .. totalComment, 0, 4000)
       
   340 
       
   341 		-- end game if its at round limit
       
   342 		if roundNumber == roundLimit then
       
   343 			for i = 0, (numhhs-1) do
   375 			for i = 0, (numhhs-1) do
   344 				if GetHogClan(hhs[i]) ~= bestClan then
   376 				if hhs[i] ~= nil then
   345 					SetEffect(hhs[i], heResurrectable, false)
   377 					SetEffect(hhs[i], heResurrectable, false)
   346 					SetHealth(hhs[i],0)
   378 					SetHealth(hhs[i],0)
   347 				end
   379 				end
   348 			end
   380 			end
   349 			gameOver = true
   381 			gameOver = true
   350 			TurnTimeLeft = 1
   382 			TurnTimeLeft = 1
   351 		end
   383 		end
   352 
   384 	else
       
   385 
       
   386 
       
   387 	end]]
       
   388 
       
   389 	--[[if roundBegun == true then
       
   390 
       
   391 		if RoundHasChanged == true then
       
   392 			roundN = roundN + 1
       
   393 			RoundHasChanged = false
       
   394 			onNewRound()
       
   395 		end
       
   396 
       
   397 		if lastRound ~= TotalRounds then -- new round, but not really
       
   398 
       
   399 			if RoundHasChanged == false then
       
   400 				RoundHasChanged = true
       
   401 			end
       
   402 
       
   403 		end
       
   404 
       
   405 		AddCaption("RoundN:" .. roundN .. "; " .. "TR: " .. TotalRounds)
       
   406 
       
   407 		lastRound = TotalRounds
       
   408 
       
   409 	end]]
       
   410 
       
   411 	------------
       
   412 	----- old
       
   413 	------------
       
   414 
       
   415 	if GetHogClan(CurrentHedgehog) == firstClan then
       
   416 		onNewRound()
   353 	end
   417 	end
   354 
   418 
   355 end
   419 end
   356 
   420 
   357 function DisableTumbler()
   421 function DisableTumbler()
   400 	WaterRise = 0
   464 	WaterRise = 0
   401 end
   465 end
   402 
   466 
   403 
   467 
   404 function onGameStart()
   468 function onGameStart()
       
   469 
       
   470 	roundN = 0
       
   471 	lastRound = TotalRounds
       
   472 	RoundHasChanged = false -- true
       
   473 
   405 	RebuildTeamInfo()
   474 	RebuildTeamInfo()
   406 
   475 
   407 	ShowMission	(
   476 	ShowMission	(
   408 				loc("RACER"),
   477 				loc("RACER"),
   409 				loc("a Hedgewars mini-game"),
   478 				loc("a Hedgewars mini-game"),
   411 				loc("Build a track and race.") .. "|" ..
   480 				loc("Build a track and race.") .. "|" ..
   412 				loc("Round Limit:") .. " " .. roundLimit .. "|" ..
   481 				loc("Round Limit:") .. " " .. roundLimit .. "|" ..
   413 
   482 
   414 				"", 4, 4000
   483 				"", 4, 4000
   415 				)
   484 				)
   416 
       
   417 
       
   418 end
   485 end
   419 
   486 
   420 function PlaceWayPoint(x,y)
   487 function PlaceWayPoint(x,y)
   421 
   488 
   422 	if (wpCount < wpLimit) then -- seems to not work with a hedgehog nil chek
   489 	if (wpCount < wpLimit) then -- seems to not work with a hedgehog nil chek
   488 function onGameTick()
   555 function onGameTick()
   489 
   556 
   490 	-- airstrike detected, convert this into a potential waypoint spot
   557 	-- airstrike detected, convert this into a potential waypoint spot
   491 	if cGear ~= nil then
   558 	if cGear ~= nil then
   492 		x,y = GetGearTarget(cGear)
   559 		x,y = GetGearTarget(cGear)
   493 		
   560 
   494 		DeleteGear(cGear)
   561 		DeleteGear(cGear)
   495 
   562 
   496 		if TestRectForObstacle(x-20, y-20, x+20, y+20, true) then
   563 		if TestRectForObstacle(x-20, y-20, x+20, y+20, true) then
   497 			AddCaption(loc("Please place the way-point in the open, within the map boundaries."))
   564 			AddCaption(loc("Please place the way-point in the open, within the map boundaries."))
   498 			PlaySound(sndDenied)
   565 			PlaySound(sndDenied)
   523 				trackTime = 0
   590 				trackTime = 0
   524 
   591 
   525 				SetGearPosition(CurrentHedgehog, wpX[0], wpY[0])
   592 				SetGearPosition(CurrentHedgehog, wpX[0], wpY[0])
   526 				AddGear(GetX(CurrentHedgehog), GetY(CurrentHedgehog), gtGrenade, 0, 0, 0, 1)
   593 				AddGear(GetX(CurrentHedgehog), GetY(CurrentHedgehog), gtGrenade, 0, 0, 0, 1)
   527 				FollowGear(CurrentHedgehog)
   594 				FollowGear(CurrentHedgehog)
   528 				ShowMission("...", "...", "...", 2, 1)
   595 
       
   596 				HideMission()
   529 
   597 
   530 			else
   598 			else
   531 				-- still in placement mode
   599 				-- still in placement mode
   532 			end
   600 			end
   533 
   601 
   544 		-- if the RACE has started, show tracktimes and keep tabs on waypoints
   612 		-- if the RACE has started, show tracktimes and keep tabs on waypoints
   545 		if (racerActive == true) and (gameBegun == true) then
   613 		if (racerActive == true) and (gameBegun == true) then
   546 
   614 
   547 			--ghost
   615 			--ghost
   548 			gTimer = gTimer + 1
   616 			gTimer = gTimer + 1
   549 			if gTimer == 15 then
   617 			if gTimer == 40 then
   550 				gTimer = 0
   618 				gTimer = 0
   551 				HandleGhost()
   619 				HandleGhost()
   552 			end
   620 			end
   553 
   621 
   554 			trackTime = trackTime + 1
   622 			trackTime = trackTime + 1
   581 end
   649 end
   582 
   650 
   583 function onGearResurrect(gear)
   651 function onGearResurrect(gear)
   584 
   652 
   585 	AddVisualGear(GetX(gear), GetY(gear), vgtBigExplosion, 0, false)
   653 	AddVisualGear(GetX(gear), GetY(gear), vgtBigExplosion, 0, false)
       
   654 
       
   655 	if gear == CurrentHedgehog then
       
   656 		DisableTumbler()
       
   657 	end
   586 
   658 
   587 	-- if the player stops and "dies" or flies into water, stop him racing
   659 	-- if the player stops and "dies" or flies into water, stop him racing
   588 	--[[if gear == CurrentHedgehog then
   660 	--[[if gear == CurrentHedgehog then
   589 		DisableTumbler()
   661 		DisableTumbler()
   590 		ShowMission(loc("RACER"),
   662 		ShowMission(loc("RACER"),