Clear drawn maps in TechRacer
authorWuzzy <Wuzzy2@mail.ru>
Thu, 15 Mar 2018 03:29:31 +0100
changeset 13220 bc95df84395f
parent 13219 9c81e34f1933
child 13221 95311e220eb6
Clear drawn maps in TechRacer
share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua
share/hedgewars/Data/Scripts/Multiplayer/Tunnels.lua
share/hedgewars/Data/Scripts/TechMaps.lua
share/hedgewars/Data/Scripts/Utils.lua
--- a/share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua	Thu Mar 15 02:59:37 2018 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua	Thu Mar 15 03:29:31 2018 +0100
@@ -81,6 +81,7 @@
 HedgewarsScriptLoad("/Scripts/OfficialChallenges.lua")
 HedgewarsScriptLoad("/Scripts/Tracker.lua")
 HedgewarsScriptLoad("/Scripts/Params.lua")
+HedgewarsScriptLoad("/Scripts/Utils.lua")
 HedgewarsScriptLoad("/Scripts/TechMaps.lua")
 
 ------------------
@@ -793,30 +794,36 @@
 end
 
 function onGameInit()
+
+    TemplateFilter = 0
+
+    if MapGen == mgDrawn then
+        eraseMap(false)
+    else
+        MapGen = mgDrawn
+    end
+
     if mapID == nil then
         mapID = 2 + GetRandom(7)
     end
 
     addHashData(mapID)
 
-		Theme = "Cave"
-		Map = ""
-
-		MapGen = mgDrawn
-		TemplateFilter = 0
+    Theme = "Cave"
+    Map = ""
 
-		EnableGameFlags(gfInfAttack, gfDisableWind, gfBorder)
-		DisableGameFlags(gfSolidLand)
-		CaseFreq = 0
-        TurnTime = 90000
-        WaterRise = 0
-        HealthDecrease = 0
+    EnableGameFlags(gfInfAttack, gfDisableWind, gfBorder)
+    DisableGameFlags(gfSolidLand)
+    CaseFreq = 0
+    TurnTime = 90000
+    WaterRise = 0
+    HealthDecrease = 0
 
-		for x = 1, 16 do
-			AddPoint(x*100,100,5)
-		end
+    for x = 1, 16 do
+        AddPoint(x*100,100,5)
+    end
 
-		FlushPoints()
+    FlushPoints()
 
 end
 
--- a/share/hedgewars/Data/Scripts/Multiplayer/Tunnels.lua	Thu Mar 15 02:59:37 2018 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Tunnels.lua	Thu Mar 15 03:29:31 2018 +0100
@@ -1,16 +1,13 @@
+HedgewarsScriptLoad("/Scripts/Utils.lua")
 
 function onPreviewInit()
-onGameInit()
+    onGameInit()
 end
 
 function onGameInit()
     MapGen = mgDrawn
     TemplateFilter = 0
-    for i = 200,2000,600 do
-        AddPoint(1,i,63)
-        AddPoint(4000,i)
-    end
-
+    fillMap(false)
     side = 0
     for i = 0,1+MapFeatureSize*2 do
         if side > 3 then 
--- a/share/hedgewars/Data/Scripts/TechMaps.lua	Thu Mar 15 02:59:37 2018 +0100
+++ b/share/hedgewars/Data/Scripts/TechMaps.lua	Thu Mar 15 03:29:31 2018 +0100
@@ -12,6 +12,7 @@
 
 
 HedgewarsScriptLoad("/Scripts/Tracker.lua")
+HedgewarsScriptLoad("/Scripts/Utils.lua")
 
 techX = {}
 techY = {}
@@ -92,11 +93,16 @@
 		return
 	end
 
+        if MapGen == mgDrawn then
+	    eraseMap(false)
+        else
+	    MapGen = mgDrawn
+        end
+
 	if mapID == nil then
 		mapID = 2 + GetRandom(7)
 	end
 
-	MapGen = mgDrawn
     TemplateFilter = 0
 
     for x = 1, 16 do
--- a/share/hedgewars/Data/Scripts/Utils.lua	Thu Mar 15 02:59:37 2018 +0100
+++ b/share/hedgewars/Data/Scripts/Utils.lua	Thu Mar 15 03:29:31 2018 +0100
@@ -20,3 +20,27 @@
     end
     return false
 end
+
+local function drawFullMap(erase, flush)
+	for x = 200,4000,600 do
+		for y = 100,2000,150 do
+			AddPoint(x, y, 63, erase)
+		end
+	end
+	if flush ~= false then
+		FlushPoints()
+	end
+end
+
+-- Completely fill the map with land. Requires MapGen=mgDrawn.
+-- If flush is false, FlushPoints() is not called.
+function fillMap(flush)
+	drawFullMap(false, flush)
+end
+
+-- Completely erase all land from drawn maps. Requires MapGen=mgDrawn.
+-- If flush is false, FlushPoints() is not called.
+function eraseMap(flush)
+	drawFullMap(true, flush)
+end
+