home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / games / volume17 / napoleon / part04 < prev    next >
Encoding:
Text File  |  1993-03-03  |  10.1 KB  |  323 lines

  1. Subject:  v17i041:  napoleon - text adventure game, Part04/04
  2. Newsgroups: comp.sources.games
  3. Approved: billr@saab.CNA.TEK.COM
  4.  
  5. Submitted-by: pc123@cus.cam.ac.uk (Pete Chown)
  6. Posting-number: Volume 17, Issue 41
  7. Archive-name: napoleon/Part04
  8. Environment: Unix, ASNI-C
  9.  
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 4 (of 4)."
  18. # Contents:  adv.h copyright toplev.c
  19. # Wrapped by billr@saab on Thu Mar  4 09:46:52 1993
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. if test -f 'adv.h' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'adv.h'\"
  23. else
  24. echo shar: Extracting \"'adv.h'\" \(4570 characters\)
  25. sed "s/^X//" >'adv.h' <<'END_OF_FILE'
  26. X/* Copyright (C) 1992 Pete Chown.
  27. X
  28. X   Here is my latest adventure game, Napoleon (see the documentation
  29. X   if you don't know why it's called that).  Have fun... (don't cheat,
  30. X   even though you've got the source :-) ).
  31. X
  32. X   This game is free software; you can redistribute it and/or modify
  33. X   it under the terms of the GNU General Public License as published by
  34. X   the Free Software Foundation; either version 1, or (at your option)
  35. X   any later version.
  36. X
  37. X   The game is distributed in the hope that it will be useful, but
  38. X   WITHOUT ANY WARRANTY; without even the implied warranty of
  39. X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  40. X   General Public License for more details.
  41. X
  42. X   The GNU General Public License is often shipped with GNU software, and
  43. X   is generally kept in a file called COPYING or LICENSE.  If you do not
  44. X   have a copy of the license, write to the Free Software Foundation,
  45. X   675 Mass Ave, Cambridge, MA 02139, USA. */
  46. X
  47. X/* Define PURE_ANSI if you are building Napoleon on a system which is not
  48. X   Unix compatible.  Then the result will be ANSI conforming, but will
  49. X   have no command history and will not be able to detect the size of the
  50. X   screen.  Otherwise define UNIX.
  51. X
  52. X   Define HAS_XMALLOC if your system has xmalloc() built into the C library.
  53. X   It will not then be defined again by this program.
  54. X*/
  55. X
  56. X#if (!defined(PURE_ANSI) && !defined(UNIX)) || (defined(PURE_ANSI) && defined(UNIX))
  57. X#error You must define one of PURE_ANSI and UNIX.
  58. X#endif
  59. X
  60. X#include <stdio.h>
  61. X#include <string.h>
  62. X#include <ctype.h>
  63. X#include <stdarg.h>
  64. X#include <signal.h>
  65. X#include <time.h>
  66. X
  67. X#ifdef HAS_STDLIB
  68. X#include <stdlib.h>
  69. X#endif
  70. X
  71. X#ifndef PURE_ANSI
  72. X
  73. X#include "readline/readline.h"
  74. X#include "readline/history.h"
  75. X
  76. X#endif
  77. X
  78. X#define VERSION "1.02 (" __DATE__ ")"
  79. X#define NAME "Napoleon"
  80. X#define bool int
  81. X#define TRUE 1
  82. X#define FALSE 0
  83. X#define LINE_NO_HISTORY 5
  84. X#define LINE_HISTORY 6
  85. X#ifdef CHECKING_CONSISTENCY
  86. X#define fail() { fprintf(stderr,"Internal inconsistency detected\n"); exit(4); }
  87. X#else
  88. X#define fail() { fprintf(stderr,"Internal inconsistency detected, fail point is " __FILE__ ":%d\n",__LINE__); exit(4); }
  89. X#endif
  90. X
  91. Xstruct objtype {
  92. X  unsigned int room:1,player:1,alive:1,luminous:1,opaque:1,virtual:1,visited:1,container:1;
  93. X};
  94. X
  95. Xtypedef struct tagobject {
  96. X  int above,below,inside,next,parent,n,s,w,e,nw,ne,sw,se,u,d;
  97. X  char *examine,*longname,*shortname;
  98. X  struct objtype objtype;
  99. X} object;
  100. X
  101. Xextern void format(char *,...);
  102. Xextern char *getline(char *,int);
  103. Xextern void loadgame(void);
  104. Xextern void initialise(void);
  105. Xextern void describe_room(int,bool);
  106. Xextern void command(int,char *);
  107. Xextern int getroom(int);
  108. Xextern void detachfromchain(int);
  109. Xextern int yyparse(void);
  110. Xextern bool strcmp_ci(char *,char *);
  111. Xextern void addtochain(int,int,int *);
  112. Xextern bool ancestor(int,int);
  113. Xextern void savegame(void);
  114. Xextern void addfirstdescendants(int);
  115. Xextern void inventory(int);
  116. Xextern int yylex(void);
  117. Xextern void moveplayer(void);
  118. Xextern int rnd(int);
  119. Xextern void yyerror(char *);
  120. Xextern void addadjective(char *);
  121. Xextern void addobject(int);
  122. Xextern int getobject(char *);
  123. Xextern bool ispresent(int,int);
  124. Xextern void examine(void);
  125. Xextern void do_read(void);
  126. Xextern void get(void);
  127. Xextern void drop(void);
  128. Xextern void put(int,int *);
  129. Xextern int premove(int,int);
  130. Xextern void postmove(void);
  131. Xextern void postdescription(int);
  132. Xextern void speech(int,int);
  133. Xextern bool dogreeting(int);
  134. Xextern bool dofarewell(int);
  135. Xextern void doyes(int);
  136. Xextern void dono(int);
  137. Xextern void twirl(void);
  138. Xextern void turn(void);
  139. Xextern void examineobject(int,int);
  140. Xextern int playnoughts(void);
  141. Xextern void more(void);
  142. Xextern void hack(void);
  143. Xextern bool illuminated(int);
  144. Xextern void justput(int,int,int *);
  145. Xextern void play(int);
  146. Xextern char *quickname(char *,int);
  147. Xextern void playnandc(int);
  148. Xextern void give(int);
  149. Xextern bool wantsit(int,int);
  150. Xextern void destroy(int);
  151. Xextern void throw(int);
  152. Xextern void jump(int);
  153. Xextern void touch(int);
  154. Xextern void unlock(int,int);
  155. Xextern void resumscore(void);
  156. Xextern bool referred_to(int);
  157. Xextern int getbeastie(void);
  158. Xextern void record(int,int);
  159. Xextern void drink(int);
  160. Xextern void precommand(void);
  161. Xextern void do_wait(void);
  162. Xextern void kiss(int);
  163. Xextern bool quadruples(void);
  164. Xextern void search(int);
  165. Xextern void climb(int);
  166. X
  167. Xextern void *xmalloc(int);
  168. X
  169. Xextern bool descr,looked,dead,all,hacker,finished,speechflag;
  170. Xextern object *objects,intobjects [];
  171. Xextern int player,direction,score,yaccplayer,listedobjects,objectlist [200],subject,said,delay;
  172. Xextern char *yaccstring;
  173. Xextern unsigned char flags [128];
  174. END_OF_FILE
  175. if test 4570 -ne `wc -c <'adv.h'`; then
  176.     echo shar: \"'adv.h'\" unpacked with wrong size!
  177. fi
  178. # end of 'adv.h'
  179. fi
  180. if test -f 'copyright' -a "${1}" != "-c" ; then 
  181.   echo shar: Will not clobber existing file \"'copyright'\"
  182. else
  183. echo shar: Extracting \"'copyright'\" \(961 characters\)
  184. sed "s/^X//" >'copyright' <<'END_OF_FILE'
  185. X/* Copyright (C) 1992 Pete Chown.
  186. X
  187. X   Here is my latest adventure game, Napoleon (see the documentation
  188. X   if you don't know why it's called that).  Have fun... (don't cheat,
  189. X   even though you've got the source :-) ).
  190. X
  191. X   This game is free software; you can redistribute it and/or modify
  192. X   it under the terms of the GNU General Public License as published by
  193. X   the Free Software Foundation; either version 1, or (at your option)
  194. X   any later version.
  195. X
  196. X   The game is distributed in the hope that it will be useful, but
  197. X   WITHOUT ANY WARRANTY; without even the implied warranty of
  198. X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  199. X   General Public License for more details.
  200. X
  201. X   The GNU General Public License is often shipped with GNU software, and
  202. X   is generally kept in a file called COPYING or LICENSE.  If you do not
  203. X   have a copy of the license, write to the Free Software Foundation,
  204. X   675 Mass Ave, Cambridge, MA 02139, USA. */
  205. END_OF_FILE
  206. if test 961 -ne `wc -c <'copyright'`; then
  207.     echo shar: \"'copyright'\" unpacked with wrong size!
  208. fi
  209. # end of 'copyright'
  210. fi
  211. if test -f 'toplev.c' -a "${1}" != "-c" ; then 
  212.   echo shar: Will not clobber existing file \"'toplev.c'\"
  213. else
  214. echo shar: Extracting \"'toplev.c'\" \(2356 characters\)
  215. sed "s/^X//" >'toplev.c' <<'END_OF_FILE'
  216. X/* Copyright (C) 1992 Pete Chown.
  217. X
  218. X   Here is my latest adventure game, Napoleon (see the documentation
  219. X   if you don't know why it's called that).  Have fun... (don't cheat,
  220. X   even though you've got the source :-) ).
  221. X
  222. X   This game is free software; you can redistribute it and/or modify
  223. X   it under the terms of the GNU General Public License as published by
  224. X   the Free Software Foundation; either version 1, or (at your option)
  225. X   any later version.
  226. X
  227. X   The game is distributed in the hope that it will be useful, but
  228. X   WITHOUT ANY WARRANTY; without even the implied warranty of
  229. X   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  230. X   General Public License for more details.
  231. X
  232. X   The GNU General Public License is often shipped with GNU software, and
  233. X   is generally kept in a file called COPYING or LICENSE.  If you do not
  234. X   have a copy of the license, write to the Free Software Foundation,
  235. X   675 Mass Ave, Cambridge, MA 02139, USA. */
  236. X
  237. X#include "adv.h"
  238. X
  239. Xextern int main(int,char *[]);
  240. X
  241. Xbool dead,finished = FALSE,descr,looked,hacker = FALSE;
  242. Xint player,score = 0;
  243. X
  244. Xstatic void write_disclaimer(void)
  245. X{
  246. X  format("%s, version %s, copyright (c) Pete Chown 1992\n\n",NAME,VERSION);
  247. X  format("Napoleon is free software and you are welcome to distribute copies"
  248. X" of it under certain conditions; read the scroll (in the office where you st"
  249. X"art) to see them.  There is absolutely no warranty for Napoleon; again detai"
  250. X"ls are on the scroll.\n\n");
  251. X}
  252. X
  253. Xextern int main(int argc,char *argv [])
  254. X{
  255. X  bool quitting,gotinput;
  256. X  char *line;
  257. X
  258. X  write_disclaimer();
  259. X  initialise();
  260. X
  261. X  do {
  262. X    dead = FALSE;
  263. X    descr = TRUE;
  264. X    for(;;)
  265. X    {
  266. X      if(descr) {
  267. X    describe_room(player,looked);
  268. X    descr = FALSE;
  269. X    looked = FALSE;
  270. X      }
  271. X      precommand();
  272. X      if(dead || finished) break;
  273. X      line = getline("(napoleon) ",LINE_HISTORY);
  274. X      command(player,line);
  275. X      if(dead || finished) break;
  276. X    }
  277. X    quitting = gotinput = FALSE;
  278. X    do {
  279. X      format("Enter 'R' to restart, 'L' to load a saved game or 'Q' to quit:");
  280. X      line = getline(">",LINE_NO_HISTORY);
  281. X      switch(tolower(*line))
  282. X      {
  283. X      case 'r':
  284. X    initialise();
  285. X    gotinput = TRUE;
  286. X    break;
  287. X      case 'l':
  288. X    loadgame();
  289. X    gotinput = TRUE;
  290. X    break;
  291. X      case 'q':
  292. X    quitting = gotinput = TRUE;
  293. X    break;
  294. X      }
  295. X    } while(! gotinput);
  296. X  } while(! quitting);
  297. X
  298. X  return 0;
  299. X}
  300. END_OF_FILE
  301. if test 2356 -ne `wc -c <'toplev.c'`; then
  302.     echo shar: \"'toplev.c'\" unpacked with wrong size!
  303. fi
  304. # end of 'toplev.c'
  305. fi
  306. echo shar: End of archive 4 \(of 4\).
  307. cp /dev/null ark4isdone
  308. MISSING=""
  309. for I in 1 2 3 4 ; do
  310.     if test ! -f ark${I}isdone ; then
  311.     MISSING="${MISSING} ${I}"
  312.     fi
  313. done
  314. if test "${MISSING}" = "" ; then
  315.     echo You have unpacked all 4 archives.
  316.     rm -f ark[1-9]isdone
  317. else
  318.     echo You still need to unpack the following archives:
  319.     echo "        " ${MISSING}
  320. fi
  321. ##  End of shell archive.
  322. exit 0
  323.