home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / vmsnet / maxewr2 / part04 < prev    next >
Internet Message Format  |  1993-07-13  |  97KB

  1. Path: uunet!noc.near.net!howland.reston.ans.net!usc!elroy.jpl.nasa.gov!ames!koriel!lll-winken.llnl.gov!fnnews.fnal.gov!fnnews!SNYDER
  2. From: SNYDER@d0sb10.fnal.gov
  3. Newsgroups: vmsnet.sources.games
  4. Subject: Mazewar for VMS (4/5) (repost)
  5. Date: 14 Jul 1993 06:04:05 GMT
  6. Organization: SUNY Stony Brook High Energy Physics
  7. Lines: 3000
  8. Message-ID: <SNYDER.93Jul14000405@d0sb10.fnal.gov>
  9. NNTP-Posting-Host: d0sb10.fnal.gov
  10. Xref: uunet vmsnet.sources.games:754
  11.  
  12. -+-+-+-+-+-+-+-+ START OF PART 4 -+-+-+-+-+-+-+-+
  13. XX`6009`6009`6009XORToken(ratLoc->ratId);
  14. XX`6009`6009if`6020((oldVisible`6020!=`6020ratLook->visible)`6020`607C`607C
  15. XX`6009`6009`6020`6020`6020`6020(ratInfo->score`6020!=`6020ratLoc->score))`6020
  16. V`607B
  17. XX`6009`6009`6009ratInfo->score`6020=`6020ratLoc->score;
  18. XX`6009`6009`6009UpdateScoreCard(ratLoc->ratId);
  19. XX`6009`6009`607D
  20. XX`6009`6009ratHealth`605BratLoc->ratId`605D.rcvd`6020=`6020TRUE;
  21. XX`6009`6009break;
  22. XX
  23. XX`6009case`6020RAT_KILL:`6009`6009`6009/*`6020someone`6020shot`6020at`6020me
  24. V`6020*/
  25. XX`6009`6009if`6020(!M.invincible)`6020`607B
  26. XX`6009`6009`6009ratKill`6020=`6020(RatKill)`6020`6026pack->body;
  27. XX`6009`6009`6009holdBreath(ratKill);
  28. XX`6009`6009`607D
  29. XX`6009`6009break;
  30. XX
  31. XX`6009case`6020RAT_DEAD:`6009`6009`6009/*`6020I`6020hit`6020someone`6020*/
  32. XX`6009`6009ratDead`6020=`6020(RatDead)`6020`6026pack->body;
  33. XX`6009`6009if`6020(ratDead->killedBy`6020==`6020M.myRatId)`6020`607B
  34. XX`6009`6009`6009FlashTop();`6009/*`6020got`6020him!`6020*/
  35. XX`6009`6009`6009M.score`6020+=`602010;`6009/*`602010`6020points`6020for`6020a
  36. V`6020kill`6020*/
  37. XX`6009`6009`6009M.score`6020+=`60201;`6009/*`6020make`6020up`6020for`6020shot
  38. V`6020cost`6020*/
  39. XX`6009`6009`6009M.ratcb.rats`605BM.myRatId`605D.score`6020=`6020M.score;
  40. XX`6009`6009`6009UpdateScoreCard(M.myRatId);
  41. XX`6009`6009`6009sendLocToAll();
  42. XX`6009`6009`607D
  43. XX`6009`6009break;
  44. XX
  45. XX`6009case`6020RAT_STATUS:`6009`6009/*`6020new`6020info`6020about`6020everyone
  46. V`6020*/
  47. XX`6009`6009status`6020=`6020(RatStatus)`6020`6026pack->body;
  48. XX`6009`6009if`6020(bcmp(`6026status->rats`605BM.myRatId`605D.addr,`6020`6026M.
  49. VmyAddr,
  50. XX`6009`6009`6009`6020`6020sizeof(M.myAddr))`6020!=`60200)
  51. XX`6009`6009`6009break;`6009`6009/*`6020not`6020for`6020me,`6020from`6020anothe
  52. Vr`6020game`6020*/
  53. XX`6009`6009`6009`6009`6009/*`6020perhaps`6020left`6020over`6020from`6020findDu
  54. Vke()`6020*/
  55. XX
  56. XX`6009`6009/*`6020Have`6020a`6020new`6020table,`6020turn`6020off`6020any`6020v
  57. Visible`6020opponents
  58. XV`6020*/
  59. XX
  60. XX`6009`6009for`6020(ratId`6020=`60200;`6020ratId`6020<`6020MAXRATS;`6020ratId+
  61. V+)
  62. XX`6009`6009`6009if`6020(R2d2`605BratId`605D.visible`6020==`6020TRUE)
  63. XX`6009`6009`6009`6009XORToken(ratId);
  64. XX`6009`6009bcopy((char`6020*)status,`6020(char`6020*)`6026M.ratcb,`6020sizeof(
  65. VRatCb));
  66. XX`6009`6009if`6020(M.ratcb.dukeRat`6020==`6020M.myRatId)
  67. XX`6009`6009`6009M.duke`6020=`6020TRUE;
  68. XX`6009`6009for`6020(ratId`6020=`60200;`6020ratId`6020<`6020MAXRATS;`6020ratId+
  69. V+)`6020`607B
  70. XX`6009`6009`6009TokenVisible(ratId);
  71. XX`6009`6009`6009if`6020(R2d2`605BratId`605D.visible`6020==`6020TRUE)
  72. XX`6009`6009`6009`6009XORToken(ratId);
  73. XX`6009`6009`607D
  74. XX`6009`6009NewScoreCard();
  75. XX`6009`6009ratInfo`6020=`6020`6026M.ratcb.rats`605BM.myRatId`605D;
  76. XX`6009`6009if`6020((ratInfo->xLoc`6020!=`6020M.xloc)`6020`607C`607C
  77. XX`6009`6009`6020`6020`6020`6020(ratInfo->yLoc`6020!=`6020M.yloc)`6020`607C`607
  78. VC
  79. XX`6009`6009`6020`6020`6020`6020(ratInfo->dir`6020`6020!=`6020M.dir))
  80. XX`6009`6009`6009sendLocToAll();
  81. XX`6009`6009
  82. XX`6009`6009break;
  83. XX
  84. XX`6009case`6020RAT_NEW:`6009`6009`6009/*`6020new`6020player`6020*/
  85. XX`6009`6009ratNew`6020=`6020(RatNew)`6020`6026pack->body;
  86. XX`6009`6009if`6020(ratNew->pass`6020==`6020RAT_PASSWORD)`6020`607B
  87. XX`6009`6009`6009if`6020(M.duke)`6020`607B
  88. XX`6009`6009`6009`6009/*`6020
  89. XX`6009`6009`6009`6009`6020*`6020need`6020to`6020check`6020for`6020duplicates
  90. V`6020here;
  91. XX`6009`6009`6009`6009`6020*`6020a`6020previous`6020reply`6020might`6020have
  92. V`6020been
  93. XX`6009`6009`6009`6009`6020*`6020lost.`6020Can't`6020let`6020the`6020same`6020g
  94. Vuy`6020in`6020the
  95. XX`6009`6009`6009`6009`6020*`6020game`6020twice.
  96. XX`6009`6009`6009`6009`6020*/
  97. XX
  98. XX`6009`6009`6009`6009register`6020RatId`6009id;
  99. XX
  100. XX`6009`6009`6009`6009for`6020(id`6020=`60200;`6020id`6020<`6020MAXRATS;`6020id
  101. V++)
  102. XX`6009`6009`6009`6009`6009if`6020(M.ratcb.rats`605Bid`605D.playing`6020`6026
  103. V`6026
  104. XX`6009`6009`6009`6009`6009`6020`6020`6020`6020!bcmp(`6026M.ratcb.rats`605Bid
  105. V`605D.addr,
  106. XX`6009`6009`6009`6009`6009`6009`6020`6020`6026evp->eventSource,
  107. XX`6009`6009`6009`6009`6009`6009`6020`6020sizeof`6020(Sockaddr)))`6020`607B
  108. XX
  109. XX`6009`6009`6009`6009`6009`6009/*`6020already`6020there`6020*/
  110. XX`6009`6009`6009`6009`6009`6009sendStatus(evp->eventSource);
  111. XX`6009`6009`6009`6009`6009`6009break;
  112. XX`6009`6009`6009`6009`6009`607D
  113. XX`6009`6009`6009`6009if`6020(id`6020>=`6020MAXRATS)`6020`607B`6009/*`6020fell
  114. V`6020through`6020*/
  115. XX`6009`6009`6009`6009`6009allocateNewRat(ratNew);
  116. XX`6009`6009`6009`6009`6009sendAllStatus();
  117. XX`6009`6009`6009`6009`607D
  118. XX`6009`6009`6009`607D`6020else
  119. XX`6009`6009`6009`6009sendStatus(evp->eventSource);
  120. XX`6009`6009`607D
  121. XX`6009`6009break;
  122. XX
  123. XX`6009case`6020RAT_GOING:`6009`6009`6020`6020`6020`6020`6020`6020`6020/*`6020p
  124. Vlayer`6020leaving,`6020only
  125. XV`6020rcvd`6020if`6020duke`6020*/
  126. XX`6009`6009ratGone`6020=`6020(RatGone)`6020`6026pack->body;
  127. XX`6009`6009ratLeft(ratGone->ratId);
  128. XX`6009`6009break;
  129. XX
  130. XX`6009case`6020RAT_QUERY:`6009`6009`6009/*`6020are`6020you`6020alive?`6020*/
  131. XX`6009`6009/*
  132. XX`6009`6009`6020*`6020register`6020their`6020net`6020address,`6020in`6020case
  133. V`6020they`6020got`6020a
  134. XX`6009`6009`6020*`6020RAT_MOVE,`6020moved,`6020and`6020the`6020change`6020got
  135. V`6020lost`6020somewhere.
  136. XV
  137. XX`6009`6009`6020*/
  138. XX`6009`6009ratQuery`6020=`6020(RatQuery)`6020`6026pack->body;
  139. XX`6009`6009M.ratcb.rats`605BratQuery->ratId`605D.addr`6020=`6020evp->eventSour
  140. Vce;
  141. XX
  142. XX`6009`6009sendAlive();
  143. XX`6009`6009break;
  144. XX
  145. XX`6009case`6020RAT_ALIVE:`6009`6009`6009/*`6020I`6020am`6020alive`6020*/
  146. XX`6009`6009ratAlive`6020=`6020(RatAlive)`6020`6026pack->body;
  147. XX`6009`6009ratHealth`605BratAlive->ratId`605D.rcvd`6020=`6020TRUE;
  148. XX`6009`6009break;
  149. XX
  150. XX`6009case`6020RAT_SURVEY:`6009`6009/*`6020who's`6020out`6020there?`6020*/
  151. XX`6009`6009ratNew`6020=`6020(RatNew)`6020`6026pack->body;
  152. XX`6009`6009if`6020(ratNew->pass`6020==`6020RAT_PASSWORD)
  153. XX`6009`6009`6009sendStatus(evp->eventSource);
  154. XX`6009`6009break;
  155. XX
  156. XX`6009case`6020RAT_MOVE:`6009`6009`6009/*`6020move`6020to`6020M.mazePort`6020*
  157. V/
  158. XX`6009`6009ratMove`6020=`6020(RatMove)`6020`6026pack->body;
  159. XX`6009`6009if`6020(ratMove->ratId`6020!=`6020M.ratcb.dukeRat)
  160. XX`6009`6009`6009MWError("bogus`6020RAT_MOVE");
  161. XX#ifdef`6020VMS
  162. XX`6009`6009socket_close(M.theSocket);
  163. XX#else
  164. XX`6009`6009close(M.theSocket);
  165. XX#endif
  166. XX
  167. XX`6009`6009/*`6020
  168. XX`6009`6009`6020*`6020If`6020the`6020socket`6020being`6020closed`6020is`6020on
  169. V`6020this`6020machine,
  170. XX`6009`6009`6020*`6020leave`6020some`6020time`6020for`6020the`6020socket`6020t
  171. Vo`6020close`6020down`6020be
  172. XVfore
  173. XX`6009`6009`6020*`6020I`6020try`6020to`6020grab`6020it.
  174. XX`6009`6009`6020*/
  175. XX
  176. XX`6009`6009if`6020(bcmp((char`6020*)`6020`6026evp->eventSource.sin_addr,
  177. XX`6009`6009`6009`6020`6020(char`6020*)`6020`6026M.myAddr.sin_addr,
  178. XX`6009`6009`6009`6020`6020sizeof(M.myAddr.sin_addr))`6020==`60200)
  179. XX`6009`6009`6009sleep(1);
  180. XX
  181. XX`6009`6009/*`6020grab`6020the`6020socket`6020*/
  182. XX
  183. XX`6009`6009newSocket`6020=`6020socket(AF_INET,`6020SOCK_DGRAM,`60200);
  184. XX`6009`6009if`6020(newSocket`6020<`60200)
  185. XX`6009`6009`6009MWError("RAT_MOVE`6020lost`6020socket");
  186. XX#ifdef`6020VMS
  187. XX`6009`6009M.theSocket`6020=`6020newSocket;
  188. XX#else
  189. XX`6009`6009if`6020(dup2(newSocket,`6020M.theSocket)`6020<`60200)
  190. XX`6009`6009`6009MWError("RAT_MOVE`6020dup2`6020failed");
  191. XX#endif
  192. XX`6009`6009`607B
  193. XX`6009`6009`6020`6020int`6020opt`6020=`60201;
  194. XX`6009`6009`6020`6020if`6020(setsockopt(M.theSocket,`6020SOL_SOCKET,`6020SO_RE
  195. VUSEADDR,
  196. XX`6009`6009`6009`6009`6020`6026opt,`6020sizeof`6020(opt))`6020<`60200)
  197. XX`6009`6009`6020`6020`6020`6020MWError("RAT_MOVE`6020can't`6020reuse`6020addre
  198. Vsses");
  199. XX`6009`6009`607D
  200. XX`6009`6009M.myAddr.sin_port`6020=`6020M.mazePort;
  201. XX`6009`6009nullAddr`6020=`6020M.myAddr;`6009/*`6020see`6020netInit()`6020*/
  202. XX`6009`6009bzero((char`6020*)`6020`6026nullAddr.sin_addr,`6020sizeof(nullAddr.
  203. Vsin_addr));
  204. XX`6009`6009if`6020(bind(M.theSocket,`6020`6026nullAddr,`6020sizeof(nullAddr))
  205. V`6020<`60200)
  206. XX`6009`6009`6009MWError("RAT_MOVE`6020can't`6020bind");
  207. XX#ifdef`6020VMS
  208. XX`6009`6009arm_net_input`6020(M.theSocket);
  209. XX#endif
  210. XX`6009`6009M.ratcb.rats`605BM.myRatId`605D.addr`6020=`6020M.myAddr;
  211. XX`6009`6009sendAllStatus();
  212. XX`6009`6009break;
  213. XX
  214. XX`6009default:
  215. XX`6009`6009sprintf(buf,`6020"readRats`6020bad`6020packet`6020type`60200x%x",
  216. V`6020pack->type);
  217. XX`6009`6009MWError(buf);
  218. XX`6009`607D
  219. XX`607D
  220. XX
  221. XX/*`6020
  222. XX`6020*`6020In`6020order`6020to`6020reduce`6020the`6020network`6020traffic,
  223. V`6020only`6020send`6020out
  224. XV`6020the`6020location`6020change`6020if
  225. XX`6020*`6020there's`6020no`6020keyboard`6020input`6020pending.
  226. XX`6020*/
  227. XX
  228. XXSendLocation()
  229. XX`607B
  230. XX`6009Boolean`6009`6009KBEventPending();
  231. XX`6009if`6020(!KBEventPending())
  232. XX`6009`6009if`6020(sendLocation)`6020`607B
  233. XX`6009`6009`6009sendLocToAll();
  234. XX`6009`6009`6009sendLocation`6020=`6020FALSE;
  235. XX`6009`6009`607D
  236. XX`607D
  237. XX
  238. XX/*`6020
  239. XX`6020*`6020Let`6020everyone`6020know`6020I've`6020moved.
  240. XX`6020*/
  241. XX
  242. XXsendLocToAll()
  243. XX`607B
  244. XX`6009RatPacket`6009pack;
  245. XX`6009RatLocation`6009ratloc;
  246. XX`6009RatId`6009`6009i;
  247. XX`6009RatInfo`6009`6009ratInfo`6020=`6020`6026M.ratcb.rats`605BM.myRatId`605D;
  248. V
  249. XX
  250. XX`6009ratInfo->xLoc`6020=`6020M.xloc;`6009`6009/*`6020update`6020my`6020table,
  251. V`6020too`6020*/
  252. XX`6009ratInfo->yLoc`6020=`6020M.yloc;
  253. XX`6009ratInfo->dir`6020`6020=`6020M.dir;
  254. XX`6009ratInfo->score`6020=`6020M.score;
  255. XX
  256. XX`6009pack.type`6020=`6020RAT_LOCATION;
  257. XX`6009ratloc`6020=`6020(RatLocation)`6020`6026pack.body;
  258. XX`6009ratloc->ratId`6020=`6020M.myRatId;
  259. XX`6009ratloc->xLoc`6020=`6020ratInfo->xLoc;
  260. XX`6009ratloc->yLoc`6020=`6020ratInfo->yLoc;
  261. XX`6009ratloc->dir`6020=`6020ratInfo->dir;
  262. XX`6009ratloc->score`6020=`6020ratInfo->score;
  263. XX`6009ConvertOutgoing(`6026pack);
  264. XX`6009
  265. XX`6009/*`6020
  266. XX`6009`6020*`6020Would`6020really`6020like`6020this`6020to`6020be`6020asynchro
  267. Vnous,`6020so`6020play
  268. XV`6020could
  269. XX`6009`6020*`6020continue`6020while`6020the`6020packets`6020are`6020being`6020
  270. Vsent.`6020Of`6020course
  271. XV,`6020then,
  272. XX`6009`6020*`6020the`6020data`6020might`6020change`6020in`6020the`6020midst
  273. V`6020of`6020all`6020this...
  274. XX`6009`6020*/
  275. XX
  276. XX`6009for`6020(i`6020=`60200;`6020i`6020<`6020MAXRATS;`6020i++)
  277. XX`6009`6009if`6020((i`6020!=`6020M.myRatId)`6020`6026`6026`6020(M.ratcb.rats
  278. V`605Bi`605D.playing))
  279. XX`6009`6009`6009if`6020(sendto(M.theSocket,`6020`6026pack,`6020sizeof(pack),
  280. V`60200,
  281. XX`6009`6009`6009`6009`6020`6020`6026M.ratcb.rats`605Bi`605D.addr,`6020sizeof(S
  282. Vockaddr))`6020<`60200)
  283. XX`6009`6009`6009`6009MWError("sendLocToAll");
  284. XX`607D
  285. XX
  286. XXsendAllStatus()
  287. XX`607B
  288. XX`6009RatId`6009i;
  289. XX
  290. XX`6009for`6020(i`6020=`60200;`6020i`6020<`6020MAXRATS;`6020i++)
  291. XX`6009`6009if`6020((i`6020!=`6020M.myRatId)`6020`6026`6026`6020(M.ratcb.rats
  292. V`605Bi`605D.playing))
  293. XX`6009`6009`6009sendStatus(M.ratcb.rats`605Bi`605D.addr);
  294. XX`607D
  295. XX
  296. XX/*`6020
  297. XX`6020*`6020Send`6020the`6020entire`6020status`6020data`6020to`6020a`6020rat.
  298. XX`6020*/
  299. XX
  300. XXsendStatus(to)
  301. XXSockaddr`6020to;
  302. XX`607B
  303. XX`6009RatPacket`6009pack;
  304. XX
  305. XX`6009pack.type`6020=`6020RAT_STATUS;
  306. XX`6009pack.body`6020=`6020M.ratcb;
  307. XX`6009ConvertOutgoing(`6026pack);
  308. XX`6009if`6020(sendto(M.theSocket,`6020`6026pack,`6020sizeof(pack),`60200,`6020
  309. V`6026to,`6020sizeof
  310. XV(to))`6020<`60200)
  311. XX`6009`6009MWError("sendStatus");
  312. XX`607D
  313. XX
  314. XX/*`6020
  315. XX`6020*`6020Tell`6020a`6020player`6020he's`6020being`6020shot`6020at.
  316. XX`6020*/
  317. XX
  318. XXsendKill()
  319. XX`607B
  320. XX`6009RatPacket`6009pack;
  321. XX`6009RatKill`6009`6009ratKill;
  322. XX`6009RatId`6009`6009ixRatId;
  323. XX
  324. XX`6009for`6020(ixRatId`6020=`60200;`6020ixRatId`6020<`6020MAXRATS;`6020ixRatId
  325. V++)`6020`607B
  326. XX`6009`6009if`6020(ixRatId`6020==`6020M.myRatId)
  327. XX`6009`6009`6009continue;
  328. XX`6009`6009if`6020(R2d2`605BixRatId`605D.visible)`6020`607B
  329. XX`6009`6009`6009pack.type`6020=`6020RAT_KILL;
  330. XX`6009`6009`6009ratKill`6020=`6020(RatKill)`6020`6026pack.body;
  331. XX`6009`6009`6009ratKill->ratId`6020=`6020M.myRatId;
  332. XX`6009`6009`6009ratKill->xLoc`6020=`6020M.xloc;
  333. XX`6009`6009`6009ratKill->yLoc`6020=`6020M.yloc;
  334. XX`6009`6009`6009ratKill->dir`6020`6020=`6020M.dir;
  335. XX`6009`6009`6009ConvertOutgoing(`6026pack);
  336. XX`6009`6009`6009if`6020(sendto(M.theSocket,`6020`6026pack,`6020sizeof(pack),
  337. V`60200,
  338. XX`6009`6009`6009`6009`6020`6020`6020`6026M.ratcb.rats`605BixRatId`605D.addr,
  339. XX`6009`6009`6009`6009`6020`6020`6020sizeof(M.ratcb.rats`605BixRatId`605D.addr)
  340. V)`6020<`60200)
  341. XX`6009`6009`6009`6009MWError("sendKill");
  342. XX`6009`6009`607D
  343. XX`6009`607D
  344. XX`607D
  345. XX
  346. XX/*`6020
  347. XX`6020*`6020Tell`6020a`6020shooter`6020he`6020hit`6020me.
  348. XX`6020*/
  349. XX
  350. XXsendDead(killerRatId)
  351. XXRatId`6009killerRatId;
  352. XX`607B
  353. XX`6009RatPacket`6009pack;
  354. XX`6009RatDead`6009`6009ratDead;
  355. XX
  356. XX`6009pack.type`6020=`6020RAT_DEAD;
  357. XX`6009ratDead`6020=`6020(RatDead)`6020`6026pack.body;
  358. XX`6009ratDead->ratId`6020=`6020M.myRatId;
  359. XX`6009ratDead->killedBy`6020=`6020killerRatId;
  360. XX`6009ConvertOutgoing(`6026pack);
  361. XX`6009if`6020(sendto(M.theSocket,`6020`6026pack,`6020sizeof(pack),`60200,
  362. XX`6009`6009`6020`6020`6026M.ratcb.rats`605BkillerRatId`605D.addr,`6020sizeof(S
  363. Vockaddr))`6020<`60200
  364. XV)
  365. XX`6009`6009MWError("sendDead");
  366. XX`607D
  367. XX
  368. XX/*`6020
  369. XX`6020*`6020Tell`6020the`6020duke`6020I'm`6020leaving.
  370. XX`6020*/
  371. XX
  372. XXsendGoing()
  373. XX`607B
  374. XX`6009RatPacket`6009pack;
  375. XX`6009RatGone`6009`6009ratGone;
  376. XX
  377. XX`6009pack.type`6020=`6020RAT_GOING;
  378. XX`6009ratGone`6020=`6020(RatGone)`6020`6026pack.body;
  379. XX`6009ratGone->ratId`6020=`6020M.myRatId;
  380. XX`6009ConvertOutgoing(`6026pack);
  381. XX`6009if`6020(sendto(M.theSocket,`6020`6026pack,`6020sizeof(pack),`60200,
  382. XX`6009`6009`6020`6020`6026M.ratcb.rats`605BM.ratcb.dukeRat`605D.addr,`6020size
  383. Vof(Sockaddr))`6020<
  384. XV`60200)
  385. XX`6009`6009MWError("sendGoing");
  386. XX`607D
  387. XX
  388. XX/*`6020
  389. XX`6020*`6020Ask`6020the`6020silent`6020types`6020if`6020they're`6020alive.
  390. XX`6020*/
  391. XX
  392. XXsendQuery()
  393. XX`607B
  394. XX`6009RatPacket`6009pack;
  395. XX`6009RatId`6009`6009ratId;
  396. XX`6009RatQuery`6009ratQuery;
  397. XX
  398. XX`6009for`6020(ratId`6020=`60200;`6020ratId`6020<`6020MAXRATS;`6020ratId++)
  399. XX`6009`6009if`6020(ratHealth`605BratId`605D.send)`6020`607B
  400. XX`6009`6009`6009pack.type`6020=`6020RAT_QUERY;
  401. XX`6009`6009`6009ratQuery`6020=`6020(RatQuery)`6020`6026pack.body;
  402. XX`6009`6009`6009ratQuery->ratId`6020=`6020M.myRatId;
  403. XX`6009`6009`6009ratHealth`605BratId`605D.send`6020=`6020FALSE;
  404. XX`6009`6009`6009ConvertOutgoing(`6026pack);
  405. XX`6009`6009`6009if`6020(sendto(M.theSocket,`6020`6026pack,`6020sizeof(pack),
  406. V`60200,
  407. XX`6009`6009`6009`6009`6020`6020`6026M.ratcb.rats`605BratId`605D.addr,
  408. XX`6009`6009`6009`6009`6020`6020sizeof(Sockaddr))`6020<`60200)
  409. XX`6009`6009`6009`6009MWError("sendQuery");
  410. XX`6009`6009`607D
  411. XX`607D
  412. XX
  413. XX/*`6020
  414. XX`6020*`6020Register`6020someone`6020as`6020alive,`6020and`6020let`6020them
  415. V`6020know`6020we`6020are,
  416. XV`6020too.`6020
  417. XX`6020*/
  418. XX
  419. XXsendAlive()
  420. XX`607B
  421. XX`6009RatPacket`6009pack;
  422. XX`6009RatId`6009`6009ratId;
  423. XX`6009RatAlive`6009ratAlive;
  424. XX
  425. XX`6009for`6020(ratId`6020=`60200;`6020ratId`6020<`6020MAXRATS;`6020ratId++)
  426. V`6020`607B
  427. XX`6009`6009if`6020((ratId`6020==`6020M.myRatId)`6020`607C`607C
  428. XX`6009`6009`6020`6020`6020`6020!M.ratcb.rats`605BratId`605D.playing)
  429. XX`6009`6009`6009continue;
  430. XX`6009`6009pack.type`6020=`6020RAT_ALIVE;
  431. XX`6009`6009ratAlive`6020=`6020(RatAlive)`6020`6026pack.body;
  432. XX`6009`6009ratAlive->ratId`6020=`6020M.myRatId;
  433. XX`6009`6009ConvertOutgoing(`6026pack);
  434. XX`6009`6009if`6020(sendto(M.theSocket,`6020`6026pack,`6020sizeof(pack),`60200,
  435. V
  436. XX`6009`6009`6020`6020`6020`6020`6020`6020`6026M.ratcb.rats`605BratId`605D.addr
  437. V,`6020sizeof(Sockaddr))
  438. XV`6020<`60200)
  439. XX`6009`6009`6009MWError("sendAlive");
  440. XX`6009`607D
  441. XX`607D
  442. XX
  443. XX/*`6020
  444. XX`6020*`6020Let`6020a`6020new`6020player`6020in`6020the`6020game.
  445. XX`6020*/
  446. XX
  447. XXallocateNewRat(ratNew)
  448. XXRatNew`6009ratNew;
  449. XX`607B
  450. XX`6009RatId`6009ratId;
  451. XX`6009RatInfo`6009ratInfo;
  452. XX
  453. XX`6009for`6020(ratId`6020=`60200;`6020ratId`6020<`6020MAXRATS;`6020ratId++)
  454. V`6020`607B
  455. XX`6009`6009ratInfo`6020=`6020`6026M.ratcb.rats`605BratId`605D;
  456. XX`6009`6009if`6020(!ratInfo->playing)`6020`607B
  457. XX`6009`6009`6009ratInfo->playing`6020=`6020TRUE;
  458. XX`6009`6009`6009ratInfo->xLoc`6020=`6020ratNew->xLoc;
  459. XX`6009`6009`6009ratInfo->yLoc`6020=`6020ratNew->yLoc;
  460. XX`6009`6009`6009ratInfo->dir`6020`6020=`6020ratNew->dir;
  461. XX`6009`6009`6009ratInfo->score`6020=`60200;
  462. XX`6009`6009`6009ratInfo->addr`6020=`6020ratNew->addr;
  463. XX`6009`6009`6009strncpy(ratInfo->name,`6020ratNew->name,`6020NAMESIZE);
  464. XX`6009`6009`6009TokenVisible(ratId);
  465. XX`6009`6009`6009UpdateScoreCard(ratId);
  466. XX`6009`6009`6009if`6020(R2d2`605BratId`605D.visible`6020==`6020TRUE)
  467. XX`6009`6009`6009`6009XORToken(ratId);
  468. XX`6009`6009`6009AddNewPlayer(ratId,`6020ratNew->xLoc,`6020ratNew->yLoc,
  469. XX`6009`6009`6009`6009`6009ratNew->dir);
  470. XX`6009`6009`6009return;
  471. XX`6009`6009`607D
  472. XX`6009`607D
  473. XX`607D
  474. XX
  475. XX/*`6020
  476. XX`6020*`6020I`6020wanna`6020go`6020home!
  477. XX`6020*/
  478. XX
  479. XXquit()
  480. XX`607B
  481. XX`6009RatId`6009ratId;
  482. XX
  483. XX`6009if`6020(!M.duke)
  484. XX`6009`6009sendGoing();
  485. XX`6009else`6020`607B`6009`6009`6009`6009/*`6020oh`6020oh,`6020I'm`6020the`6020
  486. Vduke`6020rat`6020*/
  487. XX`6009`6009M.ratcb.rats`605BM.myRatId`605D.playing`6020=`6020FALSE;
  488. XX`6009`6009for`6020(ratId`6020=`60200;`6020ratId`6020<`6020MAXRATS;`6020ratId+
  489. V+)
  490. XX`6009`6009`6009if`6020(M.ratcb.rats`605BratId`605D.playing)`6020`607B
  491. XX`6009`6009`6009`6009M.ratcb.dukeRat`6020=`6020ratId;
  492. XX`6009`6009`6009`6009sendAllStatus();
  493. XX`6009`6009`6009`6009break;
  494. XX`6009`6009`6009`607D
  495. XX`6009`6009moveSomeone(M.myRatId);
  496. XX`6009`607D
  497. XX`6009StopWindow();
  498. XX`6009exit(0);
  499. XX`607D
  500. XX
  501. XX/*`6020
  502. XX`6020*`6020Clean`6020up`6020after`6020someone`6020who`6020has`6020left.`6020L
  503. Vet`6020everyone`6020els
  504. XVe`6020know,`6020too.
  505. XX`6020*/
  506. XX
  507. XXratLeft(ratId)
  508. XXRatId`6009ratId;
  509. XX`607B
  510. XX`6009if`6020(R2d2`605BratId`605D.visible`6020==`6020TRUE)
  511. XX`6009`6009XORToken(ratId);
  512. XX`6009R2d2`605BratId`605D.visible`6020=`6020FALSE;
  513. XX`6009M.ratcb.rats`605BratId`605D.playing`6020=`6020FALSE;
  514. XX`6009ExitPlayer(ratId);
  515. XX`6009UpdateScoreCard(ratId);
  516. XX`6009sendAllStatus();
  517. XX`6009moveSomeone(ratId);
  518. XX`607D
  519. XX
  520. XX/*`6020
  521. XX`6020*`6020See`6020if`6020the`6020guy`6020leaving`6020has`6020vacated`6020the
  522. V`6020reserved`6020port.
  523. XV`6020If`6020so,`6020try`6020to
  524. XX`6020*`6020find`6020someone`6020else`6020on`6020that`6020machine`6020and`6020
  525. Vtell`6020him`6020to`6020m
  526. XVove`6020there.
  527. XX`6020*/
  528. XX
  529. XXmoveSomeone(ratId)
  530. XXRatId`6009ratId;
  531. XX`607B
  532. XX`6009Sockaddr`6009hisAddr;
  533. XX`6009RatId`6009`6009newRat;
  534. XX`6009RatPacket`6009pack;
  535. XX`6009RatMove`6009`6009ratMove;
  536. XX
  537. XX`6009hisAddr`6020=`6020M.ratcb.rats`605BratId`605D.addr;
  538. XX`6009if`6020(hisAddr.sin_port`6020!=`6020M.mazePort)
  539. XX`6009`6009return;
  540. XX
  541. XX`6009for`6020(newRat`6020=`60200;`6020newRat`6020<`6020MAXRATS;`6020newRat++)
  542. V`6020`607B
  543. XX`6009`6009if`6020(newRat`6020==`6020ratId)
  544. XX`6009`6009`6009continue;
  545. XX`6009`6009if`6020(M.ratcb.rats`605BnewRat`605D.playing`6020==`6020FALSE)
  546. XX`6009`6009`6009continue;
  547. XX`6009`6009if`6020(!bcmp(`6026M.ratcb.rats`605BnewRat`605D.addr.sin_addr,
  548. XX`6009`6009`6009`6020`6020`6026hisAddr.sin_addr,`6020sizeof(hisAddr.sin_addr))
  549. V)`6020`607B
  550. XX`6009`6009`6009pack.type`6020=`6020RAT_MOVE;
  551. XX`6009`6009`6009ratMove`6020=`6020(RatMove)`6020`6026pack.body;
  552. XX`6009`6009`6009ratMove->ratId`6020=`6020M.ratcb.dukeRat;
  553. XX`6009`6009`6009ConvertOutgoing(`6026pack);
  554. XX`6009`6009`6009if`6020(sendto(M.theSocket,`6020`6026pack,`6020sizeof(pack),
  555. V`60200,
  556. XX`6009`6009`6009`6009`6020`6020`6026M.ratcb.rats`605BnewRat`605D.addr,
  557. XX`6009`6009`6009`6009`6020`6020sizeof(Sockaddr))`6020<`60200)
  558. XX`6009`6009`6009`6009MWError("moveSomeone");
  559. XX
  560. XX`6009`6009`6009/*`6020
  561. XX`6009`6009`6009`6020*`6020If`6020I'm`6020the`6020one`6020leaving,`6020must
  562. V`6020free`6020up`6020my`6020port
  563. XV.
  564. XX`6009`6009`6009`6020*/
  565. XX
  566. XX`6009`6009`6009if`6020(ratId`6020==`6020M.myRatId)
  567. XX#ifdef`6020VMS
  568. XX`6009`6009`6009`6009socket_close(M.theSocket);
  569. XX#else
  570. XX`6009`6009`6009`6009close(M.theSocket);
  571. XX#endif
  572. XX`6009`6009`6009break;
  573. XX`6009`6009`607D
  574. XX`6009`607D
  575. XX`6009`6009
  576. XX`607D
  577. XX
  578. XX/*`6020
  579. XX`6020*`6020Make`6020sure`6020nobody`6020has`6020died`6020unnoticed.
  580. XX`6020*/
  581. XX
  582. XXstatic`6020Boolean`6009`6009started`6020=`6020FALSE;
  583. XXstruct`6020timeval`6009waitStart;
  584. XXstatic`6020Boolean`6009`6009runDoctor`6020=`6020TRUE;
  585. XX
  586. XXstatic
  587. XXratDoctor()
  588. XX`607B
  589. XX`6009RatId`6009ratId,`6020nextRatId();
  590. XX`6009struct`6020timeval`6009now;
  591. XX
  592. XX`6009if`6020(!runDoctor)
  593. XX`6009`6009return;
  594. XX
  595. XX`6009if`6020(started`6020==`6020FALSE)`6020`607B
  596. XX`6009`6009gettimeofday(`6026waitStart,`6020NULL);
  597. XX`6009`6009for`6020(ratId`6020=`60200;`6020ratId`6020<`6020MAXRATS;`6020ratId+
  598. V+)`6020`607B
  599. XX`6009`6009`6009ratHealth`605BratId`605D.count`6020=`60200;
  600. XX`6009`6009`6009ratHealth`605BratId`605D.send`6020=`6020FALSE;
  601. XX`6009`6009`6009ratHealth`605BratId`605D.rcvd`6020=`6020FALSE;
  602. XX`6009`6009`607D
  603. XX`6009`6009started`6020=`6020TRUE;
  604. XX`6009`6009return;
  605. XX`6009`607D`6020else`6020`607B
  606. XX`6009`6009gettimeofday(`6026now,`6020NULL);
  607. XX`6009`6009if`6020((now.tv_sec`6020-`6020waitStart.tv_sec)`6020<`60205)
  608. XX`6009`6009`6009return;
  609. XX`6009`6009for`6020(ratId`6020=`60200;`6020ratId`6020<`6020MAXRATS;`6020ratId+
  610. V+)`6020`607B
  611. XX`6009`6009`6009if`6020((!M.ratcb.rats`605BratId`605D.playing)`6020`607C`607C
  612. XX`6009`6009`6009`6020`6020`6020`6020(ratId`6020==`6020M.myRatId))
  613. XX`6009`6009`6009`6009continue;
  614. XX`6009`6009`6009if`6020(ratHealth`605BratId`605D.rcvd)`6020`607B
  615. XX`6009`6009`6009`6009ratHealth`605BratId`605D.count`6020=`60200;
  616. XX`6009`6009`6009`6009ratHealth`605BratId`605D.rcvd`6020=`6020FALSE;
  617. XX`6009`6009`6009`6009continue;
  618. XX`6009`6009`6009`607D
  619. XX`6009`6009`6009if`6020(++ratHealth`605BratId`605D.count`6020<`60205)`6020`607
  620. VB
  621. XX`6009`6009`6009`6009ratHealth`605BratId`605D.send`6020=`6020TRUE;
  622. XX`6009`6009`6009`6009continue;
  623. XX`6009`6009`6009`607D
  624. XX`6009`6009`6009if`6020(M.duke`6020`607C`607C
  625. XX`6009`6009`6009`6020`6020`6020`6020((M.ratcb.dukeRat`6020==`6020ratId)`6020
  626. V`6026`6026
  627. XX`6009`6009`6009`6020`6020`6020`6020`6020(nextRatId(ratId)`6020==`6020M.myRatI
  628. Vd)))`6020`607B
  629. XX`6009`6009`6009`6009M.duke`6020=`6020TRUE;
  630. XX`6009`6009`6009`6009M.ratcb.dukeRat`6020=`6020M.myRatId;
  631. XX`6009`6009`6009`6009ratLeft(ratId);
  632. XX`6009`6009`6009`607D
  633. XX`6009`6009`607D
  634. XX`6009`6009sendQuery();
  635. XX`6009`6009gettimeofday(`6026waitStart,`6020NULL);
  636. XX`6009`607D
  637. XX`6009
  638. XX`607D
  639. XX
  640. XXRatId
  641. XXnextRatId(ratId)
  642. XXRatId`6009ratId;
  643. XX`607B
  644. XX`6009RatId`6009ixRatId;
  645. XX
  646. XX`6009for`6020(ixRatId`6020=`60200;`6020ixRatId`6020<`6020MAXRATS;`6020ixRatId
  647. V++)
  648. XX`6009`6009if`6020(M.ratcb.rats`605BixRatId`605D.playing`6020`6026`6026
  649. XX`6009`6009`6020`6020`6020`6020(ixRatId`6020!=`6020ratId))
  650. XX`6009`6009`6009return`6020ixRatId;
  651. XX`6009return`6020ixRatId;
  652. XX`607D
  653. XX
  654. XXNewPosition()
  655. XX`607B
  656. XX`6009register`6009rndCnt`6020=`60200;
  657. XX
  658. XX`6009M.xloc`6020=`6020M.yloc`6020=`60200;`6009`6009/*`6020start`6020on`6020oc
  659. Vcupied`6020square`6020*/
  660. XX`6009while`6020(mp`605BM.xloc`605D.y`605BM.yloc`605D)`6020`607B
  661. XX`6009`6009M.xloc`6020=`6020random(MAZEXMAX);
  662. XX`6009`6009M.yloc`6020=`6020random(MAZEYMAX);
  663. XX`6009`6009if`6020(++rndCnt`6020==`6020100)`6020`607B
  664. XX`6009`6009`6009rndCnt`6020=`60200;
  665. XX`6009`6009`6009InitRandom();
  666. XX`6009`6009`607D
  667. XX`6009`607D
  668. XX
  669. XX`6009/*`6020prevent`6020a`6020blank`6020wall`6020at`6020first`6020glimpse`602
  670. V0*/
  671. XX
  672. XX`6009if`6020(!M.maze`605BM.xloc+1`605D.y`605BM.yloc`605D)`6020M.dir`6020=`602
  673. V0NORTH;
  674. XX`6009if`6020(!M.maze`605BM.xloc-1`605D.y`605BM.yloc`605D)`6020M.dir`6020=`602
  675. V0SOUTH;
  676. XX`6009if`6020(!M.maze`605BM.xloc`605D.y`605BM.yloc+1`605D)`6020M.dir`6020=`602
  677. V0EAST;
  678. XX`6009if`6020(!M.maze`605BM.xloc`605D.y`605BM.yloc-1`605D)`6020M.dir`6020=`602
  679. V0WEST;
  680. XX
  681. XX`6009return;
  682. XX`607D
  683. XX
  684. XX/*`6020re-initialize`6020the`6020maze`6020randomization`6020vector`6020*/
  685. XXInitRandom()
  686. XX`607B
  687. XX`6009struct`6020timeval`6009t;
  688. XX`6009struct`6020timezone`6009tz;
  689. XX`6009register`6020int`6009i;
  690. XX
  691. XX`6009gettimeofday(`6026t,`6020`6026tz);
  692. XX`6009for`6020(i`6020=`60200;`6020i`6020<`6020VECTORSIZE;`6020i++)
  693. XX`6009`6009M.randomVector`605Bi`605D`6020=`6020M.randomVector`605Bi`605D`6020+
  694. V`6020t.tv_sec`6020`6026
  695. XV`60200xffff;
  696. XX`607D
  697. XX
  698. XXrandom(limit)
  699. XXregister`6020int`6009limit;
  700. XX`607B
  701. XX`6009register`6020unsigned`6020int`6009ret;
  702. XX
  703. XX`6009ret`6020=`6020M.randomVector`605Bi1`605D`6020=`6020M.randomVector`605Bi1
  704. V`605D`6020+`6020M.rando
  705. XVmVector`605Bi2`605D;
  706. XX`6009if`6020(++i1`6020>=`6020VECTORSIZE)
  707. XX`6009`6009i1`6020=`60200;
  708. XX`6009if`6020(++i2`6020>=`6020VECTORSIZE)
  709. XX`6009`6009i2`6020=`60200;
  710. XX`6009return`6020ret%limit;
  711. XX`607D
  712. XX
  713. XXMWError(s)
  714. XXchar`6020*s;
  715. XX`607B
  716. XX`6009StopWindow();
  717. XX`6009fprintf(stderr,`6020"MazeWar:`6020%s`605Cn",`6020s);
  718. XX`6009perror("MazeWar");
  719. XX`6009exit(-1);
  720. XX`607D
  721. X$`20call`20unpack`20MAZEWAR.C;16`20908553038`20""
  722. X$!
  723. X$`20create`20'f'
  724. XX
  725. XX
  726. XX
  727. XXMAZEWAR(6)`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020
  728. V`6020`6020`6020`6020`6020`6020`6020`6020`6020
  729. XV`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020
  730. V`6020`6020`6020`6020`6020`6020`6020`6020MAZEWAR(6
  731. XV)
  732. XX
  733. XX
  734. XXN`6008NA`6008AM`6008ME`6008E
  735. XX`6020`6020`6020`6020`6020MazeWar`6020-`6020distributed`6020rats`6020in`6020a
  736. V`6020maze
  737. XX
  738. XXS`6008SY`6008YN`6008NT`6008TA`6008AX`6008X
  739. XX`6020`6020`6020`6020`6020/`6008/u`6008us`6008sr`6008r/`6008/g`6008ga`6008am
  740. V`6008me`6008es`6008s/`6008/m`6008mw
  741. XV`6008w`6020`605B`6020_`6008w_`6008i_`6008n_`6008d_`6008o_`6008w`6020_`6008s_
  742. V`6008y_`6008s_`6008t_`6008e_`6008m
  743. XV`6020_`6008o_`6008p_`6008t_`6008i_`6008o_`6008n_`6008s`6020`605D
  744. XX
  745. XXD`6008DE`6008ES`6008SC`6008CR`6008RI`6008IP`6008PT`6008TI`6008IO`6008ON`6008N
  746. V
  747. XX`6020`6020`6020`6020`6020This`6020`6020program`6020implements`6020the`6020age
  748. V-old`6020game`6020of`6020Ma
  749. XVzeWar.`6020`6020Maze-
  750. XX`6020`6020`6020`6020`6020War`6020first`6020appeared`6020at`6020MIT`6020in`602
  751. V0the`6020early`6020`60201970s
  752. XV,`6020`6020using`6020`6020IMLAC
  753. XX`6020`6020`6020`6020`6020displays`6020`6020and`6020`6020the`6020`6020ArpaNet
  754. V`6020network.`6020`6020Legend
  755. XV`6020has`6020it`6020that,`6020at
  756. XX`6020`6020`6020`6020`6020one`6020point`6020during`6020that`6020period,`6020Ma
  757. VzeWar`6020was`6020`6020bann
  758. XVed`6020`6020by`6020`6020DARPA
  759. XX`6020`6020`6020`6020`6020from`6020`6020the`6020ArpaNet`6020because`6020half
  760. V`6020of`6020all`6020the`6020pac
  761. XVkets`6020in`6020a`6020given
  762. XX`6020`6020`6020`6020`6020month`6020were`6020MazeWar`6020packets`6020flying
  763. V`6020between`6020Stanford
  764. XV`6020and`6020`6020MIT.
  765. XX
  766. XX`6020`6020`6020`6020`6020MazeWar`6020`6020appeared`6020again`6020at`6020the
  767. V`6020Xerox`6020Palo`6020Alto
  768. XV`6020Research`6020Cen-
  769. XX`6020`6020`6020`6020`6020ter`6020in`6020the`6020late`60201970's`6020on`6020th
  770. Ve`6020Alto,`6020the`6020first
  771. XV`6020personal`6020`6020com-
  772. XX`6020`6020`6020`6020`6020puter.`6020`6020`6020This`6020`6020version`6020`6020
  773. Vhas`6020subsequently`6020been
  774. XV`6020ported`6020to`6020many
  775. XX`6020`6020`6020`6020`6020personal`6020machines,`6020and`6020forms`6020the`602
  776. V0basis`6020for`6020`6020thi
  777. XVs`6020`6020Unix`6020`6020ver-
  778. XX`6020`6020`6020`6020`6020sion.
  779. XX
  780. XX`6020`6020`6020`6020`6020_`6008M_`6008w`6020`6020attempts`6020`6020to`6020be
  781. V`6020as`6020faithful`6020to`6020th
  782. XVe`6020original`6020Alto`6020version
  783. XX`6020`6020`6020`6020`6020as`6020possible.`6020`6020The`6020shape`6020and`6020
  784. Vpictures`6020of`6020the`6020m
  785. XVaze`6020are`6020`6020as`6020`6020in
  786. XX`6020`6020`6020`6020`6020the`6020`6020original,`6020and`6020there`6020are`602
  787. V0no`6020embellishments
  788. XV`6020such`6020as`6020tele-
  789. XX`6020`6020`6020`6020`6020port`6020traps`6020or`6020robot`6020amanuenses.
  790. XX
  791. XXP`6008PL`6008LA`6008AY`6008Y
  792. XX`6020`6020`6020`6020`6020You,`6020the`6020player,`6020are`6020a`6020rat`6020i
  793. Vn`6020a`6020maze,`6020and`6020t
  794. XVhe`6020`6020objective`6020`6020is
  795. XX`6020`6020`6020`6020`6020to`6020find`6020your`6020opponents`6020and`6020shoot
  796. V`6020them`6020before`6020th
  797. XVey`6020shoot`6020you.
  798. XX
  799. XX`6020`6020`6020`6020`6020Each`6020of`6020the`6020(up`6020to`6020eight)`6020pl
  800. Vayers`6020in`6020a`6020game
  801. XV`6020may`6020be`6020on`6020a`6020dif-
  802. XX`6020`6020`6020`6020`6020ferent`6020`6020host.`6020`6020`6020Upon`6020`6020st
  803. Vartup,`6020you`6020are`6020aske
  804. XVd`6020for`6020the`6020name`6020by
  805. XX`6020`6020`6020`6020`6020which`6020you`6020wish`6020to`6020be`6020known`6020f
  806. Vor`6020the`6020duration`6020o
  807. XVf`6020the`6020game,`6020and
  808. XX`6020`6020`6020`6020`6020the`6020`6020name`6020of`6020the`6020`6060`6060Duke
  809. V`6020host''.`6020`6020If`6020you
  810. XV`6020type`6020a`6020bare`6020carriage
  811. XX`6020`6020`6020`6020`6020return`6020to`6020this`6020query,`6020_`6008m_`6008w
  812. V`6020will`6020find`6020a`6020ga
  813. XVme`6020by`6020broadcasting`6020on
  814. XX`6020`6020`6020`6020`6020the`6020`6020local`6020network,`6020and`6020join`602
  815. V0any`6020game`6020it`6020find
  816. XVs.`6020`6020If`6020you`6020wish
  817. XX`6020`6020`6020`6020`6020to`6020join`6020a`6020specific`6020game,`6020or`6020
  818. Va`6020game`6020on`6020`6020anot
  819. XVher`6020`6020network,`6020`6020or
  820. XX`6020`6020`6020`6020`6020your`6020`6020network`6020doesn't`6020support`6020br
  821. Voadcasting,`6020type
  822. XV`6020in`6020the`6020name
  823. XX`6020`6020`6020`6020`6020of`6020one`6020of`6020the`6020hosts`6020involved`602
  824. V0`6020in`6020`6020that`6020`6020g
  825. XVame.`6020`6020`6020The`6020`6020program
  826. XX`6020`6020`6020`6020`6020_`6008m_`6008a_`6008z_`6008e_`6008f_`6008i_`6008n_
  827. V`6008d`6020`6020will`6020`6020aid`6020
  828. XV`6020you`6020`6020in`6020finding`6020out`6020what`6020games`6020are`6020cur-
  829. XX`6020`6020`6020`6020`6020rently`6020being`6020played.
  830. XX
  831. XX`6020`6020`6020`6020`6020Once`6020in`6020a`6020game,`6020you`6020are`6020`602
  832. V0presented`6020`6020with`6020
  833. XV`6020the`6020`6020game`6020`6020window.
  834. XX`6020`6020`6020`6020`6020This`6020window`6020is`6020made`6020up`6020of`6020th
  835. Vree`6020sections.`6020`6020Th
  836. XVe`6020upper`6020section
  837. XX`6020`6020`6020`6020`6020is`6020a`6020perspective`6020view`6020of`6020your
  838. V`6020view`6020forward.`6020
  839. XV`6020By`6020pressing`6020the
  840. XX`6020`6020`6020`6020`6020left`6020`6020or`6020`6020right`6020`6020mouse`6020
  841. V`6020buttons,`6020you`6020may
  842. XV`6020peek`6020to`6020the`6020left`6020or
  843. XX`6020`6020`6020`6020`6020right`6020around`6020corners.
  844. XX
  845. XX`6020`6020`6020`6020`6020The`6020middle`6020section`6020of`6020the`6020window
  846. V`6020is`6020a`6020top`6020vie
  847. XVw`6020of`6020the`6020`6020maze,
  848. XX`6020`6020`6020`6020`6020showing`6020`6020your`6020current`6020position`6020a
  849. Vnd`6020heading`6020in`6020t
  850. XVhe`6020maze.`6020`6020You
  851. XX`6020`6020`6020`6020`6020move`6020around`6020the`6020maze`6020by`6020using
  852. V`6020the`6020following`6020key
  853. XVs:
  854. XX
  855. XX`6020`6020`6020`6020`6020A`6020`6020`6020`6020`6020About`6020face;`6020flip
  856. V`6020end-for-end
  857. XX`6020`6020`6020`6020`6020S`6020`6020`6020`6020`6020Turn`602090`6020degrees
  858. V`6020left
  859. XX`6020`6020`6020`6020`6020D`6020`6020`6020`6020`6020Move`6020forward`6020one
  860. V`6020cell
  861. XX
  862. XX
  863. XX
  864. XX`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020
  865. V`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020
  866. XV`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020
  867. V`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020
  868. XV`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`60201
  869. XX
  870. XX
  871. XX
  872. XX
  873. XX
  874. XXMAZEWAR(6)`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020
  875. V`6020`6020`6020`6020`6020`6020`6020`6020`6020
  876. XV`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020
  877. V`6020`6020`6020`6020`6020`6020`6020`6020MAZEWAR(6
  878. XV)
  879. XX
  880. XX
  881. XX`6020`6020`6020`6020`6020F`6020`6020`6020`6020`6020Turn`602090`6020degrees
  882. V`6020right
  883. XX`6020`6020`6020`6020`6020<space>Move`6020backward`6020one`6020cell
  884. XX`6020`6020`6020`6020`6020Q`6020`6020`6020`6020`6020Quit
  885. XX
  886. XX`6020`6020`6020`6020`6020For`6020left-handers,`6020there`6020are`6020equivale
  887. Vnts`6020on`6020the`6020nu
  888. XVmeric`6020`6020key-
  889. XX`6020`6020`6020`6020`6020pad.`6020`6020On`6020the`6020DEC`6020LK201`6020keybo
  890. Vard,`6020the`6020`60604',`6020
  891. XV`60605',`6020`60606',`6020`6060,',`6020and
  892. XX`6020`6020`6020`6020`6020right`6020cursor`6020arrow`6020keys`6020perform`6020
  893. Vthe`6020equivalent`6020op
  894. XVerations.
  895. XX
  896. XX`6020`6020`6020`6020`6020The`6020lower`6020section`6020of`6020the`6020window
  897. V`6020shows`6020the`6020names
  898. XV`6020`6020and`6020`6020scores
  899. XX`6020`6020`6020`6020`6020of`6020`6020the`6020`6020other`6020`6020players`6020
  900. Vin`6020the`6020game.`6020`6020Whe
  901. XVn`6020you`6020sight`6020another
  902. XX`6020`6020`6020`6020`6020rat,`6020that`6020rat's`6020score`6020line`6020is
  903. V`6020highlighted.`6020`6020Sho
  904. XVot`6020by`6020`6020press-
  905. XX`6020`6020`6020`6020`6020ing`6020`6020the`6020`6020middle`6020`6020mouse`6020
  906. V`6020button.`6020`6020`6020When
  907. XV`6020you`6020are`6020shot`6020at,`6020the
  908. XX`6020`6020`6020`6020`6020mouse`6020cursor`6020changes`6020from`6020a`6020rat
  909. V`6020to`6020a`6020dead`6020rat
  910. XV,`6020and`6020you`6020`6020have
  911. XX`6020`6020`6020`6020`6020one`6020`6020second`6020to`6020move`6020out`6020of
  912. V`6020the`6020way`6020of`6020the
  913. XV`6020shot`6020or`6020shoot`6020back
  914. XX`6020`6020`6020`6020`6020or`6020both.`6020`6020A`6020shot`6020costs`6020one
  915. V`6020point;`6020`6020getting
  916. XV`6020`6020hit`6020`6020costs`6020`6020five
  917. XX`6020`6020`6020`6020`6020points;`6020`6020hitting`6020someone`6020adds`6020te
  918. Vn`6020points.`6020`6020When
  919. XV`6020you`6020are`6020hit,
  920. XX`6020`6020`6020`6020`6020the`6020screen`6020flashes`6020and`6020you`6020are
  921. V`6020transported`6020to`6020
  922. XV`6020another`6020`6020sec-
  923. XX`6020`6020`6020`6020`6020tion`6020of`6020the`6020maze.
  924. XX
  925. XX`6020`6020`6020`6020`6020If`6020your`6020window`6020system`6020supports`6020i
  926. Vt,`6020when`6020you`6020ico
  927. XVnify`6020the`6020game
  928. XX`6020`6020`6020`6020`6020window,`6020it`6020will`6020let`6020you`6020know`602
  929. V0when`6020someone`6020joins
  930. XV`6020the`6020game`6020`6020or
  931. XX`6020`6020`6020`6020`6020shoots`6020`6020at`6020`6020you`6020(by`6020flashing
  932. V,`6020in`6020most`6020cases).
  933. XV`6020`6020This`6020way,`6020you
  934. XX`6020`6020`6020`6020`6020can`6020be`6020notified`6020whenever`6020someone`602
  935. V0else`6020is`6020interest
  936. XVed`6020in`6020wast-
  937. XX`6020`6020`6020`6020`6020ing`6020some`6020time,`6020by`6020always`6020leaving
  938. V`6020a`6020game`6020around.
  939. XV
  940. XX
  941. XXS`6008SE`6008EE`6008E`6020A`6008AL`6008LS`6008SO`6008O
  942. XX`6020`6020`6020`6020`6020mazefind(6)
  943. XX
  944. XXA`6008AU`6008UT`6008TH`6008HO`6008OR`6008R
  945. XX`6020`6020`6020`6020`6020Christopher`6020A.`6020Kent
  946. XX
  947. XX
  948. XX
  949. XX
  950. XX
  951. XX
  952. XX
  953. XX
  954. XX
  955. XX
  956. XX
  957. XX
  958. XX
  959. XX
  960. XX
  961. XX
  962. XX
  963. XX
  964. XX
  965. XX
  966. XX
  967. XX
  968. XX
  969. XX
  970. XX
  971. XX
  972. XX
  973. XX`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020
  974. V`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020
  975. XV`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020
  976. V`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020
  977. XV`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`6020`60202
  978. X+-+-+-+-+-+-+-+-`20`20END`20`20OF`20PART`205`20+-+-+-+-+-+-+-+-
  979. $ call unpack [.MAZEWAR]MAZEWAR.5;1 672902849 ""
  980. $!
  981. $ create 'f'
  982. X.TH`20MAZEWAR`206
  983. X.SH`20NAME
  984. XMazeWar`20`5C-`20distributed`20rats`20in`20a`20maze
  985. X.SH`20SYNTAX
  986. X.B`20/usr/games/mw
  987. X`5B
  988. X.I`20
  989. Xwindow`20system`20options
  990. X`5D
  991. X.SH`20DESCRIPTION
  992. XThis`20program`20implements`20the`20age-old`20game`20of`20MazeWar.
  993. XMazeWar`20first`20appeared`20at`20MIT`20in`20the`20early`201970s,`20using`20IM
  994. VLAC`20displays`20and
  995. Xthe`20ArpaNet`20network.
  996. XLegend`20has`20it`20that,`20at`20one`20point`20during`20that`20period,`20MazeW
  997. Var`20was`20banned
  998. Xby`20DARPA`20from`20the`20ArpaNet`20because`20half`20of`20all`20the`20packets
  999. V`20in`20a`20given
  1000. Xmonth`20were`20MazeWar`20packets`20flying`20between`20Stanford`20and`20MIT.
  1001. X.PP
  1002. XMazeWar`20appeared`20again`20at`20the`20Xerox`20Palo`20Alto`20Research`20Cente
  1003. Vr`20in`20the`20late
  1004. X1970's`20on`20the`20Alto,`20the`20first`20personal`20computer.
  1005. XThis`20version`20has`20subsequently`20been`20ported`20to`20many
  1006. Xpersonal`20machines,`20and`20forms`20the`20basis`20for`20this`20Unix`20version
  1007. V.
  1008. X.PP
  1009. X.I`20Mw
  1010. Xattempts`20to`20be`20as`20faithful`20to`20the`20original`20Alto`20version`20as
  1011. V`20possible.`20
  1012. XThe`20shape`20and`20pictures`20of`20the`20maze`20are`20as`20in`20the`20origina
  1013. Vl,`20and`20there`20are
  1014. Xno`20embellishments`20such`20as`20teleport`20traps`20or`20robot`20amanuenses.
  1015. X.SH`20PLAY
  1016. XYou,`20the`20player,`20are`20a`20rat`20in`20a`20maze,`20and`20the`20objective
  1017. V`20is`20to`20
  1018. Xfind`20your`20opponents`20and`20shoot`20them`20before`20they`20shoot`20you.
  1019. X.PP
  1020. XEach`20of`20the`20(up`20to`20eight)`20players`20in`20a`20game`20may`20be`20on
  1021. V`20a`20different`20host.`20
  1022. XUpon`20startup,`20you`20are`20asked`20for`20the`20name`20by`20which`20you`20wi
  1023. Vsh`20to`20be`20known`20for
  1024. Xthe`20duration`20of`20the`20game,`20and`20the`20name`20of`20the`20`60`60Duke
  1025. V`20host''.
  1026. XIf`20you`20type`20a`20bare`20carriage`20return`20to`20this`20query,`20
  1027. X.I`20mw
  1028. Xwill`20find`20a`20game`20by`20broadcasting`20on`20the`20local`20network,`20and
  1029. V`20join`20any`20game
  1030. Xit`20finds.`20
  1031. XIf`20you`20wish`20to`20join`20a`20specific`20game,`20or`20a`20game`20on`20anot
  1032. Vher`20network,`20or`20your
  1033. Xnetwork`20doesn't`20support`20broadcasting,
  1034. Xtype`20in`20the`20name`20of`20one`20of`20the`20hosts`20involved`20in`20that
  1035. V`20game.
  1036. XThe`20program
  1037. X.I`20mazefind
  1038. Xwill`20aid`20you`20in`20finding`20out`20what`20games`20are`20currently`20being
  1039. V`20played.
  1040. X.PP
  1041. XOnce`20in`20a`20game,`20you`20are`20presented`20with`20the`20game`20window.
  1042. XThis`20window`20is`20made`20up`20of`20three`20sections.
  1043. XThe`20upper`20section`20is`20a`20perspective`20view`20of`20your`20view`20forwa
  1044. Vrd.`20
  1045. XBy`20pressing
  1046. Xthe`20left`20or`20right`20mouse`20buttons,`20you`20may`20peek`20to`20the`20lef
  1047. Vt`20or`20right`20around
  1048. Xcorners.
  1049. X.PP
  1050. XThe`20middle`20section`20of`20the`20window`20is`20a`20top`20view`20of`20the
  1051. V`20maze,`20showing`20your
  1052. Xcurrent`20position`20and`20heading`20in`20the`20maze.`20
  1053. XYou`20move`20around`20the`20maze`20by`20using`20the`20following`20keys:
  1054. X.sp
  1055. X.ta`20.6i
  1056. X.nf
  1057. XA`09About`20face;`20flip`20end`5C-for`5C-end
  1058. XS`09Turn`2090`20degrees`20left
  1059. XD`09Move`20forward`20one`20cell
  1060. XF`09Turn`2090`20degrees`20right
  1061. X<space>`09Move`20backward`20one`20cell
  1062. XQ`09Quit
  1063. X.fi
  1064. X.sp
  1065. XFor`20left`5C-handers,`20there`20are`20equivalents`20on`20the`20numeric`20keyp
  1066. Vad.`20
  1067. XOn`20the`20DEC`20LK201`20keyboard,`20the`20`604',`20`605',`20`606',`20`60,',
  1068. V`20and`20right`20cursor`20arrow
  1069. Xkeys`20perform`20the`20equivalent`20operations.
  1070. X.PP
  1071. XThe`20lower`20section`20of`20the`20window`20shows`20the`20names`20and`20scores
  1072. V`20of`20the`20other
  1073. Xplayers`20in`20the`20game.
  1074. XWhen`20you`20sight`20another`20rat,`20that`20rat's`20score`20line`20is`20highl
  1075. Vighted.
  1076. XShoot`20by`20pressing`20the`20middle`20mouse`20button.
  1077. XWhen`20you`20are`20shot`20at,`20the`20mouse`20cursor`20changes`20from`20a`20ra
  1078. Vt`20to`20a`20dead`20rat,
  1079. Xand`20you`20have`20one`20second`20to`20move`20out`20of`20the`20way`20of`20the
  1080. V`20shot`20or`20shoot`20back
  1081. Xor`20both.
  1082. XA`20shot`20costs`20one`20point;`20getting`20hit`20costs`20five`20points;`20hit
  1083. Vting`20someone
  1084. Xadds`20ten`20points.
  1085. XWhen`20you`20are`20hit,`20the`20screen`20flashes`20and`20you`20are`20transport
  1086. Ved`20to`20another
  1087. Xsection`20of`20the`20maze.
  1088. X.PP
  1089. XIf`20your`20window`20system`20supports`20it,`20when`20you`20iconify`20the`20ga
  1090. Vme`20window,`20it
  1091. Xwill`20let`20you`20know`20when`20someone`20joins`20the`20game`20or`20shoots
  1092. V`20at`20you`20(by
  1093. Xflashing,`20in`20most`20cases).
  1094. XThis`20way,`20you`20can`20be`20notified`20whenever`20someone`20else`20is`20int
  1095. Verested`20in
  1096. Xwasting`20some`20time,`20by`20always`20leaving`20a`20game`20around.
  1097. X.SH`20"SEE`20ALSO"
  1098. Xmazefind(6)
  1099. X.SH`20AUTHOR
  1100. XChristopher`20A.`20Kent
  1101. $ call unpack [.MAZEWAR]MAZEWAR.6;1 33627330 ""
  1102. $!
  1103. $ create 'f'
  1104. X/*`20$Header:`20mazewar.c,v`201.13`2088/08/25`2009:57:53`20kent`20Exp`20$`20*/
  1105. V
  1106. X
  1107. X/*`20
  1108. X`20*`20mazewar.c`20-`20Rats`20in`20a`20maze
  1109. X`20*`20
  1110. X`20*`20Author:`09Christopher`20A.`20Kent
  1111. X`20*`20`09`09Western`20Research`20Laboratory
  1112. X`20*`20`09`09Digital`20Equipment`20Corporation
  1113. X`20*`20Date:`09Wed`20Sep`2024`201986
  1114. X`20*/
  1115. X
  1116. X/***********************************************************
  1117. XCopyright`201986`20by`20Digital`20Equipment`20Corporation,`20Maynard,`20Massac
  1118. Vhusetts,
  1119. X
  1120. 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
  1121. V`20Rights`20Reserved
  1122. X
  1123. XPermission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20software
  1124. V`20and`20its`20
  1125. Xdocumentation`20for`20any`20purpose`20and`20without`20fee`20is`20hereby`20gran
  1126. Vted,`20
  1127. Xprovided`20that`20the`20above`20copyright`20notice`20appear`20in`20all`20copie
  1128. Vs`20and`20that
  1129. Xboth`20that`20copyright`20notice`20and`20this`20permission`20notice`20appear
  1130. V`20in`20
  1131. Xsupporting`20documentation,`20and`20that`20the`20names`20of`20Digital`20not
  1132. V`20be
  1133. Xused`20in`20advertising`20or`20publicity`20pertaining`20to`20disstribution`20o
  1134. Vf`20the
  1135. Xsoftware`20without`20specific,`20written`20prior`20permission.`20`20
  1136. X
  1137. XDIGITAL`20DISCLAIMS`20ALL`20WARRANTIES`20WITH`20REGARD`20TO`20THIS`20SOFTWARE,
  1138. V`20INCLUDING
  1139. XALL`20IMPLIED`20WARRANTIES`20OF`20MERCHANTABILITY`20AND`20FITNESS,`20IN`20NO
  1140. V`20EVENT`20SHALL
  1141. XDIGITAL`20BE`20LIABLE`20FOR`20ANY`20SPECIAL,`20INDIRECT`20OR`20CONSEQUENTIAL
  1142. V`20DAMAGES`20OR
  1143. XANY`20DAMAGES`20WHATSOEVER`20RESULTING`20FROM`20LOSS`20OF`20USE,`20DATA`20OR
  1144. V`20PROFITS,
  1145. XWHETHER`20IN`20AN`20ACTION`20OF`20CONTRACT,`20NEGLIGENCE`20OR`20OTHER`20TORTIO
  1146. VUS`20ACTION,
  1147. XARISING`20OUT`20OF`20OR`20IN`20CONNECTION`20WITH`20THE`20USE`20OR`20PERFORMANC
  1148. VE`20OF`20THIS
  1149. XSOFTWARE.
  1150. X
  1151. X******************************************************************/
  1152. X
  1153. X/*`20
  1154. X`20*`20This`20is`20an`20adaptation`20of`20the`20Mazewar`20program`20built`20at
  1155. V`20Xerox`20PARC`20in
  1156. X`20*`20Mesa`20for`20Altos`20by`20Jim`20Guyton`20and`20others`20in`20the`20late
  1157. V`201970s`20and`20beyond.
  1158. X`20*`20Unlike`20other`20programs`20that`20have`20appeared`20from`20time`20to
  1159. V`20time,`20this
  1160. X`20*`20one`20attempts`20to`20remain`20faithful`20to`20the`20original`20spirit
  1161. V`20of`20the`20game,
  1162. X`20*`20with`20no`20fancy`20additions`20(like`20seeing`20your`20opponents`20or
  1163. V`20teleport
  1164. X`20*`20traps).`20I`20hope`20you`20enjoy`20it.
  1165. X`20*/
  1166. X
  1167. X/*
  1168. X`20*`20vms`20port`207/93`20`20scott`20snyder`20<snyder@fnald0.fnal.gov>
  1169. X`20*`20$Log:`09mazewar.c,v`20$
  1170. X`20*`20Revision`201.13`20`2088/08/25`20`2009:57:53`20`20kent
  1171. X`20*`20Copyright.
  1172. X`20*`20
  1173. X`20*`20Revision`201.12`20`2088/02/11`20`2018:00:39`20`20kent
  1174. X`20*`20Changes`20so`20the`20value`20of`20M.theSocket`20doesn't`20change`20(thi
  1175. Vs`20makes`20the
  1176. X`20*`20window`20system`20code`20simpler).
  1177. X`20*`20
  1178. X`20*`20Revision`201.11`20`2088/02/11`20`2017:52:41`20`20kent
  1179. X`20*`20Move`20some`20code`20out`20of`20the`20play`20loop`20so`20it`20can`20be
  1180. V`20called`20by`20an`20"external"`20
  1181. X`20*`20play`20loop`20(such`20as`20is`20needed`20for`20the`20X11`20toolkit).
  1182. X`20*`20
  1183. X`20*`20Revision`201.10`20`2087/03/31`20`2015:47:34`20`20kent
  1184. X`20*`20Handle`20duplicated`20RAT_NEW`20packets`20while`20joining`20the`20game.
  1185. V`20If`20the`20
  1186. X`20*`20guy`20is`20already`20in`20the`20game,`20just`20send`20him`20a`20status
  1187. V`20packet;`20previously,
  1188. X`20*`20he'd`20get`20added`20to`20the`20game`20again!
  1189. X`20*`20
  1190. X`20*`20Revision`201.9`20`2087/03/31`20`2014:37:37`20`20kent
  1191. X`20*`20Portability`20considerations,`20especially`20byteswapping`20to/from`20t
  1192. Vhe`20net.
  1193. X`20*`20
  1194. X`20*`20Revision`201.8`20`2086/12/04`20`2017:44:53`20`20kent
  1195. X`20*`20Notify`20user`20also`20if`20shot;`20make`20sure`20non-dukes`20get`20not
  1196. Vified`20on`20game`20joins.
  1197. X`20*`20
  1198. X`20*`20Revision`201.7`20`2086/12/03`20`2018:13:10`20`20kent
  1199. X`20*`20Cleaned`20up`20the`20shot`20handling`20code`20a`20bit.`20Was`20waiting
  1200. V`20two`20seconds
  1201. X`20*`20instead`20of`20one,`20and`20would`20only`20handle`20one`20shot`20off
  1202. V`20the`20queue
  1203. X`20*`20every`20time`20around`20the`20loop,`20instead`20of`20all`20applicable.
  1204. X`20*`20
  1205. X`20*`20Also`20cleaned`20up`20a`20race`20in`20the`20port`20moving`20code`20for
  1206. V`20when`20the`20mover`20and
  1207. X`20*`20the`20quitter`20were`20on`20the`20same`20machine.
  1208. X`20*`20
  1209. X`20*`20Revision`201.6`20`2086/12/03`20`2013:31:10`20`20kent
  1210. X`20*`20
  1211. X`20*`20
  1212. X`20*`20Revision`201.5`20`2086/12/03`20`2010:15:03`20`20kent
  1213. X`20*`20Only`20send`20location`20when`20moving,`20not`20every`20time`20screen
  1214. V`20needs`20updating.
  1215. X`20*`20
  1216. X`20*`20Revision`201.4`20`2086/12/03`20`2010:00:19`20`20kent
  1217. X`20*`20Changes`20to`20allow`20multiple`20players`20per`20machine.
  1218. X`20*`20
  1219. X`20*`20Revision`201.3`20`2086/12/01`20`2023:44:42`20`20kent
  1220. X`20*`20Housecleaning`20and`20documentation`20pass.
  1221. X`20*`20
  1222. X`20*`20Revision`201.2`20`2086/12/01`20`2014:47:04`20`20kent
  1223. X`20*`20Changes`20for`20a`20realistic`20implementation`20of`20shooting.
  1224. X`20*`20
  1225. X`20*`20Revision`201.1`20`2086/11/26`20`2016:57:53`20`20kent
  1226. X`20*`20Initial`20revision
  1227. X`20*`20
  1228. X`20*/
  1229. X
  1230. X#ifndef`09lint
  1231. Xstatic`20char`20rcs_ident`5B`5D`20=`20"$Header:`20mazewar.c,v`201.13`2088/08/2
  1232. V5`2009:57:53`20kent`20Exp`20$";
  1233. X#endif
  1234. X
  1235. X#include`20<sys/types.h>
  1236. X#include`20<sys/socket.h>
  1237. X#include`20<sys/time.h>
  1238. X
  1239. X#include`20<netinet/in.h>
  1240. X
  1241. X#include`20<signal.h>
  1242. X#include`20<stdio.h>
  1243. X#ifdef`20VMS
  1244. X#include`20<string.h>
  1245. X#else
  1246. X#include`20<strings.h>
  1247. X#endif
  1248. X
  1249. X#include`20"mazewar.h"
  1250. X
  1251. Xstatic`20int`09`09i1`20=`200;`09`09/*`20random`20number`20hackery`20*/
  1252. Xstatic`20int`09`09i2`20=`2024;
  1253. X
  1254. Xstatic`20Boolean`09`09updateView;`09/*`20true`20if`20update`20needed`20*/
  1255. Xstatic`20Boolean`09`09sendLocation;`09/*`20true`20if`20must`20send`20out`20loc
  1256. Vation`20*/
  1257. X
  1258. Xstatic`20MazeTypePtr`09mp`20=`20M.maze;`09/*`20easy`20access`20to`20Maze`20*/
  1259. X
  1260. Xstatic`20RatHealth`09ratHealth;`09/*`20keep`20track`20of`20other`20players`20*
  1261. V/
  1262. X
  1263. Xstatic`20ratDoctor`20();
  1264. X
  1265. Xmain(argc,`20argv)
  1266. Xchar`20**argv;
  1267. X`7B
  1268. X`09int`09quit();
  1269. X
  1270. X`09signal(SIGHUP,`20quit);
  1271. X`09signal(SIGINT,`20quit);
  1272. X`09signal(SIGTERM,`20quit);
  1273. X`09MazeInit(argc,`20argv);
  1274. X`09play();
  1275. X`7D
  1276. X
  1277. Xplay()
  1278. X`7B
  1279. X`09MWEvent`09`09event;
  1280. X`09RatPacket`09incoming;
  1281. X`09Boolean`09`09KBEventPending();
  1282. X
  1283. X`09event.eventDetail`20=`20`26incoming;
  1284. X
  1285. X`09while`20(1)`20`7B
  1286. X`09`09NextEvent(`26event);
  1287. X`09`09if`20(!M.peeking)
  1288. X`09`09`09switch(event.eventType)`20`7B
  1289. X`09`09`09case`20EVENT_A:
  1290. X`09`09`09`09aboutFace();
  1291. X`09`09`09`09break;
  1292. X
  1293. X`09`09`09case`20EVENT_S:
  1294. X`09`09`09`09leftTurn();
  1295. X`09`09`09`09break;
  1296. X
  1297. X`09`09`09case`20EVENT_D:
  1298. X`09`09`09`09forward();
  1299. X`09`09`09`09break;
  1300. X
  1301. X`09`09`09case`20EVENT_F:
  1302. X`09`09`09`09rightTurn();
  1303. X`09`09`09`09break;
  1304. X
  1305. X`09`09`09case`20EVENT_BAR:
  1306. X`09`09`09`09backward();
  1307. X`09`09`09`09break;
  1308. X
  1309. X`09`09`09case`20EVENT_I:
  1310. X`09`09`09`09makeInvincible(TRUE);
  1311. X`09`09`09`09break;
  1312. X
  1313. X`09`09`09case`20EVENT_K:
  1314. X`09`09`09`09makeInvincible(FALSE);
  1315. X`09`09`09`09break;
  1316. X
  1317. X`09`09`09case`20EVENT_O:
  1318. X`09`09`09`09makeOmniscient(TRUE);
  1319. X`09`09`09`09break;
  1320. X
  1321. X`09`09`09case`20EVENT_L:
  1322. X`09`09`09`09makeOmniscient(FALSE);
  1323. X`09`09`09`09break;
  1324. X
  1325. X`09`09`09case`20EVENT_LEFT_D:
  1326. X`09`09`09`09peekLeft();
  1327. X`09`09`09`09break;
  1328. X
  1329. X`09`09`09case`20EVENT_MIDDLE_D:
  1330. X`09`09`09`09shoot();
  1331. X`09`09`09`09break;
  1332. X
  1333. X`09`09`09case`20EVENT_RIGHT_D:
  1334. X`09`09`09`09peekRight();
  1335. X`09`09`09`09break;
  1336. X
  1337. X`09`09`09case`20EVENT_NETWORK:
  1338. X`09`09`09`09readRats(`26event);
  1339. X`09`09`09`09break;
  1340. X
  1341. X`09`09`09case`20EVENT_INT:
  1342. X`09`09`09`09quit();
  1343. X`09`09`09`09break;
  1344. X
  1345. X`09`09`09`7D
  1346. X`09`09else
  1347. X`09`09`09switch`20(event.eventType)`20`7B
  1348. X`09`09`09case`20EVENT_RIGHT_U:
  1349. X`09`09`09case`20EVENT_LEFT_U:
  1350. X`09`09`09`09peekStop();
  1351. X`09`09`09`09break;
  1352. X
  1353. X`09`09`09case`20EVENT_NETWORK:
  1354. X`09`09`09`09readRats(`26event);
  1355. X`09`09`09`09break;
  1356. X`09`09`09`7D
  1357. X`09`09`09
  1358. X`09`09ratDoctor();`09`09/*`20clean`20house`20*/
  1359. X
  1360. X`09`09DoRatKillQ();
  1361. X`09`09
  1362. X`09`09DoViewUpdate();
  1363. X`09`09
  1364. X`09`09SendLocation();
  1365. X`09`7D
  1366. X`7D
  1367. X
  1368. Xstatic`09Direction`09_aboutFace`5BNDIRECTION`5D`20=`7BSOUTH,`20NORTH,`20WEST,
  1369. V`20EAST`7D;
  1370. Xstatic`09Direction`09_leftTurn`5BNDIRECTION`5D`20=`09`7BWEST,`20EAST,`20NORTH,
  1371. V`20SOUTH`7D;
  1372. Xstatic`09Direction`09_rightTurn`5BNDIRECTION`5D`20=`7BEAST,`20WEST,`20SOUTH,
  1373. V`20NORTH`7D;
  1374. X
  1375. XaboutFace()
  1376. X`7B
  1377. X`09M.dir`20=`20_aboutFace`5BM.dir`5D;
  1378. X`09updateView`20=`20TRUE;
  1379. X`09sendLocation`20=`20TRUE;
  1380. X`7D
  1381. X
  1382. XleftTurn()
  1383. X`7B
  1384. X`09M.dir`20=`20_leftTurn`5BM.dir`5D;
  1385. X`09updateView`20=`20TRUE;
  1386. X`09sendLocation`20=`20TRUE;
  1387. X`7D
  1388. X
  1389. XrightTurn()
  1390. X`7B
  1391. X`09M.dir`20=`20_rightTurn`5BM.dir`5D;
  1392. X`09updateView`20=`20TRUE;
  1393. X`09sendLocation`20=`20TRUE;
  1394. X`7D
  1395. X
  1396. X/*`20remember`20...`20"North"`20is`20to`20the`20right`20...`20positive`20X`20m
  1397. Votion`20*/
  1398. X
  1399. Xforward()
  1400. X`7B
  1401. X`09register`20int`09tx`20=`20M.xloc;
  1402. X`09register`20int`09ty`20=`20M.yloc;
  1403. X
  1404. X`09switch(M.dir)`20`7B
  1405. X`09case`20NORTH:`09if`20(!mp`5Btx+1`5D.y`5Bty`5D)`09tx++;`20break;
  1406. X`09case`20SOUTH:`09if`20(!mp`5Btx-1`5D.y`5Bty`5D)`09tx--;`20break;
  1407. X`09case`20EAST:`09if`20(!mp`5Btx`5D.y`5Bty+1`5D)`09ty++;`20break;
  1408. X`09case`20WEST:`09if`20(!mp`5Btx`5D.y`5Bty-1`5D)`09ty--;`20break;
  1409. X`09default:
  1410. X`09`09MWError("bad`20direction`20in`20Forward");
  1411. X`09`7D
  1412. X`09if`20((M.xloc`20!=`20tx)`20`7C`7C`20(M.yloc`20!=`20ty))`20`7B
  1413. X`09`09M.xloc`20=`20tx;`20M.yloc`20=`20ty;
  1414. X`09`09updateView`20=`20TRUE;
  1415. X`09`09sendLocation`20=`20TRUE;
  1416. X`09`7D
  1417. X`7D
  1418. X
  1419. Xbackward()
  1420. X`7B
  1421. X`09register`20int`09tx`20=`20M.xloc;
  1422. X`09register`20int`09ty`20=`20M.yloc;
  1423. X
  1424. X`09switch(M.dir)`20`7B
  1425. X`09case`20NORTH:`09if`20(!mp`5Btx-1`5D.y`5Bty`5D)`09tx--;`20break;
  1426. X`09case`20SOUTH:`09if`20(!mp`5Btx+1`5D.y`5Bty`5D)`09tx++;`20break;
  1427. X`09case`20EAST:`09if`20(!mp`5Btx`5D.y`5Bty-1`5D)`09ty--;`20break;
  1428. X`09case`20WEST:`09if`20(!mp`5Btx`5D.y`5Bty+1`5D)`09ty++;`20break;
  1429. X`09default:
  1430. X`09`09MWError("bad`20direction`20in`20Backward");
  1431. X`09`7D
  1432. X`09if`20((M.xloc`20!=`20tx)`20`7C`7C`20(M.yloc`20!=`20ty))`20`7B
  1433. X`09`09M.xloc`20=`20tx;`20M.yloc`20=`20ty;
  1434. X`09`09updateView`20=`20TRUE;
  1435. X`09`09sendLocation`20=`20TRUE;
  1436. X`09`7D
  1437. X`7D
  1438. X
  1439. XmakeInvincible(neverDie)
  1440. XBoolean`20neverDie;
  1441. X`7B
  1442. X`09M.invincible`20=`20neverDie;
  1443. X`09ShowPosition(M.xloc,`20M.yloc,`20M.invincible,`20M.dir);
  1444. X`7D
  1445. X
  1446. XmakeOmniscient(allSeeing)
  1447. XBoolean`20allSeeing;
  1448. X`7B
  1449. X`09M.omniscient`20=`20allSeeing;
  1450. X`09ShowAllPositions();
  1451. X`7D
  1452. X
  1453. XpeekLeft()
  1454. X`7B
  1455. X`09M.xPeek`20=`20M.xloc;
  1456. X`09M.yPeek`20=`20M.yloc;
  1457. X`09M.dirPeek`20=`20M.dir;
  1458. X
  1459. X`09switch(M.dir)`20`7B
  1460. X`09case`20NORTH:`09if`20(!mp`5BM.xloc+1`5D.y`5BM.yloc`5D)`20`7B
  1461. X`09`09`09`09M.xPeek`20=`20M.xloc`20+`201;
  1462. X`09`09`09`09M.dirPeek`20=`20WEST;
  1463. X`09`09`09`7D
  1464. X`09`09`09break;
  1465. X
  1466. X`09case`20SOUTH:`09if`20(!mp`5BM.xloc-1`5D.y`5BM.yloc`5D)`20`7B
  1467. X`09`09`09`09M.xPeek`20=`20M.xloc`20-`201;
  1468. X`09`09`09`09M.dirPeek`20=`20EAST;
  1469. X`09`09`09`7D
  1470. X`09`09`09break;
  1471. X
  1472. X`09case`20EAST:`09if`20(!mp`5BM.xloc`5D.y`5BM.yloc+1`5D)`20`7B
  1473. X`09`09`09`09M.yPeek`20=`20M.yloc`20+`201;
  1474. X`09`09`09`09M.dirPeek`20=`20NORTH;
  1475. X`09`09`09`7D
  1476. X`09`09`09break;
  1477. X
  1478. X`09case`20WEST:`09if`20(!mp`5BM.xloc`5D.y`5BM.yloc-1`5D)`20`7B
  1479. X`09`09`09`09M.yPeek`20=`20M.yloc`20-`201;
  1480. X`09`09`09`09M.dirPeek`20=`20SOUTH;
  1481. X`09`09`09`7D
  1482. X`09`09`09break;
  1483. X
  1484. X`09default:
  1485. X`09`09`09MWError("bad`20direction`20in`20PeekLeft");
  1486. X`09`7D
  1487. X
  1488. X`09/*`20if`20any`20change,`20display`20the`20new`20view`20without`20moving!
  1489. V`20*/
  1490. X
  1491. X`09if`20((M.xPeek`20!=`20M.xloc)`20`7C`7C`20(M.yPeek`20!=`20M.yloc))`20`7B
  1492. X`09`09M.peeking`20=`20TRUE;
  1493. X`09`09updateView`20=`20TRUE;
  1494. X`09`7D
  1495. X`7D
  1496. X
  1497. XpeekRight()
  1498. X`7B
  1499. X`09M.xPeek`20=`20M.xloc;
  1500. X`09M.yPeek`20=`20M.yloc;
  1501. X`09M.dirPeek`20=`20M.dir;
  1502. X
  1503. X`09switch(M.dir)`20`7B
  1504. X`09case`20NORTH:`09if`20(!mp`5BM.xloc+1`5D.y`5BM.yloc`5D)`20`7B
  1505. X`09`09`09`09M.xPeek`20=`20M.xloc`20+`201;
  1506. X`09`09`09`09M.dirPeek`20=`20EAST;
  1507. X`09`09`09`7D
  1508. X`09`09`09break;
  1509. X
  1510. X`09case`20SOUTH:`09if`20(!mp`5BM.xloc-1`5D.y`5BM.yloc`5D)`20`7B
  1511. X`09`09`09`09M.xPeek`20=`20M.xloc`20-`201;
  1512. X`09`09`09`09M.dirPeek`20=`20WEST;
  1513. X`09`09`09`7D
  1514. X`09`09`09break;
  1515. X
  1516. X`09case`20EAST:`09if`20(!mp`5BM.xloc`5D.y`5BM.yloc+1`5D)`20`7B
  1517. X`09`09`09`09M.yPeek`20=`20M.yloc`20+`201;
  1518. X`09`09`09`09M.dirPeek`20=`20SOUTH;
  1519. X`09`09`09`7D
  1520. X`09`09`09break;
  1521. X
  1522. X`09case`20WEST:`09if`20(!mp`5BM.xloc`5D.y`5BM.yloc-1`5D)`20`7B
  1523. X`09`09`09`09M.yPeek`20=`20M.yloc`20-`201;
  1524. X`09`09`09`09M.dirPeek`20=`20NORTH;
  1525. X`09`09`09`7D
  1526. X`09`09`09break;
  1527. X
  1528. X`09default:
  1529. X`09`09`09MWError("bad`20direction`20in`20PeekRight");
  1530. X`09`7D
  1531. X
  1532. X`09/*`20if`20any`20change,`20display`20the`20new`20view`20without`20moving!
  1533. V`20*/
  1534. X
  1535. X`09if`20((M.xPeek`20!=`20M.xloc)`20`7C`7C`20(M.yPeek`20!=`20M.yloc))`20`7B
  1536. X`09`09M.peeking`20=`20TRUE;
  1537. X`09`09updateView`20=`20TRUE;
  1538. X`09`7D
  1539. X`7D
  1540. X
  1541. XpeekStop()
  1542. X`7B
  1543. X`09M.peeking`20=`20FALSE;
  1544. X`09updateView`20=`20TRUE;
  1545. X`7D
  1546. X
  1547. XDoViewUpdate()
  1548. X`7B
  1549. X`09if`20(updateView)`20`7B`09/*`20paint`20the`20screen`20*/
  1550. X`09`09ShowPosition(M.xloc,`20M.yloc,`20M.invincible,`20M.dir);
  1551. X`09`09if`20(M.peeking)
  1552. X`09`09`09ShowView(M.xPeek,`20M.yPeek,`20M.dirPeek);
  1553. X`09`09else
  1554. X`09`09`09ShowView(M.xloc,`20M.yloc,`20M.dir);
  1555. X`09`09updateView`20=`20FALSE;
  1556. X`09`7D
  1557. X`7D
  1558. X
  1559. Xshoot()
  1560. X`7B
  1561. X`09M.score--;
  1562. X`09M.ratcb.rats`5BM.myRatId`5D.score--;
  1563. X`09UpdateScoreCard(M.myRatId);
  1564. X`09sendKill();
  1565. X`7D
  1566. X
  1567. X/*`20
  1568. X`20*`20add`20the`20shot`20to`20the`20shot`20queue.`20It'll`20be`20processed
  1569. V`20later.
  1570. X`20*/
  1571. X
  1572. XholdBreath(ratKill)
  1573. XRatKill`09ratKill;
  1574. X`7B
  1575. X`09RatKillQ_t`09rkp;
  1576. X`09struct`20timeval`09now;
  1577. X`09
  1578. X`09DeadRatCursor();
  1579. X`09gettimeofday(`26now,`20NULL);
  1580. X
  1581. X`09if`20(RatKillQ`20==`20NULL)`20`7B
  1582. X`09`09RatKillQ`20=`20(RatKillQ_t)`20malloc(sizeof(AqRatKillQ));
  1583. X`09`09rkp`20=`20RatKillQ;
  1584. X`09`7D`20else`20`7B
  1585. X`09`09for`20(rkp`20=`20RatKillQ;`20rkp->nextOne`20!=`20NULL;`20rkp`20=`20rkp->
  1586. VnextOne)
  1587. X`09`09`09;
  1588. X`09`09rkp->nextOne`20=`20(RatKillQ_t)`20malloc(sizeof(AqRatKillQ));
  1589. X`09`09rkp`20=`20rkp->nextOne;
  1590. X`09`7D
  1591. X
  1592. X`09bcopy((char`20*)ratKill,`20(char`20*)`26rkp->thisOne,`20sizeof(AqRatKill));
  1593. V
  1594. X`09rkp->nextOne`20=`20NULL;
  1595. X`09rkp->shotHits`20=`20now;
  1596. X`09rkp->shotHits.tv_sec++;
  1597. X`7D
  1598. X
  1599. X/*`20
  1600. X`20*`20finally`20see`20if`20the`20shot`20hit`20home.
  1601. X`20*/
  1602. X
  1603. XhandleKill(tx,`20ty,`20td,`20ratId)
  1604. XLoc`09tx,`20ty;
  1605. XDirection`20td;
  1606. XRatId`09ratId;
  1607. X`7B
  1608. X`09while`20(!M.maze`5Btx`5D.y`5Bty`5D)`20`7B
  1609. X`09`09switch`20(td)`20`7B
  1610. X`09`09case`20NORTH:`09tx++;`20break;
  1611. X`09`09case`20SOUTH:`09tx--;`20break;
  1612. X`09`09case`20EAST:`09ty++;`20break;
  1613. X`09`09case`20WEST:`09ty--;`20break;
  1614. X`09`09`7D
  1615. X`09`09if`20((M.xloc`20==`20tx)`20`26`26`20(M.yloc`20==`20ty))`20`7B`09/*`20Oh
  1616. V`20oh...`20*/
  1617. X`09`09`09sendDead(ratId);
  1618. X`09`09`09NewPosition();`09/*`20avoid`20multiple`20hits`20*/
  1619. X`09`09`09FlashScreen();
  1620. X`09`09`09M.score`20-=`205;`09/*`20minus`205`20points`20for`20getting`20killed
  1621. V`20*/
  1622. X`09`09`09M.ratcb.rats`5BM.myRatId`5D.score`20=`20M.score;
  1623. X`09`09`09UpdateScoreCard(M.myRatId);
  1624. X`09`09`09NotifyPlayer();
  1625. X`09`09`09updateView`20=`20TRUE;
  1626. X`09`09`09sendLocation`20=`20TRUE;
  1627. X`09`09`7D
  1628. X`09`7D
  1629. X`09RatCursor();
  1630. X`7D
  1631. X
  1632. X/*
  1633. X`20*`20Process`20the`20pending`20shots,`20if`20any.
  1634. X`20*/
  1635. X
  1636. XDoRatKillQ()
  1637. X`7B
  1638. X`09struct`20timeval`09now;
  1639. X`09RatKillQ_t`09rkp`20=`20RatKillQ;
  1640. X`09RatKill`09`09ratKill;
  1641. X
  1642. X`09if`20(RatKillQ`20!=`20NULL)`20`7B
  1643. X`09`09gettimeofday(`26now,`20NULL);
  1644. X`09`09while`20(rkp`20!=`20NULL)`20`7B
  1645. X`09`09`09if`20(now.tv_sec`20>=`20rkp->shotHits.tv_sec)`20`7B
  1646. X`09`09`09`09if`20(now.tv_usec`20>=
  1647. X`09`09`09`09`20`20`20`20rkp->shotHits.tv_usec)`20`7B
  1648. X`09`09`09`09`09ratKill`20=`20`26RatKillQ->thisOne;
  1649. X`09`09`09`09`09handleKill(ratKill->xLoc,
  1650. X`09`09`09`09`09`09`20`20`20ratKill->yLoc,
  1651. X`09`09`09`09`09`09`20`20`20ratKill->dir,
  1652. X`09`09`09`09`09`09`20`20`20ratKill->ratId);
  1653. X`09`09`09`09`09RatKillQ`20=`20RatKillQ->nextOne;
  1654. X`09`09`09`09`09free((char`20*)`20rkp);
  1655. X`09`09`09`09`09rkp`20=`20RatKillQ;
  1656. X`09`09`09`09`7D`20else
  1657. X`09`09`09`09`09break;
  1658. X`09`09`09`7D`20else
  1659. X`09`09`09`09break;
  1660. X`09`09`7D
  1661. X`09`09if`20(RatKillQ`20==`20NULL)
  1662. X`09`09`09RatCursor();
  1663. X`09`7D
  1664. X`7D
  1665. X`09`09
  1666. X/*`20
  1667. X`20*`20Convert`20the`20contents`20of`20a`20packet`20to`20network`20order`20bef
  1668. Vore`20sending.
  1669. X`20*/
  1670. X
  1671. XConvertOutgoing(p)
  1672. XRatPacket`20*p;
  1673. X`7B
  1674. X`09char`09`09buf`5B64`5D;
  1675. X`09RatId`09`09ratId;
  1676. X`09RatLocation`09ratLoc;
  1677. X`09RatKill`09`09ratKill;
  1678. X`09RatDead`09`09ratDead;
  1679. X`09RatStatus`09ratStatus;
  1680. X`09RatNew`09`09ratNew;
  1681. X`09RatGone`09`09ratGone;
  1682. X`09RatQuery`09ratQuery;
  1683. X`09RatAlive`09ratAlive;
  1684. X`09RatMove`09`09ratMove;
  1685. X
  1686. X`09switch(p->type)`20`7B
  1687. X`09case`20RAT_LOCATION:
  1688. X`09`09ratLoc`20=`20(RatLocation)`20`26p->body;
  1689. X`09`09ratLoc->ratId`20=`20htonl(ratLoc->ratId);
  1690. X`09`09ratLoc->xLoc`20=`20`20htons(ratLoc->xLoc);
  1691. X`09`09ratLoc->yLoc`20=`20`20htons(ratLoc->yLoc);
  1692. X`09`09ratLoc->dir`20=`20`20`20htons(ratLoc->dir);
  1693. X`09`09ratLoc->score`20=`20htonl(ratLoc->score);
  1694. X`09`09break;
  1695. X
  1696. X`09case`20RAT_KILL:
  1697. X`09`09ratKill`20=`20(RatKill)`20`26p->body;
  1698. X`09`09ratKill->ratId`20=`20htonl(ratKill->ratId);
  1699. X`09`09ratKill->xLoc`20`20=`20htons(ratKill->xLoc);
  1700. X`09`09ratKill->yLoc`20`20=`20htons(ratKill->yLoc);
  1701. X`09`09ratKill->dir`20`20`20=`20htons(ratKill->dir);
  1702. X`09`09break;
  1703. X
  1704. X`09case`20RAT_DEAD:
  1705. X`09`09ratDead`20=`20(RatDead)`20`26p->body;
  1706. X`09`09ratDead->ratId`20=`20htonl(ratDead->ratId);
  1707. X`09`09ratDead->killedBy`20=`20htonl(ratDead->killedBy);
  1708. X`09`09break;
  1709. X
  1710. X`09case`20RAT_STATUS:
  1711. X`09`09ratStatus`20=`20(RatStatus)`20`26p->body;
  1712. X`09`09ratStatus->dukeRat`20=`20htonl(ratStatus->dukeRat);
  1713. X`09`09for`20(ratId`20=`200;`20ratId`20<`20MAXRATS;`20ratId++)`20`7B
  1714. X`09`09`09RatInfo`09ratInfo;
  1715. X
  1716. X`09`09`09ratInfo`20=`20`26ratStatus->rats`5BratId`5D;
  1717. X`09`09`09ratInfo->playing`20=`20htons(ratInfo->playing);
  1718. X`09`09`09ratInfo->xLoc`20=`20htons(ratInfo->xLoc);
  1719. X`09`09`09ratInfo->yLoc`20=`20htons(ratInfo->yLoc);
  1720. X`09`09`09ratInfo->dir`20=`20htons(ratInfo->dir);
  1721. X`09`09`09ratInfo->score`20=`20htonl(ratInfo->score);
  1722. X`09`09`09ratInfo->addr.sin_family`20=
  1723. X`09`09`09`09ntohs(ratInfo->addr.sin_family);
  1724. X`09`09`09/*`20don't`20touch`20address`20or`20name`20*/
  1725. X`09`09`7D
  1726. X`09`09break;
  1727. X
  1728. X`09case`20RAT_NEW:
  1729. X`09`09ratNew`20=`20(RatNew)`20`26p->body;
  1730. X`09`09ratNew->pass`20=`20htons(ratNew->pass);
  1731. X`09`09ratNew->xLoc`20=`20htons(ratNew->xLoc);
  1732. X`09`09ratNew->yLoc`20=`20htons(ratNew->yLoc);
  1733. X`09`09ratNew->dir`20`20=`20htons(ratNew->dir);
  1734. X`09`09ratNew->addr.sin_family`20=
  1735. X`09`09`09htons(ratNew->addr.sin_family);
  1736. X`09`09/*`20don't`20touch`20address`20or`20name`20*/
  1737. X`09`09break;
  1738. X
  1739. X`09case`20RAT_GOING:
  1740. X`09`09ratGone`20=`20(RatGone)`20`26p->body;
  1741. X`09`09ratGone->ratId`20=`20htonl(ratGone->ratId);
  1742. X`09`09break;
  1743. X
  1744. X`09case`20RAT_QUERY:
  1745. X`09`09ratQuery`20=`20(RatQuery)`20`26p->body;
  1746. X`09`09ratQuery->ratId`20=`20htonl(ratQuery->ratId);
  1747. X`09`09break;
  1748. X
  1749. X`09case`20RAT_ALIVE:
  1750. X`09`09ratAlive`20=`20(RatAlive)`20`26p->body;
  1751. X`09`09ratAlive->ratId`20=`20htonl(ratAlive->ratId);
  1752. X`09`09break;
  1753. X
  1754. X`09case`20RAT_SURVEY:
  1755. X`09`09ratNew`20=`20(RatNew)`20`26p->body;
  1756. X`09`09ratNew->pass`20=`20htons(ratNew->pass);
  1757. X`09`09ratNew->xLoc`20=`20htons(ratNew->xLoc);
  1758. X`09`09ratNew->yLoc`20=`20htons(ratNew->yLoc);
  1759. X`09`09ratNew->dir`20`20=`20htons(ratNew->dir);
  1760. X`09`09/*`20don't`20touch`20address`20or`20name`20*/
  1761. X`09`09break;
  1762. X
  1763. X`09case`20RAT_MOVE:
  1764. X`09`09ratMove`20=`20(RatMove)`20`26p->body;
  1765. X`09`09ratMove->ratId`20=`20htonl(ratMove->ratId);
  1766. X`09`09break;
  1767. X
  1768. X`09default:
  1769. X`09`09sprintf(buf,`20"ConvertOutgoing`20bad`20type`20%d`20(%d)",
  1770. X`09`09`09p->type,`20htons(p->type));
  1771. X`09`09MWError(buf);
  1772. X`09`7D
  1773. X`09p->type`20=`20htonl(p->type);
  1774. X`7D
  1775. X
  1776. X/*`20
  1777. X`20*`20Convert`20the`20contents`20of`20a`20packet`20to`20host`20order`20after
  1778. V`20ConvertIncoming.
  1779. X`20*/
  1780. X
  1781. XConvertIncoming(p)
  1782. XRatPacket`20*p;
  1783. X`7B
  1784. X`09char`09`09buf`5B64`5D;
  1785. X`09RatId`09`09ratId;
  1786. X`09RatLocation`09ratLoc;
  1787. X`09RatKill`09`09ratKill;
  1788. X`09RatDead`09`09ratDead;
  1789. X`09RatStatus`09ratStatus;
  1790. X`09RatNew`09`09ratNew;
  1791. X`09RatGone`09`09ratGone;
  1792. X`09RatQuery`09ratQuery;
  1793. X`09RatAlive`09ratAlive;
  1794. X`09RatMove`09`09ratMove;
  1795. X
  1796. X`09p->type`20=`20ntohl(p->type);
  1797. X`09switch(p->type)`20`7B
  1798. X`09case`20RAT_LOCATION:
  1799. X`09`09ratLoc`20=`20(RatLocation)`20`26p->body;
  1800. X`09`09ratLoc->ratId`20=`20ntohl(ratLoc->ratId);
  1801. X`09`09ratLoc->xLoc`20=`20`20ntohs(ratLoc->xLoc);
  1802. X`09`09ratLoc->yLoc`20=`20`20ntohs(ratLoc->yLoc);
  1803. X`09`09ratLoc->dir`20=`20`20`20ntohs(ratLoc->dir);
  1804. X`09`09ratLoc->score`20=`20ntohl(ratLoc->score);
  1805. X`09`09break;
  1806. X
  1807. X`09case`20RAT_KILL:
  1808. X`09`09ratKill`20=`20(RatKill)`20`26p->body;
  1809. X`09`09ratKill->ratId`20=`20ntohl(ratKill->ratId);
  1810. X`09`09ratKill->xLoc`20`20=`20ntohs(ratKill->xLoc);
  1811. X`09`09ratKill->yLoc`20`20=`20ntohs(ratKill->yLoc);
  1812. X`09`09ratKill->dir`20`20`20=`20ntohs(ratKill->dir);
  1813. X`09`09break;
  1814. X
  1815. X`09case`20RAT_DEAD:
  1816. X`09`09ratDead`20=`20(RatDead)`20`26p->body;
  1817. X`09`09ratDead->ratId`20=`20ntohl(ratDead->ratId);
  1818. X`09`09ratDead->killedBy`20=`20ntohl(ratDead->killedBy);
  1819. X`09`09break;
  1820. X
  1821. X`09case`20RAT_STATUS:
  1822. X`09`09ratStatus`20=`20(RatStatus)`20`26p->body;
  1823. X`09`09ratStatus->dukeRat`20=`20ntohl(ratStatus->dukeRat);
  1824. X`09`09for`20(ratId`20=`200;`20ratId`20<`20MAXRATS;`20ratId++)`20`7B
  1825. X`09`09`09RatInfo`09ratInfo;
  1826. X
  1827. X`09`09`09ratInfo`20=`20`26ratStatus->rats`5BratId`5D;
  1828. X`09`09`09ratInfo->playing`20=`20ntohs(ratInfo->playing);
  1829. X`09`09`09ratInfo->xLoc`20=`20ntohs(ratInfo->xLoc);
  1830. X`09`09`09ratInfo->yLoc`20=`20ntohs(ratInfo->yLoc);
  1831. X`09`09`09ratInfo->dir`20=`20ntohs(ratInfo->dir);
  1832. X`09`09`09ratInfo->score`20=`20ntohl(ratInfo->score);
  1833. X`09`09`09ratInfo->addr.sin_family`20=
  1834. X`09`09`09`09ntohs(ratInfo->addr.sin_family);
  1835. X`09`09`09/*`20don't`20touch`20address`20or`20name`20*/
  1836. X`09`09`7D
  1837. X`09`09break;
  1838. X
  1839. X`09case`20RAT_NEW:
  1840. X`09`09ratNew`20=`20(RatNew)`20`26p->body;
  1841. X`09`09ratNew->pass`20=`20ntohs(ratNew->pass);
  1842. X`09`09ratNew->xLoc`20=`20ntohs(ratNew->xLoc);
  1843. X`09`09ratNew->yLoc`20=`20ntohs(ratNew->yLoc);
  1844. X`09`09ratNew->dir`20`20=`20ntohs(ratNew->dir);
  1845. X`09`09ratNew->addr.sin_family`20=
  1846. X`09`09`09ntohs(ratNew->addr.sin_family);
  1847. X`09`09/*`20don't`20touch`20address`20or`20name`20*/
  1848. X`09`09break;
  1849. X
  1850. X`09case`20RAT_GOING:
  1851. X`09`09ratGone`20=`20(RatGone)`20`26p->body;
  1852. X`09`09ratGone->ratId`20=`20ntohl(ratGone->ratId);
  1853. X`09`09break;
  1854. X
  1855. X`09case`20RAT_QUERY:
  1856. X`09`09ratQuery`20=`20(RatQuery)`20`26p->body;
  1857. X`09`09ratQuery->ratId`20=`20ntohl(ratQuery->ratId);
  1858. X`09`09break;
  1859. X
  1860. X`09case`20RAT_ALIVE:
  1861. X`09`09ratAlive`20=`20(RatAlive)`20`26p->body;
  1862. X`09`09ratAlive->ratId`20=`20ntohl(ratAlive->ratId);
  1863. X`09`09break;
  1864. X
  1865. X`09case`20RAT_SURVEY:
  1866. X`09`09ratNew`20=`20(RatNew)`20`26p->body;
  1867. X`09`09ratNew->pass`20=`20ntohs(ratNew->pass);
  1868. X`09`09ratNew->xLoc`20=`20ntohs(ratNew->xLoc);
  1869. X`09`09ratNew->yLoc`20=`20ntohs(ratNew->yLoc);
  1870. X`09`09ratNew->dir`20`20=`20ntohs(ratNew->dir);
  1871. X`09`09/*`20don't`20touch`20address`20or`20name`20*/
  1872. X`09`09break;
  1873. X
  1874. X`09case`20RAT_MOVE:
  1875. X`09`09ratMove`20=`20(RatMove)`20`26p->body;
  1876. X`09`09ratMove->ratId`20=`20ntohl(ratMove->ratId);
  1877. X`09`09break;
  1878. X
  1879. X`09default:
  1880. X`09`09sprintf(buf,`20"ConvertIncoming`20bad`20type`20%d`20(%d)",
  1881. X`09`09`09p->type,`20ntohs(p->type));
  1882. X`09`09MWError(buf);
  1883. X`09`7D
  1884. X`7D
  1885. X
  1886. X#ifdef`09PACKET_TRACE
  1887. Xstatic`20char`09*packTypes`5B`5D`20=`20`7B
  1888. X`09"RAT_LOCATION",
  1889. X`09"RAT_KILL",
  1890. X`09"RAT_DEAD",
  1891. X`09"RAT_STATUS",
  1892. X`09"RAT_NEW",
  1893. X`09"RAT_GOING",
  1894. X`09"RAT_QUERY",
  1895. X`09"RAT_ALIVE",
  1896. X`09"RAT_SURVEY",
  1897. X`09"RAT_MOVE",
  1898. X`090
  1899. X`7D;
  1900. X#endif`09PACKET_TRACE
  1901. X
  1902. XreadRats(evp)
  1903. XMWEvent`20*evp;
  1904. X`7B
  1905. X`09register`20RatLocation`09ratLoc;
  1906. X`09register`20RatLook`09ratLook;
  1907. X`09register`20RatAlive`09ratAlive;
  1908. X`09RatPacket`09*pack`20=`20evp->eventDetail;
  1909. X`09RatInfo`09`09ratInfo;
  1910. X`09Boolean`09`09oldVisible;
  1911. X`09RatId`09`09ratId;
  1912. X`09RatStatus`09status;
  1913. X`09RatNew`09`09ratNew;
  1914. X`09RatGone`09`09ratGone;
  1915. X`09RatKill`09`09ratKill;
  1916. X`09RatDead`09`09ratDead;
  1917. X`09RatQuery`09ratQuery;
  1918. X`09RatMove`09`09ratMove;
  1919. X`09Sockaddr`09nullAddr;
  1920. X`09char`09`09buf`5B32`5D;
  1921. X`09int`09`09newSocket;
  1922. X
  1923. X#ifdef`09PACKET_TRACE
  1924. X`09printf("received`20%s`20(%d)`5Cn",
  1925. X`09`09packTypes`5Bpack->type`20-`201`5D,`20pack->type);
  1926. X#endif`09PACKET_TRACE
  1927. X
  1928. X`09switch(pack->type)`20`7B
  1929. X`09case`20RAT_LOCATION:`09`09/*`20someone`20moved`20*/
  1930. X`09`09ratLoc`20=`20(RatLocation)`20`26pack->body;
  1931. X`09`09ratLook`20=`20`26R2d2`5BratLoc->ratId`5D;
  1932. X`09`09if`20((oldVisible`20=`20ratLook->visible)`20==`20TRUE)
  1933. X`09`09`09XORToken(ratLoc->ratId);
  1934. X`09`09ratInfo`20=`20`26M.ratcb.rats`5BratLoc->ratId`5D;
  1935. X`09`09ratInfo->xLoc`20=`20ratLoc->xLoc;
  1936. X`09`09ratInfo->yLoc`20=`20ratLoc->yLoc;
  1937. X`09`09ratInfo->dir`20`20=`20ratLoc->dir;
  1938. X`09`09DisplayOthersPosition(ratLoc->ratId,`20ratLoc->xLoc,
  1939. X`09`09`09`09`20`20`20`20`20`20ratLoc->yLoc,`20ratLoc->dir);
  1940. X`09`09TokenVisible(ratLoc->ratId);
  1941. X`09`09if`20(ratLook->visible`20==`20TRUE)
  1942. X`09`09`09XORToken(ratLoc->ratId);
  1943. X`09`09if`20((oldVisible`20!=`20ratLook->visible)`20`7C`7C
  1944. X`09`09`20`20`20`20(ratInfo->score`20!=`20ratLoc->score))`20`7B
  1945. X`09`09`09ratInfo->score`20=`20ratLoc->score;
  1946. X`09`09`09UpdateScoreCard(ratLoc->ratId);
  1947. X`09`09`7D
  1948. X`09`09ratHealth`5BratLoc->ratId`5D.rcvd`20=`20TRUE;
  1949. X`09`09break;
  1950. X
  1951. X`09case`20RAT_KILL:`09`09`09/*`20someone`20shot`20at`20me`20*/
  1952. X`09`09if`20(!M.invincible)`20`7B
  1953. X`09`09`09ratKill`20=`20(RatKill)`20`26pack->body;
  1954. X`09`09`09holdBreath(ratKill);
  1955. X`09`09`7D
  1956. X`09`09break;
  1957. X
  1958. X`09case`20RAT_DEAD:`09`09`09/*`20I`20hit`20someone`20*/
  1959. X`09`09ratDead`20=`20(RatDead)`20`26pack->body;
  1960. X`09`09if`20(ratDead->killedBy`20==`20M.myRatId)`20`7B
  1961. X`09`09`09FlashTop();`09/*`20got`20him!`20*/
  1962. X`09`09`09M.score`20+=`2010;`09/*`2010`20points`20for`20a`20kill`20*/
  1963. X`09`09`09M.score`20+=`201;`09/*`20make`20up`20for`20shot`20cost`20*/
  1964. X`09`09`09M.ratcb.rats`5BM.myRatId`5D.score`20=`20M.score;
  1965. X`09`09`09UpdateScoreCard(M.myRatId);
  1966. X`09`09`09sendLocToAll();
  1967. X`09`09`7D
  1968. X`09`09break;
  1969. X
  1970. X`09case`20RAT_STATUS:`09`09/*`20new`20info`20about`20everyone`20*/
  1971. X`09`09status`20=`20(RatStatus)`20`26pack->body;
  1972. X`09`09if`20(bcmp(`26status->rats`5BM.myRatId`5D.addr,`20`26M.myAddr,
  1973. X`09`09`09`20`20sizeof(M.myAddr))`20!=`200)
  1974. X`09`09`09break;`09`09/*`20not`20for`20me,`20from`20another`20game`20*/
  1975. X`09`09`09`09`09/*`20perhaps`20left`20over`20from`20findDuke()`20*/
  1976. X
  1977. X`09`09/*`20Have`20a`20new`20table,`20turn`20off`20any`20visible`20opponents
  1978. V`20*/
  1979. X
  1980. X`09`09for`20(ratId`20=`200;`20ratId`20<`20MAXRATS;`20ratId++)
  1981. X`09`09`09if`20(R2d2`5BratId`5D.visible`20==`20TRUE)
  1982. X`09`09`09`09XORToken(ratId);
  1983. X`09`09bcopy((char`20*)status,`20(char`20*)`26M.ratcb,`20sizeof(RatCb));
  1984. X`09`09if`20(M.ratcb.dukeRat`20==`20M.myRatId)
  1985. X`09`09`09M.duke`20=`20TRUE;
  1986. X`09`09for`20(ratId`20=`200;`20ratId`20<`20MAXRATS;`20ratId++)`20`7B
  1987. X`09`09`09TokenVisible(ratId);
  1988. X`09`09`09if`20(R2d2`5BratId`5D.visible`20==`20TRUE)
  1989. X`09`09`09`09XORToken(ratId);
  1990. X`09`09`7D
  1991. X`09`09NewScoreCard();
  1992. X`09`09ratInfo`20=`20`26M.ratcb.rats`5BM.myRatId`5D;
  1993. X`09`09if`20((ratInfo->xLoc`20!=`20M.xloc)`20`7C`7C
  1994. X`09`09`20`20`20`20(ratInfo->yLoc`20!=`20M.yloc)`20`7C`7C
  1995. X`09`09`20`20`20`20(ratInfo->dir`20`20!=`20M.dir))
  1996. X`09`09`09sendLocToAll();
  1997. X`09`09
  1998. X`09`09break;
  1999. X
  2000. X`09case`20RAT_NEW:`09`09`09/*`20new`20player`20*/
  2001. X`09`09ratNew`20=`20(RatNew)`20`26pack->body;
  2002. X`09`09if`20(ratNew->pass`20==`20RAT_PASSWORD)`20`7B
  2003. X`09`09`09if`20(M.duke)`20`7B
  2004. X`09`09`09`09/*`20
  2005. X`09`09`09`09`20*`20need`20to`20check`20for`20duplicates`20here;
  2006. X`09`09`09`09`20*`20a`20previous`20reply`20might`20have`20been
  2007. X`09`09`09`09`20*`20lost.`20Can't`20let`20the`20same`20guy`20in`20the
  2008. X`09`09`09`09`20*`20game`20twice.
  2009. X`09`09`09`09`20*/
  2010. X
  2011. X`09`09`09`09register`20RatId`09id;
  2012. X
  2013. X`09`09`09`09for`20(id`20=`200;`20id`20<`20MAXRATS;`20id++)
  2014. X`09`09`09`09`09if`20(M.ratcb.rats`5Bid`5D.playing`20`26`26
  2015. X`09`09`09`09`09`20`20`20`20!bcmp(`26M.ratcb.rats`5Bid`5D.addr,
  2016. X`09`09`09`09`09`09`20`20`26evp->eventSource,
  2017. X`09`09`09`09`09`09`20`20sizeof`20(Sockaddr)))`20`7B
  2018. X
  2019. X`09`09`09`09`09`09/*`20already`20there`20*/
  2020. X`09`09`09`09`09`09sendStatus(evp->eventSource);
  2021. X`09`09`09`09`09`09break;
  2022. X`09`09`09`09`09`7D
  2023. X`09`09`09`09if`20(id`20>=`20MAXRATS)`20`7B`09/*`20fell`20through`20*/
  2024. X`09`09`09`09`09allocateNewRat(ratNew);
  2025. X`09`09`09`09`09sendAllStatus();
  2026. X`09`09`09`09`7D
  2027. X`09`09`09`7D`20else
  2028. X`09`09`09`09sendStatus(evp->eventSource);
  2029. X`09`09`7D
  2030. X`09`09break;
  2031. X
  2032. X`09case`20RAT_GOING:`09`09`20`20`20`20`20`20`20/*`20player`20leaving,`20only
  2033. V`20rcvd`20if`20duke`20*/
  2034. X`09`09ratGone`20=`20(RatGone)`20`26pack->body;
  2035. X`09`09ratLeft(ratGone->ratId);
  2036. X`09`09break;
  2037. X
  2038. X`09case`20RAT_QUERY:`09`09`09/*`20are`20you`20alive?`20*/
  2039. X`09`09/*
  2040. X`09`09`20*`20register`20their`20net`20address,`20in`20case`20they`20got`20a
  2041. X`09`09`20*`20RAT_MOVE,`20moved,`20and`20the`20change`20got`20lost`20somewhere.
  2042. V
  2043. X`09`09`20*/
  2044. X`09`09ratQuery`20=`20(RatQuery)`20`26pack->body;
  2045. X`09`09M.ratcb.rats`5BratQuery->ratId`5D.addr`20=`20evp->eventSource;
  2046. X
  2047. X`09`09sendAlive();
  2048. X`09`09break;
  2049. X
  2050. X`09case`20RAT_ALIVE:`09`09`09/*`20I`20am`20alive`20*/
  2051. X`09`09ratAlive`20=`20(RatAlive)`20`26pack->body;
  2052. X`09`09ratHealth`5BratAlive->ratId`5D.rcvd`20=`20TRUE;
  2053. X`09`09break;
  2054. X
  2055. X`09case`20RAT_SURVEY:`09`09/*`20who's`20out`20there?`20*/
  2056. X`09`09ratNew`20=`20(RatNew)`20`26pack->body;
  2057. X`09`09if`20(ratNew->pass`20==`20RAT_PASSWORD)
  2058. X`09`09`09sendStatus(evp->eventSource);
  2059. X`09`09break;
  2060. X
  2061. X`09case`20RAT_MOVE:`09`09`09/*`20move`20to`20M.mazePort`20*/
  2062. X`09`09ratMove`20=`20(RatMove)`20`26pack->body;
  2063. X`09`09if`20(ratMove->ratId`20!=`20M.ratcb.dukeRat)
  2064. X`09`09`09MWError("bogus`20RAT_MOVE");
  2065. X#ifdef`20VMS
  2066. X`09`09socket_close(M.theSocket);
  2067. X#else
  2068. X`09`09close(M.theSocket);
  2069. X#endif
  2070. X
  2071. X`09`09/*`20
  2072. X`09`09`20*`20If`20the`20socket`20being`20closed`20is`20on`20this`20machine,
  2073. X`09`09`20*`20leave`20some`20time`20for`20the`20socket`20to`20close`20down`20be
  2074. Vfore
  2075. X`09`09`20*`20I`20try`20to`20grab`20it.
  2076. X`09`09`20*/
  2077. X
  2078. X`09`09if`20(bcmp((char`20*)`20`26evp->eventSource.sin_addr,
  2079. X`09`09`09`20`20(char`20*)`20`26M.myAddr.sin_addr,
  2080. X`09`09`09`20`20sizeof(M.myAddr.sin_addr))`20==`200)
  2081. X`09`09`09sleep(1);
  2082. X
  2083. X`09`09/*`20grab`20the`20socket`20*/
  2084. X
  2085. X`09`09newSocket`20=`20socket(AF_INET,`20SOCK_DGRAM,`200);
  2086. X`09`09if`20(newSocket`20<`200)
  2087. X`09`09`09MWError("RAT_MOVE`20lost`20socket");
  2088. X#ifdef`20VMS
  2089. X`09`09M.theSocket`20=`20newSocket;
  2090. X#else
  2091. X`09`09if`20(dup2(newSocket,`20M.theSocket)`20<`200)
  2092. X`09`09`09MWError("RAT_MOVE`20dup2`20failed");
  2093. X#endif
  2094. X`09`09`7B
  2095. X`09`09`20`20int`20opt`20=`201;
  2096. X`09`09`20`20if`20(setsockopt(M.theSocket,`20SOL_SOCKET,`20SO_REUSEADDR,
  2097. X`09`09`09`09`20`26opt,`20sizeof`20(opt))`20<`200)
  2098. X`09`09`20`20`20`20MWError("RAT_MOVE`20can't`20reuse`20addresses");
  2099. X`09`09`7D
  2100. X`09`09M.myAddr.sin_port`20=`20M.mazePort;
  2101. X`09`09nullAddr`20=`20M.myAddr;`09/*`20see`20netInit()`20*/
  2102. X`09`09bzero((char`20*)`20`26nullAddr.sin_addr,`20sizeof(nullAddr.sin_addr));
  2103. X`09`09if`20(bind(M.theSocket,`20`26nullAddr,`20sizeof(nullAddr))`20<`200)
  2104. X`09`09`09MWError("RAT_MOVE`20can't`20bind");
  2105. X#ifdef`20VMS
  2106. X`09`09arm_net_input`20(M.theSocket);
  2107. X#endif
  2108. X`09`09M.ratcb.rats`5BM.myRatId`5D.addr`20=`20M.myAddr;
  2109. X`09`09sendAllStatus();
  2110. X`09`09break;
  2111. X
  2112. X`09default:
  2113. X`09`09sprintf(buf,`20"readRats`20bad`20packet`20type`200x%x",`20pack->type);
  2114. X`09`09MWError(buf);
  2115. X`09`7D
  2116. X`7D
  2117. X
  2118. X/*`20
  2119. X`20*`20In`20order`20to`20reduce`20the`20network`20traffic,`20only`20send`20out
  2120. V`20the`20location`20change`20if
  2121. X`20*`20there's`20no`20keyboard`20input`20pending.
  2122. X`20*/
  2123. X
  2124. XSendLocation()
  2125. X`7B
  2126. X`09Boolean`09`09KBEventPending();
  2127. X`09if`20(!KBEventPending())
  2128. X`09`09if`20(sendLocation)`20`7B
  2129. X`09`09`09sendLocToAll();
  2130. X`09`09`09sendLocation`20=`20FALSE;
  2131. X`09`09`7D
  2132. X`7D
  2133. X
  2134. X/*`20
  2135. X`20*`20Let`20everyone`20know`20I've`20moved.
  2136. X`20*/
  2137. X
  2138. XsendLocToAll()
  2139. X`7B
  2140. X`09RatPacket`09pack;
  2141. X`09RatLocation`09ratloc;
  2142. X`09RatId`09`09i;
  2143. X`09RatInfo`09`09ratInfo`20=`20`26M.ratcb.rats`5BM.myRatId`5D;
  2144. X
  2145. X`09ratInfo->xLoc`20=`20M.xloc;`09`09/*`20update`20my`20table,`20too`20*/
  2146. X`09ratInfo->yLoc`20=`20M.yloc;
  2147. X`09ratInfo->dir`20`20=`20M.dir;
  2148. X`09ratInfo->score`20=`20M.score;
  2149. X
  2150. X`09pack.type`20=`20RAT_LOCATION;
  2151. X`09ratloc`20=`20(RatLocation)`20`26pack.body;
  2152. X`09ratloc->ratId`20=`20M.myRatId;
  2153. X`09ratloc->xLoc`20=`20ratInfo->xLoc;
  2154. X`09ratloc->yLoc`20=`20ratInfo->yLoc;
  2155. X`09ratloc->dir`20=`20ratInfo->dir;
  2156. X`09ratloc->score`20=`20ratInfo->score;
  2157. X`09ConvertOutgoing(`26pack);
  2158. X`09
  2159. X`09/*`20
  2160. X`09`20*`20Would`20really`20like`20this`20to`20be`20asynchronous,`20so`20play
  2161. V`20could
  2162. X`09`20*`20continue`20while`20the`20packets`20are`20being`20sent.`20Of`20course
  2163. V,`20then,
  2164. X`09`20*`20the`20data`20might`20change`20in`20the`20midst`20of`20all`20this...
  2165. X`09`20*/
  2166. X
  2167. X`09for`20(i`20=`200;`20i`20<`20MAXRATS;`20i++)
  2168. X`09`09if`20((i`20!=`20M.myRatId)`20`26`26`20(M.ratcb.rats`5Bi`5D.playing))
  2169. X`09`09`09if`20(sendto(M.theSocket,`20`26pack,`20sizeof(pack),`200,
  2170. X`09`09`09`09`20`20`26M.ratcb.rats`5Bi`5D.addr,`20sizeof(Sockaddr))`20<`200)
  2171. X`09`09`09`09MWError("sendLocToAll");
  2172. X`7D
  2173. X
  2174. XsendAllStatus()
  2175. X`7B
  2176. X`09RatId`09i;
  2177. X
  2178. X`09for`20(i`20=`200;`20i`20<`20MAXRATS;`20i++)
  2179. X`09`09if`20((i`20!=`20M.myRatId)`20`26`26`20(M.ratcb.rats`5Bi`5D.playing))
  2180. X`09`09`09sendStatus(M.ratcb.rats`5Bi`5D.addr);
  2181. X`7D
  2182. X
  2183. X/*`20
  2184. X`20*`20Send`20the`20entire`20status`20data`20to`20a`20rat.
  2185. X`20*/
  2186. X
  2187. XsendStatus(to)
  2188. XSockaddr`20to;
  2189. X`7B
  2190. X`09RatPacket`09pack;
  2191. X
  2192. X`09pack.type`20=`20RAT_STATUS;
  2193. X`09pack.body`20=`20M.ratcb;
  2194. X`09ConvertOutgoing(`26pack);
  2195. X`09if`20(sendto(M.theSocket,`20`26pack,`20sizeof(pack),`200,`20`26to,`20sizeof
  2196. V(to))`20<`200)
  2197. X`09`09MWError("sendStatus");
  2198. X`7D
  2199. X
  2200. X/*`20
  2201. X`20*`20Tell`20a`20player`20he's`20being`20shot`20at.
  2202. X`20*/
  2203. X
  2204. XsendKill()
  2205. X`7B
  2206. X`09RatPacket`09pack;
  2207. X`09RatKill`09`09ratKill;
  2208. X`09RatId`09`09ixRatId;
  2209. X
  2210. X`09for`20(ixRatId`20=`200;`20ixRatId`20<`20MAXRATS;`20ixRatId++)`20`7B
  2211. X`09`09if`20(ixRatId`20==`20M.myRatId)
  2212. X`09`09`09continue;
  2213. X`09`09if`20(R2d2`5BixRatId`5D.visible)`20`7B
  2214. X`09`09`09pack.type`20=`20RAT_KILL;
  2215. X`09`09`09ratKill`20=`20(RatKill)`20`26pack.body;
  2216. X`09`09`09ratKill->ratId`20=`20M.myRatId;
  2217. X`09`09`09ratKill->xLoc`20=`20M.xloc;
  2218. X`09`09`09ratKill->yLoc`20=`20M.yloc;
  2219. X`09`09`09ratKill->dir`20`20=`20M.dir;
  2220. X`09`09`09ConvertOutgoing(`26pack);
  2221. X`09`09`09if`20(sendto(M.theSocket,`20`26pack,`20sizeof(pack),`200,
  2222. X`09`09`09`09`20`20`20`26M.ratcb.rats`5BixRatId`5D.addr,
  2223. X`09`09`09`09`20`20`20sizeof(M.ratcb.rats`5BixRatId`5D.addr))`20<`200)
  2224. X`09`09`09`09MWError("sendKill");
  2225. X`09`09`7D
  2226. X`09`7D
  2227. X`7D
  2228. X
  2229. X/*`20
  2230. X`20*`20Tell`20a`20shooter`20he`20hit`20me.
  2231. X`20*/
  2232. X
  2233. XsendDead(killerRatId)
  2234. XRatId`09killerRatId;
  2235. X`7B
  2236. X`09RatPacket`09pack;
  2237. X`09RatDead`09`09ratDead;
  2238. X
  2239. X`09pack.type`20=`20RAT_DEAD;
  2240. X`09ratDead`20=`20(RatDead)`20`26pack.body;
  2241. X`09ratDead->ratId`20=`20M.myRatId;
  2242. X`09ratDead->killedBy`20=`20killerRatId;
  2243. X`09ConvertOutgoing(`26pack);
  2244. X`09if`20(sendto(M.theSocket,`20`26pack,`20sizeof(pack),`200,
  2245. X`09`09`20`20`26M.ratcb.rats`5BkillerRatId`5D.addr,`20sizeof(Sockaddr))`20<`200
  2246. V)
  2247. X`09`09MWError("sendDead");
  2248. X`7D
  2249. X
  2250. X/*`20
  2251. X`20*`20Tell`20the`20duke`20I'm`20leaving.
  2252. X`20*/
  2253. X
  2254. XsendGoing()
  2255. X`7B
  2256. X`09RatPacket`09pack;
  2257. X`09RatGone`09`09ratGone;
  2258. X
  2259. X`09pack.type`20=`20RAT_GOING;
  2260. X`09ratGone`20=`20(RatGone)`20`26pack.body;
  2261. X`09ratGone->ratId`20=`20M.myRatId;
  2262. X`09ConvertOutgoing(`26pack);
  2263. X`09if`20(sendto(M.theSocket,`20`26pack,`20sizeof(pack),`200,
  2264. X`09`09`20`20`26M.ratcb.rats`5BM.ratcb.dukeRat`5D.addr,`20sizeof(Sockaddr))`20<
  2265. V`200)
  2266. X`09`09MWError("sendGoing");
  2267. X`7D
  2268. X
  2269. X/*`20
  2270. X`20*`20Ask`20the`20silent`20types`20if`20they're`20alive.
  2271. X`20*/
  2272. X
  2273. XsendQuery()
  2274. X`7B
  2275. X`09RatPacket`09pack;
  2276. X`09RatId`09`09ratId;
  2277. X`09RatQuery`09ratQuery;
  2278. X
  2279. X`09for`20(ratId`20=`200;`20ratId`20<`20MAXRATS;`20ratId++)
  2280. X`09`09if`20(ratHealth`5BratId`5D.send)`20`7B
  2281. X`09`09`09pack.type`20=`20RAT_QUERY;
  2282. X`09`09`09ratQuery`20=`20(RatQuery)`20`26pack.body;
  2283. X`09`09`09ratQuery->ratId`20=`20M.myRatId;
  2284. X`09`09`09ratHealth`5BratId`5D.send`20=`20FALSE;
  2285. X`09`09`09ConvertOutgoing(`26pack);
  2286. X`09`09`09if`20(sendto(M.theSocket,`20`26pack,`20sizeof(pack),`200,
  2287. X`09`09`09`09`20`20`26M.ratcb.rats`5BratId`5D.addr,
  2288. X`09`09`09`09`20`20sizeof(Sockaddr))`20<`200)
  2289. X`09`09`09`09MWError("sendQuery");
  2290. X`09`09`7D
  2291. X`7D
  2292. X
  2293. X/*`20
  2294. X`20*`20Register`20someone`20as`20alive,`20and`20let`20them`20know`20we`20are,
  2295. V`20too.`20
  2296. X`20*/
  2297. X
  2298. XsendAlive()
  2299. X`7B
  2300. X`09RatPacket`09pack;
  2301. X`09RatId`09`09ratId;
  2302. X`09RatAlive`09ratAlive;
  2303. X
  2304. X`09for`20(ratId`20=`200;`20ratId`20<`20MAXRATS;`20ratId++)`20`7B
  2305. X`09`09if`20((ratId`20==`20M.myRatId)`20`7C`7C
  2306. X`09`09`20`20`20`20!M.ratcb.rats`5BratId`5D.playing)
  2307. X`09`09`09continue;
  2308. X`09`09pack.type`20=`20RAT_ALIVE;
  2309. X`09`09ratAlive`20=`20(RatAlive)`20`26pack.body;
  2310. X`09`09ratAlive->ratId`20=`20M.myRatId;
  2311. X`09`09ConvertOutgoing(`26pack);
  2312. X`09`09if`20(sendto(M.theSocket,`20`26pack,`20sizeof(pack),`200,
  2313. X`09`09`20`20`20`20`20`20`26M.ratcb.rats`5BratId`5D.addr,`20sizeof(Sockaddr))
  2314. V`20<`200)
  2315. X`09`09`09MWError("sendAlive");
  2316. X`09`7D
  2317. X`7D
  2318. X
  2319. X/*`20
  2320. X`20*`20Let`20a`20new`20player`20in`20the`20game.
  2321. X`20*/
  2322. X
  2323. XallocateNewRat(ratNew)
  2324. XRatNew`09ratNew;
  2325. X`7B
  2326. X`09RatId`09ratId;
  2327. X`09RatInfo`09ratInfo;
  2328. X
  2329. X`09for`20(ratId`20=`200;`20ratId`20<`20MAXRATS;`20ratId++)`20`7B
  2330. X`09`09ratInfo`20=`20`26M.ratcb.rats`5BratId`5D;
  2331. X`09`09if`20(!ratInfo->playing)`20`7B
  2332. X`09`09`09ratInfo->playing`20=`20TRUE;
  2333. X`09`09`09ratInfo->xLoc`20=`20ratNew->xLoc;
  2334. X`09`09`09ratInfo->yLoc`20=`20ratNew->yLoc;
  2335. X`09`09`09ratInfo->dir`20`20=`20ratNew->dir;
  2336. X`09`09`09ratInfo->score`20=`200;
  2337. X`09`09`09ratInfo->addr`20=`20ratNew->addr;
  2338. X`09`09`09strncpy(ratInfo->name,`20ratNew->name,`20NAMESIZE);
  2339. X`09`09`09TokenVisible(ratId);
  2340. X`09`09`09UpdateScoreCard(ratId);
  2341. X`09`09`09if`20(R2d2`5BratId`5D.visible`20==`20TRUE)
  2342. X`09`09`09`09XORToken(ratId);
  2343. X`09`09`09AddNewPlayer(ratId,`20ratNew->xLoc,`20ratNew->yLoc,
  2344. X`09`09`09`09`09ratNew->dir);
  2345. X`09`09`09return;
  2346. X`09`09`7D
  2347. X`09`7D
  2348. X`7D
  2349. X
  2350. X/*`20
  2351. X`20*`20I`20wanna`20go`20home!
  2352. X`20*/
  2353. X
  2354. Xquit()
  2355. X`7B
  2356. X`09RatId`09ratId;
  2357. X
  2358. X`09if`20(!M.duke)
  2359. X`09`09sendGoing();
  2360. X`09else`20`7B`09`09`09`09/*`20oh`20oh,`20I'm`20the`20duke`20rat`20*/
  2361. X`09`09M.ratcb.rats`5BM.myRatId`5D.playing`20=`20FALSE;
  2362. X`09`09for`20(ratId`20=`200;`20ratId`20<`20MAXRATS;`20ratId++)
  2363. X`09`09`09if`20(M.ratcb.rats`5BratId`5D.playing)`20`7B
  2364. X`09`09`09`09M.ratcb.dukeRat`20=`20ratId;
  2365. X`09`09`09`09sendAllStatus();
  2366. X`09`09`09`09break;
  2367. X`09`09`09`7D
  2368. X`09`09moveSomeone(M.myRatId);
  2369. X`09`7D
  2370. X`09StopWindow();
  2371. X`09exit(0);
  2372. X`7D
  2373. X
  2374. X/*`20
  2375. X`20*`20Clean`20up`20after`20someone`20who`20has`20left.`20Let`20everyone`20els
  2376. Ve`20know,`20too.
  2377. X`20*/
  2378. X
  2379. XratLeft(ratId)
  2380. XRatId`09ratId;
  2381. X`7B
  2382. X`09if`20(R2d2`5BratId`5D.visible`20==`20TRUE)
  2383. X`09`09XORToken(ratId);
  2384. X`09R2d2`5BratId`5D.visible`20=`20FALSE;
  2385. X`09M.ratcb.rats`5BratId`5D.playing`20=`20FALSE;
  2386. X`09ExitPlayer(ratId);
  2387. X`09UpdateScoreCard(ratId);
  2388. X`09sendAllStatus();
  2389. X`09moveSomeone(ratId);
  2390. X`7D
  2391. X
  2392. X/*`20
  2393. X`20*`20See`20if`20the`20guy`20leaving`20has`20vacated`20the`20reserved`20port.
  2394. V`20If`20so,`20try`20to
  2395. X`20*`20find`20someone`20else`20on`20that`20machine`20and`20tell`20him`20to`20m
  2396. Vove`20there.
  2397. X`20*/
  2398. X
  2399. XmoveSomeone(ratId)
  2400. XRatId`09ratId;
  2401. X`7B
  2402. X`09Sockaddr`09hisAddr;
  2403. X`09RatId`09`09newRat;
  2404. X`09RatPacket`09pack;
  2405. X`09RatMove`09`09ratMove;
  2406. X
  2407. X`09hisAddr`20=`20M.ratcb.rats`5BratId`5D.addr;
  2408. X`09if`20(hisAddr.sin_port`20!=`20M.mazePort)
  2409. X`09`09return;
  2410. X
  2411. X`09for`20(newRat`20=`200;`20newRat`20<`20MAXRATS;`20newRat++)`20`7B
  2412. X`09`09if`20(newRat`20==`20ratId)
  2413. X`09`09`09continue;
  2414. X`09`09if`20(M.ratcb.rats`5BnewRat`5D.playing`20==`20FALSE)
  2415. X`09`09`09continue;
  2416. X`09`09if`20(!bcmp(`26M.ratcb.rats`5BnewRat`5D.addr.sin_addr,
  2417. X`09`09`09`20`20`26hisAddr.sin_addr,`20sizeof(hisAddr.sin_addr)))`20`7B
  2418. X`09`09`09pack.type`20=`20RAT_MOVE;
  2419. X`09`09`09ratMove`20=`20(RatMove)`20`26pack.body;
  2420. X`09`09`09ratMove->ratId`20=`20M.ratcb.dukeRat;
  2421. X`09`09`09ConvertOutgoing(`26pack);
  2422. X`09`09`09if`20(sendto(M.theSocket,`20`26pack,`20sizeof(pack),`200,
  2423. X`09`09`09`09`20`20`26M.ratcb.rats`5BnewRat`5D.addr,
  2424. X`09`09`09`09`20`20sizeof(Sockaddr))`20<`200)
  2425. X`09`09`09`09MWError("moveSomeone");
  2426. X
  2427. X`09`09`09/*`20
  2428. X`09`09`09`20*`20If`20I'm`20the`20one`20leaving,`20must`20free`20up`20my`20port
  2429. V.
  2430. X`09`09`09`20*/
  2431. X
  2432. X`09`09`09if`20(ratId`20==`20M.myRatId)
  2433. X#ifdef`20VMS
  2434. X`09`09`09`09socket_close(M.theSocket);
  2435. X#else
  2436. X`09`09`09`09close(M.theSocket);
  2437. X#endif
  2438. X`09`09`09break;
  2439. X`09`09`7D
  2440. X`09`7D
  2441. X`09`09
  2442. X`7D
  2443. X
  2444. X/*`20
  2445. X`20*`20Make`20sure`20nobody`20has`20died`20unnoticed.
  2446. X`20*/
  2447. X
  2448. Xstatic`20Boolean`09`09started`20=`20FALSE;
  2449. Xstruct`20timeval`09waitStart;
  2450. Xstatic`20Boolean`09`09runDoctor`20=`20TRUE;
  2451. X
  2452. Xstatic
  2453. XratDoctor()
  2454. X`7B
  2455. X`09RatId`09ratId,`20nextRatId();
  2456. X`09struct`20timeval`09now;
  2457. X
  2458. X`09if`20(!runDoctor)
  2459. X`09`09return;
  2460. X
  2461. X`09if`20(started`20==`20FALSE)`20`7B
  2462. X`09`09gettimeofday(`26waitStart,`20NULL);
  2463. X`09`09for`20(ratId`20=`200;`20ratId`20<`20MAXRATS;`20ratId++)`20`7B
  2464. X`09`09`09ratHealth`5BratId`5D.count`20=`200;
  2465. X`09`09`09ratHealth`5BratId`5D.send`20=`20FALSE;
  2466. X`09`09`09ratHealth`5BratId`5D.rcvd`20=`20FALSE;
  2467. X`09`09`7D
  2468. X`09`09started`20=`20TRUE;
  2469. X`09`09return;
  2470. X`09`7D`20else`20`7B
  2471. X`09`09gettimeofday(`26now,`20NULL);
  2472. X`09`09if`20((now.tv_sec`20-`20waitStart.tv_sec)`20<`205)
  2473. X`09`09`09return;
  2474. X`09`09for`20(ratId`20=`200;`20ratId`20<`20MAXRATS;`20ratId++)`20`7B
  2475. X`09`09`09if`20((!M.ratcb.rats`5BratId`5D.playing)`20`7C`7C
  2476. X`09`09`09`20`20`20`20(ratId`20==`20M.myRatId))
  2477. X`09`09`09`09continue;
  2478. X`09`09`09if`20(ratHealth`5BratId`5D.rcvd)`20`7B
  2479. X`09`09`09`09ratHealth`5BratId`5D.count`20=`200;
  2480. X`09`09`09`09ratHealth`5BratId`5D.rcvd`20=`20FALSE;
  2481. X`09`09`09`09continue;
  2482. X`09`09`09`7D
  2483. X`09`09`09if`20(++ratHealth`5BratId`5D.count`20<`205)`20`7B
  2484. X`09`09`09`09ratHealth`5BratId`5D.send`20=`20TRUE;
  2485. X`09`09`09`09continue;
  2486. X`09`09`09`7D
  2487. X`09`09`09if`20(M.duke`20`7C`7C
  2488. X`09`09`09`20`20`20`20((M.ratcb.dukeRat`20==`20ratId)`20`26`26
  2489. X`09`09`09`20`20`20`20`20(nextRatId(ratId)`20==`20M.myRatId)))`20`7B
  2490. X`09`09`09`09M.duke`20=`20TRUE;
  2491. X`09`09`09`09M.ratcb.dukeRat`20=`20M.myRatId;
  2492. X`09`09`09`09ratLeft(ratId);
  2493. X`09`09`09`7D
  2494. X`09`09`7D
  2495. X`09`09sendQuery();
  2496. X`09`09gettimeofday(`26waitStart,`20NULL);
  2497. X`09`7D
  2498. X`09
  2499. X`7D
  2500. X
  2501. XRatId
  2502. XnextRatId(ratId)
  2503. XRatId`09ratId;
  2504. X`7B
  2505. X`09RatId`09ixRatId;
  2506. X
  2507. X`09for`20(ixRatId`20=`200;`20ixRatId`20<`20MAXRATS;`20ixRatId++)
  2508. X`09`09if`20(M.ratcb.rats`5BixRatId`5D.playing`20`26`26
  2509. X`09`09`20`20`20`20(ixRatId`20!=`20ratId))
  2510. X`09`09`09return`20ixRatId;
  2511. X`09return`20ixRatId;
  2512. X`7D
  2513. X
  2514. XNewPosition()
  2515. X`7B
  2516. X`09register`09rndCnt`20=`200;
  2517. X
  2518. X`09M.xloc`20=`20M.yloc`20=`200;`09`09/*`20start`20on`20occupied`20square`20*/
  2519. X`09while`20(mp`5BM.xloc`5D.y`5BM.yloc`5D)`20`7B
  2520. X`09`09M.xloc`20=`20random(MAZEXMAX);
  2521. X`09`09M.yloc`20=`20random(MAZEYMAX);
  2522. X`09`09if`20(++rndCnt`20==`20100)`20`7B
  2523. X`09`09`09rndCnt`20=`200;
  2524. X`09`09`09InitRandom();
  2525. X`09`09`7D
  2526. X`09`7D
  2527. X
  2528. X`09/*`20prevent`20a`20blank`20wall`20at`20first`20glimpse`20*/
  2529. X
  2530. X`09if`20(!M.maze`5BM.xloc+1`5D.y`5BM.yloc`5D)`20M.dir`20=`20NORTH;
  2531. X`09if`20(!M.maze`5BM.xloc-1`5D.y`5BM.yloc`5D)`20M.dir`20=`20SOUTH;
  2532. X`09if`20(!M.maze`5BM.xloc`5D.y`5BM.yloc+1`5D)`20M.dir`20=`20EAST;
  2533. X`09if`20(!M.maze`5BM.xloc`5D.y`5BM.yloc-1`5D)`20M.dir`20=`20WEST;
  2534. X
  2535. X`09return;
  2536. X`7D
  2537. X
  2538. X/*`20re-initialize`20the`20maze`20randomization`20vector`20*/
  2539. XInitRandom()
  2540. X`7B
  2541. X`09struct`20timeval`09t;
  2542. X`09struct`20timezone`09tz;
  2543. X`09register`20int`09i;
  2544. X
  2545. X`09gettimeofday(`26t,`20`26tz);
  2546. X`09for`20(i`20=`200;`20i`20<`20VECTORSIZE;`20i++)
  2547. X`09`09M.randomVector`5Bi`5D`20=`20M.randomVector`5Bi`5D`20+`20t.tv_sec`20`26
  2548. V`200xffff;
  2549. X`7D
  2550. X
  2551. Xrandom(limit)
  2552. Xregister`20int`09limit;
  2553. X`7B
  2554. X`09register`20unsigned`20int`09ret;
  2555. X
  2556. X`09ret`20=`20M.randomVector`5Bi1`5D`20=`20M.randomVector`5Bi1`5D`20+`20M.rando
  2557. VmVector`5Bi2`5D;
  2558. X`09if`20(++i1`20>=`20VECTORSIZE)
  2559. X`09`09i1`20=`200;
  2560. X`09if`20(++i2`20>=`20VECTORSIZE)
  2561. X`09`09i2`20=`200;
  2562. X`09return`20ret%limit;
  2563. X`7D
  2564. X
  2565. XMWError(s)
  2566. Xchar`20*s;
  2567. X`7B
  2568. X`09StopWindow();
  2569. X`09fprintf(stderr,`20"MazeWar:`20%s`5Cn",`20s);
  2570. X`09perror("MazeWar");
  2571. X`09exit(-1);
  2572. X`7D
  2573. $ call unpack [.MAZEWAR]MAZEWAR.C;17 1461979702 ""
  2574. $!
  2575. $ create 'f'
  2576. X
  2577. X
  2578. X
  2579. XMAZEWAR(6)`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20
  2580. V`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20MAZEWAR(6
  2581. V)
  2582. X
  2583. X
  2584. XN`08NA`08AM`08ME`08E
  2585. X`20`20`20`20`20MazeWar`20-`20distributed`20rats`20in`20a`20maze
  2586. X
  2587. XS`08SY`08YN`08NT`08TA`08AX`08X
  2588. X`20`20`20`20`20/`08/u`08us`08sr`08r/`08/g`08ga`08am`08me`08es`08s/`08/m`08mw
  2589. V`08w`20`5B`20_`08w_`08i_`08n_`08d_`08o_`08w`20_`08s_`08y_`08s_`08t_`08e_`08m
  2590. V`20_`08o_`08p_`08t_`08i_`08o_`08n_`08s`20`5D
  2591. X
  2592. XD`08DE`08ES`08SC`08CR`08RI`08IP`08PT`08TI`08IO`08ON`08N
  2593. X`20`20`20`20`20This`20`20program`20implements`20the`20age-old`20game`20of`20Ma
  2594. VzeWar.`20`20Maze-
  2595. X`20`20`20`20`20War`20first`20appeared`20at`20MIT`20in`20the`20early`20`201970s
  2596. V,`20`20using`20`20IMLAC
  2597. X`20`20`20`20`20displays`20`20and`20`20the`20`20ArpaNet`20network.`20`20Legend
  2598. V`20has`20it`20that,`20at
  2599. X`20`20`20`20`20one`20point`20during`20that`20period,`20MazeWar`20was`20`20bann
  2600. Ved`20`20by`20`20DARPA
  2601. X`20`20`20`20`20from`20`20the`20ArpaNet`20because`20half`20of`20all`20the`20pac
  2602. Vkets`20in`20a`20given
  2603. X`20`20`20`20`20month`20were`20MazeWar`20packets`20flying`20between`20Stanford
  2604. V`20and`20`20MIT.
  2605. X
  2606. X`20`20`20`20`20MazeWar`20`20appeared`20again`20at`20the`20Xerox`20Palo`20Alto
  2607. V`20Research`20Cen-
  2608. X`20`20`20`20`20ter`20in`20the`20late`201970's`20on`20the`20Alto,`20the`20first
  2609. V`20personal`20`20com-
  2610. X`20`20`20`20`20puter.`20`20`20This`20`20version`20`20has`20subsequently`20been
  2611. V`20ported`20to`20many
  2612. X`20`20`20`20`20personal`20machines,`20and`20forms`20the`20basis`20for`20`20thi
  2613. Vs`20`20Unix`20`20ver-
  2614. X`20`20`20`20`20sion.
  2615. X
  2616. X`20`20`20`20`20_`08M_`08w`20`20attempts`20`20to`20be`20as`20faithful`20to`20th
  2617. Ve`20original`20Alto`20version
  2618. X`20`20`20`20`20as`20possible.`20`20The`20shape`20and`20pictures`20of`20the`20m
  2619. Vaze`20are`20`20as`20`20in
  2620. X`20`20`20`20`20the`20`20original,`20and`20there`20are`20no`20embellishments
  2621. V`20such`20as`20tele-
  2622. X`20`20`20`20`20port`20traps`20or`20robot`20amanuenses.
  2623. X
  2624. XP`08PL`08LA`08AY`08Y
  2625. X`20`20`20`20`20You,`20the`20player,`20are`20a`20rat`20in`20a`20maze,`20and`20t
  2626. Vhe`20`20objective`20`20is
  2627. X`20`20`20`20`20to`20find`20your`20opponents`20and`20shoot`20them`20before`20th
  2628. Vey`20shoot`20you.
  2629. X
  2630. X`20`20`20`20`20Each`20of`20the`20(up`20to`20eight)`20players`20in`20a`20game
  2631. V`20may`20be`20on`20a`20dif-
  2632. X`20`20`20`20`20ferent`20`20host.`20`20`20Upon`20`20startup,`20you`20are`20aske
  2633. Vd`20for`20the`20name`20by
  2634. X`20`20`20`20`20which`20you`20wish`20to`20be`20known`20for`20the`20duration`20o
  2635. Vf`20the`20game,`20and
  2636. X`20`20`20`20`20the`20`20name`20of`20the`20`60`60Duke`20host''.`20`20If`20you
  2637. V`20type`20a`20bare`20carriage
  2638. X`20`20`20`20`20return`20to`20this`20query,`20_`08m_`08w`20will`20find`20a`20ga
  2639. Vme`20by`20broadcasting`20on
  2640. X`20`20`20`20`20the`20`20local`20network,`20and`20join`20any`20game`20it`20find
  2641. Vs.`20`20If`20you`20wish
  2642. X`20`20`20`20`20to`20join`20a`20specific`20game,`20or`20a`20game`20on`20`20anot
  2643. Vher`20`20network,`20`20or
  2644. X`20`20`20`20`20your`20`20network`20doesn't`20support`20broadcasting,`20type
  2645. V`20in`20the`20name
  2646. X`20`20`20`20`20of`20one`20of`20the`20hosts`20involved`20`20in`20`20that`20`20g
  2647. Vame.`20`20`20The`20`20program
  2648. X`20`20`20`20`20_`08m_`08a_`08z_`08e_`08f_`08i_`08n_`08d`20`20will`20`20aid`20
  2649. V`20you`20`20in`20finding`20out`20what`20games`20are`20cur-
  2650. X`20`20`20`20`20rently`20being`20played.
  2651. X
  2652. X`20`20`20`20`20Once`20in`20a`20game,`20you`20are`20`20presented`20`20with`20
  2653. V`20the`20`20game`20`20window.
  2654. X`20`20`20`20`20This`20window`20is`20made`20up`20of`20three`20sections.`20`20Th
  2655. Ve`20upper`20section
  2656. X`20`20`20`20`20is`20a`20perspective`20view`20of`20your`20view`20forward.`20
  2657. V`20By`20pressing`20the
  2658. X`20`20`20`20`20left`20`20or`20`20right`20`20mouse`20`20buttons,`20you`20may
  2659. V`20peek`20to`20the`20left`20or
  2660. X`20`20`20`20`20right`20around`20corners.
  2661. X
  2662. X`20`20`20`20`20The`20middle`20section`20of`20the`20window`20is`20a`20top`20vie
  2663. Vw`20of`20the`20`20maze,
  2664. X`20`20`20`20`20showing`20`20your`20current`20position`20and`20heading`20in`20t
  2665. Vhe`20maze.`20`20You
  2666. X`20`20`20`20`20move`20around`20the`20maze`20by`20using`20the`20following`20key
  2667. Vs:
  2668. X
  2669. X`20`20`20`20`20A`20`20`20`20`20About`20face;`20flip`20end-for-end
  2670. X`20`20`20`20`20S`20`20`20`20`20Turn`2090`20degrees`20left
  2671. X`20`20`20`20`20D`20`20`20`20`20Move`20forward`20one`20cell
  2672. X
  2673. X
  2674. X
  2675. X`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20
  2676. V`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20
  2677. V`20`20`20`20`20`20`20`20`20`20`20`20`20`201
  2678. X
  2679. X
  2680. X
  2681. X
  2682. X
  2683. XMAZEWAR(6)`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20
  2684. V`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20MAZEWAR(6
  2685. V)
  2686. X
  2687. X
  2688. X`20`20`20`20`20F`20`20`20`20`20Turn`2090`20degrees`20right
  2689. X`20`20`20`20`20<space>Move`20backward`20one`20cell
  2690. X`20`20`20`20`20Q`20`20`20`20`20Quit
  2691. X
  2692. X`20`20`20`20`20For`20left-handers,`20there`20are`20equivalents`20on`20the`20nu
  2693. Vmeric`20`20key-
  2694. X`20`20`20`20`20pad.`20`20On`20the`20DEC`20LK201`20keyboard,`20the`20`604',`20
  2695. V`605',`20`606',`20`60,',`20and
  2696. X`20`20`20`20`20right`20cursor`20arrow`20keys`20perform`20the`20equivalent`20op
  2697. Verations.
  2698. X
  2699. X`20`20`20`20`20The`20lower`20section`20of`20the`20window`20shows`20the`20names
  2700. V`20`20and`20`20scores
  2701. X`20`20`20`20`20of`20`20the`20`20other`20`20players`20in`20the`20game.`20`20Whe
  2702. Vn`20you`20sight`20another
  2703. X`20`20`20`20`20rat,`20that`20rat's`20score`20line`20is`20highlighted.`20`20Sho
  2704. Vot`20by`20`20press-
  2705. X`20`20`20`20`20ing`20`20the`20`20middle`20`20mouse`20`20button.`20`20`20When
  2706. V`20you`20are`20shot`20at,`20the
  2707. X`20`20`20`20`20mouse`20cursor`20changes`20from`20a`20rat`20to`20a`20dead`20rat
  2708. V,`20and`20you`20`20have
  2709. X`20`20`20`20`20one`20`20second`20to`20move`20out`20of`20the`20way`20of`20the
  2710. V`20shot`20or`20shoot`20back
  2711. X`20`20`20`20`20or`20both.`20`20A`20shot`20costs`20one`20point;`20`20getting
  2712. V`20`20hit`20`20costs`20`20five
  2713. X`20`20`20`20`20points;`20`20hitting`20someone`20adds`20ten`20points.`20`20When
  2714. V`20you`20are`20hit,
  2715. X`20`20`20`20`20the`20screen`20flashes`20and`20you`20are`20transported`20to`20
  2716. V`20another`20`20sec-
  2717. X`20`20`20`20`20tion`20of`20the`20maze.
  2718. X
  2719. X`20`20`20`20`20If`20your`20window`20system`20supports`20it,`20when`20you`20ico
  2720. Vnify`20the`20game
  2721. X`20`20`20`20`20window,`20it`20will`20let`20you`20know`20when`20someone`20joins
  2722. V`20the`20game`20`20or
  2723. X`20`20`20`20`20shoots`20`20at`20`20you`20(by`20flashing,`20in`20most`20cases).
  2724. V`20`20This`20way,`20you
  2725. X`20`20`20`20`20can`20be`20notified`20whenever`20someone`20else`20is`20interest
  2726. Ved`20in`20wast-
  2727. X`20`20`20`20`20ing`20some`20time,`20by`20always`20leaving`20a`20game`20around.
  2728. V
  2729. X
  2730. XS`08SE`08EE`08E`20A`08AL`08LS`08SO`08O
  2731. X`20`20`20`20`20mazefind(6)
  2732. X
  2733. XA`08AU`08UT`08TH`08HO`08OR`08R
  2734. X`20`20`20`20`20Christopher`20A.`20Kent
  2735. X
  2736. X
  2737. X
  2738. X
  2739. X
  2740. X
  2741. X
  2742. X
  2743. X
  2744. X
  2745. X
  2746. X
  2747. X
  2748. X
  2749. X
  2750. X
  2751. X
  2752. X
  2753. X
  2754. X
  2755. X
  2756. X
  2757. X
  2758. X
  2759. X
  2760. X
  2761. X
  2762. X`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20
  2763. V`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20`20
  2764. V`20`20`20`20`20`20`20`20`20`20`20`20`20`202
  2765. X
  2766. X
  2767. $ call unpack [.MAZEWAR]MAZEWAR.DOC;1 1109228115 ""
  2768. $!
  2769. $ create 'f'
  2770. X/*`20$Header:`20mazewar.h,v`201.7`2088/08/25`2009:59:51`20kent`20Exp`20$`20*/
  2771. X
  2772. X/*`20
  2773. X`20*`20mazewar.h`20-`20Definitions`20for`20MazeWar
  2774. X`20*`20
  2775. X`20*`20Author:`09Christopher`20A.`20Kent
  2776. X`20*`20`09`09Western`20Research`20Laboratory
  2777. X`20*`20`09`09Digital`20Equipment`20Corporation
  2778. X`20*`20Date:`09Wed`20Sep`2024`201986
  2779. X`20*/
  2780. X
  2781. X/***********************************************************
  2782. XCopyright`201986`20by`20Digital`20Equipment`20Corporation,`20Maynard,`20Massac
  2783. Vhusetts,
  2784. X
  2785. 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
  2786. V`20Rights`20Reserved
  2787. X
  2788. XPermission`20to`20use,`20copy,`20modify,`20and`20distribute`20this`20software
  2789. V`20and`20its`20
  2790. Xdocumentation`20for`20any`20purpose`20and`20without`20fee`20is`20hereby`20gran
  2791. Vted,`20
  2792. Xprovided`20that`20the`20above`20copyright`20notice`20appear`20in`20all`20copie
  2793. Vs`20and`20that
  2794. Xboth`20that`20copyright`20notice`20and`20this`20permission`20notice`20appear
  2795. V`20in`20
  2796. Xsupporting`20documentation,`20and`20that`20the`20names`20of`20Digital`20not
  2797. V`20be
  2798. Xused`20in`20advertising`20or`20publicity`20pertaining`20to`20disstribution`20o
  2799. Vf`20the
  2800. Xsoftware`20without`20specific,`20written`20prior`20permission.`20`20
  2801. X
  2802. XDIGITAL`20DISCLAIMS`20ALL`20WARRANTIES`20WITH`20REGARD`20TO`20THIS`20SOFTWARE,
  2803. V`20INCLUDING
  2804. XALL`20IMPLIED`20WARRANTIES`20OF`20MERCHANTABILITY`20AND`20FITNESS,`20IN`20NO
  2805. V`20EVENT`20SHALL
  2806. XDIGITAL`20BE`20LIABLE`20FOR`20ANY`20SPECIAL,`20INDIRECT`20OR`20CONSEQUENTIAL
  2807. V`20DAMAGES`20OR
  2808. XANY`20DAMAGES`20WHATSOEVER`20RESULTING`20FROM`20LOSS`20OF`20USE,`20DATA`20OR
  2809. V`20PROFITS,
  2810. XWHETHER`20IN`20AN`20ACTION`20OF`20CONTRACT,`20NEGLIGENCE`20OR`20OTHER`20TORTIO
  2811. VUS`20ACTION,
  2812. XARISING`20OUT`20OF`20OR`20IN`20CONNECTION`20WITH`20THE`20USE`20OR`20PERFORMANC
  2813. VE`20OF`20THIS
  2814. XSOFTWARE.
  2815. X
  2816. X******************************************************************/
  2817. X
  2818. X/*
  2819. X`20*`20$Log:`09mazewar.h,v`20$
  2820. X`20*`20Revision`201.7`20`2088/08/25`20`2009:59:51`20`20kent
  2821. X`20*`20Copyright.
  2822. X`20*`20
  2823. X`20*`20Revision`201.6`20`2088/08/11`20`2011:37:59`20`20kent
  2824. X`20*`20Fix`20a`20type`20clash`20with`20X11`20include`20files.`20We`20need`20a
  2825. V`20Boolean`20to`20be`20a`20short
  2826. X`20*`20for`20alignment`20purposes,`20but`20X11`20typedefs`20it`20to`20be`20a
  2827. V`20char.`20
  2828. X`20*`20
  2829. X`20*`20Revision`201.5`20`2087/03/31`20`2014:42:32`20`20kent
  2830. X`20*`20Portability`20considerations,`20especially`20byteswapping`20to/from`20t
  2831. Vhe`20net.
  2832. X`20*`20
  2833. X`20*`20Revision`201.4`20`2086/12/03`20`2010:00:54`20`20kent
  2834. X`20*`20Changes`20to`20allow`20multiple`20players`20per`20machine.
  2835. X`20*`20
  2836. X`20*`20Revision`201.3`20`2086/12/01`20`2023:45:53`20`20kent
  2837. X`20*`20Housecleaning`20and`20documentation`20pass.
  2838. X`20*`20
  2839. X`20*`20Revision`201.2`20`2086/12/01`20`2014:47:52`20`20kent
  2840. X`20*`20Changes`20for`20a`20realistic`20implementation`20of`20shooting.
  2841. X`20*`20
  2842. X`20*`20Revision`201.1`20`2086/11/26`20`2016:58:19`20`20kent
  2843. X`20*`20Initial`20revision
  2844. X`20*`20
  2845. X`20*`20Revision`201.1`20`2086/11/26`20`2016:56:33`20`20kent
  2846. X`20*`20Initial`20revision
  2847. X`20*`20
  2848. X`20*/
  2849. X
  2850. X/*`20fundamental`20constants`20*/
  2851. X
  2852. X#ifndef`09TRUE
  2853. X#define`09TRUE`09`091
  2854. X#define`09FALSE`09`090
  2855. X#endif`09TRUE
  2856. X
  2857. X#define`09MAZEXMAX`0932
  2858. X#define`09MAZEYMAX`0916
  2859. X#define`09MAXRATS`09`098
  2860. X#define`09VECTORSIZE`0955
  2861. X#define`09NAMESIZE`0920
  2862. X#define`09NDIRECTION`094
  2863. X#define`09NORTH`09`090
  2864. X#define`09SOUTH`09`091
  2865. X#define`09EAST`09`092
  2866. X#define`09WEST`09`093
  2867. X#define`09NVIEW`09`094
  2868. X#define`09LEFT`09`090
  2869. X#define`09RIGHT`09`091
  2870. X#define`09REAR`09`092
  2871. X#define`09FRONT`09`093
  2872. X
  2873. X/*`20types`20*/
  2874. X
  2875. Xtypedef`09struct`20sockaddr_in`09`09Sockaddr;
  2876. X#define`09Boolean`09short`09`09/*`20don't`20clash`20with`20X11`20toolkit`20*/
  2877. Xtypedef`20struct`20`7BBoolean`09y`5BMAZEYMAX`5D;`7D`09MazeRow;
  2878. Xtypedef`09MazeRow`09`09`09`09MazeType
  2879. X`09`5BMAZEXMAX`5D;
  2880. Xtypedef`09MazeRow`09`09`09`09*MazeTypePtr;
  2881. Xtypedef`09short`09`09`09`09Direction;
  2882. Xtypedef`09struct`20`7Bshort`09x,`20y;`20`7D`09`09XYpoint;
  2883. Xtypedef`09struct`20`7BXYpoint`09p1,`20p2;`7D`09XYpair;
  2884. Xtypedef`09struct`20`7Bshort`09xcor,`20ycor;`7D`09XY;
  2885. X
  2886. Xtypedef`09struct`20`7Bshort`09bits`5B16`5D;`7D`09BitCell;
  2887. X
  2888. Xtypedef`09short`09`09`09`09Loc;
  2889. Xtypedef`09unsigned`20long`09`09`09Score;
  2890. Xtypedef`09char`09`09`09`09RatName
  2891. X`09`5BNAMESIZE`5D;
  2892. Xtypedef`09long`09`09`09`09RatId;
  2893. X
  2894. Xtypedef`09struct`20`7B
  2895. X`09RatId`09ratId;
  2896. X`09Score`09score;
  2897. X`09Loc`09xLoc,`20yLoc;
  2898. X`09Direction`09dir;
  2899. X`7D`09`09`09`09`09AqRatLocation;
  2900. Xtypedef`09AqRatLocation`20*`09`09`09RatLocation;
  2901. X
  2902. Xtypedef`20struct`20`7B
  2903. X`09RatId`09ratId;
  2904. X`09Loc`09xLoc,`20yLoc;
  2905. X`09Direction`09dir;
  2906. X`7D`09`09`09`09`09AqRatKill;
  2907. Xtypedef`09AqRatKill`20*`09`09`09RatKill;
  2908. X
  2909. Xstruct`20_AqRatKillQ`20`7B
  2910. X`09AqRatKill`09thisOne;
  2911. X`09struct`20_AqRatKillQ`09*nextOne;
  2912. X`09struct`20timeval`09shotHits;
  2913. X`7D;
  2914. Xtypedef`20struct`20_AqRatKillQ`09`09AqRatKillQ;
  2915. Xtypedef`09AqRatKillQ`20*`09`09`09RatKillQ_t;
  2916. X
  2917. Xtypedef`09struct`20`7B
  2918. X`09RatId`09ratId;
  2919. X`09RatId`09killedBy;
  2920. X`7D`09`09`09`09`09AqRatDead;
  2921. Xtypedef`09AqRatDead`20*`09`09`09RatDead;
  2922. X
  2923. Xtypedef`09struct`20`7B
  2924. X`09Sockaddr`09addr;
  2925. X`09short`09`09pass;
  2926. X`09Loc`09`09xLoc,`20yLoc;
  2927. X`09Direction`09dir;
  2928. X`09RatName`09`09name;
  2929. X`7D`09`09`09`09`09AqRatNew;
  2930. Xtypedef`09AqRatNew`20*`09`09`09RatNew;
  2931. X
  2932. Xtypedef`09struct`20`7B
  2933. X`09RatId`09ratId;
  2934. X`7D`09`09`09`09`09AqRatGone;
  2935. Xtypedef`09AqRatGone`20*`09`09`09RatGone;
  2936. X
  2937. Xtypedef`09struct`20`7B
  2938. X`09RatId`09ratId;
  2939. X`7D`09`09`09`09`09AqRatQuery;
  2940. Xtypedef`09AqRatQuery`20*`09`09`09RatQuery;
  2941. X
  2942. Xtypedef`20struct`20`7B
  2943. X`09RatId`09ratId;
  2944. X`7D`09`09`09`09`09AqRatAlive;
  2945. Xtypedef`09AqRatAlive`20*`09`09`09RatAlive;
  2946. X
  2947. Xtypedef`20struct`20`7B
  2948. X`09RatId`09ratId;
  2949. X`7D`09`09`09`09`09AqRatMove;
  2950. Xtypedef`09AqRatMove`20*`09`09`09RatMove;
  2951. X
  2952. Xtypedef`09struct`20`7B
  2953. X`09Sockaddr`09addr;
  2954. X`09Score`09`09score;
  2955. X`09Boolean`09`09playing;
  2956. X`09Loc`09`09xLoc,`20yLoc;
  2957. X`09Direction`09dir;
  2958. X`09RatName`09`09name;
  2959. X`7D`09`09`09`09`09RatObject;
  2960. Xtypedef`09RatObject`20*`09`09`09RatInfo;
  2961. X
  2962. Xtypedef`09struct`20`7B
  2963. X`09RatId`09`09dukeRat;
  2964. X`09RatObject`09rats`5BMAXRATS`5D;
  2965. X`7D`09`09`09`09`09RatCb;
  2966. Xtypedef`09RatCb`20*`09`09`09`09RatStatus;
  2967. X
  2968. Xtypedef`09long`09`09`09`09TokenId;
  2969. X
  2970. Xtypedef`09struct`20`7B
  2971. X`09Boolean`09visible;
  2972. X`09Loc`09x,`20y;
  2973. X`09short`09distance;
  2974. X`09TokenId`09tokenId;
  2975. X`7D`09`09`09`09`09RatAppearance;
  2976. Xtypedef`09RatAppearance`09`09`09R2d2_t
  2977. X`09`5BMAXRATS`5D;
  2978. Xtypedef`09RatAppearance`20*`09`09`09RatLook;
  2979. X
  2980. Xtypedef`09struct`20`7BTokenId`09t`5BNDIRECTION`5D;`7D`09RelativeTokens
  2981. X`09`5BNDIRECTION`5D;
  2982. X
  2983. Xtypedef`09struct`20`7B
  2984. X`09Boolean`09send;
  2985. X`09Boolean`09rcvd;
  2986. X`09short`09count;
  2987. X`7D`09`09`09`09`09RatNetHealth;
  2988. Xtypedef`09RatNetHealth`09`09`09RatHealth
  2989. X`09`5BMAXRATS`5D;
  2990. X
  2991. X/*`20network`20stuff`20*/
  2992. X
  2993. X#define`09MAZEPORT`091111
  2994. X#define`09MAZESERVICE`09"mazewar"
  2995. X
  2996. X#define`09RAT_LOCATION`091
  2997. X#define`09RAT_KILL`092
  2998. X#define`09RAT_DEAD`093
  2999. X#define`09RAT_STATUS`094
  3000. X#define`09RAT_NEW`09`095
  3001. X#define`09RAT_GOING`096
  3002. X#define`09RAT_QUERY`097
  3003. X#define`09RAT_ALIVE`098
  3004. X#define`09RAT_SURVEY`099
  3005. X#define`09RAT_MOVE`0910
  3006. X#define`09RAT_PASSWORD`09032610
  3007. X
  3008. Xtypedef`09struct`20`7B
  3009. X`09long`09type;
  3010. X`09RatCb`09body;`09`09`09/*`20largest`20type`20above`20*/
  3011. +-+-+-+-+-+-+-+-  END  OF PART 4 +-+-+-+-+-+-+-+-
  3012.