From 8d8f62baefdcbb1b71d75d505b95e3cc4a675056 Mon Sep 17 00:00:00 2001
From: flarn2006 <flarn2006@gmail.com>
Date: Fri, 28 May 2021 23:59:39 -0400
Subject: [PATCH] Add additional multitagging functionality

---
 extras/conf/SRB2-22.cfg | 14 ++++++++++++++
 src/p_setup.c           | 33 +++++++++++++++++++++++++++++----
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/extras/conf/SRB2-22.cfg b/extras/conf/SRB2-22.cfg
index d36c16b755..ad930a4851 100644
--- a/extras/conf/SRB2-22.cfg
+++ b/extras/conf/SRB2-22.cfg
@@ -640,22 +640,36 @@ linedeftypes
 			prefix = "(63)";
 		}
 
+		96
+		{
+			title = "Apply Tag to Tagged Sectors";
+			prefix = "(96)";
+			flags8192text = "[13] Use Front Side Offsets";
+			flags32768text = "[15] Use Back Side Offsets";
+		}
+
 		97
 		{
 			title = "Apply Tag to Front Sector";
 			prefix = "(97)";
+			flags8192text = "[13] Use Front Side Offsets";
+			flags32768text = "[15] Use Back Side Offsets";
 		}
 
 		98
 		{
 			title = "Apply Tag to Back Sector";
 			prefix = "(98)";
+			flags8192text = "[13] Use Front Side Offsets";
+			flags32768text = "[15] Use Back Side Offsets";
 		}
 
 		99
 		{
 			title = "Apply Tag to Front and Back Sectors";
 			prefix = "(99)";
+			flags8192text = "[13] Use Front Side Offsets";
+			flags32768text = "[15] Use Back Side Offsets";
 		}
 
 		540
diff --git a/src/p_setup.c b/src/p_setup.c
index 16c0802486..6375decac5 100644
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -2952,19 +2952,44 @@ static void P_LinkMapData(void)
 
 // For maps in binary format, add multi-tags from linedef specials. This must be done
 // before any linedef specials have been processed.
+static void P_AddBinaryMapTagsFromLine(sector_t *sector, line_t *line)
+{
+	Tag_Add(&sector->tags, Tag_FGet(&line->tags));
+	if (line->flags & ML_EFFECT6) {
+		if (sides[line->sidenum[0]].textureoffset)
+			Tag_Add(&sector->tags, (INT32)sides[line->sidenum[0]].textureoffset);
+		if (sides[line->sidenum[0]].rowoffset)
+			Tag_Add(&sector->tags, (INT32)sides[line->sidenum[0]].rowoffset);
+	}
+	if (line->flags & ML_TFERLINE) {
+		if (sides[line->sidenum[1]].textureoffset)
+			Tag_Add(&sector->tags, (INT32)sides[line->sidenum[1]].textureoffset);
+		if (sides[line->sidenum[1]].rowoffset)
+			Tag_Add(&sector->tags, (INT32)sides[line->sidenum[1]].rowoffset);
+	}
+}
+
 static void P_AddBinaryMapTags(void)
 {
 	size_t i;
 
 	for (i = 0; i < numlines; i++)
 	{
+		// 96: Apply Tag to Tagged Sectors
 		// 97: Apply Tag to Front Sector
 		// 98: Apply Tag to Back Sector
 		// 99: Apply Tag to Front and Back Sectors
-		if (lines[i].special == 97 || lines[i].special == 99)
-			Tag_Add(&lines[i].frontsector->tags, Tag_FGet(&lines[i].tags));
-		if (lines[i].special == 98 || lines[i].special == 99)
-			Tag_Add(&lines[i].backsector->tags, Tag_FGet(&lines[i].tags));
+		if (lines[i].special == 96) {
+			mtag_t tag = Tag_FGet(&lines[i].frontsector->tags);
+			INT32 s;
+			TAG_ITER_DECLARECOUNTER(0);
+			TAG_ITER_SECTORS(0, tag, s)
+				P_AddBinaryMapTagsFromLine(&sectors[s], &lines[i]);
+		} else if (lines[i].special == 97 || lines[i].special == 99) {
+			P_AddBinaryMapTagsFromLine(lines[i].frontsector, &lines[i]);
+		} else if (lines[i].special == 98 || lines[i].special == 99) {
+			P_AddBinaryMapTagsFromLine(lines[i].backsector, &lines[i]);
+		}
 	}
 }
 
-- 
GitLab