GetParentAmmo

From ZDoom Wiki
Jump to navigation Jump to search

Ammo

virtual Class<Ammo> GetParentAmmo()

Usage

Returns the first ammo class that the calling class is based on. This is used to determine if a specific ammo type is a new ammo type or a new pickup for an existing ammo type.

For example, Clip is based on Ammo directly, so this function will return 'Clip'. But ClipBox is based on Clip, so this function in ClipBox will return 'Clip' as well, and thus ClipBox gives Clip when picked up.

This function must be overridden if an author wants to introduce their own base ammo class, with features/functionality that should affect all ammo types in their project.

Examples

This creates a new base ammo type, FloatingAmmoBase, which bobs in the air and is only affected by 30% of gravity. This can be used as a base to create new ammo types that will all inherit this behavior:

class FloatingAmmoBase : Ammo
{
	Default
	{
		+FLOATBOB
		Gravity 0.3;
	}

	override Class<Ammo> GetParentAmmo ()
	{
		class<Object> type = GetClass();

		while (type.GetParentClass() != "FloatingAmmoBase" && type.GetParentClass() != null)
		{
			type = type.GetParentClass();
		}
		return (class<Ammo>)(type);
	}
}