ejb@think.ARPA (Erik Bailey) (04/24/86)
#!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # Makefile # assign.c # best_score.c # blackout.c # build.c # constants.h # detect_mv.c # end_game.c # feed_pop.c # funcdef.h # global.c # global.h # header # This archive created: Sat Jun 8 12:55:14 1985 echo shar: extracting Makefile '(2103 characters)' cat << \SHAR_EOF > Makefile # Galaxy Makefile. # SccsId %W% (mrdch&amnnon) %G% # LIBDIR = /usr/games/lib/galaxy CFILES = assign.c blackout.c build.c detect_mv.c feed_pop.c \ global.c init_all.c kill_alm.c leave_at.c \ move_to.c no_detect.c over_stat.c parse.c planet_enq.c \ planet_inf.c planet_sit.c play.c put_alm.c \ retrieve.c softclock.c take_from.c term2init.c trade.c \ use_term.c wizard.c write.c end_game.c \ savegame.c terminal.c set_missle.c best_score.c OFILES = assign.o blackout.o build.o detect_mv.o feed_pop.o \ global.o init_all.o kill_alm.o leave_at.o \ move_to.o no_detect.o over_stat.o parse.o planet_enq.o \ planet_inf.o planet_sit.o play.o put_alm.o \ retrieve.o softclock.o take_from.o term2init.o trade.o \ use_term.o wizard.o write.o end_game.o \ savegame.o terminal.o set_missle.o best_score.o HEADERS = header constants.h funcdef.h global.h typedefs.h options.h \ score.h table.h SOURCEDIR = . LDFLAGS = CC = /bin/cc RM = /bin/rm CTAGS = /usr/ucb/ctags GET = /usr/bin/sccs get -s PR = /bin/pr LPR = /usr/bin/lpr ECHO = /bin/echo MV = /bin/mv TAR = /bin/tar all : galaxy @${ECHO} Galaxy is up to date. galaxy : ${OFILES} ${CC} ${LDFLAGS} ${OFILES} -ltermlib @${MV} a.out galaxy tags : ${CFILES} ${HEADERS} ${CTAGS} ${CFILES} ${HEADERS} clean : sccs info ${RM} -f ${OFILES} lpr : ${PR} ${HEADERS} ${CFILES} | ${LPR} ${OFILES} : ${HEADERS} .PRECIOUS: ${CFILES} ${HEADERS} .DEFAULT: ${CFILES} ${HEADERS} ${GET} $@ install: cp galaxy ${LIBDIR} mv ${LIBDIR}/galaxy ${LIBDIR}/galaxy.out chmod 700 ${LIBDIR}/galaxy.out ${LIBDIR}/okgalaxy chmod 4111 ${LIBDIR}/galaxy.out ${LIBDIR}/okgalaxy liblock: chmod 700 ${LIBDIR}/galaxy.out ${LIBDIR}/okgalaxy libok: chmod 4111 ${LIBDIR}/galaxy.out ${LIBDIR}/okgalaxy tar : ${TAR} cv ${SOURCEDIR} backup : ${TAR} cv /users/guest/galaxy SHAR_EOF if test 2103 -ne "`wc -c Makefile`" then echo shar: error transmitting Makefile '(should have been 2103 characters)' fi echo shar: extracting assign.c '(1760 characters)' cat << \SHAR_EOF > assign.c /* * %W% (mrdch&amnnon) %G% */ # include "header" extern int work_p[MAXPL][CLASES];/* change actual working class */ assign (s) char *s; { planet * pp; int i, focup, socup; char fc, sc; pp = getpl (s); /* identify planet */ assert_player (pp); /* justify planet & owner */ i = atoi (s); /* how many people are concerned */ assert_number (i); /* justify no. */ skipword (s); /* go to the first occupation */ fc = *s++; /* take the first char */ skipwhite (s); /* go to the second */ sc = *s++; /* take the second */ assert_end (s); /* see if end is clear */ if (fc == sc) { say ("It will not change much, my lord !!"); return; } focup = which_class (fc); assert_occup (focup); /* does it exist?? */ if (pp -> inventar.popul[focup] < i) { say ("But sir, you don't have that many %s at %s!!!", ocup_name[focup], pp -> pid); return; } socup = which_class (sc); assert_occup (socup); /* does the second exist?? */ if (focup == SLAV || socup == SLAV) { say ("Slaves cannot be assigned or reassigned, my lord!!"); return; } /* here perform the actual assignment */ pp -> inventar.popul[focup] -= i; pp -> inventar.popul[socup] += i; say ("The people are reassigned and ready, my lord."); for (i = 0; i < MAXPL; i++) if (pp -> pid == pl[i].pid)/* find the corresponding no. */ break; work_p[i][focup] = pp -> inventar.popul[focup]; return; } SHAR_EOF if test 1760 -ne "`wc -c assign.c`" then echo shar: error transmitting assign.c '(should have been 1760 characters)' fi echo shar: extracting best_score.c '(7505 characters)' cat << \SHAR_EOF > best_score.c /* * %W% (mrdch&amnnon) %G% */ /* * this program displays best scores ( optional all ) from the score * file. * options: * -t 10 best winners and related stat. * -a all scores sorted by time. * -m only my games. * user only `user''s games. */ # include <sys/types.h> # include <sys/stat.h> # include "score.h" # include "constants.h" struct reslts { char namepl[20] ; int nwon ; int nlost ; int nyears ; }; int n_entries ; struct score *entries ; struct reslts *uprslts ; glxscore(ac, av) int ac ; char **av ; { struct stat stbuf ; char *malloc() ; int fd ; register int i ; struct reslts *scrpn ; char *getlogin(); if(stat(GALSCOR, &stbuf) == -1) { print("No score file.\n\r") ; return; } n_entries = stbuf.st_size / sizeof(struct score) ; if((n_entries * sizeof(struct score)) != stbuf.st_size) { print("Ill formatted score file.\n\r") ; return; } entries = (struct score *) malloc(stbuf.st_size) ; uprslts = (struct reslts *) malloc(n_entries * sizeof(struct reslts)) ; if(entries == 0 || uprslts == 0) { print("cannot allocate entry space.\n\r") ; return; } scrpn = uprslts ; for (i = 0 ; i < n_entries ; i++ ,scrpn++ ) { scrpn->nwon = 0 ; scrpn->nlost = 0 ; scrpn->nyears = 0 ; } fd = open(GALSCOR, 0) ; if(fd == -1) { perror(GALSCOR) ; return; } if(read(fd, (char *) entries, stbuf.st_size) != stbuf.st_size) { perror("read error") ; return; } ac-- , av++ ; for(i = 0 ; i < ac ; i++) { if(av[i][0] == '-') switch(av[i][1]) { case 't' : dispbest(10) ; break; case 'a' : dispall() ; break ; case 'm' : dispuser(getlogin()) ; break ; default : print("unknown option.\n\r") ; return; } else dispuser(av[i]) ; } } dispuser(plname) char *plname ; { struct reslts *scrpn ; int i, nply ; nply = findbest() ; scrpn = uprslts ; for (i = 0 ; i < nply ; i++ ,scrpn++) if (strcmp(scrpn->namepl , plname) == 0) break ; if ( i == nply ) { print("\n\rIt seems that %s never played galaxy. Poor man...\n\r",plname) ; return; } print("\n\rThe GALAXY results for %s are:\n\r",plname) ; print("==================================\n\r") ; print("Games won: %d\tGames lost: %d\tTotal years played: %d\n\r\n\r", scrpn->nwon, scrpn->nlost, scrpn->nyears) ; print("This is the complete list:\n\r") ; print("\n\rWinner\tLooser\tYears\tWinning date and time\n\r") ; print("------------------------------------------------\n\r") ; for ( i = 0 ; i < n_entries ; i++ ) { if (strcmp(plname , entries[i].win) == 0 ) dispentr(i) ; if(strcmp (plname , entries[i].los) == 0 ) dispentr(i) ; } } dispbest(nbest) { struct reslts *scrpn ; int i, nply; nply = findbest() ; scrpn = uprslts ; print("\n\r******************************************************") ; print("\n\r\t\tBest players in GALAXY game\n\r") ; print("******************************************************\n\r\n\r") ; print("Rank\tPlayer\tWon\tLost\tYears\tScore\n\r") ; print("----------------------------------------------\n\r") ; for (i = 0 ; i < nbest && i < nply ; i++, scrpn++) print("%d\t%s\t%3d\t%3d\t%3d\t%3d\n\r",i+1, scrpn->namepl, scrpn->nwon, scrpn->nlost, scrpn->nyears, 2*scrpn->nwon - scrpn->nlost) ; print("\n\r") ; } findbest() { int i, j, k , p_players ; int which ; int qcmp() ; i = 0 ; p_players = 0 ; for(i = 0 ; i < n_entries ; i++) { if ( strcmp(entries[i].win , "-null") == 0 ) continue ; if ( strcmp(entries[i].los , "-null") == 0 ) continue ; if ( strcmp(entries[i].los , entries[i].win) == 0 ) continue ; which = -1 ; for (j = 0 ; j < p_players ; j++ ) { if (strcmp(uprslts[j].namepl,entries[i].win) == 0 ) { which = j ; } } if (which != -1) updt_res(i,1,which) ; else add_player(i,1,p_players++) ; which = -1 ; for (j = 0 ; j < p_players ; j++ ) { if(strcmp (uprslts[j].namepl,entries[i].los) == 0 ) { which = j ; } } if (which != -1) updt_res(i,0,which ) ; else add_player(i,0,p_players++) ; } qsort(uprslts, p_players, sizeof uprslts[0], qcmp); return(p_players) ; } add_player(at_entry,ifwon,new_player) int at_entry; /* where is the player located at entry table */ int ifwon; /* did he win this time */ int new_player; /* pointer to the new players entry */ { if (ifwon) strcpy(uprslts[new_player].namepl,entries[at_entry].win); else strcpy(uprslts[new_player].namepl,entries[at_entry].los); updt_res(at_entry,ifwon,new_player) ; } updt_res(i,winner,player) { uprslts[player].nwon += winner ; uprslts[player].nlost += !winner ; uprslts[player].nyears += entries[i].years ; } qcmp(p1,p2) struct reslts *p1 ,*p2 ; { return((2*p2->nwon - p2->nlost) - (2*p1->nwon - p1->nlost ) ) ; } dispall() { register int i ; print("\n\r******************************************************") ; print("\n\r\tThe complete list of the GALAXY games\n\r") ; print("******************************************************\n\r") ; print("\n\rWinner\tLooser\tYears\tWinning date and time\n\r") ; print("------------------------------------------------\n\r") ; for(i = 0 ; i < n_entries ; i++) dispentr(i) ; } dispentr(i) { char *ctime(); print("%s\t%s\t%d\t%s", entries[i].win, entries[i].los, entries[i].years, ctime(&entries[i].played_at)) ; } SHAR_EOF if test 7505 -ne "`wc -c best_score.c`" then echo shar: error transmitting best_score.c '(should have been 7505 characters)' fi echo shar: extracting blackout.c '(726 characters)' cat << \SHAR_EOF > blackout.c /* * %W% (mrdch&amnnon) %G% */ # include "header" blackout (s) char *s; { planet * pp; int i; pp = getpl (s); /* get planet id */ assert_player (pp); /* see if legal planet + owner */ skipwhite (s); /* go to the money part */ i = atoi (s); /* take the amount */ assert_money (i); /* see if there is enough of it */ skipword (s); /* skip that no. */ assert_end (s); /* does it end good?? */ pp -> secur += i; /* raise the BLACKOUT */ teller[player] -= i; /* take his money */ } SHAR_EOF if test 726 -ne "`wc -c blackout.c`" then echo shar: error transmitting blackout.c '(should have been 726 characters)' fi echo shar: extracting build.c '(3479 characters)' cat << \SHAR_EOF > build.c /* * %W% (mrdch&amnnon) %G% */ # include "header" /* * In order to build new ships, several requirements have to be met. * The planet on which it is to be build has to be assigned * to Industrial, with some buiders on it. * The knowledge level on that planet has to be at least equal to the * level of ships to be build. The material there has to be * at least equal to 1 ship needed for that level, and money should * be provided. */ build (s) char *s; { planet * pp; int j, factor, nships, ship_type, money; pp = getpl (s); /* get planet id */ assert_player (pp); /* verify existence + owner */ if (!pp -> inventar.popul[BUIL]) { say ("But sir, who will carry out this work??"); return; } skipwhite (s); if (*s == 't') { /* ONLY money is to be added */ s++; skipwhite (s); /* go to the money portion */ money = atoi (s); /* collect the money */ assert_money (money); /* does he own that much?? */ skipword (s); assert_end (s); /* chek now how it ends */ pp -> to_build[BUILD_MONEY] += money; teller[player] -= money; factor = 1; j = pp -> to_build[LEVEL]; while (j-- > 0) factor *= 2; if (pp -> to_build[BUILD_MONEY] >= factor * SHIP_COST) say ("The builders will start right away, sir !!"); else say ("The money won't do for a single ship, sir !!"); return; } nships = atoi (s); /* see how many ships to build */ assert_negative (nships); if (nships) { /* skip the no. chars */ skipnum (s); /* go to the ship type */ skipwhite (s); } else nships = 1; /* if none given, assume 1 */ if (*s < 'a') *s += ('a' - 'A'); /* transform type to l.c. */ if ((*s < 'a') || (*s > 'a' + MAXSHIPS - 1)) { say ("The type of ship is not clear, sir!!"); return; } ship_type = *s - 'a'; if (pp -> to_build[LEVEL] != ship_type && pp -> to_build[NSHIPS]) { say ("But sir, the builders are still working on the previous ships!!"); return; /* CANNOT change LEVEL */ } if (pp -> inventar.know < ship_type) { say ("The knowledge there is insufficient, sir."); return; } factor = 1; j = ship_type; while (j-- > 0) factor *= 2; /* calculate material for X type ship. */ if (pp -> inventar.metals < factor) { say ("The material is insufficient for even one ship, sir."); return; } s++; skipwhite (s); /* go to the money portion */ money = 0; if (*s) { /* probably wants to add money */ money = atoi (s); /* collect it */ assert_money (money); /* see if he owns that much */ skipword (s); /* chek now how it ends */ assert_end (s); } teller[player] -= money; /* take player's money */ pp -> to_build[BUILD_MONEY] += money;/* add to existing */ pp -> to_build[LEVEL] = ship_type; pp -> to_build[NSHIPS] += nships; if (pp -> to_build[BUILD_MONEY] >= factor * SHIP_COST) say ("The builders will start right away, sir !!"); else say ("The money won't do for a single ship, sir !!"); } SHAR_EOF if test 3479 -ne "`wc -c build.c`" then echo shar: error transmitting build.c '(should have been 3479 characters)' fi echo shar: extracting constants.h '(3899 characters)' cat << \SHAR_EOF > constants.h /* * %W% (mrdch&amnnon) %G% */ /* * 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 DOSCORE "/usr/games/lib/galaxy/glxscore" # define ONLINE "/usr/games/lib/galaxy/online/" # 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 5 /* 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 2000 /* 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 3899 -ne "`wc -c constants.h`" then echo shar: error transmitting constants.h '(should have been 3899 characters)' fi echo shar: extracting detect_mv.c '(726 characters)' cat << \SHAR_EOF > detect_mv.c /* * %W% (mrdch&amnnon) %G% */ # include "header" detectmv (s) char *s; { planet * pp; int i; pp = getpl (s); /* get planet id */ assert_player (pp); /* see if legal planet + owner */ skipwhite (s); /* go to the money part */ i = atoi (s); /* take the amount */ assert_money (i); /* see if there is enough of it */ skipword (s); /* skip that no. */ assert_end (s); /* does it end good?? */ pp -> detect += i; /* raise the DETECT */ teller[player] -= i; /* take his money */ } SHAR_EOF if test 726 -ne "`wc -c detect_mv.c`" then echo shar: error transmitting detect_mv.c '(should have been 726 characters)' fi echo shar: extracting end_game.c '(3509 characters)' cat << \SHAR_EOF > end_game.c /* * %W% (mrdch&amnnon) %G% */ # include "header" char s1[] = "We are on our way to a BETTER LAND... let GOD be with us next time."; extern char moreflg[] ; /* * When the game ends, this function is calles to show it * in a rather dramatic way. The looser sees his galaxy vanishing, * while the winner gets a satisfactory view of the galaxy that * transforms to his original sign. */ end_game (winplay) { char winc = '*'; /* the default winning sign */ /* keeps the new coordinates of vanishing planets */ int newcord[2][MAXPL]; int i, j, m, captr; char *ps1 = s1; int line = 19, col; if (winplay) winc = '@'; /* notify the winner */ termn (winplay); if (moreflg[winplay]) endmore() ; cleol (19, 0); disch ('\007'); say ("Sir!!! We won the battle!!! The enemy runs away!!!"); disch ('\007'); (void) fflush (tty); /* notify the looser */ termn (!winplay); if (moreflg[!winplay]) endmore() ; disch ('\007'); say ("Dear sir, we have lost everything. I wish you best luck next time..."); disch ('\007'); cleol (line, 0); /* back to the winner */ termn (winplay); so (19, 20, " Our forces are taking over the two Galaxies..."); (void) fflush (tty); /* and again the looser */ termn (!winplay); for (i = 0; i < MAXPL; i++) { pos (pl[i].coord[0], pl[i].coord[1] + 1); newcord[0][i] = pl[i].coord[0]; newcord[1][i] = pl[i].coord[1] + 1; pl[i].d_symbol[player] = winc; pl[i].d_symbol[!player] = winc; } /* display the comforting line to the looser */ col = 5; so (line--, col, ps1); col += 3; ps1 += 3; /* make it succesivly shorter */ s1[strlen (s1) - 3] = '\0'; for (i = 0; i < MAXPL; i++) { pos (newcord[0][i], newcord[1][i]); disch (winc); pos (newcord[0][i], newcord[1][i] - 1); disch (' '); pos (newcord[0][i], newcord[1][i] + 1); disch (' '); } captr = 0; j = 20; while (j) { if (j < 14 && captr < MAXPL) { termn (winplay); for (m = 0; m < 7; m++) { curse_com (&pl[captr]); captr++; } (void) fflush (tty); termn (!winplay); } if (j % 2) { cleol (line, 0); so (line--, col, ps1); col += 3; ps1 += 3; s1[strlen (s1) - 3] = '\0'; } /* place the vanishing planets in their new position on screen */ for (i = 0; i < MAXPL; i++) { pos (newcord[0][i], newcord[1][i]); disch (' '); if (newcord[0][i] > 8) newcord[0][i]--; else if (newcord[0][i] < 8) newcord[0][i]++; if (newcord[1][i] - 39 >= 2) newcord[1][i] -= 2; else if (newcord[1][i] - 39 == 1) newcord[1][i]--; else if (39 - newcord[1][i] >= 2) newcord[1][i] += 2; else if (39 - newcord[1][i] == 1) newcord[1][i]++; pos (newcord[0][i], newcord[1][i]); disch (winc); (void) fflush (tty); } j--; } (void) fflush (tty); termn (winplay); endgame (winplay); } SHAR_EOF if test 3509 -ne "`wc -c end_game.c`" then echo shar: error transmitting end_game.c '(should have been 3509 characters)' fi echo shar: extracting feed_pop.c '(822 characters)' cat << \SHAR_EOF > feed_pop.c /* * %W% (mrdch&amnnon) %G% */ # include "header" feedpop (s) char *s; { int i, j; i = atoi (s); /* see how much he wants to give */ if (i <= 0) { say ("But sir, please be more generous !!!"); return; } assert_money (i); /* see if he has that much */ skipword (s); assert_end (s); /* does it end properly? */ teller[player] -= i; /* take his money */ food[player] += i; /* and give it to the poors */ j = food[player] * FEED_RATIO; i = count_popul (player) - count_class (player, CITI); if (j > i) /* he gave them more then enough */ say ("Thousands thanks, my lord !!"); else say ("%d of your people might starve to death, my lord.", i - j); } SHAR_EOF if test 822 -ne "`wc -c feed_pop.c`" then echo shar: error transmitting feed_pop.c '(should have been 822 characters)' fi echo shar: extracting funcdef.h '(399 characters)' cat << \SHAR_EOF > funcdef.h /* * %W% (mrdch&amnnon) %G% */ /* * global macros. */ #define skipwhite(s) doskipwhite(&s) #define skipblack(s) doskipblack(&s) #define skipword(s) doskipword(&s) #define skipnum(s) doskipnum(&s) #define getpl(s) dogetpl(&s) #define ishex(a) ((a >= '0' && a <= '9')|| (a >= 'a' && a <= 'f')) #define isnum(a) ((a >= '0' && a <= '9')) #define TWOZERO { 0, 0 } SHAR_EOF if test 399 -ne "`wc -c funcdef.h`" then echo shar: error transmitting funcdef.h '(should have been 399 characters)' fi echo shar: extracting global.c '(9888 characters)' cat << \SHAR_EOF > global.c /* * %W% (mrdch&amnnon) %G% */ # include "header" # define PLANET_H 1000 /* * This file contains little functions, used globaly * in almost all the parsing functions. */ /* LINTLIBRARY */ /*VARARGS1*/ say (a, b, c, d, e, f, g, h, i) char *a; { cleol (23, 10); fprintf (tty, a, b, c, d, e, f, g, h, i); } /*VARARGS1*/ msg (a, b, c, d, e, f, g, h, i) char *a; { pos (21, 10); fprintf (tty, a, b, c, d, e, f, g, h, i); } /*VARARGS1*/ bug (a, b, c, d, e, f, g, h, i) char *a; { fprintf (stderr, a, b, c, d, e, f, g, h, i); fprintf (stderr, "\r\n"); (void) kill (getpid (), 9); endgame (-1); } /*VARARGS1*/ pr_at (line, col, a, b, c, d, e, f, g, h, i) char *a; { pos (line, col); fprintf (tty, a, b, c, d, e, f, g, h, i); } /*VARARGS1*/ print (a, b, c, d, e, f, g, h, i) char *a; { fprintf (tty, a, b, c, d, e, f, g, h, i); } disch (c) char c; { putc (c, tty); } /* A function to skip * spaces, and point to the first NON space */ doskipwhite (s) char **s; { while (isspace (**s) && **s) { skip++; (*s)++; } } /* A function to skip * NON spaces, and point to the first space */ doskipblack (s) char **s; { while (!isspace (**s) && **s) { skip++; (*s)++; } } /* skip a word WITH it's boundries */ doskipword (s) char **s; { doskipwhite (s); doskipblack (s); doskipwhite (s); } /* skip only NUMERICAL. point to the first NON numeric. */ doskipnum (s) char **s; { doskipwhite (s); while (isnum (**s)) { skip++; (*s)++; } } /* * parse a planet name. this set of functions should * return a pointer to the planet structure, given a * planet name. */ planet * planet_list[PLANET_H]; planet * getid (s) char *s; { planet * dogetid (); register planet * pp; char pid[4]; skipwhite (s); strncpy (pid, s, 3); pp = dogetid (pid); if (pp != 0) skip += 3; /* a legal name was found, 3 chars */ return (pp); } /* * hash the planet's name, and if found return the pointer * to it. */ planet * dogetid (s) char *s; { int hval = 0; planet * pl; hval = hash_planet (s); pl = planet_list[hval]; if (pl == 0) return (0); if (strcmp (pl -> pid, s) != 0) return (0); else return (pl); } /* * This hash function should be perfect. No collisions are allowed. */ hash_planet (s) register char *s; { register ac; switch (*s++) { case 'l': ac = 1; break; case 'c': ac = 2; break; case 'r': ac = 3; break; default: bug ("bad arg to hash_planet %s", s-1); } ac *= 16; ac += hexval (*s++); ac *= 16; ac += hexval (*s); return (ac % PLANET_H); } /* * the initialization function for planet's recognization */ init_getid () { register i; register hval; for (i = 0; i < MAXPL; i++) { hval = hash_planet (pl[i].pid); if (planet_list[hval] != 0) bug ("hash function not perfect (init_getid)"); planet_list[hval] = &pl[i]; } capitals[0] = getid ("l00"); capitals[1] = getid ("r00"); } /* * The main function that deals with the planet id * in a given string. */ planet * dogetpl (s) char **s; { register planet * pp; doskipwhite (s); skip = 0; if (ispid (*s)) /* a possibly legal name was given */ pp = getid (*s); /* get the planet's pointer */ else pp = curpln; *s += skip; assert_planet (pp); return (pp); } /* * Check if a given string starts with chars that * possibly represent a planet, and the two other * chars are legal continuations of such name. */ ispid (s) char *s; { switch (*s++) { case 'c': case 'r': case 'l': break; default: return (0); } if (fisnum (*s++)) /* the first must be numeric */ if (fishex (*s++)) /* the second can be hex */ return (1); return (0); } fisnum (a) { return (isnum (a)); } fishex (a) { return (ishex (a)); } hexval (c) int c; { if (isdigit (c)) return (c - '0'); else return (c - 'a' + 10); } /* check if the direction is one allowed */ find_direct (cs) char cs; { int j; switch (cs) { case ',': /* counter-clockwise */ j = 8; break; case '.': /* clockwise */ j = 9; break; case '8': /* north */ j = 0; break; case '6': /* west */ j = 2; break; case '2': /* south */ j = 4; break; case '4': /* east */ j = 6; break; case '9': /* north-east */ j = 1; break; case '3': /* south-east */ j = 3; break; case '1': /* south-west */ j = 5; break; case '7': /* north-west */ j = 7; break; default: j = -1; } return (j); } /* * This function checks if a given planet (parameter) * is TOTALY empty. Returnes 0 if so. */ chek_empty (pp) planet * pp; { int i, j, k, flg = 0; for (i = 0; i < CLASES; i++) { if (pp -> inventar.popul[i]) flg++; if (pp -> to_take.popul[i]) flg++; } if (pp -> inventar.know) flg++; if (pp -> inventar.metals) flg++; if (pp -> to_take.know) flg++; if (pp -> to_take.metals) flg++; if (pp -> secur) flg++; if (pp -> alms) flg++; if (pp -> paint) flg++; if (pp -> detect) flg++; for (i = 0; i < 3; i++) if (pp -> to_build[i]) flg++; if (pp -> reports) flg++; for (i = 0; i < MAXSHIPS; i++) { if (pp -> ships[i]) flg++; if (pp -> missile[i]) flg++; } for (i = 0; i < 2; i++) for (j = 0; j < ESPTYP; j++) for (k = 0; k < ESPSIZ; k++) if (pp -> espion[i][j][k]) flg++; return (flg); } /* * assert functions. One never returns to calling function * if condition is met. */ assert_money (n) { if (n <= 0) { if (iswiz[player] == 1) return; say ("That little money won't do, sir."); longjmp (jparse, 1); } if (iswiz[player] == 1) teller[player] += n; if (n > teller[player]) { say ("You don't have that much money, sir."); longjmp (jparse, 1); } } assert_end (s) char *s; { skipwhite (s); if (*s) { say ("The command's end is not clear, sir."); longjmp (jparse, 1); } } assert_number (n) { if (iswiz[player] == 1) return; if (n == 0) { say ("That will not change much, sir."); longjmp (jparse, 1); } assert_negative (n); } assert_negative (n) { if (iswiz[player] == 1) return; if (n < 0) { say ("Negative number, sir ???"); longjmp (jparse, 1); } } assert_planet (p) planet * p; { if (!p) { say ("I don't know that planet, sir!!"); longjmp (jparse, 1); } } assert_player (p) planet * p; { assert_planet (p); if (iswiz[player] == 1) return; if (p -> whos != player) { say ("Unfortunately, the planet is not yet yours, sir."); longjmp (jparse, 1); } } assert_occup (ocup) { if (ocup < 0) { say ("I don't recognize the occupation, sir."); longjmp (jparse, 1); } } assert_loosing () { say ("So sorry, sir, we have lost them all..."); longjmp (jparse, 1); } /* check if a given planet is a capital */ iscapital (pp) planet * pp; { if (strcmp (pp -> pid, "r00") == 0 || strcmp (pp -> pid, "l00") == 0) return (1); else return (0); } /* * this swich checks for the types of legal ocupations. * It also check for the planet type that was before, * and the planet-type that should be after change will * be made. */ which_class (cc) char cc; { switch (cc) { case 'f': return (FIGT); case 'c': return (CITI); case 's': return (SCIE); case 'b': return (BUIL); case 'm': return (MINE); case 'v': return (SLAV); default: return (-1); /* unrecognized */ } } /* * Function to count the no of population in a given * planet. */ planet_popul (pp) planet * pp; { int i = 0, j; for (j = 0; j < CLASES; j++) i += pp -> inventar.popul[j]; return (i); } /* * returns the total no. of people from a predifined class. */ count_class (j, class) int j, class; { int i, ncount = 0; for (i = 0; i < MAXPL; i++) if (pl[i].whos == j) { ncount += pl[i].inventar.popul[class]; ncount += pl[i].to_take.popul[class]; } return (ncount); } /* * returns the total no. of population of a player. */ count_popul (j) { int i, k, ncount = 0; for (i = 0; i < MAXPL; i++) if (pl[i].whos == j) for (k = 0; k < CLASES; k++) { ncount += pl[i].inventar.popul[k]; ncount += pl[i].to_take.popul[k]; } return (ncount); } SHAR_EOF if test 9888 -ne "`wc -c global.c`" then echo shar: error transmitting global.c '(should have been 9888 characters)' fi echo shar: extracting global.h '(1783 characters)' cat << \SHAR_EOF > global.h /* * %W% (mrdch&amnnon) %G% */ /* * This file contains the definitions of all the * global variables and return value types of functions. */ extern jmp_buf jparse; extern planet * capitals[2]; extern int skip; /* number of chars to skip. */ extern info * info_head[2]; /* linked info head */ extern planet * spntr; /* pointer to current 'star' */ extern planet * apntr; /* pointer to current 'ampers' */ extern planet * curpln; extern FILE * tty; /* We write to this tty */ extern FILE * ttys[]; /* these are the players terminals */ extern int player; /* the current player */ extern int teller[2]; /* the money available to each */ extern int food[2]; /* the money invested in food */ extern int trade[2]; /* the money invested in trade */ extern planet pl[]; /* the planets themselves */ extern char *ocup_name[]; /* the names of the occupations */ extern int chand[MAXCHAN]; extern int year; /* The current year */ extern int iswiz[2]; /* Am i a wizard? */ extern int wants_quit[2]; extern int wants_save[2]; extern int wants_restor[2]; extern int wants_newy[2]; extern int wants_pause[2]; extern int Pause; /* Are we having a break or not */ extern char ply0[100], *ply1; /* the names of the players */ extern int espcost[ESPTYP]; extern char *inftypes[ESPTYP]; extern struct terminal ttycs[2]; extern struct terminal *ttyc; planet * getid (); planet * dogetpl (); /* getpl is a macro */ time_t time (); long lseek (); char *strcpy (); char *sprintf (); char *strcat (); SHAR_EOF if test 1783 -ne "`wc -c global.h`" then echo shar: error transmitting global.h '(should have been 1783 characters)' fi echo shar: extracting header '(329 characters)' cat << \SHAR_EOF > header /* * %W% (mrdch&amnnon) %G% */ /* * this file includes all includes. */ # include <sys/types.h> # include <stdio.h> # include <ctype.h> # include <setjmp.h> # include "constants.h" # include "typedefs.h" # include "funcdef.h" # include "global.h" # include "options.h" SHAR_EOF if test 329 -ne "`wc -c header`" then echo shar: error transmitting header '(should have been 329 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.