games@tekred.TEK.COM (06/17/88)
Submitted by: ihnp4!homxc!smile Comp.sources.games: Volume 4, Issue 43 Archive-name: conquer3/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 <file", e.g.. If this archive is complete, you # will see the following message at the end: # "End of archive 2 (of 8)." # Contents: combat.c npc.c # Wrapped by billr@saab on Thu Jun 16 09:39:56 1988 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f combat.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"combat.c\" else echo shar: Extracting \"combat.c\" \(24900 characters\) sed "s/^X//" >combat.c <<'END_OF_combat.c' 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 "header.h" X#include "data.h" X X#define MGKNUM 32 /* number of units possible in battle */ X#define ATKR 2 X#define DFND 1 X Xextern FILE *fnews; Xextern short country; X Xshort retreatside; /* ATKR, DFND, or none (0) */ Xshort retreatx; /* retreat x square */ Xshort retreaty; /* retreat y square */ X Xint unit[MGKNUM]; /*armynum*/ Xint owner[MGKNUM]; /*owner*/ Xint side[MGKNUM]; /*see definitions->1=units 2=unit*/ Xint troops[MGKNUM]; /*starting troops in army */ Xint anation; /*nation attacking in this fight*/ Xint dnation; /*one nation defending in this fight*/ X X/*RESOLVE COMBAT RESULTS */ X/*attacker wants a high roll and defender wants low roll on both dice*/ X/* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9*/ X Xint Cbt6_1[]={ X20,20,20,20,20,15,10,10,10,10,5,5,5,5,5,0,0,0,0,0,0 X}; Xint Cbt5_1[]={ X40,30,20,20,20,20,20,20,10,10,10,10,5,5,5,0,0,0,0,0,0 X}; Xint Cbt4_1[]={ X50,40,30,30,30,20,20,20,20,10,10,10,10,5,5,5,0,0,0,0,0 X}; Xint Cbt3_1[]={ X60,50,40,30,30,30,20,20,20,20,10,10,10,10,5,5,5,0,0,0,0 X}; Xint Cbt2_1[]={ X70,50,40,40,40,40,30,30,20,20,20,20,10,10,10,10,10,5,5,5,0 X}; Xint Cbt3_2[]={ X80,60,40,40,40,40,30,30,30,30,20,20,20,20,20,20,20,10,10,10,0 X}; Xint Cbt5_4[]={ X90,60,50,50,50,50,40,40,30,30,30,30,30,30,30,30,30,20,10,10,10 X}; Xint Cbt1_1[]={ X100,90,60,60,60,60,50,50,40,40,40,40,30,30,30,30,20,20,20,10,10 X}; Xint Cbt4_5[]={ X100,90,80,70,70,70,60,60,50,50,50,50,40,40,40,40,40,30,20,20,10 X}; Xint Cbt2_3[]={ X110,90,80,80,70,70,60,60,50,50,50,50,40,40,40,40,40,40,30,20,10 X}; Xint Cbt1_2[]={ X110,100,100,90,80,80,80,80,70,60,60,60,50,50,50,50,50,40,30,30,10 X}; Xint Cbt1_3[]={ X120,110,110,100,90,90,90,90,80,80,70,70,70,70,60,50,50,40,30,30,20 X}; Xint Cbt1_4[]={ X120,110,100,100,90,90,90,90,80,80,70,70,70,70,60,50,50,40,30,30,20 X}; Xint Cbt1_5[]={ X130,110,110,100,100,90,90,90,80,80,70,70,70,70,60,50,50,40,40,30,20 X}; Xint Cbt1_6[]={ X130,120,110,110,110,100,100,90,90,90,80,80,80,70,70,50,50,40,40,40,40 X}; X X X/*run all combat on map X * procedure is to find each sector with armies in attack mode and X * then search around them X */ Xvoid Xcombat() X{ X register int i,j; X /*if fought is 1 then do not fight a second battle in sector*/ X short fought[MAPX][MAPY]; X int temp; X short armynum,nvynum; X int valid; X int count=0; X X printf("RUN COMBAT SUBROUTINES"); X fprintf(fnews,"4\tBATTLE SUMMARY STATISTICS\n"); X /*for each nation, if in attack mode run a check*/ X X for(i=0;i<MAPX;i++) for(j=0;j<MAPY;j++) fought[i][j]=0; X X for(anation=0;anation<NTOTAL;anation++) if(ntn[anation].active>0) { X X /*army combat*/ X for(j=0;j<MAXARM;j++) if((ntn[anation].arm[j].stat==ATTACK) X &&(ntn[anation].arm[j].sold>0) X &&(fought[ntn[anation].arm[j].xloc][ntn[anation].arm[j].yloc]==0)){ X X fought[ntn[anation].arm[j].xloc][ntn[anation].arm[j].yloc]=1; X /*initialize matrix*/ X for(temp=0;temp<MGKNUM;temp++){ X unit[temp]=(-1); X owner[temp]=(-1); X side[temp]=(-1); X troops[temp]=0; X } X X /*check all armies in area and add to matrix*/ X count=0; X valid=FALSE; X /*is valid,set matrix*/ X for(country=0;country<NTOTAL;country++) X if(ntn[country].active!=0) X for(armynum=0;armynum<MAXARM;armynum++) X if((ASOLD>0) X &&(ASTAT!=SCOUT) X &&(AXLOC==ntn[anation].arm[j].xloc) X &&(AYLOC==ntn[anation].arm[j].yloc) X &&(count<MGKNUM)) { X X if((country!=anation) X &&(ntn[anation].dstatus[country]>HOSTILE)) { X valid=TRUE; X dnation=country; X } X unit[count]=armynum; X owner[count]=country; X count++; X } X X if(valid==TRUE) fight(); X } X X /*navy combat*/ X for(j=0;j<MAXNAVY;j++) X if((ntn[anation].nvy[j].warships>0) X&&(fought[ntn[anation].nvy[j].xloc][ntn[anation].nvy[j].yloc]==0) X&&(sct[ntn[anation].nvy[j].xloc][ntn[anation].nvy[j].yloc].altitude==WATER)){ X X fought[ntn[anation].nvy[j].xloc][ntn[anation].nvy[j].yloc]=1; X X /*initialize matrix*/ X for(temp=0;temp<MGKNUM;temp++){ X unit[temp]=(-1); X owner[temp]=(-1); X side[temp]=(-1); X troops[temp]=0; X } X X /*check all fleets in 1 sector range and add to matrix*/ X count=0; X valid=FALSE; X /*is valid,set matrix*/ X for(country=0;country<NTOTAL;country++) X if(ntn[country].active!=0) X for(nvynum=0;nvynum<MAXNAVY;nvynum++) X if((NWAR+NMER>0) X &&(abs(NXLOC-ntn[anation].nvy[j].xloc)<=1) X &&(abs(NYLOC-ntn[anation].nvy[j].yloc)<=1) X &&(count<MGKNUM)) { X fought[NXLOC][NYLOC]=1; X if((country!=anation) X &&(ntn[anation].dstatus[country]>HOSTILE)){ X valid=TRUE; X dnation=country; X } X unit[count]=nvynum; X owner[count]=country; X count++; X } X if(valid==TRUE) navalcbt(); X } X } X printf("\nall army and navy attacks completed"); X} X X/*taking the three matrices, run a combat*/ Xvoid Xfight() X{ X FILE *fpmsg, *fopen(); X char tempstr[15]; X int droll,aroll; X int odds; /*odds total times 100*/ X int done; X int i,j,k; X int asold=0,dsold=0; /*a's and d's total soldiers*/ X int Aloss=0,Dloss=0; /*a's and d's total losses*/ X int PAloss,PDloss; /*percent a and d loss*/ X int loss,divisor; X int abonus=0,dbonus=0; /*bonus aggregate*/ X short vampire=0; /*# non vamps deaded */ X short nvamps=0; /*number of vampire armies*/ X X /* determine who is attacker & who is on defenders side?*/ X for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)){ X if(owner[j]==anation) side[j]=ATKR; X else if(owner[j]==dnation) side[j]=DFND; X else if(ntn[anation].dstatus[owner[j]]==JIHAD) side[j]=DFND; X else if(ntn[owner[j]].dstatus[anation]==JIHAD) side[j]=DFND; X else if(ntn[anation].dstatus[owner[j]]==WAR) side[j]=DFND; X else if(ntn[owner[j]].dstatus[anation]==WAR) side[j]=DFND; X else if((ntn[owner[j]].dstatus[anation]==CONFEDERACY)&&(ntn[owner[j]].dstatus[dnation]>HOSTILE)) side[j]=ATKR; X else if((ntn[owner[j]].dstatus[anation]==ALLIED)&&(ntn[owner[j]].dstatus[dnation]>HOSTILE)) side[j]=ATKR; X } X X /*calculate number of troops */ X asold=0; X dsold=0; X for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)) { X if(side[i]==ATKR){ X troops[i] = ntn[owner[i]].arm[unit[i]].sold; X asold += ntn[owner[i]].arm[unit[i]].sold; X } else if(side[i]==DFND){ X troops[i] = ntn[owner[i]].arm[unit[i]].sold; X dsold += ntn[owner[i]].arm[unit[i]].sold; X } X if(magic(owner[i],VAMPIRE)==1) nvamps++; X } X X if((dsold<=0)||(asold<=0)) { X printf("\nERROR CONDITION -- ABORTING THIS COMBAT!!!!!!\n"); X return; X } X odds = (asold*100)/dsold; X X /* CALCULATE WEIGHTED AVERAGE BONUS*/ X abonus=0; X dbonus=0; X for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)) { X if(side[i]==ATKR) X abonus += cbonus(i)*troops[i]; X else if(side[i]==DFND) X dbonus += cbonus(i)*troops[i]; X } X X /*archer bonus if not in fort vs kinghts/cavalry*/ X j=0; X k=0; X for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)) X X if(sct[ntn[owner[i]].arm[unit[i]].xloc][ntn[owner[i]].arm[unit[i]].yloc].fortress==0){ X if((ntn[owner[i]].arm[unit[i]].unittyp == A_CAVALRY) X ||(ntn[owner[i]].arm[unit[i]].unittyp == A_KNIGHT)) X if(side[i]==ATKR) j+=troops[i]; X else if(side[i]==DFND) k+=troops[i]; X } X X for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)) { X if(j>0) abonus += (15 * j * troops[i]) / asold; X if(k>0) dbonus += (15 * k * troops[i]) / dsold; X } X X abonus/=asold; X dbonus/=dsold; X X/*CALCULATED BONUSES TO WHOLE COMBAT*/ X for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)) { X if(sct[ntn[owner[i]].arm[unit[i]].xloc][ntn[owner[i]].arm[unit[i]].yloc].fortress != 0){ X /*Catapults add +1%/20 men defending castle (max +10%)*/ X if((ntn[owner[i]].arm[unit[i]].unittyp == A_CATAPULT) X &&(side[i]==DFND)) X abonus += max((troops[i]/20),10); X /*Seige_engines add +1%/20 men when attacking fortress*/ X else if((ntn[owner[i]].arm[unit[i]].unittyp == A_SEIGE) X &&(side[i]==ATKR)) X abonus += max((troops[i]/20),30); X } X else { X /*Catapults add +1%/40 men normal combat (max +10%)*/ X if(ntn[owner[i]].arm[unit[i]].unittyp == A_CATAPULT) X abonus+=max((troops[i]/40),10); X } X } X X /*RUN COMBAT */ X /*DICE RESULTS MAY BE FROM 0 TO 200*/ X /*attacker wants a high roll and defender wants low roll on both dice*/ X aroll = abs(rand()%100); X aroll += 50 + abonus - dbonus; X if(aroll<0) aroll=0; X if(aroll>199) aroll=199; X X droll = abs(rand()%100); X droll += 50 + abonus - dbonus; X if(droll<0) droll=0; X if(droll>199) droll=199; X X /*odds bonus*/ X if(odds>1500) { X PAloss = (Cbt6_1[aroll/10])/4; X PDloss = Cbt1_6[20-droll/10]+30; X } else if(odds>600) { X PAloss = Cbt6_1[aroll/10]; X PDloss = Cbt1_6[20-droll/10]; X } else if(odds>500){ X PAloss = Cbt5_1[aroll/10]; X PDloss = Cbt1_5[20-droll/10]; X } else if(odds>400){ X PAloss = Cbt4_1[aroll/10]; X PDloss = Cbt1_4[20-droll/10]; X } else if(odds>300) { X PAloss = Cbt3_1[aroll/10]; X PDloss = Cbt1_3[20-droll/10]; X } else if(odds>200) { X PAloss = Cbt2_1[aroll/10]; X PDloss = Cbt1_2[20-droll/10]; X } else if(odds>150) { X PAloss = Cbt3_2[aroll/10]; X PDloss = Cbt2_3[20-droll/10]; X } else if(odds>125) { X PAloss = Cbt5_4[aroll/10]; X PDloss = Cbt4_5[20-droll/10]; X } else if(odds>100){ X PAloss = Cbt1_1[aroll/10]; X PDloss = Cbt1_1[20-droll/10]; X } else if(odds>75) { X PAloss = Cbt4_5[aroll/10]; X PDloss = Cbt5_4[20-droll/10]; X } else if(odds>50) { X PAloss = Cbt1_2[aroll/10]; X PDloss = Cbt2_1[20-droll/10]; X } else if(odds>33) { X PAloss = Cbt1_3[aroll/10]; X PDloss = Cbt3_1[20-droll/10]; X } else if(odds>15) { X PAloss = Cbt1_6[aroll/10]; X PDloss = Cbt6_1[20-droll/10]; X } else { X PAloss = 120; X PDloss = 0; X } X X retreatside = 0; X X if((PDloss > 2* PAloss) X &&(PDloss>=50) X &&(odds>150) X &&(rand()%4==0)) retreatside=DFND; X X if((PAloss > 2* PDloss) X &&(PAloss>=50) X &&(odds<150) X &&(rand()%2==0)) retreatside=ATKR; X X if(retreatside!=0) { X fdxyretreat(); X /* no legal retreat route */ X if((retreatx== ntn[owner[0]].arm[unit[0]].xloc) X && (retreaty== ntn[owner[0]].arm[unit[0]].yloc)){ X if(retreatside==ATKR) PAloss+=10; X else PDloss+=10; X#ifdef DEBUG X printf("side %d (%d %d) cant retreat...+10% loss\n",retreatside,retreatx,retreaty); X#endif DEBUG X } X#ifdef DEBUG X else X printf("retreat side %d to %d %d\n",retreatside,retreatx,retreaty); X#endif DEBUG X } X X /*divisor is the smallest combat bonus*/ X divisor = 100; X for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)){ X if(side[i]==ATKR) X divisor= min (divisor,ntn[owner[i]].aplus); X else X divisor= min (divisor,ntn[owner[i]].dplus); X } X divisor+=100; X X /*NOTE LOSSES ARE ADJUSTED BY CBONUS*/ X for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)){ X if(side[i]==ATKR){ X if( ntn[owner[i]].arm[unit[i]].unittyp >= MINMONSTER) { X if((rand()%100) < PAloss){ /* kill it */ X Aloss += troops[i]; X ntn[owner[i]].arm[unit[i]].sold=0; X } X } else { X loss=(troops[i]*PAloss*divisor) /(100*(100+ntn[owner[i]].aplus)); X if(loss>troops[i] ) X loss=troops[i]; X /*army can't have less than 25 men in it*/ X if(troops[i]-loss<25) X loss=troops[i]; X Aloss+=loss; X ntn[owner[i]].arm[unit[i]].sold-=loss; X } X } else if(side[i]==DFND){ X if( ntn[owner[i]].arm[unit[i]].unittyp >= MINMONSTER) { X if((rand()%100) < PDloss){ /* kill it */ X Dloss +=troops[i]; X ntn[owner[i]].arm[unit[i]].sold=0; X } X } else { X loss=(troops[i]*PDloss*divisor)/(100*(100+ntn[owner[i]].dplus)); X if(loss>troops[i] ) X loss=troops[i]; X /*destroy army if < 25 men*/ X if(troops[i]-loss<25) X loss=troops[i]; X Dloss+=loss; X ntn[owner[i]].arm[unit[i]].sold-=loss; X } X } X if((nvamps>0)&&(magic(owner[i],VAMPIRE)==1)) X vampire+= loss / 3; X } X#ifdef HIDELOC X fprintf(fnews,"4.\tBattle occurs in %s", ntn[sct[ntn[owner[0]].arm[unit[0]].xloc][ntn[owner[0]].arm[unit[0]].yloc].owner].name); X#else X fprintf(fnews,"4.\tBattle in %d,%d",ntn[owner[0]].arm[unit[0]].xloc, ntn[owner[0]].arm[unit[0]].yloc); X#endif X for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)){ X done=FALSE; X for(i=0;i<j;i++) if(owner[j]==owner[i]) done=TRUE; X if(done==FALSE) { X if(side[i]==ATKR) X fprintf(fnews,", attacker %s",ntn[owner[j]].name); X else if(side[i]==DFND) X fprintf(fnews,", defender %s",ntn[owner[j]].name); X } X } X fprintf(fnews,"\n"); X if(nvamps>0){ X for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)){ X if(magic(owner[i],VAMPIRE)==1) X ntn[owner[i]].arm[unit[i]].sold+=vampire/nvamps; X } X } X X /*who is in the battle*/ X for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)){ X done=FALSE; X X /*first time your nation appears done=FALSE*/ X for(i=0;i<j;i++) if(owner[j]==owner[i]) done=TRUE; X X if((done==FALSE)&&(ntn[owner[j]].active==1)) { X sprintf(tempstr,"%s%d",msgfile,owner[j]); X if ((fpmsg=fopen(tempstr,"a+"))==NULL) { X printf("\n\tERROR OPENING %s",tempstr); X exit(FAIL); X } X X fprintf(fpmsg,"%s\tBATTLE SUMMARY for sector %d, %d\n",ntn[owner[j]].name,ntn[owner[0]].arm[unit[0]].xloc, ntn[owner[0]].arm[unit[0]].yloc); X X if(side[j]==ATKR) fprintf(fpmsg,"%s\tYou are on the Attacking Side\n",ntn[owner[j]].name); X else fprintf(fpmsg,"%s\tYou are on the Defending Side\n",ntn[owner[j]].name); X X /*detail all participants in battle*/ X for(k=0;k<MGKNUM;k++) if(owner[k]!=(-1)){ X if(side[k]==DFND) X fprintf(fpmsg,"%s\t%s is defending with army %d (type %s, men %d, bonus=%d)\n", X ntn[owner[j]].name, X ntn[owner[k]].name, X unit[k], X unittype[ntn[owner[k]].arm[unit[k]].unittyp%100], X troops[k], X cbonus(k)); X else if(side[k]==ATKR) X fprintf(fpmsg,"%s\t%s is attacking with army %d (type %s, men %d, bonus=%d)\n", X ntn[owner[j]].name, X ntn[owner[k]].name, X unit[k], X unittype[ntn[owner[k]].arm[unit[k]].unittyp%100], X troops[k], X cbonus(k)); X else X fprintf(fpmsg,"%s\t%s is neutral with army %d (type %s, men %d, bonus=%d)\n", X ntn[owner[j]].name, X ntn[owner[k]].name, X unit[k], X unittype[ntn[owner[k]].arm[unit[k]].unittyp%100], X ntn[owner[k]].arm[unit[k]].sold, X cbonus(k)); X } X X fprintf(fpmsg,"%s\tattacking soldiers=%d\tmodified roll=%d-> attackers percent loss %d%%\n",ntn[owner[j]].name,asold,aroll,PAloss); X fprintf(fpmsg,"%s\tdefending soldiers=%d\tmodified roll=%d-> defenders percent loss %d%%\n",ntn[owner[j]].name,dsold,droll,PDloss); X fprintf(fpmsg,"%s\tODDS are %d to 100\n",ntn[owner[j]].name,odds); X fprintf(fpmsg,"%s\tRESULT: Attackers lose %d men, Defenders lose %d men\n",ntn[owner[j]].name,Aloss, Dloss); X if(retreatside==ATKR){ X fprintf(fpmsg,"%s\t\tAdditionally, All attackers retreat to %d %d\n",ntn[owner[j]].name,retreatx,retreaty); X#ifdef DEBUG X printf("%s\t\tAdditionally, All attackers retreat to %d %d\n",ntn[owner[j]].name,retreatx,retreaty); X#endif DEBUG X } else if(retreatside==DFND){ X fprintf(fpmsg,"%s\t\tAdditionally, All defenders retreat to %d %d\n",ntn[owner[j]].name,retreatx,retreaty); X#ifdef DEBUG X printf("%s\t\tAdditionally, All defenders retreat to %d %d\n",ntn[owner[j]].name,retreatx,retreaty); X#endif DEBUG X } X fprintf(fpmsg,"%s\n","END"); X fclose(fpmsg); X } X } X retreat(); X} X X/*Subroutine to determine combat bonuses for unit i in matrix*/ X/* returns int - bonus */ Xint Xcbonus(num) X{ X short armynum; X int armbonus; X X armbonus=0; X armynum=unit[num]; X country=owner[num]; X X /*Racial combat bonus due to terrain (the faster you move the better)*/ X armbonus+=5*(9-movecost[AXLOC][AYLOC]); X X if((magic(country,MI_MONST)==1)&&(unit[num]==0)) armbonus+=20; X if((magic(country,AV_MONST)==1)&&(unit[num]==0)) armbonus+=20; X if((magic(country,MA_MONST)==1)&&(unit[num]==0)) armbonus+=20; X X if(((magic(country,DESTROYER)==1) X ||(magic(country,DERVISH)==1)) X &&((sct[AXLOC][AYLOC].vegetation==ICE) X ||(sct[AXLOC][AYLOC].vegetation==DESERT))) X armbonus+=30; X X if(side[num]==DFND){ X X if(sct[AXLOC][AYLOC].altitude==MOUNTAIN) armbonus+=20; X else if(sct[AXLOC][AYLOC].altitude==HILL) armbonus+=10; X X if(sct[AXLOC][AYLOC].vegetation==JUNGLE) armbonus+=20; X else if(sct[AXLOC][AYLOC].vegetation==FOREST) armbonus+=15; X else if(sct[AXLOC][AYLOC].vegetation==WOOD) armbonus+=10; X X armbonus += ntn[owner[num]].dplus; X X if(sct[AXLOC][AYLOC].designation==DCASTLE) X armbonus+=5*sct[AXLOC][AYLOC].fortress; X else if((ASTAT==GARRISON) X &&(sct[AXLOC][AYLOC].designation==DCITY)){ X if(magic(country,ARCHITECT)==1){ X armbonus+=10+16*sct[AXLOC][AYLOC].fortress; X } X else armbonus+=10+8*sct[AXLOC][AYLOC].fortress; X } X else if((ASTAT==GARRISON) X &&(sct[AXLOC][AYLOC].designation==DCAPITOL)){ X if(magic(country,ARCHITECT)==1){ X armbonus+=20+20*sct[AXLOC][AYLOC].fortress; X } X else armbonus+=20+10*sct[AXLOC][AYLOC].fortress; X } X X } X else if(side[num]==ATKR) armbonus += ntn[owner[num]].aplus; X X /*army status is important*/ X if(ASTAT==MARCH) armbonus-=40; X X /*if a fortress*/ X if(sct[AXLOC][AYLOC].fortress!=0){ X /*Cavalry and Knights get -20%*/ X if((ATYPE == A_CAVALRY) ||(ATYPE == A_KNIGHT)) armbonus -= 20; X /*Archers gain pluses*/ X else if((ATYPE == A_ARCHER)&&(side[num]==DFND)) armbonus += 15; X else if((ATYPE == A_ARCHER)&&(side[num]==ATKR)) armbonus += 5; X } X X /*Phalanx and Legionaires need certain numbers of troops*/ X if(((ATYPE!=A_PHALANX) || (ASOLD>500)) X &&((ATYPE!=A_LEGION) || (ASOLD>1000))){ X if(side[num]==ATKR) armbonus+= *(unitattack+(ATYPE%100)); X else armbonus+= *(unitdefend+(ATYPE%100)); X } X X return(armbonus); X} X Xfdxyretreat() /* finds retreat location */ X{ X int x,y,nation=(-1); X int xsctr= ntn[owner[0]].arm[unit[0]].xloc; X int ysctr= ntn[owner[0]].arm[unit[0]].yloc; X X if((sct[xsctr][ysctr].designation==DCITY) X ||(sct[xsctr][ysctr].designation==DCAPITOL)){ X retreatside=0; X return; X } X retreatx=xsctr; X retreaty=ysctr; X X if(retreatside == ATKR) nation=anation; X else nation=dnation; X X for(x= xsctr-1; x<=xsctr+1; x++) X for(y= ysctr-1; y<=ysctr+1; y++) if(ONMAP){ X if(tofood(sct[x][y].vegetation,0)==0) continue; X if(((sct[x][y].owner == nation) X ||(ntn[sct[x][y].owner].dstatus[nation] < NEUTRAL)) X ||(solds_in_sector( x, y, sct[x][y].owner) == 0)){ X retreatx=x; X retreaty=y; X#ifdef DEBUG X printf("%d %d RETREAT TO %d %d\n",xsctr,ysctr,x,y); X#endif DEBUG X return; X } X } X} X Xretreat() X{ X int cnum; X X if(retreatside == 0) return; X X for(cnum=0;cnum<MGKNUM;cnum++) if(owner[cnum]!=(-1)){ X if(owner[cnum] > MAXNTN ) continue; /*monsts dont retreat */ X if((side[cnum]==ATKR)&&(retreatside==ATKR)){ X ntn[owner[cnum]].arm[unit[cnum]].xloc = retreatx; X ntn[owner[cnum]].arm[unit[cnum]].yloc = retreaty; X } X else if((side[cnum]==DFND)&&(retreatside==DFND)){ X ntn[owner[cnum]].arm[unit[cnum]].xloc = retreatx; X ntn[owner[cnum]].arm[unit[cnum]].yloc = retreaty; X } X } X} X X/*SUBROUTINE TO RUN NAVAL COMBAT ON ALL SHIPS */ X/*just like fight, this takes array of owner,side,unit and calculate*/ Xvoid Xnavalcbt() X{ X FILE *fpmsg, *fopen(); X int sailor; X char tempmsg[15]; X int aship=0,dship=0; /*a's and d's total war ships*/ X int asunk=0,dsunk=0; /*a's and d's losses for the round*/ X int amsunk=0,dmsunk=0; /*a's and d's msunks for the round*/ X register int done,i,j,k; X X /* determine who is attacker & who is on defenders side?*/ X for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)){ X if(owner[j]==anation) side[j]=ATKR; X else if(ntn[anation].dstatus[owner[j]]==JIHAD) side[j]=DFND; X else if(ntn[owner[j]].dstatus[anation]==JIHAD) side[j]=DFND; X else if(ntn[anation].dstatus[owner[j]]==WAR) side[j]=DFND; X else if(ntn[owner[j]].dstatus[anation]==WAR) side[j]=DFND; X else if((ntn[owner[j]].dstatus[anation]==CONFEDERACY) X &&(ntn[owner[j]].dstatus[dnation]>HOSTILE)) side[j]=ATKR; X else if((ntn[owner[j]].dstatus[anation]==ALLIED) X &&(ntn[owner[j]].dstatus[dnation]>HOSTILE)) side[j]=ATKR; X } X X /*RUN COMBAT; loop until done*/ X /*determine relative strengths--does anybody try to flee*/ X /*calculate number of ships on a side*/ X for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)){ X if(side[j]==DFND) { X dship+=ntn[owner[j]].nvy[unit[j]].warships; X } X else if(side[j]==ATKR) { X aship+=ntn[owner[j]].nvy[unit[j]].warships; X } X } X X /*no bonus currently included in this combat*/ X X /*each warship can do damage 40%; once all warships sunk then all*/ X /*sunk are captured merchant*/ X sailor=FALSE; X for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)) if(side[j]==ATKR) X if(magic(owner[j],SAILOR)==TRUE) sailor=TRUE; X if(sailor==TRUE) for(i=0;i<aship;i++) if(rand()%10<=5) dsunk++; X else for(i=0;i<aship;i++) if(rand()%10<=3) dsunk++; X X sailor=FALSE; X for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)) if(side[j]==DFND) X if(magic(owner[j],SAILOR)==TRUE) sailor=TRUE; X if(sailor==TRUE) for(i=0;i<dship;i++) if(rand()%10<=4) asunk++; X else for(i=0;i<dship;i++) if(rand()%10<=3) asunk++; X X#ifdef HIDELOC X fprintf(fnews,"4.\tNaval Battle occurs"); X#else X fprintf(fnews,"4.\t%d,%d: Naval Battle",ntn[owner[0]].nvy[unit[0]].xloc, ntn[owner[0]].nvy[unit[0]].yloc); X#endif X for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)){ X k=0; X for(i=0;i<j;i++) if(owner[j]==owner[i]) k=1; X if(k==0) { X if(side[i]==DFND) X fprintf(fnews,", attacker %s",ntn[owner[j]].name); X else if(side[i]==ATKR) X fprintf(fnews,", defender %s",ntn[owner[j]].name); X } X } X fprintf(fnews,"\n"); X X X#ifdef HIDELOC X fprintf(fnews,"4.\t\tNaval attackers lose %d of %d warships\n", X min(asunk,aship),aship); X fprintf(fnews,"4.\t\tNaval defenders lose %d of %d warships\n", X min(dsunk,dship),dship); X fprintf(fnews,"4.\t\tNaval attackers lose %d merchants\n", X max(0,asunk-aship)); X fprintf(fnews,"4.\t\tNaval defenders lose %d merchants\n", X max(0,dsunk-dship)); X#else X fprintf(fnews,"4.\t%d,%d: Naval attackers lose %d of %d warships\n", X ntn[owner[0]].nvy[unit[0]].xloc, X ntn[owner[0]].nvy[unit[0]].yloc,min(asunk,aship),aship); X fprintf(fnews,"4.\t%d,%d: Naval defenders lose %d of %d warships\n", X ntn[owner[0]].nvy[unit[0]].xloc, X ntn[owner[0]].nvy[unit[0]].yloc,min(dsunk,dship),dship); X fprintf(fnews,"4.\t%d,%d: Naval attackers lose %d merchants\n", X ntn[owner[0]].nvy[unit[0]].xloc, X ntn[owner[0]].nvy[unit[0]].yloc,max(0,asunk-aship)); X fprintf(fnews,"4.\t%d,%d: Naval defenders lose %d merchants\n", X ntn[owner[0]].nvy[unit[0]].xloc, X ntn[owner[0]].nvy[unit[0]].yloc,max(0,dsunk-dship)); X#endif X X for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)){ X if((asunk>0)&&(side[i]==ATKR)){ X if(asunk > aship ) { X ntn[owner[i]].nvy[unit[i]].warships=0; X amsunk = asunk - aship; X } else { X ntn[owner[i]].nvy[unit[i]].warships -= asunk * ntn[owner[i]].nvy[unit[i]].warships/aship; X } X } X else if((dsunk>0)&&(side[i]==DFND)){ X if(dsunk > dship ) { X ntn[owner[i]].nvy[unit[i]].warships=0; X dmsunk = dsunk -dship; X } else { X ntn[owner[i]].nvy[unit[i]].warships -= dsunk * ntn[owner[i]].nvy[unit[i]].warships / dship; X } X } X } X /* take care of merchants*/ X for(i=0;i<MGKNUM;i++) if(owner[i]!=(-1)){ X if((amsunk>0)&&(side[i]==ATKR)){ X if(amsunk >= ntn[owner[i]].nvy[unit[i]].merchant ) { X amsunk -= ntn[owner[i]].nvy[unit[i]].merchant; X ntn[owner[i]].nvy[unit[i]].merchant=0; X } else { X ntn[owner[i]].nvy[unit[i]].merchant-=amsunk; X amsunk=0; X } X } X else if((dmsunk>0)&&(side[i]==DFND)){ X if(dmsunk >= ntn[owner[i]].nvy[unit[i]].merchant ) { X dmsunk -= ntn[owner[i]].nvy[unit[i]].merchant; X ntn[owner[i]].nvy[unit[i]].merchant=0; X } else { X ntn[owner[i]].nvy[unit[i]].merchant-=dmsunk; X dmsunk=0; X } X } X } X X /*will round continue; does one side wish to withdraw*/ X X /*mail results; who is in the battle*/ X for(j=0;j<MGKNUM;j++) if(owner[j]!=(-1)){ X done=FALSE; X X /*first time your nation appears done=FALSE*/ X for(i=0;i<j;i++) if(owner[j]==owner[i]) done=TRUE; X X if((done==FALSE)&&(ntn[owner[j]].active==1)) { X sprintf(tempmsg,"%s%d",msgfile,owner[j]); X if ((fpmsg=fopen(tempmsg,"a+"))==NULL) { X fprintf(fnews,"4.\tERROR OPENING %s\n",tempmsg); X exit(FAIL); X } X X fprintf(fpmsg,"%s NAVAL BATTLE in sector %d %d\n" X ,ntn[owner[j]].name,ntn[owner[0]].nvy[unit[0]].xloc X ,ntn[owner[0]].nvy[unit[0]].yloc); X X if(side[j]==ATKR) X fprintf(fpmsg,"%s You are on the Attacking Side\n" X ,ntn[owner[j]].name); X else fprintf(fpmsg,"%s You are on the Defending Side\n" X ,ntn[owner[j]].name); X X /*detail all participants in battle*/ X for(k=0;k<MGKNUM;k++) if(owner[k]!=(-1)){ X if(side[k]==DFND) X fprintf(fpmsg,"%s\t%s is defender with navy %d\n" ,ntn[owner[j]].name , ntn[owner[k]].name,unit[k]); X else fprintf(fpmsg,"%s\t%s is attacker with navy %d\n",ntn[owner[j]].name,ntn[owner[k]].name, unit[k]); X } X X fprintf(fpmsg,"%s RESULT: Attackers lose %d ships, Defenders lose %d ships\n",ntn[owner[j]].name, asunk,dsunk); X fprintf(fpmsg,"%s Attackers capture %d merchants, Defenders capture %d merchants\n",ntn[owner[j]].name, dmsunk,amsunk); X fprintf(fpmsg,"END\n"); X fclose(fpmsg); X } X } X} END_OF_combat.c if test 24900 -ne `wc -c <combat.c`; then echo shar: \"combat.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f npc.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"npc.c\" else echo shar: Extracting \"npc.c\" \(28401 characters\) sed "s/^X//" >npc.c <<'END_OF_npc.c' 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 "header.h" X#include "data.h" X#include <ctype.h> 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/*ntn 1 is nation you are updating*/ Xvoid Xnewdip(ntn1,ntn2) X{ X if(ntn[ntn1].active<2) { X if(ntn[ntn1].dstatus[ntn2]==UNMET) X ntn[ntn1].dstatus[ntn2]=NEUTRAL; X } X else if(ntn[ntn1].race==ntn[ntn2].race){ X if(rand()%5<3) ntn[ntn1].dstatus[ntn2]=FRIENDLY; X else if(rand()%2==0) ntn[ntn1].dstatus[ntn2]=ALLIED; X else ntn[ntn1].dstatus[ntn2]=NEUTRAL; X } X else switch(ntn[ntn1].race) { X case DWARF: X switch(ntn[ntn2].race) { X case ELF: X ntn[ntn1].dstatus[ntn2]=HOSTILE; X break; X case HUMAN: X ntn[ntn1].dstatus[ntn2]=NEUTRAL; X break; X case ORC: X default: X ntn[ntn1].dstatus[ntn2]=WAR; X break; X } X break; X case ELF: X switch(ntn[ntn2].race) { X case DWARF: X ntn[ntn1].dstatus[ntn2]=HOSTILE; X break; X case HUMAN: X ntn[ntn1].dstatus[ntn2]=NEUTRAL; X break; X case ORC: X default: X ntn[ntn1].dstatus[ntn2]=WAR; X break; X } X break; X case ORC: X switch(ntn[ntn2].race) { X case HUMAN: X ntn[ntn1].dstatus[ntn2]=NEUTRAL; X break; X case DWARF: X case ELF: X default: X ntn[ntn1].dstatus[ntn2]=WAR; X break; X } X break; X case HUMAN: X switch(ntn[ntn2].race) { X case DWARF: X case ELF: X ntn[ntn1].dstatus[ntn2]=NEUTRAL; X break; X case ORC: X ntn[ntn1].dstatus[ntn2]=HOSTILE; X break; X default: X ntn[ntn1].dstatus[ntn2]=WAR; X break; X } X break; X default: X ntn[ntn1].dstatus[ntn2]=WAR; X break; X } X} X Xvoid Xmonster() X{ X short nvynum,armynum; X int x, y; X X /*move nomads randomly until within 2 of city then attack*/ X country=NNOMAD; X for(armynum=0;armynum<MAXARM;armynum++) if(ASOLD>0){ X ASOLD *= 11; X ASOLD /= 10; 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,FALSE); 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 ATYPE=A_INFANTRY; X ASTAT=ATTACK; X } X } X country=NLIZARD; X for(armynum=0;armynum<MAXARM;armynum++) if(ASOLD>0){ X ASOLD*=105; X ASOLD/=100; X } X country=NPIRATE; 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<MAXNAVY;nvynum++){ X for(x=1;x<MAXNTN;x++) for(y=0;y<MAXNAVY;y++) X if((ntn[x].nvy[y].xloc-NXLOC<2) X &&(sct[ntn[x].nvy[y].xloc][ntn[x].nvy[y].yloc].altitude==WATER) X &&(ntn[x].nvy[y].xloc-NXLOC>(-2)) X &&(ntn[x].nvy[y].yloc-NYLOC<2) X &&(ntn[x].nvy[y].yloc-NYLOC>(-2))){ 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)) { X NWAR++; X NCREW+=SHIPCREW; X } X } X} X X#ifdef NPC X Xvoid Xn_redes(x,y,goldthresh,ironthresh,citythresh) Xint goldthresh,ironthresh,citythresh; X{ X register struct s_sector *sptr = &sct[x][y]; X X if(sptr->designation == DCAPITOL) return; X X /*large enough for a city now?*/ X if(((sptr->people > (spread.civilians/CITYLIMIT)) X ||((spread.civilians<30000)&&(sptr->people>1000))) X &&( spread.food > spread.civilians*3) X &&( sptr->iron < ironthresh) X &&( spread.incity+spread.incap < spread.civilians * CITYPERCENT / 100) X &&( spread.sectors > 10) X &&( sptr->gold < goldthresh)){ X sptr->designation=DCITY; X spread.incity+=sptr->people; X spread.infarm-=sptr->people; X } X X /*not large enough for city and not enough food*/ X if((sptr->designation==DCITY) X &&( spread.food < spread.civilians*2) X &&( tofood(sptr->vegetation,sptr->owner) > citythresh )){ X sptr->designation=DFARM; X spread.incity-=sptr->people; X spread.infarm+=sptr->people; X } X X if((sptr->designation==DCITY) X &&( spread.incity+spread.incap > spread.civilians * CITYPERCENT / 66)){ X sptr->designation=DFARM; X spread.incity-=sptr->people; X spread.infarm+=sptr->people; X } X X /*what if it is not a city*/ X if((sptr->designation!=DCITY)&&(sptr->designation!=DCAPITOL)){ X if(( sptr->gold >= goldthresh+2 ) X &&( sptr->iron < sptr->gold )){ X sptr->designation=DGOLDMINE; X } X else if( sptr->iron >= ironthresh ){ X sptr->designation=DMINE; X } X else if( sptr->gold >= goldthresh ){ X sptr->designation=DGOLDMINE; X } X else sptr->designation=DFARM; X } X} X Xvoid Xredomil() X{ X short x,y,armynum; X int i, free, done, ideal, militia=0; X long diff=0; X int ok; X X#ifdef DEBUG X check(__LINE__); X#endif DEBUG X /* check out any ship crews */ X for(armynum=1;armynum<MAXNAVY;armynum++) { X if((ntn[country].nvy[armynum].merchant>0) X || (ntn[country].nvy[armynum].warships>0)) X ntn[country].nvy[armynum].crew = X (ntn[country].nvy[armynum].merchant+ntn[country].nvy[armynum].warships)*SHIPCREW; X } X#ifdef DEBUG X check(__LINE__); X#endif DEBUG X /* code to check and move armies back if they are too far out */ X for(armynum=1;armynum<MAXARM;armynum++) if(ASOLD>0){ X ok = 0; X for(x=AXLOC-3;x<=AXLOC+3;x++) X for(y=AYLOC-3;y<=AYLOC+3;y++) X if((ONMAP)&&(sct[x][y].owner==country)) ok=1; X if(ok==0){ X AXLOC=ntn[country].capx; X AYLOC=ntn[country].capy; X } X } X for(armynum=1;armynum<MAXARM;armynum++) X if((ASOLD>0)&&(ATYPE==A_MILITIA)){ X militia+=ASOLD; X } X ntn[country].tmil -= militia; X X /*make sure enough men in army 0 -- garrison duty in capitol*/ X armynum=0; X ASTAT=GARRISON; X ATYPE=A_INFANTRY; 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(ntn[country].tgold < 0) ideal/=2; X#ifdef DEBUG X if(peace==8) X printf("\t%s IS AT PEACE - garrison in cap is %d, ideal is %d\n",ntn[country].name,ASOLD,ideal); X else if(peace==12) X printf("\t%s IS AT WAR - garrison in cap is %d, ideal is %d\n",ntn[country].name,ASOLD,ideal); X else printf("error - incap is %d ideal is %d\n",ASOLD,ideal); X#endif DEBUG X X /*MILRATIO ratio mil:civ for non player countries*/ X /*MILINCAP ratio (mil in cap):mil for NPCs*/ X#ifdef DEBUG X check(__LINE__); X#endif DEBUG 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 / *(u_eniron + (ATYPE%100)))); X X diff = (long) min ((int) diff, sct[ntn[country].capx][ntn[country].capy].people/2); X X if(ntn[country].tgold<0 || ntn[country].tiron<0) if(diff > 0) diff=0; X X#ifdef DEBUG X printf("\tadding %d men to garrison (too few men on garrison)\n",diff); X#endif DEBUG X X sct[ntn[country].capx][ntn[country].capy].people-=diff; X ASOLD+=diff; X ntn[country].tciv-=diff; X ntn[country].tmil+=diff; X if(magic(country,WARRIOR)==1) /* take WARRIOR power into account */ X ntn[country].tgold -= (diff * *(u_encost + (ATYPE%100))) / 2; X else ntn[country].tgold-=diff* *(u_encost + (ATYPE%100)); X ntn[country].tiron-=(diff* *(u_eniron + (ATYPE%100))); X#ifdef DEBUG X if(ASOLD < 0) printf("error 2... ASOLD=%d <0\n",ASOLD); X#endif DEBUG 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#ifdef DEBUG X printf("\tsplit garrison of %d men\n",diff); X#endif DEBUG X free=0; X ASOLD-=diff; X#ifdef DEBUG X if(ASOLD < 0) printf("error... subtracting %d from %d\n",diff,ASOLD); X#endif DEBUG 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* *(u_eniron + (ATYPE%100))); X if(magic(country,WARRIOR)==1) /* WARRIOR power */ X ntn[country].tgold+=(diff* *(u_encost + (ATYPE%100))) / 2; X else ntn[country].tgold+=diff* *(u_encost + (ATYPE%100)); X } X#ifdef DEBUG X else printf("\tno action - ASOLD (%d) ~= ideal (%d)\n",ASOLD,ideal); X printf("\tFinal Garrison Army %d (%s) type is %s men is %d\n",armynum,ntn[country].name,*(unittype+(ATYPE)),ASOLD); X#endif DEBUG X X /*build ships and/or armies*/ X done=FALSE; X ideal = ntn[country].tciv * peace / (10 * MILRATIO); X if(ntn[country].tgold<0) { ideal*=4; ideal/=5; } X#ifdef DEBUG X printf("\t%s total military is %d -> ideal is %d\n",ntn[country].name,ntn[country].tmil,ideal); X check(__LINE__); X#endif DEBUG X /*if < ideal build new army in the capitol - if possible*/ X if(ntn[country].tmil < ((4*ideal)/5)) { X for(armynum=1;armynum<MAXARM;armynum++) X if((done==FALSE)&&(ASOLD==0)) { X done=TRUE; X ATYPE=A_INFANTRY; X ASOLD = min ((int) (ideal-ntn[country].tmil), (int) (ntn[country].tiron/ (*(u_eniron + (ATYPE%100))))); X X ASOLD = min (ASOLD,sct[ntn[country].capx][ntn[country].capy].people/2); X ASOLD = min (ASOLD, (int) (ntn[country].tgold/ *(u_encost+(ATYPE%100)))); X if(ASOLD>0){ X#ifdef DEBUG Xprintf("\tnot enough soldiers - build new army %d with %d men\n",armynum,ASOLD); X#endif DEBUG X ntn[country].tiron-=(ASOLD* *(u_eniron + (ATYPE%100))); X AXLOC= ntn[country].capx; X AYLOC= ntn[country].capy; X ntn[country].tmil += ASOLD; X ntn[country].tciv -= ASOLD; X if(magic(country,WARRIOR)==1) /* WARRIOR power */ X ntn[country].tgold-=(ASOLD* *(u_encost + (ATYPE%100))) / 2; X else ntn[country].tgold-=ASOLD* *(u_encost + (ATYPE%100)); X sct[AXLOC][AYLOC].people-=ASOLD; X ASTAT= DEFEND; X AMOVE=0; X } X else ASOLD=0; X } X#ifdef DEBUG X check(__LINE__); X#endif DEBUG X } else if(ntn[country].tmil > (6*ideal/5)){ X#ifdef DEBUG X check(__LINE__); X#endif DEBUG X /*disband a pseudo-random army*/ X done=FALSE; X diff=ntn[country].tmil-(6*ideal/5); X#ifdef DEBUG X if(ASOLD < 0) printf("\ndisbanding pseudo random army of about %d men\n",diff); X#endif DEBUG X for(armynum=1;armynum<MAXARM;armynum++){ X if((done==FALSE) X &&(ASOLD>0) X &&(ATYPE!=A_MILITIA) X &&(sct[AXLOC][AYLOC].owner==country) X &&((sct[AXLOC][AYLOC].gold>4) X ||(sct[AXLOC][AYLOC].iron>4) X ||(sct[AXLOC][AYLOC].designation==DCITY)) X &&(ASOLD<=diff)){ X#ifdef DEBUG X printf("\ttoo many soldiers eliminate army %d (%d men)\n",armynum,ASOLD); X#endif DEBUG X diff-=ASOLD; X sct[AXLOC][AYLOC].people+=ASOLD; X ntn[country].tmil -= ASOLD; X ntn[country].tciv += ASOLD; X ASOLD=0; X if(diff<=50) done=TRUE; X } X#ifdef DEBUG X if(ASOLD < 0) printf("error X... ASOLD=%d <0\n",ASOLD); X#endif DEBUG X } X } X#ifdef DEBUG X check(__LINE__); X#endif DEBUG X#ifdef DEBUG X printf("\twhew... new tmil is %d\n",ntn[country].tmil); X#endif DEBUG X X /*resize armies */ X /*maximum npc army is 200 or tmil/20, minimum is 50*/ X for(armynum=1;armynum<MAXARM;armynum++){ X if((ASOLD>200)&&(ASOLD>ntn[country].tmil/20)) { X free=FALSE; X for(i=1;i<MAXARM;i++){ X if((free==0)&&(ntn[country].arm[i].sold==0)){ X free=1; X ASOLD/=2; X ATYPE=A_INFANTRY; X ntn[country].arm[i].sold = ASOLD; X ntn[country].arm[i].unittyp = A_INFANTRY; X ntn[country].arm[i].smove = AMOVE; X ntn[country].arm[i].stat = DEFEND; X ntn[country].arm[i].xloc = AXLOC; X ntn[country].arm[i].yloc = AYLOC; X } X } X } X /*minimum npc army is 50, merge them*/ X else if(ASOLD<50) { X free=0; X for(i=1;i<MAXARM;i++){ X if((ntn[country].arm[i].sold>0) X &&(ntn[country].arm[i].xloc==AXLOC) X &&(ntn[country].arm[i].yloc==AYLOC) X &&(ntn[country].arm[i].unittyp==ATYPE) X &&(i!=armynum)&&(free==0)){ X free=1; X ntn[country].arm[i].sold += ASOLD; X ntn[country].arm[i].unittyp=A_INFANTRY; X ASOLD=0; X } X } X } X } X#ifdef DEBUG X check(__LINE__); X#endif DEBUG X X /* assure that militia unit resides in each city */ X for(armynum=0;armynum<MAXARM;armynum++) X if((ASOLD>0)&&(ATYPE==A_MILITIA)){ X#ifdef DEBUG X printf("\t\t%s army %d (now %d men - populace %d)\n",unittype[ATYPE],armynum,ASOLD,sct[AXLOC][AYLOC].people); X#endif DEBUG X if((sct[AXLOC][AYLOC].designation!=DCITY) X &&(sct[AXLOC][AYLOC].designation!=DCAPITOL)){ X#ifdef DEBUG X printf("\teliminating %s army %d as %d %d is des:%c alt:%c own:%d\n",unittype[ATYPE],armynum,AXLOC,AYLOC,sct[AXLOC][AYLOC].designation,sct[AXLOC][AYLOC].altitude,sct[AXLOC][AYLOC].owner); X#endif DEBUG X if(sct[AXLOC][AYLOC].owner == country) X sct[AXLOC][AYLOC].people+=ASOLD; X else X sct[ntn[country].capx][ntn[country].capy].people+=ASOLD; X ASOLD=0; X } X } X X if(ntn[country].tgold > 0) X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) X if((sct[x][y].owner==country) X &&((sct[x][y].designation==DCITY)||(sct[x][y].designation==DCAPITOL))){ X free=FALSE; X for(armynum=0;armynum<MAXARM;armynum++){ X if((ASOLD>0) X &&(AXLOC==x)&&(AYLOC==y) X &&(ATYPE==A_MILITIA)) { X free=TRUE; X break; X } X } X if(free==FALSE) { /* draft a new militia army */ X for(armynum=0;armynum<MAXARM;armynum++) if(ASOLD==0){ X ATYPE=A_MILITIA; X AXLOC=x; X AYLOC=y; X free=TRUE; X break; X } X } X if((free==TRUE)) { X /* want to add ideal troops */ X ideal = sct[x][y].people/MILINCITY - ASOLD; X ideal = min(ideal, 250); X if(ideal>0){ X if(magic(country,WARRIOR)==TRUE){ /* WARRIOR power */ X ntn[country].tgold-= X (ideal* *(u_encost+ATYPE))/2; X } else { X ntn[country].tgold-= X ideal* *(u_encost + ATYPE); X } X } X ASOLD+=ideal; X ASTAT=GARRISON; X#ifdef DEBUG X if(ATYPE!=A_MILITIA) printf("ERROR - NOT MILITIA\n"); X printf("\tadding %d troops to %s army %d (now %d men - populace %d)\n",ideal,unittype[ATYPE],armynum,ASOLD,sct[x][y].people); X#endif DEBUG X } X } X#ifdef DEBUG X check(__LINE__); X#endif DEBUG X X /* if archer power - all units are archers */ X if(magic(country,ARCHER)==1) X for(armynum=1;armynum<MAXARM;armynum++) X if((ASOLD>0)&&(ATYPE!=A_MILITIA)) ATYPE=A_ARCHER; X} X Xvoid Xgetdstatus() X{ X int x,oldstat[MAXNTN]; X X if(ntn[country].active<=1) return; X X for(x=1;x<MAXNTN;x++) { X oldstat[x] = ntn[country].dstatus[x]; X /*if they at war with you go to war with them*/ X if(ntn[x].dstatus[country]>=WAR) { X if(ntn[country].dstatus[x]<WAR) X fprintf(fnews,"2.\tnation %s returns %s's declaration of war\n",ntn[country].name,ntn[x].name); X X ntn[country].dstatus[x]=WAR; X } else X 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) { X ntn[country].dstatus[x]=WAR; X } else if(rand()%8==0) { X ntn[country].dstatus[x]=JIHAD; X } 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]<WAR)) X if(rand()%3==0) ntn[country].dstatus[x]--; X X if((ntn[country].dstatus[x]<WAR) X &&(ntn[country].dstatus[x]>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]+1<ntn[country].dstatus[x]){ X if(rand()%3==0) X ntn[country].dstatus[x]--; X } X if(ntn[x].race==ntn[country].race) X if(rand()%3==0) X ntn[country].dstatus[x]--; X } X if(rand()%6==0) { X if(ntn[country].dstatus[x]!=JIHAD) X ntn[country].dstatus[x]++; X } X else if((rand()%5==0) X &&(ntn[country].dstatus[x]!=CONFEDERACY)) { X ntn[country].dstatus[x]--; X } X } X } X X for(x=1;x<MAXNTN;x++) X if(ntn[x].active>1){ X if((rand()%5==0) X &&(ntn[x].dstatus[country]==WAR) X &&(ntn[country].dstatus[x]==WAR)) { X ntn[x].dstatus[country]=HOSTILE; X ntn[country].dstatus[x]=HOSTILE; X fprintf(fnews,"2.\tnation %s and %s announce ceasefire\n",ntn[country].name,ntn[x].name); X } else if((oldstat[x]==WAR)&&(ntn[country].dstatus[x]==WAR)){ X fprintf(fnews,"2.\tnation %s stays at war with %s\n",ntn[country].name,ntn[x].name); X } else if((oldstat[x]<WAR)&&(ntn[country].dstatus[x]==WAR)){ X fprintf(fnews,"2.\tnation %s goes to war with %s\n",ntn[country].name,ntn[x].name); X } else if((oldstat[x]!=JIHAD)&&(ntn[country].dstatus[x]==JIHAD)){ X fprintf(fnews,"2.\tnation %s announces a jihad with %s\n",ntn[country].name,ntn[x].name); X } X } X} X Xint Xnationrun() X{ X int goldthresh,ironthresh,citythresh; X int armynum,loop; X int x,y,i; X long zz; X X#ifdef DEBUG X check(__LINE__); X#endif DEBUG X prep(country); 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 getdstatus(); X X /*move units */ X /*are they at war with any normal countries*/ X peace=0; X for(i=1;i<MAXNTN;i++) if(ntn[country].dstatus[i]>peace) X peace=ntn[country].dstatus[i]; X X#ifdef DEBUG X check(__LINE__); X#endif DEBUG X if(peace<WAR){ X peace=8; X pceattr(); X } else { X /*if war then attack &/or expand */ X peace=12; X /*are they attacking or defending */ X if(ntn[country].tmil==0) defattr(); X else for(x=0;x<MAXNTN;x++) if(ntn[country].dstatus[x]>HOSTILE){ 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;armynum<MAXARM;armynum++) X if((ASOLD>0)&&(ATYPE!=A_MILITIA)) X ASTAT=ATTACK; X atkattr(); X } X /*defender*/ X else { X for(armynum=1;armynum<MAXARM;armynum++) X if((ASOLD>0)&&(ATYPE!=A_MILITIA)){ X if(ASOLD<350) ASTAT=DEFEND; X else ASTAT=ATTACK; X } X defattr(); X } X } X } X#ifdef DEBUG X check(__LINE__); X#endif DEBUG X for(armynum=1;armynum<MAXARM;armynum++) X if((ASOLD!=0) X &&(ATYPE!=A_MILITIA)) armymove(armynum); X X /* INTELLIGENT SECTOR REDESIGNATION */ X if(ntn[country].active!=1) { /* no pc's */ X goldthresh=4; X ironthresh=4; X citythresh=10; X for(loop=1;loop<5;loop++) { X#ifdef DEBUG X printf("\tnpcredes(): country %s, food %ld gold %d, iron %d, city %d\n",ntn[country].name,spread.food,goldthresh,ironthresh,citythresh); X#endif DEBUG X X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) X if((sct[x][y].owner==country) X &&(is_habitable(x,y))) X n_redes(x,y,goldthresh,ironthresh,citythresh); X X spreadsheet(country); X X if(spread.food < spread.civilians * 2L) { X goldthresh++; X ironthresh++; X citythresh--; X } else if(spread.food > spread.civilians * 3L) { X if(rand()%2==0) goldthresh--; X else ironthresh--; X if(goldthresh==0) goldthresh=1; X if(ironthresh==0) ironthresh=1; X citythresh++; X } X else break; X } X } X X /*build forts in any cities*/ X if(ntn[country].active!=1) for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) X if(((sct[x][y].designation==DCITY) X ||(sct[x][y].designation==DCAPITOL)) X &&(sct[x][y].owner==country) X &&(sct[x][y].fortress<10) X &&(ntn[country].tgold>10000) X &&(rand()%5==0) X &&(sct[x][y].fortress<(sct[x][y].people%1000))) X sct[x][y].fortress++; X#ifdef DEBUG X check(__LINE__); X#endif DEBUG X /*redo mil*/ X if(ntn[country].active!=1) redomil(); X#ifdef DEBUG X check(__LINE__); X#endif DEBUG X X /*buy new powers and/or new weapons*/ X if(getmgkcost(M_MIL,country) < getmgkcost(M_CIV,country)){ X if(ntn[country].jewels > getmgkcost(M_MIL,country)) { X ntn[country].jewels-=getmgkcost(M_MIL,country); X if((zz=getmagic(M_MIL))!=0){ X fprintf(fnews,"1.\tnation %s gets combat power number %d\n",ntn[country].name,zz); X printf("\tnation %s gets combat power number %d\n",ntn[country].name,zz); X exenewmgk(zz); X } else if((zz=getmagic(M_MIL))!=0){ X fprintf(fnews,"1.\tnation %s gets combat power number %d\n",ntn[country].name,zz); X printf("\tnation %s gets combat power number %d\n",ntn[country].name,zz); X exenewmgk(zz); X } X else ntn[country].jewels+=getmgkcost(M_MIL,country); X } X } else { X if(ntn[country].jewels > getmgkcost(M_CIV,country)) { X ntn[country].jewels-=getmgkcost(M_CIV,country); X if((zz=getmagic(M_CIV))!=0){ X fprintf(fnews,"1.\tnation %s gets civilian power number %d\n",ntn[country].name,zz); X printf("\tnation %s gets civilian power number %d\n",ntn[country].name,zz); X exenewmgk(zz); X } X else if((zz=getmagic(M_CIV))!=0){ X fprintf(fnews,"1.\tnation %s gets civilian power number %d\n",ntn[country].name,zz); X printf("\tnation %s gets civilian power number %d\n",ntn[country].name,zz); X exenewmgk(zz); X } X else ntn[country].jewels+=getmgkcost(M_CIV,country); X } X } X X#ifdef DEBUG X check(__LINE__); X#endif DEBUG X if(magic(country,VAMPIRE)!=1) { 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 /* SHOULD USE spread.iron but it didnt work right */ 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 printf("\tnation %s buys +1 percent attack and defence\n",ntn[country].name); X } X } X} X X/* make sectors of those with whom you are peaceful attr = 1 */ Xn_atpeace() X{ X register int x,y; X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) X if((sct[x][y].owner!=0) X &&(ntn[country].dstatus[sct[x][y].owner]<WAR) X &&(abs(x-ntn[country].capx)>2) X &&(abs(y-ntn[country].capy)>2)) X attr[x][y]=1; X} X X/* you are too far from capitol */ Xn_toofar() X{ X register int x,y; X for(x=ntn[country].capx+NPCTOOFAR;x<MAPX;x++) X for(y=0;y<MAPY;y++) if(ONMAP) X attr[x][y]=1; X for(y=ntn[country].capy+NPCTOOFAR;y<MAPY;y++) X for(x=0;x<MAPY;x++) if(ONMAP) X attr[x][y]=1; X for(x=0;x<ntn[country].capx-NPCTOOFAR;x++) X for(y=0;y<MAPY;y++) if(ONMAP) X attr[x][y]=1; X for(y=0;y<ntn[country].capy-NPCTOOFAR;y++) X for(x=0;x<MAPY;x++) if(ONMAP) X attr[x][y]=1; X} X X/* take undefended land */ Xn_unowned() X{ X register int x,y; X int dist; X X /* around capitol */ X for(x=ntn[country].capx-4;x<=ntn[country].capx+4;x++){ X for(y=ntn[country].capy-4;y<=ntn[country].capy+4;y++){ X if((ONMAP)&&(sct[x][y].owner==0)) { X /* find distance btwn x,y and cap */ X dist=abs(x-ntn[country].capx)+abs(y,ntn[country].capy); X if(dist<10) attr[x][y]+= 500 - 50*dist; X } X } X } X X for(x=0;x<MAPX;x++) { X for(y=0;y<MAPY;y++) { X /*add to attractiveness for unowned sectors*/ X if(sct[x][y].owner == 0) { X attr[x][y]+=100; X } else { X if(sct[x][y].owner == NNOMAD) X attr[x][y]+=25; X } X } X } X if(is_habitable(x,y) == 0) attr[x][y] /= 5; X} Xvoid Xn_defend(natn) Xregister short natn; X{ X int x,y; X X /* add 1/10th of soldiers in sector */ X for(x=1;x<MAXARM;x++) if(ntn[natn].arm[x].sold > 0) X if(sct[ntn[natn].arm[x].xloc][ntn[natn].arm[x].yloc].owner==country) X attr[ntn[natn].arm[x].xloc][ntn[natn].arm[x].yloc] += X ntn[natn].arm[x].sold/10; X X /*plus 80 if near your capitol */ 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;x<MAPX;x++) for(y=0;y<MAPY;y++) { X if(movecost[x][y]==1) attr[x][y] += 50; X else if(movecost[x][y]<=3) attr[x][y] += 20; X else if(movecost[x][y]<=5) attr[x][y] += 10; X X if((sct[x][y].designation==DCITY) X &&((sct[x][y].owner==country)||(sct[x][y].owner==natn))){ X attr[x][y] += 50; X } X } X} X Xvoid Xn_attack(nation) Xregister short nation; X{ X register int x,y; X X /*plus 40 if next to their capitol */ 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((sct[x][y].owner==nation)&&(ONMAP)) X attr[x][y]+=40; X } X } X X /*plus 100 if on their capitol*/ X attr[ntn[nation].capx][ntn[nation].capy]+=100; X} X X/* +100 if undefended sectors of nation, +60 if not */ Xvoid Xn_undefended( nation ) X{ X register int x,y; X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++) if(sct[x][y].owner==nation){ X if(is_habitable(x,y) == 0) { X attr[x][y] += 30; X } else if(occ[x][y]==0) { X attr[x][y]+=100; X } else { X attr[x][y]+=60; X } X } X} X X/* +60 if between two capitols */ Xvoid Xn_between(nation) Xint nation; X{ X int x1,x2,y1,y2,x,y; X X /*plus if strategic blocking sector*/ X X /*+60 if between the two capitol*/ X if (ntn[nation].capx < ntn[country].capx){ X x1=ntn[nation].capx; X x2=ntn[country].capx; 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 X/* if in jeopardy, move to survive X * if within two of cap add 1/5th of men X * if on cap and war and 2x your garrison go jihad and + 1/2 men X */ Xvoid Xn_survive() X{ X register struct army *aptr; X int nation,armynum; X X if(sct[ntn[country].capy][ntn[country].capy].owner!=country){ X attr[ntn[country].capy][ntn[country].capy]=1000; X } X X /*defend your capitol if occupied, +50 more if with their army*/ X for(nation=1;nation<MAXNTN;nation++) X if((ntn[nation].active != 0) X &&((ntn[nation].dstatus[country]>=WAR) X ||(ntn[country].dstatus[nation]>=WAR))){ X for(armynum=1;armynum<MAXARM;armynum++) X if(ntn[nation].arm[armynum].sold > 0) { X X aptr = &(ntn[nation].arm[armynum]); X X if((aptr->xloc==ntn[nation].capx) X &&(aptr->yloc==ntn[nation].capy)){ X if(aptr->sold>2*ntn[country].arm[0].sold){ X attr[aptr->xloc][aptr->yloc]+= X aptr->sold/2; X } else { X attr[aptr->xloc][aptr->yloc]+= X aptr->sold/5; X } X } X else if((aptr->xloc<=ntn[nation].capx+2) X &&(aptr->xloc>=ntn[nation].capx-2) X &&(aptr->yloc<=ntn[nation].capy+2) X &&(aptr->yloc>=ntn[nation].capy-2)){ X attr[aptr->xloc][aptr->yloc]+=aptr->sold/5; X X } X } X } X} X Xvoid Xdefattr() X{ X int nation; X X n_unowned(); X X for(nation=1;nation<MAXNTN;nation++) X if((ntn[nation].active!=0)&&(ntn[country].dstatus[nation]>=WAR)) { X n_defend(nation); X n_between(nation); X n_undefended(nation); X } X X n_toofar(); X n_survive(); X} X X/*calculate attractiveness of attacking sectors*/ Xvoid Xatkattr() X{ X int nation; X X n_unowned(); X X /*adjust for each nation that you are at war with*/ X for(nation=1;nation<MAXNTN;nation++) X if(ntn[country].active!=0) X if(ntn[country].dstatus[nation]==WAR) { X n_between(nation); X n_undefended(nation); X n_attack(nation); X } else if(ntn[country].dstatus[nation]==JIHAD) { X n_attack(nation); X n_attack(nation); X n_between(nation); X n_undefended(nation); X n_attack(nation); X n_between(nation); X n_undefended(nation); X n_attack(nation); X } X X n_toofar(); X n_survive(); X} X X/*calculate attractiveness when at peace*/ Xint Xpceattr() X{ X n_unowned(); X n_atpeace(); X n_toofar(); X n_survive(); X} X#endif X X#ifdef DEBUG Xcheck(line) Xint line; X{ X int armynum; X for(armynum=0;armynum<MAXARM;armynum++) X if(ASOLD<0) { X printf("ERROR: line %d army %d nation %s soldier %d\n",line,armynum,ntn[country].name,ASOLD); X ASOLD=0; X } X if((AXLOC>MAPX)||(AYLOC>MAPY)){ X printf("CHECK ERROR: line %d army %d nation %s loc %d %d\n",line,armynum,ntn[country].name,AXLOC,AYLOC); X } X if(ntn[country].tiron < 0L) X printf("ERROR: line %d nation %s iron is %ld\n",line,ntn[country].name,ntn[country].tiron); X if(ntn[country].tfood < 0L) X printf("ERROR: line %d nation %s food is %ld\n",line,ntn[country].name,ntn[country].tfood); X if(ntn[country].jewels < 0L) X printf("ERROR: line %d nation %s jewels is %ld\n",line,ntn[country].name,ntn[country].jewels); X} X#endif DEBUG END_OF_npc.c if test 28401 -ne `wc -c <npc.c`; then echo shar: \"npc.c\" unpacked with wrong size! fi # end of overwriting check fi echo shar: End of archive 2 \(of 8\). cp /dev/null ark2isdone 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