bool AWeapon::PickupForAmmo (AWeapon *ownedWeapon) { bool gotstuff = false; // Don't take ammo if the weapon sticks around. if (!ShouldStay ()) { int oldamount1 = 0; int oldamount2 = 0; if (ownedWeapon->Ammo1 != NULL) oldamount1 = ownedWeapon->Ammo1->Amount; if (ownedWeapon->Ammo2 != NULL) oldamount2 = ownedWeapon->Ammo2->Amount; if (AmmoGive1 > 0) gotstuff = AddExistingAmmo (ownedWeapon->Ammo1, AmmoGive1); if (AmmoGive2 > 0) gotstuff |= AddExistingAmmo (ownedWeapon->Ammo2, AmmoGive2); AActor *Owner = ownedWeapon->Owner; if (gotstuff && Owner != NULL && Owner->player != NULL) { 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()); } } } return gotstuff; }
bool AClericWeaponPiece::TryPickup (AActor *&toucher) { if (!toucher->IsKindOf (PClass::FindClass(NAME_MagePlayer)) && !toucher->IsKindOf (PClass::FindClass(NAME_FighterPlayer))) { return Super::TryPickup(toucher); } else { // Wrong class, but try to pick up for ammo if (ShouldStay()) { // Can't pick up weapons for other classes in coop netplay return false; } AWeapon * Defaults=(AWeapon*)GetDefaultByType(WeaponClass); bool gaveSome = !!(toucher->GiveAmmo (Defaults->AmmoType1, Defaults->AmmoGive1) + toucher->GiveAmmo (Defaults->AmmoType2, Defaults->AmmoGive2)); if (gaveSome) { GoAwayAndDie (); } return gaveSome; } }
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; }
bool AInventory::CallTryPickup (AActor *toucher, AActor **toucher_return) { TObjPtr<AInventory> Invstack = Inventory; // A pointer of the inventories item stack. // unmorphed versions of a currently morphed actor cannot pick up anything. if (toucher->flags & MF_UNMORPHED) return false; bool res; if (CanPickup(toucher)) res = TryPickup(toucher); else if (!(ItemFlags & IF_RESTRICTABSOLUTELY)) res = TryPickupRestricted(toucher); // let an item decide for itself how it will handle this else return false; // Morph items can change the toucher so we need an option to return this info. if (toucher_return != NULL) *toucher_return = toucher; if (!res && (ItemFlags & IF_ALWAYSPICKUP) && !ShouldStay()) { res = true; GoAwayAndDie(); } if (res) { GiveQuest(toucher); // Transfer all inventory accross that the old object had, if requested. if ((ItemFlags & IF_TRANSFER)) { while (Invstack) { AInventory* titem = Invstack; Invstack = titem->Inventory; if (titem->Owner == this) { if (!titem->CallTryPickup(toucher)) // The object no longer can exist { titem->Destroy(); } } } } } return res; }
bool AWeaponPiece::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; } AWeapon * Defaults=(AWeapon*)GetDefaultByType(WeaponClass); bool gaveSome = !!(toucher->GiveAmmo (Defaults->AmmoType1, Defaults->AmmoGive1) + toucher->GiveAmmo (Defaults->AmmoType2, Defaults->AmmoGive2)); if (gaveSome) { GoAwayAndDie (); } return gaveSome; }
bool AInventory::GoAway () { // Dropped items never stick around if (flags & MF_DROPPED) { return false; } if (!ShouldStay ()) { Hide (); if (ShouldRespawn ()) { return true; } return false; } return true; }
END_DEFAULTS bool AFighterWeapon::TryPickup (AActor *toucher) { // The Doom and Hexen players are not excluded from pickup in case // somebody wants to use these weapons with either of those games. if (toucher->IsKindOf (RUNTIME_CLASS(AClericPlayer)) || toucher->IsKindOf (RUNTIME_CLASS(AMagePlayer))) { // Wrong class, but try to pick up for mana 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; } return Super::TryPickup (toucher); }
void AInventory::Touch (AActor *toucher) { player_t *player = toucher->player; // If a voodoo doll touches something, pretend the real player touched it instead. if (player != NULL) { toucher = player->mo; } bool localview = toucher->CheckLocalView(consoleplayer); if (!CallTryPickup (toucher, &toucher)) return; // This is the only situation when a pickup flash should ever play. if (PickupFlash != NULL && !ShouldStay()) { Spawn(PickupFlash, Pos(), ALLOW_REPLACE); } if (!(ItemFlags & IF_QUIET)) { const char * message = PickupMessage (); if (message != NULL && *message != 0 && localview && (StaticLastMessageTic != gametic || StaticLastMessage != message)) { StaticLastMessageTic = gametic; StaticLastMessage = message; PrintPickupMessage (message); StatusBar->FlashCrosshair (); } // Special check so voodoo dolls picking up items cause the // real player to make noise. if (player != NULL) { PlayPickupSound (player->mo); if (!(ItemFlags & IF_NOSCREENFLASH)) { player->bonuscount = BONUSADD; } } else { PlayPickupSound (toucher); } } // [RH] Execute an attached special (if any) DoPickupSpecial (toucher); if (flags & MF_COUNTITEM) { if (player != NULL) { player->itemcount++; } level.found_items++; } if (flags5 & MF5_COUNTSECRET) { P_GiveSecret(player != NULL? (AActor*)player->mo : toucher, true, true, -1); } //Added by MC: Check if item taken was the roam destination of any bot for (int i = 0; i < MAXPLAYERS; i++) { if (players[i].Bot != NULL && this == players[i].Bot->dest) players[i].Bot->dest = NULL; } }