Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!amdcad!ames!ll-xn!mit-eddie!uw-beaver!tektronix!tekgen!tekred!games-request From: games-request@tekred.TEK.COM Newsgroups: comp.sources.games Subject: v03i072: conquer - version 2 of the renamed conquest adventure game, Part03/06 Message-ID: <2106@tekred.TEK.COM> Date: 22 Jan 88 21:33:59 GMT Sender: billr@tekred.TEK.COM Lines: 2168 Approved: billr@tekred.TEK.COM Submitted by: ihnp4!mhuxd!smile (Ed Barlow) Comp.sources.games: Volume 3, Issue 72 Archive-name: conquer/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/*conquer is copyrighted 1986 by Ed Barlow. X * I spent a long time writing this code & I hope that you respect this. X * I give permission to alter the code, but not to copy or redistribute X * it without my explicit permission. If you alter the code, X * please document changes and send me a copy, so all can have it. X * This code, to the best of my knowledge works well, but it is my first X * 'C' program and should be treated as such. I disclaim any X * responsibility for the codes actions (use at your own risk). I guess X * I am saying "Happy gaming", and am trying not to get sued in the process. X * Ed X */ X X/* commands.c */ X X/*include files*/ X#include "header.h" X#include "data.h" X#include X Xextern short xcurs,ycurs,xoffset,yoffset; Xextern FILE *fexe; /*execute file pointer*/ Xextern short country; Xextern short selector; Xextern short pager; Xextern short xcurs,ycurs,xoffset,yoffset; 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 X &&newdes!=HILL&&newdes!=CLEAR) return; X sct[XREAL][YREAL].altitude=newdes; X if((newdes==PEAK)||(newdes==WATER)) { X sct[XREAL][YREAL].owner=0; X sct[XREAL][YREAL].people=0; X sct[XREAL][YREAL].fortress=0; X } X /*will fall through as must change vegetation*/ X case 'v': X /*vegetation types*/ X mvprintw(LINES-2,7,"VEGITATIONS: change to %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c or %c?", X VOLCANO,DESERT,WASTE,BARREN,LT_VEG, X GOOD,WOOD,FORREST,JUNGLE,SWAMP,ICE,NONE); X refresh(); X newdes=getch(); X if(newdes!=VOLCANO X &&newdes!=DESERT&&newdes!=WASTE X &&newdes!=BARREN&&newdes!=LT_VEG X &&newdes!=NONE&&newdes!=GOOD X &&newdes!=WOOD&&newdes!=FORREST&&newdes!=JUNGLE X &&newdes!=SWAMP&&newdes!=ICE) return; X sct[XREAL][YREAL].vegetation=newdes; X if(isdigit(sct[XREAL][YREAL].vegetation)==0) X sct[XREAL][YREAL].designation=newdes; X return; X case 'o': X mvprintw(LINES-2,7,"what nation owner:"); X refresh(); X x = get_number(); 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 anything"); 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].vegetation)!=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) X &&(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) X &&(sct[XREAL][YREAL].designation!=DCITY)){ X mvprintw(LINES-1,0,"Sector must be a city: hit any key "); X refresh(); X getch(); X } X else if((ntn[country].tiron>DESCOST) X &&(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 { X mvprintw(LINES-1,0,"Need 500 people to build to city"); X refresh(); X getch(); X } X } X else { X mvprintw(LINES-1,0,"Not enough iron: hit any key "); X refresh(); X getch(); X } X } X else { X mvprintw(LINES-1,0,"vegetation unlivable: hit any key "); X refresh(); X getch(); X } X } X else { X mvprintw(LINES-1,0,"Sorry, you don't own sector: hit any key "); X refresh(); X getch(); X } X} X X/*build fort or ship-type */ Xconstruct() X{ X int nearsea; X long cost; X int armbonus; 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 mvaddstr(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((isgod == 0) && (ntn[country].tgold < 0 )) { X mvaddstr(LINES-1,0,"You are broke: hit any key"); X refresh(); X getch(); X return; X } X X if((sct[XREAL][YREAL].designation==DCITY) X ||(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 if(sct[XREAL][YREAL].designation==DCITY) armbonus=8; X else if(sct[XREAL][YREAL].designation==DCAPITOL) armbonus=10; X if(magic(country,ARCHITECT)==1) armbonus*=2; X X move(LINES-1,0); X clrtoeol(); X mvprintw(LINES-2,0,"Construct ortifications (+%d%% - %ld gold) or hips?:",armbonus,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 mnumber = get_number(); X mvprintw(LINES-2,0,"build how many warships:"); X clrtoeol(); X refresh(); X wnumber = get_number(); 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 %d%% fort points for %ld gold",armbonus,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 int 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) X &&(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) X &&(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 > (int) (ntn[country].tiron/10)) { 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 -= 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 army = -1; X } else { 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 } X if(army==(-1)) { X mvprintw(LINES-2,0,"raising a new army"); X clrtoeol(); X refresh(); X armynum=0; X while((army==(-1))&&(armynum=MAXARM)) { X beep(); X mvprintw(LINES-1,0,"Sorry you have an Invalid army number (%d)",armynum); X refresh(); X getch(); X return; X } X if(ASTAT==SCOUT) { X beep(); X mvprintw(LINES-1,0,"Sorry can't change scouts"); 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 status = get_number(); 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 tempfile[ 30 ]; X char mesgfile[ 30 ]; X char line[80]; X char save[20][80]; X X clear(); X /*open file*/ X sprintf(tempfile,"%s:temp",msgfile); X if( (fptemp = fopen(tempfile,"w")) == NULL ) { X mvprintw(0,0,"error on creating %s--hit return", tempfile); X refresh(); X getch(); X return; X } X X sprintf(mesgfile,"%s%d",msgfile,country); X if ((mesgfp=fopen(mesgfile,"r"))==NULL) { X mvprintw(0,0,"no messages in %s, hit return",mesgfile); 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",realname,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 mvaddstr(0,0,"Moving civilians costs 50 per civilian"); X mvprintw(1,0,"sector contains %d people",sct[XREAL][YREAL].people); X mvaddstr(2,0,"how many people to move?"); X clrtoeol(); X refresh(); X people = get_number(); X if((people<0) X ||(people>sct[XREAL][YREAL].people) X ||(people*50>ntn[country].tgold)){ X mvaddstr(5,0,"Sorry...Input error or you do not have the gold"); X clrtoeol(); X refresh(); X getch(); X makebottom(); X return; X } X X mvprintw(5,0,"sector location is x=%d, y=%d",XREAL,YREAL); X mvaddstr(7,0,"what x location to move to?"); X refresh(); X i = get_number(); X X if((i-(XREAL))>2||(i-(XREAL))<-2) { X mvprintw(10,0,"can only move 2 sectors (you tried %hd)...--hit any key",i-(XREAL)); X refresh(); X getch(); X return; X } X X mvaddstr(10,0,"what y location to move to?"); X clrtoeol(); X refresh(); X j = get_number(); X if((j-(YREAL)>2)||((YREAL)-j>2)) { X mvprintw(10,0,"sorry, can only move 2 sectors (you tried %hd)...--hit any key",j-(XREAL)); X refresh(); X getch(); X } X else if(sct[i][j].owner!=country){ X mvaddstr(12,0,"sorry, you dont own it..."); X clrtoeol(); X refresh(); X getch(); X } X /*need to check move cost > 0 for sector*/ X else if(movecost[i][j]<0){ X mvaddstr(12,0,"you can't enter there..."); X clrtoeol(); X refresh(); X getch(); X } X else { X ntn[country].tgold-=50*people; X sct[XREAL][YREAL].people-=people; X SADJCIV; X sct[i][j].people+=people; X SADJCIV2; X } X} X Xarmygoto() X{ X short armynum=0,loop=0; X armynum=getselunit(); X if((armynum<0)||(armynum>MAXARM)) armynum=0; X else armynum++; X /* move to next army with > 0 soldiers*/ X while ((armynum < MAXARM) && (ASOLD <= 0)) armynum++; X if(armynum >= MAXARM) { X armynum=0; X if(ASOLD <= 0) return(0); X } X /*move to correct location*/ X xcurs = AXLOC - xoffset; X ycurs = AYLOC - yoffset; X coffmap(); X X /*select correct unit*/ X selector=0; X pager=0; X while((getselunit() != armynum) && (loop++ < 500)) { X selector+=2; X if(selector>=10) { X selector=0; X pager+=1; X } X } X return(1); X} X Xnavygoto() X{ X short nvynum=0,loop=0; X nvynum=getselunit()-MAXARM; X if((nvynum<0)||(nvynum>MAXNAVY)) nvynum=0; X else nvynum++; X /* move to next nvy with > 0 soldiers*/ X while ((nvynum < MAXNAVY) && (NMER+NWAR <= 0)) nvynum++; X if(nvynum >= MAXNAVY) { X nvynum=0; X if(NMER+NWAR <= 0) return(0); X } X /*move to correct location*/ X xcurs = NXLOC - xoffset; X ycurs = NYLOC - yoffset; X coffmap(); X X /*select correct unit*/ X selector=0; X pager=0; X while(((getselunit()-MAXARM) != nvynum) && (loop++ < 500)) { X selector+=2; X if(selector>=10) { X selector=0; X pager+=1; X } X } X return(1); X} END_OF_commands.c if test 18869 -ne `wc -c magic.c <<'END_OF_magic.c' X/*conquer is copyrighted 1986 by Ed Barlow. X * I spent a long time writing this code & I hope that you respect this. X * I give permission to alter the code, but not to copy or redistribute X * it without my explicit permission. If you alter the code, X * please document changes and send me a copy, so all can have it. X * This code, to the best of my knowledge works well, but it is my first X * 'C' program and should be treated as such. I disclaim any X * responsibility for the codes actions (use at your own risk). I guess X * I am saying "Happy gaming", and am trying not to get sued in the process. X * Ed X */ X X/*create a new login for a new player*/ X#include "header.h" X#include "data.h" X#include 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{ Xint newpower; X newpower=1<