1//************************************************************************** 2//** 3//** ## ## ## ## ## #### #### ### ### 4//** ## ## ## ## ## ## ## ## ## ## #### #### 5//** ## ## ## ## ## ## ## ## ## ## ## ## ## ## 6//** ## ## ######## ## ## ## ## ## ## ## ### ## 7//** ### ## ## ### ## ## ## ## ## ## 8//** # ## ## # #### #### ## ## 9//** 10//** $Id: FourthWeaponPiece.vc 4326 2010-07-19 21:00:24Z firebrand_kh $ 11//** 12//** Copyright (C) 1999-2006 Jānis Legzdiņš 13//** 14//** This program is free software; you can redistribute it and/or 15//** modify it under the terms of the GNU General Public License 16//** as published by the Free Software Foundation; either version 2 17//** of the License, or (at your option) any later version. 18//** 19//** This program is distributed in the hope that it will be useful, 20//** but WITHOUT ANY WARRANTY; without even the implied warranty of 21//** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22//** GNU General Public License for more details. 23//** 24//************************************************************************** 25 26class FourthWeaponPiece : WeaponPiece 27 abstract; 28 29const int 30 WPIECE1 = 1, 31 WPIECE2 = 2, 32 WPIECE3 = 4; 33 34class<Actor> PieceClass; 35 36bool gaveWeapon; 37 38//========================================================================== 39// 40// TryPickup 41// 42//========================================================================== 43 44bool TryPickup(EntityEx Toucher) 45{ 46 int GaveAmmo; 47 bool checkAssembled; 48 Inventory Inv; 49 50 checkAssembled = true; 51 gaveWeapon = false; 52 if (!ClassIsChildOf(Toucher.Class, GetClassReplacement(PieceClass))) 53 { 54 // Wrong class, but try to pick up for mana 55 if (ShouldStay()) 56 { 57 // Can't pick up wrong-class weapons in coop netplay 58 return false; 59 } 60 checkAssembled = false; 61 GaveAmmo = PlayerEx(Toucher.Player).GiveAmmo(WeaponType.default.AmmoType1, 62 WeaponType.default.AmmoGive1) | 63 PlayerEx(Toucher.Player).GiveAmmo(WeaponType.default.AmmoType2, 64 WeaponType.default.AmmoGive2); 65 if (!GaveAmmo) 66 { 67 // Didn't need the mana, so don't pick it up 68 return false; 69 } 70 GoAwayAndDie(); 71 return true; 72 } 73 74 FourthWeaponHolder Hold = FourthWeaponHolder( 75 Toucher.FindInventory(FourthWeaponHolder)); 76 if (!Hold) 77 { 78 Hold = Spawn(FourthWeaponHolder,,,, false); 79 Hold.AttachToOwner(Toucher); 80 Hold.PieceMask = 0; 81 } 82 83 if (ShouldStay() && (Hold.PieceMask & PieceValue)) 84 { 85 // Already has the piece 86 return false; 87 } 88 89 GaveAmmo = PlayerEx(Toucher.Player).GiveAmmo(WeaponType.default.AmmoType1, 90 WeaponType.default.AmmoGive1) | 91 PlayerEx(Toucher.Player).GiveAmmo(WeaponType.default.AmmoType2, 92 WeaponType.default.AmmoGive2); 93 if (ShouldStay()) 94 { 95 PieceValue = GetPieceValueTrans(PieceValue); 96 } 97 98 if ((Hold.PieceMask & PieceValue) == PieceValue) 99 { 100 // Already has the piece, check if mana needed 101 if (!GaveAmmo) 102 { 103 // Didn't need the mana, so don't pick it up 104 return false; 105 } 106 } 107 108 // Pick up the weapon piece 109 110 // Check if fourth weapon assembled 111 Hold.PieceMask |= PieceValue; 112 if (Hold.PieceMask == (WPIECE1 | WPIECE2 | WPIECE3)) 113 { 114 // Give the weapon if we don't already have it 115 if (!Weapon(Toucher.FindInventory(WeaponType))) 116 { 117 Weapon Wpn = Level.Spawn(WeaponType); 118 if (!Wpn.TryPickup(Toucher)) 119 { 120 Wpn.Destroy(); 121 } 122 else 123 { 124 gaveWeapon = true; 125 PlayerEx(Toucher.Player).PendingWeapon = Wpn; 126 GivenWeapon = Wpn; 127 } 128 } 129 } 130 GoAwayAndDie(); 131 return true; 132} 133 134//========================================================================== 135// 136// GetPickupMessage 137// 138//========================================================================== 139 140string GetPickupMessage() 141{ 142 if (gaveWeapon) 143 { 144 return Inventory(GivenWeapon).PickupMessage; 145 } 146 else 147 { 148 return ::GetPickupMessage(); 149 } 150} 151 152//========================================================================== 153// 154// PlayPickupSound 155// 156//========================================================================== 157 158void PlayPickupSound(EntityEx Toucher) 159{ 160 if (gaveWeapon) 161 { 162 // Play the build-sound full volume for all players 163 Toucher.PlaySound('WeaponBuild', CHAN_BODY, 1.0, ATTN_NONE); 164 } 165 else 166 { 167 ::PlayPickupSound(Toucher); 168 } 169} 170 171//========================================================================== 172// 173// ShouldStay 174// 175//========================================================================== 176 177bool ShouldStay() 178{ 179 return Level.Game.netgame && !Level.Game.deathmatch; 180} 181 182//========================================================================== 183// 184// GetPieceValueTrans 185// 186//========================================================================== 187 188final int GetPieceValueTrans(int Val) 189{ 190 switch (Val) 191 { 192 case WPIECE1: 193 return WPIECE1 | WPIECE2 | WPIECE3; 194 case WPIECE2: 195 return WPIECE2 | WPIECE3; 196 case WPIECE3: 197 return WPIECE3; 198 } 199 // Should not happen. 200 return 0; 201} 202 203defaultproperties 204{ 205 Height = 32.0; 206 bFullVolPickupSound = true; 207 PickupSound = 'PickupWeapon'; 208} 209