Add SetActorFlag ACS function

int SetActorFlag(int tid, str flagname, bool value);

- Mimics DECORATE's A_ChangeFlag
- Returns number of actors affected (number of things with the flag)
- Affects activator if TID is 0

# Conflicts:
#	src/p_acs.cpp
This commit is contained in:
yqco 2016-08-24 04:21:46 -06:00 committed by Christoph Oelckers
commit 2e8aa53e6a
4 changed files with 96 additions and 84 deletions

View file

@ -162,6 +162,71 @@ void ModActorFlag(AActor *actor, FFlagDef *fd, bool set)
#endif
}
//==========================================================================
//
// Finds a flag by name and sets or clears it
//
// Returns true if the flag was found for the actor; else returns false
//
//==========================================================================
bool ModActorFlag(AActor *actor, FString &flagname, bool set, bool printerror)
{
bool found = false;
if (actor != NULL)
{
const char *dot = strchr(flagname, '.');
FFlagDef *fd;
PClassActor *cls = actor->GetClass();
if (dot != NULL)
{
FString part1(flagname.GetChars(), dot - flagname);
fd = FindFlag(cls, part1, dot + 1);
}
else
{
fd = FindFlag(cls, flagname, NULL);
}
if (fd != NULL)
{
found = true;
if (actor->CountsAsKill() && actor->health > 0) --level.total_monsters;
if (actor->flags & MF_COUNTITEM) --level.total_items;
if (actor->flags5 & MF5_COUNTSECRET) --level.total_secrets;
if (fd->structoffset == -1)
{
HandleDeprecatedFlags(actor, cls, set, fd->flagbit);
}
else
{
ActorFlags *flagp = (ActorFlags*)(((char*)actor) + fd->structoffset);
// If these 2 flags get changed we need to update the blockmap and sector links.
bool linkchange = flagp == &actor->flags && (fd->flagbit == MF_NOBLOCKMAP || fd->flagbit == MF_NOSECTOR);
if (linkchange) actor->UnlinkFromWorld();
ModActorFlag(actor, fd, set);
if (linkchange) actor->LinkToWorld();
}
if (actor->CountsAsKill() && actor->health > 0) ++level.total_monsters;
if (actor->flags & MF_COUNTITEM) ++level.total_items;
if (actor->flags5 & MF5_COUNTSECRET) ++level.total_secrets;
}
else if (printerror)
{
DPrintf(DMSG_ERROR, "ACS/DECORATE: '%s' is not a flag in '%s'\n", flagname.GetChars(), cls->TypeName.GetChars());
}
}
return found;
}
//==========================================================================
//
// Returns whether an actor flag is true or not.