- Added a DropAmmoFactor field to WeaponGiver so that ModifyDropAmount() can record the drop

amount modifier into it without fiddling with the actual AmmoGiveX fields.

SVN r4246 (trunk)
This commit is contained in:
Randy Heit 2013-05-02 00:24:53 +00:00
parent 163d8ba3e6
commit d86b16d540
3 changed files with 32 additions and 37 deletions

View file

@ -359,7 +359,17 @@ enum
WIF_BOT_BFG = 1<<28, // this is a BFG
};
#define S_LIGHTDONE 0
class AWeaponGiver : public AWeapon
{
DECLARE_CLASS(AWeaponGiver, AWeapon)
public:
bool TryPickup(AActor *&toucher);
void Serialize(FArchive &arc);
fixed_t DropAmmoFactor;
};
// Health is some item that gives the player health when picked up.
class AHealth : public AInventory

View file

@ -705,16 +705,17 @@ FState *AWeapon::GetZoomState ()
/* Weapon giver ***********************************************************/
class AWeaponGiver : public AWeapon
{
DECLARE_CLASS(AWeaponGiver, AWeapon)
public:
bool TryPickup(AActor *&toucher);
};
IMPLEMENT_CLASS(AWeaponGiver)
void AWeaponGiver::Serialize(FArchive &arc)
{
Super::Serialize(arc);
if (SaveVersion >= 4246)
{
arc << DropAmmoFactor;
}
}
bool AWeaponGiver::TryPickup(AActor *&toucher)
{
FDropItem *di = GetDropItems();
@ -734,36 +735,15 @@ bool AWeaponGiver::TryPickup(AActor *&toucher)
weap->ItemFlags &= ~IF_ALWAYSPICKUP; // use the flag of this item only.
weap->flags = (weap->flags & ~MF_DROPPED) | (this->flags & MF_DROPPED);
// If we're not overriding the ammo given amounts, then apply dropped
// item modifications if needed.
if (weap->flags & MF_DROPPED)
{
dropammofactor = G_SkillProperty(SKILLP_DropAmmoFactor);
if (dropammofactor < 0)
{
dropammofactor = FRACUNIT/2;
}
}
else
{
dropammofactor = FRACUNIT;
}
// If our ammo gives are non-negative, transfer them to the real weapon.
if (AmmoGive1 >= 0) weap->AmmoGive1 = AmmoGive1;
if (AmmoGive2 >= 0) weap->AmmoGive2 = AmmoGive2;
if (AmmoGive1 < 0)
// If DropAmmoFactor is non-negative, modify the given ammo amounts.
if (DropAmmoFactor > 0)
{
weap->AmmoGive1 = FixedMul(weap->AmmoGive1, dropammofactor);
}
else
{
weap->AmmoGive1 = AmmoGive1;
}
if (AmmoGive2 < 0)
{
weap->AmmoGive2 = FixedMul(weap->AmmoGive2, dropammofactor);
}
else
{
weap->AmmoGive2 = AmmoGive2;
weap->AmmoGive1 = FixedMul(weap->AmmoGive1, DropAmmoFactor);
weap->AmmoGive2 = FixedMul(weap->AmmoGive2, DropAmmoFactor);
}
weap->BecomeItem();
}

View file

@ -3025,6 +3025,11 @@ void ModifyDropAmount(AInventory *inv, int dropamount)
inv->Amount = inv->GetClass()->Meta.GetMetaInt (AIMETA_DropAmount, MAX(1, FixedMul(inv->Amount, dropammofactor)));
inv->ItemFlags |= flagmask;
}
else if (inv->IsKindOf (RUNTIME_CLASS(AWeaponGiver)))
{
static_cast<AWeaponGiver *>(inv)->DropAmmoFactor = dropammofactor;
inv->ItemFlags |= flagmask;
}
else if (inv->IsKindOf (RUNTIME_CLASS(AWeapon)))
{
// The same goes for ammo from a weapon.