Example #1
0
bool AWeaponGiver::TryPickup(AActor *&toucher)
{
	FDropItem *di = GetDropItems();
	AWeapon *weap;

	if (di != NULL)
	{
		const PClass *ti = PClass::FindClass(di->Name);
		if (ti->IsDescendantOf(RUNTIME_CLASS(AWeapon)))
		{
			if (master == NULL)
			{
				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.
					if (AmmoGive1 >= 0) weap->AmmoGive1 = AmmoGive1;
					if (AmmoGive2 >= 0) weap->AmmoGive2 = AmmoGive2;
					weap->BecomeItem();
				}
				else return false;
			}

			weap = barrier_cast<AWeapon*>(master);
			bool res = weap->CallTryPickup(toucher);
			if (res) GoAwayAndDie();
			return res;
		}
	}
	return false;
}
Example #2
0
bool AWeaponGiver::TryPickup(AActor *&toucher)
{
	DDropItem *di = GetDropItems();
	AWeapon *weap;

	if (di != NULL)
	{
		PClassWeapon *ti = dyn_cast<PClassWeapon>(PClass::FindClass(di->Name));
		if (ti != NULL)
		{
			if (master == NULL)
			{
				master = weap = static_cast<AWeapon*>(Spawn(di->Name));
				if (weap != NULL)
				{
					weap->ItemFlags &= ~IF_ALWAYSPICKUP;	// use the flag of this item only.
					weap->flags = (weap->flags & ~MF_DROPPED) | (this->flags & MF_DROPPED);

					// 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 DropAmmoFactor is non-negative, modify the given ammo amounts.
					if (DropAmmoFactor > 0)
					{
						weap->AmmoGive1 = int(weap->AmmoGive1 * DropAmmoFactor);
						weap->AmmoGive2 = int(weap->AmmoGive2 * DropAmmoFactor);
					}
					weap->BecomeItem();
				}
				else return false;
			}

			weap = barrier_cast<AWeapon*>(master);
			bool res = weap->CallTryPickup(toucher);
			if (res)
			{
				GoAwayAndDie();
				master = NULL;
			}
			return res;
		}
	}
	return false;
}