[comp.sources.games] v06i083: conquer4 - middle earth multi-player game

billr@saab.CNA.TEK.COM (Bill Randle) (06/24/89)

Submitted-by: adb@bu-it.bu.edu (Adam Bryant)
Posting-number: Volume 6, Issue 83
Archive-name: conquer4/Part01
Superseeds: conquer3; Volume 4, Issue 42-49



	[Ed has given me permission to distribute this via USENET.  As mentioned
	 in the README file, he is losing his net address, so bug reports, etc.
	 should be refered to Adam, whose address is in the "Submitted-by" field
	 above.		-br]

#! /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 1 (of 14)."
# Contents:  README MANIFEST patchlevel.h update.c
# Wrapped by billr@saab on Thu Jun 15 15:20:08 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(7658 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X	*********************************************************
X	*	README FILE FOR THE INSTALLER OF CONQUER	*
X	*********************************************************
X
XWhat you have here is a copyrighted release 4 version version of CONQUER.  
XI make no guaranties to the sanity or style of this code, but do believe
Xthat it should work as documented.  I have included numerous bugfixes
Xfrom previous releases posting, and have added numerous enhancements. 
XThe file notes.v4 details changes between v3.5 and v4, bugs and other things.  
X
XI have no current email address... Too bad.  I will post a patch to THIS FILE
Xwhen i get a new email address. The hazards of switching jobs.   Adam Bryant
Xhas volunteered to take mail for the summer of 1989 at
X"arpa!bucsf.bu.edu!adb".  He is the co-author of the game... so send comments
Xto him. We like feedback on the game.  Comments and feature requests are
Xvery useful to me as they are my primary method of deciding what to next
Xadd to the code.  Your interest is appreciated.
X
XIncluded in this file are the following:
X	1) A Brief Description of Conquer
X	2) Installation (unpacking) Instructions
X	3) Configuration Instructions
X	4) Compilation Instructions
X	5) Administration instructions
X	6) Changes in this version
X
XThis version should not be redistributed ( please read the copyright note in
Xheader.h ).	Any comments and bug reports would be appreciated.
X
X-----------------------------------------------------------
XI   A Brief Description of Conquer
X-----------------------------------------------------------
XA complete description of Conquer v4 is contained in "man.page" and 
X"conquer.docs".  "conquer.docs" is created from the files txt[0-5] which
Xare customized from data in the header files.  These txt[] files are
Xthen converted int help[0-5] files, which contain configuration data.
X"make docs" will create this file from current data.  Note conquer.doc IS 
XCREATED WHEN THE PROGRAM IS COMPILED.  I have tried to make the documentation 
Xas good as possible, but I guarantee that I have missed a lot.    Consider
Xthis a feature and enjoy any (hopefully pleasant) suprises you get.
X-----------------------------------------------------------
XII  Installation (unpacking) Instructions
X-----------------------------------------------------------
XThis program came in several shell archive scripts. They can can be unpacked
Xby using "sh filename".  If you are reading this, you know this.
X
XIf you suspect missing files, please check the MANIFEST.
X-----------------------------------------------------------
XIII Configuration
X-----------------------------------------------------------
XTHE FOLLOWING FILES SHOULD BE MODIFIED TO REFLECT YOUR ENVIRONMENT
XAND THE TYPE OF GAME YOU WISH TO PLAY.  THE GAME WILL NOT RUN UNLESS
XYOU MODIFY THESE FILES APPROPRIATELY.
X
Xheader.h	modify as per instructions
XMakefile	modify as per instructions
X
XI have tried to comment this stuff appropriately.
X
XThe options specified in these files will be reflected
Xin the conquer.docs and help files when the program is compiled.
X
XYou will probably also want to take a look at the "rules*" file. This
Xcontains the grammar rules for the random mail messages generated by
XNPC's. You may wish to insert some local people's names, or think of
Xsome really juicy insults. The format of the file should be obvious;
Xbasically %FOO declares a class FOO and one of the things inside that
Xclass will be selected randomly. Obviously, %MAIN is the top level which
Xthen calls on the subclasses to construct sentences.
X
X-----------------------------------------------------------
XIV  Compilation Instructions
X-----------------------------------------------------------
XThis program should be easy to compile.  Just type make.
X
XNote: Sometimes curses does not include termcap or termlib.  If all the
X	'.c' files get compiled, but do not link together,  and 
X	unreferenced symbol errors occur,  try adding "-ltermcap" after
X	the "-lcurses" line in the makefile.
X
X-----------------------------------------------------------
XV   administration instructions
X-----------------------------------------------------------
XNow that you have compiled it, this is how you administer/set up/run the game.
XI recommend following these instructions once yourself in a mock game 
X(ie. no other players) for a few turns to get things straight.  Then you 
Xcan add other players.
X
XThe command line format for the administration commands is 
X
X	conqrun [-maxp -dDIR -rSCENARIO]\n",argv[0]);
X		-m          make a world
X		-a          add new player
X		-x          execute program
X		-d DIR      to use play different game
X		-p          print a map
X		-r SCENARIO read map while making a new world
X			    uses SCENARIO.ele, SCENARIO.veg, &  SCENARIO.nat
X
XThe conqrun executable is for the game super user only (game password is
Xchecked)
X
XIn addition the the conqrun command, the makefile helps you as follows:
X
Xmake:		Compiles the code.
Xmake clobber:   Clobber everything but the source (destroys executables)
Xmake clean:     Clean up objects (does not destroy executables)
Xmake new_game:	Create a new game, make world, add players...
Xmake install:	Install game in appropriate directory
Xmake docs:	Creates documentation from help file
X
XFinally, I have included an 'at' script that permits automatic updating.
Xrun:		read this shell script, it permits you to run the update
X		automatically.  It needs to be modified for time to update.
X
XThe command line for the conquer executable can be found by reading
Xthe help files.  
X
XAgain, prior to the compile, you should have followed the instructions
Xin the Makefile and in header.h.  
X
XYou can administrate world either via "make new_game" or via:
X	<conqrun -m>    this will make your world.  
X			This also sets up npc nations as per the nations file
X			npc stats can be adjusted by editing nations
X			prior to making the world.  Non player nations have
X			the same password as god.
Xor	 <conqrun -rSCENARIO>    this will make your world by using scenarios.
X			Basically, the scenarios include a nation file and
X			three map files (elevation, vegetation, and nation
X			setup). Look at the rome scenario included in the game.
X			[ this scenario is not finished yet ]
X
XYou can add ( 0 or more ) players via
X	<conqrun -a>    which should be self explanatory.  This wont work if
X			the world is filled, as it would be if a scenario was
X			read in and the SCENARIO.ntn file filled the world.
X			This is because the program wont find spots to place
X			your players.  Adjust the nations file for your
X			scenario to set up players.  When they log in, they
X			will be asked for a new password.
X
X
XOnce you log in as a player or as god, you can get help by
Xtyping '?'.  Play around with the commands and get your syntax right.
X
XTry logging in as either a player or non player nation (they use the super
Xuser password) and noticing any differences.
X
XIMPORTANT NOTE ON PLAY BALANCE: 
XThe world is not created equal.  Some players may start in very bad
Xpositions.  You can either start them over (destroy that nation in the
Xchange nation command and create a new one), or modify the surrounding
Xterain appropriately (god can use the redesignate command to change
Xelevation and vegetation).
X
XNow move around on the map and learn where the players are
Xpositioned.  If there is a problem (they are surrounded by water...), 
Xuse the redesignate command to change elevation or vegetation. 
XIn the worst case, god can destroy a nation
Xwith 'c', the change nation command.  Once you
Xthink the game will be fair, it is time to allow players to proceed.
X
XNow you are all set -- play via 
X	<conquer>
X
Xand update with <conqrun -x> via an script similar to "run"
END_OF_FILE
if test 7658 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'MANIFEST'\"
else
echo shar: Extracting \"'MANIFEST'\" \(1447 characters\)
sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
X   File Name		Archive #	Description
X-----------------------------------------------------------
X MANIFEST                   1	This shipping list
X Makefile                  14	
X README                     1	
X admin.c                    9	
X cexecute.c                14	
X check.c                    9	
X combat.c                   4	
X commands.c                 6	
X data.c                    13	
X data.h                     8	
X display.c                 11	
X extcmds.c                  2	
X forms.c                   13	
X header.h                  13	
X io.c                       4	
X magic.c                    8	
X main.c                    10	
X makeworl.c                 9	
X man.pag                   14	
X misc.c                     3	
X move.c                     7	
X nations                    6	
X navy.c                     3	
X newhelp.c                 12	
X newlogin.c                 7	
X newlogin.h                 9	
X notes.v4                   2	
X npc.c                      5	
X patchlevel.h               1	
X randeven.c                11	
X reports.c                 10	
X rules                     12	
X run                        4	
X sort.c                    14	
X spew.c                    12	
X trade.c                   12	
X txt0                      13	
X txt1                       5	
X txt2                       6	
X txt3                      14	
X txt4                       7	
X txt5                      11	
X update.c                   1	
END_OF_FILE
if test 1447 -ne `wc -c <'MANIFEST'`; then
    echo shar: \"'MANIFEST'\" unpacked with wrong size!
fi
# end of 'MANIFEST'
fi
if test -f 'patchlevel.h' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'patchlevel.h'\"
else
echo shar: Extracting \"'patchlevel.h'\" \(21 characters\)
sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
X#define PATCHLEVEL	0
END_OF_FILE
if test 21 -ne `wc -c <'patchlevel.h'`; then
    echo shar: \"'patchlevel.h'\" unpacked with wrong size!
fi
# end of 'patchlevel.h'
fi
if test -f 'update.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'update.c'\"
else
echo shar: Extracting \"'update.c'\" \(42715 characters\)
sed "s/^X//" >'update.c' <<'END_OF_FILE'
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	dissarray;		/* TRUE if nation in dissarray */
Xint	**attr;			/* sector attractiveness */
X
X/****************************************************************/
X/*	UPDATE() - updates the whole world			*/
X/****************************************************************/
Xvoid
Xupdate()
X{
X	char command[80],filename[80];
X
X	sprintf(filename,"%s%d",newsfile,TURN);
X	if ((fnews=fopen(filename,"w"))==NULL) {
X		printf("error opening news file\n");
X		exit(FAIL);
X	}
X	check();
X
X	updexecs();	/*run each nation in a random order*/
X	check();
X
X#ifdef MONSTER
X	for( country=1;country<NTOTAL;country++)
X		if( ntn[country].active == NPC_LIZARD )
X			updlizards();	/* run lizard nations */
X	check();
X	monster();	/* update monster nations */
X	check();
X#endif
X
X	check();
X	combat();	/* run combat */
X	check();
X	updcapture();	/* capture unoccupied sectors */
X
X#ifdef TRADE
X	uptrade();	/* update trade */
X#endif
X
X	updmil();	/* reset military stuff for whole world */
X
X#ifdef RANEVENT
X	randomevent();	/*run random events after setting movements */
X#endif RANEVENT
X
X	updsectors();	/* for whole map, update one sector at a time*/
X	updcomodities();/* commodities & food, metal, jewels */
X	updleader();	/* new leaders are born, old leaders become wiser */
X
X	/* check for destroyed nations */
X	for(country=1;country<NTOTAL;country++)
X	if(isntn(ntn[country].active)) {
X		if(ntn[country].tciv + ntn[country].tmil < 50)
X			destroy(country);
X	}
X
X	fprintf(fnews,"1\tIMPORTANT WORLD NEWS\n");
X	fprintf(fnews,"5\tGLOBAL ANNOUNCEMENTS (see mail)\n");
X	fclose(fnews);
X
X#ifdef CHEAT
X	cheat();
X#endif CHEAT
X
X	score();	/* score all nations */
X
X	/* check for mercenary increase 5% chance*/
X	if (rand()%20==0) {
X		printf("increasing mercenary bonuses\n");
X		MERCATT++;
X		MERCDEF++;
X	}
X	sprintf(command,"/bin/rm -f %s*",exefile);
X	printf("%s\n",command);
X	system(command);
X
X	sprintf( command,"%s/%s %s %s", EXEDIR, sortname, filename, filename );
X	printf("%s\n",command);
X	system(command);
X
X	/* remove old news files */
X	if (TURN>MAXNEWS) {
X		sprintf(filename,"%s%d",newsfile,TURN-MAXNEWS);
X		unlink(filename);
X	}
X
X	/* increase turn number by one */
X	TURN++;
X	att_base();	/* calculate base for nation attributes */
X	att_bonus();	/* calculate tradegood bonus for nation attributes */
X}
X
X/****************************************************************/
X/*	ATTRACT() - how attractive is sector to civilians	*/
X/* returns attractiveness 					*/
X/****************************************************************/
Xint
Xattract(x,y,race)
X{
X	register struct s_sector	*sptr = &sct[x][y];
X	int	designation;
X	int	Attr = 1;
X
X	designation=sptr->designation;
X	if(sptr->tradegood != TG_none
X	&& *(tg_stype+sptr->tradegood)==designation ) {
X		if((designation!=DMINE)
X		&& (designation!=DGOLDMINE))
X		Attr += ( tg_value[sptr->tradegood] - '0' )*TGATTR;
X	}
X
X	if(designation==DGOLDMINE){
X		if(sptr->jewels>=6) Attr+=GOLDATTR*sptr->jewels*2;
X		else	Attr+=GOLDATTR*sptr->jewels;
X	} else if(designation==DFARM){
X		if(ntn[sptr->owner].tfood <= ntn[sptr->owner].eatrate*(ntn[sptr->owner].tciv*11)/250)
X			Attr+=50*FARMATTR;
X		else Attr+=tofood(sptr,sptr->owner)*FARMATTR;
X	}
X	else if(designation==DCITY) Attr+=CITYATTR;
X	else if(designation==DCAPITOL) Attr+=CITYATTR;
X	else if(designation==DTOWN) Attr+=TOWNATTR;
X	else if(designation==DMINE) {
X		if(sptr->metal>6) Attr+=MINEATTR*sptr->metal*2;
X		else Attr+=MINEATTR*sptr->metal;
X	} else if((designation!=DROAD)&&(designation!=DNODESIG)
X	&&(designation!=DDEVASTATED)&& is_habitable(x,y) ) Attr+= OTHRATTR;
X
X	switch(race){
X	case DWARF:
X		if((designation==DGOLDMINE)&&(sptr->jewels>=4))
X			Attr += DGOLDATTR;
X		else if((designation==DMINE)&&(sptr->metal>=4))
X			Attr += DMINEATTR;
X		else if(designation==DTOWN) Attr += DTOWNATTR;
X		else if(designation==DCITY) Attr += DCITYATTR;
X		else if(designation==DCAPITOL) Attr += DCITYATTR;
X
X		if(sptr->vegetation==WOOD) Attr += DWOODATTR;
X		else if(sptr->vegetation==FOREST) Attr += DFOREATTR;
X
X		if(sptr->altitude==MOUNTAIN) Attr += DMNTNATTR;
X		else if(sptr->altitude==HILL) Attr += DHILLATTR;
X		else if(sptr->altitude==CLEAR) Attr += DCLERATTR;
X		else Attr=0;
X		break;
X	case ELF:
X		if((designation==DGOLDMINE)&&(sptr->jewels>=4))
X			Attr += EGOLDATTR;
X		else if((designation==DMINE)&&(sptr->metal>=4))
X			Attr += EMINEATTR;
X		else if(designation==DTOWN) Attr += ECITYATTR;
X		else if(designation==DCITY) Attr += ECITYATTR;
X		else if(designation==DCAPITOL) Attr += ECITYATTR;
X
X		if(sptr->vegetation==WOOD) Attr += EWOODATTR;
X		else if(sptr->vegetation==FOREST) Attr += EFOREATTR;
X
X		if(sptr->altitude==MOUNTAIN) Attr += EMNTNATTR;
X		else if(sptr->altitude==HILL) Attr += EHILLATTR;
X		else if(sptr->altitude==CLEAR) Attr += ECLERATTR;
X		else Attr=0;
X		break;
X	case HUMAN:
X		if((designation==DGOLDMINE)&&(sptr->jewels>=4))
X			Attr += HGOLDATTR;
X		else if((designation==DMINE)&&(sptr->metal>=4))
X			Attr += HMINEATTR;
X		else if(designation==DTOWN) Attr += HCITYATTR;
X		else if(designation==DCITY) Attr += HCITYATTR;
X		else if(designation==DCAPITOL) Attr += HCITYATTR;
X
X		if(sptr->vegetation==WOOD) Attr += HWOODATTR;
X		else if(sptr->vegetation==FOREST) Attr += HFOREATTR;
X
X		if(sptr->altitude==MOUNTAIN) Attr += HMNTNATTR;
X		else if(sptr->altitude==HILL) Attr += HHILLATTR;
X		else if(sptr->altitude==CLEAR) Attr += HCLERATTR;
X		else Attr=0;
X		break;
X	case ORC:
X		if((designation==DGOLDMINE)&&(sptr->jewels>=4))
X			Attr += OGOLDATTR;
X		else if((designation==DMINE)&&(sptr->metal>=4))
X			Attr += OMINEATTR;
X		else if(designation==DTOWN) Attr += OCITYATTR;
X		else if(designation==DCITY) Attr += OCITYATTR;
X		else if(designation==DCAPITOL) Attr += OCITYATTR;
X
X		if(sptr->vegetation==WOOD) Attr += OWOODATTR;
X		else if(sptr->vegetation==FOREST) Attr += OFOREATTR;
X
X		if(sptr->altitude==MOUNTAIN) Attr += OMNTNATTR;
X		else if(sptr->altitude==HILL) Attr += OHILLATTR;
X		else if(sptr->altitude==CLEAR) Attr += OCLERATTR;
X		else Attr=0;
X		break;
X	default:
X		break;
X	}
X	if((designation==DDEVASTATED)||(Attr<0)||(movecost[x][y]<0)) Attr=0;
X	return(Attr);
X}
X
X/****************************************************************/
X/*	ARMYMOVE() 						*/
X/* armymove moves an army... and returns the # of sectors taken	*/
X/****************************************************************/
Xint
Xarmymove(armynum)
Xint armynum;
X{
X	long		sum, where;
X	register int	x, y;
X	int	i;
X	long	menok;			/* enough men in the army? */
X	int	leadflag=FALSE;		/* leader w/o group */
X	int	takesctr=FALSE; 	/* takesctr is # unowned sctrs*/
X
X	if(P_ASTAT>=NUMSTATUS) return(takesctr);
X	if(P_AMOVE==0) return(takesctr);
X	/* if leader w/o group */
X	if((P_ATYPE>=MINLEADER)&&(P_ATYPE<MINMONSTER)&&(P_ASTAT!=GENERAL)) {
X		leadflag=TRUE;
X		/* the king stays in capitol on RULE */
X		if(P_ATYPE == getleader(curntn->class)-1 ){
X			P_AXLOC=curntn->capx;
X			P_AYLOC=curntn->capy;
X			P_ASTAT=RULE;
X			return(takesctr);
X		}
X	}
X
X	sum=0;
X	if(leadflag) {		/* find unattached soldiers & move anywhere */
X		for(i=0;i<MAXARM;i++)
X		if(( curntn->arm[i].unittyp<MINLEADER )
X		&&( curntn->arm[i].stat!=MILITIA )
X		&&( curntn->arm[i].stat!=ONBOARD )
X		&&( curntn->arm[i].stat!=TRADED )
X		&&( curntn->arm[i].stat<NUMSTATUS ))
X			sum+=curntn->arm[i].sold;
X	} else	{
X		/* use menok as a temp vbl now == men in army */
X		menok=0;
X		if((P_ATYPE>=MINLEADER)
X		&&(P_ATYPE<MINMONSTER)
X		&&(P_ASTAT==GENERAL)) {
X			for(x=0;x<MAXARM;x++)
X				if((curntn->arm[x].stat==(NUMSTATUS+armynum))
X				&& (curntn->arm[x].unittyp<MINLEADER))
X					menok+=P_ASOLD;
X		} else	menok=P_ASOLD;
X		if((menok > TAKESECTOR ) 
X		||( P_ATYPE>=MINLEADER)) menok=TRUE;
X		else menok=FALSE;
X		/* range of 4 if menok is FALSE else 2 */
X		for(x=P_AXLOC-4+menok*2;x<=P_AXLOC+4-menok*2;x++)
X		for(y=P_AYLOC-4+menok*2;y<=P_AYLOC+4-menok*2;y++) if(ONMAP(x,y))
X			if( menok==TRUE || ISCITY(sct[x][y].designation) )
X				sum+=attr[x][y];
X	}
X
X	if(sum==0) {
X		P_AXLOC=curntn->capx;
X		P_AYLOC=curntn->capy;
X		P_ASTAT=DEFEND;
X	} else if(leadflag) {	/* find leader a group! */
X		where=rand()%sum;
X		for(x=0;x<MAXARM;x++)
X		if((curntn->arm[x].unittyp<MINLEADER )
X		&&( curntn->arm[x].stat!=MILITIA )
X		&&( curntn->arm[x].stat!=ONBOARD )
X		&&( curntn->arm[x].stat!=TRADED )
X		&&( curntn->arm[x].stat<NUMSTATUS )){
X			where-=curntn->arm[x].sold;
X			if(where > 0) continue;
X			P_AXLOC=curntn->arm[x].xloc;
X			P_AYLOC=curntn->arm[x].yloc;
X			break;
X		}
X		if(x!=MAXARM) for(x=0;x<MAXARM;x++) {
X			if((curntn->arm[x].unittyp<MINLEADER )
X			&&( curntn->arm[x].stat<NUMSTATUS )
X			&&( curntn->arm[x].sold>=0 )
X			&&( curntn->arm[x].stat!=MILITIA )
X			&&( curntn->arm[x].stat!=SIEGED )
X			&&( curntn->arm[x].stat!=ONBOARD )
X			&&( curntn->arm[x].stat!=TRADED )
X			&&( P_AXLOC==curntn->arm[x].xloc )
X			&&( P_AYLOC==curntn->arm[x].yloc )){
X				curntn->arm[x].stat=NUMSTATUS+armynum;
X				P_ASTAT=GENERAL;
X				break;
X			}
X		}
X	} else {
X		where=rand()%sum;
X		/* range of 4 if menok is FALSE else 2 */
X		for(x=P_AXLOC-4+menok*2;x<=P_AXLOC+4-menok*2;x++)
X		for(y=P_AYLOC-4+menok*2;y<=P_AYLOC+4-menok*2;y++) if(ONMAP(x,y)){
X			if( menok==TRUE || ISCITY(sct[x][y].designation) )
X				where -= attr[x][y];
X			if( (where < 0 )
X			&& movecost[x][y]>=1
X			&& movecost[x][y]<=P_AMOVE
X			&&(land_reachp(P_AXLOC,P_AYLOC,x,y,P_AMOVE,country))){
X				P_AXLOC=x;
X				P_AYLOC=y;
X				if(P_ATYPE == getleader(curntn->class)-1 ){
X					P_AXLOC=curntn->capx;
X					P_AYLOC=curntn->capy;
X				}
X
X				/* CHANGE SO ARMIES MOVE PSEUDO INDEPENDANTLY */
X				if((sct[x][y].designation != DCITY)
X				&&(sct[x][y].designation != DCAPITOL)
X				&&(sct[x][y].designation != DTOWN)
X				&&(sct[x][y].owner==country))
X					attr[x][y] /= 8;
X
X				if(sct[x][y].owner==0){
X					sct[x][y].owner=country;
X					curntn->popularity++;
X					attr[x][y]/=8;
X					takesctr++;
X				}
X		
X				if((P_ATYPE>=MINLEADER)&&(P_ASTAT==GENERAL))
X				for(x=0;x<MAXARM;x++) 
X				if((curntn->arm[x].sold>0 )
X				&&( curntn->arm[x].stat==armynum+NUMSTATUS)){
X					curntn->arm[x].xloc=P_AXLOC;
X					curntn->arm[x].yloc=P_AYLOC;
X				}
X				return(takesctr);
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=P_AXLOC-2;x<=P_AXLOC+2;x++) for(y=P_AYLOC-2;y<=P_AYLOC+2;y++) {
X			if(!ONMAP(x,y))
X				continue;
X
X			if(leadflag) where -= solds_in_sector(x,y,country);
X			else where -= attr[x][y];
X			if( (where < 0 )
X			&& movecost[x][y]>=1
X			&& movecost[x][y]<=P_AMOVE
X			&&(land_reachp(P_AXLOC,P_AYLOC,x,y,P_AMOVE,country))){
X				P_AXLOC=x;
X				P_AYLOC=y;
X				if(sct[x][y].owner==0){
X					curntn->popularity++;
X					sct[x][y].owner=country;
X					attr[x][y] = 1;
X					takesctr++;
X				}
X				if((P_ATYPE>=MINLEADER)&&(P_ASTAT==GENERAL))
X				for(i=0;i<MAXARM;i++) 
X				if((curntn->arm[i].sold>0 )
X				&&( curntn->arm[i].stat==armynum+NUMSTATUS)){
X					curntn->arm[i].xloc=P_AXLOC;
X					curntn->arm[i].yloc=P_AYLOC;
X				}
X				return(takesctr);
X			} /* if */
X		} /* for for */
X	} /* if */
X	return(takesctr);
X}
X
X/****************************************************************/
X/*	SCORE() 						*/
X/* score updates the scores of all nations			*/
X/****************************************************************/
Xvoid
Xscore()
X{
X	int x;
X	printf("\nupdating nations scores\n");
X	for(x=1;x<NTOTAL;x++) if(isntn(ntn[x].active))
X		ntn[x].score += score_one(x);
X}
X
X#ifdef CHEAT
X/****************************************************************/
X/*	CHEAT() 						*/
X/* this routine cheats in favor of npc nations 			*/
X/*								*/
X/* I pride this code... it needs not to cheat to play a good	*/
X/* game.  This routine is the only cheating that it will do,	*/
X/* and it is fairly minor.					*/
X/****************************************************************/
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<NTOTAL;x++) if(isnpc(ntn[x].active)) {
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<NTOTAL;x++)
X		if(ispc(ntn[x].active))  {
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<NTOTAL;x++) 
X		if(isnpc(ntn[x].active))  {
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<NTOTAL;x++) 
X	if(isnpc(ntn[x].active ) 
X	&&(ntn[x].score < avgscore)
X	&&(ntn[x].race != ORC )
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<NTOTAL;x++) if(isnpc(ntn[x].active))
X		for(y=1;y<NTOTAL;y++) if(isnpc(ntn[y].active))
X			if((ntn[x].dstatus[y]!=TREATY)
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/****************************************************************/
X/*	UPDEXECS() 						*/
X/* update all nations in a random order				*/
X/* move civilians of that nation 				*/
X/****************************************************************/
Xvoid
Xupdexecs()
X{
X	register struct s_sector	*sptr;
X	register int i, j;
X	register int x,y;
X	int	armynum;
X	int moved,done,loop=0,number=0;
X
X	int execed[NTOTAL];
X
X	check();
X	attr = (int **) m2alloc(MAPX,MAPY,sizeof(int));
X	check();
X	for(country=0;country<NTOTAL;country++) 
X		if( isntn(ntn[country].active) ) execed[country]=FALSE;
X		else {
X			execed[country]=TRUE;
X			loop++;
X		}
X
X	for(;loop<NTOTAL;loop++){
X		number=(rand()%(NTOTAL-loop))+1; /*get random active nation*/
X
X		done=FALSE;
X		/*Find the appropiate nation*/
X		for(country=0;done==FALSE && country<NTOTAL;country++) {
X			if (execed[country]==FALSE) number--;
X			if (number==0) {
X				execed[country]=TRUE;
X				done=TRUE;
X				country--;	/* compensate for inc */
X			}
X		}
X
X		curntn = &ntn[country];
X		if(curntn->active == INACTIVE) continue;
X
X		printf("updating nation number %d -> %s\n",country,curntn->name);
X	check();
X
X		dissarray=FALSE;
X#ifdef TRADE
X		if(isntn(curntn->active)) checktrade();
X#endif TRADE
X
X		/*if execute is 0 and PC nation then they did not move*/
X		if((execute(TRUE)==0)&&(ispc(curntn->active))){
X			printf("\tnation %s did not move\n",curntn->name);
X#ifdef CMOVE
X			printf("\tthe computer will move for %s\n",curntn->name);
X			fprintf(fnews,"1.\tthe computer will move for %s\n",curntn->name);
X			mailopen( country );
X			fprintf(fm,"the computer moved for you (%s) in %s of Year %d\n",curntn->name,PSEASON(TURN),YEAR(TURN));
X			mailclose();
X	check();
X			nationrun();
X	check();
X#endif CMOVE
X		}
X#ifdef NPC
X	check();
X		/* run npc nations */
X		if(isnpc(curntn->active)) {
X			nationrun();
X	check();
X#ifdef ORCTAKE
X			/*do npc nation magic*/
X			if(magic(country,MA_MONST)==TRUE) {
X				if((x=takeover(5,0))==1)
X				printf("SUCCESSFUL TAKEOVER OF %d by %s",x,curntn->name);
X			} else if(magic(country,AV_MONST)==TRUE) {
X				if((x=takeover(3,0))==1)
X				printf("SUCCESSFUL TAKEOVER OF %d by %s",x,curntn->name);
X			} else if(magic(country,MI_MONST)==TRUE){
X				if((x=takeover(1,0))==1)
X				printf("SUCCESSFUL TAKEOVER OF %d by %s",x,curntn->name);
X			}
X#endif ORCTAKE
X		}
X#endif NPC
X
X		/* is leader killed - put nation into dissarray */
X		x = getleader((int)curntn->class) - 1;
X		for(armynum=0;armynum<MAXARM;armynum++)
X			if(P_ATYPE == x) break;
X#ifdef DEBUG
Xprintf("checking for leader in nation %s: armynum=%d\n",curntn->name,armynum);
X#endif DEBUG
X
X		if(armynum == MAXARM) {
X			dissarray=TRUE;
X			if(rand()%100 < 30) {	/* new leader takes over */
X				x++;
X				for(armynum=0;armynum<MAXARM;armynum++)
X					if(P_ATYPE == x) break;
X				if( armynum<MAXARM) {
X					P_ATYPE=x-1;
X					P_ASOLD= *(unitminsth+(x-1)%UTYPE);
X					dissarray=FALSE;
X					fprintf(stderr,"new leader in nation %s\n",curntn->name);
X					fprintf(fnews,"1.\tnation %s has a new leader\n",curntn->name);
X					if(ispc(curntn->active)){
X						mailopen(country);
X						fprintf(fm,"MESSAGE FROM CONQUER: YOU HAVE A NEW LEADER\n");
X						fprintf(fm,"YOUR TROOPS MAY NOW MOVE NORMALLY\n");
X						mailclose();
X					}
X				}
X			}
X		} else dissarray=FALSE;
X
X		if( dissarray ==  TRUE) {
X			fprintf(stderr,"no leader in nation %s\n",curntn->name);
X			fprintf(fnews,"1.\tnation %s still has no national leader\n",curntn->name);
X			if(ispc(curntn->active)){
X				mailopen(country);
X				fprintf(fm,"MESSAGE FROM CONQUER: YOU DONT HAVE A COUNTRY LEADER\n");
X				fprintf(fm,"YOUR TROOPS MAY NOT MOVE\n");
X				fprintf(fm,"THERE IS A 30%% CHANCE/TURN OF GETTING A NEW ONE \n");
X				mailclose();
X			}
X		}
X
X		updmove(curntn->race,country);	/*update movement array*/
X
X		/* Recalculate ATTR MATRIX for civilians */
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,sptr->owner)!=0)){
X				attr[x][y]=attract(x,y,curntn->race);
X			} else attr[x][y]=0;
X		}
X
X		/*if near capitol add to attr*/
X		for(x=curntn->capx-2;x<=curntn->capx+2;x++)
X			for(y=curntn->capy-2;y<=curntn->capy+2;y++)
X				if((ONMAP(x,y))&&(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 ) continue;
X			if( sptr->people == 0 ) continue;
X
X			for(i=x-2;i<=x+2;i++) for(j=y-2;j<=y+2;j++) 
X			if(ONMAP(i,j)){
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 ) continue;
X
X				sct[i][j].people += moved;
X				sptr->people -= moved;
X			} /* for */
X		} /* for */
X	} /* for */
X
X	/*zero out all recalculated values; do not clear god */
X	for(country=1;country<NTOTAL;country++) if(isntn(ntn[country].active)){
X		ntn[country].tships=0;
X		ntn[country].tmil=0;
X		if(rand()%4==0) ntn[country].spellpts/=2;
X		if(magic(country,SUMMON)==TRUE) {
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		if(magic(country,MA_MONST)==TRUE) ntn[country].spellpts+=2;
X		else if(magic(country,AV_MONST)==TRUE) ntn[country].spellpts+=1;
X		else if((magic(country,MI_MONST)==TRUE)
X			&&( rand()%2==0)) ntn[country].spellpts+=1;
X	}
X	free(attr);
X}
X
X/****************************************************************/
X/*	UPDLIZARDS() 						*/
X/* update lizards	 					*/
X/****************************************************************/
Xvoid
Xupdlizards()
X{
X	register int i, j;
X	int armynum;
X
X	printf("updating lizard (nation %d)\n ",country);
X	curntn = &ntn[country];
X	for(armynum=0;armynum<MAXARM;armynum++)
X	if((P_ASOLD>0)) {
X		P_AMOVE =20;	/* just in case god wants to move them */
X		if(armynum%2==0) {
X			if(P_ASTAT!=SIEGED) P_ASTAT=GARRISON;
X		} else {
X			if(ntn[country].arm[armynum-1].sold<=0) {
X				P_ASOLD=0;
X				continue;
X			}
X			P_AXLOC = ntn[country].arm[armynum-1].xloc;
X			P_AYLOC = ntn[country].arm[armynum-1].yloc;
X			/* try to relieve sieges */
X			if(P_ASTAT!=SIEGED
X			&& ntn[country].arm[armynum-1].stat!=SIEGED) {
X			for(i=ntn[country].arm[armynum-1].xloc-1;i<=ntn[country].arm[armynum-1].xloc+1;i++) {
X				for(j=ntn[country].arm[armynum-1].yloc-1;j<=ntn[country].arm[armynum-1].yloc+1;j++) {
X					if(ONMAP(i,j)
X					&&(sct[i][j].altitude!=WATER) 
X					&&(sct[i][j].altitude!=PEAK) 
X					&&(sct[i][j].owner != country) 
X					&&(rand()%3==0)){
X						P_AXLOC = i;
X						P_AYLOC = j;
X					}
X				}
X			}
X			}
X			/* this cheats by giving garrison bonus with movement */
X			if((sct[P_AXLOC][P_AYLOC].designation==DFORT)
X			&&(sct[P_AXLOC][P_AYLOC].owner==country)) {
X				if(P_ASTAT!=SIEGED) P_ASTAT=GARRISON;
X			} else P_ASTAT=ATTACK;
X		}
X	}
X#ifdef DEBUG
X	for(armynum=0;armynum<MAXARM;armynum++) {
X		if((P_ASOLD>0)&&(sct[P_AXLOC][P_AYLOC].altitude==WATER))
X			printf("ERROR line %d... %s army %d in water (army %d: x: %d y: %d)\n",__LINE__,ntn[country].name,armynum,armynum-1, ntn[country].arm[armynum-1].xloc, ntn[country].arm[armynum-1].yloc);
X	}
X#endif DEBUG
X}
X
X/****************************************************************/
X/*	UPDCAPTURE() 						*/
X/* capture unoccupied sectors					*/
X/****************************************************************/
Xvoid
Xupdcapture()
X{
X	register struct s_sector	*sptr;
X	int armynum, occval;
X
X	fprintf(fnews,"3\tNEWS ON WHAT SECTORS HAVE BEEN CAPTURED\n");
X	printf("distributing captured sectors\n");
X
X	/*look for any areas where armies alone in sector*/
X	prep(0,FALSE);
X
X	for(country=1;country<NTOTAL;country++) 
X	if(ntn[country].active!=INACTIVE){
X		curntn = &ntn[country];
X		for(armynum=0;armynum<MAXARM;armynum++)
X/* cheat in favor of npcs as the create army routines assume 75 man armies */
X		if(P_ATYPE<MINLEADER) {
X			if((ispc(curntn->active)&&(P_ASOLD>TAKESECTOR))
X			||((isnotpc(curntn->active))&&(P_ASOLD>75))){
X				/* may not capture land while on a fleet */
X				if(P_ASTAT==ONBOARD) continue;
X				/* may not capture water */
X				if(sct[P_AXLOC][P_AYLOC].altitude==WATER) {
X					printf("Nation %s Army %d in Water\n",curntn->name,armynum);
X					continue;
X				}
X				if(occ[P_AXLOC][P_AYLOC] != country) continue;
X				sptr = &sct[P_AXLOC][P_AYLOC];
X				if(sptr->owner==0){
X					sptr->owner=country;
X					curntn->popularity++;
X				} else if((sptr->owner!=country)
X				&&(curntn->dstatus[sptr->owner]>=WAR)
X				&&(occ[P_AXLOC][P_AYLOC]==country)){
X
X					if((sptr->owner!=0)
X					&&(ntn[sptr->owner].race!=curntn->race))
X						if(magic(country,SLAVER)==TRUE){
X							flee(P_AXLOC,P_AYLOC,1,TRUE);
X						}else{
X							flee(P_AXLOC,P_AYLOC,1,FALSE);
X						}
X
X				if((isntn( curntn->active ))
X				&&(isntn( ntn[sptr->owner].active)))
X#ifdef HIDELOC
X					fprintf(fnews,"3.\tarea captured by %s from %s\n",curntn->name,ntn[sptr->owner].name);
X#else
X					fprintf(fnews,"3.\tarea %d,%d captured by %s from %s\n",P_AXLOC,P_AYLOC,curntn->name,ntn[sptr->owner].name);
X#endif HIDELOC
X					sptr->owner=country;
X					curntn->popularity++;
X				}
X			}
X		} else if(P_ASTAT==A_SCOUT && P_ATYPE!=A_SPY && P_ASOLD>0) {
X			occval=occ[P_AXLOC][P_AYLOC];
X			/* capture situations:
X			 *   - alone with a hostile army     [PFINDSCOUT% chance]
X			 *   - alone in someone else's territory with one of
X			 *      their armies (non-allied)    [(PFINDSCOUT/5)% chance]
X			 * NOTE: do not remove chance to capture in unmet territory.
X			 */
X			if (occval!=0 && occval!=country && occval<NTOTAL) {
X				if(((ntn[occval].dstatus[country]>=HOSTILE)
X				  &&(rand()%100<PFINDSCOUT))
X				||((sct[P_AXLOC][P_AYLOC].owner==occval)
X				  &&(ntn[occval].dstatus[country]!=TREATY)
X				  &&(ntn[occval].dstatus[country]!=ALLIED)
X				  &&(rand()%100<PFINDSCOUT/5))) {
X					/* capture the scout */
X					P_ASOLD=0;
X					if (ispc(curntn->active)) {
X						mailopen(country);
X						fprintf(fm,"Message from Conquer\n\n");
X						fprintf(fm,"\tYour Scouting Unit %d was captured\n");
X						fprintf(fm,"\t  by %s military in sector %d,%d\n",
X							ntn[occval].name,P_AXLOC,P_AYLOC);
X						mailclose();
X					}
X					if (ispc(ntn[occval].active)) {
X						mailopen(occval);
X						fprintf(fm,"Message from Conquer\n\n");
X						fprintf(fm,"\tA Scout from nation %s was captured\n",curntn->name);
X						fprintf(fm,"\t  in sector %d,%d.\n",P_AXLOC,P_AYLOC);
X						mailclose();
X					}
X				}
X			}
X		}
X	}
X
X	/* capture countries */
X	for(country=1;country<NTOTAL;country++)
X	if (isntn(ntn[country].active)) {
X
X		/* check for capitols being sacked */
X		if(sct[ntn[country].capx][ntn[country].capy].owner != country)
X			sackem(country);
X	}
X}
X
X/**************************************************************/
X/*	UPDSECTORS() 						*/
X/* update sectors one at a time				*/
X/**************************************************************/
Xvoid
Xupdsectors()
X{
X	register struct s_sector	*sptr;
X	register struct s_nation		*nptr;
X	long	charity;	/* talons to the poor */
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		int rephold;
X
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( sct[x][y].tradegood == TG_none )
X			if(rand()%2==0) getmetal( &sct[x][y] );
X			else getjewel( &sct[x][y] );
X		}
X
X		/* calculate reproduction per season */ 
X		rephold = nptr->repro/4;
X		if ((SEASON(TURN)!=WINTER) &&
X		(SEASON(TURN)<=(nptr->repro%4)))
X			rephold++;
X
X		/* only one capitol per nation */
X		if (sptr->designation==DCAPITOL) {
X			if (nptr->capx!=x || nptr->capy!=y) {
X				sptr->designation=DCITY;
X			}
X		}
X
X		/* if huge number dont reproduce */
X		if(sptr->people >= ABSMAXPEOPLE) {
X			sptr->people = ABSMAXPEOPLE;
X			if(sptr->people * sptr->metal > 2*(rand()%100)*TOMUCHMINED)
X				if(sptr->designation==DMINE) sptr->metal--;
X			if(sptr->people * sptr->jewels > 2*(rand()%100)*TOMUCHMINED)
X				if(sptr->designation==DGOLDMINE) sptr->jewels--;
X		} else if((sptr->people > TOMANYPEOPLE)
X		&&(sptr->designation!=DTOWN)
X		&&(sptr->designation!=DCAPITOL)
X		&&(sptr->designation!=DCITY)){
X			sptr->people += (rephold * sptr->people)/200;
X			if(sptr->people > ABSMAXPEOPLE)
X				sptr->people = ABSMAXPEOPLE;
X			if(sptr->people * sptr->metal > 2*(rand()%100)*TOMUCHMINED)
X				if(sptr->designation==DMINE) sptr->metal--;
X			if(sptr->people * sptr->jewels > 2*(rand()%100)*TOMUCHMINED)
X				if(sptr->designation==DGOLDMINE) sptr->jewels--;
X		} else if(sptr->people<100) {
X			sptr->people+=sptr->people/10;
X		} else {
X			sptr->people += (rephold * sptr->people)/100; 
X			if(sptr->people * sptr->metal > (rand()%100)*TOMUCHMINED)
X				if(sptr->designation==DMINE) sptr->metal--;
X			if(sptr->people * sptr->jewels > (rand()%100)*TOMUCHMINED)
X				if(sptr->designation==DGOLDMINE) sptr->jewels--;
X		}
X		/* if no metal/gold left, remove tradegood */
X		if(((sptr->designation==DGOLDMINE)&&(sptr->jewels==0))
X		||((sptr->designation==DMINE)&&(sptr->metal==0))){
X			sptr->tradegood = TG_none;
X			sptr->designation = DDEVASTATED;
X		}
X
X		/*check all adjacent sectors and decide if met */
X		for(i=x-MEETNTN;i<=x+MEETNTN;i++)
X		for(j=y-MEETNTN;j<=y+MEETNTN;j++)
X		if(ONMAP(i,j)&&(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,sptr->owner)<DESFOOD){
X			if((sptr->designation != DSTOCKADE)
X			&&(sptr->designation != DFORT)
X			&&(sptr->designation != DROAD))
X			sptr->designation=DNODESIG;
X		}
X	}
X
X	for(country=1;country<NTOTAL;country++) {
X		curntn = &ntn[country];
X		if(isntn(curntn->active)){
X
X			/* check for depletion of country through */
X			/* lack of a capitol                      */
X			if((sct[curntn->capx][curntn->capy].designation!=DCAPITOL)
X			  ||(sct[curntn->capx][curntn->capy].owner!=country)) {
X
X				printf("depleting nation %s\n",curntn->name);
X				deplete(country);
X				printf("TEMP: done depleting\n");
X			}
X
X			spreadsheet(country);
X			curntn->popularity = min(0,(int)(curntn->popularity-2*curntn->inflation));
X			curntn->tsctrs = spread.sectors;
X			curntn->tciv=spread.civilians;
X			curntn->tfood=spread.food;
X
X			/* take out for charity */
X			charity=((spread.gold-curntn->tgold)*curntn->charity)/100;
X
X			if(charity > 0) curntn->tgold = spread.gold - charity;
X			else curntn->tgold = spread.gold;
X			if(curntn->tciv > 0) charity /= curntn->tciv;
X			else charity = 0;
X
X			/* give them some benefit of the doubt */
X			curntn->popularity += 5*charity;
X			if(curntn->poverty < (charity+1)/2 )
X				curntn->poverty = 0;
X			else	curntn->poverty -= (charity+1)/2;
X
X			/* Calculate inflation base */
X			if(curntn->inflation > 0) 
X				curntn->inflation = rand()%(curntn->inflation/2+1);
X			else curntn->inflation = 0;
X			curntn->inflation += (curntn->tax_rate/4 + (rand()%(curntn->tax_rate*3/4+1)));
X
X			/* adjustment for military */
X			if (spread.civilians>0)
X				curntn->inflation += ((curntn->tmil*100/spread.civilians - 15)/5);
X			/* adjustment for debt and/or wealth */
X			if(curntn->tgold<75000L) {
X				curntn->inflation += (short)(-(curntn->tgold/25000L)+1);
X			} else if(curntn->tgold<100000L) {
X				curntn->inflation -= 1;
X			} else if(curntn->tgold>=200000L) {
X				curntn->inflation += (short)(curntn->tgold/100000L-1);
X			}
X			/* plus maybe an adjustment for jewel production as a ratio */
X			/* for whatever is produced by the country.                 */
X
X			/* use charity here for gold lost to inflation */
X			charity = (curntn->tgold * curntn->inflation )/100;
X			curntn->tgold -= charity;
X			curntn->metals=spread.metal;
X			curntn->jewels=spread.jewels;
X		}
X	}
X}
X
X/****************************************************************/
X/*	UPDMIL() 						*/
X/* reset military stuff 					*/
X/****************************************************************/
X#define MAXSIEGE (NTOTAL)
Xvoid
Xupdmil()
X{
X	struct	army	*A;
X	int	AX, AY, AT;	/* armies x,y locations, type : for speed */
X	int armynum,nvynum,flag,dfltunit;
X	int army2,asmen,dsmen,nation,sieges=0;
X	char siegex[MAXSIEGE],siegey[MAXSIEGE],siegok[MAXSIEGE];
X
X	fprintf(stderr,"updating armies and navies\n");
X	for(country=1;country<NTOTAL;country++) 
X	if(isntn(ntn[country].active)){
X		curntn = &ntn[country];
X
X		if(ispc(curntn->active)) {
X		prep( country, TRUE );	/* occ[][] now >0 if leader near */
X		dfltunit = defaultunit(country);
X		} else dfltunit = A_INFANTRY;
X
X		dissarray=TRUE;
X		for(armynum=0;armynum<MAXARM;armynum++)
X			if (P_ATYPE==(getleader(curntn->class)-1)) {
X				dissarray=FALSE;
X				break;
X			}
X
X		for(armynum=0;armynum<MAXARM;armynum++) if(P_ASOLD>0) {
X
X			A = &curntn->arm[armynum];
X			AX = A->xloc;
X			AY = A->yloc;
X			if(A->unittyp==A_INFANTRY)
X				A->unittyp = dfltunit;
X			AT=A->unittyp;
X
X			if( AT< MINLEADER ) {
X				curntn->tmil+=A->sold;
X				if( AT==A_MILITIA ) A->stat=MILITIA;
X			}
X
X			/* if group does not have a leader anymore */
X			if((A->stat >= NUMSTATUS)
X			&&((curntn->arm[A->stat-NUMSTATUS].unittyp<MINLEADER)
X			||(curntn->arm[A->stat-NUMSTATUS].sold==0))) {
X				A->stat=ATTACK;
X			}
X			flag=TRUE;
X
X			/*add movement to all armies */
X			/*unitmove is 10 times movement rate*/
X			if(dissarray) A->smove=0;
X			else switch(A->stat) {
X			case MARCH:
X				A->smove=(curntn->maxmove * *(unitmove+(AT%UTYPE)))/5;
X				break;
X			case MILITIA:
X			case ONBOARD:
X				A->smove=0;
X				break;
X			case SIEGE:
X				if((sct[AX][AY].owner!=country)
X				&&(fort_val(&sct[AX][AY]) > 0)) {
X					A->smove=0;
X					flag=FALSE;
X					for (army2=0;flag==FALSE && army2<sieges;army2++)
X						if ((AX==siegex[army2])
X						&&(AY==siegey[army2])) flag=TRUE;
X					/* if this is a new SIEGE... check it */
X					if (flag==FALSE && sieges<MAXSIEGE) {
X						siegex[sieges]=AX;
X						siegey[sieges]=AY;
X						siegok[sieges]=FALSE;
X						asmen=0;
X						dsmen=0;
X						for(nation=0;nation<NTOTAL;nation++){
X							for(army2=0;army2<MAXARM;army2++)
X							if((ntn[nation].arm[army2].xloc==AX)
X							&&(ntn[nation].arm[army2].yloc==AY)
X							&&(ntn[nation].arm[army2].stat==SIEGE)){
X								if (ntn[nation].arm[army2].unittyp==A_SIEGE)
X								asmen+=3*ntn[nation].arm[army2].sold;
X								else asmen+=ntn[nation].arm[army2].sold;
X							}
X						}
X						nation=sct[siegex[sieges]][siegey[sieges]].owner;
X						for(army2=0;army2<MAXARM;army2++)
X						if((ntn[nation].arm[army2].xloc==AX)
X						&&(ntn[nation].arm[army2].yloc==AY)){
X							if (ntn[nation].arm[army2].unittyp==A_MILITIA)
X							dsmen+=ntn[nation].arm[army2].sold/2;
X							else dsmen+=ntn[nation].arm[army2].sold;
X						}
X						if(asmen > 2*dsmen) {
X							siegok[sieges]=TRUE;
X							sieges++;
X							/* keep SIEGE status */
X							break;
X						}
X					} else {
X						/* keep SIEGE status */
X						if (siegok[army2-1]==TRUE) break;
X					}
X				}
X				flag=FALSE;
X				/* should drop through to defend reset */
X			case GARRISON:
X				if((flag==TRUE)
X				&&(fort_val(&sct[AX][AY]) > 0)
X				&&(sct[AX][AY].owner==country)) {
X					A->smove=0;
X					P_AMOVE=0;
X					break;
X				}
X				flag=FALSE;
X				/* reset to defend for improper garrison */
X			case RULE:
X				if((flag==TRUE)
X				&&(ISCITY(sct[AX][AY].designation))
X				&&(AT>=MINLEADER)&&(AT<MINMONSTER)
X				&&(sct[AX][AY].owner==country)) {
X					A->smove=0;
X					break;
X				}
X				/* reset to defend for improper Rule */
X			case SIEGED:
X			case SORTIE:
X				/* reset besieged or sortie troops to DEFEND */
X			case FLIGHT:
X			case MAGDEF:
X			case MAGATT:
X				/* reset magical stats to DEFEND */
X				A->stat=DEFEND;
X			default:
X				A->smove=(curntn->maxmove * *(unitmove+(AT%UTYPE)))/10;
X				break;
X			}
X
X			/* empower flight */
X			if((avian(AT)==TRUE)
X 			&&( A->stat!=ONBOARD )
X			&&( A->stat<NUMSTATUS ))
X				A->stat=FLIGHT;
X
X			if((magic(country,ROADS)==1)
X			&&(sct[AX][AY].owner!=country)){
X				if(A->smove>7) A->smove-=4;
X				else A->smove=4;
X			}
X
X			if((magic(country,SAPPER)==1)
X			&&((AT==A_CATAPULT)||(AT==A_SIEGE))){
X				curntn->tgold -= A->sold * (*(unitmaint+(AT))) / 2;
X			} else if (AT<MINLEADER) {
X				curntn->tgold -= A->sold * (*(unitmaint+(AT%UTYPE)));
X				if((ispc(ntn[country].active))
X				&&(occ[AX][AY] == 0)) 
X					A->smove /= 2;
X			} else if (AT>=MINMONSTER) {
X				curntn->tgold -= 5L * (*(unitmaint+(AT%UTYPE)));
X				if(curntn->jewels > (*(unitmaint+(AT%UTYPE))))
X				curntn->jewels -= (long) (*(unitmaint+(AT%UTYPE)));
X				else {
X					if(ispc(curntn->active)) {
X					mailopen(country);
X					fprintf(fm,"Message to %s from Conquer\n",curntn->name);
X					fprintf(fm,"\nYour %s (unit %d) leaves due to lack of jewels\n",
X						*(unittype+(AT%UTYPE)),armynum);
X					mailclose();
X					A->sold=0;
X					}
X				}
X			}
X		}
X		/* group moves at rate of slowest +2 */
X		for(armynum=0;armynum<MAXARM;armynum++) 
X		if(( P_ASTAT == GENERAL )&&(P_ASOLD>0)){
X			flag=FALSE;
X			for(nvynum=0;nvynum<MAXARM;nvynum++) {
X				if((curntn->arm[nvynum].sold>0)
X				&&(curntn->arm[nvynum].stat==armynum+NUMSTATUS)){
X				flag=TRUE;
X				if(P_AMOVE > curntn->arm[nvynum].smove)
X					P_AMOVE = curntn->arm[nvynum].smove;
X				}
X			}
X			if(flag==FALSE) P_ASTAT=DEFEND;
X			else P_AMOVE+=2;
X		}
X		/*add to movement of fleets*/
X		for(nvynum=0;nvynum<MAXNAVY;nvynum++) {
X			/*update sea sectors*/
X			if(P_NWSHP!=0 || P_NMSHP!=0 || P_NGSHP!=0) {
X#ifdef STORMS
X				if(sct[P_NXLOC][P_NYLOC].altitude==WATER) {
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((ntn[country].active != NPC_PIRATE )
X				&&(magic(country,SAILOR)==FALSE)
X				&&( rand()%100 < PSTORM) ) {
X#ifdef HIDELOC
X					fprintf(fnews,"3.\tstorm sinks %s fleet at sea\n",curntn->name);
X#else
X					fprintf(fnews,"3.\tstorm sinks %s fleet in %d,%d\n",curntn->name,P_NXLOC,P_NYLOC);
X#endif HIDELOC
X					P_NWSHP=0;
X					P_NMSHP=0;
X					P_NGSHP=0;
X					armynum=P_NARMY;
X					if(armynum>=0&&armynum<MAXARM) {
X						P_ASOLD=0;
X					}
X					P_NARMY=0;
X					P_NPEOP=0;
X					P_NCREW=0;
X				}
X				/* destroy ships without crew */
X				if(P_NCREW==0) {
X					P_NWSHP=0;
X					P_NMSHP=0;
X					P_NGSHP=0;
X					armynum=P_NARMY;
X					if(armynum>=0&&armynum<MAXARM) {
X						P_ASOLD=0;
X					}
X					P_NARMY=0;
X				}
X				}
X#endif
X				if(dissarray) P_NMOVE=0;
X				else P_NMOVE = (fltspeed(nvynum)*P_NCREW)/SHIPCREW;
X				if(magic(country,SAILOR)==TRUE) P_NMOVE*=2;
X
X				curntn->tships += fltships(country,nvynum);
X				curntn->tgold -= flthold(nvynum)*SHIPMAINT;
X			} else {
X				P_NWSHP=0;
X				P_NMSHP=0;
X				P_NGSHP=0;
X			}
X		} /* for */
X	}
X	fprintf(stderr,"doing sieges\n");
X
X	/* kill movement on SIEGED troops */
X	for(army2=0;army2<sieges;army2++) {
X		if (siegok[army2]==FALSE) continue;
X		country= sct[siegex[army2]][siegey[army2]].owner;
X		curntn = &ntn[country];
X#ifdef HIDELOC
X		fprintf(fnews,"2.\tSector in nation %s is under siege\n",
X			curntn->name);
X#else
X		fprintf(fnews,"2.\tNation %s under siege in sector %d,%d\n",
X			curntn->name,siegex[army2],siegey[army2]);
X#endif HIDELOC
X		if(ispc(curntn->active)) {
X			mailopen( country );
X			fprintf(fm, "Message to %s from Conquer\n\n",ntn[nation].name);
X			fprintf(fm, "\tYou are under siege in sector %d,%d.\n",
X				siegex[army2],siegey[army2]);
X			mailclose();
X		}
X		for(armynum=0;armynum<MAXARM;armynum++) if(P_ASOLD>0){
X			if(P_ASTAT!=FLIGHT&&(P_AXLOC==siegex[army2])
X			&&(P_AYLOC==siegey[army2])) {
X				P_AMOVE=0;
X				if((P_ASTAT!=ONBOARD)&&(P_ASTAT!=RULE)&&(P_ASTAT!=TRADED))
X				P_ASTAT=SIEGED;
X			}
X		}
X	}
X	printf("done with military\n");
X}
X
X/****************************************************************/
X/*	UPDCOMODITIES()						*/
X/* update commodities						*/
X/****************************************************************/
Xvoid
Xupdcomodities()
X{
X	register struct s_sector	*sptr;
X	register int x,y;
X	long xx;
X	long dead;
X
X	fprintf(fnews,"2\tWORLD ECONOMY & DECLARATIONS OF WAR\n");
X	printf("working on world economy\n");
X	for(country=1;country<NTOTAL;country++) 
X	if(isntn(ntn[country].active)){
X		curntn = &ntn[country];
X		/*soldiers eat  2 times as much */
X		curntn->tfood-=curntn->tmil*P_EATRATE*2;
X		curntn->tfood-=curntn->tciv*P_EATRATE;
X
X		/*starve people*/
X		if(curntn->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==DTOWN)
X			||(sptr->designation==DCAPITOL)
X			||(sptr->designation==DCITY))
X			&&(curntn->tfood<0)){
X				/*lose one person in city per three food*/
X				/*maximum of 1/3 people in city lost*/
X				if(sptr->people < curntn->tfood){
X					sptr->people+=curntn->tfood/3;
X					curntn->tfood=0;
X				} else {
X					curntn->tfood+=sptr->people;
X					dead = sptr->people/3;
X					sptr->people -= dead;
X				}
X#ifdef HIDELOC
X				fprintf(fnews,"2.\tfamine hits town in %s.\n",curntn->name);
X#else
X				fprintf(fnews,"2.\tfamine hits town at %d,%d in %s.\n",x,y,curntn->name);
X#endif HIDELOC
X				printf("famine hits town at %d,%d in %s.\n",x,y,curntn->name);
X				if(ispc(curntn->active)){
X				mailopen( country );
X				fprintf(fm,"Message to %s from CONQUER\n%s\n",curntn->name,curntn->name);
X				fprintf(fm," During the %s of Year %d,\n",PSEASON(TURN),YEAR(TURN));
X				fprintf(fm," a famine hit your town at %d,%d.\n",x,y);
X				fprintf(fm," %d out of %d people died.\n",dead,sptr->people);
X				mailclose();
X				}
X			}
X		}
X		/*this state can occur if few people live in cities*/
X		if(curntn->tfood<0) curntn->tfood=0L;
X		curntn->tfood *= (100-curntn->spoilrate);
X		curntn->tfood /= 100;
X
X		if(curntn->tgold>GOLDTHRESH*curntn->jewels){
X			/* buy jewels off commodities board */
X			xx=curntn->tgold-GOLDTHRESH*curntn->jewels;
X			curntn->jewels += (xx*GODJEWL/GODPRICE);
X			curntn->tgold  -= xx;
X		}
X
X		/* fix overflow problems */
X		if(curntn->tgold < -1*BIG)  {
X			fprintf(fnews,"2.\tVariable Overflow - gold in nation %s\n",curntn->name);
X			curntn->tgold=BIG;
X		}
X		if(curntn->tfood < -1*BIG)  {
X			fprintf(fnews,"2.\tVariable Overflow - food in nation %s\n",curntn->name);
X			curntn->tfood=BIG;
X		}
X		if(curntn->jewels < -1*BIG) {
X			fprintf(fnews,"2.\tVariable Overflow - jewels in nation %s\n",curntn->name);
X			curntn->jewels=BIG;
X		}
X		if(curntn->metals < -1*BIG)  {
X			fprintf(fnews,"2.\tVariable Overflow - metal in nation %s\n",curntn->name);
X			curntn->metals=BIG;
X		}
X	}
X}
X
X/****************************************************************/
X/* Conquer: Copyright (c) 1988 by Edward M Barlow
X/*	UPDLEADER()						*/
X/****************************************************************/
Xvoid
Xupdleader()
X{
X	int	nation,armynum,born,type;
X	printf("working on national leaders\n");
X	for(nation=0;nation<NTOTAL;nation++) {
X		curntn = &ntn[nation];
X		if(!isntn(curntn->active)) continue;
X
X		/* monster nations get monsters */
X		if((SEASON(TURN) == SPRING)&&(magic(nation,MI_MONST)==TRUE)) {
X			born=100;	/* born represents strength of monst */
X			if(magic(nation,AV_MONST)==TRUE) born=200;
X			if(magic(nation,MA_MONST)==TRUE) born=BIG;
X
X			do type = MINMONSTER + rand()%(MAXMONSTER-MINMONSTER+1);
X			while( *(unitminsth+(type%UTYPE)) > born);
X
X			for(armynum=0;armynum < MAXARM;armynum++) {
X				if(P_ASOLD != 0) continue;
X				P_ATYPE = type;
X				P_ASOLD = *(unitminsth+(type%UTYPE));
X				P_AXLOC = curntn->capx;
X				P_AYLOC = curntn->capy;
X				P_ASTAT = DEFEND;
X				P_AMOVE = 2*curntn->maxmove;
X				if( ispc( ntn[nation].active ) ){
X					mailopen( nation );
X					fprintf(fm,"Message to %s from Conquer:\n",ntn[nation].name);
X					fprintf(fm,"\t\tMonster born in your nation!\n");
X					mailclose();
X				}
X				printf("\tmonster born in nation %s\n",curntn->name); 
X				break;
X			}
X		}
X
X		switch(curntn->class){	/* get national born rate */
X		case C_NPC:
X		case C_KING:
X		case C_TRADER:
X		case C_EMPEROR:	born = 50; break;
X		case C_WIZARD:
X		case C_PRIEST:
X		case C_PIRATE:
X		case C_WARLORD:
X		case C_DEMON:	born = 25; break;
X		case C_DRAGON:
X		case C_SHADOW:	born = 2; break;
X		default:
X			printf("ERROR - national class (%d) undefined\n",curntn->class);
X			abrt();
X		}
X		/* born represents yearly birth rate */
X		if( rand()%400 >= born ) continue;
X
X		for(armynum=0;armynum < MAXARM;armynum++) { /* add one leader */
X			if(P_ASOLD != 0) continue;
X			P_ATYPE = getleader(curntn->class);
X			P_ASOLD = *(unitminsth+(P_ATYPE%UTYPE));
X			P_AXLOC = curntn->capx;
X			P_AYLOC = curntn->capy;
X			P_ASTAT = DEFEND;
X			P_AMOVE = 2*curntn->maxmove;
X			if( ispc( ntn[nation].active ) ){
X				mailopen( nation );
X				fprintf(fm,"Message to %s from Conquer:\n",ntn[nation].name);
X				fprintf(fm,"\t\tLeader born in your nation!\n");
X				mailclose();
X			}
X			printf("\tleader born in nation %s\n",curntn->name); 
X			break;
X		}
X	}
X}
END_OF_FILE
if test 42715 -ne `wc -c <'update.c'`; then
    echo shar: \"'update.c'\" unpacked with wrong size!
fi
# end of 'update.c'
fi
echo shar: End of archive 1 \(of 14\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 14 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0