xiaoyao.tin 21 KB

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