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