xiaoyao.tin 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. #nop vim: set filetype=tt:;
  2. /*
  3. 本文件属于 PaoTin++ 的一部分
  4. ===========
  5. PaoTin++ © 2020~2023 的所有版权均由担子炮(dzp <danzipao@gmail.com>) 享有并保留一切法律权利
  6. 你可以在遵照 GPLv3 协议的基础之上使用、修改及重新分发本程序。
  7. ===========
  8. */
  9. VAR {逍遥行地图数据} map.xiaoyao.map {};
  10. VAR {逍遥行房间数据} map.xiaoyao.room {};
  11. load-module basic/busy;
  12. event.HandleOnce {map/init} {map/xiaoyao} {map} {xiaoyao.Init};
  13. VAR {逍遥行正在赶路} {xiaoyao.under-way} {0};
  14. #alias {xiaoyao.Init} {
  15. event.Handle {map/GotRoomInfo} {xiaoyao.try-locate} {map/xiaoyao} {xiaoyao.try-locate};
  16. storage.Load {map-xiaoyao} {map.xiaoyao.map;map.xiaoyao.room};
  17. };
  18. #alias {xiaoyao.checkMap} {
  19. #local node {};
  20. #local areaMap {};
  21. #foreach {*map.xiaoyao.map[]} {node} {
  22. #local next {};
  23. #if { &map.xiaoyao.map[$node][] == 1 && "$map.xiaoyao.map[$node][DOCK]" != "" } {
  24. warnLog 这是个纯粹的码头 => $node;
  25. };
  26. #foreach {*map.xiaoyao.map[$node][]} {next} {
  27. #regex {$node} {%*(%*的%*)} {
  28. #format {areaMap[&2][$node]} {true};
  29. };
  30. #local link {$map.xiaoyao.map[$node][$next]};
  31. #if { "$next" == "DOCK" || "$link" == "TODO" } {
  32. errLog $node => $next 尚未联通。;
  33. };
  34. };
  35. };
  36. #local maxNodeNum {0};
  37. #local maxNodeNumArea {};
  38. #local area {};
  39. #foreach {*areaMap[]} {area} {
  40. okLog $area(&areaMap[$area][]): @slist.Join{{@slist.FromList{@list.FromSlist{*areaMap[$area][]}}};、};
  41. #if { &areaMap[$area][] > $maxNodeNum } {
  42. #local maxNodeNum {&areaMap[$area][]};
  43. #local maxNodeNumArea {$area};
  44. };
  45. };
  46. okLog 地图连接性检查正常,一共包含 &map.xiaoyao.map[] 个节点,&areaMap[] 个区域,节点最多的区域是「$maxNodeNumArea」,共有 $maxNodeNum 个节点。;
  47. };
  48. #alias {xiaoyao.SimpleMap} {
  49. #local bigArea {};
  50. #local areaMap {};
  51. #local area {};
  52. #local node {};
  53. #foreach {*map.xiaoyao.map[]} {node} {
  54. #regex {$node} {%*(%*的%*)} {
  55. #format {area} {%s} {&2};
  56. };
  57. #local bigArea {@map.AreaColor{$area}};
  58. #list {areaMap[$bigArea][$area]} add {$node};
  59. };
  60. #local screenWidth {};
  61. #screen get cols screenWidth;
  62. #local lines {};
  63. #local line {};
  64. #local color {};
  65. #local lineWidth {0};
  66. #local buttons {};
  67. #local bigAreaCount {0};
  68. #local areaCount {0};
  69. #local nodeCount {0};
  70. #loop {1} {&areaMap[]} {bigArea} {
  71. #math bigAreaCount {$bigAreaCount + 1};
  72. #local bgColor *areaMap[+$bigArea];
  73. #local fgColor {0};
  74. #loop {1} {&areaMap[+$bigArea][]} {area} {
  75. #math areaCount {$areaCount + 1};
  76. #math fgColor {($fgColor + 1) % 2};
  77. #local index {$bgColor};
  78. #replace index {%*4%+1d%*} {&2};
  79. #if { "$bgColor" == "46" } {
  80. #local color {\e[${bgColor};@math.Eval{30 + $fgColor * 4}m};
  81. };
  82. #elseif { $index == 3 } {
  83. #local color {\e[${bgColor};@math.Eval{30 + $fgColor * 4}m};
  84. };
  85. #else {
  86. #local color {\e[${bgColor};@math.Eval{37 - $fgColor * 4}m};
  87. };
  88. #cat line {$color};
  89. #loop {1} {&areaMap[+$bigArea][+$area][]} {node} {
  90. #local node {$areaMap[+$bigArea][+$area][+$node]};
  91. #local city {$node};
  92. #replace city {%S(%S)} {&1};
  93. #local width {@math.Eval{ ( @math.Int{@str.Width{$city} * 1.0 / 4 + 0.4} + 1 ) * 4 }};
  94. #if { $lineWidth + $width > $screenWidth } {
  95. #if { $screenWidth > $lineWidth } {
  96. #cat line {@str.Space{@math.Eval{$screenWidth - $lineWidth}}};
  97. };
  98. #local lineWidth {0};
  99. #list lines add {{
  100. {text}{$line}
  101. {buttons}{$buttons}
  102. }};
  103. #local line {$color};
  104. #local buttons {};
  105. };
  106. #cat line {@str.AlignLeft{{$city};$width}};
  107. #list buttons add {{
  108. {begin}{@math.Eval{$lineWidth + 1}}
  109. {end}{@math.Eval{$lineWidth + $width}}
  110. {node}{$node}
  111. }};
  112. #local lineWidth {@math.Eval{ $lineWidth + $width }};
  113. };
  114. };
  115. };
  116. #list lines add {{
  117. {text}{$line}
  118. {buttons}{$buttons}
  119. }};
  120. #class xiaoyao.Map kill;
  121. #class xiaoyao.Map open;
  122. #local lineNo {1};
  123. #loop {1} {&lines[]} {lineNo} {
  124. #echo {%s} {$lines[$lineNo][text]};
  125. #local button {};
  126. #foreach {$lines[$lineNo][buttons][]} {button} {
  127. #local row {@math.Eval{$lineNo - 4 - &lines[] - $prompt-bot-max-line}};
  128. #line sub var #button {$row;$button[begin];$row;$button[end]} {
  129. #class xiaoyao.Map kill;
  130. #buffer lock off;
  131. #buffer end;
  132. xiaoyao.Goto $button[node];
  133. };
  134. };
  135. };
  136. #line oneshot #event {RECEIVED INPUT CHARACTER} {
  137. okLog 你略作观察后收起了地图继续赶路。;
  138. #class xiaoyao.Map kill;
  139. #buffer end;
  140. };
  141. #class xiaoyao.Map close;
  142. okLog 共包含 &map.xiaoyao.map[] 个节点,$bigAreaCount 个大区,$areaCount 个区域。;
  143. #buffer lock on;
  144. };
  145. #alias {xiaoyao.Map} {
  146. #local retry {@defaultNum{%1;0}};
  147. #local args {%2};
  148. #if { "$args" != "" } {
  149. xtt.Send {map $args};
  150. #return;
  151. };
  152. #local retry {@defaultNum{%1;0}};
  153. #if { $retry == 0 &&
  154. ( "$gMapRoom[node]$gMapRoom[dock]" == ""
  155. || &gMapRoom[area][] == 0
  156. || "@map.GetArea{}" == "" )
  157. } {
  158. #line sub {func;var} event.HandleOnce {map/GotArea} {xiaoyao/Map} {map} {xiaoyao.Map {@math.Eval{$retry + 1}} $args};
  159. map.GetArea;
  160. #return;
  161. };
  162. #local here {@xiaoyao.Locate{}};
  163. #if { "$here" == "" } {
  164. xtt.Send {map};
  165. #return;
  166. };
  167. #class xiaoyao.Map open;
  168. #alias {xiaoyao.Map.open} {
  169. #class xiaoyao.Map open;
  170. #var xiaoyao.Map.lines {0};
  171. #action {^%*{|ID=map}$} {#math xiaoyao.Map.lines {$xiaoyao.Map.lines + 1}} {2.5};
  172. #sub {~{*UTF8};4;44m{\p{Han}+}} {;4;44m@mslp.Exec{xiaoyao.Map.Goto %%%1;%%%1}};
  173. #action {担子炮修订时间} {xiaoyao.Map.close} {2.0};
  174. #class xiaoyao.Map close;
  175. #if { @existsFile{var/data/map.txt} } {
  176. #scan txt var/data/map.txt;
  177. };
  178. #elseif { @existsFile{mud/$gCurrentMUDLIB/data/map.txt} } {
  179. #scan txt mud/$gCurrentMUDLIB/data/map.txt;
  180. };
  181. #elseif { @existsFile{data/map.txt} } {
  182. #scan txt data/map.txt;
  183. };
  184. #else {
  185. errLog 缺少 data/map.txt 文件。;
  186. xtt.Send {map};
  187. };
  188. };
  189. #alias {xiaoyao.Map.close} {
  190. #local lines {};
  191. #screen get rows lines;
  192. #if { $prompt-bot-max-line > 0 } {
  193. #math lines {$lines - $prompt-bot-max-line - 1};
  194. };
  195. #if { $prompt-top-max-line > 0 } {
  196. #math lines {$lines - $prompt-top-max-line - 1};
  197. };
  198. #buffer end;
  199. keyboard.LessMode;
  200. #math lines {$xiaoyao.Map.lines - $lines + 2};
  201. #if { $lines > 0 } {
  202. #buffer up $lines;
  203. };
  204. #class xiaoyao.Map kill;
  205. };
  206. okLog <560>你展开地图,发现不知为什么许多地方似乎被人涂成了蓝色。<099>;
  207. xiaoyao.Map.open;
  208. #class xiaoyao.Map close;
  209. };
  210. #alias {xiaoyao.Map.Goto} {
  211. #local node {%1};
  212. keyboard.NormalMode;
  213. #if { &map.xiaoyao.map[$node(%*)] == 1 } {
  214. #local node *map.xiaoyao.map[$node(%*)];
  215. };
  216. xiaoyao.Goto $node;
  217. };
  218. #alias {map} {
  219. #local width {0};
  220. #screen get cols width;
  221. #if { $width > 132 } {
  222. xiaoyao.Map 0 {%0};
  223. };
  224. #else {
  225. xiaoyao.SimpleMap;
  226. };
  227. };
  228. ///=== {
  229. // ## xiaoyao.Goto <目的节点>
  230. // 逍遥行快速行走,可以从一个城市移动到另一个城市。支持自动坐船、自动过河。
  231. //
  232. // 逍遥行底层采用的是系统 walk 命令,这要求你必须站在逍遥行节点才能使用本别名。
  233. // 但是本别名<169>可以自动连续 walk<299>,达到长途行走的目的。
  234. //
  235. // 为避免重复,完整的逍遥行节点名称采用「<169>节点名(区域的房间名)<299>」格式表达。
  236. // 目的地暂时仅支持中文,但允许模糊查询。举例来说,假如你想前往「全真派(全真教的宫门)」,
  237. // 那么你输入「全真派」、「全真教」、「宫门」、「全真」、甚至「教的宫」都是可以的。
  238. //
  239. // 本别名存在三个变体,你可以用 HELP 进一步了解:
  240. // - xiaoyao.GotoThen: 允许调用者在行走完成之后,执行一段代码。
  241. // - xiaoyao.GotoEmit: 允许调用者在行走完成之后,发射一个事件。
  242. // - xy: 专供命令行使用并为此做过特别优化的别名,不要在脚本中使用它。
  243. //
  244. // 关于 walk 命令的细节可以参考 help walk。
  245. // };
  246. #alias {xiaoyao.Goto} {
  247. xiaoyao.goto {%1} {%2} {xiaoyao.Goto};
  248. };
  249. ///=== {
  250. // ## xy <目的地> [<回调代码>]
  251. // 通过逍遥行前往目的地。如果指定了回调代码,那么到达目的地之后,会执行它。
  252. // 参见 HELP xiaoyao.Goto。
  253. // };
  254. #alias {xy} {
  255. #local target {%1};
  256. #local callback {%22};
  257. #info arguments save;
  258. #local count &info[ARGUMENTS][];
  259. #unvar info[ARGUMENTS];
  260. #if { $count == 1 } {
  261. xtt.Usage xiaoyao.Goto {<169>这里是 PaoTin++ 逍遥行};
  262. #return;
  263. };
  264. #if { $count > 3 } {
  265. #local callback {%20};
  266. #local old {%20};
  267. #replace {callback} {^$target } {};
  268. #if { "$callback" === "$old" } {
  269. #replace {callback} {^\\x7B$target\\x7D } {};
  270. };
  271. };
  272. #line sub {escapes;var} xiaoyao.GotoThen {$target} {$callback};
  273. };
  274. ///=== {
  275. // ## xiaoyao.GotoThen <目的地> [<回调代码>]
  276. // 通过逍遥行前往目的地。如果指定了回调代码,那么到达目的地之后,会执行它。
  277. // 参见 HELP xiaoyao.Goto。
  278. // };
  279. #alias {xiaoyao.GotoThen} {
  280. #local target {%1};
  281. #local callback {%22};
  282. #if { "$callback" == "" } {
  283. #local callback {#0};
  284. };
  285. #local hook {map/xiaoyao/@uuid{}};
  286. #line sub {escapes;var} event.HandleOnce {map/walk/continue} {$hook} {map/xiaoyao} {$callback};
  287. xiaoyao.goto {$target} {$hook} {xiaoyao.GotoThen};
  288. };
  289. ///=== {
  290. // ## xiaoyao.GotoEmit <目的地> [<回调钩子名称>]
  291. // 通过逍遥行前往目的地。
  292. // 如果你事先注册了指定名称的回调钩子在事件 map/walk/continue 上,那么到达目的地之后,会唤醒它。
  293. // 参见 HELP xiaoyao.Goto。
  294. // };
  295. #alias {xiaoyao.GotoEmit} {
  296. #local target {%1};
  297. #local hook {%2};
  298. xiaoyao.goto {$target} {$hook} {xiaoyao.GotoEmit};
  299. };
  300. #alias {xiaoyao.goto} {
  301. #local target {%1};
  302. #local hook {@default{%2;xiaoyao/goto/end}};
  303. #local name {@default{%3;xiaoyao.GotoEmit}};
  304. #local retry {@defaultNum{%4;0}};
  305. #if { "$target" == "" } {
  306. xtt.Usage $name {<169>这里是 PaoTin++ 逍遥行};
  307. xiaoyao.goto.cancel {$hook};
  308. #return;
  309. };
  310. #if { &map.xiaoyao.map[] == 0 } {
  311. errLog 加载逍遥行节点数据文件失败。;
  312. okLog 请确保逍遥行数据文件 var/data/map-xiaoyao.tin 或 data/map-xiaoyao.tin 正确无误。;
  313. xiaoyao.goto.cancel {$hook};
  314. #return;
  315. };
  316. #if { $retry > 1 } {
  317. errLog 请先前往逍遥行节点。所有的码头、walk 节点均为逍遥行节点。;
  318. xiaoyao.goto.cancel {$hook};
  319. #return;
  320. };
  321. #if { "$gMapRoom[node]$gMapRoom[dock]" == ""
  322. || &gMapRoom[area][] == 0
  323. || "@map.GetArea{}" == ""
  324. } {
  325. #line sub {func;var} event.HandleOnce map/GotArea {xiaoyao/goto} {xiaoyao} {xiaoyao.goto {$target} {$hook} {@math.Eval{$retry + 1}}};
  326. map.GetArea;
  327. #return;
  328. };
  329. #local here {@xiaoyao.Locate{}};
  330. #if { "$here" == "" } {
  331. errLog 请先前往逍遥行节点。所有的码头、walk 节点均为逍遥行节点。;
  332. xiaoyao.goto.cancel {$hook};
  333. #return;
  334. };
  335. #if { "$here" == "%*$target%*" } {
  336. #if { "$hook" != "" } {
  337. okLog 你已经来到了 $here;
  338. event.DelayEmit map/walk/continue {$hook};
  339. };
  340. #return;
  341. };
  342. infoLog 计算从<129>$here<299>到<139>$target<299>的路径。;
  343. #local target {@xiaoyao.findPath{$here;"NODE" == "%*$target%*"}};
  344. #if { "$target" == "" } {
  345. errLog 找不到路径。;
  346. xiaoyao.goto.cancel {$hook};
  347. #return;
  348. };
  349. #if { "$target[path]" == "" } {
  350. errLog 找不到路径,似乎安装出错了,请联系开发者。;
  351. xiaoyao.goto.cancel {$hook};
  352. #return;
  353. };
  354. okLog 计算结果: {$target[path]};
  355. #replace {target[route]} {(%*)} {};
  356. okLog 途经节点: $target[route];
  357. prompt.Set {{walk}{<139>正在前往 <129>$target[room]<139>...<299>}};
  358. #line sub var event.HandleOnce map/walk/continue {xiaoyao/goto} {map/xiaoyao} {xiaoyao.walk-end $hook};
  359. #var xiaoyao.under-way {1};
  360. map.WalkNodes {$target[path]} {xiaoyao/goto};
  361. };
  362. #alias {xiaoyao.goto.cancel} {
  363. #local hook {%1};
  364. event.UnHandle {map/walk/continue} {$hook} {map/xiaoyao};
  365. };
  366. #alias {xiaoyao.walk-end} {
  367. #local hook {%1};
  368. okLog 行走完成。;
  369. #if { "$hook" != "" } {
  370. event.DelayEmit map/walk/continue {$hook};
  371. };
  372. #var xiaoyao.under-way {0};
  373. #nop 配合 try-locate 进行定位。;
  374. look;
  375. };
  376. #alias {xiaoyao.try-locate} {
  377. #nop 移动中,位置随时会变。;
  378. #if { ! @ga.AllDone{} || $xiaoyao.under-way } {
  379. #return;
  380. };
  381. #nop 探索中,数据内容不全。 ;
  382. #if { @isTrue{$xiaoyao.explore} } {
  383. #return;
  384. };
  385. #nop 光看房间名就就不像是节点。;
  386. #local nodes {$map.xiaoyao.room[$gMapRoom[name]]};
  387. #if { "$nodes" == "" } {
  388. #if { &map.xiaoyao.map[] > 0 } {
  389. prompt.Set {{walk}{<139>逍遥行已启动,可识别 &map.xiaoyao.map[] 个节点,目前工作正常。<299>}};
  390. };
  391. #return;
  392. };
  393. #nop 空闲,没有移动,可能是节点,那么就具体调查一下。;
  394. event.HandleOnce {map/GotArea} {xiaoyao.locate} {map/xiaoyao} {xiaoyao.locate};
  395. map.GetArea;
  396. };
  397. #alias {xiaoyao.locate} {
  398. #local here {@xiaoyao.Locate{}};
  399. #if { "$here" == "" } {
  400. #return;
  401. };
  402. okLog 这里是 $here;
  403. #local links {@table.Keys{map.xiaoyao.map[$here];%*}};
  404. #local buttons {};
  405. #local link {};
  406. #foreach {$links} {link} {
  407. #local short {@str.Replace{$link;{%*(%*的%*)};{&1}}};
  408. #local button {【@mslp.Exec{{xiaoyao.Goto $link};<139>$short<299>}】};
  409. #cat buttons {$button};
  410. };
  411. prompt.Set {{walk}{$buttons}};
  412. };
  413. #func {xiaoyao.Locate} {
  414. #local room {$gMapRoom[name]};
  415. #local area {@map.GetArea{}};
  416. #local node {$gMapRoom[node]};
  417. #local dock {$gMapRoom[dock]};
  418. #local pattern {$area的$room};
  419. #nop 光看名字就长得不像,那肯定不是了。;
  420. #local nodes {$map.xiaoyao.room[$room]};
  421. #if { "$nodes" == "" } {
  422. #return {};
  423. };
  424. #if { "$area" == "" } {
  425. #local pattern {%*的$room};
  426. };
  427. #if { @slist.Contains{{$gMapRoom[lookable]};{<node>}} } {
  428. #nop 节点以 walk 节点名称标记;
  429. #local pattern {@default{$node;%*}($pattern)};
  430. };
  431. #elseif { "$dock" != "" } {
  432. #nop 没有节点的码头以区域名称加码头标记。;
  433. #local pattern {@default{$area;%*}码头($pattern)};
  434. };
  435. #elseif { "$area" != "" && "@sset.Intersection{{$gMapRoom[mark]};{★;☆}}" != "" } {
  436. #nop 既不是节点,又不是码头,那么如果有地域信息大概也是可以的。;
  437. #local pattern {%*($pattern)};
  438. };
  439. #else {
  440. #return {};
  441. };
  442. #if { "$pattern" != "%*\%*%*" } {
  443. #return {$pattern};
  444. };
  445. #nop 否则参考数据库来确定,当且仅当数据库中只有一条匹配记录时,才能断定;
  446. #if { &map.xiaoyao.map[$pattern][] != 1 } {
  447. #return {};
  448. };
  449. #local location @table.Keys{map.xiaoyao.map;{$pattern}};
  450. #nop 如果房间名和节点名已经获得,那么可以据此更新地区名;
  451. #if { "$area" == "" && "$node" != "" } {
  452. #local area {$location};
  453. #replace area {%*(%*的%*)} {&2};
  454. #var gMapRoom[area][RESOLVED] {$area};
  455. event.Emit map/GotArea;
  456. };
  457. #return {$location};
  458. };
  459. #nop 计算路径;
  460. #func {xiaoyao.findPath} {
  461. #local src {%1};
  462. #local cond {%2};
  463. #local dst {};
  464. #replace cond {NODE} {\$node};
  465. #replace cond {LINK} {\$map.xiaoyao.map[\$node]};
  466. #local routeMap {
  467. {$src}{START}
  468. };
  469. #local checkList {{1}{$src}};
  470. #while {1} {
  471. #if { &checkList[] == 0 || ( "$dst" != "" && "$routeMap[$dst]" != "" ) } {
  472. #break;
  473. };
  474. #nop 遍历所有新发现的节点;
  475. #local nodes {$checkList};
  476. #local checkList {};
  477. #local node {};
  478. #foreach {$nodes[]} {node} {
  479. #local next {};
  480. #local c {};
  481. #line sub {var;functions;escapes} #format c {%s} {$cond};
  482. #if { $c } {
  483. #nop 满足条件的节点。;
  484. #local dst {$node};
  485. #break;
  486. };
  487. #foreach {*map.xiaoyao.map[$node][]} {next} {
  488. #if { "$routeMap[$next]" != "" } {
  489. #nop 已经检索过的节点。;
  490. #continue;
  491. };
  492. #local link {$map.xiaoyao.map[$node][$next]};
  493. #if { "$link" == "TODO" } {
  494. #nop BUG: 不完整的连接。;
  495. #continue;
  496. };
  497. #list {checkList} {add} {$next};
  498. #local routeMap[$next] {$node};
  499. };
  500. };
  501. };
  502. #if { "$dst" == "" || "$routeMap[$dst]" == "" } {
  503. #return {};
  504. };
  505. #local route {$dst};
  506. #local path {};
  507. #local node {$dst};
  508. #while { "$node" != "$src" } {
  509. #local prev {$routeMap[$node]};
  510. #local link {$map.xiaoyao.map[$prev][$node]};
  511. #local node {$prev};
  512. #format route {%s-%s} {$node} {$route};
  513. #if { "$link" == "PATH" } {
  514. #list path insert 1 {PATH/{$action}};
  515. };
  516. #else {
  517. #list path insert 1 {$link};
  518. };
  519. };
  520. #list path {simplify};
  521. #return {
  522. {room}{$dst}
  523. {route}{$route}
  524. {path}{$path}
  525. };
  526. };
  527. #func {xiaoyao.locateByName} {
  528. #local name {%1};
  529. #if { "$name" == "" } {
  530. #return {};
  531. };
  532. #if { &map.xiaoyao.map[=$name] > 0 } {
  533. #return {$name};
  534. };
  535. #local nodes {@table.Keys{map.xiaoyao.map;%*$name%*}};
  536. #local best {};
  537. #local better {};
  538. #local normal {};
  539. #local node {};
  540. #foreach {$nodes} {node} {
  541. #if { "$node" == "$name(%*)" } {
  542. #return {$node};
  543. };
  544. #if { "$node" == "%*(%*的$name)" && "$node" != "%*{津|渡|渡口})" } {
  545. #local best {$node};
  546. };
  547. #elseif { "$node" == "%*($name的%*)" && "$node" != "%*{津|渡|渡口})" } {
  548. #local better {$node};
  549. };
  550. #elseif { "$node" == "%*(%*$name%*)" } {
  551. #local normal {$node};
  552. };
  553. };
  554. #if { "$best" != "" } {
  555. #return {$best};
  556. };
  557. #elseif { "$better" != "" } {
  558. #return {$better};
  559. };
  560. #else {
  561. #return {$normal};
  562. };
  563. };
  564. ///=== {
  565. // ## xiaoyao.Query <出发节点> <目的节点>
  566. // 计算逍遥行路径。
  567. // 出发节点和目的节点都支持模糊查询。
  568. //
  569. // 本别名也可简写为 <139>xyq<299>。
  570. // };
  571. #alias {xiaoyao.Query} {
  572. #local begin {@str.Format{%U}};
  573. #local origin {@xiaoyao.locateByName{%1}};
  574. #local target {@xiaoyao.locateByName{%2}};
  575. #if { "$origin" == "" || "$target" == "" } {
  576. xtt.Usage xiaoyao.Query {<169>这里是 PaoTin++ 逍遥行路径查询工具};
  577. #return;
  578. };
  579. infoLog 计算从<129>$origin<299>到<139>$target<299>的路径。;
  580. #local target {@xiaoyao.findPath{$origin;"NODE" == "%*$target%*"}};
  581. #if { "$target" == "" } {
  582. errLog 找不到路径。;
  583. #return;
  584. };
  585. #if { "$target[path]" == "" } {
  586. okLog 你已经来到了 $target[room];
  587. #return;
  588. };
  589. #local end {@str.Format{%U}};
  590. #local elapsed {@math.Eval{($end * 1.000 - $begin * 1.000) / 1000.000}};
  591. okLog 计算结果: {$target[path]};
  592. #replace {target[route]} {(%*)} {};
  593. okLog 途经节点: $target[route];
  594. infoLog 计算耗时: $elapsed 毫秒。;
  595. infoLog;
  596. infoLog PaoTin++ 用户使用 <120>xy %2<299> 即可完成行走,支持自动坐船过河。;
  597. infoLog 下载地址: <488><149>https://pkuxkx.net/wiki/tools/paotin<299>;
  598. infoLog;
  599. };
  600. #alias {xyq} {xiaoyao.Query};
  601. ///=== {
  602. // ## xiaoyao.LoadData
  603. // 加载逍遥行依赖的数据文件。
  604. // };
  605. #alias {xiaoyao.LoadData} {
  606. storage.Load {map-xiaoyao} {map.xiaoyao.map;map.xiaoyao.room};
  607. storage.Load {map-area} {map.area.dict};
  608. };