ASA fruit02: Change Captain Lime clan color when he turns evil
authorWuzzy <Wuzzy2@mail.ru>
Mon, 21 Jan 2019 06:16:01 +0100
changeset 14648 30d3e1d6aedf
parent 14647 bc4296649bbf
child 14649 5fc5e4b79a5a
ASA fruit02: Change Captain Lime clan color when he turns evil
ChangeLog.txt
share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit02.lua
--- a/ChangeLog.txt	Mon Jan 21 05:57:01 2019 +0100
+++ b/ChangeLog.txt	Mon Jan 21 06:16:01 2019 +0100
@@ -39,6 +39,7 @@
  * Searching in the dust: Fix a lot of broken/stupid smuggler behaviours
  * Chasing the blue hog: Fix player not losing the race when timing out while still having the rope
  * Chasing the blue hog: Fix player winning if Crazy Runner died
+ * Getting to the device: Fix clan colors
  * Various minor tweaks and bugfixes
 
 Controls:
--- a/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit02.lua	Mon Jan 21 05:57:01 2019 +0100
+++ b/share/hedgewars/Data/Missions/Campaign/A_Space_Adventure/fruit02.lua	Mon Jan 21 06:16:01 2019 +0100
@@ -67,13 +67,12 @@
 -- Hog Solo and Green Bananas
 teamA.name = loc("Hog Solo and GB")
 teamA.color = -6
--- Captain Lime will use a color which is almost the same as the color of teamA.
--- It works, but it's a hack.
--- Technically, this makes Captain Lime an enemy team in the mission but for the player
--- it looks like an ally. This is because Camptain Lime starts friendly (story-wise),
--- but might become your enemy during the course of this mission.
--- TODO: For teamB, use same color of teamA when friendly, change color when evil
+-- Captain Lime can use one of 2 clan colors:
+-- One when being friendly (same as hero), and a different one when he turns evil.
+-- Captain Lime be in his own clan.
 teamB.name = loc("Captain Lime")
+teamB.colorNice = teamA.color
+teamB.colorEvil = -5
 teamC.name = loc("Fruit Assassins")
 teamC.color = -1
 
@@ -132,28 +131,12 @@
 	HogTurnLeft(green3.gear, true)
 
 	-- Captain Lime
-	-- Returns a color that is as close as possible to the color argument
-	-- but does not equal color and otherCollision.
-	local getSimilarColor = function(color, otherCollision)
-		local goingUp = false
-		local collision1 = color
-		while(color == collision1 or color == otherCollision) do
-			-- Try out colors by varying the blue color component until
-			-- we don't collide with any of the 2 colors.
-			if ((color % 0x100) > 0) and (not goingUp) then
-				color = color - 0x1
-			else
-				goingUp = true
-				color = color + 0x1
-			end
-		end
-		return color
-	end
-	-- Captain Lime gets a fake color clore to hero's clan color.
-	-- This is a hack, but it works. See explanation at top of file
-	local cptnColor = getSimilarColor(heroColor, assassinsColor)
-	AddTeam(teamB.name, cptnColor, "Cherry", "Island", "Default", "congo-brazzaville")
-	green1.gear= AddHog(green1.name, 0, 100, green1.hat)
+        -- Spawn with his "true" evil color so a new clan is created for Captain Lime ...
+	AddTeam(teamB.name, teamB.colorEvil, "Cherry", "Island", "Default", "congo-brazzaville")
+	green1.gear = AddHog(green1.name, 0, 100, green1.hat)
+	-- ... however, we immediately change the color to "nice mode".
+	-- Captain Lime starts as (seemingly) friendly in this mission.
+	SetClanColor(GetHogClan(green1.gear), teamB.colorNice)
 	SetGearPosition(green1.gear, green1.x, green1.y)
 
 	-- Populate goals table
@@ -573,6 +556,8 @@
 function makeCptLimeEvil()
 	-- Turn Captain Lime evil
 	SetHogLevel(green1.gear, 1)
+	-- ... and reveal his "true" evil color. Muhahaha!
+	SetClanColor(GetHogClan(green1.gear), teamB.colorEvil)
 	EndTurn(true)
 end