share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua
changeset 13559 3c562f52609c
parent 13558 af92481415ef
child 13560 dc7b1a4ddded
equal deleted inserted replaced
13558:af92481415ef 13559:3c562f52609c
     1 ------------------------------------------
     1 --------------
     2 -- TECH RACER v0.8
     2 -- TECH RACER
     3 -----------------------------------------
     3 --------------
     4 
     4 
     5 -- DEVELOPER WARNING - FOR OFFICIAL DEVELOPMENT --
     5 -- DEVELOPER WARNING - FOR OFFICIAL DEVELOPMENT --
     6 -- Be careful when editig this script, do not introduce changes lightly!
     6 -- Be careful when editig this script, do not introduce changes lightly!
     7 -- This script is used for time records on the official Hedgewars server.
     7 -- This script is used for time records on the official Hedgewars server.
     8 -- Introducing breaking changes means we have to invalidate past time records!
     8 -- Introducing breaking changes means we have to invalidate past time records!
     9 
     9 
    10 --------------
    10 --------------
    11 -- TO DO
    11 -- TO DO
    12 --------------
    12 --------------
    13 -- allow scrolling of maps (was going to add this in the engine itself, but it can be done now by refreshing preview)
    13 -- allow scrolling of maps (was going to add this in the engine itself, but it can be done now by refreshing preview)
    14 
       
    15 --------------
       
    16 --0.2
       
    17 --------------
       
    18 -- should work better "out the box"
       
    19 -- changed map generation
       
    20 -- put a hog limiter in place
       
    21 -- removed parsecommand
       
    22 -- fix one of the test maps
       
    23 -- hopefully added some support for future official challenges etc
       
    24 -- changed theme
       
    25 -- minor cleanups?
       
    26 
       
    27 --------------
       
    28 --0.3
       
    29 --------------
       
    30 -- ehh, scrap everything? those old maps probably still desync so they can die for now
       
    31 -- hopefully fix map 3
       
    32 -- add two new crappy map to test an idea.
       
    33 
       
    34 --------------
       
    35 --0.4
       
    36 --------------
       
    37 -- updated version text (lol)
       
    38 -- some preliminary support for hand-drawn map loading
       
    39 -- some support for being really lazy
       
    40 -- an extra map or two
       
    41 -- param for infinite UFO fuel
       
    42 -- param for number of rounds
       
    43 
       
    44 --------------
       
    45 --0.5
       
    46 --------------
       
    47 -- migrated maps to an external script
       
    48 
       
    49 --------------
       
    50 --0.6
       
    51 --------------
       
    52 -- move 1 line of code :D (allows loading of HWMAP points to actually work)
       
    53 
       
    54 --------------
       
    55 --0.7
       
    56 --------------
       
    57 -- allow waypoints to be loaded automatically via TechMaps or HWMAP
       
    58 -- (temporarily?) remove ability to place waypoints manually
       
    59 -- break stuff?
       
    60 
       
    61 --------------
       
    62 --0.8
       
    63 --------------
       
    64 -- should (more or less) work "out of the box" now
       
    65 -- generate map previews for level
       
    66 -- randomly assign a map in the case of no map param
       
    67 -- no longer allow custom ammosets (ammo should be specified by map so that records can be valid, though we probably still need to completely limit gameflags)
       
    68 
       
    69 --------------
       
    70 --0.9
       
    71 --------------
       
    72 -- added variable portal limiter (and effects) from Escape script
       
    73 -- allow variable ufoFuel (nil is default, 2000 is infinite)
       
    74 -- disallow specifying fuel in params (do this in TechMaps or HedgeEditor please)
       
    75 
    14 
    76 -----------------------------
    15 -----------------------------
    77 -- SCRIPT BEGINS
    16 -- SCRIPT BEGINS
    78 -----------------------------
    17 -----------------------------
    79 
    18 
   166 				{amSwitch,			"amSwitch",			0}
   105 				{amSwitch,			"amSwitch",			0}
   167 				}
   106 				}
   168 
   107 
   169 local activationStage = 0
   108 local activationStage = 0
   170 local jet = nil
   109 local jet = nil
   171 portalDistance = 5000 -- 15
   110 portalDistance = 5000
   172 ufoFuel = 0
   111 ufoFuel = 0
   173 local fMod = 1000000 -- 1
   112 local fMod = 1000000
   174 local roundLimit = 3
   113 local roundLimit = 3
   175 local roundNumber = 0
   114 local roundNumber = 0
   176 local firstClan = 10
   115 local firstClan = 10
   177 
   116 
   178 local fastX = {}
   117 local fastX = {}
   239 local RoundHasChanged
   178 local RoundHasChanged
   240 
   179 
   241 -------------------
   180 -------------------
   242 -- general methods
   181 -- general methods
   243 -------------------
   182 -------------------
   244 
       
   245 --function onPrecise()
       
   246 --end
       
   247 
   183 
   248 function RebuildTeamInfo()
   184 function RebuildTeamInfo()
   249 
   185 
   250 
   186 
   251         -- make a list of individual team names
   187         -- make a list of individual team names
   334 
   270 
   335                 g1X = g1X - g2X
   271                 g1X = g1X - g2X
   336                 g1Y = g1Y - g2Y
   272                 g1Y = g1Y - g2Y
   337                 dist = (g1X*g1X) + (g1Y*g1Y)
   273                 dist = (g1X*g1X) + (g1Y*g1Y)
   338 
   274 
   339                 --if i == 0 then
       
   340                 --      AddCaption(dist .. "/" .. (wpRad*wpRad) )
       
   341                 --end
       
   342 
       
   343                 NR = (48/100*wpRad)/2
   275                 NR = (48/100*wpRad)/2
   344 
   276 
   345                 if dist < (NR*NR) and not gameOver then
   277                 if dist < (NR*NR) and not gameOver then
   346                 --if dist < (wpRad*wpRad) then
   278                         wpCol[i] = GetClanColor(GetHogClan(CurrentHedgehog))
   347                         --AddCaption("howdy")
       
   348                         wpCol[i] = GetClanColor(GetHogClan(CurrentHedgehog)) -- new                             --GetClanColor(1)
       
   349                         SetVisualGearValues(wpCirc[i], wpX[i], wpY[i], 64, 64, 1, 10, 0, wpRad, 5, wpCol[i])
   279                         SetVisualGearValues(wpCirc[i], wpX[i], wpY[i], 64, 64, 1, 10, 0, wpRad, 5, wpCol[i])
   350 
   280 
   351                         wpRem = 0
   281                         wpRem = 0
   352                         for k = 0, (wpCount-1) do
   282                         for k = 0, (wpCount-1) do
   353                                 if wpActive[k] == false then
   283                                 if wpActive[k] == false then
   434                 if teamNameArr[i] ~= " " and teamScore[i] ~= 1000000 then
   364                 if teamNameArr[i] ~= " " and teamScore[i] ~= 1000000 then
   435                         SetTeamLabel(teamNameArr[i], string.format(loc("%.1fs"), teamScore[i]/1000))
   365                         SetTeamLabel(teamNameArr[i], string.format(loc("%.1fs"), teamScore[i]/1000))
   436                 end
   366                 end
   437         end
   367         end
   438 
   368 
   439         --------
       
   440         --new
       
   441         --------
       
   442 
       
   443         if bestTime == trackTime then
   369         if bestTime == trackTime then
   444                 --AddCaption("wooooooooooooooooooooooooooooo")
       
   445 
       
   446                 fastColour = GetClanColor(GetHogClan(CurrentHedgehog))
   370                 fastColour = GetClanColor(GetHogClan(CurrentHedgehog))
   447 
   371 
   448                 for i = 0, (currCount-1) do
   372                 for i = 0, (currCount-1) do
   449                         fastX[i] = currX[i]
   373                         fastX[i] = currX[i]
   450                         fastY[i] = currY[i]
   374                         fastY[i] = currY[i]
   451                 end
   375                 end
   452 
   376 
   453                 fastCount = currCount
   377                 fastCount = currCount
   454                 fastIndex = 0
   378                 fastIndex = 0
   455 
   379 
   456                 --currCount = 0 -- is this needed?
       
   457 
       
   458         else
   380         else
   459                 currCount = 0
   381                 currCount = 0
   460                 fastIndex = 0
   382                 fastIndex = 0
   461         end
   383         end
   462 
   384 
   467 
   389 
   468         roundNumber = roundNumber + 1
   390         roundNumber = roundNumber + 1
   469 
   391 
   470         totalComment = ""
   392         totalComment = ""
   471         for i = 0, (TeamsCount-1) do
   393         for i = 0, (TeamsCount-1) do
   472                         if teamNameArr[i] ~= " " then                           -- teamScore[teamClan[i]]
   394                         if teamNameArr[i] ~= " " then
   473 				if teamScore[i] ~= 1000000 then
   395 				if teamScore[i] ~= 1000000 then
   474                                 	teamComment[i] = string.format(loc("%s: %.1fs"), teamNameArr[i], (teamScore[i]/1000)) .. "|"
   396                                 	teamComment[i] = string.format(loc("%s: %.1fs"), teamNameArr[i], (teamScore[i]/1000)) .. "|"
   475 				else
   397 				else
   476                                 	teamComment[i] = string.format(loc("%s: Did not finish"), teamNameArr[i]) .. "|"
   398                                 	teamComment[i] = string.format(loc("%s: Did not finish"), teamNameArr[i]) .. "|"
   477 				end
   399 				end
   541 
   463 
   542 end
   464 end
   543 
   465 
   544 function CheckForNewRound()
   466 function CheckForNewRound()
   545 
   467 
   546         -------------
       
   547         ------ new
       
   548         -------------
       
   549 
       
   550         --[[turnN = turnN + 1
       
   551         if gameBegun == false then
       
   552                 if turnN == 2 then
       
   553                         for i = 0, (numhhs-1) do
       
   554                                 if hhs[i] ~= nil then
       
   555                                         SetEffect(hhs[i], heResurrectable, 0)
       
   556                                         SetHealth(hhs[i],0)
       
   557                                 end
       
   558                         end
       
   559                         gameOver = true
       
   560                         TurnTimeLeft = 1
       
   561                 end
       
   562         else
       
   563 
       
   564 
       
   565         end]]
       
   566 
       
   567         --[[if roundBegun == true then
       
   568 
       
   569                 if RoundHasChanged == true then
       
   570                         roundN = roundN + 1
       
   571                         RoundHasChanged = false
       
   572                         onNewRound()
       
   573                 end
       
   574 
       
   575                 if lastRound ~= TotalRounds then -- new round, but not really
       
   576 
       
   577                         if RoundHasChanged == false then
       
   578                                 RoundHasChanged = true
       
   579                         end
       
   580 
       
   581                 end
       
   582 
       
   583                 AddCaption("RoundN:" .. roundN .. "; " .. "TR: " .. TotalRounds)
       
   584 
       
   585                 lastRound = TotalRounds
       
   586 
       
   587         end]]
       
   588 
       
   589         ------------
       
   590         ----- old
       
   591         ------------
       
   592 
       
   593         if GetHogClan(CurrentHedgehog) == firstClan then
   468         if GetHogClan(CurrentHedgehog) == firstClan then
   594                 onNewRound()
   469                 onNewRound()
   595         end
   470         end
   596 
   471 
   597 end
   472 end
   630                 fastIndex = fastIndex + 1
   505                 fastIndex = fastIndex + 1
   631 
   506 
   632                 tempE = AddVisualGear(fastX[fastIndex], fastY[fastIndex], vgtSmoke, 0, false)
   507                 tempE = AddVisualGear(fastX[fastIndex], fastY[fastIndex], vgtSmoke, 0, false)
   633                 g1, g2, g3, g4, g5, g6, g7, g8, g9, g10 = GetVisualGearValues(tempE)
   508                 g1, g2, g3, g4, g5, g6, g7, g8, g9, g10 = GetVisualGearValues(tempE)
   634                 SetVisualGearValues(tempE, g1, g2, g3, g4, g5, g6, g7, g8, g9, fastColour )
   509                 SetVisualGearValues(tempE, g1, g2, g3, g4, g5, g6, g7, g8, g9, fastColour )
   635 
       
   636                 --AddCaption("fC: " .. fastIndex .. " / " .. fastCount)
       
   637 
       
   638         else
       
   639 
       
   640                 --AddCaption("excep fC: " .. fastIndex .. " / " .. fastCount)
       
   641 
   510 
   642         end
   511         end
   643 
   512 
   644 end
   513 end
   645 
   514 
   698             local minO, maxO, flashing = FlashingHelper(wpCount)
   567             local minO, maxO, flashing = FlashingHelper(wpCount)
   699             -- Make first waypoint flash very noticably before the hog starts racing
   568             -- Make first waypoint flash very noticably before the hog starts racing
   700             SetVisualGearValues(wpCirc[wpCount], wpX[wpCount], wpY[wpCount], minO, maxO, 1, flashing, 0, wpRad, 5, wpCol[wpCount])
   569             SetVisualGearValues(wpCirc[wpCount], wpX[wpCount], wpY[wpCount], minO, maxO, 1, flashing, 0, wpRad, 5, wpCol[wpCount])
   701 
   570 
   702             wpCount = wpCount + 1
   571             wpCount = wpCount + 1
   703 
       
   704             --AddCaption(loc("Waypoint placed.") .. " " .. loc("Available points remaining: ") .. (wpLimit-wpCount))
       
   705         end
   572         end
   706     end
   573     end
   707 end
   574 end
   708 
   575 
   709 
   576 
   774 function onParameters()
   641 function onParameters()
   775 
   642 
   776 	parseParams()
   643 	parseParams()
   777 	mapID = tonumber(params["m"])
   644 	mapID = tonumber(params["m"])
   778 
   645 
   779 	--ufoFuel = tonumber(params["ufoFuel"])
       
   780 	roundLimit = tonumber(params["rounds"])
   646 	roundLimit = tonumber(params["rounds"])
   781 
   647 
   782 	if (roundLimit == 0) or (roundLimit == nil) then
   648 	if (roundLimit == 0) or (roundLimit == nil) then
   783 		roundLimit = 3
   649 		roundLimit = 3
   784 	end
   650 	end
   920 
   786 
   921 		--79-82 (reserved for future wep crates)
   787 		--79-82 (reserved for future wep crates)
   922 		--89,88,87,86 and 85,84,83,82 (reserved for the 2 custom sprites and their landflags)
   788 		--89,88,87,86 and 85,84,83,82 (reserved for the 2 custom sprites and their landflags)
   923 
   789 
   924 		--90-99 reserved for scripted structures
   790 		--90-99 reserved for scripted structures
   925 		--[[elseif specialPointsFlag[i] == 90 then
       
   926 			--PlaceStruc("generator")
       
   927 		elseif specialPointsFlag[i] == 91 then
       
   928 			--PlaceStruc("healingstation")
       
   929 		elseif specialPointsFlag[i] == 92 then
       
   930 			--PlaceStruc("respawner")
       
   931 		elseif specialPointsFlag[i] == 93 then
       
   932 			--PlaceStruc("teleportationnode")
       
   933 		elseif specialPointsFlag[i] == 94 then
       
   934 			--PlaceStruc("biofilter")
       
   935 		elseif specialPointsFlag[i] == 95 then
       
   936 			--PlaceStruc("supportstation")
       
   937 		elseif specialPointsFlag[i] == 96 then
       
   938 			--PlaceStruc("constructionstation")
       
   939 		elseif specialPointsFlag[i] == 97 then
       
   940 			--PlaceStruc("reflectorshield")
       
   941 		elseif specialPointsFlag[i] == 98 then
       
   942 			--PlaceStruc("weaponfilter")]]
       
   943 
   791 
   944 		elseif specialPointsFlag[i] == 98 then
   792 		elseif specialPointsFlag[i] == 98 then
   945 			portalDistance = specialPointsX[i]
   793 			portalDistance = specialPointsX[i]
   946 			ufoFuel = specialPointsY[i]
   794 			ufoFuel = specialPointsY[i]
   947 
   795 
  1026 
   874 
  1027 		trackTeams()
   875 		trackTeams()
  1028 
   876 
  1029 		roundN = 0
   877 		roundN = 0
  1030         lastRound = TotalRounds
   878         lastRound = TotalRounds
  1031         RoundHasChanged = false -- true
   879         RoundHasChanged = false
  1032 
   880 
  1033 	    RebuildTeamInfo()
   881 	    RebuildTeamInfo()
  1034 
   882 
  1035 		for i=0 , TeamsCount - 1 do
   883 		for i=0 , TeamsCount - 1 do
  1036 			cnthhs = 0
   884 			cnthhs = 0
  1064 
   912 
  1065         racerActive = false
   913         racerActive = false
  1066 
   914 
  1067 		activationStage = 1
   915 		activationStage = 1
  1068 
   916 
  1069 		--AddAmmo(CurrentHedgehog, amBazooka, 100)
       
  1070 		--AddAmmo(CurrentHedgehog, amJetpack, 100)
       
  1071 
       
  1072 		--ClearMap()
       
  1073 
       
  1074 
       
  1075         trackTime = 0
   917         trackTime = 0
  1076 
   918 
  1077         currCount = 0 -- hopefully this solves problem
   919         currCount = 0 -- hopefully this solves problem
  1078     --    AddAmmo(CurrentHedgehog, amAirAttack, 0)
       
  1079         gTimer = 0
   920         gTimer = 0
  1080 
   921 
  1081         -- Set the waypoints to unactive on new round
   922         -- Set the waypoints to unactive on new round
  1082         if not gameOver then
   923         if not gameOver then
  1083                 for i = 0,(wpCount-1) do
   924                 for i = 0,(wpCount-1) do
  1088                 end
   929                 end
  1089         end
   930         end
  1090 
   931 
  1091         -- Handle Starting Stage of Game
   932         -- Handle Starting Stage of Game
  1092         if (gameOver == false) and (gameBegun == false) then
   933         if (gameOver == false) and (gameBegun == false) then
  1093                -- if wpCount >= 3 then
       
  1094                         gameBegun = true
   934                         gameBegun = true
  1095 						--  --[[activationStage = 200]]
       
  1096                         roundNumber = 0
   935                         roundNumber = 0
  1097                         firstClan = GetHogClan(CurrentHedgehog)
   936                         firstClan = GetHogClan(CurrentHedgehog)
  1098                 --else
       
  1099                 --        ShowMission(loc("RACER"),
       
  1100                 --        loc("NOT ENOUGH WAYPOINTS"),
       
  1101                 --        loc("Place more waypoints using the 'Air Attack' weapon."), 2, 4000)
       
  1102                 --        AddAmmo(CurrentHedgehog, amAirAttack, 4000)
       
  1103 				--		SetWeapon(amAirAttack)
       
  1104                -- end
       
  1105         end
   937         end
  1106 
   938 
  1107         if gameOver == true then
   939         if gameOver == true then
  1108                 gameBegun = false
   940                 gameBegun = false
  1109                 racerActive = false -- newadd
   941                 racerActive = false
  1110         end
   942         end
  1111 
   943 
  1112         AddAmmo(CurrentHedgehog, amTardis, 0)
   944         AddAmmo(CurrentHedgehog, amTardis, 0)
  1113         AddAmmo(CurrentHedgehog, amDrillStrike, 0)
   945         AddAmmo(CurrentHedgehog, amDrillStrike, 0)
  1114         AddAmmo(CurrentHedgehog, amMineStrike, 0)
   946         AddAmmo(CurrentHedgehog, amMineStrike, 0)
  1175         if racerActive == false then
  1007         if racerActive == false then
  1176 
  1008 
  1177                 if (TurnTimeLeft > 0) and (TurnTimeLeft ~= TurnTime) then
  1009                 if (TurnTimeLeft > 0) and (TurnTimeLeft ~= TurnTime) then
  1178 
  1010 
  1179                         -- if the gamehas started put the player in the middle of the first
  1011                         -- if the gamehas started put the player in the middle of the first
  1180                         --waypoint that was placed
  1012                         -- waypoint that was placed
  1181                         if gameBegun == true then
  1013                         if gameBegun == true then
  1182                                 AddCaption(loc("Good to go!"))
  1014                                 AddCaption(loc("Good to go!"))
  1183                                 racerActive = true
  1015                                 racerActive = true
  1184                                 trackTime = 0
  1016                                 trackTime = 0
  1185 
  1017 
  1186 
  1018 
  1187 								SetGearPosition(CurrentHedgehog, wpX[0], wpY[0])
  1019                                 SetGearPosition(CurrentHedgehog, wpX[0], wpY[0])
  1188                                 --AddGear(GetX(CurrentHedgehog), GetY(CurrentHedgehog), gtGrenade, 0, 0, 0, 1)
  1020                                 SetGearMessage(CurrentHedgehog,gmLeft)
  1189                                 --SetGearVelocity(CurrentHedgehog,1000000,1000000)
  1021 
  1190 								SetGearMessage(CurrentHedgehog,gmLeft)
  1022                                 FollowGear(CurrentHedgehog)
  1191 
       
  1192 
       
  1193 								FollowGear(CurrentHedgehog)
       
  1194 
  1023 
  1195                                 HideMission()
  1024                                 HideMission()
  1196 								activationStage = 201
  1025                                 activationStage = 201
  1197 
       
  1198 						else
       
  1199                                 -- still in placement mode
       
  1200                         end
  1026                         end
  1201 
  1027 
  1202                 end
  1028                 end
  1203 
  1029 
  1204         elseif (activationStage == 201) and (TurnTimeLeft > 0) and (TurnTimeLeft ~= TurnTime) then
  1030         elseif (activationStage == 201) and (TurnTimeLeft > 0) and (TurnTimeLeft ~= TurnTime) then
  1205 			SetGearMessage(CurrentHedgehog,0)
  1031                 SetGearMessage(CurrentHedgehog,0)
  1206 			activationStage = 202
  1032                 activationStage = 202
  1207 		end
  1033 	end
  1208 
       
  1209 
       
  1210 
  1034 
  1211         -- has the player started his tumbling spree?
  1035         -- has the player started his tumbling spree?
  1212         if (CurrentHedgehog ~= nil) then
  1036         if (CurrentHedgehog ~= nil) then
  1213 
       
  1214                 --airstrike conversion used to be here
       
  1215 
  1037 
  1216                 -- if the RACE has started, show tracktimes and keep tabs on waypoints
  1038                 -- if the RACE has started, show tracktimes and keep tabs on waypoints
  1217                 if (racerActive == true) and (activationStage == 202) then
  1039                 if (racerActive == true) and (activationStage == 202) then
  1218 
  1040 
  1219                         --ghost
  1041                         --ghost