2006-02-24 04:48:15 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "a_pickups.h"
|
|
|
|
#include "gi.h"
|
|
|
|
#include "d_player.h"
|
|
|
|
#include "s_sound.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "r_state.h"
|
|
|
|
#include "p_pspr.h"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "m_misc.h"
|
|
|
|
#include "gameconfigfile.h"
|
|
|
|
#include "cmdlib.h"
|
|
|
|
#include "templates.h"
|
|
|
|
#include "sbar.h"
|
2008-08-08 10:24:08 +00:00
|
|
|
#include "thingdef/thingdef.h"
|
2008-09-14 23:54:38 +00:00
|
|
|
#include "doomstat.h"
|
|
|
|
#include "g_level.h"
|
2009-02-20 22:28:48 +00:00
|
|
|
#include "d_net.h"
|
2011-07-06 14:20:54 +00:00
|
|
|
#include "farchive.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
#define BONUSADD 6
|
|
|
|
|
|
|
|
IMPLEMENT_POINTY_CLASS (AWeapon)
|
|
|
|
DECLARE_POINTER (Ammo1)
|
|
|
|
DECLARE_POINTER (Ammo2)
|
|
|
|
DECLARE_POINTER (SisterWeapon)
|
|
|
|
END_POINTERS
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
FString WeaponSection;
|
|
|
|
TArray<FString> KeyConfWeapons;
|
2009-03-12 03:54:23 +00:00
|
|
|
FWeaponSlots *PlayingKeyConf;
|
2009-02-20 00:53:25 +00:00
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
TArray<PClassWeapon *> Weapons_ntoh;
|
|
|
|
TMap<PClassWeapon *, int> Weapons_hton;
|
2009-02-24 05:58:59 +00:00
|
|
|
|
|
|
|
static int STACK_ARGS ntoh_cmp(const void *a, const void *b);
|
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
IMPLEMENT_CLASS(PClassWeapon)
|
|
|
|
|
|
|
|
PClassWeapon::PClassWeapon()
|
|
|
|
{
|
|
|
|
SlotNumber = -1;
|
|
|
|
SlotPriority = FIXED_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PClassWeapon::Derive(PClass *newclass)
|
|
|
|
{
|
|
|
|
assert(newclass->IsKindOf(RUNTIME_CLASS(PClassWeapon)));
|
|
|
|
Super::Derive(newclass);
|
|
|
|
PClassWeapon *newc = static_cast<PClassWeapon *>(newclass);
|
|
|
|
|
|
|
|
newc->SlotNumber = SlotNumber;
|
|
|
|
newc->SlotPriority = SlotPriority;
|
|
|
|
}
|
|
|
|
|
2016-02-09 22:08:51 +00:00
|
|
|
|
|
|
|
void PClassWeapon::ReplaceClassRef(PClass *oldclass, PClass *newclass)
|
|
|
|
{
|
|
|
|
Super::ReplaceClassRef(oldclass, newclass);
|
|
|
|
AWeapon *def = (AWeapon*)Defaults;
|
|
|
|
if (def != NULL)
|
|
|
|
{
|
|
|
|
if (def->AmmoType1 == oldclass) def->AmmoType1 = static_cast<PClassAmmo *>(newclass);
|
|
|
|
if (def->AmmoType2 == oldclass) def->AmmoType2 = static_cast<PClassAmmo *>(newclass);
|
|
|
|
if (def->SisterWeaponType == oldclass) def->SisterWeaponType = static_cast<PClassWeapon *>(newclass);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: Serialize
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void AWeapon::Serialize (FArchive &arc)
|
|
|
|
{
|
|
|
|
Super::Serialize (arc);
|
|
|
|
arc << WeaponFlags
|
|
|
|
<< AmmoType1 << AmmoType2
|
|
|
|
<< AmmoGive1 << AmmoGive2
|
|
|
|
<< MinAmmo1 << MinAmmo2
|
|
|
|
<< AmmoUse1 << AmmoUse2
|
|
|
|
<< Kickback
|
|
|
|
<< YAdjust
|
2008-06-15 02:25:09 +00:00
|
|
|
<< UpSound << ReadySound
|
2006-02-24 04:48:15 +00:00
|
|
|
<< SisterWeaponType
|
|
|
|
<< ProjectileType << AltProjectileType
|
|
|
|
<< SelectionOrder
|
|
|
|
<< MoveCombatDist
|
2008-04-15 22:17:30 +00:00
|
|
|
<< Ammo1 << Ammo2 << SisterWeapon << GivenAsMorphWeapon
|
2008-06-22 09:13:19 +00:00
|
|
|
<< bAltFire
|
2012-05-02 20:58:29 +00:00
|
|
|
<< ReloadCounter;
|
|
|
|
if (SaveVersion >= 3615) {
|
|
|
|
arc << BobStyle << BobSpeed << BobRangeX << BobRangeY;
|
|
|
|
}
|
|
|
|
arc << FOVScale
|
2009-09-14 21:41:44 +00:00
|
|
|
<< Crosshair;
|
2013-03-24 02:25:12 +00:00
|
|
|
if (SaveVersion >= 4203)
|
|
|
|
{
|
|
|
|
arc << MinSelAmmo1 << MinSelAmmo2;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 23:51:23 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: MarkPrecacheSounds
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void AWeapon::MarkPrecacheSounds() const
|
|
|
|
{
|
|
|
|
Super::MarkPrecacheSounds();
|
|
|
|
UpSound.MarkUsed();
|
|
|
|
ReadySound.MarkUsed();
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: TryPickup
|
|
|
|
//
|
|
|
|
// If you can't see the weapon when it's active, then you can't pick it up.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2011-09-23 08:23:51 +00:00
|
|
|
bool AWeapon::TryPickupRestricted (AActor *&toucher)
|
|
|
|
{
|
|
|
|
// Wrong class, but try to pick up for ammo
|
|
|
|
if (ShouldStay())
|
|
|
|
{ // Can't pick up weapons for other classes in coop netplay
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool gaveSome = (NULL != AddAmmo (toucher, AmmoType1, AmmoGive1));
|
|
|
|
gaveSome |= (NULL != AddAmmo (toucher, AmmoType2, AmmoGive2));
|
|
|
|
if (gaveSome)
|
|
|
|
{
|
|
|
|
GoAwayAndDie ();
|
|
|
|
}
|
|
|
|
return gaveSome;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: TryPickup
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2008-09-13 22:08:41 +00:00
|
|
|
bool AWeapon::TryPickup (AActor *&toucher)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-10-31 14:53:21 +00:00
|
|
|
FState * ReadyState = FindState(NAME_Ready);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (ReadyState != NULL &&
|
2008-08-10 14:19:47 +00:00
|
|
|
ReadyState->GetFrame() < sprites[ReadyState->sprite].numframes)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
return Super::TryPickup (toucher);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: Use
|
|
|
|
//
|
|
|
|
// Make the player switch to this weapon.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
bool AWeapon::Use (bool pickup)
|
|
|
|
{
|
|
|
|
AWeapon *useweap = this;
|
|
|
|
|
2006-04-16 13:29:50 +00:00
|
|
|
// Powered up weapons cannot be used directly.
|
|
|
|
if (WeaponFlags & WIF_POWERED_UP) return false;
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
// If the player is powered-up, use the alternate version of the
|
|
|
|
// weapon, if one exists.
|
|
|
|
if (SisterWeapon != NULL &&
|
|
|
|
SisterWeapon->WeaponFlags & WIF_POWERED_UP &&
|
2011-11-07 00:43:41 +00:00
|
|
|
Owner->FindInventory (RUNTIME_CLASS(APowerWeaponLevel2), true))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
useweap = SisterWeapon;
|
|
|
|
}
|
|
|
|
if (Owner->player != NULL && Owner->player->ReadyWeapon != useweap)
|
|
|
|
{
|
|
|
|
Owner->player->PendingWeapon = useweap;
|
|
|
|
}
|
|
|
|
// Return false so that the weapon is not removed from the inventory.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-07-05 10:17:10 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: Destroy
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2008-07-05 10:31:36 +00:00
|
|
|
void AWeapon::Destroy()
|
2008-07-05 10:17:10 +00:00
|
|
|
{
|
2012-03-15 23:18:13 +00:00
|
|
|
AWeapon *sister = SisterWeapon;
|
|
|
|
|
|
|
|
if (sister != NULL)
|
2008-07-05 10:17:10 +00:00
|
|
|
{
|
|
|
|
// avoid recursion
|
2012-03-15 23:18:13 +00:00
|
|
|
sister->SisterWeapon = NULL;
|
|
|
|
if (sister != this)
|
|
|
|
{ // In case we are our own sister, don't crash.
|
|
|
|
sister->Destroy();
|
|
|
|
}
|
2008-07-05 10:17:10 +00:00
|
|
|
}
|
|
|
|
Super::Destroy();
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: HandlePickup
|
|
|
|
//
|
|
|
|
// Try to leach ammo from the weapon if you have it already.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
bool AWeapon::HandlePickup (AInventory *item)
|
|
|
|
{
|
|
|
|
if (item->GetClass() == GetClass())
|
|
|
|
{
|
|
|
|
if (static_cast<AWeapon *>(item)->PickupForAmmo (this))
|
|
|
|
{
|
|
|
|
item->ItemFlags |= IF_PICKUPGOOD;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (Inventory != NULL)
|
|
|
|
{
|
|
|
|
return Inventory->HandlePickup (item);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: PickupForAmmo
|
|
|
|
//
|
|
|
|
// The player already has this weapon, so try to pick it up for ammo.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
bool AWeapon::PickupForAmmo (AWeapon *ownedWeapon)
|
|
|
|
{
|
|
|
|
bool gotstuff = false;
|
|
|
|
|
|
|
|
// Don't take ammo if the weapon sticks around.
|
|
|
|
if (!ShouldStay ())
|
|
|
|
{
|
2009-02-21 10:15:11 +00:00
|
|
|
int oldamount1 = 0;
|
|
|
|
int oldamount2 = 0;
|
|
|
|
if (ownedWeapon->Ammo1 != NULL) oldamount1 = ownedWeapon->Ammo1->Amount;
|
2009-03-15 08:08:29 +00:00
|
|
|
if (ownedWeapon->Ammo2 != NULL) oldamount2 = ownedWeapon->Ammo2->Amount;
|
2008-12-27 20:18:31 +00:00
|
|
|
|
2006-07-03 09:07:56 +00:00
|
|
|
if (AmmoGive1 > 0) gotstuff = AddExistingAmmo (ownedWeapon->Ammo1, AmmoGive1);
|
|
|
|
if (AmmoGive2 > 0) gotstuff |= AddExistingAmmo (ownedWeapon->Ammo2, AmmoGive2);
|
2008-12-27 20:18:31 +00:00
|
|
|
|
|
|
|
AActor *Owner = ownedWeapon->Owner;
|
2009-02-21 10:15:11 +00:00
|
|
|
if (gotstuff && Owner != NULL && Owner->player != NULL)
|
2008-12-27 20:18:31 +00:00
|
|
|
{
|
2009-02-21 10:15:11 +00:00
|
|
|
if (ownedWeapon->Ammo1 != NULL && oldamount1 == 0)
|
|
|
|
{
|
|
|
|
static_cast<APlayerPawn *>(Owner)->CheckWeaponSwitch(ownedWeapon->Ammo1->GetClass());
|
|
|
|
}
|
|
|
|
else if (ownedWeapon->Ammo2 != NULL && oldamount2 == 0)
|
|
|
|
{
|
|
|
|
static_cast<APlayerPawn *>(Owner)->CheckWeaponSwitch(ownedWeapon->Ammo2->GetClass());
|
|
|
|
}
|
2008-12-27 20:18:31 +00:00
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
return gotstuff;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: CreateCopy
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
AInventory *AWeapon::CreateCopy (AActor *other)
|
|
|
|
{
|
|
|
|
AWeapon *copy = static_cast<AWeapon*>(Super::CreateCopy (other));
|
|
|
|
if (copy != this)
|
|
|
|
{
|
|
|
|
copy->AmmoGive1 = AmmoGive1;
|
|
|
|
copy->AmmoGive2 = AmmoGive2;
|
|
|
|
}
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: CreateTossable
|
|
|
|
//
|
|
|
|
// A weapon that's tossed out should contain no ammo, so you can't cheat
|
|
|
|
// by dropping it and then picking it back up.
|
2009-01-25 01:52:38 +00:00
|
|
|
//
|
|
|
|
//===========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
AInventory *AWeapon::CreateTossable ()
|
|
|
|
{
|
|
|
|
// Only drop the weapon that is meant to be placed in a level. That is,
|
|
|
|
// only drop the weapon that normally gives you ammo.
|
|
|
|
if (SisterWeapon != NULL &&
|
|
|
|
((AWeapon*)GetDefault())->AmmoGive1 == 0 &&
|
|
|
|
((AWeapon*)GetDefault())->AmmoGive2 == 0 &&
|
|
|
|
(((AWeapon*)SisterWeapon->GetDefault())->AmmoGive1 > 0 ||
|
|
|
|
((AWeapon*)SisterWeapon->GetDefault())->AmmoGive2 > 0))
|
|
|
|
{
|
|
|
|
return SisterWeapon->CreateTossable ();
|
|
|
|
}
|
|
|
|
AWeapon *copy = static_cast<AWeapon *> (Super::CreateTossable ());
|
|
|
|
|
|
|
|
if (copy != NULL)
|
|
|
|
{
|
|
|
|
// If this weapon has a sister, remove it from the inventory too.
|
|
|
|
if (SisterWeapon != NULL)
|
|
|
|
{
|
2008-07-05 10:17:10 +00:00
|
|
|
SisterWeapon->SisterWeapon = NULL;
|
2006-02-24 04:48:15 +00:00
|
|
|
SisterWeapon->Destroy ();
|
|
|
|
}
|
2006-09-09 01:14:13 +00:00
|
|
|
// To avoid exploits, the tossed weapon must not have any ammo.
|
2006-02-24 04:48:15 +00:00
|
|
|
copy->AmmoGive1 = 0;
|
|
|
|
copy->AmmoGive2 = 0;
|
|
|
|
}
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: AttachToOwner
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void AWeapon::AttachToOwner (AActor *other)
|
|
|
|
{
|
|
|
|
Super::AttachToOwner (other);
|
|
|
|
|
|
|
|
Ammo1 = AddAmmo (Owner, AmmoType1, AmmoGive1);
|
|
|
|
Ammo2 = AddAmmo (Owner, AmmoType2, AmmoGive2);
|
|
|
|
SisterWeapon = AddWeapon (SisterWeaponType);
|
|
|
|
if (Owner->player != NULL)
|
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
if (!Owner->player->userinfo.GetNeverSwitch() && !(WeaponFlags & WIF_NO_AUTO_SWITCH))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
Owner->player->PendingWeapon = this;
|
|
|
|
}
|
|
|
|
if (Owner->player->mo == players[consoleplayer].camera)
|
|
|
|
{
|
|
|
|
StatusBar->ReceivedWeapon (this);
|
|
|
|
}
|
|
|
|
}
|
2008-04-15 22:17:30 +00:00
|
|
|
GivenAsMorphWeapon = false; // will be set explicitly by morphing code
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: AddAmmo
|
|
|
|
//
|
|
|
|
// Give some ammo to the owner, even if it's just 0.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2010-03-24 02:49:37 +00:00
|
|
|
AAmmo *AWeapon::AddAmmo (AActor *other, PClassActor *ammotype, int amount)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
AAmmo *ammo;
|
|
|
|
|
|
|
|
if (ammotype == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-09-25 23:31:27 +00:00
|
|
|
|
|
|
|
// [BC] This behavior is from the original Doom. Give 5/2 times as much ammo when
|
|
|
|
// we pick up a weapon in deathmatch.
|
2008-08-30 19:44:19 +00:00
|
|
|
if (( deathmatch ) && ( gameinfo.gametype & GAME_DoomChex ))
|
2007-09-25 23:31:27 +00:00
|
|
|
amount = amount * 5 / 2;
|
|
|
|
|
2006-09-09 01:14:13 +00:00
|
|
|
// extra ammo in baby mode and nightmare mode
|
2007-07-28 12:38:10 +00:00
|
|
|
if (!(this->ItemFlags&IF_IGNORESKILL))
|
2006-09-09 01:14:13 +00:00
|
|
|
{
|
2007-10-29 22:15:46 +00:00
|
|
|
amount = FixedMul(amount, G_SkillProperty(SKILLP_AmmoFactor));
|
2006-09-09 01:14:13 +00:00
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
ammo = static_cast<AAmmo *>(other->FindInventory (ammotype));
|
|
|
|
if (ammo == NULL)
|
|
|
|
{
|
2006-07-16 09:10:45 +00:00
|
|
|
ammo = static_cast<AAmmo *>(Spawn (ammotype, 0, 0, 0, NO_REPLACE));
|
2006-02-24 04:48:15 +00:00
|
|
|
ammo->Amount = MIN (amount, ammo->MaxAmount);
|
|
|
|
ammo->AttachToOwner (other);
|
|
|
|
}
|
|
|
|
else if (ammo->Amount < ammo->MaxAmount)
|
|
|
|
{
|
|
|
|
ammo->Amount += amount;
|
|
|
|
if (ammo->Amount > ammo->MaxAmount)
|
|
|
|
{
|
|
|
|
ammo->Amount = ammo->MaxAmount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ammo;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: AddExistingAmmo
|
|
|
|
//
|
|
|
|
// Give the owner some more ammo he already has.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
2009-03-06 22:58:34 +00:00
|
|
|
EXTERN_CVAR(Bool, sv_unlimited_pickup)
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
bool AWeapon::AddExistingAmmo (AAmmo *ammo, int amount)
|
|
|
|
{
|
2009-03-06 22:58:34 +00:00
|
|
|
if (ammo != NULL && (ammo->Amount < ammo->MaxAmount || sv_unlimited_pickup))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-09-09 01:14:13 +00:00
|
|
|
// extra ammo in baby mode and nightmare mode
|
2007-07-28 12:38:10 +00:00
|
|
|
if (!(ItemFlags&IF_IGNORESKILL))
|
2006-09-09 01:14:13 +00:00
|
|
|
{
|
2007-10-29 22:15:46 +00:00
|
|
|
amount = FixedMul(amount, G_SkillProperty(SKILLP_AmmoFactor));
|
2006-09-09 01:14:13 +00:00
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
ammo->Amount += amount;
|
2009-03-06 22:58:34 +00:00
|
|
|
if (ammo->Amount > ammo->MaxAmount && !sv_unlimited_pickup)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
ammo->Amount = ammo->MaxAmount;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: AddWeapon
|
|
|
|
//
|
|
|
|
// Give the owner a weapon if they don't have it already.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
AWeapon *AWeapon::AddWeapon (PClassWeapon *weapontype)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
AWeapon *weap;
|
|
|
|
|
2008-08-02 08:38:07 +00:00
|
|
|
if (weapontype == NULL || !weapontype->IsDescendantOf(RUNTIME_CLASS(AWeapon)))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
weap = static_cast<AWeapon *>(Owner->FindInventory (weapontype));
|
|
|
|
if (weap == NULL)
|
|
|
|
{
|
2006-07-16 09:10:45 +00:00
|
|
|
weap = static_cast<AWeapon *>(Spawn (weapontype, 0, 0, 0, NO_REPLACE));
|
2006-02-24 04:48:15 +00:00
|
|
|
weap->AttachToOwner (Owner);
|
|
|
|
}
|
|
|
|
return weap;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: ShouldStay
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
bool AWeapon::ShouldStay ()
|
|
|
|
{
|
|
|
|
if (((multiplayer &&
|
|
|
|
(!deathmatch && !alwaysapplydmflags)) || (dmflags & DF_WEAPONS_STAY)) &&
|
|
|
|
!(flags & MF_DROPPED))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: CheckAmmo
|
|
|
|
//
|
|
|
|
// Returns true if there is enough ammo to shoot. If not, selects the
|
|
|
|
// next weapon to use.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2012-04-07 11:33:35 +00:00
|
|
|
bool AWeapon::CheckAmmo (int fireMode, bool autoSwitch, bool requireAmmo, int ammocount)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int altFire;
|
|
|
|
int count1, count2;
|
|
|
|
int enough, enoughmask;
|
2012-04-07 11:33:35 +00:00
|
|
|
int lAmmoUse1;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-06-07 16:38:19 +00:00
|
|
|
if ((dmflags & DF_INFINITE_AMMO) || (Owner->player->cheats & CF_INFINITEAMMO))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (fireMode == EitherFire)
|
|
|
|
{
|
|
|
|
bool gotSome = CheckAmmo (PrimaryFire, false) || CheckAmmo (AltFire, false);
|
|
|
|
if (!gotSome && autoSwitch)
|
|
|
|
{
|
2008-03-12 02:56:11 +00:00
|
|
|
barrier_cast<APlayerPawn *>(Owner)->PickNewWeapon (NULL);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
return gotSome;
|
|
|
|
}
|
|
|
|
altFire = (fireMode == AltFire);
|
|
|
|
if (!requireAmmo && (WeaponFlags & (WIF_AMMO_OPTIONAL << altFire)))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
count1 = (Ammo1 != NULL) ? Ammo1->Amount : 0;
|
|
|
|
count2 = (Ammo2 != NULL) ? Ammo2->Amount : 0;
|
|
|
|
|
2012-05-05 14:23:00 +00:00
|
|
|
if ((WeaponFlags & WIF_DEHAMMO) && (Ammo1 == NULL))
|
|
|
|
{
|
|
|
|
lAmmoUse1 = 0;
|
|
|
|
}
|
|
|
|
else if (ammocount >= 0 && (WeaponFlags & WIF_DEHAMMO))
|
2012-04-07 11:33:35 +00:00
|
|
|
{
|
|
|
|
lAmmoUse1 = ammocount;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lAmmoUse1 = AmmoUse1;
|
|
|
|
}
|
|
|
|
|
|
|
|
enough = (count1 >= lAmmoUse1) | ((count2 >= AmmoUse2) << 1);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (WeaponFlags & (WIF_PRIMARY_USES_BOTH << altFire))
|
|
|
|
{
|
|
|
|
enoughmask = 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
enoughmask = 1 << altFire;
|
|
|
|
}
|
2006-10-31 14:53:21 +00:00
|
|
|
if (altFire && FindState(NAME_AltFire) == NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{ // If this weapon has no alternate fire, then there is never enough ammo for it
|
|
|
|
enough &= 1;
|
|
|
|
}
|
2009-05-31 22:14:23 +00:00
|
|
|
if (((enough & enoughmask) == enoughmask) || (enough && (WeaponFlags & WIF_AMMO_CHECKBOTH)))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// out of ammo, pick a weapon to change to
|
|
|
|
if (autoSwitch)
|
|
|
|
{
|
2008-03-12 02:56:11 +00:00
|
|
|
barrier_cast<APlayerPawn *>(Owner)->PickNewWeapon (NULL);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: DepleteAmmo
|
|
|
|
//
|
|
|
|
// Use up some of the weapon's ammo. Returns true if the ammo was successfully
|
|
|
|
// depleted. If checkEnough is false, then the ammo will always be depleted,
|
|
|
|
// even if it drops below zero.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2012-04-07 11:33:35 +00:00
|
|
|
bool AWeapon::DepleteAmmo (bool altFire, bool checkEnough, int ammouse)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-06-07 16:38:19 +00:00
|
|
|
if (!((dmflags & DF_INFINITE_AMMO) || (Owner->player->cheats & CF_INFINITEAMMO)))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2012-04-07 11:33:35 +00:00
|
|
|
if (checkEnough && !CheckAmmo (altFire ? AltFire : PrimaryFire, false, false, ammouse))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!altFire)
|
|
|
|
{
|
|
|
|
if (Ammo1 != NULL)
|
|
|
|
{
|
2012-04-07 11:33:35 +00:00
|
|
|
if (ammouse >= 0 && (WeaponFlags & WIF_DEHAMMO))
|
|
|
|
{
|
|
|
|
Ammo1->Amount -= ammouse;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Ammo1->Amount -= AmmoUse1;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
if ((WeaponFlags & WIF_PRIMARY_USES_BOTH) && Ammo2 != NULL)
|
|
|
|
{
|
|
|
|
Ammo2->Amount -= AmmoUse2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (Ammo2 != NULL)
|
|
|
|
{
|
|
|
|
Ammo2->Amount -= AmmoUse2;
|
|
|
|
}
|
|
|
|
if ((WeaponFlags & WIF_ALT_USES_BOTH) && Ammo1 != NULL)
|
|
|
|
{
|
|
|
|
Ammo1->Amount -= AmmoUse1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Ammo1 != NULL && Ammo1->Amount < 0)
|
|
|
|
Ammo1->Amount = 0;
|
|
|
|
if (Ammo2 != NULL && Ammo2->Amount < 0)
|
|
|
|
Ammo2->Amount = 0;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: PostMorphWeapon
|
|
|
|
//
|
|
|
|
// Bring this weapon up after a player unmorphs.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void AWeapon::PostMorphWeapon ()
|
|
|
|
{
|
2012-05-01 03:43:14 +00:00
|
|
|
if (Owner == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
Owner->player->PendingWeapon = WP_NOCHANGE;
|
|
|
|
Owner->player->ReadyWeapon = this;
|
|
|
|
Owner->player->psprites[ps_weapon].sy = WEAPONBOTTOM;
|
2009-08-29 15:50:03 +00:00
|
|
|
Owner->player->refire = 0;
|
2006-10-31 14:53:21 +00:00
|
|
|
P_SetPsprite (Owner->player, ps_weapon, GetUpState());
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: EndPowerUp
|
|
|
|
//
|
|
|
|
// The Tome of Power just expired.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void AWeapon::EndPowerup ()
|
|
|
|
{
|
2006-05-07 23:55:17 +00:00
|
|
|
if (SisterWeapon != NULL && WeaponFlags&WIF_POWERED_UP)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-10-31 14:53:21 +00:00
|
|
|
if (GetReadyState() != SisterWeapon->GetReadyState())
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2007-10-19 08:49:02 +00:00
|
|
|
if (Owner->player->PendingWeapon == NULL ||
|
|
|
|
Owner->player->PendingWeapon == WP_NOCHANGE)
|
2007-04-29 08:44:32 +00:00
|
|
|
Owner->player->PendingWeapon = SisterWeapon;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Owner->player->ReadyWeapon = SisterWeapon;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: GetUpState
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
FState *AWeapon::GetUpState ()
|
|
|
|
{
|
2006-10-31 14:53:21 +00:00
|
|
|
return FindState(NAME_Select);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: GetDownState
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
FState *AWeapon::GetDownState ()
|
|
|
|
{
|
2006-10-31 14:53:21 +00:00
|
|
|
return FindState(NAME_Deselect);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: GetReadyState
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
FState *AWeapon::GetReadyState ()
|
|
|
|
{
|
2006-10-31 14:53:21 +00:00
|
|
|
return FindState(NAME_Ready);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// AWeapon :: GetAtkState
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2006-10-31 14:53:21 +00:00
|
|
|
FState *AWeapon::GetAtkState (bool hold)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-10-31 14:53:21 +00:00
|
|
|
FState * state=NULL;
|
|
|
|
|
|
|
|
if (hold) state = FindState(NAME_Hold);
|
|
|
|
if (state == NULL) state = FindState(NAME_Fire);
|
|
|
|
return state;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
2006-10-31 14:53:21 +00:00
|
|
|
// AWeapon :: GetAtkState
|
2006-02-24 04:48:15 +00:00
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2006-10-31 14:53:21 +00:00
|
|
|
FState *AWeapon::GetAltAtkState (bool hold)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-10-31 14:53:21 +00:00
|
|
|
FState * state=NULL;
|
|
|
|
|
|
|
|
if (hold) state = FindState(NAME_AltHold);
|
|
|
|
if (state == NULL) state = FindState(NAME_AltFire);
|
|
|
|
return state;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2012-04-07 13:07:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
2015-12-31 22:41:09 +00:00
|
|
|
// AWeapon :: GetStateForButtonName
|
2012-04-07 13:07:25 +00:00
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2015-12-31 22:41:09 +00:00
|
|
|
FState *AWeapon::GetStateForButtonName (FName button)
|
2012-04-07 13:07:25 +00:00
|
|
|
{
|
2015-12-31 22:41:09 +00:00
|
|
|
return FindState(button);
|
2012-04-07 13:07:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-08 10:24:08 +00:00
|
|
|
/* Weapon giver ***********************************************************/
|
|
|
|
|
2008-08-09 11:35:42 +00:00
|
|
|
IMPLEMENT_CLASS(AWeaponGiver)
|
2008-08-08 10:24:08 +00:00
|
|
|
|
2013-05-02 00:24:53 +00:00
|
|
|
void AWeaponGiver::Serialize(FArchive &arc)
|
|
|
|
{
|
|
|
|
Super::Serialize(arc);
|
|
|
|
if (SaveVersion >= 4246)
|
|
|
|
{
|
|
|
|
arc << DropAmmoFactor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-13 22:08:41 +00:00
|
|
|
bool AWeaponGiver::TryPickup(AActor *&toucher)
|
2008-08-08 10:24:08 +00:00
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
DDropItem *di = GetDropItems();
|
2009-06-19 21:00:18 +00:00
|
|
|
AWeapon *weap;
|
2008-08-08 10:24:08 +00:00
|
|
|
|
|
|
|
if (di != NULL)
|
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
PClassWeapon *ti = dyn_cast<PClassWeapon>(PClass::FindClass(di->Name));
|
|
|
|
if (ti != NULL)
|
2008-08-08 10:24:08 +00:00
|
|
|
{
|
2009-06-19 21:00:18 +00:00
|
|
|
if (master == NULL)
|
2008-08-08 10:24:08 +00:00
|
|
|
{
|
2009-06-19 21:00:18 +00:00
|
|
|
master = weap = static_cast<AWeapon*>(Spawn(di->Name, 0, 0, 0, NO_REPLACE));
|
|
|
|
if (weap != NULL)
|
|
|
|
{
|
|
|
|
weap->ItemFlags &= ~IF_ALWAYSPICKUP; // use the flag of this item only.
|
2012-10-11 04:38:52 +00:00
|
|
|
weap->flags = (weap->flags & ~MF_DROPPED) | (this->flags & MF_DROPPED);
|
2013-04-30 03:07:39 +00:00
|
|
|
|
2013-05-02 00:24:53 +00:00
|
|
|
// If our ammo gives are non-negative, transfer them to the real weapon.
|
2009-06-19 21:00:18 +00:00
|
|
|
if (AmmoGive1 >= 0) weap->AmmoGive1 = AmmoGive1;
|
|
|
|
if (AmmoGive2 >= 0) weap->AmmoGive2 = AmmoGive2;
|
2013-04-30 03:07:39 +00:00
|
|
|
|
2013-05-02 00:24:53 +00:00
|
|
|
// If DropAmmoFactor is non-negative, modify the given ammo amounts.
|
|
|
|
if (DropAmmoFactor > 0)
|
2013-04-30 03:07:39 +00:00
|
|
|
{
|
2013-05-02 00:24:53 +00:00
|
|
|
weap->AmmoGive1 = FixedMul(weap->AmmoGive1, DropAmmoFactor);
|
|
|
|
weap->AmmoGive2 = FixedMul(weap->AmmoGive2, DropAmmoFactor);
|
2013-04-30 03:07:39 +00:00
|
|
|
}
|
2009-06-19 21:00:18 +00:00
|
|
|
weap->BecomeItem();
|
|
|
|
}
|
|
|
|
else return false;
|
2008-08-08 10:24:08 +00:00
|
|
|
}
|
2009-06-19 21:00:18 +00:00
|
|
|
|
|
|
|
weap = barrier_cast<AWeapon*>(master);
|
|
|
|
bool res = weap->CallTryPickup(toucher);
|
2012-10-11 04:38:52 +00:00
|
|
|
if (res)
|
|
|
|
{
|
|
|
|
GoAwayAndDie();
|
|
|
|
master = NULL;
|
|
|
|
}
|
2009-06-19 21:00:18 +00:00
|
|
|
return res;
|
2008-08-08 10:24:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
/* Weapon slots ***********************************************************/
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlot :: AddWeapon
|
|
|
|
//
|
|
|
|
// Adds a weapon to the end of the slot if it isn't already in it.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
bool FWeaponSlot::AddWeapon(const char *type)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
return AddWeapon(static_cast<PClassWeapon *>(PClass::FindClass(type)));
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
bool FWeaponSlot::AddWeapon(PClassWeapon *type)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
unsigned int i;
|
2008-08-02 08:38:07 +00:00
|
|
|
|
|
|
|
if (type == NULL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!type->IsDescendantOf(RUNTIME_CLASS(AWeapon)))
|
|
|
|
{
|
|
|
|
Printf("Can't add non-weapon %s to weapon slots\n", type->TypeName.GetChars());
|
|
|
|
return false;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
for (i = 0; i < Weapons.Size(); i++)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
if (Weapons[i].Type == type)
|
2006-02-24 04:48:15 +00:00
|
|
|
return true; // Already present
|
|
|
|
}
|
2009-02-20 00:53:25 +00:00
|
|
|
WeaponInfo info = { type, -1 };
|
|
|
|
Weapons.Push(info);
|
2006-02-24 04:48:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlot :: AddWeaponList
|
|
|
|
//
|
|
|
|
// Appends all the weapons from the space-delimited list to this slot.
|
|
|
|
// Set clear to true to remove any weapons already in this slot first.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FWeaponSlot :: AddWeaponList(const char *list, bool clear)
|
|
|
|
{
|
|
|
|
FString copy(list);
|
|
|
|
char *buff = copy.LockBuffer();
|
|
|
|
char *tok;
|
|
|
|
|
|
|
|
if (clear)
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
tok = strtok(buff, " ");
|
|
|
|
while (tok != NULL)
|
|
|
|
{
|
|
|
|
AddWeapon(tok);
|
|
|
|
tok = strtok(NULL, " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlot :: LocateWeapon
|
|
|
|
//
|
|
|
|
// Returns the index for the specified weapon in this slot, or -1 if it isn't
|
|
|
|
// in this slot.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
int FWeaponSlot::LocateWeapon(PClassWeapon *type)
|
2009-02-20 00:53:25 +00:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < Weapons.Size(); ++i)
|
|
|
|
{
|
|
|
|
if (Weapons[i].Type == type)
|
|
|
|
{
|
|
|
|
return (int)i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlot :: PickWeapon
|
|
|
|
//
|
|
|
|
// Picks a weapon from this slot. If no weapon is selected in this slot,
|
|
|
|
// or the first weapon in this slot is selected, returns the last weapon.
|
|
|
|
// Otherwise, returns the previous weapon in this slot. This means
|
|
|
|
// precedence is given to the last weapon in the slot, which by convention
|
|
|
|
// is probably the strongest. Does not return weapons you have no ammo
|
|
|
|
// for or which you do not possess.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2010-05-30 07:47:08 +00:00
|
|
|
AWeapon *FWeaponSlot::PickWeapon(player_t *player, bool checkammo)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
2011-04-17 17:10:47 +00:00
|
|
|
if (player->mo == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-02-20 00:53:25 +00:00
|
|
|
// Does this slot even have any weapons?
|
|
|
|
if (Weapons.Size() == 0)
|
|
|
|
{
|
|
|
|
return player->ReadyWeapon;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
if (player->ReadyWeapon != NULL)
|
|
|
|
{
|
2009-03-10 23:07:37 +00:00
|
|
|
for (i = 0; (unsigned)i < Weapons.Size(); i++)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
if (Weapons[i].Type == player->ReadyWeapon->GetClass() ||
|
2006-02-24 04:48:15 +00:00
|
|
|
(player->ReadyWeapon->WeaponFlags & WIF_POWERED_UP &&
|
|
|
|
player->ReadyWeapon->SisterWeapon != NULL &&
|
2009-02-20 00:53:25 +00:00
|
|
|
player->ReadyWeapon->SisterWeapon->GetClass() == Weapons[i].Type))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-08-04 23:19:09 +00:00
|
|
|
for (j = (i == 0 ? Weapons.Size() - 1 : i - 1);
|
2006-02-24 04:48:15 +00:00
|
|
|
j != i;
|
2009-08-04 23:19:09 +00:00
|
|
|
j = (j == 0 ? Weapons.Size() - 1 : j - 1))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
AWeapon *weap = static_cast<AWeapon *> (player->mo->FindInventory(Weapons[j].Type));
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2010-05-30 07:47:08 +00:00
|
|
|
if (weap != NULL && weap->IsKindOf(RUNTIME_CLASS(AWeapon)))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2010-05-30 07:47:08 +00:00
|
|
|
if (!checkammo || weap->CheckAmmo(AWeapon::EitherFire, false))
|
|
|
|
{
|
|
|
|
return weap;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-20 00:53:25 +00:00
|
|
|
for (i = Weapons.Size() - 1; i >= 0; i--)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
AWeapon *weap = static_cast<AWeapon *> (player->mo->FindInventory(Weapons[i].Type));
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2010-05-30 07:47:08 +00:00
|
|
|
if (weap != NULL && weap->IsKindOf(RUNTIME_CLASS(AWeapon)))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2010-05-30 07:47:08 +00:00
|
|
|
if (!checkammo || weap->CheckAmmo(AWeapon::EitherFire, false))
|
|
|
|
{
|
|
|
|
return weap;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return player->ReadyWeapon;
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlot :: SetInitialPositions
|
|
|
|
//
|
|
|
|
// Fills in the position field for every weapon currently in the slot based
|
|
|
|
// on its position in the slot. These are not scaled to [0,1] so that extra
|
|
|
|
// weapons can use those values to go to the start or end of the slot.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FWeaponSlot::SetInitialPositions()
|
|
|
|
{
|
|
|
|
unsigned int size = Weapons.Size(), i;
|
|
|
|
|
|
|
|
if (size == 1)
|
|
|
|
{
|
|
|
|
Weapons[0].Position = 0x8000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < size; ++i)
|
|
|
|
{
|
|
|
|
Weapons[i].Position = i * 0xFF00 / (size - 1) + 0x80;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlot :: Sort
|
|
|
|
//
|
|
|
|
// Rearranges the weapons by their position field.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FWeaponSlot::Sort()
|
|
|
|
{
|
|
|
|
// This does not use qsort(), because the sort should be stable, and
|
|
|
|
// there is no guarantee that qsort() is stable. This insertion sort
|
|
|
|
// should be fine.
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 1; i < (int)Weapons.Size(); ++i)
|
|
|
|
{
|
|
|
|
fixed_t pos = Weapons[i].Position;
|
2010-03-25 20:38:00 +00:00
|
|
|
PClassWeapon *type = Weapons[i].Type;
|
2009-02-20 00:53:25 +00:00
|
|
|
for (j = i - 1; j >= 0 && Weapons[j].Position > pos; --j)
|
|
|
|
{
|
|
|
|
Weapons[j + 1] = Weapons[j];
|
|
|
|
}
|
|
|
|
Weapons[j + 1].Type = type;
|
|
|
|
Weapons[j + 1].Position = pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-12 03:54:23 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlots - Copy Constructor
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
FWeaponSlots::FWeaponSlots(const FWeaponSlots &other)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < NUM_WEAPON_SLOTS; ++i)
|
|
|
|
{
|
|
|
|
Slots[i] = other.Slots[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlots :: Clear
|
|
|
|
//
|
|
|
|
// Removes all weapons from every slot.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FWeaponSlots::Clear()
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < NUM_WEAPON_SLOTS; ++i)
|
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
Slots[i].Clear();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlots :: AddDefaultWeapon
|
|
|
|
//
|
2006-02-24 04:48:15 +00:00
|
|
|
// If the weapon already exists in a slot, don't add it. If it doesn't,
|
2009-02-20 00:53:25 +00:00
|
|
|
// then add it to the specified slot.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
ESlotDef FWeaponSlots::AddDefaultWeapon (int slot, PClassWeapon *type)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int currSlot, index;
|
|
|
|
|
|
|
|
if (!LocateWeapon (type, &currSlot, &index))
|
|
|
|
{
|
|
|
|
if (slot >= 0 && slot < NUM_WEAPON_SLOTS)
|
|
|
|
{
|
|
|
|
bool added = Slots[slot].AddWeapon (type);
|
|
|
|
return added ? SLOTDEF_Added : SLOTDEF_Full;
|
|
|
|
}
|
|
|
|
return SLOTDEF_Full;
|
|
|
|
}
|
|
|
|
return SLOTDEF_Exists;
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlots :: LocateWeapon
|
|
|
|
//
|
|
|
|
// Returns true if the weapon is in a slot, false otherwise. If the weapon
|
|
|
|
// is found, it can also optionally return the slot and index for it.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
bool FWeaponSlots::LocateWeapon (PClassWeapon *type, int *const slot, int *const index)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_WEAPON_SLOTS; i++)
|
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
j = Slots[i].LocateWeapon(type);
|
|
|
|
if (j >= 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
if (slot != NULL) *slot = i;
|
|
|
|
if (index != NULL) *index = j;
|
|
|
|
return true;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FindMostRecentWeapon
|
|
|
|
//
|
|
|
|
// Locates the slot and index for the most recently selected weapon. If the
|
|
|
|
// player is in the process of switching to a new weapon, that is the most
|
|
|
|
// recently selected weapon. Otherwise, the current weapon is the most recent
|
|
|
|
// weapon.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
static bool FindMostRecentWeapon(player_t *player, int *slot, int *index)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
if (player->PendingWeapon != WP_NOCHANGE)
|
|
|
|
{
|
2009-02-20 22:28:48 +00:00
|
|
|
return player->weapons.LocateWeapon(player->PendingWeapon->GetClass(), slot, index);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else if (player->ReadyWeapon != NULL)
|
|
|
|
{
|
|
|
|
AWeapon *weap = player->ReadyWeapon;
|
2009-02-20 22:28:48 +00:00
|
|
|
if (!player->weapons.LocateWeapon(weap->GetClass(), slot, index))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
// If the current weapon wasn't found and is powered up,
|
|
|
|
// look for its non-powered up version.
|
2006-02-24 04:48:15 +00:00
|
|
|
if (weap->WeaponFlags & WIF_POWERED_UP && weap->SisterWeaponType != NULL)
|
|
|
|
{
|
2009-02-20 22:28:48 +00:00
|
|
|
return player->weapons.LocateWeapon(weap->SisterWeaponType, slot, index);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlots :: PickNextWeapon
|
|
|
|
//
|
|
|
|
// Returns the "next" weapon for this player. If the current weapon is not
|
|
|
|
// in a slot, then it just returns that weapon, since there's nothing to
|
|
|
|
// consider it relative to.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
AWeapon *FWeaponSlots::PickNextWeapon(player_t *player)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int startslot, startindex;
|
2009-06-09 07:45:04 +00:00
|
|
|
int slotschecked = 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-06-24 03:32:28 +00:00
|
|
|
if (player->mo == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-02-20 00:53:25 +00:00
|
|
|
if (player->ReadyWeapon == NULL || FindMostRecentWeapon(player, &startslot, &startindex))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
int slot;
|
|
|
|
int index;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (player->ReadyWeapon == NULL)
|
|
|
|
{
|
|
|
|
startslot = NUM_WEAPON_SLOTS - 1;
|
2009-02-20 00:53:25 +00:00
|
|
|
startindex = Slots[startslot].Size() - 1;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
slot = startslot;
|
|
|
|
index = startindex;
|
|
|
|
do
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
if (++index >= Slots[slot].Size())
|
|
|
|
{
|
|
|
|
index = 0;
|
2009-06-09 07:45:04 +00:00
|
|
|
slotschecked++;
|
2009-02-20 00:53:25 +00:00
|
|
|
if (++slot >= NUM_WEAPON_SLOTS)
|
|
|
|
{
|
|
|
|
slot = 0;
|
|
|
|
}
|
|
|
|
}
|
2010-03-25 20:38:00 +00:00
|
|
|
PClassWeapon *type = Slots[slot].GetWeapon(index);
|
2009-02-20 00:53:25 +00:00
|
|
|
AWeapon *weap = static_cast<AWeapon *>(player->mo->FindInventory(type));
|
|
|
|
if (weap != NULL && weap->CheckAmmo(AWeapon::EitherFire, false))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
return weap;
|
|
|
|
}
|
|
|
|
}
|
2014-06-01 06:11:50 +00:00
|
|
|
while ((slot != startslot || index != startindex) && slotschecked <= NUM_WEAPON_SLOTS);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
return player->ReadyWeapon;
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlots :: PickPrevWeapon
|
|
|
|
//
|
|
|
|
// Returns the "previous" weapon for this player. If the current weapon is
|
|
|
|
// not in a slot, then it just returns that weapon, since there's nothing to
|
|
|
|
// consider it relative to.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
AWeapon *FWeaponSlots::PickPrevWeapon (player_t *player)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int startslot, startindex;
|
2009-06-09 07:45:04 +00:00
|
|
|
int slotschecked = 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2008-06-24 03:32:28 +00:00
|
|
|
if (player->mo == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
if (player->ReadyWeapon == NULL || FindMostRecentWeapon (player, &startslot, &startindex))
|
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
int slot;
|
|
|
|
int index;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (player->ReadyWeapon == NULL)
|
|
|
|
{
|
|
|
|
startslot = 0;
|
|
|
|
startindex = 0;
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
slot = startslot;
|
|
|
|
index = startindex;
|
|
|
|
do
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
if (--index < 0)
|
|
|
|
{
|
2009-06-09 07:45:04 +00:00
|
|
|
slotschecked++;
|
2009-02-20 00:53:25 +00:00
|
|
|
if (--slot < 0)
|
|
|
|
{
|
|
|
|
slot = NUM_WEAPON_SLOTS - 1;
|
|
|
|
}
|
|
|
|
index = Slots[slot].Size() - 1;
|
|
|
|
}
|
2010-03-25 20:38:00 +00:00
|
|
|
PClassWeapon *type = Slots[slot].GetWeapon(index);
|
2009-02-20 00:53:25 +00:00
|
|
|
AWeapon *weap = static_cast<AWeapon *>(player->mo->FindInventory(type));
|
|
|
|
if (weap != NULL && weap->CheckAmmo(AWeapon::EitherFire, false))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
return weap;
|
|
|
|
}
|
|
|
|
}
|
2014-06-01 06:11:50 +00:00
|
|
|
while ((slot != startslot || index != startindex) && slotschecked <= NUM_WEAPON_SLOTS);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
return player->ReadyWeapon;
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlots :: AddExtraWeapons
|
|
|
|
//
|
|
|
|
// For every weapon class for the current game, add it to its desired slot
|
|
|
|
// and position within the slot. Does not first clear the slots.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FWeaponSlots::AddExtraWeapons()
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
unsigned int i;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
// Set fractional positions for current weapons.
|
|
|
|
for (i = 0; i < NUM_WEAPON_SLOTS; ++i)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
Slots[i].SetInitialPositions();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
// Append extra weapons to the slots.
|
2010-04-16 02:57:51 +00:00
|
|
|
for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2010-04-16 02:57:51 +00:00
|
|
|
PClass *cls = PClassActor::AllActorClasses[i];
|
2009-02-20 00:53:25 +00:00
|
|
|
|
2010-03-24 02:49:37 +00:00
|
|
|
if (!cls->IsDescendantOf(RUNTIME_CLASS(AWeapon)))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2010-03-25 20:38:00 +00:00
|
|
|
PClassWeapon *acls = static_cast<PClassWeapon *>(cls);
|
2010-03-24 02:49:37 +00:00
|
|
|
if ((acls->GameFilter == GAME_Any || (acls->GameFilter & gameinfo.gametype)) &&
|
|
|
|
acls->Replacement == NULL && // Replaced weapons don't get slotted.
|
2012-07-14 03:04:41 +00:00
|
|
|
!(((AWeapon *)(acls->Defaults))->WeaponFlags & WIF_POWERED_UP) &&
|
2010-03-24 02:49:37 +00:00
|
|
|
!LocateWeapon(acls, NULL, NULL) // Don't duplicate it if it's already present.
|
2009-02-20 00:53:25 +00:00
|
|
|
)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
int slot = acls->SlotNumber;
|
2009-02-20 00:53:25 +00:00
|
|
|
if ((unsigned)slot < NUM_WEAPON_SLOTS)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
FWeaponSlot::WeaponInfo info = { acls, acls->SlotPriority };
|
2009-02-20 00:53:25 +00:00
|
|
|
Slots[slot].Weapons.Push(info);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
// Now resort every slot to put the new weapons in their proper places.
|
|
|
|
for (i = 0; i < NUM_WEAPON_SLOTS; ++i)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
Slots[i].Sort();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2009-02-20 00:53:25 +00:00
|
|
|
}
|
|
|
|
|
2009-04-04 17:46:33 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlots :: SetFromGameInfo
|
|
|
|
//
|
|
|
|
// If neither the player class nor any defined weapon contain a
|
|
|
|
// slot assignment, use the game's defaults
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void FWeaponSlots::SetFromGameInfo()
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
// Only if all slots are empty
|
|
|
|
for (i = 0; i < NUM_WEAPON_SLOTS; ++i)
|
|
|
|
{
|
|
|
|
if (Slots[i].Size() > 0) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append extra weapons to the slots.
|
|
|
|
for (i = 0; i < NUM_WEAPON_SLOTS; ++i)
|
|
|
|
{
|
|
|
|
for (unsigned j = 0; j < gameinfo.DefaultWeaponSlots[i].Size(); i++)
|
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
PClassWeapon *cls = dyn_cast<PClassWeapon>(PClass::FindClass(gameinfo.DefaultWeaponSlots[i][j]));
|
2009-04-04 17:46:33 +00:00
|
|
|
if (cls == NULL)
|
|
|
|
{
|
|
|
|
Printf("Unknown weapon class '%s' found in default weapon slot assignments\n",
|
|
|
|
gameinfo.DefaultWeaponSlots[i][j].GetChars());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Slots[i].AddWeapon(cls);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
2009-03-12 03:54:23 +00:00
|
|
|
// FWeaponSlots :: StandardSetup
|
2009-02-20 00:53:25 +00:00
|
|
|
//
|
2009-03-12 03:54:23 +00:00
|
|
|
// Setup weapons in this order:
|
2009-02-20 00:53:25 +00:00
|
|
|
// 1. Use slots from player class.
|
2009-03-12 03:54:23 +00:00
|
|
|
// 2. Add extra weapons that specify their own slots.
|
2009-04-04 17:46:33 +00:00
|
|
|
// 3. If all slots are empty, use the settings from the gameinfo (compatibility fallback)
|
2009-03-12 03:54:23 +00:00
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
void FWeaponSlots::StandardSetup(PClassPlayerPawn *type)
|
2009-03-12 03:54:23 +00:00
|
|
|
{
|
|
|
|
SetFromPlayer(type);
|
|
|
|
AddExtraWeapons();
|
2009-04-04 17:46:33 +00:00
|
|
|
SetFromGameInfo();
|
2009-03-12 03:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlots :: LocalSetup
|
|
|
|
//
|
|
|
|
// Setup weapons in this order:
|
|
|
|
// 1. Run KEYCONF weapon commands, affecting slots accordingly.
|
|
|
|
// 2. Read config slots, overriding current slots. If WeaponSection is set,
|
2009-02-20 00:53:25 +00:00
|
|
|
// then [<WeaponSection>.<PlayerClass>.Weapons] is tried, followed by
|
|
|
|
// [<WeaponSection>.Weapons] if that did not exist. If WeaponSection is
|
|
|
|
// empty, then the slots are read from [<PlayerClass>.Weapons].
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2010-03-24 02:49:37 +00:00
|
|
|
void FWeaponSlots::LocalSetup(PClassActor *type)
|
2009-02-20 00:53:25 +00:00
|
|
|
{
|
2009-03-12 03:54:23 +00:00
|
|
|
P_PlaybackKeyConfWeapons(this);
|
2009-02-20 00:53:25 +00:00
|
|
|
if (WeaponSection.IsNotEmpty())
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
FString sectionclass(WeaponSection);
|
|
|
|
sectionclass << '.' << type->TypeName.GetChars();
|
|
|
|
if (RestoreSlots(GameConfig, sectionclass) == 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
RestoreSlots(GameConfig, WeaponSection);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-20 00:53:25 +00:00
|
|
|
else
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
RestoreSlots(GameConfig, type->TypeName.GetChars());
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2009-02-20 00:53:25 +00:00
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-03-12 03:54:23 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlots :: SendDifferences
|
|
|
|
//
|
|
|
|
// Sends the weapon slots from this instance that differ from other's.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2012-03-22 22:29:25 +00:00
|
|
|
void FWeaponSlots::SendDifferences(int playernum, const FWeaponSlots &other)
|
2009-02-20 22:28:48 +00:00
|
|
|
{
|
2009-03-12 03:54:23 +00:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_WEAPON_SLOTS; ++i)
|
2009-02-20 22:28:48 +00:00
|
|
|
{
|
2009-03-12 03:54:23 +00:00
|
|
|
if (other.Slots[i].Size() == Slots[i].Size())
|
2009-02-20 22:28:48 +00:00
|
|
|
{
|
2009-03-12 03:54:23 +00:00
|
|
|
for (j = (int)Slots[i].Size(); j-- > 0; )
|
2009-02-24 05:58:59 +00:00
|
|
|
{
|
2009-03-12 03:54:23 +00:00
|
|
|
if (other.Slots[i].GetWeapon(j) != Slots[i].GetWeapon(j))
|
2009-03-11 00:42:04 +00:00
|
|
|
{
|
2009-03-12 03:54:23 +00:00
|
|
|
break;
|
2009-03-11 00:42:04 +00:00
|
|
|
}
|
2009-02-24 05:58:59 +00:00
|
|
|
}
|
2009-03-12 03:54:23 +00:00
|
|
|
if (j < 0)
|
|
|
|
{ // The two slots are the same.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// The slots differ. Send mine.
|
2012-03-22 22:29:25 +00:00
|
|
|
if (playernum == consoleplayer)
|
|
|
|
{
|
|
|
|
Net_WriteByte(DEM_SETSLOT);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Net_WriteByte(DEM_SETSLOTPNUM);
|
|
|
|
Net_WriteByte(playernum);
|
|
|
|
}
|
2009-03-12 03:54:23 +00:00
|
|
|
Net_WriteByte(i);
|
|
|
|
Net_WriteByte(Slots[i].Size());
|
|
|
|
for (j = 0; j < Slots[i].Size(); ++j)
|
|
|
|
{
|
|
|
|
Net_WriteWeapon(Slots[i].GetWeapon(j));
|
2009-02-20 22:28:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlots :: SetFromPlayer
|
|
|
|
//
|
|
|
|
// Sets all weapon slots according to the player class.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
void FWeaponSlots::SetFromPlayer(PClassPlayerPawn *type)
|
2009-02-20 00:53:25 +00:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
for (int i = 0; i < NUM_WEAPON_SLOTS; ++i)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
if (!type->Slot[i].IsEmpty())
|
2009-02-20 00:53:25 +00:00
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
Slots[i].AddWeaponList(type->Slot[i], false);
|
2009-02-20 00:53:25 +00:00
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// FWeaponSlots :: RestoreSlots
|
|
|
|
//
|
|
|
|
// Reads slots from a config section. Any slots in the section override
|
|
|
|
// existing slot settings, while slots not present in the config are
|
|
|
|
// unaffected. Returns the number of slots read.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
int FWeaponSlots::RestoreSlots(FConfigFile *config, const char *section)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
FString section_name(section);
|
|
|
|
const char *key, *value;
|
|
|
|
int slotsread = 0;
|
|
|
|
|
|
|
|
section_name += ".Weapons";
|
|
|
|
if (!config->SetSection(section_name))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
return 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2009-02-20 00:53:25 +00:00
|
|
|
while (config->NextInSection (key, value))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
if (strnicmp (key, "Slot[", 5) != 0 ||
|
|
|
|
key[5] < '0' ||
|
|
|
|
key[5] > '0'+NUM_WEAPON_SLOTS ||
|
|
|
|
key[6] != ']' ||
|
|
|
|
key[7] != 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
continue;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2009-02-20 00:53:25 +00:00
|
|
|
Slots[key[5] - '0'].AddWeaponList(value, true);
|
|
|
|
slotsread++;
|
|
|
|
}
|
|
|
|
return slotsread;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// CCMD setslot
|
|
|
|
//
|
|
|
|
//===========================================================================
|
2009-02-20 22:28:48 +00:00
|
|
|
|
|
|
|
void FWeaponSlots::PrintSettings()
|
|
|
|
{
|
|
|
|
for (int i = 1; i <= NUM_WEAPON_SLOTS; ++i)
|
|
|
|
{
|
|
|
|
int slot = i % NUM_WEAPON_SLOTS;
|
|
|
|
if (Slots[slot].Size() > 0)
|
|
|
|
{
|
|
|
|
Printf("Slot[%d]=", slot);
|
|
|
|
for (int j = 0; j < Slots[slot].Size(); ++j)
|
|
|
|
{
|
|
|
|
Printf("%s ", Slots[slot].GetWeapon(j)->TypeName.GetChars());
|
|
|
|
}
|
|
|
|
Printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
CCMD (setslot)
|
|
|
|
{
|
|
|
|
int slot;
|
|
|
|
|
|
|
|
if (argv.argc() < 2 || (slot = atoi (argv[1])) >= NUM_WEAPON_SLOTS)
|
|
|
|
{
|
|
|
|
Printf("Usage: setslot [slot] [weapons]\nCurrent slot assignments:\n");
|
|
|
|
if (players[consoleplayer].mo != NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
FString config(GameConfig->GetConfigPath(false));
|
|
|
|
Printf(TEXTCOLOR_BLUE "Add the following to " TEXTCOLOR_ORANGE "%s" TEXTCOLOR_BLUE
|
|
|
|
" to retain these bindings:\n" TEXTCOLOR_NORMAL "[", config.GetChars());
|
|
|
|
if (WeaponSection.IsNotEmpty())
|
|
|
|
{
|
|
|
|
Printf("%s.", WeaponSection.GetChars());
|
|
|
|
}
|
|
|
|
Printf("%s.Weapons]\n", players[consoleplayer].mo->GetClass()->TypeName.GetChars());
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2009-02-20 22:28:48 +00:00
|
|
|
players[consoleplayer].weapons.PrintSettings();
|
2009-02-20 00:53:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ParsingKeyConf)
|
|
|
|
{
|
|
|
|
KeyConfWeapons.Push(argv.args());
|
|
|
|
}
|
2009-03-12 03:54:23 +00:00
|
|
|
else if (PlayingKeyConf != NULL)
|
2009-02-20 22:28:48 +00:00
|
|
|
{
|
2009-03-12 03:54:23 +00:00
|
|
|
PlayingKeyConf->Slots[slot].Clear();
|
2009-02-24 05:58:59 +00:00
|
|
|
for (int i = 2; i < argv.argc(); ++i)
|
2009-02-20 22:28:48 +00:00
|
|
|
{
|
2009-03-12 03:54:23 +00:00
|
|
|
PlayingKeyConf->Slots[slot].AddWeapon(argv[i]);
|
2009-02-20 22:28:48 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-20 00:53:25 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (argv.argc() == 2)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
Printf ("Slot %d cleared\n", slot);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2009-02-20 22:28:48 +00:00
|
|
|
|
|
|
|
Net_WriteByte(DEM_SETSLOT);
|
|
|
|
Net_WriteByte(slot);
|
|
|
|
Net_WriteByte(argv.argc()-2);
|
|
|
|
for (int i = 2; i < argv.argc(); i++)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
Net_WriteWeapon(dyn_cast<PClassWeapon>(PClass::FindClass(argv[i])));
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// CCMD addslot
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
void FWeaponSlots::AddSlot(int slot, PClassWeapon *type, bool feedback)
|
2009-02-20 22:28:48 +00:00
|
|
|
{
|
2009-02-24 05:58:59 +00:00
|
|
|
if (type != NULL && !Slots[slot].AddWeapon(type) && feedback)
|
2009-02-20 22:28:48 +00:00
|
|
|
{
|
2009-03-10 23:56:47 +00:00
|
|
|
Printf ("Could not add %s to slot %d\n", type->TypeName.GetChars(), slot);
|
2009-02-20 22:28:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
CCMD (addslot)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 22:28:48 +00:00
|
|
|
unsigned int slot;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (argv.argc() != 3 || (slot = atoi (argv[1])) >= NUM_WEAPON_SLOTS)
|
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
Printf ("Usage: addslot <slot> <weapon>\n");
|
2006-02-24 04:48:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
PClassWeapon *type= dyn_cast<PClassWeapon>(PClass::FindClass(argv[2]));
|
|
|
|
if (type == NULL)
|
|
|
|
{
|
|
|
|
Printf("%s is not a weapon\n", argv[2]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
if (ParsingKeyConf)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
KeyConfWeapons.Push(argv.args());
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2009-03-12 03:54:23 +00:00
|
|
|
else if (PlayingKeyConf != NULL)
|
2009-02-20 22:28:48 +00:00
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
PlayingKeyConf->AddSlot(int(slot), type, false);
|
2009-02-20 22:28:48 +00:00
|
|
|
}
|
2009-02-20 00:53:25 +00:00
|
|
|
else
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 22:28:48 +00:00
|
|
|
Net_WriteByte(DEM_ADDSLOT);
|
|
|
|
Net_WriteByte(slot);
|
2010-03-25 20:38:00 +00:00
|
|
|
Net_WriteWeapon(type);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2009-02-20 00:53:25 +00:00
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// CCMD weaponsection
|
|
|
|
//
|
|
|
|
//===========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
CCMD (weaponsection)
|
|
|
|
{
|
|
|
|
if (argv.argc() > 1)
|
|
|
|
{
|
|
|
|
WeaponSection = argv[1];
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// CCMD addslotdefault
|
|
|
|
//
|
|
|
|
//===========================================================================
|
2010-03-25 20:38:00 +00:00
|
|
|
void FWeaponSlots::AddSlotDefault(int slot, PClassWeapon *type, bool feedback)
|
2009-02-20 22:28:48 +00:00
|
|
|
{
|
2009-02-24 05:58:59 +00:00
|
|
|
if (type != NULL && type->IsDescendantOf(RUNTIME_CLASS(AWeapon)))
|
2009-02-20 22:28:48 +00:00
|
|
|
{
|
2009-02-24 05:58:59 +00:00
|
|
|
switch (AddDefaultWeapon(slot, type))
|
2009-02-20 22:28:48 +00:00
|
|
|
{
|
|
|
|
case SLOTDEF_Full:
|
2009-02-24 05:58:59 +00:00
|
|
|
if (feedback)
|
|
|
|
{
|
|
|
|
Printf ("Could not add %s to slot %d\n", type->TypeName.GetChars(), slot);
|
|
|
|
}
|
2009-02-20 22:28:48 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
case SLOTDEF_Added:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SLOTDEF_Exists:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-20 00:53:25 +00:00
|
|
|
|
|
|
|
CCMD (addslotdefault)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
PClassWeapon *type;
|
2009-02-20 00:53:25 +00:00
|
|
|
unsigned int slot;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
if (argv.argc() != 3 || (slot = atoi (argv[1])) >= NUM_WEAPON_SLOTS)
|
|
|
|
{
|
|
|
|
Printf ("Usage: addslotdefault <slot> <weapon>\n");
|
|
|
|
return;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
type = dyn_cast<PClassWeapon>(PClass::FindClass(argv[2]));
|
|
|
|
if (type == NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
Printf ("%s is not a weapon\n", argv[2]);
|
2009-02-20 22:28:48 +00:00
|
|
|
return;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
if (ParsingKeyConf)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
KeyConfWeapons.Push(argv.args());
|
|
|
|
}
|
2009-03-12 03:54:23 +00:00
|
|
|
else if (PlayingKeyConf != NULL)
|
2009-02-20 22:28:48 +00:00
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
PlayingKeyConf->AddSlotDefault(int(slot), type, false);
|
2009-02-20 22:28:48 +00:00
|
|
|
}
|
2009-02-20 00:53:25 +00:00
|
|
|
else
|
|
|
|
{
|
2009-02-20 22:28:48 +00:00
|
|
|
Net_WriteByte(DEM_ADDSLOTDEFAULT);
|
|
|
|
Net_WriteByte(slot);
|
2010-03-25 20:38:00 +00:00
|
|
|
Net_WriteWeapon(type);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// P_PlaybackKeyConfWeapons
|
|
|
|
//
|
|
|
|
// Executes the weapon-related commands from a KEYCONF lump.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-03-12 03:54:23 +00:00
|
|
|
void P_PlaybackKeyConfWeapons(FWeaponSlots *slots)
|
2009-02-20 00:53:25 +00:00
|
|
|
{
|
2009-03-12 03:54:23 +00:00
|
|
|
PlayingKeyConf = slots;
|
2009-02-20 00:53:25 +00:00
|
|
|
for (unsigned int i = 0; i < KeyConfWeapons.Size(); ++i)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-20 00:53:25 +00:00
|
|
|
FString cmd(KeyConfWeapons[i]);
|
|
|
|
AddCommandString(cmd.LockBuffer());
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2009-03-12 03:54:23 +00:00
|
|
|
PlayingKeyConf = NULL;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2009-02-20 00:53:25 +00:00
|
|
|
//===========================================================================
|
|
|
|
//
|
2009-02-24 05:58:59 +00:00
|
|
|
// P_SetupWeapons_ntohton
|
|
|
|
//
|
|
|
|
// Initializes the ntoh and hton maps for weapon types. To populate the ntoh
|
|
|
|
// array, weapons are sorted first by game, then lexicographically. Weapons
|
|
|
|
// from the current game are sorted first, followed by weapons for all other
|
|
|
|
// games, and within each block, they are sorted by name.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void P_SetupWeapons_ntohton()
|
|
|
|
{
|
|
|
|
unsigned int i;
|
2010-03-25 20:38:00 +00:00
|
|
|
PClassWeapon *cls;
|
2009-02-24 05:58:59 +00:00
|
|
|
|
|
|
|
Weapons_ntoh.Clear();
|
|
|
|
Weapons_hton.Clear();
|
|
|
|
|
|
|
|
cls = NULL;
|
|
|
|
Weapons_ntoh.Push(cls); // Index 0 is always NULL.
|
2010-04-16 02:57:51 +00:00
|
|
|
for (i = 0; i < PClassActor::AllActorClasses.Size(); ++i)
|
2009-02-24 05:58:59 +00:00
|
|
|
{
|
2010-04-16 02:57:51 +00:00
|
|
|
PClassActor *cls = PClassActor::AllActorClasses[i];
|
2009-02-24 05:58:59 +00:00
|
|
|
|
2010-03-24 02:49:37 +00:00
|
|
|
if (cls->IsDescendantOf(RUNTIME_CLASS(AWeapon)))
|
2009-02-24 05:58:59 +00:00
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
Weapons_ntoh.Push(static_cast<PClassWeapon *>(cls));
|
2009-02-24 05:58:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
qsort(&Weapons_ntoh[1], Weapons_ntoh.Size() - 1, sizeof(Weapons_ntoh[0]), ntoh_cmp);
|
|
|
|
for (i = 0; i < Weapons_ntoh.Size(); ++i)
|
|
|
|
{
|
|
|
|
Weapons_hton[Weapons_ntoh[i]] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// ntoh_cmp
|
2009-02-20 00:53:25 +00:00
|
|
|
//
|
2009-02-24 05:58:59 +00:00
|
|
|
// Sorting comparison function used by P_SetupWeapons_ntohton().
|
|
|
|
//
|
|
|
|
// Weapons that filter for the current game appear first, weapons that filter
|
|
|
|
// for any game appear second, and weapons that filter for some other game
|
|
|
|
// appear last. The idea here is to try to keep all the weapons that are
|
|
|
|
// most likely to be used at the start of the list so that they only need
|
|
|
|
// one byte to transmit across the network.
|
2009-02-20 00:53:25 +00:00
|
|
|
//
|
|
|
|
//===========================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-02-24 05:58:59 +00:00
|
|
|
static int STACK_ARGS ntoh_cmp(const void *a, const void *b)
|
2009-02-20 00:53:25 +00:00
|
|
|
{
|
2010-03-25 20:38:00 +00:00
|
|
|
PClassWeapon *c1 = *(PClassWeapon **)a;
|
|
|
|
PClassWeapon *c2 = *(PClassWeapon **)b;
|
2010-03-24 02:49:37 +00:00
|
|
|
int g1 = c1->GameFilter == GAME_Any ? 1 : (c1->GameFilter & gameinfo.gametype) ? 0 : 2;
|
|
|
|
int g2 = c2->GameFilter == GAME_Any ? 1 : (c2->GameFilter & gameinfo.gametype) ? 0 : 2;
|
2009-02-24 05:58:59 +00:00
|
|
|
if (g1 != g2)
|
|
|
|
{
|
|
|
|
return g1 - g2;
|
|
|
|
}
|
|
|
|
return stricmp(c1->TypeName.GetChars(), c2->TypeName.GetChars());
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// P_WriteDemoWeaponsChunk
|
|
|
|
//
|
|
|
|
// Store the list of weapons so that adding new ones does not automatically
|
|
|
|
// break demos.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void P_WriteDemoWeaponsChunk(BYTE **demo)
|
|
|
|
{
|
|
|
|
WriteWord(Weapons_ntoh.Size(), demo);
|
|
|
|
for (unsigned int i = 1; i < Weapons_ntoh.Size(); ++i)
|
|
|
|
{
|
|
|
|
WriteString(Weapons_ntoh[i]->TypeName.GetChars(), demo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// P_ReadDemoWeaponsChunk
|
|
|
|
//
|
|
|
|
// Restore the list of weapons that was current at the time the demo was
|
|
|
|
// recorded.
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void P_ReadDemoWeaponsChunk(BYTE **demo)
|
|
|
|
{
|
|
|
|
int count, i;
|
2010-03-25 20:38:00 +00:00
|
|
|
PClassWeapon *type;
|
2009-02-24 05:58:59 +00:00
|
|
|
const char *s;
|
|
|
|
|
|
|
|
count = ReadWord(demo);
|
|
|
|
Weapons_ntoh.Resize(count);
|
|
|
|
Weapons_hton.Clear(count);
|
|
|
|
|
|
|
|
Weapons_ntoh[0] = type = NULL;
|
|
|
|
Weapons_hton[type] = 0;
|
|
|
|
|
|
|
|
for (i = 1; i < count; ++i)
|
|
|
|
{
|
|
|
|
s = ReadStringConst(demo);
|
2010-03-25 20:38:00 +00:00
|
|
|
type = dyn_cast<PClassWeapon>(PClass::FindClass(s));
|
2009-02-24 05:58:59 +00:00
|
|
|
// If a demo was recorded with a weapon that is no longer present,
|
|
|
|
// should we report it?
|
|
|
|
Weapons_ntoh[i] = type;
|
|
|
|
if (type != NULL)
|
|
|
|
{
|
|
|
|
Weapons_hton[type] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// Net_WriteWeapon
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
void Net_WriteWeapon(PClassWeapon *type)
|
2009-02-24 05:58:59 +00:00
|
|
|
{
|
|
|
|
int index, *index_p;
|
|
|
|
|
|
|
|
index_p = Weapons_hton.CheckKey(type);
|
|
|
|
if (index_p == NULL)
|
|
|
|
{
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
index = *index_p;
|
|
|
|
}
|
|
|
|
// 32767 weapons better be enough for anybody.
|
|
|
|
assert(index >= 0 && index <= 32767);
|
|
|
|
if (index < 128)
|
|
|
|
{
|
|
|
|
Net_WriteByte(index);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Net_WriteByte(0x80 | index);
|
|
|
|
Net_WriteByte(index >> 7);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// Net_ReadWeapon
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
2010-03-25 20:38:00 +00:00
|
|
|
PClassWeapon *Net_ReadWeapon(BYTE **stream)
|
2009-02-24 05:58:59 +00:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
index = ReadByte(stream);
|
|
|
|
if (index & 0x80)
|
|
|
|
{
|
|
|
|
index = (index & 0x7F) | (ReadByte(stream) << 7);
|
|
|
|
}
|
2009-03-10 23:07:37 +00:00
|
|
|
if ((unsigned)index >= Weapons_ntoh.Size())
|
2009-02-24 05:58:59 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return Weapons_ntoh[index];
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2009-06-30 19:20:39 +00:00
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// A_ZoomFactor
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
DEFINE_ACTION_FUNCTION_PARAMS(AWeapon, A_ZoomFactor)
|
|
|
|
{
|
2010-02-12 06:04:57 +00:00
|
|
|
PARAM_ACTION_PROLOGUE;
|
|
|
|
PARAM_FLOAT_OPT (zoom) { zoom = 1; }
|
|
|
|
PARAM_INT_OPT (flags) { flags = 0; }
|
2009-06-30 19:20:39 +00:00
|
|
|
|
|
|
|
if (self->player != NULL && self->player->ReadyWeapon != NULL)
|
|
|
|
{
|
2010-02-12 06:04:57 +00:00
|
|
|
zoom = 1 / clamp(zoom, 0.1, 50.0);
|
2009-06-30 19:20:39 +00:00
|
|
|
if (flags & 1)
|
2009-06-30 22:37:40 +00:00
|
|
|
{ // Make the zoom instant.
|
2010-02-12 06:04:57 +00:00
|
|
|
self->player->FOV = float(self->player->DesiredFOV * zoom);
|
2009-06-30 19:20:39 +00:00
|
|
|
}
|
2009-06-30 22:37:40 +00:00
|
|
|
if (flags & 2)
|
|
|
|
{ // Disable pitch/yaw scaling.
|
|
|
|
zoom = -zoom;
|
|
|
|
}
|
2010-02-12 06:04:57 +00:00
|
|
|
self->player->ReadyWeapon->FOVScale = float(zoom);
|
2009-06-30 19:20:39 +00:00
|
|
|
}
|
2010-02-12 06:04:57 +00:00
|
|
|
return 0;
|
2009-06-30 19:20:39 +00:00
|
|
|
}
|
2009-07-01 02:00:36 +00:00
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
//
|
|
|
|
// A_SetCrosshair
|
|
|
|
//
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
DEFINE_ACTION_FUNCTION_PARAMS(AWeapon, A_SetCrosshair)
|
|
|
|
{
|
2010-02-12 06:04:57 +00:00
|
|
|
PARAM_ACTION_PROLOGUE;
|
|
|
|
PARAM_INT(xhair);
|
2009-07-01 02:00:36 +00:00
|
|
|
|
|
|
|
if (self->player != NULL && self->player->ReadyWeapon != NULL)
|
|
|
|
{
|
|
|
|
self->player->ReadyWeapon->Crosshair = xhair;
|
|
|
|
}
|
2010-02-12 06:04:57 +00:00
|
|
|
return 0;
|
2009-07-01 02:00:36 +00:00
|
|
|
}
|