Re: A_SetDuration Code Pointer

Moderator: GZDoom Developers

User avatar
HotWax
Posts: 10002
Joined: Fri Jul 18, 2003 6:18 pm
Location: Idaho Falls, ID

Re: A_SetDuration Code Pointer

Post by HotWax »

Well... That was easy.

[edit] The patch is now an attachment [/edit]

And it seems I misunderstood how ZDoom processes frames, because A_Delay actually affects its own frame and not the previous. Works like a charm:

Code: Select all

actor CrazyImp : DoomImp replaces DoomImp
{
	States
	{		
		Spawn:
			// Who says you can't have 0-tic loops!? ;)
			TROO A 0 A_Look
			TROO A 0 A_Delay(random(1, 3) * 10)
			TROO B 0 A_Look
			TROO B 0 A_Delay (random(1, 3) * 10)
			loop
		Melee:
		Missile:
			TROO EF 8 A_FaceTarget
			TROO F 0 A_Delay (random(0, 5) * 5)
			TROO G 6 A_TroopAttack  // See DoomImpBall
			TROO G 5 A_Delay (random(0, 10))
			goto See
		Pain:
			TROO H 2 A_Delay (random(0, 4))
			TROO H 2 A_Pain
			TROO H 0 A_Delay (random(0, 5) * 7)
			goto See
	}
}

// Hey, is that per-actor slow-mo I see there?!
actor MrSpeedUp : ZombieMan replaces ZombieMan
{
	States
	{
		See:
			POSS A 1 A_Chase
			POSS A 0 A_Delay(health)
			POSS B 1 A_Chase
			POSS B 0 A_Delay(health)
			POSS C 1 A_Chase
			POSS C 0 A_Delay(health)
			POSS D 1 A_Chase
			POSS D 0 A_Delay(health)
			loop
		Missile:
			POSS E 1 A_FaceTarget
			POSS E 0 A_Delay(health)
			POSS F 1 A_PosAttack
			POSS F 0 A_Delay(health)
			POSS E 1 A_Delay(health)
			goto See
		Pain:
			POSS G 1 A_Delay(health)
			POSS G 1 A_Pain
			POSS G 1 A_Delay(health)
			goto See
	}
}
Ready for move to Code Submissions.
Attachments
A_Delay.txt
(1.09 KiB) Downloaded 87 times
Last edited by HotWax on Thu Jul 02, 2009 3:01 pm, edited 1 time in total.
User avatar
The Slimeinator
Posts: 44
Joined: Fri Jun 26, 2009 1:23 pm

Re: A_SetDuration Code Pointer

Post by The Slimeinator »

HotWax wrote:Well... That was easy.

Code: Select all

Index: src/thingdef/thingdef_codeptr.cpp
===================================================================
--- src/thingdef/thingdef_codeptr.cpp	(revision 1701)
+++ src/thingdef/thingdef_codeptr.cpp	(working copy)
@@ -2671,3 +2671,17 @@
 		CheckStopped(self);
 	}
 }
+
+//===========================================================================
+//
+// A_Delay
+//
+//===========================================================================
+DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_Delay)
+{
+	ACTION_PARAM_START(1);
+	ACTION_PARAM_INT(delay, 0);
+
+	if (delay > 0)
+		self->tics += delay;
+}
\ No newline at end of file
Index: wadsrc/static/actors/actor.txt
===================================================================
--- wadsrc/static/actors/actor.txt	(revision 1701)
+++ wadsrc/static/actors/actor.txt	(working copy)
@@ -245,6 +245,7 @@
 	action native A_SetPitch(float pitch);
 	action native A_ScaleVelocity(float scale);
 	action native A_ChangeVelocity(float x = 0, float y = 0, float z = 0, int flags = 0);
+	action native A_Delay(int delay);
 
 	States
 	{
And it seems I misunderstood how ZDoom processes frames, because A_Delay actually affects its own frame and not the previous. Works like a charm:

Code: Select all

actor CrazyImp : DoomImp replaces DoomImp
{
	States
	{		
		Spawn:
			// Who says you can't have 0-tic loops!? ;)
			TROO A 0 A_Look
			TROO A 0 A_Delay(random(1, 3) * 10)
			TROO B 0 A_Look
			TROO B 0 A_Delay (random(1, 3) * 10)
			loop
		Melee:
		Missile:
			TROO EF 8 A_FaceTarget
			TROO F 0 A_Delay (random(0, 5) * 5)
			TROO G 6 A_TroopAttack  // See DoomImpBall
			TROO G 5 A_Delay (random(0, 10))
			goto See
		Pain:
			TROO H 2 A_Delay (random(0, 4))
			TROO H 2 A_Pain
			TROO H 0 A_Delay (random(0, 5) * 7)
			goto See
	}
}

// Hey, is that per-actor slow-mo I see there?!
actor MrSpeedUp : ZombieMan replaces ZombieMan
{
	States
	{
		See:
			POSS A 1 A_Chase
			POSS A 0 A_Delay(health)
			POSS B 1 A_Chase
			POSS B 0 A_Delay(health)
			POSS C 1 A_Chase
			POSS C 0 A_Delay(health)
			POSS D 1 A_Chase
			POSS D 0 A_Delay(health)
			loop
		Missile:
			POSS E 1 A_FaceTarget
			POSS E 0 A_Delay(health)
			POSS F 1 A_PosAttack
			POSS F 0 A_Delay(health)
			POSS E 1 A_Delay(health)
			goto See
		Pain:
			POSS G 1 A_Delay(health)
			POSS G 1 A_Pain
			POSS G 1 A_Delay(health)
			goto See
	}
}
Ready for move to Code Submissions.
Thanks for the patch.
User avatar
bagheadspidey
Posts: 1490
Joined: Sat Oct 20, 2007 10:31 pm
Contact:

A_SetDuration Code Pointer

Post by bagheadspidey »

Nice one. I support this. Haven't tried it yet, but do bad things happen if you put delays in the pickup or use states of a CustomInventory?
User avatar
Nash
 
 
Posts: 17434
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: A_SetDuration Code Pointer

Post by Nash »

Could this be used to dynamically alter a weapon's animation speed?

In my RPG-ish mod thingy, I want the player's melee attack speed to be based on how much strength (an inventory item) he has. A weak fighter will have some trouble swinging a heavy axe, while a strong fighter will be able to swing it around like it's a piece of light wood.
User avatar
Rachael
Posts: 13531
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: A_SetDuration Code Pointer

Post by Rachael »

Merging into community build (though I see no reason why this won't be merged, anyway)
Gez
 
 
Posts: 17833
Joined: Fri Jul 06, 2007 3:22 pm

Re: A_SetDuration Code Pointer

Post by Gez »

bagheadspidey wrote:do bad things happen if you put delays in the pickup or use states of a CustomInventory?
Very important point.
User avatar
Rachael
Posts: 13531
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: A_SetDuration Code Pointer

Post by Rachael »

Gez wrote:
bagheadspidey wrote:do bad things happen if you put delays in the pickup or use states of a CustomInventory?
Very important point.
This can be tested now.

http://svn.drdteam.org/community/zdoom- ... r1701M.zip
User avatar
bagheadspidey
Posts: 1490
Joined: Sat Oct 20, 2007 10:31 pm
Contact:

Re: A_SetDuration Code Pointer

Post by bagheadspidey »

Hmm, overall it's pretty benign. This code creates a weird situation:

Code: Select all

actor shit : CustomInventory 
{  
  States
  {  
  Pickup:
     // TNT1 A 0 ThrustThing(angle*256/360, 1, 0, 0)
     TNT1 A 0 A_ChangeVelocity(0, 1.0)
     TNT1 A 0 A_Delay(1)
  }
} 
For some reason it only happens with ChangeVelocity, not ThrustThing, but leaving any delay in there will cause the player to instantly "teleport" as far as he can until he hits a wall upon getting this item. If A_Delay is commented out, the player just gets a little nudge.

Anyway, it's the only adverse effect I've seen, and it's not too bad. What I can't seem to figure out is why this affects ChangeVelocity but not ThrustThing?
User avatar
HotWax
Posts: 10002
Joined: Fri Jul 18, 2003 6:18 pm
Location: Idaho Falls, ID

Re: A_SetDuration Code Pointer

Post by HotWax »

Thanks for your testing on this. I'm not very practiced in Decorate and I suspected there were going to be some weird uses that could screw things up, but I couldn't think of any.

Do you think this needs to be resolved in code or is more something the author should need to be aware of? I'd rather put power into the modder's hands than to artifically take it away to avoid mis-use, but if needed I could probably have the function refuse to run on certain class types.

Also if you can find any other ways to screw things up with it, let me know. Crashes or game hangs would be the biggest issues, obviously. Right now the only thing I can think of is somebody unintentionally generating a 0-tic loop by misusing the expression evaluator. Don't think there's anything I can do about that, though.
User avatar
Enjay
 
 
Posts: 26517
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: A_SetDuration Code Pointer

Post by Enjay »

Can I ask what the advantage is for this pointer? Is it just that it makes random durations possible or is there something else? If it is just random durations, then would it not have been better to simply* have random durations.

*The author of this post has no idea how "simple" adding random durations would be nor, for that matter, if they are even possible.
User avatar
Rachael
Posts: 13531
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: A_SetDuration Code Pointer

Post by Rachael »

I think HotWax's solution is actually the simplest, without requiring any rewrites of code - it's also easy to use.
User avatar
Enjay
 
 
Posts: 26517
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: A_SetDuration Code Pointer

Post by Enjay »

Easier than:

TROO A (random (1,6)) A_Look

Or similar :?:
User avatar
Nash
 
 
Posts: 17434
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia
Contact:

Re: A_SetDuration Code Pointer

Post by Nash »

As I've asked in my previous post, I think the advantage of this is that frames can have their durations altered dynamically in-game...

Here are some uses I can think of:

1) Monsters that move slower the less health it has.
2) Weapon attacks (mainly useful for melee-style weapons) that can be sped up or down depending on certain conditions.
3) Randomized durations for that extra randomness (useful for stuff like particle effects and explosions).

EDIT: Enjay, I don't think that piece of DECORATE snippet works... ?
Last edited by Nash on Thu Jul 02, 2009 2:52 pm, edited 1 time in total.
User avatar
The Slimeinator
Posts: 44
Joined: Fri Jun 26, 2009 1:23 pm

Re: A_SetDuration Code Pointer

Post by The Slimeinator »

@Enjay: That won't work. This feature request came from an old feature request that requested that method. Graf said that couldn't work. Thus, A_Delay instead.
User avatar
Rachael
Posts: 13531
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: A_SetDuration Code Pointer

Post by Rachael »

Enjay wrote:Easier than:

TROO A (random (1,6)) A_Look

Or similar :?:
That's another thing - you're kinda screwing with the format of DECORATE. If that's already possible, then consider my last 2 statements null and void. If not, you'd have to add in a lot of spaces between durations and code pointers if you want to line up your code properly. And the more spacing you do with code, the more it goes off the edge of the editor, and the more of a pain in the butt it is to maintain.
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”