ejb@think.ARPA (Erik Bailey) (05/15/86)
As per request, here are parts 4 & 5. People, if you have had problems, or are missing parts to: GALAXY, WAR, or DPY, *please* mail me at: !ihnp4!think!ejb or ejb@think.com... This is FAR better than posting gripes to the net. --Erik Bailey ------------------------rock&roll!--------------------------- #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # Makefile # READ_ME # constants.h # edscore.c # galaxy.csh # galaxy.motd # local.c # okgalaxy.c # pager.c # safe # score.h # This archive created: Sat Jun 8 13:51:28 1985 echo shar: extracting Makefile '(774 characters)' cat << \SHAR_EOF > Makefile # # %W% (mrdch&amnnon) %E% # LIBDIR = /usr/games/lib/galaxy GAMES = /usr/games MV = /bin/mv CFLAGS = -O -s all: okgalaxy pager local edscore okgalaxy: okgalaxy.c cc ${CFLAGS} -o okgalaxy okgalaxy.c pager: pager.c cc ${CFLAGS} -o pager pager.c local: local.c cc ${CFLAGS} -o local local.c edscore: edscore.c constants.h score.h cc $(CFLAGS) -o edscore edscore.c .DEFAULT: sccs get $@ clean: /bin/rm okgalaxy pager local edscore install: all chuser galaxy okgalaxy pager local edscore galaxy.motd galaxy.csh chmod 755 galaxy.csh cp okgalaxy pager local edscore ${LIBDIR} chmod 4111 ${LIBDIR}/okgalaxy cp galaxy.motd ${LIBDIR} cp galaxy.csh ${GAMES}/galaxy SHAR_EOF if test 774 -ne "`wc -c Makefile`" then echo shar: error transmitting Makefile '(should have been 774 characters)' fi echo shar: extracting READ_ME '(498 characters)' cat << \SHAR_EOF > READ_ME This directory holds the service programs, used by galaxy. The make will make it all. Read before using. Some remarks: "galaxy.csh" is the front end of the whole game. It enables posting of some remarks through a motd file in /users/games/lib/galaxy. "edscore" enables paging through the score file for editing purpose. Use whenever necessary. "okgalxy","pager" and "local" are programs to establish communication when the game starts. mrdch & amnnon SHAR_EOF if test 498 -ne "`wc -c READ_ME`" then echo shar: error transmitting READ_ME '(should have been 498 characters)' fi echo shar: extracting constants.h '(3763 characters)' cat << \SHAR_EOF > constants.h /* * %W% (mrdch&amnnon) %E% */ /* * this file contains all the constants used by the game. */ # define HOME "/usr/games/lib/galaxy/" # define LOCAL "/usr/games/lib/galaxy/local" # define WIZFIL "/usr/games/lib/galaxy/wizards" # define LOGFIL "/usr/games/lib/galaxy/galaxy.log" # define SAVEFIL "/usr/games/lib/galaxy/galaxy.save" # define SAVETMP "/usr/games/lib/galaxy/galaxy.tmp" # define GALSCOR "/usr/games/lib/galaxy/galaxy.scor" # define PAGER "/usr/games/lib/galaxy/pager" # define ESPSIZ 8 /* max nesting of espionage */ # define MAXSHIPS 7 /* how many types of ships */ # define MAXPL 91 /* how many planets are there */ # define PLKINDS 5 /* how many kinds of planets */ # define MAXCHAN 2 /* maximum no. of chanels to open */ # define NCREW 64 /* no. of fighters in A-type HAWK */ # define VISITORS 128 /* no. of additional people */ # define MSGSIZ 150 /* max chars in a single masseg */ # define CLASES 6 /* how many clases of people */ # define FIGT 0 /* fighters */ # define CITI 1 /* citizens */ # define SCIE 2 /* scientists */ # define BUIL 3 /* builders */ # define MINE 4 /* miners */ # define SLAV 5 /* slaves */ # define ESPTYP 7 /* different types of espionage:*/ # define ESPKIND 0 /* what kind of planet is it */ # define ESPPOP 1 /* how many people are there */ # define ESPKNOW 2 /* what is the knowledge level */ # define ESPMTL 3 /* how much metal was digged out*/ # define ESPSHIP 4 /* what are the forces there */ # define ESPALM 5 /* how many ALM were installed */ # define ESPMSL 6 /* how many missiles are there */ # define BUILD_MONEY 0 /* MONEY given to build ships */ # define LEVEL 1 /* the LEVEL of ships ordered build */ # define NSHIPS 2 /* the NO. of ships ordered build */ # define N_PSI 20 /* max possible messages on screen */ # define ALMCOST 100 /* how much costs 1 ALM */ # define REMOVE_COST 50 /* to remove one if yours */ # define ALM_KILL_COST 200 /* to remove from the enemy's planet */ # define YEARLENGTH 180 /* a turn is 3 min. */ # define PERC_TRADE 10 /* the minimum % of profit in trade */ # define PERC_POPUL 10 /* the % of natural growth */ # define FEED_RATIO 100 /* no. people fed by 1 teller a year*/ # define MINING_FACTOR 100 /* years_manpower 1A metals */ # define KNOW_FACTOR 1000 /* years_manpower to raise 1 level */ # define SHIP_COST 100 /* basic cost factor to build ship */ # define MISSILE_COST 400 /* to put a A-type missile */ # define REDUCE_RATE 10 /* detecting lost effect % in a year */ # define FADE_RATE 25 /* undetection paint fading rate */ # define MIN_ESP 100 /* the minimum to report ANYTHING */ # define KIND_ESP MIN_ESP /* to find out the planet's type */ # define POPUL_ESP 5*MIN_ESP /* for it's population */ # define KNOW_ESP 3*MIN_ESP /* the level of knowledge there */ # define METAL_ESP 2*MIN_ESP /* how much metal has he */ # define FORCE_ESP 10*MIN_ESP /* what are his forces there */ # define ALM_ESP 2*MIN_ESP /* how many alms he's got */ # define MSL_ESP 8*MIN_ESP /* how many missiles he set there */ SHAR_EOF if test 3763 -ne "`wc -c constants.h`" then echo shar: error transmitting constants.h '(should have been 3763 characters)' fi echo shar: extracting edscore.c '(1888 characters)' cat << \SHAR_EOF > edscore.c /* * %W% (mrdch&amnnon) %E% */ # include <sys/types.h> # include "constants.h" # include "score.h" # include <stdio.h> char *tmpf = "/usr/games/lib/galaxy/scoreXXXXXX"; char *ctime (); int tmp, sc; main () { struct score s; char c; long time(); sc = open (GALSCOR, 0); if (sc < 0) { perror (GALSCOR); exit (1); } tmp = creat (mktemp (tmpf), 0600); if (tmp < 0) { perror (tmpf); exit (1); } while (read (sc, &s, sizeof (s)) == sizeof (s)) { if (c != 'q') { char *str, *index (); str = ctime (&s.played_at); *index (str, '\n') = '\0'; printf ("%s,%s %d %s ", s.win, s.los, s.years, str); c = getchar (); if (c != '\n') while (getchar () != '\n'); } switch (c) { case 'd': break; case 'q': default: write (tmp, &s, sizeof (s)); break; case 'a': write (tmp, &s, sizeof (s)); printf("winner ? "); gets(s.win); printf("looser ? "); gets(s.los); printf("years ? "); rint(&s.years); s.played_at = time(0); write(tmp, &s, sizeof(s)); break; } } if (unlink (GALSCOR) < 0) { fprintf (stderr, "unlink "); perror (GALSCOR); exit (1); } if (link (tmpf, GALSCOR) < 0) { fprintf (stderr, "link "); perror (GALSCOR); exit (1); } if (unlink (tmpf) < 0) { fprintf (stderr, "unlink "); perror (tmpf); exit (1); } exit (0); } rint(i) int *i; { char s[100]; gets(s); *i = atoi(s); } SHAR_EOF if test 1888 -ne "`wc -c edscore.c`" then echo shar: error transmitting edscore.c '(should have been 1888 characters)' fi echo shar: extracting galaxy.csh '(158 characters)' cat << \SHAR_EOF > galaxy.csh #! /bin/csh -f # # %W% (mrdch&amnnon) %E% # set motd = "/usr/games/lib/galaxy/galaxy.motd" if ( -e $motd) cat $motd /usr/games/lib/galaxy/galaxy.out $argv SHAR_EOF if test 158 -ne "`wc -c galaxy.csh`" then echo shar: error transmitting galaxy.csh '(should have been 158 characters)' fi echo shar: extracting galaxy.motd '(214 characters)' cat << \SHAR_EOF > galaxy.motd Wellcome to the Universe of Galaxies!!! If that's your first time to try galaxy, I hope you have read the manual first. If not, hit 'del' to exit and then do 'man galaxy'. Enjoy your journey!!! SHAR_EOF if test 214 -ne "`wc -c galaxy.motd`" then echo shar: error transmitting galaxy.motd '(should have been 214 characters)' fi echo shar: extracting local.c '(421 characters)' cat << \SHAR_EOF > local.c /* * %W% (mrdch&amnnon) %E% */ # include <stdio.h> struct chan { int ichan ; char c ; } ; main(ac, av) int ac ; char **av ; { struct chan c ; if(ac != 2) exit(1) ; c.ichan = atoi(av[1]) ; while(!feof(stdin)) { c.c = getchar() ; write(1, (char *)&c, sizeof(c)) ; } exit(0) ; } SHAR_EOF if test 421 -ne "`wc -c local.c`" then echo shar: error transmitting local.c '(should have been 421 characters)' fi echo shar: extracting okgalaxy.c '(804 characters)' cat << \SHAR_EOF > okgalaxy.c /* * %W% (mrdch&amnnon) %E% */ # include <stdio.h> # include <signal.h> # include <sys/types.h> # include <sys/stat.h> struct stat stbuf ; char *tty ; main() { char *ttyname() ; int doexit() ; tty = ttyname(0) ; if(tty == 0) { fprintf(stderr, "Don't know you.\n") ; exit(1) ; } stat(tty, &stbuf) ; signal(SIGINT, doexit) ; signal(SIGQUIT, doexit) ; signal(SIGTSTP, doexit) ; if(chmod(tty, 0666) == -1) { fprintf(stderr, "Your tty ain't yours.\n") ; exit(1) ; } printf("Please wait.....") ; fflush(stdout) ; pause() ; } doexit() { chmod(tty, stbuf.st_mode) ; exit(0) ; } SHAR_EOF if test 804 -ne "`wc -c okgalaxy.c`" then echo shar: error transmitting okgalaxy.c '(should have been 804 characters)' fi echo shar: extracting pager.c '(563 characters)' cat << \SHAR_EOF > pager.c /* * %W% (mrdch&amnnon) %E% */ # include <stdio.h> main(ac, av) int ac ; char **av ; { FILE *tty ; if(ac != 3) getout("arg count") ; tty = fopen(av[1], "w") ; if(tty == NULL) getout("cannot open terminal") ; fprintf(tty, "\07\07%s would like to play galaxy with you.\n\r",av[2]) ; fprintf(tty, "\07\07If you wish to play exec /usr/games/okgalaxy\n\r") ; exit(0) ; } getout(s) char *s ; { fprintf(stderr, "pager: %s.\n", s) ; exit(1) ; } SHAR_EOF if test 563 -ne "`wc -c pager.c`" then echo shar: error transmitting pager.c '(should have been 563 characters)' fi echo shar: creating directory safe mkdir safe chdir safe echo shar: extracting Makefile '(768 characters)' cat << \SHAR_EOF > Makefile # # %W% (mrdch&amnnon) %E% # LIBDIR = /usr/games/lib/galaxy GAMES = /usr/games MV = /bin/mv CFLAGS = -O -s all: okgalaxy pager local edscore okgalaxy: okgalaxy.c cc ${CFLAGS} -o okgalaxy okgalaxy.c pager: pager.c cc ${CFLAGS} -o pager pager.c local: local.c cc ${CFLAGS} -o local local.c edscore: edscore.c constants.h score.h cc $(CFLAGS) -o edscore edscore.c .DEFAULT: sccs get $@ clean: /bin/rm okgalaxy pager local edscore install: all chuser galaxy okgalaxy pager local edscore galaxy.motd galaxy.csh chmod 755 galaxy.csh cp okgalaxy pager local edscore ${LIBDIR} chmod 4111 ${LIBDIR}/okgalaxy cp galaxy.motd ${LIBDIR} cp galaxy.csh ${GAMES} SHAR_EOF if test 768 -ne "`wc -c Makefile`" then echo shar: error transmitting Makefile '(should have been 768 characters)' fi echo shar: extracting READ_ME '(498 characters)' cat << \SHAR_EOF > READ_ME This directory holds the service programs, used by galaxy. The make will make it all. Read before using. Some remarks: "galaxy.csh" is the front end of the whole game. It enables posting of some remarks through a motd file in /users/games/lib/galaxy. "edscore" enables paging through the score file for editing purpose. Use whenever necessary. "okgalxy","pager" and "local" are programs to establish communication when the game starts. mrdch & amnnon SHAR_EOF if test 498 -ne "`wc -c READ_ME`" then echo shar: error transmitting READ_ME '(should have been 498 characters)' fi echo shar: extracting constants.h '(3763 characters)' cat << \SHAR_EOF > constants.h /* * %W% (mrdch&amnnon) %E% */ /* * this file contains all the constants used by the game. */ # define HOME "/usr/games/lib/galaxy/" # define LOCAL "/usr/games/lib/galaxy/local" # define WIZFIL "/usr/games/lib/galaxy/wizards" # define LOGFIL "/usr/games/lib/galaxy/galaxy.log" # define SAVEFIL "/usr/games/lib/galaxy/galaxy.save" # define SAVETMP "/usr/games/lib/galaxy/galaxy.tmp" # define GALSCOR "/usr/games/lib/galaxy/galaxy.scor" # define PAGER "/usr/games/lib/galaxy/pager" # define ESPSIZ 8 /* max nesting of espionage */ # define MAXSHIPS 7 /* how many types of ships */ # define MAXPL 91 /* how many planets are there */ # define PLKINDS 5 /* how many kinds of planets */ # define MAXCHAN 2 /* maximum no. of chanels to open */ # define NCREW 64 /* no. of fighters in A-type HAWK */ # define VISITORS 128 /* no. of additional people */ # define MSGSIZ 150 /* max chars in a single masseg */ # define CLASES 6 /* how many clases of people */ # define FIGT 0 /* fighters */ # define CITI 1 /* citizens */ # define SCIE 2 /* scientists */ # define BUIL 3 /* builders */ # define MINE 4 /* miners */ # define SLAV 5 /* slaves */ # define ESPTYP 7 /* different types of espionage:*/ # define ESPKIND 0 /* what kind of planet is it */ # define ESPPOP 1 /* how many people are there */ # define ESPKNOW 2 /* what is the knowledge level */ # define ESPMTL 3 /* how much metal was digged out*/ # define ESPSHIP 4 /* what are the forces there */ # define ESPALM 5 /* how many ALM were installed */ # define ESPMSL 6 /* how many missiles are there */ # define BUILD_MONEY 0 /* MONEY given to build ships */ # define LEVEL 1 /* the LEVEL of ships ordered build */ # define NSHIPS 2 /* the NO. of ships ordered build */ # define N_PSI 20 /* max possible messages on screen */ # define ALMCOST 100 /* how much costs 1 ALM */ # define REMOVE_COST 50 /* to remove one if yours */ # define ALM_KILL_COST 200 /* to remove from the enemy's planet */ # define YEARLENGTH 180 /* a turn is 3 min. */ # define PERC_TRADE 10 /* the minimum % of profit in trade */ # define PERC_POPUL 10 /* the % of natural growth */ # define FEED_RATIO 100 /* no. people fed by 1 teller a year*/ # define MINING_FACTOR 100 /* years_manpower 1A metals */ # define KNOW_FACTOR 1000 /* years_manpower to raise 1 level */ # define SHIP_COST 100 /* basic cost factor to build ship */ # define MISSILE_COST 400 /* to put a A-type missile */ # define REDUCE_RATE 10 /* detecting lost effect % in a year */ # define FADE_RATE 25 /* undetection paint fading rate */ # define MIN_ESP 100 /* the minimum to report ANYTHING */ # define KIND_ESP MIN_ESP /* to find out the planet's type */ # define POPUL_ESP 5*MIN_ESP /* for it's population */ # define KNOW_ESP 3*MIN_ESP /* the level of knowledge there */ # define METAL_ESP 2*MIN_ESP /* how much metal has he */ # define FORCE_ESP 10*MIN_ESP /* what are his forces there */ # define ALM_ESP 2*MIN_ESP /* how many alms he's got */ # define MSL_ESP 8*MIN_ESP /* how many missiles he set there */ SHAR_EOF if test 3763 -ne "`wc -c constants.h`" then echo shar: error transmitting constants.h '(should have been 3763 characters)' fi echo shar: extracting edscore.c '(1888 characters)' cat << \SHAR_EOF > edscore.c /* * %W% (mrdch&amnnon) %E% */ # include <sys/types.h> # include "constants.h" # include "score.h" # include <stdio.h> char *tmpf = "/usr/games/lib/galaxy/scoreXXXXXX"; char *ctime (); int tmp, sc; main () { struct score s; char c; long time(); sc = open (GALSCOR, 0); if (sc < 0) { perror (GALSCOR); exit (1); } tmp = creat (mktemp (tmpf), 0600); if (tmp < 0) { perror (tmpf); exit (1); } while (read (sc, &s, sizeof (s)) == sizeof (s)) { if (c != 'q') { char *str, *index (); str = ctime (&s.played_at); *index (str, '\n') = '\0'; printf ("%s,%s %d %s ", s.win, s.los, s.years, str); c = getchar (); if (c != '\n') while (getchar () != '\n'); } switch (c) { case 'd': break; case 'q': default: write (tmp, &s, sizeof (s)); break; case 'a': write (tmp, &s, sizeof (s)); printf("winner ? "); gets(s.win); printf("looser ? "); gets(s.los); printf("years ? "); rint(&s.years); s.played_at = time(0); write(tmp, &s, sizeof(s)); break; } } if (unlink (GALSCOR) < 0) { fprintf (stderr, "unlink "); perror (GALSCOR); exit (1); } if (link (tmpf, GALSCOR) < 0) { fprintf (stderr, "link "); perror (GALSCOR); exit (1); } if (unlink (tmpf) < 0) { fprintf (stderr, "unlink "); perror (tmpf); exit (1); } exit (0); } rint(i) int *i; { char s[100]; gets(s); *i = atoi(s); } SHAR_EOF if test 1888 -ne "`wc -c edscore.c`" then echo shar: error transmitting edscore.c '(should have been 1888 characters)' fi echo shar: extracting galaxy.csh '(158 characters)' cat << \SHAR_EOF > galaxy.csh #! /bin/csh -f # # %W% (mrdch&amnnon) %E% # set motd = "/usr/games/lib/galaxy/galaxy.motd" if ( -e $motd) cat $motd /usr/games/lib/galaxy/galaxy.out $argv SHAR_EOF if test 158 -ne "`wc -c galaxy.csh`" then echo shar: error transmitting galaxy.csh '(should have been 158 characters)' fi echo shar: extracting galaxy.motd '(214 characters)' cat << \SHAR_EOF > galaxy.motd Wellcome to the Universe of Galaxies!!! If that's your first time to try galaxy, I hope you have read the manual first. If not, hit 'del' to exit and then do 'man galaxy'. Enjoy your journey!!! SHAR_EOF if test 214 -ne "`wc -c galaxy.motd`" then echo shar: error transmitting galaxy.motd '(should have been 214 characters)' fi echo shar: extracting local.c '(421 characters)' cat << \SHAR_EOF > local.c /* * %W% (mrdch&amnnon) %E% */ # include <stdio.h> struct chan { int ichan ; char c ; } ; main(ac, av) int ac ; char **av ; { struct chan c ; if(ac != 2) exit(1) ; c.ichan = atoi(av[1]) ; while(!feof(stdin)) { c.c = getchar() ; write(1, (char *)&c, sizeof(c)) ; } exit(0) ; } SHAR_EOF if test 421 -ne "`wc -c local.c`" then echo shar: error transmitting local.c '(should have been 421 characters)' fi echo shar: extracting okgalaxy.c '(804 characters)' cat << \SHAR_EOF > okgalaxy.c /* * %W% (mrdch&amnnon) %E% */ # include <stdio.h> # include <signal.h> # include <sys/types.h> # include <sys/stat.h> struct stat stbuf ; char *tty ; main() { char *ttyname() ; int doexit() ; tty = ttyname(0) ; if(tty == 0) { fprintf(stderr, "Don't know you.\n") ; exit(1) ; } stat(tty, &stbuf) ; signal(SIGINT, doexit) ; signal(SIGQUIT, doexit) ; signal(SIGTSTP, doexit) ; if(chmod(tty, 0666) == -1) { fprintf(stderr, "Your tty ain't yours.\n") ; exit(1) ; } printf("Please wait.....") ; fflush(stdout) ; pause() ; } doexit() { chmod(tty, stbuf.st_mode) ; exit(0) ; } SHAR_EOF if test 804 -ne "`wc -c okgalaxy.c`" then echo shar: error transmitting okgalaxy.c '(should have been 804 characters)' fi echo shar: extracting pager.c '(563 characters)' cat << \SHAR_EOF > pager.c /* * %W% (mrdch&amnnon) %E% */ # include <stdio.h> main(ac, av) int ac ; char **av ; { FILE *tty ; if(ac != 3) getout("arg count") ; tty = fopen(av[1], "w") ; if(tty == NULL) getout("cannot open terminal") ; fprintf(tty, "\07\07%s would like to play galaxy with you.\n\r",av[2]) ; fprintf(tty, "\07\07If you wish to play exec /usr/games/okgalaxy\n\r") ; exit(0) ; } getout(s) char *s ; { fprintf(stderr, "pager: %s.\n", s) ; exit(1) ; } SHAR_EOF if test 563 -ne "`wc -c pager.c`" then echo shar: error transmitting pager.c '(should have been 563 characters)' fi echo shar: extracting score.h '(436 characters)' cat << \SHAR_EOF > score.h /* * %W% (mrdch&amnnon) %E% */ /* * this file defines the score information structure. */ struct score /* score log structure */ { char win[20] ; /* winner name */ char los[20] ; /* looser name */ int years ; /* game years played */ time_t played_at ; /* date played at */ } ; SHAR_EOF if test 436 -ne "`wc -c score.h`" then echo shar: error transmitting score.h '(should have been 436 characters)' fi echo shar: done with directory safe chdir .. echo shar: extracting score.h '(436 characters)' cat << \SHAR_EOF > score.h /* * %W% (mrdch&amnnon) %E% */ /* * this file defines the score information structure. */ struct score /* score log structure */ { char win[20] ; /* winner name */ char los[20] ; /* looser name */ int years ; /* game years played */ time_t played_at ; /* date played at */ } ; SHAR_EOF if test 436 -ne "`wc -c score.h`" then echo shar: error transmitting score.h '(should have been 436 characters)' fi # End of shell archive exit 0 -- Erik Bailey -- 7 Oak Knoll (USENET courtesy of ihnp4!think!ejb Arlington, MA 02174 Thinking Machines Corp. ejb@think.com (617) 643-0732 Cambridge, MA) It takes thought to make a program that thinks. But it takes work to make a program that works.