-
Notifications
You must be signed in to change notification settings - Fork 381
Expand file tree
/
Copy pathaction_menu_macros.lua
More file actions
150 lines (130 loc) · 4.08 KB
/
action_menu_macros.lua
File metadata and controls
150 lines (130 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
local ui = require("lib.ui")
local action_menu_macros = {}
local function popup_recent_messages()
local entries = gapi.get_messages(12)
if #entries == 0 then
ui.popup(locale.gettext("No recent messages."))
return
end
local lines = { locale.gettext("Recent Messages"), "" }
for _, entry in ipairs(entries) do
table.insert(lines, string.format("[%s] %s", entry.time, entry.text))
end
ui.popup(table.concat(lines, "\n"))
end
local function popup_recent_lua_log()
local entries = gapi.get_lua_log(20)
if #entries == 0 then
ui.popup(locale.gettext("No recent Lua log entries."))
return
end
local lines = { locale.gettext("Recent Lua Log"), "" }
for _, entry in ipairs(entries) do
local source_prefix = entry.from_user and "> " or ""
table.insert(lines, string.format("[%s] %s%s", entry.level, source_prefix, entry.text))
end
ui.popup(table.concat(lines, "\n"))
end
local function announce_current_turn()
local turn_value = gapi.current_turn():to_turn()
gapi.add_msg(string.format(locale.gettext("Current turn: %d"), turn_value))
end
local function report_agent_context()
local avatar = gapi.get_avatar()
local map = gapi.get_map()
local pos = avatar:get_pos_ms()
local turn_value = gapi.current_turn():to_turn()
local details = string.format(
"[AI] turn=%d local_ms=(%d,%d,%d) outside=%s sheltered=%s",
turn_value,
pos.x,
pos.y,
pos.z,
tostring(map:is_outside(pos)),
tostring(map:is_sheltered(pos))
)
gapi.add_msg(details)
end
local function report_look_target()
local target = gapi.look_around()
if not target then
gapi.add_msg(locale.gettext("Look canceled."))
return
end
local target_abs = gapi.get_map():get_abs_ms(target)
gapi.add_msg(
string.format(
"[AI] look local_ms=(%d,%d,%d) abs_ms=(%d,%d,%d)",
target.x,
target.y,
target.z,
target_abs.x,
target_abs.y,
target_abs.z
)
)
end
local function report_adjacent_choice()
local target = gapi.choose_adjacent(locale.gettext("Choose adjacent tile for AI context"), true)
if not target then
gapi.add_msg(locale.gettext("Adjacent selection canceled."))
return
end
local target_abs = gapi.get_map():get_abs_ms(target)
gapi.add_msg(
string.format(
"[AI] adjacent local_ms=(%d,%d,%d) abs_ms=(%d,%d,%d)",
target.x,
target.y,
target.z,
target_abs.x,
target_abs.y,
target_abs.z
)
)
end
action_menu_macros.register_defaults = function()
gapi.register_action_menu_entry({
id = "bn_macro_recent_messages",
name = locale.gettext("Recent Messages"),
description = locale.gettext("Show the latest in-game messages in a popup."),
category = "info",
fn = popup_recent_messages,
})
gapi.register_action_menu_entry({
id = "bn_macro_recent_lua_log",
name = locale.gettext("Recent Lua Log"),
description = locale.gettext("Show the latest Lua console log entries in a popup."),
category = "info",
fn = popup_recent_lua_log,
})
gapi.register_action_menu_entry({
id = "bn_macro_current_turn",
name = locale.gettext("Current Turn"),
description = locale.gettext("Print the current absolute turn in the message log."),
category = "info",
fn = announce_current_turn,
})
gapi.register_action_menu_entry({
id = "bn_macro_agent_context",
name = locale.gettext("AI Context Packet"),
description = locale.gettext("Print turn, local coordinates, and shelter/outside state."),
category = "info",
fn = report_agent_context,
})
gapi.register_action_menu_entry({
id = "bn_macro_look_target",
name = locale.gettext("AI Look Target"),
description = locale.gettext("Pick a tile via look-around and print local/absolute coordinates."),
category = "info",
fn = report_look_target,
})
gapi.register_action_menu_entry({
id = "bn_macro_adjacent_target",
name = locale.gettext("AI Adjacent Target"),
description = locale.gettext("Pick an adjacent tile and print local/absolute coordinates."),
category = "info",
fn = report_adjacent_choice,
})
end
return action_menu_macros