diff --git a/source/games/sw/src/actor.cpp b/source/games/sw/src/actor.cpp index 9f055b1c7..9c2f7bb9c 100644 --- a/source/games/sw/src/actor.cpp +++ b/source/games/sw/src/actor.cpp @@ -494,7 +494,6 @@ int DoGenerateSewerDebris(DSWActor* actor) { SPRITEp sp = &actor->s(); USERp u = actor->u(); - short n; static STATEp Debris[] = { @@ -510,9 +509,9 @@ int DoGenerateSewerDebris(DSWActor* actor) { u->Tics = u->WaitTics; - n = SpawnSprite(STAT_DEAD_ACTOR, 0, Debris[RANDOM_P2(4<<8)>>8], sp->sectnum, sp->x, sp->y, sp->z, sp->ang, 200); + auto spawned = SpawnActor(STAT_DEAD_ACTOR, 0, Debris[RANDOM_P2(4<<8)>>8], sp->sectnum, sp->x, sp->y, sp->z, sp->ang, 200); - SetOwner(u->SpriteNum, n); + SetOwner(actor, spawned); } return 0; diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index 9a23ff5ce..82486c489 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1938,7 +1938,9 @@ int move_missile(int spritenum, int xchange, int ychange, int zchange, int ceild int DoPickTarget(SPRITEp sp, uint32_t max_delta_ang, int skip_targets); void change_sprite_stat(short, short); -void SetOwner(short, short); +void SetOwner(DSWActor*, DSWActor*); +void SetOwner(int a, int b); // we still need this... +void ClearOwner(DSWActor* ownr); void SetAttach(short, short); void analyzesprites(spritetype* tsprite, int& spritesortcnt, int viewx, int viewy, int viewz, int camang); void ChangeState(short SpriteNum, STATEp statep); diff --git a/source/games/sw/src/jweapon.cpp b/source/games/sw/src/jweapon.cpp index f61fa3c59..aff27d7d6 100644 --- a/source/games/sw/src/jweapon.cpp +++ b/source/games/sw/src/jweapon.cpp @@ -312,7 +312,6 @@ SpawnMidSplash(short SpriteNum) np = &sprite[New]; nu = User[New].Data(); - //SetOwner(Weapon, New); np->shade = -12; np->xrepeat = 70-RandomRange(20); np->yrepeat = 70-RandomRange(20); @@ -346,7 +345,6 @@ SpawnFloorSplash(short SpriteNum) np = &sprite[New]; nu = User[New].Data(); - //SetOwner(Weapon, New); np->shade = -12; np->xrepeat = 70-RandomRange(20); np->yrepeat = 70-RandomRange(20); diff --git a/source/games/sw/src/sprite.cpp b/source/games/sw/src/sprite.cpp index 60bee0dce..393faf1b0 100644 --- a/source/games/sw/src/sprite.cpp +++ b/source/games/sw/src/sprite.cpp @@ -583,29 +583,28 @@ STATE s_IconFlag[] = {ICON_FLAG + 2, 32, DoGet, &s_IconFlag[0]} }; -void -SetOwner(short owner, short child) +void SetOwner(DSWActor* ownr, DSWActor* child) { - SPRITEp cp = &sprite[child]; + SPRITEp cp = &child->s(); - if (owner == 0) + if (ownr != nullptr && ownr->hasU()) { - ////DSPRINTF(ds, "Set Owner possible problem - owner is 0, child %d", child); - //MONO_PRINT(ds); + SET(ownr->u()->Flags2, SPR2_CHILDREN); } - if (owner >= 0) - { - ASSERT(User[owner].Data()); - SET(User[owner]->Flags2, SPR2_CHILDREN); - } - else - { - ////DSPRINTF(ds,"Owner is -1 !!!!!!!!!!!!!!!!!!!!!"); - //MONO_PRINT(ds); - } + cp->owner = ownr? ownr->GetSpriteIndex() : -1; +} - cp->owner = owner; + +void ClearOwner(DSWActor* child) +{ + if (child) child->s().owner = -1; +} + +void SetOwner(int a, int b) +{ + if (a >= 0 && b >= 0) SetOwner(&swActors[a], &swActors[b]); + else if (b >= 0) ClearOwner(&swActors[b]); } void @@ -1001,6 +1000,13 @@ SpawnSprite(short stat, short id, STATEp state, short sectnum, int x, int y, int return SpriteNum; } +DSWActor* SpawnActor(short stat, short id, STATEp state, short sectnum, int x, int y, int z, int ang, int vel) +{ + int s = SpawnSprite(stat, id, state, sectnum, x, y, z, ang, vel); + return s >= 0 ? &swActors[s] : nullptr; +} + + void PicAnimOff(short picnum) { diff --git a/source/games/sw/src/sprite.h b/source/games/sw/src/sprite.h index 56f2dc19a..72d2381ce 100644 --- a/source/games/sw/src/sprite.h +++ b/source/games/sw/src/sprite.h @@ -32,6 +32,7 @@ BEGIN_SW_NS void KillSprite(int16_t SpriteNum); int16_t SpawnSprite(short stat, short id, STATEp state, short sectnum, int x, int y, int z, int ang, int vel); +DSWActor* SpawnActor(short stat, short id, STATEp state, short sectnum, int x, int y, int z, int ang, int vel); void SpriteSetup(void); int move_actor(short SpriteNum, int xchange, int ychange, int zchange); short GetSpriteDir(short sn); diff --git a/source/games/sw/src/swactor.h b/source/games/sw/src/swactor.h index ca073cc9b..c9088ea45 100644 --- a/source/games/sw/src/swactor.h +++ b/source/games/sw/src/swactor.h @@ -30,17 +30,6 @@ public: spritetype& s() { return sprite[index]; } USER* u() { return User[index].Data(); } - void SetOwner(DSWActor* own) - { - s().owner = own ? own->s().index : -1; - } - - DSWActor* GetOwner() - { - if (s().owner == -1 || s().owner == MAXSPRITES - 1) return nullptr; - return base() + s().owner; - } - int GetSpriteIndex() const { return index;