Home | History | Annotate | Line # | Download | only in warp
warp.h revision 1.1
      1 /* $Header: /tank/opengrok/rsync2/NetBSD/src/games/warp/warp.h,v 1.1 2020/11/09 23:37:05 kamil Exp $ */
      2 
      3 /* $Log: warp.h,v $
      4 /* Revision 1.1  2020/11/09 23:37:05  kamil
      5 /* Add Warp Kit, Version 7.0 by Larry Wall
      6 /*
      7 /* Warp is a real-time space war game that doesn't get boring very quickly.
      8 /* Read warp.doc and the manual page for more information.
      9 /*
     10 /* games/warp originally distributed with 4.3BSD-Reno, is back to the BSD
     11 /* world via NetBSD. Its remnants were still mentioned in games/Makefile.
     12 /*
     13 /* Larry Wall, the original author and the copyright holder, generously
     14 /* donated the game and copyright to The NetBSD Foundation, Inc.
     15 /*
     16 /* Import the game sources as-is from 4.3BSD-Reno, with the cession
     17 /* of the copyright and license to BSD-2-clause NetBSD-style.
     18 /*
     19 /* Signed-off-by: Larry Wall <larry (at) wall.org>
     20 /* Signed-off-by: Kamil Rytarowski <kamil (at) netbsd.org>
     21 /*
     22  * Revision 7.0.1.2  86/12/12  17:08:42  lwall
     23  * Baseline for net release.
     24  *
     25  * Revision 7.0.1.1  86/10/16  10:54:26  lwall
     26  * Added Damage.  Fixed random bugs.
     27  *
     28  * Revision 7.0  86/10/08  15:17:55  lwall
     29  * Split into separate files.  Added amoebas and pirates.
     30  *
     31  */
     32 
     33 extern int errno;
     34 
     35 #include "config.h"	/* generated by Configure script */
     36 
     37 #include <stdio.h>
     38 #include <signal.h>
     39 #include <ctype.h>
     40 #include <sys/types.h>
     41 #include <sys/stat.h>
     42 #include <errno.h>
     43 
     44 /* WARPLIB must be readable and writeable by warp, but not by anyone who you
     45  * don't trust.  In other words, to set up warp so everyone can play and
     46  * no one can cheat, give warp a uid of its own and make warp setuid to
     47  * that uid.  WARPLIB must then NOT be made writeable by the world,
     48  * since no attempt is made to encrypt saved games or anything.
     49  * (It must be readable by the world, however, due to a strangeness in
     50  * access.)
     51  */
     52 
     53 #define SAVEDIR "./"
     54 #define NEWSFILE "warp.news"
     55 #define HELPFILE "warp.doc"
     56 #define LOCKFILE ".warp.lock"
     57 #define LOGFILE "warp.log"
     58 #define SCOREBOARD "warp.top"
     59 #define LSCOREBOARD "warp.lowtop"
     60 #define FSCOREBOARD "warp.funtop"
     61 #define TMPSCOREBOARD "warp.topnew"
     62 #define WARPMACRO "%X/Kbmap.%{TERM}"
     63 
     64 /* warp library */
     65 #ifndef WARPLIB		/* ~ and %l only ("~%l" is permissable) */
     66 #   ifdef PRIVLIB
     67 #	define WARPLIB PRIVLIB
     68 #   else
     69 #	define WARPLIB "/usr/games/warp"
     70 #   endif
     71 #endif
     72 
     73 EXT char *warplib;
     74 
     75 #define PERMMAPS 8	/* how many starmaps are permanent */
     76 #define MAPS 20		/* how many starmaps to choose from */
     77 			/* (MAPS - PERMMAPS is # of half-gone universes) */
     78 
     79 /*
     80  * Screen size info, minimum screen size is 23x40 (actually 24x80).
     81  * YSIZE and XSIZE should be relatively prime so that a torpedo launched
     82  * at an angle will eventually cover the whole screen.
     83  * To calculate a new position for something:
     84  * new_position = (current_position + delta + ?SIZE00) % ?SIZE
     85  * This allows for negative deltas of up to ?SIZE00 (% doesn't work right
     86  * on negative numbers).
     87  * ?SIZE01, etc. are fudges for efficiency--they already include a delta.
     88  */
     89 
     90 #define XYSIZE 920
     91 #define XYSIZEx4 3680
     92 
     93 #define YSIZE   23
     94 #define YSIZE00 2300
     95 #define YSIZE01 2301
     96 #define YSIZE99 2299
     97 
     98 #define XSIZE   40
     99 #define XSIZE00 4000
    100 #define XSIZE01 4001
    101 #define XSIZE99 3999
    102 #define XSIZE02 4002
    103 #define XSIZE98 3998
    104 #define XSIZE03 4003
    105 #define XSIZE97 3997
    106 #define XSIZE08 4008
    107 #define XSIZE92 3992
    108 
    109 EXT char amb[YSIZE][XSIZE];
    110 
    111 #ifdef WHOAMI
    112 #    include <whoami.h>
    113 #endif
    114 
    115 #ifndef isalnum
    116 #   define isalnum(c) (isalpha(c) || isdigit(c))
    117 #endif
    118 
    119 #ifdef TERMIO
    120 #   include <termio.h>
    121 #else
    122 #   include <sgtty.h>
    123 #endif
    124 
    125 #include <sys/timeb.h>
    126 
    127 #   include <pwd.h>
    128 
    129 #define BITSPERBYTE 8
    130 #define LBUFLEN 512	/* line buffer length */
    131 
    132 #ifdef pdp11
    133 #   define CBUFLEN 256	/* command buffer length */
    134 #   define PUSHSIZE 128
    135 #else
    136 #   define CBUFLEN 512	/* command buffer length */
    137 #   define PUSHSIZE 256
    138 #endif
    139 #ifdef pdp11
    140 #   define MAXFILENAME 128
    141 #else
    142 #   define MAXFILENAME 512
    143 #endif
    144 #define FINISHCMD 0177
    145 
    146 /* some handy defs */
    147 
    148 #define bool char
    149 #define TRUE (1)
    150 #define FALSE (0)
    151 #define Null(t) ((t)0)
    152 #define Nullch Null(char *)
    153 #define Nullfp Null(FILE *)
    154 
    155 #define Ctl(ch) (ch & 037)
    156 
    157 #define strNE(s1,s2) (strcmp(s1,s2))
    158 #define strEQ(s1,s2) (!strcmp(s1,s2))
    159 #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
    160 #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
    161 
    162 #define sgn(x) ((x) < 0 ? -1 : (x) > 0)
    163 
    164 /* Things we can figure out ourselves */
    165 
    166 #ifdef SIGPROF
    167 #   define BSD42		/* do we have Berkeley 4.2? */
    168 #endif
    169 
    170 #ifdef FIONREAD
    171 #   define PENDING
    172 #else
    173 #   ifdef O_NDELAY
    174 #	define PENDING
    175 #   else
    176 #	ifdef RDCHK
    177 #	    define PENDING
    178 #	endif
    179 #   endif
    180 #endif
    181 
    182 #define UNLINK(victim) unlink(victim)
    183 
    184 /* Valid substitutions for strings marked with % comment are:
    185  *	%H	Host name (yours)
    186  *	%L	Login name (yours)
    187  *	%N	Full name (yours)
    188  *	%O	Original working directory (where you ran warp from)
    189  *	%X	Warp library directory
    190  *	%~	Home directory
    191  *	%.	Directory containing . files
    192  *	%$	current process number
    193  *	%{name} Environment variable "name".  %{name-default} form allowed.
    194  *	%"prompt"
    195  *		Print prompt and insert what is typed.
    196  *	%`command`
    197  *		Insert output of command.
    198  *	%(test_text=pattern?if_text:else_text)
    199  *		Substitute if_text if test_text matches pattern, otherwise
    200  *		substitute else_text.  Use != for negated match.
    201  *		% substitutions are done on test_text, if_text, and else_text.
    202  *		(Note: %() only works if CONDSUB defined.)
    203  */
    204 
    205 /* *** System Dependent Stuff *** */
    206 
    207 /* NOTE: many of these are defined in the config.h file */
    208 
    209 #ifndef ROOTID
    210 #   define ROOTID 0        /* uid of superuser */
    211 #endif
    212 
    213 #   define sigset Signal
    214 #   define sigignore(sig) Signal(sig,SIG_IGN)
    215 
    216 #ifndef LOGDIRFIELD
    217 #   define LOGDIRFIELD 6		/* Which field (origin 1) is the */
    218 					/* login directory in /etc/passwd? */
    219 					/* (If it is not kept in passwd, */
    220 					/* but getpwnam() returns it, */
    221 					/* define the symbol GETPWENT) */
    222 #endif
    223 #ifndef GCOSFIELD
    224 #   define GCOSFIELD 5
    225 #endif
    226 
    227 /* Undefine any of the following features to save both I and D space */
    228 /* In general, earlier ones are easier to get along without */
    229 /* Pdp11's without split I and D may have to undefine them all */
    230 #define DEBUGGING	/* include debugging code */
    231 #define PUSHBACK	/* macros and keymaps using pushback buffer */
    232 #define CONDSUB		/* allow %(cond?text:text) */
    233 #define BACKTICK	/* allow %`command` */
    234 #define PROMPTTTY	/* allow %"prompt" */
    235 #define GETLOGIN	/* use getlogin() routine as backup to environment */
    236 			/* variables USER or LOGNAME */
    237 #define TILDENAME	/* allow ~logname expansion */
    238 #define GETWD		/* use our getwd() instead of piped in pwd */
    239 #define SETUIDGID	/* substitute eaccess() for access() so that rn */
    240 			/* can run setuid or setgid */
    241 			/* if not setuid or setgid, you don't need it */
    242 #define VERBOSE		/* compile in more informative messages */
    243 #define TERSE		/* compile in shorter messages */
    244 
    245 /* some dependencies among options */
    246 
    247 #ifndef SETUIDGID
    248 #   define eaccess access
    249 #endif
    250 
    251 #ifdef VERBOSE
    252 #   ifdef TERSE
    253 #	define IF(c) if (c)
    254 #	define ELSE else
    255 #   else /* !TERSE */
    256 #	define IF(c)
    257 #	define ELSE
    258 #   endif
    259 #else /* !VERBOSE */
    260 #   ifndef TERSE
    261 #	define TERSE
    262 #   endif
    263 #   define IF(c) "IF" outside of VERBOSE???
    264 #   define ELSE "ELSE" outside of VERBOSE???
    265 #endif
    266 
    267 #ifdef DEBUGGING
    268 #   define assert(ex) {if (!(ex)){fprintf(stderr,"Assertion failed: file %s, line %d\r\n", __FILE__, __LINE__);sig_catcher(0);}}
    269 #else
    270 #   define assert(ex) ;
    271 #endif
    272 
    273 #define TCSIZE 512	/* capacity for termcap strings */
    274 
    275 /* End of Space Conservation Section */
    276 
    277 /* More System Dependencies */
    278 
    279 /* preferred shell for use in doshell routine */
    280 /*  ksh or sh would be okay here */
    281 #ifndef PREFSHELL
    282 #   define PREFSHELL "/bin/csh"
    283 #endif
    284 
    285 /* path to fastest starting shell */
    286 #ifndef SH
    287 #   define SH "/bin/sh"
    288 #endif
    289 
    290 /* location of macro file */
    291 #ifndef WARPMACRO
    292 #   ifdef PUSHBACK
    293 #	define WARPMACRO "%./.warpmac"
    294 #   endif
    295 #endif
    296 
    297 /* location of full name */
    298 #ifndef FULLNAMEFILE
    299 #   ifndef PASSNAMES
    300 #	define FULLNAMEFILE "%./.fullname"
    301 #   endif
    302 #endif
    303 
    304 /* a motd-like file for warp */
    305 #ifndef WARPNEWSNAME		/* % and ~ */
    306 #   define WARPNEWSNAME "%X/warp.news"
    307 #endif
    308 
    309 /* typedefs */
    310 
    311 typedef unsigned int	MEM_SIZE;	/* for passing to malloc */
    312 
    313 /* *** end of the machine dependent stuff *** */
    314 
    315 /* GLOBAL THINGS */
    316 
    317 /* file statistics area */
    318 
    319 EXT struct stat filestat;
    320 
    321 /* various things of type char */
    322 
    323 char	*index();
    324 char	*rindex();
    325 char	*getenv();
    326 char	*strcat();
    327 char	*strcpy();
    328 
    329 EXT char buf[LBUFLEN+1];	/* general purpose line buffer */
    330 
    331 EXT char *cwd INIT(Nullch);		/* current working directory */
    332 
    333 /* switches */
    334 
    335 #ifdef DEBUGGING
    336     EXT int debug INIT(0);				/* -D */
    337 #   define DEB_FILEXP 64
    338 #endif
    339 
    340 #ifdef VERBOSE
    341 #   ifdef TERSE
    342 	EXT bool verbose INIT(TRUE);			/* +t */
    343 #   endif
    344 #endif
    345 
    346 /* miscellania */
    347 
    348 EXT FILE *tmpfp INIT(Nullfp);	/* scratch fp */
    349 
    350 #define NOMARKING 0
    351 #define STANDOUT 1
    352 #define UNDERLINE 2
    353 
    354 /* Factored strings */
    355 
    356 EXT char nullstr[] INIT("");
    357 EXT char readerr[] INIT("warp read error");
    358 EXT char cantopen[] INIT("Can't open %s\r\n");
    359 
    360 #ifdef VERBOSE
    361     EXT char nocd[] INIT("Can't chdir to directory %s\r\n");
    362 #else
    363     EXT char nocd[] INIT("Can't find %s\r\n");
    364 #endif
    365 
    366 extern int errno;
    367 
    368 EXT bool justonemoretime INIT(TRUE);
    369 EXT bool keepgoing INIT(TRUE);
    370 
    371 EXT bool friendspec INIT(FALSE);
    372 EXT bool piratespec INIT(FALSE);
    373 EXT bool amoebaspec INIT(FALSE);
    374 EXT bool starspec INIT(FALSE);
    375 EXT bool klingspec INIT(FALSE);
    376 EXT bool apolspec INIT(FALSE);
    377 EXT bool crushspec INIT(FALSE);
    378 EXT bool romspec INIT(FALSE);
    379 EXT bool prespec INIT(FALSE);
    380 EXT bool tholspec INIT(FALSE);
    381 EXT bool gornspec INIT(FALSE);
    382 EXT bool beginner INIT(FALSE);
    383 EXT bool massacre INIT(FALSE);
    384 EXT bool lowspeed INIT(FALSE);
    385 EXT bool debugging INIT(FALSE);
    386 EXT bool didkill INIT(FALSE);
    387 EXT bool experimenting INIT(FALSE);
    388 EXT bool scorespec INIT(FALSE);
    389 EXT bool metakey INIT(FALSE);
    390 
    391 EXT bool bombed_out;
    392 EXT bool panic INIT(FALSE);
    393 EXT bool madgorns;
    394 
    395 EXT int madfriends;
    396 
    397 EXT int inumpirates;
    398 EXT int numpirates;
    399 EXT int inumfriends;
    400 EXT int numfriends;
    401 EXT int inumamoebas;
    402 EXT int numamoebas;
    403 EXT int inumstars;
    404 EXT int numstars;
    405 EXT int inumenemies;
    406 EXT int numenemies;
    407 EXT int inumroms;
    408 EXT int inumthols;
    409 EXT int inumapollos;
    410 EXT int numapollos;
    411 EXT int apolloflag;
    412 EXT int inumcrushes;
    413 EXT int numcrushes;
    414 EXT int inumgorns;
    415 EXT int numgorns;
    416 EXT int deados;
    417 EXT int deadmudds;
    418 EXT int smarts;
    419 EXT int ismarts INIT(0);
    420 EXT int numos INIT(0);
    421 EXT int numxes INIT(0);
    422 EXT int ient;
    423 EXT int numents;
    424 EXT int ibase;
    425 EXT int numbases;
    426 EXT int inuminhab;
    427 EXT int numinhab;
    428 EXT int wave;
    429 EXT int cumsmarts;
    430 EXT int prescene INIT(-1);
    431 EXT int scandist;
    432 EXT int antibase;
    433 EXT int sm35;
    434 EXT int sm45;
    435 EXT int sm50;
    436 EXT int sm55;
    437 EXT int sm80;
    438 EXT int sm95;
    439 EXT int entmax;
    440 EXT int basemax;
    441 EXT int enemshields;
    442 EXT int super;
    443 EXT int whenok;
    444 EXT int yamblast;
    445 EXT int xamblast;
    446 EXT int ambsize;
    447 
    448 EXT char spbuf[512];
    449 
    450 char *index(), *ttyname(), *malloc(), *ctime(), *strcpy();
    451 char *getenv(), cmstore(), *tgoto();
    452 long atol();
    453 
    454 #define Fclose (void)fclose
    455 #define Fflush (void)fflush
    456 #define Fgets (void)fgets
    457 #define Sprintf (void)sprintf
    458 #define Signal (void)signal
    459 #define Safecpy (void)safecpy
    460 #define Cpytill (void)cpytill
    461 #define Tract (void)tract
    462 #define Make_object (void)make_object
    463 #define Read_tty (void)read_tty
    464