- FlagOwner refactoring.

Only those parts which use it as a sprite index, seveal actors recycle it as a general purpose variable.
This commit is contained in:
Christoph Oelckers 2021-11-01 12:13:24 +01:00
parent e9fc342c93
commit aef68363b4
4 changed files with 18 additions and 16 deletions

View file

@ -1131,6 +1131,7 @@ struct USER
DSWActor* targetActor; // target player for the enemy - can only handle one player at at time
DSWActor* flameActor;
DSWActor* attachActor; // attach to sprite if needed - electro snake
DSWActor* flagOwnerActor;
int Flags;
int Flags2;
@ -1249,7 +1250,7 @@ struct USER
// !JIM! my extensions
int ShellNum; // This is shell no. 0 to whatever
// Shell gets deleted when ShellNum < (ShellCount - MAXSHELLS)
short FlagOwner; // The spritenum of the original flag
short FlagOwner; // The spritenum of the original flag (abused to hell by other things)
short Vis; // Shading upgrade, for shooting, etc...
bool DidAlert; // Has actor done his alert noise before?

View file

@ -2090,8 +2090,10 @@ int DoCarryFlag(DSWActor* actor)
SPRITEp sp = &actor->s();
const int FLAG_DETONATE_STATE = 99;
SPRITEp fp = &sprite[u->FlagOwner];
USERp fu = User[u->FlagOwner].Data();
auto fown = u->flagOwnerActor;
if (!fown) return 0;
SPRITEp fp = &fown->s();
USERp fu = fown->u();
// if no owner then die
@ -2139,10 +2141,9 @@ int DoCarryFlag(DSWActor* actor)
if (sector[ap->sectnum].hitag == 9000 && sector[ap->sectnum].lotag == ap->pal
&& ap->pal != sp->pal)
{
if (u->FlagOwner >= 0)
if (fown != nullptr)
{
if (fp->lotag) // Trigger everything if there is a
// lotag
if (fp->lotag) // Trigger everything if there is a lotag
DoMatchEverything(nullptr, fp->lotag, ON);
}
if (!TEST_BOOL1(fp))
@ -2248,11 +2249,13 @@ DoCarryFlagNoDet(DSWActor* actor)
SPRITEp ap = &u->attachActor->s();
USERp au = u->attachActor->u();
SPRITEp fp = &sprite[u->FlagOwner];
USERp fu = User[u->FlagOwner].Data();
auto fown = u->flagOwnerActor;
if (!fown) return 0;
SPRITEp fp = &fown->s();
USERp fu = fown->u();
if (u->FlagOwner >= 0)
if (u->flagOwnerActor != nullptr)
fu->WaitTics = 30 * 120; // Keep setting respawn tics so it
// won't respawn
@ -2269,7 +2272,7 @@ DoCarryFlagNoDet(DSWActor* actor)
if (!au || au->Health <= 0)
{
if (u->FlagOwner >= 0)
if (u->flagOwnerActor != nullptr)
fu->WaitTics = 0; // Tell it to respawn
SetSuicide(actor);
return false;
@ -2279,12 +2282,9 @@ DoCarryFlagNoDet(DSWActor* actor)
if (sector[ap->sectnum].hitag == 9000 && sector[ap->sectnum].lotag == ap->pal
&& ap->pal != sp->pal)
{
if (u->FlagOwner >= 0)
if (u->flagOwnerActor != nullptr)
{
//DSPRINTF(ds, "Flag has owner %d, fp->lotag = %d", u->FlagOwner, fp->lotag);
//MONO_PRINT(ds);
if (fp->lotag) // Trigger everything if there is a
// lotag
if (fp->lotag) // Trigger everything if there is a lotag
DoMatchEverything(nullptr, fp->lotag, ON);
fu->WaitTics = 0; // Tell it to respawn
}

View file

@ -921,6 +921,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, USER& w, USER* def
("bounce", w.bounce, def->bounce)
("ShellNum", w.ShellNum, def->ShellNum)
("FlagOwner", w.FlagOwner, def->FlagOwner)
("FlagOwnerActor", w.flagOwnerActor, def->flagOwnerActor)
("Vis", w.Vis, def->Vis)
("DidAlert", w.DidAlert, def->DidAlert)
("filler", w.filler, def->filler)

View file

@ -6461,7 +6461,7 @@ KeyMain:
nu->spal = np->pal = sp->pal; // Set the palette of the flag
SetOwner(pp->PlayerSprite,New); // Player now owns the flag
nu->FlagOwner = SpriteNum; // Tell carried flag who owns it
nu->flagOwnerActor = actor; // Tell carried flag who owns it
KillGet(SpriteNum); // Set up for flag respawning
break;
}