Mostly Harmless

Legacy:Evolution/EvoETV

From Unreal Wiki, The Unreal Engine Documentation Site
< Legacy:Evolution
Revision as of 06:56, 29 November 2002 by Evolution (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
  1. //-----------------------------------------------------------
  2. //
  3. //-----------------------------------------------------------
  4. class EvoETV extends Mutator;
  5.  
  6. var TeamInfo Teams[4];
  7. var int MessageCount;
  8. var Pawn MovingPawn;
  9. var bool debug;
  10. var string MyIP;
  11. var string MyLocalIP;
  12.  
  13. function PostBeginPlay()
  14. {
  15. 	local int i;
  16. 	super.PostBeginPlay();
  17. 	Level.Game.RegisterMessageMutator(Self);
  18.  
  19. 	for (i=0;i<TeamGamePlus(Level.Game).MaxTeams;i++)
  20. 		Teams[i]=TeamGamePlus(Level.Game).Teams[i];
  21.  
  22. 	if ((TeamGamePlus(Level.Game)!=None)&&(TeamGamePlus(Level.Game).TimeLimit!=0))
  23. 		SetTimer(float((TeamGamePlus(Level.Game).TimeLimit*60)/3),true);
  24. 	else SetTimer(600.0,true);
  25.  
  26. 	Timer();
  27. }
  28.  
  29. function Timer()
  30. {
  31. 	BroadcastMessage("SYSTEM: type 'mutate et' in your console to even the teams.");
  32. }
  33.  
  34. function bool MutatorBroadcastLocalizedMessage( Actor Sender, Pawn Receiver, out class<LocalMessage> Message, out optional int Switch, out optional PlayerReplicationInfo RelatedPRI_1, out optional PlayerReplicationInfo RelatedPRI_2, out optional Object OptionalObject )
  35. {
  36. 	local int OldTeam;
  37. 	if ((Message==class'DeathMatchMessage')&&(switch==3))
  38. 	{
  39. 		if (RelatedPRI_1!=None)
  40. 		{
  41. 			if ((MovingPawn!=None)&&(RelatedPRI_1.Owner==MovingPawn))
  42. 			{
  43. 				if (++MessageCount<NumPlayers())
  44. 				{
  45. 					if (debug)
  46. 					{
  47. 						log(class@"Intercepting message to"@Receiver.PlayerReplicationInfo.PlayerName@"that"@RelatedPRI_1.PlayerName@"is changing teams.");
  48. 						log(class@"Count:"@MessageCount@"NumPlayers:"@NumPlayers());
  49. 					}
  50. 					return false;
  51. 				}
  52. 				else
  53. 				{
  54. 					MovingPawn=None;
  55. 					RelatedPRI_1.TweenRate=0;
  56. 					MessageCount=0;
  57. 					if (debug)
  58. 					{
  59. 						if (RelatedPRI_1.Team==0)
  60. 							OldTeam=1;
  61. 						log(class@"Teams were successfully balanced."@RelatedPRI_1.PlayerName@"was moved to"@TeamGamePlus(Level.Game).TeamColor[OldTeam]);
  62. 					}
  63. 				}
  64. 			}
  65. 			else
  66. 			{
  67. 				RelatedPRI_1.TweenRate = Level.TimeSeconds;
  68. 				if (debug)
  69. 					log(class@"TEAMCHANGE("$Level.TimeSeconds$"):"@RelatedPRI_1.PlayerName@RelatedPRI_1.Team@RelatedPRI_1.TweenRate);
  70. 			}
  71. 		}
  72. 	}
  73.  
  74. 	if ( NextMessageMutator != None )
  75. 		return NextMessageMutator.MutatorBroadcastLocalizedMessage( Sender, Receiver, Message, Switch, RelatedPRI_1, RelatedPRI_2, OptionalObject );
  76. 	else
  77. 		return true;
  78. }
  79.  
  80. function Mutate(string MutateString, PlayerPawn Sender)
  81. {
  82. 	local int pos;
  83. 	local string address;
  84. 	local Pawn P;
  85. 	if (MutateString~="et")
  86. 	{
  87. 		if (debug)
  88. 			log("*************************ET CALLED****************************");
  89. 		if ((Max(Teams[0].Size,Teams[1].Size) - Min(Teams[0].Size,Teams[1].Size))>1)
  90. 		{
  91. 			EvenTeams(Sender);
  92. 			if (debug)
  93. 				log(class@"Call to EvenTeams from"@Sender.PlayerReplicationInfo.PlayerName@"complete - team were NOT even");
  94. 		}
  95. 		else
  96. 		{
  97. 			Sender.ClientMessage("Teams are even,"@Sender.PlayerReplicationInfo.PlayerName);
  98. 			if (debug)
  99. 			{
  100. 				log(class@"Call to EvenTeams from"@Sender.PlayerReplicationInfo.PlayerName@"complete - teams were even");
  101. 				log(class@"Red Size:"$Teams[0].Size@"Blue Size:"$Teams[1].Size);
  102. 				for (P=Level.PawnList;P!=None;P=P.NextPawn)
  103. 					if (P.PlayerReplicationInfo!=None)
  104. 						log(Class@p.playerreplicationinfo.playername@"on team"@p.playerreplicationinfo.team);
  105. 			}
  106.  
  107. 		}
  108. 		return;
  109. 	}
  110. 	else if (MutateString~="etdebug")
  111. 	{
  112. 		address = Sender.GetPlayerNetworkAddress();
  113. 		if (((InStr(Address,MyIP)!=-1)||(InStr(Address,MyLocalIP)!=-1))||Sender.bAdmin)
  114. 		{
  115. 			log(class@"etdebug was called!!!"@Address);
  116. 			debug=true;
  117. 			Sender.ClientMessage("Debug has been enabled!!!");
  118. 			return;
  119. 		}
  120. 	}
  121. 	else if (MutateString~="etalert")
  122. 	{
  123. 		address = Sender.GetPlayerNetworkAddress();
  124. 		if (((InStr(Address,MyIP)!=-1)||(InStr(Address,MyLocalIP)!=-1))||Sender.bAdmin)
  125. 			log(class@"ETALERT:"@Level.TimeSeconds@"Red:"$TeamGamePlus(Level.Game).TeamColor[0]@"Blue:"$TeamGamePlus(Level.Game).TeamColor[1]);
  126. 		return;
  127. 	}
  128.  
  129. 	else if (NextMutator!=None)
  130. 		NextMutator.Mutate(MutateString, Sender);
  131. }
  132.  
  133. function EvenTeams(PlayerPawn Sender)
  134. {
  135. 	local Pawn P;
  136. 	local float NewestTime;
  137. 	local Pawn NewestPawn;
  138. 	local int Smallest,Biggest,i;
  139.  
  140. 	for (i=1;i<TeamGamePlus(Level.Game).MaxTeams;i++)
  141. 		if (Teams[i].Size>Teams[Biggest].Size)
  142. 			Biggest=i;
  143.  
  144. 	if (debug)
  145. 		log(class@"Biggest Team:"@TeamGamePlus(Level.Game).TeamColor[Biggest]);
  146.  
  147. 	for (P=Level.PawnList;P!=None;P=P.NextPawn)
  148. 	{
  149. 		if ((P.PlayerReplicationInfo!=None)&&(P.PlayerReplicationInfo.Team==Biggest) && (P.PlayerReplicationInfo.HasFlag==None)&&(Spectator(P)==None))
  150. 		{
  151. 			if (debug)
  152. 				log(class@"Checking"@P@P.PlayerReplicationInfo.PlayerName@TeamGamePlus(Level.Game).TeamColor[P.PlayerReplicationInfo.Team]@P.PlayerReplicationInfo.TweenRate);
  153.  
  154. 		if (P.PlayerReplicationInfo.TweenRate > NewestTime)
  155. 			{
  156. 				if (debug)
  157. 					log(class@"Found newer time than"@NewestTime@P@P.PlayerReplicationInfo.PlayerName);
  158. 				NewestTime = P.PlayerReplicationInfo.TweenRate;
  159. 				NewestPawn = P;
  160. 			}
  161. 		}
  162. 	}
  163. 	if (newestPawn!=none)
  164. 	{
  165.  
  166. 		if (debug)
  167. 			log(class@"Attempting to move"@NewestPawn.PlayerReplicationInfo.PlayerName@PlayerPawn(NewestPawn).GetPlayerNetworkaddress());
  168. 		if (newestPawn.PlayerReplicationInfo.HasFlag!=None)
  169. 		{
  170. 			Sender.ClientMessage("Not allowed to switch"@NewestPawn.PlayerReplicationInfo.PlayerName@"while the player is holding a flag.");
  171. 			if (debug)
  172. 				log(class@"Failed to switch"@NewestPawn.PlayerReplicationInfo.PlayerName$", FC");
  173. 			return;
  174. 		}
  175.  
  176. 		MovingPawn=NewestPawn;
  177. 		NewestPawn.Died( None, '', NewestPawn.Location );
  178. 		Smallest = 0;
  179.  
  180. 		for( i=1; i<TeamGamePlus(Level.Game).MaxTeams; i++ )
  181. 			if ( Teams[Smallest].Size > Teams[i].Size )
  182. 				Smallest = i;
  183.  
  184. 		if (TeamGamePlus(Level.Game).ChangeTeam(NewestPawn, Smallest))
  185. 			BroadcastMessage(NewestPawn.PlayerReplicationInfo.PlayerName@"was moved to the"@TeamGamePlus(Level.Game).TeamColor[Smallest]@"team.");
  186. 		else BroadcastMessage(NewestPawn.PlayerReplicationInfo.PlayerName@"could not be moved!!!");
  187. 	}
  188. 	else
  189. 	{
  190. 		log(class@"NEWEST PAWN WAS NONE!");
  191. 		Sender.ClientMessage("There was an error balancing the teams.  Please try again in a few seconds.");
  192. 	}
  193. }
  194.  
  195. function int NumPlayers()
  196. {
  197. 	if (debug)
  198. 		log(class@"NumPlayer()::NumPlayers:"$DeathMatchPlus(Level.Game).NumPlayers@"NumBots:"$DeathMatchPlus(Level.Game).NumBots);
  199. 	if (LastManStanding(Level.Game)!=None)
  200. 		return DeathMatchPlus(Level.Game).NumPlayers+DeathMatchPlus(Level.Game).NumBots-LastManStanding(Level.Game).NumGhosts;
  201. 	else return DeathMatchPlus(Level.Game).NumPlayers+DeathMatchPlus(Level.Game).NumBots;
  202. }