home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / vmsnet / mazewar / part05 < prev    next >
Text File  |  1993-07-09  |  55KB  |  1,608 lines

  1. Newsgroups: vmsnet.sources.games
  2. Path: uunet!ddsw1!lll-winken.llnl.gov!uwm.edu!linac!newsaintmail
  3. From: SNYDER@d0sb10.fnal.gov
  4. Subject: Mazewar for VMS (5/5)
  5. Message-ID: <SNYDER.93Jul10033629@d0sb10.fnal.gov>
  6. Sender: daemon@linac.fnal.gov (The Background Man)
  7. Nntp-Posting-Host: d0sb10.fnal.gov
  8. Organization: SUNY Stony Brook High Energy Physics
  9. Date: Sat, 10 Jul 1993 09:36:29 GMT
  10. Lines: 1595
  11. Xref: uunet vmsnet.sources.games:750
  12.  
  13.  
  14. -+-+-+-+-+-+-+-+ START OF PART 5 -+-+-+-+-+-+-+-+
  15. X`7D`09`09`09`09`09RatPacket;
  16. X
  17. X/*`20variables`20"exported"`20by`20the`20mazewar`20"module"`20*/
  18. X
  19. Xstruct`20_mazewar`20`7B
  20. X`09Direction`09dir;`09`09/*`20which`20way`20am`20I`20looking?`20*/
  21. X`09Direction`09dirPeek;`09/*`20direction`20for`20peek`20display`20*/
  22. X`09Boolean`09duke;`09`09`09/*`20I`20am`20the`20duke`20*/
  23. X`09Sockaddr`09dukeAddr;`09/*`20where`20is`20the`20duke?`20*/
  24. X`09Boolean`09invincible;`09`09/*`20can`20I`20be`20killed?`20*/
  25. X`09MazeType`09maze;`09`09/*`20the`20maze`20in`20bits`20*/
  26. X`09long`09`09mazePort;`09/*`20the`20port`20to`20keep`20busy`20*/
  27. X`09Sockaddr`09myAddr;`09`09/*`20my`20net`20address`20*/
  28. X`09RatId`09myRatId;`09`09/*`20my`20index`20into`20the`20ratcb`20*/
  29. X`09Boolean`09omniscient;`09`09/*`20can`20I`20see`20everyone?`20*/
  30. X`09Boolean`09peeking;`09`09/*`20peeking`20in`20progress`20*/
  31. X`09int`09theSocket;`09`09/*`20the`20main`20socket`20*/
  32. X`09short`09randomVector`5BVECTORSIZE`5D;
  33. X`09RatCb`09ratcb;`09`09`09/*`20my`20copy`20of`20the`20world`20*/
  34. X`09Score`09score;`09`09`09/*`20my`20total`20so`20far`20*/
  35. X`09Loc`09xloc;`09`09`09/*`20current`20x`20location`20*/
  36. X`09Loc`09yloc;`09`09`09/*`20current`20y`20location`20*/
  37. X`09Loc`09xPeek;`09`09`09/*`20x`20for`20peek`20display`20*/
  38. X`09Loc`09yPeek;`09`09`09/*`20y`20for`20peek`20display`20*/
  39. X`7DM;`09`09`09`09`09/*`20expediency`20wins`20out`20*/
  40. X
  41. X/*`20events`20*/
  42. X
  43. X#define`09EVENT_A`09`091`09`09/*`20user`20pressed`20"A"`20*/
  44. X#define`09EVENT_S`09`092`09`09/*`20user`20pressed`20"S"`20*/
  45. X#define`09EVENT_D`09`093`09`09/*`20user`20pressed`20"D"`20*/
  46. X#define`09EVENT_F`09`094`09`09/*`20user`20pressed`20"F"`20*/
  47. X#define`09EVENT_BAR`095`09`09/*`20user`20pressed`20space`20bar`20*/
  48. X#define`09EVENT_I`09`096`09`09/*`20user`20pressed`20"I"`20*/
  49. X#define`09EVENT_K`09`097`09`09/*`20user`20pressed`20"K"`20*/
  50. X#define`09EVENT_O`09`098`09`09/*`20user`20pressed`20"O"`20*/
  51. X#define`09EVENT_L`09`099`09`09/*`20user`20pressed`20"L"`20*/
  52. X#define`09EVENT_LEFT_D`0910`09`09/*`20user`20pressed`20left`20mouse`20button
  53. V`20*/
  54. X#define`09EVENT_LEFT_U`0911`09`09/*`20user`20released`20l.m.b`20*/
  55. X#define`09EVENT_MIDDLE_D`0912`09`09/*`20user`20pressed`20middle`20button`20*/
  56. X#define`09EVENT_RIGHT_D`0913`09`09/*`20user`20pressed`20right`20button`20*/
  57. X#define`09EVENT_RIGHT_U`0914`09`09/*`20user`20released`20r.m.b`20*/
  58. X#define`09EVENT_NETWORK`0915`09`09/*`20incoming`20network`20packet`20*/
  59. X#define`09EVENT_INT`0916`09`09/*`20user`20pressed`20interrupt`20key`20*/
  60. X#define`09EVENT_TIMEOUT`0917`09`09/*`20nothing`20happened!`20*/
  61. X
  62. Xtypedef`09struct`20`7B
  63. X`09short`09`09eventType;
  64. X`09RatPacket`09*eventDetail;`09/*`20for`20incoming`20data`20*/
  65. X`09Sockaddr`09eventSource;
  66. X`7D`09`09`09`09`09MWEvent;
  67. X
  68. XR2d2_t`09`09R2d2;
  69. XRatKillQ_t`09RatKillQ;
  70. X
  71. Xvoid`09NextEvent();
  72. X`09
  73. Xchar`09*malloc();
  74. $ call unpack [.MAZEWAR]MAZEWAR.H;1 1948739102 ""
  75. $!
  76. $ create 'f'
  77. Xsys$share:decw$xtshr/share
  78. Xsys$share:decw$xlibshr/share
  79. Xmultinet:multinet_socket_library/share
  80. $ call unpack [.MAZEWAR]MAZEWAR.OPT;3 -
  81.  508047064 "FORMAT STREAM_LF;CARRIAGE_CONTROL CARRIAGE_RETURN"
  82. $!
  83. $ create 'f'
  84. XThis`20is`20Mazewar`20for`20UNIX.`20It`20is`20a`20direct`20descendant`20of`20t
  85. Vhe`20Mazewar
  86. Xplayed`20at`20MIT`20and`20Xerox`20PARC,`20and`20boasts`20none`20of`20the`20emb
  87. Vellishments`20found
  88. Xin`20other`20such`20programs.`20It's`20basically`20just`20run,`20peek,`20and
  89. V`20shoot;`20no`20robot
  90. Xamenuenses,`20teleport`20traps,`20or`20other`20such`20fluff.
  91. X
  92. XBasically,`20ASDF`20and`20space`20move`20you`20around,`20middle`20mouse`20shoo
  93. Vts,`20left`20and
  94. Xright`20mouse`20let`20you`20peek`20around`20corners.`20Type`20Q`20to`20quit.
  95. V`20Lefties`20may`20use
  96. Xthe`20numeric`20pad`20instead`20of`20ASDF;`20on`20a`20DEC`20LK201`20keyboard,
  97. V`20the`20456,`20row
  98. Xserves`20for`20ASDF,`20and`20the`20right`20cursor`20arrow`20is`20equivalent
  99. V`20to`20the`20space`20bar.
  100. XQ`20quits.
  101. X
  102. XGames`20are`20normally`20begun`20by`20broadcasting`20to`20find`20members`20of
  103. V`20a`20game;`20if
  104. Xyour`20system`20doesn't`20allow`20normal`20users`20to`20do`20broadcasts,`20you
  105. V'll`20have`20to`20do
  106. Xsomething`20like`20run`20it`20setuid`20root`20(or`20whomever)`20and`20change
  107. V`20findDuke$init.c
  108. Xto`20do`20a`20setuid(getuid())`20after`20the`20broadcast.`20The`20code`20as
  109. V`20distributed`20does`20a
  110. Xbroadcast`20to`20INADDR_BROADCAST`20(all`201s);`20your`20network`20might`20sti
  111. Vll`20be`20configured
  112. Xto`20use`20INADDR_ANY`20(all`200s).`20The`20place`20to`20change`20this`20is
  113. V`20in`20the`20declaration`20of
  114. XCFLAGS`20in`20the`20Makefile.
  115. X
  116. XAlso,`20the`204.3`20setsockopt()`20call`20is`20pickier`20about`20its`20argumen
  117. Vts`20when`20trying`20to
  118. Xenable`20broadcasting.`20`20Define`20BSD_43`20in`20the`20Makefile`20to`20compi
  119. Vle`20the`20appropriate
  120. Xcode`20for`204.3`20and`204.3-derived`20systems.`20`20The`20code`20that`20worke
  121. Vd`20on`204.2`20is`20still
  122. Xavailable`20for`20systems`20that`20might`20not`20like`20the`20new`20arguments.
  123. V
  124. X
  125. XIf`20you`20know`20you`20don't`20have`20broadcast`20ability`20and`20never`20wil
  126. Vl,`20define
  127. XNO_BROADCAST`20in`20the`20Makefile,`20and`20that`20code`20will`20be`20compiled
  128. V`20out`20of`20init.c;
  129. Xmazefind`20isn't`20touched,`20but`20it`20won't`20do`20anything`20useful.`20In
  130. V`20this`20case,`20you`20must
  131. Xspecify`20a`20duke`20host`20(the`20name`20of`20any`20host`20currently`20in`20a
  132. V`20game`20will`20do)`20or`20the
  133. Xplayers`20won't`20be`20able`20to`20find`20each`20other.`20
  134. X
  135. XIn`20each`20game`20there`20is`20one`20player`20who`20is`20designated`20the`20"
  136. Vduke"`20and`20manages
  137. Xthe`20joining`20and`20leaving`20of`20other`20players.`20When`20starting`20a
  138. V`20game,`20if`20you
  139. Xwish`20to`20join`20a`20specific`20game,`20especially`20one`20on`20a`20differen
  140. Vt`20net,`20you`20may
  141. Xspecify`20the`20name`20of`20the`20duke`20host,`20which`20will`20be`20contacted
  142. V`20directly.`20This
  143. Xhas`20not`20been`20extensively`20tested.`20Games`20across`20long`20network`20d
  144. Velays`20might`20be
  145. Xpretty`20strange...
  146. X
  147. XIf`20you`20enjoy`20this`20program`20and`20keep`20it,`20please`20send`20a`20pic
  148. Vture`20post`20card`20to`20me:
  149. X
  150. XChris`20Kent
  151. XDEC`20Western`20Research`20Lab
  152. X100`20Hamilton`20Avenue
  153. XPalo`20Alto,`20CA`2094301
  154. X
  155. XInclude`20your`20ArpaNet`20or`20UUCP`20mailing`20address`20and`20I'll`20keep
  156. V`20you`20informed`20
  157. Xof`20updates.
  158. X
  159. XDecember,`201986
  160. X
  161. XBob`20Brown,`20Malcolm`20Slaney,`20and`20Mike`20Yang`20deserve`20a`20long`20ro
  162. Vund`20of`20applause`20for
  163. Xhaving`20ported`20to`20new`20window`20systems.`20`20We've`20tested`20it`20on
  164. V`20a`20lot`20of
  165. Xarchitectures,`20but`20byte-`20or`20bit-order`20bugs`20may`20still`20be`20lurk
  166. Ving.`20`20Note`20that
  167. Xthere`20is`20conditional`20code`20in`20the`20X11`20driver`20to`20not`20use`20s
  168. Verver-resident`20bitmaps
  169. Xif`20your`20server`20doesn't`20do`20them`20right`20(this`20was`20designed`20fo
  170. Vr`20the`20QDSS).
  171. X
  172. XHave`20fun,
  173. Xchris
  174. X
  175. XAugust,`201988
  176. $ call unpack [.MAZEWAR]README.;1 561999293 ""
  177. $!
  178. $ create 'f'
  179. X
  180. XMazewar`20on`20VMS
  181. X
  182. XThis`20is`20a`20port`20of`20the`20X11`20mazewar`20game`20to`20VMS/Multinet.
  183. XYou`20can`20compile`20it`20with`20either`20gcc`20or`20VAX`20C.`20`20Look`20at
  184. V`20descrip.mms,
  185. Xuncomment`20the`20appropriate`20lines,`20and`20run`20MMS.`20`20If`20you`20don'
  186. Vt`20have
  187. XMMS,`20it`20shouldn't`20be`20difficult`20to`20do`20by`20hand.`20`20See`20the
  188. V`20man`20pages
  189. Xfor`20playing`20instructions.
  190. X
  191. XNote`20that`20this`20kit`20does`20not`20include`20all`20of`20the`20original
  192. V`20distribution;`20i've
  193. Xleft`20out`20the`20subview`20and`20X10`20support`20files.
  194. X
  195. Xscott`20snyder
  196. Xsnyder@fnald0.fnal.gov
  197. $ call unpack [.MAZEWAR]VMS-README.;1 -
  198.  1517435425 "FORMAT STREAM_LF;CARRIAGE_CONTROL CARRIAGE_RETURN"
  199. $!
  200. $ create 'f'
  201. X/*`20$Header:`20winX11.c,v`201.30`2089/02/24`2016:29:44`20kent`20Exp`20$`20*/
  202. X
  203. X/*`20
  204. X`20*`20window_X11.c`20-`20Window-system`20specific`20routines`20for`20X11
  205. X`20*`20
  206. X`20*`20Author:`09Mike`20Yang
  207. X`20*`20`09`09Western`20Research`20Laboratory
  208. X`20*`09`20`09Digital`20Equipment`20Corporation
  209. X`20*`20Date:`09Mon`20Jul`2025`201988
  210. X`20*/
  211. X
  212. X/***********************************************************
  213. XCopyright`201988`20by`20Digital`20Equipment`20Corporation,`20Maynard,`20Massac
  214. Vhusetts,
  215. X
  216. X`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20All
  217. V`20Rights`20Reserved
  218. X
  219. XPermission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20software
  220. V`20and`20its`20
  221. Xdocumentation`20for`20any`20purpose`20and`20without`20fee`20is`20hereby`20gran
  222. Vted,`20
  223. Xprovided`20that`20the`20above`20copyright`20notice`20appear`20in`20all`20copie
  224. Vs`20and`20that
  225. Xboth`20that`20copyright`20notice`20and`20this`20permission`20notice`20appear
  226. V`20in`20
  227. Xsupporting`20documentation,`20and`20that`20the`20names`20of`20Digital`20not
  228. V`20be
  229. Xused`20in`20advertising`20or`20publicity`20pertaining`20to`20disstribution`20o
  230. Vf`20the
  231. Xsoftware`20without`20specific,`20written`20prior`20permission.`20`20
  232. X
  233. XDIGITAL`20DISCLAIMS`20ALL`20WARRANTIES`20WITH`20REGARD`20TO`20THIS`20SOFTWARE,
  234. V`20INCLUDING
  235. XALL`20IMPLIED`20WARRANTIES`20OF`20MERCHANTABILITY`20AND`20FITNESS,`20IN`20NO
  236. V`20EVENT`20SHALL
  237. XDIGITAL`20BE`20LIABLE`20FOR`20ANY`20SPECIAL,`20INDIRECT`20OR`20CONSEQUENTIAL
  238. V`20DAMAGES`20OR
  239. XANY`20DAMAGES`20WHATSOEVER`20RESULTING`20FROM`20LOSS`20OF`20USE,`20DATA`20OR
  240. V`20PROFITS,
  241. XWHETHER`20IN`20AN`20ACTION`20OF`20CONTRACT,`20NEGLIGENCE`20OR`20OTHER`20TORTIO
  242. VUS`20ACTION,
  243. XARISING`20OUT`20OF`20OR`20IN`20CONNECTION`20WITH`20THE`20USE`20OR`20PERFORMANC
  244. VE`20OF`20THIS
  245. XSOFTWARE.
  246. X
  247. X******************************************************************/
  248. X
  249. X/*`20
  250. X`20*`20It`20is`20intended`20that`20this`20file`20presents`20a`20window`20syste
  251. Vm-independent
  252. X`20*`20set`20of`20routines`20to`20MazeWar;`20that`20is,`20if`20you`20want`20to
  253. V`20run`20MW`20under
  254. X`20*`20another`20window`20system,`20this`20is`20the`20only`20file`20that`20nee
  255. Vds`20to`20be
  256. X`20*`20changed.`20It`20isn't`20yet`20clear`20how`20well`20I've`20succeeded,
  257. V`20but`20it's`20a`20start.
  258. X`20*`20
  259. X`20*`20Routines`20that`20are`20presented`20to`20the`20outside`20are`20capitali
  260. Vzed;`20local
  261. X`20*`20routines`20are`20not.
  262. X`20*/
  263. X
  264. X/*#define`09USE_BITMAPS`09/*`20turn`20on`20if`20you`20know`20CopyPlanes`20work
  265. Vs`20*/
  266. X
  267. X/*
  268. X`20*`20vms`20port`207/93`20`20scott`20snyder`20<snyder@fnald0.fnal.gov>
  269. X`20*`20$Log:`09winX11.c,v`20$
  270. X`20*`20Revision`201.30`20`2089/02/24`20`2016:29:44`20`20kent
  271. X`20*`20Changed`20inversion`20code`20to`20use`20GXxor`20instead`20of`20GXcopyIn
  272. Vverted.`20Makes
  273. X`20*`20the`20code`20a`20little`20cleaner,`20and`20Joel`20says`20it'll`20run
  274. V`20slightly`20
  275. X`20*`20faster`20(big`20deal).
  276. X`20*`20
  277. X`20*`20Revision`201.29`20`2089/02/24`20`2016:18:51`20`20kent
  278. X`20*`20Fixed`20a`20number`20of`20problems`20with`20the`20icon`20flashing`20cod
  279. Ve.
  280. X`20*`20
  281. X`20*`20Revision`201.28`20`2089/02/23`20`2010:10:25`20`20kent
  282. X`20*`20Changed`20to`20X11`20format`20bitmaps.
  283. X`20*`20
  284. X`20*`20Revision`201.27`20`2089/02/22`20`2017:28:08`20`20kent
  285. X`20*`20Make`20the`20cursor`20bitmap`20files`20internal,`20instead`20of`20tryin
  286. Vg`20to`20read
  287. X`20*`20them`20at`20runtime`20(!).`20Requires`20some`20byteswapping`20on`20MSBF
  288. Virst`20machines.
  289. X`20*`20
  290. X`20*`20Revision`201.26`20`2089/01/18`20`2017:26:46`20`20kent
  291. X`20*`20Set`20class`20hints`20for`20the`20window`20so`20the`20window`20manager
  292. V`20does
  293. X`20*`20the`20right`20thing.
  294. X`20*`20
  295. X`20*`20Revision`201.25`20`2088/09/07`20`2010:49:07`20`20kent
  296. X`20*`20Many`20changes`20in`20the`20name`20of`20portability.
  297. X`20*`20
  298. X`20*`20Revision`201.24`20`2088/08/12`20`2011:01:24`20`20kent
  299. X`20*`20Cleaned`20up`20image`20code.
  300. X`20*`20
  301. X`20*`20Revision`201.22`20`2088/08/11`20`2008:48:44`20`20kent
  302. X`20*`20Put`20Bitmap/CopyPlane`20code`20in`20for`20those`20that`20can`20use`20i
  303. Vt.
  304. X`20*`20
  305. X`20*`20Revision`201.21`20`2088/08/10`20`2016:41:08`20`20kent
  306. X`20*`20Changed`20rats`20to`20be`20an`20XImage`20that`20I`20put.`20Fixed`20xor
  307. V`20so`20it`20works`20properly
  308. X`20*`20on`20ANY`20sex`20display.
  309. X`20*`20
  310. X`20*`20Revision`201.20`20`2088/08/10`20`2011:16:55`20`20kent
  311. X`20*`20Eliminated`20use`20of`20keycodes`20in`20input`20event`20mapping.`20
  312. X`20*`20
  313. X`20*`20Revision`201.19`20`2088/08/09`20`2020:19:33`20`20kent
  314. X`20*`20Changed`20the`20mazePixmap`20to`20use`20an`20XImage`20and`20always`20pu
  315. Vt`20the`20bits
  316. X`20*`20remotely.`20Amazingly`20enough,`20the`20performance`20is`20a`20lot`20be
  317. Vtter,`20and
  318. X`20*`20the`20startup`20delay`20is`20a`20lot`20less.
  319. X`20*`20
  320. X`20*`20Revision`201.18`20`2088/08/09`20`2019:42:32`20`20kent
  321. X`20*`20Sped`20up`20arrow`20display`20code`20(HackMazeBitmap).`20Previously`20w
  322. Vas`20creating
  323. X`20*`20a`20Pixmap`20(and`20not`20destroying`20it!)`20every`20time`20--`20costi
  324. Vng`20a`20round`20trip
  325. X`20*`20for`20each`20call.`20Changed`20it`20to`20Create/Put/Destroy`20an`20XIma
  326. Vge,`20which
  327. X`20*`20costs`20a`20little`20locally,`20but`20no`20round`20trips.`20Big`20diffe
  328. Vrence!
  329. X`20*`20
  330. X`20*`20Also`20some`20general`20code`20cleanup.
  331. X`20*`20
  332. X`20*`20Revision`201.17`20`2088/07/25`20`2018:18:27`20`20kent
  333. X`20*`20Switch`20to`20zero-width`20lines.`20Much`20faster.
  334. X`20*`20
  335. X`20*`20Revision`201.16`20`2088/07/25`20`2009:12:40`20`20mikey
  336. X`20*`20cleanup`20source
  337. X`20*`20
  338. X`20*`20Revision`201.15`20`2088/07/25`20`2009:01:54`20`20mikey
  339. X`20*`20Coalesced`20line`20drawing`20requests,`20fixed`20depth`20bugs
  340. X`20*`20
  341. X`20*`20Revision`201.14`20`2088/07/20`20`2011:53:26`20`20mikey
  342. X`20*`20moved`20code`20from`20StartWindow`20to`20InitWindow`20so`20as`20to`20el
  343. Viminate`20timeout
  344. X`20*`20problems`20with`20ratDoctor.
  345. X`20*`20
  346. X`20*`20Revision`201.13`20`2088/06/21`20`2009:24:51`20`20mikey
  347. X`20*`20Fixed`20some`20bugs`20in`20the`20previous`20version.`20`20FocusIn`20doe
  348. Vsn't
  349. X`20*`20do`20anything`20now`20if`20an`20Expose`20event`20is`20in`20the`20queue
  350. V`20at`20all.
  351. X`20*`20
  352. X`20*`20Revision`201.12`20`2088/06/20`20`2016:52:35`20`20mikey
  353. X`20*`20Use`20XCheckIfEvent`20to`20reduce`20duplication`20if`20focusin`20and
  354. V`20expose`20events
  355. X`20*`20follow`20each`20other,`20eliminated`20use`20of`20GXcopyInverted`20and
  356. V`20instead
  357. X`20*`20set`20foreground`20and`20background,`20tried`20to`20eliminate`20buttonp
  358. Vress
  359. X`20*`20effect`20when`20selecting`20window.
  360. X`20*`20
  361. X`20*`20Revision`201.11`20`2088/06/20`20`2010:01:06`20`20mikey
  362. X`20*`20Inverts`20display`20when`20input`20focus`20is`20not`20in`20the`20window
  363. V.`20`20A`20lot`20of
  364. X`20*`20updating...`20maybe`20it`20can`20be`20reduced.
  365. X`20*`20
  366. X`20*`20Revision`201.10`20`2088/06/19`20`2015:16:18`20`20mikey
  367. X`20*`20Handles`2032x32`20bitmap`20for`20X11`20and`20eliminated`20kludges`20for
  368. V`20wm.
  369. X`20*`20Currently`20flashes`20icon`20depending`20on`20input`20focus.`20`20Shoul
  370. Vd
  371. X`20*`20change`20to`20depending`20on`20open/closed.
  372. X`20*`20
  373. X`20*`20Revision`201.9`20`2088/06/17`20`2014:53:12`20`20mikey
  374. X`20*`20Flashing`20icon`20on`20focus`20events
  375. X`20*`20
  376. X`20*`20Revision`201.8`20`2088/06/17`20`2012:48:52`20`20mikey
  377. X`20*`20Icon`20fixed`20for`20color`20(gpx)`20displays.
  378. X`20*`20
  379. X`20*`20Revision`201.7`20`2088/06/17`20`2011:35:41`20`20mikey
  380. X`20*`20fixed`20inverted`20bitmaps`20on`20vs100,`20eliminated`20blob,`20created
  381. V`20icon
  382. X`20*`20for`20monochrome`20wm.`20`20icon`20still`20messed`20for`20gpx.
  383. X`20*`20
  384. X`20*`20Revision`201.6`20`2088/06/17`20`2010:47:31`20`20mikey
  385. X`20*`20undid`20invertDisplay`20because`20of`20problems`20with`20screen`20saver
  386. V`20and`20with
  387. X`20*`20window`20exposure/update.`20`20other`20problems:`20blob`20in`20upperlef
  388. Vt`20of`5C
  389. X`20*`20maze`20on`20vs100,`20inverted`20bitmaps`20on`20vs100,`20unsuccessful
  390. V`20creation
  391. X`20*`20of`2032x32`20icon`20`5Boxmap.
  392. X`20*`20
  393. X`20*`20Revision`201.5`20`2088/06/16`20`2016:09:30`20`20mikey
  394. X`20*`20replaced`20most`20uses`20of`20XCreateBitmap`20with`20XCreatePixmapFromB
  395. VitmapData
  396. X`20*`20to`20solve`20vs100`20problems.`20`20still`20have`20negated-black/white
  397. V`20problems
  398. X`20*`20with`20bitmaps`20and`20vs100.
  399. X`20*`20
  400. X`20*`20Revision`201.4`20`2088/06/16`20`2015:29:55`20`20mikey
  401. X`20*`20disabled`20icon`20flashing,`20fixed`20inverting`20problems,`20still`20h
  402. Vave`20to
  403. X`20*`20fix`20vs100`20bitmap`20display
  404. X`20*`20
  405. X`20*`20Revision`201.3`20`2088/06/15`20`2011:40:05`20`20mikey
  406. X`20*`20before`20trying`20to`20fix`20icon`20window
  407. X`20*`20
  408. X`20*/
  409. X
  410. X#ifndef`09lint
  411. Xstatic`20char`20rcs_ident`5B`5D`20=`20"$Header:`20winX11.c,v`201.30`2089/02/24
  412. V`2016:29:44`20kent`20Exp`20$";
  413. X#endif
  414. X
  415. X#if`20defined(VMS)`20`26`26`20defined(__GNUC__)
  416. X#define`20TYPES_H_DEFINED
  417. X#endif
  418. X#ifdef`20VMS
  419. X#define`20__TIME
  420. X#endif
  421. X
  422. X#include`20<sys/types.h>
  423. X
  424. X#include`20<X11/Xos.h>
  425. X#include`20<X11/Xlib.h>
  426. X#include`20<X11/Xutil.h>
  427. X#include`20<X11/Xatom.h>
  428. X#include`20<X11/Xresource.h>
  429. X#include`20<X11/StringDefs.h>
  430. X
  431. X#include`20<sys/time.h>
  432. X
  433. X#include`20<netinet/in.h>
  434. X
  435. X#include`20<errno.h>
  436. X#include`20<stdio.h>
  437. X#ifdef`20VMS
  438. X#include`20<string.h>
  439. X#else
  440. X#include`20<pwd.h>
  441. X#include`20<strings.h>
  442. X#endif
  443. X
  444. X#include`20"mazewar.h"
  445. X#undef`09Boolean
  446. X
  447. X#include`20<X11/Intrinsic.h>
  448. X
  449. X#define`09VIEW_X_DIM`09400
  450. X#define`09VIEW_Y_DIM`09400
  451. X#define`09VIEW_X_ORIGIN`09100
  452. X#define`09VIEW_Y_ORIGIN`0950
  453. X#define`09MAZE_X_DIM`09(MAZEXMAX*16)
  454. X#define`09MAZE_Y_DIM`09(MAZEYMAX*16)
  455. X#define`09MAZE_X_ORIGIN`0948
  456. X#define`09MAZE_Y_ORIGIN`09451
  457. X#define`09SCORE_X_DIM`09192
  458. X#define`09SCORE_Y_DIM`09((scoreFontInfo->max_bounds.ascent`20+`20scoreFontInfo
  459. V->max_bounds.descent)`20*`20MAXRATS)
  460. X#define`09SCORE_X_ORIGIN`09208
  461. X#define`09SCORE_Y_ORIGIN`09708
  462. X#define`09MIN_X_DIM`09608`09`09/*`20see`20comments`20for`20InitWindow()`20*/
  463. X#define`09MIN_Y_DIM`09SCORE_Y_ORIGIN`09/*`20see`20InitWindow()`20*/
  464. X
  465. X#define`20DEFAULT_FONT`20"-*-Fixed-Medium-R-Normal--13-**-1"
  466. X#define`20DEFAULT_POSITION`20"%dx%d+0+0"`09/*`20upper`20left`20hand`20corner
  467. V`20*/
  468. X
  469. X#define`20ICON_FLASH_PERIOD`204
  470. X
  471. Xshort`09mazeBits`5BMAZEXMAX*MAZEYMAX*16`5D;`09/*`20shorts`20better`20be`2016
  472. V`20bits!`20*/
  473. XWindow`09mwWindow;`09`09`09/*`20parent`20window`20*/
  474. X#ifdef`09USE_BITMAPS
  475. XPixmap`09mazeBitmap;`09`09`09/*`20the`20maze`20*/
  476. XPixmap`09ratsBitmap;`09`09`09/*`20the`20rats`20*/
  477. X#else
  478. XXImage`09*ratsImage;`09`09`09/*`20the`20rats`20*/
  479. XXImage`09*mazeImage;`09`09`09/*`20the`20maze`20*/
  480. X#endif`09USE_BITMAPS
  481. XPixmap`09iconMask;`09`09`09/*`20mask`20for`20icon`20outline`20*/
  482. XXFontStruct`09*scoreFontInfo;
  483. XBoolean`09mapped`20=`09FALSE;`09`09/*`20should`20really`20display?`20*/
  484. XBoolean`09flashIcon`20=`09FALSE;`09`09/*`20should`20icon`20be`20flashing?`20*/
  485. V
  486. XBoolean`09iconInverted`20=`09FALSE;`09`09/*`20icon`20should`20be/is`20inverted
  487. V`20*/
  488. Xint`09displayFD;`09`09`09/*`20fd`20of`20display`20for`20events`20*/
  489. X
  490. XPixel`09`09fg_pixel;`09`09/*`20color`20of`20lines`20and`20such`20*/
  491. XPixel`09`09bg_pixel;`09`09/*`20color`20of`20background`20*/
  492. XPixel`09`09mouseground;`09`09/*`20mouse`20cursor`20color`20*/
  493. XFont`09`09scoreFont;`09`09/*`20font`20for`20printing`20scores`20*/
  494. XPixel`09`09borderColor;
  495. XCardinal`09borderWidth;
  496. X
  497. XDisplay`09*dpy;`09`09`09`09/*`20display`20used`20*/
  498. Xint`09screen;`09`09`09`09/*`20screen`20on`20the`20display`20*/
  499. Xunsigned`20int`09cur_width,`20cur_height;`09/*`20current`20width,`20height`20o
  500. Vf`20window`20*/
  501. XGC`09copyGC,`20xorGC;`09`09`09/*`20graphics`20contexts`20for`20window`20*/
  502. XPixmap`09icon_pixmap,`20iconmask_pixmap;`09/*`20icon,`20mask`20bitmaps`20*/
  503. XPixmap`09icon_reverse_pixmap;
  504. Xint`09icon_flash`20=`200;
  505. XXImage`09*arrowImage;
  506. X
  507. X#include`20"bitmaps/icon.ic"
  508. X#include`20"bitmaps/rat.cur"
  509. X#include`20"bitmaps/ratMask.cur"
  510. X#include`20"bitmaps/dRat.cur"
  511. X#include`20"bitmaps/dRatMask.cur"
  512. X#include`20"bitmaps/cup.cur"
  513. X
  514. Xstatic`20Cursor`09ratCursor,`20deadRatCursor,`20hourGlassCursor;
  515. X
  516. Xextern`20char`09*getenv();
  517. Xextern`20int`09errno;
  518. X
  519. Xstatic`20char`09*progName;
  520. X
  521. XPixmap`09`09xCreateBitmapFromBitCell();
  522. Xstatic`20repaintWindow`20();
  523. Xstatic`20repaintIcon`20();
  524. X
  525. Xstatic`20XrmOptionDescRec`20opTable`5B`5D`20=`20`7B
  526. X`7B"-mouse",`09"*mouseColor",`09XrmoptionSepArg,`09(caddr_t)`20NULL`7D,
  527. X`7D;
  528. X
  529. X#define`09XtNmouse`09"mouse"
  530. X
  531. Xint`09zero`20=`200;
  532. Xint`09one`20=`201;
  533. X
  534. Xstatic`20XtResource`20resources`5B`5D`20=`20`7B
  535. X`09`7BXtNforeground,`20XtCForeground,`20XtRPixel,`20sizeof(Pixel),
  536. X`09`20(Cardinal)`26fg_pixel,`20XtRString,`20"black"`7D,
  537. X`09`7BXtNbackground,`20XtCBackground,`20XtRPixel,`20sizeof(Pixel),
  538. X`09`20(Cardinal)`26bg_pixel,`20XtRString,`20"white"`7D,
  539. X`09`7BXtNmouse,`20XtCCursor,`20XtRPixel,`20sizeof(Pixel),
  540. X`09`20(Cardinal)`26mouseground,`20XtRString,`20"black"`7D,
  541. X`09`7BXtNfont,`20XtCFont,`20XtRFont,`20sizeof(Font),
  542. X`09`20(Cardinal)`26scoreFont,`20XtRString,`20DEFAULT_FONT`7D,`20
  543. X`09`7BXtNborderWidth,`20XtCBorderWidth,`20XtRInt,`20sizeof(int),
  544. X`09`20(Cardinal)`26borderWidth,`20XtRInt,`20(caddr_t)`20`26one`7D,
  545. X`09`7BXtNborder,`20XtCBorderColor,`20XtRPixel,`20sizeof(Pixel),
  546. X`09`20(Cardinal)`26borderColor,`20XtRString,`20"black"`7D,
  547. X`7D;
  548. X
  549. X/*`20
  550. X`20*`20ALL`20COORDINATES`20ASSUME`20ORIGIN`20(0,0)`20AT`20UPPER`20LEFT!
  551. X`20*/
  552. X
  553. X/*`20
  554. X`20*`20Initialize`20the`20window.`20The`20overall`20window`20must`20be`20at
  555. V`20least`20608x`20by
  556. X`20*`20808y`20(the`20size`20of`20the`20Alto`20screen).`20There`20are`20three
  557. V`20distinct
  558. X`20*`20subregions:
  559. X`20*`09A`20400x`20by`20400y`20area`20for`20the`20view,`20beginning`20at`20(100
  560. V,50)
  561. X`20*`09A`20512x`20by`20256y`20area`20for`20the`20maze,`20beginning`20at`20(48,
  562. V`20451)
  563. X`20*`09A`20192x`20by`2096y`20area`20for`20the`20score`20lines,`20at`20(208,
  564. V`20706)
  565. X`20*
  566. X`20*`09Actually,`20the`20y`20dimension`20of`20both`20the`20whole`20window`20an
  567. Vd`20the`20score
  568. X`20*`09subwindow`20must`20be`20enough`20to`20accommodate`20MAXRATS`20lines`20o
  569. Vf`20the
  570. X`20*`09height`20of`20the`20scoreFont.
  571. X`20*/
  572. X
  573. X/*`20parse`20arguments`20and`20set`20up`20window`20state`20*/
  574. X
  575. X#if`20defined(VMS)`20`26`26`20!defined(__GNUC__)
  576. X#define`20rindex`20strrchr
  577. X#endif
  578. X
  579. XInitWindow(argc,`20argv)
  580. Xchar`09**argv;
  581. X`7B
  582. X`09XGCValues`20gc_values;
  583. X`09XWMHints`20wmhints;
  584. X`09Widget`09w;
  585. X`09XClassHint`09classHint;
  586. X`09GC`09iconGC;
  587. X
  588. X`09progName`20=`20rindex(argv`5B0`5D,`20'/');
  589. X`09if`20(progName)
  590. X`09`09progName++;
  591. X`09else
  592. X`09`09progName`20=`20argv`5B0`5D;
  593. X
  594. X`09/*
  595. X`09`20*`20We`20cheat`20here`20by`20using`20the`20Toolkit`20to`20do`20the`20ini
  596. Vtialization`20work.
  597. X`09`20*`20We`20just`20ignore`20the`20top-level`20widget`20that`20gets`20create
  598. Vd.
  599. X`09`20*/
  600. X
  601. X`09w`20=`20XtInitialize("mazewar",`20"mazewar",`20opTable,`20XtNumber(opTable)
  602. V,`20
  603. X`09`09`09`26argc,`20argv);
  604. X
  605. X`09dpy`20=`20XtDisplay(w);
  606. X`09screen`20=`20DefaultScreen(dpy);
  607. X
  608. X`09XtGetApplicationResources(w,`20(caddr_t)`20NULL,`20resources,`20
  609. X`09`09`09`09XtNumber(resources),`20NULL,`20(Cardinal)`200);
  610. X`09
  611. X`09if`20(!scoreFont)
  612. X`09`09MWError("cannot`20open`20font");
  613. X`09scoreFontInfo`20=`20XQueryFont(dpy,`20scoreFont);
  614. X
  615. X`20`20`20`20`20`20`20`20cur_width`20=`20MIN_X_DIM;
  616. X`20`20`20`20`20`20`20`20cur_height`20=`20MIN_Y_DIM`20+`20(MAXRATS+1)`20*
  617. X`09`20`20`20`20`20`20`20`20`20`20`20`20`20(scoreFontInfo->max_bounds.ascent
  618. V`20+
  619. X`09`09`20`20`20`20`20`20scoreFontInfo->max_bounds.descent);
  620. X
  621. X`09mwWindow`20=`20XCreateSimpleWindow(dpy,`20
  622. X`09`09`09`09`09RootWindow(dpy,`20screen),
  623. X`09`09`09`09`090,`200,`20
  624. X`09`09`09`09`09cur_width,`20cur_height,
  625. X`09`09`09`09`09borderWidth,`200,`20bg_pixel);
  626. X`09XStoreName(dpy,`20mwWindow,`20"MazeWar");
  627. X`09XSetIconName(dpy,`20mwWindow,`20"MazeWar");
  628. X`09classHint.res_name`20=`20"mazewar";
  629. X`09classHint.res_class`20=`20"mazewar";
  630. X`09XSetClassHint(dpy,`20mwWindow,`20`26classHint);
  631. X
  632. X`09gc_values.function`20=`20GXcopy;
  633. X`09gc_values.foreground`20=`20fg_pixel;
  634. X`09gc_values.background`20=`20bg_pixel;
  635. X`09gc_values.font`20=`20scoreFont;
  636. X`09gc_values.line_width`20=`200;
  637. X`09copyGC`20=`20XCreateGC(dpy,`20mwWindow,
  638. X`09`09`20`20`20`20`20`20`20GCFunction`20`7C`20GCForeground`20`7C`20GCBackgroun
  639. Vd
  640. X`09`09`20`20`20`20`20`20`20`7C`20GCLineWidth`20`7C`20GCFont,
  641. X`09`09`20`20`20`20`20`20`20`26gc_values);
  642. X
  643. X`09gc_values.function`20=`20GXxor;
  644. X`09gc_values.plane_mask`20=`20AllPlanes;
  645. X`09gc_values.foreground`20=`20fg_pixel`20`5E`20bg_pixel;
  646. X`09gc_values.background`20=`200;
  647. X`09xorGC`20=`20XCreateGC(dpy,`20mwWindow,
  648. X`09`09`20`20`20`20`20`20`20GCFunction`20`7C`20GCForeground`20`7C`20GCBackgroun
  649. Vd`20`7C`20GCPlaneMask,
  650. X`09`09`20`20`20`20`20`20`20`26gc_values);
  651. X
  652. X`09icon_pixmap`20=`20XCreatePixmapFromBitmapData(
  653. X`09`09`09dpy,`20mwWindow,`20
  654. X`09`09`09icon_bits,`20
  655. X`09`09`09icon_width,`20icon_height,`20
  656. X`09`09`09fg_pixel,`20bg_pixel,`20
  657. X`09`09`09XDefaultDepth(dpy,`20screen));
  658. X
  659. X`09/*`20is`20this`20even`20used?`20*/
  660. X`09gc_values.function`20=`20GXclear;
  661. X`09gc_values.plane_mask`20=`20AllPlanes;
  662. X`09iconGC`20=`20XCreateGC(dpy,`20mwWindow,`20
  663. X`09`09`09GCFunction`20`7C`20GCPlaneMask,`20
  664. X`09`09`09`26gc_values);
  665. X`09iconmask_pixmap`20=`20XCreatePixmap(dpy,`20mwWindow,
  666. X`09`09`09`09`09icon_width,`20icon_height,`20
  667. X`09`09`09`09`09XDefaultDepth(dpy,`20screen));
  668. X`09XFillRectangle(dpy,`20iconmask_pixmap,`20iconGC,`200,`200,
  669. X`09`09`09icon_width,`20icon_height);
  670. X
  671. X`09icon_reverse_pixmap`20=`20XCreatePixmapFromBitmapData(dpy,`20mwWindow,
  672. X`09`09`09`09`09`09`20`20icon_bits,
  673. X`09`09`09`09`09`09`20`20icon_width,`20icon_height,
  674. X`09`09`09`09`09`09`20`20bg_pixel,`20fg_pixel,`20
  675. X`09`09`09`09`09`09`20`20XDefaultDepth(dpy,`20screen));
  676. X
  677. X`20`20`20`20`20`20`20`20wmhints.flags`20=`20IconPixmapHint`20`7C`20IconMaskHin
  678. Vt;
  679. X`20`20`20`20`20`20`20`20wmhints.icon_pixmap`20=`20icon_pixmap;
  680. X`20`20`20`20`20`20`20`20wmhints.icon_mask`20=`20iconmask_pixmap;
  681. X`20`20`20`20`20`20`20`20XSetWMHints(dpy,`20mwWindow,`20`26wmhints);
  682. X
  683. X`09initCursors();
  684. X`09arrowImage`20=`20XCreateImage(dpy,`20DefaultVisual(dpy,`20DefaultScreen(dpy
  685. V)),
  686. X`09`09`09`091,`20XYBitmap,`200,`20NULL,`20
  687. X`09`09`09`0916,`2016,`208,`202);
  688. X`09arrowImage->byte_order`20=`20MSBFirst;
  689. X`09arrowImage->bitmap_bit_order`20=`20MSBFirst;
  690. X`7D
  691. X
  692. X/*`20
  693. X`20*`20actually`20start`20the`20display`20up,`20after`20all`20the`20user`20int
  694. Veraction`20has
  695. X`20*`20been`20done.
  696. X`20*/
  697. X
  698. XStartWindow(ratBits,`20ratWidth,`20ratHeight)
  699. Xshort`09*ratBits;
  700. X`7B
  701. X`09XSelectInput(dpy,`20mwWindow,`20KeyPressMask`20`7C`20ButtonPressMask`20`7C
  702. X`09`09`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20ButtonReleas
  703. VeMask`20`7C`20`20ExposureMask`20`7C
  704. X`09`09`09`09`20`20`20`20StructureNotifyMask`20`7C`20FocusChangeMask);
  705. X`09HourGlassCursor();
  706. X
  707. X`09initMaze();
  708. X`09SwapBitmaps();
  709. X
  710. X`09displayFD`20=`20XConnectionNumber(dpy);
  711. X
  712. X`09XMapWindow(dpy,`20mwWindow);`09`09/*`20Map`20window`20to`20screen`20*/
  713. X`09initRats(ratBits,`20ratWidth,`20ratHeight);
  714. X`7D
  715. X
  716. X/*
  717. X`20*`20Shut`20down`20the`20window`20system,`20resetting`20any`20terminal`20mod
  718. Ves`20or`20what
  719. X`20*`20have`20you`20that`20may`20have`20been`20altered.`20No-op`20for`20X11.
  720. X`20*/
  721. X
  722. XStopWindow()
  723. X`7B
  724. X`09
  725. X`7D
  726. X
  727. X/*`20
  728. X`20*`20Clear`20out`20the`20view`20subwindow.`20If`20possible,`20delay`20the
  729. V`20visible`20effect
  730. X`20*`20until`20all`20the`20lines`20have`20been`20drawn`20(since`20this`20is
  731. V`20only`20called`20by
  732. X`20*`20ShowView(),`20which`20is`20about`20to`20draw`20a`20bunch`20of`20lines).
  733. V
  734. X`20*/
  735. X
  736. XClearView()
  737. X`7B
  738. X`09XClearArea(dpy,`20mwWindow,`20VIEW_X_ORIGIN,`20VIEW_Y_ORIGIN,
  739. X`09`09`20`20`20`20`20`20`20VIEW_X_DIM,`20VIEW_Y_DIM,`20False);
  740. X`7D
  741. X
  742. X/*
  743. X`20*`20Flash`20the`20view`20window`20to`20indicate`20a`20hit`20on`20an`20oppon
  744. Vent.
  745. X`20*/
  746. X
  747. XFlashTop()
  748. X`7B
  749. X`09XFillRectangle(dpy,`20mwWindow,`20xorGC,`20
  750. X`09`09VIEW_X_ORIGIN,`20VIEW_Y_ORIGIN,`20
  751. X`09`09VIEW_X_DIM,`20VIEW_Y_DIM);
  752. X`09XFlush(dpy);
  753. X
  754. X`09/*`20might`20want`20some`20delay`20here`20*/
  755. X
  756. X`09XFillRectangle(dpy,`20mwWindow,`20xorGC,`20
  757. X`09`09VIEW_X_ORIGIN,`20VIEW_Y_ORIGIN,`20
  758. X`09`09VIEW_X_DIM,`20VIEW_Y_DIM);
  759. X`09XFlush(dpy);
  760. X`7D
  761. X
  762. X/*
  763. X`20*`20Flash`20the`20whole`20window`20to`20indicate`20we`20were`20hit.
  764. X`20*/
  765. X
  766. XFlashScreen()
  767. X`7B
  768. X`09XFillRectangle(dpy,`20mwWindow,`20xorGC,`200,`200,`20cur_width,`20cur_heigh
  769. Vt);
  770. X`09XFlush(dpy);
  771. X
  772. X`09/*`20might`20want`20some`20delay`20here`20*/
  773. X
  774. X`09XFillRectangle(dpy,`20mwWindow,`20xorGC,`200,`200,`20cur_width,`20cur_heigh
  775. Vt);
  776. X`09XFlush(dpy);
  777. X`7D
  778. X
  779. X/*`20
  780. X`20*`20Draw`20a`20line`20in`20the`20view`20subwindow.`20Don't`20show`20it`20ri
  781. Vght`20away`20if`20possible.
  782. X`20*/
  783. X
  784. XDrawViewLine(x1,`20y1,`20x2,`20y2)
  785. X`7B
  786. X`09XDrawLine(dpy,`20mwWindow,`20copyGC,`20x1+VIEW_X_ORIGIN,`20y1+VIEW_Y_ORIGIN
  787. V,
  788. X`09`09`20`20x2+VIEW_X_ORIGIN,`20y2+VIEW_Y_ORIGIN);
  789. X`7D
  790. X
  791. X#ifdef`20VMS
  792. X#include`20<vms/inetiodef.h>
  793. X#include`20<ssdef.h>
  794. X#include`20<sys/socket.h>
  795. Xconst`20int`20net_efn`20=`2010;
  796. Xstatic`20int`20input_inited`20=`200;
  797. Xstatic`20struct`20`7B
  798. X`20`20short`20stat;
  799. X`20`20short`20len;
  800. X`20`20int`20x;
  801. X`7D`20net_iosb;
  802. X
  803. Xvoid`20arm_net_input`20(int`20socket)
  804. X`7B
  805. X`20`20int`20stat;
  806. X`20`20static`20char`20buffer`5B1024`5D;
  807. X
  808. X`20`20sys$clref`20(net_efn);
  809. X`20`20stat`20=`20sys$qio`20(net_efn,`20socket,`20IO$_RECEIVE,`20`26net_iosb,
  810. V`200,`200,
  811. X`09`09`20`20buffer,`20sizeof`20(buffer),`20MSG_PEEK,`200,`200,`200);
  812. X`20`20if`20((stat`261)`20==`200)`20lib$signal`20(stat);
  813. X`7D
  814. X
  815. X#endif
  816. X
  817. X/*`20
  818. X`20*`20Event`20handling.`20Presents`20a`20uniform`20event`20interface`20to`20t
  819. Vhe`20game,`20and
  820. X`20*`20handles`20all`20other`20events`20in`20here.`20The`20game`20only`20sees
  821. V`20the`20events
  822. X`20*`20that`20affect`20it`20directly,`20as`20defined`20in`20mazewar.h.`20They
  823. V`20are:
  824. X`20*
  825. X`20*`09keypresses`20that`20affect`20the`20game
  826. X`20*`09mouse`20button`20clicks
  827. X`20*`09incoming`20network`20packets
  828. X`20*`09timeouts`20(there's`20a`20"heartbeat"`20to`20drive`20the`20shot`20clock
  829. V)
  830. X`20*
  831. X`20*`20All`20other`20events`20should`20be`20swallowed`20by`20this`20routine.
  832. V`20Also,`20since
  833. X`20*`20keyboard`20focus`20is`20dependent`20on`20the`20mouse`20being`20in`20the
  834. V`20game`20window,
  835. X`20*`20try`20to`20let`20the`20user`20know`20that`20he's`20wandered`20outside
  836. V`20the`20window
  837. X`20*`20by`20inverting`20the`20window`20(should`20make`20it`20obvious)`20and
  838. V`20is`20now`20vulnerable
  839. X`20*`20and`20defenseless.
  840. X`20*/
  841. X
  842. Xvoid
  843. XNextEvent(event)
  844. XMWEvent`09*event;
  845. X`7B
  846. X`09int`09fdmask;
  847. X`09XEvent`09xev;
  848. X`09struct`20timeval`20timeout;
  849. X`09int`09ret;
  850. X`09char`09c`20=`200;
  851. X
  852. X#ifdef`20VMS
  853. X`09int`20efn_mask;
  854. X`20`20`20if`20(!input_inited)`20`7B
  855. X`20`20`20`20`20arm_net_input`20(M.theSocket);
  856. X`20`20`20`20`20input_inited`20=`201;
  857. X`20`20`20`7D
  858. X#endif
  859. X
  860. X`20`20`20`20while`20(1)`20`7B
  861. X`09icon_flash`20=`20(++icon_flash)`20%`20ICON_FLASH_PERIOD;
  862. X
  863. X`09if`20(!XPending(dpy))`09/*`20this`20does`20an`20XFlush,`20too`20*/
  864. X`09`09if`20(flashIcon`20`26`26`20!icon_flash`20`26`26`20!mapped)`20`7B
  865. X`09`09`09/*`20invert`20the`20icon`20`20*/
  866. X`09`09`09iconInverted`20=`20!iconInverted;
  867. X`09`09`09repaintIcon();
  868. X`09`09`7D
  869. X
  870. X`09/*
  871. X`09`20*`20Look`20for`20events.`20`20Try`20to`20arrange`20that`20X`20events`20h
  872. Vave`20priority`20over
  873. X`09`20*`20network`20traffic.`20`20See`20if`20there's`20an`20X`20event`20pendin
  874. Vg.`20`20If`20so,`20check
  875. X`09`20*`20for`20a`20net`20event,`20too;`20if`20not,`20select`20on`20both`20the
  876. V`20network`20and`20the`20X
  877. X`09`20*`20connection.`20`20If`20that`20doesn't`20time`20out,`20but`20there's
  878. V`20no`20X`20event
  879. X`09`20*`20pending,`20try`20again,`20just`20selecting`20on`20the`20X`20connecti
  880. Von.`20`20If`20that
  881. X`09`20*`20times`20out,`20let`20the`20network`20event`20get`20processed.
  882. X`09`20*
  883. X`09`20*`20Can't`20just`20select`20on`20the`20two`20fds,`20because`20there`20ma
  884. Vy`20be`20X`20events
  885. X`09`20*`20pending`20in`20the`20queue`20that`20have`20already`20been`20read.
  886. X`09`20*
  887. X`09`20*`20This`20may`20look`20baroque,`20but`20we've`20seen`20some`20instances
  888. V`20where`20X`20server
  889. X`09`20*`20latency`20seems`20to`20let`20the`20network`20events`20take`20priorit
  890. Vy`20over`20sever
  891. X`09`20*`20events,`20leading`20to`20sluggish`20keyboard`20response`20and`20lots
  892. V`20of`20local
  893. X`09`20*`20death.
  894. X`09`20*
  895. X`09`20*`20Also,`20can't`20just`20ignore`20network`20events`20--`20if`20the`20s
  896. Verver`20is`20slow`20and
  897. X`09`20*`20lots`20of`20X`20events`20get`20queued,`20someone`20else's`20ratDocto
  898. Vr`20will`20time`20you
  899. X`09`20*`20out`20if`20you`20never`20answer.
  900. X`09`20*/
  901. X
  902. X`09if`20(!XPending(dpy))`20`7B
  903. X#ifdef`20VMS
  904. X`09`20`20`20`20`20`20`20`20ret`20=`20XMultiplexInput`20(1,`20`26dpy,`201<<net_
  905. Vefn,`20500,`200,`20`26efn_mask);
  906. X`09`09if`20(ret`20<`200)
  907. X`09`09`20`20MWError`20("XMultiplexInput`20error");
  908. X#else
  909. X`09`09fdmask`20=`20(1`20<<`20displayFD)`20`7C`20(1`20<<`20M.theSocket);
  910. X`09`09timeout.tv_sec`20=`200;
  911. X`09`09timeout.tv_usec`20=`20500000;
  912. X`09`09while`20((ret`20=`20select(32,`20`26fdmask,`20NULL,`20NULL,`20`26timeout
  913. V))`20==`20-1)
  914. X`09`09`09if`20(errno`20!=`20EINTR)
  915. X`09`09`09`09MWError("select`20error`20on`20events");
  916. X#endif
  917. X`09`09if`20(ret`20==`200)`20`7B
  918. X`09`09`09event->eventType`20=`20EVENT_TIMEOUT;
  919. X`09`09`09return;
  920. X`09`09`7D
  921. X`09`7D`20else`20`7B
  922. X#ifndef`20VMS
  923. X`09`09fdmask`20=`201`20<<`20M.theSocket;
  924. X`09`09timeout.tv_sec`20=`200;
  925. X`09`09timeout.tv_usec`20=`200;
  926. X`09`09while`20((ret`20=`20select(32,`20`26fdmask,`20NULL,`20NULL,`20`26timeout
  927. V))`20==`20-1)
  928. X`09`09`09if`20(errno`20!=`20EINTR)
  929. X`09`09`09`09MWError("select`20error`20on`20events");
  930. X#endif
  931. X`09`7D
  932. X`09if`20(XPending(dpy))`20`7B
  933. X`09`09XNextEvent(dpy,`20`26xev);
  934. X`09`09switch`20(xev.type)`20`7B
  935. X`09`09case`20KeyPress:
  936. X`09`09`09event->eventType`20=`200;
  937. X`09`09`09XLookupString((XKeyEvent`20*)`20`26xev,`20`26c,`201,`20
  938. X`09`09`09`09`09NULL,`20NULL);
  939. X`09`09`09
  940. X`09`09`09switch(c)`20`7B
  941. X`09`09`09case`20'a':
  942. X`09`09`09case`20'4':`09/*`20keypad`20*/
  943. X`09`09`09`09event->eventType`20=`20EVENT_A;
  944. X`09`09`09`09return;
  945. X
  946. X`09`09`09case`20's':
  947. X`09`09`09case`20'5':
  948. X`09`09`09`09event->eventType`20=`20EVENT_S;
  949. X`09`09`09`09return;
  950. X
  951. X`09`09`09case`20'd':
  952. X`09`09`09case`20'6':
  953. X`09`09`09`09event->eventType`20=`20EVENT_D;
  954. X`09`09`09`09return;
  955. X
  956. X`09`09`09case`20'f':
  957. X`09`09`09case`20',':
  958. X`09`09`09`09event->eventType`20=`20EVENT_F;
  959. X`09`09`09`09return;
  960. X
  961. X`09`09`09case`20'`20':
  962. X`09`09`09case`20'`5C033':`09/*`20ESC`20lead`20in`20of`20arrow`20*/
  963. X`09`09`09`09event->eventType`20=`20EVENT_BAR;
  964. X`09`09`09`09return;
  965. X
  966. X`09`09`09case`20'i':
  967. X`09`09`09`09event->eventType`20=`20EVENT_I;
  968. X`09`09`09`09return;
  969. X
  970. X`09`09`09case`20'k':
  971. X`09`09`09`09event->eventType`20=`20EVENT_K;
  972. X`09`09`09`09return;
  973. X
  974. X`09`09`09case`20'o':
  975. X`09`09`09`09event->eventType`20=`20EVENT_O;
  976. X`09`09`09`09return;
  977. X
  978. X`09`09`09case`20'l':
  979. X`09`09`09`09event->eventType`20=`20EVENT_L;
  980. X`09`09`09`09return;
  981. X
  982. X`09`09`09case`20'q':
  983. X`09`09`09case`20'`5C177':`09/*`20DEL`20*/
  984. X`09`09`09case`20'`5C003':`09/*`20`5EC`20*/
  985. X`09`09`09`09event->eventType`20=`20EVENT_INT;
  986. X`09`09`09`09return;
  987. X`09`09`09`7D
  988. X`09`09`09break;
  989. X
  990. X#define`09RightButton`09Button3
  991. X#define`09MiddleButton`09Button2
  992. X#define`09LeftButton`09Button1
  993. X`09`09case`20ButtonPress:
  994. X`09`09`09event->eventType`20=`200;
  995. X`09`09`09switch(((XButtonPressedEvent`20*)`20
  996. X`09`09`09`09`26xev)->button`20`26`200xff)`20`7B
  997. X`09`09`09case`20RightButton:
  998. X`09`09`09`09event->eventType`20=`20EVENT_RIGHT_D;
  999. X`09`09`09`09return;
  1000. X
  1001. X`09`09`09case`20MiddleButton:
  1002. X`09`09`09`09event->eventType`20=`20EVENT_MIDDLE_D;
  1003. X`09`09`09`09return;
  1004. X
  1005. X`09`09`09case`20LeftButton:
  1006. X`09`09`09`09event->eventType`20=`20EVENT_LEFT_D;
  1007. X`09`09`09`09return;
  1008. X`09`09`09`7D
  1009. X`09`09`09break;
  1010. X
  1011. X`09`09case`20ButtonRelease:
  1012. X`09`09`09event->eventType`20=`200;
  1013. X`09`09`09switch(((XButtonReleasedEvent`20*)`20
  1014. X`09`09`09`09`26xev)->button`260xff)`20`7B
  1015. X`09`09`09case`20RightButton:
  1016. X`09`09`09`09event->eventType`20=`20EVENT_RIGHT_U;
  1017. X`09`09`09`09return;
  1018. X
  1019. X`09`09`09case`20LeftButton:
  1020. X`09`09`09`09event->eventType`20=`20EVENT_LEFT_U;
  1021. X`09`09`09`09return;
  1022. X`09`09`09`7D
  1023. X`09`09`09break;
  1024. X
  1025. X`09`09case`20Expose:
  1026. X`09`09`09repaintWindow();
  1027. X`09`09`09break;
  1028. X
  1029. X`09`09case`20FocusIn:
  1030. X`09`09case`20MapNotify:
  1031. X`09`09`09mapped`20=`20TRUE;
  1032. X`09`09`09iconInverted`20=`20FALSE;
  1033. X`09`09`09flashIcon`20=`20FALSE;
  1034. X`09`09`09repaintIcon();
  1035. X`09`09`09break;
  1036. X
  1037. X`09`09case`20FocusOut:
  1038. X`09`09case`20UnmapNotify:
  1039. X`09`09`09mapped`20=`20FALSE;
  1040. X`09`09`09break;
  1041. X`09`09`7D
  1042. X`09`7D
  1043. X
  1044. X#ifdef`20VMS
  1045. X`09if`20(sys$readef`20(net_efn,`20`26efn_mask)`20==`20SS$_WASSET)`20`7B
  1046. X#else
  1047. X`09if`20(fdmask`20`26`20(1`20<<`20M.theSocket))`20`7B
  1048. X#endif
  1049. X`09`09int`20fromLen`20=`20sizeof(event->eventSource);
  1050. X`09`09int`20cc;
  1051. X
  1052. X`09`09event->eventType`20=`20EVENT_NETWORK;
  1053. X`09`09cc`20=`20recvfrom(M.theSocket,`20event->eventDetail,
  1054. X`09`09`09sizeof(RatPacket),`200,`20`26event->eventSource,`20`26fromLen);
  1055. X#ifdef`20VMS
  1056. X`09`09arm_net_input`20(M.theSocket);
  1057. X#endif
  1058. X`09`09if`20(cc`20<=`200)`20`7B
  1059. X`09`09`09if`20(cc`20<`200`20`26`26`20errno`20!=`20EINTR)
  1060. X`09`09`09`09perror("event`20recvfrom");
  1061. X`09`09`09continue;
  1062. X`09`09`7D
  1063. X`09`09if`20(fromLen`20!=`20sizeof(struct`20sockaddr_in))
  1064. X`09`09`09continue;
  1065. X`09`09ConvertIncoming(event->eventDetail);
  1066. X`09`09return;
  1067. X`09`7D
  1068. X`20`20`20`20`7D
  1069. X`7D
  1070. X
  1071. X
  1072. X/*`20
  1073. X`20*`20Peek`20to`20see`20if`20there's`20a`20keyboard`20event`20waiting,`20in
  1074. V`20case`20the
  1075. X`20*`20program`20wants`20to`20short-circuit`20some`20code.`20If`20your`20syste
  1076. Vm`20won't`20let
  1077. X`20*`20you`20implement`20this`20feature`20easily,`20just`20always`20return`20F
  1078. VALSE.
  1079. X`20*/
  1080. X
  1081. XBoolean
  1082. XKBEventPending()
  1083. X`7B
  1084. X`20`20`20`20`20`20`20`20return`20(XPending(dpy)`20!=`200);
  1085. X`7D
  1086. X
  1087. X/*`20Please`20stand`20by`20...`20*/
  1088. X
  1089. XHourGlassCursor()
  1090. X`7B
  1091. X`09XDefineCursor(dpy,`20mwWindow,`20hourGlassCursor);
  1092. X`09XFlush(dpy);
  1093. X`7D
  1094. X
  1095. X/*`20Let`20the`20games`20begin!`20*/
  1096. XRatCursor()
  1097. X`7B
  1098. X`09XDefineCursor(dpy,`20mwWindow,`20ratCursor);
  1099. X`09XFlush(dpy);
  1100. X`7D
  1101. X
  1102. X/*`20He's`20dead,`20Jim`20...`20or`20might`20be`20*/
  1103. XDeadRatCursor()
  1104. X`7B
  1105. X`09XDefineCursor(dpy,`20mwWindow,`20deadRatCursor);
  1106. X`09XFlush(dpy);
  1107. X`7D
  1108. X
  1109. X/*`20
  1110. X`20*`20Update`20the`20displayed`20bitmap.`20Would`20really`20like`20to`20store
  1111. V`20the`20arrow`20bitmaps
  1112. X`20*`20remotely,`20but`20the`20non-normal`20ones`20(especially`20otherArrows)
  1113. V`20may`20change.`20
  1114. X`20*/
  1115. X
  1116. XHackMazeBitmap(x,`20y,`20newBits)
  1117. XBitCell`20*newBits;
  1118. X`7B
  1119. X`09arrowImage->data`20=`20(char`20*)newBits;
  1120. X`09XPutImage(dpy,`20mwWindow,`20copyGC,`20arrowImage,`200,`200,`20
  1121. X`09`09`09`20`20x*16`20+`20MAZE_X_ORIGIN,`20y*16`20+`20MAZE_Y_ORIGIN,`20
  1122. X`09`09`09`20`2016,`2016);
  1123. X`7D
  1124. X
  1125. X/*
  1126. X`20*`20Display`20a`20rat.`20`20Width,`20height,`20srcX`20and`20srcY`20describe
  1127. V`20the`20subbitmap`20in`20the
  1128. X`20*`20rats`20bitmap`20that`20is`20the`20desired`20view`20of`20the`20opponent.
  1129. V
  1130. X`20*/
  1131. X
  1132. XDisplayRatBitmap(screenX,`20screenY,`20width,`20height,`20srcX,`20srcY)
  1133. X`7B
  1134. X#ifdef`09USE_BITMAPS
  1135. X`09XCopyPlane(dpy,`20ratsBitmap,`20mwWindow,`20xorGC,`20srcX,`20srcY,
  1136. X`09`09`20`20width,`20height,
  1137. X`09`09`20`20screenX+VIEW_X_ORIGIN,`20screenY+VIEW_Y_ORIGIN,`201);
  1138. X#else
  1139. X`09XPutImage(dpy,`20mwWindow,`20xorGC,`20ratsImage,`20srcX,`20srcY,`20
  1140. X`09`09`20`20screenX+VIEW_X_ORIGIN,`20screenY+VIEW_Y_ORIGIN,
  1141. X`09`09`20`20width,`20height);
  1142. X#endif`09USE_BITMAPS
  1143. X`7D
  1144. X
  1145. X/*`20
  1146. X`20*`20Display`20the`20score`20line`20for`20the`20indicated`20player.`20Name
  1147. V`20is`20left
  1148. X`20*`20justified,`20score`20is`20right`20justified`20within`20the`20score`20wi
  1149. Vndow.
  1150. X`20*/
  1151. X
  1152. XWriteScoreString(rat)
  1153. XRatId`09rat;
  1154. X`7B
  1155. X`09char`09buf`5B64`5D;
  1156. X`09int`09leftEdge;
  1157. X
  1158. X`09sprintf(buf,`20"%d",`20(unsigned`20int)`20M.ratcb.rats`5Brat`5D.score);
  1159. X
  1160. X`09XClearArea(dpy,`20mwWindow,`20SCORE_X_ORIGIN,
  1161. X`09`09`20`20`20SCORE_Y_ORIGIN`20+
  1162. X`09`09`20`20`20rat`20*`20(scoreFontInfo->max_bounds.ascent`20+
  1163. X`09`09`09`20`20scoreFontInfo->max_bounds.descent),
  1164. X`09`09`20`20`20SCORE_X_DIM,
  1165. X`09`09`20`20`20(scoreFontInfo->max_bounds.ascent`20+
  1166. X`09`09`20`20`20`20scoreFontInfo->max_bounds.descent),
  1167. X`09`09`20`20`20FALSE);
  1168. X`09XDrawImageString(dpy,`20mwWindow,`20copyGC,`20SCORE_X_ORIGIN,
  1169. X`09`09`09`20SCORE_Y_ORIGIN`20+
  1170. X`09`09`09`20rat`20*`20(scoreFontInfo->max_bounds.ascent`20+
  1171. X`09`09`09`09scoreFontInfo->max_bounds.descent)`20+
  1172. X`09`09`09`20scoreFontInfo->max_bounds.ascent,
  1173. X`09`09`09`20M.ratcb.rats`5Brat`5D.name,`20strlen(M.ratcb.rats`5Brat`5D.name));
  1174. V
  1175. X`09leftEdge`20=`20SCORE_X_DIM`20-`20XTextWidth(scoreFontInfo,`20buf,`20strlen(
  1176. Vbuf));
  1177. X`09XDrawImageString(dpy,`20mwWindow,`20copyGC,`20leftEdge+SCORE_X_ORIGIN,
  1178. X`09`09`09`20SCORE_Y_ORIGIN`20+
  1179. X`09`09`09`20rat`20*`20(scoreFontInfo->max_bounds.ascent`20+
  1180. X`09`09`09`09scoreFontInfo->max_bounds.descent)`20+
  1181. X`09`09`09`20scoreFontInfo->max_bounds.ascent,
  1182. X`09`09`09`20buf,`20strlen(buf));
  1183. X`7D
  1184. X
  1185. X/*`20
  1186. X`20*`20Clear`20out`20the`20score`20line`20for`20a`20player`20that's`20left`20t
  1187. Vhe`20game.
  1188. X`20*/
  1189. X
  1190. XClearScoreLine(rat)
  1191. XRatId`09rat;
  1192. X`7B
  1193. X`09XClearArea(dpy,`20mwWindow,`20SCORE_X_ORIGIN,
  1194. X`09`09`20`20`20`20`20`20`20SCORE_Y_ORIGIN`20+
  1195. X`09`09`20`20`20`20`20`20`20rat`20*`20(scoreFontInfo->max_bounds.ascent`20+
  1196. X`09`09`09`20`20`20`20`20`20scoreFontInfo->max_bounds.descent),
  1197. X`09`09`20`20`20`20`20`20`20SCORE_X_DIM,
  1198. X`09`09`20`20`20`20`20`20`20scoreFontInfo->max_bounds.ascent`20+
  1199. X`09`09`20`20`20`20`20`20`20`20`20scoreFontInfo->max_bounds.descent,`20False);
  1200. X`7D
  1201. X
  1202. X/*`20
  1203. X`20*`20Pretty`20obvious,`20eh?`20Means`20the`20guy's`20in`20sight.
  1204. X`20*/
  1205. X
  1206. XInvertScoreLine(rat)
  1207. XRatId`09rat;
  1208. X`7B
  1209. X`09XFillRectangle(dpy,`20mwWindow,`20xorGC,`20
  1210. X`09`09`20`20SCORE_X_ORIGIN,
  1211. X`09`09`20`20SCORE_Y_ORIGIN`20+
  1212. X`09`09`20`20rat`20*`20(scoreFontInfo->max_bounds.ascent`20+
  1213. X`09`09`09`20scoreFontInfo->max_bounds.descent),
  1214. X`09`09`20`20SCORE_X_DIM,
  1215. X`09`09`20`20scoreFontInfo->max_bounds.ascent`20+
  1216. X`09`09`20`20scoreFontInfo->max_bounds.descent);
  1217. X`7D
  1218. X
  1219. X/*`20
  1220. X`20*`20Let`20the`20user`20know`20that`20a`20new`20player`20joined.`20This`20re
  1221. Vally`20should`20only
  1222. X`20*`20take`20effect`20if`20the`20window`20is`20iconic,`20so`20you`20can`20kee
  1223. Vp`20a`20game`20around
  1224. X`20*`20all`20day,`20close`20it`20up`20when`20there's`20no`20activity,`20and
  1225. V`20know`20when
  1226. X`20*`20someone`20else`20is`20also`20out`20to`20kill`20some`20time.
  1227. X`20*/
  1228. X
  1229. XNotifyPlayer()
  1230. X`7B
  1231. X`09flashIcon`20=`20TRUE;
  1232. X`7D
  1233. X
  1234. X/*
  1235. X`20*`20END`20PUBLIC`20ROUTINES
  1236. X`20*/
  1237. X
  1238. X/*`20set`20up`20needed`20bitmaps`20in`20the`20server`20*/
  1239. X
  1240. XinitCursors()
  1241. X`7B
  1242. X`20`20`20`20`20`20`20`20Pixmap`09p,`20m;
  1243. X`09XColor`09mc,`20bc;
  1244. X
  1245. X`09mc.pixel`20=`20mouseground;
  1246. X`09bc.pixel`20=`20bg_pixel;
  1247. X`09mc.flags`20=`20DoRed`20`7C`20DoGreen`20`7C`20DoBlue;
  1248. X`09bc.flags`20=`20DoRed`20`7C`20DoGreen`20`7C`20DoBlue;
  1249. X`09XQueryColor(dpy,`20DefaultColormap(dpy,`20screen),`20`26mc);
  1250. X`09XQueryColor(dpy,`20DefaultColormap(dpy,`20screen),`20`26bc);
  1251. X
  1252. X`09m`20=`20XCreateBitmapFromData(dpy,`20mwWindow,`20
  1253. X`09`09(char`20*)ratMask_bits,`20
  1254. X`09`09ratMask_width,`20ratMask_height);
  1255. X`09p`20=`20XCreateBitmapFromData(dpy,`20mwWindow,`20
  1256. X`09`09(char`20*)rat_bits,`20
  1257. X`09`09rat_width,`20rat_height);
  1258. X`09ratCursor`20=`20XCreatePixmapCursor(dpy,`20p,`20m,`20`26mc,`20`26bc,`20
  1259. X`09`09rat_x_hot,`20rat_y_hot);
  1260. X
  1261. X`09m`20=`20XCreateBitmapFromData(dpy,`20mwWindow,`20
  1262. X`09`09(char`20*)dRatMask_bits,`20
  1263. X`09`09dRatMask_width,`20dRatMask_height);
  1264. X`09p`20=`20XCreateBitmapFromData(dpy,`20mwWindow,`20
  1265. X`09`09(char`20*)dRat_bits,`20
  1266. X`09`09dRat_width,`20dRat_height);
  1267. X`09deadRatCursor`20=`20XCreatePixmapCursor(dpy,`20p,`20m,`20`26mc,`20`26bc,
  1268. V`200,`200);
  1269. X
  1270. X`09p`20=`20XCreateBitmapFromData(dpy,`20mwWindow,`20
  1271. X`09`09(char`20*)cup_bits,
  1272. X`09`09cup_width,`20cup_height);
  1273. X`09hourGlassCursor`20=`20XCreatePixmapCursor(dpy,`20p,`20p,`20`26mc,`20`26bc,
  1274. V`200,`200);
  1275. X`7D
  1276. X
  1277. X/*
  1278. X`20*`20construct`20an`20XImage`20of`20the`20maze.
  1279. X`20*/
  1280. X
  1281. XinitMaze()
  1282. X`7B
  1283. X`09register`20int`09i,`20j,`20k,`20line,`20index;
  1284. X
  1285. X`09for`20(i`20=`200;`20i`20<`20MAZEYMAX;`20i++)`20`7B
  1286. X`09`09line`20=`20i`20*`20MAZEXMAX`20*`20MAZEYMAX;
  1287. X`09`09for`20(j`20=`200;`20j`20<`20MAZEXMAX;`20j++)`20`7B
  1288. X`09`09`09index`20=`20line`20+`20j;
  1289. X`09`09`09for`20(k`20=`200;`20k`20<`2016;`20k++)`20`7B
  1290. X`09`09`09`09if`20(M.maze`5Bj`5D.y`5Bi`5D)
  1291. X`09`09`09`09`09mazeBits`5Bindex`5D`20=`200177777;
  1292. X`09`09`09`09else
  1293. X`09`09`09`09`09mazeBits`5Bindex`5D`20=`200;
  1294. X`09`09`09`09index`20+=`2032;
  1295. X`09`09`09`7D
  1296. X`09`09`09`09`09
  1297. X`09`09`7D
  1298. X`09`7D
  1299. X
  1300. X#ifdef`09USE_BITMAPS
  1301. X`09mazeBitmap`20=`20xCreateBitmapFromBitCell(dpy,`20mwWindow,`20(char`20*)`20m
  1302. VazeBits,
  1303. X`09`09`09`09`09MAZE_X_DIM,`20MAZE_Y_DIM);
  1304. X`09if`20(mazeBitmap`20==`200)
  1305. X#else
  1306. X`09mazeImage`20=`20XCreateImage(dpy,`20DefaultVisual(dpy,`20DefaultScreen(dpy)
  1307. V),
  1308. X`09`09`09`091,`20XYBitmap,`200,`20(char`20*)mazeBits,`20
  1309. X`09`09`09`09MAZE_X_DIM,`20MAZE_Y_DIM,`208,`20MAZE_X_DIM>>3);
  1310. X`09mazeImage->byte_order`20=`20MSBFirst;
  1311. X`09mazeImage->bitmap_bit_order`20=`20MSBFirst;
  1312. X
  1313. X`09if`20(mazeImage`20==`200)
  1314. X#endif`09USE_BITMAPS
  1315. X`09`09MWError("Can't`20create`20maze`20Pixmap");
  1316. X`7D
  1317. X
  1318. X/*
  1319. X`20*`20actually`20put`20the`20maze`20Pixmap`20on`20the`20screen.`20
  1320. X`20*/
  1321. X
  1322. XdrawMaze()
  1323. X`7B
  1324. X#ifdef`09USE_BITMAPS
  1325. X`09XCopyPlane(dpy,`20mazeBitmap,`20mwWindow,`20copyGC,`200,`200,`20
  1326. X`09`09`09MAZE_X_DIM,`20MAZE_Y_DIM,`20
  1327. X`09`09`09MAZE_X_ORIGIN,`20MAZE_Y_ORIGIN,`201);
  1328. X#else
  1329. X`09XPutImage(dpy,`20mwWindow,`20copyGC,`20mazeImage,`200,`200,`20
  1330. X`09`09`09MAZE_X_ORIGIN,`20MAZE_Y_ORIGIN,
  1331. X`09`09`09MAZE_X_DIM,`20MAZE_Y_DIM);
  1332. X#endif`09USE_BITMAPS
  1333. X`7D
  1334. X
  1335. X/*
  1336. X`20*`20Create`20the`20bitmap`20of`20the`20rats`20for`20later`20use.
  1337. X`20*/
  1338. X
  1339. XinitRats(bits,`20width,`20height)
  1340. Xshort`20*bits;
  1341. X`7B
  1342. X#ifdef`09USE_BITMAPS
  1343. X`09ratsBitmap`20=`20xCreateBitmapFromBitCell(dpy,`20mwWindow,`20(char`20*)`20b
  1344. Vits,`20
  1345. X`09`09`09`09`09width,`20height);
  1346. X`09if`20(ratsBitmap`20==`200)
  1347. X#else
  1348. X`09ratsImage`20=`20XCreateImage(dpy,`20DefaultVisual(dpy,`20DefaultScreen(dpy)
  1349. V),
  1350. X`09`09`09`091,`20XYBitmap,`200,`20(char`20*)`20bits,
  1351. X`09`09`09`09width,`20height,`208,`20width>>3);
  1352. X`09ratsImage->byte_order`20=`20MSBFirst;
  1353. X`09ratsImage->bitmap_bit_order`20=`20MSBFirst;
  1354. X
  1355. X`09if`20(ratsImage`20==`200)
  1356. X#endif`09USE_BITMAPS
  1357. X`09`09MWError("Can't`20create`20rats");
  1358. X`7D
  1359. X
  1360. X/*
  1361. X`20*`20Repaint`20the`20window`20for`20exposure`20and`20resize`20events.`20All
  1362. V`20drawing`20is
  1363. X`20*`20done`20here,`20even`20though`20there`20are`20times`20during`20the`20ini
  1364. Vtialization
  1365. X`20*`20code`20when`20it`20would`20seem`20obvious`20to`20put`20some`20of`20the
  1366. V`20display`20up;`20this
  1367. X`20*`20way`20portions`20of`20the`20display`20aren't`20shown`20twice`20then.
  1368. X`20*/
  1369. X
  1370. Xstatic
  1371. XrepaintWindow()
  1372. X`7B
  1373. X`09drawMaze();
  1374. X`09ShowPosition(M.xloc,`20M.yloc,`20M.invincible,`20M.dir);
  1375. X`09ShowView(M.xloc,`20M.yloc,`20M.dir);
  1376. X`09ShowAllPositions();
  1377. X
  1378. X`09NewScoreCard();
  1379. X`09XFlush(dpy);
  1380. X`7D
  1381. X
  1382. X/*`20
  1383. X`20*`20Repaint`20the`20icon`20for`20exposure`20events,`20or`20while`20flashing
  1384. V`20to`20indicate
  1385. X`20*`20that`20there's`20a`20new`20player.`20
  1386. X`20*/
  1387. X
  1388. Xstatic
  1389. XrepaintIcon()
  1390. X`7B
  1391. X`09XWMHints`20wmhints;
  1392. X
  1393. X`09if`20(!iconInverted)
  1394. X`09`09wmhints.icon_pixmap`20=`20icon_pixmap;
  1395. X`09else
  1396. X`09`09wmhints.icon_pixmap`20=`20icon_reverse_pixmap;
  1397. X`09wmhints.flags`20=`20IconPixmapHint`20`7C`20IconMaskHint;
  1398. X`09wmhints.icon_mask`20=`20iconmask_pixmap;
  1399. X`09XSetWMHints(dpy,`20mwWindow,`20`26wmhints);
  1400. X`7D
  1401. X
  1402. X/*`20
  1403. X`20*`20Invert`20the`20whole`20display.`20Used`20to`20let`20the`20user`20know
  1404. V`20the`20mouse`20has
  1405. X`20*`20strayed`20outside`20the`20window.`20We`20don't`20do`20this`20for`20X11.
  1406. V
  1407. X`20*/
  1408. X
  1409. Xstatic
  1410. XinvertDisplay()
  1411. X`7B
  1412. X
  1413. X`7D
  1414. X
  1415. X/*
  1416. X`20*`20A`20hack`20of`20XCreateBitmapFromData`20that`20assumes`20MSBFirst`20Bit
  1417. VCells`20insterad`20of
  1418. X`20*`20LSBFirst`20bytes.
  1419. X`20*/
  1420. X
  1421. XPixmap
  1422. XxCreateBitmapFromBitCell(display,`20d,`20data,`20width,`20height)
  1423. XDisplay`20*display;
  1424. XDrawable`20d;
  1425. Xchar`20*data;
  1426. Xunsigned`20int`20width,`20height;
  1427. X`7B
  1428. X`09XImage`20ximage;
  1429. X`09GC`20gc;
  1430. X`09Pixmap`20pix;
  1431. X
  1432. X`09pix`20=`20XCreatePixmap(display,`20d,`20width,`20height,`201);
  1433. X`09if`20(!pix)
  1434. X`09`20`20return(0);
  1435. X`09gc`20=`20XCreateGC(display,`20pix,`20(unsigned`20long)0,`20(XGCValues`20*)0
  1436. V);
  1437. X`09ximage.height`20=`20height;
  1438. X`09ximage.width`20=`20width;
  1439. X`09ximage.depth`20=`201;
  1440. X`09ximage.xoffset`20=`200;
  1441. X`09ximage.format`20=`20ZPixmap;
  1442. X`09ximage.data`20=`20data;
  1443. X`09ximage.byte_order`20=`20MSBFirst;
  1444. X`09ximage.bitmap_unit`20=`208;
  1445. X`09ximage.bitmap_bit_order`20=`20MSBFirst;
  1446. X`09ximage.bitmap_pad`20=`208;
  1447. X`09ximage.bytes_per_line`20=`20(width+7)/8;
  1448. X
  1449. X`09XPutImage(display,`20pix,`20gc,`20`26ximage,`200,`200,`200,`200,`20width,
  1450. V`20height);
  1451. X`09XFreeGC(display,`20gc);
  1452. X`09return(pix);
  1453. X`7D
  1454. $ call unpack [.MAZEWAR]WINX11.C;23 1044224713 ""
  1455. $!
  1456. $ create 'f'
  1457. X#define`20cup_width`2016
  1458. X#define`20cup_height`2016
  1459. X#define`20cup_x_hot`201
  1460. X#define`20cup_y_hot`2012
  1461. Xstatic`20char`20cup_bits`5B`5D`20=`20`7B
  1462. X`20`20`200x80,`200x00,`200x00,`200x07,`200x00,`200x08,`200xc0,`200x07,`200x20,
  1463. V`200x00,`200xf0,`200x07,
  1464. X`20`20`200x48,`200x3c,`200xf8,`200x47,`200x08,`200x58,`200x08,`200x40,`200x08,
  1465. V`200x3c,`200x18,`200x08,
  1466. X`20`20`200xf6,`200x37,`200x02,`200x20,`200xfc,`200x17,`200x00,`200x00`7D;
  1467. $ call unpack [.MAZEWAR.BITMAPS]CUP.CUR;1 91030048 ""
  1468. $!
  1469. $ create 'f'
  1470. X`7B
  1471. X`20`20`20`200x0000,`200x2088,`200x1045,`200x0082,
  1472. X`20`20`20`200x0000,`200x1000,`200x2000,`200x4100,
  1473. X`20`20`20`200x8220,`200x87ff,`200x8ffa,`200x7ffc,
  1474. X`20`20`20`200x0fe8,`200x07c0,`200x0000,`200x0000
  1475. X`7D
  1476. $ call unpack [.MAZEWAR.BITMAPS]DEADRAT.ICON;1 1426785107 ""
  1477. $!
  1478. $ create 'f'
  1479. X#define`20dRat_width`2016
  1480. X#define`20dRat_height`2016
  1481. X#define`20dRat_x_hot`200
  1482. X#define`20dRat_y_hot`209
  1483. Xstatic`20char`20dRat_bits`5B`5D`20=`20`7B
  1484. X`20`20`200x00,`200x00,`200x88,`200x20,`200x45,`200x10,`200x82,`200x00,`200x00,
  1485. V`200x00,`200x00,`200x10,
  1486. X`20`20`200x00,`200x20,`200x00,`200x41,`200x20,`200x82,`200xff,`200x87,`200xfa,
  1487. V`200x8f,`200xfc,`200x7f,
  1488. X`20`20`200xe8,`200x0f,`200xc0,`200x07,`200x00,`200x00,`200x00,`200x00`7D;
  1489. $ call unpack [.MAZEWAR.BITMAPS]DRAT.CUR;1 158162923 ""
  1490. $!
  1491. $ create 'f'
  1492. X#define`20dRatMask_width`2016
  1493. X#define`20dRatMask_height`2016
  1494. X#define`20dRatMask_x_hot`20-1
  1495. X#define`20dRatMask_y_hot`20-1
  1496. Xstatic`20char`20dRatMask_bits`5B`5D`20=`20`7B
  1497. X`20`20`200x98,`200x60,`200xdd,`200x71,`200xef,`200x38,`200xc7,`200x19,`200x82,
  1498. V`200x00,`200x00,`200x30,
  1499. X`20`20`200x00,`200xf1,`200xe0,`200xf3,`200xff,`200xc7,`200xff,`200xcf,`200xff,
  1500. V`200xff,`200xfe,`200xff,
  1501. X`20`20`200xfc,`200x7f,`200xe8,`200x0f,`200xc0,`200x07,`200x00,`200x00`7D;
  1502. $ call unpack [.MAZEWAR.BITMAPS]DRATMASK.CUR;1 1729771963 ""
  1503. $!
  1504. $ create 'f'
  1505. X#define`20icon_width`2032
  1506. X#define`20icon_height`2032
  1507. Xstatic`20char`20icon_bits`5B`5D`20=`20`7B
  1508. X`20`20`200x0000,`200x0000,`200x0000,`200x0000,`200x0002,`200x0000,`200x0000,
  1509. V`200x003c,
  1510. X`20`20`200x0004,`200x0000,`200x0000,`200x0006,`200x0008,`200x0000,`200x0000,
  1511. V`200x0005,
  1512. X`20`20`200x0010,`200x0000,`200x0080,`200x0004,`200x0020,`200x0000,`200x0040,
  1513. V`200x0004,
  1514. X`20`20`200x0040,`200x0000,`200x0020,`200x0004,`200x0040,`200x0000,`200x0010,
  1515. V`200x0004,
  1516. X`20`20`200x00c0,`200x00ff,`200x000f,`200x0004,`200x0040,`200x0000,`200x0008,
  1517. V`200x0004,
  1518. X`20`20`200x0040,`200x0000,`200x0008,`200x0004,`200x0040,`200x0000,`200x0008,
  1519. V`200x0004,
  1520. X`20`20`200x0040,`200x0000,`200x0008,`200x0004,`200x0040,`200x0000,`200x0008,
  1521. V`200x0004,
  1522. X`20`20`200x0040,`200x0000,`200x0008,`200x0004,`200x00c0,`200x00ff,`200x000f,
  1523. V`200x0004,
  1524. X`20`20`200x0040,`200x0000,`200x0010,`200x0004,`200x0040,`200x0000,`200x0020,
  1525. V`200x0004,
  1526. X`20`20`200x0020,`200x00f0,`200x0041,`200x0004,`200x0010,`200x00fa,`200x0083,
  1527. V`200x0004,
  1528. X`20`20`200x0008,`200x00ff,`200x0003,`200x0005,`200x0084,`200x00fe,`200x001f,
  1529. V`200x0006,
  1530. X`20`20`200x00c2,`200x00ff,`200x0023,`200x003c,`200x0080,`200x0010,`200x0022,
  1531. V`200x0000,
  1532. X`20`20`200x0000,`200x0000,`200x0010,`200x0000,`200x0000,`200x00c0,`200x000f,
  1533. V`200x0000,
  1534. X`20`20`200x0000,`200x0020,`200x0000,`200x0000,`200x0000,`200x0040,`200x0000,
  1535. V`200x0000,
  1536. X`20`20`200x0000,`200x0080,`200x0000,`200x0000,`200x0000,`200x0040,`200x0000,
  1537. V`200x0000,
  1538. X`20`20`200x0000,`200x0000,`200x0000,`200x0000,`200x0000,`200x0000,`200x0000,
  1539. V`200x0000`7D;
  1540. $ call unpack [.MAZEWAR.BITMAPS]ICON.IC;1 1311781663 ""
  1541. $!
  1542. $ create 'f'
  1543. X/*`20Format_version=1,`20Width=64,`20Height=64,`20Depth=1,`20Valid_bits_per_it
  1544. Vem=16
  1545. X`20*/
  1546. X`090x8888,0x8888,0x8888,0x8888,0x8800,0x0000,0x0000,0x0008,
  1547. X`090x2200,0x0000,0x0000,0x0022,0x2284,0x0000,0x0820,0x0022,
  1548. X`090x8884,0x0000,0x0820,0x0008,0x88CC,0x71F1,0xC827,0x1608,
  1549. X`090x22CC,0x8812,0x2928,0x9922,0x22B4,0x0822,0x2540,0x9022,
  1550. X`090x88B4,0x7843,0xE547,0x9008,0x8884,0x8882,0x0548,0x9008,
  1551. X`090x2284,0x8902,0x2288,0x9022,0x2284,0x79F1,0xC287,0x9022,
  1552. X`090x8800,0x0000,0x0000,0x0008,0x8800,0x0000,0x0000,0x0008,
  1553. X`090x2200,0x0000,0x0000,0x0022,0x2222,0x2222,0x2222,0x2222,
  1554. X`090x8888,0x8888,0x8888,0x8888,0x9FFF,0xFFFF,0xFFFF,0xFFFC,
  1555. X`090x3800,0x0000,0x0000,0x0006,0x3400,0x0000,0x0000,0x0006,
  1556. X`090x9200,0x0000,0x0000,0x0004,0x9100,0x0000,0x0000,0x0004,
  1557. X`090x3080,0x0000,0x0000,0x0006,0x3040,0x0000,0x0000,0x01FE,
  1558. X`090x9020,0x0000,0x0000,0x0304,0x9010,0x0000,0x0000,0x0504,
  1559. X`090x3008,0x0000,0x0000,0x0906,0x3004,0x0000,0x0000,0x1106,
  1560. X`090x9002,0x0000,0x0000,0x2104,0x9001,0x0000,0x0000,0x4104,
  1561. X`090x3000,0x8000,0x0000,0x8106,0x3000,0x4000,0x0001,0x0106,
  1562. X`090x9000,0x3FFF,0xFFFE,0x0104,0x9000,0x2000,0x0002,0x0104,
  1563. X`090x3000,0x2000,0x0002,0x0106,0x3000,0x2000,0x0002,0x0106,
  1564. X`090x9000,0x2000,0x0002,0x0104,0x9000,0x2000,0x0002,0x0104,
  1565. X`090x3000,0x2000,0x0002,0x0106,0x3000,0x2000,0x0002,0x0106,
  1566. X`090x9000,0x2000,0x0002,0x0104,0x9000,0x2000,0x0002,0x0104,
  1567. X`090x3000,0x2000,0x0002,0x0106,0x3000,0x3FFF,0xFFFE,0x0106,
  1568. X`090x9000,0x4000,0x0001,0x0104,0x9000,0x8000,0x0000,0x8104,
  1569. X`090x3001,0x0000,0x0000,0x4106,0x3002,0x0000,0x0000,0x2106,
  1570. X`090x9004,0x0000,0x0000,0x1104,0x9008,0x0001,0xF000,0x0904,
  1571. X`090x3010,0x000B,0xF800,0x0506,0x3020,0x001F,0xF800,0x0306,
  1572. X`090x9040,0x002F,0xFF00,0x01FC,0x9080,0x007F,0xF880,0x0004,
  1573. X`090x3100,0x0021,0x0880,0x0006,0x3200,0x0000,0x0100,0x0006,
  1574. X`090x9400,0x0000,0x7E00,0x0004,0x9800,0x0000,0x8000,0x0004,
  1575. X`090x3000,0x0000,0x4000,0x0006,0x3000,0x0000,0x2000,0x0006,
  1576. X`090x9FFF,0xFFFF,0xFFFF,0xFFFC,0x8888,0x8888,0x8888,0x8888,
  1577. X`090x2222,0x2222,0x2222,0x2222,0x2222,0x2222,0x2222,0x2222
  1578. $ call unpack [.MAZEWAR.BITMAPS]MAZE.ICON;1 2019630532 ""
  1579. $!
  1580. $ create 'f'
  1581. X#define`20rat_width`2016
  1582. X#define`20rat_height`2016
  1583. X#define`20rat_x_hot`200
  1584. X#define`20rat_y_hot`206
  1585. Xstatic`20char`20rat_bits`5B`5D`20=`20`7B
  1586. X`20`20`200x00,`200x00,`200x00,`200x00,`200xc0,`200x07,`200xe8,`200x0f,`200xfc,
  1587. V`200x0f,`200xfa,`200x7f,
  1588. X`20`20`200xff,`200x8f,`200x42,`200x08,`200x00,`200x40,`200x00,`200x3f,`200x80,
  1589. V`200x00,`200x00,`200x01,
  1590. X`20`20`200x00,`200x02,`200x00,`200x01,`200x00,`200x00,`200x00,`200x00`7D;
  1591. $ call unpack [.MAZEWAR.BITMAPS]RAT.CUR;1 978398403 ""
  1592. $!
  1593. $ create 'f'
  1594. X#define`20ratMask_width`2016
  1595. X#define`20ratMask_height`2016
  1596. X#define`20ratMask_x_hot`20-1
  1597. X#define`20ratMask_y_hot`20-1
  1598. Xstatic`20char`20ratMask_bits`5B`5D`20=`20`7B
  1599. X`20`20`200x00,`200x00,`200xc0,`200x07,`200xe8,`200x0f,`200xfc,`200x1f,`200xfe,
  1600. V`200x7f,`200xff,`200xff,
  1601. X`20`20`200xff,`200xff,`200xff,`200xdf,`200xe7,`200xfc,`200x00,`200xff,`200x80,
  1602. V`200x7f,`200x80,`200x03,
  1603. X`20`20`200x00,`200x03,`200x80,`200x03,`200x00,`200x01,`200x00,`200x00`7D;
  1604. X
  1605. $ call unpack [.MAZEWAR.BITMAPS]RATMASK.CUR;1 708512115 ""
  1606. $ v=f$verify(v)
  1607. $ exit
  1608.