Racer: Reposition and resize predefined waypoints in scaled drawn maps
authorWuzzy <Wuzzy2@mail.ru>
Sat, 26 Oct 2019 21:59:42 +0200
changeset 15483 70aba717485a
parent 15482 4cc9ec732392
child 15484 d0ef2d8da64a
Racer: Reposition and resize predefined waypoints in scaled drawn maps Previously, predefined waypoints broke when using any but the default drawn map size.
share/hedgewars/Data/Scripts/Multiplayer/Racer.lua
--- a/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Sat Oct 26 02:36:08 2019 +0300
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Sat Oct 26 21:59:42 2019 +0200
@@ -101,6 +101,7 @@
 local wpCol = {}
 local wpActive = {}
 local wpRad = 450
+local WAYPOINT_RADIUS_MIN = 40
 local wpCount = 0
 local wpLimit = 8
 
@@ -193,7 +194,7 @@
         end
     end
     if params["waypointradius"] ~= nil then
-        wpRad = math.max(40, math.floor(tonumber(params["waypointradius"])))
+        wpRad = math.max(WAYPOINT_RADIUS_MIN, math.floor(tonumber(params["waypointradius"])))
         if type(wpRad) ~= "number" then
              wpRad = 450
         end
@@ -635,6 +636,20 @@
 end
 
 function onGameStart()
+
+	-- Adjust pre-defined waypoints in scaled drawn maps
+	if MapGen == mgDrawn and MapFeatureSize ~= 12 and specialPointsCount > 0 then
+		local landW = RightX - LeftX + 1
+		local landH = LAND_HEIGHT - TopY
+		-- Reposition pre-defined waypoints
+        	for i = 0, (specialPointsCount-1) do
+        		specialPointsX[i] = LeftX + div(specialPointsX[i] * landW, 4096)
+        		specialPointsY[i] = TopY + div(specialPointsY[i] * landH, 2048)
+		end
+		-- Scale waypoint size
+		wpRad = math.max(WAYPOINT_RADIUS_MIN, div(wpRad * landW, 4096))
+	end
+
 	if ClansCount >= 2 then
 		SendGameResultOff()
 		SendRankingStatsOff()