[comp.sources.games] v04i046: conquer3 - middle earth multi-player game

games@tekred.TEK.COM (06/17/88)

Submitted by: ihnp4!homxc!smile
Comp.sources.games: Volume 4, Issue 46
Archive-name: conquer3/Part05



#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 5 (of 8)."
# Contents:  io.c nations randevent.c update.c
# Wrapped by billr@saab on Thu Jun 16 09:40:00 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f io.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"io.c\"
else
echo shar: Extracting \"io.c\" \(6460 characters\)
sed "s/^X//" >io.c <<'END_OF_io.c'
X/*io.c*/
X/*Print and io subroutines for game*/
X
X/*conquer : Copyright (c) 1988 by Ed Barlow.
X *  I spent a long time writing this code & I hope that you respect this.
X *  I give permission to alter the code, but not to copy or redistribute
X *  it without my explicit permission.  If you alter the code,
X *  please document changes and send me a copy, so all can have it.
X *  This code, to the best of my knowledge works well,  but it is my first
X *  'C' program and should be treated as such.  I disclaim any
X *  responsibility for the codes actions (use at your own risk).  I guess
X *  I am saying "Happy gaming", and am trying not to get sued in the process.
X *                                                Ed
X */
X
X/*include files*/
X#include <ctype.h>
X#include "header.h"
X#include "data.h"
X
X/*Declarations*/
Xextern struct s_sector sct[MAPX][MAPY];
Xextern struct nation ntn[NTOTAL];   /* player nation stats */
Xextern FILE *fexe;
X
X/*offset of upper left hand corner*/
Xextern short xoffset;
Xextern short yoffset;
X/*current cursor postion (relative to 00 in upper corner)*/
X/*	position is 2*x,y*/
Xextern short xcurs;
Xextern short ycurs;
X/*redraw map in this turn if redraw is a 1*/
Xextern short redraw;
X/*display state*/
Xextern short hilmode;
Xextern short dismode;
X/* nation id of owner*/
Xextern short country;
X#ifdef ADMIN
X/*print a sector.altitude map subroutine*/
Xvoid
Xprintele()
X{
X	register int X, Y;
X	printf("doing print of altitude\n");
X	for(Y=0;Y<MAPY;Y++) {
X		for(X=0;X<MAPX;X++) putc(sct[X][Y].altitude,stdout);
X		putc('\n',stdout);
X	}
X}
X#endif ADMIN
X#ifdef ADMIN
Xvoid
Xpr_ntns()
X{
X	register int X, Y;
X	printf("doing print of nations\n");
X	for(Y=0;Y<MAPY;Y++) {
X		for(X=0;X<MAPX;X++) {
X			if(sct[X][Y].owner==0)
X				putc(sct[X][Y].altitude,stdout);
X			else putc(ntn[sct[X][Y].owner].mark,stdout);
X		}
X		putc('\n',stdout);
X	}
X}
X#endif ADMIN
X
X/*print all data--trashes/creates datafile in the process*/
Xvoid
Xwritedata()
X{
X	int fd;
X	printf("\ndoing write of data\n");
X	if((fd = creat(datafile,0666))==-1) {
X		printf("cant open data.  check permissions\n");
X		return;
X	}
X	write(fd,sct,sizeof(sct));
X	write(fd,ntn,sizeof(ntn));
X	close(fd);
X}
X
Xvoid
Xreaddata()
X{
X	int fd;
X	int n_read;
X
X	/*read in existing nation army and navy data*/
X	/*check if file openable*/
X	printf("reading data file\n");
X	if( (fd = open(datafile,0)) < 0 ) {
X		fprintf( stderr, "can not open %s \n", datafile );
X		exit(FAIL);
X	}
X	if((n_read=read(fd,sct,sizeof(sct)))==0) printf("EOF\n");
X	else if(n_read==-1) printf("error reading sector data (sct)\n");
X	if(n_read!=sizeof(sct)) {
X		printf( "wrong data format (%d vs. %d)\n",n_read, sizeof(sct) );
X		abrt();
X	}
X	if((n_read=read(fd,ntn,sizeof(ntn)))==0) printf("EOF\n");
X	else if(n_read==-1) printf("error reading nation data (ntn)\n");
X	if(n_read!=sizeof(ntn)) {
X		printf( "wrong data format (%d vs. %d)\n",n_read, sizeof(ntn) );
X		abrt();
X	}
X	close(fd);
X	verifydata( __FILE__, __LINE__ );
X
X} /* readdata() */
X
X#ifdef ADMIN
X/*print a map subroutine*/
Xvoid
Xprintveg()
X{
X	register int X, Y;
X	printf("doing print of vegetation\n");
X	for(Y=0;Y<MAPY;Y++) {
X		for(X=0;X<MAPX;X++) putc(sct[X][Y].vegetation,stdout);
X		putc('\n',stdout);
X	}
X}
X#endif ADMIN
X#ifdef CONQUER
Xvoid
Xoffmap()
X{
X	redraw=FALSE;
X	/*set offset offsets can not be < 0*/
X	if(xcurs<1){
X		if(XREAL<=0) {
X			xoffset=0;
X			xcurs=0;
X		}
X		else {
X			redraw=TRUE;
X			xoffset-=15;
X			xcurs+=15;
X		}
X	}
X	else if(xcurs >= (COLS-22)/2){
X		if(XREAL<MAPX) {
X			redraw=TRUE;
X			xoffset+=15;
X			xcurs-=15;
X		}
X	}
X	if(XREAL>=MAPX) xcurs=MAPX-1-xoffset;
X	if(xoffset<0) {
X		xcurs += xoffset;
X		xoffset=0;
X	}
X	if(xcurs<0) {
X		xoffset += xcurs;
X		xcurs=0;
X	}
X	else if(xcurs >= (COLS-22)/2) {
X		redraw=TRUE;
X		xoffset+=15;
X		xcurs-=15;
X	}
X
X	if(ycurs<1){
X		if(YREAL<=0) {
X			yoffset=0;
X			ycurs=0;
X		}
X		else {
X			redraw=TRUE;
X			ycurs+=15;
X			yoffset-=15;
X		}
X	}
X	else if(ycurs >= SCREEN_Y_SIZE){
X		if(YREAL<MAPY) {
X			redraw=TRUE;
X			yoffset+=15;
X			ycurs-=15;
X		}
X	}
X	if(YREAL>=MAPY) ycurs=MAPY-1-yoffset;
X	if(yoffset<0) {
X		ycurs += yoffset;
X		yoffset=0;
X	}
X	if(ycurs<0) {
X		yoffset += ycurs;
X		ycurs=0;
X	}
X	else if(ycurs >= SCREEN_Y_SIZE) {
X		redraw=TRUE;
X		yoffset+=15;
X		ycurs-=15;
X	}
X}
X#endif CONQUER
X#ifdef CONQUER
Xvoid
Xprintscore()
X{
X	int i;
X	int nationid; 	/*current nation id */
X
X	printf("id	race	class	score	gold	military people	sectors	name\n");
X	for (nationid=1; nationid<MAXNTN; nationid++) {
X
X		if(ntn[nationid].active==0) continue;
X		printf("%d",nationid);
X		for(i=1;i<8;i++)
X			if(ntn[nationid].race==*(races+i)[0])
X				printf("	%s",*(races+i));
X		if(ntn[nationid].active>=2) printf("	NPC");
X		else printf("	%s",*(Class+ntn[nationid].class));
X		printf("	%ld	%ld	%ld	%ld	%d",
X			ntn[nationid].score ,ntn[nationid].tgold
X			,ntn[nationid].tmil ,ntn[nationid].tciv
X			,ntn[nationid].tsctrs );
X		printf("	%s\n",ntn[nationid].name);
X	}
X}
X#endif CONQUER
X
Xvoid
Xflee(x,y,z,slaver)
Xint x,y,z,slaver;
X{
X	/*count is number of acceptable sectors*/
X	int count=0;
X	int slaves=0;
X	int i,j;
X
X	if(slaver==TRUE){
X		slaves= sct[x][y].people/4;
X		sct[x][y].people-=slaves;
X	}
X
X	/*flee*/
X	sct[x][y].people*=6;
X	sct[x][y].people/=10;
X	/*check if next to anybody of the sectors owners race*/
X	for(i=x-2;i<=x+2;i++) for(j=y-2;j<=y+2;j++)
X		if(i>=0&&i<MAPX&&j>=0&&j<MAPY
X		&&(ntn[sct[i][j].owner].race==ntn[sct[x][y].owner].race))
X			count++;
X
X	if(count>0) {
X	if(z==0) if(slaver==TRUE){
X			mvprintw(LINES-2,20,"CIVILIANS ABANDON SECTOR (%d slaves)",slaves);
X		}else{
X			mvaddstr(LINES-2,20,"CIVILIANS ABANDON SECTOR");
X		}
X	for(i=x-2;i<=x+2;i++) for(j=y-2;j<=y+2;j++)
X		if(i>=0&&i<MAPX&&j>=0&&j<MAPY
X		&&(ntn[sct[i][j].owner].race==ntn[sct[x][y].owner].race)) {
X			sct[i][j].people += sct[x][y].people / count;
X			if(z==0) SADJCIV2;
X		}
X	}
X	else {
X	sct[x][y].people /= 2;
X	for(i=x-4;i<=x+4;i++) for(j=y-4;j<=y+4;j++)
X		if(i>=0&&i<MAPX&&j>=0&&j<MAPY
X		&&(ntn[sct[i][j].owner].race==ntn[sct[x][y].owner].race))
X			count++;
X	if(count>0) {
X	if(z==0) mvaddstr(LINES-2,20,"PEOPLE FLEE SECTOR AND HALF DIE");
X	for(i=x-4;i<=x+4;i++) for(j=y-4;j<=y+4;j++)
X		if(i>=0&&i<MAPX&&j>=0&&j<MAPY
X		&&(ntn[sct[i][j].owner].race==ntn[sct[x][y].owner].race)) {
X			sct[i][j].people += sct[x][y].people / count;
X			if(z==0) SADJCIV2;
X		}
X	}
X	else if(z==0) mvaddstr(LINES-2,20,"PEOPLE IN SECTOR DIE");
X	}
X
X	sct[x][y].people = slaves;
X	if(z==0) SADJCIV;
X	sct[x][y].fortress=0;
X	/*SINFORT;*/
X	if(tofood(sct[XREAL][YREAL].vegetation,sct[XREAL][YREAL].owner)!=0) {
X		sct[x][y].designation=DDEVASTATED;
X		if(z==0) SADJDES2;
X	}
X}
X
END_OF_io.c
if test 6460 -ne `wc -c <io.c`; then
    echo shar: \"io.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f nations -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"nations\"
else
echo shar: Extracting \"nations\" \(2960 characters\)
sed "s/^X//" >nations <<'END_OF_nations'
X# GAME MASTERS FILE ON NPC NATIONS:  COMPILE TIME ONLY
X#  comments are offset by a # sign in the first column
X#
X#  THERE IS A LIMIT OF "MAXNTN" NATIONS TOTAL; Be sure this is ok
X#
X# name 		:nations name
X#		:examples include Darboth Ummaya Rugar Jute Atlantis Iberia 
X#		:Kuybyshev Avar Grodor Bantanya Fung Codor Delph Macitania 
X# leader 	: permitted leaders are "dwarfking","elfking","elfdruid",
X#			"elfwizard","demon","dragon","wizard","priest",
X#			"shadow","king","priestking","wizard","demigod"
X# race   	:Character, ORC='O',ELF='E',DWARF='D',LZARD='L',HUMAN='H'
X#		:BRIGAND='P' BARBARIAN='B'
X# mark		:unique mark for race (ie & or ! or 1 or H...)
X# loc	 	:G,F,R  location (good,fair,random)
X# aplus 	:attack percentage plus (multiples of 10 (ie 10,20,30))
X# dplus		:defence percentage plus (multiples of 10 (ie 10,20,30))
X# maxmove 	:movement rate (4 to 8)
X# gold		:total gold at start
X# mil	 	:total military at start
X# civilians 	:total civilians at start
X# repro-rate    :reproduction rate of nation (percentage)
X# aggr		:aggressiveness (1--always peaceful) to (10 -- always hostile)
X#
X#EXAMPLE NATIONS							PTS
X#	Sporf    demon      O S R 0  0   6  1000  2500 4000 10 9 	9
X#	Athens   king       H A R 10 10  9  10000 500  5000 5 4		9
X#	Fung     king       E F F 20 30  8  20000 200  3000 3 2		6
X#	X        dwarfking  D X R 20 20  6  20000 1500 4000 4 4 	6
X#	ADD PTS IN VALUE TO THE ABOVE FORE RACIAL BASES TO GET BALANCE
X#
X#  THE NATIONS LISTED BELOW ARE CALIBRATED AS FOLLOWS
X#  ELVES: fung (27), lint (28), anorian (29), roos (22)   	=>106 points
X#  ORCS : sporf (24), etland (24), woolos (36), darboth (20)   	=>106 points
X#  HUMAN: argos(24), taelos(20), cordoba(21), zaos(21), tokus(20) =>106 pts
X#  DWARF: Goldor (22), Muldor (38), Sodor (25), Valar(20)	 =>106 points
X#
X# format:     (note that offset by a space)
X#
X# name leader race mark location aplus dplus maxmove gold mil civ repro aggr
X#########################################################################
Xanorian  elfwizard  E A F 30 40  8  70000 1500 8500 8  2
Xbobland  dragon     O B F 20 0   6  12000  1500 8000 10 9
Xcordoba  wizard     H C R 10 10  2  30000 1500 8000 8  4
Xdarboth  balrog     O D R 0  0   7  70000 1500 9500 8  9
Xedland   dragon     O E R 20 0   8  12000  1500 8500 10 9
Xfung     elfking    E F F 10 40  8  50000 1000 9500 8  2
Xgotho    warking    H G R 10 10  9  50000 1000 6150 8  4
Xhargo    king       H H R 10 10  9  30000 1500 11000 7 4
Xlint     elfwizard  E L F 20 30  8  50000 1500 7900 10 2
Xmedal    elfpriest  E M R 20 0   6  16000  2000 6500 10 9
Xnoria    dwarfduke  D N R 10 30  6  50000 1000 10000 8 4
Xroos     dwarfduke  D R F 15 10  9  50000 1000 7900 7  8
Xsodor    dwarfking  D S F 10 30  6  160000 5000 18000 7 4
Xtokus    king       H T R 10 10  8  30000 1000 7500 8  4
Xwoooo    shadow     O W F 10 10  10 60000 3500 17000 10 9
XValar    dwarf      D V R 10 15  8  30000 1000 7000 8  4
Xzaos     king       H Z R 10 15  12 30000 1000 7000 8  4
END_OF_nations
if test 2960 -ne `wc -c <nations`; then
    echo shar: \"nations\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f randevent.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"randevent.c\"
else
echo shar: Extracting \"randevent.c\" \(22037 characters\)
sed "s/^X//" >randevent.c <<'END_OF_randevent.c'
X/* Conquer: Copyright (c) 1988 by Edward M Barlow */
X#include	<stdio.h>
X#include	<ctype.h>
X#include	"header.h"
X#include "data.h"
X#ifdef RANEVENT
X#ifdef ADMIN
X
Xextern FILE *fnews;
Xextern short country;
X
Xchar eventstr[80];
Xint xpos,ypos;		/* saved x and y position */
X
Xchar *randevents[] = {
X/* 0 */  "province rebels -- disolve 10% of nation",
X/* 1 */  "evil wizard sets up -- disolve 10% of nation",
X/* 2 */  "tax revolt -- disolve 20% of nation",
X/* 3 */  "rebelion  -- disolve 30% of nation",
X/* 4 */  "army revolts -- disolve 30% of nation",
X/* 5 */  "religious schism -- disolve 30% of nation",
X/* 6 */  "peasant revolt ",
X/* 7 */  "peasant revolt ",
X/* 8 */  "peasant revolt ",
X/* 9 */  "dragon raid -- lose 30% of food",
X/* 10 */  "famine -- food in granaries reduced 75%",
X/* 11 */  "hurricane",
X/* 12 */  "tornado",
X/* 13 */  "volcano erupts -- all flee, 30% die (in 1 sector range)",
X/* 14 */  "royal wedding (absorb neighbor nation)",
X/* 15 */  "new alloy gives new fighter power",
X/* 16 */  "royal advisor discovered to be spy -- lose power",
X/* 17 */  "gold strike one sector ",
X/* 18 */  "gold strike one sector ",
X/* 19 */  "gold vein runs out in one goldmine sector ",
X/* 20 */  "gold vein runs out in one goldmine sector ",
X/* 21 */  "flood",
X/* 22 */  "earthquake",
X/* 23 */  "frost -- crops ruined",
X/* 24 */  "dragon killed, you gain his jewel hoard",
X/* 25 */  "several nomad armies raid in your area",
X/* 26 */  "town burns to the ground",
X/* 27 */  "black plague -- 40% of populace & armies die",
X/* 28 */  "pirate raid on harbor",
X/* 29 */  "barbarian raid",
X/* 30 */  "new magician offers you magic power",
X/* 31 */  "new magic item give you magic power",
X/* 32 */  "ores in one iron mine run out",
X/* 33 */  "new architect strengthens castle walls",
X/* 34 */  "new ores discovered + 4-10 iron one sector",
X/* 35 */  "skilled diplomat obtains peace",
X/* 36 */  "severe winter",
X/* 37 */  "severe winter",
X/* 38 */  "tidal wave -- abandon all coastlands ",
X/* 39 */  "ninja destroy general staff - 1/2 armies paralyzed",
X/* 40 */  "general found to be spy -- many armies paralyzed",
X/* 41 */  "general prosperity +20% gold",
X/* 42 */  "plague kills 20% of your soldiers",
X/* 43 */  "poor conditions kill 20% of your soldiers"
X};
X#define MAXRANEVENT 43
X
X/*finds unused nation and sets it up partially*/
Xint
Xfindnew()
X{
X	int newntn=0,nationis;
X	for ( nationis=MAXNTN ; nationis >= 1; nationis--)
X		if (ntn[nationis].active == 0) newntn=nationis;
X	if (newntn == 0) return (0);
X	strcpy(ntn[newntn].leader,"rebel");
X	strcpy(ntn[newntn].passwd,ntn[0].passwd);
X	ntn[newntn].class=0;
X	ntn[newntn].score=0L;
X	ntn[newntn].tsctrs=0;
X	ntn[newntn].active=2;
X	return(newntn);
X}
X
X/* disolve a certain percent of a nation */
X/*returns value of new nation */
Xint
Xdisolve(percent, target)
Xint target;
Xint percent;
X{
X	int new;	/* new nation number */
X	int split;	/* number of sectors split */
X	int defaultx=(-1), defaulty=(-1), realx=(-1), realy=(-1), dist;
X	int i,j,armynum,narmynum,posi,posj;
X	int notdone=1;
X	char tmpchr;
X
X	split =  ntn[target].tsctrs * percent / 100;
X	if (split==0) {
X		strcpy(eventstr,"no sectors to split");
X		return(0);
X	}
X	if (split<=7) {
X		strcpy(eventstr,"nation is too small->no sectors will be split");
X		return(0);
X	}
X	/* find starting town */
X	for(posi=0; posi<MAPX; posi++) for(posj=0; posj<MAPY; posj++) {
X		if((sct[posi][posj].designation == DCITY )
X		&&(sct[posi][posj].owner == target)){
X			if ( rand()%5 == 0 ) {
X				realx = posi;
X				realy = posj;
X			} else {
X				defaultx = posi;
X				defaulty = posj;
X			}
X		}
X	}
X	if ((realx == (-1) ) && (realy == (-1))){
X		realx = defaultx;
X		realy = defaulty;
X	}
X	if ((realx == (-1) ) && (realy == (-1))) {
X		strcpy(eventstr,"can't disolve nation->no cities available");
X		return(0);
X	}
X	new=findnew();
X	if(new == 0) {
X		strcpy(eventstr,"no nations available");
X		return(0);
X	}
X
X	strcpy(ntn[new].name,"r-");
X	strncat(ntn[new].name,ntn[target].name,min(NAMELTH-2,strlen(ntn[target].name)));
X	for (armynum=0;armynum<MAXNAVY;armynum++)
X		if(strcmp(ntn[armynum].name, ntn[new].name)==0) {
X			strcpy(eventstr,"no nations available");
X			return(0);
X		}
X#ifdef HIDELOC
X	sprintf(eventstr,"new nation created");
X#else
X	sprintf(eventstr,"new nation created at %d,%d",realx,realy);
X#endif HIDELOC
X	wdisaster(target,realx,realy,0,"revolt");
X	sct[realx][realy].owner=new;
X	ntn[new].capx=realx;
X	ntn[new].capy=realy;
X	sct[realx][realy].designation=DCAPITOL;
X	ntn[new].race= ntn[target].race;
X	ntn[new].tgold= ntn[target].tgold* percent / 100;
X	ntn[new].tfood= ntn[target].tfood* percent / 100;
X	ntn[new].jewels= ntn[target].jewels* percent / 100;
X	ntn[new].tiron= ntn[target].tiron* percent / 100;
X	ntn[new].tciv= ntn[target].tciv* percent / 100;
X	ntn[new].tmil= ntn[target].tmil* percent / 100;
X	ntn[target].tgold -= ntn[new].tgold;
X	ntn[target].tfood -= ntn[new].tfood;
X	ntn[target].jewels -= ntn[new].jewels;
X	ntn[target].tiron -= ntn[new].tiron;
X	ntn[target].tciv -= ntn[new].tciv;
X	ntn[target].tmil -= ntn[new].tmil;
X	ntn[new].repro= ntn[target].repro;
X	ntn[new].maxmove= ntn[target].maxmove;
X	ntn[new].aplus= ntn[target].aplus;
X	ntn[new].dplus= ntn[target].dplus;
X	ntn[new].location= ntn[target].location;
X	ntn[new].powers= ntn[target].powers;
X	/* make the rebellion's mark some unused uppercase letter */
X	tmpchr='A'-1;
X	while (notdone) {
X		tmpchr++;
X		notdone=0;
X		for (i=0;i<MAXNTN;i++)
X			if (ntn[i].mark==tmpchr && ntn[i].active>0)
X				notdone=1;
X		if (!notdone && !isalpha(tmpchr))
X			notdone=1;
X		if (tmpchr=='Z')
X			notdone=0;
X	}
X	ntn[new].mark= tmpchr;
X	for ( dist=2 ; dist < 10; dist++) if (split > 0)
X	for (i=defaultx-dist; i<defaultx+dist; i++)
X		for (j=defaulty-dist; j<defaulty+dist; j++){
X			if (i>=0 && j>=0 && i<MAPX && j<MAPY
X			&&(split>0)
X			&&( sct[i][j].designation != DCAPITOL )
X			&&( sct[i][j].owner == target)){
X					split--;
X					sct[i][j].owner=new;
X			}
X		}
X
X	narmynum=1;
X	for (armynum=0;armynum<MAXNAVY;armynum++) {
X		ntn[new].nvy[armynum].warships = 0;
X		ntn[new].nvy[armynum].merchant = 0;
X	}
X	for (armynum=0;armynum<MAXARM;armynum++)
X		if((ntn[target].arm[armynum].sold>0)
X		&&(sct[ntn[target].arm[armynum].xloc][ntn[target].arm[armynum].yloc].owner==new)){
X			ntn[new].arm[narmynum].sold
X				=ntn[target].arm[armynum].sold;
X			ntn[new].arm[narmynum].unittyp
X				=ntn[target].arm[armynum].unittyp;
X			ntn[new].arm[narmynum].xloc
X				=ntn[target].arm[armynum].xloc;
X			ntn[new].arm[narmynum].yloc
X				=ntn[target].arm[armynum].yloc;
X			ntn[new].arm[narmynum].stat
X				=ntn[target].arm[armynum].stat;
X			ntn[new].arm[narmynum].smove
X				=ntn[target].arm[armynum].smove;
X			ntn[target].arm[armynum].sold = 0;
X			narmynum++;
X		}
X	for (armynum=narmynum; armynum<MAXARM; armynum++)
X		ntn[new].arm[armynum].sold = 0;
X	armynum=0;
X	ntn[new].arm[0].sold = 300;
X	ntn[new].arm[0].unittyp = A_INFANTRY;
X	ntn[new].arm[0].xloc = realx;
X	ntn[new].arm[0].yloc = realy;
X	ntn[new].arm[0].stat = GARRISON;
X	ntn[new].arm[0].smove = 0;
X	for (dist=0;dist<MAXNTN;dist++) if(dist!=new) {
X		/* create realistic diplomatic status */
X		if (ntn[target].dstatus[dist]==UNMET) {
X			ntn[new].dstatus[dist]=UNMET;
X			ntn[dist].dstatus[new]=UNMET;
X		}
X		else if (ntn[target].dstatus[dist]<NEUTRAL)
X		{
X			ntn[new].dstatus[dist]=HOSTILE;
X			ntn[dist].dstatus[new]=HOSTILE;
X		}
X		else {
X			ntn[new].dstatus[dist]=NEUTRAL;
X			ntn[dist].dstatus[new]=NEUTRAL;
X		}
X	}
X	for (dist=MAXNTN;dist<NTOTAL;dist++) {
X		ntn[new].dstatus[dist]=WAR;
X		ntn[dist].dstatus[new]=WAR;
X	}
X	ntn[new].dstatus[target]=WAR;
X	ntn[target].dstatus[new]=WAR;
X	return(new);
X}
X
Xint
Xrandomevent()
X{
X	unsigned char	wierd;		/*because its weird I need to use this*/
X	long totalscore=0;
X	int count, event, newnation, i, j, armynum,x,y;
X	int done, holdval;	/*if 1 then event happened */
X	long newpower;
X	struct s_sector *sptr;
X
X	printf("RANDOM HAPPENINGS ARE NOW BEING CHECKED\n");
X
X#ifdef VULCANIZE
X/* have a volcano erupt on the map based on percent chance of PVULCAN */
X	if(rand()%100<PVULCAN) erupt();
X#endif
X
X	for(country=0;country<MAXNTN;country++)
X		if( ntn[country].active != 0 )
X			totalscore+= ntn[country].score;
X
X	/* decide what nations get random event */
X	for(country=0;country<MAXNTN;country++)
X	if (( ntn[country].active != 0 )
X	&&(ntn[country].score > 20L)
X	&&((rand()%totalscore) < NORANDEVENTS * ntn[country].score)){
X		event = rand()%(MAXRANEVENT+1);
X		printf("event %2d",event);
X		done=TRUE;
X		/* do the event */
X		switch(event) {
X		case 0:
X			/*general/province defects*/
X			if(disolve(10, country)==0) done=FALSE;;
X			break;
X		case 1:
X			/*evil wizard sets up -- disolve 10%*/
X			if(disolve(10, country)==0) done=FALSE;;
X			break;
X		case 2:
X			/*tax revolt -- disolve 20%*/
X			if(disolve(20, country)==0) done=FALSE;;
X			break;
X		case 3:
X			/*rebelion  -- disolve 30%*/
X			if(rand()%2==0) { if(disolve(30, country)==0) done=FALSE; }
X			else done=FALSE;
X			break;
X		case 4:
X			/*general takes over province -- disolve 30%*/
X			if(rand()%2==0) { if(disolve(30, country)==0) done=FALSE; }
X			else done=FALSE;
X			break;
X		case 5:
X			/*religious schism -- disolve 30%*/
X			if(rand()%2==0) { if(disolve(30, country)==0) done=FALSE; }
X			else done=FALSE;
X			break;
X		case 6:
X		case 7:
X		case 8:
X			/*peasant revolt */
X			if((newnation=disolve(10, country)) == 0 ) done=FALSE;
X			if(done==TRUE)
X			for (i=0; i<MAPX; i++) for (j=0; j<MAPY; j++)
X				if(( sct[i][j].owner == country)
X				&&( solds_in_sector(i,j,country)==0))
X				if(rand()%10<=3) {
X					sct[i][j].owner = newnation;
X					for(armynum=0;armynum<MAXARM;armynum++)
X					if(ASOLD == 0) {
X						ASOLD = sct[i][j].people/4;
X						ASTAT = A_MILITIA;
X						sct[i][j].people -= ASOLD;
X						break;
X					}
X				}
X			break;
X		case 9:
X			/*dragon raid -- lose 30% of food*/
X				ntn[country].tfood *= 7L;
X				ntn[country].tfood /= 10L;
X			break;
X		case 10:
X			/*famine -- food=0 10% starve*/
X			ntn[country].tfood /= 4L;
X			break;
X		case 11:
X			/*hurricane*/
X			sptr = rand_sector();
X
X			wdisaster(country,xpos,ypos,20,"hurricane");
X			sprintf (eventstr,"centered on sector %d, %d", xpos, ypos);
X			/* one hex radius */
X			for (x=xpos-1;x<=xpos+1;x++)
X			for (y=ypos-1;y<=ypos+1;y++) if(ONMAP) {
X				sptr = &sct[x][y];
X				if ((sptr->designation != DCAPITOL) &&
X				(sptr->designation != DCITY))
X					sptr->designation = DNODESIG;
X				else if (sptr->fortress != 0)
X					sptr->fortress--;
X				reduce(x, y, 20);
X			}
X			break;
X		case 12:
X			/*tornado*/
X			sptr = rand_sector();
X			sprintf (eventstr, "in sector %d, %d", xpos, ypos);
X			if ((sptr->designation != DCAPITOL)
X			&& (sptr->designation != DCITY))
X				sptr->designation = DNODESIG;
X			else {
X				if (sptr->fortress < 2) sptr->fortress = 0;
X				else sptr->fortress -= 2;
X			}
X			wdisaster(country,xpos,ypos,25,"tornado");
X			reduce(xpos, ypos, 25);
X			break;
X		case 13:
X			/*volcano -- all flee around one mountain -- 30% die*/
X			holdval=0;		/* holdval is # of mountains */
X			for (i=0; i<MAPX; i++) for (j=0; j<MAPY; j++)
X			if(sct[i][j].owner==country && sct[i][j].altitude==MOUNTAIN)
X				holdval++;
X
X			if (holdval > 0) count = (rand()%holdval) + 1;
X			else count = done = FALSE;
X			if( count == FALSE ) break;
X
X			for (i=0; count && (i<MAPX); i++)
X			for (j=0;count && (j<MAPY); j++)
X			if (( sct[i][j].owner == country)
X			&& (sct[i][j].altitude == MOUNTAIN)) {
X				count--;
X				if (count == 0) {
X				blowup(i,j);
X				}
X			}
X			break;
X		case 14:
X			/*royal wedding (absorb neighbor nation)*/
X			/*	takeover ( 100, 0 ); */  done=FALSE;
X			/* something not right.... */
X			break;
X		case 15:
X			/*new alloy +10% combat (WARRIOR...)*/
X			if(magic(country,WARRIOR)!=1){
X				ntn[country].powers|=WARRIOR;
X				exenewmgk(WARRIOR);
X			}
X			else if(magic(country,CAPTAIN)!=1){
X				ntn[country].powers|=CAPTAIN;
X				exenewmgk(CAPTAIN);
X			}
X			else if(magic(country,WARLORD)!=1){
X				ntn[country].powers|=WARLORD;
X				exenewmgk(WARLORD);
X			}
X			break;
X		case 16:
X			/*royal advisor is spy -- lose power*/
X			done=FALSE;
X			break;
X		case 17:
X		case 18:
X			/*gold strike one sector +4-10 gold*/
X			done=FALSE;
X			for (i=0; i<MAPX; i++) for (j=0; j<MAPY; j++)
X				if(( sct[i][j].owner == country)
X				&& (done == FALSE)
X				&& (is_habitable(i,j))
X				&& (rand()%3 == 0)) {
X					wierd = (char) rand()%7;
X					wierd+=4;
X					sct[i][j].gold += wierd;
X					done=TRUE;
X					break;
X				}
X			break;
X		case 19:
X		case 20:
X			/*gold vein runs out one goldmine sector >5 gold */
X			for (i=0; i<MAPX; i++) for (j=0; j<MAPY; j++)
X				if(( sct[i][j].owner == country)
X				&& (sct[i][j].gold >= 5)
X				&& (done == FALSE)
X				&& (sct[i][j].designation == DGOLDMINE)){
X					sct[i][j].gold =0;
X					sct[i][j].designation = DFARM;
X					done=TRUE;
X				}
X			break;
X		case 21:
X			/*flood*/
X			done=FALSE;
X			break;
X		case 22:	/*earthquake*/
X			/* get epicenter */
X			sptr = rand_sector();
X			sprintf (eventstr, "quake in sector %d, %d (owner %s)", xpos, ypos,ntn[country].name);
X			/* 10% damage in 3 sectors, 25 in 1, 50 in */
X			for (x=xpos-3;x<=xpos+3;x++)
X			for (y=ypos-3;y<=ypos+3;y++) if(ONMAP) {
X				reduce(x, y, 10);
X			}
X
X			for (x=xpos-1;x<=xpos+1;x++)
X			for (y=ypos-1;y<=ypos+1;y++) if(ONMAP) {
X				reduce(x,y,15);	/* ADDITIONAL 15% */
X				if(((rand()%2) == 0)
X				&&(sct[x][y].designation!= DCAPITOL)
X				&&(sct[x][y].designation!= DCITY))
X					sct[x][y].designation=DNODESIG;
X			}
X
X			if(is_habitable(xpos,ypos))
X				sptr->designation = DDEVASTATED;
X			if (sptr->fortress < 2) sptr->fortress = 0;
X			else sptr->fortress -= 2;
X			reduce(xpos, ypos, 25);	/* ADDITIONAL 25% */
X			wdisaster(country,xpos,ypos,50,"earthquake");
X			break;
X		case 23:
X			/*frost -- crops ruined*/
X			done=FALSE;
X			break;
X		case 24:
X			/*dragon killed + 50000 jewels*/
X			ntn[country].jewels+=50000;
X			break;
X		case 25:
X			/*nomad raid -- put large nomad army in area*/
X			done=FALSE;
X			for(count=0; count < 100; count++) if(done <= 3){
X			i=(rand()%(MAPX-8))+4;
X			j=(rand()%(MAPY-8))+4;
X			/* get army number */
X			armynum = -1;
X			for(newpower=0; newpower<MAXARM; newpower++)
X				if (ntn[NNOMAD].arm[newpower].sold == 0)
X					armynum=newpower;
X			if(armynum == -1) done=4;
X			else if((is_habitable(i,j))
X			&& ( sct[i][j].owner == country)) {
X				ntn[NNOMAD].arm[armynum].xloc =i;
X				ntn[NNOMAD].arm[armynum].yloc =j;
X				if(ntn[country].tmil > 10000)	/* 800-4800 */
X				ntn[NNOMAD].arm[armynum].sold =800+50*(rand()%80);
X				else if(ntn[country].tmil > 5000) /* 500-2500 */
X				ntn[NNOMAD].arm[armynum].sold =500+50*(rand()%40);
X				else if(ntn[country].tmil > 1000) /* 400-1400 */
X				ntn[NNOMAD].arm[armynum].sold =400+20*(rand()%50);
X				else	/* 200-600 */
X				ntn[NNOMAD].arm[armynum].sold =200+20*(rand()%20);
X				ntn[NNOMAD].arm[armynum].unittyp = A_CAVALRY;
X				ntn[NNOMAD].arm[armynum].stat =ATTACK;
X				done++;
X			}
X			}
X			done=TRUE;
X			break;
X		case 26:
X			/*town burns -- reduce fort and redesignate*/
X			done=FALSE;
X			for (i=0; i<MAPX; i++) for (j=0; j<MAPY; j++)
X				if(( sct[i][j].owner == country)
X				&& ( done == FALSE )
X				&& ( sct[i][j].designation == DCITY)){
X					sct[i][j].designation = DNODESIG;
X					wdisaster(country,i,j,50,"city burned down");
X					reduce(i,j,50);
X					done=TRUE;
X				}
X			break;
X		case 27:
X			/*plague -- 40% of populace dies*/
X				for (i=0; i<MAPX; i++) for (j=0; j<MAPY; j++)
X					if( sct[i][j].owner == country){
X					sct[i][j].people *= 6;
X					sct[i][j].people /= 10;
X					}
X				for (armynum=0; armynum<MAXARM; armynum++)
X					if((ASOLD > 0)&&(ATYPE<MINMONSTER)){
X						ASOLD *= (6);
X						ASOLD /= (10);
X					}
X			break;
X		case 28: /*pirate raid on harbor*/
X			done=FALSE;
X			break;
X		case 29: /*barbarian raid*/
X			done=FALSE;
X			break;
X		case 30: /*new magician + RANDOM POWER*/
X			/*buy new powers and/or new weapons*/
X			if((newpower=getmagic(M_CIV))!=0L){
X				printf("\tnation %s gets magic power number %ld\n",ntn[country].name,newpower);
X				fprintf(fnews,"1. \tevent in %s->gets magic power number %ld\n", ntn[country].name,newpower);
X				exenewmgk(newpower);
X			}
X			else done=FALSE;
X			break;
X		case 31: /*new magic item + RANDOM POWER*/
X			/*buy new powers and/or new weapons*/
X			if((newpower=getmagic(M_MIL))!=0){
X				printf("\tnation %s gets magic power number %ld\n",ntn[country].name,newpower);
X				fprintf(fnews,"1. \tevent in %s->gets magic power number %ld\n", ntn[country].name,newpower);
X				exenewmgk(newpower);
X			}
X			else done=FALSE;
X			break;
X		case 32:
X			/* ores run out */
X			done=FALSE;
X			for (i=0; i<MAPX; i++) for (j=0; j<MAPY; j++)
X			if(( sct[i][j].owner == country)
X				&& (sct[i][j].iron >= 5)
X				&& (done == FALSE)
X				&& (sct[i][j].designation == DMINE)){
X					sct[i][j].iron =0;
X					sct[i][j].designation = DNODESIG;
X					done=TRUE;
X			}
X		case 33:
X			/*new architect strengthens castle walls */
X				for (i=0; i<MAPX; i++) for (j=0; j<MAPY; j++)
X					if(( sct[i][j].owner == country)
X					&& (sct[i][j].designation == DCITY
X					|| sct[i][j].designation == DCAPITOL))
X					sct[i][j].fortress += 2;
X			break;
X		case 34:
X			/*new ores discovered + 4-10 iron*/
X			done=FALSE;
X			for (i=0; i<MAPX; i++) for (j=0; j<MAPY; j++)
X				if(( sct[i][j].owner == country)
X				&& (done == FALSE)
X				&& (is_habitable(i,j))
X				&& (sct[i][j].iron != 0)){
X					sct[i][j].iron += 4;
X					wierd = (char) rand()%7;
X					sct[i][j].iron += wierd;
X					done=TRUE;
X				}
X			break;
X		case 35:
X			/*new leader sets up peace*/
X			for (newnation=0;newnation<MAXNTN;newnation++) if(country!=newnation) {
X				if( ntn[newnation].dstatus[country]>NEUTRAL ){
X				ntn[newnation].dstatus[country]=NEUTRAL;
X				ntn[country].dstatus[newnation]=NEUTRAL;
X				}
X			}
X			break;
X		case 36:
X		case 37:
X			/*severe winter*/
X			done=FALSE;
X			break;
X		case 38:
X			/*tidal wave -- abandon all coastlands */
X			done=FALSE;
X			break;
X		case 39: /*ninja attack paralyzes half your armys AMOVE=0*/
X		case 40: /*general found to be spy AMOVE=0*/
X			for(armynum=0; armynum<MAXARM; armynum++) if(rand()%2==0)
X				AMOVE = 0;
X			break;
X		case 41:
X			/*general prosperity +20% gold*/
X			if (ntn[country].tgold > 0l) {
X				ntn[country].tgold *= 12l;
X				ntn[country].tgold /= 10l;
X			}
X			else done=FALSE;
X			break;
X		case 42:
X		case 43:
X			/*kill 20% of armies*/
X			for (armynum=0; armynum<MAXARM; armynum++)
X				if((ASOLD > 0) && (ATYPE<MINMONSTER)){
X					ASOLD *= (8);
X					ASOLD /= (10);
X				}
X			break;
X		default:
X			printf("error condition -- illegal random event\n");
X			break;
X		}
X		if(done==TRUE) fprintf(fnews,"1. \tevent in %s - %s\n"
X			,ntn[country].name,randevents[event]);
X		if(done==TRUE) printf("\t%s -- %s\n"
X			,ntn[country].name,randevents[event]);
X		else printf("\t%s -- (unimplemented) %s\n"
X			,ntn[country].name,randevents[event]);
X		if(strlen(eventstr)>5) {
X			printf("\t\t->%s\n",eventstr);
X			if(done==TRUE) fprintf(fnews,"1. \tevent in %s -->%s\n"
X				,ntn[country].name,eventstr);
X		}
X		strcpy(eventstr,"");
X	}
X}
X
X#ifdef VULCANIZE
X/*volcano erupts --- causes devastation in surrounding sectors */
Xvoid
Xerupt()
X{
X	int i, j, nvolcanos=0, volhold;
X
X	printf("checking for volcanic eruptions\n");
X	/* count all of the volcanos */
X	for (i=0; i<MAPX; i++) for (j=0; j<MAPY; j++)
X		if(sct[i][j].vegetation == VOLCANO) nvolcanos++;
X
X	if(nvolcanos==0) {
X		printf("no volcano's found\n");
X		return;
X	}
X	/* choose a random one to erupt */
X	volhold = rand()%nvolcanos;
X	for (i=0; i<MAPX; i++) for (j=0; j<MAPY; j++)
X	if ( sct[i][j].vegetation == VOLCANO ) {
X		volhold--;
X		if (volhold == 0) blowup(i,j);
X	}
X}
X#endif VULCANIZE
X
X/* blowup a volcano in sector i,j */
Xvoid
Xblowup(i,j)
Xregister int i,j;
X{
X	register int x,y;
X	wdisaster(sct[i][j].owner,i,j,100,"volcano erupted");
X	printf("\tvolcano at %d, %d erupts; devastates surounding area\n",i,j);
X	fprintf(fnews,"1. \tevent in sector %d, %d->volcanic eruption causes devastation\n",i,j);
X	sct[i][j].vegetation = VOLCANO;
X	sct[i][j].gold = 0;
X	sct[i][j].iron = 0;
X	reduce(i,j,100);
X	if(is_habitable(i,j))
X		sct[i][j].designation = DDEVASTATED;
X	sct[i][j].fortress = 0;
X	/* decrease neighboring population and armies 30% */
X	for(x=i-1; x<=i+1; x++) for(y=j-1; y<=j+1; y++)
X	if((ONMAP)&&(sct[x][y].altitude != WATER)) {
X		reduce(x,y,30);
X		if(is_habitable(x,y))
X			sct[x][y].designation = DDEVASTATED;
X		sct[x][y].fortress = 0;
X	}
X}
X
X/** reduce will drop armies & and civilians in sector by percent **/
Xvoid
Xreduce(x,y,percent)
Xint x,y,percent;
X{
X	long temp;	/* used to avoid overflow problems */
X	int armynum,ctry;
X
X	percent = 100 - percent;	/* invert percent so math works */
X
X	/* work on people */
X	temp = sct[x][y].people;
X	temp *= percent;
X	temp /= 100;
X	sct[x][y].people = temp;
X
X	/* work on armies */
X	for(ctry=1;ctry<MAXNTN;ctry++) {
X		for(armynum=0;armynum<MAXARM;armynum++)
X		if((ntn[ctry].arm[armynum].xloc==x)
X		&&(ntn[ctry].arm[armynum].unittyp<MINMONSTER)
X		&&(ntn[ctry].arm[armynum].yloc==y)) {
X			temp = ntn[ctry].arm[armynum].sold;
X			temp *= percent;
X			temp /= 100;
X			ntn[ctry].arm[armynum].sold = temp;
X		}
X	}
X}
X
X/* returns pointer to random sector in country */
Xstruct s_sector
X*rand_sector()
X{
X	int count=0;
X	for(xpos=0;xpos<MAPX;xpos++) for(ypos=0;ypos<MAPX;ypos++)
X		if(sct[xpos][ypos].owner == country) count++;
X	count = rand()%count;
X	for(xpos=0;xpos<MAPX;xpos++) for(ypos=0;ypos<MAPX;ypos++){
X		if(sct[xpos][ypos].owner == country) count--;
X		if(count==0) return(&sct[xpos][ypos]);
X	}
X	abrt();
X}
X
X/*global disaster report --- tell 'em where it hit */
Xwdisaster(cntry,xloc,yloc,prcnt,event)
Xint cntry,xloc,yloc,prcnt;
Xchar *event;
X{
X	char line[100];
X	FILE *fp, *fopen();
X	char realname[12];
X
X	/*send a message to the country if it is a PC*/
X	if (ntn[country].active!=1) {
X		return;
X	}
X	strcpy(realname,ntn[cntry].name);
X	sprintf(line,"%s%d",msgfile,cntry);
X	if((fp=fopen(line,"a+"))==NULL) {
X		printf("\nError in writing disaster report.");
X		abrt();
X	}
X	fprintf(fp,"%s GLOBAL DISASTER REPORT\n",realname);
X	fprintf(fp,"%s \n",realname);
X	fprintf(fp,"%s\tDisaster occurs within nation %s:\n",realname,realname);
X	fprintf(fp,"%s\tA %s struck during the day centered around location %d %d.\n",realname,event,xloc,yloc);
X	if(prcnt>0) {
X		fprintf(fp,"%s\tDamage was estimated at about %d%% in severity.\n",realname,prcnt);
X	}
X	fputs("END\n",fp);
X	fclose(fp);
X}
X#endif ADMIN
X#endif RANEVENT
END_OF_randevent.c
if test 22037 -ne `wc -c <randevent.c`; then
    echo shar: \"randevent.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f update.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"update.c\"
else
echo shar: Extracting \"update.c\" \(21402 characters\)
sed "s/^X//" >update.c <<'END_OF_update.c'
X/* Conquer: Copyright (c) 1988 by Edward M Barlow
X *  I spent a long time writing this code & I hope that you respect this.
X *  I give permission to alter the code, but not to copy or redistribute
X *  it without my explicit permission.  If you alter the code,
X *  please document changes and send me a copy, so all can have it.
X *  This code, to the best of my knowledge works well,  but it is my first
X *  'C' program and should be treated as such.  I disclaim any
X *  responsibility for the codes actions (use at your own risk).  I guess
X *  I am saying "Happy gaming", and am trying not to get sued in the process.
X *                                                Ed
X */
X
X#include "header.h"
X#include "data.h"
X#include <ctype.h>
X
Xextern FILE *fnews;
X
Xextern short country;
Xint attr[MAPX][MAPY];     /*sector attactiveness*/
Xextern short movecost[MAPX][MAPY];
X
X/*update nation */
Xvoid
Xupdate()
X{
X	char command[80];
X
X	if ((fnews=fopen(newsfile,"w"))==NULL) {
X		printf("error opening news file\n");
X		exit(FAIL);
X	}
X
X	/*run each nation in a random order*/
X	updexecs();
X
X#ifdef LZARD
X	/* run lizard nations */
X	updlizards();
X#endif
X
X#ifdef MONSTER
X	/* update monster nations */
X	monster();
X#endif
X
X	/*run combat*/
X	combat();
X
X	/* capture unoccupied sectors */
X	updcapture();
X
X	/*for whole map, update one sector at a time*/
X	updsectors();
X
X	/*reset military stuff for whole world*/
X	updmil();
X
X	/*commodities: feed the people, too much gold?, validate iron*/
X	updcomodities();
X
X#ifdef RANEVENT
X	/*run random events */
X	randomevent();
X#endif RANEVENT
X
X	fprintf(fnews,"1\tIMPORTANT WORLD NEWS\n");
X	fclose(fnews);
X
X#ifdef CHEAT
X	cheat();
X#endif CHEAT
X
X	/* score all nations */
X	score();
X
X	sprintf(command,"/bin/rm -f %s*",exefile);
X	printf("%s\n",command);
X	system(command);
X
X	sprintf( command, "sort -n -o %s %s", newsfile, newsfile );
X	printf("%s\n",command);
X	system(command);
X}
X
X/* returns attractiventess */
Xint
Xattract(x,y,race)
X{
X	register struct s_sector	*sptr = &sct[x][y];
X	int	Attr = 1;
X
X	if((sptr->designation==DGOLDMINE)&&(sptr->gold>3)){
X		if(ntn[sptr->owner].jewels<=ntn[sptr->owner].tgold*GOLDTHRESH)
X			Attr+=120;
X		else if(sptr->gold>5) Attr+=120;
X		else Attr+=75;
X	}
X	else if((sptr->designation==DFARM)&&(tofood(sptr->vegetation,sptr->owner)>=6)){
X		if(ntn[sptr->owner].tfood<=ntn[sptr->owner].tciv*FOODTHRESH)
X			Attr+=300;
X		else if(tofood(sptr->vegetation,sptr->owner)==9) Attr+=100;
X		else Attr+=40;
X	}
X	else if(sptr->designation==DCAPITOL) Attr+=200;
X	else if(sptr->designation==DCITY) Attr+=125;
X	else if((sptr->designation==DMINE)&&(sptr->iron>3)) {
X		if(ntn[sptr->owner].tiron<=ntn[sptr->owner].tciv)
X			Attr+=120;
X		else if(sptr->iron>5) Attr+=100;
X		else Attr+=50;
X	}
X
X	switch(race){
X	case DWARF:
X		if((sptr->designation==DGOLDMINE)&&(sptr->gold>=5))
X			Attr+=100;
X		else if((sptr->designation==DMINE)&&(sptr->iron>=5))
X			Attr+=100;
X
X		if(sptr->altitude==MOUNTAIN) Attr+=40;
X		else if(sptr->altitude==HILL) Attr+=20;
X		else if(sptr->altitude==CLEAR) Attr+=0;
X		else Attr=0;
X		break;
X	case ELF:
X		if(sptr->vegetation==JUNGLE) Attr+=40;
X		else if(sptr->vegetation==WOOD) Attr+=90;
X		else if(sptr->vegetation==FOREST) Attr+=50;
X
X		if((sptr->designation==DGOLDMINE)&&(sptr->gold>=5))
X			Attr+=75;
X
X		if(sptr->altitude==MOUNTAIN) Attr-=20;
X		else if(sptr->altitude==HILL) Attr-=10;
X		else if(sptr->altitude==CLEAR) Attr+=0;
X		else Attr=0;
X		break;
X	case HUMAN:
X		Attr+=tofood(sptr->vegetation,sptr->owner)*4;
X
X		if((sptr->designation==DGOLDMINE)&&(sptr->gold>=5))
X			Attr+=75;
X		else if((sptr->designation==DMINE)&&(sptr->iron>=5))
X			Attr+=75;
X		else if((sptr->designation==DFARM)&&(tofood(sptr->vegetation,sptr->owner)>=6))
X			Attr+=55;
X		else if(sptr->designation==DCAPITOL) Attr+=70;
X		else if(sptr->designation==DCITY) Attr+=50;
X
X		if(sptr->altitude==MOUNTAIN) Attr-=10;
X		else if(sptr->altitude==HILL) Attr+=00;
X		else if(sptr->altitude==CLEAR) Attr+=10;
X		else Attr=0;
X		break;
X	case ORC:
X		if(sptr->designation==DCAPITOL) Attr+=120;
X		else if(sptr->designation==DCITY) Attr+=75;
X		else if((sptr->designation==DGOLDMINE)&&(sptr->gold>=5))
X			Attr+=75;
X		else if((sptr->designation==DMINE)&&(sptr->iron>=5))
X			Attr+=75;
X
X		if(sptr->altitude==MOUNTAIN) Attr+=20;
X		else if(sptr->altitude==HILL) Attr+=10;
X		else if(sptr->altitude==CLEAR) Attr+=0;
X		else Attr=0;
X		break;
X	default:
X		break;
X	}
X	if((Attr<0)||(movecost[x][y]<0)) Attr=0;
X	return(Attr);
X}
X
Xvoid
Xarmymove(armynum)
Xint armynum;
X{
X	int		sum, where;
X	register int	x, y;
X
X	sum=0;
X	for(x=AXLOC-2;x<=AXLOC+2;x++)
X		for(y=AYLOC-2;y<=AYLOC+2;y++)
X			if(ONMAP) sum+=attr[x][y];
X
X	if(sum==0) {
X		AXLOC=ntn[country].capx;
X		AYLOC=ntn[country].capy;
X	} else {
X		where=rand()%sum;
X		for(x=AXLOC-2;x<=AXLOC+2;x++) for(y=AYLOC-2;y<=AYLOC+2;y++) {
X			if( x < 0 || x >= MAPX || y < 0 || y >= MAPY )
X				continue;
X
X			where -= attr[x][y];
X			if( (where < 0 )
X			&& movecost[x][y]>=1
X			&& movecost[x][y]<=AMOVE
X		        &&(land_reachp(AXLOC,AYLOC,x,y,AMOVE,country))){
X				AXLOC=x;
X				AYLOC=y;
X				/* CHANGE SO ARMIES MOVE PSEUDO INDEPENDANTLY */
X				if((sct[x][y].designation != DCAPITOL)
X				&&(sct[x][y].designation != DCITY)
X				&&(sct[x][y].owner==country))
X					attr[x][y]/=2;
X
X				if(sct[x][y].owner==0){
X					sct[x][y].owner=country;
X					attr[x][y]/=2;
X				}
X		
X				return;
X			} /* if */
X		} /* for for */
X
X		/*do again - have this block if lots of bad terrain*/
X		/*what could happen is that it won't find a move first time*/
X		for(x=AXLOC-2;x<=AXLOC+2;x++) for(y=AYLOC-2;y<=AYLOC+2;y++) {
X			if( x < 0 || x >= MAPX || y < 0 || y >= MAPY )
X				continue;
X
X			where -= attr[x][y];
X			if( (where < 0 )
X			&& movecost[x][y]>=1
X			&& movecost[x][y]<=AMOVE
X		        &&(land_reachp(AXLOC,AYLOC,x,y,AMOVE,country))){
X				AXLOC=x;
X				AYLOC=y;
X				if(sct[x][y].owner==0)
X					sct[x][y].owner=country;
X				return;
X			} /* if */
X		} /* for for */
X	} /* if */
X}
X
Xvoid
Xscore()
X{
X	int x;
X	printf("\nupdating scores for all nations\n");
X	for(x=1;x<MAXNTN;x++) if(ntn[x].active!=0) ntn[x].score += score_one(x);
X}
X
X#ifdef CHEAT
X/* this routine cheats in favor of npc nations */
Xvoid
Xcheat()
X{
X	int x,y;
X	int bonus=0, count=0, npcavg, pcavg, avgscore=0;
X	/* add gold */
X	for(x=1;x<MAXNTN;x++) if(ntn[x].active>1) {
X		if((ntn[x].tgold<ntn[x].tciv)
X		&&( rand()%5==0)){
X			ntn[x].tgold+=10000;
X			printf("npc cheat routine - add $10000 to nation %s\n",ntn[x].name);
X		}
X	}
X
X	for(x=1;x<MAXNTN;x++) if(ntn[x].active!=0)
X		if(ntn[x].active==1)  {
X			bonus+=ntn[x].aplus+ntn[x].dplus;
X			avgscore+=ntn[x].score;
X			count++;
X		}
X
X	if(count==0) return;
X	pcavg = bonus / count;
X	avgscore /= count;
X	printf("pc average score is %d count is %d\n",avgscore,count);
X
X	bonus=0;
X	count=0;
X	for(x=1;x<MAXNTN;x++) if(ntn[x].active!=0)
X		if(ntn[x].active!=1)  {
X			bonus+=ntn[x].aplus+ntn[x].dplus;
X			count++;
X		}
X	if(count==0) return;
X	npcavg = bonus / count;
X	for(x=1;x<MAXNTN;x++) 
X	if((ntn[x].active > 1) 
X	&&(ntn[x].score < avgscore)
X	&&(rand()%100 < (pcavg-npcavg))) {
X		if(ntn[x].aplus>ntn[x].dplus) ntn[x].dplus+=1;
X		else ntn[x].aplus+=1;
X		printf("npc cheat routine - add 1%% to nation %s combat skill\n",ntn[x].name);
X	}
X
X	/* cheat by making npc's frendlier to each other if they are */
X	/* of the same race */
X	for(x=1;x<MAXNTN;x++) if(ntn[x].active>=2)
X		for(y=1;y<MAXNTN;y++) if(ntn[y].active>=2)
X			if((ntn[x].dstatus[y]!=CONFEDERACY)
X			&&(ntn[x].dstatus[y]!=UNMET)){
X				if(ntn[x].race == ntn[y].race){
X					ntn[x].dstatus[y]--;
X				} else {
X					if(ntn[x].dstatus[y]!=JIHAD)
X						if(rand()%4==0)
X							ntn[x].dstatus[y]--;
X				}
X			}
X}
X#endif CHEAT
X
X/* update all nations in a random order, move civilians of that nation */
Xupdexecs()
X{
X	register struct s_sector	*sptr;
X	register int i, j;
X	register int x,y;
X	int moved,done, number=0;
X
X	int finis=FALSE;
X	int execed[MAXNTN];
X
X	for(country=0;country<MAXNTN;country++) execed[country]=FALSE;
X
X	system("date");
X
X	while(finis==FALSE){
X
X		/*get random active nation*/
X		country=(rand()%(MAXNTN-1))+1;
X		if(ntn[country].active <= 0) continue;
X
X		done=FALSE;
X		number=0;
X		/*Find the next unupdated nation*/
X		while(done==FALSE){
X			if((ntn[country].active>0)
X			&&(execed[country]==FALSE)) {
X				done=TRUE;
X				execed[country]=TRUE;
X			} else {
X				country++;
X				number++;
X				if(number>MAXNTN) {
X					finis=TRUE;
X					done=TRUE;
X				}
X				else if(country>=MAXNTN) country=1;
X			}
X		}
X
X		if(finis==TRUE) continue;
X
X		printf("updating nation number %d -> %s\n",country,ntn[country].name);
X
X		/*if execute is 0 and PC nation then they did not move*/
X		if((execute()==0)&&(ntn[country].active==1)){
X			printf("\tnation %s did not move\n",ntn[country].name);
X#ifdef CMOVE
X			printf("\tthe computer will move for %s\n",ntn[country].name);
X			fprintf(fnews,"1.\tthe computer will move for %s\n",ntn[country].name);
X			nationrun();
X#endif
X		}
X#ifdef NPC
X		/* run npc nations */
X		if(ntn[country].active>=2) {
X			nationrun();
X			/*do magic*/
X#ifdef ORCTAKE
X			if(magic(country,MA_MONST)==1) {
X				if(x=takeover(5,0)==1)
X				printf("SUCCESSFUL TAKEOVER OF %d",x);
X			} else if(magic(country,AV_MONST)==1) {
X				if(x=takeover(3,0)==1)
X				printf("SUCCESSFUL TAKEOVER OF %d",x);
X			} else if(magic(country,MI_MONST)==1){
X				if(x=takeover(1,0)==1)
X				printf("SUCCESSFUL TAKEOVER OF %d",x);
X			}
X#endif ORCTAKE
X		}
X#endif
X
X		/*update movement array*/
X		updmove( ntn[country].race,country );
X
X		/*THIS IS WHERE YOU ZERO THE ATTR MATRIX*/
X		/*calculate sector attractiveness*/
X		for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) {
X			sptr = &sct[x][y];
X			if((sptr->owner==country)
X			&&(tofood(sptr->vegetation,sptr->owner)!=0)){
X				attr[x][y]=attract(x,y,ntn[country].race);
X			}
X			else if(((magic(sptr->owner,DERVISH)==1)
X			||(magic(sptr->owner,DESTROYER)==1))
X			&&((sptr->vegetation==ICE)
X			||(sptr->vegetation==DESERT))) {
X				attr[x][y]=36;
X			}
X			else attr[x][y]=0;
X		}
X
X		/*if near capitol add to attr*/
X		for(x=ntn[country].capx-2;x<=ntn[country].capx+2;x++)
X			for(y=ntn[country].capy-2;y<=ntn[country].capy+2;y++)
X				if(attr[x][y]>0) attr[x][y]+=20;
X
X/*MOVE CIVILIANS based on the ratio of attractivenesses
X	 *
X	 * EQUILIBRIUM(1) = A1/(A1+A2) * (P1+P2)
X	 * EQUILIBRIUM(2) = A2/(A1+A2) * (P1+P2)
X	 * MOVE 1/5 of way to equilibrium each turn
X	 * DELTA(1) = (EQUILIBRIUM(1)-P1)/5 = (A1P2-P1A2)/5(A1+A2)
X	 * DELTA(2) = (EQUILIBRIUM(2)-P2)/5 = (A2P1-P2A1)/5(A1+A2) = -DELTA(1)
X	 * ij is refered to as 1, xy as 2
X	 * NOTE AM ADDING 1 to divisor to prevent floating exception errors
X	 */
X		for(x=0; x<MAPX; x++ ) for(y=0; y<MAPY; y++) {
X
X			sptr = &sct[x][y];
X			if( sptr->owner != country )
X				continue;
X			if( sptr->people == 0 )
X				continue;
X
X			for(i=x-2;i<=x+2;i++) {
X				if( i < 0 || i >= MAPX  )
X					continue;
X
X				for(j=y-2;j<=y+2;j++) {
X					if( j < 0 || j >= MAPY )
X						continue;
X					if( sct[i][j].owner != country)
X						continue;
X					moved=(sptr->people*attr[i][j]-sct[i][j].people*attr[x][y])/(1+5*(attr[i][j]+attr[x][y]));
X					if( moved <= 0 )
X						continue;
X
X					sct[i][j].people += moved;
X					sptr->people -= moved;
X				} /* for */
X			} /* for */
X		} /* for */
X	} /* while */
X
X	/*zero out all recalculated values*/
X	for(country=0;country<MAXNTN;country++){
X		ntn[country].tships=0;
X		ntn[country].tmil=0;
X		if(magic(country,SUMMON)==TRUE) {
X			if(rand()%4==0) ntn[country].spellpts/=2;
X			ntn[country].spellpts+=4;
X			if(magic(country,WYZARD)==TRUE)
X				ntn[country].spellpts+=3;
X			if(magic(country,SORCERER)==TRUE)
X				ntn[country].spellpts+=3;
X		}
X	}
X
X}
X
X#ifdef LZARD
X/* update lizards and monsters */
Xupdlizards()
X{
X	register int i, j;
X	int armynum;
X
X	puts("updating lizards\n ");
X	country = NLIZARD;
X	/*move to lizard castle*/
X	for(armynum=0;armynum<MAXARM;armynum++)
X	if((ASOLD>0)&&(ASTAT==ATTACK)) {
X		if(ntn[NLIZARD].arm[armynum-1].sold<=0) {
X			ASOLD=0;
X			continue;
X		}
X		AMOVE =20;	/* just in case god wants to move them */
X		AXLOC = ntn[NLIZARD].arm[armynum-1].xloc;
X		AYLOC = ntn[NLIZARD].arm[armynum-1].yloc;
X		for(i=ntn[NLIZARD].arm[armynum-1].xloc-1;i<=ntn[NLIZARD].arm[armynum-1].xloc+1;i++) {
X			for(j=ntn[NLIZARD].arm[armynum-1].yloc-1;j<=ntn[NLIZARD].arm[armynum-1].yloc+1;j++) {
X				if((i>=0)&&(j>=0)&&(i<MAPX)&&(j<MAPY)
X				&&(sct[i][j].altitude!=WATER)
X				&&(sct[i][j].altitude!=PEAK)
X				&&(sct[i][j].owner != NLIZARD)
X				&&(rand()%3==0)){
X					AXLOC = i;
X					AYLOC = j;
X				}
X			}
X		}
X	}
X#ifdef DEBUG
X	for(armynum=0;armynum<MAXARM;armynum++) {
X		if((ASOLD>0)&&(sct[AXLOC][AYLOC].altitude==WATER))
X			printf("ERROR line %d... %s army %d in water (army %d: x: %d y: %d)\n",__LINE__,ntn[NLIZARD].name,armynum,armynum-1, ntn[NLIZARD].arm[armynum-1].xloc, ntn[NLIZARD].arm[armynum-1].yloc);
X	}
X#endif DEBUG
X}
X#endif
X
X/* capture unoccupied sectors */
Xupdcapture()
X{
X	register struct s_sector	*sptr;
X	int armynum;
X
X	fprintf(fnews,"3\tNEWS ON WHAT SECTORS HAVE BEEN CAPTURED\n");
X	/*look for any areas where armies alone in sector*/
X	prep(country);
X	for(country=1;country<NTOTAL;country++) if(ntn[country].active!=0){
X		for(armynum=0;armynum<MAXARM;armynum++)
X/* cheat in favor of npcs as the routines assume 75 man armies */
X		if(((ntn[country].active==1)&&(ASOLD>TAKESECTOR))
X		||((ntn[country].active>1)&&(ASOLD>75))){
X			sptr = &sct[AXLOC][AYLOC];
X			if(sptr->owner==0){
X				sptr->owner=country;
X			}
X			else if((sptr->owner!=country)
X			&&(ntn[country].dstatus[sptr->owner]>=WAR)
X			&&(occ[AXLOC][AYLOC]==country)){
X
X				if((sptr->owner!=0)
X				&&(ntn[sptr->owner].race!=ntn[country].race))
X					if(magic(country,SLAVER)==TRUE){
X					flee(AXLOC,AYLOC,1,TRUE);
X					}else{
X					flee(AXLOC,AYLOC,1,FALSE);
X					}
X#ifdef HIDELOC
X				fprintf(fnews,"3.\tarea captured by %s from %s\n",ntn[country].name,ntn[sptr->owner].name);
X#else
X				fprintf(fnews,"3.\tarea %d,%d captured by %s from %s\n",AXLOC,AYLOC,ntn[country].name,ntn[sptr->owner].name);
X#endif HIDELOC
X				sptr->owner=country;
X			}
X		}
X	}
X
X	/* capture countries */
X	for(country=1;country<MAXNTN;country++)
X		if((ntn[country].active>=2)
X		&&((ntn[country].tciv==0)
X		||(sct[ntn[country].capx][ntn[country].capy].owner!=country)))
X			destroy(country);
X}
X
X/* update sectors */
Xupdsectors()
X{
X	register struct s_sector	*sptr;
X	register struct nation		*nptr;
X	register int i, j;
X	register int x,y;
X
X	printf("\nupdating all sectors\n");
X	for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) {
X		sptr = &sct[x][y];
X		if(sptr->owner == 0) continue;
X		nptr = &ntn[sptr->owner];
X
X		/* add to contents of sector */
X		if(rand()%100<FINDPERCENT) {
X			if(rand()%2==0) sct[x][y].iron++;
X			else sct[x][y].gold++;
X		}
X
X		/* if huge number dont reproduce */
X		if(sptr->people > BIG / 50L) {
X			if(sptr->people * sptr->iron > 2*(rand()%100)*TOMUCHMINED)
X				sptr->iron--;
X			if(sptr->people * sptr->gold > 2*(rand()%100)*TOMUCHMINED)
X				sptr->gold--;
X		} else if((sptr->people > TOMANYPEOPLE)&&(sptr->designation!=DCITY)&&(sptr->designation!=DCAPITOL)){
X			sptr->people += (nptr->repro * sptr->people)/200;
X			if(sptr->people * sptr->iron > 2*(rand()%100)*TOMUCHMINED)
X				sptr->iron--;
X			if(sptr->people * sptr->gold > 2*(rand()%100)*TOMUCHMINED)
X				sptr->gold--;
X		} else if(sptr->people<100) {
X			sptr->people+=sptr->people/10;
X		} else {
X			sptr->people += (nptr->repro * sptr->people)/100;
X			if(sptr->people * sptr->iron > (rand()%100)*TOMUCHMINED)
X				sptr->iron--;
X			if(sptr->people * sptr->gold > (rand()%100)*TOMUCHMINED)
X				sptr->gold--;
X		}
X
X		/*check all adjacent sectors and decide if met */
X		for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++)
X		if(i>=0&&i<MAPX&&j>=0&&j<MAPY&&(sct[i][j].owner!=0)) {
X			if(sptr->owner!=sct[i][j].owner) {
X				if(nptr->dstatus[sct[i][j].owner]==UNMET)
X					newdip(sptr->owner,sct[i][j].owner);
X				if(ntn[sct[i][j].owner].dstatus[sptr->owner]==UNMET)
X					newdip(sct[i][j].owner,sptr->owner);
X			}
X		}
X
X		/* if desert sector... reverts to desert */
X		if(tofood(sptr->vegetation,sptr->owner)<DESFOOD){
X			sptr->designation=DNODESIG;
X		}
X	}
X
X	for(country=1;country<MAXNTN;country++) {
X		if(ntn[country].active != 0){
X			spreadsheet(country);
X			ntn[country].tsctrs = spread.sectors;
X			ntn[country].tciv=spread.civilians;
X			ntn[country].tfood=spread.food;
X			ntn[country].tgold=spread.gold;
X			ntn[country].tiron=spread.iron;
X			ntn[country].jewels=spread.jewels;
X		}
X	}
X}
X
X/* reset military stuff */
Xupdmil()
X{
X	register int x,y;
X	int armynum,nvynum;
X
X	printf("updating armies and navies\n");
X	for(country=1;country<NTOTAL;country++) if(ntn[country].active!=0){
X		for(armynum=0;armynum<MAXARM;armynum++){
X			if(ASOLD>0) {
X				ntn[country].tmil+=ASOLD;
X				/*add movement to all armies */
X				/*unitmove is 10 times movement rate*/
X				switch(ASTAT) {
X				case MARCH:
X					AMOVE=(ntn[country].maxmove * *(unitmove+(ATYPE%100)))/5;
X					break;
X				case SCOUT:
X				case ATTACK:
X				case DEFEND:
X					AMOVE=(ntn[country].maxmove * *(unitmove+(ATYPE%100)))/10;
X					break;
X				case GARRISON:
X					AMOVE=0;
X					break;
X				default:
X					ASTAT=DEFEND;
X					AMOVE=(ntn[country].maxmove * *(unitmove+(ATYPE%100)))/10;
X				}
X				if((magic(country,ROADS)==1)
X				&&(sct[AXLOC][AYLOC].owner!=country))
X					if(AMOVE>4) AMOVE-=4;
X
X				if((magic(country,VAMPIRE)==1)
X				&&(ATYPE<100)){
X				ntn[country].tgold -= ASOLD * (*(unitmaint+(ATYPE))) / 4;
X				} else
X				if((magic(country,SAPPER)==1)
X				&&((ATYPE==A_CATAPULT)||(ATYPE==A_SEIGE))){
X				ntn[country].tgold -= ASOLD * (*(unitmaint+(ATYPE))) / 2;
X				} else
X				ntn[country].tgold -= ASOLD * (*(unitmaint+(ATYPE%100)));
X				if(ATYPE>=MINMONSTER)
X				ntn[country].jewels -= ASOLD * (*(unitmaint+(ATYPE%100))/5);
X			}
X		}
X		/*add to movement of fleets*/
X		for(nvynum=0;nvynum<MAXNAVY;nvynum++) {
X			/*update sea sectors*/
X			if( NMER + NWAR > 0 ) {
X				if(sct[NXLOC][NYLOC].altitude==WATER) {
X#ifdef STORMS
X/*
X *	Storms should stay around and slowly move
X *	around the world.
X */
X				/*all ships sunk on percentage PSTORM*/
X				/*pirates never are sunk (implicitly)*/
X				if( country != NPIRATE &&
X				(rand()%100 < PSTORM) ) {
X					x = NXLOC;
X					y = NYLOC;
X#ifdef HIDELOC
X					fprintf(fnews,"3.\tstorm sinks %s fleet at sea\n",ntn[country].name);
X#else
X					fprintf(fnews,"3.\tstorm sinks %s fleet in %d,%d\n",ntn[country].name,x,y);
X#endif HIDELOC
X					NWAR=0;
X					NMER=0;
X				}
X#endif
X				}
X				NMOVE = 3 * ntn[country].maxmove * NCREW;
X				NMOVE /= ((NWAR+NMER)*SHIPCREW);
X				ntn[country].tships += NWAR + NMER;
X				ntn[country].tgold -= (NWAR + NMER) * SHIPMAINT;
X			} else {
X				NWAR=0;
X				NMER=0;
X			}
X		} /* for */
X	}
X}
X
X/* update commodities */
Xupdcomodities()
X{
X	FILE *fpmsg;
X	register struct s_sector	*sptr;
X	register int x,y;
X	long xx;
X	char command[80];
X	long dead;
X
X	fprintf(fnews,"2\tWORLD FOOD SUPPLY & DECLARATIONS OF WAR\n");
X	for(country=1;country<MAXNTN;country++) if(ntn[country].active!=0){
X		/*soldiers eat  2*/
X		ntn[country].tfood-=ntn[country].tmil*2;
X		/*civilians eat 1*/
X		ntn[country].tfood-=ntn[country].tciv;
X
X		/*starve people*/
X		if(ntn[country].tfood<0) for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) {
X			sptr = &sct[x][y];
X			if((sptr->owner==country)
X			&&((sptr->designation==DCITY)
X			||(sptr->designation==DCAPITOL))
X			&&(ntn[country].tfood<0)){
X				/*lose one person in city per three food*/
X				/*maximum of 1/3 people in city lost*/
X				if(sptr->people < ntn[country].tfood){
X					sptr->people+=ntn[country].tfood/3;
X					ntn[country].tfood=0;
X				}
X				else {
X					ntn[country].tfood+=sptr->people;
X					dead = sptr->people/3;
X					sptr->people -= dead;
X				}
X				fprintf(fnews,"2.\tfamine hits city at %d,%d in %s.\n",x,y,ntn[country].name);
X#ifdef HIDELOC
X				fprintf(fnews,"2.\tfamine hits town in %s.\n",ntn[country].name);
X#else
X				fprintf(fnews,"2.\tfamine hits town at %d,%d in %s.\n",x,y,ntn[country].name);
X#endif HIDELOC
X				printf("famine hits town at %d,%d in %s.\n",x,y,ntn[country].name);
X				sprintf(command,"%s%d",msgfile,country);
X				if(ntn[country].active==1)
X				if((fpmsg=fopen(command,"a+"))==NULL) {
X				printf("error opening %s\n",command);
X				} else {
X				fprintf(fpmsg,"%s notice from program\n%s\n",ntn[country].name,ntn[country].name);
X				fprintf(fpmsg,"%s famine hits town at %d,%d in %s.-> %ld people reduced by %ld\n%s\n",ntn[country].name,x,y,ntn[country].name,sptr->people,dead,ntn[country].name);
X				fprintf(fpmsg,"END\n");
X				fclose(fpmsg);
X				}
X			}
X		}
X		/*this state can occur if few people live in cities*/
X		if(ntn[country].tfood<0) {
X			ntn[country].tfood=0L;
X		}
X		else if(ntn[country].tfood>FOODTHRESH*ntn[country].tciv) {
X			ntn[country].tgold+=ntn[country].tfood-FOODTHRESH*ntn[country].tciv;
X			ntn[country].tfood=FOODTHRESH*ntn[country].tciv;
X		}
X
X		if(ntn[country].tgold>GOLDTHRESH*ntn[country].jewels){
X			xx=ntn[country].tgold-GOLDTHRESH*ntn[country].jewels;
X			ntn[country].jewels += xx/GOLDTHRESH;
X			ntn[country].tgold  -= xx;
X		}
X		else if(ntn[country].tgold > JEWELTHRESH * ntn[country].jewels){
X			fprintf(fnews,"3.\tTAX REVOLT IN NATION %s\n",ntn[country].name);
X		}
X
X		/* fix overflow problems */
X     	if(ntn[country].tgold < -1*BIG)  {
X			fprintf(fnews,"2.\tVariable Overflow - gold in nation %s\n",ntn[country].name);
X			ntn[country].tgold=BIG;
X		}
X     	if(ntn[country].tfood < -1*BIG)  {
X			fprintf(fnews,"2.\tVariable Overflow - food in nation %s\n",ntn[country].name);
X			ntn[country].tfood=BIG;
X		}
X     	if(ntn[country].jewels < -1*BIG) {
X			fprintf(fnews,"2.\tVariable Overflow - jewels in nation %s\n",ntn[country].name);
X			ntn[country].jewels=BIG;
X		}
X     	if(ntn[country].tiron < -1*BIG)  {
X			fprintf(fnews,"2.\tVariable Overflow - iron in nation %s\n",ntn[country].name);
X			ntn[country].tiron=BIG;
X		}
X	}
X}
END_OF_update.c
if test 21402 -ne `wc -c <update.c`; then
    echo shar: \"update.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 5 \(of 8\).
cp /dev/null ark5isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 8 archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0