Racer and TechRacer: Move cameera to first waypoint in Ready phase
authorWuzzy <Wuzzy2@mail.ru>
Fri, 16 Feb 2018 23:42:00 +0100
changeset 13029 a568bc16a99a
parent 13028 acba432d34b1
child 13030 261b8fd14235
Racer and TechRacer: Move cameera to first waypoint in Ready phase
ChangeLog.txt
share/hedgewars/Data/Scripts/Multiplayer/Racer.lua
share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua
--- a/ChangeLog.txt	Fri Feb 16 21:00:37 2018 +0100
+++ b/ChangeLog.txt	Fri Feb 16 23:42:00 2018 +0100
@@ -30,7 +30,7 @@
  + Construction Mode: Allow to change "Switch Hedgehog" in weapon scheme
  + Construction Mode: Hide selected sub-modes from crate/object placer from enemies over the net
  + Continental supplies: Custom weapon icons for the special weapons
- + Racer, Tech Racer: First waypoint flashes before the hog starts moving
+ + Racer, Tech Racer: Beforee starting a round, make first waypoint flash and center camera to it
  + Racer: Use dark waypoints in bright themes like Bath
  + Racer, Tech Racer: Various other waypoint appearance improvements
  + Battalion: Minor message and visual improvements
--- a/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Fri Feb 16 21:00:37 2018 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/Racer.lua	Fri Feb 16 23:42:00 2018 +0100
@@ -137,6 +137,7 @@
 --------
 
 local cGear = nil
+local cameraGear = nil -- gear created to center the cameera on
 
 local bestClan = 10
 local bestTime = 1000000
@@ -826,6 +827,15 @@
                         end
                         SetVisualGearValues(wpCirc[i], nil, nil, minO, maxO, nil, flashing, nil, nil, nil, wpCol[i])
                 end
+
+                if cameraGear then
+                        DeleteGear(cameraGear)
+                end
+                -- Move camera to first waypoint
+		-- We use a dummy gear to feed FollowGear. It does not affect the race.
+                cameraGear = AddGear(wpX[0], wpY[0], gtGenericFaller, 0, 0, 0, 5000)
+                SetState(cameraGear, bor(GetState(cameraGear), gstNoGravity+gstInvisible))
+                FollowGear(cameraGear)
         end
 
         if gameOver == true then
@@ -838,7 +848,6 @@
         AddAmmo(CurrentHedgehog, amMineStrike, 0)
         AddAmmo(CurrentHedgehog, amNapalm, 0)
         AddAmmo(CurrentHedgehog, amPiano, 0)
-
 end
 
 function onGameTick20()
@@ -967,6 +976,8 @@
 
         if GetGearType(gear) == gtAirAttack then
                 cGear = nil
+        elseif gear == cameraGear then
+                cameraGear = nil
         end
 
 end
--- a/share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua	Fri Feb 16 21:00:37 2018 +0100
+++ b/share/hedgewars/Data/Scripts/Multiplayer/TechRacer.lua	Fri Feb 16 23:42:00 2018 +0100
@@ -212,6 +212,7 @@
 --------
 
 local cGear = nil
+local cameraGear = nil
 
 local bestClan = 10
 local bestTime = 1000000
@@ -1145,9 +1146,21 @@
         end
 
 
-		if activationStage < 10 then
-				HandleFreshMapCreation()
-		end
+	if activationStage < 10 then
+		HandleFreshMapCreation()
+
+                if not gameOver and gameBegun and not racerActive then
+			if cameraGear then
+				DeleteGear(cameraGear)
+			end
+			-- Move camera to first waypoint.
+			-- We use a dummy gear to feed FollowGear. It does not affect the race.
+			cameraGear = AddGear(wpX[0], wpY[0], gtGenericFaller, 0, 0, 0, 5000)
+			SetState(cameraGear, bor(GetState(cameraGear), gstNoGravity+gstInvisiblee))
+			FollowGear(cameraGear)
+                end
+
+	end
 
 
         -- start the player tumbling with a boom once their turn has actually begun
@@ -1338,12 +1351,14 @@
 function onGearDelete(gear)
 
         if isATrackedGear(gear) then
-			trackDeletion(gear)
-		elseif GetGearType(gear) == gtAirAttack then
+		trackDeletion(gear)
+	elseif GetGearType(gear) == gtAirAttack then
                 cGear = nil
         elseif GetGearType(gear) == gtJetpack then
-			jet = nil
-		end
+		jet = nil
+	elseif gear == cameraGear then
+		cameraGear = nil
+	end
 
 end