Allow embiggener to give mag ammo like in the sidemods.
This commit is contained in:
parent
186229c421
commit
6baa8b8215
8 changed files with 127 additions and 75 deletions
|
|
@ -354,6 +354,59 @@ Class HammerspaceEmbiggener : Inventory
|
|||
}
|
||||
}
|
||||
}
|
||||
// do the same for mag ammo, in a separate loop
|
||||
for ( int i=0; i<AllActorClasses.Size(); i++ )
|
||||
{
|
||||
let type = (class<MagAmmo>)(AllActorClasses[i]);
|
||||
if ( !type || (type.GetParentClass() != 'MagAmmo') ) continue;
|
||||
let magitem = MagAmmo(other.FindInventory(type));
|
||||
int amount = GetDefaultByType(type).BackpackAmount*self.Amount;
|
||||
if ( traded ) amount = 0;
|
||||
if ( amount < 0 ) amount = 0;
|
||||
int mags = amount/GetDefaultByType(type).ClipSize;
|
||||
amount = amount%GetDefaultByType(type).ClipSize;
|
||||
if ( !magitem )
|
||||
{
|
||||
// The player did not have the magitem. Add it.
|
||||
magitem = MagAmmo(Spawn(type));
|
||||
magitem.Amount = amount;
|
||||
magitem.AttachToOwner(other);
|
||||
// by this point, we assume that the parent ammo pointer is valid, so...
|
||||
let ammoitem = magitem.pamo;
|
||||
// append some mags to it
|
||||
if ( ammoitem.Amount < ammoitem.MaxAmount )
|
||||
{
|
||||
if ( (ammoitem.Amount > 0) && (ammoitem.Amount+mags < 0) )
|
||||
ammoitem.Amount = int.max;
|
||||
else ammoitem.Amount += mags;
|
||||
if ( (ammoitem.Amount > ammoitem.MaxAmount) && !sv_unlimited_pickup )
|
||||
ammoitem.Amount = ammoitem.MaxAmount;
|
||||
}
|
||||
// we can't add extra mags, just max out the spare ammo
|
||||
else if ( mags > 0 ) magitem.Amount = min(magitem.MaxAmount,magitem.Amount+magitem.ClipSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( magitem.Amount+amount >= magitem.MaxAmount )
|
||||
{
|
||||
mags++;
|
||||
amount -= magitem.MaxAmount;
|
||||
}
|
||||
magitem.Amount += amount;
|
||||
let ammoitem = magitem.pamo;
|
||||
// append some mags to it
|
||||
if ( ammoitem.Amount < ammoitem.MaxAmount )
|
||||
{
|
||||
if ( (ammoitem.Amount > 0) && (ammoitem.Amount+mags < 0) )
|
||||
ammoitem.Amount = int.max;
|
||||
else ammoitem.Amount += mags;
|
||||
if ( (ammoitem.Amount > ammoitem.MaxAmount) && !sv_unlimited_pickup )
|
||||
ammoitem.Amount = ammoitem.MaxAmount;
|
||||
}
|
||||
// we can't add extra mags, just max out the spare ammo
|
||||
else if ( mags > 0 ) magitem.Amount = min(magitem.MaxAmount,magitem.Amount+magitem.ClipSize);
|
||||
}
|
||||
}
|
||||
self.Amount = min(self.Amount,MaxAmount);
|
||||
if ( GetParentClass() == 'HammerspaceEmbiggener' )
|
||||
{
|
||||
|
|
@ -403,6 +456,31 @@ Class HammerspaceEmbiggener : Inventory
|
|||
if ( (i.Amount > i.MaxAmount) && !sv_unlimited_pickup )
|
||||
i.Amount = i.MaxAmount;
|
||||
}
|
||||
if ( traded ) return true;
|
||||
// give spare mag ammo separately
|
||||
for ( Inventory i=Owner.Inv; i; i=i.Inv )
|
||||
{
|
||||
if ( !(i is 'MagAmmo') ) continue;
|
||||
int amount = MagAmmo(i).BackpackAmount*item.Amount;
|
||||
int mags = amount/MagAmmo(i).ClipSize;
|
||||
amount = amount%MagAmmo(i).ClipSize;
|
||||
if ( i.Amount+amount >= MagAmmo(i).ClipSize )
|
||||
{
|
||||
mags++;
|
||||
amount -= MagAmmo(i).ClipSize;
|
||||
}
|
||||
i.Amount += amount;
|
||||
Ammo a = MagAmmo(i).pamo;
|
||||
if ( a.Amount < a.MaxAmount )
|
||||
{
|
||||
if ( (a.Amount > 0) && (a.Amount+mags < 0) )
|
||||
a.Amount = int.max;
|
||||
else a.Amount += mags;
|
||||
if ( (a.Amount > a.MaxAmount) && !sv_unlimited_pickup )
|
||||
a.Amount = a.MaxAmount;
|
||||
}
|
||||
else if ( mags > 0 ) i.Amount = min(i.MaxAmount,i.Amount+MagAmmo(i).ClipSize);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// new ammo suddenly added? upgrade it (this shouldn't happen unless fucky scripting has been involved)
|
||||
|
|
|
|||
|
|
@ -644,6 +644,7 @@ Class SilverBullets : MagAmmo
|
|||
Stamina -12000;
|
||||
MagAmmo.ParentAmmo "SilverBulletAmmo";
|
||||
MagAmmo.ClipSize 5;
|
||||
MagAmmo.BackpackAmount 2;
|
||||
Inventory.MaxAmount 5;
|
||||
+FLOATBOB;
|
||||
FloatBobStrength 0.25;
|
||||
|
|
@ -756,6 +757,7 @@ Class CandyGunBullets : MagAmmo
|
|||
Stamina -14000;
|
||||
MagAmmo.ParentAmmo "CandyGunAmmo";
|
||||
MagAmmo.ClipSize 7;
|
||||
MagAmmo.BackpackAmount 1;
|
||||
Inventory.MaxAmount 7;
|
||||
+FLOATBOB;
|
||||
FloatBobStrength 0.25;
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ Class SWWMClipAmmoMed : SWWMAmmoSpawner
|
|||
bex = SWWMUtility.ItemExists('HeavyMahSheenGun',ownedonly:enemydrop);
|
||||
if ( (!aex && bex) || (Random[Replacements](0,1) && bex) )
|
||||
return 'SheenSmallAmmo';
|
||||
return Random[Replacements](0,1)?'EvisceratorShell2':'EvisceratorShell';
|
||||
return Random[Replacements](0,2)?'EvisceratorShell':'EvisceratorShell2';
|
||||
}
|
||||
}
|
||||
Class SWWMClipAmmoBig : SWWMAmmoSpawner
|
||||
|
|
@ -159,7 +159,7 @@ Class SWWMClipAmmoBig : SWWMAmmoSpawner
|
|||
bex = SWWMUtility.ItemExists('HeavyMahSheenGun',ownedonly:enemydrop);
|
||||
if ( (!aex && bex) || (Random[Replacements](0,1) && bex) )
|
||||
return 'SheenBigAmmo';
|
||||
return Random[Replacements](0,1)?'EvisceratorShell2':'EvisceratorShell3';
|
||||
return Random[Replacements](0,2)?'EvisceratorShell2':'EvisceratorShell3';
|
||||
}
|
||||
}
|
||||
Class SWWMBlastAmmoSmall : SWWMAmmoSpawner
|
||||
|
|
@ -181,7 +181,7 @@ Class SWWMBlastAmmoBig : SWWMAmmoSpawner
|
|||
bex = SWWMUtility.ItemExists('HeavyMahSheenGun',ownedonly:enemydrop);
|
||||
if ( (!aex && bex) || (Random[Replacements](0,1) && bex) )
|
||||
return 'SheenBigAmmo';
|
||||
return Random[Replacements](0,2)?'EvisceratorShell3':'EvisceratorShell2';
|
||||
return Random[Replacements](0,2)?'EvisceratorShell2':'EvisceratorShell3';
|
||||
}
|
||||
}
|
||||
Class SWWMRocketAmmoSmall : SWWMAmmoSpawner
|
||||
|
|
@ -201,7 +201,7 @@ Class SWWMRocketAmmoBig : SWWMAmmoSpawner
|
|||
bool aex = SWWMUtility.ItemExists('Hellblazer',ownedonly:enemydrop),
|
||||
bex = SWWMUtility.ItemExists('Quadravol',ownedonly:enemydrop);
|
||||
if ( (!aex && bex) || (Random[Replacements](0,1) && bex) )
|
||||
return Random[Replacements](0,4)?'QuadravolAmmo2':'QuadravolAmmo3';
|
||||
return Random[Replacements](0,3)?'QuadravolAmmo2':'QuadravolAmmo3';
|
||||
switch ( Random[Replacements](0,11) )
|
||||
{
|
||||
case 0:
|
||||
|
|
@ -209,12 +209,12 @@ Class SWWMRocketAmmoBig : SWWMAmmoSpawner
|
|||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
return Random[Replacements](0,4)?'HellblazerMissiles':'HellblazerMissiles2';
|
||||
return Random[Replacements](0,3)?'HellblazerMissiles':'HellblazerMissiles2';
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
return Random[Replacements](0,7)?'HellblazerCrackshots':'HellblazerCrackshots2';
|
||||
return Random[Replacements](0,5)?'HellblazerCrackshots':'HellblazerCrackshots2';
|
||||
case 9:
|
||||
case 10:
|
||||
return 'HellblazerRavagers';
|
||||
|
|
@ -229,13 +229,13 @@ Class SWWMCellAmmoSmall : SWWMAmmoSpawner
|
|||
{
|
||||
if ( !Random[Replacements](0,2) )
|
||||
{
|
||||
if ( !Random[Replacements](0,3) )
|
||||
{
|
||||
bool aex = SWWMUtility.ItemExists('CandyGun',ownedonly:enemydrop),
|
||||
bex = SWWMUtility.ItemExists('MisterRifle',ownedonly:enemydrop);
|
||||
if ( (!aex && bex) || (Random[Replacements](0,1) && bex) ) return !Random[Replacements](0,2)?'MisterGAmmo':Random[Replacements](0,2)?'MisterRound':'MisterRound2';
|
||||
if ( aex ) return 'CandyGunBullets';
|
||||
}
|
||||
bool aex = SWWMUtility.ItemExists('CandyGun',ownedonly:enemydrop),
|
||||
bex = SWWMUtility.ItemExists('MisterRifle',ownedonly:enemydrop);
|
||||
if ( (!aex && bex) || (Random[Replacements](0,1) && bex) ) return !Random[Replacements](0,2)?'MisterGAmmo':Random[Replacements](0,2)?'MisterRound':'MisterRound2';
|
||||
if ( aex ) return 'CandyGunBullets';
|
||||
}
|
||||
if ( Random[Replacements](0,1) )
|
||||
{
|
||||
bool aex = SWWMUtility.ItemExists('SilverBullet',ownedonly:enemydrop),
|
||||
bex = SWWMUtility.ItemExists('RayKhom',ownedonly:enemydrop);
|
||||
if ( (!aex && bex) || (Random[Replacements](0,1) && bex) ) return 'RayBolt2';
|
||||
|
|
@ -258,6 +258,13 @@ Class SWWMCellAmmoBig : SWWMAmmoSpawner
|
|||
if ( (SWWMUtility.ItemExists('Ynykron')) && SWWMUtility.CheckNeedsItem('YnykronAmmo',true) && !SWWMUtility.ItemExists('YnykronAmmo',worldonly:true) && !SWWMUtility.ItemExists('Ynykron',worldonly:true) )
|
||||
return 'YnykronAmmo';
|
||||
}
|
||||
if ( !Random[Replacements](0,2) )
|
||||
{
|
||||
bool aex = SWWMUtility.ItemExists('CandyGun',ownedonly:enemydrop),
|
||||
bex = SWWMUtility.ItemExists('MisterRifle',ownedonly:enemydrop);
|
||||
if ( (!aex && bex) || (Random[Replacements](0,1) && bex) ) return !Random[Replacements](0,2)?'MisterGAmmo2':Random[Replacements](0,2)?'MisterRound5':'MisterAmmo';
|
||||
if ( aex ) return Random[Replacements](0,2)?'CandyGunBullets3':'CandyGunAmmo';
|
||||
}
|
||||
if ( Random[Replacements](0,1) )
|
||||
{
|
||||
bool aex = SWWMUtility.ItemExists('SilverBullet',ownedonly:enemydrop),
|
||||
|
|
@ -269,13 +276,6 @@ Class SWWMCellAmmoBig : SWWMAmmoSpawner
|
|||
return Random[Replacements](0,2)?'SilverBulletAmmo':'SilverBulletAmmo2';
|
||||
}
|
||||
}
|
||||
if ( !Random[Replacements](0,2) )
|
||||
{
|
||||
bool aex = SWWMUtility.ItemExists('CandyGun',ownedonly:enemydrop),
|
||||
bex = SWWMUtility.ItemExists('MisterRifle',ownedonly:enemydrop);
|
||||
if ( (!aex && bex) || (Random[Replacements](0,1) && bex) ) return !Random[Replacements](0,2)?'MisterGAmmo2':Random[Replacements](0,2)?'MisterRound5':'MisterAmmo';
|
||||
if ( aex ) return Random[Replacements](0,3)?'CandyGunBullets3':'CandyGunAmmo';
|
||||
}
|
||||
bool aex = SWWMUtility.ItemExists('Sparkster',ownedonly:enemydrop),
|
||||
bex = SWWMUtility.ItemExists('ModernSparkster',ownedonly:enemydrop);
|
||||
if ( (!aex && bex) || (Random[Replacements](0,1) && bex) )
|
||||
|
|
|
|||
|
|
@ -236,30 +236,6 @@ Class SWWMAmmo : Ammo
|
|||
return Super.HandlePickup(item);
|
||||
}
|
||||
|
||||
override bool CanPickup( Actor toucher )
|
||||
{
|
||||
// don't allow picking up ammo for weapons we can't pick up
|
||||
if ( !Super.CanPickup(toucher) ) return false;
|
||||
for ( int i=0; i<AllActorClasses.Size(); i++ )
|
||||
{
|
||||
let w = (Class<Weapon>)(AllActorClasses[i]);
|
||||
if ( !w ) continue;
|
||||
if ( w is 'SWWMWeapon' )
|
||||
{
|
||||
let def = GetDefaultByType((Class<SWWMWeapon>)(w));
|
||||
if ( !def.UsesAmmo(GetClass()) ) continue;
|
||||
if ( !def.CanPickup(toucher) ) return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
let def = GetDefaultByType(w);
|
||||
if ( (def.AmmoType1 != GetClass()) && (def.AmmoType2 != GetClass()) ) continue;
|
||||
if ( !def.CanPickup(toucher) ) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
override void AttachToOwner( Actor other )
|
||||
{
|
||||
Super.AttachToOwner(other);
|
||||
|
|
@ -310,6 +286,7 @@ Class MagAmmo : Inventory abstract
|
|||
Property ParentAmmo : ParentAmmo;
|
||||
Property ClipSize : ClipSize;
|
||||
Property PickupTag : PickupTag;
|
||||
Property BackpackAmount : BackpackAmount;
|
||||
|
||||
default
|
||||
{
|
||||
|
|
@ -378,17 +355,6 @@ Class MagAmmo : Inventory abstract
|
|||
// drop excess mag ammo
|
||||
if ( (item is 'MagAmmo') && (MagAmmo(item).GetParentMagAmmo() == GetClass()) )
|
||||
{
|
||||
// can somehow happen
|
||||
if ( !pamo )
|
||||
{
|
||||
pamo = Ammo(Owner.FindInventory(ParentAmmo));
|
||||
if ( !pamo )
|
||||
{
|
||||
pamo = Ammo(Spawn(ParentAmmo));
|
||||
pamo.AttachToOwner(Owner);
|
||||
pamo.Amount = 0;
|
||||
}
|
||||
}
|
||||
if ( bUNDROPPABLE || bUNTOSSABLE )
|
||||
{
|
||||
// undroppable mag ammo only drops full mags.
|
||||
|
|
@ -503,14 +469,6 @@ Class MagAmmo : Inventory abstract
|
|||
return copy;
|
||||
}
|
||||
|
||||
override bool CanPickup( Actor toucher )
|
||||
{
|
||||
// don't allow picking up ammo for weapons we can't pick up
|
||||
if ( !Super.CanPickup(toucher) ) return false;
|
||||
let def = GetDefaultByType(ParentAmmo);
|
||||
return def.CanPickup(toucher);
|
||||
}
|
||||
|
||||
private Inventory DoDrop( Class<Inventory> type )
|
||||
{
|
||||
let copy = Inventory(Spawn(type,Owner.Pos,NO_REPLACE));
|
||||
|
|
@ -564,6 +522,18 @@ Class MagAmmo : Inventory abstract
|
|||
MagFill();
|
||||
}
|
||||
|
||||
override void AttachToOwner( Actor other )
|
||||
{
|
||||
Super.AttachToOwner(other);
|
||||
pamo = Ammo(other.FindInventory(ParentAmmo));
|
||||
if ( !pamo )
|
||||
{
|
||||
pamo = Ammo(Spawn(ParentAmmo));
|
||||
pamo.AttachToOwner(other);
|
||||
pamo.Amount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool MagFill()
|
||||
{
|
||||
// double-check that parent ammo exists
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue