Merge antoc27's commits master_git
authorWuzzy <Wuzzy2@mail.ru>
Thu, 16 May 2019 22:07:06 +0200
changeset 14979 4406994969c3
parent 14978 fe8b4f2da9aa (diff)
parent 14971 9719a998670b (current diff)
child 14980 f359d8f86501
Merge antoc27's commits
--- a/ChangeLog.txt	Thu May 16 21:26:27 2019 +0200
+++ b/ChangeLog.txt	Thu May 16 22:07:06 2019 +0200
@@ -135,6 +135,7 @@
  + Utils library: New calls: getReadableChallengeRecord, updateChallengeRecord, integerSqrt, integerHypotenuse
  + New callback: onGameResult(winningClan): Called when the game ends normally. winningClan = index of winning clan or -1 on draw
  + New callback: onCaseDrop(gear): Called at the point where a crate MIGHT be dropped between turns. Gear is the crate gear or nil
+ + New callback: ooHogSwitch(oldHog): Called when hogs was switched with the “switch hedgehog” utility
  + New callback: onPreciseLocal(): Called when precise key is pressed client-side
  + SendStat extension: Option to use predefined modes with siPointType, like "!POINTS" or "!TIME"
  + SimpleMission: Add isMissionTeam attribute for teams
--- a/hedgewars/uGearsHandlersMess.pas	Thu May 16 21:26:27 2019 +0200
+++ b/hedgewars/uGearsHandlersMess.pas	Thu May 16 22:07:06 2019 +0200
@@ -3338,6 +3338,7 @@
     hedgehog: PHedgehog;
     State: Longword;
     switchDir: Longword;
+    oldUid: Longword;
 begin
     AllInactive := false;
 
@@ -3355,6 +3356,7 @@
     if (Gear^.Message and gmSwitch) <> 0 then
         begin
         HHGear := CurrentHedgehog^.Gear;
+        oldUid:= HHGear^.uid;
         HHGear^.Message := HHGear^.Message and (not gmSwitch);
         Gear^.Message := Gear^.Message and (not gmSwitch);
 
@@ -3387,6 +3389,7 @@
         AmmoMenuInvalidated:= true;
 
         HHGear := CurrentHedgehog^.Gear;
+        ScriptCall('onHogSwitch', oldUid);
         HHGear^.State := State;
         HHGear^.Active := true;
         FollowGear := HHGear;
--- a/share/hedgewars/Data/Maps/CTF_Blizzard/map.lua	Thu May 16 21:26:27 2019 +0200
+++ b/share/hedgewars/Data/Maps/CTF_Blizzard/map.lua	Thu May 16 22:07:06 2019 +0200
@@ -105,6 +105,7 @@
 						-- currently every 6 TURNS, should this work
 						-- on ROUNDS instead?
 local effectTimer = 0
+local gameEnded = false
 
 local ropeGear = nil
 
@@ -120,6 +121,11 @@
 local teamIndex = {} -- at what point in the hhs{} does each team begin
 local clanTeams = {} -- list of teams per clan
 
+local mostCapturesHogName = nil -- name of hog who holds the record of most flags captured
+local mostCapturesHogTeam = nil -- name of team who holds the record of most flags captured
+local mostCaptures = 0 -- number of most per-hog captures
+local capturesPerHog = {}
+
 -------------------
 -- flag variables
 -------------------
@@ -155,8 +161,8 @@
 --zone and teleporter variables
 --------------------------------
 
-local redTel
-local orangeTel
+local leftTel
+local rightTel
 
 local zXMin = {}
 local zWidth = {}
@@ -175,16 +181,18 @@
 	if effectTimer > 50 then
 		effectTimer = 0
 
-		for i = 0,1 do
-			local eX = 10 + zXMin[i] + GetRandom(zWidth[i]-10)
-			local eY = 50 + zYMin[i] + GetRandom(zHeight[i]-110)
+		local i = GetHogClan(CurrentHedgehog)
+		if i ~= 0 and i ~= 1 then
+			return
+		end
+		local eX = 10 + zXMin[i] + GetRandom(zWidth[i]-10)
+		local eY = 50 + zYMin[i] + GetRandom(zHeight[i]-110)
 
-			-- steam and smoke and DUST look good, smokering looks trippy
-			-- smoketrace and eviltrace are not effected by wind?
-			-- chunk is a LR falling gear
-			local tempE = AddVisualGear(eX, eY, vgtDust, 0, false)
-			SetVisualGearValues(tempE, eX, eY, nil, nil, nil, nil, nil, nil, nil, fCol[i])
-		end
+		-- steam and smoke and DUST look good, smokering looks trippy
+		-- smoketrace and eviltrace are not effected by wind?
+		-- chunk is a LR falling gear
+		local tempE = AddVisualGear(eX, eY, vgtDust, 0, false)
+		SetVisualGearValues(tempE, eX, eY, nil, nil, nil, nil, nil, nil, nil, fCol[i])
 	end
 end
 
@@ -228,14 +236,38 @@
 		alt = 0
 	end
 
-	if fCaptures[teamID] == 3 then
+	if fCaptures[teamID] == 3 and not gameEnded then
+		gameEnded = true
 		for i = 0, (numhhs-1) do
 			if GetHogClan(hhs[i]) == alt then
 				SetEffect(hhs[i], heResurrectable, 0)
 				SetHealth(hhs[i],0)
 			end
 		end
-		ShowMission(loc("GAME OVER!"), loc("Victory for the ") .. GetHogTeamName(CurrentHedgehog), loc("Hooray!"), 0, 0)
+		local victoryMsg = string.format(loc("Victory for %s!"), GetHogTeamName(CurrentHedgehog))
+		AddCaption(victoryMsg, capcolDefault, capgrpGameState)
+
+		-- Calculate team rankings
+		local teamList = {}
+		for i=0, TeamsCount-1 do
+			local name = GetTeamName(i)
+			local clan = GetTeamClan(name)
+			if fCaptures[clan] ~= nil then
+				table.insert(teamList, { score = fCaptures[clan], name = name, clan = clan })
+			end
+		end
+		local teamRank = function(a, b)
+			return a.score > b.score
+		end
+		table.sort(teamList, teamRank)
+
+		for i=1, #teamList do
+			SendStat(siPointType, "!POINTS")
+			SendStat(siPlayerKills, tostring(teamList[i].score), teamList[i].name)
+		end
+		if mostCaptures >= 2 then
+			SendStat(siCustomAchievement, string.format(loc("%s (%s) has captured the flag %d times."), mostCapturesHogName, mostCapturesHogTeam, mostCaptures))
+		end
 	end
 
 end
@@ -246,10 +278,9 @@
 
 		if fNeedsRespawn[i] == true then
 			fGear[i] = SpawnFakeAmmoCrate(fSpawnX[i],fSpawnY[i],false,false)
-			--fGear[i] = SpawnHealthCrate(fSpawnX[i],fSpawnY[i])
 			fNeedsRespawn[i] = false
 			fIsMissing[i] = false -- new, this should solve problems of a respawned flag being "returned" when a player tries to score
-			AddCaption(loc("Flag respawned!"))
+			AddCaption(loc("Flag respawned!"), capcolDefault, capgrpAmmoinfo)
 		end
 
 	end
@@ -259,7 +290,6 @@
 function FlagDeleted(gear)
 
 	local wtf, bbq
-	PlaySound(sndShotgunReload)
 	if (gear == fGear[0]) then
 		wtf = 0
 		bbq = 1
@@ -271,12 +301,13 @@
 	if CurrentHedgehog ~= nil then
 
 		--if the player picks up the flag
-		if CheckDistance(CurrentHedgehog, fGear[wtf]) < 1600 then
+		if band(GetGearMessage(gear), gmDestroy) ~= 0 then
 
 			fGear[wtf] = nil -- the flag has now disappeared and we shouldnt be pointing to it
 
 			-- player has successfully captured the enemy flag
 			if (GetHogClan(CurrentHedgehog) == wtf) and (CurrentHedgehog == fThief[bbq]) and (fIsMissing[wtf] == false) then
+				PlaySound(sndShotgunReload)
 				fIsMissing[wtf] = false
 				fNeedsRespawn[wtf] = true
 				fIsMissing[bbq] = false
@@ -288,25 +319,33 @@
 					SetTeamLabel(clanTeams[wtf][i], fCaptures[wtf])
 				end
 
+				capturesPerHog[CurrentHedgehog] = capturesPerHog[CurrentHedgehog] + 1
+				if capturesPerHog[CurrentHedgehog] > mostCaptures then
+					mostCaptures = capturesPerHog[CurrentHedgehog]
+					mostCapturesHogName = GetHogName(CurrentHedgehog)
+					mostCapturesHogTeam = GetHogTeamName(CurrentHedgehog)
+				end
+
 				PlaySound(sndHomerun)
 				fThief[bbq] = nil -- player no longer has the enemy flag
 				CheckScore(wtf)
 
 			--if the player is returning the flag
 			elseif GetHogClan(CurrentHedgehog) == wtf then
-
+				PlaySound(sndShotgunReload)
 				fNeedsRespawn[wtf] = true
 
 				-- NEW ADDIITON, does this work? Should make it possible to return your flag and then score in the same turn
 				if fIsMissing[wtf] == true then
 					HandleRespawns() -- this will set fIsMissing[wtf] to false :)
-					AddCaption(loc("Flag returned!"))
+					AddCaption(loc("Flag returned!"), capcolDefault, capgrpAmmoinfo)
 				elseif fIsMissing[wtf] == false then
 					AddCaption(loc("That was pointless. The flag will respawn next round."))
 				end
 
 			--if the player is taking the enemy flag
 			elseif GetHogClan(CurrentHedgehog) == bbq then
+				PlaySound(sndShotgunReload)
 				fIsMissing[wtf] = true
 				for i = 0,numhhs-1 do
 					if CurrentHedgehog == hhs[i] then
@@ -321,7 +360,7 @@
 
 			end
 
-		-- if flag has been destroyed, probably
+		-- if flag has been destroyed
 		else
 
 			if GetY(fGear[wtf]) > 2025 then
@@ -368,6 +407,7 @@
 		else
 			fGear[wtf] = SpawnFakeAmmoCrate(fThiefX[wtf],(fThiefY[wtf]-50),false,false)
 		end
+		AddCaption(string.format(loc("%s has dropped the flag!"), GetHogName(gear)), capcolDefault, capgrpAmmoinfo)
 
 		AddVisualGear(fThiefX[wtf], fThiefY[wtf], vgtBigExplosion, 0, false)
 		fThief[wtf] = nil
@@ -399,28 +439,15 @@
 -- general methods
 ------------------------
 
-function CheckDistance(gear1, gear2)
-
-	local g1X, g1Y = GetGearPosition(gear1)
-	local g2X, g2Y = GetGearPosition(gear2)
-
-	g1X = g1X - g2X
-	g1Y = g1Y - g2Y
-	local dist = (g1X*g1X) + (g1Y*g1Y)
-
-	return dist
-
-end
-
 function CheckTeleporters()
 
 	local teleportActive = false
 
-	if (GearIsInZone(CurrentHedgehog, redTel) == true) and (GetHogClan(CurrentHedgehog) == 0) then
+	if (GearIsInZone(CurrentHedgehog, leftTel) == true) and (GetHogClan(CurrentHedgehog) == 0) then
 		teleportActive = true
 		destinationX = 1402
 		destinationY = 321
-	elseif (GearIsInZone(CurrentHedgehog, orangeTel) == true) and (GetHogClan(CurrentHedgehog) == 1) then
+	elseif (GearIsInZone(CurrentHedgehog, rightTel) == true) and (GetHogClan(CurrentHedgehog) == 1) then
 		teleportActive = true
 		destinationX = 2692
 		destinationY = 321
@@ -438,6 +465,7 @@
 		elseif actionReset == 20 then
 			AddVisualGear(GetX(CurrentHedgehog), GetY(CurrentHedgehog), vgtBigExplosion, 0, false)
 			SetGearPosition(CurrentHedgehog,destinationX,destinationY)
+			PlaySound(sndWarp)
 			AddVisualGear(GetX(CurrentHedgehog), GetY(CurrentHedgehog), vgtBigExplosion, 0, false)
 		end
 
@@ -511,6 +539,7 @@
 		elseif r == 7 then
 			SpawnSupplyCrate(0,0,amPortalGun)
 		end
+		PlaySound(sndReinforce, CurrentHedgehog)
 
 	end
 
@@ -534,17 +563,26 @@
 	Map = "Blizzard" -- The map to be played
 	Theme = "Snow" -- The theme to be used
 
+	SendHealthStatsOff()
+	SendRankingStatsOff()
+
 end
 
 
 function onGameStart()
 
-	ShowMission(loc("CTF_Blizzard"), loc("Capture The Flag"), loc(" - Return the enemy flag to your base to score | - First team to 3 captures wins | - You may only score when your flag is in your base | - Hogs will drop the flag if killed, or drowned | - Dropped flags may be returned or recaptured | - Hogs respawn when killed"), 0, 0)
-
+	ShowMission(loc("CTF_Blizzard"), loc("Capture The Flag"),
+		loc("- Return the enemy flag to your base to score") .."|"..
+		string.format(loc("- First clan to score %d captures wins"), 3) .. "|"..
+		loc("- You may only score when your flag is in your base") .."|"..
+		loc("- Hogs will drop the flag when killed") .."|"..
+		loc("- Dropped flags may be returned or recaptured").."|"..
+		loc("- Hogs will be revived") .."|"..
+		loc("- Touch the sparkles near your base to teleport"), 0, 0)
 
 	-- initialize teleporters
-	redTel = CreateZone(342,1316,42,449)	-- red teleporter
-	orangeTel = CreateZone(3719,1330,45,449)	-- orange teleporter
+	leftTel = CreateZone(342,1316,42,449)	-- left teleporter (clan 0)
+	rightTel = CreateZone(3719,1330,45,449)	-- right teleporter (clan 1)
 
 
 	--new improved placement schematics aw yeah
@@ -616,6 +654,11 @@
 function onNewTurn()
 
 	HandleRespawns()
+
+end
+
+function onCaseDrop()
+
 	HandleCrateDrops()
 
 end
@@ -639,7 +682,9 @@
 	end
 
 	HandleCircles()
-	ManageTeleporterEffects()
+	if (CurrentHedgehog ~= nil) then
+		ManageTeleporterEffects()
+	end
 
 end
 
@@ -707,6 +752,7 @@
 
 	if GetGearType(gear) == gtHedgehog then
 
+		capturesPerHog[gear] = 0
 		if GetHogClan(gear) > 1 then
 			DeleteGear(gear)
 			if not excessHogsWarning then