- Expose GetFloorPlane and GetCeilingPlane to UDBScript

- Add two new example scripts, remove one useless example script
This commit is contained in:
spherallic 2024-02-20 15:25:13 +01:00
parent 59492bfbf5
commit 192ddc9e6c
4 changed files with 76 additions and 73 deletions

View file

@ -0,0 +1,17 @@
/// <reference path="../udbscript.d.ts" />
`#version 5`;
`#name Convert thing height to absolute Z`;
UDB.Map.getSelectedOrHighlightedThings().forEach(thing => {
const sector = thing.getSector();
if (thing.flags['absolutez'] == false && sector != null) {
let plane = sector.getFloorPlane();
let z = plane.getZ([thing.position.x, thing.position.y]);
thing.position.z += z;
thing.flags['absolutez'] = true;
}
});

View file

@ -0,0 +1,33 @@
/// <reference path="../udbscript.d.ts" />
`#version 5`;
`#name Copy slope from opposite surface`;
`#scriptoptions
surfaceType
{
description = "Affected surface type";
default = 0;
type = 11; // Enum
enumvalues {
0 = "Floor";
1 = "Ceiling";
}
}
`;
UDB.Map.getSelectedOrHighlightedSectors().forEach(sector => {
if (UDB.ScriptOptions.surfaceType == 0) {
const slope = sector.getCeilingSlope();
sector.setFloorSlope([-slope.x, -slope.y, -slope.z]);
sector.floorSlopeOffset = -sector.ceilingSlopeOffset;
sector.floorHeight = sector.ceilingHeight;
} else {
const slope = sector.getFloorSlope();
sector.setCeilingSlope([-slope.x, -slope.y, -slope.z]);
sector.ceilingSlopeOffset = -sector.floorSlopeOffset;
sector.ceilingHeight = sector.floorHeight;
}
});

View file

@ -1,73 +0,0 @@
/// <reference path="../../udbscript.d.ts" />
`#version 4`;
`#name Imps to Arch-Viles`;
`#description Turns all Imps that appear on UV into Arch-Viles. To make it a bit more fair for the player it also adds a health potion to the monster's position.`;
UDB.Map.getThings().filter(t => t.type == 3001 && ((UDB.Map.isUDMF && t.flags.skill5) || (!UDB.Map.isUDMF && t.flags['4']))).forEach(t => {
let addav = false;
let skillsum = 0;
// Count the number of skills the Imp appears on
if(UDB.Map.isUDMF)
{
for(let i=1; i <= 5; i++)
if(t.flags['skill' + i])
skillsum++;
}
else
{
for(let i=0; i < 3; i++)
if(t.flags[parseInt(1 << i)])
skillsum++;
}
// If the Imp appears on more than one skill we need to add the Arch-Vile, otherwise we can
// simply set the existing thing's type to that of the Arch-Vile
if(skillsum != 1)
addav = true;
// Create a new health potion at the thing's position
let hp = UDB.Map.createThing(t.position, 2014);
if(UDB.Map.isUDMF)
{
hp.flags.skill5 = true;
for(let i=1; i <= 4; i++)
hp.flags['skill' + i] = false;
}
else
{
hp.flags['4'] = true;
hp.flags['1'] = hp.flags['2'] = false;
}
if(addav)
{
// Create a new Arch-Vile and copy all the original thing's properties
let av = UDB.Map.createThing(t.position);
t.copyPropertiesTo(av);
av.type = 64;
// Set the skill flags. Since we're addin an Arch-Vile we have to unset the Imp's UV flag,
// and remove the Arch-Viles (and health potion's) other skill flags
if(UDB.Map.isUDMF)
{
t.flags.skill5 = false;
for(let i=1; i <= 4; i++)
av.flags['skill' + i] = false;
}
else
{
t.flags['4'] = false;
av.flags['1'] = av.flags['2'] = false;
}
}
else
{
// Modify the existing thing to be the Arch-Vile
t.type = 64;
}
});

View file

@ -699,6 +699,19 @@ namespace CodeImp.DoomBuilder.UDBScript.Wrapper
return new Vector3DWrapper(sector.FloorSlope.GetNormal());
}
/// <summary>
/// Gets the floor's plane, accounting for flat planes, UDMF slopes and line slopes.
/// </summary>
/// <returns>The floor's plane as a `Plane`</returns>
public PlaneWrapper getFloorPlane()
{
if (sector.IsDisposed)
throw BuilderPlug.Me.ScriptRunner.CreateRuntimeException("Sector is disposed, the getFloorPlane method can not be accessed.");
Plane plane = Sector.GetFloorPlane(sector);
return new PlaneWrapper(new Vector3D(plane.a, plane.b, plane.c), plane.d);
}
/// <summary>
/// Sets the floor's slope vector. The vector has to be normalized.
/// </summary>
@ -730,6 +743,19 @@ namespace CodeImp.DoomBuilder.UDBScript.Wrapper
return new Vector3DWrapper(sector.CeilSlope.GetNormal());
}
/// <summary>
/// Gets the ceiling's plane, accounting for flat planes, UDMF slopes and line slopes.
/// </summary>
/// <returns>The ceiling's plane as a `Plane`</returns>
public PlaneWrapper getCeilingPlane()
{
if (sector.IsDisposed)
throw BuilderPlug.Me.ScriptRunner.CreateRuntimeException("Sector is disposed, the getCeilingPlane method can not be accessed.");
Plane plane = Sector.GetCeilingPlane(sector);
return new PlaneWrapper(new Vector3D(plane.a, plane.b, plane.c), plane.d);
}
/// <summary>
/// Sets the ceiling's slope vector. The vector has to be normalized.
/// </summary>