From baa99150d076cf4fb2781d95414a35dc00e27033 Mon Sep 17 00:00:00 2001
From: MascaraSnake <jonassauer27@gmail.com>
Date: Sat, 25 Dec 2021 09:58:00 +0100
Subject: [PATCH] Adapt Fang waypoint to UDMF

---
 extras/conf/udb/Includes/SRB222_things.cfg |  6 ++++++
 src/p_enemy.c                              | 25 ++++++++++------------
 src/p_setup.c                              |  4 ++++
 3 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/extras/conf/udb/Includes/SRB222_things.cfg b/extras/conf/udb/Includes/SRB222_things.cfg
index e5bec6d3a..5cc285118 100644
--- a/extras/conf/udb/Includes/SRB222_things.cfg
+++ b/extras/conf/udb/Includes/SRB222_things.cfg
@@ -3989,6 +3989,12 @@ udmf
 			sprite = "internal:eggmanway";
 			width = 8;
 			height = 16;
+			arg0
+			{
+				title = "Center waypoint?";
+				type = 11;
+				enum = "noyes";
+			}
 		}
 	}
 
diff --git a/src/p_enemy.c b/src/p_enemy.c
index 079ae5e64..bff7622b7 100644
--- a/src/p_enemy.c
+++ b/src/p_enemy.c
@@ -12693,7 +12693,7 @@ void A_Boss5FindWaypoint(mobj_t *actor)
 {
 	INT32 locvar1 = var1;
 	boolean avoidcenter;
-	UINT32 i;
+	INT32 i;
 	UINT8 extrainfo = (actor->spawnpoint ? actor->spawnpoint->extrainfo : 0);
 
 	if (LUA_CallAction(A_BOSS5FINDWAYPOINT, actor))
@@ -12735,25 +12735,26 @@ void A_Boss5FindWaypoint(mobj_t *actor)
 	}
 	else if (locvar1 == 1) // always go to ambush-marked waypoint
 	{
+		boolean found = false;
+
 		if (avoidcenter)
 			goto nowaypoints; // if we can't go the center, why on earth are we doing this?
 
-		for (i = 0; i < nummapthings; i++)
+		TAG_ITER_THINGS(extrainfo, i)
 		{
 			if (!mapthings[i].mobj)
 				continue;
 			if (mapthings[i].mobj->type != MT_FANGWAYPOINT)
 				continue;
-			if (mapthings[i].extrainfo != extrainfo)
-				continue;
-			if (!(mapthings[i].options & MTF_AMBUSH))
+			if (!(mapthings[i].args[0]))
 				continue;
 
 			P_SetTarget(&actor->tracer, mapthings[i].mobj);
+			found = true;
 			break;
 		}
 
-		if (i == nummapthings)
+		if (!found)
 			goto nowaypoints;
 	}
 	else // locvar1 == 0
@@ -12766,7 +12767,7 @@ void A_Boss5FindWaypoint(mobj_t *actor)
 		actor->z += hackoffset;
 
 		// first, count how many waypoints we have
-		for (i = 0; i < nummapthings; i++)
+		TAG_ITER_THINGS(extrainfo, i)
 		{
 			if (!mapthings[i].mobj)
 				continue;
@@ -12774,9 +12775,7 @@ void A_Boss5FindWaypoint(mobj_t *actor)
 				continue;
 			if (actor->tracer == mapthings[i].mobj) // this was your tracer last time
 				continue;
-			if (mapthings[i].extrainfo != extrainfo)
-				continue;
-			if (mapthings[i].options & MTF_AMBUSH)
+			if (mapthings[i].args[0])
 			{
 				if (avoidcenter)
 					continue;
@@ -12823,7 +12822,7 @@ void A_Boss5FindWaypoint(mobj_t *actor)
 		numfangwaypoints = 0;
 
 		// now find them again and add them to the table!
-		for (i = 0; i < nummapthings; i++)
+		TAG_ITER_THINGS(extrainfo, i)
 		{
 			if (!mapthings[i].mobj)
 				continue;
@@ -12831,9 +12830,7 @@ void A_Boss5FindWaypoint(mobj_t *actor)
 				continue;
 			if (actor->tracer == mapthings[i].mobj) // this was your tracer last time
 				continue;
-			if (mapthings[i].extrainfo != extrainfo)
-				continue;
-			if (mapthings[i].options & MTF_AMBUSH)
+			if (mapthings[i].args[0])
 			{
 				if (avoidcenter)
 					continue;
diff --git a/src/p_setup.c b/src/p_setup.c
index 03a7cf564..e2603cc46 100644
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -3130,6 +3130,7 @@ static void P_AddBinaryMapTags(void)
 		case 762:
 			Tag_FSet(&mapthings[i].tags, mapthings[i].angle);
 			break;
+		case 294:
 		case 780:
 			Tag_FSet(&mapthings[i].tags, mapthings[i].extrainfo);
 			break;
@@ -4899,6 +4900,9 @@ static void P_ConvertBinaryMap(void)
 		case 136: //Pyre Fly
 			mapthings[i].args[0] = !!(mapthings[i].options & MTF_AMBUSH);
 			break;
+		case 294:
+			mapthings[i].args[0] = !!(mapthings[i].options & MTF_AMBUSH);
+			break;
 		case 502: //Star post
 			if (mapthings[i].extrainfo)
 				// Allow thing Parameter to define star post num too!
-- 
GitLab