From a023633c1670c3ebc98c6014c25d51ad7781167a Mon Sep 17 00:00:00 2001 From: MajorCooke Date: Sat, 9 Mar 2024 07:14:12 -0600 Subject: [PATCH] GZDoom Game Configuration: Added support for PathNodes. (#1032) UDBScript: Added scripts for PathNode management --- Build/Configurations/Includes/ZDoom_misc.cfg | 20 +++ .../Configurations/Includes/ZDoom_things.cfg | 35 ++++++ .../Scripts/Examples/GZDoom/ConnectNode.js | 114 ++++++++++++++++++ .../Scripts/Examples/GZDoom/NewNode.js | 87 +++++++++++++ 4 files changed, 256 insertions(+) create mode 100644 Build/UDBScript/Scripts/Examples/GZDoom/ConnectNode.js create mode 100644 Build/UDBScript/Scripts/Examples/GZDoom/NewNode.js diff --git a/Build/Configurations/Includes/ZDoom_misc.cfg b/Build/Configurations/Includes/ZDoom_misc.cfg index bb6165f1..bc221de2 100755 --- a/Build/Configurations/Includes/ZDoom_misc.cfg +++ b/Build/Configurations/Includes/ZDoom_misc.cfg @@ -222,6 +222,26 @@ secact_flagsrename } } +pathnode_flagsrename +{ + DoomMapSetIO + { + 8 = "Transition"; + } + + HexenMapSetIO + { + 8 = "Transition"; + 16384 = "Invert Size Check"; + } + + UniversalMapSetIO + { + ambush = "Transition"; + standing = "Invert Size Check"; + } +} + // Default sector brightness levels sectorbrightness { diff --git a/Build/Configurations/Includes/ZDoom_things.cfg b/Build/Configurations/Includes/ZDoom_things.cfg index 32780fd1..6d1c2617 100755 --- a/Build/Configurations/Includes/ZDoom_things.cfg +++ b/Build/Configurations/Includes/ZDoom_things.cfg @@ -1284,6 +1284,41 @@ zdoom } } + 9022 + { + title = "Path Node"; + sprite = "internal:PathFollower"; + class = "PathNode"; + flagsrename { include("ZDoom_misc.cfg", "pathnode_flagsrename") } + radius = 16; + height = 56; + arg0 + { + title = "TID 1"; + type = 14; + } + arg1 + { + title = "TID 2"; + type = 14; + } + arg2 + { + title = "TID 3"; + type = 14; + } + arg3 + { + title = "TID 4"; + type = 14; + } + arg4 + { + title = "TID 5"; + type = 14; + } + } + 9024 { title = "Patrol Point"; diff --git a/Build/UDBScript/Scripts/Examples/GZDoom/ConnectNode.js b/Build/UDBScript/Scripts/Examples/GZDoom/ConnectNode.js new file mode 100644 index 00000000..0a5c1ff9 --- /dev/null +++ b/Build/UDBScript/Scripts/Examples/GZDoom/ConnectNode.js @@ -0,0 +1,114 @@ +/// + +`#version 4`; + +`#name Connect Nodes`; + +`#description Connects nodes to/from the first selected PathNode.`; + +`#scriptoptions + +direction +{ + description = "Assignment Direction"; + default = 2; + type = 11; // Enum + enumvalues { + 0 = "To First"; + 1 = "From First"; + 2 = "Both"; + } +} + +doclear +{ + description = "Clear first thing's arguments"; + default = "False"; + type = 3; // Boolean +} + +`; + +let things = UDB.Map.getSelectedThings(); + +if(things.length < 2) + UDB.die('You have to select at least 2 things.'); + +let dir = UDB.ScriptOptions.direction; +let clr = UDB.ScriptOptions.doclear; + +let receiver = things[0]; + +let pos = 0; + +let i = 0; +if (clr) +{ + for (i; i < 5; i++) + receiver.args[i] = 0; +} + +things.forEach(n => +{ + if (n != receiver) + { + if (dir > 0) + { + // look for the tid first, make sure it's not already assigned. + let found = false; + for (i = 0; i < 5; i++) + { + if (n.args[i] == receiver.tag) + { + found = true; + break; + } + } + // Not found, so assign it. + if (!found) for (i = 0; i < 5; i++) + { + + if (n.args[i] == 0) + { + n.args[i] = receiver.tag; + break; + } + } + + } + if ((dir == 0 || dir == 2) && (pos < 5 && n.tag != 0)) + { + + if (clr) // No special management necessary. + { + receiver.args[pos] = n.tag; + pos++; + } + else // Look for a free spot. + { + let found = false; + for (i = 0; i < 5; i++) + { + if (receiver.args[i] == n.tag) + { + found = true; + break; + } + } + if (!found) + { + for (i = pos; i < 5; i++) + { + if (receiver.args[i] == 0) + { + receiver.args[i] = n.tag; + pos = i; + found = true; + break; + } + } + } + } + } + } +}); \ No newline at end of file diff --git a/Build/UDBScript/Scripts/Examples/GZDoom/NewNode.js b/Build/UDBScript/Scripts/Examples/GZDoom/NewNode.js new file mode 100644 index 00000000..dabd96d8 --- /dev/null +++ b/Build/UDBScript/Scripts/Examples/GZDoom/NewNode.js @@ -0,0 +1,87 @@ +/// + +`#version 4`; + +`#name New Path Node`; + +`#description Creates a new node and assigns it a TID. If a Path Node is already selected, connects the two automatically.`; + +`#scriptoptions + +gridsnap +{ + description = "Grid Snap"; + default = 1; + type = 11; // enum + enumvalues { + 0 = "Disabled"; + 1 = "Enabled"; + } +} +`; + + +let mpos = UDB.Map.mousePosition; + +if(!mpos.isFinite()) + UDB.die('Mouse cursor must be inside the map'); + + +let nodetype = 9022; +let ntag = UDB.Map.getNewTag(); +let things = UDB.Map.getSelectedThings(); + +let node = UDB.Map.createThing(mpos, nodetype); +if (UDB.ScriptOptions.gridsnap > 0) + node.snapToGrid(); +node.tag = ntag; + +let i = 0; +let count = 0; +if(things.length > 0) +{ + things.forEach(n => + { + if (n.type == nodetype) + { + // For the new node, assign the path IDs to it, up to max arguments. + if (n.tag != 0 && count < 5) + { + node.args[count] = n.tag; + count++; + } + // For the selected nodes, check for an empty slot. + let pos = -1; + + for(i = 0; i < 5; i++) + { + if (n.args[i] != 0) + continue; + + pos = i; + break; + } + + + + // Check if the tag is already used first. + if (pos >= 0) + { + for (i = 0; i < 5; i++) + { + if (n.args[i] == ntag) + { + pos = -1; + break; + } + } + } + // Free slot, and unpresent. Set it in. + if (pos >= 0) + n.args[pos] = ntag; + } + }); +} + +UDB.Map.clearSelectedThings(); +node.selected = true;