From 56f76a141edbc1df423b9c441c553fca25320c49 Mon Sep 17 00:00:00 2001 From: Player701 Date: Sun, 4 Nov 2018 20:55:52 +0300 Subject: [PATCH] - Added a function to get the actor's age in ticks. --- src/actor.h | 2 ++ src/p_mobj.cpp | 18 ++++++++++++++++++ wadsrc/static/zscript/actor.txt | 1 + 3 files changed, 21 insertions(+) diff --git a/src/actor.h b/src/actor.h index f357e6c9f..9123da4fa 100644 --- a/src/actor.h +++ b/src/actor.h @@ -1035,6 +1035,8 @@ public: // When was this actor spawned? (relative to the current level) int GetLevelSpawnTime() const; + // How many ticks passed since this actor was spawned? + int GetAge() const; // info for drawing // NOTE: The first member variable *must* be snext. diff --git a/src/p_mobj.cpp b/src/p_mobj.cpp index a1e7cbac8..67d934060 100644 --- a/src/p_mobj.cpp +++ b/src/p_mobj.cpp @@ -8085,6 +8085,24 @@ DEFINE_ACTION_FUNCTION(AActor, GetLevelSpawnTime) ACTION_RETURN_INT(self->GetLevelSpawnTime()); } +//========================================================================== +// +// AActor :: GetAge +// +// Returns the number of ticks passed since this actor was spawned. +// +//========================================================================== +int AActor::GetAge() const +{ + return level.totaltime - SpawnTime; +} + +DEFINE_ACTION_FUNCTION(AActor, GetAge) +{ + PARAM_SELF_PROLOGUE(AActor); + ACTION_RETURN_INT(self->GetAge()); +} + //--------------------------------------------------------------------------- // // PROP A_RestoreSpecialPosition diff --git a/wadsrc/static/zscript/actor.txt b/wadsrc/static/zscript/actor.txt index 70ea25e91..48172b821 100644 --- a/wadsrc/static/zscript/actor.txt +++ b/wadsrc/static/zscript/actor.txt @@ -710,6 +710,7 @@ class Actor : Thinker native native clearscope double GetCameraHeight() const; native clearscope double GetGravity() const; native clearscope int GetLevelSpawnTime() const; + native clearscope int GetAge() const; native bool CheckClass(class checkclass, int ptr_select = AAPTR_DEFAULT, bool match_superclass = false); native void AddInventory(Inventory inv);