UnrealShare
Class CoopGame

source: e:\games\UnrealTournament\UnrealShare\Classes\CoopGame.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Info
         |
         +--Engine.GameInfo
            |
            +--UnrealShare.UnrealGameInfo
               |
               +--UnrealShare.CoopGame
Direct Known Subclasses:None

class CoopGame
extends UnrealShare.UnrealGameInfo

//============================================================================= // CoopGame. //=============================================================================
Variables
 bool bNoFriendlyFire
 bool bSpecialFallDamage


Function Summary
 void AddDefaultInventory(Pawn PlayerPawn)
 NavigationPoint FindPlayerStart(Pawn Player, optional byte, optional string)
 bool IsRelevant(Actor Other)
 void Killed(Pawn killer, Pawn Other, name damageType)
 float PlaySpawnEffect(Inventory Inv)
 void PlayTeleportEffect(Actor Incoming, bool bOut, bool bSound)
 void PostBeginPlay()
 int ReduceDamage(int Damage, name DamageType, Pawn injured, Pawn instigatedBy)
 void SendPlayer(PlayerPawn aPlayer, string URL)
 bool ShouldRespawn(Actor Other)



Source Code


00001	//=============================================================================
00002	// CoopGame.
00003	//=============================================================================
00004	class CoopGame extends UnrealGameInfo;
00005	
00006	var() config bool	bNoFriendlyFire;
00007	var bool	bSpecialFallDamage;
00008	
00009	function PostBeginPlay()
00010	{
00011		Super.PostBeginPlay();
00012	
00013		bClassicDeathMessages = True;
00014	}
00015	
00016	function bool IsRelevant(actor Other)
00017	{
00018		// hide all playerpawns
00019	
00020		if ( Other.IsA('PlayerPawn') && !Other.IsA('Spectator') )
00021		{
00022			Other.SetCollision(false,false,false);
00023			Other.bHidden = true;
00024		}
00025		return Super.IsRelevant(Other);
00026	}
00027	
00028	function float PlaySpawnEffect(inventory Inv)
00029	{
00030		Playsound(sound'RespawnSound');
00031		if ( !bCoopWeaponMode || !Inv.IsA('Weapon') )
00032		{
00033			spawn( class 'ReSpawn',,, Inv.Location );
00034			return 0.3;
00035		}
00036		return 0.0;
00037	}
00038	
00039	event playerpawn Login
00040	(
00041		string Portal,
00042		string Options,
00043		out string Error,
00044		class<playerpawn> SpawnClass
00045	)
00046	{
00047		local PlayerPawn      NewPlayer;
00048		local string          InName, InPassword;
00049		local pawn			  aPawn;
00050	
00051		NewPlayer =  Super.Login(Portal, Options, Error, SpawnClass);
00052		if ( NewPlayer != None )
00053		{
00054			if ( !NewPlayer.IsA('Spectator') )
00055			{
00056				NewPlayer.bHidden = false;
00057				NewPlayer.SetCollision(true,true,true);
00058			}
00059			log("Logging in to "$Level.Title);
00060			if ( Level.Title ~= "The Source Antechamber" )
00061			{
00062				bSpecialFallDamage = true;
00063				log("reduce fall damage");
00064			}
00065		}
00066		return NewPlayer;
00067	}
00068		
00069	function NavigationPoint FindPlayerStart( Pawn Player, optional byte InTeam, optional string incomingName )
00070	{
00071		local PlayerStart Dest, Candidate[8], Best;
00072		local float Score[8], BestScore, NextDist;
00073		local pawn OtherPlayer;
00074		local int i, num;
00075		local Teleporter Tel;
00076	
00077		num = 0;
00078		//choose candidates	
00079		foreach AllActors( class 'PlayerStart', Dest )
00080		{
00081			if ( (Dest.bSinglePlayerStart || Dest.bCoopStart) && !Dest.Region.Zone.bWaterZone )
00082			{
00083				if (num<4)
00084					Candidate[num] = Dest;
00085				else if (Rand(num) < 4)
00086					Candidate[Rand(4)] = Dest;
00087				num++;
00088			}
00089		}
00090		
00091		if (num>4) num = 4;
00092		else if (num == 0)
00093			return None;
00094			
00095		//assess candidates
00096		for (i=0;i<num;i++)
00097			Score[i] = 4000 * FRand(); //randomize
00098			
00099		foreach AllActors( class 'Pawn', OtherPlayer )
00100		{
00101			if (OtherPlayer.bIsPlayer)
00102			{
00103				for (i=0;i<num;i++)
00104				{
00105					NextDist = VSize(OtherPlayer.Location - Candidate[i].Location);
00106					Score[i] += NextDist;
00107					if (NextDist < OtherPlayer.CollisionRadius + OtherPlayer.CollisionHeight)
00108						Score[i] -= 1000000.0;
00109				}
00110			}
00111		}
00112		
00113		BestScore = Score[0];
00114		Best = Candidate[0];
00115		for (i=1;i<num;i++)
00116		{
00117			if (Score[i] > BestScore)
00118			{
00119				BestScore = Score[i];
00120				Best = Candidate[i];
00121			}
00122		}			
00123					
00124		return Best;
00125	}
00126	
00127	function int ReduceDamage(int Damage, name DamageType, pawn injured, pawn instigatedBy)
00128	{
00129		if ( bNoFriendlyFire && (instigatedBy != None) 
00130			&& instigatedBy.bIsPlayer && injured.bIsPlayer && (instigatedBy != injured) )
00131			return 0;
00132	
00133		if ( (DamageType == 'Fell') && bSpecialFallDamage )
00134			return Min(Damage, 5);
00135	
00136		return Super.ReduceDamage(Damage, DamageType, injured, instigatedBy);
00137	}
00138	
00139	function bool ShouldRespawn(Actor Other)
00140	{
00141		if ( Other.IsA('Weapon') && !Weapon(Other).bHeldItem && (Weapon(Other).ReSpawnTime != 0) )
00142		{
00143			Inventory(Other).ReSpawnTime = 1.0;
00144			return true;
00145		}
00146		return false;
00147	}
00148	
00149	function SendPlayer( PlayerPawn aPlayer, string URL )
00150	{
00151		// hack to skip end game in coop play
00152		if ( left(URL,6) ~= "endgame")
00153		{
00154			Level.ServerTravel( "Vortex2", false);
00155			return;
00156		}
00157	
00158		Level.ServerTravel( URL, true );
00159	}
00160	
00161	function PlayTeleportEffect( actor Incoming, bool bOut, bool bSound)
00162	{
00163	}
00164	
00165	function Killed(pawn killer, pawn Other, name damageType)
00166	{
00167		super.Killed(killer, Other, damageType);
00168		if ( (Killer != None) && (Other.bIsPlayer || Other.IsA('Nali')) )
00169			killer.PlayerReplicationInfo.Score -= 2;
00170	}	
00171	
00172	function AddDefaultInventory( pawn PlayerPawn )
00173	{
00174		local Translator newTranslator;
00175	
00176		if ( Level.DefaultGameType != class'VRikersGame' ) 
00177			Super.AddDefaultInventory(PlayerPawn);
00178	
00179		// Spawn translator.
00180		if( PlayerPawn.IsA('Spectator') || PlayerPawn.FindInventoryType(class'Translator') != None )
00181			return;
00182		newTranslator = Spawn(class'Translator',,, Location);
00183		if( newTranslator != None )
00184		{
00185			newTranslator.bHeldItem = true;
00186			newTranslator.GiveTo( PlayerPawn );
00187			PlayerPawn.SelectedItem = newTranslator;
00188			newTranslator.PickupFunction(PlayerPawn);
00189		}
00190	}
00191	
00192	defaultproperties
00193	{
00194	     bNoFriendlyFire=True
00195	     bHumansOnly=True
00196	     bRestartLevel=False
00197	     bPauseable=False
00198	     bCoopWeaponMode=True
00199	     ScoreBoardType=Class'UnrealShare.UnrealScoreBoard'
00200	     GameMenuType=Class'UnrealShare.UnrealCoopGameOptions'
00201	     RulesMenuType="UMenu.UMenuCoopGameRulesSClient"
00202	     SettingsMenuType="UMenu.UMenuCoopGameRulesSClient"
00203	     BeaconName="Coop"
00204	     GameName="Coop Game"
00205	}

End Source Code