home *** CD-ROM | disk | FTP | other *** search
/ Game Level Design / GLDesign.bin / Software / UnrealEngine2Runtime / UE2Runtime-22262001_Demo.exe / Engine / Classes / PlayerReplicationInfo.uc < prev    next >
Text File  |  2003-06-23  |  6KB  |  236 lines

  1. //=============================================================================
  2. // PlayerReplicationInfo.
  3. //=============================================================================
  4. class PlayerReplicationInfo extends ReplicationInfo
  5.     native nativereplication;
  6.  
  7. var float                Score;            // Player's current score.
  8. var float                Deaths;            // Number of player's deaths.
  9. var CarriedObject        HasFlag;
  10. var int                    Ping;                // packet loss packed into this property as well
  11. var Volume                PlayerVolume;
  12. var ZoneInfo            PlayerZone;
  13. var int                    NumLives;
  14.  
  15. var string                PlayerName;        // Player name, or blank if none.
  16. var string                CharacterName, OldCharacterName;
  17. var string                OldName, PreviousName;        // Temporary value.
  18. var int                    PlayerID;        // Unique id number.
  19. var TeamInfo            Team;            // Player Team
  20. var int                    TeamID;            // Player position in team.
  21. var class<VoicePack>    VoiceType;
  22. var bool                bAdmin;                // Player logged in as Administrator
  23. var bool                bIsFemale;
  24. var bool                bIsSpectator;
  25. var bool                bOnlySpectator;
  26. var bool                bWaitingPlayer;
  27. var bool                bReadyToPlay;
  28. var bool                bOutOfLives;
  29. var bool                bBot;
  30. var bool                bWelcomed;            // set after welcome message broadcast (not replicated)
  31. var bool                bReceivedPing;            
  32. var bool                bHasFlag;            
  33.  
  34. // Time elapsed.
  35. var int                    StartTime;
  36.  
  37. var localized String    StringDead;
  38. var localized String    StringSpectating;
  39. var localized String    StringUnknown;
  40.  
  41. var int                    GoalsScored;        // not replicated - used on server side only
  42. var int                    Kills;                // not replicated
  43.                  
  44. replication
  45. {
  46.     // Things the server should send to the client.
  47.     reliable if ( bNetDirty && (Role == Role_Authority) )
  48.         Score, Deaths, bHasFlag, PlayerVolume, PlayerZone,
  49.         PlayerName, Team, TeamID, VoiceType, bIsFemale, bAdmin, 
  50.         bIsSpectator, bOnlySpectator, bWaitingPlayer, bReadyToPlay,
  51.         bOutOfLives, CharacterName;
  52.     reliable if ( bNetDirty && (!bNetOwner || bDemoRecording) && (Role == Role_Authority) )
  53.         Ping; 
  54.     reliable if ( bNetInitial && (Role == Role_Authority) )
  55.         StartTime, bBot;
  56. }
  57.  
  58. function PostBeginPlay()
  59. {
  60.     if ( Role < ROLE_Authority )
  61.         return;
  62.     if (AIController(Owner) != None)
  63.         bBot = true;
  64.     StartTime = Level.Game.GameReplicationInfo.ElapsedTime;
  65.     Timer();
  66.     SetTimer(1.5 + FRand(), true);
  67. }
  68.  
  69. simulated function PostNetBeginPlay()
  70. {
  71.     local GameReplicationInfo GRI;
  72.     
  73.     ForEach DynamicActors(class'GameReplicationInfo',GRI)
  74.     {
  75.         GRI.AddPRI(self);
  76.         break;
  77.     }
  78. }
  79.  
  80. simulated function Destroyed()
  81. {
  82.     local GameReplicationInfo GRI;
  83.     
  84.     ForEach DynamicActors(class'GameReplicationInfo',GRI)
  85.         GRI.RemovePRI(self);
  86.         
  87.     Super.Destroyed();
  88. }
  89.     
  90. function SetCharacterName(string S)
  91. {
  92.     CharacterName = S;
  93. }
  94.  
  95. /* Reset() 
  96. reset actor to initial state - used when restarting level without reloading.
  97. */
  98. function Reset()
  99. {
  100.     Super.Reset();
  101.     Score = 0;
  102.     Deaths = 0;
  103.     SetFlag(None);
  104.     bReadyToPlay = false;
  105.     NumLives = 0;
  106.     bOutOfLives = false;
  107. }
  108.  
  109. function SetFlag(CarriedObject NewFlag)
  110. {
  111.     HasFlag = NewFlag;
  112.     bHasFlag = (HasFlag != None);
  113. }
  114.  
  115. simulated function string GetHumanReadableName()
  116. {
  117.     return PlayerName;
  118. }
  119.  
  120. simulated function string GetLocationName()
  121. {
  122.     if( ( PlayerVolume == None ) && ( PlayerZone == None ) )
  123.     {
  124.         if ( (Owner != None) && Controller(Owner).IsInState('Dead') )
  125.             return StringDead;
  126.         else
  127.         return StringSpectating;
  128.     }
  129.     
  130.     if( ( PlayerVolume != None ) && ( PlayerVolume.LocationName != class'Volume'.Default.LocationName ) )
  131.         return PlayerVolume.LocationName;
  132.     else if( PlayerZone != None && ( PlayerZone.LocationName != "" )  )
  133.         return PlayerZone.LocationName;
  134.     else if ( Level.Title != Level.Default.Title )
  135.         return Level.Title;
  136.     else
  137.         return StringUnknown;
  138. }
  139.  
  140. simulated function material GetPortrait();
  141. event UpdateCharacter();
  142.  
  143. function UpdatePlayerLocation()
  144. {
  145.     local Volume V, Best;
  146.     local Pawn P;
  147.     local Controller C;
  148.  
  149.     C = Controller(Owner);
  150.  
  151.     if( C != None )
  152.         P = C.Pawn;
  153.     
  154.     if( P == None )
  155.         {
  156.         PlayerVolume = None;
  157.         PlayerZone = None;
  158.         return;
  159.     }
  160.     
  161.     if ( PlayerZone != P.Region.Zone )
  162.         PlayerZone = P.Region.Zone;
  163.  
  164.     foreach P.TouchingActors( class'Volume', V )
  165.     {
  166.         if( V.LocationName == "") 
  167.             continue;
  168.         
  169.         if( (Best != None) && (V.LocationPriority <= Best.LocationPriority) )
  170.             continue;
  171.             
  172.         if( V.Encompasses(P) )
  173.             Best = V;
  174.         }
  175.     if ( PlayerVolume != Best )
  176.         PlayerVolume = Best;
  177. }
  178.  
  179. /* DisplayDebug()
  180. list important controller attributes on canvas
  181. */
  182. simulated function DisplayDebug(Canvas Canvas, out float YL, out float YPos)
  183. {
  184.     if ( Team != None )
  185.         Canvas.DrawText("     PlayerName "$PlayerName$" Team "$Team.GetHumanReadableName()$" has flag "$HasFlag);
  186.     else
  187.         Canvas.DrawText("     PlayerName "$PlayerName$" NO Team");
  188. }
  189.                      
  190. event ClientNameChange()
  191. {
  192.     local PlayerController PC;
  193.  
  194.     ForEach DynamicActors(class'PlayerController', PC)
  195.         PC.ReceiveLocalizedMessage( class'GameMessage', 2, self );          
  196. }
  197.  
  198. function Timer()
  199. {
  200.     local Controller C;
  201.  
  202.     UpdatePlayerLocation();
  203.     SetTimer(1.5 + FRand(), true);
  204.     if( FRand() < 0.65 )
  205.         return;
  206.  
  207.     if( !bBot )
  208.     {
  209.         C = Controller(Owner);
  210.         if ( !bReceivedPing )
  211.             Ping = int(C.ConsoleCommand("GETPING"));
  212.     }
  213. }
  214.  
  215. function SetPlayerName(string S)
  216. {
  217.     OldName = PlayerName;
  218.     PlayerName = S;
  219. }
  220.  
  221. function SetWaitingPlayer(bool B)
  222. {
  223.     bIsSpectator = B;    
  224.     bWaitingPlayer = B;
  225. }
  226.  
  227. defaultproperties
  228. {
  229.     RemoteRole=ROLE_SimulatedProxy
  230.     bAlwaysRelevant=True
  231.     StringSpectating="Spectating"
  232.     StringUnknown="Unknown"
  233.     StringDead="Dead"
  234.     NetUpdateFrequency=5
  235. }
  236.