2013-04-11 11:04:16 +00:00
|
|
|
|
using System.Collections.Generic;
|
2012-09-26 00:04:17 +00:00
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
|
using CodeImp.DoomBuilder.VisualModes;
|
|
|
|
|
using CodeImp.DoomBuilder.GZBuilder.Geometry;
|
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
|
using CodeImp.DoomBuilder.Config;
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
namespace CodeImp.DoomBuilder.GZBuilder.Data
|
|
|
|
|
{
|
|
|
|
|
public static class LinksCollector
|
|
|
|
|
{
|
|
|
|
|
private struct ThingsCheckResult
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
public bool ProcessPathNodes;
|
|
|
|
|
public bool ProcessInterpolationPoints;
|
|
|
|
|
public bool ProcessThingsWithGoal;
|
|
|
|
|
public bool ProcessCameras;
|
2012-09-26 00:04:17 +00:00
|
|
|
|
public bool ProcessActorMovers;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public static List<Line3D> GetThingLinks(ICollection<VisualThing> visualThings)
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
List<Thing> things = new List<Thing>();
|
|
|
|
|
foreach (VisualThing vt in visualThings) things.Add(vt.Thing);
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
ThingsCheckResult result = CheckThings(things);
|
2013-09-11 09:47:53 +00:00
|
|
|
|
if (result.ProcessPathNodes || result.ProcessInterpolationPoints || result.ProcessThingsWithGoal || result.ProcessCameras)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
return GetThingLinks(result, true);
|
2013-09-11 09:47:53 +00:00
|
|
|
|
return new List<Line3D>();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public static List<Line3D> GetThingLinks(ICollection<Thing> things)
|
|
|
|
|
{
|
|
|
|
|
ThingsCheckResult result = CheckThings(things);
|
2013-09-11 09:47:53 +00:00
|
|
|
|
if (result.ProcessPathNodes || result.ProcessInterpolationPoints || result.ProcessThingsWithGoal || result.ProcessCameras)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
return GetThingLinks(result, false);
|
2013-09-11 09:47:53 +00:00
|
|
|
|
return new List<Line3D>();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private static ThingsCheckResult CheckThings(ICollection<Thing> things)
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
ThingsCheckResult result = new ThingsCheckResult();
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach (Thing t in things)
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
if(t.Type == 9024) //zdoom path node
|
|
|
|
|
result.ProcessPathNodes = true;
|
|
|
|
|
else if(t.Type == 9070) //zdoom camera interpolation point
|
|
|
|
|
result.ProcessInterpolationPoints = true;
|
|
|
|
|
else if(t.Action == 229 && t.Args[1] != 0) //Thing_SetGoal
|
|
|
|
|
result.ProcessThingsWithGoal = true;
|
|
|
|
|
else if(t.Type == 9072 && (t.Args[0] != 0 || t.Args[1] != 0)) //camera with a path
|
|
|
|
|
result.ProcessCameras = true;
|
|
|
|
|
else if(t.Type == 9074 && (t.Args[0] != 0 || t.Args[1] != 0) && t.Args[3] != 0) //actor mover
|
|
|
|
|
result.ProcessActorMovers = true;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
|
|
|
|
if(result.ProcessActorMovers || result.ProcessCameras)
|
|
|
|
|
result.ProcessInterpolationPoints = true;
|
|
|
|
|
|
|
|
|
|
if(result.ProcessThingsWithGoal)
|
|
|
|
|
result.ProcessPathNodes = true;
|
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
return result;
|
|
|
|
|
}
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private static List<Line3D> GetThingLinks(ThingsCheckResult result, bool correctHeight)
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
List<Line3D> lines = new List<Line3D>();
|
2012-09-26 00:04:17 +00:00
|
|
|
|
Dictionary<int, List<Thing>> pathNodes = new Dictionary<int, List<Thing>>();
|
|
|
|
|
Dictionary<int, List<Thing>> interpolationPoints = new Dictionary<int, List<Thing>>();
|
2013-09-11 09:47:53 +00:00
|
|
|
|
List<Thing> thingsWithGoal = new List<Thing>();
|
|
|
|
|
List<Thing> cameras = new List<Thing>();
|
2012-09-26 00:04:17 +00:00
|
|
|
|
List<Thing> actorMovers = new List<Thing>();
|
|
|
|
|
Dictionary<int, List<Thing>> actorMoverTargets = new Dictionary<int, List<Thing>>();
|
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
//collect relevant things
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach (Thing t in General.Map.Map.Things)
|
|
|
|
|
{
|
|
|
|
|
if(result.ProcessPathNodes && t.Type == 9024)
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
if(!pathNodes.ContainsKey(t.Tag))
|
|
|
|
|
pathNodes[t.Tag] = new List<Thing>();
|
|
|
|
|
pathNodes[t.Tag].Add(t);
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(result.ProcessInterpolationPoints && t.Type == 9070)
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
if(!interpolationPoints.ContainsKey(t.Tag))
|
|
|
|
|
interpolationPoints[t.Tag] = new List<Thing>();
|
|
|
|
|
interpolationPoints[t.Tag].Add(t);
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if (result.ProcessThingsWithGoal && t.Action == 229 && t.Args[1] != 0)
|
2013-09-11 09:47:53 +00:00
|
|
|
|
thingsWithGoal.Add(t);
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if (result.ProcessCameras && t.Type == 9072 && (t.Args[0] != 0 || t.Args[1] != 0))
|
2013-09-11 09:47:53 +00:00
|
|
|
|
cameras.Add(t);
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(result.ProcessActorMovers && t.Type == 9074 && (t.Args[0] != 0 || t.Args[1] != 0) && t.Args[3] != 0)
|
2012-09-26 00:04:17 +00:00
|
|
|
|
actorMovers.Add(t);
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(actorMovers.Count > 0)
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
List<int> targetedTags = new List<int>();
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Thing t in actorMovers) targetedTags.Add(t.Args[3]);
|
|
|
|
|
foreach(Thing t in General.Map.Map.Things)
|
|
|
|
|
{
|
|
|
|
|
if(targetedTags.Contains(t.Tag))
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
if(!actorMoverTargets.ContainsKey(t.Tag))
|
|
|
|
|
actorMoverTargets[t.Tag] = new List<Thing>();
|
|
|
|
|
actorMoverTargets[t.Tag].Add(t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-21 14:42:12 +00:00
|
|
|
|
Vector3D start, end;
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
//process path nodes
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if (result.ProcessPathNodes)
|
|
|
|
|
{
|
|
|
|
|
foreach (KeyValuePair<int, List<Thing>> group in pathNodes)
|
|
|
|
|
{
|
|
|
|
|
foreach(Thing t in group.Value)
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
if(t.Args[0] == 0) continue; //no goal
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(pathNodes.ContainsKey(t.Args[0]))
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
start = t.Position;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(correctHeight) start.z += GetCorrectHeight(t);
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Thing tt in pathNodes[t.Args[0]])
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
end = tt.Position;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(correctHeight) end.z += GetCorrectHeight(tt);
|
2012-09-26 00:04:17 +00:00
|
|
|
|
lines.Add(new Line3D(start, end));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
//process things with Thing_SetGoal
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if (result.ProcessThingsWithGoal)
|
|
|
|
|
{
|
|
|
|
|
foreach (Thing t in thingsWithGoal)
|
|
|
|
|
{
|
|
|
|
|
if (pathNodes.ContainsKey(t.Args[1]))
|
|
|
|
|
{
|
|
|
|
|
if (t.Args[0] == 0 || t.Args[0] == t.Tag)
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
start = t.Position;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if (correctHeight) start.z += GetCorrectHeight(t);
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Thing tt in pathNodes[t.Args[1]])
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
end = tt.Position;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(correctHeight) end.z += GetCorrectHeight(tt);
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
|
|
|
|
lines.Add(new Line3D(start, end, Line3DType.ACTIVATOR));
|
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//process interpolation points
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if (result.ProcessInterpolationPoints)
|
|
|
|
|
{
|
|
|
|
|
foreach (KeyValuePair<int, List<Thing>> group in interpolationPoints)
|
|
|
|
|
{
|
|
|
|
|
foreach(Thing t in group.Value)
|
|
|
|
|
{
|
2013-08-08 11:04:13 +00:00
|
|
|
|
int targetTag = t.Args[3] + (t.Args[4] << 8);
|
2012-09-26 00:04:17 +00:00
|
|
|
|
if(targetTag == 0) continue; //no goal
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(interpolationPoints.ContainsKey(targetTag))
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
start = t.Position;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(correctHeight) start.z += GetCorrectHeight(t);
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Thing tt in interpolationPoints[targetTag])
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
end = tt.Position;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(correctHeight) end.z += GetCorrectHeight(tt);
|
2012-09-26 00:04:17 +00:00
|
|
|
|
lines.Add(new Line3D(start, end));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
//process cameras
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if (result.ProcessCameras)
|
|
|
|
|
{
|
|
|
|
|
foreach (Thing t in cameras)
|
|
|
|
|
{
|
2013-08-08 11:04:13 +00:00
|
|
|
|
int targetTag = t.Args[0] + (t.Args[1] << 8);
|
2013-09-11 09:47:53 +00:00
|
|
|
|
if (targetTag == 0) continue; //no goal
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(interpolationPoints.ContainsKey(targetTag))
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
start = t.Position;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(correctHeight) start.z += GetCorrectHeight(t);
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Thing tt in interpolationPoints[targetTag])
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
end = tt.Position;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(correctHeight) end.z += GetCorrectHeight(tt);
|
2012-09-26 00:04:17 +00:00
|
|
|
|
lines.Add(new Line3D(start, end, Line3DType.ACTIVATOR));
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
|
|
|
|
//process actor movers
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(result.ProcessActorMovers)
|
|
|
|
|
{
|
|
|
|
|
foreach(Thing t in actorMovers)
|
|
|
|
|
{
|
2013-08-08 11:04:13 +00:00
|
|
|
|
int targetTag = t.Args[0] + (t.Args[1] << 8);
|
2012-09-26 00:04:17 +00:00
|
|
|
|
if(targetTag == 0) continue; //no goal
|
|
|
|
|
|
|
|
|
|
//add interpolation point target
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(interpolationPoints.ContainsKey(targetTag))
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
start = t.Position;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(correctHeight) start.z += GetCorrectHeight(t);
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Thing tt in interpolationPoints[targetTag])
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
end = tt.Position;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(correctHeight) end.z += GetCorrectHeight(tt);
|
2012-09-26 00:04:17 +00:00
|
|
|
|
lines.Add(new Line3D(start, end, Line3DType.ACTIVATOR));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//add thing-to-move target
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(actorMoverTargets.ContainsKey(t.Args[3]))
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
start = t.Position;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(correctHeight) start.z += GetCorrectHeight(t);
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Thing tt in actorMoverTargets[t.Args[3]])
|
|
|
|
|
{
|
2012-09-26 00:04:17 +00:00
|
|
|
|
end = tt.Position;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(correctHeight) end.z += GetCorrectHeight(tt);
|
2012-09-26 00:04:17 +00:00
|
|
|
|
lines.Add(new Line3D(start, end, Line3DType.ACTIVATOR));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
return lines;
|
|
|
|
|
}
|
2012-09-26 00:04:17 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private static float GetCorrectHeight(Thing thing)
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
ThingTypeInfo tti = General.Map.Data.GetThingInfo(thing.Type);
|
|
|
|
|
float height = tti.Height / 2f;
|
|
|
|
|
if (thing.Sector != null) height += thing.Sector.FloorHeight;
|
|
|
|
|
return height;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-26 00:04:17 +00:00
|
|
|
|
}
|