Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!amdcad!ames!ll-xn!mit-eddie!uw-beaver!tektronix!tekgen!tekred!games-request From: games-request@tekred.TEK.COM Newsgroups: comp.sources.games Subject: v03i071: conquer - version 2 of the renamed conquest adventure game, Part02/06 Message-ID: <2105@tekred.TEK.COM> Date: 22 Jan 88 21:33:26 GMT Sender: billr@tekred.TEK.COM Lines: 1823 Approved: billr@tekred.TEK.COM Submitted by: ihnp4!mhuxd!smile (Ed Barlow) Comp.sources.games: Volume 3, Issue 71 Archive-name: conquer/Part02 #! /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 cexecute.c <<'END_OF_cexecute.c' X/*conquer is copyrighted 1986 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/*EXECUTE THE PROGRAM*/ X#include "header.h" X#include "data.h" Xextern short country; X Xexecute() X{ X FILE *fp, *fopen(); X int cmd,savectry; X char comment[20]; X char temp[10]; X long longvar,long2var; X int armynum; X short int x,y; X int execed=0; X int done=0; X char line[80]; X X /*execute in random order*/ X /*open exefile file*/ X sprintf(line,"%s%d",exefile,country); X if ((fp=fopen(line,"r"))==NULL) { X /*THIS MEANS THAT THE NATION HAS NOT MOVED YET*/ X return(0); X } X savectry=country; X X /*read in file*/ X if(fgets(line,80,fp)==NULL) done=1; X while(done==0) { X /*read and parse a new line*/ X /*CODE IF YOU USE LONG VAR IS L_*/ X if( line[0] == 'L' && line[1] == '_' ) { X sscanf(line,"%s %d %hd %ld %ld %hd %s", X temp,&cmd,&country,&longvar,&long2var,&y,comment); X } else { X sscanf(line,"%s %d %hd %d %hd %hd %s", X temp,&cmd,&country,&armynum,&x,&y,comment); X } X execed=1; X switch(cmd){ X case XASTAT: /*Aadjstat*/ X if((x>0)&&(x<6)) ASTAT=x; X break; X case XAMEN: /*Aadjmen*/ X armynum= (int) longvar; X ASOLD= (int) long2var; X break; X case XALOC: /*Aadjloc*/ X AXLOC=x; X AYLOC=y; X break; X case XNLOC: /*nadjloc*/ X ntn[country].nvy[armynum].xloc=x; X ntn[country].nvy[armynum].yloc=y; X break; X case XNASHP: /*nadjshp*/ X ntn[country].nvy[armynum].merchant=x; X ntn[country].nvy[armynum].warships=y; X break; X case XECNAME: /*Nadjname*/ X strcpy(ntn[country].name,comment); X break; X case XECPAS: /*Nadjpas*/ X strncpy(ntn[country].passwd,comment,PASSLTH); X break; X case XECMARK: /*Echgmark*/ X ntn[country].mark=comment[0]; X break; X case XSADES: /*Sadjdes*/ X if((sct[x][y].owner==country)||(country==0)) { X sct[x][y].designation=comment[0]; X } X if(sct[x][y].designation==DCAPITOL){ X ntn[country].capx=x; X ntn[country].capy=y; X } X break; X case XSACIV: /*Sadjciv*/ X sct[x][y].people=armynum; X break; X case XSIFORT: /*Sincfort*/ X sct[x][y].fortress++; X break; X case XNAGOLD: /*Nadjgold:*/ X ntn[country].tgold = longvar; X break; X case XAMOV: X AMOVE=x; X break; X case XNMOV: X ntn[country].nvy[armynum].smove=x; X break; X case XSAOWN: X sct[x][y].owner=country; X break; X case EDADJ: X ntn[country].dstatus[armynum]=x; X break; X case XNARGOLD: X ntn[country].jewels = longvar; X break; X case XNAIRON: X ntn[country].tiron = longvar; X break; X case INCAPLUS: X ntn[country].aplus++; X break; X case INCDPLUS: X ntn[country].dplus++; X break; X case DESTRY: X sct[ntn[armynum].capx][ntn[armynum].capy].owner=savectry; X country=armynum; X destroy(); X country=savectry; X break; X case CHG_MGK: X ntn[country].powers|=long2var; X if(ntn[country].powers!=longvar){ X printf("\nERROR ON MAGIC READ %ld != %d (or of %d)",longvar,ntn[country].powers,long2var); X getchar(); X } X exenewmgk(long2var); X long2var=0; X } X if(fgets(line,80,fp)==NULL) done=1; X } X fclose(fp); X /*return 1 if it did something*/ X country=savectry; X if(execed==1) return(1); X else return(0); X} X END_OF_cexecute.c if test 3670 -ne `wc -c makeworld.c <<'END_OF_makeworld.c' X/*conquer is copyrighted 1986 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/*Create a world*/ X X/*DEFINE TEMPORARY VARIABLES FROM MAKEFILE*/ X#include X#include X#include "header.h" X#include "data.h" X X#define HALF 2 X#define LAND 3 X Xextern short country; Xint area_map[MAXX][MAXY];/*Value Map of Areas*/ Xint type[MAPX][MAPY]; X Xmakeworld() X{ X register int i,j; X register int x,y; X int n; /*count used in string searches*/ X float avvalue; /*Average water tvalue of sectors*/ X int number[5]; /*Number of sectors with type=[0-4]*/ X char passwd[12]; X int alloc = NUMAREAS * 2;/*Value Allocated*/ X int place[MAXX][MAXY] ;/*Temporary matrix to see if an area is placed*/ X int X, Y; X int X1,Y1; X int X2,Y2; X int valid; X int nranges; X int rnd; X int tempfd; X char newstring[40]; X X /*abort if datafile currently exists*/ X if(tempfd=open(datafile,0)!=-1) { X printf("ABORTING: File %s exists\n",datafile); X printf("\tthis means that a game is in progress. To proceed, you must remove \n"); X printf("\tthe existing data file. This will, of course, destroy that game.\n\n"); X exit(1); X } X printf("\n**********************WELCOME TO CONQUER**********************"); X printf("\nThe world will now be created...Your super user login will be 'god'."); X printf("\nNon player countries will be read from data stored in the nations file"); X printf("\n& will have the same password as god (about to be entered). Add player"); X printf("\nnations with the command . Have fun!!!\n"); X printf("\nRemember to check the world out before playing to make sure"); X printf("\nno nations are in bad positions (surrounded by water... )"); X printf("******************************************************************\n\n"); X X printf("First, we must zero extraneous files from prior games\n"); X sprintf(newstring,"rm %s*\n",exefile); X printf("\t%s",newstring); X system(newstring); X sprintf(newstring,"rm %s*\n",msgfile); X printf("\t%s",newstring); X system(newstring); X sprintf(newstring,"> %s",newsfile); X printf("\t%s\n",newstring); X system(newstring); X printf("OK This has been done, Now to set up a new world\n\n"); X X printf("please enter new super user password (remember this!):"); X scanf("%s",passwd); X getchar(); X printf("please reenter password:"); X scanf("%s",ntn[0].passwd); X getchar(); X if((strlen(ntn[0].passwd)<2) X ||(strncmp(passwd,ntn[0].passwd,PASSLTH)!=0)) { X printf("\ninvalid super user password\n"); X exit(1); X } X strncpy(ntn[0].passwd,crypt(passwd,SALT),PASSLTH); X X printf("\n\ncreating world\n"); X /*initialize variables */ X avvalue = (((float) PWATER/25.0)); /*Average water tvalue of sectors*/ X for(i=0;ialloc) { X /*have not allocated high enough so Allocate more */ X x = rand()%4; /*0 to 3*/ X if(number[x]>0) { X number[x] = number[x] - 1; X number[x+1] = number[x+1] + 1; X alloc = alloc + 1; X } X } X else { X /*have allocated too much Allocate less */ X x = (rand()%4) +1; /*1 to 4*/ X if(number[x]>0) { X number[x] = number[x] - 1; X number[x-1] = number[x-1] + 1; X alloc = alloc - 1; X } X } X } X X i=0; X while((number[4]>0)&&(i<500)) { X i++; X /*place a full land sector anywhere but on edge*/ X X = ((rand()%(MAXX-2))+1); /*1 to MAXX-2)*/ X Y = ((rand()%(MAXY-2))+1); /*1 to MAXY-2)*/ X if(place[X][Y] == 0) { X place[X][Y]=1; X area_map[X][Y]=4; X number[4]=number[4] - 1; X /*place surrounding sectors*/ X if(place[X+1][Y] == 0) { X rnd = rand()%100 + 1; /*1 to 100*/ X if((rnd<25) && (number[4]>0)) { X area_map[X+1][Y]=4; X number[4]=number[4]-1; X place[X+1][Y]=1; X } X if(rnd>25 && number[3]>0) { X area_map[X+1][Y]=3; X number[3]=number[3]-1; X place[X+1][Y]=1; X } X } X if(place[X-1][Y] == 0) { X rnd = rand()%100 + 1 ; /*(1 to 100)*/ X if(rnd<25 && number[4]>0) { X area_map[X-1][Y]=4; X number[4]=number[4]-1; X place[X-1][Y]=1; X } X if(rnd>25 && number[3]>0) { X area_map[X-1][Y]=3; X number[3]=number[3]-1; X place[X-1][Y]=1; X } X } X if(place[X][Y+1] == 0) { X rnd = rand()%100 + 1 ; /*(1 to 100)*/ X if(rnd<25 && number[4]>0) { X area_map[X][Y+1]=4; X number[4]=number[4]-1; X place[X][Y+1]=1; X } X if(rnd>25 && number[3]>0) { X area_map[X][Y+1]=3; X number[3]=number[3]-1; X place[X][Y+1]=1; X } X } X if(place[X][Y-1] == 0) { X rnd = rand()%100 + 1 ; /*(1 to 100)*/ X if(rnd<25 && number[4]>0) { X area_map[X][Y-1]=4; X number[4]=number[4]-1; X place[X][Y-1]=1; X } X if(rnd>25 && number[3]>0) { X area_map[X][Y-1]=3; X number[3]=number[3]-1; X place[X][Y-1]=1; X } X } X } X } X X /* place all other areas*/ X for(X=0;X0) { X area_map[X][Y]=rnd; X number[rnd]=number[rnd]-1; X place[X][Y]=1; X } X } X } X X /*ALL AREAS PLACED, NOW DETERMINE SECTOR TYPE X *fill in each area with sectors X * 1) water X * 2) water with major islands (25% land) X * 3) 50/50 water/land X * 4) land with major water (75% Land) X * 5) land X */ X for(Y=0;Y0) { X /*Place one range randomly*/ X X1 = rand()%(MAPX-6); X Y1 = rand()%(MAPY-6); X if((type[X1][Y1]==LAND) X &&(type[X1+1][Y1+1]==LAND) X &&(type[X1+1][Y1]==LAND) X &&(type[X1][Y1+1]==LAND) X &&(type[X1+2][Y1+2]==LAND)) { X /*place second endpoint */ X valid = 0; X i=0; X nranges--; X while((valid==0) && (i<500)) { X i++; X X2 = (rand()%7) + X1; X Y2 = (rand()%7) + Y1; X if(type[X2][Y2] == LAND) { X valid = 1; X /*fill in mountain range*/ X for(x=X1;x<=X2;x++) { X if(X180) sct[x][y].altitude=PEAK; X else sct[x][y].altitude=MOUNTAIN; X if((y < MAPY - 1) X && type[x][y+1] == LAND) { X rnd=rand()%100+1; X if(rnd>90) sct[x][y+1].altitude=PEAK; X else if(rnd>50) sct[x][y+1].altitude=MOUNTAIN; X else if(rnd>20) sct[x][y+1].altitude=HILL; X } X if((y!=0) X && type[x][y-1] == LAND ) { X rnd=rand()%100+1; X if(rnd>90) sct[x][y-1].altitude=PEAK; X else if(rnd>50) sct[x][y-1].altitude=MOUNTAIN; X else if(rnd>20) sct[x][y-1].altitude=HILL; X } X if((y>=2) X &&(type[x][y-2] == LAND )) { X rnd=rand()%100+1; X if(rnd>90) sct[x][y-2].altitude=MOUNTAIN; X else if(rnd>50) sct[x][y-2].altitude=HILL; X } X if((y < MAPY - 2) X &&(type[x][y+2] == LAND )) { X rnd=rand()%100+1; X if(rnd>90) sct[x][y+2].altitude=MOUNTAIN; X else if(rnd>50) sct[x][y+2].altitude=HILL; X } X } X } X } X } X } X X /*fill in random hills to work out,not to left of to water*/ X for(i=1;iMAPY/2+8)||(yMAPY/2+8)||(y= MAXX ) X2 = 0; X if( Y3 < 0 ) Y3 = MAXY - 1; X if( Y4 >= MAXY ) Y4 = 0; X X area=area_map[X0][Y0]; X /*fill in south*/ X edgearea=area_map[X4][Y4]; X if(area + edgearea > 6) for(i=0;i<8;i++) type[X0*8+i][Y0*8+7] = LAND; X else if((area + edgearea)>3) { X for(i=0;i<8;i++) X if(rand()%2 == 0) type[(X0*8)+i][Y0*8+7] = LAND; X else type[(X0*8)+i][Y0*8+7] = WATER; X } X else for(i=0;i<8;i++) type[(X0*8)+i][Y0*8+7] = WATER; X /*fill in east*/ X edgearea=area_map[X2][Y2]; X if(area + edgearea > 6) for(i=0;i<8;i++) type[X0*8+7][Y0*8+i] = LAND; X else if((area + edgearea)>3) { X for(i=0;i<8;i++) X if(rand()%2==0) type[X0*8+7][Y0*8+i] = LAND; X else type[X0*8+7][Y0*8+i] = WATER; X } X else for(i=0;i<8;i++) type[X0*8+7][Y0*8+i] = WATER; X /*fill in west*/ X edgearea=area_map[X1][Y1]; X if(area + edgearea > 6) for(i=0;i<=7;i++) type[X0*8][Y0*8+i] = LAND; X else if((area + edgearea)>3) { X for(i=0;i<8 ;i++) X if(rand()%2==0) type[X0*8][Y0*8+i] = LAND; X else type[X0*8][Y0*8+i] = WATER; X } X else for(i=0;i<8 ;i++) type[X0*8][Y0*8+i] = WATER; X /*fill in north*/ X edgearea=area_map[X3][Y3]; X if(area + edgearea > 6) for(i=0;i<8 ;i++) type[X0*8+i][Y0*8] = LAND; X else if((area + edgearea)>3) { X for(i=0;i<8 ;i++) X if(rand()%2==0) type[(X0*8)+i][Y0*8] = LAND; X else type[(X0*8)+i][Y0*8] = WATER; X } X else for(i=0;i<8 ;i++) type[(X0*8)+i][Y0*8] = WATER; X} X X/* ALLOCATE POPULATIONS OF THE WORLD*/ Xpopulate() X{ X int i=0,x=0,y=0,j=0; X int nvynum=0,army2num=0,armynum=0; X int temp; X int cnum=0; X FILE *fp, *fopen(); X int done=0; X char line[80]; X X X /*randomly scatter lizard city (want in DESERTS/swamp/Ice) */ X /*don't reproduce. Their cities are fortified and stockpiled */ X#ifdef LZARD X strncpy(ntn[NLIZARD].name,"lizard",10); X strncpy(ntn[NLIZARD].leader,"dragon",10); X strcpy(ntn[NLIZARD].passwd,ntn[0].passwd); X ntn[NLIZARD].race=LIZARD; X ntn[NLIZARD].mark='*'; X ntn[NLIZARD].active=2; X ntn[NLIZARD].aplus=0; X ntn[NLIZARD].dplus=0; X ntn[NLIZARD].maxmove=0; X ntn[NLIZARD].repro=0; X ntn[NLIZARD].powers=KNOWALL; X for(i=0;i=0&&j>=0&&inpc.c <<'END_OF_npc.c' X/*conquer is copyrighted 1986 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 "header.h" X#include "data.h" X#include X Xextern FILE *fnews; X Xextern short country; Xextern int attr[MAPX][MAPY]; /*sector attactiveness*/ Xextern short movecost[MAPX][MAPY]; Xint peace; /*is 8 if at peace, 12 if at war*/ X X#ifdef NPC Xnationrun() X{ X int armynum,price; X int x,y,i,z; X X prep(); X X /* is there an error*/ X if((sct[ntn[country].capx][ntn[country].capy].owner==country) X &&(sct[ntn[country].capx][ntn[country].capy].designation!=DCAPITOL)){ X sct[ntn[country].capx][ntn[country].capy].designation=DCAPITOL; X } X X /*go to war*/ X for(x=1;x=WAR) { X ntn[country].dstatus[x]=WAR; X } X /*else adjust diplomacy*/ X else if((ntn[country].dstatus[x]!=UNMET) X &&(ntn[country].dstatus[x]!=JIHAD) X &&(ntn[country].dstatus[x]!=CONFEDERACY) X &&(ntn[country].active!=1)){ X if((ntn[x].tmil>4*ntn[country].tmil) X &&(ntn[x].score>4*ntn[country].score)){ X if(rand()%3==0) ntn[country].dstatus[x]=WAR; X else if(rand()%8==0) X ntn[country].dstatus[x]=JIHAD; X } X /*if 2* mil and 2* score then not like them*/ X else if((ntn[x].tmil>2*ntn[country].tmil) X &&(ntn[x].score>2*ntn[country].score)){ X if((ntn[country].dstatus[x]!=WAR) X &&(ntn[x].race!=ntn[country].race)){ X if(rand()%3==0) X ntn[country].dstatus[x]++; X } X } X /*adjust based on your status with them*/ X if((ntn[country].dstatus[x]==WAR) X &&(ntn[x].dstatus[country]ALLIED)){ X if(ntn[x].dstatus[country]>1+ntn[country].dstatus[x]){ X if(rand()%3==0) X ntn[country].dstatus[x]++; X } X else X if(ntn[x].dstatus[country]+1peace) X peace=ntn[country].dstatus[i]; X X if(peaceHOSTILE){ X if(100*(ntn[country].tmil*(ntn[country].aplus+100))/((ntn[country].tmil*(ntn[country].aplus+100))+(ntn[x].tmil*(ntn[x].dplus+100)))>rand()%100){ X /*attacker*/ X for(armynum=1;armynum0)&&(ASTAT!=GARRISON)) X ASTAT=ATTACK; X atkattr(); X } X /*defender*/ X else { X for(armynum=1;armynum0)&&(ASTAT!=GARRISON)){ X if(ASOLD<350) ASTAT=DEFEND; X else ASTAT=ATTACK; X } X defattr(); X } X } X X for(armynum=1;armynum 2 * price) { X if((z=getmagic())!=0){ X fprintf(fnews,"2.\tnation %s gets magic power number %d\n",ntn[country].name,z); X exenewmgk(z); X ntn[country].jewels-=price; X } X else if((z=getmagic())!=0){ X fprintf(fnews,"2.\tnation %s gets magic power number %d\n",ntn[country].name,z); X exenewmgk(z); X ntn[country].jewels-=price; X } X else if((z=getmagic())!=0){ X fprintf(fnews,"2.\tnation %s gets magic power number %d\n",ntn[country].name,z); X exenewmgk(z); X ntn[country].jewels-=price; X } X } X i=0; X if(magic(country,WARLORD)==1) i=30; X else if(magic(country,CAPTAIN)==1) i=20; X else if(magic(country,WARRIOR)==1) i=10; X x = max ( ntn[country].aplus-i, 10 ) / 10; X if(ntn[country].tiron > 3 * IRONORE * ntn[country].tmil*x*x){ X ntn[country].aplus+=1; X ntn[country].dplus+=1; X ntn[country].tiron-=2*IRONORE*ntn[country].tmil*x*x; X } X} X X/*calculate attractiveness when at peace*/ Xpceattr() X{ X int x,y,temp; X /*add around capital*/ 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((ONMAP)&&(sct[x][y].owner==0)) attr[x][y]+=180; X X /*add to attractiveness for unowned sectors*/ X for(x=0;xntn[country].capx) temp+=x-ntn[country].capx; X else temp+=ntn[country].capx-x; X if(y>ntn[country].capy) temp+=y-ntn[country].capy; X else temp+=ntn[country].capy-y; X if(temp<3) attr[x][y]+=300-(50*temp); X else if(temp<20) attr[x][y]+=100; X } X else if((sct[x][y].owner==NNOMAD) X ||(sct[x][y].owner==NBARBARIAN) X ||(sct[x][y].owner==NPIRATE)) attr[x][y]+=100; X X if(sct[ntn[country].capy][ntn[country].capy].owner!=country){ X attr[ntn[country].capy][ntn[country].capy]=1000; X } X} X X/*calculate attractiveness of attacking sectors*/ Xatkattr() X{ X int nation,armie,x,y,x1,x2,Y1,y2; X 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((ONMAP)&&(sct[x][y].owner==0)) attr[x][y]+=80; X X for(x=0;x=WAR)&&(ntn[country].active!=0)){ X X /*plus 1/2 men if in sector with their army*/ X /*defend your capital if occupied, +50 more if with their army*/ X for(armie=1;armie 0) { X X attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/10; X X if((ntn[nation].arm[armie].xloc<=ntn[country].capx+2) X &&(ntn[nation].arm[armie].yloc<=ntn[country].capy+2) X &&(ntn[nation].arm[armie].xloc>=ntn[country].capx-2) X &&(ntn[nation].arm[armie].yloc>=ntn[country].capy-2)){ X attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/5; X if((rand()%3==0) X &&(ntn[country].dstatus[nation]2*ntn[country].arm[0].sold){ X attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/2; X } X else attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/5; X } X } X } X } X X /*plus 40 if next to their capital */ X for(x=ntn[nation].capx-1;x<=ntn[nation].capy+1;x++){ X for(y=ntn[nation].capy-1;y<=ntn[nation].capy+1;y++){ X if(ONMAP) X attr[x][y]+=40; X } X } X X /*plus 100 if on their capital*/ X attr[ntn[nation].capx][ntn[nation].capy]+=100; X X /*+60 if between the two capitals*/ X if (ntn[nation].capx < ntn[country].capx){ X x1=ntn[nation].capx; X x2=ntn[country].capx; X } X else { X x1=ntn[country].capx; X x2=ntn[nation].capx; X } X if (ntn[nation].capy < ntn[country].capy){ X Y1=ntn[nation].capy; X y2=ntn[country].capy; X } X else { X Y1=ntn[country].capy; X y2=ntn[nation].capy; X } X for(x=x1;x<=x2;x++) for(y=Y1;y<=y2;y++) { X if(ONMAP) attr[x][y]+=60; X } X X /*for each sector +60 if their sector*/ X for(x=0;x=WAR)) { X X /*plus if near enemy army*/ X /*plus 30 if next to their army*/ X /*plus 60 if with their army*/ X for(armie=1;armie 0) { X X attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/10; X X if((ntn[nation].arm[armie].xloc<=ntn[country].capx+2) X &&(ntn[nation].arm[armie].yloc<=ntn[country].capy+2) X &&(ntn[nation].arm[armie].xloc>=ntn[country].capx-2) X &&(ntn[nation].arm[armie].yloc>=ntn[country].capy-2)){ X attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/5; X if((rand()%3==0) X &&(ntn[country].dstatus[nation]2*ntn[country].arm[0].sold){ X attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/2; X } X else attr[ntn[nation].arm[armie].xloc][ntn[nation].arm[armie].yloc]+=ntn[nation].arm[armie].sold/5; X } X } X } X X X /*plus if strategic blocking sector*/ X /*+60 if between the two capitals*/ X if (ntn[nation].capx < ntn[country].capx){ X x1=ntn[nation].capx; X x2=ntn[country].capx; X } X else { X x1=ntn[country].capx; X x2=ntn[nation].capx; X } X if (ntn[nation].capy < ntn[country].capy){ X y1=ntn[nation].capy; X y2=ntn[country].capy; X } X else { X y1=ntn[country].capy; X y2=ntn[nation].capy; X } X X for(x=x1;x<=x2;x++) for(y=y1;y<=y2;y++) { X if(ONMAP) attr[x][y]+=60; X } X X /*plus 80 if near your capital */ X for(x=ntn[country].capx-1;x<=ntn[country].capy+1;x++){ X for(y=ntn[country].capy-1;y<=ntn[country].capy+1;y++){ X if(ONMAP) attr[x][y]+=80; X } X } X X /*plus based on defensive value*/ X for(x=0;x0) { X if(ntn[sct[AXLOC][AYLOC].owner].race==ntn[country].race) X sct[AXLOC][AYLOC].people+=ASOLD; X ASOLD=0; X } X for(nvynum=0;nvynum0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].tgold+=ntn[country].tgold; X if(ntn[country].jewels>0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].jewels+=ntn[country].jewels; X if(ntn[country].tiron>0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].tiron+=ntn[country].tiron; X if(ntn[country].tfood>0) ntn[sct[ntn[country].capx][ntn[country].capy].owner].tfood+=ntn[country].tfood; X } X X /*if god destroys then kill all population*/ X if(country==sct[ntn[country].capx][ntn[country].capy].owner){ X for(x=0;x0){ X x=AXLOC+rand()%4-2; X y=AYLOC+rand()%4-2; X if(ONMAP&&(is_habitable(x,y)) X &&(land_reachp(AXLOC,AYLOC,x,y,ntn[country].arm[armynum].smove,country))){ X AXLOC=x; X AYLOC=y; X /*if owned & unoccupied you take & people flee*/ X if( (sct[x][y].owner) == 0 || solds_in_sector( x, y, sct[x][y].owner) == 0 ) { X if(sct[x][y].owner==0) X fprintf(fnews,"3.\tnomads take sector %d,%d\n",x,y); X else fprintf(fnews,"3.\tnomads capture sector %d,%d\n",x,y); X if(sct[x][y].owner!=0) flee(x,y,1); X sct[x][y].owner=NNOMAD; X sct[x][y].designation=DDEVASTATED; X } X } X } X else { X /*place a new Nomad army*/ X x=(rand()%(MAPX-8))+4; X y=(rand()%(MAPY-8))+4; X if((rand()%4==0)&&(is_habitable(x,y))) { X AXLOC=x; X AYLOC=y; X ASOLD=100+100*rand()%10; X ASTAT=ATTACK; X } X } X fprintf(fnews,"2.\t%s are updated\n",ntn[NPIRATE].name); X /*if pirate fleet within 3 attack if outnumber any fleets */ X for(nvynum=0;nvynum(-2)) X &&(ntn[x].nvy[y].yloc-NYLOC<2) X &&(ntn[x].nvy[y].yloc-NYLOC>(-2)) X &&(sct[ntn[x].nvy[y].xloc][ntn[x].nvy[y].yloc].altitude==WATER)){ X NXLOC= ntn[x].nvy[y].xloc; X NYLOC= ntn[x].nvy[y].yloc; X } X /*add one warship to random pirate fleet*/ X if((NWAR>0)&&(rand()%3==0)) NWAR++; X } X} X Xnpcredes(x,y) X{ X long food; X /*large enough for a city now?*/ X if(((sct[x][y].people*(CITYLIMIT+(ntn[sct[x][y].owner].tsctrs/3))>ntn[sct[x][y].owner].tciv) X ||((ntn[sct[x][y].owner].tciv<30000) X &&(sct[x][y].people>1000))) X &&(ntn[sct[x][y].owner].tfood>ntn[sct[x][y].owner].tciv*2)){ X if((rand()%2==0) X &&((sct[x][y].designation==DFARM) X ||(sct[x][y].designation==DGOLDMINE) X ||(sct[x][y].designation==DMINE)) X &&(sct[x][y].iron<5) X &&(sct[x][y].gold<5)) X sct[x][y].designation=DCITY; X } X /*not large enough for city and not enough food*/ X else if((sct[x][y].designation==DCITY) X &&(ntn[sct[x][y].owner].tfood5)){ X sct[x][y].designation=DFARM; X food= (long) todigit(sct[x][y].vegetation)*sct[x][y].people; X ntn[sct[x][y].owner].tfood += food; X ntn[sct[x][y].owner].tgold += food*TAXFOOD/100-(sct[x][y].people * TAXCITY/100); X } X /*not large enough for a city but enough food*/ X else if((sct[x][y].designation==DCITY)&&(rand()%5==0)){ X sct[x][y].designation=DFARM; X food= (long) todigit(sct[x][y].vegetation)*sct[x][y].people; X ntn[sct[x][y].owner].tfood += food; X ntn[sct[x][y].owner].tgold += food*TAXFOOD/100-(sct[x][y].people * TAXCITY/100); X } X X /*what if it is not a city*/ X if((sct[x][y].designation!=DCITY)&&(sct[x][y].designation!=DCAPITOL)){ X sct[x][y].designation=DFARM; X /*crisis situation -- need more food producers*/ X if(ntn[sct[x][y].owner].tfood<=2*ntn[sct[x][y].owner].tciv){ X if(sct[x][y].iron>5) X sct[x][y].designation=DMINE; X if((sct[x][y].gold>5) X &&(sct[x][y].gold>sct[x][y].iron-2)) X sct[x][y].designation=DGOLDMINE; X } X /*non crisis situation -- need more food producers*/ X else { X if(sct[x][y].iron>2) X sct[x][y].designation=DMINE; X if((sct[x][y].gold>2) X &&(sct[x][y].gold>sct[x][y].iron-2)) X sct[x][y].designation=DGOLDMINE; X } X } X} X Xredomil() X{ X short x,y,armynum; X int i, free, done, ideal; X long diff; X X /*make sure enough men in army 0 -- garrison duty in capital*/ X armynum=0; X ASTAT=GARRISON; X AXLOC=ntn[country].capx; X AYLOC=ntn[country].capy; X X /*Ideally ASOLD[0]*MILINCAP=tmil*peace/10*/ X ideal = ntn[country].tmil * peace / (10*MILINCAP); X/*if(peace==8) printf("\tpeace - incap is %d, ideal is %d,",ASOLD,ideal); X *else if(peace==12) printf("\twar - incap is %d, ideal is %d,",ASOLD,ideal); X *else printf("error - incap is %d ideal is %d",ASOLD,ideal); X */ X /*MILRATIO ratio mil:civ for non player countries*/ X /*MILINCAP ratio (mil in cap):mil for NPCs*/ X X if((ASOLD*10) < (9*ideal)){ X X /*too few soldiers on garrison*/ X /*diff is number to change mil in cap (>0)*/ X if(ntn[country].tgold<0L) diff=0; X else diff = (long) min ( ideal-ASOLD , (int) (ntn[country].tiron/10)); X X diff = (long) min ((int) diff, sct[ntn[country].capx][ntn[country].capy].people/2); X if(ntn[country].tgold<=0 || ntn[country].tiron<=0) if(diff > 0) diff=0; X X /*printf(" add-diff is %d",diff);*/ X sct[ntn[country].capx][ntn[country].capy].people-=diff; X ASOLD+=diff; X ntn[country].tciv-=diff; X ntn[country].tmil+=diff; X ntn[country].tgold-=diff*ENLISTCOST; X ntn[country].tiron-=diff*10; X } X /*else split garrison army if 1.25* needed number*/ X else if(ASOLD *4 > 5*ideal){ X /*diff here is a negative number*/ X diff=((4*ASOLD)-(5*ideal))/4; X /*printf(" split diff is %d",diff);*/ X free=0; X ASOLD-=diff; X ntn[country].tmil-=diff; X ntn[country].tciv+=diff; X sct[ntn[country].capx][ntn[country].capy].people+=diff; X /*I add back gold as armies get redone anyway*/ X ntn[country].tiron+=diff*10; X ntn[country].tgold+=diff*ENLISTCOST; X } X /*else printf(" no action - diff=%d",diff);*/ X /*printf(" new Arm 0 is %d",ASOLD);*/ X X /*build ships and/or armies*/ X done=0; X ideal = ntn[country].tciv * peace / (10 * MILRATIO); X /*printf("\n\ttmil is %d ideal is %d",ntn[country].tmil,ideal);*/ X /*if tmil*MILRATIO0){ X /*printf(" build army %d to %d men",armynum,ASOLD);*/ X ntn[country].tiron-=ASOLD*10; X AXLOC= ntn[country].capx; X AYLOC= ntn[country].capy; X ntn[country].tmil += ASOLD; X ntn[country].tciv -= ASOLD; X ntn[country].tgold-=ASOLD*ENLISTCOST; X sct[AXLOC][AYLOC].people-=ASOLD; X ASTAT= DEFEND; X AMOVE=0; X } X } X } X /*disband ships and/or armies*/ X else if(ntn[country].tmil > 1.2*ideal){ X /*disband a pseudo-random army*/ X done=0; X diff=ntn[country].tmil-(1.2*ideal); X for(armynum=1;armynum5) X ||(sct[AXLOC][AYLOC].iron>5)) X &&(rand()%5==0)&&(ASOLD200)&&(ASOLD>ntn[country].tmil/20)) { X free=0; X for(i=1;i0) X &&(ntn[country].arm[i].xloc==AXLOC) X &&(ntn[country].arm[i].yloc==AYLOC) X &&(i!=armynum)&&(free==0)){ X free=1; X ntn[country].arm[i].sold += ASOLD; X ASOLD=0; X } X } X } X } X X for(x=0;x0){ X armynum=free; X AXLOC=x; X AYLOC=y; X } X } X } X} END_OF_npc.c if test 24352 -ne `wc -c