share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua
changeset 11937 8fd4926e1e9e
parent 11936 c750c21e4a44
child 12079 8f222872d432
equal deleted inserted replaced
11936:c750c21e4a44 11937:8fd4926e1e9e
   206 -- racer vars
   206 -- racer vars
   207 --------
   207 --------
   208 
   208 
   209 local cGear = nil
   209 local cGear = nil
   210 
   210 
   211 local bestClan = nil
   211 local bestClan = 10
   212 local bestTime = nil
   212 local bestTime = 1000000
   213 
   213 
   214 local gameBegun = false
   214 local gameBegun = false
   215 local gameOver = false
   215 local gameOver = false
   216 local racerActive = false
   216 local racerActive = false
   217 local trackTime = 0
   217 local trackTime = 0
   356 
   356 
   357 end
   357 end
   358 
   358 
   359 function AdjustScores()
   359 function AdjustScores()
   360 
   360 
   361         if bestTime == nil then
   361 	local bestTimeComment = loc("Did not finish")
   362                 bestTime = 1000000
       
   363                 bestClan = 10
       
   364                 bestTimeComment = "N/A"
       
   365         end
       
   366 
   362 
   367         newScore = false
   363         newScore = false
   368 
   364 
   369         -- update this clan's time if the new track is better
   365         -- update this clan's time if the new track is better
   370         for i = 0, (numTeams-1) do
   366         for i = 0, (numTeams-1) do
   376                                 newScore = false
   372                                 newScore = false
   377                         end
   373                         end
   378                 end
   374                 end
   379         end
   375         end
   380 
   376 
   381         --bestTime = 100000
       
   382         --bestClan = 10
       
   383 
       
   384         -- find the best time out of those so far
   377         -- find the best time out of those so far
   385         for i = 0, (numTeams-1) do
   378         for i = 0, (numTeams-1) do
   386                 if teamScore[i] < bestTime then
   379                 if teamScore[i] < bestTime then
   387                         bestTime = teamScore[i]
   380                         bestTime = teamScore[i]
   388                         bestClan = teamClan[i]
   381                         bestClan = teamClan[i]
   389                 end
   382                 end
   390         end
   383         end
   391 
   384 
   392         if bestTime ~= 1000000 then
   385         if bestTime ~= 1000000 then
   393                 bestTimeComment = (bestTime/1000) ..loc("s")
   386                 bestTimeComment = string.format(loc("%.1fs"), (bestTime/1000))
   394         end
   387         end
   395 
   388 
   396         if newScore == true then
   389         if newScore == true then
   397                 if trackTime == bestTime then -- best time of the race
   390                 if trackTime == bestTime then -- best time of the race
   398                         ShowMission(loc("TechRacer"),
   391                         ShowMission(loc("TechRacer"),
   399                         loc("Track completed!"),
   392                         loc("Track completed!"),
   400                         string.format(loc("New race record: %.1fs"), (trackTime/1000)) .. "|" ..
   393                         string.format(loc("New race record: %.1fs"), (trackTime/1000)) .. "|" ..
   401                         string.format(loc("Winning time: %s") .. bestTimeComment), 0, 4000)
   394                         string.format(loc("Winning time: %s"), bestTimeComment), 0, 4000)
   402                         PlaySound(sndHomerun)
   395                         PlaySound(sndHomerun)
   403                 else    -- best time for the clan
   396                 else    -- best time for the clan
   404                         ShowMission(loc("TechRacer"),
   397                         ShowMission(loc("TechRacer"),
   405                         loc("Track completed!"),
   398                         loc("Track completed!"),
   406                         string.format(loc("New clan record: %.1fs"), (trackTime/1000)) .. "|" ..
   399                         string.format(loc("New clan record: %.1fs"), (trackTime/1000)) .. "|" ..
   447         roundNumber = roundNumber + 1
   440         roundNumber = roundNumber + 1
   448 
   441 
   449         totalComment = ""
   442         totalComment = ""
   450         for i = 0, (TeamsCount-1) do
   443         for i = 0, (TeamsCount-1) do
   451                         if teamNameArr[i] ~= " " then                           -- teamScore[teamClan[i]]
   444                         if teamNameArr[i] ~= " " then                           -- teamScore[teamClan[i]]
   452                                 teamComment[i] = teamNameArr[i] .. ": " .. (teamScore[i]/1000) .. loc("s|")
   445 				if teamScore[i] ~= 1000000 then
       
   446                                 	teamComment[i] = string.format(loc("%s: %.1fs"), teamNameArr[i], (teamScore[i]/1000)) .. "|"
       
   447 				else
       
   448                                 	teamComment[i] = string.format(loc("%s: Did not finish"), teamNameArr[i]) .. "|"
       
   449 				end
   453                                 totalComment = totalComment .. teamComment[i]
   450                                 totalComment = totalComment .. teamComment[i]
   454                         elseif teamNameArr[i] == " " then
   451                         elseif teamNameArr[i] == " " then
   455                                 teamComment[i] = "|"
   452                                 teamComment[i] = "|"
   456                         end
   453                         end
   457         end
   454         end
   469                 -- Sort the scores for the ranking list
   466                 -- Sort the scores for the ranking list
   470                 local unfinishedArray = {}
   467                 local unfinishedArray = {}
   471                 local sortedTeams = {}
   468                 local sortedTeams = {}
   472                 local k = 1
   469                 local k = 1
   473                 for i = 0, TeamsCount-1 do
   470                 for i = 0, TeamsCount-1 do
   474                         if teamScore[i] ~= -1 and teamNameArr[i] ~= " " then
   471                         if teamScore[i] ~= 1000000 and teamNameArr[i] ~= " " then
   475                                sortedTeams[k] = {}
   472                                sortedTeams[k] = {}
   476                                sortedTeams[k].name = teamNameArr[i]
   473                                sortedTeams[k].name = teamNameArr[i]
   477                                sortedTeams[k].score = teamScore[i]
   474                                sortedTeams[k].score = teamScore[i]
   478                                k = k + 1
   475                                k = k + 1
   479                         else
   476                         else