home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3200 < prev    next >
Encoding:
Internet Message Format  |  1991-04-18  |  47.0 KB

  1. From: xanthian@zorch.SF-Bay.ORG (Kent Paul Dolan)
  2. Newsgroups: rec.games.programmer,alt.sources,alt.sources.amiga
  3. Subject: townmaze part 01/04
  4. Message-ID: <1991Apr18.034540.7109@zorch.SF-Bay.ORG>
  5. Date: 18 Apr 91 03:45:40 GMT
  6.  
  7.  
  8. Archive-name: townmaze/part01
  9.  
  10. Sorry to be so slow at this, but enough folks asked for it I thought
  11. I'd better go ahead and clean up the hacked up mess it began as.  It
  12. now compiles, with only make file changes, on an ANSI C and an old
  13. C compiler on two different architectures/OSs, so perhaps most of the
  14. portability problems will be small ones.  No longer a slave to #defines,
  15. it now has 8 optional command line parameters, malloc()s its work space,
  16. frees it on exit(), and otherwise behaves itself.  It's also grown huge,
  17. from 30K when it first worked as one monolithic file to around 170K now,
  18. aided and abetted by over 50K of documentation, and lots of overhead
  19. from make files and splitting the files out and putting in prototypes
  20. and such stuff.  Enough whining; give this kid a job!  An excerpt from
  21. the README file follows, and then part one of the shar.  This is a
  22. vanilla cshar makekit production (thanks as always to Rich Salz) in four
  23. parts.
  24.  
  25. Kent, the man from xanth.
  26. <xanthian@Zorch.SF-Bay.ORG> <xanthian@well.sf.ca.us>
  27.  
  28.  
  29. Townmaze -- A Program to Design "Bard's Tale I"-Style City Mazes
  30.  
  31. Copyright 1991 by Kent Paul Dolan, Mountain View, CA, USA 94039-0755
  32.  
  33. This program was written in response to a request in USENet newsgroup
  34. rec.games.programmer for "code that designs a town-shaped maze like the
  35. town Bard's Tale I uses"; you be the judge how well it does; I'm quite
  36. proud of the result. The goal is not a great "pencil and paper" maze,
  37. but instead a fun town for a 3D dungeon crawl game to incorporate.
  38. Here's a tiny (7/64 the size of the BT-I town) example output, big ones
  39. look better:
  40.  
  41. ht 15 wd 33 gates 8 left 1 courts 4 unused 2 straight 950 seed 113181
  42. #################################
  43. ### | | # | | # | | # | # # # ###
  44. ##### ##### ##### ##### #-#-#-###
  45. # |   | # | | #   | # #       # #
  46. ###-# ##### ### #####-# ###   #-#
  47. # # # | # |     | # |   | #     #
  48. #-### ####### #-####### ###-###-#
  49. |     | ### | # ### # | # # # # #
  50. #-### ####### #####-### #-###-###
  51. # # #   # #     # |           | #
  52. ###-#   #-#     ###       ### ###
  53. # |                       | # | #
  54. ###-### #-#-#-#-#-#-#-#-# ###-###
  55. ### # | # # # # # # # # # | # ###
  56. #################################
  57.  
  58. There are now _lots_ of command line parameters; (continued in README file).
  59.  
  60. #! /bin/sh
  61. # This is a shell archive.  Remove anything before this line, then unpack
  62. # it by saving it into a file and typing "sh file".  To overwrite existing
  63. # files, type "sh file -c".  You can also feed this as standard input via
  64. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  65. # will see the following message at the end:
  66. #        "End of archive 1 (of 4)."
  67. # Contents:  MANIFEST README cleanupmap.c closedoors.c closegates.c
  68. #   filllist.c fillmaze.c finishalleys.c freespace.c interiorcell.c
  69. #   makecourts.c makegates.c makespace.c movefromto.c nhbrexists.c
  70. #   nhbris.c showdbmaze.c showlistdet.c showlistsum.c showmaze.c
  71. #   townmain.c townmaze.with usage.c
  72. # Wrapped by xanthian@zorch on Wed Apr 17 20:34:37 1991
  73. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  74. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  75.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  76. else
  77. echo shar: Extracting \"'MANIFEST'\" \(1106 characters\)
  78. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  79. X   File Name        Archive #    Description
  80. X-----------------------------------------------------------
  81. X MANIFEST                   1    This shipping list
  82. X README                     1    
  83. X cleanupmap.c               1    
  84. X closedoors.c               1    
  85. X closegates.c               1    
  86. X connectst.c                2    
  87. X filllist.c                 1    
  88. X fillmaze.c                 1    
  89. X finishalleys.c             1    
  90. X freespace.c                1    
  91. X getargs.c                  2    
  92. X interiorcell.c             1    
  93. X makecourts.c               1    
  94. X makegates.c                1    
  95. X makespace.c                1    
  96. X makestreet.c               3    
  97. X makeunused.c               2    
  98. X movefromto.c               1    
  99. X nhbrexists.c               1    
  100. X nhbris.c                   1    
  101. X showdbmaze.c               1    
  102. X showlistdet.c              1    
  103. X showlistsum.c              1    
  104. X showmaze.c                 1    
  105. X townmain.c                 1    
  106. X townmaze.h                 2    
  107. X townmaze.lmk               2    
  108. X townmaze.with              1    
  109. X townpgmr.doc               4    
  110. X townproto.h                2    
  111. X townuser.doc               2    
  112. X usage.c                    1    
  113. END_OF_FILE
  114. if test 1106 -ne `wc -c <'MANIFEST'`; then
  115.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  116. fi
  117. # end of 'MANIFEST'
  118. fi
  119. if test -f 'README' -a "${1}" != "-c" ; then 
  120.   echo shar: Will not clobber existing file \"'README'\"
  121. else
  122. echo shar: Extracting \"'README'\" \(3940 characters\)
  123. sed "s/^X//" >'README' <<'END_OF_FILE'
  124. XTownmaze -- A Program to Design "Bard's Tale I"-Style City Mazes
  125. X
  126. XCopyright 1991 by Kent Paul Dolan, Mountain View, CA, USA 94039-0755
  127. X
  128. XThis program was written in response to a request in USENet newsgroup
  129. Xrec.games.programmer for "code that designs a town-shaped maze like the
  130. Xtown Bard's Tale I uses"; you be the judge how well it does; I'm quite
  131. Xproud of the result. The goal is not a great "pencil and paper" maze,
  132. Xbut instead a fun town for a 3D dungeon crawl game to incorporate.
  133. XHere's a tiny (7/64 the size of the BT-I town) example output, big ones
  134. Xlook better:
  135. X
  136. Xht 15 wd 33 gates 8 left 1 courts 4 unused 2 straight 950 seed 113181
  137. X#################################
  138. X### | | # | | # | | # | # # # ###
  139. X##### ##### ##### ##### #-#-#-###
  140. X# |   | # | | #   | # #       # #
  141. X###-# ##### ### #####-# ###   #-#
  142. X# # # | # |     | # |   | #     #
  143. X#-### ####### #-####### ###-###-#
  144. X|     | ### | # ### # | # # # # #
  145. X#-### ####### #####-### #-###-###
  146. X# # #   # #     # |           | #
  147. X###-#   #-#     ###       ### ###
  148. X# |                       | # | #
  149. X###-### #-#-#-#-#-#-#-#-# ###-###
  150. X### # | # # # # # # # # # | # ###
  151. X#################################
  152. X
  153. XThere are now _lots_ of command line parameters; you can choose the maze
  154. Xheight in characters, the maze width in characters, number of edge
  155. X"gate" street starting positions in the start of the maze design, the
  156. Xnumber of these gates that survive in the finished maze, the number of
  157. Xinner "courtyard" street starting positions in the start of the maze
  158. Xdesign, the number of unused cells in the interior to provide more
  159. Xcomplex branching in the building nets, how hard the program tries to
  160. Xmake the streets run straight, and you may override the clock seed of
  161. Xthe random number generator with a forced seed, to get a repeat of an
  162. Xespecially nice maze that flashed by while you weren't saving the
  163. Xoutput.
  164. X
  165. XThings to try: no gates, no courtyards, lots of gates, lots of
  166. Xcourtyards, straightnesses of 0, 250, 500, 750, 950, 980, 996, a few
  167. Xunused cells to make four way branch points.
  168. X
  169. XYou can make as big a maze as your machine has memory to hold; the maze
  170. Xelements are dynamically allocated from free memory, and freed before
  171. Xthe program exits. The mazes get pretty spectacular several pages long,
  172. Xand need to be at least a full screen to see much of the "town" effect
  173. Xat all.
  174. X
  175. XThat much stuff made the command line pretty busy, so things like
  176. Xdebugging are still controlled by #defines in the townmaze.h file.
  177. X
  178. XFor reasons having to do with Lattice C use, one of the two places I
  179. Xwrote this, the makefile is that thing called "townmaze.lmk"; at least
  180. Xon my BSD 4.3 Unix system, "make -f townmaze.lmk" works.  You may need
  181. Xto edit the makefile a little to work on your system.
  182. X
  183. XFor compiling on the Amiga, make the indicated edits.  Due to the short
  184. Xcommand line allowed by AmigaOS, the blink command must run using the
  185. Xauxiliary command input file townmaze.with.
  186. X
  187. XOne big gotcha for porting to various systems is the name of the good
  188. Xrandom number generator; if you work on a system that uses the drand48
  189. Xfamily instead of random() and srandom(), you'll want your compiles to
  190. Xhave RAND48 defined; see the townmaze.lmk file for an example of how
  191. Xthat works under Lattice C. 
  192. X
  193. XWhen you have the program built, "townmaze help" will get you a usage
  194. Xdisplay.  You may also want to read the townuser.doc and townpgmr.doc
  195. Xfiles for more information about the program for users and programmers
  196. Xrespectively.
  197. X
  198. XAny non-commercial use of this code is permitted, in whole or in part;
  199. Xcredit to the author is requested but not demanded. Commercial use may
  200. Xbe arranged with the author for little or no fee. The primary reason for
  201. Xthe copyright is to keep some yokel from patenting the algorithms
  202. Xcontained herein and spoiling programming for the rest of us.
  203. X
  204. XThis program is for fun; you use it at your own risk, of course.
  205. X
  206. XKent, the man from xanth.
  207. X<xanthian@Zorch.SF-Bay.ORG> <xanthian@well.sf.ca.us>
  208. END_OF_FILE
  209. if test 3940 -ne `wc -c <'README'`; then
  210.     echo shar: \"'README'\" unpacked with wrong size!
  211. fi
  212. # end of 'README'
  213. fi
  214. if test -f 'cleanupmap.c' -a "${1}" != "-c" ; then 
  215.   echo shar: Will not clobber existing file \"'cleanupmap.c'\"
  216. else
  217. echo shar: Extracting \"'cleanupmap.c'\" \(937 characters\)
  218. sed "s/^X//" >'cleanupmap.c' <<'END_OF_FILE'
  219. X/*
  220. X** cleanupmap.c  Copyright 1991 Kent Paul Dolan,
  221. X**               Mountain View, CA, USA 94039-0755
  222. X**
  223. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  224. X** May be freely used or modified in any non-commercial work.  Copyrighted
  225. X** only to prevent patenting by someone else.
  226. X*/
  227. X
  228. X#include <stdio.h>
  229. X#include "townmaze.h"
  230. X#include "townproto.h"
  231. X
  232. X#ifdef __STDC__
  233. Xvoid cleanupmap()
  234. X#else
  235. Xint cleanupmap()
  236. X#endif
  237. X{
  238. X
  239. X/*
  240. X** Isolated "posts" of wall segments are left by the normal map making
  241. X** process; clean them up to make nice open courtyards.
  242. X*/
  243. X
  244. X  int i, j;
  245. X
  246. X#if PROGRESS
  247. X  fprintf(stderr,"Clean up map ");
  248. X#endif
  249. X
  250. X  for (i = 4; i < (mazeheight - 4); i += 2)
  251. X    for (j = 4; j < (mazewidth - 4); j += 2)
  252. X      if (   (cmaze[i-1][j] == BLANK)
  253. X          && (cmaze[i][j+1] == BLANK)
  254. X          && (cmaze[i+1][j] == BLANK)
  255. X          && (cmaze[i][j-1] == BLANK)
  256. X         )
  257. X        cmaze[i][j] = BLANK;
  258. X  return;
  259. X
  260. X}
  261. END_OF_FILE
  262. if test 937 -ne `wc -c <'cleanupmap.c'`; then
  263.     echo shar: \"'cleanupmap.c'\" unpacked with wrong size!
  264. fi
  265. # end of 'cleanupmap.c'
  266. fi
  267. if test -f 'closedoors.c' -a "${1}" != "-c" ; then 
  268.   echo shar: Will not clobber existing file \"'closedoors.c'\"
  269. else
  270. echo shar: Extracting \"'closedoors.c'\" \(1887 characters\)
  271. sed "s/^X//" >'closedoors.c' <<'END_OF_FILE'
  272. X/*
  273. X** closedoors.c  Copyright 1991 Kent Paul Dolan,
  274. X**               Mountain View, CA, USA 94039-0755
  275. X**
  276. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  277. X** May be freely used or modified in any non-commercial work.  Copyrighted
  278. X** only to prevent patenting by someone else.
  279. X*/
  280. X
  281. X#include <stdio.h>
  282. X#include "townmaze.h"
  283. X#include "townproto.h"
  284. X
  285. X#ifdef __STDC__
  286. Xvoid closedoors()
  287. X#else
  288. Xint closedoors()
  289. X#endif
  290. X{
  291. X
  292. X/*
  293. X** The map as built so far has far too many doors per room.  Close all
  294. X** but one door of each room to make a "Bard's Tale I"-like maze.
  295. X*/
  296. X
  297. X  int deadwalk;  /* nothing interesting left but the dead cells */
  298. X  int doorct, whichdoor;
  299. X  int celli, cellj;
  300. X
  301. X#if PROGRESS
  302. X  fprintf(stderr,"Close Doors ");
  303. X#endif
  304. X
  305. X  deadwalk = dead;
  306. X
  307. X  while (deadwalk != NOPOINTER)
  308. X  {
  309. X
  310. X    celli = deadwalk/(mazewidth/2);
  311. X    cellj = deadwalk%(mazewidth/2);
  312. X
  313. X    celli = (2*celli) + 1;
  314. X    cellj = (2*cellj) + 1;
  315. X
  316. X    doorct = 0;
  317. X    if (cmaze[celli - 1][cellj] == HDOOR) doorct++;
  318. X    if (cmaze[celli][cellj + 1] == VDOOR) doorct++;
  319. X    if (cmaze[celli + 1][cellj] == HDOOR) doorct++;
  320. X    if (cmaze[celli][cellj - 1] == VDOOR) doorct++;
  321. X
  322. X    if ( doorct > 1 )
  323. X    {
  324. X      whichdoor = RANDOM()%doorct; /* keep this one */
  325. X      doorct = 0;
  326. X      if (cmaze[celli - 1][cellj] == HDOOR)
  327. X      {
  328. X        if (doorct != whichdoor) cmaze[celli - 1][cellj] = WALL;
  329. X        doorct++;
  330. X      }
  331. X      if (cmaze[celli][cellj + 1] == VDOOR)
  332. X      {
  333. X        if (doorct != whichdoor) cmaze[celli][cellj + 1] = WALL;
  334. X        doorct++;
  335. X      }
  336. X      if (cmaze[celli + 1][cellj] == HDOOR)
  337. X      {
  338. X        if (doorct != whichdoor) cmaze[celli + 1][cellj] = WALL;
  339. X        doorct++;
  340. X      }
  341. X      if (cmaze[celli][cellj - 1] == VDOOR)
  342. X      {
  343. X        if (doorct != whichdoor) cmaze[celli][cellj - 1] = WALL;
  344. X        doorct++;
  345. X      }
  346. X    }
  347. X    deadwalk = statlist[deadwalk].next;
  348. X  }
  349. X}
  350. END_OF_FILE
  351. if test 1887 -ne `wc -c <'closedoors.c'`; then
  352.     echo shar: \"'closedoors.c'\" unpacked with wrong size!
  353. fi
  354. # end of 'closedoors.c'
  355. fi
  356. if test -f 'closegates.c' -a "${1}" != "-c" ; then 
  357.   echo shar: Will not clobber existing file \"'closegates.c'\"
  358. else
  359. echo shar: Extracting \"'closegates.c'\" \(2275 characters\)
  360. sed "s/^X//" >'closegates.c' <<'END_OF_FILE'
  361. X/*
  362. X** closegates.c  Copyright 1991 Kent Paul Dolan,
  363. X**               Mountain View, CA, USA 94039-0755
  364. X**
  365. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  366. X** May be freely used or modified in any non-commercial work.  Copyrighted
  367. X** only to prevent patenting by someone else.
  368. X*/
  369. X
  370. X#include <stdio.h>
  371. X#include "townmaze.h"
  372. X#include "townproto.h"
  373. X
  374. X#ifdef __STDC__
  375. Xvoid closegates()
  376. X#else
  377. Xint closegates()
  378. X#endif
  379. X{
  380. X  int gatesleft;
  381. X  int chosengate;
  382. X  int foundgate;
  383. X  int gatewalk;
  384. X  int possiblegates;
  385. X
  386. X  int mazei, mazej;
  387. X
  388. X#if PROGRESS
  389. X  fprintf(stderr,"Close Gates ");
  390. X#endif
  391. X
  392. X  if (mazegates <= leftgates) return;
  393. X
  394. X  gatesleft = mazegates;
  395. X
  396. X  possiblegates = (mazeheight-1) + (mazewidth-1);
  397. X
  398. X/*
  399. X**  fprintf(stderr,
  400. X**    "\nmazegates %d leftgates %d gatesleft %d possiblegates %d\n",
  401. X**    mazegates,leftgates,gatesleft,possiblegates);
  402. X*/
  403. X
  404. X  while (gatesleft > leftgates)
  405. X  {
  406. X    chosengate = RANDOM()%gatesleft;
  407. X
  408. X    foundgate = 0;
  409. X
  410. X    for (gatewalk = 0; gatewalk < possiblegates; gatewalk++)
  411. X    {
  412. X      if (gatewalk < (mazewidth-1)/2)
  413. X      {
  414. X        mazei = 0;
  415. X        mazej = 2 * gatewalk + 1;
  416. X      }
  417. X      else
  418. X        if (gatewalk < ((mazewidth-1)/2 + (mazeheight-1)/2))
  419. X        {
  420. X          mazei = 2 * (gatewalk - (mazewidth-1)/2) + 1;
  421. X          mazej = mazewidth-1;
  422. X        }
  423. X        else
  424. X          if (gatewalk < ((mazewidth-1) + (mazeheight-1)/2))
  425. X          {
  426. X            mazei = mazeheight-1;
  427. X            mazej = 2 * (((mazewidth-1)/2)-
  428. X                    (gatewalk-((mazewidth-1)/2 + (mazeheight-1)/2))) + 1;
  429. X          }
  430. X          else
  431. X          {
  432. X            mazei = 2 * (((mazeheight-1)/2)-
  433. X                    (gatewalk-((mazewidth-1) + (mazeheight-1)/2))) + 1;
  434. X            mazej = 0;
  435. X          }
  436. X
  437. X/*
  438. X**      fprintf(stderr,
  439. X**              "gatesleft %d chosengate %d foundgate %d gatewalk %d",
  440. X**              gatesleft,chosengate,foundgate,gatewalk);
  441. X**      fprintf(sdterr," mazei %d mazej %d %c\n",
  442. X**              mazei,mazej, cmaze[mazei][mazej]);
  443. X*/
  444. X
  445. X      if ((cmaze[mazei][mazej] == VDOOR) || (cmaze[mazei][mazej] == HDOOR))
  446. X        if (foundgate < chosengate)
  447. X          foundgate++;
  448. X        else
  449. X        {
  450. X          cmaze[mazei][mazej] = WALL;
  451. X          gatesleft--;
  452. X          break;
  453. X        }
  454. X    }
  455. X  }
  456. X  return;
  457. X}
  458. END_OF_FILE
  459. if test 2275 -ne `wc -c <'closegates.c'`; then
  460.     echo shar: \"'closegates.c'\" unpacked with wrong size!
  461. fi
  462. # end of 'closegates.c'
  463. fi
  464. if test -f 'filllist.c' -a "${1}" != "-c" ; then 
  465.   echo shar: Will not clobber existing file \"'filllist.c'\"
  466. else
  467. echo shar: Extracting \"'filllist.c'\" \(1622 characters\)
  468. sed "s/^X//" >'filllist.c' <<'END_OF_FILE'
  469. X/*
  470. X** filllist.c  Copyright 1991 Kent Paul Dolan,
  471. X**             Mountain View, CA, USA 94039-0755
  472. X**
  473. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  474. X** May be freely used or modified in any non-commercial work.  Copyrighted
  475. X** only to prevent patenting by someone else.
  476. X*/
  477. X
  478. X#include <stdio.h>
  479. X#include "townmaze.h"
  480. X#include "townproto.h"
  481. X
  482. X#ifdef __STDC__
  483. Xvoid filllist()
  484. X#else
  485. Xint filllist()
  486. X#endif
  487. X{
  488. X  int i;
  489. X
  490. X#if PROGRESS
  491. X  fprintf(stderr,"Fill list ");
  492. X#endif
  493. X
  494. X
  495. X/*
  496. X** Everything starts in the isolated list; the others start empty.
  497. X*/
  498. X
  499. X  isolated = 0;
  500. X  live     = NOPOINTER;
  501. X  dead     = NOPOINTER;
  502. X  street   = NOPOINTER;
  503. X  unused   = NOPOINTER;
  504. X
  505. X  for (i = 0; i < listsize  - 1; i++)
  506. X    statlist[i].next = i+1;
  507. X  statlist[listsize -1].next = NOPOINTER;
  508. X  for (i = 1; i < listsize; i++)
  509. X    statlist[i].prev = i-1;
  510. X  statlist[0].prev = NOPOINTER;
  511. X  for (i = 0; i < listsize; i++)
  512. X  {
  513. X    statlist[i].status = ISOLATED;
  514. X    statlist[i].streetnum = -1;
  515. X    statlist[i].streetdir = -1;
  516. X  }
  517. X
  518. X  isolatedct = listsize;
  519. X  livect     = 0;
  520. X  deadct     = 0;
  521. X  streetct   = 0;
  522. X  unusedct   = 0;
  523. X
  524. X/*
  525. X** Corner cells are too hard to use; get them off the list.
  526. X*/
  527. X
  528. X  movefromto(&isolated,&isolatedct,&unused,&unusedct,UNUSED,0);
  529. X  movefromto(&isolated,&isolatedct,&unused,&unusedct,UNUSED,
  530. X             (mazewidth/2) - 1);
  531. X  movefromto(&isolated,&isolatedct,&unused,&unusedct,UNUSED,
  532. X             listsize-(mazewidth/2));
  533. X  movefromto(&isolated,&isolatedct,&unused,&unusedct,UNUSED,listsize - 1);
  534. X
  535. X/*
  536. X** There are no streets yet, so the streetnumct is zero too.
  537. X*/
  538. X
  539. X  streetnumct = 0;
  540. X
  541. X  return;
  542. X}
  543. END_OF_FILE
  544. if test 1622 -ne `wc -c <'filllist.c'`; then
  545.     echo shar: \"'filllist.c'\" unpacked with wrong size!
  546. fi
  547. # end of 'filllist.c'
  548. fi
  549. if test -f 'fillmaze.c' -a "${1}" != "-c" ; then 
  550.   echo shar: Will not clobber existing file \"'fillmaze.c'\"
  551. else
  552. echo shar: Extracting \"'fillmaze.c'\" \(1358 characters\)
  553. sed "s/^X//" >'fillmaze.c' <<'END_OF_FILE'
  554. X/*
  555. X** fillmaze.c  Copyright 1991 Kent Paul Dolan,
  556. X**             Mountain View, CA, USA 94039-0755
  557. X**
  558. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  559. X** May be freely used or modified in any non-commercial work.  Copyrighted
  560. X** only to prevent patenting by someone else.
  561. X*/
  562. X
  563. X#include <stdio.h>
  564. X#include "townmaze.h"
  565. X#include "townproto.h"
  566. X
  567. X#ifdef __STDC__
  568. Xvoid fillmaze()
  569. X#else
  570. Xint fillmaze()
  571. X#endif
  572. X{
  573. X  int i, j;
  574. X
  575. X#if PROGRESS
  576. X  fprintf(stderr,"Fill maze ");
  577. X#endif
  578. X
  579. X/*
  580. X** Fill maze with "wall" characters and "blank" characters,
  581. X** so that entire maze starts out as doorless rooms with walls
  582. X** between.
  583. X*/
  584. X
  585. X  for (i = 0; i < mazeheight; i++)
  586. X    for (j = 0; j < mazewidth; j++)
  587. X      switch (((i%2)<<1) + (j%2))
  588. X      {
  589. X      case 0:
  590. X        cmaze[i][j] = WALL;
  591. X        break;
  592. X      case 1:
  593. X        cmaze[i][j] = WALL;
  594. X        break;
  595. X      case 2:
  596. X        cmaze[i][j] = WALL;
  597. X        break;
  598. X      case 3:
  599. X        cmaze[i][j] = BLANK;
  600. X        break;
  601. X      default:
  602. X        fprintf(stderr,"failure in maze fill section\n");
  603. X        freespace();
  604. X        exit(1);
  605. X      }
  606. X/*
  607. X** The corner cells are too hard to use, so nuke them in the drawing.
  608. X*/
  609. X
  610. X  cmaze[1][1]                 = WALL;
  611. X  cmaze[1][mazewidth - 2]         = WALL;
  612. X  cmaze[mazeheight - 2][1]        = WALL;
  613. X  cmaze[mazeheight -2][mazewidth - 2] = WALL;
  614. X
  615. X  return;
  616. X}
  617. END_OF_FILE
  618. if test 1358 -ne `wc -c <'fillmaze.c'`; then
  619.     echo shar: \"'fillmaze.c'\" unpacked with wrong size!
  620. fi
  621. # end of 'fillmaze.c'
  622. fi
  623. if test -f 'finishalleys.c' -a "${1}" != "-c" ; then 
  624.   echo shar: Will not clobber existing file \"'finishalleys.c'\"
  625. else
  626. echo shar: Extracting \"'finishalleys.c'\" \(1589 characters\)
  627. sed "s/^X//" >'finishalleys.c' <<'END_OF_FILE'
  628. X/*
  629. X** finishalleys.c  Copyright 1991 Kent Paul Dolan,
  630. X**                 Mountain View, CA, USA 94039-0755
  631. X**
  632. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  633. X** May be freely used or modified in any non-commercial work.  Copyrighted
  634. X** only to prevent patenting by someone else.
  635. X*/
  636. X
  637. X#include <stdio.h>
  638. X#include "townmaze.h"
  639. X#include "townproto.h"
  640. X
  641. X#ifdef __STDC__
  642. Xvoid finishalleys()
  643. X#else
  644. Xint finishalleys()
  645. X#endif
  646. X{
  647. X
  648. X  int i, nhbrid;
  649. X  int livewalk, targetcell;
  650. X
  651. X#if PROGRESS
  652. X  if (livect > 0) fprintf(stderr,"Alleys ");
  653. X#endif
  654. X
  655. X  while(livect > 0)
  656. X  {
  657. X    targetcell = RANDOM()%livect;
  658. X    livewalk = live;
  659. X    for (i = 0; i < (targetcell - 1); i++)
  660. X      if (livewalk == NOPOINTER)
  661. X      {
  662. X        fprintf(stderr,"live list too short in finishalleys\n");
  663. X        showdebugmaze();
  664. X        freespace();
  665. X        exit(1);
  666. X      }
  667. X      else
  668. X      {
  669. X        livewalk = statlist[livewalk].next;
  670. X      }
  671. X/*
  672. X** Since this is a live cell, it is supposed to have a street cell
  673. X** neighbor; find one and adopt its street number.  If directions
  674. X** are implemented, then this has to be expanded to pick a random
  675. X** neighbor street fairly and adopt its number and direction.
  676. X** [Done in makestreet(), enabled by the "-1" last parameter.]
  677. X*/
  678. X    for (nhbrid = 0; nhbrid < 4; nhbrid++)
  679. X      if (nhbrexists(livewalk,nhbrid))
  680. X        if (statlist[nhbris(livewalk,nhbrid)].status == STREET)
  681. X        {
  682. X          makestreet(livewalk,
  683. X                     statlist[nhbris(livewalk,nhbrid)].streetnum,-1);
  684. X          break;
  685. X        }
  686. X  }
  687. X/*  fprintf(stderr,"\n"); */
  688. X  return;
  689. X}
  690. END_OF_FILE
  691. if test 1589 -ne `wc -c <'finishalleys.c'`; then
  692.     echo shar: \"'finishalleys.c'\" unpacked with wrong size!
  693. fi
  694. # end of 'finishalleys.c'
  695. fi
  696. if test -f 'freespace.c' -a "${1}" != "-c" ; then 
  697.   echo shar: Will not clobber existing file \"'freespace.c'\"
  698. else
  699. echo shar: Extracting \"'freespace.c'\" \(980 characters\)
  700. sed "s/^X//" >'freespace.c' <<'END_OF_FILE'
  701. X/*
  702. X** freespace.c  Copyright 1991 Kent Paul Dolan,
  703. X**              Mountain View, CA, USA 94039-0755
  704. X**
  705. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  706. X** May be freely used or modified in any non-commercial work.  Copyrighted
  707. X** only to prevent patenting by someone else.
  708. X*/
  709. X
  710. X#include <stdio.h>
  711. X#include "townmaze.h"
  712. X#include "townproto.h"
  713. X
  714. X#ifdef __STDC__
  715. Xvoid freespace()
  716. X#else
  717. Xint freespace()
  718. X#endif
  719. X{
  720. X  int i;
  721. X
  722. X#ifdef __STDC__
  723. X  for (i = 0; i < mazeheight; i++)
  724. X  if (free(cmaze[i]) == -1)
  725. X  {
  726. X     fprintf(stderr,"error freeing cmaze row; quitting freespace early\n");
  727. X     exit(1);
  728. X  }
  729. X  if (free(cmaze) == -1)
  730. X  {
  731. X     fprintf(stderr,"error freeing cmaze body; quitting freespace early\n");
  732. X     exit(1);
  733. X  }
  734. X  if (free(statlist) == -1)
  735. X  {
  736. X     fprintf(stderr,"error freeing statlist; quitting freespace early\n");
  737. X     exit(1);
  738. X  }
  739. X#else
  740. X  for (i = 0; i < mazeheight; i++) free(cmaze[i]);
  741. X  free(cmaze);
  742. X  free(statlist);
  743. X#endif
  744. X  return;
  745. X}
  746. END_OF_FILE
  747. if test 980 -ne `wc -c <'freespace.c'`; then
  748.     echo shar: \"'freespace.c'\" unpacked with wrong size!
  749. fi
  750. # end of 'freespace.c'
  751. fi
  752. if test -f 'interiorcell.c' -a "${1}" != "-c" ; then 
  753.   echo shar: Will not clobber existing file \"'interiorcell.c'\"
  754. else
  755. echo shar: Extracting \"'interiorcell.c'\" \(577 characters\)
  756. sed "s/^X//" >'interiorcell.c' <<'END_OF_FILE'
  757. X/*
  758. X** interiorcell.c  Copyright 1991 Kent Paul Dolan,
  759. X**                  Mountain View, CA, USA 94039-0755
  760. X**
  761. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  762. X** May be freely used or modified in any non-commercial work.  Copyrighted
  763. X** only to prevent patenting by someone else.
  764. X*/
  765. X
  766. X#include <stdio.h>
  767. X#include "townmaze.h"
  768. X#include "townproto.h"
  769. X
  770. X#ifdef __STDC__
  771. Xint interiorcell(int cellid)
  772. X#else
  773. Xint interiorcell(cellid)
  774. X  int cellid;
  775. X#endif
  776. X{
  777. X  int i;
  778. X  for (i = 0; i < 4; i++)
  779. X    if (!nhbrexists(cellid,i)) return (1==0);
  780. X  return (1==1);
  781. X}
  782. END_OF_FILE
  783. if test 577 -ne `wc -c <'interiorcell.c'`; then
  784.     echo shar: \"'interiorcell.c'\" unpacked with wrong size!
  785. fi
  786. # end of 'interiorcell.c'
  787. fi
  788. if test -f 'makecourts.c' -a "${1}" != "-c" ; then 
  789.   echo shar: Will not clobber existing file \"'makecourts.c'\"
  790. else
  791. echo shar: Extracting \"'makecourts.c'\" \(1742 characters\)
  792. sed "s/^X//" >'makecourts.c' <<'END_OF_FILE'
  793. X/*
  794. X** makecourts.c  Copyright 1991 Kent Paul Dolan,
  795. X**               Mountain View, CA, USA 94039-0755
  796. X**
  797. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  798. X** May be freely used or modified in any non-commercial work.  Copyrighted
  799. X** only to prevent patenting by someone else.
  800. X*/
  801. X
  802. X#include <stdio.h>
  803. X#include "townmaze.h"
  804. X#include "townproto.h"
  805. X
  806. X#ifdef __STDC__
  807. Xvoid makecourts()
  808. X#else
  809. Xint makecourts()
  810. X#endif
  811. X{
  812. X
  813. X  int totalcells;
  814. X  int chosencell;
  815. X  int tries;
  816. X  int i;
  817. X
  818. X/*
  819. X** Pepper courts around the city interior; keep them apart for algorithmic
  820. X** robustness reasons.
  821. X*/
  822. X
  823. X#if PROGRESS
  824. X  fprintf(stderr,"Courts ");
  825. X#endif
  826. X
  827. X  totalcells = ((mazeheight-1)/2 * (mazewidth-1)/2);
  828. X
  829. X  for (i = 0; i < mazecourts; i++)
  830. X  {
  831. X
  832. X/*  fprintf(stderr,"Court %d\n",i); */
  833. X
  834. X/*
  835. X** Set up to prevent infinite loop from unforseen geometry problems.
  836. X*/
  837. X
  838. X   tries = 0;
  839. X
  840. X/*
  841. X** Keep looking until a candidate cell is found for this ith court.
  842. X*/
  843. X    do
  844. X    {
  845. X      /* not perfectly fair, but good enough for moderate sized mazes. */
  846. X      chosencell = RANDOM()%totalcells;
  847. X
  848. X/*    fprintf(stderr,"  chosencell %d\n",chosencell); */
  849. X
  850. X      tries++;
  851. X
  852. X    } while (   (tries <= MAXTRIES)
  853. X             && (
  854. X                    (interiorcell(chosencell) != (1==1))
  855. X                 || (statlist[chosencell].status != ISOLATED)
  856. X                 || (statlist[nhbris(chosencell,0)].status != ISOLATED)
  857. X                 || (statlist[nhbris(chosencell,1)].status != ISOLATED)
  858. X                 || (statlist[nhbris(chosencell,2)].status != ISOLATED)
  859. X                 || (statlist[nhbris(chosencell,3)].status != ISOLATED)
  860. X                )
  861. X            );
  862. X
  863. X    if (tries <= MAXTRIES) makestreet(chosencell,streetnumct++,RANDOM()%4);
  864. X  }
  865. X  return;
  866. X}
  867. END_OF_FILE
  868. if test 1742 -ne `wc -c <'makecourts.c'`; then
  869.     echo shar: \"'makecourts.c'\" unpacked with wrong size!
  870. fi
  871. # end of 'makecourts.c'
  872. fi
  873. if test -f 'makegates.c' -a "${1}" != "-c" ; then 
  874.   echo shar: Will not clobber existing file \"'makegates.c'\"
  875. else
  876. echo shar: Extracting \"'makegates.c'\" \(2929 characters\)
  877. sed "s/^X//" >'makegates.c' <<'END_OF_FILE'
  878. X/*
  879. X** makegates.c  Copyright 1991 Kent Paul Dolan,
  880. X**              Mountain View, CA, USA 94039-0755
  881. X**
  882. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  883. X** May be freely used or modified in any non-commercial work.  Copyrighted
  884. X** only to prevent patenting by someone else.
  885. X*/
  886. X
  887. X#include <stdio.h>
  888. X#include "townmaze.h"
  889. X#include "townproto.h"
  890. X
  891. X#ifdef __STDC__
  892. Xvoid makegates()
  893. X#else
  894. Xint makegates()
  895. X#endif
  896. X{
  897. X
  898. X  int gatewalls;
  899. X  int chosenwall;
  900. X  int chosencell;
  901. X  int stdir;
  902. X  int tries;
  903. X  int i;
  904. X
  905. X/*
  906. X** Pepper gates around the outer wall; avoid gates at corners for
  907. X** esthetic reasons.
  908. X*/
  909. X
  910. X#if PROGRESS
  911. X  fprintf(stderr,"Gates ");
  912. X#endif
  913. X
  914. X  gatewalls = 2 * (mazeheight/2 + mazewidth/2);
  915. X
  916. X  for (i = 0; i < mazegates; i++)
  917. X  {
  918. X
  919. X/*  fprintf(stderr,"Gate %d\n",i); */
  920. X
  921. X/*
  922. X** Protect against infinite looping.
  923. X*/
  924. X    tries = 0;
  925. X/*
  926. X** Keep looking until a candidate cell is found for this ith gate.
  927. X*/
  928. X    do
  929. X    {
  930. X      /* not perfectly fair, but good enough for moderate sized mazes. */
  931. X      chosenwall = RANDOM()%gatewalls;
  932. X                                       
  933. X/*    fprintf(stderr,"  chosenwall %d\n",chosenwall); */
  934. X      if (chosenwall < (mazewidth/2))
  935. X      {
  936. X        chosencell = chosenwall;
  937. X        stdir = 2;
  938. X/*      fprintf(stderr,"    top chosencell %d\n",chosencell); */
  939. X      }
  940. X      else
  941. X        if (chosenwall < ((mazewidth/2) + (mazeheight/2)))
  942. X        {
  943. X          chosencell = ((chosenwall - (mazewidth/2) + 1) 
  944. X                                      * (mazewidth/2) - 1);
  945. X          stdir = 3;
  946. X/*        fprintf(stderr,"      right chosencell %d\n",chosencell); */
  947. X        }
  948. X        else
  949. X          if (chosenwall < (mazewidth - 1 + (mazeheight/2)))
  950. X          {
  951. X            chosencell = (listsize - chosenwall + (mazewidth/2) 
  952. X                          + (mazeheight/2) - 1);
  953. X            stdir = 0;
  954. X/*          fprintf(stderr,"        bottom chosencell %d\n",chosencell); */
  955. X          }
  956. X          else
  957. X          {
  958. X            chosencell = (mazewidth - 1 + mazeheight - 1 - chosenwall - 1)
  959. X                         * (mazewidth/2);
  960. X            stdir = 1;
  961. X/*          fprintf(stderr,"          left chosencell %d\n",chosencell); */
  962. X
  963. X          }
  964. X      tries++;
  965. X    } while (   (tries <= MAXTRIES)
  966. X             && (   (statlist[chosencell].status != ISOLATED)
  967. X                 || (   nhbrexists(chosencell,0)
  968. X                     && (statlist[nhbris(chosencell,0)].status != ISOLATED) )
  969. X                 || (   nhbrexists(chosencell,1)
  970. X                     && (statlist[nhbris(chosencell,1)].status != ISOLATED) )
  971. X                 || (   nhbrexists(chosencell,2)
  972. X                     && (statlist[nhbris(chosencell,2)].status != ISOLATED) )
  973. X                 || (   nhbrexists(chosencell,3)
  974. X                     && (statlist[nhbris(chosencell,3)].status != ISOLATED) )
  975. X                )
  976. X            );
  977. X
  978. X    if (tries <= MAXTRIES) makestreet(chosencell,streetnumct++,stdir);
  979. X  }
  980. X  return;
  981. X}
  982. END_OF_FILE
  983. if test 2929 -ne `wc -c <'makegates.c'`; then
  984.     echo shar: \"'makegates.c'\" unpacked with wrong size!
  985. fi
  986. # end of 'makegates.c'
  987. fi
  988. if test -f 'makespace.c' -a "${1}" != "-c" ; then 
  989.   echo shar: Will not clobber existing file \"'makespace.c'\"
  990. else
  991. echo shar: Extracting \"'makespace.c'\" \(1750 characters\)
  992. sed "s/^X//" >'makespace.c' <<'END_OF_FILE'
  993. X/*
  994. X** makespace.c  Copyright 1991 Kent Paul Dolan,
  995. X**              Mountain View, CA, USA 94039-0755
  996. X**
  997. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  998. X** May be freely used or modified in any non-commercial work.  Copyrighted
  999. X** only to prevent patenting by someone else.
  1000. X*/
  1001. X
  1002. X#include <stdio.h>
  1003. X#include "townmaze.h"
  1004. X#include "townproto.h"
  1005. X
  1006. X#ifdef __STDC__
  1007. Xvoid makespace()
  1008. X#else
  1009. Xint makespace()
  1010. X#endif
  1011. X{
  1012. X  int i,j;
  1013. X
  1014. X  if ((statlist = (DLENODE *)malloc(listsize * sizeof(DLENODE))) == NULL)
  1015. X  {
  1016. X    fprintf(stderr,
  1017. X      "Unable to allocate space for cell list for that size maze\n");
  1018. X    exit(1);
  1019. X  }
  1020. X
  1021. X  if ((cmaze = (char **)malloc(mazeheight * sizeof(char *))) == NULL)
  1022. X  {
  1023. X    fprintf(stderr,"%s%s",
  1024. X      "Unable to allocate space for maze display pointer list for that",
  1025. X      " size maze\n");
  1026. X#ifdef __STDC__
  1027. X    if (free(statlist) == -1)
  1028. X      fprintf(stderr,"unable to free(statlist) on bailout\n");
  1029. X#else
  1030. X    free(statlist);
  1031. X#endif
  1032. X
  1033. X    exit(1);
  1034. X  }
  1035. X
  1036. X  for (i = 0; i < mazewidth; i++)
  1037. X  {
  1038. X    if ((cmaze[i] = (char *)malloc(mazewidth * sizeof(char))) == NULL)
  1039. X    {
  1040. X      fprintf(stderr,
  1041. X      "Unable to allocate space for maze char array for that size maze\n");
  1042. X#ifdef __STDC__
  1043. X      for (j = 0; j < i; j++)
  1044. X      {
  1045. X        if (free(cmaze[j]) == -1)
  1046. X        {
  1047. X          fprintf(stderr,"unable to free(cmaze[%d]) on bailout\n",j);
  1048. X          break;
  1049. X        }
  1050. X      }
  1051. X      if (free(cmaze) == -1)
  1052. X        fprintf(stderr,"unable to free(cmaze) on bailout\n");
  1053. X      else
  1054. X        if (free(statlist) == -1)
  1055. X          fprintf(stderr,"unable to free(statlist) on bailout\n");
  1056. X#else
  1057. X      for (j = 0; j < i; j++) free(cmaze[j]);
  1058. X      free(cmaze);
  1059. X      free(statlist);
  1060. X#endif
  1061. X      exit(1);
  1062. X    }
  1063. X  }
  1064. X  
  1065. X  return;
  1066. X}
  1067. END_OF_FILE
  1068. if test 1750 -ne `wc -c <'makespace.c'`; then
  1069.     echo shar: \"'makespace.c'\" unpacked with wrong size!
  1070. fi
  1071. # end of 'makespace.c'
  1072. fi
  1073. if test -f 'movefromto.c' -a "${1}" != "-c" ; then 
  1074.   echo shar: Will not clobber existing file \"'movefromto.c'\"
  1075. else
  1076. echo shar: Extracting \"'movefromto.c'\" \(1495 characters\)
  1077. sed "s/^X//" >'movefromto.c' <<'END_OF_FILE'
  1078. X/*
  1079. X** movefromto.c  Copyright 1991 Kent Paul Dolan,
  1080. X**               Mountain View, CA, USA 94039-0755
  1081. X**
  1082. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  1083. X** May be freely used or modified in any non-commercial work.  Copyrighted
  1084. X** only to prevent patenting by someone else.
  1085. X*/
  1086. X
  1087. X#include <stdio.h>
  1088. X#include "townmaze.h"
  1089. X#include "townproto.h"
  1090. X
  1091. X#ifdef __STDC__
  1092. Xvoid movefromto(int *fromlist,int *fromcount,int *tolist,int *tocount,
  1093. X                int newstat,int cellnum)
  1094. X#else
  1095. Xint movefromto(fromlist,fromcount,tolist,tocount,newstat,cellnum)
  1096. X  int *fromlist;
  1097. X  int *fromcount;
  1098. X  int *tolist;
  1099. X  int *tocount;
  1100. X  int newstat;
  1101. X  int cellnum;
  1102. X#endif
  1103. X{
  1104. X
  1105. X  int oldnext;
  1106. X  int oldprev;
  1107. X
  1108. X/*
  1109. X** Save vital existing links.
  1110. X*/
  1111. X
  1112. X  oldnext = statlist[cellnum].next;
  1113. X  oldprev = statlist[cellnum].prev;
  1114. X
  1115. X/*
  1116. X** Unlink cell from old position somewhere in fromlist.
  1117. X*/
  1118. X
  1119. X  if (statlist[cellnum].next != NOPOINTER)
  1120. X    statlist[oldnext].prev = statlist[cellnum].prev;
  1121. X
  1122. X  if (statlist[cellnum].prev != NOPOINTER)
  1123. X    statlist[oldprev].next = statlist[cellnum].next;
  1124. X  else *fromlist = statlist[cellnum].next;
  1125. X
  1126. X/*
  1127. X** Link cell into new position at head of tolist.
  1128. X*/
  1129. X
  1130. X  statlist[cellnum].next = *tolist;
  1131. X
  1132. X  statlist[cellnum].prev = NOPOINTER;
  1133. X
  1134. X  if (*tolist != NOPOINTER)
  1135. X    statlist[*tolist].prev = cellnum;
  1136. X
  1137. X  *tolist = cellnum;
  1138. X
  1139. X/*
  1140. X** Update list length counts.
  1141. X*/
  1142. X
  1143. X  (*fromcount)--;
  1144. X  (*tocount)++;
  1145. X
  1146. X/*
  1147. X** update cell status
  1148. X*/
  1149. X
  1150. X      statlist[cellnum].status = newstat;
  1151. X
  1152. X  return;
  1153. X}
  1154. END_OF_FILE
  1155. if test 1495 -ne `wc -c <'movefromto.c'`; then
  1156.     echo shar: \"'movefromto.c'\" unpacked with wrong size!
  1157. fi
  1158. # end of 'movefromto.c'
  1159. fi
  1160. if test -f 'nhbrexists.c' -a "${1}" != "-c" ; then 
  1161.   echo shar: Will not clobber existing file \"'nhbrexists.c'\"
  1162. else
  1163. echo shar: Extracting \"'nhbrexists.c'\" \(1175 characters\)
  1164. sed "s/^X//" >'nhbrexists.c' <<'END_OF_FILE'
  1165. X/*
  1166. X** nhbrexists.c  Copyright 1991 Kent Paul Dolan,
  1167. X**               Mountain View, CA, USA 94039-0755
  1168. X**
  1169. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  1170. X** May be freely used or modified in any non-commercial work.  Copyrighted
  1171. X** only to prevent patenting by someone else.
  1172. X*/
  1173. X
  1174. X#include <stdio.h>
  1175. X#include "townmaze.h"
  1176. X#include "townproto.h"
  1177. X
  1178. X#ifdef __STDC__
  1179. Xint nhbrexists(int cellid,int nhbrid)
  1180. X#else
  1181. Xint nhbrexists(cellid,nhbrid)
  1182. X  int cellid, nhbrid;
  1183. X#endif
  1184. X{
  1185. X  int celli, cellj;
  1186. X
  1187. X  celli = cellid / (mazewidth/2);
  1188. X  cellj = cellid % (mazewidth/2);
  1189. X
  1190. X  switch (nhbrid)
  1191. X  {
  1192. X    case 0: /* too far north? */
  1193. X      return (((celli - 1) < 0) ? (1==0) : (1==1));
  1194. X      break;
  1195. X
  1196. X    case 1: /* too far east? */
  1197. X      return (((cellj + 1) >= (mazewidth/2)) ? (1==0) : (1==1));
  1198. X      break;
  1199. X
  1200. X    case 2: /* too far south? */
  1201. X      return (((celli + 1) >= (mazeheight/2)) ? (1==0) : (1==1));
  1202. X      break;
  1203. X
  1204. X    case 3:/* too far west? */
  1205. X      return (((cellj - 1) < 0) ? (1==0) : (1==1));
  1206. X      break;
  1207. X
  1208. X    default:
  1209. X      fprintf(stderr,"bad neighbor id value to nhbrexists %d\n",nhbrid);
  1210. X      showdebugmaze();
  1211. X      freespace();
  1212. X      exit(1);
  1213. X  }
  1214. X}
  1215. END_OF_FILE
  1216. if test 1175 -ne `wc -c <'nhbrexists.c'`; then
  1217.     echo shar: \"'nhbrexists.c'\" unpacked with wrong size!
  1218. fi
  1219. # end of 'nhbrexists.c'
  1220. fi
  1221. if test -f 'nhbris.c' -a "${1}" != "-c" ; then 
  1222.   echo shar: Will not clobber existing file \"'nhbris.c'\"
  1223. else
  1224. echo shar: Extracting \"'nhbris.c'\" \(1127 characters\)
  1225. sed "s/^X//" >'nhbris.c' <<'END_OF_FILE'
  1226. X/*
  1227. X** nhbris.c  Copyright 1991 Kent Paul Dolan,
  1228. X**           Mountain View, CA, USA 94039-0755
  1229. X**
  1230. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  1231. X** May be freely used or modified in any non-commercial work.  Copyrighted
  1232. X** only to prevent patenting by someone else.
  1233. X*/
  1234. X
  1235. X#include <stdio.h>
  1236. X#include "townmaze.h"
  1237. X#include "townproto.h"
  1238. X
  1239. X#ifdef __STDC__
  1240. Xint nhbris(int cellid,int nhbrid)
  1241. X#else
  1242. Xint nhbris(cellid,nhbrid)
  1243. X  int cellid, nhbrid;
  1244. X#endif
  1245. X{
  1246. X  int celli, cellj;
  1247. X
  1248. X  celli = cellid / (mazewidth/2);
  1249. X  cellj = cellid % (mazewidth/2);
  1250. X
  1251. X  switch (nhbrid)
  1252. X  {
  1253. X    case 0:
  1254. X      return ( ( (celli - 1) * (mazewidth/2) ) + cellj ); /* north nhbr */
  1255. X      break;
  1256. X    case 1:
  1257. X      return ( ( celli * (mazewidth/2) ) + cellj + 1); /* east nhbr */
  1258. X      break;
  1259. X    case 2:
  1260. X      return ( ( (celli + 1) * (mazewidth/2) ) + cellj ); /* south nhbr */
  1261. X      break;
  1262. X    case 3:
  1263. X      return ( ( celli * (mazewidth/2) ) + cellj - 1); /* west nhbr */
  1264. X      break;
  1265. X    default:
  1266. X      fprintf(stderr,"bad neighbor id value to nhbris %d\n",nhbrid);
  1267. X      showdebugmaze();
  1268. X      freespace();
  1269. X      exit(1);
  1270. X  }
  1271. X}
  1272. END_OF_FILE
  1273. if test 1127 -ne `wc -c <'nhbris.c'`; then
  1274.     echo shar: \"'nhbris.c'\" unpacked with wrong size!
  1275. fi
  1276. # end of 'nhbris.c'
  1277. fi
  1278. if test -f 'showdbmaze.c' -a "${1}" != "-c" ; then 
  1279.   echo shar: Will not clobber existing file \"'showdbmaze.c'\"
  1280. else
  1281. echo shar: Extracting \"'showdbmaze.c'\" \(1837 characters\)
  1282. sed "s/^X//" >'showdbmaze.c' <<'END_OF_FILE'
  1283. X/*
  1284. X** showdbmaze.c  Copyright 1991 Kent Paul Dolan,
  1285. X**               Mountain View, CA, USA 94039-0755
  1286. X**
  1287. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  1288. X** May be freely used or modified in any non-commercial work.  Copyrighted
  1289. X** only to prevent patenting by someone else.
  1290. X*/
  1291. X
  1292. X#include <stdio.h>
  1293. X#include "townmaze.h"
  1294. X#include "townproto.h"
  1295. X
  1296. X#ifdef __STDC__
  1297. Xvoid showdebugmaze()
  1298. X#else
  1299. Xint showdebugmaze()
  1300. X#endif
  1301. X{
  1302. X  int i, j, cellid;
  1303. X
  1304. X/*
  1305. X** Draw the character version of the maze to stdout.
  1306. X*/
  1307. X
  1308. X  fprintf(stdout,"\n");
  1309. X  for (i = 0; i < mazeheight; i++)
  1310. X  {
  1311. X    for (j = 0; j < mazewidth; j++)
  1312. X      if (((i%2)==1)&&((j%2)==1))
  1313. X      {
  1314. X        cellid = (i/2)*(mazewidth/2)+(j/2);
  1315. X        switch (statlist[cellid].status)
  1316. X        {
  1317. X          case ISOLATED:
  1318. X            fprintf(stdout,"%c",'I');
  1319. X            break;
  1320. X          case LIVE:
  1321. X            fprintf(stdout,"%c",'L');
  1322. X            break;
  1323. X          case DEAD:
  1324. X            fprintf(stdout,"%c",'D');
  1325. X            break;
  1326. X          case STREET:
  1327. X            switch (statlist[cellid].streetdir)
  1328. X            {
  1329. X            case -1:
  1330. X              fprintf(stdout,"%c",BLANK);
  1331. X              break;
  1332. X            case 0:
  1333. X              fprintf(stdout,"%c",'^');
  1334. X              break;
  1335. X            case 1:
  1336. X              fprintf(stdout,"%c",'>');
  1337. X              break;
  1338. X            case 2:
  1339. X              fprintf(stdout,"%c",'v');
  1340. X              break;
  1341. X            case 3:
  1342. X              fprintf(stdout,"%c",'<');
  1343. X              break;
  1344. X            default:
  1345. X              fprintf(stdout,"%c",'X');
  1346. X            }
  1347. X            break;
  1348. X          case UNUSED:
  1349. X            fprintf(stdout,"%c",'U');
  1350. X            break;
  1351. X          default:
  1352. X            fprintf(stdout,"%c",'?');
  1353. X        }
  1354. X      }
  1355. X      else
  1356. X        fprintf(stdout,"%c",cmaze[i][j]);
  1357. X    fprintf(stdout,"\n");
  1358. X  }
  1359. X  return;
  1360. X}
  1361. END_OF_FILE
  1362. if test 1837 -ne `wc -c <'showdbmaze.c'`; then
  1363.     echo shar: \"'showdbmaze.c'\" unpacked with wrong size!
  1364. fi
  1365. # end of 'showdbmaze.c'
  1366. fi
  1367. if test -f 'showlistdet.c' -a "${1}" != "-c" ; then 
  1368.   echo shar: Will not clobber existing file \"'showlistdet.c'\"
  1369. else
  1370. echo shar: Extracting \"'showlistdet.c'\" \(1206 characters\)
  1371. sed "s/^X//" >'showlistdet.c' <<'END_OF_FILE'
  1372. X/*
  1373. X** showlistdet.c  Copyright 1991 Kent Paul Dolan,
  1374. X**                Mountain View, CA, USA 94039-0755
  1375. X**
  1376. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  1377. X** May be freely used or modified in any non-commercial work.  Copyrighted
  1378. X** only to prevent patenting by someone else.
  1379. X*/
  1380. X
  1381. X#include <stdio.h>
  1382. X#include "townmaze.h"
  1383. X#include "townproto.h"
  1384. X
  1385. X#ifdef __STDC__
  1386. Xvoid showlistdetail()
  1387. X#else
  1388. Xint showlistdetail()
  1389. X#endif
  1390. X{
  1391. X
  1392. X  int i, j;
  1393. X
  1394. X  for (i = 0; i < (mazeheight/2); i++)
  1395. X  {
  1396. X    for (j = 0; j < (mazewidth/2); j++)
  1397. X      fprintf(stderr,"%4d ",statlist[j + ((mazewidth/2)*i)].prev);
  1398. X    fprintf(stderr,"\n");
  1399. X
  1400. X    for (j = 0; j < (mazewidth/2); j++)
  1401. X      fprintf(stderr,"%4d ",statlist[j + ((mazewidth/2)*i)].next);
  1402. X    fprintf(stderr,"\n");
  1403. X
  1404. X    for (j = 0; j < (mazewidth/2); j++)
  1405. X      fprintf(stderr,"%4d ",statlist[j + ((mazewidth/2)*i)].status);
  1406. X    fprintf(stderr,"\n");
  1407. X
  1408. X    for (j = 0; j < (mazewidth/2); j++)
  1409. X      fprintf(stderr,"%4d ",statlist[j + ((mazewidth/2)*i)].streetnum);
  1410. X    fprintf(stderr,"\n");
  1411. X
  1412. X    for (j = 0; j < (mazewidth/2); j++)
  1413. X      fprintf(stderr,"%4d ",statlist[j + ((mazewidth/2)*i)].streetdir);
  1414. X    fprintf(stderr,"\n\n");
  1415. X
  1416. X  }
  1417. X  return;
  1418. X}
  1419. END_OF_FILE
  1420. if test 1206 -ne `wc -c <'showlistdet.c'`; then
  1421.     echo shar: \"'showlistdet.c'\" unpacked with wrong size!
  1422. fi
  1423. # end of 'showlistdet.c'
  1424. fi
  1425. if test -f 'showlistsum.c' -a "${1}" != "-c" ; then 
  1426.   echo shar: Will not clobber existing file \"'showlistsum.c'\"
  1427. else
  1428. echo shar: Extracting \"'showlistsum.c'\" \(1017 characters\)
  1429. sed "s/^X//" >'showlistsum.c' <<'END_OF_FILE'
  1430. X/*
  1431. X** showlistsum.c  Copyright 1991 Kent Paul Dolan,
  1432. X**                Mountain View, CA, USA 94039-0755
  1433. X**
  1434. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  1435. X** May be freely used or modified in any non-commercial work.  Copyrighted
  1436. X** only to prevent patenting by someone else.
  1437. X*/
  1438. X
  1439. X#include <stdio.h>
  1440. X#include "townmaze.h"
  1441. X#include "townproto.h"
  1442. X
  1443. X#ifdef __STDC__
  1444. Xvoid showlistsummary()
  1445. X#else
  1446. Xint showlistsummary()
  1447. X#endif
  1448. X{
  1449. X  fprintf(stderr,"ISOLATED = %5d isolated = %5d isolatedct = %5d\n",
  1450. X          ISOLATED,isolated,isolatedct);
  1451. X  fprintf(stderr,"LIVE     = %5d live     = %5d livect     = %5d\n",
  1452. X          LIVE,live,livect);
  1453. X  fprintf(stderr,"DEAD     = %5d dead     = %5d deadct     = %5d\n",
  1454. X          DEAD,dead,deadct);
  1455. X  fprintf(stderr,
  1456. X          "STREET   = %5d street   = %5d streetct   = %5d streetnumct %5d\n",
  1457. X          STREET,street,streetct,streetnumct);
  1458. X  fprintf(stderr,"UNUSED   = %5d unused   = %5d unusedct   = %5d\n",
  1459. X          UNUSED,unused,unusedct);
  1460. X  return;
  1461. X}
  1462. X
  1463. END_OF_FILE
  1464. if test 1017 -ne `wc -c <'showlistsum.c'`; then
  1465.     echo shar: \"'showlistsum.c'\" unpacked with wrong size!
  1466. fi
  1467. # end of 'showlistsum.c'
  1468. fi
  1469. if test -f 'showmaze.c' -a "${1}" != "-c" ; then 
  1470.   echo shar: Will not clobber existing file \"'showmaze.c'\"
  1471. else
  1472. echo shar: Extracting \"'showmaze.c'\" \(706 characters\)
  1473. sed "s/^X//" >'showmaze.c' <<'END_OF_FILE'
  1474. X/*
  1475. X** showmaze.c  Copyright 1991 Kent Paul Dolan,
  1476. X**             Mountain View, CA, USA 94039-0755
  1477. X**
  1478. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  1479. X** May be freely used or modified in any non-commercial work.  Copyrighted
  1480. X** only to prevent patenting by someone else.
  1481. X*/
  1482. X
  1483. X#include <stdio.h>
  1484. X#include "townmaze.h"
  1485. X#include "townproto.h"
  1486. X
  1487. X#ifdef __STDC__
  1488. Xvoid showmaze()
  1489. X#else
  1490. Xint showmaze()
  1491. X#endif
  1492. X{
  1493. X  int i, j;
  1494. X
  1495. X/*
  1496. X** Draw the character version of the maze to stdout.
  1497. X*/
  1498. X
  1499. X#if PROGRESS
  1500. X  fprintf(stdout,"\n");
  1501. X#endif
  1502. X
  1503. X  for (i = 0; i < mazeheight; i++)
  1504. X  {
  1505. X    for (j = 0; j < mazewidth; j++)
  1506. X      fprintf(stdout,"%c",cmaze[i][j]);
  1507. X    fprintf(stdout,"\n");
  1508. X  }
  1509. X  return;
  1510. X}
  1511. END_OF_FILE
  1512. if test 706 -ne `wc -c <'showmaze.c'`; then
  1513.     echo shar: \"'showmaze.c'\" unpacked with wrong size!
  1514. fi
  1515. # end of 'showmaze.c'
  1516. fi
  1517. if test -f 'townmain.c' -a "${1}" != "-c" ; then 
  1518.   echo shar: Will not clobber existing file \"'townmain.c'\"
  1519. else
  1520. echo shar: Extracting \"'townmain.c'\" \(996 characters\)
  1521. sed "s/^X//" >'townmain.c' <<'END_OF_FILE'
  1522. X/*
  1523. X** townmain.c  Copyright 1991 Kent Paul Dolan,
  1524. X**             Mountain View, CA, USA 94039-0755
  1525. X**
  1526. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  1527. X** May be freely used or modified in any non-commercial work.  Copyrighted
  1528. X** only to prevent patenting by someone else.
  1529. X*/
  1530. X
  1531. X#include <stdio.h>
  1532. X#define MAINLINE 1
  1533. X#include "townmaze.h"
  1534. X#include "townproto.h"
  1535. X
  1536. X#ifdef __STDC__
  1537. Xvoid main(int argc,char *argv[])
  1538. X#else
  1539. Xint main(argc,argv)
  1540. X  int argc;
  1541. X  char *argv[];
  1542. X#endif
  1543. X{
  1544. X
  1545. X  SEEDRANDOM(randomseed = time(0));
  1546. X  getargs(argc,argv);
  1547. X  makespace();
  1548. X  fillmaze();
  1549. X  filllist();
  1550. X  makeunused();
  1551. X  makegates();
  1552. X  makecourts();
  1553. X#if SHOWSTART
  1554. X  showdebugmaze();
  1555. X#endif
  1556. X  connectstreets();
  1557. X  finishalleys();
  1558. X  closedoors();
  1559. X  closegates();
  1560. X  cleanupmap();
  1561. X/*
  1562. X#if PROGRESS
  1563. X  fprintf(stderr,"\n");
  1564. X#endif
  1565. X  showlistsummary();
  1566. X  showlistdetail();
  1567. X*/
  1568. X#if SHOWEND
  1569. X#if PROGRESS
  1570. X  fprintf(stderr,"\n");
  1571. X#endif
  1572. X  showdebugmaze();
  1573. X#endif
  1574. X  showmaze();
  1575. X  freespace();
  1576. X/*
  1577. X*/
  1578. X  exit(0);
  1579. X}
  1580. END_OF_FILE
  1581. if test 996 -ne `wc -c <'townmain.c'`; then
  1582.     echo shar: \"'townmain.c'\" unpacked with wrong size!
  1583. fi
  1584. # end of 'townmain.c'
  1585. fi
  1586. if test -f 'townmaze.with' -a "${1}" != "-c" ; then 
  1587.   echo shar: Will not clobber existing file \"'townmaze.with'\"
  1588. else
  1589. echo shar: Extracting \"'townmaze.with'\" \(360 characters\)
  1590. sed "s/^X//" >'townmaze.with' <<'END_OF_FILE'
  1591. Xfrom
  1592. Xlib:c.o
  1593. Xcleanupmap.o
  1594. Xclosedoors.o
  1595. Xclosegates.o
  1596. Xconnectst.o
  1597. Xfilllist.o
  1598. Xfillmaze.o
  1599. Xfinishalleys.o
  1600. Xfreespace.o
  1601. Xgetargs.o
  1602. Xinteriorcell.o
  1603. Xmakegates.o
  1604. Xmakecourts.o
  1605. Xmakespace.o
  1606. Xmakestreet.o
  1607. Xmakeunused.o
  1608. Xmovefromto.o
  1609. Xnhbrexists.o
  1610. Xnhbris.o
  1611. Xshowdbmaze.o
  1612. Xshowlistdet.o
  1613. Xshowlistsum.o
  1614. Xshowmaze.o
  1615. Xtownmain.o
  1616. Xusage.o
  1617. Xlib
  1618. Xlib:lcm.lib
  1619. Xlib:lc.lib
  1620. Xlib:amiga.lib
  1621. Xto
  1622. Xtownmaze
  1623. END_OF_FILE
  1624. if test 360 -ne `wc -c <'townmaze.with'`; then
  1625.     echo shar: \"'townmaze.with'\" unpacked with wrong size!
  1626. fi
  1627. # end of 'townmaze.with'
  1628. fi
  1629. if test -f 'usage.c' -a "${1}" != "-c" ; then 
  1630.   echo shar: Will not clobber existing file \"'usage.c'\"
  1631. else
  1632. echo shar: Extracting \"'usage.c'\" \(2052 characters\)
  1633. sed "s/^X//" >'usage.c' <<'END_OF_FILE'
  1634. X/*
  1635. X** usage.c  Copyright 1991 Kent Paul Dolan,
  1636. X**          Mountain View, CA, USA 94039-0755
  1637. X**
  1638. X** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  1639. X** May be freely used or modified in any non-commercial work.  Copyrighted
  1640. X** only to prevent patenting by someone else.
  1641. X*/
  1642. X
  1643. X#include <stdio.h>
  1644. X#include "townmaze.h"
  1645. X#include "townproto.h"
  1646. X
  1647. X#ifdef __STDC__
  1648. Xvoid usage()
  1649. X#else
  1650. Xint usage()
  1651. X#endif
  1652. X{
  1653. X/*
  1654. X** Sorry about the format here; beats breaking the lines in unnatural places.
  1655. X*/
  1656. X  fprintf(stderr,"%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
  1657. X"Usage: townmaze [-h #] [-w #] [-g #] [-l #] [-c #] [-u #] [-s #] [-r #]\n",
  1658. X"Where: -h = height of maze in characters; minimum is 11, must be odd;\n",
  1659. X"       -w = width of maze in characters; minimum is 11, must be odd;\n",
  1660. X"       -g = gates in maze; how many streets start at city wall,\n",
  1661. X"            maximum is 2 * (height - 6)/7 + 2 (width - 6)/7;\n",
  1662. X"            lots of gates get rid of outer prominade;\n",
  1663. X"       -l = leave # gates openable; rest are made back into walls at\n",
  1664. X"            end of maze design processing, range is 0 to g;\n",
  1665. X"       -c = courts in maze; how many streets start inside the city;\n",
  1666. X"            maximum is (((height - 5)/6)*((width - 5)/6));\n",
  1667. X"            courts make more complex mazes at the expense of density;\n",
  1668. X"       -u = unused cells in maze; adds interesting shapes; maximum of\n",
  1669. X"            (((height-1)/14)*((width-1)/14)) is allowed, to preserve\n",
  1670. X"            connectivity of streets by leaving three cells between\n",
  1671. X"            unused cells so that streets can get past them;\n",
  1672. X"       -s = straightness of streets, range 0 to 998; straighter streets\n",
  1673. X"            make for more buildings, denser maze.\n",
  1674. X"       -r = force this random number routine seed to get the same maze\n",
  1675. X"            as the last time this seed was used.\n",
  1676. X"There must be at least one gate or court;              Copyright 1991,\n",
  1677. X"Spaces between flags and values are mandatory!!        Kent Paul Dolan.\n");
  1678. X   return;
  1679. X}
  1680. END_OF_FILE
  1681. if test 2052 -ne `wc -c <'usage.c'`; then
  1682.     echo shar: \"'usage.c'\" unpacked with wrong size!
  1683. fi
  1684. # end of 'usage.c'
  1685. fi
  1686. echo shar: End of archive 1 \(of 4\).
  1687. cp /dev/null ark1isdone
  1688. MISSING=""
  1689. for I in 1 2 3 4 ; do
  1690.     if test ! -f ark${I}isdone ; then
  1691.     MISSING="${MISSING} ${I}"
  1692.     fi
  1693. done
  1694. if test "${MISSING}" = "" ; then
  1695.     echo You have unpacked all 4 archives.
  1696.     rm -f ark[1-9]isdone
  1697. else
  1698.     echo You still need to unpack the following archives:
  1699.     echo "        " ${MISSING}
  1700. fi
  1701. ##  End of shell archive.
  1702. exit 0
  1703.