//************************************************************************** //** //** ## ## ## ## ## #### #### ### ### //** ## ## ## ## ## ## ## ## ## ## #### #### //** ## ## ## ## ## ## ## ## ## ## ## ## ## ## //** ## ## ######## ## ## ## ## ## ## ## ### ## //** ### ## ## ### ## ## ## ## ## ## //** # ## ## # #### #### ## ## //** //** $Id: BackpackItem.vc 2565 2007-08-02 21:01:15Z 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. //** //************************************************************************** class BackpackItem : Inventory abstract; // A depleeted backpack will not give any ammo. bool bDepleeted; //========================================================================== // // HandlePickup // //========================================================================== bool HandlePickup(Inventory Item) { if (BackpackItem(Item)) { Inventory AmmoItem; for (AmmoItem = EntityEx(Owner).Inventory; AmmoItem; AmmoItem = AmmoItem.Inventory) { // Only direct descendants. if (GetClassParent(AmmoItem.Class) != Ammo) { continue; } if (AmmoItem.Amount == AmmoItem.MaxAmount) { continue; } int num = Ammo(AmmoItem).default.BackpackAmount; if (!num || BackpackItem(Item).bDepleeted) { continue; } if (Level.Game.gameskill == sk_baby || (Level.Game.gameskill == sk_nightmare && LineSpecialGameInfo(Level.Game).bNightmareExtraAmmo)) { // extra ammo in baby mode and nightmare mode if (LineSpecialGameInfo(Level.Game).bBabyNightmareDoubleAmmo) { num <<= 1; } else { num += num >> 1; } } int oldammo = AmmoItem.Amount; AmmoItem.Amount += num; if (AmmoItem.Amount > AmmoItem.MaxAmount) { AmmoItem.Amount = AmmoItem.MaxAmount; } if (oldammo <= 0 && Owner.Player) { PlayerEx(Owner.Player).GotAmmo(Ammo(AmmoItem)); } } Item.bPickupGood = true; return true; } if (Inventory) { return Inventory.HandlePickup(Item); } return false; } //========================================================================== // // CreateCopy // //========================================================================== Inventory CreateCopy(EntityEx Toucher) { class Cls; // Give toucher every kind of ammo. foreach AllClasses(Ammo, Cls) { // Only direct descendants. if (GetClassParent(Cls) != Ammo) { continue; } Ammo AmmoItem = Ammo(Toucher.FindInventory(Cls)); if (!AmmoItem) { AmmoItem = Spawn(Cls); AmmoItem.AttachToOwner(Toucher); AmmoItem.Amount = 0; } if (AmmoItem.MaxAmount < AmmoItem.BackpackMaxAmount) { AmmoItem.MaxAmount = AmmoItem.BackpackMaxAmount; } if (AmmoItem.Amount == AmmoItem.MaxAmount) { continue; } int num = AmmoItem.default.BackpackAmount; if (!num || bDepleeted) { continue; } if (Level.Game.gameskill == sk_baby || (Level.Game.gameskill == sk_nightmare && LineSpecialGameInfo(Level.Game).bNightmareExtraAmmo)) { // extra ammo in baby mode and nightmare mode if (LineSpecialGameInfo(Level.Game).bBabyNightmareDoubleAmmo) { num <<= 1; } else { num += num >> 1; } } int oldammo = AmmoItem.Amount; AmmoItem.Amount += num; if (AmmoItem.Amount > AmmoItem.MaxAmount) { AmmoItem.Amount = AmmoItem.MaxAmount; } if (oldammo <= 0 && Toucher.Player) { PlayerEx(Toucher.Player).GotAmmo(AmmoItem); } } Inventory Copy = ::CreateCopy(Toucher); return Copy; } //========================================================================== // // DetachedFromOwner // //========================================================================== void DetachedFromOwner() { // Backpack has been removed, reset all ammo maximal amounts to default. Inventory AmmoItem; for (AmmoItem = EntityEx(Owner).Inventory; AmmoItem; AmmoItem = AmmoItem.Inventory) { if (GetClassParent(AmmoItem.Class) != Ammo) { // Not an ammo. continue; } if (AmmoItem.MaxAmount != Ammo(AmmoItem).BackpackMaxAmount) { // Maximal amount doesn't match what backpack should give. continue; } AmmoItem.MaxAmount = AmmoItem.default.MaxAmount; if (AmmoItem.Amount > AmmoItem.MaxAmount) { AmmoItem.Amount = AmmoItem.MaxAmount; } } } //========================================================================== // // CreateTossable // //========================================================================== Inventory CreateTossable() { // Set depleeted flag to prevent cheating. Inventory Copy = ::CreateTossable(); BackpackItem(Copy).bDepleeted = true; return Copy; } defaultproperties { }