2013-04-16 12:52:40 +00:00
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
|
|
|
|
{
|
|
|
|
|
internal class EffectPlaneCopySlope : SectorEffect
|
|
|
|
|
{
|
|
|
|
|
// Linedef that is used to create this effect
|
2014-05-05 08:36:15 +00:00
|
|
|
|
private readonly Linedef linedef;
|
|
|
|
|
private readonly bool front;
|
2013-04-16 12:52:40 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public EffectPlaneCopySlope(SectorData data, Linedef sourcelinedef, bool front) : base(data)
|
|
|
|
|
{
|
2014-05-05 08:36:15 +00:00
|
|
|
|
this.linedef = sourcelinedef;
|
|
|
|
|
this.front = front;
|
2013-04-16 12:52:40 +00:00
|
|
|
|
|
|
|
|
|
// New effect added: This sector needs an update!
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(data.Mode.VisualSectorExists(data.Sector))
|
|
|
|
|
{
|
2013-04-16 12:52:40 +00:00
|
|
|
|
BaseVisualSector vs = (BaseVisualSector)data.Mode.GetVisualSector(data.Sector);
|
|
|
|
|
vs.UpdateSectorGeometry(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This makes sure we are updated with the source linedef information
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public override void Update()
|
|
|
|
|
{
|
2013-04-16 12:52:40 +00:00
|
|
|
|
Sector sourcesector = null;
|
|
|
|
|
SectorData sourcesectordata = null;
|
|
|
|
|
|
2014-05-05 08:36:15 +00:00
|
|
|
|
// Copy slopes from tagged sectors
|
2013-04-16 12:52:40 +00:00
|
|
|
|
//check which arguments we must use
|
2014-05-05 08:36:15 +00:00
|
|
|
|
int floorArg = (front ? 0 : 2);
|
|
|
|
|
int ceilingArg = (front ? 1 : 3);
|
2013-04-16 12:52:40 +00:00
|
|
|
|
|
|
|
|
|
//find sector to align floor to
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(linedef.Args[floorArg] > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach(Sector s in General.Map.Map.Sectors)
|
|
|
|
|
{
|
2015-07-28 15:04:21 +00:00
|
|
|
|
if(s.Tags.Contains(linedef.Args[floorArg]))
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2013-04-16 12:52:40 +00:00
|
|
|
|
sourcesector = s;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(sourcesector != null)
|
|
|
|
|
{
|
2013-04-16 12:52:40 +00:00
|
|
|
|
sourcesectordata = data.Mode.GetSectorData(sourcesector);
|
|
|
|
|
if(!sourcesectordata.Updated) sourcesectordata.Update();
|
|
|
|
|
|
|
|
|
|
data.Floor.plane = sourcesectordata.Floor.plane;
|
|
|
|
|
sourcesectordata.AddUpdateSector(data.Sector, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(linedef.Args[ceilingArg] > 0)
|
|
|
|
|
{
|
2013-04-16 12:52:40 +00:00
|
|
|
|
//find sector to align ceiling to
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(linedef.Args[ceilingArg] != linedef.Args[floorArg])
|
|
|
|
|
{
|
2013-04-16 12:52:40 +00:00
|
|
|
|
sourcesector = null;
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
foreach(Sector s in General.Map.Map.Sectors)
|
|
|
|
|
{
|
2015-07-28 15:04:21 +00:00
|
|
|
|
if(s.Tags.Contains(linedef.Args[ceilingArg]))
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2013-04-16 12:52:40 +00:00
|
|
|
|
sourcesector = s;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(sourcesector != null)
|
|
|
|
|
{
|
2013-04-16 12:52:40 +00:00
|
|
|
|
sourcesectordata = data.Mode.GetSectorData(sourcesector);
|
|
|
|
|
if(!sourcesectordata.Updated) sourcesectordata.Update();
|
|
|
|
|
|
2014-05-05 08:36:15 +00:00
|
|
|
|
data.Ceiling.plane = sourcesectordata.Ceiling.plane;
|
2013-04-16 12:52:40 +00:00
|
|
|
|
sourcesectordata.AddUpdateSector(data.Sector, true);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
else if(sourcesector != null) //ceiling uses the same sector as floor
|
|
|
|
|
{
|
2013-04-16 12:52:40 +00:00
|
|
|
|
data.Ceiling.plane = sourcesectordata.Ceiling.plane;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-05-05 08:36:15 +00:00
|
|
|
|
|
2014-05-06 08:21:10 +00:00
|
|
|
|
//check the flags...
|
|
|
|
|
bool copyFloor = false;
|
|
|
|
|
bool copyCeiling = false;
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(linedef.Args[4] > 0 && linedef.Args[4] != 3 && linedef.Args[4] != 12)
|
|
|
|
|
{
|
|
|
|
|
if (front)
|
|
|
|
|
{
|
2014-05-06 08:21:10 +00:00
|
|
|
|
copyFloor = (linedef.Args[4] & 2) == 2;
|
|
|
|
|
copyCeiling = (linedef.Args[4] & 8) == 8;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-05-06 08:21:10 +00:00
|
|
|
|
copyFloor = (linedef.Args[4] & 1) == 1;
|
|
|
|
|
copyCeiling = (linedef.Args[4] & 4) == 4;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-05 08:36:15 +00:00
|
|
|
|
// Copy slope across the line
|
|
|
|
|
if(!copyFloor && !copyCeiling) return;
|
|
|
|
|
|
|
|
|
|
//get appropriate source sector data
|
|
|
|
|
sourcesectordata = data.Mode.GetSectorData(front ? linedef.Back.Sector : linedef.Front.Sector);
|
|
|
|
|
if(!sourcesectordata.Updated) sourcesectordata.Update();
|
|
|
|
|
|
|
|
|
|
//copy floor slope?
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(copyFloor)
|
|
|
|
|
{
|
2014-05-05 08:36:15 +00:00
|
|
|
|
data.Floor.plane = sourcesectordata.Floor.plane;
|
|
|
|
|
sourcesectordata.AddUpdateSector(data.Sector, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//copy ceiling slope?
|
2014-12-03 23:15:26 +00:00
|
|
|
|
if(copyCeiling)
|
|
|
|
|
{
|
2014-05-05 08:36:15 +00:00
|
|
|
|
data.Ceiling.plane = sourcesectordata.Ceiling.plane;
|
|
|
|
|
sourcesectordata.AddUpdateSector(data.Sector, true);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-16 12:52:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|