Move health sorter to visual gears:
authorunc0rr
Sun, 19 Apr 2009 11:59:23 +0000
changeset 2005 aa79f631711b
parent 2004 f7944d5adc5f
child 2006 587636c8344e
Move health sorter to visual gears: - Should fix or at least help with problems when one of players quits (needs testing) - Breaks 0.9.10 compatibility, so increase protocol number and set version to 0.9.11-dev
CMakeLists.txt
hedgewars/GSHandlers.inc
hedgewars/uConsts.pas
hedgewars/uGears.pas
hedgewars/uTeams.pas
hedgewars/uVisualGears.pas
--- a/CMakeLists.txt	Sun Apr 19 11:40:41 2009 +0000
+++ b/CMakeLists.txt	Sun Apr 19 11:59:23 2009 +0000
@@ -10,7 +10,7 @@
 
 set(CPACK_PACKAGE_VERSION_MAJOR "0")
 set(CPACK_PACKAGE_VERSION_MINOR "9")
-set(CPACK_PACKAGE_VERSION_PATCH "10")
+set(CPACK_PACKAGE_VERSION_PATCH "11-dev")
 
 if(DEFINED DATA_INSTALL_DIR)
 	set(SHAREPATH ${DATA_INSTALL_DIR}/hedgewars/)
@@ -20,7 +20,7 @@
 set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
 
 set(HEDGEWARS_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
-set(HEDGEWARS_PROTO_VER 25)
+set(HEDGEWARS_PROTO_VER 26)
 
 if(WITH_SERVER)
 	set(HAVE_NETSERVER true)
--- a/hedgewars/GSHandlers.inc	Sun Apr 19 11:40:41 2009 +0000
+++ b/hedgewars/GSHandlers.inc	Sun Apr 19 11:59:23 2009 +0000
@@ -1095,83 +1095,6 @@
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
-const cSorterWorkTime = 640;
-var thexchar: array[0..cMaxTeams] of
-			record
-			dy, ny, dw: LongInt;
-			team: PTeam;
-			SortFactor: QWord;
-			end;
-    currsorter: PGear = nil;
-
-procedure doStepTeamHealthSorterWork(Gear: PGear);
-var i: LongInt;
-begin
-AllInactive:= false;
-dec(Gear^.Timer);
-if (Gear^.Timer and 15) = 0 then
-	for i:= 0 to Pred(TeamsCount) do
-		with thexchar[i] do
-			begin
-			{$WARNINGS OFF}
-			team^.DrawHealthY:= ny + dy * Gear^.Timer div 640;
-			team^.TeamHealthBarWidth:= team^.NewTeamHealthBarWidth + dw * Gear^.Timer div cSorterWorkTime;
-			{$WARNINGS ON}
-			end;
-
-if (Gear^.Timer = 0) or (currsorter <> Gear) then
-	begin
-	if currsorter = Gear then currsorter:= nil;
-	DeleteGear(Gear)
-	end
-end;
-
-procedure doStepTeamHealthSorter(Gear: PGear);
-var i: Longword;
-	b: boolean;
-	t: LongInt;
-begin
-AllInactive:= false;
-
-for t:= 0 to Pred(TeamsCount) do
-	with thexchar[t] do
-		begin
-		dy:= TeamsArray[t]^.DrawHealthY;
-		dw:= TeamsArray[t]^.TeamHealthBarWidth - TeamsArray[t]^.NewTeamHealthBarWidth;
-		team:= TeamsArray[t];
-		SortFactor:= TeamsArray[t]^.Clan^.ClanHealth;
-		SortFactor:= (SortFactor shl  3) + TeamsArray[t]^.Clan^.ClanIndex;
-		SortFactor:= (SortFactor shl 30) + TeamsArray[t]^.TeamHealth;
-		end;
-
-if TeamsCount > 1 then
-	repeat
-	b:= true;
-	for t:= 0 to TeamsCount - 2 do
-		if (thexchar[t].SortFactor > thexchar[Succ(t)].SortFactor) then
-			begin
-			thexchar[cMaxTeams]:= thexchar[t];
-			thexchar[t]:= thexchar[Succ(t)];
-			thexchar[Succ(t)]:= thexchar[cMaxTeams];
-			b:= false
-			end
-	until b;
-
-t:= - 4;
-for i:= 0 to Pred(TeamsCount) do
-	with thexchar[i] do
-		begin
-		dec(t, team^.HealthTex^.h + 2);
-		ny:= t;
-		dy:= dy - ny
-		end;
-
-Gear^.Timer:= cSorterWorkTime;
-Gear^.doStep:= @doStepTeamHealthSorterWork;
-currsorter:= Gear
-end;
-
-////////////////////////////////////////////////////////////////////////////////
 procedure doStepIdle(Gear: PGear);
 begin
 AllInactive:= false;
--- a/hedgewars/uConsts.pas	Sun Apr 19 11:40:41 2009 +0000
+++ b/hedgewars/uConsts.pas	Sun Apr 19 11:59:23 2009 +0000
@@ -64,15 +64,15 @@
 	TGearType = (gtAmmo_Bomb, gtHedgehog, gtAmmo_Grenade, gtHealthTag, // 3
 			gtGrave, gtUFO, gtShotgunShot, gtPickHammer, gtRope, // 8
 			gtSmokeTrace, gtExplosion, gtMine, gtCase, gtDEagleShot, gtDynamite, // 14
-			gtTeamHealthSorter, gtClusterBomb, gtCluster, gtShover, gtFlame, // 19
-			gtFirePunch, gtATStartGame, gtATSmoothWindCh, gtATFinishGame, // 23
-			gtParachute, gtAirAttack, gtAirBomb, gtBlowTorch, gtGirder, // 28
-			gtTeleport, gtSwitcher, gtTarget, gtMortar, // 32
-			gtWhip, gtKamikaze, gtCake, gtSeduction, gtWatermelon, gtMelonPiece, // 38
+			gtClusterBomb, gtCluster, gtShover, gtFlame, // 18
+			gtFirePunch, gtATStartGame, gtATSmoothWindCh, gtATFinishGame, // 24
+			gtParachute, gtAirAttack, gtAirBomb, gtBlowTorch, gtGirder, // 27
+			gtTeleport, gtSwitcher, gtTarget, gtMortar, // 31
+			gtWhip, gtKamikaze, gtCake, gtSeduction, gtWatermelon, gtMelonPiece, // 37
 			gtHellishBomb, gtEvilTrace, gtWaterUp, gtDrill, gtBallGun, gtBall,gtRCPlane);
 
 	TVisualGearType = (vgtFlake, vgtCloud, vgtExplPart, vgtExplPart2, vgtFire,
-			vgtSmallDamageTag);
+			vgtSmallDamageTag, vgtTeamHealthSorter);
 
 	TGearsType = set of TGearType;
 
--- a/hedgewars/uGears.pas	Sun Apr 19 11:40:41 2009 +0000
+++ b/hedgewars/uGears.pas	Sun Apr 19 11:59:23 2009 +0000
@@ -128,7 +128,6 @@
 			@doStepCase,
 			@doStepDEagleShot,
 			@doStepDynamite,
-			@doStepTeamHealthSorter,
 			@doStepBomb,
 			@doStepCluster,
 			@doStepShover,
--- a/hedgewars/uTeams.pas	Sun Apr 19 11:40:41 2009 +0000
+++ b/hedgewars/uTeams.pas	Sun Apr 19 11:59:23 2009 +0000
@@ -105,7 +105,7 @@
 procedure TeamGone(s: shortstring);
 
 implementation
-uses uMisc, uWorld, uAI, uLocale, uConsole, uAmmos, uChat;
+uses uMisc, uWorld, uAI, uLocale, uConsole, uAmmos, uChat, uVisualGears;
 const MaxTeamHealth: LongInt = 0;
 
 procedure FreeTeamsList; forward;
@@ -356,7 +356,7 @@
 
 RecountClanHealth(team^.Clan);
 
-AddGear(0, 0, gtTeamHealthSorter, 0, _0, _0, 0)
+AddVisualGear(0, 0, vgtTeamHealthSorter)
 end;
 
 procedure RestoreTeamsFromSave;
--- a/hedgewars/uVisualGears.pas	Sun Apr 19 11:40:41 2009 +0000
+++ b/hedgewars/uVisualGears.pas	Sun Apr 19 11:59:23 2009 +0000
@@ -39,6 +39,7 @@
 		dX: hwFloat;
 		dY: hwFloat;
 		mdY: QWord;
+		Timer: Longword;
 		Angle, dAngle: real;
 		Kind: TVisualGearType;
 		doStep: TVGearStepProcedure;
@@ -57,7 +58,7 @@
 	vobVelocity, vobFallSpeed: LongInt;
 
 implementation
-uses uWorld, uMisc, uStore;
+uses uWorld, uMisc, uStore, uTeams;
 const cExplFrameTicks = 110;
 
 procedure AddDamageTag(X, Y, Damage, Color: LongWord);
@@ -160,6 +161,85 @@
 	dec(Gear^.FrameTicks, Steps)
 end;
 
+////////////////////////////////////////////////////////////////////////////////
+const cSorterWorkTime = 640;
+var thexchar: array[0..cMaxTeams] of
+			record
+			dy, ny, dw: LongInt;
+			team: PTeam;
+			SortFactor: QWord;
+			end;
+    currsorter: PVisualGear = nil;
+
+procedure doStepTeamHealthSorterWork(Gear: PVisualGear; Steps: Longword);
+var i, t: LongInt;
+begin
+for t:= 1 to Steps do
+	begin
+	dec(Gear^.Timer);
+	if (Gear^.Timer and 15) = 0 then
+		for i:= 0 to Pred(TeamsCount) do
+			with thexchar[i] do
+				begin
+				{$WARNINGS OFF}
+				team^.DrawHealthY:= ny + dy * Gear^.Timer div 640;
+				team^.TeamHealthBarWidth:= team^.NewTeamHealthBarWidth + dw * Gear^.Timer div cSorterWorkTime;
+				{$WARNINGS ON}
+				end;
+
+	if (Gear^.Timer = 0) or (currsorter <> Gear) then
+		begin
+		if currsorter = Gear then currsorter:= nil;
+		DeleteVisualGear(Gear);
+		exit
+		end
+	end
+end;
+
+procedure doStepTeamHealthSorter(Gear: PVisualGear; Steps: Longword);
+var i: Longword;
+	b: boolean;
+	t: LongInt;
+begin
+for t:= 0 to Pred(TeamsCount) do
+	with thexchar[t] do
+		begin
+		dy:= TeamsArray[t]^.DrawHealthY;
+		dw:= TeamsArray[t]^.TeamHealthBarWidth - TeamsArray[t]^.NewTeamHealthBarWidth;
+		team:= TeamsArray[t];
+		SortFactor:= TeamsArray[t]^.Clan^.ClanHealth;
+		SortFactor:= (SortFactor shl  3) + TeamsArray[t]^.Clan^.ClanIndex;
+		SortFactor:= (SortFactor shl 30) + TeamsArray[t]^.TeamHealth;
+		end;
+
+if TeamsCount > 1 then
+	repeat
+	b:= true;
+	for t:= 0 to TeamsCount - 2 do
+		if (thexchar[t].SortFactor > thexchar[Succ(t)].SortFactor) then
+			begin
+			thexchar[cMaxTeams]:= thexchar[t];
+			thexchar[t]:= thexchar[Succ(t)];
+			thexchar[Succ(t)]:= thexchar[cMaxTeams];
+			b:= false
+			end
+	until b;
+
+t:= - 4;
+for i:= 0 to Pred(TeamsCount) do
+	with thexchar[i] do
+		begin
+		dec(t, team^.HealthTex^.h + 2);
+		ny:= t;
+		dy:= dy - ny
+		end;
+
+Gear^.Timer:= cSorterWorkTime;
+Gear^.doStep:= @doStepTeamHealthSorterWork;
+currsorter:= Gear;
+//doStepTeamHealthSorterWork(Gear, Steps)
+end;
+
 // ==================================================================
 const doStepHandlers: array[TVisualGearType] of TVGearStepProcedure =
 		(
@@ -168,7 +248,8 @@
 			@doStepExpl,
 			@doStepExpl,
 			@doStepFire,
-			@doStepSmallDamage
+			@doStepSmallDamage,
+			@doStepTeamHealthSorter
 		);
 
 function  AddVisualGear(X, Y: LongInt; Kind: TVisualGearType): PVisualGear;