From d63ac59fa00ac739efdef6b1ab3c3b1b32694d43 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 31 Oct 2021 16:00:55 +0100 Subject: [PATCH] - FindBreakSpriteMatch --- source/games/sw/src/break.cpp | 28 ++++++++++++---------------- source/games/sw/src/break.h | 2 +- source/games/sw/src/game.h | 7 +++++-- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/source/games/sw/src/break.cpp b/source/games/sw/src/break.cpp index 766f82e25..cf754d8ac 100644 --- a/source/games/sw/src/break.cpp +++ b/source/games/sw/src/break.cpp @@ -534,21 +534,19 @@ BREAK_INFOp SetupSpriteForBreak(DSWActor* actor) // ACTIVATE ////////////////////////////////////////////// -short FindBreakSpriteMatch(short match) +DSWActor* FindBreakSpriteMatch(short match) { - int i; - - StatIterator it(STAT_BREAKABLE); - while ((i = it.NextIndex()) >= 0) + SWStatIterator it(STAT_BREAKABLE); + while (auto actor = it.Next()) { - auto sp = &sprite[i]; + auto sp = &actor->s(); if (SP_TAG2(sp) == match && sp->picnum == ST1) { - return i; + return actor; } } - return -1; + return nullptr; } // @@ -658,7 +656,6 @@ int AutoBreakWall(WALLp wallp, int hit_x, int hit_y, int hit_z, short ang, short bool UserBreakWall(WALLp wp, short) { - short SpriteNum; SPRITEp sp; short match = wp->hitag; int block_flags = CSTAT_WALL_BLOCK|CSTAT_WALL_BLOCK_HITSCAN; @@ -666,9 +663,9 @@ bool UserBreakWall(WALLp wp, short) int flags = block_flags|type_flags; bool ret = false; - SpriteNum = FindBreakSpriteMatch(match); + auto actor = FindBreakSpriteMatch(match); - if (SpriteNum < 0) + if (actor == nullptr) { // do it the old way and get rid of wall - assumed to be masked DoSpawnSpotsForKill(match); @@ -683,7 +680,7 @@ bool UserBreakWall(WALLp wp, short) return true; } - sp = &sprite[SpriteNum]; + sp = &actor->s(); if (wp->picnum == SP_TAG5(sp)) return true; @@ -875,11 +872,10 @@ int UserBreakSprite(short BreakSprite) SPRITEp bp = &sprite[BreakSprite]; short match = bp->lotag; short match_extra; - short SpriteNum; - SpriteNum = FindBreakSpriteMatch(match); + auto actor = FindBreakSpriteMatch(match); - if (SpriteNum < 0) + if (actor == nullptr) { // even if you didn't find a matching ST1 go ahead and kill it and match everything // its better than forcing everyone to have a ST1 @@ -890,7 +886,7 @@ int UserBreakSprite(short BreakSprite) return true; } - sp = &sprite[SpriteNum]; + sp = &actor->s(); match_extra = SP_TAG6(bp); if (bp->picnum == SP_TAG5(sp)) diff --git a/source/games/sw/src/break.h b/source/games/sw/src/break.h index 6e1e9140b..27590a9c5 100644 --- a/source/games/sw/src/break.h +++ b/source/games/sw/src/break.h @@ -50,7 +50,7 @@ BREAK_INFOp FindSpriteBreakInfo(short picnum); void SortBreakInfo(void); BREAK_INFOp SetupWallForBreak(WALLp wallp); BREAK_INFOp SetupSpriteForBreak(DSWActor* actor); -short FindBreakSpriteMatch(short match); +DSWActor* FindBreakSpriteMatch(short match); bool HitBreakWall(WALLp wp, int, int, int, short ang, short type); int HitBreakSprite(short BreakSprite, short type); bool CheckBreakToughness(BREAK_INFOp break_info, short ID); diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 3c354b6fb..dd81b4da0 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -470,8 +470,11 @@ inline int SPRITEp_SIZE_BOS(const spritetype* sp) // Directions // -#define DEGREE_45 256 -#define DEGREE_90 512 +enum +{ + DEGREE_45 = 256, + DEGREE_90 = 512 +}; //// //