Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

Engine.Inventory


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710
//=============================================================================
// The inventory class, the parent class of all objects which can be
// picked up and carried by actors.
//=============================================================================
class Inventory expands Actor
    abstract
    intrinsic;

#exec Texture Import File=Textures\Inventry.pcx Name=S_Inventory Mips=Off Flags=2

//-----------------------------------------------------------------------------
// Information relevant to Active/Inactive state.

var() travel byte AutoSwitchPriority; // Autoswitch value, 0=never autoswitch.
var() byte        InventoryGroup;     // The weapon/inventory set, 1-9 (0=none).
var() bool        bActivatable;       // Whether item can be activated.
var() bool        bDisplayableInv;    // Item displayed in HUD.
var travel bool   bActive;            // Whether item is currently activated.
var   bool        bSleepTouch;        // Set when item is touched when leaving sleep state.
var   bool        bHeldItem;          // Set once an item has left pickup state.

//-----------------------------------------------------------------------------
// Ambient glow related info.

var(Display) bool bAmbientGlow;       // Whether to glow or not.

//-----------------------------------------------------------------------------
// Information relevant to Pickup state.

var() bool      bInstantRespawn;      // Can be tagged so this item respawns instantly.
var() bool      bRotatingPickup;      // Rotates when in pickup state.
var() localized string[64]  PickupMessage; // Human readable description when picked up.
var() localized string[32]  ItemName; // Human readable name of item
var() localized string[16]  ItemArticle; // Human readable article (e.g. "a", "an")
var() float     RespawnTime;          // Respawn after this time, 0 for instant.
var name        PlayerLastTouched;    // Player who last touched this item.

//-----------------------------------------------------------------------------
// Rendering information.

// Player view rendering info.
var() vector      PlayerViewOffset;   // Offset from view center.
var() mesh        PlayerViewMesh;     // Mesh to render.
var() float       PlayerViewScale;    // Mesh scale.
var() float       BobDamping;         // how much to damp view bob

// Pickup view rendering info.
var() mesh        PickupViewMesh;     // Mesh to render.
var() float       PickupViewScale;    // Mesh scale.

// 3rd person mesh.
var() mesh        ThirdPersonMesh;    // Mesh to render.
var() float       ThirdPersonScale;   // Mesh scale.

//-----------------------------------------------------------------------------
// Status bar info.

var() texture     StatusIcon;         // Icon used with ammo/charge/power count.

//-----------------------------------------------------------------------------
// Armor related info.

var() name        ProtectionType1;    // Protects against DamageType (None if non-armor).
var() name        ProtectionType2;    // Secondary protection type (None if non-armor).
var() travel int  Charge;             // Amount of armor or charge if not an armor (charge in time*10).
var() int         ArmorAbsorption;    // Percent of damage item absorbs 0-100.
var() bool        bIsAnArmor;         // Item will protect player.
var() int         AbsorptionPriority; // Which items absorb damage first (higher=first).
var() inventory   NextArmor;          // Temporary list created by Armors to prioritize damage absorption.

//-----------------------------------------------------------------------------
// AI related info.

var() float       MaxDesireability;   // Maximum desireability this item will ever have.
var   InventorySpot MyMarker;

//-----------------------------------------------------------------------------
// Sound assignments.

var() sound PickupSound, ActivateSound, DeActivateSound, RespawnSound;

//-----------------------------------------------------------------------------
// HUD graphics.

var() texture Icon;
var() localized String[32] M_Activated;
var() localized String[32] M_Selected;
var() localized String[32] M_Deactivated;

// Network replication.
replication
{
    // Things the server should send to the client.
    reliable if( Role==ROLE_Authority && bNetOwner )
        bIsAnArmor, Charge, bActivatable, bActive, PlayerViewOffset;
}

function PostBeginPlay()
{
    if ( ItemName == "" )
        ItemName = GetItemName(string(Class));

    Super.PostBeginPlay();
}

// Draw first person view of inventory (called by HUD for weapon)
simulated event RenderOverlays( canvas Canvas )
{
    bHidden = True;
    SetLocation( Owner.Location + CalcDrawOffset() );
    SetRotation( Pawn(Owner).ViewRotation );
    Canvas.DrawActor(self, false);
}

//=============================================================================
// AI inventory functions.

event float BotDesireability( pawn Bot )
{
    local Inventory AlreadyHas;
    local float desire;
    local bool bChecked;

    desire = MaxDesireability;

    if ( RespawnTime < 10 )
    {
        bChecked = true;
        AlreadyHas = Bot.FindInventoryType(class); 
        if ( (AlreadyHas != None) 
            && (AlreadyHas.Charge >= Charge) )
                return -1;
    }

    if( bIsAnArmor )
    {
        if ( !bChecked )
            AlreadyHas = Bot.FindInventoryType(class); 
        if ( AlreadyHas != None )
            desire *= 0.4;
        
        desire *= (Charge * 0.005);
        desire *= (ArmorAbsorption * 0.01);
        return desire;
    }
    else return desire;
}

function Weapon RecommendWeapon( out float rating, out int bUseAltMode )
{
    if ( inventory != None )
        return inventory.RecommendWeapon(rating, bUseAltMode);
    else
    {
        rating = -1;
        return None;
    }
}

//=============================================================================
// Inventory travelling across servers.

//
// Called after a travelling inventory item has been accepted into a level.
//
event TravelPreAccept()
{
    Super.TravelPreAccept();
    GiveTo( Pawn(Owner) );
    if( bActive )
        Activate();
}

//=============================================================================
// General inventory functions.

//
// Called by engine when destroyed.
//
function Destroyed()
{
    if (MyMarker != None )
        MyMarker.markedItem = None;     
    // Remove from owner's inventory.
    if( Pawn(Owner)!=None )
        Pawn(Owner).DeleteInventory( Self );
}

//
// Compute offset for drawing.
//
simulated final function vector CalcDrawOffset()
{
    local vector DrawOffset, WeaponBob;

    DrawOffset = ((0.01 * PlayerViewOffset) >> Pawn(Owner).ViewRotation);

    if ( (Level.NetMode == NM_DedicatedServer) 
        || ((Level.NetMode == NM_ListenServer) && (Owner.RemoteRole == ROLE_AutonomousProxy)) )
        DrawOffset += (Pawn(Owner).BaseEyeHeight * vect(0,0,1));
    else
    {   
        DrawOffset += (Pawn(Owner).EyeHeight * vect(0,0,1));
        WeaponBob = BobDamping * Pawn(Owner).WalkBob;
        WeaponBob.Z = (0.45 + 0.55 * BobDamping) * Pawn(Owner).WalkBob.Z;
        DrawOffset += WeaponBob;
    }
    return DrawOffset;
}

//
// Become a pickup.
//
function BecomePickup()
{
    if ( Physics != PHYS_Falling )
        RemoteRole    = ROLE_SimulatedProxy;
    Mesh          = PickupViewMesh;
    DrawScale     = PickupViewScale;
    bOnlyOwnerSee = false;
    bHidden       = false;
    bCarriedItem  = false;
    NetPriority   = 2;
    SetCollision( true, false, false );
}

//
// Become an inventory item.
//
function BecomeItem()
{
    RemoteRole    = ROLE_DumbProxy;
    Mesh          = PlayerViewMesh;
    DrawScale     = PlayerViewScale;
    bOnlyOwnerSee = false;
    bHidden       = true;
    bCarriedItem  = true;
    NetPriority   = 2;
    SetCollision( false, false, false );
    SetPhysics(PHYS_None);
    SetTimer(0.0,False);
    AmbientGlow = 0;
}

//
// Give this inventory item to a pawn.
//
function GiveTo( pawn Other )
{
    Instigator = Other;
    BecomeItem();
    Other.AddInventory( Self );
    GotoState('Idle2');
}

// Either give this inventory to player Other, or spawn a copy
// and give it to the player Other, setting up original to be respawned.
//
function inventory SpawnCopy( pawn Other )
{
    local inventory Copy;
    if( Level.Game.ShouldRespawn(self) )
    {
        Copy = spawn(Class,Other);
        Copy.Tag           = Tag;
        Copy.Event         = Event;
        GotoState('Sleeping');
    }
    else
        Copy = self;

    Copy.RespawnTime = 0.0;
    Copy.bHeldItem = true;
    Copy.GiveTo( Other );
    return Copy;
}

//
// Set up respawn waiting if desired.
//
function SetRespawn()
{
    if( Level.Game.ShouldRespawn(self) )
        GotoState('Sleeping');
    else
        Destroy();
}


//
// Toggle Activation of selected Item.
// 
function Activate()
{
    if( bActivatable )
    {
        Pawn(Owner).ClientMessage(ItemName$M_Activated);    
        GoToState('Activated');
    }
}

//
// Function which lets existing items in a pawn's inventory
// prevent the pawn from picking something up. Return true to abort pickup
// or if item handles pickup, otherwise keep going through inventory list.
//
function bool HandlePickupQuery( inventory Item )
{
    if ( Item.Class == Class )
        return true;
    if ( Inventory == None )
        return false;

    return Inventory.HandlePickupQuery(Item);
}

//
// Select first activatable item.
//
function Inventory SelectNext()
{
    if ( bActivatable ) 
    {
        Pawn(Owner).ClientMessage(ItemName$M_Selected);
        return self;
    }
    if ( Inventory != None )
        return Inventory.SelectNext();
    else
        return None;
}

//
// Toss this item out.
//
function DropFrom(vector StartLocation)
{
    if ( !SetLocation(StartLocation) )
        return; 
    RespawnTime = 0.0; //don't respawn
    SetPhysics(PHYS_Falling);
    RemoteRole = ROLE_DumbProxy;
    BecomePickup();
    NetPriority = 6;
    bCollideWorld = true;
    if ( Pawn(Owner) != None )
        Pawn(Owner).DeleteInventory(self);
    GotoState('PickUp', 'Dropped');
}

//=============================================================================
// Capabilities: For feeding general info to bots.

// For future use.
function float InventoryCapsFloat( name Property, pawn Other, actor Test );
function string[255] InventoryCapsString( name Property, pawn Other, actor Test );

//=============================================================================
// Firing/using.

// Fire functions which must be implemented in child classes.
function Fire( float Value );
function AltFire( float Value );
function Use( pawn User );

//=============================================================================
// Weapon functions.

//
// Find a weapon in inventory that has an Inventory Group matching F.
//

function Weapon WeaponChange( byte F )
{
    if( Inventory == None)
        return None;
    else
        return Inventory.WeaponChange( F );
}

//=============================================================================
// Armor functions.

//
// Scan the player's inventory looking for items that reduce damage
// to the player.  If Armor's protection type matches DamageType, then no damage is taken.
// Returns the reduced damage.
//
function int ReduceDamage( int Damage, name DamageType, vector HitLocation )
{
    local Inventory FirstArmor;
    local int ReducedAmount,ArmorDamage;
    
    if( Damage<0 )
        return 0;
    
    ReducedAmount = Damage;
    FirstArmor = PrioritizeArmor(Damage, DamageType, HitLocation);
    while( (FirstArmor != None) && (ReducedAmount > 0) )
    {
        ReducedAmount = FirstArmor.ArmorAbsorbDamage(ReducedAmount, DamageType, HitLocation);
        FirstArmor = FirstArmor.nextArmor;
    } 
    return ReducedAmount;
}

//
// Return the best armor to use.
//
function inventory PrioritizeArmor( int Damage, name DamageType, vector HitLocation )
{
    local Inventory FirstArmor, InsertAfter;

    if ( Inventory != None )
        FirstArmor = Inventory.PrioritizeArmor(Damage, DamageType, HitLocation);
    else
        FirstArmor = None;

    if ( bIsAnArmor)
    {
        if ( FirstArmor == None )
        {
            nextArmor = None;
            return self;
        }

        // insert this armor into the prioritized armor list
        if ( FirstArmor.ArmorPriority(DamageType) < ArmorPriority(DamageType) )
        {
            nextArmor = FirstArmor;
            return self;
        }
        InsertAfter = FirstArmor;
        while ( (InsertAfter.nextArmor != None) 
            && (InsertAfter.nextArmor.ArmorPriority(DamageType) > ArmorPriority(DamageType)) )
            InsertAfter = InsertAfter.nextArmor;

        nextArmor = InsertAfter.nextArmor;
        InsertAfter.nextArmor = self;
    }
    return FirstArmor;
}

//
// Absorb damage.
//
function int ArmorAbsorbDamage(int Damage, name DamageType, vector HitLocation)
{
    local int ArmorDamage;

    ArmorImpactEffect(HitLocation);
    if( (DamageType!='None') && ((ProtectionType1==DamageType) || (ProtectionType2==DamageType)) )
        return 0;
    
    if (DamageType=='Drowned') Return Damage;
    
    ArmorDamage = (Damage * ArmorAbsorption) / 100;
    if( ArmorDamage >= Charge )
    {
        ArmorDamage = Charge;
        Destroy();
    }
    else 
        Charge -= ArmorDamage;
    return (Damage - ArmorDamage);
}

//
// Return armor value.
//
function int ArmorPriority(name DamageType)
{
    if ( DamageType == 'Drowned' )
        return 0;
    if( (DamageType!='None') 
        && ((ProtectionType1==DamageType) || (ProtectionType2==DamageType)) )
        return 1000000;

    return AbsorptionPriority;
}

//
// This function is called by ArmorAbsorbDamage and displays a visual effect 
// for an impact on an armor.
//
function ArmorImpactEffect(vector HitLocation){ }

//
// Used to inform inventory when owner jumps.
//
function OwnerJumped()
{
    if( Inventory != None )
        Inventory.OwnerJumped();
}

//=============================================================================
// Pickup state: this inventory item is sitting on the ground.

auto state Pickup
{
    singular function ZoneChange( ZoneInfo NewZone )
    {
        local float splashsize;
        local actor splash;

        if( NewZone.bWaterZone && !Region.Zone.bWaterZone ) 
        {
            splashSize = 0.000025 * Mass * (250 - 0.5 * Velocity.Z);
            if ( NewZone.EntrySound != None )
                PlaySound(NewZone.EntrySound, SLOT_Interact, splashSize);
            if ( NewZone.EntryActor != None )
            {
                splash = Spawn(NewZone.EntryActor); 
                if ( splash != None )
                    splash.DrawScale = 2 * splashSize;
            }
        }
    }

    // Validate touch, and if valid trigger event.
    function bool ValidTouch( actor Other )
    {
        local Actor A;

        if( Pawn(Other)!=None && Pawn(Other).bIsPlayer && (Pawn(Other).Health > 0) && Level.Game.PickupQuery(Pawn(Other), self) )
        {
            if( Event != '' )
                foreach AllActors( class 'Actor', A, Event )
                    A.Trigger( Other, Other.Instigator );
            return true;
        }
        return false;
    }
        
    // When touched by an actor.
    function Touch( actor Other )
    {
        // If touched by a player pawn, let him pick this up.
        if( ValidTouch(Other) )
        {
            SpawnCopy(Pawn(Other));
            Pawn(Other).ClientMessage(PickupMessage, 'Pickup');
            PlaySound (PickupSound);        
            if ( Level.Game.Difficulty > 1 )
                Other.MakeNoise(0.1 * Level.Game.Difficulty);       
        }
    }

    // Landed on ground.
    function Landed(Vector HitNormal)
    {
        local rotator newRot;
        newRot = Rotation;
        newRot.pitch = 0;
        SetRotation(newRot);
        SetTimer(2.0, false);
    }

    // Make sure no pawn already touching (while touch was disabled in sleep).
    function CheckTouching()
    {
        local int i;

        bSleepTouch = false;
        for ( i=0; i<4; i++ )
            if ( (Touching[i] != None) && Touching[i].IsA('Pawn') )
                Touch(Touching[i]);
    }

    function Timer()
    {
        if ( RemoteRole != ROLE_SimulatedProxy )
        {
            NetPriority = 2;
            RemoteRole = ROLE_SimulatedProxy;
            if ( bHeldItem )
                SetTimer(40.0, false);
            return;
        }

        if ( bHeldItem )
            Destroy();
    }

    function BeginState()
    {
        BecomePickup();
        bCollideWorld = true;
        if ( bHeldItem )
            SetTimer(45, false);
    }

    function EndState()
    {
        bCollideWorld = false;
        bSleepTouch = false;
    }

Begin:
    BecomePickup();
    if ( bRotatingPickup && (Physics != PHYS_Falling) )
        SetPhysics(PHYS_Rotating);

Dropped:
    if( bAmbientGlow )
        AmbientGlow=255;
    if( bSleepTouch )
        CheckTouching();
}

//=============================================================================
// Active state: this inventory item is armed and ready to rock!

state Activated
{
    function BeginState()
    {
        bActive = true;
        if ( Pawn(Owner).bIsPlayer && (ProtectionType1 != '') )
            Pawn(Owner).ReducedDamageType = ProtectionType1;
    }

    function EndState()
    {
        bActive = false;
        if ( (Pawn(Owner) != None)
            && Pawn(Owner).bIsPlayer && (ProtectionType1 != '') )
            Pawn(Owner).ReducedDamageType = '';
    }

    function Activate()
    {
        if ( Pawn(Owner) != None )
            Pawn(Owner).ClientMessage(ItemName$M_Deactivated);  
        GoToState('DeActivated');   
    }
}

//=============================================================================
// Sleeping state: Sitting hidden waiting to respawn.

State Sleeping
{
    ignores Touch;

    function BeginState()
    {
        BecomePickup();
        bHidden = true;
    }
    function EndState()
    {
        local int i;

        bSleepTouch = false;
        for ( i=0; i<4; i++ )
            if ( (Touching[i] != None) && Touching[i].IsA('Pawn') )
                bSleepTouch = true;
    }           
Begin:
    Sleep( ReSpawnTime );
    PlaySound( RespawnSound );  
    Level.Game.PlaySpawnEffect(self);
    Sleep( 0.3 );
    GoToState( 'Pickup' );
}

function ActivateTranslator(bool bHint)
{
    if( Inventory!=None )
        Inventory.ActivateTranslator( bHint );
}

//
// Null state.
//
State Idle2
{
}

defaultproperties
{
     bAmbientGlow=True
     bRotatingPickup=True
     PickupMessage="Snagged an item"
     ItemArticle="a"
     PlayerViewScale=1.000000
     BobDamping=0.960000
     PickupViewScale=1.000000
     ThirdPersonScale=1.000000
     MaxDesireability=0.005000
     M_Activated=" activated"
     M_Selected=" selected"
     M_Deactivated=" deactivated"
     bIsItemGoal=True
     bTravel=True
     RemoteRole=ROLE_SimulatedProxy
     DrawType=DT_Mesh
     Texture=Texture'Engine.S_Inventory'
     AmbientGlow=255
     CollisionRadius=30.000000
     CollisionHeight=30.000000
     bCollideActors=True
     bFixedRotationDir=True
     RotationRate=(Yaw=5000)
     DesiredRotation=(Yaw=30000)
     NetPriority=2.000000
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Sun 21/2/2010 23:48:40.000 - Creation time: Sun 21/2/2010 23:49:52.133 - Created with UnCodeX