Skip to content

Commit 36f5717

Browse files
committed
doom lua: help button
1 parent 72034a2 commit 36f5717

2 files changed

Lines changed: 142 additions & 109 deletions

File tree

Assets/Lua/Doom/doom.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ local function make_buttons()
606606
make_button(-110, h*8, "Hilite " ..(Hilite and " ON" or "OFF"), hilite_toggle)
607607
make_button(-110, h*9, "Follow " ..(Follow and " ON" or "OFF"), follow_toggle)
608608
make_button(-110, h*10,"Reset View", reset_view)
609+
make_button( -50, h*11,"Help", print_help)
609610

610611
if InterceptsInfo > InterceptsState.NONE then
611612
make_button(w+5, h*10, "Print Intercepts", function()

Assets/Lua/Doom/doom.misc.lua

Lines changed: 141 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -287,19 +287,19 @@ LastMouse = {
287287
-- map colors (0xAARRGGBB or "name")
288288
---@type table<string, map_pref>
289289
MapPrefs = {
290-
player = { color = 0xff60d0ff, radius_min_zoom = 0.00, text_min_zoom = 0.25, },
291-
enemy = { color = 0xffff0000, radius_min_zoom = 0.00, text_min_zoom = 0.25, },
292-
enemy_idle = { color = 0xffaa0000, radius_min_zoom = 0.00, text_min_zoom = 0.25, },
293-
missile = { color = 0xffff8000, radius_min_zoom = 0.00, text_min_zoom = 0.25, },
294-
shootable = { color = 0xffaaaaaa, radius_min_zoom = 0.00, text_min_zoom = 0.50, },
290+
player = { color = 0xff60d0ff, radius_min_zoom = 0.00, text_min_zoom = 0.50, },
291+
enemy = { color = 0xffff0000, radius_min_zoom = 0.00, text_min_zoom = 0.75, },
292+
enemy_idle = { color = 0xffaa0000, radius_min_zoom = 0.00, text_min_zoom = 1.00, },
293+
missile = { color = 0xffff8000, radius_min_zoom = 0.00, text_min_zoom = 1.00, },
294+
shootable = { color = 0xffaaaaaa, radius_min_zoom = 0.00, text_min_zoom = 1.00, },
295295
countitem = { color = 0xffffff00, radius_min_zoom = 0.00, text_min_zoom = 1.50, },
296296
item = { color = 0xff00ff00, radius_min_zoom = 0.00, text_min_zoom = 1.50, },
297-
solid = { color = 0xff505050, radius_min_zoom = 0.75, text_min_zoom = false,},
298297
highlight = { color = 0xffff00ff, radius_min_zoom = 0.00, text_min_zoom = 0.20, },
299298
grid = { color = 0xff808080, radius_min_zoom = 0.00, text_min_zoom = 0.00, },
299+
solid = { color = 0xff505050, radius_min_zoom = 0.75, text_min_zoom = false,},
300300
-- corpse = { color = 0xaaaaaaaa, radius_min_zoom = 0.00, text_min_zoom = 0.75, },
301301
-- misc = { color = 0xffa0a0a0, radius_min_zoom = 0.75, text_min_zoom = 1.00, },
302-
-- inert = { color = 0x80808080, radius_min_zoom = 0.75, text_min_zoom = false, },
302+
-- inert = { color = 0x80808080, radius_min_zoom = 0.75, text_min_zoom = false,},
303303
}
304304

305305
--#endregion
@@ -784,6 +784,107 @@ end
784784
--#endregion
785785

786786

787+
--#region MATH
788+
789+
--- Returns 2 passed numbers in order from smaller to bigger. Expands them further apart by 200, because this is meant to be used by `reset_view()` and to have a bit more space around visible objects.
790+
---@param smaller number
791+
---@param bigger number
792+
---@return number smaller
793+
---@return number bigger
794+
local function maybe_swap(smaller, bigger)
795+
if smaller > bigger then
796+
return bigger, smaller
797+
end
798+
return smaller - 100, bigger + 100
799+
end
800+
801+
---@param var number
802+
---@param minimum number
803+
---@param maximum number
804+
---@return boolean
805+
function in_range(var, minimum, maximum)
806+
return var >= minimum and var <= maximum
807+
end
808+
809+
---@param point vertex
810+
---@param v1 vertex
811+
---@param v2 vertex
812+
---@return boolean
813+
local function check_side(point, v1, v2)
814+
return ((v2.y - v1.y) / (v2.x - v1.x)) * (point.x - v1.x) + v1.y < point.y
815+
end
816+
817+
--- Distance to point projecton on infinite line
818+
---@param point vertex
819+
---@param v1 vertex
820+
---@param v2 vertex
821+
---@return number # Sign indicates which side the point is on
822+
function distance_to_line(point, v1, v2)
823+
local PAx = v1.x - point.x
824+
local PAy = v1.y - point.y
825+
local ABx = v2.x - v1.x
826+
local ABy = v2.y - v1.y
827+
local t = -PAx * ABx + -PAy * ABy
828+
t = t / (ABx * ABx + ABy * ABy)
829+
local PXx = PAx + t * ABx;
830+
local PXy = PAy + t * ABy;
831+
local dist = math.sqrt(PXx * PXx + PXy * PXy)
832+
833+
if check_side(point, v1, v2) then
834+
return -dist
835+
end
836+
837+
return dist
838+
end
839+
840+
local function dist_sq(p1, p2)
841+
return (p1.x - p2.x)^2 + (p1.y - p2.y)^2
842+
end
843+
844+
--- Distance to closest point of the segment
845+
---@param point vertex
846+
---@param v1 vertex
847+
---@param v2 vertex
848+
---@return number # Sign indicates which side the point is on
849+
function distance_to_segment(point, v1, v2)
850+
local ab_sq = dist_sq(v1, v2)
851+
if ab_sq == 0 then return math.sqrt(dist_sq(point, v1)) end
852+
local t =
853+
((point.x - v1.x) * (v2.x - v1.x) +
854+
(point.y - v1.y) * (v2.y - v1.y)) / ab_sq
855+
t = math.max(0, math.min(1, t))
856+
local closestPoint = {
857+
x = v1.x + t * (v2.x - v1.x),
858+
y = v1.y + t * (v2.y - v1.y)
859+
}
860+
local dist = math.sqrt(dist_sq(point, closestPoint))
861+
862+
if check_side(point, v1, v2) then
863+
return -dist
864+
end
865+
866+
return dist
867+
end
868+
869+
--- Rotate triangle around its center
870+
---@param t triangle
871+
---@param angle integer
872+
---@return triangle
873+
function rotate_triangle(t, angle)
874+
local rad = (angle * math.pi) / 180.0;
875+
local newt = { a = {}, b = {}, c = {}, center = t.center }
876+
newt.a.x = (t.a.x-t.center.x)*math.cos(rad)-(t.a.y-t.center.y)*math.sin(rad)+t.center.x
877+
newt.a.y = (t.a.x-t.center.x)*math.sin(rad)+(t.a.y-t.center.y)*math.cos(rad)+t.center.y
878+
newt.b.x = (t.b.x-t.center.x)*math.cos(rad)-(t.b.y-t.center.y)*math.sin(rad)+t.center.x
879+
newt.b.y = (t.b.x-t.center.x)*math.sin(rad)+(t.b.y-t.center.y)*math.cos(rad)+t.center.y
880+
newt.c.x = (t.c.x-t.center.x)*math.cos(rad)-(t.c.y-t.center.y)*math.sin(rad)+t.center.x
881+
newt.c.y = (t.c.x-t.center.x)*math.sin(rad)+(t.c.y-t.center.y)*math.cos(rad)+t.center.y
882+
return newt
883+
end
884+
885+
--#endregion
886+
887+
787888
--#region AUTOMAP
788889

789890
---@param divider integer
@@ -1014,107 +1115,6 @@ end
10141115
--#endregion
10151116

10161117

1017-
--#region MATH
1018-
1019-
--- Returns 2 passed numbers in order from smaller to bigger. Expands them further apart by 200, because this is meant to be used by `reset_view()` and to have a bit more space around visible objects.
1020-
---@param smaller number
1021-
---@param bigger number
1022-
---@return number smaller
1023-
---@return number bigger
1024-
local function maybe_swap(smaller, bigger)
1025-
if smaller > bigger then
1026-
return bigger, smaller
1027-
end
1028-
return smaller - 100, bigger + 100
1029-
end
1030-
1031-
---@param var number
1032-
---@param minimum number
1033-
---@param maximum number
1034-
---@return boolean
1035-
function in_range(var, minimum, maximum)
1036-
return var >= minimum and var <= maximum
1037-
end
1038-
1039-
---@param point vertex
1040-
---@param v1 vertex
1041-
---@param v2 vertex
1042-
---@return boolean
1043-
local function check_side(point, v1, v2)
1044-
return ((v2.y - v1.y) / (v2.x - v1.x)) * (point.x - v1.x) + v1.y < point.y
1045-
end
1046-
1047-
--- Distance to point projecton on infinite line
1048-
---@param point vertex
1049-
---@param v1 vertex
1050-
---@param v2 vertex
1051-
---@return number # Sign indicates which side the point is on
1052-
function distance_to_line(point, v1, v2)
1053-
local PAx = v1.x - point.x
1054-
local PAy = v1.y - point.y
1055-
local ABx = v2.x - v1.x
1056-
local ABy = v2.y - v1.y
1057-
local t = -PAx * ABx + -PAy * ABy
1058-
t = t / (ABx * ABx + ABy * ABy)
1059-
local PXx = PAx + t * ABx;
1060-
local PXy = PAy + t * ABy;
1061-
local dist = math.sqrt(PXx * PXx + PXy * PXy)
1062-
1063-
if check_side(point, v1, v2) then
1064-
return -dist
1065-
end
1066-
1067-
return dist
1068-
end
1069-
1070-
local function dist_sq(p1, p2)
1071-
return (p1.x - p2.x)^2 + (p1.y - p2.y)^2
1072-
end
1073-
1074-
--- Distance to closest point of the segment
1075-
---@param point vertex
1076-
---@param v1 vertex
1077-
---@param v2 vertex
1078-
---@return number # Sign indicates which side the point is on
1079-
function distance_to_segment(point, v1, v2)
1080-
local ab_sq = dist_sq(v1, v2)
1081-
if ab_sq == 0 then return math.sqrt(dist_sq(point, v1)) end
1082-
local t =
1083-
((point.x - v1.x) * (v2.x - v1.x) +
1084-
(point.y - v1.y) * (v2.y - v1.y)) / ab_sq
1085-
t = math.max(0, math.min(1, t))
1086-
local closestPoint = {
1087-
x = v1.x + t * (v2.x - v1.x),
1088-
y = v1.y + t * (v2.y - v1.y)
1089-
}
1090-
local dist = math.sqrt(dist_sq(point, closestPoint))
1091-
1092-
if check_side(point, v1, v2) then
1093-
return -dist
1094-
end
1095-
1096-
return dist
1097-
end
1098-
1099-
--- Rotate triangle around its center
1100-
---@param t triangle
1101-
---@param angle integer
1102-
---@return triangle
1103-
function rotate_triangle(t, angle)
1104-
local rad = (angle * math.pi) / 180.0;
1105-
local newt = { a = {}, b = {}, c = {}, center = t.center }
1106-
newt.a.x = (t.a.x-t.center.x)*math.cos(rad)-(t.a.y-t.center.y)*math.sin(rad)+t.center.x
1107-
newt.a.y = (t.a.x-t.center.x)*math.sin(rad)+(t.a.y-t.center.y)*math.cos(rad)+t.center.y
1108-
newt.b.x = (t.b.x-t.center.x)*math.cos(rad)-(t.b.y-t.center.y)*math.sin(rad)+t.center.x
1109-
newt.b.y = (t.b.x-t.center.x)*math.sin(rad)+(t.b.y-t.center.y)*math.cos(rad)+t.center.y
1110-
newt.c.x = (t.c.x-t.center.x)*math.cos(rad)-(t.c.y-t.center.y)*math.sin(rad)+t.center.x
1111-
newt.c.y = (t.c.x-t.center.x)*math.sin(rad)+(t.c.y-t.center.y)*math.cos(rad)+t.center.y
1112-
return newt
1113-
end
1114-
1115-
--#endregion
1116-
1117-
11181118
--#region IO
11191119

11201120
--- Deserializer
@@ -1464,6 +1464,34 @@ end
14641464

14651465
--#region MISC
14661466

1467+
function print_help()
1468+
local help = "Script for Doom engine games by feos and kalimag.\n\n"..
1469+
1470+
"Shows player info. If you have several players in-game you can hover on player info and scroll the mouse wheel to show info for different players.\n"..
1471+
"Shows current tic, in-game time, and RNG index along with value at that index.\n\n"..
1472+
1473+
"Shows Automap consisting of linedefs, sectors, and things (toggled via the 'Map' button).\n"..
1474+
"Shows blockmap grid (toggled via the 'Grid' button).\n"..
1475+
"The 'Reset View' button zooms and pans the automap to make all things visible.\n"..
1476+
"The 'Follow' button makes the camera stick to the player that is currently selected on the left panel.\n"..
1477+
"The 'Hilite' buttons enables highlight/selection mode where you can hover on sectors, linedefs, and things to see their info on the left, in corresponding colors.\n"..
1478+
"Use Mouse Wheel to zoom in and out, and mouse movement with the 'Space' key held down to pan.\n\n"..
1479+
1480+
"Buttons for adding things, lines, and sectors allow to track those entities. If more than one object of a given type is tracked, you can hoven on them and scroll through them with the mouse wheel. They can also be removed from the tracked list by hitting the red cross button that appears on hover. \n\n"..
1481+
1482+
"Tracked entity lists and Automap config are saved when the script is stopped or restarted or when you add or remove tracked entities. To manually edit the config file, disable the script, edit the 'doom.settings.lua' file if it exists, then start the script again. Editing it while the script is running will overwrite your edits later. Config also stored Angle type which has no other way to change it.\n\n"..
1483+
1484+
"You can log which thing has used or crossed linedefs, with options being None, Player, and All\n\n"..
1485+
1486+
"You can log various info every time a P_Random() call happens with a class that changes the RNG value. Log prints tic count when the call happened, which call it is per that tic, the RNG index, the value at that index, and the call stack (while file and line called P_Random() within which function).\n\n"..
1487+
1488+
"You can display intercepts on the Automap: tracelines and blockmap blocks where intercepts happen. Red color means an intercept happened on this tic, then the color fades to grey.\n\n"..
1489+
1490+
"And the most complicated feature is intercept logging. It will inform you when the intercept count exceeded a user-defined limit, which is 128 by default but can be changed in config (the 'InterceptLimit' value). If the intercept count exceeded exactly 128 (regardless of user defined limit), a button will appear that will print info on all the intercepts that caused the overflow, as well as info on all the vanilla addresses they corrupted. Boom fixed intercept overflow, so in Boom complevel this feature is disabled."
1491+
1492+
print(help)
1493+
end
1494+
14671495
--- Doom uses left mouse clock for firing and if we're running unpaused we don't want clicking script buttons to trigger fire. Currently only blocks first player fire. TODO: block for all players
14681496
function suppress_click_input()
14691497
if MAP_CLICK_BLOCK and MAP_CLICK_BLOCK ~= "" then
@@ -1595,6 +1623,8 @@ end
15951623
--#endregion
15961624

15971625

1626+
--#region LOOKUPS
1627+
15981628
-- Additional types that are not identifiable by flags alone
15991629
HighlightTypes = to_lookup({
16001630

@@ -1655,4 +1685,6 @@ InertTypes = to_lookup({
16551685
MobjType.HEXEN_SGSHARD6, MobjType.HEXEN_SGSHARD7, MobjType.HEXEN_SGSHARD8,
16561686
MobjType.HEXEN_SGSHARD9,
16571687
MobjType.HEXEN_WRAITHFX3,
1658-
})
1688+
})
1689+
1690+
--#endregion

0 commit comments

Comments
 (0)