From 2ad31247ecfc4fa5d1104b0b88d99fe4822801cd Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 22 Oct 2020 22:31:10 +0200 Subject: [PATCH] - henstand and bowling. --- source/games/duke/src/actors_r.cpp | 54 ++--- source/games/duke/src/bowling.cpp | 351 ++++++++++++++--------------- 2 files changed, 198 insertions(+), 207 deletions(-) diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 6681e1a99..77d1672e5 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -38,7 +38,7 @@ BEGIN_DUKE_NS void dojaildoor(); void moveminecart(); -void ballreturn(short spr); +void ballreturn(DDukeActor* spr); short pinsectorresetdown(short sect); short pinsectorresetup(short sect); short checkpins(short sect); @@ -2767,20 +2767,19 @@ DETONATEB: // //--------------------------------------------------------------------------- -static int henstand(int i) +static int henstand(DDukeActor *actor) { - spritetype* s = &sprite[i]; - auto t = &hittype[i].temp_data[0]; + auto s = &actor->s; + auto t = &actor->temp_data[0]; int sect = s->sectnum; - int j; if (s->picnum == HENSTAND || s->picnum == HENSTAND + 1) { s->lotag--; if (s->lotag == 0) { - fi.spawn(i, HEN); - deletesprite(i); + spawn(actor, HEN); + deletesprite(actor); return 1; } } @@ -2788,32 +2787,33 @@ static int henstand(int i) s->xvel = 0; if (s->xvel) { - makeitfall(i); - j = fi.movesprite(i, + makeitfall(actor); + Collision coll; + movesprite_ex(actor, (sintable[(s->ang + 512) & 2047] * s->xvel) >> 14, (sintable[s->ang & 2047] * s->xvel) >> 14, - s->zvel, CLIPMASK0); - if (j & 49152) + s->zvel, CLIPMASK0, coll); + if (coll.type) { - if ((j & 49152) == 32768) + if (coll.type == kHitWall) { - j &= (MAXWALLS - 1); + int j = coll.index; int k = getangle( wall[wall[j].point2].x - wall[j].x, wall[wall[j].point2].y - wall[j].y); s->ang = ((k << 1) - s->ang) & 2047; } - else if ((j & 49152) == 49152) + else if (coll.type == kHitSprite) { - j &= (MAXSPRITES - 1); - fi.checkhitsprite(i, j); - if (sprite[j].picnum == HEN) + auto hitact = coll.actor; + fi.checkhitsprite(actor->GetIndex(), hitact->GetIndex()); + if (hitact->s.picnum == HEN) { - int ns = fi.spawn(j, HENSTAND); - deletesprite(j); - sprite[ns].xvel = 32; - sprite[ns].lotag = 40; - sprite[ns].ang = s->ang; + auto ns = spawn(hitact, HENSTAND); + deletesprite(hitact); + ns->s.xvel = 32; + ns->s.lotag = 40; + ns->s.ang = s->ang; } } } @@ -2834,18 +2834,18 @@ static int henstand(int i) if (krand() & 1) s->picnum = HENSTAND + 1; if (!s->xvel) - return 2;//deletesprite(i); still needs to run a script but should not do on a deleted object + return 2;//deletesprite(actor); still needs to run a script but should not do on a deleted object } if (s->picnum == RRTILE3440 || (s->picnum == RRTILE3440 + 1 && !s->xvel)) { - return 2;//deletesprite(i); still needs to run a script but should not do on a deleted object + return 2;//deletesprite(actor); still needs to run a script but should not do on a deleted object } } else if (sector[s->sectnum].lotag == 900) { if (s->picnum == BOWLINGBALL) - ballreturn(i); - deletesprite(i); + ballreturn(actor); + deletesprite(actor); return 1; } return 0; @@ -3023,7 +3023,7 @@ void moveactors_r(void) case HENSTAND: case HENSTAND+1: { - int todo = henstand(i); + int todo = henstand(&hittype[i]); if (todo == 2) deleteafterexecute = true; if (todo == 1) continue; break; diff --git a/source/games/duke/src/bowling.cpp b/source/games/duke/src/bowling.cpp index bb9579b8c..70283953b 100644 --- a/source/games/duke/src/bowling.cpp +++ b/source/games/duke/src/bowling.cpp @@ -36,25 +36,22 @@ BEGIN_DUKE_NS short pinsectorresetdown(short sect); -void ballreturn(short spr) +void ballreturn(DDukeActor *ball) { - int j, i; - StatIterator it(STAT_BOWLING); - while ((i = it.NextIndex()) >= 0) + DukeStatIterator it(STAT_BOWLING); + while (auto act = it.Next()) { - auto si = &sprite[i]; - if (si->picnum == RRTILE281 && sprite[spr].sectnum == si->sectnum) + if (act->s.picnum == RRTILE281 && ball->s.sectnum == act->s.sectnum) { - StatIterator it2(STAT_BOWLING); - while ((j = it2.NextIndex()) >= 0) + DukeStatIterator it2(STAT_BOWLING); + while (auto act2 = it2.Next()) { - auto sj = &sprite[j]; - if (sj->picnum == RRTILE282 && si->hitag == sj->hitag) - fi.spawn(j, BOWLINGBALLSPRITE); - if (sj->picnum == RRTILE280 && si->hitag == sj->hitag && sj->lotag == 0) + if (act2->s.picnum == RRTILE282 && act->s.hitag == act2->s.hitag) + spawn(act2, BOWLINGBALLSPRITE); + if (act2->s.picnum == RRTILE280 && act->s.hitag == act2->s.hitag && act2->s.lotag == 0) { - sj->lotag = 100; - sj->extra++; + act2->s.lotag = 100; + act2->s.extra++; } } } @@ -63,15 +60,12 @@ void ballreturn(short spr) short pinsectorresetdown(short sect) { - int vel, j; - - j = getanimationgoal(anim_ceilingz, sect); + int j = getanimationgoal(anim_ceilingz, sect); if (j == -1) { j = sector[sect].floorz; - vel = 64; - setanimation(sect, anim_ceilingz, sect, j, vel); + setanimation(sect, anim_ceilingz, sect, j, 64); return 1; } return 0; @@ -79,15 +73,12 @@ short pinsectorresetdown(short sect) short pinsectorresetup(short sect) { - int vel, j; - - j = getanimationgoal(anim_ceilingz, sect); + int j = getanimationgoal(anim_ceilingz, sect); if (j == -1) { j = sector[nextsectorneighborz(sect, sector[sect].ceilingz, -1, -1)].ceilingz; - vel = 64; - setanimation(sect, anim_ceilingz, sect, j, vel); + setanimation(sect, anim_ceilingz, sect, j, 64); return 1; } return 0; @@ -99,76 +90,76 @@ short checkpins(short sect) int x, y; short pins[10]; short tag; - - pin = 0; - for(i=0;i<10;i++) pins[i] = 0; - SectIterator it(sect); - while ((i = it.NextIndex()) >= 0) + pin = 0; + for (i = 0; i < 10; i++) pins[i] = 0; + + DukeSectIterator it(sect); + while (auto a2 = it.Next()) { - if (sprite[i].picnum == RRTILE3440) + if (a2->s.picnum == RRTILE3440) { pin++; - pins[sprite[i].lotag] = 1; + pins[a2->s.lotag] = 1; } - if (sprite[i].picnum == RRTILE280) + if (a2->s.picnum == RRTILE280) { - tag = sprite[i].hitag; + tag = a2->s.hitag; } } if (tag) { tag += 2024; - tileCopySection(2024,0,0,128,64,tag,0,0); - for(i=0;i<10;i++) + tileCopySection(2024, 0, 0, 128, 64, tag, 0, 0); + for (i = 0; i < 10; i++) { if (pins[i] == 1) { switch (i) { - case 0: - x = 64; - y = 48; - break; - case 1: - x = 56; - y = 40; - break; - case 2: - x = 72; - y = 40; - break; - case 3: - x = 48; - y = 32; - break; - case 4: - x = 64; - y = 32; - break; - case 5: - x = 80; - y = 32; - break; - case 6: - x = 40; - y = 24; - break; - case 7: - x = 56; - y = 24; - break; - case 8: - x = 72; - y = 24; - break; - case 9: - x = 88; - y = 24; - break; + case 0: + x = 64; + y = 48; + break; + case 1: + x = 56; + y = 40; + break; + case 2: + x = 72; + y = 40; + break; + case 3: + x = 48; + y = 32; + break; + case 4: + x = 64; + y = 32; + break; + case 5: + x = 80; + y = 32; + break; + case 6: + x = 40; + y = 24; + break; + case 7: + x = 56; + y = 24; + break; + case 8: + x = 72; + y = 24; + break; + case 9: + x = 88; + y = 24; + break; } - tileCopySection(2023,0,0,8,8,tag,x-4,y-10); + tileCopySection(2023, 0, 0, 8, 8, tag, x - 4, y - 10); } } } @@ -178,84 +169,84 @@ short checkpins(short sect) void resetpins(short sect) { - short i, j, tag; + int i, tag; int x, y; - SectIterator it(sect); - while ((i = it.NextIndex()) >= 0) + DukeSectIterator it(sect); + while (auto a2 = it.Next()) { - if (sprite[i].picnum == 3440) - deletesprite(i); + if (a2->s.picnum == RRTILE3440) + deletesprite(a2); } it.Reset(sect); - while ((i = it.NextIndex()) >= 0) + while (auto a2 = it.Next()) { - if (sprite[i].picnum == 283) + if (a2->s.picnum == 283) { - j = fi.spawn(i,3440); - sprite[j].lotag = sprite[i].lotag; - if (sprite[j].lotag == 3 || sprite[j].lotag == 5) + auto spawned = spawn(a2, RRTILE3440); + spawned->s.lotag = a2->s.lotag; + if (spawned->s.lotag == 3 || spawned->s.lotag == 5) { - sprite[j].clipdist = (1+(krand()%1))*16+32; + spawned->s.clipdist = (1 + (krand() % 1)) * 16 + 32; } else { - sprite[j].clipdist = (1+(krand()%1))*16+32; + spawned->s.clipdist = (1 + (krand() % 1)) * 16 + 32; } - sprite[j].ang -= ((krand()&32)-(krand()&64))&2047; + spawned->s.ang -= ((krand() & 32) - (krand() & 64)) & 2047; } - if (sprite[i].picnum == 280) - tag = sprite[i].hitag; + if (a2->s.picnum == 280) + tag = a2->s.hitag; } if (tag) { - tag += LANEPICS+1; - tileCopySection(LANEPICS+1,0,0,128,64,tag,0,0); - for(i=0;i<10;i++) + tag += LANEPICS + 1; + tileCopySection(LANEPICS + 1, 0, 0, 128, 64, tag, 0, 0); + for (i = 0; i < 10; i++) { switch (i) { - case 0: - x = 64; - y = 48; - break; - case 1: - x = 56; - y = 40; - break; - case 2: - x = 72; - y = 40; - break; - case 3: - x = 48; - y = 32; - break; - case 4: - x = 64; - y = 32; - break; - case 5: - x = 80; - y = 32; - break; - case 6: - x = 40; - y = 24; - break; - case 7: - x = 56; - y = 24; - break; - case 8: - x = 72; - y = 24; - break; - case 9: - x = 88; - y = 24; - break; + case 0: + x = 64; + y = 48; + break; + case 1: + x = 56; + y = 40; + break; + case 2: + x = 72; + y = 40; + break; + case 3: + x = 48; + y = 32; + break; + case 4: + x = 64; + y = 32; + break; + case 5: + x = 80; + y = 32; + break; + case 6: + x = 40; + y = 24; + break; + case 7: + x = 56; + y = 24; + break; + case 8: + x = 72; + y = 24; + break; + case 9: + x = 88; + y = 24; + break; } - tileCopySection(LANEPICS,0,0,8,8,tag,x-4,y-10); + tileCopySection(LANEPICS, 0, 0, 8, 8, tag, x - 4, y - 10); } } } @@ -265,58 +256,58 @@ void resetlanepics(void) int x, y; short i; short tag, pic; - for(tag=0;tag<4;tag++) + for (tag = 0; tag < 4; tag++) { pic = tag + 1; if (pic == 0) continue; - pic += LANEPICS+1; - tileCopySection(LANEPICS+1,0,0,128,64, pic,0,0); - for(i=0;i<10;i++) + pic += LANEPICS + 1; + tileCopySection(LANEPICS + 1, 0, 0, 128, 64, pic, 0, 0); + for (i = 0; i < 10; i++) { switch (i) { - case 0: - x = 64; - y = 48; - break; - case 1: - x = 56; - y = 40; - break; - case 2: - x = 72; - y = 40; - break; - case 3: - x = 48; - y = 32; - break; - case 4: - x = 64; - y = 32; - break; - case 5: - x = 80; - y = 32; - break; - case 6: - x = 40; - y = 24; - break; - case 7: - x = 56; - y = 24; - break; - case 8: - x = 72; - y = 24; - break; - case 9: - x = 88; - y = 24; - break; + case 0: + x = 64; + y = 48; + break; + case 1: + x = 56; + y = 40; + break; + case 2: + x = 72; + y = 40; + break; + case 3: + x = 48; + y = 32; + break; + case 4: + x = 64; + y = 32; + break; + case 5: + x = 80; + y = 32; + break; + case 6: + x = 40; + y = 24; + break; + case 7: + x = 56; + y = 24; + break; + case 8: + x = 72; + y = 24; + break; + case 9: + x = 88; + y = 24; + break; } - tileCopySection(LANEPICS,0,0,8,8,pic,x-4,y-10); + tileCopySection(LANEPICS, 0, 0, 8, 8, pic, x - 4, y - 10); } } }