ejb@think.ARPA (Erik Bailey) (04/24/86)
#!/bin/sh
# shar: Shell Archiver
# Run the following text with /bin/sh to create:
# planet_enq.c
# planet_inf.c
# planet_sit.c
# play.c
# put_alm.c
# retrieve.c
# savegame.c
# This archive created: Sat Jun 8 13:03:30 1985
echo shar: extracting planet_enq.c '(1689 characters)'
cat << \SHAR_EOF > planet_enq.c
/*
* %W% (mrdch&amnnon) %G%
*/
# include "header"
planetenq (s)
char *s;
{
planet * pp;
int ntellers;
int enqtype;
int enqlvl = 0;
pp = getpl (s);
skipwhite (s);
if (isdigit (*s)) {
enqlvl = *s++ - '0';
/* calculate level of espionage */
if (enqlvl > ESPSIZ) {
say ("Sir, we don't have such level of spies!");
return;
}
skipwhite (s);
}
/* see what subject he wants to enquire */
switch (*s++) {
case 's':
enqtype = ESPKIND;
break;
case 'p':
enqtype = ESPPOP;
break;
case 'k':
enqtype = ESPKNOW;
break;
case 't':
enqtype = ESPMTL;
break;
case 'f':
enqtype = ESPSHIP;
break;
case 'a':
enqtype = ESPALM;
break;
case 'm':
enqtype = ESPMSL;
break;
default:
say ("Our spies don't recognize that kind of info, Sir. ");
return;
}
skipwhite (s);
ntellers = atoi (s);
assert_money (ntellers);
/* see if enough money is available */
teller[player] -= ntellers;
if (pp -> whos == 2) {
if (ntellers >= MIN_ESP) {
say ("The rumors has it that this planet is uninhabited.");
spy_msg ("An empty planet", player, pp, 0);
}
else
say ("But sir, that little money won't bring any information !!!");
return;
}
/* perform actual investment */
pp -> espion[player][enqtype][enqlvl] += ntellers;
say ("The spies are on their way, sir.");
}
SHAR_EOF
if test 1689 -ne "`wc -c planet_enq.c`"
then
echo shar: error transmitting planet_enq.c '(should have been 1689 characters)'
fi
echo shar: extracting planet_inf.c '(15087 characters)'
cat << \SHAR_EOF > planet_inf.c
/*
* %W% (mrdch&amnnon) %G%
*/
# include "header"
/*
* # define CLASES 6
* # define MAXSHIPS 7
* # define ESPTYP 10
* # define ESPSIZ 8
*
* struct _movable
* {
* int popul[CLASES] ;
* int metals ;
* int know ;
* };
*
* struct _planet
* {
* char symbol ;
* char d_symbol[2] ;
* char pid[4] ;
* int coord[2] ;
* planet *gate[10] ;
* int whos ;
* movable inventar ;
* movable to_take ;
* int secur ;
* int alms ;
* int paint ;
* int detect ;
* int to_build[3] ;
* info *reports ;
* int ships[MAXSHIPS] ;
* int espion[2][ESPTYP][ESPSIZ];
* };
*
* Some explanations about the planet structure :
*
* The first field is the char shown on the map: '*', '@' and '#'.
* The second is the char currently displayed at each player term.
* Next is the name . Always three characters + '\0'.
* Next two numbers are the planets' coordinates on the terminal.
* Ten pointers that show aloowed planets to go to.
* The order in which they are initialized is the order of the
* key-pad on the tvi-925.
* 7 8 9
* 4 * 6
* 1 2 3
* <- ->
* Int representing ownership. 0-"*" 1-"@" or 2 (for no-one).
* #### The next 3 items are movable, but belong to a planet. ######
* Next 6 numbers indicate the population, divided to occupation.
* One number shows the amount of metal digged out in A-type quan.
* One number indicating the knowledge level on the planet.
* #### The next 3 items are the storage location for transporting.
* Next 6 numbers indicate the population, divided to occupation.
* One number shows the amount of metal digged out in A-type quan.
* One number indicating the knowledge level on the planet.
* One number indicates black- out.
* One number indicates ALMs layed on that planet.
* One number indicating the sum dedicated to paint the ships.
* One number indicating sum dedicated to detect movement.
* one number indicating sum dedicated to build ships.
* Next 2 no. indicating how many ships to be build & their level.
* One poineter to reports about this planet.
* Next 7 no. show the ships and their level.
* Next 160 numbers indicate Espinage.
* Each player has a two dimension array that is comprised
* of 10 kinds of espionage and 8 levels of counter espionage.
* Each cell holds the money invested for obtaining information
* for that level and kind of information.
*/
planet pl[MAXPL] = {
{
'*', '*', '*', "l00", 8, 17, &pl[1], &pl[2], &pl[3], &pl[4], &pl[5], &pl[6], &pl[7], &pl[8], NULL, NULL, 0, 960, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, 15
},
{
'*', '*', '*', "l10", 6, 17, &pl[9], NULL, NULL, &pl[2], &pl[0], &pl[8], NULL, NULL, &pl[8], &pl[2]
},
{
'*', '*', '*', "l11", 7, 19, NULL, &pl[10], NULL, &pl[3], NULL, &pl[0], NULL, &pl[1], &pl[1], &pl[3]
},
{
'*', '*', '*', "l12", 8, 20, NULL, NULL, &pl[11], NULL, NULL, &pl[4], &pl[0], &pl[2], &pl[2], &pl[4]
},
{
'*', '*', '*', "l13", 9, 19, NULL, &pl[3], NULL, &pl[12], NULL, &pl[5], NULL, &pl[0], &pl[3], &pl[5]
}
,
{
'*', '*', '*', "l14", 10, 17, &pl[0], &pl[4], NULL, NULL, &pl[13], NULL, NULL, &pl[6], &pl[4], &pl[6]
}
,
{
'*', '*', '*', "l15", 9, 15, NULL, &pl[0], NULL, &pl[5], NULL, &pl[14], NULL, &pl[7], &pl[5], &pl[7]
}
,
{
'*', '*', '*', "l16", 8, 14, NULL, &pl[8], &pl[0], &pl[6], NULL, NULL, &pl[15], NULL, &pl[6], &pl[8]
}
,
{
'*', '*', '*', "l17", 7, 15, NULL, &pl[1], NULL, &pl[0], NULL, &pl[7], NULL, &pl[16], &pl[7], &pl[1]
}
,
{
'*', '*', '*', "l20", 3, 17, &pl[17], NULL, NULL, &pl[10], &pl[1], &pl[16], NULL, NULL, &pl[16], &pl[10]
}
,
{
'*', '*', '*', "l21", 5, 22, NULL, &pl[19], NULL, &pl[11], NULL, &pl[2], NULL, &pl[9], &pl[9], &pl[11]
}
,
{
'*', '*', '*', "l22", 8, 25, NULL, NULL, &pl[21], NULL, NULL, &pl[12], &pl[3], &pl[10], &pl[10], &pl[12]
}
,
{
'*', '*', '*', "l23", 11, 22, NULL, &pl[11], NULL, &pl[23], NULL, &pl[13], NULL, &pl[4], &pl[11], &pl[13]
}
,
{
'*', '*', '*', "l24", 13, 17, &pl[5], &pl[12], NULL, NULL, &pl[25], NULL, NULL, &pl[14], &pl[12], &pl[14]
}
,
{
'*', '*', '*', "l25", 11, 12, NULL, &pl[6], NULL, &pl[13], NULL, &pl[27], NULL, &pl[15], &pl[13], &pl[15]
}
,
{
'*', '*', '*', "l26", 8, 9, NULL, &pl[16], &pl[7], &pl[14], NULL, NULL, &pl[29], NULL, &pl[14], &pl[16]
}
,
{
'*', '*', '*', "l27", 5, 12, NULL, &pl[9], NULL, &pl[8], NULL, &pl[15], NULL, &pl[31], &pl[15], &pl[9]
}
,
{
'*', '*', '*', "l30", 0, 17, NULL, NULL, &pl[66], &pl[18], &pl[9], &pl[32], NULL, NULL, &pl[32], &pl[18]
}
,
{
'*', '*', '*', "l31", 1, 22, NULL, &pl[66], NULL, &pl[19], NULL, NULL, NULL, &pl[17], &pl[17], &pl[19]
}
,
{
'*', '*', '*', "l32", 3, 26, NULL, NULL, &pl[71], &pl[20], NULL, &pl[10], NULL, &pl[18], &pl[18], &pl[20]
}
,
{
'*', '*', '*', "l33", 5, 28, NULL, NULL, &pl[74], &pl[21], NULL, NULL, NULL, &pl[19], &pl[19], &pl[21]
}
,
{
'*', '*', '*', "l34", 8, 29, NULL, NULL, &pl[77], NULL, NULL, &pl[22], &pl[11], &pl[20], &pl[20], &pl[22]
}
,
{
'*', '*', '*', "l35", 11, 28, NULL, &pl[21], &pl[80], NULL, NULL, &pl[23], NULL, NULL, &pl[21], &pl[23]
}
,
{
'*', '*', '*', "l36", 13, 26, NULL, &pl[22], &pl[83], NULL, NULL, &pl[24], NULL, &pl[12], &pl[22], &pl[24]
}
,
{
'*', '*', '*', "l37", 15, 22, NULL, &pl[23], NULL, &pl[86], NULL, &pl[25], NULL, NULL, &pl[23], &pl[25]
}
,
{
'*', '*', '*', "l38", 16, 17, &pl[13], &pl[24], &pl[86], NULL, NULL, NULL, NULL, &pl[26], &pl[24], &pl[26]
}
,
{
'*', '*', '*', "l39", 15, 12, NULL, NULL, NULL, &pl[25], NULL, NULL, NULL, &pl[27], &pl[25], &pl[27]
}
,
{
'*', '*', '*', "l3a", 13, 8, NULL, &pl[14], NULL, &pl[26], NULL, NULL, NULL, &pl[28], &pl[26], &pl[28]
}
,
{
'*', '*', '*', "l3b", 11, 6, NULL, NULL, NULL, &pl[27], NULL, NULL, NULL, &pl[29], &pl[27], &pl[29]
}
,
{
'*', '*', '*', "l3c", 8, 5, NULL, &pl[30], &pl[15], &pl[28], NULL, NULL, NULL, NULL, &pl[28], &pl[30]
}
,
{
'*', '*', '*', "l3d", 5, 6, NULL, &pl[31], NULL, NULL, NULL, &pl[29], NULL, NULL, &pl[29], &pl[31]
}
,
{
'*', '*', '*', "l3e", 3, 8, NULL, &pl[32], NULL, &pl[16], NULL, &pl[30], NULL, NULL, &pl[30], &pl[32]
}
,
{
'*', '*', '*', "l3f", 1, 12, NULL, &pl[17], NULL, NULL, NULL, &pl[31], NULL, NULL, &pl[31], &pl[17]
}
,
{
'@', '@', '@', "r00", 8, 61, &pl[34], &pl[35], &pl[36], &pl[37], &pl[38], &pl[39], &pl[40], &pl[41], NULL, NULL, 1, 960, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, 15
}
,
{
'@', '@', '@', "r10", 6, 61, &pl[42], NULL, NULL, &pl[35], &pl[33], &pl[41], NULL, NULL, &pl[41], &pl[35], 1
}
,
{
'@', '@', '@', "r11", 7, 63, NULL, &pl[43], NULL, &pl[36], NULL, &pl[33], NULL, &pl[34], &pl[34], &pl[36], 1
}
,
{
'@', '@', '@', "r12", 8, 64, NULL, NULL, &pl[44], NULL, NULL, &pl[37], &pl[33], &pl[35], &pl[35], &pl[37], 1
}
,
{
'@', '@', '@', "r13", 9, 63, NULL, &pl[36], NULL, &pl[45], NULL, &pl[38], NULL, &pl[33], &pl[36], &pl[38], 1
}
,
{
'@', '@', '@', "r14", 10, 61, &pl[33], &pl[37], NULL, NULL, &pl[46], NULL, NULL, &pl[39], &pl[37], &pl[39], 1
}
,
{
'@', '@', '@', "r15", 9, 59, NULL, &pl[33], NULL, &pl[38], NULL, &pl[47], NULL, &pl[40], &pl[38], &pl[40], 1
}
,
{
'@', '@', '@', "r16", 8, 58, NULL, &pl[41], &pl[33], &pl[39], NULL, NULL, &pl[48], NULL, &pl[39], &pl[41], 1
}
,
{
'@', '@', '@', "r17", 7, 59, NULL, &pl[34], NULL, &pl[33], NULL, &pl[40], NULL, &pl[49], &pl[40], &pl[34], 1
}
,
{
'@', '@', '@', "r20", 3, 61, &pl[50], NULL, NULL, &pl[43], &pl[34], &pl[49], NULL, NULL, &pl[49], &pl[43], 1
}
,
{
'@', '@', '@', "r21", 5, 66, NULL, &pl[52], NULL, &pl[44], NULL, &pl[35], NULL, &pl[42], &pl[42], &pl[44], 1
}
,
{
'@', '@', '@', "r22", 8, 69, NULL, NULL, &pl[54], NULL, NULL, &pl[45], &pl[36], &pl[43], &pl[43], &pl[45], 1
}
,
{
'@', '@', '@', "r23", 11, 66, NULL, &pl[44], NULL, &pl[56], NULL, &pl[46], NULL, &pl[37], &pl[44], &pl[46], 1
}
,
{
'@', '@', '@', "r24", 13, 61, &pl[38], &pl[45], NULL, NULL, &pl[58], NULL, NULL, &pl[47], &pl[45], &pl[47], 1
}
,
{
'@', '@', '@', "r25", 11, 56, NULL, &pl[39], NULL, &pl[46], NULL, &pl[60], NULL, &pl[48], &pl[46], &pl[48], 1
}
,
{
'@', '@', '@', "r26", 8, 53, NULL, &pl[49], &pl[40], &pl[47], NULL, NULL, &pl[62], NULL, &pl[47], &pl[49], 1
}
,
{
'@', '@', '@', "r27", 5, 56, NULL, &pl[42], NULL, &pl[41], NULL, &pl[48], NULL, &pl[64], &pl[48], &pl[42], 1
}
,
{
'@', '@', '@', "r30", 0, 61, NULL, NULL, NULL, &pl[51], &pl[42], &pl[65], &pl[70], NULL, &pl[65], &pl[51], 1
}
,
{
'@', '@', '@', "r31", 1, 66, NULL, NULL, NULL, &pl[52], NULL, NULL, NULL, &pl[50], &pl[50], &pl[52], 1
}
,
{
'@', '@', '@', "r32", 3, 70, NULL, NULL, NULL, &pl[53], NULL, &pl[43], NULL, &pl[51], &pl[51], &pl[53], 1
}
,
{
'@', '@', '@', "r33", 5, 72, NULL, NULL, NULL, &pl[54], NULL, NULL, NULL, &pl[52], &pl[52], &pl[54], 1
}
,
{
'@', '@', '@', "r34", 8, 73, NULL, NULL, NULL, NULL, NULL, &pl[55], &pl[44], &pl[53], &pl[53], &pl[55], 1
}
,
{
'@', '@', '@', "r35", 11, 72, NULL, &pl[54], NULL, NULL, NULL, &pl[56], NULL, NULL, &pl[54], &pl[56], 1
}
,
{
'@', '@', '@', "r36", 13, 70, NULL, &pl[55], NULL, NULL, NULL, &pl[57], NULL, &pl[45], &pl[55], &pl[57], 1
}
,
{
'@', '@', '@', "r37", 15, 66, NULL, &pl[56], NULL, NULL, NULL, &pl[58], NULL, NULL, &pl[56], &pl[58], 1
}
,
{
'@', '@', '@', "r38", 16, 61, &pl[46], &pl[57], NULL, NULL, NULL, NULL, &pl[90], &pl[59], &pl[57], &pl[59], 1
}
,
{
'@', '@', '@', "r39", 15, 56, NULL, NULL, NULL, &pl[58], NULL, &pl[90], NULL, &pl[60], &pl[58], &pl[60], 1
}
,
{
'@', '@', '@', "r3a", 13, 52, NULL, &pl[47], NULL, &pl[59], NULL, NULL, &pl[85], &pl[61], &pl[59], &pl[61], 1
}
,
{
'@', '@', '@', "r3b", 11, 50, NULL, NULL, NULL, &pl[60], NULL, NULL, &pl[82], &pl[62], &pl[60], &pl[62], 1
}
,
{
'@', '@', '@', "r3c", 8, 49, NULL, &pl[63], &pl[48], &pl[61], NULL, NULL, &pl[79], NULL, &pl[61], &pl[63], 1
}
,
{
'@', '@', '@', "r3d", 5, 50, NULL, &pl[64], NULL, NULL, NULL, &pl[62], &pl[76], NULL, &pl[62], &pl[64], 1
}
,
{
'@', '@', '@', "r3e", 3, 52, NULL, &pl[65], NULL, &pl[49], NULL, &pl[63], &pl[73], NULL, &pl[63], &pl[65], 1
}
,
{
'@', '@', '@', "r3f", 1, 56, NULL, &pl[50], NULL, NULL, NULL, &pl[64], NULL, &pl[70], &pl[64], &pl[50], 1
}
,
{
'#', '#', '#', "c00", 0, 28, NULL, NULL, &pl[67], NULL, NULL, &pl[18], &pl[17], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c01", 0, 34, NULL, NULL, &pl[68], NULL, &pl[71], NULL, &pl[66], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c02", 0, 39, NULL, NULL, &pl[69], NULL, &pl[72], NULL, &pl[67], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c03", 0, 44, NULL, NULL, &pl[70], NULL, &pl[73], NULL, &pl[68], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c04", 0, 50, NULL, NULL, &pl[50], &pl[65], NULL, NULL, &pl[69], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c11", 3, 34, &pl[67], NULL, &pl[72], NULL, &pl[74], NULL, &pl[19], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c12", 3, 39, &pl[68], NULL, &pl[73], NULL, &pl[75], NULL, &pl[71], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c13", 3, 44, &pl[69], NULL, &pl[64], NULL, &pl[76], NULL, &pl[72], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c21", 5, 34, &pl[71], NULL, &pl[75], NULL, &pl[77], NULL, &pl[20], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c22", 5, 39, &pl[72], NULL, &pl[76], NULL, &pl[78], NULL, &pl[74], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c23", 5, 44, &pl[73], NULL, &pl[63], NULL, &pl[79], NULL, &pl[75], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c31", 8, 34, &pl[74], NULL, &pl[78], NULL, &pl[80], NULL, &pl[21], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c32", 8, 39, &pl[75], NULL, &pl[79], NULL, &pl[81], NULL, &pl[77], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c33", 8, 44, &pl[76], NULL, &pl[62], NULL, &pl[82], NULL, &pl[78], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c41", 11, 34, &pl[77], NULL, &pl[81], NULL, &pl[83], NULL, &pl[22], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c42", 11, 39, &pl[78], NULL, &pl[82], NULL, &pl[84], NULL, &pl[80], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c43", 11, 44, &pl[79], NULL, &pl[61], NULL, &pl[85], NULL, &pl[81], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c51", 13, 34, &pl[80], NULL, &pl[84], NULL, &pl[87], NULL, &pl[23], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c52", 13, 39, &pl[81], NULL, &pl[85], NULL, &pl[88], NULL, &pl[83], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c53", 13, 44, &pl[82], NULL, &pl[60], NULL, &pl[89], NULL, &pl[84], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c60", 16, 28, NULL, NULL, &pl[87], NULL, NULL, NULL, &pl[25], &pl[24], NULL, NULL, 2
}
,
{
'#', '#', '#', "c61", 16, 34, &pl[83], NULL, &pl[88], NULL, NULL, NULL, &pl[86], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c62", 16, 39, &pl[84], NULL, &pl[89], NULL, NULL, NULL, &pl[87], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c63", 16, 44, &pl[85], NULL, &pl[90], NULL, NULL, NULL, &pl[88], NULL, NULL, NULL, 2
}
,
{
'#', '#', '#', "c64", 16, 50, NULL, &pl[59], &pl[58], NULL, NULL, NULL, &pl[89], NULL, NULL, NULL, 2
}
};
SHAR_EOF
if test 15087 -ne "`wc -c planet_inf.c`"
then
echo shar: error transmitting planet_inf.c '(should have been 15087 characters)'
fi
echo shar: extracting planet_sit.c '(5473 characters)'
cat << \SHAR_EOF > planet_sit.c
/*
* %W% (mrdch&amnnon) %G%
*/
# include "header"
planetsit (s)
char *s;
{
planet * pp;
pp = getpl (s);
skipwhite (s); /* find the first non-white */
if (*s == 'i') {
skipword (s);
assert_end (s);
ps_i (pp);
return;
}
flip ();
clear ();
pos (0, 20);
print ("Information available about: %s \r\n\n", pp -> pid);
/* give full information to wizards or owner */
if (pp -> whos == player || iswiz[player])
if (chek_empty (pp))
print_info (pp);
else
print ("\r\n\n This planet is empty.");
else {
if (!count_spies (pp, player))
print ("Sorry sir, no information.");
else {
print ("Your spies are assigned to:\r\n");
dis_spies (pp, player, 3, 0);
}
}
more ();
}
/* gives all the information about a given planet */
print_info (pp)
planet * pp;
{
int i,
j,
ps,
cc,
col;
if (j = pp -> inventar.popul[FIGT])
print ("There are %d Fighters ready.\r\n", j);
if (j = pp -> inventar.popul[CITI])
print ("Agricultural with %6d Citizens \r\n", j);
if (j = pp -> inventar.popul[MINE])
print ("Mining-planet with %6d Miners.\r\n", j);
if (j = pp -> inventar.popul[BUIL])
print ("Industrial with %6d Builders.\r\n", j);
if (j = pp -> inventar.popul[SCIE])
print ("Scientific with %6d Scientists.\r\n", j);
if (j = pp -> inventar.popul[SLAV])
print (" It has %6d Slaves. \r\n", j);
print ("\r\n");
i = 0;
for (j = 0; j < CLASES; j++)
if (pp -> to_take.popul[j])
i++;
if (pp -> to_take.metals)
i++;
if (pp -> to_take.know)
i++;
if (i) {
print ("Ready to be moved\r\n");
for (j = 0; j < CLASES; j++)
if ((i = pp -> to_take.popul[j]))
print ("%6d %s.\r\n", i, ocup_name[j]);
if ((i = pp -> to_take.metals))
print ("%6d A-type material.\r\n", i);
if ((cc = pp -> to_take.know))
print (" %c-type knowledge.", 'A' + cc);
}
ps = 2;
col = 45;
i = 0;
for (j = 0; j < MAXSHIPS; j++)
if (pp -> ships[j] || pp -> missile[j])
i++;
if (i) {
pos (ps++, col + 3);
print ("No. of ships and missiles:");
for (i = 0; i < MAXSHIPS; i++) {
if ((j = pp -> ships[i]) || pp -> missile[i]) {
pos (ps++, col);
print ("%c-type %4d ships %4d missiles.", i + 'A', j, pp -> missile[i]);
}
}
}
ps++;
if (j = pp -> secur) {
pos (ps++, col);
print ("Blacked out with %d Tellers.", j);
}
if (j = pp -> detect) {
pos (ps++, col);
print ("Detect moves with %d Tellers.", j);
}
if (j = pp -> paint) {
pos (ps++, col);
print ("No detection paint %d Tellers.", j);
}
if (j = pp -> inventar.metals) {
pos (ps++, col);
print ("Metal for %d A-type HAWKs ready.", j);
}
if (j = pp -> inventar.know) {
pos (ps++, col);
print ("Knowledge of %c-type available.", j + 'A');
}
if (j = pp -> alms) {
pos (ps++, col);
print ("%d of ALMs installed.", j);
}
if (j = pp -> to_build[BUILD_MONEY]) {
pos (ps++, col);
print ("Building ships with %d tellers.", j);
}
if (j = pp -> to_build[NSHIPS]) {
pos (ps++, col);
print (" %d %c-type ships ordered.",
j , pp -> to_build[LEVEL] + 'A');
}
if (count_spies (pp, player)) {
ps++;
pr_at (ps++, 30, "Your spies are assigned to:");
dis_spies (pp, player, ps, 30);
}
}
/*
* gives the information about spies reports, gathered so far.
*/
ps_i (pp)
planet * pp;
{
info * x;
int nmgs = 1;
/* count how many messages are on the line */
if (count_msgs (pp -> reports, player) == 0) {
say ("No messages, sir.");
return;
}
/* leave up to 24 message */
scroll_msgs (&pp -> reports, player);
flip ();
clear ();
pr_at (0, 20, "Information available about: %s\r\n ", pp -> pid);
x = pp -> reports;
while (x) {
pos (nmgs, 0);
if (x -> owner == player) {
print ("%s.", x -> msg);
nmgs++;
}
x = x -> next;
}
more ();
}
/* returns the no. of messages awaitaing */
count_msgs (hd, ply)
info * hd;
int ply;
{
int ac = 0;
while (hd) {
if (hd -> owner == ply)
ac++;
hd = hd -> next;
}
return (ac);
}
count_spies (pp, ply)
planet * pp;
{
int i,
j;
for (i = 0; i < ESPTYP; i++)
for (j = 0; j < ESPSIZ; j++)
if (pp -> espion[ply][i][j])
return (1);
return (0);
}
extern char *inftypes[];
dis_spies (pp, ply, line, col)
planet * pp;
{
int i,
j,
flg;
for (i = 0; i < ESPTYP; i++) {
flg = 0;
for (j = 0; j < ESPSIZ; j++)
if (pp -> espion[ply][i][j])
flg++;
if (flg) {
pr_at (line++, col, "%s:\t", inftypes[i]);
for (j = 0; j < ESPSIZ; j++) {
if (pp -> espion[ply][i][j])
print ("%d %d\t", j, pp -> espion[ply][i][j]);
}
}
}
}
SHAR_EOF
if test 5473 -ne "`wc -c planet_sit.c`"
then
echo shar: error transmitting planet_sit.c '(should have been 5473 characters)'
fi
echo shar: extracting play.c '(1969 characters)'
cat << \SHAR_EOF > play.c
/*
* %W% (mrdch&amnnon) %G%
*/
# include "header"
char buffer1[BUFSIZ];
char buffer2[BUFSIZ];
main (argc, argv)
int argc;
char *argv[];
{
/* If any argument present, go to score analysis */
if (argc > 1){
tty = stdout;
glxscore (argc, argv);
exit(0) ;
}
init_getid ();
term2init ();
/* Get the terminal from the player enviroment */
fillterm (getenv ("TERM"), &ttycs[1]);
/* Now go and start playing */
play ();
/*
* And when it's all over, return the terminal to the
* original state. then kill the two reading processes
*/
term1 ();
ctrlreset ();
term0 ();
ctrlreset ();
(void) kill (getpid (), 9);
}
play () {
/* Open the chanels for writing */
ttys[0] = fdopen (chand[0], "w");
ttys[1] = fdopen (chand[1], "w");
setbuf (ttys[0], buffer1);
setbuf (ttys[1], buffer2);
/* Initial the first terminal */
term0 ();
cap_set (ttyc);
clear ();
if (!iswiz[player])
show_name ();
fflush(tty) ;
/* Initial the second terminal */
term1 ();
cap_set (ttyc);
clear ();
if (!iswiz[player])
show_name ();
fflush(tty) ;
/* transform the name of the game to it's map */
if (!iswiz[player]) {
sleep (5) ;
prologue ();
sleep (3) ;
}
/* redraw the map, enabling inverse video */
termn (0);
init_dis();
cleol(18,0) ;
cleol(19,0) ;
cleol(20,0) ;
cleol(21,0) ;
cleol(22,20) ;
cleol(23,0) ;
prteller () ;
fflush(tty) ;
termn (1);
init_dis();
cleol(18,0) ;
cleol(19,0) ;
cleol(20,0) ;
cleol(21,0) ;
cleol(22,20) ;
cleol(23,0) ;
prteller () ;
fflush(tty) ;
/* Go and start reading what the players are writing */
parse ();
}
/* Functions to set the active terminal and the current player */
term0 () {
tty = ttys[0];
ttyc = &ttycs[0];
player = 0;
}
term1 () {
tty = ttys[1];
ttyc = &ttycs[1];
player = 1;
}
SHAR_EOF
if test 1969 -ne "`wc -c play.c`"
then
echo shar: error transmitting play.c '(should have been 1969 characters)'
fi
echo shar: extracting put_alm.c '(694 characters)'
cat << \SHAR_EOF > put_alm.c
/*
* %W% (mrdch&amnnon) %G%
*/
# include "header"
putalm (s)
char *s;
{
planet * pp;
int i,
nalms;
pp = getpl (s);
assert_player (pp); /* check valid planet and owner */
if (planet_popul (pp) == 0) {
say ("But sir, there is nobody there to do it.");
return;
}
nalms = atoi (s);
assert_number (nalms); /* valid no.? */
skipword (s);
assert_end (s); /* ends gracefully? */
i = ALMCOST * nalms;
assert_money (i); /* hase enough money? */
pp -> alms += nalms;
teller[player] -= i;
say ("Beware, sir, we'll better get the hell out of here!!");
}
SHAR_EOF
if test 694 -ne "`wc -c put_alm.c`"
then
echo shar: error transmitting put_alm.c '(should have been 694 characters)'
fi
echo shar: extracting retrieve.c '(3078 characters)'
cat << \SHAR_EOF > retrieve.c
/*
* %W% (mrdch&amnnon) %G%
*/
# include "header"
/*
* This function enables recovering from real stupid typing
* mistakes. It could happen that when giving a command
* involving money, too many '000...' will be typed.
* Retrieving that money ( or part of it ) is made possible.
* To avoid as much as possible the influence of such command
* on the tactics one employs, it is NOT general, and it costs
* some percentenge of the money asked to be retrieved.
*/
# define PERC_LOST 15
retrieve (s)
char *s;
{
planet * pp;
int i,
money;
double d;
skipwhite (s);
money = atoi (s);
assert_number (money);
skipword (s);
skipwhite (s);
switch (*s++) {
case 'f': /* food */
assert_end (s);
if (food[player] < money) {
say ("But you don't have that much there, sir!!!");
return;
}
i = count_popul (player) - count_class (player, CITI);
i = i / FEED_RATIO; /* that much they consume */
money -= i;
if (money <= 0) {
say ("This much was consumed already, sir.");
return;
}
food[player] -= money;
d = (double) money * ((double) PERC_LOST + (rand () % 5)) / 100.;
money -= (int) d;
break;
case 't': /* trade */
assert_end (s);
if (trade[player] < money) {
say ("But you don't have that much there, sir!!!");
return;
}
trade[player] -= money;
d = (double) money * ((double) PERC_LOST + (rand () % 5)) / 100.;
money -= (int) d;
break;
case 's': /* ships */
pp = getpl (s); /* get planet id */
assert_end (s);
assert_player (pp); /* verify existence + owner */
if (pp -> to_build[BUILD_MONEY] < money) {
say ("But you don't have that much there, sir!!!");
return;
}
pp -> to_build[BUILD_MONEY] -= money;
d = (double) money * ((double) PERC_LOST + (rand () % 5)) / 100.;
money -= (int) d;
break;
case 'b': /* blackout */
pp = getpl (s); /* get planet id */
assert_end (s);
assert_player (pp); /* verify existence + owner */
if (pp -> secur < money) {
say ("But you don't have that much there, sir!!!");
return;
}
pp -> secur -= money;
d = (double) money * ((double) PERC_LOST + (rand () % 5)) / 100.;
money -= (int) d;
break;
default:
say ("Source of retrivel is not clear, sir.");
return;
}
if (money == 0) {
say ("Sorry sir. Couldn't get anything out of it.");
return;
}
teller[player] += money;
say ("Menaged to retrieve only %d Tellers, sir.", money);
}
SHAR_EOF
if test 3078 -ne "`wc -c retrieve.c`"
then
echo shar: error transmitting retrieve.c '(should have been 3078 characters)'
fi
echo shar: extracting savegame.c '(6284 characters)'
cat << \SHAR_EOF > savegame.c
/*
* %W% (mrdch&amnnon) %G%
*/
# include "header"
# include <signal.h>
# include <pwd.h>
extern char *sys_errlist[];
char errmsg[511];
extern errno;
movedir (saver)
char *saver;
{
struct passwd *p;
struct passwd *getpwnam ();
p = getpwnam (saver);
if (p == 0)
return;
else
if (chdir (p -> pw_dir) != -1)
return;
else
return;
}
# include "table.h"
# define TABSIZ 100
# define K 1024
int SWITCH_FLAG;
char version[80] = "Galaxy: version 1 6/9/84";
/*
* A few helpfull hints about galaxy's save file structure:
* The save file is made of three parts:
* 1. Galaxy version.
* 2. The program break.
* 3. global information.
*
* save should read the version, and compare it to the current.
* if they don't match, save must abort.
* after reading the program break, it should be re-set using
* brk(1).
* Now, save is prepared to read back all global data.
*/
char *
save (f)
char *f;
{
extern end;
extern edata;
extern etext;
char *sbrk ();
char *sbrk0;
int savef;
int nwrite;
char *realetext;
umask (0);
realetext = (char *) & etext;
realetext = (char *) ((int) (realetext + K - 1) & ~(K - 1));
savef = creat (f, 0600);
if (savef == -1) {
(void) sprintf(errmsg, "%s: %s", f, sys_errlist[errno]);
return(errmsg);
}
sbrk0 = sbrk (0);
enc_write (savef, version, 80);
if (enc_write (savef, (char *) & sbrk0, sizeof (sbrk0)) != sizeof (sbrk0)) {
(void) close (savef);
unlink (f);
return ("read error");
}
nwrite = (int) sbrk0 - (int) realetext;
if (enc_write (savef, realetext, nwrite) != nwrite) {
(void) close (savef);
unlink (f);
return ("read error");
}
(void) close (savef);
return (0);
}
char *
restor (f)
char *f;
{
extern etext;
extern edata;
extern end;
int savef;
char *brk ();
char *sbrk0;
int nread;
char *realetext;
char vers[81];
realetext = (char *) & etext;
realetext = (char *) ((int) (realetext + K - 1) & ~(K - 1));
savef = open (f, 0);
if (savef == -1) {
(void) sprintf(errmsg, "%s: %s", f, sys_errlist[errno]);
return(errmsg);
}
enc_read (savef, vers, 80);
if (strcmp (vers, version) != 0) {
close (savef);
/* don't unlink here! */
return ("ill formated save file");
}
if (enc_read (savef, (char *) & sbrk0, sizeof (sbrk0)) != sizeof (sbrk0)) {
perror ("read sbrk0");
(void) close (savef);
return ("read error");
}
if (brk (sbrk0) == (char *) - 1) {
perror ("brk");
(void) close (savef);
return ("not enough memory");
}
nread = (int) sbrk0 - (int) realetext;
if (enc_read (savef, realetext, nread) != nread) {
perror ("read etext");
(void) close (savef);
return ("read error");
}
return (0);
}
enc_write (fd, buf, nwrite)
int fd,
nwrite;
char *buf;
{
char buf2[TABSIZ + 1];
char *cp;
char *bp = buf;
int i;
int nw = nwrite;
while (nwrite > 0) {
cp = buf2;
for (i = 0; i < TABSIZ && nwrite > 0; i++, nwrite--) {
*cp++ = crypt_tab[i] ^ *bp++;
}
if (write (fd, buf2, i) != i)
return (-1);
}
return (nw);
}
enc_read (fd, buf, nread)
int fd,
nread;
char *buf;
{
char buf2[TABSIZ + 1];
char *cp;
char *bp = buf;
int i;
int cc;
int nr = nread;
while (nread > 0) {
cp = buf2;
cc = read (fd, cp, nread > TABSIZ ? TABSIZ : nread);
if (cc != (nread > TABSIZ ? TABSIZ : nread))
return (nr - nread);
for (i = 0; i < TABSIZ && nread > 0; i++, nread--)
*bp++ = crypt_tab[i] ^ *cp++;
}
return (nr);
}
savegame (fn)
char *fn;
{
static char fn1[100];
char *c;
skipwhite (fn);
if (wants_save[player]) {
say ("save canceled");
wants_save[player] = 0;
return;
}
wants_save[player] = 1;
if (wants_save[!player])
goto saveit;
strcpy (fn1, fn);
dowrite_enemy ("Lets save the game, O.K ?", !player);
say ("Ok, saving when he agrees...");
if (player == 0)
movedir (ply0);
else
movedir (ply1);
return;
saveit:
if (nullstr (fn) && nullstr (fn1))
strcpy (fn, "galaxy.save");
if (nullstr (fn1))
strcpy (fn1, fn);
if (nullstr (fn))
strcpy (fn, fn1);
if (strcmp (fn, fn1) != 0) {
say ("Hey, he wants to save on \"%s\"!", fn1);
wants_save[0] = wants_save[1] = 0;
return;
}
wants_save[0] = wants_save[1] = 0;
c = save (fn);
if (c != 0)
say (c);
if (iswiz[1] || iswiz[2])
return;
endgame (-1);
}
restorgame (fn)
char *fn;
{
char *c;
static char fn1[100];
char pl[100];
skipwhite (fn);
if (wants_restor[player]) {
say ("restor canceled");
wants_restor[player] = 0;
return;
}
wants_restor[player] = 1;
if (wants_restor[!player])
goto restorit;
strcpy (fn1, fn);
dowrite_enemy ("Lets restor, O.K ?", !player);
if (player == 0)
movedir (ply0);
else
movedir (ply1);
return;
restorit:
if (nullstr (fn) && nullstr (fn1))
strcpy (fn, "galaxy.save");
if (nullstr (fn1))
strcpy (fn1, fn);
if (nullstr (fn))
strcpy (fn, fn1);
if (strcmp (fn, fn1) != 0) {
say ("Hey, he wants to restore on \"%s\"!", fn1);
wants_restor[0] = wants_restor[1] = 0;
return;
}
/*
* save player0's name.
*/
strcpy (pl, ply0);
c = restor (fn);
if (c != 0)
say (c);
/*
* This is the hard part. When restoring a game, the users
* may have switched terminals. in this case, we have to
* switch the terminals.
*/
if (strcmp (ply0, pl) == 0) /* it's ok. */
return;
/* else o o, switched */
SWITCH_FLAG = 1;
}
nullstr (s)
char *s;
{
return (*s == '\0');
}
SHAR_EOF
if test 6284 -ne "`wc -c savegame.c`"
then
echo shar: error transmitting savegame.c '(should have been 6284 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.