Fix air attack placement in HedgeEditor/Construction Mode
authorWuzzy <Wuzzy2@mail.ru>
Tue, 02 Apr 2019 14:51:55 +0200
changeset 14742 2e8213c0951f
parent 14741 37a781d28e43
child 14743 731c8406bff0
Fix air attack placement in HedgeEditor/Construction Mode Caused by the restructuring of how air attack works
hedgewars/uGearsHandlersMess.pas
share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua
share/hedgewars/Data/Scripts/Multiplayer/HedgeEditor.lua
--- a/hedgewars/uGearsHandlersMess.pas	Tue Apr 02 01:34:13 2019 +0200
+++ b/hedgewars/uGearsHandlersMess.pas	Tue Apr 02 14:51:55 2019 +0200
@@ -2999,7 +2999,7 @@
     if (GameTicks and $3F) = 0 then
         AddVisualGear(hwRound(Gear^.X), hwRound(Gear^.Y), vgtSmokeTrace);
 
-    if (hwRound(Gear^.X) > (max(LAND_WIDTH,4096)+2048)) or (hwRound(Gear^.X) < -2048) then
+    if (hwRound(Gear^.X) > (max(LAND_WIDTH,4096)+2048)) or (hwRound(Gear^.X) < -2048) or ((Gear^.Message and gmDestroy) > 0) then
         begin
         // avoid to play forever (is this necessary?)
         StopSoundChan(Gear^.SoundChannel);
--- a/share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua	Tue Apr 02 01:34:13 2019 +0200
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Construction_Mode.lua	Tue Apr 02 14:51:55 2019 +0200
@@ -106,6 +106,7 @@
 local fortMode = false -- is using a fort map?
 local tempID_CheckProximity = nil -- temporary structure variable for CheckProximity
 local cGear = nil -- detects placement of girders and objects (using airattack)
+local cGearPlacementDone = false
 local uniqueStructureID = 0 -- Counter and ID for structures. Is incremented each time a structure spawns
 
 -- Colors
@@ -1385,17 +1386,19 @@
 		local x,y = GetGearTarget(cGear)
 
 		if GetGearType(cGear) == gtAirAttack then
-			DeleteGear(cGear)
-			PlaceObject(x, y)
+			SetGearMessage(cGear, bor(GetGearMessage(cGear), gmDestroy))
+			if not cGearPlacementDone then
+				PlaceObject(x, y)
+				cGearPlacementDone = true
+			end
 		elseif GetGearType(cGear) == gtTeleport then
-
-				CheckTeleport(cGear, x, y)
-				cGear = nil
+			CheckTeleport(cGear, x, y)
+			cGear = nil
+			cGearPlacementDone = true
 		elseif GetGearType(cGear) == gtGirder then
-
 			currentGirderRotation = GetState(cGear)
-
 			PlaceObject(x, y)
+			cGearPlacementDone = true
 		end
 
 	end
@@ -1877,6 +1880,7 @@
 	local gt = GetGearType(gear)
 	if (gt == gtAirAttack) or (gt == gtTeleport) or (gt == gtGirder) then
 		cGear = gear
+		cGearPlacementDone = false
 	end
 
 	if isATrackedGear(gear) then
--- a/share/hedgewars/Data/Scripts/Multiplayer/HedgeEditor.lua	Tue Apr 02 01:34:13 2019 +0200
+++ b/share/hedgewars/Data/Scripts/Multiplayer/HedgeEditor.lua	Tue Apr 02 14:51:55 2019 +0200
@@ -594,6 +594,7 @@
 local waypointPreviewSprite = nil
 
 local cGear = nil -- detects placement of girders and objects (using airattack)
+local cGearPlacementDone = false
 local curWep = amNothing
 local leftHeld = false
 local rightHeld = false
@@ -3092,14 +3093,15 @@
 		x,y = GetGearTarget(cGear)
 
 		if GetGearType(cGear) == gtAirAttack and GetCurAmmoType() == amCMGearPlacementTool then
-			DeleteGear(cGear)
+			SetGearMessage(cGear, bor(GetGearMessage(cGear), gmDestroy))
+			if not cGearPlacementDone then
+				PlaceObject(x, y)
+				cGearPlacementDone = true
+			end
+		elseif GetGearType(cGear) == gtGirder and not cGearPlacementDone then
+			CGR = GetState(cGear)
 			PlaceObject(x, y)
-		elseif GetGearType(cGear) == gtGirder then
-
-			CGR = GetState(cGear)
-
-			-- improve rectangle test based on CGR when you can be bothered
-			PlaceObject(x, y)
+			cGearPlacementDone = true
 		end
 
 	end
@@ -3837,6 +3839,7 @@
 
 	if (GetGearType(gear) == gtAirAttack and GetCurAmmoType() == amCMGearPlacementTool) or (GetGearType(gear) == gtGirder) then
 		cGear = gear
+		cGearPlacementDone = false
 	end
 
 	local tagTint