-
Notifications
You must be signed in to change notification settings - Fork 0
/
pathing.tf
311 lines (286 loc) · 9.38 KB
/
pathing.tf
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
;;
;; tf-mapper/pathing.tf
;;
;; Map functions supporting path-finding between multiple rooms.
;;
/loaded __tf_mapper_pathing__
;
; Find a path toward a room and take the first step.
;
; Currently, only a roomId is accepted.
;
; /step <room>
;
;/def step = \
; /let _target=%{1}%;\
; /if (_target == util_getVar("map.currentRoom.id") \
; /echo You're already there!%;\
; /return%;\
; /endif%;\
; /let _step=$[map_step(map_path(_target))]%;\
; /echo Stepping toward %{_target} : %_step%;\
; /echo /send -h %_step
;
; Find a path toward a room and spam the entire path.
;
; Current, only a roomId is accepted.
;
; /go <room>
;
;/def go = \
; /let _target=%{1}%;\
; /if (_target == util_getVar("map.currentRoom.id") \
; /echo You're already there!%;\
; /return%;\
; /endif%;\
; /let pathInfo=$(/pathTo %{_target})%;\
; /if (regmatch("^(\d+) (\d+) (\d+) (.+)$", pathInfo)) \
; /map_execute_path %{P4}%;\
; /else \
; /echo Could not find path to %{_target}.%;\
; /endif
;
; Given a path, spam each component immediately.
;
/def map_executePath = \
/let _bit=%;\
/let _rest=%{*}%;\
/while (_rest !~ "") \
/let _semiIdx=%;\
/test _semiIdx := strstr(_rest, ";")%;\
/if ( _semiIdx == -1) \
/test _bit := _rest%;\
/test _rest := ""%;\
/else \
/test _bit := substr(_rest, 0, _semiIdx)%;\
/test _rest := substr(_rest, _semiIdx + 1)%;\
/endif%;\
/if (_bit !~ "") \
/send -h %{_bit}%;\
/endif%;\
/done
;
; Run the pathing algorithm and return just the path component.
;
/def map_path = \
/let _pathInfo=$(/map_findPath %{*})%;\
/if (regmatch("^(\d+) (\d+) (\d+) (.+)$", _pathInfo)) \
/result {P4}%;\
/else \
/result 0%;\
/endif
;
; Execute the Lua pathing algorithm.
;
/def map_findPath = \
/if ({#} > 1) \
/let _fromId=%{1}%;\
/let _toOptions=%{-1}%;\
/elseif ({#} == 0) \
/let _fromId=$[util_getVar("map.currentRoom.id")]%;\
/if (_fromId =~ "") \
/echo -aCyellow Cannot execute path algorithm. We don't know where we are.%;\
/result -1%;\
/endif%;\
/let _toOptions=$[getVar("map.path.target.roomId")]%;\
/elseif ({#} == 1) \
/let _fromId=$[util_getVar("map.currentRoom.id")]%;\
/if (_fromId =~ "") \
/echo -aCyellow Cannot execute path algorithm. We don't know where we are.%;\
/result -1%;\
/endif%;\
/let _toOptions=%{*}%;\
/endif%;\
/let _pathScriptLoc=%{TF_NPM_MODULES_ROOT}/tf-mapper/lua/map_path.lua%;\
/let _mapLoc=%{map_mapFile}%;\
/let _r=$(/quote -S -decho !lua %{_pathScriptLoc} %{_mapLoc} %{_fromId} %{_toOptions})%;\
/result _r
;/def map_step = \
; /let idx=%;\
; /let path=%{1}%;\
; /test idx := 0%;\
; /if (strlen(path) == 0) \
; /echo No path?%;\
; /return%;\
; /else \
; /let dir=%;\
; /test dir := strchr(path, "newsud")%;\
; /if (dir != -1) \
; /return substr(path, dir, 1)%;\
; /endif%;\
; /endif
/def map_createPath = \
/let _pathName=%{1}%;\
/let _pathVar=$[map_pathVarName(_pathName)]%;\
/let _pathProgressVar=$[map_pathProgressVarName(_pathName)]%;\
/let _oldPath=$[map_getPath(_pathName)]%;\
/let _newPath=%{-1}%;\
/if (_oldPath !~ _newPath) \
/test util_setVar(_pathVar, _newPath)%;\
/test util_setVar(_pathProgressVar, _newPath)%;\
/else \
/echo Path %{1} unchanged.%;\
/endif
/def map_stepPath = \
/let _pathName=%{1}%;\
/let _path=$[map_getPath(_pathName)]%;\
/let _pathProgress=$[map_getPathProgress(_pathName)]%;\
; /echo Stepping through %{_pathName} : %{_path}%;\
; /echo Progress is <%{_pathProgress}>%;\
/let _currentId=$[util_getVar("map.currentRoom.id")]%;\
/if (_currentId =~ "") \
/echo -aCyellow Cannot execute step algorithm. We don't know where we are.%;\
/result -1%;\
/endif%;\
/let _next=$(/car %{_pathProgress})%;\
/if (_next =~ _currentId) \
/test _next := map_shiftPathProgress(_pathName)%;\
/endif%;\
/let _path=$[map_path(_next)]%;\
/let _firstMove=$[map_firstMoveOfPath(_path)]%;\
/if (_firstMove !~ "0") \
/test map_executePath(_firstMove)%;\
/else \
/echo -aCred Error calculating first move in path.%;\
/endif
/def map_nextPath = \
/let _pathName=%{1}%;\
/let _path=$[map_getPath(_pathName)]%;\
/let _pathProgress=$[map_getPathProgress(_pathName)]%;\
; /echo Stepping through %{_pathName} : %{_path}%;\
; /echo Progress is <%{_pathProgress}>%;\
/let _currentId=$[util_getVar("map.currentRoom.id")]%;\
/if (_currentId =~ "") \
/echo -aCyellow Cannot execute step algorithm. We don't know where we are.%;\
/result -1%;\
/endif%;\
/let _next=$(/car %{_pathProgress})%;\
/if (_next =~ _currentId) \
/test _next := map_shiftPathProgress(_pathName, 0)%;\
/endif%;\
/let _path=$[map_path(_next)]%;\
; /let _firstMove=$[map_firstMoveOfPath(_path)]%;\
/result _path
; /if (_path !~ "0") \
; /test map_executePath(_path)%;\
; /else \
; /echo -aCred Error calculating first move in path.%;\
; /endif
/def map_path_goNext = \
/let _pathName=%{1}%;\
/let _path=$[map_nextPath(_pathName)]%;\
/test map_executePath(_path)
/def map_pathVarName = \
/let _path=%{1}%;\
/let _varName=map.path.$[textencode(_path)]%;\
/result _varName
/def map_pathProgressVarName = \
/let _path=%{1}%;\
/let _varName=map.path.progress.$[textencode(_path)]%;\
/result _varName
/def map_getPath = \
/let _pathName=%{1}%;\
/let _pathVar=$[map_pathVarName(_pathName)]%;\
/result util_getVar(_pathVar)
/def map_resetPath = \
/let _pathName=%{1}%;\
/let _progressName=$[map_pathProgressVarName(_pathName)]%;\
/let _path=$[map_getPath(_pathName)]%;\
/test util_setVar(_progressName, _path)
/def map_pushPath = \
/let _pathName=%{1}%;\
/let _roomId=%{2}%;\
/let _varName=$[map_pathProgressVarName(_pathName)]%;\
/let _pathProgress=$[map_getPathProgress(_pathName)]%;\
/let _first=$(/car %{_pathProgress})%;\
/if (_first !~ _roomId) \
/test util_setVar(_varName, strcat(_roomId, " ", _pathProgress))%;\
/map_getPathProgress %{_varName}%;\
/endif
/def map_getPathProgress = \
/let _pathName=%{1}%;\
/let _pathProgressVar=$[map_pathProgressVarName(_pathName)]%;\
/result util_getVar(_pathProgressVar)
/def map_shiftPathProgress = \
/let _pathName=%{1}%;\
/let _circular=1%;\
/if ({#} & {2}) \
/test _circular := {2}%;\
/endif%;\
/let _pathProgress=$[map_getPathProgress(_pathName)]%;\
/if (_pathProgress =~ "") \
/test _pathProgress := map_getPath(_pathName)%;\
/endif%;\
/let _rest=$(/cdr %{_pathProgress})%;\
/if (_rest =~ "") \
/if (_circular) \
/let _rest=$[map_getPath(_pathName)]%;\
/else \
/echo End of path. Please select a new one.%;\
/endif%;\
/endif%;\
/test util_setVar(map_pathProgressVarName(_pathName), _rest)%;\
/let _pathProgress=$[map_getPathProgress(_pathName)]%;\
/let _next=$(/car %{_rest})%;\
/result _next
/def map_firstMoveOfPath = \
/let _path=%{*}%;\
/let _moveRegexp=$["^(\d+)?([newsud])"]%;\
/let _next=%;\
/while (!regmatch(_moveRegexp, _path) & strlen(_path) > 0) \
/let _nextSemi=$[strstr(_path, ";", 1)]%;\
/if (_nextSemi == -1) \
/test _next := strcat(_next, _path)%;\
/test _path := ""%;\
/else \
/test _next := strcat(_next, substr(_path, 0, _nextSemi + 1))%;\
/test _path := substr(_path, _nextSemi + 1)%;\
/endif%;\
/done%;\
/if (strlen(_path) > 0) \
/test _next := strcat(_next, {P2})%;\
/endif%;\
/result _next
/alias go \
/setVar map.path.retryCount 3 %;\
/map_go %{*}
/def map_go = \
/if ({#} > 1) \
/setVar map.path.target.roomId %{2}%;\
/elseif ({#} == 1) \
/setVar map.path.target.roomId %{1}%;\
/endif%;\
/let _mapPath=$(/map_path %{*})%;\
/return map_executePath(_mapPath)
/alias go_and \
/setVar map.path.retryCount 3 %;\
/map_go_and %{*}
/def map_go_and = \
/setVar map.path.completeHandler %{1}%;\
/util_addListener map_path_complete map_path_complete_handler%;\
/map_go %{-1}
/def map_path_complete_handler = \
/util_removeListener map_path_complete map_path_complete_handler%;\
/$[getVar("map.path.completeHandler")] $[getVar("map.path.target.roomId")]
/alias mark /map_markRoom %{*}
/def map_markRoom = \
/let _current=$[util_getVar("map.currentRoom.id")]%;\
/let _marked=$[util_getVar("map.markRoom.id")]%;\
/if (_current =~ "" | strstr(_current, " ") != -1) \
/echo -aCyellow Cannot mark current room. I'm not sure where we are.%;\
/elseif (_current !~ _marked) \
/test util_setVar("map.markRoom.id", _current)%;\
/echo -aCyellow Marking current room (%{_current}).%;\
/endif
/alias gmark /map_goToMarkedRoom %{*}
/def map_goToMarkedRoom = \
/let _mark=$[util_getVar("map.markRoom.id")]%;\
/if (_mark =~ "") \
/echo -aCyellow No room marked. Cancelling.%;\
/else \
/if ({#} > 0) \
/map_go %{1} %{_mark}%;\
/else \
/map_go %{_mark}%;\
/endif%;\
/endif