From 31e5023004f8092c7f44c3dc34c564d4830d4022 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 22 Oct 2020 01:12:16 +0200 Subject: [PATCH] - dodge, furthestcanseepoint, furthestangle. --- source/games/duke/src/actors.cpp | 29 +++++++++++++++-------------- source/games/duke/src/actors_d.cpp | 2 +- source/games/duke/src/actors_r.cpp | 2 +- source/games/duke/src/funct.h | 4 ++-- source/games/duke/src/gameexec.cpp | 6 +++--- source/games/duke/src/player_d.cpp | 2 +- source/games/duke/src/player_r.cpp | 4 ++-- 7 files changed, 25 insertions(+), 24 deletions(-) diff --git a/source/games/duke/src/actors.cpp b/source/games/duke/src/actors.cpp index e3df0294d..50a8e3d58 100644 --- a/source/games/duke/src/actors.cpp +++ b/source/games/duke/src/actors.cpp @@ -5082,20 +5082,20 @@ void makeitfall(DDukeActor* actor) // //--------------------------------------------------------------------------- -int dodge(spritetype* s) +int dodge(DDukeActor* actor) { - int i; + auto s = &actor->s; int bx, by, mx, my, bxvect, byvect, mxvect, myvect, d; mx = s->x; my = s->y; mxvect = sintable[(s->ang + 512) & 2047]; myvect = sintable[s->ang & 2047]; - StatIterator it(STAT_PROJECTILE); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_PROJECTILE); + while (auto ac = it.Next()) { - auto si = &sprite[i]; - if (si->owner == i || si->sectnum != s->sectnum) + auto si = &ac->s; + if (ac->GetOwner() == ac || si->sectnum != s->sectnum) continue; bx = si->x - mx; @@ -5122,17 +5122,17 @@ int dodge(spritetype* s) // //--------------------------------------------------------------------------- -int furthestangle(int i, int angs) +int furthestangle(DDukeActor *actor, int angs) { + auto s = &actor->s; short j, hitsect, hitwall, hitspr, furthest_angle, angincs; int hx, hy, hz, d, greatestd; - spritetype* s = &sprite[i]; greatestd = -(1 << 30); angincs = 2048 / angs; if (s->picnum != TILE_APLAYER) - if ((hittype[i].temp_data[0] & 63) > 2) return(s->ang + 1024); + if ((actor->temp_data[0] & 63) > 2) return(s->ang + 1024); for (j = s->ang; j < (2048 + s->ang); j += angincs) { @@ -5158,18 +5158,19 @@ int furthestangle(int i, int angs) // //--------------------------------------------------------------------------- -int furthestcanseepoint(int i, spritetype* ts, int* dax, int* day) +int furthestcanseepoint(DDukeActor *actor, DDukeActor* tosee, int* dax, int* day) { + auto s = &actor->s; short j, hitsect, hitwall, hitspr, angincs; int hx, hy, hz, d, da;//, d, cd, ca,tempx,tempy,cx,cy; - spritetype* s = &sprite[i]; - if ((hittype[i].temp_data[0] & 63)) return -1; + if ((actor->temp_data[0] & 63)) return -1; if (ud.multimode < 2 && ud.player_skill < 3) angincs = 2048 / 2; else angincs = 2048 / (1 + (krand() & 1)); + auto ts = &tosee->s; for (j = ts->ang; j < (2048 + ts->ang); j += (angincs - (krand() & 511))) { hitscan(ts->x, ts->y, ts->z - (16 << 8), ts->sectnum, @@ -5258,14 +5259,14 @@ void alterang(int a, int g_i, int g_p) j = 2; if (a & furthestdir) { - goalang = furthestangle(g_i, j); + goalang = furthestangle(&hittype[g_i], j); g_sp->ang = goalang; g_sp->owner = ps[g_p].i; } if (a & fleeenemy) { - goalang = furthestangle(g_i, j); + goalang = furthestangle(&hittype[g_i], 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 7fa797fdd..afa5f7d15 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -3915,7 +3915,7 @@ void move_d(int g_i, int g_p, int g_x) if (a & getv) g_sp->zvel += ((*(moveptr + 1) << 4) - g_sp->zvel) >> 1; if (a & dodgebullet) - dodge(g_sp); + dodge(&hittype[g_i]); if (g_sp->picnum != APLAYER) alterang(a, g_i, g_p); diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 49261e81f..41d6df3ac 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -3905,7 +3905,7 @@ void move_r(int g_i, int g_p, int g_x) if (a & getv) g_sp->zvel += ((*(moveptr + 1) << 4) - g_sp->zvel) >> 1; if (a & dodgebullet) - dodge(g_sp); + dodge(&hittype[g_i]); if (g_sp->picnum != APLAYER) alterang(a, g_i, g_p); diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index 23e9a28b5..d2b0d8e7f 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -96,7 +96,7 @@ void handle_se130(DDukeActor* i, int countmax, int EXPLOSION2); void respawn_rrra(DDukeActor* oldact, DDukeActor* newact); -int dodge(spritetype*); +int dodge(DDukeActor*); void alterang(int a, int g_i, 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); @@ -171,7 +171,7 @@ void doorders(const CompletionFunc& func); void LoadActor(int i, int p, int x); void execute(int s, int p, int d); void makeitfall(DDukeActor* s); -int furthestangle(int snum, int angDiv); +int furthestangle(DDukeActor* snum, int angDiv); void getglobalz(DDukeActor* s); void OnEvent(int id, int pnum = -1, int snum = -1, int dist = -1); diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index b4d233c76..b74bf15f1 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -80,7 +80,7 @@ struct ParseState void parseifelse(int condition); }; -int furthestcanseepoint(int i, spritetype* ts, int* dax, int* day); +int furthestcanseepoint(DDukeActor* i, DDukeActor* ts, int* dax, int* day); bool ifsquished(int i, int p); void fakebubbaspawn(int g_i, int g_p); void tearitup(int sect); @@ -1493,7 +1493,7 @@ static bool ifcansee(int g_i, int g_p) // also modifies 'target' x&y if found.. - j = furthestcanseepoint(g_i, s, &hittype[g_i].lastvx, &hittype[g_i].lastvy); + j = furthestcanseepoint(&hittype[g_i], ps[g_p].GetActor(), &hittype[g_i].lastvx, &hittype[g_i].lastvy); if (j == -1) j = 0; else j = 1; @@ -2542,7 +2542,7 @@ int ParseState::parse(void) break; case concmd_ifbulletnear: - parseifelse( dodge(g_sp) == 1); + parseifelse( dodge(g_ac) == 1); break; case concmd_ifrespawn: if( badguy(g_sp) ) diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 53c9012cd..2ccf2eb6d 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -3079,7 +3079,7 @@ HORIZONLY: changespritesect(pi, p->cursectnum); if (ud.clipping == 0) - j = (pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 164L, (4L << 8), (4L << 8), CLIPMASK0) < 0 && furthestangle(pi, 8) < 512); + j = (pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 164L, (4L << 8), (4L << 8), CLIPMASK0) < 0 && furthestangle(p->GetActor(), 8) < 512); else j = 0; if (ud.clipping == 0) diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index dbd4773b9..4992331df 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -4060,9 +4060,9 @@ HORIZONLY: if (ud.clipping == 0) { if (s->clipdist == 64) - j = (pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 128L, (4L << 8), (4L << 8), CLIPMASK0) < 0 && furthestangle(pi, 8) < 512); + j = (pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 128L, (4L << 8), (4L << 8), CLIPMASK0) < 0 && furthestangle(p->GetActor(), 8) < 512); else - j = (pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 16L, (4L << 8), (4L << 8), CLIPMASK0) < 0 && furthestangle(pi, 8) < 512); + j = (pushmove(&p->posx, &p->posy, &p->posz, &p->cursectnum, 16L, (4L << 8), (4L << 8), CLIPMASK0) < 0 && furthestangle(p->GetActor(), 8) < 512); } else j = 0;