share/hedgewars/Data/Scripts/Multiplayer/Racer.lua
changeset 12967 e32fff07b8d7
parent 12965 21eda4fe383c
child 13024 a568bc16a99a
equal deleted inserted replaced
12966:b543d767fed3 12967:e32fff07b8d7
   164 
   164 
   165 local boostX = 0
   165 local boostX = 0
   166 local boostY = 0
   166 local boostY = 0
   167 local boostValue = 1
   167 local boostValue = 1
   168 
   168 
       
   169 -- themes with bright background
       
   170 local brightThemes = {
       
   171 	Bath = true,
       
   172 	Bamboo = true,
       
   173 	Beach = true,
       
   174 	Blox = true,
       
   175 	Compost = true,
       
   176 	Desert = true,
       
   177 	Fruit = true,
       
   178 	Golf = true,
       
   179 	Hoggywood = true,
       
   180 	Jungle = true,
       
   181 	Olympics = true,
       
   182 	Sheep = true,
       
   183 }
       
   184 -- themes with medium or heavily mixed brightness.
       
   185 -- only add themes here if both bright and dark waypoint
       
   186 -- colors fail otherwise.
       
   187 local mediumThemes = {
       
   188 	Halloween = true,
       
   189 }
       
   190 -- All themes not explicitly listed above are assumed to
       
   191 -- be "dark" and work with the default bright waypoints.
       
   192 
       
   193 -- Waypoint colors in 3 color themes!
       
   194 -- We do this so the waypoints are easy on the eyes,
       
   195 -- at least in each of the default themes.
       
   196 
       
   197 -- Bright waypoints (default)
       
   198 local waypointColourBright = 0xFFFFFFFF -- Primary colour of inactive waypoints
       
   199 local waypointColourBrightAtPlacement = 0xAAAAAAFF -- Colour of non-highlighted waypoints while placing
       
   200 -- Medium bright waypoints
       
   201 local waypointColourMedium = 0x606060FF
       
   202 local waypointColourMediumAtPlacement = 0x404040FF
       
   203 -- Dark waypoints
       
   204 local waypointColourDark = 0x000000FF
       
   205 local waypointColourDarkAtPlacement = 0x303030FF
       
   206 
       
   207 -- Waypoints touched by the players assume the clan color, which is unchanged.
       
   208 -- Touched waypoints are not important to be visible.
       
   209 
       
   210 -- Default waypoint colors (only use these color variables in the code below)
       
   211 local waypointColour = waypointColourBright
       
   212 local waypointColourAtPlacement = waypointColourBrightAtPlacement
       
   213 
   169 -------------------
   214 -------------------
   170 -- general methods
   215 -- general methods
   171 -------------------
   216 -------------------
       
   217 
       
   218 -- Returns brightness level of background from 1-3.
       
   219 -- 1 = brightest
       
   220 function GetBackgroundBrightness()
       
   221 	-- This just looks at the theme names above.
       
   222 	-- This code will fail for bright unofficial themes.
       
   223 	-- TODO: Change how this thing works.
       
   224 	-- Consider adding a function into the Lua API which looks
       
   225 	-- up the theme's sky color, so we could use thit instead.
       
   226 	if brightThemes[Theme] then
       
   227 		return 1
       
   228 	elseif mediumThemes[Theme] then
       
   229 		return 2
       
   230 	else
       
   231 		return 3
       
   232 	end
       
   233 end
   172 
   234 
   173 --[[
   235 --[[
   174 Parameters syntax:
   236 Parameters syntax:
   175 
   237 
   176 teamrope=true
   238 teamrope=true
   600 
   662 
   601         roundN = 0
   663         roundN = 0
   602         lastRound = TotalRounds
   664         lastRound = TotalRounds
   603         RoundHasChanged = false
   665         RoundHasChanged = false
   604 
   666 
       
   667 	if GetBackgroundBrightness() == 1 then
       
   668 		-- Dark waypoint colour theme
       
   669 		waypointColour = waypointColourDark
       
   670 		waypointColourAtPlacement = waypointColourDarkAtPlacement
       
   671 	elseif GetBackgroundBrightness() == 2 then
       
   672 		-- Medium waypoint colour theme
       
   673 		waypointColour = waypointColourMedium
       
   674 		waypointColourAtPlacement = waypointColourMediumAtPlacement
       
   675 	end
       
   676 
   605         for i = 0, (specialPointsCount-1) do
   677         for i = 0, (specialPointsCount-1) do
   606                 PlaceWayPoint(specialPointsX[i], specialPointsY[i], false)
   678                 PlaceWayPoint(specialPointsX[i], specialPointsY[i], false)
   607         end
   679         end
   608 
   680 
   609         RebuildTeamInfo()
   681         RebuildTeamInfo()
   633     if not racerActive then
   705     if not racerActive then
   634         if wpCount == 0 or wpX[wpCount - 1] ~= x or wpY[wpCount - 1] ~= y then
   706         if wpCount == 0 or wpX[wpCount - 1] ~= x or wpY[wpCount - 1] ~= y then
   635 
   707 
   636             wpX[wpCount] = x
   708             wpX[wpCount] = x
   637             wpY[wpCount] = y
   709             wpY[wpCount] = y
   638             wpCol[wpCount] = 0xffffffff
   710             wpCol[wpCount] = waypointColour
   639             wpCirc[wpCount] = AddVisualGear(wpX[wpCount],wpY[wpCount],vgtCircle,0,true)
   711             wpCirc[wpCount] = AddVisualGear(wpX[wpCount],wpY[wpCount],vgtCircle,0,true)
   640 
   712 
   641             local flashing, minO, maxO
   713             local flashing, minO, maxO
   642             if wpCount == 0 then
   714             if wpCount == 0 then
   643                 -- First waypoint flashes. Useful to know since this is the spawn position.
   715                 -- First waypoint flashes. Useful to know since this is the spawn position.
   648                 minO, maxO = 255, 255
   720                 minO, maxO = 255, 255
   649                 flashing = 0
   721                 flashing = 0
   650             end
   722             end
   651             SetVisualGearValues(wpCirc[wpCount], wpX[wpCount], wpY[wpCount], minO, maxO, 1, flashing, 0, wpRad, 5, wpCol[wpCount])
   723             SetVisualGearValues(wpCirc[wpCount], wpX[wpCount], wpY[wpCount], minO, maxO, 1, flashing, 0, wpRad, 5, wpCol[wpCount])
   652 
   724 
   653             -- Make last waypoint white while making all previous ones light gray.
   725             -- Use alternate waypoint color for all waypoints but the last one. This gives a subtle “highlighting” effect.
   654             -- Note the last waypoint can be deleted with Precise.
   726             SetVisualGearValues(wpCirc[wpCount-1], nil, nil, nil, nil, nil, nil, nil, nil, nil, waypointColourAtPlacement)
   655             SetVisualGearValues(wpCirc[wpCount-1], nil, nil, nil, nil, nil, nil, nil, nil, nil, 0xaaaaaaff)
       
   656 
   727 
   657             wpCount = wpCount + 1
   728             wpCount = wpCount + 1
   658 
   729 
   659             if placedByUser then
   730             if placedByUser then
   660                 AddCaption(string.format(loc("Waypoint placed. Available points remaining: %d"), wpLimit-wpCount))
   731                 AddCaption(string.format(loc("Waypoint placed. Available points remaining: %d"), wpLimit-wpCount))
   675         wpX[wpCount] = nil
   746         wpX[wpCount] = nil
   676         wpY[wpCount] = nil
   747         wpY[wpCount] = nil
   677         wpCol[wpCount] = nil
   748         wpCol[wpCount] = nil
   678         DeleteVisualGear(wpCirc[wpCount])
   749         DeleteVisualGear(wpCirc[wpCount])
   679         wpCirc[wpCount] = nil
   750         wpCirc[wpCount] = nil
   680         SetVisualGearValues(wpCirc[wpCount-1], nil, nil, nil, nil, nil, nil, nil, nil, nil, 0xffffffff)
   751         SetVisualGearValues(wpCirc[wpCount-1], nil, nil, nil, nil, nil, nil, nil, nil, nil, waypointColour)
   681         AddCaption(string.format(loc("Waypoint removed. Available points: %d"), wpLimit-wpCount))
   752         AddCaption(string.format(loc("Waypoint removed. Available points: %d"), wpLimit-wpCount))
   682     else
   753     else
   683         PlaySound(sndDenied)
   754         PlaySound(sndDenied)
   684         AddCaption(loc("No waypoint to be removed!"))
   755         AddCaption(loc("No waypoint to be removed!"))
   685     end
   756     end
   741 
   812 
   742         -- Set the waypoints to unactive on new round
   813         -- Set the waypoints to unactive on new round
   743         if gameBegun and not gameOver then
   814         if gameBegun and not gameOver then
   744                 for i = 0,(wpCount-1) do
   815                 for i = 0,(wpCount-1) do
   745                         wpActive[i] = false
   816                         wpActive[i] = false
   746                         wpCol[i] = 0xffffffff
   817                         wpCol[i] = waypointColour
   747                         local flashing, minO, maxO
   818                         local flashing, minO, maxO
   748                         if i == 0 then
   819                         if i == 0 then
   749                             -- Make first waypoint flash very noticably
   820                             -- Make first waypoint flash very noticably
   750                             minO, maxO = 92, 255
   821                             minO, maxO = 92, 255
   751                             flashing = 2
   822                             flashing = 2