- aim and all calling instances.

This also takes care of RR's chicken arrow storing an actor reference in lotag.
This commit is contained in:
Christoph Oelckers 2020-11-01 20:57:02 +01:00
parent 8268c1b538
commit 768487584e
7 changed files with 123 additions and 119 deletions

View file

@ -1116,11 +1116,12 @@ static void chickenarrow(DDukeActor* actor)
spawn(actor, MONEY); spawn(actor, MONEY);
} }
} }
auto ts = &hittype[s->lotag]; // Grrrr... auto ts = actor->seek_actor;
if (!ts) return;
if (ts->s.extra <= 0) if (ts->s.extra <= 0)
s->lotag = 0; actor->seek_actor = nullptr;
if (s->lotag != 0 && s->hitag > 5) if (actor->seek_actor && s->hitag > 5)
{ {
int ang, ang2, ang3; int ang, ang2, ang3;
ang = getangle(ts->s.x - s->x, ts->s.y - s->y); ang = getangle(ts->s.x - s->x, ts->s.y - s->y);

View file

@ -128,7 +128,7 @@ void playerAimUp(int snum, ESyncBits actions);
void playerAimDown(int snum, ESyncBits actions); void playerAimDown(int snum, ESyncBits actions);
bool view(struct player_struct* pp, int* vx, int* vy, int* vz, short* vsectnum, int ang, fixed_t q16horiz, double smoothratio); bool view(struct player_struct* pp, int* vx, int* vy, int* vz, short* vsectnum, int ang, fixed_t q16horiz, double smoothratio);
void tracers(int x1, int y1, int z1, int x2, int y2, int z2, int n); void tracers(int x1, int y1, int z1, int x2, int y2, int z2, int n);
int aim(spritetype* s, int aang); DDukeActor* aim(DDukeActor* s, int aang);
void checkweapons(struct player_struct* const p); void checkweapons(struct player_struct* const p);
int findotherplayer(int p, int* d); int findotherplayer(int p, int* d);
void quickkill(struct player_struct* p); void quickkill(struct player_struct* p);

View file

@ -281,13 +281,14 @@ int hitawall(struct player_struct* p, int* hitw)
// //
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
int aim(spritetype* s, int aang) DDukeActor* aim(DDukeActor* actor, int aang)
{ {
char gotshrinker, gotfreezer; char gotshrinker, gotfreezer;
int i, j, a, k, cans; int a, k, cans;
int aimstats[] = { STAT_PLAYER, STAT_DUMMYPLAYER, STAT_ACTOR, STAT_ZOMBIEACTOR }; int aimstats[] = { STAT_PLAYER, STAT_DUMMYPLAYER, STAT_ACTOR, STAT_ZOMBIEACTOR };
int dx1, dy1, dx2, dy2, dx3, dy3, smax, sdist; int dx1, dy1, dx2, dy2, dx3, dy3, smax, sdist;
int xv, yv; int xv, yv;
auto s = &actor->s;
a = s->ang; a = s->ang;
@ -298,7 +299,7 @@ int aim(spritetype* s, int aang)
{ {
// The chickens in RRRA are homing and must always autoaim. // The chickens in RRRA are homing and must always autoaim.
if (!isRRRA() || ps[s->yvel].curr_weapon != CHICKEN_WEAPON) if (!isRRRA() || ps[s->yvel].curr_weapon != CHICKEN_WEAPON)
return -1; return nullptr;
} }
else if (ps[s->yvel].auto_aim == 2) else if (ps[s->yvel].auto_aim == 2)
{ {
@ -313,12 +314,12 @@ int aim(spritetype* s, int aang)
} }
if (weap > CHAINGUN_WEAPON || weap == KNEE_WEAPON) if (weap > CHAINGUN_WEAPON || weap == KNEE_WEAPON)
{ {
return -1; return nullptr;
} }
} }
} }
j = -1; DDukeActor* aimed = nullptr;
// if(s->picnum == TILE_APLAYER && ps[s->yvel].aim_mode) return -1; // if(s->picnum == TILE_APLAYER && ps[s->yvel].aim_mode) return -1;
if (isRR()) if (isRR())
@ -349,13 +350,12 @@ int aim(spritetype* s, int aang)
for (k = 0; k < 4; k++) for (k = 0; k < 4; k++)
{ {
if (j >= 0) if (aimed)
break; break;
DukeStatIterator it(aimstats[k]); DukeStatIterator it(aimstats[k]);
while (auto act = it.Next()) while (auto act = it.Next())
{ {
i = act->GetIndex();
auto sp = &act->s; auto sp = &act->s;
if (sp->xrepeat > 0 && sp->extra >= 0 && (sp->cstat & (257 + 32768)) == 257) if (sp->xrepeat > 0 && sp->extra >= 0 && (sp->cstat & (257 + 32768)) == 257)
if (badguy(sp) || k < 2) if (badguy(sp) || k < 2)
@ -391,7 +391,7 @@ int aim(spritetype* s, int aang)
if (a && cans) if (a && cans)
{ {
smax = sdist; smax = sdist;
j = int(act-hittype); aimed = act;
} }
} }
} }
@ -399,7 +399,7 @@ int aim(spritetype* s, int aang)
} }
} }
return j; return aimed;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View file

@ -319,7 +319,7 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith
auto s = &actor->s; auto s = &actor->s;
int sect = s->sectnum; int sect = s->sectnum;
int zvel; int zvel;
short hitsect, hitspr, hitwall, l, j, k = -1; short hitsect, hitspr, hitwall, l, k;
int hitx, hity, hitz; int hitx, hity, hitz;
if (s->extra >= 0) s->shade = -96; if (s->extra >= 0) s->shade = -96;
@ -329,16 +329,16 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith
SetGameVarID(g_iAimAngleVarID, AUTO_AIM_ANGLE, actor, p); SetGameVarID(g_iAimAngleVarID, AUTO_AIM_ANGLE, actor, p);
OnEvent(EVENT_GETAUTOAIMANGLE, p, ps[p].GetActor(), -1); OnEvent(EVENT_GETAUTOAIMANGLE, p, ps[p].GetActor(), -1);
int varval = GetGameVarID(g_iAimAngleVarID, actor, p); int varval = GetGameVarID(g_iAimAngleVarID, actor, p);
j = -1; DDukeActor* aimed = nullptr;
if (varval > 0) if (varval > 0)
{ {
j = aim(s, varval); aimed = aim(actor, varval);
} }
if (j >= 0) if (aimed)
{ {
int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (5 << 8); int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) + (5 << 8);
switch (sprite[j].picnum) switch (aimed->s.picnum)
{ {
case GREENSLIME: case GREENSLIME:
case GREENSLIME + 1: case GREENSLIME + 1:
@ -352,8 +352,8 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith
dal -= (8 << 8); dal -= (8 << 8);
break; break;
} }
zvel = ((sprite[j].z - sz - dal) << 8) / ldist(&sprite[ps[p].i], &sprite[j]); zvel = ((aimed->s.z - sz - dal) << 8) / ldist(ps[p].GetActor(), aimed);
sa = getangle(sprite[j].x - sx, sprite[j].y - sy); sa = getangle(aimed->s.x - sx, aimed->s.y - sy);
} }
if (isWW2GI()) if (isWW2GI())
@ -367,14 +367,14 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith
zRange = GetGameVarID(g_iZRangeVarID, actor, p); zRange = GetGameVarID(g_iZRangeVarID, actor, p);
sa += (angRange / 2) - (krand() & (angRange - 1)); sa += (angRange / 2) - (krand() & (angRange - 1));
if (j == -1) if (aimed == nullptr)
{ {
// no target // no target
zvel = -ps[p].horizon.sum().asq16() >> 11; zvel = -ps[p].horizon.sum().asq16() >> 11;
} }
zvel += (zRange / 2) - (krand() & (zRange - 1)); zvel += (zRange / 2) - (krand() & (zRange - 1));
} }
else if (j == -1) else if (aimed == nullptr)
{ {
sa += 16 - (krand() & 31); sa += 16 - (krand() & 31);
zvel = -ps[p].horizon.sum().asq16() >> 11; zvel = -ps[p].horizon.sum().asq16() >> 11;
@ -386,7 +386,7 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith
else else
{ {
int x; int x;
j = findplayer(s, &x); int j = findplayer(actor, &x);
sz -= (4 << 8); sz -= (4 << 8);
zvel = ((ps[j].posz - sz) << 8) / (ldist(&sprite[ps[j].i], s)); zvel = ((ps[j].posz - sz) << 8) / (ldist(&sprite[ps[j].i], s));
if (s->picnum != BOSS1) if (s->picnum != BOSS1)
@ -559,10 +559,11 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith
static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith) static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith)
{ {
spritetype* const s = &sprite[i]; auto actor = &hittype[i];
spritetype* const s = &actor->s;
int sect = s->sectnum; int sect = s->sectnum;
int vel, zvel; int vel, zvel;
short l, j, scount; short l, scount;
if (s->extra >= 0) s->shade = -96; if (s->extra >= 0) s->shade = -96;
@ -585,13 +586,13 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith)
if (p >= 0) if (p >= 0)
{ {
j = aim(s, AUTO_AIM_ANGLE); auto aimed = aim(actor, AUTO_AIM_ANGLE);
if (j >= 0) if (aimed)
{ {
int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) - (12 << 8); int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) - (12 << 8);
zvel = ((sprite[j].z - sz - dal) * vel) / ldist(&sprite[ps[p].i], &sprite[j]); zvel = ((aimed->s.z - sz - dal) * vel) / ldist(ps[p].GetActor(), aimed);
sa = getangle(sprite[j].x - sx, sprite[j].y - sy); sa = getangle(aimed->s.x - sx, aimed->s.y - sy);
} }
else else
zvel = -mulscale16(ps[p].horizon.sum().asq16(), 98); zvel = -mulscale16(ps[p].horizon.sum().asq16(), 98);
@ -599,7 +600,7 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith)
else else
{ {
int x; int x;
j = findplayer(s, &x); int j = findplayer(actor, &x);
// sa = getangle(ps[j].oposx-sx,ps[j].oposy-sy); // sa = getangle(ps[j].oposx-sx,ps[j].oposy-sy);
sa += 16 - (krand() & 31); sa += 16 - (krand() & 31);
zvel = (((ps[j].oposz - sz + (3 << 8))) * vel) / ldist(&sprite[ps[j].i], s); zvel = (((ps[j].oposz - sz + (3 << 8))) * vel) / ldist(&sprite[ps[j].i], s);
@ -636,7 +637,7 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith)
while (scount > 0) while (scount > 0)
{ {
j = EGS(sect, sx, sy, sz, atwith, -127, sizx, sizy, sa, vel, zvel, i, 4); int j = EGS(sect, sx, sy, sz, atwith, -127, sizx, sizy, sa, vel, zvel, i, 4);
sprite[j].extra += (krand() & 7); sprite[j].extra += (krand() & 7);
if (atwith == COOLEXPLOSION1) if (atwith == COOLEXPLOSION1)
@ -670,27 +671,28 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith)
static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith) static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith)
{ {
spritetype* const s = &sprite[i]; auto actor = &hittype[i];
auto s = &actor->s;
int sect = s->sectnum; int sect = s->sectnum;
int vel, zvel; int vel, zvel;
short l, j, scount; short l, scount;
if (s->extra >= 0) s->shade = -96; if (s->extra >= 0) s->shade = -96;
scount = 1; scount = 1;
vel = 644; vel = 644;
j = -1; DDukeActor* aimed = nullptr;
if (p >= 0) if (p >= 0)
{ {
j = aim(s, 48); aimed = aim(actor, 48);
if (j >= 0) if (aimed)
{ {
int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (8 << 8); int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) + (8 << 8);
zvel = ((sprite[j].z - sz - dal) * vel) / ldist(&sprite[ps[p].i], &sprite[j]); zvel = ((aimed->s.z - sz - dal) * vel) / ldist(ps[p].GetActor(), aimed);
if (sprite[j].picnum != RECON) if (aimed->s.picnum != RECON)
sa = getangle(sprite[j].x - sx, sprite[j].y - sy); sa = getangle(aimed->s.x - sx, aimed->s.y - sy);
} }
else zvel = -mulscale16(ps[p].horizon.sum().asq16(), 81); else zvel = -mulscale16(ps[p].horizon.sum().asq16(), 81);
if (atwith == RPG) if (atwith == RPG)
@ -700,7 +702,7 @@ static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith)
else else
{ {
int x; int x;
j = findplayer(s, &x); int j = findplayer(actor, &x);
sa = getangle(ps[j].oposx - sx, ps[j].oposy - sy); sa = getangle(ps[j].oposx - sx, ps[j].oposy - sy);
if (s->picnum == BOSS3) if (s->picnum == BOSS3)
{ {
@ -724,10 +726,7 @@ static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith)
if (badguy(s) && (s->hitag & face_player_smart)) if (badguy(s) && (s->hitag & face_player_smart))
sa = s->ang + (krand() & 31) - 16; sa = s->ang + (krand() & 31) - 16;
} }
if (p < 0) aimed = nullptr;
if (p >= 0 && j >= 0)
l = j;
else l = -1;
auto spawned = EGS(sect, auto spawned = EGS(sect,
sx + (sintable[(348 + sa + 512) & 2047] / 448), sx + (sintable[(348 + sa + 512) & 2047] / 448),
@ -737,7 +736,7 @@ static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith)
auto spj = &spawned->s; auto spj = &spawned->s;
spj->extra += (krand() & 7); spj->extra += (krand() & 7);
if (atwith != FREEZEBLAST) if (atwith != FREEZEBLAST)
spawned->temp_actor = l >= 0? &hittype[l] : nullptr;// spawned->s.yvel = l; spawned->temp_actor = aimed;
else else
{ {
spj->yvel = numfreezebounces; spj->yvel = numfreezebounces;
@ -911,19 +910,20 @@ static void shootlaser(int i, int p, int sx, int sy, int sz, int sa)
static void shootgrowspark(int i, int p, int sx, int sy, int sz, int sa) static void shootgrowspark(int i, int p, int sx, int sy, int sz, int sa)
{ {
spritetype* const s = &sprite[i]; auto actor = &hittype[i];
auto s = &actor->s;
int sect = s->sectnum; int sect = s->sectnum;
int zvel; int zvel;
short hitsect, hitspr, hitwall, j, k; short hitsect, hitspr, hitwall, k;
int hitx, hity, hitz; int hitx, hity, hitz;
if (p >= 0) if (p >= 0)
{ {
j = aim(s, AUTO_AIM_ANGLE); auto aimed = aim(actor, AUTO_AIM_ANGLE);
if (j >= 0) if (aimed)
{ {
int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (5 << 8); int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) + (5 << 8);
switch (sprite[j].picnum) switch (aimed->s.picnum)
{ {
case GREENSLIME: case GREENSLIME:
case GREENSLIME + 1: case GREENSLIME + 1:
@ -937,8 +937,8 @@ static void shootgrowspark(int i, int p, int sx, int sy, int sz, int sa)
dal -= (8 << 8); dal -= (8 << 8);
break; break;
} }
zvel = ((sprite[j].z - sz - dal) << 8) / (ldist(&sprite[ps[p].i], &sprite[j])); zvel = ((aimed->s.z - sz - dal) << 8) / (ldist(ps[p].GetActor(), aimed));
sa = getangle(sprite[j].x - sx, sprite[j].y - sy); sa = getangle(aimed->s.x - sx, aimed->s.y - sy);
} }
else else
{ {
@ -952,7 +952,7 @@ static void shootgrowspark(int i, int p, int sx, int sy, int sz, int sa)
else else
{ {
int x; int x;
j = findplayer(s, &x); int j = findplayer(s, &x);
sz -= (4 << 8); sz -= (4 << 8);
zvel = ((ps[j].posz - sz) << 8) / (ldist(&sprite[ps[j].i], s)); zvel = ((ps[j].posz - sz) << 8) / (ldist(&sprite[ps[j].i], s));
zvel += 128 - (krand() & 255); zvel += 128 - (krand() & 255);
@ -971,7 +971,7 @@ static void shootgrowspark(int i, int p, int sx, int sy, int sz, int sa)
s->cstat |= 257; s->cstat |= 257;
j = EGS(sect, hitx, hity, hitz, GROWSPARK, -16, 28, 28, sa, 0, 0, i, 1); int j = EGS(sect, hitx, hity, hitz, GROWSPARK, -16, 28, 28, sa, 0, 0, i, 1);
sprite[j].pal = 2; sprite[j].pal = 2;
sprite[j].cstat |= 130; sprite[j].cstat |= 130;
@ -1141,19 +1141,19 @@ void shoot_d(int i, int atwith)
if (s->extra >= 0) s->shade = -96; if (s->extra >= 0) s->shade = -96;
if (p >= 0) if (p >= 0)
{ {
j = isNamWW2GI()? -1 : aim(s, AUTO_AIM_ANGLE); auto aimed = isNamWW2GI()? nullptr : aim(actor, AUTO_AIM_ANGLE);
if (j >= 0) if (aimed)
{ {
dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1); dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1);
zvel = ((sprite[j].z - sz - dal - (4 << 8)) * 768) / (ldist(&sprite[ps[p].i], &sprite[j])); zvel = ((aimed->s.z - sz - dal - (4 << 8)) * 768) / (ldist(ps[p].GetActor(), aimed));
sa = getangle(sprite[j].x - sx, sprite[j].y - sy); sa = getangle(aimed->s.x - sx, aimed->s.y - sy);
} }
else zvel = -mulscale16(ps[p].horizon.sum().asq16(), 98); else zvel = -mulscale16(ps[p].horizon.sum().asq16(), 98);
} }
else if (s->statnum != 3) else if (s->statnum != 3)
{ {
j = findplayer(s, &x); j = findplayer(actor, &x);
l = ldist(&sprite[ps[j].i], s); l = ldist(ps[j].GetActor(), actor);
zvel = ((ps[j].oposz - sz) * 512) / l; zvel = ((ps[j].oposz - sz) * 512) / l;
} }
else zvel = 0; else zvel = 0;

View file

@ -213,27 +213,28 @@ static void shootmelee(int i, int p, int sx, int sy, int sz, int sa, int atwith)
static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith) static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith)
{ {
spritetype* const s = &sprite[i]; auto actor = &hittype[i];
auto s = &actor->s;
int sect = s->sectnum; int sect = s->sectnum;
int zvel; int zvel;
short hitsect, hitspr, hitwall, l, j, k; short hitsect, hitspr, hitwall, l, k;
int hitx, hity, hitz; int hitx, hity, hitz;
if (s->extra >= 0) s->shade = -96; if (s->extra >= 0) s->shade = -96;
if (p >= 0) if (p >= 0)
{ {
j = aim(s, AUTO_AIM_ANGLE); auto aimed = aim(actor, AUTO_AIM_ANGLE);
if (j >= 0) if (aimed)
{ {
int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (5 << 8); int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) + (5 << 8);
zvel = ((sprite[j].z - sz - dal) << 8) / ldist(&sprite[ps[p].i], &sprite[j]); zvel = ((aimed->s.z - sz - dal) << 8) / ldist(ps[p].GetActor(), aimed);
sa = getangle(sprite[j].x - sx, sprite[j].y - sy); sa = getangle(aimed->s.x - sx, aimed->s.y - sy);
} }
if (atwith == SHOTSPARK1) if (atwith == SHOTSPARK1)
{ {
if (j == -1) if (aimed == nullptr)
{ {
sa += 16 - (krand() & 31); sa += 16 - (krand() & 31);
zvel = -ps[p].horizon.sum().asq16() >> 11; zvel = -ps[p].horizon.sum().asq16() >> 11;
@ -246,7 +247,7 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith
sa += 64 - (krand() & 127); sa += 64 - (krand() & 127);
else else
sa += 16 - (krand() & 31); sa += 16 - (krand() & 31);
if (j == -1) zvel = -ps[p].horizon.sum().asq16() >> 11; if (aimed == nullptr) zvel = -ps[p].horizon.sum().asq16() >> 11;
zvel += 128 - (krand() & 255); zvel += 128 - (krand() & 255);
} }
sz -= (2 << 8); sz -= (2 << 8);
@ -254,9 +255,9 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith
else else
{ {
int x; int x;
j = findplayer(s, &x); int j = findplayer(actor, &x);
sz -= (4 << 8); sz -= (4 << 8);
zvel = ((ps[j].posz - sz) << 8) / (ldist(&sprite[ps[j].i], s)); zvel = ((ps[j].posz - sz) << 8) / (ldist(ps[j].GetActor(), actor));
if (s->picnum != BOSS1) if (s->picnum != BOSS1)
{ {
zvel += 128 - (krand() & 255); zvel += 128 - (krand() & 255);
@ -467,10 +468,11 @@ static void shootweapon(int i, int p, int sx, int sy, int sz, int sa, int atwith
static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith) static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith)
{ {
spritetype* const s = &sprite[i]; auto actor = &hittype[i];
auto s = &actor->s;
int sect = s->sectnum; int sect = s->sectnum;
int vel, zvel; int vel, zvel;
short j, scount; short scount;
if (isRRRA()) if (isRRRA())
{ {
@ -510,15 +512,15 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith)
if (p >= 0) if (p >= 0)
{ {
j = aim(s, AUTO_AIM_ANGLE); auto aimed = aim(actor, AUTO_AIM_ANGLE);
if (j >= 0) if (aimed)
{ {
sx += sintable[(s->ang + 512 + 160) & 2047] >> 7; sx += sintable[(s->ang + 512 + 160) & 2047] >> 7;
sy += sintable[(s->ang + 160) & 2047] >> 7; sy += sintable[(s->ang + 160) & 2047] >> 7;
int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) - (12 << 8); int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) - (12 << 8);
zvel = ((sprite[j].z - sz - dal) * vel) / ldist(&sprite[ps[p].i], &sprite[j]); zvel = ((aimed->s.z - sz - dal) * vel) / ldist(ps[p].GetActor(), aimed);
sa = getangle(sprite[j].x - sx, sprite[j].y - sy); sa = getangle(aimed->s.x - sx, aimed->s.y - sy);
} }
else else
{ {
@ -530,7 +532,7 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith)
else else
{ {
int x; int x;
j = findplayer(s, &x); int j = findplayer(s, &x);
// sa = getangle(ps[j].oposx-sx,ps[j].oposy-sy); // sa = getangle(ps[j].oposx-sx,ps[j].oposy-sy);
if (s->picnum == HULK) if (s->picnum == HULK)
sa -= (krand() & 31); sa -= (krand() & 31);
@ -582,7 +584,7 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith)
while (scount > 0) while (scount > 0)
{ {
j = EGS(sect, sx, sy, sz, atwith, -127, sizx, sizy, sa, vel, zvel, i, 4); auto j = EGS(sect, sx, sy, sz, atwith, -127, sizx, sizy, sa, vel, zvel, i, 4);
sprite[j].extra += (krand() & 7); sprite[j].extra += (krand() & 7);
sprite[j].cstat = 128; sprite[j].cstat = 128;
sprite[j].clipdist = 4; sprite[j].clipdist = 4;
@ -608,52 +610,53 @@ static void shootstuff(int i, int p, int sx, int sy, int sz, int sa, int atwith)
static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith) static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith)
{ {
spritetype* const s = &sprite[i]; auto actor = &hittype[i];
auto s = &actor->s;
int sect = s->sectnum; int sect = s->sectnum;
int vel, zvel; int vel, zvel;
short l, j, scount; short l, scount;
short var90 = 0; DDukeActor* act90 = nullptr;
if (s->extra >= 0) s->shade = -96; if (s->extra >= 0) s->shade = -96;
scount = 1; scount = 1;
vel = 644; vel = 644;
j = -1; DDukeActor* aimed = nullptr;
if (p >= 0) if (p >= 0)
{ {
j = aim(s, 48); aimed = aim(actor, 48);
if (j >= 0) if (aimed)
{ {
if (isRRRA() && atwith == RPG2) if (isRRRA() && atwith == RPG2)
{ {
if (sprite[j].picnum == HEN || sprite[j].picnum == HENSTAYPUT) if (aimed->s.picnum == HEN || aimed->s.picnum == HENSTAYPUT)
var90 = ps[screenpeek].i; act90 = ps[screenpeek].GetActor();
else else
var90 = j; act90 = aimed;
} }
int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) + (8 << 8); int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) + (8 << 8);
zvel = ((sprite[j].z - sz - dal) * vel) / ldist(&sprite[ps[p].i], &sprite[j]); zvel = ((aimed->s.z - sz - dal) * vel) / ldist(ps[p].GetActor(), aimed);
if (sprite[j].picnum != RECON) if (aimed->s.picnum != RECON)
sa = getangle(sprite[j].x - sx, sprite[j].y - sy); sa = getangle(aimed->s.x - sx, aimed->s.y - sy);
} }
else zvel = -mulscale16(ps[p].horizon.sum().asq16(), 81); else zvel = -mulscale16(ps[p].horizon.sum().asq16(), 81);
if (atwith == RPG) if (atwith == RPG)
S_PlayActorSound(RPG_SHOOT, i); S_PlayActorSound(RPG_SHOOT, actor);
else if (isRRRA()) else if (isRRRA())
{ {
if (atwith == RPG2) if (atwith == RPG2)
S_PlayActorSound(244, i); S_PlayActorSound(244, actor);
else if (atwith == RRTILE1790) else if (atwith == RRTILE1790)
S_PlayActorSound(94, i); S_PlayActorSound(94, actor);
} }
} }
else else
{ {
int x; int x;
j = findplayer(s, &x); int j = findplayer(s, &x);
sa = getangle(ps[j].oposx - sx, ps[j].oposy - sy); sa = getangle(ps[j].oposx - sx, ps[j].oposy - sy);
if (s->picnum == BOSS3) if (s->picnum == BOSS3)
sz -= (32 << 8); sz -= (32 << 8);
@ -663,16 +666,14 @@ static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith)
sz += 24 << 8; sz += 24 << 8;
} }
l = ldist(&sprite[ps[j].i], s); l = ldist(ps[j].GetActor(), actor);
zvel = ((ps[j].oposz - sz) * vel) / l; zvel = ((ps[j].oposz - sz) * vel) / l;
if (badguy(s) && (s->hitag & face_player_smart)) if (badguy(s) && (s->hitag & face_player_smart))
sa = s->ang + (krand() & 31) - 16; sa = s->ang + (krand() & 31) - 16;
} }
if (p >= 0 && j >= 0) if (p < 0) aimed = nullptr;
l = j;
else l = -1;
if (isRRRA() && atwith == RRTILE1790) if (isRRRA() && atwith == RRTILE1790)
{ {
@ -694,7 +695,7 @@ static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith)
} }
else if (atwith == RPG2) else if (atwith == RPG2)
{ {
spawned->s.lotag = var90; spawned->seek_actor = act90;
spawned->s.hitag = 0; spawned->s.hitag = 0;
fi.lotsofmoney(spawned, (krand() & 3) + 1); fi.lotsofmoney(spawned, (krand() & 3) + 1);
} }
@ -702,7 +703,7 @@ static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith)
spawned->s.extra += (krand() & 7); spawned->s.extra += (krand() & 7);
if (atwith != FREEZEBLAST) if (atwith != FREEZEBLAST)
spawned->temp_actor = l >= 0? &hittype[l] : nullptr;// spawned->s.yvel = l; spawned->temp_actor = aimed;
else else
{ {
spawned->s.yvel = numfreezebounces; spawned->s.yvel = numfreezebounces;
@ -762,10 +763,11 @@ static void shootrpg(int i, int p, int sx, int sy, int sz, int sa, int atwith)
static void shootwhip(int i, int p, int sx, int sy, int sz, int sa, int atwith) static void shootwhip(int i, int p, int sx, int sy, int sz, int sa, int atwith)
{ {
spritetype* const s = &sprite[i]; auto actor = &hittype[i];
auto s = &actor->s;
int sect = s->sectnum; int sect = s->sectnum;
int vel, zvel; int vel, zvel;
short j, scount; short scount;
if (s->extra >= 0) s->shade = -96; if (s->extra >= 0) s->shade = -96;
@ -785,13 +787,13 @@ static void shootwhip(int i, int p, int sx, int sy, int sz, int sa, int atwith)
if (p >= 0) if (p >= 0)
{ {
j = aim(s, AUTO_AIM_ANGLE); auto aimed = aim(actor, AUTO_AIM_ANGLE);
if (j >= 0) if (aimed)
{ {
int dal = ((sprite[j].xrepeat * tilesiz[sprite[j].picnum].y) << 1) - (12 << 8); int dal = ((aimed->s.xrepeat * tilesiz[aimed->s.picnum].y) << 1) - (12 << 8);
zvel = ((sprite[j].z - sz - dal) * vel) / ldist(&sprite[ps[p].i], &sprite[j]); zvel = ((aimed->s.z - sz - dal) * vel) / ldist(ps[p].GetActor(), aimed);
sa = getangle(sprite[j].x - sx, sprite[j].y - sy); sa = getangle(aimed->s.x - sx, aimed->s.y - sy);
} }
else else
zvel = -mulscale16(ps[p].horizon.sum().asq16(), 98); zvel = -mulscale16(ps[p].horizon.sum().asq16(), 98);
@ -799,13 +801,13 @@ static void shootwhip(int i, int p, int sx, int sy, int sz, int sa, int atwith)
else else
{ {
int x; int x;
j = findplayer(s, &x); int j = findplayer(s, &x);
// sa = getangle(ps[j].oposx-sx,ps[j].oposy-sy); // sa = getangle(ps[j].oposx-sx,ps[j].oposy-sy);
if (s->picnum == VIXEN) if (s->picnum == VIXEN)
sa -= (krand() & 16); sa -= (krand() & 16);
else else
sa += 16 - (krand() & 31); sa += 16 - (krand() & 31);
zvel = (((ps[j].oposz - sz + (3 << 8))) * vel) / ldist(&sprite[ps[j].i], s); zvel = (((ps[j].oposz - sz + (3 << 8))) * vel) / ldist(ps[j].GetActor(), actor);
} }
int oldzvel = zvel; int oldzvel = zvel;
@ -817,7 +819,7 @@ static void shootwhip(int i, int p, int sx, int sy, int sz, int sa, int atwith)
while (scount > 0) while (scount > 0)
{ {
j = EGS(sect, sx, sy, sz, atwith, -127, sizx, sizy, sa, vel, zvel, i, 4); int j = EGS(sect, sx, sy, sz, atwith, -127, sizx, sizy, sa, vel, zvel, i, 4);
sprite[j].extra += (krand() & 7); sprite[j].extra += (krand() & 7);
sprite[j].cstat = 128; sprite[j].cstat = 128;

View file

@ -336,6 +336,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, weaponhit& w, weap
("bposz", w.bposz, def->bposz) ("bposz", w.bposz, def->bposz)
("aflags", w.aflags, def->aflags) ("aflags", w.aflags, def->aflags)
("temp_actor", w.temp_actor, def->temp_actor) ("temp_actor", w.temp_actor, def->temp_actor)
("seek_actor", w.seek_actor, def->seek_actor)
.Array("temp_data", w.temp_data, def->temp_data, 6) .Array("temp_data", w.temp_data, def->temp_data, 6)
.EndObject(); .EndObject();
} }

View file

@ -30,7 +30,7 @@ struct weaponhit
short timetosleep; short timetosleep;
int floorz, ceilingz, lastvx, lastvy, bposx, bposy, bposz, aflags; int floorz, ceilingz, lastvx, lastvy, bposx, bposy, bposz, aflags;
int temp_data[6]; int temp_data[6];
weaponhit* temp_actor; weaponhit* temp_actor, *seek_actor;
spritetype& s; // direct reference to the corresponding sprite. spritetype& s; // direct reference to the corresponding sprite.
static weaponhit* array(); // this is necessary to allow define inline functions referencing the global array inside the definition itself. static weaponhit* array(); // this is necessary to allow define inline functions referencing the global array inside the definition itself.