Dynamic TID Assigner

From ZDoom Wiki
Jump to navigation Jump to search
Note: The functionality provided by the NextTID function shown here can also be found directly in the engine. You should use UniqueTID instead of this function, as it will be faster.

Assumed Knowledge

It is assumed that before you begin this tutorial, you are familiar with the following concepts:

The Function

We'll start with a map level integer for the base TID to start assigning. For this example we'll use the negative range, from -32767 to -1.

int GiveTID = -32767;

function int NextTID (void)
{
    for ( ; GiveTID < 0; GiveTID++)
    {
        if (!ThingCount (T_NONE, GiveTID))
            return GiveTID;
    }
    return 0;
}

The Script

This is the script your actor will need to activate to give itself a genuine TID. There are several ways to go about the activation. The script checks for the activator to have no TID, then generates a new one to give it. So, if you have a special TID you need to preserve, the script will not overwrite it. If used correctly, this can be a handy tool for individual actor identification for large scale scenarios.

Script 999 (void)
{
    if (!ActivatorTID ())
    {
        Thing_ChangeTID (0, NextTID ());
    }
}

Application

This is an example of how to use DECORATE to modify your Imps so that they will assign themselves unique tids.

ACTOR NewDoomImp : DoomImp replaces DoomImp
{
	States
	{
	Spawn:
		TROO A 0
		TROO A 0 ACS_ExecuteAlways (999, 0)
		TROO AB 10 A_Look
		Goto Spawn+2
	}
}

See Also

Tutorials