//************************************************************************** //** //** ## ## ## ## ## #### #### ### ### //** ## ## ## ## ## ## ## ## ## ## #### #### //** ## ## ## ## ## ## ## ## ## ## ## ## ## ## //** ## ## ######## ## ## ## ## ## ## ## ### ## //** ### ## ## ### ## ## ## ## ## ## //** # ## ## # #### #### ## ## //** //** $Id: Powerup.vc 2615 2007-08-10 19:09:58Z dj_jl $ //** //** Copyright (C) 1999-2006 Jānis Legzdiņš //** //** This program is free software; you can redistribute it and/or //** modify it under the terms of the GNU General Public License //** as published by the Free Software Foundation; either version 2 //** of the License, or (at your option) any later version. //** //** This program is distributed in the hope that it will be useful, //** but WITHOUT ANY WARRANTY; without even the implied warranty of //** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //** GNU General Public License for more details. //** //************************************************************************** //** //** Base class for all powerups. //** //************************************************************************** class Powerup : Inventory abstract; float EffectTime; int BlendColour; name Mode; replication { reliable if (Role == ROLE_Authority && bNetOwner) EffectTime, Mode; } //========================================================================== // // Destroyed // //========================================================================== void Destroyed() { EndEffect(); ::Destroyed(); } //========================================================================== // // Tick // //========================================================================== void Tick(float DeltaTime) { // Powerup cannot exist without an owner. if (!Owner) { Destroy(); return; } if (EffectTime > 0.0) { EffectTime -= DeltaTime; if (EffectTime <= 0.0) { Destroy(); } } } //========================================================================== // // HandlePickup // //========================================================================== bool HandlePickup(Inventory Item) { if (Item.Class == Class) { Powerup Pow = Powerup(Item); // Permanent powerups can be always picked up. if (!Pow.EffectTime) { Item.bPickupGood = true; return true; } // Don't pick it up if not yet blinking unless it should always be // picked up. if (EffectTime > PlayerEx::BLINKTHRESHOLD && !Item.bAlwaysPickup) { // Already have it. return true; } // Only increase effect time. if (EffectTime < Pow.EffectTime) { EffectTime = Pow.EffectTime; } Item.bPickupGood = true; return true; } if (Inventory) { return Inventory.HandlePickup(Item); } return false; } //========================================================================== // // CreateCopy // //========================================================================== Inventory CreateCopy(EntityEx Toucher) { Owner = Toucher; InitEffect(); Owner = none; return self; } //========================================================================== // // OwnerDied // //========================================================================== void OwnerDied() { // Powerups don't last after owner's death. Destroy(); } //========================================================================== // // InitEffect // //========================================================================== void InitEffect() { } //========================================================================== // // DoEffect // //========================================================================== void DoEffect() { if (!Owner) { return; } if (EffectTime > 0.0 && Owner.Player) { if (EffectTime > PlayerEx::BLINKTHRESHOLD || (ftoi(4.0 * EffectTime) & 1)) { if (BlendColour == INVERSECOLOUR) { Owner.Player.FixedColourmap = INVERSECOLOURMAP; } } else if (BlendColour == INVERSECOLOUR && Owner.Player.FixedColourmap == INVERSECOLOURMAP) { Owner.Player.FixedColourmap = 0; } } } //========================================================================== // // EndEffect // //========================================================================== void EndEffect() { } //========================================================================== // // GetBlend // //========================================================================== int GetBlend() { if (EffectTime <= PlayerEx::BLINKTHRESHOLD && !(ftoi(4.0 * EffectTime) & 1)) { return 0; } if (BlendColour == INVERSECOLOUR) { return 0; } return BlendColour; } defaultproperties { }