games-request@tekred.TEK.COM (10/26/87)
Submitted by: ihnp4!mhuxd!smile (E.BARLOW) Comp.sources.games: Volume 2, Issue 59 Archive-name: conquest/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 5)." # Contents: combat.c magic.c newlogin.c # Wrapped by billr@tekred on Mon Oct 26 10:33:03 1987 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\" \(18977 characters\) sed "s/^X//" >combat.c <<'END_OF_combat.c' X/*conquest 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#include "header.h" X X#define ATKR 2 X#define DFND 1 X X/*is sector occupied, if MAXNTN+1 2+ armies occupy*/ Xextern short occ[MAPX][MAPY]; Xextern FILE *fnews; Xextern short country; X Xint unit[32]; /*armynum*/ Xint owner[32]; /*owner*/ Xint side[32]; /*see definitions->1=units 2=unit*/ 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[]={ X 30,20,15,15,15,15,15,15,15,10,10,10,5,5,5,0,0,0,0,0,0 X}; Xint Cbt5_1[]={ X 40,30,20,20,20,20,15,15,15,10,10,10,5,5,5,0,0,0,0,0,0 X}; Xint Cbt4_1[]={ X 40,35,30,25,25,20,20,15,15,15,10,10,10,5,5,5,0,0,0,0,0 X}; Xint Cbt3_1[]={ X 55,45,35,30,25,25,20,20,20,15,15,10,10,10,5,5,5,0,0,0,0 X}; Xint Cbt2_1[]={ X 60,50,35,35,35,35,25,25,20,20,15,15,10,10,10,10,10,5,5,5,0 X}; Xint Cbt3_2[]={ X 65,55,35,35,35,35,30,30,25,25,20,20,15,15,15,15,15,10,10,10,0 X}; Xint Cbt5_4[]={ X 65,55,45,45,45,45,35,35,30,30,30,30,25,25,25,25,25,15,10,10,10 X}; Xint Cbt1_1[]={ X 85,65,55,55,55,55,45,45,35,35,35,35,25,25,25,25,25,15,10,10,10 X}; Xint Cbt4_5[]={ X 100,75,65,65,65,65,55,55,45,45,45,45,35,35,35,35,35,25,20,15,10 X}; Xint Cbt2_3[]={ X 100,85,75,75,65,65,55,55,45,45,45,45,40,40,35,35,35,35,25,20,10 X}; Xint Cbt1_2[]={ X 100,100,95,90,80,80,75,75,65,60,60,60,45,50,45,45,45,35,30,25,10 X}; Xint Cbt1_3[]={ X 110,110,100,100,90,90,85,85,80,80,70,70,65,65,55,50,45,40,30,25,10 X}; Xint Cbt1_4[]={ X 110,110,100,100,90,90,90,85,80,80,70,70,65,65,55,50,45,40,30,25,10 X}; Xint Cbt1_5[]={ X 120,110,110,100,100,90,90,90,80,80,70,70,65,65,55,50,45,40,30,25,10 X}; Xint Cbt1_6[]={ X 130,120,110,110,110,100,100,90,90,90,80,80,80,70,65,50,45,40,30,25,10 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 */ 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)&&(ntn[anation].arm[j].sold>0)&&(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<32;temp++){ X unit[temp]=(-1); X owner[temp]=(-1); X side[temp]=(-1); X } X X /*check all armies in area and add to matrix*/ X count=0; X valid=0; X /*is valid,set matrix*/ X for(country=0;country<NTOTAL;country++) if(ntn[country].active!=0) for(armynum=0;armynum<MAXARM;armynum++) if((ASOLD>0)&&(ASTAT!=SCOUT)&&(AXLOC==ntn[anation].arm[j].xloc)&&(AYLOC==ntn[anation].arm[j].yloc)&&(count<32)) { X X if((country!=anation)&&(ntn[anation].dstatus[country]>HOSTILE)) { X valid=1; X dnation=country; X } X unit[count]=armynum; X owner[count]=country; X count++; X } X X if(valid==1) fight(); X } X X /*navy combat*/ X for(j=0;j<MAXNAVY;j++) X if((ntn[anation].nvy[j].warships>0)&&(fought[ntn[anation].nvy[j].xloc][ntn[anation].nvy[j].yloc]==0)&&(sct[ntn[anation].arm[j].xloc][ntn[anation].arm[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<32;temp++){ X unit[temp]=(-1); X owner[temp]=(-1); X side[temp]=(-1); X } X X /*check all fleets in 1 sector range and add to matrix*/ X count=0; X valid=0; X /*is valid,set matrix*/ X for(country=0;country<NTOTAL;country++) if(ntn[country].active!=0) for(nvynum=0;nvynum<MAXNAVY;nvynum++) if((NWAR+NMER>0)&&(abs(NXLOC-ntn[anation].nvy[j].xloc)<=1)&&(abs(NYLOC-ntn[anation].nvy[j].yloc)<=1)&&(count<32)) { X fought[ntn[country].nvy[nvynum].xloc][ntn[country].nvy[nvynum].yloc]=1; X if((country!=anation)&&(ntn[anation].dstatus[country]>HOSTILE)){ X valid=1; X dnation=country; X } X unit[count]=armynum; X owner[count]=country; X count++; X } X if(valid==1) navalcbt(); X } X } X printf("\nall army and navy attacks completed"); X} X X/*taking the three matrices, run a combat*/ Xfight() X{ X FILE *fpmsg, *fopen(); 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; 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<32;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<32;i++) if(owner[i]!=(-1)) { X if(side[i]==ATKR) X asold += ntn[owner[i]].arm[unit[i]].sold; X else if(side[i]==DFND) X dsold += ntn[owner[i]].arm[unit[i]].sold; X if(magic(owner[i],VAMPIRE)==1) nvamps++; X } X X if((dsold<=0)||(asold<=0)) { X printf("ERROR 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<32;i++) if(owner[i]!=(-1)) { X if(side[i]==ATKR) X abonus += cbonus(i)*ntn[owner[i]].arm[unit[i]].sold; X else if(side[i]==DFND) X dbonus += cbonus(i)*ntn[owner[i]].arm[unit[i]].sold; X } X X abonus/=asold; X dbonus/=dsold; 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 = rand()%100 + 50 + abonus - dbonus; X droll = rand()%100 + 50 + abonus - dbonus; X X if(aroll<0) aroll=0; X if(aroll>199) aroll=199; 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 } X if(odds>600) { X PAloss = Cbt6_1[aroll/10]; X PDloss = Cbt1_6[20-droll/10]; X } X else if(odds>500){ X PAloss = Cbt5_1[aroll/10]; X PDloss = Cbt1_5[20-droll/10]; X } X else if(odds>400){ X PAloss = Cbt4_1[aroll/10]; X PDloss = Cbt1_4[20-droll/10]; X } X else if(odds>300) { X PAloss = Cbt3_1[aroll/10]; X PDloss = Cbt1_3[20-droll/10]; X } X else if(odds>200) { X PAloss = Cbt2_1[aroll/10]; X PDloss = Cbt1_2[20-droll/10]; X } X else if(odds>150) { X PAloss = Cbt3_2[aroll/10]; X PDloss = Cbt2_3[20-droll/10]; X } X else if(odds>125) { X PAloss = Cbt5_4[aroll/10]; X PDloss = Cbt4_5[20-droll/10]; X } X else if(odds>100){ X PAloss = Cbt1_1[aroll/10]; X PDloss = Cbt1_1[20-droll/10]; X } X else if(odds>75) { X PAloss = Cbt4_5[aroll/10]; X PDloss = Cbt5_4[20-droll/10]; X } X else if(odds>50) { X PAloss = Cbt1_2[aroll/10]; X PDloss = Cbt2_1[20-droll/10]; X } X else if(odds>33) { X PAloss = Cbt1_3[aroll/10]; X PDloss = Cbt3_1[20-droll/10]; X } X else if(odds>15) { X PAloss = Cbt1_6[aroll/10]; X PDloss = Cbt6_1[20-droll/10]; X } X else { X PAloss = 120; X PDloss = 0; X } X X if ((fpmsg=fopen(MSGFILE,"a+"))==NULL) { X printf("\n\tERROR OPENING %s",MSGFILE); X exit(1); X } X X /*NOTE LOSSES ARE ADJUSTED BY CBONUS*/ X for(i=0;i<32;i++) if(owner[i]!=(-1)){ X if(side[i]==ATKR){ X loss=(ntn[owner[i]].arm[unit[i]].sold * PAloss * 1.2)/(100+2*ntn[owner[i]].aplus); X if(loss>ntn[owner[i]].arm[unit[i]].sold ) X loss=ntn[owner[i]].arm[unit[i]].sold; X /*army can't have less than 25 men in it*/ X if(ntn[owner[i]].arm[unit[i]].sold-loss<25) X loss=ntn[owner[i]].arm[unit[i]].sold; X Aloss+=loss; X ntn[owner[i]].arm[unit[i]].sold-=loss; X X } X else if(side[i]==DFND){ X loss=(ntn[owner[i]].arm[unit[i]].sold * PDloss * 1.2)/(100+2*ntn[owner[i]].dplus); X if(loss>ntn[owner[i]].arm[unit[i]].sold ) X loss=ntn[owner[i]].arm[unit[i]].sold; X /*destroy army if < 25 men*/ X if(ntn[owner[i]].arm[unit[i]].sold-loss<25) X loss=ntn[owner[i]].arm[unit[i]].sold; X Dloss+=loss; X ntn[owner[i]].arm[unit[i]].sold-=loss; X } X if((nvamps>0)&&(magic(owner[i],VAMPIRE)==1)) vampire+=loss/2; X } X X fprintf(fnews,"4.\tBattle in %d,%d",ntn[owner[0]].arm[unit[0]].xloc, ntn[owner[0]].arm[unit[0]].yloc); X for(j=0;j<32;j++) if(owner[j]!=(-1)){ X done=0; X for(i=0;i<j;i++) if(owner[j]==owner[i]) done=1; X if(done==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 if(nvamps>0){ X for(i=0;i<32;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<32;j++) if(owner[j]!=(-1)){ X done=0; X X /*first time your nation appears done=0*/ X for(i=0;i<j;i++) if(owner[j]==owner[i]) done=1; X X if((done==0)&&(ntn[owner[j]].active==1)) { X X fprintf(fpmsg,"%s BATTLE 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 You are on the Attacking Side\n",ntn[owner[j]].name); X else fprintf(fpmsg,"%s You are on the Defending Side\n",ntn[owner[j]].name); X X /*detail all participants in battle*/ X for(k=0;k<32;k++) if(owner[k]!=(-1)){ X if(side[k]==DFND) fprintf(fpmsg,"%s\t %s is defending with army %d \n",ntn[owner[j]].name, ntn[owner[k]].name,unit[k]); X else fprintf(fpmsg,"%s\t %s is attacking with army %d \n",ntn[owner[j]].name,ntn[owner[k]].name, unit[k]); X } X X fprintf(fpmsg,"%s attacking soldiers=%d\tmodified roll=%d\n",ntn[owner[j]].name,asold,aroll); X fprintf(fpmsg,"%s defending soldiers=%d\tmodified roll=%d\n",ntn[owner[j]].name,dsold,droll); X fprintf(fpmsg,"%s ODDS are %d to 100\n",ntn[owner[j]].name,odds); X fprintf(fpmsg,"%s RESULT: Attackers lose %d men, Defenders lose %d men\n",ntn[owner[j]].name,Aloss, Dloss); X fprintf(fpmsg,"%s\n","END"); X } X } X fclose(fpmsg); X} X X/*Subroutine to determine combat bonuses for unit i in matrix*/ 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)||(magic(country,DERVISH)==1))&&((sct[AXLOC][AYLOC].vegitation==ICE)||(sct[AXLOC][AYLOC].vegitation==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].vegitation==JUNGLE) armbonus+=20; X else if(sct[AXLOC][AYLOC].vegitation==FORREST) armbonus+=15; X else if(sct[AXLOC][AYLOC].vegitation==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)&&(sct[AXLOC][AYLOC].designation==DCITY)){ X if(magic(country,ARCHER)==1) armbonus+=30; 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)&&(sct[AXLOC][AYLOC].designation==DCAPITOL)){ X if(magic(country,ARCHER)==1) armbonus+=30; 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 return(armbonus); X} X Xprep() X{ X short armynum,nvynum; X int save,i,j; X /*set occ to 0*/ X for(i=0;i<MAPX;i++) for(j=0;j<MAPX;j++) occ[i][j]=0; X save=country; X /*set occ to country of occupant army*/ X for(country=0;country<NTOTAL;country++) X if(ntn[country].active!=0) { X for(armynum=0;armynum<MAXARM;armynum++){ X if((ASOLD>0)&&(ASTAT!=SCOUT)){ X if((occ[AXLOC][AYLOC]==0)||(occ[AXLOC][AYLOC]==country)) X occ[AXLOC][AYLOC]=country; X else occ[AXLOC][AYLOC]=MAXNTN+5; X } X } X for(nvynum=0;nvynum<MAXNAVY;nvynum++){ X if(NWAR+NMER>0){ X if((occ[NXLOC][NYLOC]==0)||(occ[NXLOC][NYLOC]==country)) X occ[NXLOC][NYLOC]=country; X else occ[NXLOC][NYLOC]=MAXNTN+5; X } X } X } X country=save; X} X X/*SUBROUTINE TO RUN NAVAL COMBAT ON ALL SHIPS */ X/*just like fight, this takes array of owner,side,unit and calculate*/ Xnavalcbt() X{ X FILE *fpmsg, *fopen(); X int done=0; X int temp1,temp2; 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 taloss=0,tdloss=0; /*total a's and d's total losses*/ X register int k,i,j; X X /* determine who is attacker & who is on defenders side?*/ X for(j=0;j<32;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)&&(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 /*RUN COMBAT; loop until done*/ X /*determine relative strengths--does anybody try to flee*/ X X while(done==0){ X /*calculate number of ships on a side*/ X for(j=0;j<32;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 10%; once all warships sunk then all*/ X /*sunk are are captured merchant*/ X for(i=0;i<32;i++) X if((owner[i]!=(-1))&&(ntn[owner[i]].nvy[unit[i]].warships>0)){ X for(j=0;j<ntn[owner[i]].nvy[unit[i]].warships;j++) X if(side[j]==ATKR) if(rand()%10==0) asunk++; X else if(rand()%10==0) dsunk++; X } X X fprintf(fnews,"4.\tNaval Battle in %d,%d",ntn[owner[0]].arm[unit[0]].xloc, ntn[owner[0]].arm[unit[0]].yloc); X for(j=0;j<32;j++) if(owner[j]!=(-1)){ X done=0; X for(i=0;i<j;i++) if(owner[j]==owner[i]) done=1; X if(done==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 fprintf(fnews,"\n4.\tthis round attackers lose %d of %d warships (remainder prizes)",asunk,aship); X fprintf(fnews,"\n4.\tthis round defenders lose %d of %d warships (remainder prizes)",dsunk,dship); X X taloss+=asunk; X tdloss+=dsunk; X X if ((fpmsg=fopen(MSGFILE,"a+"))==NULL) { X fprintf(fnews,"\n4.\tERROR OPENING %s",MSGFILE); X exit(1); X } X X for(i=0;i<32;i++) if(owner[i]!=(-1)){ X if((asunk>0)&&(side[i]==ATKR)){ X if(asunk>ntn[owner[i]].nvy[unit[i]].warships) { X asunk-=ntn[owner[i]].nvy[unit[i]].warships; X ntn[owner[i]].nvy[unit[i]].warships=0; X } X else { X ntn[owner[i]].nvy[unit[i]].warships-=asunk; X asunk=0; X } X } X else if((dsunk>0)&&(side[i]==DFND)){ X if(dsunk>ntn[owner[i]].nvy[unit[i]].warships) { X dsunk-=ntn[owner[i]].nvy[unit[i]].warships; X ntn[owner[i]].nvy[unit[i]].warships=0; X } X else { X ntn[owner[i]].nvy[unit[i]].warships-=dsunk; X dsunk=0; X } X } X } X X /*prizes*/ X if(dsunk+asunk>0) { X X temp1=asunk; X temp2=dsunk; X for(i=0;i<32;i++) if(owner[i]!=(-1)){ X if((dsunk>0)&&(side[i]==ATKR)){ X ntn[owner[i]].nvy[unit[i]].merchant+=dsunk; X dsunk=0; X if(rand()%2==0) done=1; X } X if((asunk>0)&&(side[i]==DFND)){ X ntn[owner[i]].nvy[unit[i]].merchant+=asunk; X asunk=0; X if(rand()%2==0) done=1; X } X } X asunk=temp1; X dsunk=temp2; X X /*remove prizes?*/ X for(i=0;i<32;i++) if(owner[i]!=(-1)){ X if((asunk>0)&&(side[i]==ATKR)){ X if(asunk>aship) { X asunk-=ntn[owner[i]].nvy[unit[i]].merchant; X ntn[owner[i]].nvy[unit[i]].merchant=0; X } X else { X ntn[owner[i]].nvy[unit[i]].merchant-=asunk; X asunk=0; X } X } X else if((dsunk>0)&&(side[i]==DFND)){ X if(dsunk>dship) { X dsunk-=ntn[owner[i]].nvy[unit[i]].merchant; X ntn[owner[i]].nvy[unit[i]].merchant=0; X } X else { X ntn[owner[i]].nvy[unit[i]].merchant-=dsunk; X dsunk=0; X } X } X } X } X X /*will round continue; does one side wish to withdraw*/ X if(rand()%3==0) done=1; X else if((taloss>1.5*tdloss)||(tdloss>1.5*taloss)){ X if(rand()%3==0) done=1; X } X } X X /*mail results; who is in the battle*/ X for(j=0;j<32;j++) if(owner[j]!=(-1)){ X done=0; X X /*first time your nation appears done=0*/ X for(i=0;i<j;i++) if(owner[j]==owner[i]) done=1; X X if((done==0)&&(ntn[owner[j]].active==1)) { X X fprintf(fpmsg,"%s NAVAL BATTLE SUMMARY for sector %d, %d\n",ntn[owner[j]].name,ntn[owner[0]].nvy[unit[0]].xloc, ntn[owner[0]].nvy[unit[0]].yloc); X X if(side[j]==ATKR) fprintf(fpmsg,"%s You are on the Attacking Side\n",ntn[owner[j]].name); X else fprintf(fpmsg,"%s You are on the Defending Side\n",ntn[owner[j]].name); X X /*detail all participants in battle*/ X for(k=0;k<32;k++) X if((owner[k]!=owner[j]&&(owner[k]!=(-1)))){ X if(side[k]==DFND) 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, taloss,tdloss); X fprintf(fpmsg,"END\n"); X } X } X X fclose(fpmsg); X} END_OF_combat.c if test 18977 -ne `wc -c <combat.c`; then echo shar: \"combat.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f magic.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"magic.c\" else echo shar: Extracting \"magic.c\" \(9276 characters\) sed "s/^X//" >magic.c <<'END_OF_magic.c' X/*conquest 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 new login for a new player*/ X#include "header.h" X#include <ctype.h> X Xextern short country; Xextern short redraw; Xextern FILE *fexe; Xextern FILE *fnews; X X/*give player one new magic power in current magic (powers)*/ X/*do nothing if that player has that power or it is not permitted*/ X/*getmagic() returns the value of the power gained, and stores it in power*/ X Xgetmagic() X{ Xshort newpower; X newpower=rand()%MAXPOWER; X switch(newpower){ X case WARRIOR: X case CAPTAIN: X case WARLORD: X if(magic(country,WARRIOR)!=1){ X ntn[country].powers*=WARRIOR; X return(WARRIOR); X } X else if(magic(country,CAPTAIN)!=1){ X ntn[country].powers*=CAPTAIN; X return(CAPTAIN); X } X else if(magic(country,WARLORD)!=1){ X ntn[country].powers*=WARLORD; X return(WARLORD); X } X break; X case MI_MONST: X case AV_MONST: X case MA_MONST: X if(ntn[country].race!=ORC) return(1); X if(magic(country,MI_MONST)!=1){ X ntn[country].powers*=MI_MONST; X return(MI_MONST); X } X else if(magic(country,AV_MONST)!=1){ X ntn[country].powers*=AV_MONST; X return(AV_MONST); X } X else if(magic(country,MA_MONST)==1){ X ntn[country].powers*=MA_MONST; X return(MA_MONST); X } X break; X case SPY: X case KNOWALL: X case DERVISH: X case HIDDEN: X case ARCHITECT: X case URBAN: X case THE_VOID: X case HEALER: X case ARCHER: X case CAVALRY: X if(magic(country,newpower)==1) return(1); X ntn[country].powers*=newpower; X return(newpower); X case DESTROYER: X if((ntn[country].race!=ELF)&&(magic(country,DESTROYER)!=1)){ X ntn[country].powers*=DESTROYER; X return(DESTROYER); X } X break; X case VAMPIRE: X if((ntn[country].race!=ELF)&&(magic(country,VAMPIRE)!=1)){ X ntn[country].powers*=VAMPIRE; X return(VAMPIRE); X } X break; X case MINER: X if((ntn[country].race!=ELF)&&(ntn[country].race!=DWARF)&&(magic(country,MINER)!=1)){ X ntn[country].powers*=MINER; X return(MINER); X } X case STEEL: X if(magic(country,STEEL)==1) return(1); X if(magic(country,MINER)!=1) return(1); X ntn[country].powers*=STEEL; X return(STEEL); X case BREEDER: X if(magic(country,BREEDER)==1) return(1); X if(ntn[country].race!=ORC) return(1); X ntn[country].powers*=BREEDER; X return(BREEDER); X } X return(1); X} X X/*form to interactively get a magic power*/ Xdomagic() X{ X short x,count,done=0,loop=0; X short isgod=0; X short overmax=0; X if(country==0) { X isgod=1; X clear(); X mvaddstr(0,0,"WHAT NATION NUMBER:"); X refresh(); X echo(); X scanw("%hd",&country); X noecho(); X } X X while(done==0){ X clear(); X count=3; X redraw=TRUE; X standout(); X mvprintw(0,(COLS/2)-15,"MAGIC POWERS FOR %s",ntn[country].name); X standend(); X /*print the powers that you have*/ X if(magic(country,WARRIOR)==1) X mvaddstr(count++,0,"you have WARRIOR power (Fighter Level 1)"); X if(magic(country,CAPTAIN)==1) X mvaddstr(count++,0,"you have CAPTAIN power (Fighter Level 2)"); X if(magic(country,WARLORD)==1) X mvaddstr(count++,0,"you have WARLORD power (Fighter Level 3)"); X if(magic(country,MI_MONST)==1) X mvaddstr(count++,0,"you have MINOR MONSTER power"); X if(magic(country,AV_MONST)==1) X mvaddstr(count++,0,"you have AVERAGE MONSTER power"); X if(magic(country,MA_MONST)==1) X mvaddstr(count++,0,"you have MAJOR MONSTER power"); X if(magic(country,SPY)==1) X mvaddstr(count++,0,"you have SPY power"); X if(magic(country,KNOWALL)==1) X mvaddstr(count++,0,"you have KNOWALL power"); X if(magic(country,DERVISH)==1) X mvaddstr(count++,0,"you have DERVISH power"); X if(magic(country,DESTROYER)==1) X mvaddstr(count++,0,"you have DESTROYER power"); X if(magic(country,HIDDEN)==1) X mvaddstr(count++,0,"you have HIDDEN power"); X if(magic(country,THE_VOID)==1) X mvaddstr(count++,0,"you have THE_VOID power"); X if(magic(country,ARCHITECT)==1) X mvaddstr(count++,0,"you have ARCHITECT power"); X if(magic(country,VAMPIRE)==1) X mvaddstr(count++,0,"you have VAMPIRE power"); X if(magic(country,HEALER)==1) X mvaddstr(count++,0,"you have HEALER power"); X if(magic(country,MINER)==1) X mvaddstr(count++,0,"you have MINER power"); X if(magic(country,URBAN)==1) X mvaddstr(count++,0,"you have URBAN power"); X if(magic(country,STEEL)==1) X mvaddstr(count++,0,"you have STEEL power"); X if(magic(country,ARCHER)==1) X mvaddstr(count++,0,"you have ARCHER power"); X if(magic(country,CAVALRY)==1) X mvaddstr(count++,0,"you have CAVALRY power"); X if(magic(country,BREEDER)==1) X mvaddstr(count++,0,"you have BREEDER power"); X standout(); X if(count>=PCPOWERS+3){ X mvaddstr(count++,0,"YOU HAVE THE MAXIMUM NUMBER OF POWERS"); X mvaddstr(count++,0," NEW POWERS COST DOUBLE AND ARE INVALID UNLESS THEY"); X mvaddstr(count++,0," AUGMENT EXISTING FIGHTER OR MONSTER POWERS (hit any char)"); X standend(); X overmax=1; X } X X if(ntn[country].race==ORC){ X mvprintw(count++,0,"DO YOU WISH TO TAKE OVER A NPC NATION (enter y or n):"); X mvaddstr(count++,0," Base 10 percent for 100K Jewels if Confederacy and the same race"); X refresh(); X if(getch()=='y'){ X mvprintw(count++,0,"SORRY; NOT IMPLEMENTED YET"); X } X } X X count++; X mvprintw(count++,0,"DO YOU WISH TO BUY A RANDOM NEW POWER FOR %d JEWELS (enter y or n):",JWL_MGK); X standend(); X refresh(); X if(getch()=='y'){ X if(((ntn[country].jewels>JWL_MGK)&&(overmax==0))||(ntn[country].jewels>2*JWL_MGK)) { X while(loop==0) if((x=getmagic())!=1){ X if((ntn[country].powers<=1)||(x<1)){ X mvprintw(count++,0,"ERROR ON POWER #%d",x); X } X else if(overmax==1){ X ntn[country].jewels-=2*JWL_MGK; X if(((magic(country,WARRIOR)==1)&&((x==CAPTAIN)||(x==WARLORD)))||((magic(country,MI_MONST)==1)&&((x==AV_MONST)||(x==MA_MONST)))){ X CHGMGK; X exenewmgk(x); X } X else { X mvprintw(count++,0,"USELESS POWER (number %d)",x); X ntn[country].powers/=x; X } X } X else { X ntn[country].jewels-=JWL_MGK; X mvprintw(count++,0,"YOU NOW HAVE POWER #%d",x); X CHGMGK; X exenewmgk(x); X } X refresh(); X getch(); X loop=1; X } X } X else { X mvaddstr(count++,0,"NOT ENOUGH JEWELS -- hit any key"); X refresh(); X getch(); X done=1; X } X } X else done=1; X } X if(isgod==1) country=0; X} X X/*do magic for both npcs and pcs in update*/ X/*if target is 0 then it will be picked randomly*/ Xtakeover(percent,target) X{ Xint loop=1,y,save; X save=country; X country=target; X if(rand()%100<percent){ X loop=0; X y=0; X if (target==0) while(loop==0){ X y++; X country=rand()%MAXNTN; X if((ntn[country].race==ntn[save].race)&&(ntn[country].active>=2)) loop=1; X else if(y>=500) { X country=save; X return; X } X } X sct[ntn[country].capx][ntn[country].capy].owner=save; X fprintf(fnews,"1.\tnation %s taken over by %s\n",ntn[country].name,ntn[save].name); X destroy(); X } X country=save; X} X X/*execute new magic*/ Xexenewmgk(newpower) X{ X short x,y; X switch(newpower){ X case WARRIOR: X ntn[country].aplus+=10; X ntn[country].dplus+=10; X break; X case CAPTAIN: X ntn[country].aplus+=10; X ntn[country].dplus+=10; X break; X case WARLORD: X ntn[country].aplus+=10; X ntn[country].dplus+=10; X break; X case HEALER: X if(ntn[country].race==ORC) { X if(ntn[country].repro<=11) X ntn[country].repro+=2; X else ntn[country].repro=13; X } X else if(ntn[country].repro<=8){ X ntn[country].repro=10; X } X else if(ntn[country].repro==9){ X ntn[country].repro=10; X ntn[country].dplus+=5; X } X else if(ntn[country].repro>=10){ X ntn[country].dplus+=10; X } X break; X case DESTROYER: X for(x=ntn[country].capx-3;x<=ntn[country].capx+3;x++) { X for(y=ntn[country].capy-3;y<=ntn[country].capy+3;y++){ X if((x>0)&&(y>0)&&(x<MAPX)&&(y<MAPY)&&(sct[x][y].altitude!=WATER)&&(isdigit(sct[x][y].vegitation)==0)){ X sct[x][y].vegitation=DESERT; X sct[x][y].designation=DESERT; X } X } X } X break; X case MI_MONST: X case AV_MONST: X case MA_MONST: X case SPY: X case KNOWALL: X case DERVISH: X case HIDDEN: X case THE_VOID: X case ARCHITECT: X case MINER: X break; X case VAMPIRE: X ntn[country].aplus-=35; X ntn[country].dplus-=35; X ntn[country].maxmove-=2; X break; X case URBAN: X if(ntn[country].race==ORC) { X ntn[country].repro+=3; X if(ntn[country].repro>=13){ X ntn[country].maxmove+=2*(ntn[country].repro-13); X ntn[country].repro=13; X } X } X else if(ntn[country].repro<=9){ X ntn[country].repro+=3; X } X else { X ntn[country].maxmove+=2*(ntn[country].repro-9); X ntn[country].repro=12; X } X break; X case STEEL: X break; X case ARCHER: X ntn[country].dplus+=10; X break; X case CAVALRY: X ntn[country].aplus+=10; X ntn[country].maxmove+=6; X break; X case BREEDER: X ntn[country].repro+=3; X ntn[country].dplus-=10; X ntn[country].dplus-=10; X break; X } X} END_OF_magic.c if test 9276 -ne `wc -c <magic.c`; then echo shar: \"magic.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f newlogin.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"newlogin.c\" else echo shar: Extracting \"newlogin.c\" \(22711 characters\) sed "s/^X//" >newlogin.c <<'END_OF_newlogin.c' X/*conquest 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 new login for a new player*/ X#include <ctype.h> X X#include "header.h" X Xextern short country; X Xnewlogin() X{ X /* use points to create empire, add if late starter*/ X int points; X char tempc[10]; X int n; X int valid=1; /*valid == 0 means continue loop*/ X int temp; X int more=0; /*0 if add another player*/ X int loop; X int x; X char tempo[8]; X char passwd[8]; X register i; X X printf("\nPreparing to add player\n"); X printf("break at any time to abort\n"); X X while(more==0) { X points=MAXPTS; X /*find valid nation number type*/ X for(i=1;i<MAXNTN;i++) X if(ntn[i].active==0) { X country=i; X break; X } X printf("first valid nation id is %d\n",country); X X if(i==MAXNTN) { X beep(); X printf("error, cant add new nation\n"); X return; X } X X ntn[country].active=1; X X valid=0; X /*get name*/ X while(valid==0) { X valid=1; X printf("\nwhat name would you like your nation to have:"); X scanf("%s",ntn[country].name); X X if((strlen(ntn[country].name)<=1)||(strlen(ntn[country].name)<=1)){ X printf("\ninvalid name"); X valid=0; X } X X /*check if already used*/ X if((strcmp(ntn[i].name,"god")==0)||(strcmp(ntn[i].name,"unowned")==0)){ X printf("\nname already used"); X valid=0; X } X X for(i=1;i<(country-1);i++) X if(strcmp(ntn[i].name,ntn[country].name)==0) { X printf("\nname already used"); X valid=0; X } X } X X /*get password*/ X valid=0; X while(valid==0) { X printf("\nwhat is your nations password:"); X scanf("%s",passwd); X if((strlen(passwd)>=8)||(strlen(passwd)<2)) { X beep(); X printf("\ninvalid password (too short or long)"); X } X else { X printf("\nreenter your nations password:"); X scanf("%s",ntn[country].passwd); X } X if(strcmp(passwd,ntn[country].passwd)==0) valid=1; X } X strncpy(ntn[country].passwd,crypt(passwd,SALT),PASSLTH); X X /*get your name*/ X valid=0; X while(valid==0) { X valid=1; X printf("\nenter either YOUR name (j_smith) or the name of your nations leader (gandalf...)"); X printf("\n\t(maximum 10 characters, no spaces):"); X scanf("%s",tempc); X if((strlen(tempc)>=10)||(strlen(tempc)<2)) { X beep(); X printf("\ninvalid name (too short or long)"); X valid=0; X } X else strcpy(ntn[country].leader,tempc); X } X X valid=0; X while(valid==0) { X valid=1; X printf("\nwhat race would you like to be:"); X printf("\n\tchoose (d)warf,(e)lf,(o)rc,(h)uman:"); X scanf("%s",tempo); X switch(tempo[0]) { X case 'd': X printf("\ndwarf chosen\n"); X getclass(DWARF); X ntn[country].race=DWARF; X ntn[country].tgold=100000; /*1 pts*/ X ntn[country].tfood=12000; /*0 pts*/ X ntn[country].jewels=10000; /*0 pts*/ X ntn[country].tiron=10000; /*0 pts*/ X ntn[country].tciv= 6000; /*6 pts*/ X ntn[country].tmil= 1500; /*1.5 pts*/ X ntn[country].repro= 4; /*4 pts*/ X ntn[country].maxmove= 6; /*1.5 pts*/ X ntn[country].aplus= 20; /*2 pts*/ X ntn[country].dplus= 20; /*2 pts*/ X ntn[country].location=RANDOM; /*0+ pts*/ X /*MINER POWER INATE TO DWARVES*/ X printf("you have magical MINING skills"); X ntn[country].powers=MINER; X exenewmgk(MINER); X points-=18; X break; X case 'e': X printf("\nelf chosen\n"); X getclass(ELF); X ntn[country].race=ELF; X ntn[country].tgold=100000; /*1 pts*/ X ntn[country].tfood=12000; X ntn[country].jewels=10000; X ntn[country].tiron=10000; X ntn[country].tciv=7000; /*7 pts*/ X ntn[country].tmil=200; /*0 pts*/ X ntn[country].repro=3; /*3 pts*/ X ntn[country].maxmove=8; /*2 pts*/ X ntn[country].aplus=10; /*1 pts*/ X ntn[country].dplus=40; /*4 pts*/ X ntn[country].location=FAIR; /*1 pts*/ X printf("you have magical cloaking skills"); X ntn[country].powers=THE_VOID; X exenewmgk(THE_VOID); X points-=20; /* VOID COSTS ADDITIONAL PT*/ X break; X case 'o': X printf("\norc chosen\n"); X getclass(ORC); X ntn[country].race=ORC; X ntn[country].tgold=1000; /*0 pts*/ X ntn[country].tfood=12000; X ntn[country].jewels=10000; X ntn[country].tiron=10000; X ntn[country].tciv=4000; /*4 pts*/ X ntn[country].tmil=2500; /*2.5 pts*/ X ntn[country].repro=10; /*10 pts*/ X ntn[country].maxmove=6; /*1.5 pts*/ X ntn[country].aplus=00; /*0 pts*/ X ntn[country].dplus=00; /*0 pts*/ X /*MINOR MONSTER POWER INATE TO ORCS*/ X printf("your leader is a minor monster (army 0 is very potent)"); X ntn[country].powers=MI_MONST; X exenewmgk(MI_MONST); X ntn[country].location=RANDOM; /*0 pts*/ X points-=18; X break; X case 'h': X printf("\nhuman chosen\n"); X ntn[country].race=HUMAN; X getclass(HUMAN); X ntn[country].tgold=1000; /*0 pts*/ X ntn[country].tfood=12000; /*0 pts*/ X ntn[country].jewels=10000; /*0 pts*/ X ntn[country].tiron=10000; /*0 pts*/ X ntn[country].tciv=6000; /*6 pts*/ X ntn[country].tmil=1000; /*1 pts*/ X ntn[country].repro=5; /*5 pts*/ X ntn[country].maxmove=10; /*2.5 pts*/ X ntn[country].aplus=10; /*1 pts*/ X ntn[country].dplus=10; /*1 pts*/ X ntn[country].location=RANDOM; /*0 pts*/ X /*WARRIOR POWER INATE TO HUMANS*/ X printf("you have magical WARRIOR skills"); X ntn[country].powers=WARRIOR; X exenewmgk(WARRIOR); X points-=18; X break; X default: X printf("\ninvalid race\n "); X valid=0; X } X } X X ntn[country].mark=(*ntn[country].name); X printf("\ntesting first letter of name (%c) for nation mark...",ntn[country].mark); X valid=1; X while(valid==1) { X valid=0; X if((isprint(ntn[country].mark)==0)||(isspace(ntn[country].mark)!=0)) { X printf("\n%c is not a graphical character",ntn[country].mark); X valid=1; X } X if(valid==0) for(i=0;i<=3;i++) if(ntn[country].mark==(*(ele+i))) { X printf("\n%c is an altitude character",ntn[country].mark); X valid=1; X } X if(valid==0) for(i=0;i<=11;i++) if(ntn[country].mark==(*(veg+i))) { X printf("\n%c is a vegitation character,ntn[country].mark"); X valid=1; X } X if(valid==0) for(i=1;i<country;i++) if(ntn[i].mark==ntn[country].mark) { X printf("\n%c is an already used character",ntn[country].mark); X valid=1; X } X if(valid==0) if(ntn[i].mark=='*') { X printf("\n'*' is invalid character"); X valid=1; X } X if(valid==1){ X printf("\nplease reenter new national mark for maps:"); X printf("\n (this can be any printing key like ! or O)"); X scanf("%s",tempc); X ntn[country].mark=(*tempc); X } X else printf("\nvalid\n"); X } X X printf("\nmark currently is %c\n",ntn[country].mark); X X while(points>0) { X printf("\n\nwhat would you like to buy with your remaining %d points\n\n",points); X printf("\t1. population (1000/pt):\t\tnow have %d civilians\n",ntn[country].tciv); X printf("\t2. more gold ($100000/pt):\t\tnow have %d gold pieces\n",ntn[country].tgold); X printf("\t3. better location:\t\t\tlocation is now is %c\n",ntn[country].location); X printf("\t4. more soldiers (1000/pt):\t\tnow have %d soldiers\n",ntn[country].tmil); X printf("\t5. better attack (10%%/pt):\t\tnow is +%d\n ",ntn[country].aplus); X printf("\t6. better defence (10%%/pt):\t\tnow is +%d\n",ntn[country].dplus); X printf("\t7. higher reproduction (1%%/pt):\t\trate is now %d%%\n",ntn[country].repro); X printf("\t8. higher movement (4/pt): \t\tnow move %d sectors\n",ntn[country].maxmove); X printf("\t9. double raw recourses (1 pt): \tfood now %d\n",ntn[country].tfood); X printf("\t \tgold dust now %d\n",ntn[country].jewels); X printf("\t \tiron now %d\n",ntn[country].tiron); X printf("\t10. additional random magic power (1 pt)\n"); X X X printf("\nWhat option to buy:"); X scanf("%d",&n); X switch(n) { X X case 1: X printf("additional population costs 1 pt per 1000\n"); X printf("how many points to spend on population:"); X scanf("%d",&temp); X putchar('\n'); X if(points >= temp) { X points -= temp; X ntn[country].tciv+=temp*1000; X } X else printf("You dont have enough points left"); X break; X case 2: X printf("you now have $%d\n",ntn[country].tgold); X printf("and can buy gold at $100000 per point\n"); X printf("how many points to spend on added gold:"); X scanf("%d",&temp); X putchar('\n'); X if(points>=temp) X { X points-=temp; X ntn[country].tgold+=temp*100000; X } X else printf("You dont have enough points left"); X break; X case 3: X printf("you now are in %c location\n",ntn[country].location); X printf(" R=random, F=fair, G=good\n"); X if(ntn[country].location==RANDOM){ X printf("2pts for (g)ood location or 1pts for (f)air\n"); X } X if(ntn[country].location==FAIR){ X printf("1pts for (g)ood location\n"); X } X if(ntn[country].location==GREAT) return; X X printf("what type of location do you wish:"); X scanf("%s",tempo); X switch(tempo[0]) { X case 'g': X case GREAT: X if(ntn[country].location==FAIR){ X printf("1pts for (g)ood location\n"); X if(points>=1) { X points -=1; X ntn[country].location=GREAT; X } X else printf("You dont have enough points left"); X } X else { X if(points>=2) { X points -=2; X ntn[country].location=GREAT; X } X else printf("You dont have enough points left"); X } X break; X case 'f': X case FAIR: X if(ntn[country].location==RANDOM){ X if(points>=1) { X points -=1; X ntn[country].location=FAIR; X } X else printf("You dont have enough points left"); X } X else printf("\nlocation unchanged\n"); X break; X default: X printf("\nlocation unchanged\n"); X } X putchar('\n'); X break; X case 4: X printf("you start with %d soldiers\n",ntn[country].tmil); X printf("additional military costs 1 / 1000\n"); X printf("how many points you wish:"); X scanf("%d",&temp); X putchar('\n'); X if(points >= temp) { X points -= temp; X ntn[country].tmil+=temp*1000; X } X else printf("You dont have enough points left"); X break; X case 5: X printf("now have %d percent attack bonus\n",ntn[country].aplus); X printf("an additional 10 percent per point\n"); X printf("how many points you wish:"); X scanf("%d",&temp); X putchar('\n'); X if(points >= temp) { X points -= temp; X ntn[country].aplus+=temp*10; X } X else printf("You dont have enough points left"); X break; X case 6: X printf("now have %d percent defence bonus\n",ntn[country].dplus); X printf("an additional 10 percent per point\n"); X printf("how many points you wish:"); X scanf("%d",&temp); X putchar('\n'); X if(points >= temp) { X points -= temp; X ntn[country].dplus+=temp*10; X } X else printf("You dont have enough points left"); X break; X case 7: X printf("repro rate costs 1 per percent\n"); X printf("you now have %d percent\n",ntn[country].repro); X if((ntn[country].race!=ORC)&&(ntn[country].repro>=10)){ X printf("you have the maximum rate"); X break; X } X printf("how many points you wish:"); X scanf("%d",&temp); X putchar('\n'); X if(points >= temp) { X if((ntn[country].race!=ORC)&&(ntn[country].repro+temp>=10)){ X printf("that exceeds the 10% limit"); X } X else { X points -= temp; X ntn[country].repro+=temp; X } X } X else printf("You dont have enough points left"); X break; X case 8: X printf("additional movement costs 1 per +4 sct/turn\n"); X printf("you start with a rate of 6\n"); X printf("you now have a rate of 10\n"); X putchar('\n'); X if(points >= 1) { X points -= 1; X ntn[country].maxmove+=4; X } X else printf("You dont have enough points left"); X break; X case 9: X printf("doubling raw materials\n"); X if(points >0) { X points--; X ntn[country].tfood*=2; X ntn[country].jewels*=2; X ntn[country].tiron*=2; X X } X break; X case 10: X printf("choosing basic magic at 1 point cost\n"); X if(points >0) { X points--; X loop=0; X while(loop==0) if((x=getmagic())>1){ X exenewmgk(x); X loop=1; X } X } X else printf("sorry not enough points\n"); X break; X default: X printf("invalid option\n"); X } X } X X printnat(); X printf("\nhit 'y' if OK?"); X getchar(); X if(getchar()!='y'){ X ntn[i].active=0; X getchar(); X printf("\n OK, nation deleted\n"); X printf("\nhit return to add another nation"); X printf("\nhit any other key to continue?"); X if(getchar()=='\n') more=0; X else more=1; X putchar('\n'); X } X else { X place(); X getchar(); X printf("\nNation is now added to world"); X printf("\nhit return to add another nation"); X printf("\nhit any other key to continue?"); X if(getchar()=='\n') more=0; X else more=1; X putchar('\n'); X } X } X writedata(); X} X Xprintnat() X{ X int i; X i=country; X printf("am about to print stats for nation %d\n\n",i); X printf("name is %8s\n",ntn[i].name); X printf("leader is %8s\n",ntn[i].leader); X printf("total sctrs :%2d\n",ntn[i].tsctrs); X printf("class is %8s\n",*(Class+ntn[i].class)); X printf("mark is %c \n",ntn[i].mark); X printf("race is %c \n",ntn[i].race); X printf("aplus is +%2d\n",ntn[i].aplus); X printf("dplus is +%2d\n",ntn[i].dplus); X printf("total gold is %5d\n",ntn[i].tgold); X printf("maxmove is %2d sctrs\n",ntn[i].maxmove); X printf("jewels is %2d\n",ntn[i].jewels); X printf("total military is %5d\n",ntn[i].tmil); X printf("total civilians is %5d\n",ntn[i].tciv); X printf("repro is %2d percent\n",ntn[i].repro); X printf("total iron :%5d\n",ntn[i].tiron); X printf("total food :%5d\n",ntn[i].tfood); X printf("total ships :%2d\n",ntn[i].tships); X} X X/*PLACE NATION*/ Xplace() X{ X int placed=0; X int t; X int temp; X int n; /*count vbl for inf loop*/ X short armynum=0; X register i,j,x,y; X X n=0; X updmove(ntn[country].race); X switch(ntn[country].location) { X case OOPS: X while ((placed == 0)&&(n++<800)){ X placed=1; X if(ntn[country].active==1){ X x = (rand()%(MAPX-8))+4; X y = (rand()%(MAPY-8))+4; X } X else { X x = (rand()%(MAPX-2))+1; X y = (rand()%(MAPY-2))+1; X } X X for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++) X if(sct[x][y].owner!=0) placed=0; X X if((movecost[x][y]<=0)||(movecost[x][y]>5)) placed=0; X } X break; X case RANDOM: X while ((placed == 0)&&(n<2000)){ X placed=1; X if(ntn[country].active==1){ X#if (MAPX>12) X x = rand()%(MAPX-12)+6; X y = rand()%(MAPY-12)+6; X#else X x = rand()%(MAPX-8)+4; X y = rand()%(MAPY-8)+4; X#endif X /*important that no countries near*/ X for(i=x-4;i<=x+4;i++) for(j=y-4;j<=y+4;j++) X if((sct[i][j].owner<MAXNTN)&&(sct[i][j].owner!=0)) placed=0; X } X else { X x = (rand()%(MAPX-6))+3; X y = (rand()%(MAPY-6))+3; X /*important that no countries near*/ X for(i=x-2;i<=x+2;i++) for(j=y-2;j<=y+2;j++) X if((sct[i][j].owner<MAXNTN)&&(sct[i][j].owner!=0)) placed=0; X } X for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++) X if(sct[x][y].owner!=0) placed=0; X if((movecost[x][y]<=0)||(movecost[x][y]>4)) placed=0; X n++; X } X if (placed==1) for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++) X if(sct[i][j].altitude!=WATER) sct[i][j].vegitation=GOOD; X break; X case FAIR: X while ((placed == 0)&&(n<500)) { X if(ntn[country].active==1){ X#if (MAPX>24) X x = rand()%(MAPX-24)+12; X y = rand()%(MAPY-24)+12; X#else X x = rand()%(MAPX-14)+7; X y = rand()%(MAPY-14)+7; X#endif X } X else { X x = rand()%(MAPX-10)+5; X y = rand()%(MAPY-10)+5; X } X X for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++) X if(sct[x][y].owner!=0) placed=0; X X n++; X placed=1; X if((movecost[x][y]>0)&&(movecost[x][y]<=4)){ X#if(PWATER>50) X for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++) X if(sct[i][j].altitude==WATER) placed=0; X /*important that no countries near*/ X for(i=x-3;i<=x+3;i++) for(j=y-3;j<=y+3;j++){ X if((sct[i][j].owner<MAXNTN)&&(sct[i][j].owner!=0)) placed=0; X } X#else X for(i=x-1;i<=x;i++) for(j=y-1;j<=y;j++) X if(sct[i][j].altitude==WATER) placed=0; X /*important that no countries near*/ X for(i=x-2;i<=x+2;i++) for(j=y-2;j<=y+2;j++){ X if((sct[i][j].owner<MAXNTN)&&(sct[i][j].owner!=0)) placed=0; X } X#endif X } X else placed=0; X } X if (placed==1) for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++) X if(sct[i][j].altitude!=WATER) sct[i][j].vegitation=GOOD; X break; X case GREAT: X placed = 0; X while ((placed == 0) && (n<1500)){ X placed=1; X if(ntn[country].active==1){ X#if (MAPX>40) X x = rand()%(MAPX-40)+20; X y = rand()%(MAPY-40)+20; X#else X x = rand()%(MAPX-18)+9; X y = rand()%(MAPY-18)+9; X#endif X X /*important that no countries near*/ X for(i=x-4;i<=x+4;i++) for(j=y-4;j<=y+4;j++){ X if((sct[i][j].owner<MAXNTN)&&(sct[i][j].owner!=0)) placed=0; X } X } X else { X#if (MAPX>24) X x = rand()%(MAPX-24)+12; X y = rand()%(MAPY-24)+12; X#else X x = rand()%(MAPX-12)+6; X y = rand()%(MAPY-12)+6; X#endif X for(i=x-2;i<=x+2;i++) for(j=y-2;j<=y+2;j++){ X if((sct[i][j].owner<MAXNTN)&&(sct[i][j].owner!=0)) placed=0; X } X } X X for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++) X if(sct[x][y].owner!=0) placed=0; X X n++; /*variable to prevent infinite loop*/ X if((movecost[x][y]>0)&&(movecost[x][y]<4)){ X#if(PWATER>50) X /*if any water within 2 sectors placed = 0*/ X for(i=x-2;i<=x+2;i++) for(j=y-2;j<=y+2;j++) X if(movecost[x][y]<0) placed=0; X#else X for(i=x-2;i<=x+1;i++) for(j=y-2;j<=y+1;j++) X if(movecost[x][y]<0) placed=0; X#endif X X if (placed==1) switch(ntn[country].race) { X case DWARF: X sct[x][y].altitude=MOUNTAIN; X sct[x][y].designation=MOUNTAIN; X for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++) if((i!=x)&&(j!=y)&&(sct[i][j].altitude!=WATER)){ X if (rand()%3==0) { X sct[i][j].altitude=MOUNTAIN; X sct[i][j].designation=MOUNTAIN; X sct[i][j].gold=rand()%6; X sct[i][j].iron=rand()%6; X } X else { X sct[i][j].altitude=HILL; X sct[i][j].designation=HILL; X sct[i][j].iron=rand()%4; X sct[i][j].gold=rand()%4; X } X } X break; X case ELF: X sct[x][y].vegitation = FORREST; X for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++) if((i!=x)&&(j!=y)&&(sct[i][j].altitude!=WATER)) { X if (rand()%3==0) X sct[i][j].vegitation=FORREST; X else sct[i][j].vegitation=WOOD; X X if (rand()%2==0) X sct[i][j].gold=rand()%8; X else sct[i][j].gold=rand()%4; X } X break; X case ORC: X sct[x][y].altitude=MOUNTAIN; X for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++) if((i!=x)&&(j!=y)&&(sct[i][j].altitude!=WATER)) { X if (rand()%3==0) { X sct[i][j].altitude=MOUNTAIN; X sct[i][j].designation=MOUNTAIN; X } X else { X sct[i][j].altitude=HILL; X sct[i][j].designation=HILL; X } X if (rand()%2==0){ X sct[i][j].iron=rand()%8; X sct[i][j].gold=rand()%8; X } X else { X sct[i][j].iron=rand()%4; X sct[i][j].gold=rand()%4; X } X } X break; X case HUMAN: X sct[x][y].altitude = CLEAR; X for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++) if((i!=x)&&(j!=y)&&(sct[i][j].altitude!=WATER)) { X if (rand()%2==0) X sct[x][y].altitude = CLEAR; X X if (rand()%2==0) X sct[i][j].vegitation=WOOD; X else X sct[i][j].vegitation=GOOD; X X if (rand()%2==0) X sct[i][j].gold=rand()%7+1; X else X sct[i][j].iron=rand()%7+1; X } X break; X } X } X else placed=0; X } X } X X /*done with one try*/ X if(placed==1) { X ntn[country].capx = x; X ntn[country].capy = y; X sct[x][y].designation=DCAPITOL; X sct[x][y].owner=country; X sct[x][y].people=ntn[country].tciv; X sct[x][y].fortress=5; X X /* put all military into armies of 100 */ X armynum=0; X temp=ntn[country].tmil; X ASOLD=ntn[country].tmil/3; X temp-=ASOLD; X ASTAT=GARRISON; X AMOVE=0; X AXLOC=ntn[country].capx; X AYLOC=ntn[country].capy; X while((armynum<MAXARM)&&(temp>0)) { X armynum++; X if(temp>100){ X ASOLD=100; X temp-=100; X } X else { X ASOLD=temp; X temp=0; X } X AXLOC=ntn[country].capx; X AYLOC=ntn[country].capy; X ASTAT=DEFEND; X AMOVE=ntn[country].maxmove; X } X if(temp>0) { X armynum=0; X ASOLD+=temp; X } X X /* give you some terain to start with: pc nations get more*/ X if ((ntn[country].active>=2)&&(ntn[country].location==GREAT)) X t=1; X else if (ntn[country].active>=2) t=0; X else if (ntn[country].location==OOPS) t=0; X else if (ntn[country].location==RANDOM) t=0; X else if (ntn[country].location==FAIR) t=1; X else if (ntn[country].location==GREAT) t=2; X else printf("error"); X X for(i=x-t;i<=x+t;i++) for(j=y-t;j<=y+t;j++) X if((movecost[i][j]>=0)&&(sct[i][j].owner==0)&&(sct[i][j].people==0)) { X sct[i][j].owner=country; X sct[i][j].designation=DFARM; X } X } X else { X if(ntn[country].location==OOPS) printf("ERROR\n"); X else if(ntn[country].location==RANDOM) { X printf("RANDOM PLACE FAILED, TRYING TO PLACE AGAIN\n"); X ntn[country].location=OOPS; X place(); X } X else if(ntn[country].location==FAIR) { X printf("FAIR PLACE FAILED, TRYING TO PLACE AGAIN\n"); X ntn[country].location=RANDOM; X place(); X } X else if(ntn[country].location==GREAT) { X printf("GOOD PLACE FAILED, TRYING TO PLACE AGAIN\n"); X ntn[country].location=FAIR; X place(); X } X } X} X X/*get class routine*/ Xgetclass(race) X{ X short check=0; X short tmp; X while(check==0){ X printf("what type of nation would you like to be\n"); X printf("1. king (Humans, Dwarves, and Elves)\n"); X printf("2. emperor (Humans, Dwarves, and Elves)\n"); X printf("3. wizard (Humans, Dwarves, and Elves)\n"); X printf("4. theocracy (Humans Only)\n"); X printf("5. pirate (Humans & Orcs Only)\n"); X printf("6. trader (Elves & Dwarves Only)\n"); X printf("7. tyrant (Humans & Orcs Only)\n"); X printf("8. demon (Orcs Only)\n"); X printf("9. dragon (Orcs Only)\n"); X printf("10. shadow (Orcs Only)\n\n"); X printf("\tinput:"); X scanf("%hd",&tmp); X if((tmp>=1)&&(tmp<=10)) { X if((race==HUMAN)&&((tmp<6)||(tmp==7))) check=1; X else if((race==DWARF)&&((tmp<=3)||(tmp==6))) check=1; X else if((race==ELF)&&((tmp==6)||(tmp<=3))) check=1; X else if((race==ORC)&&((tmp==5)||(tmp>6))) check=1; X else printf("bad input \n\n\n"); X } X else printf("\tinvalid input\n\n\n"); X } X ntn[country].class=tmp; X} END_OF_newlogin.c if test 22711 -ne `wc -c <newlogin.c`; then echo shar: \"newlogin.c\" unpacked with wrong size! fi # end of overwriting check fi echo shar: End of archive 2 \(of 5\). cp /dev/null ark2isdone MISSING="" for I in 1 2 3 4 5 ; do if test ! -f ark${I}isdone ; then MISSING="${MISSING} ${I}" fi done if test "${MISSING}" = "" ; then echo You have unpacked all 5 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