Use player's team identity for SimpleMission-based mission
authorWuzzy <Wuzzy2@mail.ru>
Thu, 20 Dec 2018 18:23:13 +0100
changeset 14504 310b167141cc
parent 14503 d4aa64f51c9f
child 14505 764ba6182389
Use player's team identity for SimpleMission-based mission
ChangeLog.txt
share/hedgewars/Data/Missions/Scenario/Bazooka_Battlefield.lua
share/hedgewars/Data/Missions/Scenario/Big_Armory.lua
share/hedgewars/Data/Missions/Scenario/Tentacle_Terror.lua
share/hedgewars/Data/Missions/Scenario/User_Mission_-_Newton_and_the_Hammock.lua
share/hedgewars/Data/Missions/Scenario/User_Mission_-_Nobody_Laugh.lua
share/hedgewars/Data/Missions/Scenario/User_Mission_-_The_Great_Escape.lua
share/hedgewars/Data/Missions/Scenario/portal.lua
share/hedgewars/Data/Scripts/SimpleMission.lua
--- a/ChangeLog.txt	Thu Dec 20 17:51:46 2018 +0100
+++ b/ChangeLog.txt	Thu Dec 20 18:23:13 2018 +0100
@@ -28,6 +28,7 @@
  + New return value: AddTeam and AddMissionTeam return team index of new team
  + Utils library: New calls: getReadableChallengeRecord, updateChallengeRecord
  + New callback: onGameResult(winningClan): Called when the game ends normally. winningClan = index of winning clan or -1 on draw
+ + SimpleMission: Add isMissionTeam attribute for teams
  + SpeedShoppa/TargetPractice libraries: Remove custom hog and team info settings
  + Params explode, poison in the SpawnFake*Crate functions now optional and default to false
 
--- a/share/hedgewars/Data/Missions/Scenario/Bazooka_Battlefield.lua	Thu Dec 20 17:51:46 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/Bazooka_Battlefield.lua	Thu Dec 20 18:23:13 2018 +0100
@@ -14,24 +14,16 @@
 		[amBazooka] = { count = 9 },
 	},
 	teams = {
-		{ name = loc("Pincer Knights"),
-		flag = "cm_swordshield",
-		grave = "Grave",
+		{ isMissionTeam = true,
 		hogs = {
 			{
-			name = loc("Left Tong"),
 			health = 100,
 			x = 276, y = 825,
-			botLevel = 0,
-			hat = "knight",
 			ammo = { [amSwitch] = 100 },
 			},
 			{
-			name = loc("Right Tong"),
 			health = 100,
 			x = 1794, y = 716,
-			botLevel = 0,
-			hat = "knight",
 			faceLeft = true,
 			},
 		}, },
--- a/share/hedgewars/Data/Missions/Scenario/Big_Armory.lua	Thu Dec 20 17:51:46 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/Big_Armory.lua	Thu Dec 20 18:23:13 2018 +0100
@@ -28,16 +28,12 @@
 		* relevant GameFlag: gfDisableLandObjects ]]
 	},
 	teams = {
-		{ name = loc("Pro Killers"),
+		{ isMissionTeam = true,
 		clanID = 0,
-		flag = "cm_scout",
-		grave = "Bone",
 		hogs = {
 			{
-			name = loc("Ultrasoldier"),
 			health = 100,
 			x = 543, y = 1167,
-			hat = "Terminator_Glasses",
 			ammo = heroAmmo,
 			}
 		}, },
--- a/share/hedgewars/Data/Missions/Scenario/Tentacle_Terror.lua	Thu Dec 20 17:51:46 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/Tentacle_Terror.lua	Thu Dec 20 18:23:13 2018 +0100
@@ -16,16 +16,12 @@
 	},
 	wind = -50,
 	teams = {
-		{ name = loc("Hell Army"),
-		flag = "cm_hellish",
-		grave = "Simple_reversed",
+		{ isMissionTeam = true,
 		hogs = { {
-			name = loc("Lord Evil"),
 			faceLeft = true,
 			health = 30,
 			x = 1210, y = 1446,
-			hat = "Evil",
-			botLevel = 0 } }
+			} }
 		},
 		{ name = loc("Heavenly Defense"),
 		flag = "cm_fcw",
--- a/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Newton_and_the_Hammock.lua	Thu Dec 20 17:51:46 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Newton_and_the_Hammock.lua	Thu Dec 20 18:23:13 2018 +0100
@@ -13,12 +13,10 @@
 		MapFeatureSize = 12,
 	},
 	teams = {
-		{ name = loc("Pathetic Resistance"),
+		{ isMissionTeam = true,
 		clanID = 0,
-		flag = "cm_yinyang",
-		grave = "Plinko",
 		hogs = {
-			{name = loc("Ikeda"), health = 48, x = 397, y = 865, hat = "StrawHat"}
+			{health = 48, x = 397, y = 865}
 		}, },
 
 		{ name = loc("Cybernetic Empire"),
--- a/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Nobody_Laugh.lua	Thu Dec 20 17:51:46 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/User_Mission_-_Nobody_Laugh.lua	Thu Dec 20 18:23:13 2018 +0100
@@ -24,26 +24,17 @@
 		[amSwitch] = { count = 9 },
 	},
 	teams = {
-		{ name = loc("Nameless Heroes"),
-		flag = "cm_crossedswords",
-		grave = "eyecross",
-		voice = "HillBilly",
+		{ isMissionTeam = true,
 		clanID = 0,
 		hogs = {
 			{
-			name = loc("Hunter"),
 			health = 1,
 			x = 1267, y = 451,
-			hat = "Skull",
-			botLevel = 0,
 			ammo = { [amParachute] = 1, [amHammer] = 1 },
 			},
 			{
-			name = loc("Drowner"),
 			health = 31,
 			x = 1332, y = 451,
-			hat = "mp3",
-			botLevel = 0,
 			ammo = { [amWhip] = 1 },
 			},
 		}},
--- a/share/hedgewars/Data/Missions/Scenario/User_Mission_-_The_Great_Escape.lua	Thu Dec 20 17:51:46 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/User_Mission_-_The_Great_Escape.lua	Thu Dec 20 18:23:13 2018 +0100
@@ -19,10 +19,8 @@
 		[amFirePunch] = { ammoInCrate = 3 },
 	},
 	teams = {
-		{ name = loc("Hero Team"),
-		flag = "cm_swordshield",
-		grave = "star",
-		hogs = {{ name = loc("Good Dude"), health = 1, x = 1050, y = 534 }},
+		{ isMissionTeam = true,
+		hogs = {{ health = 1, x = 1050, y = 534 }},
 		},
 		{ name = loc("Bad Team"),
 		flag = "cm_dragonrb",
--- a/share/hedgewars/Data/Missions/Scenario/portal.lua	Thu Dec 20 17:51:46 2018 +0100
+++ b/share/hedgewars/Data/Missions/Scenario/portal.lua	Thu Dec 20 18:23:13 2018 +0100
@@ -19,10 +19,10 @@
 	HealthDecrease = 0
 	WaterRise = 0
 
-	AddMissionTeam(-9)
+	AddMissionTeam(-1)
 	player = AddMissionHog(10)
 
-	AddTeam(loc("Hell Army"), -1, "skull", "Island", "Default", "cm_hellish")
+	AddTeam(loc("Hell Army"), -9, "skull", "Island", "Default", "cm_hellish")
 	enemy1 = AddHog(loc("Lucifer"), 1, 200, "InfernalHorns")
 	enemy2 = AddHog(loc("Voldemort"), 1, 150, "WizardHat")
 	enemy3 = AddHog(loc("Zombi"), 1, 100, "Zombi")
@@ -32,7 +32,7 @@
 	enemy7 = AddHog(loc("C-2"), 1, 50, "cyborg1")
 	enemy8 = AddHog(loc("Rider"), 1, 50, "scif_SparkssHelmet")
 
-	AddTeam(loc("Badmad"), -1, "skull", "Island", "Default", "cm_pentagram")
+	AddTeam(loc("Badmad"), -9, "skull", "Island", "Default", "cm_pentagram")
 	enemy9 = AddHog(loc("C-1"), 1, 50, "cyborg2")
 	enemy10 = AddHog(loc("Hidden"), 1, 40, "bushhider")
 	enemy11 = AddHog(loc("Ronald"), 1, 70, "clown")
--- a/share/hedgewars/Data/Scripts/SimpleMission.lua	Thu Dec 20 17:51:46 2018 +0100
+++ b/share/hedgewars/Data/Scripts/SimpleMission.lua	Thu Dec 20 18:23:13 2018 +0100
@@ -53,27 +53,30 @@
 	- probability		probability in crates (default: 0)
 
 	TEAM DATA
+	- isMissionTeam		if true, this is the player's chosen team for this mission (default: false)
 	- hogs			table of hedgehogs in this team (must contain at least 1 hog)
-	- name			team name
 	- clanID		ID of the clan to which this team belongs to. Counting starts at 0.
 				By default, each team goes into its own clan.
 				Important: The clan of the player and allies MUST be 0.
 				Important: You MUST either set the clan ID explicitly for all teams or none of them.
+	These arguments will be ignored if this is a mission team:
+	- name			team name
 	- flag			flag name (default: hedgewars)
 	- grave			grave name (has default grave for each team)
 	- fort			fort name (default: Castle)
 
 	HEDGEHOG DATA:
 	- id			optional identifier for goals
-	- name			hog name
+	- health		hog health (default: 100)
+	- ammo			table of ammo types
 	- x, y			hog position (default: spawns randomly on land)
-	- botLevel		1-5: Bot level (lower=stronger). 0=human player (default: 0)
-	- hat			hat name (default: NoHat)
-	- health		hog health (default: 100)
 	- poisoned		if true, hedgehog starts poisoned with 5 poison damage. Set to a number for other poison damage (default: false)
 	- frozen		if true, hedgehogs starts frozen (default: false)
 	- faceLeft		initial facing direction. true=left, false=false (default: false)
-	- ammo			table of ammo types
+	These arguments will be ignored if the hog is in a mission team:
+	- name			hog name
+	- botLevel		1-5: Bot level (lower=stronger). 0=human player (default: 0)
+	- hat			hat name (default: NoHat)
 
 	GEAR TYPES:
 	- type			gear type
@@ -656,12 +659,35 @@
 			else
 				clanID = teamData.clanID
 			end
-			grave = def(teamData.grave, defaultGraves[math.min(teamID, 8)])
-			fort = def(teamData.fort, "Castle")
-			voice = def(teamData.voice, "Default")
-			flag = def(teamData.flag, defaultFlags[math.min(teamID, 8)])
+
+			local idx
+			if teamData.isMissionTeam then
+				idx = AddMissionTeam(-(clanID+1))
+				_G.sm.playerClan = clanID
+			else
+				grave = def(teamData.grave, defaultGraves[math.min(teamID, 8)])
+				fort = def(teamData.fort, "Castle")
+				voice = def(teamData.voice, "Default")
+				flag = def(teamData.flag, defaultFlags[math.min(teamID, 8)])
 
-			AddTeam(name, -(clanID+1), grave, fort, voice, flag)
+				idx = AddTeam(name, -(clanID+1), grave, fort, voice, flag)
+				local realName = GetTeamName(idx)
+				-- Update all teamDefeat goals if the real team name differs from the
+				-- team configuration.
+				-- (AddTeam might change the name due to naming collisions)
+				if name ~= realName then
+					local checks = { params.customGoals, params.customNonGoals }
+					for c=1, 2 do
+						if checks[c] then
+							for k,goal in pairs(checks[c]) do
+								if goal.type == "teamDefeat" and goal.teamName == name then
+									goal.teamName = realName
+								end
+							end
+						end
+					end
+				end
+			end
 
 			for hogID, hogData in pairs(teamData.hogs) do
 				local name, botLevel, health, hat
@@ -669,7 +695,12 @@
 				botLevel = def(hogData.botLevel, 0)
 				health = def(hogData.health, 100)
 				hat = def(hogData.hat, "NoHat")
-				local hog = AddHog(name, botLevel, health, hat)
+				local hog
+				if teamData.isMissionTeam then
+					hog = AddMissionHog(health)
+				else
+					hog = AddHog(name, botLevel, health, hat)
+				end
 				if hogData.x ~= nil and hogData.y ~= nil then
 					SetGearPosition(hog, hogData.x, hogData.y)
 				end