A_CustomPunch Flag/Parameter: Hexen-style scan

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: A_CustomPunch Flag/Parameter: Hexen-style scan

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

by Edward-san » Wed May 16, 2012 1:55 pm

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

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

by Xaser » Wed May 16, 2012 1:09 pm

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).

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

by Blox » Wed May 16, 2012 12:23 pm

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? :?

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

by ChronoSeth » Tue May 15, 2012 5:40 am

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:

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

by Edward-san » Tue May 15, 2012 1:53 am

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.

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

by SFJake » Mon May 14, 2012 11:23 pm

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.

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

by Blzut3 » Mon May 14, 2012 9:53 pm

You're going to have to add the patch as an attachment since the forums screw with the whitespace otherwise.

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

by Edward-san » Mon May 14, 2012 3:41 pm

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'.

Re: A_CustomPunch Flag/Parameter: Hexen-style scan

by Edward-san » Mon May 14, 2012 1:09 pm

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...

A_CustomPunch Flag/Parameter: Hexen-style scan

by ChronoSeth » Mon May 14, 2012 12:56 pm

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?

Top