Advertisement
poosh

TSCBaseGuardian

Nov 9th, 2014
578
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class TSCBaseGuardian extends TSCTeamBase;
  2.  
  3. var UnrealTeamInfo Team;
  4. var int Damage; // damage per seconds that Base Guardian does to enemies
  5. var int SameTeamCounter; // if nobody of team members are at the base longer than this value, base will be lost
  6.  
  7. var TSCGameReplicationInfo TSCGRI;
  8.  
  9. var localized string strUseMessage;
  10. var localized string strUsedMessage;
  11. var localized string strCarryHintMessage;
  12. var localized string strITookTheGnome;
  13. var transient float LastTouchTime;
  14.  
  15. replication
  16. {
  17.     reliable if (bNetDirty && Role == ROLE_Authority)
  18.         Team;
  19. }
  20.  
  21. simulated function PostBeginPlay()
  22. {
  23.     TSCGRI = TSCGameReplicationInfo(Level.GRI);    
  24.     //log("TSCGRI = " $ TSCGRI, 'TSCBaseGuardian');
  25.  
  26.     super.PostBeginPlay();
  27. }
  28.  
  29. simulated function PostNetReceive()
  30. {
  31.     if ( Role < ROLE_Authority ) {
  32.         if ( bHeld && Base != none ) {
  33.             // lame replication fix
  34.             SetRelativeLocation(GameObjOffset);
  35.             SetRelativeRotation(GameObjRot);
  36.         }
  37.     }
  38. }
  39.  
  40.  
  41.  
  42. function UsedBy( Pawn user )
  43. {
  44.     if (!ValidHolder(user))
  45.         return;
  46.  
  47.     SetHolder(user.Controller);
  48. }
  49.  
  50. function SetHolder(Controller C)
  51. {
  52.     local PlayerController PC;
  53.    
  54.     super.SetHolder(C);
  55.    
  56.     PC = PlayerController(C);
  57.     if ( PC != none) {
  58.         //PC.ClientMessage(class'TSCGame'.static.ParseLoadingHintNoColor(strCarryHintMessage, PC));
  59.         PC.ClientMessage(strUsedMessage, 'CriticalEvent');
  60.         PC.TeamSay(strITookTheGnome);
  61.     }
  62. }
  63.  
  64. simulated function vector GetLocation()
  65. {
  66.     if ( bHeld ) {
  67.         if ( Base != none && !Base.bWorldGeometry )
  68.             return Base.Location;
  69.         else if ( HolderPRI != none && Controller(HolderPRI.Owner).Pawn != none )
  70.             return Controller(HolderPRI.Owner).Pawn.Location;
  71.     }
  72.        
  73.     return Location;
  74. }
  75.  
  76.  
  77. singular function Touch(Actor Other)
  78. {
  79.     if (!ValidHolder(Other))
  80.         return;
  81.        
  82.     if ( Pawn(Other) != none && PlayerController(Pawn(Other).Controller) != none) {
  83.         if ( Level.TimeSeconds - LastTouchTime > 1 )
  84.             PlayerController(Pawn(Other).controller).ClientMessage(strUseMessage, 'CriticalEvent');
  85.         LastTouchTime = Level.TimeSeconds;
  86.     }
  87. }
  88.  
  89.  
  90. function bool SameTeam(Controller c)
  91. {
  92.     if ( c == None || c.PlayerReplicationInfo == none || c.PlayerReplicationInfo.Team != Team )
  93.         return false;
  94.  
  95.     return true;
  96. }
  97.  
  98.  
  99. function bool ValidHolder(Actor Other)
  100. {
  101.     local Pawn p;
  102.  
  103.     if( bDisabled || bActive || bHome || bHeld )
  104.         return false;  
  105.  
  106.     p = Pawn(other);      
  107.     if ( p == None || p.Health <= 0 || !p.bCanPickupInventory || !p.IsPlayerPawn() )
  108.         return false;    
  109.        
  110.     if ( !SameTeam(p.Controller) )
  111.         return false;
  112.        
  113.     if ( TSCGRI.TeamCarrier[Team.TeamIndex] != none ) {
  114.         if ( TSCGRI.TeamCarrier[Team.TeamIndex].Team != Team )
  115.             TSCGRI.TeamCarrier[Team.TeamIndex] = none; // carrier changed team
  116.         else
  117.             return p.PlayerReplicationInfo == TSCGRI.TeamCarrier[Team.TeamIndex]
  118.                 || p.PlayerReplicationInfo == TSCGRI.TeamCaptain[Team.TeamIndex];
  119.     }
  120.  
  121.     return true;
  122. }
  123.  
  124. function bool ValidPlaceForBase(Vector BaseLocation)
  125. {
  126.     return !TSCGRI.AtBase(BaseLocation, TSCGRI.Teams[1-Team.TeamIndex].HomeBase);
  127. }
  128.  
  129. // Score() is used for setting up base
  130. function Score()
  131. {
  132.     local vector CheckLoc;
  133.    
  134.     if ( bDisabled || bActive )
  135.         return;
  136.    
  137.     CheckLoc = Location;
  138.     if ( !ValidPlaceForBase(CheckLoc) )
  139.         return;
  140.     // check for Z difference to prevent vertical intersection
  141.     CheckLoc.Z += TSCGRI.MaxBaseZ + TSCGRI.MinBaseZ;
  142.     if ( !ValidPlaceForBase(CheckLoc) ) {
  143.         if ( Holder != none && PlayerController(Holder.Controller) != none )
  144.             PlayerController(Holder.Controller).ReceiveLocalizedMessage(class'TSCMessages', 210);
  145.         return;
  146.     }
  147.        
  148.     GotoState('SettingUp');
  149. }
  150.  
  151. function MoveToShop(ShopVolume Shop)
  152. {
  153.     local int i;
  154.  
  155.     if ( !Shop.bTelsInit )
  156.         Shop.InitTeleports();
  157.        
  158.     if ( Shop.TelList.Length == 1 ) {
  159.         // from stupid maps with only 1 player teleport per trader
  160.         if ( Shop.TelList[0].Accept(self, Shop) ) {
  161.             GotoState('Dropped');
  162.             return;
  163.         }
  164.     }
  165.     else {
  166.         for ( i=Team.TeamIndex; i<Shop.TelList.Length; ++i ) {
  167.             if ( Shop.TelList[i].Accept(self, Shop) ) {
  168.                 GotoState('Dropped');
  169.                 return;
  170.             }
  171.         }
  172.     }
  173.    
  174.     // foreach AllActors(class'LevelDesigner', LD)
  175.         // if ( LD.MadeThisMap() )
  176.             // LD.CutHisBallsOffAndFeedToZeds();
  177.    
  178.     // if none of teleporters can accept us, just give me to the closest team member
  179.     GiveToClosestPlayer(Shop.Location);
  180. }
  181.  
  182. function GiveToClosestPlayer(vector Loc)
  183. {
  184.     local Controller C, Best;
  185.     local float BestDistSqr;
  186.  
  187.     for ( C = Level.ControllerList; C != none; C = C.nextController ) {
  188.         if ( C.bIsPlayer && C.Pawn != none && ValidHolder(C.Pawn) ) {
  189.             if ( Best == none || VSizeSquared(C.Pawn.Location - Loc) < BestDistSqr )
  190.                 Best = C;
  191.         }
  192.     }
  193.     if ( Best != none ) {
  194.         GotoState('Dropped');
  195.         SetHolder(Best);
  196.     }    
  197. }
  198.  
  199. function SuddenDeathWipe()
  200. {
  201.     local TSCGame game;
  202.    
  203.     game = TSCGame(Level.Game);
  204.     if ( TSCGRI.bSuddenDeath && game != none && game.bWaveInProgress && (game.TotalMaxMonsters > 0 || game.NumMonsters >= 10) )
  205.         game.WipeTeam(Team);
  206. }
  207.    
  208. auto state Home
  209. {
  210.     function BeginState()
  211.     {
  212.         Disable('Touch');
  213.         SetCollision(false, false);
  214.         bCollideWorld=false;        
  215.         bHome = true;
  216.         bHidden = true;
  217.         LightType = LT_None;
  218.     }
  219.    
  220.     function EndState()
  221.     {
  222.         bHome = false;
  223.         bHidden = false;
  224.         TakenTime = Level.TimeSeconds;
  225.     }
  226.    
  227.     function CheckTouching() {}
  228. }
  229.  
  230. state Dropped
  231. {
  232.     function BeginState()
  233.     {
  234.         SetCollision(true, false);
  235.         bCollideWorld=True;
  236.         bHidden = false;
  237.         LightType = LT_Pulse;
  238.         Enable('Touch');
  239.        
  240.         super.BeginState();
  241.     }
  242. }
  243.  
  244. state Held
  245. {
  246.     function BeginState()
  247.     {
  248.         super.BeginState();
  249.         Holder.bAlwaysRelevant = true;
  250.     }
  251.    
  252.     function EndState()
  253.     {
  254.         if ( Holder != none )
  255.             Holder.bAlwaysRelevant = false;
  256.         super.EndState();
  257.     }
  258.  
  259.     function SendHome() // unignore
  260.     {
  261.         global.SendHome();
  262.     }
  263. }
  264.  
  265.  
  266. state SettingUp
  267. {
  268.     ignores Score, Touch, UsedBy;
  269.    
  270.     function BeginState()
  271.     {
  272.         bActive = true;
  273.         Disable('Touch');
  274.  
  275.         SetCollision(true, false);
  276.         bCollideWorld=true;        
  277.         SetPhysics(PHYS_Falling);
  278.        
  279.         LightType = LT_Pulse;
  280.  
  281.         SetTimer(10, false); // just in case
  282.        
  283.         NetUpdateTime = Level.TimeSeconds - 1; // replicate immediately
  284.     }
  285.    
  286.     function EndState()
  287.     {
  288.         bActive = false;
  289.         SetTimer(0, false);
  290.     }    
  291.    
  292.     event Landed( vector HitNormal )
  293.     {
  294.         local rotator r;
  295.        
  296.         r = Rotation;
  297.         r.Pitch = 0;
  298.         r.Roll = 0;
  299.         SetRotation(r);
  300.         SetPhysics(PHYS_Rotating);
  301.         SetTimer(5, false); // activate the base in 5 seconds
  302.     }
  303.  
  304.    
  305.     function Timer()
  306.     {
  307.         GotoState('Guarding');
  308.     }
  309. }
  310.  
  311. state Guarding
  312. {
  313.     ignores Score;
  314.    
  315.     function BeginState()
  316.     {
  317.         local rotator r;
  318.        
  319.         bActive = true;
  320.         Disable('Touch');
  321.  
  322.         SetCollision(false, false);
  323.         bCollideWorld=false;
  324.         r = Rotation;
  325.         r.Pitch = 0;
  326.         r.Roll = 0;
  327.         SetRotation(r);        
  328.         SetPhysics(PHYS_Rotating);
  329.        
  330.         LightType = LT_Steady;
  331.        
  332.         SameTeamCounter = default.SameTeamCounter;
  333.         SetTimer(1, true);
  334.  
  335.         BroadcastLocalizedMessage(class'TSCMessages', 1+Team.TeamIndex*100);
  336.     }
  337.    
  338.     function EndState()
  339.     {
  340.         bActive = false;
  341.         SetTimer(0, false);
  342.     }
  343.    
  344.     function Timer()
  345.     {
  346.         local Controller C;
  347.         local bool bNobodyAtBase, bNobodyAlive;
  348.        
  349.         bNobodyAtBase = true;
  350.         bNobodyAlive = true;
  351.         for ( C = Level.ControllerList; C != none; C = C.nextController ) {
  352.             if ( C.bIsPlayer && C.Pawn != none && C.Pawn.Health > 0
  353.                     && C.PlayerReplicationInfo != none )
  354.             {
  355.                 if ( C.PlayerReplicationInfo.Team != Team && TSCGRI.AtBase(C.Pawn.Location, self) ) {
  356.                     C.Pawn.TakeDamage(Damage, none, C.Pawn.Location, vect(0,0,0), class'DamTypeEnemyBase');
  357.                     if ( PlayerController(C) != none && ScrnHumanPawn(C.Pawn) != none
  358.                             && ScrnHumanPawn(C.Pawn).NextEnemyBaseDamageMsg < Level.TimeSeconds )
  359.                     {
  360.                         PlayerController(C).ReceiveLocalizedMessage(class'TSCMessages', 212);
  361.                         ScrnHumanPawn(C.Pawn).NextEnemyBaseDamageMsg = Level.TimeSeconds + 6.0;
  362.                     }
  363.                 }
  364.                 else if ( bNobodyAtBase && C.PlayerReplicationInfo.Team == Team ) {
  365.                     bNobodyAlive = false;
  366.                     if ( TSCGRI.AtBase(C.Pawn.Location, self) )
  367.                         bNobodyAtBase = false;
  368.                 }
  369.             }
  370.         }
  371.         if ( bNobodyAtBase ) {
  372.             if ( bNobodyAlive || --SameTeamCounter <= 0 ) {
  373.                 BroadcastLocalizedMessage(class'TSCMessages', 2+Team.TeamIndex*100);
  374.                 SendHome();
  375.                 // if some of team members are still alive while the base
  376.                 // is lost during Sudden Death - kill them
  377.                 //if ( TSCGRI.bSuddenDeath && !bNobodyAlive )
  378.                 //    SuddenDeathWipe();
  379.             }
  380.             else if ( SameTeamCounter % 3 == 0 ) {
  381.                 for ( C = Level.ControllerList; C != none; C = C.nextController ) {
  382.                     if ( C.bIsPlayer && C.PlayerReplicationInfo != none
  383.                             && PlayerController(C) != none    
  384.                             && C.Pawn != none && C.Pawn.Health > 0
  385.                             && C.PlayerReplicationInfo.Team == Team )
  386.                     {
  387.                         PlayerController(C).ReceiveLocalizedMessage(class'TSCMessages', 211);
  388.                     }
  389.                 }              
  390.             }
  391.         }
  392.         else {
  393.             SameTeamCounter = default.SameTeamCounter;
  394.         }
  395.     }
  396. }
  397.  
  398. defaultproperties
  399. {
  400.     strUseMessage="Press USE to take the Base Guardian"
  401.     strUsedMessage="You took the Base Guardian"
  402.     strCarryHintMessage="Carry the Base Guarding to the place where you want to set up the base and press %AltFire% key"
  403.     strITookTheGnome="I took our Base Guardian (Gnome)"
  404.     MaxDropTime=0
  405.     GameObjBone="CHR_Spine3"
  406.     GameObjOffset=(X=0,Y=15,Z=0)
  407.     GameObjRot=(Pitch=-16384,Yaw=0,Roll=0)
  408.     Damage=5
  409.     SameTeamCounter=10
  410.     bCanBeDamaged=False
  411.  
  412.     LightType=LT_Steady
  413.     LightEffect=LE_QuadraticNonIncidence
  414.     LightRadius=25
  415.     LightSaturation=128
  416.     LightBrightness=150 // 220
  417.     LightPeriod=30
  418.     bStatic=False
  419.     bHidden=True
  420.     bDynamicLight=True
  421.     bStasis=False
  422.     NetPriority=3.000000
  423.     bUnlit=True
  424.  
  425.     bCollideActors=False
  426.     bCollideWorld=False
  427.     CollisionRadius=15
  428.     CollisionHeight=12
  429.     bUseCylinderCollision=True
  430.     bFixedRotationDir=True
  431.     Mass=30.000000
  432.     Buoyancy=20.000000
  433.     RotationRate=(Yaw=25000)
  434.     MessageClass=Class'UnrealGame.CTFMessage'
  435.  
  436.     Style=STY_Normal
  437.     DrawType=DT_StaticMesh
  438.     StaticMesh=StaticMesh'HillbillyHorror_SM.GardenGnome'
  439.     DrawScale=1.0
  440.    
  441.     // fucking replication
  442.     bAlwaysRelevant=true
  443.     bNetNotify=true
  444.     /*
  445.     bReplicateMovement=true
  446.     bSkipActorPropertyReplication=false
  447.     RemoteRole=Role_SimulatedProxy
  448.     */
  449. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement