Expand A_TossGib to take a class name?

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: GZDoom Developers

User avatar
Enjay
 
 
Posts: 27266
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Expand A_TossGib to take a class name?

Post by Enjay »

A_TossGib currently takes no parameters and just auto-spawns the "Meat" actor or the "Junk" actor, depending on whether the calling actor bleeds or not. It would be useful if A_TossGib could be expanded to take the name of a class to spawn instead of either of these:

A_TossGib("MyCoolGibs");

It strikes me as the kind of thing that *might* be a relatively easy thing to insert into the A_TossGib function code.

I am aware that there is also A_SpawnDebris but it behaves slightly differently and the setup of the actors that it spawns is different too, as is how they behave. I also know that it can be faked by using A_SpawnProjectile. In both cases, I prefer the behaviour and implementation of A_TossGib.

Being able to specify a class in A_TossGib would make it easier to create drop-in replacement actors, or actors that inherit from others but which spawn different meat/junk.

I did a quick search of the forum to see if it was mentioned anywhere and all I found was a post by me in a "how do I" editing thread from 2012 asking if it was possible to specify actors for A_TossGib. :lol:
User avatar
MartinHowe
Posts: 2094
Joined: Mon Aug 11, 2003 1:50 pm
Preferred Pronouns: He/Him
Location: East Suffolk (UK)

Re: Expand A_TossGib to take a class name?

Post by MartinHowe »

A_TossGib is already scriptified (in [ug]zdoom.pk3/actors/strife/strifefunctions.zs) so you could just copy the code and roll your own as a workaround:

Code: Select all

	void A_TossGib()
	{
		class <Actor> gibtype;
		if (bNoBlood) gibtype = "Junk";
		else gibtype = "Meat";
		Actor gib = Spawn (gibtype, pos + (0,0,24), ALLOW_REPLACE);

		if (gib == null)
		{
			return;
		}

		gib.Angle = random[GibTosser]() * (360 / 256.);
		gib.VelFromAngle(random[GibTosser](0, 15));
		gib.Vel.Z = random[GibTosser](0, 15);
	}
Maybe something like

Code: Select all

	void A_NJTossGib(class <Actor> gibtype = null)
	{
		if (!gibtype)
		{
		    if (bNoBlood) gibtype = "Junk";
		    else gibtype = "Meat";
		}
		
		Actor gib = Spawn (gibtype, pos + (0,0,24), ALLOW_REPLACE);

		if (gib == null)
		{
			return;
		}

		gib.Angle = random[GibTosser]() * (360 / 256.);
		gib.VelFromAngle(random[GibTosser](0, 15));
		gib.Vel.Z = random[GibTosser](0, 15);
	}
By having the default optional parameter be null, it will behave as the original if no gibtype is specified. Not tested, just a thought.
User avatar
Enjay
 
 
Posts: 27266
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: Expand A_TossGib to take a class name?

Post by Enjay »

Thanks for the suggestion. I'll give it a try and see if I can get that working. Much appreciated. I'd actually looked at the code and thought I could see where allowing use of an alternative actor would go, but I didn't know enough to figure out how actually actually write it. I can certainly follow your example though. Thanks again.

It would still be nice if there was a built-in option for anyone to use "off the shelf".

[edit]OK, I think I've figured it out (I certainly got it working for one actor). My initial stumbling block was that apparently you can't extend the ACTOR class:
the Wiki wrote:I.e. extending class Actor is impossible since it's defined within gzdoom.pk3 archive. Any attempt to extend a class in another archive file will result in an error at compile time.
So, I think I'm right in saying I'd have to extend every actor type that I want to use "A_NJTossGib" separately, or create a generic Actor substitute for them all to inherit from if I didn't want to place the extending code in each one?[/edit]
Post Reply

Return to “Feature Suggestions [GZDoom]”