From 76c4eeddc4e9ea1dc17ff52b5db93cbfbf9a0879 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 22 Oct 2020 22:48:51 +0200 Subject: [PATCH] - moveactors. --- source/games/duke/src/actors_d.cpp | 87 ++++++++--------- source/games/duke/src/actors_r.cpp | 147 ++++++++++++++--------------- 2 files changed, 113 insertions(+), 121 deletions(-) diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index bb4845cf8..a1ef0b380 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -3058,36 +3058,34 @@ DETONATEB: void moveactors_d(void) { - int x, * t; - short j, sect, p; - spritetype* s; - unsigned short k; + int x; + int sect, p; + unsigned int k; + Collision coll; - StatIterator it(STAT_ACTOR); - int i; - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto act = it.Next()) { - s = &sprite[i]; - + auto s = &act->s; sect = s->sectnum; if (s->xrepeat == 0 || sect < 0 || sect >= MAXSECTORS) { - deletesprite(i); + deletesprite(act); continue; } - t = &hittype[i].temp_data[0]; + int *t = &act->temp_data[0]; - hittype[i].bposx = s->x; - hittype[i].bposy = s->y; - hittype[i].bposz = s->z; + act->bposx = s->x; + act->bposy = s->y; + act->bposz = s->z; switch (s->picnum) { case FLAMETHROWERFLAME: - if (isWorldTour()) flamethrowerflame(&hittype[i]); + if (isWorldTour()) flamethrowerflame(act); continue; case DUCK: @@ -3104,22 +3102,20 @@ void moveactors_d(void) } else { - j = fi.ifhitbyweapon(&hittype[i]); + int j = fi.ifhitbyweapon(act); if (j >= 0) { s->cstat = 32 + 128; k = 1; - StatIterator it(STAT_ACTOR); - int j; - while ((j = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto act2 = it.Next()) { - auto sj = &sprite[j]; - if (sj->lotag == s->lotag && - sj->picnum == s->picnum) + if (act2->s.lotag == s->lotag && + act2->s.picnum == s->picnum) { - if ((sj->hitag && !(sj->cstat & 32)) || - (!sj->hitag && (sj->cstat & 32)) + if ((act2->s.hitag && !(act2->s.cstat & 32)) || + (!act2->s.hitag && (act2->s.cstat & 32)) ) { k = 0; @@ -3131,7 +3127,7 @@ void moveactors_d(void) if (k == 1) { operateactivators(s->lotag, -1); - fi.operateforcefields(i, s->lotag); + fi.operateforcefields(act->GetIndex(), s->lotag); operatemasterswitches(s->lotag); } } @@ -3141,7 +3137,7 @@ void moveactors_d(void) case RESPAWNMARKERRED: case RESPAWNMARKERYELLOW: case RESPAWNMARKERGREEN: - if (!respawnmarker(&hittype[i], RESPAWNMARKERYELLOW, RESPAWNMARKERGREEN)) continue; + if (!respawnmarker(act, RESPAWNMARKERYELLOW, RESPAWNMARKERGREEN)) continue; break; case HELECOPT: @@ -3150,39 +3146,39 @@ void moveactors_d(void) s->z += s->zvel; t[0]++; - if (t[0] == 4) S_PlayActorSound(WAR_AMBIENCE2, i); + if (t[0] == 4) S_PlayActorSound(WAR_AMBIENCE2, act); if (t[0] > (26 * 8)) { S_PlaySound(RPG_EXPLODE); - for (j = 0; j < 32; j++) - RANDOMSCRAP(s, i); + for (int j = 0; j < 32; j++) + RANDOMSCRAP(act); earthquaketime = 16; - deletesprite(i); + deletesprite(act); continue; } else if ((t[0] & 3) == 0) - fi.spawn(i, EXPLOSION2); - ssp(i, CLIPMASK0); + spawn(act, EXPLOSION2); + ssp(act, CLIPMASK0); break; case RAT: - if (!rat(&hittype[i], true)) continue; + if (!rat(act, true)) continue; break; case QUEBALL: case STRIPEBALL: - if (!queball(&hittype[i], POCKET, QUEBALL, STRIPEBALL)) continue; + if (!queball(act, POCKET, QUEBALL, STRIPEBALL)) continue; break; case FORCESPHERE: - forcesphere(&hittype[i], FORCESPHERE); + forcesphere(act, FORCESPHERE); continue; case RECON: - recon(&hittype[i], EXPLOSION2, FIRELASER, RECO_ATTACK, RECO_PAIN, RECO_ROAM, 10, [](DDukeActor* i)->int { return PIGCOP; }); + recon(act, EXPLOSION2, FIRELASER, RECO_ATTACK, RECO_PAIN, RECO_ROAM, 10, [](DDukeActor* i)->int { return PIGCOP; }); continue; case OOZ: case OOZ2: - ooz(&hittype[i]); + ooz(act); continue; case GREENSLIME: @@ -3193,16 +3189,15 @@ void moveactors_d(void) case GREENSLIME + 5: case GREENSLIME + 6: case GREENSLIME + 7: - greenslime(&hittype[i]); + greenslime(act); continue; case BOUNCEMINE: case MORTER: - j = fi.spawn(i, FRAMEEFFECT1); - hittype[j].temp_data[0] = 3; + spawn(act, FRAMEEFFECT1)->temp_data[0] = 3; case HEAVYHBOMB: - heavyhbomb(&hittype[i]); + heavyhbomb(act); continue; case REACTORBURNT: @@ -3211,17 +3206,17 @@ void moveactors_d(void) case REACTOR: case REACTOR2: - reactor(&hittype[i], REACTOR, REACTOR2, REACTORBURNT, REACTOR2BURNT, REACTORSPARK, REACTOR2SPARK); + reactor(act, REACTOR, REACTOR2, REACTORBURNT, REACTOR2BURNT, REACTORSPARK, REACTOR2SPARK); continue; case CAMERA1: - camera(&hittype[i]); + camera(act); continue; } // #ifndef VOLOMEONE - if (ud.multimode < 2 && badguy(s)) + if (ud.multimode < 2 && badguy(act)) { if (actor_tog == 1) { @@ -3232,9 +3227,9 @@ void moveactors_d(void) } // #endif - p = findplayer(s, &x); + p = findplayer(&act->s, &x); - execute(i, p, x); + execute(act, p, x); } } diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 77d1672e5..c4210d0d7 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -2860,8 +2860,8 @@ static int henstand(DDukeActor *actor) void moveactors_r(void) { int x; - int j, sect, p; - spritetype *s; + int p; + Collision coll; dojaildoor(); moveminecart(); @@ -2872,27 +2872,24 @@ void moveactors_r(void) } rr_specialstats(); - StatIterator it(STAT_ACTOR); - int i; - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_ACTOR); + while (auto act = it.Next()) { + auto s = &act->s; bool deleteafterexecute = false; // taking a cue here from RedNukem to not run scripts on deleted sprites. - - s = &sprite[i]; - - sect = s->sectnum; + auto sect = s->sectnum; if( s->xrepeat == 0 || sect < 0 || sect >= MAXSECTORS) { - deletesprite(i); + deletesprite(act); continue; } - auto t = &hittype[i].temp_data[0]; + auto t = &act->temp_data[0]; - hittype[i].bposx = s->x; - hittype[i].bposy = s->y; - hittype[i].bposz = s->z; + act->bposx = s->x; + act->bposy = s->y; + act->bposz = s->z; switch(s->picnum) @@ -2900,48 +2897,48 @@ void moveactors_r(void) case RESPAWNMARKERRED: case RESPAWNMARKERYELLOW: case RESPAWNMARKERGREEN: - if (!respawnmarker(&hittype[i], RESPAWNMARKERYELLOW, RESPAWNMARKERGREEN)) continue; + if (!respawnmarker(act, RESPAWNMARKERYELLOW, RESPAWNMARKERGREEN)) continue; break; case RAT: - if (!rat(&hittype[i], !isRRRA())) continue; + if (!rat(act, !isRRRA())) continue; break; case RRTILE3190: case RRTILE3191: case RRTILE3192: - if (!chickenplant) + if (!chickenplant) { - deletesprite(i); + deletesprite(act); continue; } - if (sector[sprite[i].sectnum].lotag == 903) - makeitfall(i); - j = fi.movesprite(i, + if (sector[sect].lotag == 903) + makeitfall(act); + movesprite_ex(act, (s->xvel*sintable[(s->ang+512)&2047])>>14, (s->xvel*sintable[s->ang&2047])>>14, - s->zvel,CLIPMASK0); - switch (sector[sprite[i].sectnum].lotag) + s->zvel,CLIPMASK0, coll); + switch (sector[sect].lotag) { case 901: - sprite[i].picnum = RRTILE3191; + s->picnum = RRTILE3191; break; case 902: - sprite[i].picnum = RRTILE3192; + s->picnum = RRTILE3192; break; case 903: - if (sprite[i].z >= sector[sprite[i].sectnum].floorz - (8<<8)) + if (s->z >= sector[sect].floorz - (8<<8)) { - deletesprite(i); + deletesprite(act); continue; } break; case 904: - deletesprite(i); + deletesprite(act); continue; break; } - if ((j & 32768) == 32768) + if (coll.type > kHitSector) { - deletesprite(i); + deletesprite(act); continue; } break; @@ -2950,55 +2947,55 @@ void moveactors_r(void) case RRTILE3122: case RRTILE3123: case RRTILE3124: - if (!chickenplant) + if (!chickenplant) { - deletesprite(i); + deletesprite(act); continue; } - makeitfall(i); - j = fi.movesprite(i, + makeitfall(act); + movesprite_ex(act, (s->xvel*(sintable[(s->ang+512)&2047]))>>14, (s->xvel*(sintable[s->ang&2047]))>>14, - s->zvel,CLIPMASK0); - if ((j & 32768) == 32768) + s->zvel,CLIPMASK0, coll); + if (coll.type > kHitSector) { - deletesprite(i); + deletesprite(act); continue; } - if (sector[s->sectnum].lotag == 903) + if (sector[sect].lotag == 903) { - if (sprite[i].z >= sector[sprite[i].sectnum].floorz - (4<<8)) + if (s->z >= sector[sect].floorz - (4<<8)) { - deletesprite(i); + deletesprite(act); continue; } } - else if (sector[s->sectnum].lotag == 904) + else if (sector[sect].lotag == 904) { - deletesprite(i); + deletesprite(act); continue; } break; case RRTILE3132: - if (!chickenplant) + if (!chickenplant) { - deletesprite(i); + deletesprite(act); continue; } - makeitfall(i); - j = fi.movesprite(i, + makeitfall(act); + movesprite_ex(act, (s->xvel*sintable[(s->ang+512)&2047])>>14, (s->xvel*sintable[s->ang&2047])>>14, - s->zvel,CLIPMASK0); - if (s->z >= sector[s->sectnum].floorz - (8<<8)) + s->zvel,CLIPMASK0, coll); + if (s->z >= sector[sect].floorz - (8<<8)) { - if (sector[s->sectnum].lotag == 1) + if (sector[sect].lotag == 1) { - j = fi.spawn(i,WATERSPLASH2); - sprite[j].z = sector[sprite[j].sectnum].floorz; + auto j = spawn(act, WATERSPLASH2); + j->s.z = sector[j->s.sectnum].floorz; } - deletesprite(i); + deletesprite(act); continue; } break; @@ -3006,12 +3003,12 @@ void moveactors_r(void) if (s->xvel) { if(!S_CheckSoundPlaying(356)) - S_PlayActorSound(356,i); + S_PlayActorSound(356,act); } else { - fi.spawn(i,BOWLINGBALLSPRITE); - deletesprite(i); + spawn(act,BOWLINGBALLSPRITE); + deletesprite(act); continue; } if (sector[s->sectnum].lotag == 900) @@ -3023,7 +3020,7 @@ void moveactors_r(void) case HENSTAND: case HENSTAND+1: { - int todo = henstand(&hittype[i]); + int todo = henstand(act); if (todo == 2) deleteafterexecute = true; if (todo == 1) continue; break; @@ -3031,10 +3028,10 @@ void moveactors_r(void) case QUEBALL: case STRIPEBALL: - if (!queball(&hittype[i], POCKET, QUEBALL, STRIPEBALL)) continue; + if (!queball(act, POCKET, QUEBALL, STRIPEBALL)) continue; break; case FORCESPHERE: - forcesphere(&hittype[i], FORCESPHERE); + forcesphere(act, FORCESPHERE); continue; case RECON: @@ -3043,9 +3040,9 @@ void moveactors_r(void) case UFO3: case UFO4: case UFO5: - recon(&hittype[i], EXPLOSION2, FIRELASER, -1, -1, 457, 8, [](DDukeActor* i) ->int + recon(act, EXPLOSION2, FIRELASER, -1, -1, 457, 8, [](DDukeActor* act) ->int { - auto s = &i->s; + auto s = &act->s; if (isRRRA() && ufospawnsminion) return MINION; else if (s->picnum == UFO1_RR) @@ -3063,33 +3060,33 @@ void moveactors_r(void) continue; case OOZ: - ooz(&hittype[i]); + ooz(act); continue; case EMPTYBIKE: if (!isRRRA()) break; - makeitfall(i); - getglobalz(i); + makeitfall(act); + getglobalz(act); if (sector[sect].lotag == 1) { - setsprite(i,s->x,s->y,hittype[i].floorz+(16<<8)); + setsprite(act,s->x,s->y,act->floorz+(16<<8)); } break; case EMPTYBOAT: if (!isRRRA()) break; - makeitfall(i); - getglobalz(i); + makeitfall(act); + getglobalz(act); break; case TRIPBOMBSPRITE: if (!isRRRA() || (sector[sect].lotag != 1 && sector[sect].lotag != 160)) if (s->xvel) { - j = fi.movesprite(i, + movesprite_ex(act, (s->xvel*sintable[(s->ang+512)&2047])>>14, (s->xvel*sintable[s->ang&2047])>>14, - s->zvel,CLIPMASK0); + s->zvel,CLIPMASK0, coll); s->xvel--; } break; @@ -3098,7 +3095,7 @@ void moveactors_r(void) if (!isRRRA()) break; case MORTER: case HEAVYHBOMB: - heavyhbomb(&hittype[i]); + heavyhbomb(act); continue; case REACTORBURNT: @@ -3107,17 +3104,17 @@ void moveactors_r(void) case REACTOR: case REACTOR2: - reactor(&hittype[i], REACTOR, REACTOR2, REACTORBURNT, REACTOR2BURNT, REACTORSPARK, REACTOR2SPARK); + reactor(act, REACTOR, REACTOR2, REACTORBURNT, REACTOR2BURNT, REACTORSPARK, REACTOR2SPARK); continue; case CAMERA1: - camera(&hittype[i]); + camera(act); continue; } // #ifndef VOLOMEONE - if( ud.multimode < 2 && badguy(s) ) + if( ud.multimode < 2 && badguy(act) ) { if( actor_tog == 1) { @@ -3128,10 +3125,10 @@ void moveactors_r(void) } // #endif - p = findplayer(s,&x); + p = findplayer(&act->s,&x); - execute(i,p,x); - if (deleteafterexecute) deletesprite(i); + execute(act,p,x); + if (deleteafterexecute) deletesprite(act); } }