AInventory *ABackpackItem::CreateCopy (AActor *other) { // Find every unique type of ammo. Give it to the player if // he doesn't have it already, and double its maximum capacity. for (unsigned int i = 0; i < PClassActor::AllActorClasses.Size(); ++i) { PClass *type = PClassActor::AllActorClasses[i]; if (type->ParentClass == RUNTIME_CLASS(AAmmo)) { PClassActor *atype = static_cast<PClassActor *>(type); AAmmo *ammo = static_cast<AAmmo *>(other->FindInventory(atype)); int amount = static_cast<AAmmo *>(GetDefaultByType(type))->BackpackAmount; // extra ammo in baby mode and nightmare mode if (!(ItemFlags&IF_IGNORESKILL)) { amount = int(amount * G_SkillProperty(SKILLP_AmmoFactor)); } if (amount < 0) amount = 0; if (ammo == NULL) { // The player did not have the ammo. Add it. ammo = static_cast<AAmmo *>(Spawn(atype)); ammo->Amount = bDepleted ? 0 : amount; if (ammo->BackpackMaxAmount > ammo->MaxAmount) { ammo->MaxAmount = ammo->BackpackMaxAmount; } if (ammo->Amount > ammo->MaxAmount) { ammo->Amount = ammo->MaxAmount; } ammo->AttachToOwner (other); } else { // The player had the ammo. Give some more. if (ammo->MaxAmount < ammo->BackpackMaxAmount) { ammo->MaxAmount = ammo->BackpackMaxAmount; } if (!bDepleted && ammo->Amount < ammo->MaxAmount) { ammo->Amount += amount; if (ammo->Amount > ammo->MaxAmount) { ammo->Amount = ammo->MaxAmount; } } } } } return Super::CreateCopy (other); }
AAmmo *AWeapon::AddAmmo (AActor *other, PClassActor *ammotype, int amount) { AAmmo *ammo; if (ammotype == NULL) { return NULL; } // [BC] This behavior is from the original Doom. Give 5/2 times as much ammo when // we pick up a weapon in deathmatch. if (( deathmatch ) && ( gameinfo.gametype & GAME_DoomChex )) amount = amount * 5 / 2; // extra ammo in baby mode and nightmare mode if (!(this->ItemFlags&IF_IGNORESKILL)) { amount = int(amount * G_SkillProperty(SKILLP_AmmoFactor)); } ammo = static_cast<AAmmo *>(other->FindInventory (ammotype)); if (ammo == NULL) { ammo = static_cast<AAmmo *>(Spawn (ammotype)); 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; }