## XIIIMP
Class XIIIMPFlag

source: C:\XIII\XIIIMP\Classes\XIIIMPFlag.uc

    Core.Object
       |
       +--Engine.Actor
          |
          +--Engine.Decoration
             |
             +--XIIIMP.XIIIMPFlag

Direct Known Subclasses:XIIIMPRFlag

class XIIIMPFlag
extends Engine.Decoration

    //-----------------------------------------------------------
    //
    //-----------------------------------------------------------

Variables
`XIIIGameReplicationInfo` | `GRI`
`XIIIPawn` | `Holder`
`XIIIPlayerReplicationInfo` | `HolderPRI`
`XIIIMPFlagBase` | `HomeBase`
`TeamInfo` | `Team`
`byte` | `TeamNum`
`bool` | `bHeld`
`bool` | `bHome`

States
Home, Held, Dropped

Function Summary
`void` | `Drop(vector newVel)`
    //_____________________________________________________________________________
`void` | `GiveHarnaisCTFAndFlag(XIIIPawn P)`
    //_____________________________________________________________________________
`void` | `PostBeginPlay()`
    //_____________________________________________________________________________
`void` | `RemoveHarnaisCTFAndFlag(XIIIPawn P)`
    //_____________________________________________________________________________
`void` | `SendHome(optional int)`
    //_____________________________________________________________________________
`void` | `SetHolderLighting()`
    //_____________________________________________________________________________

State Home Function Summary

State Held Function Summary

State Dropped Function Summary
`void` | `Touch(Actor Other)`
    //------------------------------------------
`void` | `PhysicsVolumeChange(PhysicsVolume NewVolume)`
    //------------------------------------------
`void` | `EndState()`
    //------------------------------------------

Source Code

    00001	//-----------------------------------------------------------
    00002	//
    00003	//-----------------------------------------------------------
    00004	class XIIIMPFlag extends Decoration;
    00005
    00006	var TeamInfo Team;
    00007	var byte TeamNum;
    00008	var bool bHome;
    00009	var bool bHeld;
    00010	var XIIIPawn Holder;
    00011	var XIIIPlayerReplicationInfo HolderPRI;
    00012	var XIIIGameReplicationInfo GRI;
    00013	var XIIIMPFlagBase HomeBase;
    00014	//var rotator FlagRotation;
    00015
    00016	//_____________________________________________________________________________
    00017	replication
    00018	{
    00019	    reliable if ( Role == ROLE_Authority )
    00020	      Team, bHome, bHeld;
    00021	}
    00022
    00023	//_____________________________________________________________________________
    00024	function GiveHarnaisCTFAndFlag( XIIIPawn P)
    00025	{
    00026	    local Inventory NewItem;
    00027
    00028	    if( P.FindInventoryType(Class'XIIIMP.BlueHarnaisCTF')==None )
    00029	    {
    00030	        NewItem = Spawn(Class'XIIIMP.BlueHarnaisCTF',,,P.Location);
    00031
    00032	        if( NewItem != None )
    00033	            NewItem.GiveTo(P);
    00034	    }
    00035	}
    00036	//_____________________________________________________________________________
    00037	function RemoveHarnaisCTFAndFlag( XIIIPawn P)
    00038	{
    00039	    local Inventory NewItem;
    00040
    00041	    NewItem = P.FindInventoryType(Class'XIIIMP.HarnaisCTF');
    00042
    00043	    if( NewItem != none )
    00044	        NewItem.Destroy();
    00045
    00046	    NewItem = P.FindInventoryType(Class'XIIIMP.HarnaisCTFAttachment');
    00047
    00048	    if( NewItem !=None )
    00049	        NewItem.Destroy();
    00050
    00051	    NewItem = P.FindInventoryType(Class'XIIIMP.BlueHarnaisCTF');
    00052
    00053	    if( NewItem != none )
    00054	        NewItem.Destroy();
    00055
    00056	    NewItem = P.FindInventoryType(Class'XIIIMP.BlueHarnaisCTFAttachment');
    00057
    00058	    if( NewItem !=None )
    00059	        NewItem.Destroy();
    00060	}
    00061
    00062	//_____________________________________________________________________________
    00063	function PostBeginPlay()
    00064	{
    00065	    Super.PostBeginPlay();
    00066	    log("Flag Game: "$Level.Game);
    00067	    Team = XIIIMPCTFGameInfo(Level.Game).GameReplicationInfo.Teams[TeamNum];
    00068	    Team.Flag = self;
    00069	    LoopAnim('pflag');
    00070	    GRI = XIIIGameReplicationInfo(Level.Game.GameReplicationInfo);
    00071	}
    00072
    00073	//_____________________________________________________________________________
    00074	event FellOutOfWorld()
    00075	{
    00076	    Log("FLAG"@TeamNum@"Returned");
    00077	    if ( TeamNum == 0 )
    00078	      GRI.SoundFlagState0=1;
    00079	    else
    00080	      GRI.SoundFlagState1=1;
    00081	    SendHome();
    00082	}
    00083
    00084	//_____________________________________________________________________________
    00085	function SendHome(optional int iNewSoundState)
    00086	{
    00087	    local Controller aPawn;
    00088
    00089	    if ( Holder != None )
    00090	    {
    00091	      holderPRI.HasFlag = None;
    00092	      if ( Holder.Inventory != None )
    00093	        Holder.Inventory.SetOwnerDisplay();
    00094	      Holder = None;
    00095	    }
    00096	    if ( iNewSoundState != 0 )
    00097	    {
    00098	      if ( TeamNum == 0 )
    00099	        GRI.SoundFlagState0=iNewSoundState;
    00100	      else
    00101	        GRI.SoundFlagState1=iNewSoundState;
    00102	    }
    00103	    GotoState('Home');
    00104	    SetPhysics(PHYS_None);
    00105	    bCollideWorld = false;
    00106	    SetLocation(HomeBase.Location);
    00107	    SetRotation(HomeBase.Rotation);
    00108	    SetBase(None);
    00109	    SetCollision(true,false,false);
    00110	}
    00111
    00112	//_____________________________________________________________________________
    00113
    00114	function Drop(vector newVel)
    00115	{
    00116	    Log("FLAG"@TeamNum@"Drop by "$Holder@"PRI="$HolderPRI);
    00117	    if( HolderPRI != none )
    00118	    {
    00119	//        GRI.SoundFlagState[TeamNum]=2;
    00120	        if ( TeamNum == 0 )
    00121	          GRI.SoundFlagState0=2;
    00122	        else
    00123	          GRI.SoundFlagState1=2;
    00124	        BroadcastLocalizedMessage( class'XIIIMPCTFMessage', 2, HolderPRI, None, Team );
    00125
    00126	        if (Level.Game.StatLog != None)
    00127	          Level.Game.StatLog.LogSpecialEvent("flag_dropped", HolderPRI.PlayerID, Team.TeamIndex);
    00128
    00129	        HolderPRI.HasFlag = None;
    00130	    }
    00131
    00132	    LightType = LT_Steady;
    00133	    RefreshLighting();
    00134
    00135	//    if ( Holder.Inventory != None )
    00136	//      Holder.Inventory.SetOwnerDisplay();
    00137
    00138	    Holder = None;
    00139	    HolderPRI = none;
    00140
    00141	    bCollideWorld = true;
    00142	    SetPhysics(PHYS_Falling);
    00143	    SetBase(None);
    00144	    SetCollision(true, false, false);
    00145
    00146	    GotoState('Dropped');
    00147	}
    00148
    00149	//_____________________________________________________________________________
    00150
    00151	function SetHolderLighting()
    00152	{
    00153	    Holder.AmbientGlow = 254;
    00154	    Holder.LightEffect=LE_NonIncidence;
    00155	    Holder.LightBrightness=255;
    00156	    Holder.LightHue=LightHue;
    00157	    Holder.LightRadius=6;
    00158	    Holder.LightSaturation=LightSaturation;
    00159	    Holder.LightType=LT_Steady;
    00160	    Holder.RefreshLighting();
    00161	}
    00162
    00163	//_____________________________________________________________________________
    00164	//                                DROPPED
    00165	//_____________________________________________________________________________
    00166
    00167
    00168	state Dropped
    00169	{
    00170	    event BeginState()
    00171	    {
    00172	        SetTimer2( 15.0, true);
    00173	        bCollideWorld = true;
    00174	        //PlayMenu(sndFlagDropped);
    00175	    }
    00176
    00177	    //------------------------------------------
    00178
    00179	    function EndState()
    00180	    {
    00181	        SetTimer2( 0.0, false);
    00182	    }
    00183
    00184	    //------------------------------------------
    00185
    00186	    event Timer2()
    00187	    {
    00188	        BroadcastLocalizedMessage( class'XIIIMPCTFMessage', 3, None, None, Team );
    00189
    00190	        if (Level.Game.StatLog != None)
    00191	            Level.Game.StatLog.LogSpecialEvent("flag_returned_timeout", Team.TeamIndex);
    00192
    00193	        Log("FLAG"@TeamNum@"Returned");
    00194	//        GRI.SoundFlagState[TeamNum]=1;
    00195	        if ( TeamNum == 0 )
    00196	          GRI.SoundFlagState0=1;
    00197	        else
    00198	          GRI.SoundFlagState1=1;
    00199	        SendHome();
    00200	    }
    00201
    00202	    //------------------------------------------
    00203
    00204	    function TakeDamage( int NDamage, Pawn instigatedBy, Vector hitlocation,Vector momentum, class<DamageType> damageType)
    00205	    {
    00206	      if ( PhysicsVolume.bPainCausing && (PhysicsVolume.DamagePerSec > 0) )
    00207	        timer2();
    00208	    }
    00209
    00210	    //------------------------------------------
    00211
    00212	    singular function PhysicsVolumeChange( PhysicsVolume NewVolume )
    00213	    {
    00214	      Super.PhysicsVolumeChange(NewVolume);
    00215
    00216	      if ( NewVolume.bPainCausing && (NewVolume.DamagePerSec > 0) )
    00217	        timer2();
    00218	    }
    00219
    00220	    //------------------------------------------
    00221
    00222	    function Touch(Actor Other)
    00223	    {
    00224	        local XIIIMPFlag aFlag;
    00225	        local XIIIPawn aPawn;
    00226	        local Controller C;
    00227	        local NavigationPoint N;
    00228	        local int num, i;
    00229
    00230	        aPawn = XIIIPawn(Other);
    00231
    00232	        if ( aPawn == None )
    00233	            return;
    00234
    00235	        C = aPawn.Controller;
    00236
    00237
if( C == none ) 00238 return; 00239 00240 if( ! C.bIsPlayer ) 00241 return; 00242 00243 C.MoveTimer = -1; 00244 00245 if ( C.PlayerReplicationInfo.Team == Team ) 00246 { 00247 //log("-----flag has returned"); 00248 //PlayMenu(sndFlagReturn); 00249 Log("FLAG"@TeamNum@"Returned"); 00250 // GRI.SoundFlagState[TeamNum]=1; 00251 if ( TeamNum == 0 ) 00252 GRI.SoundFlagState0=1; 00253 else 00254 GRI.SoundFlagState1=1; 00255 XIIIMPCTFGameInfo(Level.Game).ScoreFlag(C, self); 00256 SendHome(); 00257 00258 return; 00259 } 00260 else 00261 { 00262 //log("-----flag taken from dropped"); 00263 00264 Holder = aPawn; 00265 HolderPRI = XIIIPlayerReplicationInfo(aPawn.PlayerReplicationInfo); 00266 C.PlayerReplicationInfo.HasFlag = self; 00267 C.SendMessage(None, 'OTHER', 2, 10, 'TEAM'); 00268 } 00269 00270 BroadcastLocalizedMessage( class'XIIIMPCTFMessage', 4, C.PlayerReplicationInfo, None, Team ); 00271 00272 if (Level.Game.StatLog != None) 00273 Level.Game.StatLog.LogSpecialEvent("flag_pickedup", C.PlayerReplicationInfo.PlayerID, Team.TeamIndex); 00274 00275 GotoState('Held'); 00276 } 00277 00278 begin: 00279 00280 if ( PhysicsVolume.bPainCausing && (PhysicsVolume.DamagePerSec > 0) ) 00281 timer2(); 00282 } 00283 00284 00285 //_____________________________________________________________________________ 00286 // HELD 00287 //_____________________________________________________________________________ 00288 00289 00290 state Held 00291 { 00292 event FellOutOfWorld(); 00293 00294 //------------------------------------------ 00295 00296 event BeginState() 00297 { 00298 local TeamBotController Bot; 00299 00300 bHeld = true; 00301 00302 bCollideWorld = false; 00303 HomeBase.PlayAlarm(); 00304 SetPhysics(PHYS_None); 00305 SetCollision(false, false, false); 00306 SetDrawType(DT_None); 00307 00308 if( CTFBotController( Holder.Controller ) != none ) 00309 CTFBotController( Holder.Controller ).CatchFlag(); 00310 else 00311 { 00312 foreach DynamicActors(class'TeamBotController', BOT) 00313 { 00314 if( Bot.TeamID == Holder.Controller.PlayerReplicationInfo.Team.TeamIndex ) 00315 { 00316 CTFBotController( BOT ).ForceTheBotToHelpTheHumanFlagHolder(); 00317 } 00318 } 00319 } 00320 00321 Log("FLAG"@TeamNum@"Held BeginState"); 00322 // GRI.SoundFlagState[TeamNum]=4; 00323 if ( TeamNum == 0 ) 00324 GRI.SoundFlagState0=4; 00325 else 00326 GRI.SoundFlagState1=4; 00327 00328 GiveHarnaisCTFAndFlag( Holder ); 00329 } 00330 00331 //------------------------------------------ 00332 00333 event EndState() 00334 { 00335 SetDrawType(DT_StaticMesh); 00336 bHeld = false; 00337 } 00338 00339 //------------------------------------------ 00340 00341 event Tick(float DeltaTime) 00342 { 00343 if ( Holder != none ) 00344 { 00345 if( Holder.bIsDead ) 00346 { 00347 RemoveHarnaisCTFAndFlag( Holder ); 00348 Drop(Holder.Location); 00349 } 00350 else 00351 SetLocation(Holder.Location); 00352 } 00353 else 00354 { 00355 RemoveHarnaisCTFAndFlag( Holder ); 00356 Drop(Holder.Location); 00357 } 00358 } 00359 00360 //------------------------------------------ 00361 } 00362 00363 //_____________________________________________________________________________ 00364 // 00365 auto state Home 00366 { 00367 event BeginState() 00368 { 00369 //log("!!!! BeginState HOME"); 00370 bHome = true; 00371 bCollideWorld = false; 00372 if ( HomeBase != None ) // will be none when flag is created 00373 HomeBase.AmbientSound = None; 00374 00375 SetCollisionSize(Default.CollisionRadius, Default.CollisionHeight); 00376 } 00377 event EndState() 00378 { 00379 bHome = false; 00380 //SetTimer(0.0, false); 00381 } 00382 event Touch(Actor Other) 00383 { 00384 local XIIIMPFlag aFlag; 00385 local XIIIPawn aPawn; 00386 local NavigationPoint N; 00387 local int i; 00388 local float totalweight, selection, PartialWeight; 00389 local Controller C; 00390 00391 aPawn = XIIIPawn(Other); 00392 00393 if ( aPawn == None ) 00394 return; 00395 00396 C = aPawn.Controller; 00397 00398 if( C == none ) 00399 return; 00400 00401 if( ! C.bIsPlayer ) 00402 return; 00403 00404 if ( C.PlayerReplicationInfo.Team == Team ) 00405 { 00406 if ( C.PlayerReplicationInfo.HasFlag != None ) 00407 { 00408 Log("FLAG"@TeamNum@"Score"); 00409 GRI.SoundFlagState0=3; // need to put both to update states ok. 00410 GRI.SoundFlagState1=3; 00411 RemoveHarnaisCTFAndFlag( aPawn ); 00412 aFlag = XIIIMPFlag(C.PlayerReplicationInfo.HasFlag); 00413 XIIIMPCTFGameInfo(Level.Game).ScoreFlag(C, aFlag); 00414 aFlag.SendHome(); 00415 } 00416 } 00417 else 00418 { 00419 Holder = aPawn; 00420 HolderPRI = XIIIPlayerReplicationInfo(aPawn.PlayerReplicationInfo); 00421 C.MoveTimer = -1; 00422 C.PlayerReplicationInfo.HasFlag = self; 00423 Holder.MakeNoise(2.0); 00424 C.SendMessage(None, 'OTHER', 2, 10, 'TEAM'); 00425 if (Level.Game.StatLog != None) 00426 Level.Game.StatLog.LogSpecialEvent("flag_taken", HolderPRI.PlayerID, Team.TeamIndex); 00427 BroadcastLocalizedMessage( class'XIIIMPCTFMessage', 6, holderPRI, None, Team ); 00428 GotoState('Held'); 00429 } 00430 } 00431 begin: 00432 // FlagRotation.Roll = 32768+16380; 00433 SetRotation(rotation - rot(0,0,1)*(Rotation.Roll - 32768 - 16380)); 00434 } 00435 00436 00437 defaultproperties 00438 { 00439 TeamNum=1 00440 bStatic=False 00441 bStasis=False 00442 bAlwaysRelevant=True 00443 bUnlit=True 00444 bCollideActors=True 00445 bCollideWorld=True 00446 bUseCylinderCollision=True 00447 bFixedRotationDir=True 00448 DrawType=DT_StaticMesh 00449 StaticMesh=StaticMesh'Meshes_communs.flagblue' 00450 CollisionRadius=70.000000 00451 CollisionHeight=30.000000 00452 LightType=LT_Steady 00453 LightEffect=LE_NonIncidence 00454 LightBrightness=255 00455 LightHue=170 00456 LightRadius=6 00457 Mass=30.000000 00458 Buoyancy=20.000000 00459 RotationRate=(Pitch=30000,Roll=30000) 00460 NetPriority=3.000000 00461 }

End Source Code