diff --git a/src/playsim/p_tags.cpp b/src/playsim/p_tags.cpp index ae5ba5727..17b261ca8 100644 --- a/src/playsim/p_tags.cpp +++ b/src/playsim/p_tags.cpp @@ -314,6 +314,92 @@ void FTagManager::DumpTags() } } +//----------------------------------------------------------------------------- +// +// +// +//----------------------------------------------------------------------------- + +int FTagManager::CountSectorTags(const sector_t *sector) +{ + int i = sector->Index(); + + if (SectorHasTags(i)) + { + const int n = allTags.Size(); + + int j = startForSector[i]; + int c = 0; + + while(j < n && allTags[j].target == i) + { + j++; + c++; + } + + return c; + } + + return 0; +} + +int FTagManager::GetSectorTag(const sector_t *sector, int index) +{ + int i = sector->Index(); + + if (SectorHasTags(i)) + { + const int n = allTags.Size(); + + int j = startForSector[i] + index; + + return (j < n && allTags[j].target == i) ? allTags[j].tag : 0; + } +} + +//----------------------------------------------------------------------------- +// +// +// +//----------------------------------------------------------------------------- + +int FTagManager::CountLineIDs(const line_t *line) +{ + int i = line->Index(); + + if (LineHasIDs(i)) + { + const int n = allTags.Size(); + + int j = startForLine[i]; + int c = 0; + + while(j < n && allTags[j].target == i) + { + j++; + c++; + } + + return c; + } + + return 0; +} + +int FTagManager::GetLineID(const line_t *line, int index) +{ + int i = line->Index(); + + if (LineHasIDs(i)) + { + const int n = allTags.Size(); + + int j = startForLine[i] + index; + + return (j < n && allTags[j].target == i) ? allTags[j].tag : 0; + } +} + //----------------------------------------------------------------------------- // // RETURN NEXT SECTOR # THAT LINE TAG REFERS TO diff --git a/src/playsim/p_tags.h b/src/playsim/p_tags.h index 7452ef755..aee44fbd4 100644 --- a/src/playsim/p_tags.h +++ b/src/playsim/p_tags.h @@ -77,6 +77,12 @@ public: // The ones below are called by functions that cannot be declared as fri void RemoveLineIDs(int line); void DumpTags(); + + int CountSectorTags(const sector_t *sector); + int GetSectorTag(const sector_t *sector, int index); + + int CountLineIDs(const line_t *line); + int GetLineID(const line_t *line, int index); }; class FSectorTagIterator diff --git a/src/scripting/vmthunks.cpp b/src/scripting/vmthunks.cpp index d672a5192..44e628068 100644 --- a/src/scripting/vmthunks.cpp +++ b/src/scripting/vmthunks.cpp @@ -1139,6 +1139,29 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Sector, SetXOffset, SetXOffset) ACTION_RETURN_INT(self->e->XFloor.attached.Size()); } + static int CountSectorTags(const sector_t *self) + { + return level.tagManager.CountSectorTags(self); + } + + DEFINE_ACTION_FUNCTION_NATIVE(_Sector, CountTags, CountSectorTags) + { + PARAM_SELF_STRUCT_PROLOGUE(sector_t); + ACTION_RETURN_INT(level.tagManager.CountSectorTags(self)); + } + + static int GetSectorTag(const sector_t *self, int index) + { + return level.tagManager.GetSectorTag(self, index); + } + + DEFINE_ACTION_FUNCTION_NATIVE(_Sector, GetTag, GetSectorTag) + { + PARAM_SELF_STRUCT_PROLOGUE(sector_t); + PARAM_INT(index); + ACTION_RETURN_INT(level.tagManager.GetSectorTag(self, index)); + } + static int Get3DFloorTexture(F3DFloor *self, int pos) { if ( pos ) @@ -1240,6 +1263,29 @@ DEFINE_ACTION_FUNCTION_NATIVE(_Sector, SetXOffset, SetXOffset) ACTION_RETURN_INT(LineIndex(self)); } + static int CountLineIDs(const line_t *self) + { + return level.tagManager.CountLineIDs(self); + } + + DEFINE_ACTION_FUNCTION_NATIVE(_Line, CountIDs, CountLineIDs) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + ACTION_RETURN_INT(level.tagManager.CountLineIDs(self)); + } + + static int GetLineID(const line_t *self, int index) + { + return level.tagManager.GetLineID(self, index); + } + + DEFINE_ACTION_FUNCTION_NATIVE(_Line, GetID, GetLineID) + { + PARAM_SELF_STRUCT_PROLOGUE(line_t); + PARAM_INT(index); + ACTION_RETURN_INT(level.tagManager.GetLineID(self, index)); + } + //=========================================================================== // // side_t exports diff --git a/wadsrc/static/zscript/mapdata.zs b/wadsrc/static/zscript/mapdata.zs index e7f3044ff..dfe4a7016 100644 --- a/wadsrc/static/zscript/mapdata.zs +++ b/wadsrc/static/zscript/mapdata.zs @@ -254,6 +254,9 @@ struct Line native play native clearscope int GetHealth() const; native void SetHealth(int newhealth); + + native int CountIDs() const; + native int GetID(int index) const; } struct SecPlane native play @@ -646,6 +649,9 @@ struct Sector native play native clearscope int GetHealth(SectorPart part) const; native void SetHealth(SectorPart part, int newhealth); + + native int CountTags() const; + native int GetTag(int index) const; } class SectorTagIterator : Object native