From a6dbfcf9c2106d94b815b833eb03c1d5345cf676 Mon Sep 17 00:00:00 2001 From: Player701 Date: Sun, 4 Nov 2018 20:30:40 +0300 Subject: [PATCH] - Added a new field to the Actor class which stores the amount of ticks passed since the game started on the moment the actor was spawned. - Added a function to the Actor class to get its spawn time relative to the current level. - Added spawn time information to the output of the "info" console command. --- src/actor.h | 5 +++++ src/p_mobj.cpp | 29 +++++++++++++++++++++++++++-- src/version.h | 2 +- wadsrc/static/zscript/actor.txt | 2 ++ 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/actor.h b/src/actor.h index 043da9b7ca..f357e6c9ff 100644 --- a/src/actor.h +++ b/src/actor.h @@ -1033,6 +1033,8 @@ public: void AttachLight(unsigned int count, const FLightDefaults *lightdef); void SetDynamicLights(); + // When was this actor spawned? (relative to the current level) + int GetLevelSpawnTime() const; // info for drawing // NOTE: The first member variable *must* be snext. @@ -1262,6 +1264,9 @@ public: int PrevPortalGroup; TArray > AttachedLights; + // When was this actor spawned? + int SpawnTime; + // ThingIDs static void ClearTIDHashes (); void AddToHash (); diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index 596a9fc01a..a1e7cbac87 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -348,6 +348,7 @@ DEFINE_FIELD(AActor, BloodTranslation) DEFINE_FIELD(AActor, RenderHidden) DEFINE_FIELD(AActor, RenderRequired) DEFINE_FIELD(AActor, friendlyseeblocks) +DEFINE_FIELD(AActor, SpawnTime) //========================================================================== // @@ -528,8 +529,9 @@ void AActor::Serialize(FSerializer &arc) A("selfdamagefactor", SelfDamageFactor) A("stealthalpha", StealthAlpha) A("renderhidden", RenderHidden) - A("renderrequired", RenderRequired); - A("friendlyseeblocks", friendlyseeblocks); + A("renderrequired", RenderRequired) + A("friendlyseeblocks", friendlyseeblocks) + A("spawntime", SpawnTime); } #undef A @@ -5006,6 +5008,7 @@ AActor *AActor::StaticSpawn (PClassActor *type, const DVector3 &pos, replace_t a AActor *actor; actor = static_cast(const_cast(type)->CreateNew ()); + actor->SpawnTime = level.totaltime; // Set default dialogue actor->ConversationRoot = GetConversation(actor->GetClass()->TypeName); @@ -8063,6 +8066,25 @@ void AActor::SetTranslation(FName trname) // silently ignore if the name does not exist, this would create some insane message spam otherwise. } +//========================================================================== +// +// AActor :: GetLevelSpawnTime +// +// Returns the time when this actor was spawned, +// relative to the current level. +// +//========================================================================== +int AActor::GetLevelSpawnTime() const +{ + return SpawnTime - level.totaltime + level.time; +} + +DEFINE_ACTION_FUNCTION(AActor, GetLevelSpawnTime) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_INT(self->GetLevelSpawnTime()); +} + //--------------------------------------------------------------------------- // // PROP A_RestoreSpecialPosition @@ -8587,5 +8609,8 @@ void PrintMiscActorInfo(AActor *query) Printf("FriendlySeeBlocks: %d\n", query->friendlyseeblocks); Printf("Target: %s\n", query->target ? query->target->GetClass()->TypeName.GetChars() : "-"); Printf("Last enemy: %s\n", query->lastenemy ? query->lastenemy->GetClass()->TypeName.GetChars() : "-"); + Printf("Spawn time: %d ticks (%f seconds) after game start, %d ticks (%f seconds) after level start\n", + query->SpawnTime, (double) query->SpawnTime / TICRATE, + query->GetLevelSpawnTime(), (double) query->GetLevelSpawnTime() / TICRATE); } } diff --git a/src/version.h b/src/version.h index 61c6ceff8e..36707442e2 100644 --- a/src/version.h +++ b/src/version.h @@ -91,7 +91,7 @@ const char *GetVersionString(); // Use 4500 as the base git save version, since it's higher than the // SVN revision ever got. -#define SAVEVER 4552 +#define SAVEVER 4553 // This is so that derivates can use the same savegame versions without worrying about engine compatibility #define GAMESIG "GZDOOM" diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index c30d6cb249..70ea25e915 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -234,6 +234,7 @@ class Actor : Thinker native native int RenderHidden; native int RenderRequired; native readonly int FriendlySeeBlocks; + native readonly int SpawnTime; meta String Obituary; // Player was killed by this actor meta String HitObituary; // Player was killed by this actor in melee @@ -708,6 +709,7 @@ class Actor : Thinker native native void GiveSecret(bool printmsg = true, bool playsound = true); native clearscope double GetCameraHeight() const; native clearscope double GetGravity() const; + native clearscope int GetLevelSpawnTime() const; native bool CheckClass(class checkclass, int ptr_select = AAPTR_DEFAULT, bool match_superclass = false); native void AddInventory(Inventory inv);