From 85ea1df76ad3fe94575ccceed5b62929732a0527 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 22 Oct 2020 16:40:48 +0200 Subject: [PATCH] - alterang --- source/games/duke/src/actors.cpp | 41 +++++++++++++++--------------- source/games/duke/src/actors_d.cpp | 2 +- source/games/duke/src/actors_r.cpp | 2 +- source/games/duke/src/dukeactor.h | 5 ++++ source/games/duke/src/funct.h | 2 +- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index 50a8e3d58..8346e3b81 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -5198,38 +5198,39 @@ int furthestcanseepoint(DDukeActor *actor, DDukeActor* tosee, int* dax, int* day // //--------------------------------------------------------------------------- -void alterang(int a, int g_i, int g_p) +void alterang(int ang, DDukeActor* actor, int g_p) { + auto g_sp = &actor->s; short aang, angdif, goalang, j; int ticselapsed; - int* g_t = hittype[g_i].temp_data; - auto* g_sp = &sprite[g_i]; + int* t = actor->temp_data; - auto moveptr = &ScriptCode[g_t[1]]; + auto moveptr = &ScriptCode[t[1]]; - ticselapsed = (g_t[0]) & 31; + ticselapsed = (t[0]) & 31; aang = g_sp->ang; g_sp->xvel += (*moveptr - g_sp->xvel) / 5; if (g_sp->zvel < 648) g_sp->zvel += ((*(moveptr + 1) << 4) - g_sp->zvel) / 5; - if (isRRRA() && (a & windang)) + if (isRRRA() && (ang & windang)) g_sp->ang = WindDir; - else if (a & seekplayer) + else if (ang & seekplayer) { - j = !isRR()? ps[g_p].holoduke_on->GetIndex() : -1; + auto holoduke = !isRR()? ps[g_p].holoduke_on : nullptr; // NOTE: looks like 'owner' is set to target sprite ID... - if (j >= 0 && cansee(sprite[j].x, sprite[j].y, sprite[j].z, sprite[j].sectnum, g_sp->x, g_sp->y, g_sp->z, g_sp->sectnum)) - g_sp->owner = j; - else g_sp->owner = ps[g_p].i; + if (holoduke && cansee(holoduke->s.x, holoduke->s.y, holoduke->s.z, holoduke->s.sectnum, g_sp->x, g_sp->y, g_sp->z, g_sp->sectnum)) + actor->SetOwner(holoduke); + else actor->SetOwner(ps[g_p].GetActor()); - if (sprite[g_sp->owner].picnum == TILE_APLAYER) - goalang = getangle(hittype[g_i].lastvx - g_sp->x, hittype[g_i].lastvy - g_sp->y); + auto Owner = actor->GetOwner(); + if (Owner->s.picnum == TILE_APLAYER) + goalang = getangle(actor->lastvx - g_sp->x, actor->lastvy - g_sp->y); else - goalang = getangle(sprite[g_sp->owner].x - g_sp->x, sprite[g_sp->owner].y - g_sp->y); + goalang = getangle(Owner->s.x - g_sp->x, Owner->s.y - g_sp->y); if (g_sp->xvel && g_sp->picnum != TILE_DRONE) { @@ -5241,7 +5242,7 @@ void alterang(int a, int g_i, int g_p) { j = 128 - (krand() & 256); g_sp->ang += j; - if (hits(g_i) < 844) + if (hits(actor) < 844) g_sp->ang -= j; } } @@ -5257,16 +5258,16 @@ void alterang(int a, int g_i, int g_p) if (ticselapsed < 1) { j = 2; - if (a & furthestdir) + if (ang & furthestdir) { - goalang = furthestangle(&hittype[g_i], j); + goalang = furthestangle(actor, j); g_sp->ang = goalang; - g_sp->owner = ps[g_p].i; + actor->SetOwner(ps[g_p].GetActor()); } - if (a & fleeenemy) + if (ang & fleeenemy) { - goalang = furthestangle(&hittype[g_i], j); + goalang = furthestangle(actor, j); g_sp->ang = goalang; // += angdif; // = getincangle(aang,goalang)>>1; } } diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index afa5f7d15..4c98c07b0 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -3918,7 +3918,7 @@ void move_d(int g_i, int g_p, int g_x) dodge(&hittype[g_i]); if (g_sp->picnum != APLAYER) - alterang(a, g_i, g_p); + alterang(a, &hittype[g_i], g_p); if (g_sp->xvel > -6 && g_sp->xvel < 6) g_sp->xvel = 0; diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 41d6df3ac..58bddd57b 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -3908,7 +3908,7 @@ void move_r(int g_i, int g_p, int g_x) dodge(&hittype[g_i]); if (g_sp->picnum != APLAYER) - alterang(a, g_i, g_p); + alterang(a, &hittype[g_i], g_p); if (g_sp->xvel > -6 && g_sp->xvel < 6) g_sp->xvel = 0; diff --git a/source/games/duke/src/dukeactor.h b/source/games/duke/src/dukeactor.h index 16f92b446..86db77981 100644 --- a/source/games/duke/src/dukeactor.h +++ b/source/games/duke/src/dukeactor.h @@ -289,4 +289,9 @@ inline void callsound(int sect, DDukeActor* a) callsound(sect, a->GetIndex()); } +inline int hits(DDukeActor* snum) +{ + return hits(snum->GetIndex()); +} + END_DUKE_NS diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index d2b0d8e7f..821cba00d 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -97,7 +97,7 @@ void handle_se130(DDukeActor* i, int countmax, int EXPLOSION2); void respawn_rrra(DDukeActor* oldact, DDukeActor* newact); int dodge(DDukeActor*); -void alterang(int a, int g_i, int g_p); +void alterang(int ang, DDukeActor* actor, int g_p); void fall_common(int g_i, int g_p, int JIBS6, int DRONE, int BLOODPOOL, int SHOTSPARK1, int squished, int thud, int(*fallspecial)(int, int), void (*falladjustz)(spritetype*)); void checkavailweapon(struct player_struct* p); void deletesprite(DDukeActor* num);