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