Exemple #1
0
bool ABackpackItem::HandlePickup (AInventory *item)
{
    // Since you already have a backpack, that means you already have every
    // kind of ammo in your inventory, so we don't need to look at the
    // entire PClass list to discover what kinds of ammo exist, and we don't
    // have to alter the MaxAmount either.
    if (item->IsKindOf (RUNTIME_CLASS(ABackpackItem)))
    {
        for (AInventory *probe = Owner->Inventory; probe != NULL; probe = probe->Inventory)
        {
            if (probe->GetClass()->ParentClass == RUNTIME_CLASS(AAmmo))
            {
                if (probe->Amount < probe->MaxAmount || sv_unlimited_pickup)
                {
                    int amount = static_cast<AAmmo*>(probe->GetDefault())->BackpackAmount;
                    // extra ammo in baby mode and nightmare mode
                    if (!(item->ItemFlags&IF_IGNORESKILL))
                    {
                        amount = int(amount * G_SkillProperty(SKILLP_AmmoFactor));
                    }
                    probe->Amount += amount;
                    if (probe->Amount > probe->MaxAmount && !sv_unlimited_pickup)
                    {
                        probe->Amount = probe->MaxAmount;
                    }
                }
            }
        }
        // The pickup always succeeds, even if you didn't get anything
        item->ItemFlags |= IF_PICKUPGOOD;
        return true;
    }
    return false;
}
Exemple #2
0
void ABackpackItem::DetachFromOwner ()
{
	// When removing a backpack, drop the player's ammo maximums to normal
	AInventory *item;

	for (item = Owner->Inventory; item != NULL; item = item->Inventory)
	{
		if (item->GetClass()->ParentClass == RUNTIME_CLASS(AAmmo) &&
			item->MaxAmount == static_cast<AAmmo*>(item)->BackpackMaxAmount)
		{
			item->MaxAmount = static_cast<AInventory*>(item->GetDefault())->MaxAmount;
			if (item->Amount > item->MaxAmount)
			{
				item->Amount = item->MaxAmount;
			}
		}
	}
}