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: v04i045: conquer3 - middle earth multi-player game (V3), Part04/08 Message-ID: <2654@tekred.TEK.COM> Date: 16 Jun 88 21:37:09 GMT Sender: billr@tekred.TEK.COM Lines: 2156 Approved: billr@saab.CNA.TEK.COM Submitted by: ihnp4!homxc!smile Comp.sources.games: Volume 4, Issue 45 Archive-name: conquer3/Part04 #! /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 Makefile <<'END_OF_Makefile' X# conquer: Copyright (c) 1988 by Edward M Barlow X# MODIFICATION OF THIS FILE COMITS THE MODIFIER TO FOLLOW THE X# THE LIMITED USE CONTRACT CONTAINED IN THE FILE "header.h" XMAKE = /bin/make XCC = /bin/cc XRM = /bin/rm -f XLD = mld X X# This should be installed by whomever you want to own the game. X# I recommend "games" or "root". X X# uncomment the next line if you dont have getopt in your library X# (eg you are on a pc, or a non unix system). getopt.c is a X# public domain software, and has not been tested by the author X# of conquer. X#GETOPT = getopt.o X X#if the final link does not compile change to the line below X#LIBRARIES = -lcurses -ltermcap XLIBRARIES = -lcurses X X# DEFAULT is the directory where default nations & help files will be X# stored. It is also the default directory = where players will play X# if they do not use the -d option. XDEFAULT = /c28/smile/game/default X XCFLAGS = -DDEFAULTDIR=\"$(DEFAULT)\" -O X# The following CFLAGS should be used if you wish to debug the game X#CFLAGS = -DDEFAULTDIR=\"$(DEFAULT)\" -DDEBUG -g X X# this is the name of the user executable X# the user executable contains commands for the games players XGAME = conquer X# this is the name of the administrative executable X# the administrative executable contains commands for the game super user XADMIN = admin X X# This directory is where the executables will be stored XEXEDIR = /c28/smile/game/runv X X# GAME IDENTIFICATION X# this is the game identifier. See the DATA variable below XGAMEID = 1 X# This directory is where individual Conquer game data will be stored. X# As multiple simultaneous games are supported, each game must have its X# own directory. XDATA = $(EXEDIR)/lib$(GAMEID) X X# AFILS are files needed for game updating... XAFILS = combat.c cexecute.c io.c admin.c makeworld.c \ Xnewlogin.c update.c magic.c npc.c misc.c randevent.c data.c XAOBJS = combat.o cexecuteA.o ioA.o admin.o makeworld.o \ Xnewlogin.o update.o magicA.o npc.o miscA.o randevent.o dataA.o $(GETOPT) X X# GFILS are files needed to run a normal interactive game XGFILS = commands.c cexecute.c forms.c io.c main.c move.c \ Xmagic.c misc.c reports.c data.c display.c extcmds.c XGOBJS = commands.o cexecute.o forms.o io.o main.o move.o \ Xmagic.o misc.o reports.o data.o display.o extcmds.o $(GETOPT) X XHEADERS=header.h data.h newlogin.h XHELPFILE=help.txt XSUPT1=nations Makefile $(HELPFILE) README run man.page XSUPT2=execute messages news XHELPOUT=help XALLFILS=$(SUPT1) $(HEADERS) $(AFILS) commands.c forms.c main.c move.c \ Xreports.c display.c extcmds.c X Xall: $(ADMIN) $(GAME) helpfile X @echo YAY! make new_game to set up permissions, zero appropriate X @echo initial files, move $(GAME) and $(ADMIN) to X @echo $(EXEDIR), and set up the world. X @echo If a game is in progress, make install will just move $(GAME) X @echo and $(ADMIN) to $(EXEDIR). X @echo X X$(ADMIN): $(AOBJS) X @echo phew... X @echo if the next command does not you might also need -ltermcap X @echo === compiling administrative functions X $(CC) -O -o $(ADMIN) $(AOBJS) $(LIBRARIES) X X$(GAME): $(GOBJS) X @echo phew... X @echo if the next command does not compile you might also need -ltermcap X @echo === compiling user interface X $(CC) -O -o $(GAME) $(GOBJS) $(LIBRARIES) X Xclobber: X $(RM) *.o core newhelp conquer.doc $(GAME) $(ADMIN) $(HELPOUT) 2>/dev/null X Xclean: X $(RM) *.o core conquer.doc newhelp $(HELPOUT) 2>/dev/null X Xinstall: $(ADMIN) $(GAME) helpfile X cp $(GAME) $(ADMIN) $(EXEDIR) X cp $(HELPOUT) $(DATA) X cp $(HELPOUT) $(DEFAULT) X chmod 4755 $(EXEDIR)/$(GAME) X chmod 4750 $(EXEDIR)/$(ADMIN) X Xnew_game: $(ADMIN) $(GAME) helpfile X @echo Installing new game X -mkdir $(EXEDIR) 2>/dev/null X -mkdir $(DATA) 2>/dev/null X -mkdir $(DEFAULT) 2>/dev/null X chmod 755 $(EXEDIR) X chmod 751 $(DATA) $(DEFAULT) X cp $(GAME) $(ADMIN) $(EXEDIR) X chmod 4755 $(EXEDIR)/$(GAME) $(EXEDIR)/$(ADMIN) X chmod 0700 run X chmod 0644 $(HELPOUT) X chmod 0600 nations X cp $(HELPOUT) nations $(DATA) X cp $(HELPOUT) nations $(DEFAULT) X @echo now making the world X $(EXEDIR)/$(ADMIN) -d$(DATA) -m X $(EXEDIR)/$(ADMIN) -d$(DATA) -a X Xhelpfile: $(HELPOUT) X X$(HELPOUT): newhelp.c data.o header.h data.h X $(CC) $(CFLAGS) newhelp.c data.o -o newhelp X @echo Building the help file X newhelp X cat $(HELPFILE) | sed -f helpscript > $(HELPOUT) X $(RM) helpscript X cp $(HELPOUT) $(DEFAULT) X Xlint: X lint -DDEFAULTDIR=\"$(DEFAULT)\" -DCONQUER $(GFILS) > lintg X lint -DDEFAULTDIR=\"$(DEFAULT)\" -DADMIN $(AFILS) > linta X Xdocs: $(HELPOUT) conquer.doc X Xconquer.doc: X sed -e "s/^END/ /g" $(HELPOUT) > conquer.doc X Xcpio: X -$(RM) core X find . -name '*[CrpsEech]' -print | cpio -ocBv > cpiosv X Xshar: X echo " lines words chars FILENAME" > MANIFEST X wc $(ALLFILS) >> MANIFEST X createshar 1 combat.c commands.c forms.c X mv shar.out shar1 X createshar 2 move.c makeworld.c main.c X mv shar.out shar2 X createshar 3 $(SUPT1) X mv shar.out shar3 X createshar 4 npc.c newlogin.c MANIFEST newlogin.h X mv shar.out shar4 X createshar 5 reports.c misc.c randevent.c X mv shar.out shar5 X createshar 6 magic.c update.c cexecute.c data.c MANIFEST X mv shar.out shar6 X createshar 7 admin.c display.c getopt.c newhelp.c extcmds.c io.c data.h header.h X mv shar.out shar7 X Xcombat.o: data.h header.h combat.c X $(CC) $(CFLAGS) -DADMIN -c combat.c Xcexecute.o: data.h header.h cexecute.c X $(CC) $(CFLAGS) -DCONQUER -c cexecute.c Xio.o: data.h header.h io.c X $(CC) $(CFLAGS) -DCONQUER -c io.c XcexecuteA.o: data.h header.h cexecute.c X $(CC) $(CFLAGS) -DADMIN -c cexecute.c X mv cexecute.o cexecuteA.o XioA.o: data.h header.h io.c X $(CC) $(CFLAGS) -DADMIN -c io.c X mv io.o ioA.o Xadmin.o: data.h header.h admin.c X $(CC) $(CFLAGS) -DADMIN -c admin.c Xmakeworld.o: data.h header.h makeworld.c X $(CC) $(CFLAGS) -DADMIN -c makeworld.c Xnewlogin.o: data.h header.h newlogin.h newlogin.c X $(CC) $(CFLAGS) -DADMIN -c newlogin.c Xupdate.o: data.h header.h update.c X $(CC) $(CFLAGS) -DADMIN -c update.c Xmagic.o: data.h header.h magic.c X $(CC) $(CFLAGS) -DCONQUER -c magic.c XmagicA.o: data.h header.h magic.c X $(CC) $(CFLAGS) -DADMIN -c magic.c X mv magic.o magicA.o Xnpc.o: data.h header.h npc.c X $(CC) $(CFLAGS) -DADMIN -c npc.c Xmisc.o: data.h header.h misc.c X $(CC) $(CFLAGS) -DCONQUER -c misc.c XmiscA.o: data.h header.h misc.c X $(CC) $(CFLAGS) -DADMIN -c misc.c X mv misc.o miscA.o Xrandevent.o: data.h header.h randevent.c X $(CC) $(CFLAGS) -DADMIN -c randevent.c Xdata.o: data.h header.h data.c X $(CC) $(CFLAGS) -DCONQUER -c data.c XdataA.o: data.h header.h data.c X $(CC) $(CFLAGS) -DADMIN -c data.c X mv data.o dataA.o Xdisplay.o: data.h header.h display.c X $(CC) $(CFLAGS) -DCONQUER -c display.c Xreports.o: data.h header.h reports.c X $(CC) $(CFLAGS) -DCONQUER -c reports.c Xmove.o: data.h header.h move.c X $(CC) $(CFLAGS) -DCONQUER -c move.c Xmain.o: data.h header.h main.c X $(CC) $(CFLAGS) -DCONQUER -c main.c Xforms.o: data.h header.h forms.c X $(CC) $(CFLAGS) -DCONQUER -c forms.c Xcommands.o: data.h header.h commands.c X $(CC) $(CFLAGS) -DCONQUER -c commands.c END_OF_Makefile if test 6885 -ne `wc -c commands.c <<'END_OF_commands.c' X/*conquer : Copyright (c) 1988 by Ed Barlow. X * I spent a long time writing this code & I hope that you respect this. X * I give permission to alter the code, but not to copy or redistribute X * it without my explicit permission. If you alter the code, X * please document changes and send me a copy, so all can have it. X * This code, to the best of my knowledge works well, but it is my first X * 'C' program and should be treated as such. I disclaim any X * responsibility for the codes actions (use at your own risk). I guess X * I am saying "Happy gaming", and am trying not to get sued in the process. X * Ed X */ X X/* commands.c */ X X/*include files*/ X#include "header.h" X#include "data.h" X#include X X/*execute file pointer*/ Xextern FILE *fexe; Xextern short country; Xextern short selector; Xextern short pager; Xextern short xcurs,ycurs,xoffset,yoffset; X X/*change current hex designation*/ Xvoid Xredesignate() X{ X char newdes; X short x,y; X X if(country==0){ X clear_bottom(0); X mvaddstr(LINES-4,0,"SUPER USER: CHANGE (v)egetation, (e)levation, (d)esig, (o)wner, (m)inerals"); X refresh(); X switch(getch()){ X case 'e': X /*simple contour map definitions*/ X mvprintw(LINES-3,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-3,7,"VEGETATIONS: change to %c, %c, %c, %c, %c, %c, %c, %c, %c, %c, %c or %c?", X VOLCANO,DESERT,TUNDRA,BARREN,LT_VEG, X GOOD,WOOD,FOREST,JUNGLE,SWAMP,ICE,NONE); X refresh(); X newdes=getch(); X if(newdes!=VOLCANO X &&newdes!=DESERT&&newdes!=TUNDRA X &&newdes!=BARREN&&newdes!=LT_VEG X &&newdes!=NONE&&newdes!=GOOD X &&newdes!=WOOD&&newdes!=FOREST&&newdes!=JUNGLE X &&newdes!=SWAMP&&newdes!=ICE) return; X sct[XREAL][YREAL].vegetation=newdes; X if(tofood(sct[XREAL][YREAL].vegetation,0)!=0) X sct[XREAL][YREAL].designation=newdes; X return; X case 'o': X mvprintw(LINES-3,7,"what nation owner:"); X refresh(); X x = get_number(); X if (x=0) X sct[XREAL][YREAL].gold = x; X break; X case 'i': X mvaddstr(LINES-2,7,"new sector iron value:"); X refresh(); X x = get_number(); X if (x<100 && x>=0) X sct[XREAL][YREAL].iron = x; X break; X default: X break; X } X return; X } X } X if((country!=0)&&(sct[XREAL][YREAL].owner!=country)) { X errormsg("You do not own"); X return; X } X clear_bottom(0); X mvprintw(LINES-4,7,"$%d: redesignate to %c, %c, %c",DESCOST,DMINE,DGOLDMINE,DFARM); X mvprintw(LINES-3,7,"$%d: redesignate to %c, %c?",20*DESCOST,DCITY,DCAPITOL); X mvprintw(LINES-2,0,"space to return => what new designation:"); X refresh(); X /*read answer*/ X newdes=getch(); X X if(newdes!=DMINE&&newdes!=DGOLDMINE&&newdes!=DFARM&&newdes!=DCITY&&newdes!=DCAPITOL) { X errormsg("invalid input"); X return; X } X X if((SOWN==country)||(country==0)) { X if(((tofood(sct[XREAL][YREAL].vegetation,country)>=DESFOOD) X ||(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-=20*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 errormsg("New Capitol must be in a town"); X } X else if((ntn[country].tiron>DESCOST) X &&(newdes==DCITY)){ X if(sct[XREAL][YREAL].people>=500){ X ntn[country].tgold-=20*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 errormsg("Need 500 people to build to town"); X } X } else errormsg("Not enough iron for town"); X } else errormsg("vegetation too sparse"); X } else { X errormsg("Sorry, you don't own sector"); X } X} X X/*build fort or ship-type */ Xvoid Xconstruct() X{ X int nearsea,repairs; X long cost; X int armbonus; X int x,y; X short nvynum=0; X short mnumber,wnumber; X short isgod=FALSE; X char type; X X clear_bottom(0); X if(country==0){ X isgod=TRUE; X country=sct[XREAL][YREAL].owner; X } X X if(sct[XREAL][YREAL].owner!=country) { X errormsg("You do not own"); X if(isgod==TRUE) country=0; X return; X } X X if((isgod==FALSE) && (ntn[country].tgold < 0 )) { X errormsg("You are broke"); 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==TRUE) 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)==TRUE) armbonus*=2; X X mvprintw(LINES-4,0,"Construct ortifications (+%d%% - %ld gold) or hips?:",armbonus,cost); X refresh(); X type=getch(); X } else { X errormsg("Must construct in town or capitol"); X if (isgod==1) country=0; 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 errormsg("not in a harbor"); X if(isgod==TRUE) country=0; X return; X } X X repairs=FALSE; X if((nvynum=getselunit()-MAXARM)>=0){ X if(nvynum>=MAXNAVY){ X errormsg("INVALID NAVY"); X if(isgod==TRUE) country=0; X return; X } X mvaddstr(LINES-3,0,"Do you wish to repair existing fleet (y or n)"); X refresh(); X if(getch()=='y') repairs=TRUE; X else{ X mvaddstr(LINES-3,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 X if(repairs==TRUE){ X clear_bottom(0); X mvprintw(LINES-4,0,"Repairing Fleet %d",nvynum); X mvaddstr(LINES-3,0,"How many crew per ship do you wish to add:"); X clrtoeol(); X refresh(); X mnumber = get_number(); X cost = (long) mnumber*WARSHPCOST*NWAR + (long) mnumber*MERSHPCOST*NMER; X if( ntn[country].tgold < cost ) { X errormsg("NOT ENOUGH GOLD"); X if(isgod==TRUE) country=0; X return; X } X if( sct[XREAL][YREAL].people < (NWAR+NMER) * mnumber ){ X errormsg("NOT ENOUGH CIVILIANS IN SECTOR"); X if(isgod==TRUE) country=0; X return; X } X if( SHIPCREW * (NWAR+NMER) < NCREW + (NWAR+NMER) * mnumber ){ X errormsg("THAT WOULD EXCEED MAXIMUM SHIP CREW"); X if(isgod==TRUE) country=0; X return; X } X X if(magic(country,SAILOR)==TRUE){ X ntn[country].tgold -= cost/2; X } else { X ntn[country].tgold -= cost; X } X X NCREW += (NWAR+NMER) * mnumber; X if(isgod==TRUE) country=0; X return; X } X X if(nvynum<0) { X nvynum=0; X x=(-1); X while((x==(-1))&&(nvynum100)||(wnumber<0)) wnumber=0; X if((mnumber>100)||(mnumber<0)) mnumber=0; X if (wnumber==0 && mnumber==0) X { X if(isgod==1) country=0; X return; X } X cost = wnumber*WARSHPCOST + mnumber*MERSHPCOST; X if(isgod==TRUE) cost=0; X else if(magic(country,SAILOR)==TRUE) cost/=2; X X if(cost > ntn[country].tgold ) { X errormsg("sorry - not enough gold"); X if(isgod==TRUE) country=0; X return; X } X X if( sct[XREAL][YREAL].people < (wnumber+mnumber) * mnumber ){ X errormsg("NOT ENOUGH CIVILIANS IN SECTOR"); X if(isgod==TRUE) country=0; X return; X } X X if((nvynum>=0)&&(nvynum=500) X /* can only go into debt as much as the nation has jewels */ X if ((ntn[country].tgold - cost) > ((-1)*10*ntn[country].jewels)) { X mvprintw(LINES-3,25,"you build +%d%% fort points for %ld gold",armbonus,cost); X ntn[country].tgold-=cost; X sct[XREAL][YREAL].fortress++; X INCFORT; X errormsg(""); X } X else errormsg("need 500 people or you are broke"); X } X else errormsg("invalid input error"); X X if(isgod==TRUE) country=0; X refresh(); X} X X/*DRAFT IF IN A CITY*/ Xvoid Xdraft() X{ X short armynum,x,y,i; X int men=0,mercs; X short army=(-1), isgod=FALSE, newtype=0; X long i_cost, e_cost; X X clear_bottom(0); X if(country==0) { X isgod=TRUE; X country=sct[XREAL][YREAL].owner; X } X else if(sct[XREAL][YREAL].owner!=country) { X errormsg("You do not own"); X return; X } X X if((sct[XREAL][YREAL].designation!=DCITY) X &&(sct[XREAL][YREAL].designation!=DCAPITOL)) { X errormsg("must raise in towns"); X if(isgod==TRUE) country=0; X return; X } X X if((sct[XREAL][YREAL].designation==DCITY) X &&(sct[XREAL][YREAL].people*(2*CITYLIMIT+(ntn[country].tsctrs/2)) can draft up to following */ X /* draftable = max_draft - already drafted */ X /* = imen/4 - ( imen - people) */ X /* = -3/4 * imen + people) */ X if((men > sct[XREAL][YREAL].people - (3*sct[XREAL][YREAL].i_people/4)) X ||(sct[XREAL][YREAL].i_people <= 0)) { X if(sct[XREAL][YREAL].i_people <= 0) { X errormsg("aborting: can not raise in this sector"); X } X else errormsg("aborting: raising too many soldiers"); X if(isgod==TRUE) country=0; X return; X } X /*ask what type of unit*/ X y=LINES-2; X x=0; X mvaddstr(y,x,"options:"); X clrtoeol(); X x+=9; X for(i=0;i<=NOUNITTYPES;i++){ X if(unitvalid(i)==TRUE) { X mvprintw(y,x+2,"%s",*(shunittype+i)); X mvprintw(y,x,"(%c)",*(shunittype+i)[0]); X x+=7; X if(x>COLS-10){ X x=0; X y++; X } X } X } X move(y,x); X clrtoeol(); X if((magic(country,WARRIOR)==TRUE) X ||(magic(country,WARLORD)==TRUE) X ||(magic(country,CAPTAIN)==TRUE)) X mvaddstr(LINES-3,0,"(Warrior = 1/2 enlist cost) what type of unit do you want:"); X else X mvaddstr(LINES-3,0,"what type of unit do you want to raise:"); X X clrtoeol(); X refresh(); X switch(getch()){ X case 'm': X newtype=A_MILITIA; X break; X case 'I': X newtype=A_INFANTRY; X break; X case 'A': X newtype=A_ARCHER; X break; X case 'M': X newtype=A_MERCENARY; X break; X case 'P': X newtype=A_PHALANX; X break; X case 'L': X newtype=A_LEGION; X break; X case 'E': X newtype=A_ELITE; X break; X case 'D': X newtype=A_DRAGOON; X break; X case 'C': X newtype=A_CAVALRY; X break; X case 'K': X newtype=A_KNIGHT; X break; X case 'c': X newtype=A_CATAPULT; X break; X case 's': X newtype=A_SEIGE; X break; X case 'R': X newtype=A_ROC; X break; X case 'O': X newtype=A_ORC; X break; X case 'U': X newtype=A_URUK; X break; X case 'T': X newtype=A_TROLL; X break; X case 'g': X newtype=A_GRIFFON; X break; X case 'l': X newtype=A_LT_CAV; X break; X case 'o': X newtype=A_OLOG; X break; X case 'N': X newtype=A_NINJA; X break; X case 'X': X newtype=A_MARINES; X break; X case 'S': X newtype=A_SAILOR; X break; X case 'G': X newtype=A_GOBLIN; X break; X case 'e': X newtype=A_ELEPHANT; X break; X default: X errormsg("Invalid type"); X if (isgod==TRUE) country=0; X return; X } X if(unitvalid(newtype)==FALSE) { X errormsg("Invalid type"); X if (isgod==TRUE) country=0; X return; X } X X /* check that you dont have too many mercenaries */ X mercs=0; X if(newtype == A_MERCENARY){ X for(armynum=0;armynum (ntn[country].tmil-mercs)/2) { X errormsg("aborting--you would then have more than 50%% mercenaries"); X if(isgod==TRUE) country=0; X return; X } X } X X e_cost= (long) *(u_encost+newtype) * men; X i_cost= (long) *(u_eniron+newtype) * men; X X /*magiced get 1/2 enlistment costs*/ X if((magic(country,WARRIOR)==TRUE) X ||(magic(country,WARLORD)==TRUE) X ||(magic(country,CAPTAIN)==TRUE)) X e_cost/=2; X X if((magic(country,SAPPER)==TRUE) X &&((newtype==A_SEIGE)||(newtype==A_CATAPULT))){ X e_cost/=2; X i_cost/=2; X } X X /*check to see if enough gold*/ X if(e_cost > ntn[country].tgold) { X errormsg("aborting--you dont have enough gold in treasury"); X if(isgod==TRUE) country=0; X return; X } X /*check for iron deposits*/ X else if(i_cost > ntn[country].tiron) { X mvprintw(LINES-1,0,"aborting--you dont have %ld iron",i_cost); X clrtoeol(); X refresh(); X getch(); X if(isgod==TRUE) country=0; X return; X } X else { X move(LINES-2,0); X clrtoeol(); 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 /*if different types, must raise new army*/ X if(newtype == ATYPE){ 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 else army=(-1); X } X } X if(army==(-1)) { X mvprintw(LINES-2,0,"(%s, gold=%ld, iron=%ld) raising a new army",*(unittype+newtype),e_cost,i_cost); X clrtoeol(); X refresh(); X sleep(1); X X armynum=0; X while((army==(-1))&&(armynum5)) return; X change_status(armynum,status); X} X X/*go through msgfile not rewriting to temp messages you discard*/ X/* then move temp to msgfile*/ Xvoid Xrmessage() X{ X int unlink(); X FILE *mesgfp; X FILE *fptemp; X int i; X int count; X int contd; X int done=FALSE; 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 (void) unlink (tempfile) ; 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=TRUE; X while(done==FALSE) { 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 } else if(ch=='\n') linedone=TRUE; X else if(isprint(ch)&&(x<65)){ X /*concatonate to end*/ X line[x]=ch; X mvaddch(y,x,ch); X x++; X refresh(); X ch=getch(); X } else ch=getch(); X } X if (ch!='\n') { X mvaddch(y,x,ch); X line[x]=ch; X x++; X } X line[x]='\0'; X if(x<=1) done=TRUE; 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*/ Xvoid 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 Xint 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 Xint 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 23192 -ne `wc -c makeworld.c <<'END_OF_makeworld.c' X/*conquer : Copyright (c) 1988 by Ed Barlow. X * I spent a long time writing this code & I hope that you respect this. X * I give permission to alter the code, but not to copy or redistribute X * it without my explicit permission. If you alter the code, X * please document changes and send me a copy, so all can have it. X * This code, to the best of my knowledge works well, but it is my first X * 'C' program and should be treated as such. I disclaim any X * responsibility for the codes actions (use at your own risk). I guess X * I am saying "Happy gaming", and am trying not to get sued in the process. X * Ed X */ X X/*Create a world*/ X X/*DEFINE TEMPORARY VARIABLES FROM MAKEFILE*/ X#include X#include X#include "header.h" X#include "data.h" X X#define HALF 2 X#define LAND 3 X Xextern short country; Xint area_map[MAXX][MAXY];/*Value Map of Areas*/ Xint type[MAPX][MAPY]; X X#define TOHILL(x,y) { \ Xsct[(x)][(y)].altitude=HILL; \ Xnmountains--; \ X} X#define TOMT(x,y) { \ Xsct[(x)][(y)].altitude=MOUNTAIN; \ Xnmountains--; \ X} X#define TOPEAK(x,y) { \ Xsct[(x)][(y)].altitude=PEAK; \ Xnmountains--; \ X} X Xvoid Xmakeworld() X{ X register int i,j; X register int x,y; X int n; /*count used in string searches*/ X float avvalue; /*Average water tvalue of sectors*/ X int number[5]; /*Number of sectors with type=[0-4]*/ X char passwd[12]; X int alloc = NUMAREAS * 2;/*Value Allocated*/ X int tplace[MAXX][MAXY] ;/*Temporary matrix to see if an area is placed*/ X int X, Y, chance; X int X1,Y1; X int X2,Y2; X int valid; X int nmountains; X int rnd; X int tempfd; X char newstring[40]; X X /*abort if datafile currently exists*/ X if((tempfd=open(datafile,0))!=-1) { X printf("ABORTING: File %s exists\n",datafile); X printf("\tthis means that a game is in progress. To proceed, you must remove \n"); X printf("\tthe existing data file. This will, of course, destroy that game.\n\n"); X exit(FAIL); X } X printf("\n**********************WELCOME TO CONQUER**********************"); X printf("\nThe world will now be created...Your super user login will be 'god'."); X printf("\nNon player countries will be read from data stored in the nations file"); X printf("\n& will have the same password as god (about to be entered). Add player"); X printf("\nnations with the command . Have fun!!!\n"); X printf("\nRemember to check the world out before playing to make sure"); X printf("\nno nations are in bad positions (surrounded by water... )"); X printf("\n******************************************************************\n\n"); X X printf("First, we must zero extraneous files from prior games\n"); X sprintf(newstring,"rm %s* 2> /dev/null",exefile); X printf("\t%s\n",newstring); X system(newstring); X sprintf(newstring,"rm %s* 2> /dev/null",msgfile); X printf("\t%s\n",newstring); X system(newstring); X sprintf(newstring,"> %s 2> /dev/null",newsfile); X printf("\t%s\n",newstring); X system(newstring); X printf("OK This has been done, Now to set up a new world\n\n"); X X printf("please enter new conquer super user password (remember this!):"); X scanf("%s",passwd); X getchar(); X printf("please reenter conquer password:"); X scanf("%s",ntn[0].passwd); X getchar(); X if((strlen(ntn[0].passwd)<2) X ||(strncmp(passwd,ntn[0].passwd,PASSLTH)!=0)) { X printf("\ninvalid super user password\n"); X exit(FAIL); X } X strncpy(ntn[0].passwd,crypt(passwd,SALT),PASSLTH); X X printf("\n\ncreating world\n"); X /*initialize variables */ X avvalue = (((float) (100-PWATER)/25.0)); /*Average water tvalue of sectors*/ X for(i=0;ialloc) { X /*have not allocated high enough so Allocate more */ X x = rand()%4; /*0 to 3*/ X if(number[x]>0) { X number[x] = number[x] - 1; X number[x+1] = number[x+1] + 1; X alloc = alloc + 1; X } X } X else { X /*have allocated too much Allocate less */ X x = (rand()%4) +1; /*1 to 4*/ X if(number[x]>0) { X number[x] = number[x] - 1; X number[x-1] = number[x-1] + 1; X alloc = alloc - 1; X } X } X } X X i=0; X while((number[4]>0)&&(i<500)) { X i++; X /*place a full land sector anywhere but on edge*/ X X = ((rand()%(MAXX-2))+1); /*1 to MAXX-2)*/ X Y = ((rand()%(MAXY-2))+1); /*1 to MAXY-2)*/ X if(tplace[X][Y] == 0) { X tplace[X][Y]=1; X area_map[X][Y]=4; X number[4]=number[4] - 1; X /*place surrounding sectors*/ X if(tplace[X+1][Y] == 0) { X rnd = rand()%100 + 1; /*1 to 100*/ X if((rnd<25) && (number[4]>0)) { X area_map[X+1][Y]=4; X number[4]=number[4]-1; X tplace[X+1][Y]=1; X } X if(rnd>25 && number[3]>0) { X area_map[X+1][Y]=3; X number[3]=number[3]-1; X tplace[X+1][Y]=1; X } X } X if(tplace[X-1][Y] == 0) { X rnd = rand()%100 + 1 ; /*(1 to 100)*/ X if(rnd<25 && number[4]>0) { X area_map[X-1][Y]=4; X number[4]=number[4]-1; X tplace[X-1][Y]=1; X } X if(rnd>25 && number[3]>0) { X area_map[X-1][Y]=3; X number[3]=number[3]-1; X tplace[X-1][Y]=1; X } X } X if(tplace[X][Y+1] == 0) { X rnd = rand()%100 + 1 ; /*(1 to 100)*/ X if(rnd<25 && number[4]>0) { X area_map[X][Y+1]=4; X number[4]=number[4]-1; X tplace[X][Y+1]=1; X } X if(rnd>25 && number[3]>0) { X area_map[X][Y+1]=3; X number[3]=number[3]-1; X tplace[X][Y+1]=1; X } X } X if(tplace[X][Y-1] == 0) { X rnd = rand()%100 + 1 ; /*(1 to 100)*/ X if(rnd<25 && number[4]>0) { X area_map[X][Y-1]=4; X number[4]=number[4]-1; X tplace[X][Y-1]=1; X } X if(rnd>25 && number[3]>0) { X area_map[X][Y-1]=3; X number[3]=number[3]-1; X tplace[X][Y-1]=1; X } X } X } X } X X /* place all other areas*/ X for(X=0;X0) { X area_map[X][Y]=rnd; X number[rnd]=number[rnd]-1; X tplace[X][Y]=1; X } X } X } X X /*ALL AREAS PLACED, NOW DETERMINE SECTOR TYPE X *fill in each area with sectors X * 1) water X * 2) water with major islands (25% land) X * 3) 50/50 water/land X * 4) land with major water (75% Land) X * 5) land X */ X for(Y=0;Y= (100-PWATER)) { X type[X][Y] = LAND; X } X else type[X][Y] = WATER; X } X X chance=0; X for(X=0;X(NUMAREAS*3*PWATER/100)+5) { X /*Place one range randomly*/ X X1 = rand()%(MAPX-6); X Y1 = rand()%(MAPY-6); X if((type[X1][Y1]==LAND) X &&(type[X1+1][Y1+1]==LAND) X &&(type[X1+1][Y1]==LAND) X &&(type[X1][Y1+1]==LAND) X &&(type[X1+2][Y1+2]==LAND)) { X /*place second endpoint */ X valid = FALSE; X i=0; X while((valid==FALSE) && (i<500)) { X i++; X X2 = (rand()%7) + X1; X Y2 = (rand()%7) + Y1; X if(type[X2][Y2] == LAND) { X valid = TRUE; X /*fill in mountain range*/ X for(x=X1;x<=X2;x++) { X if(X180) { X TOPEAK(x,y); X } X else { X TOMT(x,y) X } X } X if((y < MAPY - 1) X && type[x][y+1] == LAND) { X rnd=rand()%100+1; X if(rnd>90) { X TOPEAK(x,y+1); X } X else if(rnd>50) { X TOMT(x,y+1); X } X else if(rnd>20) { X TOHILL(x,y+1); X } X } X if((y!=0) X && type[x][y-1] == LAND ) { X rnd=rand()%100+1; X if(rnd>90) { X TOPEAK(x,y-1); X } else X if(rnd>50) { X TOMT(x,y-1); X } else X if(rnd>20) { X TOHILL(x,y-1); X } X } X if((y>=2) X &&(type[x][y-2] == LAND )) { X rnd=rand()%100+1; X if(rnd>90) { X TOMT(x,y-2); X } else { X if(rnd>50) TOHILL(x,y-2); X } X } X if((y < MAPY - 2) X &&(type[x][y+2] == LAND )) { X rnd=rand()%100+1; X if(rnd>90) { X TOMT(x,y+2); X } else if(rnd>50) { X TOHILL(x,y+2); X } X } X } X } X } X } X } X X /*fill in random hills to work out,not to left of to water*/ X while(nmountains>0) { X x = rand()%(MAPX-1); X y = rand()%(MAPY-1); X if((type[x][y]==LAND)&&(type[x+1][y]==LAND)) X TOHILL(x,y); X } X X /*make sure no peak or mountain is next to water*/ X for(y=1;yMAPY/2+8)||(yMAPY/2+8)||(y= MAXX ) X2 = 0; X if( Y3 < 0 ) Y3 = MAXY - 1; X if( Y4 >= MAXY ) Y4 = 0; X X area=area_map[X0][Y0]; X /*fill in south*/ X edgearea=area_map[X4][Y4]; X if(area + edgearea > 6) for(i=0;i<8;i++) type[X0*8+i][Y0*8+7] = LAND; X else if((area + edgearea)>3) { X for(i=0;i<8;i++) X if(rand()%2 == 0) type[(X0*8)+i][Y0*8+7] = LAND; X else type[(X0*8)+i][Y0*8+7] = WATER; X } X else for(i=0;i<8;i++) type[(X0*8)+i][Y0*8+7] = WATER; X /*fill in east*/ X edgearea=area_map[X2][Y2]; X if(area + edgearea > 6) for(i=0;i<8;i++) type[X0*8+7][Y0*8+i] = LAND; X else if((area + edgearea)>3) { X for(i=0;i<8;i++) X if(rand()%2==0) type[X0*8+7][Y0*8+i] = LAND; X else type[X0*8+7][Y0*8+i] = WATER; X } X else for(i=0;i<8;i++) type[X0*8+7][Y0*8+i] = WATER; X /*fill in west*/ X edgearea=area_map[X1][Y1]; X if(area + edgearea > 6) for(i=0;i<=7;i++) type[X0*8][Y0*8+i] = LAND; X else if((area + edgearea)>3) { X for(i=0;i<8 ;i++) X if(rand()%2==0) type[X0*8][Y0*8+i] = LAND; X else type[X0*8][Y0*8+i] = WATER; X } X else for(i=0;i<8 ;i++) type[X0*8][Y0*8+i] = WATER; X /*fill in north*/ X edgearea=area_map[X3][Y3]; X if(area + edgearea > 6) for(i=0;i<8 ;i++) type[X0*8+i][Y0*8] = LAND; X else if((area + edgearea)>3) { X for(i=0;i<8 ;i++) X if(rand()%2==0) type[(X0*8)+i][Y0*8] = LAND; X else type[(X0*8)+i][Y0*8] = WATER; X } X else for(i=0;i<8 ;i++) type[(X0*8)+i][Y0*8] = WATER; X} X X/* ALLOCATE POPULATIONS OF THE WORLD*/ Xvoid Xpopulate() X{ X int i=0,x=0,y=0,j=0; X int nvynum=0,army2num=0,armynum=0; X int temp; X int cnum=0; X FILE *fp, *fopen(); X int done=FALSE; X char line[80]; X X X /*randomly scatter lizard city (want in DESERTS/swamp/Ice) */ X /*don't reproduce. Their cities are fortified and stockpiled */ X#ifdef LZARD X strncpy(ntn[NLIZARD].name,"lizard",10); X strncpy(ntn[NLIZARD].leader,"dragon",10); X strcpy(ntn[NLIZARD].passwd,ntn[0].passwd); X ntn[NLIZARD].race=LIZARD; X ntn[NLIZARD].mark='*'; X ntn[NLIZARD].active=2; X ntn[NLIZARD].aplus=0; X ntn[NLIZARD].dplus=0; X ntn[NLIZARD].maxmove=0; X ntn[NLIZARD].repro=0; X ntn[NLIZARD].powers=KNOWALL; X for(i=0;i=MAXARM) break; X if (is_habitable(x,y)) { X sct[x][y].designation = DCASTLE; X sct[x][y].fortress = 5+rand()%5; X sct[x][y].gold = 15+rand()%20; X for(i=x-1;i<=x+1;i++) for(j=y-1;j<=y+1;j++) X if(i>=0&&j>=0&&i