From mipos3!intelca!oliveb!ames!ll-xn!mit-eddie!uw-beaver!tektronix!tekgen!tekred!games-request Tue Oct 27 19:24:20 PST 1987 Article 6 of net.sources.games: Path: td2cad!mipos3!intelca!oliveb!ames!ll-xn!mit-eddie!uw-beaver!tektronix!tekgen!tekred!games-request From: games-request@tekred.TEK.COM Newsgroups: net.sources.games Subject: v02i060: conquest - middle earth multi-player game, Part03/05 Message-ID: <1743@tekred.TEK.COM> Date: 26 Oct 87 19:03:20 GMT Sender: billr@tekred.TEK.COM Lines: 2139 Approved: billr@tekred.TEK.COM Submitted by: ihnp4!mhuxd!smile (E.BARLOW) Comp.sources.games: Volume 2, Issue 60 Archive-name: conquest/Part03 #! /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 commands.c <<'END_OF_commands.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/* commands.c */ X X/*include files*/ X#include "header.h" X#include X Xextern short xcurs,ycurs,xoffset,yoffset; Xextern FILE *fexe; /*execute file pointer*/ Xextern short country; X X/*change current hex designation*/ Xredesignate() X{ X char newdes; X short x,y; X X if(country==0){ X mvaddstr(LINES-1,0,"SUPER USER: CHANGE (v)egitation, (e)levation, (d)esig, (o)wner"); X refresh(); X switch(getch()){ X case 'e': X /*simple contour map definitions*/ X mvprintw(LINES-2,7,"ELEVATIONS: change to %c, %c, %c, %c or %c?",WATER,PEAK,MOUNTAIN,HILL,CLEAR); X refresh(); X newdes=getch(); X if(newdes!=WATER&&newdes!=PEAK&&newdes!=MOUNTAIN&&newdes!=HILL&&newdes!=CLEAR) return; X sct[XREAL][YREAL].altitude=newdes; X /*will fall through as must change vegitation*/ X case 'v': X /*vegitation types*/ X mvprintw(LINES-2,7,"VEGITATIONS: change to %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c or %c?",VOLCANO,DESERT,WASTE,BARREN,LT_VEG,GOOD,WOOD,FORREST,JUNGLE,SWAMP,ICE,NONE); X refresh(); X newdes=getch(); X if(newdes!=VOLCANO&&newdes!=DESERT&&newdes!=WASTE&&newdes!=BARREN&&newdes!=LT_VEG&&newdes!=NONE&&newdes!=GOOD&&newdes!=WOOD&&newdes!=FORREST&&newdes!=JUNGLE&&newdes!=SWAMP&&newdes!=ICE) return; X sct[XREAL][YREAL].vegitation=newdes; X if(isdigit(sct[XREAL][YREAL].vegitation)==0) X sct[XREAL][YREAL].designation=newdes; X return; X case 'o': X mvprintw(LINES-2,7,"what nation owner:"); X refresh(); X scanw("%hd",&x); X sct[XREAL][YREAL].owner=x; X return; X } X } X if((country!=0)&&(sct[XREAL][YREAL].owner!=country)) { X mvprintw(LINES-1,0,"You do not own: hit any key"); X refresh(); X getch(); X return; X } X mvprintw(LINES-1,0,"hit space to not redesignate anyting"); X clrtoeol(); X mvprintw(LINES-2,7,"$%d: redesignate to %c, %c, %c, %c or %c?",DESCOST,DMINE,DGOLDMINE,DFARM,DCITY,DCAPITOL); X clrtoeol(); X refresh(); X /*read answer*/ X newdes=getch(); X X if(newdes!=DMINE&&newdes!=DGOLDMINE&&newdes!=DFARM&&newdes!=DCITY&&newdes!=DCAPITOL) return; X X if((SOWN==country)||(country==0)) { X if((isdigit(sct[XREAL][YREAL].vegitation)!=0)||(country==0)) { X if(((newdes!=DCITY)&&(newdes!=DCAPITOL))||(country==0)) { X /*decrement treasury*/ X sct[XREAL][YREAL].designation=newdes; X if(country==0) { X country=sct[XREAL][YREAL].owner; X SADJDES; X country=0; X } X else { X SADJDES; X ntn[country].tgold-=DESCOST; X } X } X else if((newdes==DCAPITOL)&&(sct[XREAL][YREAL].designation==DCITY)){ X X ntn[country].tgold-=5*DESCOST; X ntn[country].tiron-=DESCOST; X x=ntn[country].capx; X y=ntn[country].capy; X sct[x][y].designation=DCITY; X if(country==0) { X country=sct[x][y].owner; X SADJDES2; X country=0; X } X else SADJDES2; X sct[XREAL][YREAL].designation=newdes; X ntn[country].capx=XREAL; X ntn[country].capy=YREAL; X if(country==0) { X country=sct[XREAL][YREAL].owner; X SADJDES; X country=0; X } X else SADJDES; X } X else if((newdes==DCAPITOL)&&(sct[XREAL][YREAL].designation!=DCITY)){ X mvprintw(LINES-1,0,"Sector must be a city: hit any key "); X } X else if((ntn[country].tiron>DESCOST)&&(newdes==DCITY)){ X if(sct[XREAL][YREAL].people>=500){ X ntn[country].tgold-=5*DESCOST; X ntn[country].tiron-=DESCOST; X sct[XREAL][YREAL].designation=newdes; X if(country==0) { X country=sct[XREAL][YREAL].owner; X SADJDES; X country=0; X } X else SADJDES; X } X else mvprintw(LINES-1,0,"Need 500 people to build to city"); X } X else mvprintw(LINES-1,0,"Not enough iron: hit any key "); X } X else mvprintw(LINES-1,0,"vegitation unlivable: hit any key "); X } X else mvprintw(LINES-1,0,"Sorry, you don't own sector: hit any key "); X refresh(); X} X X/*build fort or ship-type */ Xconstruct() X{ X int nearsea; X int cost; X int x,y; X short nvynum=0; X short mnumber,wnumber; X short isgod=0; X char type; X X if(country==0){ X isgod=1; X country=sct[XREAL][YREAL].owner; X } X X if(sct[XREAL][YREAL].owner!=country) { X mvprintw(LINES-1,0,"You do not own: hit any key"); X refresh(); X getch(); X if(isgod==1) country=0; X return; X } X X if((sct[XREAL][YREAL].designation==DCITY)||(sct[XREAL][YREAL].designation==DCAPITOL)) { X /*calculate cost for fort*/ X cost=FORTCOST; X if(isgod==1) cost=0; X else for(x=1;x<=sct[XREAL][YREAL].fortress;x++) X cost*=2; X X mvprintw(LINES-2,0,"Do you wish to construct a ort (%d gold) or hips:",cost); X clrtoeol(); X refresh(); X type=getch(); X } X else { X mvprintw(LINES-2,0,"Must construct in city or capitol--hit any key"); X clrtoeol(); X refresh(); X getch(); X return; X } X X /* construct ships*/ X if (type=='s') { X /*check if next to sea*/ X nearsea=0; X for(x=XREAL-1;x<=XREAL+1;x++) X for(y=YREAL-1;y<=YREAL+1;y++) X if(sct[x][y].altitude==WATER) nearsea=1; X X if (nearsea==0) { X mvprintw(LINES-2,0,"not in a harbor: hit space"); X clrtoeol(); X refresh(); X getch(); X if(isgod==1) country=0; X return; X } X X mvprintw(LINES-2,0,"build how many merchant ships:"); X clrtoeol(); X refresh(); X echo(); X scanw("%hd",&mnumber); X noecho(); X mvprintw(LINES-2,0,"build how many warships:"); X clrtoeol(); X refresh(); X echo(); X scanw("%hd",&wnumber); X noecho(); X /*sanity checks*/ X if((wnumber>100)||(wnumber<0)) wnumber=0; X if((mnumber>100)||(mnumber<0)) mnumber=0; X mvprintw(LINES-2,0,"constructing %hd warships and %hd merchant",wnumber,mnumber); X clrtoeol(); X X if((nvynum=getselunit()-MAXARM)>=0){ X if(nvynum>=MAXNAVY){ X mvaddstr(LINES-1,0,"INVALID NAVY--hit any key"); X clrtoeol(); X refresh(); X getch(); X if(isgod==1) country=0; X return; X } X mvaddstr(LINES-1,0,"Do you wish to raise a new fleet (y or n)"); X clrtoeol(); X refresh(); X if(getch()!='y') nvynum=(-1); X } X X if(nvynum<0) { X mvprintw(LINES-2,0,"raising a new fleet"); X clrtoeol(); X refresh(); X X nvynum=0; X x=(-1); X while((x==(-1))&&(nvynum=0)&&(nvynum=500) { X X mvprintw(LINES-1,25,"you build one fort point for %d gold",cost); X ntn[country].tgold-=cost; X sct[XREAL][YREAL].fortress++; X INCFORT; X } X else mvprintw(LINES-1,25,"need 500 people"); X } X else mvprintw(LINES-1,0,"error"); X X if(isgod==1) country=0; X refresh(); X} X X/*DRAFT IF IN A CITY*/ Xdraft() X{ X short armynum; X short men=0; X short army=(-1); X short isgod=0; X if(country==0) { X isgod=1; X country=sct[XREAL][YREAL].owner; X } X else if(sct[XREAL][YREAL].owner!=country) { X mvprintw(LINES-1,0,"You do not own: hit any key"); X refresh(); X getch(); X return; X } X X if((sct[XREAL][YREAL].designation!=DCITY)&&(sct[XREAL][YREAL].designation!=DCAPITOL)) { X mvprintw(LINES-1,0,"must raise in cities: hit any key"); X refresh(); X getch(); X if(isgod==1) country=0; X return; X } X X if((sct[XREAL][YREAL].designation==DCITY)&&(sct[XREAL][YREAL].people*(2*CITYLIMIT+(ntn[country].tsctrs/2)) sct[XREAL][YREAL].people/4) { X mvprintw(LINES-2,0,"can only raise %d soldiers",sct[XREAL][YREAL].people/4); X clrtoeol(); X refresh(); X men = sct[XREAL][YREAL].people/4; X } X if(men > (short) 10*ntn[country].tiron) { X mvprintw(LINES-2,0,"aborting--only enough iron for %d troops",ntn[country].tiron/10); X clrtoeol(); X refresh(); X getch(); X if(isgod==1) country=0; X return; X } X else { X move(LINES-2,0); X clrtoeol(); X ntn[country].tiron-= (int) 10*men; X } X X /*count is order of that army in sector*/ X /*armynum is number of that army*/ X if((armynum=getselunit())>=0){ X if(armynum>=MAXARM){ X mvaddstr(LINES-1,0,"INVALID ARMY--hit any key"); X clrtoeol(); X refresh(); X getch(); X if(isgod==1) country=0; X return; X } X mvaddstr(LINES-1,0,"Do you wish to raise a new army"); X clrtoeol(); X refresh(); X if(getch()!='y') army=armynum; X else army=(-1); X } X if(army==(-1)) { X mvprintw(LINES-2,0,"raising a new army"); X clrtoeol(); X refresh(); X armynum=0; X while((army==(-1))&&(armynumMAXARM)) { X beep(); X mvprintw(LINES-1,0,"Sorry you have an Invalid army number (%d)",armynum); X refresh(); X getch(); X return; X } X clear(); X mvprintw(0,10,"ADJUST ARMY %d OF NATION %s",armynum,ntn[country].name); X mvaddstr(2,10,"1. March "); X mvaddstr(3,10,"2. Scouting--will not engage enemy if possible"); X mvaddstr(4,10,"3. Attack anybody (Hostile+) within 2 sectors"); X mvaddstr(5,10,"4. Defend "); X mvaddstr(6,10,"5. Garrison--for a city or Capital"); X mvaddstr(12,10,"Enter your choice (return to continue):"); X refresh(); X echo(); X scanw("%hd",&status); X noecho(); X if((status<1)||(status>5)) return; X if((status==SCOUT)&&(ASOLD>25)){ X clear(); X mvaddstr(12,(COLS/2)-6,"MUST HAVE < 25 MEN TO SCOUT"); X mvaddstr(13,(COLS/2)-12,"HIT ANY KEY TO CONTINUE"); X refresh(); X getch(); X return; X } X ASTAT=status; X AADJSTAT; X} X X/*go through MSGFILE not rewriting to temp messages you discard*/ X/* then move temp to MSGFILE*/ Xrmessage() X{ X FILE *mesgfp; X FILE *fptemp; X int i; X int count; X int contd; X int done=0; X char line[80]; X char save[20][80]; X X clear(); X /*open file*/ X strcpy(line,MSGFILE); X strcat(line,":temp"); X fptemp=fopen(line,"w"); X if ((mesgfp=fopen(MSGFILE,"r"))==NULL) { X mvprintw(0,0,"error on read of %s--hit return",MSGFILE); X refresh(); X getch(); X return; X } X X /*read in file a line at at time*/ X if(fgets(line,80,mesgfp)==NULL) done=1; X while(done==0) { X contd=0; X count=3; X if(strncmp(line,ntn[country].name,strlen(ntn[country].name))==0) { X clear(); X standout(); X /*print to end of message*/ X while(contd==0) { X if(count<22) strcpy(save[count-3],line); X mvprintw(count,0,"%s",line); X standend(); X for(i=0;i0) x--; X mvaddch(y,x,' '); X move(y,x); X line[x]=' '; X refresh(); X ch=getch(); X } X else if(ch=='\n') linedone=1; X else{ X /*concatonate to end*/ X line[x]=ch; X mvaddch(y,x,ch); X if(x<99) x++; X else linedone=1; X refresh(); X ch=getch(); X } X } X line[x]='\0'; X if(x<=1) done=1; X /*write to file*/ X fprintf(fp,"%s %s\n",name,line); X x=0; X y++; X } X fputs("END\n",fp); X mvprintw(20,0,"Done with messaging"); X fclose(fp); X} X X/*strategic move of civilians...once only*/ Xmoveciv() X{ X short people; X short i,j; X X mvaddstr(LINES-1,0,"Moving civilians costs 50 per civilian"); X if(sct[XREAL][YREAL].owner!=country){ X mvprintw(LINES-2,0,"you do not own: hit return"); X clrtoeol(); X refresh(); X getch(); X return; X } X else if(sct[XREAL][YREAL].people==0){ X mvaddstr(LINES-2,0,"nobody lives here!!!: hit return"); X clrtoeol(); X refresh(); X getch(); X makebottom(); X return; X } X X clear(); X mvprintw(0,0,"sector contains %d people",sct[XREAL][YREAL].people); X mvaddstr(1,0,"how many people to move?"); X clrtoeol(); X refresh(); X echo(); X scanw("%hd",&people); X noecho(); X if((people<0)||(people>sct[XREAL][YREAL].people)||(people*50>ntn[country].tgold)){ X mvaddstr(4,0,"wrong oh great moosebreath..."); X clrtoeol(); X refresh(); X getch(); X makebottom(); X return; X } X X mvprintw(4,0,"sector location is x=%d, y=%d",XREAL,YREAL); X mvaddstr(6,0,"what x location to move to?"); X refresh(); X echo(); X scanw("%hd",&i); X refresh(); X noecho(); X X if((i-(XREAL))>2||(i-(XREAL))<-2) { X mvprintw(9,0,"can only move 2 sectors (you tried %hd)...--hit any key",i-(XREAL)); X refresh(); X getch(); X return; X } X X mvaddstr(9,0,"what y location to move to?"); X clrtoeol(); X refresh(); X echo(); X scanw("%hd",&j); X noecho(); X if((j-(YREAL)>2)||((YREAL)-j>2)) { X mvprintw(9,0,"can only move 2 sectors (you tried %hd)...--hit any key",j-(XREAL)); X refresh(); X getch(); X return; X } X if(sct[XREAL][YREAL].owner!=country){ X mvaddstr(11,0,"you dont own it..."); X clrtoeol(); X refresh(); X getch(); X return; X } X ntn[country].tgold-=50*people; X sct[XREAL][YREAL].people-=people; X SADJCIV; X sct[i][j].people+=people; X SADJCIV2; X} END_OF_commands.c if test 16412 -ne `wc -c main.c <<'END_OF_main.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/*include files*/ X#include X#include "header.h" X X/*initialization data*/ X/*Movement costs*/ Xchar *ele= "#^%-~"; Xchar *elename[]= { "PEAK", "MOUNTAIN", "HILL", "FLAT","WATER"}; Xchar *veg= "VDW46973JSI~"; Xchar *vegname[]= { "VOLCANO", "DESERT", "WASTE", "BARREN(4)", "LT VEG(6)", X"GOOD (9)", "WOOD (7)", "FOREST(3)", "JUNGLE", "SWAMP", "ICE", "NONE"}; Xchar *numbers= "0123456789"; Xchar *Class[]= { "NPC", "king", "emperor", "wizard", "priest", "pirate", X"trader", "tyrant", "demon", "dragon", "shadow"}; Xchar *races[]= { "GOD","ORC","ELF","DWARF","LIZARD", X"HUMAN","PIRATE","BARBARIAN","NOMAD","UNKNOWN"}; Xchar *diploname[]= { "UNMET", "CONFEDERACY", "ALLIED", "FRIENDLY", X"NEUTRAL", "HOSTILE", "WAR", "JIHAD"}; Xchar *soldname[]= { "","MARCH","SCOUT","ATTACK","DEFEND","GARRISON"}; Xchar *des= "cCmfx$!-"; Xchar *desname[]= {"CITY", "CAPITOL", "MINE", "FARM", "DEVASTATED", "GOLDMINE", X"CASTLE", "NODESIG", "PEAK", "WATER"}; X X/*Declarations*/ Xstruct s_sector sct[MAPX][MAPY]; Xstruct nation ntn[NTOTAL]; /* player nation stats */ X X/*is sector occupied by an army?*/ Xshort occ[MAPX][MAPY]; Xshort movecost[MAPX][MAPY]; Xextern int armornvy; Xint startgold=0; X X/*offset of upper left hand corner*/ Xshort xoffset=0,yoffset=0; X/*current cursor postion (relative to 00 in upper corner)*/ X/* position is 2*x,y*/ Xshort xcurs=0,ycurs=0; X/*redraw map in this turn if redraw is a 1*/ Xshort redraw=TRUE; X/*1 if you have quit*/ Xint done=0; X/*display state*/ Xshort hilmode=0; /*highlight modes: 0=owned sectors, 1= armies, 2=none*/ Xshort dismode=2; /*display mode: 1=vegitation, 2=desig, 3=contour*/ X/* 4=armies/navies, 5=commodities, 6=fertility*/ Xshort selector=0; /*selector (y vbl) for which army/navy... is "picked"*/ X/* nation id of owner*/ Xshort country=0; X XFILE *fexe, *fopen(); X Xmain(argc,argv) Xint argc; Xchar **argv; X{ X register int i; X char name[20]; X void srand(); X int getopt(); X char passwd[20]; X long time(); X X srand((unsigned) time((long *) 0)); X /* process the command line arguments */ X while((i=getopt(argc,argv,"maxph"))!=EOF) switch(i){ X case 'm': /*make a new world*/ X makeworld(); X exit(1); X case 'a': /*anyone with password can add player*/ X readdata(); X if(strncmp(crypt(getpass("\nwhat is super user password:"),SALT),ntn[0].passwd,PASSLTH)!=0) { X printf("sorry, must be super user to add player\n"); X exit(1); X } X newlogin(); X exit(1); X case 'x': /* execute program*/ X readdata(); X update(); X writedata(); X exit(1); X case 'p': /*print the map*/ X readdata(); X if(strncmp(crypt(getpass("\nwhat is super user password:"),SALT),ntn[0].passwd,PASSLTH)!=0) { X printf("sorry, must be super user to get map\n"); X exit(1); X } X printf("what type of map\noptions are\n"); X printf("\t1) altitudes\n\t2) vegitations\n"); X printf("\t3) nations\n\n"); X printf("\tINPUT:"); X scanf("%hd",&dismode); X if(dismode==1) printele(); X else if(dismode==2) printveg(); X else pr_ntns(); X exit(1); X case 'h': /* execute help program*/ X initscr(); X savetty(); X noecho(); X raw(); X help(); X endwin(); X putchar('\n'); X exit(1); X case '?': /* print out command line arguments */ X printf("Cmd line format: conquest [-maxdhp]\n\t-m make a world\n\t-a add new player\n\t-x execute program\n\t-h print help text\n\t-p print a map\n "); X exit(1); X }; X X /* read data*/ X readdata(); X armornvy=AORN; X X /* identify the player and the country he represents */ X X /* get nation name either from command line or by asking X * if you fail will give you the name of administrator of game X */ X X /* verify existence of nation*/ X printf("conquest: copyrighted by Ed Barlow (1986)\n"); X printf("what nation would you like to be:"); X scanf("%s",name); X if(strcmp(name,"god")==0) strcpy(name,"unowned"); X country=(-1); X for(i=0;i"); X printf("\nfor more information please contact %s\n",OWNER); X return; X } X X /*get encrypted password*/ X strcpy(passwd,crypt(getpass("\nwhat is your password:"),SALT)); X if((strncmp(passwd,ntn[country].passwd,PASSLTH)!=0)&&(strncmp(passwd,ntn[0].passwd,PASSLTH)!=0)) { X strcpy(passwd,crypt(getpass("\nerror: reenter your password:"),SALT)); X if((strncmp(passwd,ntn[country].passwd,PASSLTH)!=0)&&(strncmp(passwd,ntn[0].passwd,PASSLTH)!=0)) { X printf("\nsorry:"); X printf("\nfor rules type "); X printf("\nfor more information on the system please contact %s\n",OWNER); X exit(1); X } X } X X /* check if user is super-user nation[0] */ X /* else setup cursor to capitol*/ X if(country==0) { X printf("welcome super user\n"); X xcurs=1; X xoffset=0; X ycurs=1; X yoffset=0; X } X else { X printf("\nverifing that nation %s exists\n",ntn[country].name); X startgold = ntn[country].tgold; X execute(); X if(ntn[country].capx>15) { X xcurs=15; X xoffset= (ntn[country].capx-15); X } X else { X xcurs= ntn[country].capx; X xoffset= 0; X } X if(ntn[country].capy>10) { X ycurs=10; X yoffset= (ntn[country].capy-10); X } X else { X yoffset= 0; X ycurs= ntn[country].capy; X } X } X X updmove(ntn[country].race); X X /* open output for future printing*/ X if ((fexe=fopen(EXEFILE,"a"))==NULL) { X beep(); X printf("error opening %s\n",EXEFILE); X exit(1); X } X X /* SET UP THE SCREEN */ X printf("about to set up the screen"); X initscr(); X savetty(); X raw(); X X prep(); X noecho(); X X /*main while routine*/ X done=0; X while (done==0) X { X /* check if cursor is out of bounds*/ X if((xcurs<1)||(ycurs<1)||(xcurs>=(COLS-21)/2)||((ycurs>=LINES-5))||((XREAL)>=MAPX)||((YREAL)>=MAPY)) offmap(); X X /*update map*/ X if(redraw==TRUE) { X clear(); X makemap(); /* update map*/ X makebottom(); X redraw=FALSE; X } X move(ycurs,2*xcurs); X makeside(); /*update side*/ X move(ycurs,2*xcurs); X refresh(); X /*get commands, make moves and input command*/ X parse(); X } X X if(country==0) writedata(); X else { X fprintf(fexe,"NGOLD\t%d \t%d \t%d \t0 \t0 \t%s\n",XNAGOLD ,country,ntn[country].tgold,"null"); X fprintf(fexe,"NIRON\t%d \t%d \t%d \t0 \t0 \t%s\n",XNAIRON ,country,ntn[country].tiron,"null"); X fprintf(fexe,"NRGOLD\t%d \t%d \t%d \t0 \t0 \t%s\n",XNARGOLD ,country,ntn[country].jewels,"null"); X } X /*done so quit*/ X clear(); X printw("quitting\n"); X refresh(); X noraw(); X resetty(); X endwin(); X fclose(fexe); X exit(1); X} X X/*make the bottom of the screen*/ Xmakebottom() X{ X move(LINES-4,0); X clrtoeol(); X mvprintw(LINES-3,0,"Conquest version %d",VERSION); X clrtoeol(); X mvaddstr(LINES-1,0," type ? for help"); X clrtoeol(); X mvaddstr(LINES-2,0," type Q to quit"); X clrtoeol(); X if(country==0) mvaddstr(LINES-3,COLS-20,"nation..GOD "); X else { X mvprintw(LINES-3,COLS-20,"nation...%s",ntn[country].name); X mvprintw(LINES-2,COLS-20,"treasury.%d",ntn[country].tgold); X mvprintw(LINES-1,COLS-20,"score....%d",ntn[country].score); X } X} X X/* parse */ Xparse() X{ X register int i; X char name[20]; X char passwd[12]; X int ocountry; X X switch(getch()) { X case ' ': /*redraw the screen*/ X redraw=TRUE; X break; X case 'a': /*army report*/ X redraw=TRUE; X armyrpt(); X break; X case 'A': /*adjust army*/ X redraw=TRUE; X adjarm(); X break; X case 'b': /*move south west*/ X xcurs--; X ycurs++; X break; X case 'B': /*budget*/ X redraw=TRUE; X budget(); X break; X case 'c': /*change nation stats*/ X redraw=TRUE; X change(); X break; X case 'C': /*construct*/ X construct(); X break; X case 'd': /*change display*/ X newdisplay(); X break; X case 'D': /*draft*/ X draft(); X break; X case 'f': /*report on ships and load/unload*/ X redraw=TRUE; X fleetrpt(); X break; X case 'H': /*scroll west*/ X xcurs-=((COLS-22)/4); X break; X case 'h': /*move west*/ X xcurs--; X break; X case 'J': /*scroll down*/ X ycurs+=((LINES-5)/2); X break; X case 'j': /*move down*/ X ycurs++; X break; X case 'k': /*move up*/ X ycurs--; X break; X case 'K': /*scroll up*/ X ycurs-=((LINES-5)/2); X break; X case 'l': /*move east*/ X xcurs++; X break; X case 'L': /*scroll east*/ X xcurs+=((COLS-22)/4); X break; X case 'm': /*move selected item to new x,y */ X redraw=TRUE; X mymove(); X prep(); X break; X case 'M': /*magic*/ X redraw=TRUE; X domagic(); X break; X case 'n': /*move south-east*/ X ycurs++; X xcurs++; X break; X case 'N': /*read newspaper */ X redraw=TRUE; X newspaper(); X break; X case 'p': /*pick*/ X selector+=2; X if((mvinch(selector,COLS-21))!='>') selector=0; X break; X case 'P': /*production*/ X redraw=TRUE; X produce(); X break; X case 'Q': /*quit*/ X case 'q': /*quit*/ X done=1; X break; X case 'r': /*redesignate*/ X redraw=TRUE; X redesignate(); X break; X /*list*/ X case 'R': /*Read Messages*/ X redraw=TRUE; X rmessage(); X refresh(); X break; X case 's': /*score*/ X redraw=TRUE; X showscore(); X break; X case 'S': /*diplomacy screens*/ X diploscrn(); X redraw=TRUE; X break; X case 'u': /*move north-east*/ X ycurs--; X xcurs++; X break; X case 'W': /*message*/ X redraw=TRUE; X wmessage(); X break; X case 'y': /*move north-west*/ X ycurs--; X xcurs--; X break; X case 'Z': /*move civilians up to 2 spaces*/ X redraw=TRUE; X moveciv(); X break; X case 'z': /*login as new user */ X fprintf(fexe,"NGOLD\t%d \t%d \t%d \t0 \t0 \t%s\n",XNAGOLD ,country,ntn[country].tgold,"null"); X redraw=TRUE; X fprintf(fexe,"NIRON\t%d \t%d \t%d \t0 \t0 \t%s\n",XNAIRON ,country,ntn[country].tiron,"null"); X fprintf(fexe,"NRGOLD\t%d \t%d \t%d \t0 \t0 \t%s\n",XNARGOLD ,country,ntn[country].jewels,"null"); X standout(); X clear(); X mvaddstr(0,0,"change login to : "); X standend(); X refresh(); X echo(); X scanw("%s",name); X noecho(); X X ocountry=country; X country=(-1); X if(strcmp(name,"god")==0) country=0; X else for(i=1;i=1)) X country=i; X X if(country==(-1)) { X mvaddstr(2,0,"name not found"); X country=ocountry; X break; X } X X /*get password*/ X mvaddstr(2,0,"what is your password:"); X refresh(); X getstr(passwd); X strcpy(name,crypt(passwd,SALT)); X X if((strncmp(name,ntn[country].passwd,PASSLTH)!=0)&&(strncmp(name,ntn[0].passwd,PASSLTH)!=0)){ X mvaddstr(3,0,"sorry:"); X refresh(); X country=ocountry; X break; X } X X readdata(); X startgold = ntn[country].tgold; X execute(); X updmove(ntn[country].race); X /*go to that nations capital*/ X if(country!=0) { X if(ntn[country].capx>15) { X xcurs=15; X xoffset= (ntn[country].capx-15); X } X else { X xcurs= ntn[country].capx; X xoffset= 0; X } X if(ntn[country].capy>10) { X ycurs=10; X yoffset= (ntn[country].capy-10); X } X else { X yoffset= 0; X ycurs= ntn[country].capy; X } X } X break; X case '?': /*display help screen*/ X redraw=TRUE; X help(); X break; X default: X beep(); X } X} X Xmakeside() X{ X int i; X int found=0,nvyfnd=0; X int enemy; X int y; X short armynum; X short nvynum; X int count; X int nfound=0; X X /*clear side if you cant see it as you are out of bounds*/ X if(inch()==' ') { X for(i=0;i0)&&(AXLOC==XREAL)&&(AYLOC==YREAL)) { X if(nfound<5) { X mvaddch(nfound*2,COLS-21,'>'); X if(selector==nfound*2) standout(); X mvprintw(nfound*2,COLS-20,"army %d: %d men ",armynum,ASOLD); X mvprintw(nfound*2+1,COLS-20," mv:%d st:%s",AMOVE,*(soldname+ASTAT)); X clrtoeol(); X standend(); X nfound++; X } X else mvaddstr(10,COLS-20,"MORE..."); X } X if((occ[XREAL][YREAL]!=0)&&(occ[XREAL][YREAL]!=country)&&((SOWN==country)||((ASOLD>0)&&(AXLOC<=XREAL+1)&&(AXLOC>=XREAL-1)&&(AYLOC<=YREAL+1)&&(AYLOC>=YREAL-1)))) found=1; X } X X for(nvynum=0;nvynum"); X if(selector==nfound*2) standout(); X mvprintw(nfound*2,COLS-20,"navy %d: move %d",nvynum,NMOVE); X clrtoeol(); X mvprintw(nfound*2+1,COLS-20," war:%d mer:%d",NWAR,NMER); X clrtoeol(); X standend(); X nfound++; X } X else mvaddstr(10,COLS-20,"MORE..."); X } X if((occ[XREAL][YREAL]!=0)&&(occ[XREAL][YREAL]!=country)&&(sct[XREAL][YREAL].altitude==WATER)&&(NWAR+NMER>0)&&(NXLOC<=XREAL+1)&&(NXLOC>=XREAL-1)&&(NYLOC<=YREAL+1)&&(NYLOC>=YREAL-1)) nvyfnd=1; X } X X count=0; X if(found==1) for(i=0;i0)) enemy+=ntn[i].arm[armynum].sold; X } X if(enemy>0) { X if(magic(country,SPY)==1) X mvprintw(nfound*2+count,COLS-20,"%s: %d men ",ntn[i].name,enemy); X else if(magic(i,THE_VOID)==1){ X mvprintw(nfound*2+count,COLS-20,"%s: ?? men ",ntn[i].name); X clrtoeol(); X } X else mvprintw(nfound*2+count,COLS-20,"%s: %d men ",ntn[i].name,(enemy*(rand()%60+70)/100)); X count++; X } X } X } X if(nvyfnd==1) for(i=0;i0)){ X if(magic(country,SPY)==1){ X mvprintw(nfound*2+count,COLS-20,"%s: %d ships ",ntn[i].name,ntn[i].nvy[nvynum].warships+ntn[i].nvy[nvynum].merchant); X } X else if(magic(i,THE_VOID)==1){ X mvprintw(nfound*2+count,COLS-20,"%s: ?? ships",ntn[i].name); X clrtoeol(); X } X else mvprintw(nfound*2+count,COLS-20,"%s: %d ships ",ntn[i].name,(ntn[i].nvy[nvynum].warships+ntn[i].nvy[nvynum].merchant)*(rand()%6+7)/10); X count++; X } X } X } X } X X standend(); X mvprintw(11,COLS-20,"x is %d ",XREAL); X mvprintw(11,COLS-11,"y is %d ",YREAL); X X if((country!=0)&&(sct[XREAL][YREAL].altitude=='~')){ X for(y=12;y<=20;y++) mvaddstr(y,COLS-20," "); X mvaddstr(14,COLS-9,"WATER"); X } X else { X if((country!=0)&&(country!=sct[XREAL][YREAL].owner)&&(magic(sct[XREAL][YREAL].owner,THE_VOID)==1)){ X for(y=13;y<=20;y++) mvaddstr(y,COLS-20," "); X } X else { X X for(y=13;y<=14;y++) mvaddstr(y,COLS-20," "); X X for(i=0;i<=7;i++) X if(sct[XREAL][YREAL].designation==*(des+i)){ X mvprintw(13,COLS-20,"%s",*(desname+i)); X clrtoeol(); X } X X if((sct[XREAL][YREAL].owner==country)||(country==0)) X mvprintw(15,COLS-20,"people: %6d",sct[XREAL][YREAL].people); X else X mvprintw(15,COLS-20,"people: %6d",sct[XREAL][YREAL].people*(rand()%60+70)/100); X X if((sct[XREAL][YREAL].owner==country)||(sct[XREAL][YREAL].owner==0)||(sct[XREAL][YREAL].owner>=MAXNTN)){ X mvprintw(17,COLS-20,"gold is: %3d",sct[XREAL][YREAL].gold); X mvprintw(18,COLS-20,"iron is: %3d",sct[XREAL][YREAL].iron); X if(sct[XREAL][YREAL].fortress>0){ X mvprintw(19,COLS-20,"fortress: %2d",sct[XREAL][YREAL].fortress); X } X else mvaddstr(19,COLS-20," "); X } X else { X for(y=17;y<=19;y++) mvaddstr(y,COLS-20," "); X } X } X X standout(); X if(sct[XREAL][YREAL].owner==0) mvaddstr(12,COLS-20,"unowned"); X else mvprintw(12,COLS-20,"owner: %s",ntn[sct[XREAL][YREAL].owner].name); X standend(); X clrtoeol(); X X for(i=0;i<=10;i++) X if(sct[XREAL][YREAL].vegitation==*(veg+i)) X mvprintw(13,COLS-9,"%s",*(vegname+i)); X X if(sct[XREAL][YREAL].owner!=0) for(i=1;i<=8;i++) X if(ntn[sct[XREAL][YREAL].owner].race==*(races+i)[0]){ X mvprintw(14,COLS-20,"%s",*(races+i)); X clrtoeol(); X } X X for(i=0;i<=4;i++) X if(sct[XREAL][YREAL].altitude==*(ele+i)) X mvprintw(14,COLS-9,"%s",*(elename+i)); X } X X if(movecost[XREAL][YREAL]<0) X mvaddstr(16,COLS-20,"YOU CAN'T ENTER HERE"); X else X mvprintw(16,COLS-20,"move cost: %2d ",movecost[XREAL][YREAL]); X X} X Xoffmap() X{ X redraw=FALSE; X /*set offset offsets can not be < 0*/ X if(xcurs<1){ X if(XREAL<=0) { X xoffset=0; X xcurs=0; X } X else { X redraw=TRUE; X xoffset-=15; X xcurs+=15; X } X } X else if(xcurs >= (COLS-22)/2){ X if(XREAL=MAPX) xcurs=MAPX-1-xoffset; X if(xoffset<0) xoffset=0; X if(xcurs<0) xcurs=0; 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 >= LINES-5){ X if(YREAL=MAPY) ycurs=MAPY-1-yoffset; X if(yoffset<0) yoffset=0; X if(ycurs<0) ycurs=0; X else if(ycurs >= LINES - 5) { X redraw=TRUE; X yoffset+=15; X ycurs-=15; X } X} END_OF_main.c if test 17234 -ne `wc -c reports.c <<'END_OF_reports.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 X/* screen subroutines */ X X/*include files*/ X#include X#include "header.h" X Xextern FILE *fexe; Xextern short country; Xextern int startgold; X X/*report on armies and allow changes*/ Xarmyrpt() X{ X int i,j; X int chg; X short army; X int men; X int oldx,oldy; X short oldarmy; X int done=0; X int position; X int isgod=0; X int count; /*number of armies on current screen */ X short armynum=0; /*current nation id */ X if(country==0) { X standout(); X isgod=1; X clear(); X mvaddstr(0,0,"SUPER USER; FOR WHAT NATION NUMBER:"); X clrtoeol(); X standend(); X refresh(); X echo(); X scanw("%hd",&country); X if(country<0||country>NTOTAL) return; X noecho(); X } X armynum=0; X /*new army screen*/ X while(done==0) { X clear(); X /*Operate on any armies that you wish*/ X standout(); X mvprintw(0,(COLS/2)-20,"ARMY STATS SUMMARY FOR %s",ntn[country].name); X standend(); X /* give a army report */ X X mvaddstr(3,0,"soldiers :"); X mvaddstr(4,0,"movement :"); X mvaddstr(5,0,"x location:"); X mvaddstr(6,0,"y location:"); X mvaddstr(7,0,"status :"); X X position=5; X count=0; X while((armynum0) { X count++; X position+=10; X standout(); X mvprintw(2,position,"%d:",armynum); X standend(); X mvprintw(3,position,"%d",ASOLD); X mvprintw(4,position,"%d",AMOVE); X mvprintw(5,position,"%d",AXLOC); X mvprintw(6,position,"%d",AYLOC); X mvprintw(7,position,"%s",*(soldname+ASTAT)); X } X armynum++; X } X if(armynum>=MAXARM) done=1; X X standout(); X mvaddstr(12,(COLS/2)-10,"HIT SPACE KEY IF DONE"); X mvaddstr(13,(COLS/2)-14,"HIT RETURN TO CHANGE AN ARMY"); X mvaddstr(14,(COLS/2)-14,"HIT ANY OTHER KEY TO CONTINUE"); X standend(); X refresh(); X if ((army=getch())==' ') done=1; X if (army=='\n'){ X mvaddstr(16,0,"WHAT ARMY DO YOU WANT TO CHANGE:"); X clrtoeol(); X refresh(); X echo(); X scanw("%hd",&armynum); X noecho(); X if((armynum<0)||(armynum>MAXARM)) return; X mvaddstr(18,0,"1) CHANGE STATUS, 2) TRANSFER / MERGE, 3) SPLIT ARMY, 4) DISBAND ARMY:"); X clrtoeol(); X if(isgod==1) mvaddstr(20,0,"5) LOCATION, 6) SOLDIERS:"); X refresh(); X switch(getch()){ X case '1': X mvaddstr(21,0,"1=MARCH, 2=SCOUT, 3=ATTACK, 4=DEFEND, 5=GARRISON"); X clrtoeol(); X refresh(); X scanw("%d",&chg); X if(chg<1) return; X if(chg>5) return; X if((chg==2)&&(ASOLD>25)){ X clear(); X mvaddstr(12,(COLS/2)-6,"NEED < 25 MEN TO SCOUT"); X mvaddstr(13,(COLS/2)-12,"HIT ANY KEY TO CONTINUE"); X refresh(); X getch(); X if(isgod==1) country=0; X return; X } X else if((chg>0)&&(chg<7)) { X ASTAT=chg; X AADJSTAT; X } X break; X case '2': X oldx=AXLOC; X oldy=AYLOC; X oldarmy=armynum; X mvaddstr(22,0,"TO WHAT ARMY: "); X clrtoeol(); X refresh(); X echo(); X scanw("%hd",&armynum); X if(armynum==oldarmy) { X mvprintw(23,0,"SORRY -- SAME (%d,%d",armynum,oldarmy); X refresh(); X getch(); X } X else if((armynum<0)||(armynum>MAXARM)){ X mvprintw(23,0,"SORRY -- INVALID ARMY %d",armynum); X refresh(); X getch(); X } X else if(ntn[country].arm[oldarmy].stat==SCOUT){ X mvaddstr(23,0,"SORRY -- ORIGIN ARMY IS SCOUTING"); X refresh(); X getch(); X } X else if(ASTAT==SCOUT){ X mvaddstr(23,0,"SORRY -- TARGET ARMY IS SCOUTING"); X refresh(); X getch(); X } X else if((oldx==AXLOC)&&(oldy==AYLOC)&&(ASOLD>0)) { X ASOLD+= ntn[country].arm[oldarmy].sold; X ntn[country].arm[oldarmy].sold=0; X AADJMEN; X if(AMOVE>ntn[country].arm[oldarmy].smove) X AMOVE=ntn[country].arm[oldarmy].smove; X AADJMOV; X armynum=oldarmy; X AADJMEN; X } X else { X mvaddstr(23,0,"Armies not together (hit any key) "); X refresh(); X getch(); X } X noecho(); X break; X case '3': X mvaddstr(21,0,"HOW MANY MEN TO SPLIT: "); X clrtoeol(); X refresh(); X echo(); X scanw("%d",&men); X noecho(); X if((armynum<0)||(armynum>MAXARM)) return; X if((men<25)||(ASOLD-men<25)){ X mvaddstr(23,0,"TOO FEW MEN TRANSFERED OR LEFT"); X refresh(); X getch(); X } X else if(men0) expsold+= ASOLD; X for(nvynum=0;nvynum0) expship+=(NWAR+NMER); X X standout(); X mvprintw(5,0, "nation name is ...%s ",ntn[country].name); X mvprintw(6,0, "gold in treasury..$%8ld",ntn[country].tgold); X standend(); X if(ntn[country].tfood0)) { X indesert+= sct[xsctr][ysctr].people; X revdesert+=6*sct[xsctr][ysctr].people; X } X } X if(magic(sct[xsctr][ysctr].owner,MINER)==1) { X mvaddstr(20,0,"MINER"); X reviron*=2; X revgold*=2; X } X X standout(); X mvprintw(5,0, "nation name is ...%s ",ntn[country].name); X mvprintw(6,0, "gold in treasury..$%8d",ntn[country].tgold); X standend(); X mvaddstr(8,0, "FOOD PRODUCTION"); X mvprintw(9,0, "granary now holds......%8ld tons",ntn[country].tfood); X mvprintw(10,0, "%5d people in farms..%8d tons",infood,revfood); X if((magic(country,DERVISH)==1)||(magic(country,DESTROYER)==1)) { X mvprintw(11,0, "dervish: %5d people..%8d tons",indesert,revdesert); X } X for(armynum=0;armynum0) military+=ASOLD; X mvprintw(12,0, "%5d civilians eat....%8d tons",civilians,civilians); X mvprintw(13,0, "%5d soldiers eat....%8d tons",military,military*2); X mvprintw(15,0, "TOTAL NET FOOD.........%8d tons",revfood+revdesert-civilians-military*2); X if(ntn[country].tfood+revfood+revdesert-civilians-military*2NTOTAL) return; X noecho(); X } X X count=0; X for(nvynum=0;nvynum0) { X count++; X position+=10; X standout(); X mvprintw(2,position,"%d:",nvynum); X standend(); X mvprintw(3,position,"%d",NWAR); X mvprintw(4,position,"%d",NMER); X mvprintw(5,position,"%d",NXLOC); X mvprintw(6,position,"%d",NYLOC); X mvprintw(7,position,"%d",NMOVE); X } X nvynum++; X } X if(nvynum>=MAXNAVY) done=1; X X standout(); X mvaddstr(12,(COLS/2)-10,"HIT SPACE KEY IF DONE"); X mvaddstr(13,(COLS/2)-14,"HIT RETURN TO CHANGE A NAVY"); X mvaddstr(14,(COLS/2)-14,"HIT ANY OTHER KEY TO CONTINUE"); X standend(); X refresh(); X if ((navy=getch())==' ') done=1; X if (navy=='\n'){ X mvaddstr(16,0,"WHAT NAVY DO YOU WANT TO CHANGE:"); X clrtoeol(); X refresh(); X echo(); X scanw("%hd",&nvynum); X noecho(); X if((nvynum<0)||(nvynum>MAXNAVY)) return; X mvaddstr(18,0,"1) TRANSFER / MERGE, 2) SPLIT NAVY, 3) DISBAND NAVY:"); X clrtoeol(); X refresh(); X switch(getch()){ X case '1': X oldx=NXLOC; X oldy=NYLOC; X oldnavy=nvynum; X mvaddstr(22,0,"TO WHAT NAVY: "); X clrtoeol(); X refresh(); X echo(); X scanw("%hd",&nvynum); X if(nvynum==oldnavy) { X mvprintw(23,0,"SORRY -- SAME (%d,%d)",nvynum,oldnavy); X refresh(); X getch(); X } X else if((nvynum<0)||(nvynum>MAXNAVY)){ X mvprintw(23,0,"SORRY -- INVALID NAVY %d",nvynum); X refresh(); X getch(); X } X else if((oldx==NXLOC)&&(oldy==NYLOC)) { X NWAR+=ntn[country].nvy[oldnavy].warships; X NMER+=ntn[country].nvy[oldnavy].merchant; X NADJSHP; X if(NMOVE>ntn[country].nvy[oldnavy].smove) X NMOVE=ntn[country].nvy[oldnavy].smove; X NADJMOV; X nvynum=oldnavy; X NWAR=0; X NMER=0; X NADJSHP; X } X else { X mvaddstr(23,0,"Navies not together (hit any key) "); X refresh(); X getch(); X } X noecho(); X break; X case '2': X mvaddstr(21,0,"HOW MANY WARSHIPS TO SPLIT: "); X clrtoeol(); X refresh(); X echo(); X scanw("%hd",&wships); X mvaddstr(21,0,"HOW MANY MERCHANTS TO SPLIT: "); X clrtoeol(); X refresh(); X scanw("%hd",&mships); X noecho(); X if((wshipsrun <<'END_OF_run' X#RUN CONQUEST WHEN AT COMMAND DOES NOT EXIST X#date X#while [ 1 ] X#do X#$(EXECUTABLE)/conquest -x X#/bin/sleep 86400 X#done X X#please read up on the at command, this now, and 24 hours from the time run. Xdate Xconquest -x Xat now+1day << 'EOF' X run XEOF; END_OF_run if test 256 -ne `wc -c