mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-28 06:53:58 +00:00
- Add support for user variables on things in UDMF maps. If you include an actor's user variable
in its UDMF thing definition, that user variable will be set to the desired value for that actor when the map is loaded. SVN r4140 (trunk)
This commit is contained in:
parent
00d5bee72f
commit
e434ccc3f6
3 changed files with 76 additions and 6 deletions
|
@ -142,6 +142,8 @@ int numgamesubsectors;
|
|||
bool hasglnodes;
|
||||
|
||||
TArray<FMapThing> MapThingsConverted;
|
||||
TMap<unsigned,unsigned> MapThingsUserDataIndex; // from mapthing idx -> user data idx
|
||||
TArray<FMapThingUserData> MapThingsUserData;
|
||||
|
||||
int sidecount;
|
||||
sidei_t *sidetemp;
|
||||
|
@ -1637,7 +1639,7 @@ void P_LoadNodes (MapData * map)
|
|||
//===========================================================================
|
||||
CVAR(Bool, dumpspawnedthings, false, 0)
|
||||
|
||||
void SpawnMapThing(int index, FMapThing *mt, int position)
|
||||
AActor *SpawnMapThing(int index, FMapThing *mt, int position)
|
||||
{
|
||||
AActor *spawned = P_SpawnMapThing(mt, position);
|
||||
if (dumpspawnedthings)
|
||||
|
@ -1647,6 +1649,42 @@ void SpawnMapThing(int index, FMapThing *mt, int position)
|
|||
spawned? spawned->GetClass()->TypeName.GetChars() : "(none)");
|
||||
}
|
||||
T_AddSpawnedThing(spawned);
|
||||
return spawned;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// SetMapThingUserData
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
static void SetMapThingUserData(AActor *actor, unsigned udi)
|
||||
{
|
||||
if (actor == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
while (MapThingsUserData[udi].Property != NAME_None)
|
||||
{
|
||||
FName varname = MapThingsUserData[udi].Property;
|
||||
int value = MapThingsUserData[udi].Value;
|
||||
PSymbol *sym = actor->GetClass()->Symbols.FindSymbol(varname, true);
|
||||
PSymbolVariable *var;
|
||||
|
||||
udi++;
|
||||
|
||||
if (sym == NULL || sym->SymbolType != SYM_Variable ||
|
||||
!(var = static_cast<PSymbolVariable *>(sym))->bUserVar ||
|
||||
var->ValueType.Type != VAL_Int)
|
||||
{
|
||||
DPrintf("%s is not a user variable in class %s\n", varname.GetChars(),
|
||||
actor->GetClass()->TypeName.GetChars());
|
||||
}
|
||||
else
|
||||
{ // Set the value of the specified user variable.
|
||||
*(int *)(reinterpret_cast<BYTE *>(actor) + var->offset) = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -1685,7 +1723,7 @@ void P_LoadThings (MapData * map)
|
|||
for (int i=0 ; i < numthings; i++, mt++)
|
||||
{
|
||||
// [RH] At this point, monsters unique to Doom II were weeded out
|
||||
// if the IWAD wasn't for Doom II. R_SpawnMapThing() can now
|
||||
// if the IWAD wasn't for Doom II. P_SpawnMapThing() can now
|
||||
// handle these and more cases better, so we just pass it
|
||||
// everything and let it decide what to do with them.
|
||||
|
||||
|
@ -1780,7 +1818,12 @@ void P_SpawnThings (int position)
|
|||
|
||||
for (int i=0; i < numthings; i++)
|
||||
{
|
||||
SpawnMapThing (i, &MapThingsConverted[i], position);
|
||||
AActor *actor = SpawnMapThing (i, &MapThingsConverted[i], position);
|
||||
unsigned *udi = MapThingsUserDataIndex.CheckKey((unsigned)i);
|
||||
if (udi != NULL)
|
||||
{
|
||||
SetMapThingUserData(actor, *udi);
|
||||
}
|
||||
}
|
||||
for(int i=0; i<MAXPLAYERS; i++)
|
||||
{
|
||||
|
@ -3501,6 +3544,8 @@ void P_SetupLevel (char *lumpname, int position)
|
|||
wminfo.partime = 180;
|
||||
|
||||
MapThingsConverted.Clear();
|
||||
MapThingsUserDataIndex.Clear();
|
||||
MapThingsUserData.Clear();
|
||||
linemap.Clear();
|
||||
FCanvasTextureInfo::EmptyList ();
|
||||
R_FreePastViewers ();
|
||||
|
@ -4071,6 +4116,8 @@ void P_SetupLevel (char *lumpname, int position)
|
|||
}
|
||||
}
|
||||
MapThingsConverted.Clear();
|
||||
MapThingsUserDataIndex.Clear();
|
||||
MapThingsUserData.Clear();
|
||||
|
||||
if (glsegextras != NULL)
|
||||
{
|
||||
|
|
|
@ -159,4 +159,14 @@ struct FMissingCount
|
|||
};
|
||||
typedef TMap<FString,FMissingCount> FMissingTextureTracker;
|
||||
|
||||
// Record of user data for UDMF maps
|
||||
struct FMapThingUserData
|
||||
{
|
||||
FName Property;
|
||||
int Value;
|
||||
};
|
||||
extern TMap<unsigned,unsigned> MapThingsUserDataIndex; // from mapthing idx -> user data idx
|
||||
extern TArray<FMapThingUserData> MapThingsUserData;
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -627,9 +627,12 @@ public:
|
|||
break;
|
||||
|
||||
default:
|
||||
if (!strnicmp("user_", key.GetChars(), 5))
|
||||
{
|
||||
// Custom user key - handle later
|
||||
if (0 == strnicmp("user_", key.GetChars(), 5))
|
||||
{ // Custom user key - Sets an actor's user variable directly
|
||||
FMapThingUserData ud;
|
||||
ud.Property = key;
|
||||
ud.Value = CheckInt(key);
|
||||
MapThingsUserData.Push(ud);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1603,8 +1606,18 @@ public:
|
|||
if (sc.Compare("thing"))
|
||||
{
|
||||
FMapThing th;
|
||||
unsigned userdatastart = MapThingsUserData.Size();
|
||||
ParseThing(&th);
|
||||
MapThingsConverted.Push(th);
|
||||
if (userdatastart < MapThingsUserData.Size())
|
||||
{ // User data added
|
||||
MapThingsUserDataIndex[MapThingsConverted.Size()-1] = userdatastart;
|
||||
// Mark end of the user data for this map thing
|
||||
FMapThingUserData ud;
|
||||
ud.Property = NAME_None;
|
||||
ud.Value = 0;
|
||||
MapThingsUserData.Push(ud);
|
||||
}
|
||||
}
|
||||
else if (sc.Compare("linedef"))
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue