Partial Hexen compatibility. Ammo pickups are not yet implemented.

This commit is contained in:
Marisa the Magician 2019-12-13 19:03:01 +01:00
commit cd0d7d0ec7
10 changed files with 184 additions and 13 deletions

View file

@ -276,3 +276,145 @@ Class ActMedBox : UTActivatableHealth
Stop;
}
}
// to compensate for hexen's shared ammo
Class UTHexenAmmoBox : Inventory
{
int AmmoFactor;
Property AmmoFactor : AmmoFactor;
default
{
UTHexenAmmoBox.AmmoFactor -1;
+INVENTORY.ALWAYSPICKUP;
Inventory.PickupSound = "misc/i_pkup";
}
override bool TryPickup( in out Actor toucher )
{
bool hasgiven = (AmmoFactor <= 0); // always true
for ( int i=0; i<AllActorClasses.Size(); i++ )
{
let type = (class<Ammo>)(AllActorClasses[i]);
if ( !type || (type.GetParentClass() != 'Ammo') ) continue;
// check that it's for a valid weapon
bool isvalid = false;
for ( int j=0; j<AllActorClasses.Size(); j++ )
{
let type2 = (class<Weapon>)(AllActorClasses[j]);
if ( !type2 ) continue;
let rep = GetReplacement(type2);
if ( (rep != type2) && !(rep is "DehackedPickup") ) continue;
readonly<Weapon> weap = GetDefaultByType(type2);
if ( !toucher.player || !toucher.player.weapons.LocateWeapon(type2) || weap.bCheatNotWeapon ) continue;
if ( (weap.AmmoType1 == type) || (weap.AmmoType2 == type) )
{
isvalid = true;
break;
}
}
// sneaky fix for chainsaw ammo
if ( (type is 'ChainsawAmmo') && flak_sawammo ) isvalid = true;
if ( !isvalid ) continue;
let ammoitem = Ammo(toucher.FindInventory(type));
int amount;
if ( AmmoFactor < 0 ) amount = GetDefaultByType(type).MaxAmount;
else
{
amount = (GetDefaultByType(type).Amount*100)/AmmoFactor;
// extra ammo in baby mode and nightmare mode
if ( !bIgnoreSkill ) amount = int(amount*G_SkillPropertyFloat(SKILLP_AmmoFactor));
}
if ( amount < 0 ) amount = 0;
if ( !ammoitem )
{
// The player did not have the ammoitem. Add it.
ammoitem = Ammo(Spawn(type));
ammoitem.Amount = bDepleted?0:amount;
if ( ammoitem.Amount > ammoitem.MaxAmount )
ammoitem.Amount = ammoitem.MaxAmount;
ammoitem.AttachToOwner(toucher);
hasgiven = true;
}
else
{
// The player had the ammoitem. Give some more.
if ( !bDepleted && (ammoitem.Amount < ammoitem.MaxAmount) )
{
ammoitem.Amount += amount;
if ( ammoitem.Amount > ammoitem.MaxAmount )
ammoitem.Amount = ammoitem.MaxAmount;
hasgiven = true;
}
}
}
if ( !hasgiven ) return false;
GoAwayAndDie();
return true;
}
}
Class UTMinorAmmoBox : UTHexenAmmoBox
{
default
{
Tag "$T_AMMOBOXLOW";
Inventory.PickupMessage "$I_AMMOBOXLOW";
UTHexenAmmoBox.AmmoFactor 60;
}
States
{
Spawn:
ABOX A -1;
Stop;
}
}
Class UTMediumAmmoBox : UTHexenAmmoBox
{
default
{
Tag "$T_AMMOBOXMED";
Inventory.PickupMessage "$I_AMMOBOXMED";
UTHexenAmmoBox.AmmoFactor 120;
}
States
{
Spawn:
ABOX B -1;
Stop;
}
}
Class UTMajorAmmoBox : UTHexenAmmoBox
{
default
{
Tag "$T_AMMOBOXHIGH";
Inventory.PickupMessage "$I_AMMOBOXHIGH";
UTHexenAmmoBox.AmmoFactor 180;
}
States
{
Spawn:
ABOX C -1;
Stop;
}
}
Class ActUTFullAmmoBox : UTActivatable
{
Default
{
Tag "$T_AMMOBOXFULL";
Inventory.Icon "ItemABox";
Inventory.PickupMessage "$I_AMMOBOXFULL";
+COUNTITEM;
+INVENTORY.BIGPOWERUP;
UTActivatable.GiveItem "UTHexenAmmoBox";
Inventory.RespawnTics 4200;
}
States
{
Spawn:
ABOX D -1;
Stop;
}
}