Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New MBF21 DEHACKED codepointers (first batch) #20

Merged
merged 20 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
8c73853
add parameterized A_MonsterProjectile and A_MonsterBulletAttack dehac…
XaserAcheron Mar 25, 2021
bec735f
add first batch of parameterized weapon dehacked code pointers
XaserAcheron Mar 25, 2021
f13d00e
don't use misc1/misc2 for offsets on states that use parameterized we…
XaserAcheron Mar 26, 2021
12cc45b
A_ConsumeAmmo update: subtract weapon's default ammo usage if misc1 i…
XaserAcheron Mar 26, 2021
40111e8
Merge branch 'master' into mbfplus-codepointers
XaserAcheron Mar 29, 2021
9b04231
add complevel guards to new mbf+ dehacked codepointers
XaserAcheron Mar 29, 2021
38d4657
add A_SpawnFacing dehacked codepointer
XaserAcheron Mar 30, 2021
f82d03b
add A_CheckAmmo and A_RefireTo dehacked codepointers
XaserAcheron Mar 30, 2021
cb821f5
add A_WeaponJump and A_GunFlashTo dehacked codepointers
XaserAcheron Mar 30, 2021
5350d47
use a single pr_mbf21 random ID rather than separate ones; turns out …
XaserAcheron Mar 31, 2021
19fc03b
move hitscan randomness code to a common function, use Eternity's met…
XaserAcheron Apr 1, 2021
8507a0c
add randomized vertical spread to A_Monster/WeaponBulletAttack if spr…
XaserAcheron Apr 1, 2021
df73a55
add A_RadiusDamage codepointer
XaserAcheron Apr 3, 2021
852dd55
change "mbf+" to "mbf21" since that seems to be the new name now ;)
XaserAcheron Apr 3, 2021
9269d20
actually use pr_class argument in P_RandomHitscanAngle (oops :P )
XaserAcheron Apr 4, 2021
5a425fc
be fancy
XaserAcheron Apr 4, 2021
c475c64
divide by 255 instead of right-shift 8 in P_RandomHitscanAngle, since…
XaserAcheron Apr 4, 2021
626cfb5
c style nitpick fixins
XaserAcheron Apr 7, 2021
0e3f8a7
Merge branch 'master' into mbfplus-codepointers
XaserAcheron Apr 7, 2021
ce19c89
add preliminary docs to mbf21.md
XaserAcheron Apr 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions prboom2/src/d_deh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1393,6 +1393,20 @@ static const deh_bexptr deh_bexptrs[] = // CPhipps - static const
{A_BetaSkullAttack, "A_BetaSkullAttack"}, // killough 10/98: beta lost souls attacked different
{A_Stop, "A_Stop"},

// [XA] New mbf21 codepointers
{A_SpawnFacing, "A_SpawnFacing"},
{A_MonsterProjectile, "A_MonsterProjectile"},
{A_MonsterBulletAttack, "A_MonsterBulletAttack"},
{A_RadiusDamage, "A_RadiusDamage"},
{A_WeaponProjectile, "A_WeaponProjectile"},
{A_WeaponBulletAttack, "A_WeaponBulletAttack"},
{A_WeaponSound, "A_WeaponSound"},
{A_WeaponJump, "A_WeaponJump"},
{A_ConsumeAmmo, "A_ConsumeAmmo"},
{A_CheckAmmo, "A_CheckAmmo"},
{A_RefireTo, "A_RefireTo"},
{A_GunFlashTo, "A_GunFlashTo"},

// This NULL entry must be the last in the list
{NULL, "A_NULL"}, // Ty 05/16/98
};
Expand Down
40 changes: 40 additions & 0 deletions prboom2/src/m_random.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "doomstat.h"
#include "m_random.h"
#include "lprintf.h"
#include "tables.h"

//
// M_Random
Expand Down Expand Up @@ -146,6 +147,45 @@ void M_ClearRandom (void)
rng.prndindex = rng.rndindex = 0; // clear two compatibility indices
}

// [XA] Common random formulas used by codepointers

//
// P_RandomHitscanAngle
// Outputs a random angle between (-spread, spread), as an int ('cause it can be negative).
// spread: Maximum angle (degrees, in fixed point -- not BAM!)
//
int P_RandomHitscanAngle(pr_class_t pr_class, fixed_t spread)
{
int t;
int_64_t spread_bam;

// FixedToAngle doesn't work for negative numbers,
// so for convenience take just the absolute value.
spread_bam = (spread < 0 ? FixedToAngle(-spread) : FixedToAngle(spread));
t = P_Random(pr_mbf21);
return (int)((spread_bam * (t - P_Random(pr_mbf21))) >> 8);
}

//
// P_RandomHitscanSlope
// Outputs a random angle between (-spread, spread), converted to values used for slope
// spread: Maximum vertical angle (degrees, in fixed point -- not BAM!)
//
int P_RandomHitscanSlope(pr_class_t pr_class, fixed_t spread)
{
int angle;

angle = P_RandomHitscanAngle(pr_class, spread);

// clamp it, yo
if (angle > ANG90)
return finetangent[0];
else if (-angle > ANG90)
return finetangent[FINEANGLES/2 - 1];
else
return finetangent[(ANG90 - angle) >> ANGLETOFINESHIFT];
}

// heretic

int P_SubRandom (void)
Expand Down
5 changes: 5 additions & 0 deletions prboom2/src/m_random.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ typedef enum {
pr_randomjump, // #61
pr_defect, // #62 // Start new entries -- add new entries below
pr_heretic, // #63
pr_mbf21, // #64

// End of new entries
NUMPRCLASS // MUST be last item in list
Expand Down Expand Up @@ -152,6 +153,10 @@ int P_Random(pr_class_t DA(const char *, int));
// Fix randoms for demos.
void M_ClearRandom(void);

// [XA] Common random formulas used by codepointers
int P_RandomHitscanAngle(pr_class_t pr_class, fixed_t spread);
int P_RandomHitscanSlope(pr_class_t pr_class, fixed_t spread);

// heretic

#define HITDICE(a) ((1+(P_Random(pr_heretic)&7))*a)
Expand Down
106 changes: 102 additions & 4 deletions prboom2/src/p_enemy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,7 @@ void A_VileAttack(mobj_t *actor)
// move the fire between the vile and the player
fire->x = actor->target->x - FixedMul (24*FRACUNIT, finecosine[an]);
fire->y = actor->target->y - FixedMul (24*FRACUNIT, finesine[an]);
P_RadiusAttack(fire, actor, 70);
P_RadiusAttack(fire, actor, 70, 70);
}

//
Expand Down Expand Up @@ -2339,7 +2339,7 @@ void A_Explode(mobj_t *thingy)
break;
}

P_RadiusAttack(thingy, thingy->target, damage);
P_RadiusAttack(thingy, thingy->target, damage, damage);
if (heretic) P_HitFloor(thingy);
}

Expand Down Expand Up @@ -2822,7 +2822,7 @@ void A_Detonate(mobj_t *mo)
!prboom_comp[PC_APPLY_MBF_CODEPOINTERS_TO_ANY_COMPLEVEL].state)
return;

P_RadiusAttack(mo, mo->target, mo->info->damage);
P_RadiusAttack(mo, mo->target, mo->info->damage, mo->info->damage);
}

//
Expand Down Expand Up @@ -2964,6 +2964,104 @@ void A_LineEffect(mobj_t *mo)
mo->player = oldplayer;
}

//
// [XA] New mbf21 codepointers
//

//
// A_SpawnFacing
// Spawns an actor facing the same direction as the caller.
// Basically just A_Spawn with a major quality-of-life tweak.
// misc1: Type of actor to spawn
// misc2: Height to spawn at, relative to calling actor
//
void A_SpawnFacing(mobj_t *actor)
{
if (!mbf21 || !actor->state->misc1)
return;

mobj_t *mo = P_SpawnMobj(actor->x, actor->y, (actor->state->misc2 << FRACBITS) + actor->z, actor->state->misc1 - 1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to declare this variable at the top and then set it here to avoid a warning in C, right? 🤓

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh, maybe. :P -- Fixed for consistency at least. ;)

if (mo)
mo->angle = actor->angle;

// [XA] don't bother with the dont-inherit-friendliness hack
// that exists in A_Spawn, 'cause WTF is that about anyway?
}

//
// A_MonsterProjectile
// A parameterized monster projectile attack.
// misc1: Type of actor to spawn
// misc2: Angle (degrees, in fixed point), relative to calling actor's angle
//
void A_MonsterProjectile(mobj_t *actor)
{
mobj_t *mo;
int an;

if (!mbf21 || !actor->target || !actor->state->misc1)
return;

A_FaceTarget(actor);
mo = P_SpawnMissile(actor, actor->target, actor->state->misc1 - 1);
if (!mo)
return;

// adjust the angle by misc2;
mo->angle += (unsigned int)(((int_64_t)actor->state->misc2 << 16) / 360);
an = mo->angle >> ANGLETOFINESHIFT;
mo->momx = FixedMul(mo->info->speed, finecosine[an]);
mo->momy = FixedMul(mo->info->speed, finesine[an]);

// always set the 'tracer' field, so this pointer
// can be used to fire seeker missiles at will.
P_SetTarget(&mo->tracer, actor->target);
}

//
// A_MonsterBulletAttack
// A parameterized monster bullet attack.
// misc1: Damage of attack (times 1d5)
// misc2: Horizontal spread (degrees, in fixed point);
// if negative, also use 2/3 of this value for vertical spread
//
void A_MonsterBulletAttack(mobj_t *actor)
{
int damage, angle, slope, t;
int_64_t spread;

if (!mbf21 || !actor->target)
return;

A_FaceTarget(actor);
S_StartSound(actor, actor->info->attacksound);

damage = (P_Random(pr_mbf21) % 5 + 1) * actor->state->misc1;

angle = (int)actor->angle + P_RandomHitscanAngle(pr_mbf21, actor->state->misc2);;
slope = P_AimLineAttack(actor, angle, MISSILERANGE, 0);

if (actor->state->misc2 < 0)
slope += P_RandomHitscanSlope(pr_mbf21, actor->state->misc2 * 2 / 3);

P_LineAttack(actor, angle, MISSILERANGE, slope, damage);
}

//
// A_RadiusDamage
// A parameterized version of A_Explode. Friggin' finally. :P
// misc1: Damage (int)
// misc2: Radius (also int; no real need for fractional precision here)
//
void A_RadiusDamage(mobj_t *actor)
{
if (!mbf21 || !actor->state)
return;

P_RadiusAttack(actor, actor->target, actor->state->misc1, actor->state->misc2);
}


// heretic

#include "heretic/def.h"
Expand Down Expand Up @@ -4114,7 +4212,7 @@ void A_VolcBallImpact(mobj_t * ball)
ball->z += 28 * FRACUNIT;
//ball->momz = 3*FRACUNIT;
}
P_RadiusAttack(ball, ball->target, 25);
P_RadiusAttack(ball, ball->target, 25, 25);
for (i = 0; i < 4; i++)
{
tiny = P_SpawnMobj(ball->x, ball->y, ball->z, HERETIC_MT_VOLCANOTBLAST);
Expand Down
7 changes: 7 additions & 0 deletions prboom2/src/p_enemy.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ void A_Stop(mobj_t *);

void A_SkullPop(mobj_t *);

// [XA] New mbf21 codepointers

void A_SpawnFacing(mobj_t *);
void A_MonsterProjectile(mobj_t *);
void A_MonsterBulletAttack(mobj_t *);
void A_RadiusDamage(mobj_t *);

// heretic

void P_NoiseAlert(mobj_t * target, mobj_t * emmiter);
Expand Down
19 changes: 15 additions & 4 deletions prboom2/src/p_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -2013,6 +2013,7 @@ void P_UseLines (player_t* player)
mobj_t *bombsource, *bombspot;
//e6y static
int bombdamage;
int bombdistance;


//
Expand All @@ -2026,6 +2027,7 @@ dboolean PIT_RadiusAttack (mobj_t* thing)
fixed_t dx;
fixed_t dy;
fixed_t dist;
int damage;

/* killough 8/20/98: allow bouncers to take damage
* (missile bouncers are already excluded with MF_NOBLOCKMAP)
Expand Down Expand Up @@ -2058,13 +2060,21 @@ dboolean PIT_RadiusAttack (mobj_t* thing)
if (dist < 0)
dist = 0;

if (dist >= bombdamage)
if (dist >= bombdistance)
return true; // out of range

if ( P_CheckSight (thing, bombspot) )
{
// must be in direct path
P_DamageMobj (thing, bombspot, bombsource, bombdamage - dist);

// [XA] independent damage/distance calculation.
// same formula as eternity; thanks Quas :P
if (bombdamage == bombdistance)
damage = bombdamage - dist;
else
damage = (bombdamage * (bombdistance - dist) / bombdistance) + 1;

P_DamageMobj (thing, bombspot, bombsource, damage);
}

return true;
Expand All @@ -2075,7 +2085,7 @@ dboolean PIT_RadiusAttack (mobj_t* thing)
// P_RadiusAttack
// Source is the creature that caused the explosion at spot.
//
void P_RadiusAttack(mobj_t* spot,mobj_t* source,int damage)
void P_RadiusAttack(mobj_t* spot,mobj_t* source, int damage, int distance)
{
int x;
int y;
Expand All @@ -2087,7 +2097,7 @@ void P_RadiusAttack(mobj_t* spot,mobj_t* source,int damage)

fixed_t dist;

dist = (damage+MAXRADIUS)<<FRACBITS;
dist = (distance+MAXRADIUS)<<FRACBITS;
yh = P_GetSafeBlockY(spot->y + dist - bmaporgy);
yl = P_GetSafeBlockY(spot->y - dist - bmaporgy);
xh = P_GetSafeBlockX(spot->x + dist - bmaporgx);
Expand All @@ -2102,6 +2112,7 @@ void P_RadiusAttack(mobj_t* spot,mobj_t* source,int damage)
bombsource = source;
}
bombdamage = damage;
bombdistance = distance;

for (y=yl ; y<=yh ; y++)
for (x=xl ; x<=xh ; x++)
Expand Down
2 changes: 1 addition & 1 deletion prboom2/src/p_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fixed_t P_AimLineAttack(mobj_t *t1,angle_t angle,fixed_t distance, uint_64_t mas

void P_LineAttack(mobj_t *t1, angle_t angle, fixed_t distance,
fixed_t slope, int damage );
void P_RadiusAttack(mobj_t *spot, mobj_t *source, int damage);
void P_RadiusAttack(mobj_t *spot, mobj_t *source, int damage, int distance);
dboolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y);

//jff 3/19/98 P_CheckSector(): new routine to replace P_ChangeSector()
Expand Down
Loading