A_CustomPunch Flag/Parameter: Hexen-style scan

Moderator: GZDoom Developers

Post Reply
User avatar
ChronoSeth
Posts: 1631
Joined: Mon Jul 05, 2010 2:04 pm
Location: British Columbia

A_CustomPunch Flag/Parameter: Hexen-style scan

Post by ChronoSeth »

The Wiki, on A_FPunchAttack wrote:Search for a possible target in a 90° cone in front of the calling player, starting right ahead and scanning rightwards up to 45°, then going back center and scanning leftwards up to -45°.
It would be nice to be able to apply this effect to customizable attacks as a new flag or parameter.

Is it as simple as it sounds?
Edward-san
Posts: 1774
Joined: Sat Oct 17, 2009 9:40 am

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

Post by Edward-san »

There's even a code duplication inside that function:

Code: Select all

for (i = 0; i < 16; i++)
{
	angle = pmo->angle + i*(ANG45/16);
	//certain long code....
	angle = pmo->angle-i * (ANG45/16);
	//same long code...
}
reducing such a thing would be good... and maybe I have an idea on how to do it...

[edit]A good man suggested this:

Code: Select all

Index: src/g_hexen/a_fighterplayer.cpp
===================================================================
--- src/g_hexen/a_fighterplayer.cpp	(revision 3651)
+++ src/g_hexen/a_fighterplayer.cpp	(working copy)
@@ -77,7 +77,9 @@
 	pufftype = PClass::FindClass ("PunchPuff");
 	for (i = 0; i < 16; i++)
 	{
-		angle = pmo->angle + i*(ANG45/16);
+	for (j = 1; j >= -1; j -= 2)
+	{
+		angle = pmo->angle + i*j*(ANG45/16);
 		slope = P_AimLineAttack (pmo, angle, 2*MELEERANGE, &linetarget);
 		if (linetarget)
 		{
@@ -99,29 +101,8 @@
 				goto punchdone;
 			}
 		}
-		angle = pmo->angle-i * (ANG45/16);
-		slope = P_AimLineAttack (pmo, angle, 2*MELEERANGE, &linetarget);
-		if (linetarget)
-		{
-			pmo->special1++;
-			if (pmo->special1 == 3)
-			{
-				damage <<= 1;
-				power = 6*FRACUNIT;
-				pufftype = PClass::FindClass ("HammerPuff");
-			}
-			P_LineAttack (pmo, angle, 2*MELEERANGE, slope, damage, NAME_Melee, pufftype, true, &linetarget);
-			if (linetarget != NULL)
-			{
-				if (linetarget->flags3&MF3_ISMONSTER || linetarget->player)
-				{
-					P_ThrustMobj (linetarget, angle, power);
-				}
-				AdjustPlayerAngle (pmo, linetarget);
-				goto punchdone;
-			}
-		}
 	}
+	}
 	// didn't find any creatures, so try to strike any walls
 	pmo->special1 = 0;
 

[edit2]
starting right ahead and scanning rightwards up to 45°, then going back center and scanning leftwards up to -45°
that's a little bit wrong: the scan happens twice at right ahead, then the code scans alternatively between right and left until it scans the angles near the cone, but it doesn't check the extreme angles (pmo->angle+-45°). Do you want to just customize the cone keeping it symmetrical?

[edit3]Oops you want to change A_CustomPunch behavior...
Edward-san
Posts: 1774
Joined: Sat Oct 17, 2009 9:40 am

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

Post by Edward-san »

OT: new patch related to previous post:

Code: Select all

Index: src/g_hexen/a_fighterplayer.cpp
===================================================================
--- src/g_hexen/a_fighterplayer.cpp	(revision 3651)
+++ src/g_hexen/a_fighterplayer.cpp	(working copy)
@@ -61,10 +61,11 @@
 	int damage;
 	int slope;
 	fixed_t power;
-	int i;
+	int i,j;
 	player_t *player;
 	const PClass *pufftype;
 	AActor *linetarget;
+	bool punchdone;
 
 	if (NULL == (player = self->player))
 	{
@@ -75,9 +76,12 @@
 	damage = 40+(pr_fpatk()&15);
 	power = 2*FRACUNIT;
 	pufftype = PClass::FindClass ("PunchPuff");
+	punchdone = false;
 	for (i = 0; i < 16; i++)
 	{
-		angle = pmo->angle + i*(ANG45/16);
+	for (j = 1; j >= -1; j -= 2)
+	{
+		angle = pmo->angle + i*j*(ANG45/16);
 		slope = P_AimLineAttack (pmo, angle, 2*MELEERANGE, &linetarget);
 		if (linetarget)
 		{
@@ -96,40 +100,24 @@
 					P_ThrustMobj (linetarget, angle, power);
 				}
 				AdjustPlayerAngle (pmo, linetarget);
-				goto punchdone;
+				punchdone = true;
+				break;
 			}
 		}
-		angle = pmo->angle-i * (ANG45/16);
-		slope = P_AimLineAttack (pmo, angle, 2*MELEERANGE, &linetarget);
-		if (linetarget)
-		{
-			pmo->special1++;
-			if (pmo->special1 == 3)
-			{
-				damage <<= 1;
-				power = 6*FRACUNIT;
-				pufftype = PClass::FindClass ("HammerPuff");
-			}
-			P_LineAttack (pmo, angle, 2*MELEERANGE, slope, damage, NAME_Melee, pufftype, true, &linetarget);
-			if (linetarget != NULL)
-			{
-				if (linetarget->flags3&MF3_ISMONSTER || linetarget->player)
-				{
-					P_ThrustMobj (linetarget, angle, power);
-				}
-				AdjustPlayerAngle (pmo, linetarget);
-				goto punchdone;
-			}
-		}
 	}
+	if (punchdone)
+		break;
+	}
+	if (!punchdone)
+	{
 	// didn't find any creatures, so try to strike any walls
 	pmo->special1 = 0;
 
 	angle = pmo->angle;
 	slope = P_AimLineAttack (pmo, angle, MELEERANGE, &linetarget);
 	P_LineAttack (pmo, angle, MELEERANGE, slope, damage, NAME_Melee, pufftype, true);
+	}
 
-punchdone:
 	if (pmo->special1 == 3)
 	{
 		pmo->special1 = 0;
should remove the 'goto' hax and fixed the missing declaration of 'i'.
Blzut3
 
 
Posts: 3212
Joined: Wed Nov 24, 2004 12:59 pm
Operating System Version (Optional): Kubuntu
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Contact:

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

Post by Blzut3 »

You're going to have to add the patch as an attachment since the forums screw with the whitespace otherwise.
User avatar
SFJake
Posts: 531
Joined: Sat Nov 03, 2007 11:28 am

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

Post by SFJake »

Is this for real?

I posted this suggestions long ago, its somewhere in there.

http://forum.zdoom.org/viewtopic.php?f=15&t=29360 (link for reference or closure, do not post in it, EDIT: or nevermind, do it, I thought this topic was taking care of it ^^)

^ First one was actually already in somewhat (didn't realize it), 2nd was not.

I LOVE you Edward if this is the real thing.
Last edited by SFJake on Wed May 16, 2012 5:43 pm, edited 2 times in total.
Edward-san
Posts: 1774
Joined: Sat Oct 17, 2009 9:40 am

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

Post by Edward-san »

Sorry but that patch has nothing to do with the suggestion: it's just a related improvement to the A_FPunchAttack code.
afpunch.txt
(2.01 KiB) Downloaded 32 times
Also, imho this can be closed as 'Duplicate' and continue to discuss it in the linked thread.
User avatar
ChronoSeth
Posts: 1631
Joined: Mon Jul 05, 2010 2:04 pm
Location: British Columbia

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

Post by ChronoSeth »

SFJake wrote:I posted this suggestions long ago, its somewhere in there.

http://forum.zdoom.org/viewtopic.php?f=15&t=29360 (link for reference or closure, do not post in it)
Damn it. I had thought someone had already made a post about this, but I couldn't find it. :oops:
User avatar
Blox
Posts: 3728
Joined: Wed Sep 22, 2010 9:35 am
Location: Apathetic Limbo

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

Post by Blox »

Wouldn't it have been like.. Better to merge those two (to some sort of degree), instead of just (temporarily) trashing the actual stuff in this thread? :?
User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

Post by Xaser »

Blox wrote:Wouldn't it have been like.. Better to merge those two (to some sort of degree), instead of just (temporarily) trashing the actual stuff in this thread? :?
Trashing what? From the guy who posted the code patch:
Edward-san wrote:Also, imho this can be closed as 'Duplicate' and continue to discuss it in the linked thread.
The patch is unrelated to the feature being suggested, so a new thread should be opened for it (assuming it hasn't already).
Edward-san
Posts: 1774
Joined: Sat Oct 17, 2009 9:40 am

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

Post by Edward-san »

When I'll learn about how to add/manage parameters correctly, I'll use that patch together with the change to A_CustomPunch.
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”