home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / vmsnet / ldb / part08 < prev    next >
Encoding:
Internet Message Format  |  1993-04-07  |  47.9 KB

  1. Path: uunet!zaphod.mps.ohio-state.edu!usc!news.service.uci.edu!unogate!mvb.saic.com!dayton.saic.com!dayvd.dayton.saic.com!ake
  2. From: ake@dayvd.dayton.saic.com (Earle Ake)
  3. Newsgroups: vmsnet.sources.games
  4. Subject: ldb - Long Distance Backgammon [08/16]
  5. Date: 8 Apr 93 10:57:33 EST
  6. Organization: Science Applications Intl Corp - Dayton, OH
  7. Lines: 1279
  8. Message-ID: <1993Apr8.105733.1@dayvd.dayton.saic.com>
  9. NNTP-Posting-Host: dayvd.dayton.saic.com
  10. Xref: uunet vmsnet.sources.games:669
  11.  
  12. -+-+-+-+-+-+-+-+ START OF PART 8 -+-+-+-+-+-+-+-+
  13. Xdelwin(statwin);`09`09/*`20delete`20the`20window`20*/
  14. X`7D
  15. $ call unpack DOSTATS.C;1 404862844 ""
  16. $!
  17. $ create 'f'
  18. X/*`09fe_curses.c`09`099/5/91
  19. X`20*
  20. X`20*`20Copyright`201991`20`20Perry`20R.`20Ross
  21. X`20*
  22. X`20*`20Permission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20so
  23. Vftware`20and`20its
  24. X`20*`20documentation`20without`20fee`20is`20hereby`20granted,`20subject`20to
  25. V`20the`20restrictions
  26. X`20*`20detailed`20in`20the`20README`20file,`20which`20is`20included`20here`20b
  27. Vy`20reference.
  28. X`20*`20Any`20other`20use`20requires`20written`20permission`20from`20the`20auth
  29. Vor.`20`20This`20software
  30. X`20*`20is`20distributed`20"as`20is"`20without`20any`20warranty,`20including
  31. V`20any`20implied
  32. X`20*`20warranties`20of`20merchantability`20or`20fitness`20for`20a`20particular
  33. V`20purpose.
  34. X`20*`20The`20author`20shall`20not`20be`20liable`20for`20any`20damages`20result
  35. Ving`20from`20the
  36. X`20*`20use`20of`20this`20software.`20`20By`20using`20this`20software,`20the
  37. V`20user`20agrees
  38. X`20*`20to`20these`20terms.
  39. X`20*/
  40. X
  41. X#include`20"ldb.h"
  42. X
  43. X/*======================================================================
  44. X`20*`20This`20file`20is`20the`20"curses"`20front-end`20for`20ldb.`20`20It`20pe
  45. Vrforms`20all
  46. X`20*`20display`20output`20and`20keyboard`20input`20in`20a`20way`20that`20will
  47. V`20(hopefully)
  48. X`20*`20allow`20other`20front-ends`20to`20be`20added`20later.`20`20These`20coul
  49. Vd`20include
  50. X`20*`20MAC's`20(blech),`20IBM`20PC's`20(double`20blech),`20and`20X,`20although
  51. V`20it`20must
  52. X`20*`20be`20stated`20that,`20as`20of`20this`20writing,`20ldb`20is`20not`20orga
  53. Vnized`20in`20an
  54. X`20*`20event-driven`20manner,`20so`20it`20will`20take`20more`20work`20to`20por
  55. Vt`20to`20X`20than
  56. X`20*`20just`20writing`20fe_motif.c`20or`20what`20have`20you.`20`20But`20I'm
  57. V`20working`20on`20it.
  58. X`20*
  59. X`20*`20All`20publicly-accessible`20functions`20in`20the`20front-end`20begin
  60. V`20with`20Fe.
  61. X`20*`20These`20are`20the`20functions`20that`20must`20be`20written`20to`20imple
  62. Vment`20a`20new
  63. X`20*`20front-end.`20`20There`20are`20a`20few`20private`20functions`20in`20this
  64. V`20file,`20which
  65. X`20*`20begin`20with`20P.`20`20These`20are`20used`20internally`20by`20fe_curses
  66. V.c`20and`20need`20not
  67. X`20*`20be`20implemented`20in`20other`20front-ends.
  68. X`20*
  69. X`20*`20The`20front-end`20is`20activated`20by`20calling`20FeInitialize.`20`20In
  70. V`20addition`20to
  71. X`20*`20performing`20any`20required`20initialization,`20it`20is`20mandatory`20f
  72. Vor`20FeInitialize
  73. X`20*`20to`20set`20FeIsActive`20to`20non-zero.`20`20The`20front-end`20is`20clos
  74. Ved`20down`20by
  75. X`20*`20calling`20FeFinishSession,`20which`20must`20set`20FeIsActive`20to`200.
  76. V`20`20No`20calls
  77. X`20*`20to`20any`20Fe`20functions`20may`20be`20made`20while`20FeIsActive`20is
  78. V`200.
  79. X`20*======================================================================
  80. X`20*/
  81. X
  82. XPRIVATE`20char`20PGetChr();
  83. XPRIVATE`20PGetString();
  84. XPRIVATE`20PDrawComment();
  85. XPRIVATE`20PReverseText();
  86. XPRIVATE`20PEndReverse();
  87. X
  88. XPRIVATE`20struct`20game`20*Current_Game`20=`20NULL;
  89. X
  90. X
  91. X/*`20VAX`20C`20doesn't`20have`20tgetstr,`20but`20if`20you're`20using`20vax-c,
  92. V`09*/
  93. X/*`20you're`20probably`20using`20a`20DEC`20terminal`20anyway.`09`09`09*/
  94. X#ifdef`20vaxc
  95. X#define`20PClearScreen()`20fputs("`5C33`5BH`5C33`5B2J",stdout);fflush(stdout)
  96. X#else
  97. XPRIVATE`20PClearScreen();
  98. X#endif
  99. X
  100. X
  101. X/*----------------------------------------------------------------------
  102. X`20*`09FeInitialize`20--`20initialize`20the`20front`20end
  103. X`20*
  104. X`20*`20This`20function`20initializes`20the`20curses`20package,`20turns`20off
  105. V`20echo,
  106. X`20*`20turns`20on`20cbreak`20mode`20(to`20allow`20reading`20one`20character
  107. V`20at`20a`20time),
  108. X`20*`20turns`20off`20mapping`20return`20to`20newline,`20and`20sets`20the`20FeI
  109. VsActive`20flag.
  110. X`20*`20If`20FeWaitInit`20is`20set,`20the`20user`20is`20prompted`20to`20press
  111. V`20<return>`20before
  112. X`20*`20the`20screen`20is`20cleared.`20`20FeWaitInit`20is`20set`20by`20message(
  113. V)`20to`20indicate
  114. X`20*`20that`20there`20are`20messages`20on`20the`20screen`20that`20the`20user
  115. V`20will`20want`20to
  116. X`20*`20read`20before`20the`20screen`20is`20cleared.
  117. X`20*----------------------------------------------------------------------
  118. X`20*/
  119. X
  120. XFeInitialize()
  121. X`7B
  122. Xchar`20buf`5B80`5D;
  123. X
  124. Xif`20(FeIsActive)
  125. X`09return;
  126. Xif`20(FeWaitInit)`20`7B
  127. X`09fprintf(stderr,"Press`20<return>`20to`20continue...");
  128. X`09fflush(stdout);
  129. X`09fflush(stderr);
  130. X`09fgets(buf,sizeof(buf),stdin);
  131. X`09FeWaitInit`20=`200;
  132. X`09`7D
  133. Xinitscr();
  134. Xnoecho();
  135. Xcbreak();
  136. Xnonl();
  137. XFeIsActive`20=`201;
  138. XCurrent_Game`20=`20NULL;
  139. X`7D
  140. X
  141. X
  142. X/*----------------------------------------------------------------------
  143. X`20*`09FeFinishSession`20--`20shut`20down`20the`20front`20end
  144. X`20*
  145. X`20*`20This`20function`20clears`20the`20screen,`20closes`20down`20the`20curses
  146. V`20package,
  147. X`20*`20and`20clears`20the`20FeIsActive`20flag.
  148. X`20*----------------------------------------------------------------------
  149. X`20*/
  150. X
  151. XFeFinishSession()
  152. X`7B
  153. X
  154. Xif`20(FeIsActive)`20`7B
  155. X`09clear();
  156. X`09refresh();
  157. X`09endwin();
  158. X`09FeIsActive`20=`200;
  159. X`09Current_Game`20=`20NULL;
  160. X`09`7D
  161. X`7D
  162. X
  163. X
  164. X/*----------------------------------------------------------------------
  165. X`20*`09FeDrawScreen`20--`20draw`20the`20constant`20parts`20of`20the`20screen
  166. X`20*
  167. X`20*`20This`20function`20draws`20the`20parts`20of`20the`20screen`20that`20don'
  168. Vt`20change`20for
  169. X`20*`20each`20game.`20`20This`20includes`20the`20board`20outline`20and`20a`20f
  170. Vew`20other
  171. X`20*`20miscellaneous`20things.
  172. X`20*----------------------------------------------------------------------
  173. X`20*/
  174. X
  175. XFeDrawScreen()
  176. X`7B
  177. Xstatic`20char`20horz`5B`5D`20=`20"____________________________________________
  178. V_________";
  179. Xint`20i;
  180. X
  181. Xclear();
  182. Xmvaddstr(2,5,horz);
  183. Xmvaddstr(17,5,horz);
  184. Xfor`20(i`20=`203;`20i`20<`2018;`20i++)`20`7B
  185. X`09mvaddch(i,5,'`7C');
  186. X`09mvaddch(i,29,'`7C');
  187. X`09mvaddch(i,33,'`7C');
  188. X`09mvaddch(i,57,'`7C');
  189. X`09`7D
  190. Xmvaddstr(3,61,"----------------");
  191. Xmvaddstr(4,63,"Roll`20`20Move");
  192. Xmvaddstr(12,61,"----------------");
  193. Xmvaddstr(13,63,"Roll`20`20Move");
  194. Xmvaddstr(18,62,"------`5B`20`5D------");
  195. Xfor`20(i`20=`2019;`20i`20<`2024;`20i++)
  196. X`09mvaddch(i,62,'`7C');
  197. Xmvaddstr(18,0,"Messages:");
  198. Xmvaddstr(19,0,"Sent:");
  199. Xmvaddstr(21,0,"Rcvd:");
  200. Xrefresh();
  201. X`7D
  202. X
  203. X
  204. X
  205. X/*----------------------------------------------------------------------
  206. X`20*`09FeDrawGame`20--`20draw`20all`20items`20associated`20with`20a`20game
  207. X`20*
  208. X`20*`20This`20function`20displays`20all`20information`20related`20to`20a`20spe
  209. Vcific`20game.
  210. X`20*`20This`20includes`20the`20point`20labels,`20move`20blocks,`20cube;`20shoo
  211. Vt,`20just
  212. X`20*`20about`20everything`20you`20can`20think`20of.
  213. X`20*----------------------------------------------------------------------
  214. X`20*/
  215. X
  216. XFeDrawGame(g)
  217. Xstruct`20game`20*g;
  218. X`7B
  219. Xint`20i,`20p,`20r1,`20r2;
  220. Xchar`20blots`5B12`5D,`20tmp`5B60`5D,`20*n;
  221. Xchar`20addr`5B68`5D;`09`09/*`20all`20of`20e-mail`20address`20that`20will`20fit
  222. V`20on`20top`20line`20*/
  223. Xint`20bgflag;`09`09/*`201`20=`20gammon,`202`20=`20backgammon,`200`20=`20neithe
  224. Vr`20*/
  225. Xint`20gval;`09`09/*`20game`20value`20(when`20game`20is`20over)`20*/
  226. Xstatic`20char`20pts1`5B`5D`20=`20"`201`20`20`202`20`20`203`20`20`204`20`20`205
  227. V`20`20`206`20`7C`20`20`20`7C`207`20`20`208`20`20`209`20`2010`20`2011`20`2012";
  228. V
  229. Xstatic`20char`20pts2`5B`5D`20=`20"24`20`2023`20`2022`20`2021`20`2020`20`2019
  230. V`20`7C`20`20`20`7C18`20`2017`20`2016`20`2015`20`2014`20`2013";
  231. Xstatic`20char`20*events`5B`5D`20=`20`7B`20"",`20"Gammon!`20`20",`20"Backgammon
  232. V!`20`20"`20`7D;
  233. X
  234. XCurrent_Game`20=`20g;
  235. Xmove(0,0);
  236. Xclrtoeol();
  237. Xmove(0,0);
  238. Xn`20=`20(g->opname`20!=`20NULL)`20?`20g->opname`20:`20"UNKNOWN";
  239. Xi`20=`20sizeof(addr)`20-`20strlen(n)`20-`201;`20`20/*`20longest`20e-mail`20add
  240. Vr`20we`20can`20display`20*/
  241. Xif`20(strlen(g->opaddr)`20>`20i)`20`7B`09/*`20too`20long,`20truncate`20*/
  242. X`09strncpy(addr,g->opaddr,i-3);`09/*`20leave`20space`20for`20...`20*/
  243. X`09strcpy(`26addr`5Bi-3`5D,"...");`09/*`20add`20ellipsis`20`26`20null`20termin
  244. Vate`20*/
  245. X`09`7D
  246. Xelse
  247. X`09strcpy(addr,g->opaddr);
  248. Xprintw("Playing:`20%s`20(%s)",n,addr);`09`09/*`20who`20am`20I`20playing?`20*/
  249. Xif`20(g->flags`20`26`20F_INVERT)`20`7B`09`09/*`20board`20is`20inverted?`20`20*
  250. V/
  251. X`09mvaddstr(16,6,pts2);`09`09/*`20draw`20inverted`20point`20labels`20*/
  252. X`09mvaddstr(4,6,pts1);
  253. X`09r1`20=`2011;`09`09`09/*`20remember`20which`20move`20block`20to`20use`20*/
  254. X`09r2`20=`202;
  255. X`09p`20=`201;
  256. X`09`7D
  257. Xelse`20`7B
  258. X`09mvaddstr(4,6,pts2);`09`09/*`20draw`20normal`20point`20labels`20*/
  259. X`09mvaddstr(16,6,pts1);
  260. X`09r1`20=`202;`09`09`09`09/*`20remember`20which`20move`20block`20to`20use`20*/
  261. V
  262. X`09r2`20=`2011;
  263. X`09p`20=`200;
  264. X`09`7D
  265. Xif`20(g->mydir`20>`200)`20`7B`09`09/*`20I'm`20playing`20up,`20switch`20move
  266. V`20blocks`20*/
  267. X`09i`20=`20r1;
  268. X`09r1`20=`20r2;
  269. X`09r2`20=`20i;
  270. X`09p`20=`201`20-`20p;
  271. X`09`7D
  272. Xmove(r1,63);
  273. Xprintw("Opponent`20`20(%c)",g->opcolor);
  274. Xmove(r2,63);
  275. Xprintw("You`20`20`20`20`20`20`20(%c)",g->mycolor);
  276. X
  277. Xswitch`20(g->curbd)`20`7B`09`09`09/*`20which`20board`20should`20I`20draw?`20*/
  278. V
  279. Xcase`20BD_BEFOP:
  280. X`09FeDrawBoard(g->opbd,g->opmvs,g->opdir,0,g->flags`20`26`20F_INVERT);
  281. X`09FeDrawPip(g->opbd,g);
  282. X`09break;
  283. Xcase`20BD_AFTOP:
  284. X`09FeDrawBoard(g->mybd,g->opmvs,g->opdir,1,g->flags`20`26`20F_INVERT);
  285. X`09FeDrawPip(g->mybd,g);
  286. X`09break;
  287. Xcase`20BD_CUR:
  288. X`09FeDrawBoard(g->board,NULL,g->mydir,0,g->flags`20`26`20F_INVERT);
  289. X`09FeDrawPip(g->board,g);
  290. X`09break;
  291. X`09`7D
  292. XFeLabelBoard(g);
  293. Xmvaddch(5,59,'`7C');`09`09`09/*`20draw`20those`20little`20arrows`20*/
  294. Xmvaddch(4,59,'-');
  295. Xmvaddch(14,59,'`7C');`09`09`09/*`20that`20tell`20us`20which`20direction`20*/
  296. Xmvaddch(15,59,'`7C');`09`09`09/*`20we`20are`20going`20*/
  297. Xmvaddch(16,59,'-');
  298. Xif`20(p`20==`200)`20`7B
  299. X`09mvaddstr(4,1,"-->");
  300. X`09mvaddch(4,58,'-');
  301. X`09mvaddch(6,59,'V');
  302. X`09mvaddch(16,58,'<');
  303. X`09mvaddstr(16,1,"<--");
  304. X`09mvaddstr(13,58,"`20`20`20");
  305. X`09mvaddch(12,59,'`20');
  306. X`09mvaddstr(4,30,"-->");
  307. X`09mvaddstr(16,30,"<--");
  308. X`09`7D
  309. Xelse`20`7B
  310. X`09mvaddstr(4,1,"<--");
  311. X`09mvaddch(4,58,'<');
  312. X`09mvaddch(6,59,'`7C');
  313. X`09mvaddch(16,58,'-');
  314. X`09mvaddstr(16,1,"-->");
  315. X`09mvaddstr(13,58,"/`7C`5C`5C");
  316. X`09mvaddch(12,59,'.');
  317. X`09mvaddstr(16,30,"-->");
  318. X`09mvaddstr(4,30,"<--");
  319. X`09`7D
  320. X*blots`20=`20'`5C0';`09`09`09`09/*`20did`20any`20of`20our`20blots`20get`20hit?
  321. V`20*/
  322. Xfor`20(i`20=`200,`20p`20=`200;`20i`20<`204;`20i++)`20`7B
  323. X`09FeDrawMove(g,WHO_ME,i);`09`09/*`20draw`20my`20moves`20*/
  324. X`09FeDrawMove(g,WHO_OPP,i);`09/*`20draw`20opponent's`20moves`20*/
  325. X`09if`20(g->blot`5Bi`5D`20>`200)`20`7B
  326. X`09`09strcat(blots,"`20");`09/*`20add`20a`20blot`20to`20the`20list`20*/
  327. X`09`09sprintf(tmp,"%d",g->blot`5Bi`5D);
  328. X`09`09strcat(blots,tmp);
  329. X`09`09p++;
  330. X`09`09`7D
  331. X`09`7D
  332. XFeDrawCube(g);`09`09/*`20draw`20the`20current`20game`20value`20*/
  333. XPDrawComment(WHO_ME,`20g);`09/*`20draw`20my`20old`20comment`20*/
  334. XPDrawComment(WHO_OPP,`20g);`09/*`20draw`20opponent's`20comment`20*/
  335. Xif`20(g->state`20==`20ST_MYACCEPT)
  336. X`09strcpy(tmp,"Opponent`20has`20doubled.");
  337. Xelse`20if`20(g->state`20==`20ST_GAMEOVER)`20`7B`09/*`20game`20is`20over,`20fin
  338. Vd`20out`20why`20*/
  339. X`09bgflag`20=`20gvalue(g,`26gval);`09`09/*`20calculate`20game`20value`20*/
  340. X`09switch`20(g->term)`20`7B
  341. X`09case`20T_IWIN:`09`09/*`20I`20won,`20check`20for`20gammon/backgammon`20*/
  342. X`09`09sprintf(tmp,"%sYou`20win`20%d`20point%s.",events`5Bbgflag`5D,
  343. X`09`09`09gval,(gval`20==`201)`20?`20""`20:`20"s");
  344. X`09`09break;
  345. X`09case`20T_ILOSE:`09`09/*`20I`20lost,`20check`20for`20gammon/backgammon`20*/
  346. X`09`09sprintf(tmp,"%sYou`20lose`20%d`20point%s.",events`5Bbgflag`5D,
  347. X`09`09`09gval,(gval`20==`201)`20?`20""`20:`20"s");
  348. X`09`09break;
  349. X`09case`20T_ICONCEDE:`09`09`09/*`20I`20wimped`20out`20*/
  350. X`09`09sprintf(tmp,"You`20conceded.`20`20You`20lose`20%d`20point%s.",
  351. X`09`09`09gval,(gval`20==`201)`20?`20""`20:`20"s");
  352. X`09`09break;
  353. X`09case`20T_OPCONCEDE:`09`09`09/*`20Opponent`20wimped`20out`20*/
  354. X`09`09sprintf(tmp,"Opponent`20conceded.`20`20You`20win`20%d`20point%s.",
  355. X`09`09`09gval,(gval`20==`201)`20?`20""`20:`20"s");
  356. X`09`09break;
  357. X`09case`20T_IDECLINE:`09`09`09/*`20I`20declined`20the`20double`20*/
  358. X`09`09sprintf(tmp,"Double`20declined.`20`20You`20lose`20%d`20point%s.",
  359. X`09`09`09gval,(gval`20==`201)`20?`20""`20:`20"s");
  360. X`09`09break;
  361. X`09case`20T_OPDECLINE:`09`09/*`20Opponent`20declined`20my`20double`20*/
  362. X`09`09sprintf(tmp,"Double`20declined.`20`20You`20win`20%d`20point%s.",
  363. X`09`09`09gval,(gval`20==`201)`20?`20""`20:`20"s");
  364. X`09`09break;
  365. X`09`09`7D
  366. X`09`7D
  367. Xelse`20if`20(*blots)
  368. X`09sprintf(tmp,"Blot%s`20hit:%s",(p`20==`201)`20?`20""`20:`20"s",blots);
  369. Xelse
  370. X`09*tmp`20=`20'`5C0';
  371. XFeStatusLine(tmp);
  372. XFeMessage(g->dispmsg);`09`09/*`20put`20message`20(if`20any)`20on`20message`20l
  373. Vine`20*/
  374. Xif`20(g->dispmsg`20!=`20NULL)`20`7B`09/*`20if`20there`20was`20a`20message,`20i
  375. Vt`20has`20been`20*/
  376. X`09free(g->dispmsg);`09/*`20displayed,`20so`20it`20can`20thrown`20away`20*/
  377. X`09g->dispmsg`20=`20NULL;
  378. X`09`7D
  379. Xrefresh();
  380. X`7D
  381. X
  382. X
  383. X/*----------------------------------------------------------------------
  384. X`20*`09FeDrawPip`20--`20display`20the`20PIP`20count
  385. X`20*
  386. X`20*`20This`20function`20displays`20the`20current`20pip`20count.
  387. X`20*----------------------------------------------------------------------
  388. X`20*/
  389. X
  390. XFeDrawPip(b,g)
  391. Xboard`20b;`09`09`09/*`20the`20current`20board`20array`20*/
  392. Xstruct`20game`20*g;`09`09`09/*`20the`20current`20game`20structure`20*/
  393. X`7B
  394. Xint`20mypip,`20oppip;
  395. X
  396. Xpipcount(b,g,`26mypip,`26oppip);
  397. Xmove(1,29);
  398. Xclrtoeol();
  399. Xmove(1,29);
  400. Xprintw("You:`20%3d`20`20Op:`20%3d`20`20",`20mypip,`20oppip);
  401. Xif`20(mypip`20>`20oppip)
  402. X`09printw("(%d`20behind)",`20mypip`20-`20oppip);
  403. Xelse`20if`20(oppip`20>`20mypip)
  404. X`09printw("(%d`20ahead)",`20oppip`20-`20mypip);
  405. Xelse
  406. X`09printw("(even)");
  407. X`7D
  408. X
  409. X
  410. X/*----------------------------------------------------------------------
  411. X`20*`09FeDrawPoint`20--`20draw`20all`20pieces`20on`20a`20point
  412. X`20*
  413. X`20*`20This`20function`20redraws`20all`2015`20slots`20on`20a`20point.`20`20It
  414. V`20is`20passed`20a
  415. X`20*`20board`20image`20and`20the`20index`20of`20the`20point`20to`20draw,`20fro
  416. Vm`20which`20it
  417. X`20*`20extracts`20the`20number`20of`20pieces`20on`20that`20point`20and`20the
  418. V`20character`20used
  419. X`20*`20to`20represent`20pieces.`20`20It`20will`20draw`20as`20many`20of`20these
  420. V`20pieces`20as
  421. X`20*`20exist`20on`20the`20point,`20and`20will`20draw`20blanks`20over`20the`20r
  422. Vemaining`20slots
  423. X`20*`20to`20erase`20any`20pieces`20that`20may`20have`20existed`20before.
  424. X`20*`20If`20the`20nh`20argument`20is`20greater`20than`200,`20it`20specifies
  425. V`20how`20many`20of
  426. X`20*`20the`20pieces`20drawn`20should`20be`20highlighted.`20`20This`20is`20used
  427. V`20to`20highlight
  428. X`20*`20pieces`20moved`20by`20the`20opponent.
  429. X`20*----------------------------------------------------------------------
  430. X`20*/
  431. X
  432. XFeDrawPoint(b,pt,nh,inv)
  433. Xboard`20b;`09`09/*`20the`20board`20array`20*/
  434. Xint`20pt;`09`09`09/*`20which`20point`20are`20we`20to`20draw`20*/
  435. Xint`20nh;`09`09`09/*`20how`20many`20pieces`20should`20be`20highlighted`20*/
  436. Xint`20inv;`09`09/*`20is`20the`20board`20inverted?`20*/
  437. X`7B
  438. Xstatic`20int`20cols`5BBOARDSIZE`5D`20=`20`7B`20`2031,7,11,15,19,23,27,35,39,43
  439. V,47,51,55,
  440. X`09`09`09`0955,51,47,43,39,35,27,23,19,15,11,7,31,2,2`7D;
  441. Xint`20sr,`20r;`09`09/*`20the`20row`20we`20are`20at`20*/
  442. Xint`20c;`09`09/*`20the`20column`20we`20are`20at`20*/
  443. Xint`20d;`09`09/*`20which`20direction`20does`20the`20column`20grow`201/-1`20*/
  444. Xint`20i;`09`09/*`20counter`20*/
  445. Xchar`20x;`09`09/*`20char`20to`20draw`20piece`20with`20*/
  446. Xint`20nn;`09`09/*`20number`20of`20normal`20pieces`20*/
  447. X
  448. Xif`20(`20(pt`20>`2012)`20`26`26`20(pt`20!=`20DOWNOFF))`20`7B
  449. X`09sr`20=`20inv`20?`2015`20:`205;`09/*`20starting`20row`20is`205`20(unless`20i
  450. Vnverted)`20*/
  451. X`09d`20=`20inv`20?`20-1`20:`201;`09/*`20direction`20is`20down`20(unless`20inve
  452. Vrted)`20*/
  453. X`09`7D
  454. Xelse`20`7B
  455. X`09sr`20=`20inv`20?`205`20:`2015;`09/*`20starting`20row`20is`2015`20(unless
  456. V`20inverted)`20*/
  457. X`09d`20=`20inv`20?`201`20:`20-1;`09/*`20direction`20is`20up`20(unless`20invert
  458. Ved)`20*/
  459. X`09`7D
  460. Xc`20=`20cols`5Bpt`5D;
  461. Xx`20=`20b`5Bpt`5D.color;`09`09/*`20char`20to`20draw`20piece`20with`20*/
  462. Xif`20(nh`20<`200)
  463. X`09nh`20=`200;
  464. Xelse`20if`20(nh`20>`20b`5Bpt`5D.qty)
  465. X`09nh`20=`20b`5Bpt`5D.qty;
  466. Xnn`20=`20b`5Bpt`5D.qty`20-`20nh;`09`09/*`20how`20many`20normal`20pcs`20*/
  467. Xr`20=`20sr;
  468. Xfor`20(i`20=`200;`20i`20<`2015;`20i++)`20`7B`09`09/*`20draw`20all`2015`20slots
  469. V`20on`20this`20point`20*/
  470. X`09if`20(nn`20<=`200)`20`7B`09`09/*`20no`20more`20normal`20pieces`20*/
  471. X`09`09if`20(nh`20<=`200)`09/*`20and`20no`20highlighted`20pieces`20*/
  472. X`09`09`09x`20=`20'`20';`09/*`20so`20draw`20blanks`20*/
  473. X`09`09else`20`7B
  474. X`09`09`09PReverseText();
  475. X`09`09`09nh--;
  476. X`09`09`09`7D
  477. X`09`09`7D
  478. X`09else
  479. X`09`09nn--;
  480. X`09mvaddch(r,c,x);`09`09`09/*`20draw`20this`20piece`20*/
  481. X`09PEndReverse();
  482. X`09if`20(i`20==`204)`20`7B
  483. X`09`09r`20=`20sr;`09`09`09/*`20reset`20row`20*/
  484. X`09`09c--;`09`09`09/*`20use`20col`20to`20left`20of`20first`20row`20*/
  485. X`09`09`7D
  486. X`09else`20if`20(i`20==`209)`20`7B
  487. X`09`09r`20=`20sr;`09`09`09/*`20reset`20row`20*/
  488. X`09`09c`20+=`202;`09`09`09/*`20use`20col`20to`20right`20of`20first`20row`20*/
  489. X`09`09`7D
  490. X`09else
  491. X`09`09r`20+=`20d;`09`09`09/*`20bump`20row`20number`20*/
  492. X`09`7D
  493. X`7D
  494. X
  495. X
  496. X/*----------------------------------------------------------------------
  497. X`20*`09FeDrawMove`20--`20draw`20a`20line`20in`20a`20move`20block
  498. X`20*
  499. X`20*`20This`20function`20draws`20one`20line`20in`20a`20move`20block.`20`20This
  500. V`20consists`20of`20the
  501. X`20*`20value`20of`20the`20roll,`20the`20starting`20and`20ending`20position`20o
  502. Vf`20the`20piece
  503. X`20*`20moved,`20and`20an`20asterisk`20if`20the`20move`20was`20from`20the`20opp
  504. Vonent`20and`20hit
  505. X`20*`20one`20of`20our`20blots.
  506. X`20*----------------------------------------------------------------------
  507. X`20*/
  508. X
  509. XFeDrawMove(g,who,mn)
  510. Xstruct`20game`20*g;`09`09`09/*`20the`20game`20structure`20*/
  511. Xint`20who;`09`09`09/*`20WHO_ME`20or`20WHO_OPP`20*/
  512. Xint`20mn;`09`09`09`09/*`20which`20move`20to`20draw`20*/
  513. X`7B
  514. Xint`20p,`20r,`20d;
  515. Xstruct`20mv`20*m;
  516. X
  517. Xd`20=`20(who`20==`20WHO_ME)`20?`20g->mydir`20:`20g->opdir;/*`20this`20move`20u
  518. Vpbound`20or`20downbound?`20*/
  519. Xp`20=`20(d`20>`200);`09`09`09`09/*`20upper`20or`20lower`20block?`20*/
  520. Xif`20(g->flags`20`26`20F_INVERT)`09`09/*`20inverted`20board`20*/
  521. X`09p`20=`20!p;`09`09`09`09/*`20switch`20move`20blocks`20*/
  522. Xr`20=`20mn`20+`20(p`20?`205`20:`2014);`09`09`09/*`20figure`20out`20the`20row
  523. V`20number`20*/
  524. Xm`20=`20(who`20==`20WHO_ME)`20?`20`26g->mvs`5Bmn`5D`20:`20`26g->opmvs`5Bmn`5D;
  525. V/*`20find`20the`20move`20structure`20*/
  526. Xmove(r,64);
  527. Xclrtoeol();`09`09`09`09/*`20clear`20the`20old`20move`20*/
  528. Xif`20(m->roll`20>`200)`20`7B
  529. X`09move(r,64);
  530. X`09printw("%d",m->roll);`09`09/*`20draw`20the`20roll`20*/
  531. X`09move(r,69);
  532. X`09if`20(m->pt`20<`200)`20`7B`09`09/*`20if`20it`20is`20unused,`20say`20so`20*/
  533. V
  534. X`09`09addstr("UNUSED");
  535. X`09`09return;
  536. X`09`09`7D
  537. X`09if`20(`20(`20(p`20=`20m->pt)`20==`20UPBAR)`20`7C`7C`20(m->pt`20==`20DOWNBAR
  538. V)`20)`20`7B
  539. X`09`09p`20=`20BARPT(d);`09`09/*`20if`20coming`20off`20bar,`20say`20so`20*/
  540. X`09`09printw("BAR-");
  541. X`09`09`7D
  542. X`09else
  543. X`09`09printw("%d-",m->pt);`09/*`20draw`20starting`20point`20*/
  544. X`09if`20(`20(`20(p`20+=`20d*m->roll)`20<=`200)`20`7C`7C`20(p`20>=`2025)`20)
  545. X`09`09printw("OFF");`09`09/*`20if`20bearing`20off,`20say`20so`20*/
  546. X`09else
  547. X`09`09printw("%d",p);`09`09/*`20draw`20ending`20point`20*/
  548. X`09if`20(`20(who`20==`20WHO_OPP)`20`26`26`20g->blot`5Bmn`5D)`09/*`20if`20op
  549. V`20move`20hit`20a`20blot`20*/
  550. X`09`09mvaddch(r,76,'*');`09/*`20mark`20it`20*/
  551. X`09`7D
  552. X`7D
  553. X
  554. X
  555. X/*----------------------------------------------------------------------
  556. X`20*`09FeDrawBoard`20--`20draw`20all`20points`20on`20a`20board
  557. X`20*
  558. X`20*`20This`20is`20a`20convenience`20function`20that`20calls`20FeDrawPoint`20f
  559. Vor`20all
  560. X`20*`20points`20on`20a`20board.`20`20It`20takes`20as`20an`20argument`20an`20ar
  561. Vray`20of`20moves,
  562. X`20*`20as`20well`20as`20an`20argument`20that`20determines`20whether`20DrawPoin
  563. Vt`20should`20be
  564. X`20*`20instructed`20to`20highlight`20the`20source`20of`20those`20moves,`20the
  565. V`20destination,
  566. X`20*`20or`20nothing.
  567. X`20*----------------------------------------------------------------------
  568. X`20*/
  569. X
  570. XFeDrawBoard(b,mvs,dir,sd,inv)
  571. Xboard`20b;`09`09`09/*`20board`20image`20*/
  572. Xstruct`20mv`20mvs`5B4`5D;`09`09/*`20moves`20to`20highlight`20(NULL`20=`20none)
  573. V`20*/
  574. Xint`20dir;`09`09`09/*`20direction`20*/
  575. Xint`20sd;`09`09`09`09/*`200=highlight`20source,`201=dest`20*/
  576. Xint`20inv;`09`09`09/*`20is`20the`20board`20inverted?`20*/
  577. X`7B
  578. Xint`20i,`20s,`20e;
  579. Xstatic`20char`20hcnt`5BBOARDSIZE`5D;`09/*`20number`20of`20pieces`20to`20highli
  580. Vght`20*/
  581. X
  582. Xfor`20(i`20=`200;`20i`20<`20BOARDSIZE;`20i++)
  583. X`09hcnt`5Bi`5D`20=`200;`09`09/*`20init`20to`20no`20highlight`20*/
  584. Xif`20(mvs`20!=`20NULL)`20`7B`09/*`20find`20all`20points`20that`20should`20be
  585. V`20highlighted`20*/
  586. X`09for`20(i`20=`200;`20i`20<`204;`20i++)`20`7B
  587. X`09`09if`20(`20(mvs`5Bi`5D.roll`20<=`200)`20`7C`7C`20(`20(s`20=`20mvs`5Bi`5D.p
  588. Vt)`20<`200)`20)
  589. X`09`09`09continue;`09/*`20this`20move`20is`20unused`20*/
  590. X`09`09if`20(`20(s`20<`201)`20`7C`7C`20(s`20>`2024)`20)`09/*`20if`20coming`20of
  591. Vf`20bar`20*/
  592. X`09`09`09s`20=`20BARPT(dir);`09`09/*`20use`20correct`20bar`20point`20*/
  593. X`09`09e`20=`20s`20+`20dir*mvs`5Bi`5D.roll;`09/*`20add`20in`20the`20roll`20used
  594. V`20*/
  595. X`09`09if`20(`20(e`20<`201)`20`7C`7C`20(e`20>`2024)`20)`09/*`20off`20the`20boar
  596. Vd`20*/
  597. X`09`09`09e`20=`20OFFPT(dir);`09/*`20use`20correct`20off`20point`20*/
  598. X`09`09if`20(sd`20>`200)`20`7B`09`09`09/*`20we`20are`20showing`20dest`20*/
  599. X`09`09`09hcnt`5Be`5D++;`09`09/*`20inc`20destination`20count`20*/
  600. X`09`09`09hcnt`5Bs`5D--;`09`09/*`20handle`20continued`20moves`20*/
  601. X`09`09`09`7D
  602. X`09`09else`20`7B`09`09`09`09/*`20we`20are`20showing`20start`20*/
  603. X`09`09`09hcnt`5Bs`5D++;`09`09/*`20inc`20start`20count`20*/
  604. X`09`09`09hcnt`5Be`5D--;`09`09/*`20handle`20continued`20moves`20*/
  605. X`09`09`09`7D
  606. X`09`09`7D
  607. X`09`7D
  608. Xfor`20(i`20=`200;`20i`20<`20BOARDSIZE;`20i++)`09`09/*`20draw`20each`20point
  609. V`20*/
  610. X`09FeDrawPoint(b,i,hcnt`5Bi`5D,inv);
  611. X`7D
  612. X
  613. X
  614. X/*----------------------------------------------------------------------
  615. X`20*`09FeLabelBoard`20--`20draw`20board`20info
  616. X`20*
  617. X`20*`20This`20function`20displays`20information`20about`20the`20board`20curren
  618. Vtly
  619. X`20*`20being`20displayed.`20`20This`20includes`20its`20label,`20any`20special
  620. V`20rule`20flags,
  621. X`20*`20and`20the`20current`20match`20score.
  622. X`20*----------------------------------------------------------------------
  623. X`20*/
  624. X
  625. XFeLabelBoard(g)
  626. Xstruct`20game`20*g;
  627. X`7B
  628. Xint`20i;
  629. Xstatic`20char`20*bdlbl`5B`5D`20=`20`7B"Bef",`20"Aft",`20"Cur"`7D;
  630. X
  631. Xmvaddstr(1,5,BLANKS(24));`09`09/*`20clear`20old`20stuff`20*/
  632. Xmvaddstr(1,5,bdlbl`5Bg->curbd`5D);`09`09/*`20draw`20the`20board`20label`20*/
  633. Xif`20(g->flags`20`26`20F_JACOBY)`09`09/*`20label`20special`20rules`20flags`20*
  634. V/
  635. X`09mvaddch(1,10,'J');
  636. Xif`20(g->flags`20`26`20F_CRAWFORD)`20`7B
  637. X`09if`20(g->flags`20`26`20F_CRGAME)`09/*`20if`20this`20is`20crawford`20rule
  638. V`20game`20*/
  639. X`09`09PReverseText();`09`09/*`20highlight`20the`20C`20indicator`20*/
  640. X`09mvaddch(1,11,'C');
  641. X`09if`20(g->flags`20`26`20F_CRGAME)
  642. X`09`09PEndReverse();
  643. X`09`7D
  644. Xif`20(g->flags`20`26`20F_EUROPE)
  645. X`09mvaddch(1,12,'E');
  646. Xif`20(g->flags`20`26`20F_PERM)
  647. X`09mvaddch(1,13,'P');
  648. Xif`20(g->mtotal`20>`200)`20`7B`09`09`09/*`20if`20this`20is`20a`20match`20*/
  649. X`09move(1,16);`09`09`09/*`20draw`20the`20match`20score`20*/
  650. X`09printw("%02d:%02d`20to`20%2d",
  651. X`09`09g->mcurrent`5BWHO_ME`5D,`20g->mcurrent`5BWHO_OPP`5D,`20g->mtotal);
  652. X`09`7D
  653. XFeCheckContact(g);
  654. X`7D
  655. X
  656. X
  657. X
  658. X
  659. X/*----------------------------------------------------------------------
  660. X`20*`09FeCheckContact`20--`20check`20for`20contact`20after`20a`20move`20is`20m
  661. Vade.
  662. X`20*
  663. X`20*`20This`20routine`20keeps`20the`20BAR`20indicator`20up`20to`20date`20as
  664. V`20moves`20are`20made.
  665. X`20*`20The`20BAR`20indicator`20changes`20to`20"---"`20when`20no`20further`20co
  666. Vntact`20is
  667. X`20*`20possible`20for`20a`20game.`20`20Note`20that`20the`20BAR`20indicator`20o
  668. Vnly`20reflects
  669. X`20*`20the`20value`20of`20the`20current`20board,`20and`20is`20not`20affected
  670. V`20by`20which
  671. X`20*`20board`20is`20being`20displayed.
  672. X`20*----------------------------------------------------------------------
  673. X`20*/
  674. X
  675. XFeCheckContact(g)
  676. Xstruct`20game`20*g;
  677. X`7B
  678. X
  679. Xif`20(iscontact(g))`09`09`09/*`20if`20contact`20is`20possible`20*/
  680. X`09mvaddstr(10,30,"BAR");`09`09/*`20draw`20BAR`20label`20*/
  681. Xelse`09`09`09`09`09/*`20change`20BAR`20indicator`20to`20*/
  682. X`09mvaddstr(10,30,"---");`09`09/*`20no`20contact`20indicator`20*/
  683. X`7D
  684. X
  685. X
  686. X/*----------------------------------------------------------------------
  687. X`20*`09FeGetPoint`20--`20read`20a`20point`20number`20from`20the`20user
  688. X`20*
  689. X`20*`20This`20function`20prompts`20the`20user`20for`20a`20point`20number.`20
  690. V`20The`20user`20types
  691. X`20*`20the`20input`20on`20the`20line`20of`20the`20move`20block`20corresponding
  692. V`20to`20the
  693. X`20*`20roll`20being`20used.`20`20Normally,`20the`20input`20is`20a`20number`20b
  694. Vetween`201`20and`2024.`20`20
  695. X`20*`20Point`20numbers`20are`20two`20digits`20unless:
  696. X`20*`09-`20The`20first`20digit`20is`203`20..`209.
  697. X`20*`20OR`09-`20The`20first`20digit`20is`201`20and`20there`20is`20no`20point
  698. V`20in`2010`20..`2019
  699. X`20*`09`20`20that`20could`20use`20the`20selected`20roll.
  700. X`20*`20OR`09-`20The`20first`20digit`20is`202`20and`20there`20is`20no`20point
  701. V`20in`2020`20..`2024
  702. X`20*`09`20`20that`20could`20use`20the`20selected`20roll.
  703. X`20*`20Otherwise,`20there`20must`20be`20a`20non-digit`20entered`20to`20finish
  704. V`20a`201-digit
  705. X`20*`20point`20number.`20`20Alternatively,`20the`20user`20may`20enter`20them
  706. X`20*`20with`20a`20leading`200.`20`20There`20are`20a`20number`20of`20special
  707. V`20characters`20that
  708. X`20*`20are`20also`20recognized:
  709. X`20*`09char`09`09`09return`20value
  710. X`20*`09---------------------------------------------------------------
  711. X`20*`09space`09`09`09the`20"spdflt"`20argument.
  712. X`20*`09return/linefeed`09`09the`20"crdflt"`20argument.
  713. X`20*`09DEL/ESC/BS`09`09cancel`20move.
  714. X`20*`09p/P`09`09`09the`20point`20from`20which`20a`20piece`20would`20have
  715. X`20*`09`09`09`09to`20be`20moved`20to`20land`20on`20spdflt.
  716. X`20*`09o/O`09`09`09The`20point`20from`20which`20the`20selected`20roll
  717. X`20*`09`09`09`09could`20be`20used`20to`20bear`20off.`20`20If`20that`20point
  718. X`20*`09`09`09`09is`20unoccupied,`20the`20next`20lower`20occupied
  719. X`20*`09`09`09`09point`20is`20returned.
  720. X`20*`20If`20there`20are`20pieces`20on`20the`20bar,`20the`20bar`20point`20is
  721. V`20returned`20immediately,
  722. X`20*`20since`20there`20could`20be`20no`20other`20possible`20choice`20the`20use
  723. Vr`20would`20make.
  724. X`20*----------------------------------------------------------------------
  725. X`20*/
  726. X
  727. XFeGetPoint(g,r,crdflt,spdflt)
  728. Xstruct`20game`20*g;`09`09`09`09/*`20game`20structure`20*/
  729. Xint`20r;`09`09`09`09`09/*`20which`20row`20in`20move`20block`20*/
  730. Xint`20crdflt;`09`09`09`09/*`20what`20to`20return`20for`20cr/nl`20*/
  731. Xint`20spdflt;`09`09`09`09/*`20what`20to`20return`20for`20space`20*/
  732. X`7B
  733. Xint`20n,`20row;
  734. Xchar`20buf`5B4`5D;
  735. X
  736. X
  737. Xif`20(g->board`5BBARPT(g->mydir)`5D.qty`20>`200)`09/*`20pieces`20on`20the`20ba
  738. Vr`20*/
  739. X`09return(BARPT(g->mydir));`09/*`20no`20need`20to`20even`20ask`20*/
  740. Xrow`20=`20r;
  741. Xif`20(g->flags`20`26`20F_INVERT)`09`09/*`20which`20move`20block`20do`20I`20use
  742. V?`20*/
  743. X`09row`20+=`20(g->mydir`20<`200)`20?`205`20:`2014;`09/*`20inverted`20board`20*
  744. V/
  745. Xelse
  746. X`09row`20+=`20(g->mydir`20>`200)`20?`205`20:`2014;`09/*`20normal`20board`20*/
  747. Xmove(row,69);
  748. Xclrtoeol();
  749. Xmove(row,69);
  750. Xrefresh();
  751. X*buf`20=`20PGetChr(0,1);
  752. Xif`20(`20(*buf`20==`20'`5Cn')`20`7C`7C`20(*buf`20==`20'`5Cr')`20)`09/*`20retur
  753. Vn`20means`20repeat`20move`20*/
  754. X`09return(crdflt);
  755. Xif`20(*buf`20==`20'`20')`09`09`09/*`20space`20means`20continue`20move`20*/
  756. X`09return(spdflt);
  757. Xif`20(`20(*buf`20==`20'`5C177')`20`7C`7C`20(*buf`20==`20'`5C033')`20`7C`7C`20(
  758. V*buf`20==`20'`5Cb')`20)
  759. X`09return(-1);`09`09`09/*`20DEL/ESC/BS`20means`20cancel`20move`20*/
  760. Xif`20(`20(*buf`20==`20'b')`20`7C`7C`20(*buf`20==`20'B')`20)`09/*`20bar`20*/
  761. X`09return(BARPT(g->mydir));
  762. Xif`20(`20(*buf`20==`20'p')`20`7C`7C`20(*buf`20==`20'P')`20)`20`7B`09/*`20P`20m
  763. Veans`20spdflt`20-`20roll*dir`20*/
  764. X`09n`20=`20spdflt`20-`20g->mvs`5Br`5D.roll*g->mydir;`09/*`20make`20point`20*/
  765. X`09if`20(`20(n`20<`201)`20`7C`7C`20(n`20>`2024)`20)`09`09/*`20not`20on`20board
  766. V`20*/
  767. X`09`09n`20=`2099;`09`09`09`09/*`20force`20invalid`20point`20*/
  768. X`09return(n);
  769. X`09`7D
  770. Xif`20(`20(*buf`20==`20'o')`20`7C`7C`20(*buf`20==`20'O')`20)`20`7B`09/*`20O`20m
  771. Veans`20bear`20a`20piece`20off`20*/
  772. X`09n`20=`20(`20(g->mydir`20>`200)`20?`2025`20:`200`20)`20-`20g->mydir*g->mvs
  773. V`5Br`5D.roll;
  774. X`09while`20(`20(n`20>`200)`20`26`26`20(n`20<=`2024)`20`26`26
  775. X`09`20`20`20(`20(g->board`5Bn`5D.qty`20<=`200)`20`7C`7C`20(g->board`5Bn`5D.col
  776. Vor`20!=`20g->mycolor))`20)
  777. X`09`09n`20+=`20g->mydir;
  778. X`09if`20(`20(n`20<`201)`20`7C`7C`20(n`20>`2024)`20)`09/*`20no`20piece`20found
  779. V`20*/
  780. X`09`09n`20=`2099;`09`09`09/*`20force`20invalid`20point`20*/
  781. X`09return(n);
  782. X`09`7D
  783. Xif`20(`20!`20isdigit(*buf))
  784. X`09return(99);`09`09`09/*`20force`20invalid`20point`20message`20*/
  785. Xif`20(`20(*buf`20>=`20'3')`20`26`26`20(*buf`20<=`20'9')`20)`09/*`203`20..`209
  786. V`20*/
  787. X`09return(*buf`20-`20'0');`09`09/*`20don't`20bother`20with`202nd`20digit`20*/
  788. Xif`20(*buf`20==`20'1')`20`7B`09`09`09/*`20look`20for`20valid`20move`20in`2010
  789. V`20..`2019`20*/
  790. X`09if`20(canmove(g,r,10,19)`20==`200)`09/*`20no`20valid`20move`20*/
  791. X`09`09return(1);`09`09/*`20don't`20bother`20with`20second`20digit`20*/
  792. X`09`7D
  793. Xelse`20if`20(*buf`20==`20'2')`20`7B`09`09`09/*`20look`20for`20valid`20move`20i
  794. Vn`2020`20..`2024`20*/
  795. X`09if`20(canmove(g,r,20,24)`20==`200)`09/*`20no`20valid`20move`20*/
  796. X`09`09return(2);`09`09/*`20don't`20bother`20with`20second`20digit`20*/
  797. X`09`7D
  798. Xaddch(*buf);`09`09`09`09/*`20echo`20the`20char`20*/
  799. Xrefresh();
  800. Xbuf`5B1`5D`20=`20PGetChr(0,1);
  801. Xbuf`5B2`5D`20=`20'`5C0';`09`09`09`09/*`20null`20terminate`20*/
  802. Xif`20(`20((n`20=`20atoi(buf))`20==`20UPBAR)`20`7C`7C`20(n`20==`20DOWNBAR)`20)
  803. X`09return(BARPT(g->mydir));
  804. Xreturn(n);
  805. X`7D
  806. X
  807. X
  808. X/*----------------------------------------------------------------------
  809. X`20*`09PGetChr`20--`20get`20a`20single`20character
  810. X`20*
  811. X`20*`20This`20function`20gets`20one`20character`20from`20the`20user`20and`20re
  812. Vturns`20it.
  813. X`20*`20If`20the`20"e"`20argument`20is`20non-zero,`20the`20character`20is`20ech
  814. Voed`20at`20the
  815. X`20*`20current`20cursor`20position.`20`20If`20the`20"h"`20argument`20is`20non-
  816. Vzero,`20the
  817. X`20*`20online`20help`20is`20displayed`20by`20pressing`20"H",`20"h",`20or`20"?"
  818. V.`20`20The`20`5EL`20and`20`5ER
  819. X`20*`20characters`20are`20intercepted`20and`20cause`20the`20screen`20to`20be
  820. V`20redrawn`20without
  821. X`20*`20returning`20from`20PGetChr.`20`20Null`20characters`20are`20discarded.
  822. X`20*----------------------------------------------------------------------
  823. X`20*/
  824. X
  825. XPRIVATE`20char`20PGetChr(e,h)
  826. Xint`20e,`20h;
  827. X`7B
  828. Xchar`20c;
  829. Xint`20y,`20x;
  830. X
  831. X#ifdef`20VMS
  832. Xchar`20Prompt`5B4`5D`20=`20"_$`20";
  833. Xstruct`20dsc$descriptor_s`20*cmd`20=`200,`20*prmpt=0;
  834. X$DESCRIPTOR(cm_dsc,rc.supercmd);
  835. X$DESCRIPTOR(prmpt_dsc,Prompt);
  836. X#endif
  837. X
  838. Xloop:
  839. Xif`20(`20(c`20=`20getch()`20`26`200x7f)`20==`20'`5C0')
  840. X`09goto`20loop;
  841. Xif`20(`20(c`20==`200x0c)`20`7C`7C`20(c`20==`200x12)`20)`20`7B`09/*`20`5EL`20or
  842. V`20`5ER?`20*/
  843. X`09clearok(curscr,`20TRUE);
  844. X`09wrefresh(curscr);`09/*`20repaint`20current`20screen`20*/
  845. X`09goto`20loop;`09`09/*`20and`20get`20another`20char`20*/
  846. X`09`7D
  847. Xif`20(c`20==`20rc.superkey)`20`7B`09`09`09/*`20uh`20oh,`20we're`20busted`20*/
  848. X`09getyx(stdscr,y,x);`09`09/*`20save`20old`20cursor`20postition`20*/
  849. X`09PClearScreen();`09`09`09/*`20get`20the`20screen`20cleared`20fast`20*/
  850. X`09nl();`09`09`09`09/*`20set`20tty`20back`20to`20normal`20*/
  851. X`09nocbreak();
  852. X`09echo();
  853. X#ifdef`20VMS
  854. X`09cm_dsc.dsc$w_length`20=`20strlen(rc.supercmd);`09/*`20length`20of`20cmd`20*
  855. V/
  856. X`09cmd`20=`20`26cm_dsc;`09`09`09/*`20set`20up`20the`20command`20argument`20*/
  857. X`09prmpt_dsc.dsc$w_length`20=`20strlen(Prompt);
  858. X`09prmpt`20=`20`26prmpt_dsc;`09`09`09/*`20set`20up`20the`20command`20argument
  859. V`20*/
  860. X`09lib$spawn(cmd,0,0,0,0,0,0,0,0,0,prmpt,0);`09/*`20spawn`20a`20subprocess`20*
  861. V/
  862. X#else
  863. X`09system(rc.supercmd);`09`09/*`20run`20the`20supervisor`20command`20*/
  864. X#endif
  865. X`09noecho();
  866. X`09cbreak();
  867. X`09nonl();`09`09`09`09/*`20ok,`20we're`20safe`20again`20*/
  868. X`09PClearScreen();`09`09`09/*`20clear`20old`20junk`20*/
  869. X`09clearok(curscr,`20TRUE);
  870. X`09wrefresh(curscr);`09`09/*`20repaint`20current`20screen`20*/
  871. X`09move(y,x);`09`09`09/*`20put`20cursor`20back`20where`20it`20was`20*/
  872. X`09refresh();
  873. X`09goto`20loop;`09`09`09/*`20and`20get`20another`20character`20*/
  874. X`09`7D
  875. Xif`20(h`20`26`26`20(c`20==`20'?'`20`7C`7C`20c`20==`20'h'`20`7C`7C`20c`20==`20'
  876. VH'))`20`7B`09/*`20user`20needs`20help`20*/
  877. X`09dohelp();`09`09`09/*`20give`20it`20to`20'em`20*/
  878. X`09touchwin(stdscr);`09`09/*`20Make`20sure`20the`20screen`20gets`20updated`20*
  879. V/
  880. X`09wrefresh(stdscr);`09`09/*`20Now`20refresh`20it`20*/
  881. X`09goto`20loop;`09`09`09/*`20and`20get`20another`20character`20*/
  882. X`09`7D
  883. Xif`20(h`20`26`26`20(c`20==`20'%'`20`7C`7C`20c`20==`20'#'))`20`7B`09/*`20user
  884. V`20wants`20stats`20*/
  885. X`09dostats(Current_Game);`09`09/*`20give`20it`20to`20'em`20*/
  886. X`09touchwin(stdscr);`09`09/*`20Make`20sure`20the`20screen`20gets`20updated`20*
  887. V/
  888. X`09wrefresh(stdscr);`09`09/*`20Now`20refresh`20it`20*/
  889. X`09goto`20loop;`09`09`09/*`20and`20get`20another`20character`20*/
  890. X`09`7D
  891. Xif`20(e`20`26`26`20isprint(c))`20`7B`09`09/*`20echo`20char?`20*/
  892. X`09addch(c);`09`09/*`20yup`20*/
  893. X`09refresh();
  894. X`09`7D
  895. Xreturn(c);
  896. X`7D
  897. X
  898. X
  899. X/*----------------------------------------------------------------------
  900. X`20*`09PClearScreen`20--`20clear`20the`20screen`20somehow
  901. X`20*
  902. X`20*`20This`20function`20clears`20the`20physical`20display`20without`20affecti
  903. Vng`20what
  904. X`20*`20the`20curses`20package`20thinks`20is`20there.`20`20If`20the`20"cl"`20(c
  905. Vlear`20screen)
  906. X`20*`20capability`20is`20defined,`20it`20uses`20that.`20`20If`20that`20fails,
  907. V`20it`20tries
  908. X`20*`20to`20move`20to`200,0`20and`20use`20the`20"cd"`20(clear`20to`20end`20of
  909. V`20display).
  910. X`20*`20Failing`20that,`20it`20goes`20to`20the`20bottom`20of`20the`20screen`20a
  911. Vnd`20scrolls
  912. X`20*`20it`2024`20times.
  913. X`20*----------------------------------------------------------------------
  914. X`20*/
  915. X
  916. X#ifndef`20vaxc
  917. XPRIVATE`20PClearScreen()
  918. X`7B
  919. Xchar`20*s,`20*x,`20buf`5B80`5D;
  920. X
  921. Xx`20=`20buf;
  922. Xif`20(`20(s`20=`20tgetstr("cl",`26x))`20==`20NULL)`20`7B`09`09/*`20no`20clear
  923. V`20screen`20*/
  924. X`09if`20(`20(s`20=`20tgetstr("cd",`26x))`20!=`20NULL)`20`7B`09/*`20do`20we`20h
  925. Vave`20clr`20to`20end?`20*/
  926. X`09`09move(0,0);`09`09/*`20yup,`20use`20it`20*/
  927. X`09`09refresh();
  928. X`09`09fputs(s,stdout);
  929. X`09`09`7D
  930. X`09else`20`7B`09`09`09/*`20well,`20do`20it`20the`20hard`20way`20*/
  931. X`09`09move(23,0);
  932. X`09`09refresh();
  933. X`09`09printf("`5Cn`5Cn`5Cn`5Cn`5Cn`5Cn`5Cn`5Cn`5Cn`5Cn`5Cn`5Cn`5Cn`5Cn`5Cn`5Cn
  934. V`5Cn`5Cn`5Cn`5Cn`5Cn`5Cn`5Cn`5Cn`5Cn");
  935. X`09`09`7D
  936. X`09`7D
  937. Xelse
  938. X`09fputs(s,stdout);`09/*`20send`20clear`20screen`20*/
  939. Xfflush(stdout);`09`09`09/*`20git`20along,`20li'l`20characters`20*/
  940. X`7D
  941. X#endif
  942. X
  943. X
  944. X/*----------------------------------------------------------------------
  945. X`20*`09FeGetComment`20--`20prompt`20for`20a`20comment`20to`20send`20along`20wi
  946. Vth`20a`20move
  947. X`20*
  948. X`20*`20This`20function`20allows`20the`20user`20to`20enter`20a`202-line`20comme
  949. Vnt.`20`20If`20the
  950. X`20*`20user`20types`20a`20non-empty`20string,`20it`20is`20stored`20in`20the
  951. V`20mycmt/mycmt2
  952. X`20*`20fields`20of`20the`20game`20structure`20passed`20as`20an`20argument.`20
  953. V`20The`20previous`20comment,
  954. X`20*`20if`20any,`20is`20discarded.`20`20The`20number`20of`20lines`20read`20is
  955. V`20returned,
  956. X`20*`20or`20-1`20if`20PGetString`20was`20terminated`20by`20ESC.`20`20This`20ha
  957. Vs`20the`20effect`20of
  958. X`20*`20aborting`20the`20Send`20command.
  959. X`20*----------------------------------------------------------------------
  960. X`20*/
  961. X
  962. XFeGetComment(g)
  963. Xstruct`20game`20*g;
  964. X`7B
  965. Xchar`20buf`5B120`5D;
  966. Xchar`20*lptrs`5B2`5D;
  967. Xint`20n;
  968. X
  969. Xn`20=`20PGetString(buf,56,lptrs,2,19,6);`09/*`20get`20new`20comment`20*/
  970. Xif`20(n`20<`200)`20`7B`09`09`09/*`20user`20hit`20escape,`20back`20out`20of`20s
  971. Vend`20*/
  972. X`09PDrawComment(WHO_ME,`20g);`09`09/*`20put`20my`20old`20comment`20back`20*/
  973. X`09return(-1);`09`09`09/*`20return`20"escape"`20code`20*/
  974. X`09`7D
  975. Xif`20(g->mycmt`20!=`20NULL)`09`09/*`20throw`20away`20old`20comment`20*/
  976. X`09free(g->mycmt);
  977. Xif`20(g->mycmt2`20!=`20NULL)
  978. X`09free(g->mycmt2);
  979. Xif`20(n`20>`200)
  980. X`09g->mycmt`20=`20save(lptrs`5B0`5D);`09/*`20save`20first`20line`20*/
  981. Xelse
  982. X`09g->mycmt`20=`20NULL;`09/*`20mark`20comment`20as`20empty`20*/
  983. Xif`20(n`20>`201)
  984. X`09g->mycmt2`20=`20save(lptrs`5B1`5D);`09/*`20save`20second`20line`20*/
  985. Xelse
  986. X`09g->mycmt2`20=`20NULL;
  987. Xreturn(n);
  988. X`7D
  989. X
  990. X
  991. X
  992. X/*----------------------------------------------------------------------
  993. X`20*`09PGetString`20--`20read`20a`20multi-line`20string`20from`20the`20user
  994. X`20*
  995. X`20*`20This`20function`20allows`20the`20user`20to`20enter`20multiple`20lines
  996. V`20of`20a`20fixed`20maximum
  997. X`20*`20length.`20`20The`20normal`20line`20editing`20characters`20are`20recogni
  998. Vzed`20and
  999. X`20*`20processed.`20`20These`20include:
  1000. X`20*`09DEL/BS`09`09The`20character`20before`20the`20cursor`20is`20deleted.
  1001. X`20*`09`5EX/`5EU`09`09The`20entire`20line`20is`20erased.
  1002. X`20*`09`5EL/`5ER`09`09The`20screen`20is`20redrawn.
  1003. X`20*`09`5EW/`5EB`09`09The`20word`20before`20the`20cursor`20is`20erased.
  1004. X`20*`20Typing`20past`20the`20end`20of`20a`20line`20automatically`20causes`20a
  1005. V`20word-
  1006. X`20*`20wrap`20to`20the`20next`20line.`20`20Words`20are`20delimited`20by`20spac
  1007. Ves.`20`20Typing
  1008. X`20*`20a`20carriage`20return`20or`20line`20feed`20on`20the`20last`20line,`20or
  1009. V`20on`20an`20empty
  1010. X`20*`20line,`20terminates`20PGetString;`20otherwise,`20it`20moves`20to`20the
  1011. V`20next`20line.
  1012. X`20*`20ESC`20terminates`20PGetString`20regardless`20of`20the`20cursor`20positi
  1013. Von.
  1014. X`20*`20Backspacing`20from`20the`20beginning`20of`20one`20line`20to`20the`20end
  1015. V`20of`20the`20previous
  1016. X`20*`20is`20allowed.`20`20PGetString`20returns`20the`20number`20of`20lines`20e
  1017. Vntered,
  1018. X`20*`20or`20-1`20if`20it`20was`20terminated`20by`20an`20ESC.
  1019. X`20*----------------------------------------------------------------------
  1020. X`20*/
  1021. X
  1022. XPRIVATE`20PGetString(buf,len,lines,nls,y,x)
  1023. Xchar`20*buf,`20*lines`5B`5D;
  1024. Xint`20len,`20nls,`20y,`20x;
  1025. X`7B
  1026. Xchar`20c,`20*bp,`20*p;
  1027. Xint`20cl,`20l;
  1028. X
  1029. Xfor`20(cl`20=`200;`20cl`20<`20nls;`20cl++)`20`7B
  1030. X`09lines`5Bcl`5D`20=`20NULL;`09`09/*`20clear`20line`20pointers`20*/
  1031. X`09mvaddstr(y+cl,x,BLANKS(len));`09/*`20clear`20line`20*/
  1032. X`09`7D
  1033. Xcl`20=`200;`09`09`09`09`09/*`20current`20line`20=`200`20*/
  1034. Xl`20=`200;`09`09`09`09/*`20length`20of`20current`20line`20*/
  1035. Xmove(y,x);`09`09`09/*`20go`20to`20first`20location`20in`20field`20*/
  1036. Xbp`20=`20buf;`09`09`09/*`20ptr`20to`20next`20storage`20location`20*/
  1037. Xlines`5B0`5D`20=`20buf;`09`09`09/*`20init`20first`20line`20pointer`20*/
  1038. Xrefresh();
  1039. Xwhile`20(1)`20`7B
  1040. X`09switch`20(c`20=`20PGetChr(0,0))`20`7B
  1041. X`09case`20'`5C177':`09`09/*`20DEL`20*/
  1042. X`09case`20'`5Cb':`09`09/*`20BS`20*/
  1043. X`09`09if`20(l`20<=`200)`20`7B`09/*`20at`20beginning`20of`20line`20*/
  1044. X`09`09`09if`20(cl`20<=`200)`09/*`20on`20first`20line`20*/
  1045. X`09`09`09`09break;`09`09/*`20nothing`20to`20delete`20*/
  1046. X`09`09`09cl--;`09`09/*`20back`20up`20one`20line`20*/
  1047. X`09`09`09*--bp`20=`20'`5C0';`09/*`20back`20up`20buffer`20pointer`20*/
  1048. X`09`09`09l`20=`20strlen(lines`5Bcl`5D);`09/*`20load`20line`20length`20*/
  1049. X`09`09`09move(y+cl,x+l);`09/*`20move`20cursor`20to`20end`20of`20prev`20line
  1050. V`20*/
  1051. X`09`09`09`7D
  1052. X`09`09else`20`7B
  1053. X`09`09`09bp--;`09`09/*`20back`20up`20buffer`20pointer`20*/
  1054. X`09`09`09l--;`09`09/*`20decrement`20length`20*/
  1055. X`09`09`09move(y+cl,x+l);
  1056. X`09`09`09addch('`20');`09/*`20erase`20the`20char`20from`20the`20screen`20*/
  1057. X`09`09`09move(y+cl,x+l);
  1058. X`09`09`09`7D
  1059. X`09`09refresh();
  1060. X`09`09break;
  1061. X`09case`20'`5C2':`09`09/*`20`5EB`20--`20erase`20previous`20character`20*/
  1062. X`09case`20'`5C27':`09`09/*`20`5EW`20*/
  1063. X`09`09if`20(l`20<=`200)`20`7B`09`09/*`20beginning`20of`20line`20*/
  1064. X`09`09`09if`20(cl`20<=`200)`09/*`20on`20first`20line`20*/
  1065. X`09`09`09`09break;`09`09/*`20nothing`20to`20delete`20*/
  1066. X`09`09`09cl--;`09`09/*`20back`20up`20one`20line`20*/
  1067. X`09`09`09*--bp`20=`20'`5C0';`09/*`20back`20up`20buffer`20pointer`20*/
  1068. X`09`09`09l`20=`20strlen(lines`5Bcl`5D);`09/*`20load`20line`20length`20*/
  1069. X`09`09`09`7D
  1070. X`09`09while`20(l`20>`200)`20`7B`09`09/*`20skip`20leading`20spaces,`20if`20any
  1071. V`20*/
  1072. X`09`09`09if`20(*--bp`20!=`20'`20')`20`7B
  1073. X`09`09`09`09bp++;
  1074. X`09`09`09`09break;
  1075. X`09`09`09`09`7D
  1076. X`09`09`09l--;
  1077. X`09`09`09*bp`20=`20'`5C0';
  1078. X`09`09`09`7D
  1079. X`09`09while`20(l`20>`200)`20`7B`09`09/*`20delete`20to`20last`20space`20*/
  1080. X`09`09`09if`20(*--bp`20==`20'`20')`20`7B
  1081. X`09`09`09`09bp++;
  1082. X`09`09`09`09break;
  1083. X`09`09`09`09`7D
  1084. X`09`09`09*bp`20=`20'`5C0';
  1085. X`09`09`09l--;
  1086. X`09`09`09mvaddch(y+cl,x+l,'`20');
  1087. X`09`09`09`7D
  1088. X`09`09move(y+cl,x+l);
  1089. X`09`09refresh();
  1090. X`09`09break;
  1091. X`09case`20'`5C33':`09`09/*`20ESC`20*/
  1092. X`09`09*bp++`20=`20'`5C0';`09`09/*`20terminate`20the`20string`20*/
  1093. X`09`09return(-1);`09`09/*`20return`20abort`20code`20*/
  1094. X`09case`20'`5Cr':`09`09/*`20CR`20*/
  1095. X`09case`20'`5Cn':`09`09/*`20NL`20*/
  1096. X`09`09*bp++`20=`20'`5C0';`09/*`20terminate`20the`20string`20*/
  1097. X`09`09if`20(l`20<=`200)`09`09/*`20empty`20line`20*/
  1098. X`09`09`09return(cl);`09/*`20don't`20include`20it`20in`20#lines`20*/
  1099. X`09`09if`20(cl`20>=`20nls-1)`09`09/*`20last`20line`20*/
  1100. X`09`09`09return(cl+1);`09/*`20return`20number`20of`20lines`20*/
  1101. X`09`09lines`5B++cl`5D`20=`20bp;`09/*`20go`20to`20next`20line`20*/
  1102. X`09`09l`20=`200;
  1103. X`09`09move(y+cl,x);
  1104. X`09`09refresh();
  1105. X`09`09break;
  1106. X`09case`20'`5C30':`09`09/*`20`5EX`20--`20erase`20entire`20line`20`26`20goto
  1107. V`20prev`20line`20*/
  1108. X`09case`20'`5C25':`09`09/*`20`5EU`20*/
  1109. X`09`09mvaddstr(y+cl,x,BLANKS(len));
  1110. X`09`09if`20(cl`20>`200)`20`7B`09/*`20back`20up`20one`20line`20*/
  1111. X`09`09`09bp`20=`20lines`5Bcl--`5D`20-`201;
  1112. X`09`09`09l`20=`20strlen(lines`5Bcl`5D);
  1113. X`09`09`09`7D
  1114. X`09`09else`20`7B`09`09/*`20already`20on`20top`20line,`20go`20to`20beginning
  1115. V`20*/
  1116. X`09`09`09bp`20=`20buf;
  1117. X`09`09`09l`20=`200;
  1118. X`09`09`09`7D
  1119. X`09`09move(y+cl,x+l);
  1120. X`09`09refresh();
  1121. X`09`09break;
  1122. X`09case`20'`5Ct':`09`09`09/*`20convert`20tab`20to`20a`20space`20*/
  1123. X`09`09c`20=`20'`20';
  1124. X`09`09/*`20fall`20through`20*/
  1125. X`09default:
  1126. X`09`09if`20(iscntrl(c))`7B`09`09/*`20bad`20char`20*/
  1127. X`09`09`09fputc('`5C7',stderr);`09/*`20beep`20*/
  1128. X`09`09`09fflush(stderr);
  1129. X`09`09`09break;`09`09`09/*`20`26`20ignore`20character`20*/
  1130. X`09`09`09`7D
  1131. X`09`09if`20(l`20>=`20len)`20`7B`09`09/*`20typed`20up`20to`20end`20of`20line
  1132. V`20*/
  1133. X`09`09`09if`20(cl`20>=`20nls-1)`20`7B`09/*`20last`20line,`20can't`20go`20on
  1134. V`20*/
  1135. X`09`09`09`09fputc('`5C7',stderr);`09/*`20beep`20*/
  1136. X`09`09`09`09fflush(stderr);
  1137. X`09`09`09`09break;`09`09/*`20`26`20ignore`20character`20*/
  1138. X`09`09`09`09`7D
  1139. X`09`09`09*bp++`20=`20c;`09`09/*`20store`20rcvd`20char`20*/
  1140. X`09`09`09for`20(p`20=`20bp-1;`20(l`20>`200)`20`26`26`20(!`20isspace(*p));`20p-
  1141. V-,`20l--);
  1142. X`09`09`09if`20(`20(p`20<=`20buf)`20`7C`7C`20(*p`20==`20'`5C0')`20)`20`7B
  1143. X`09`09`09`09*bp++`20=`20'`5C0';
  1144. X`09`09`09`09lines`5B++cl`5D`20=`20bp;`09/*`20didn't`20find`20word`20*/
  1145. X`09`09`09`09l`20=`200;
  1146. X`09`09`09`09`7D
  1147. X`09`09`09else`20`7B
  1148. X`09`09`09`09*p++`20=`20'`5C0';`09/*`20terminate`20previous`20line`20*/
  1149. X`09`09`09`09mvaddstr(y+cl,x,BLANKS(len));`09/*`20redraw`20*/
  1150. X`09`09`09`09mvaddstr(y+cl,x,lines`5Bcl`5D);`09/*`20w/o`20word`20*/
  1151. X`09`09`09`09lines`5B++cl`5D`20=`20p;`09/*`20start`20new`20line`20*/
  1152. X`09`09`09`09*bp`20=`20'`5C0';`09`09/*`20terminate`20word`20*/
  1153. X`09`09`09`09l`20=`20strlen(p);`09`09/*`20set`20line`20len`20*/
  1154. X`09`09`09`09mvaddstr(y+cl,x,p);`09/*`20draw`20word`20*/
  1155. X`09`09`09`09`7D
  1156. X`09`09`09move(y+cl,x+l);
  1157. X`09`09`09`7D
  1158. X`09`09else`20`7B
  1159. X`09`09`09*bp++`20=`20c;`09`09/*`20put`20char`20in`20string`20*/
  1160. X`09`09`09l++;`09`09`09/*`20bump`20length`20*/
  1161. X`09`09`09addch(c);`09`09/*`20echo`20char`20to`20screen`20*/
  1162. X`09`09`09`7D
  1163. X`09`09refresh();
  1164. X`09`09break;
  1165. X`09`09`7D
  1166. X`09`7D
  1167. X`7D
  1168. X
  1169. X
  1170. X/*----------------------------------------------------------------------
  1171. X`20*`09FeDrawMenu`20--`20draw`20menu`20choices`20in`20menu`20box
  1172. X`20*
  1173. X`20*`20This`20function`20takes`20an`20array`20of`20strings,`20terminated`20by
  1174. V`20a`20NULL
  1175. X`20*`20pointer,`20and`20writes`20each`20string`20into`20successive`20lines`20o
  1176. Vf`20the
  1177. X`20*`20menu`20box`20in`20the`20bottom`20right`20corner`20of`20the`20screen.
  1178. V`20`20If`20there`20are
  1179. X`20*`20more`20strings`20than`20will`20fit`20in`20the`20box,`20the`20extra`20st
  1180. Vrings`20are
  1181. X`20*`20ignored.`20`20If`20NULL`20is`20passed`20as`20the`20menu`20array,`20the
  1182. V`20menu`20box
  1183. X`20*`20is`20cleared.
  1184. X`20*----------------------------------------------------------------------
  1185. X`20*/
  1186. X
  1187. XFeDrawMenu(m)
  1188. Xchar`20*m`5B`5D;
  1189. X`7B
  1190. Xint`20i;
  1191. X
  1192. Xfor`20(i`20=`200;`20i`20<`205;`20i++)`20`7B`09`09/*`20clear`20all`20lines`20in
  1193. V`20menu`20box`20*/
  1194. X`09move(19+i,63);
  1195. X`09clrtoeol();
  1196. X`09`7D
  1197. Xif`20(m`20==`20NULL)`09`09`09`09/*`20no`20menu`20to`20display`20*/
  1198. X`09return;
  1199. Xfor`20(i`20=`200;`20(m`5Bi`5D`20!=`20NULL)`20`26`26`20(i`20<`205);`20i++)`20
  1200. V`7B
  1201. X`09if`20(strlen(m`5Bi`5D)`20>`2015)`09`09/*`20menu`20string`20is`20too`20long
  1202. V`20*/
  1203. X`09`09m`5B15`5D`20=`20'`5C0';`09`09/*`20so`20shorten`20it`20*/
  1204. X`09mvaddstr(19+i,64,m`5Bi`5D);`09`09/*`20put`20string`20in`20menu`20area`20*/
  1205. X`09`7D
  1206. Xrefresh();
  1207. X`7D
  1208. X
  1209. X
  1210. X/*----------------------------------------------------------------------
  1211. X`20*`09FeMenu`20--`20get`20menu`20choice`20from`20user
  1212. X`20*
  1213. X`20*`20This`20function`20accepts`20a`20menu`20choice`20from`20the`20user.`20
  1214. V`20The`20menu`20choices
  1215. X`20*`20are`20passed`20as`20an`20array`20of`20strings,`20terminated`20by`20a
  1216. V`20NULL`20pointer.
  1217. X`20*`20Users`20select`20one`20of`20these`20strings`20by`20typing`20the`20first
  1218. V`20letter`20of`20the
  1219. X`20*`20string,`20thus`20the`20first`20letter`20of`20the`20strings`20must`20be
  1220. V`20unique.
  1221. X`20*
  1222. X`20*`20FeMenu`20also`20handles`20two`20special`20cases:
  1223. X`20*`091.`20The`20user`20types`20a`20number`20between`201`20and`206`20(a`20rol
  1224. Vl)
  1225. X`20*`092.`20The`20user`20types`20some`20character`20that`20the`20caller`20wish
  1226. Ves
  1227. X`20*`09`20`20`20to`20handle`20directly.
  1228. X`20*`20If`20a`20roll`20entry`20is`20valid,`20the`20caller`20may`20pass`20up
  1229. V`20to`20two`20different
  1230. X`20*`20rolls`20that`20are`20valid`20in`20the`20r1`20and`20r2`20arguments.`20
  1231. V`20Any`20characters
  1232. X`20*`20the`20caller`20wishes`20to`20handle`20are`20passed`20as`20a`20string
  1233. V`20in`20the
  1234. X`20*`20"extra"`20argument.`20`20These`20typically`20include`20space`20and`20ne
  1235. Vwline.
  1236. X`20*
  1237. X`20*`20When`20a`20menu`20item`20is`20selected,`20it`20is`20highlighted`20befor
  1238. Ve`20FeMenu
  1239. X`20*`20returns.`20`20If`20the`20caller`20calls`20FeMenu`20again`20without`20po
  1240. Vsting`20a
  1241. X`20*`20new`20menu`20(via`20FeDrawMenu),`20the`20character`20returned`20by`20Fe
  1242. VMenu
  1243. X`20*`20on`20the`20first`20call`20should`20be`20passed`20in`20the`20"prev"`20ar
  1244. Vgument`20so
  1245. X`20*`20that`20choice`20can`20be`20un-highlighted.`20`20If`20there`20is`20no
  1246. V`20previous
  1247. X`20*`20choice`20to`20unhighlight,`20prev`20can`20be`20'`5C0'.
  1248. X`20*----------------------------------------------------------------------
  1249. X`20*/
  1250. X
  1251. Xchar`20FeMenu(m,r1,r2,extra,prev)
  1252. Xchar`20*m`5B`5D;`09`09`09/*`20array`20of`20menu`20choices`20*/
  1253. Xint`20r1,`20r2;`09`09`09/*`20rolls`20(pass`200`20if`20no`20roll`20valid)`20*/
  1254. Xchar`20*extra;`09`09`09/*`20chars`20that`20caller`20wants`20to`20handle`20*/
  1255. Xchar`20prev;`09`09`09/*`20previous`20choice`20we`20should`20un-highlight`20*/
  1256. X`7B
  1257. Xint`20i;
  1258. Xchar`20c,`20x;
  1259. X
  1260. XFeOffMenuItem(m,prev);
  1261. Xwhile`20(1)`20`7B
  1262. X`09mvaddch(18,69,'`20');
  1263. X`09move(18,69);`09`09`09/*`20put`20cursor`20in`20its`20little`20box`20*/
  1264. X`09refresh();
  1265. X`09c`20=`20PGetChr(1,1);`09`09/*`20get`20a`20character`20*/
  1266. X`09FeMessage(NULL);`09`09/*`20clear`20message`20line`20*/
  1267. X`09if`20(`20(extra`20!=`20NULL)`20`26`26`20(strchr(extra,c)`20!=`20NULL)`20)
  1268. X`09`09return(c);`09`09/*`20these`20chars`20are`20handled`20by`20caller`20*/
  1269. X`09if`20(`20(c`20>=`20'1')`20`26`26`20(c`20<=`20'6')`20)`20`7B`09/*`20handle
  1270. V`20digits`20differently`20*/
  1271. X`09`09if`20(r1`20<=`200)`20`7B
  1272. X`09`09`09FeMessage("Roll`20not`20valid`20here.");
  1273. X`09`09`09continue;
  1274. X`09`09`09`7D
  1275. X`09`09x`20=`20c`20-`20'0';`09`09/*`20convert`20to`20number`20*/
  1276. X`09`09if`20(`20(x`20==`20r1)`20`7C`7C`20(x`20==`20r2)`20)`09/*`20is`20it`20a
  1277. V`20valid`20roll?`20*/
  1278. X`09`09`09return(c);`09`09/*`20yup,`20return`20it`20*/
  1279. X`09`09FeMessage("No`20such`20roll.");
  1280. X`09`09continue;
  1281. X`09`09`7D
  1282. X`09if`20(islower(c))`09`09`09/*`20ignore`20case`20*/
  1283. X`09`09c`20=`20toupper(c);
  1284. X`09for`20(i`20=`200;`20m`5Bi`5D`20!=`20NULL;`20i++)`20`7B`09/*`20search`20menu
  1285. V`20strings`20*/
  1286. X`09`09x`20=`20*m`5Bi`5D;
  1287. X`09`09if`20(islower(x))`09`09`09/*`20ignore`20case`20*/
  1288. X`09`09`09x`20=`20toupper(x);
  1289. X`09`09if`20(c`20!=`20x)`09`09`09/*`20this`20isn't`20it`20*/
  1290. +-+-+-+-+-+-+-+-  END  OF PART 8 +-+-+-+-+-+-+-+-
  1291.