games@tekred.TEK.COM (06/17/88)
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 <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 4 (of 8)."
# Contents: Makefile commands.c makeworld.c
# Wrapped by billr@saab on Thu Jun 16 09:39:58 1988
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f Makefile -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(6885 characters\)
sed "s/^X//" >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 <Makefile`; then
echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f commands.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"commands.c\"
else
echo shar: Extracting \"commands.c\" \(23192 characters\)
sed "s/^X//" >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 <ctype.h>
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<NTOTAL) sct[XREAL][YREAL].owner=x;
X return;
X case 'm':
X mvaddstr(LINES-2,7,"(g)old, or (i)ron?");
X refresh();
X switch(getch()) {
X case 'g':
X mvaddstr(LINES-2,7,"new sector gold value: ");
X refresh();
X x = get_number();
X if (x<100 && 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 <f>ortifications (+%d%% - %ld gold) or <s>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))&&(nvynum<MAXNAVY)) {
X if(NWAR+NMER<=0) {
X x=nvynum;
X NWAR=0;
X NMER=0;
X NADJSHP;
X }
X nvynum++;
X }
X nvynum=x;
X }
X if(nvynum<0){
X errormsg("NO FREE NAVIES");
X if(isgod==TRUE) country=0;
X return;
X }
X else mvprintw(LINES-2,30,"raising new fleet %d",nvynum);
X
X
X mvprintw(LINES-3,0,"how many merchants:");
X refresh();
X mnumber = get_number();
X mvprintw(LINES-3,40,"how many warships:");
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 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<MAXNAVY)) {
X clear_bottom(0);
X mvprintw(LINES-4,0,"constructing %hd warships and %hd merchant",wnumber,mnumber);
X
X NCREW += (wnumber+mnumber) * SHIPCREW;
X sct[XREAL][YREAL].people -= (wnumber+mnumber)*SHIPCREW;
X
X ntn[country].tgold -= cost;
X
X NXLOC =XREAL;
X NYLOC =YREAL;
X NWAR+=wnumber;
X NMER+=mnumber;
X NMOVE=0;
X NADJSHP;
X NADJLOC;
X NADJMOV;
X } else errormsg("ERROR!!!!!!!!!!!!!");
X
X mvprintw(LINES-2,30,"adding ships to fleet %d",nvynum);
X mvprintw(LINES-2, 60, "PRESS ANY KEY");
X beep();
X refresh();
X getch();
X }
X /* construct fortification points*/
X else if(type=='f'){
X if(sct[XREAL][YREAL].people>=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))<ntn[country].tciv)){
X mvprintw(LINES-1,0,"need %d people in town: hit any key",ntn[country].tciv/(2*CITYLIMIT+(ntn[country].tsctrs/2)));
X refresh();
X getch();
X if(isgod==TRUE) country=0;
X return;
X }
X
X if(ntn[country].tgold <= 0){
X errormsg("you dont have any gold");
X if(isgod==TRUE) country=0;
X return;
X }
X
X /*raise an untrained army */
X mvprintw(LINES-3,0,"how many men do you wish to raise:");
X clrtoeol();
X refresh();
X men = get_number();
X if(men<=0) {
X if (isgod==TRUE) country=0;
X return;
X }
X /* i_people is initial people -> 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<MAXARM;armynum++){
X if(ATYPE==A_MERCENARY) mercs+=ASOLD;
X }
X if(men+mercs > (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))&&(armynum<MAXARM)) {
X if(ASOLD<=0) {
X army=armynum;
X ASOLD=0;
X ASTAT=DEFEND; /* set new armies to DEFEND */
X AADJSTAT;
X AADJMEN;
X }
X armynum++;
X }
X if(army==(-1)){
X errormsg("NO FREE ARMIES");
X if(isgod==TRUE) country=0;
X return;
X }
X armynum=army;
X } else {
X mvprintw(LINES-2,0,"(%s, gold=%ld, iron=%ld) adding to existing army",*(unittype+newtype),e_cost,i_cost);
X clrtoeol();
X refresh();
X sleep(1);
X }
X
X ATYPE=newtype;
X if(ATYPE != A_MERCENARY){
X sct[XREAL][YREAL].people -= men;
X SADJCIV;
X }
X AYLOC=YREAL;
X AXLOC=XREAL;
X AADJLOC;
X AMOVE=0;
X AADJMOV;
X ASOLD+=men;
X AADJMEN;
X ntn[country].tiron -= i_cost;
X ntn[country].tgold -= e_cost;
X makemap(); /* if display 'y' is set, this will show new army */
X if(isgod==TRUE) country=0;
X}
X
X/*adjust picked army*/
Xvoid
Xadjarm(armynum)
Xint armynum;
X{
X short status;
X
X clear_bottom(0);
X if(armynum==(-1)) armynum=getselunit();
X mvprintw(LINES-4,0,"ADJUST ARMY %d",armynum);
X mvaddstr(LINES-3,0,"1) March 2) Scout 3) Attack 4) Defend 5) Garrison");
X mvaddstr(LINES-2,0,"Enter your choice (return to continue):");
X refresh();
X status = get_number();
X if((status<1)||(status>5)) 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;i<strlen(ntn[country].name);i++)
X mvaddch(count,i,' ');
X count++;
X if(fgets(line,80,mesgfp)==NULL) contd=1;
X if(strncmp(line,"END",3)==0) contd=1;
X }
X standout();
X mvaddstr(LINES-3,(COLS/2)-22,"HIT RETURN TO SAVE MESSAGE");
X mvaddstr(LINES-2,(COLS/2)-22,"HIT ANY OTHER KEY TO CONTINUE");
X standend();
X refresh();
X if(getch()=='\n') {
X for(i=0;i<count-3;i++) fputs(save[i],fptemp);
X strcpy(line,"END\n");
X fputs(line,fptemp);
X }
X }
X else fputs(line,fptemp);
X if(fgets(line,80,mesgfp)==NULL) done=TRUE;
X }
X fclose(mesgfp);
X fclose(fptemp);
X
X /*IMPLEMENT A MOVE BETWEEN TMP FILE AND REAL FILE HERE*/
X move_file( tempfile, mesgfile );
X}
X
Xvoid
Xwmessage()
X{
X FILE *fp, *fopen();
X int x,y;
X int done=FALSE;
X char ch;
X char name[12];
X char realname[12];
X int temp=(-1);
X int linedone;
X char line[100];
X int nationid;
X
X /*what nation to send to*/
X clear();
X mvprintw(0,0,"to send a message to the administrator, send to 'god':");
X mvprintw(2,0,"What country name do you wish to send to:");
X refresh();
X get_nname(name);
X
X /*is name valid*/
X for(nationid=0;nationid<MAXNTN;nationid++) if(ntn[nationid].active!=0)
X if(strcmp(name,ntn[nationid].name)==0) temp=nationid;
X
X if(strcmp(name,"god")==0) {
X temp=0;
X strcpy(realname,"unowned");
X }
X else strcpy(realname,name);
X
X if (temp==(-1)) {
X mvprintw(3,0,"error--invalid name");
X refresh();
X getch();
X return;
X }
X
X sprintf(line,"%s%d",msgfile,temp);
X if ((fp=fopen(line,"a+"))==NULL) {
X mvprintw(4,0,"error opening %s",line);
X refresh();
X getch();
X return;
X }
X
X move(0,0);
X clrtoeol();
X move(2,0);
X clrtoeol();
X standout();
X mvprintw(3,(COLS-25)/2,"message to nation %s",name);
X mvprintw(LINES-2,(COLS-35)/2,"end with a return on a new line");
X standend();
X
X if (country==0)
X fprintf(fp,"%s Message to %s from GOD\n",realname,name);
X else fprintf(fp,"%s Message to %s from %s\n",realname,name,ntn[country].name);
X fprintf(fp,"%s \n",realname);
X y=6;
X x=0;
X refresh();
X while(done==FALSE) {
X linedone=FALSE;
X ch=' ';
X /*read line*/
X while(linedone==FALSE){
X /* check for delete or backspace */
X if(ch=='\b' || ch=='\177'){
X if(x>0) 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 <commands.c`; then
echo shar: \"commands.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f makeworld.c -a "${1}" != "-c" ; then
echo shar: Will not over-write existing file \"makeworld.c\"
else
echo shar: Extracting \"makeworld.c\" \(22776 characters\)
sed "s/^X//" >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 <ctype.h>
X#include <stdio.h>
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 <conquer -a>. 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;i<MAXX;i++) for(j=0;j<MAXY;j++) {
X tplace[i][j]=0;
X area_map[i][j]=0;
X }
X for(i=0;i<MAPX;i++) for(j=0;j<MAPY;j++) sct[i][j].vegetation=NONE;
X
X for(i=0;i<5;i++) number[i] = NUMAREAS/5; /*areas with type=[i]*/
X number[2]=NUMAREAS - 4*number[0]; /*correct for roundoff*/
X
X /*determine # of area types to areas*/
X for(i=0;i<250;i++) {
X if((avvalue*NUMAREAS)>alloc) {
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;X<MAXX;X++) for(Y=0;Y<MAXY;Y++) {
X while(tplace[X][Y] == 0) {
X rnd = rand()%5; /*(0 to 4)*/
X if(number[rnd]>0) {
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<MAXY;Y++) for(X=0;X<MAXX;X++) {
X /*fill in edges*/
X fill_edge(X,Y);
X /*fill in center*/
X for(i=1;i<7;i++) {
X for(j=1;j<7;j++) switch(area_map[X][Y]){
X
X case 0:
X if((rand()%100) < 95) type[X*8+i][Y*8+j]=WATER;
X else type[X*8+i][Y*8+j]=HALF;
X break;
X case 1:
X if(rand()%2 == 0) type[X*8+i][Y*8+j]=WATER;
X else type[X*8+i][Y*8+j]=HALF;
X break;
X case 2:
X if (rand()%2 == 0) type[X*8+i][Y*8+j]=WATER;
X else type[X*8+i][Y*8+j]=LAND;
X break;
X case 3:
X if (rand()%2 == 0) type[X*8+i][Y*8+j]=LAND;
X else type[X*8+i][Y*8+j]=HALF;
X break;
X case 4:
X if ((rand()%100) < 95) type[X*8+i][Y*8+j]=LAND;
X else type[X*8+i][Y*8+j]=HALF;
X break;
X default:
X printf("ERROR");
X }
X }
X }
X
X /*calculate all 50% areas*/
X for(X=0;X<MAPX;X++) for(Y=0;Y<MAPY;Y++) {
X if(type[X][Y] == HALF)
X if(rand()%100 >= (100-PWATER)) {
X type[X][Y] = LAND;
X }
X else type[X][Y] = WATER;
X }
X
X chance=0;
X for(X=0;X<MAPX;X++) for(Y=0;Y<MAPY;Y++)
X if(type[X][Y] == WATER) chance++;
X printf("amount of water is %d / %d sectors\n",chance,MAPX*MAPY);
X
X /*Newly added code to smooth the world out*/
X for(X=1;X<MAPX-1;X++) for(Y=1;Y<MAPY-1;Y++) {
X chance = 0;
X /*count # of land and sea sides*/
X for(i=X-1;i<=X+1;i++) for(j=Y-1;j<=Y+1;j++)
X if(type[i][j] == LAND) chance++;
X if(rand()%9 < chance) type[X][Y] = LAND;
X else type[X][Y] = WATER;
X }
X chance=0;
X for(X=0;X<MAPX;X++) for(Y=0;Y<MAPY;Y++)
X if(type[X][Y] == WATER) chance++;
X printf("smoothing...amount of water is %d / %d sectors\n",chance,MAPX*MAPY);
X
X /*Adjust world given sectors as land or sea, place vegetation,
X designation, and altitude */
X
X for(i=0;i<MAPX;i++) for(j=0;j<MAPY;j++)
X if(type[i][j]==LAND) sct[i][j].altitude = CLEAR;
X else sct[i][j].altitude = WATER;
X
X /*place */
X nmountains= MAPX * MAPY * PMOUNT * ( 100-PWATER ) / (100*100);
X printf("%d mountains to be placed",nmountains);
X
X /* heuristic says that 5 is cutoff number to stop placing ranges */
X while(nmountains>(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(X1<X2)
X y=((Y2-Y1)*(x-X1)/(X2-X1))+Y1;
X else y=Y1;
X if(type[x][y] == LAND){
X if(rand()%100>80) {
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;y<MAPY-1;y++) for(x=1;x<MAPX-1;x++)
X if((sct[x][y].altitude==PEAK)
X ||(sct[x][y].altitude==MOUNTAIN))
X for(i=0;i<=2;i++) for(j=0;j<=2;j++)
X if(sct[x+i-1][y+j-1].altitude==WATER)
X sct[x][y].altitude=HILL;
X
X /*FIGURE OUT SECTOR VEGETATION TYPE
X *use sector.altitude, and sector to determine vegetation
X *from water is distance from nearest water
X */
X
X for(x=0;x<MAPX;x++) for(y=0;y<MAPY;y++)
X if(type[x][y]==LAND)
X {
X sct[x][y].vegetation=(*(veg+3+rand()%5));
X /*if hill then decrement vegetation*/
X if(sct[x][y].altitude==HILL) {
X for(n=3;n<9;n++)
X if(sct[x][y].vegetation==(*(veg+n)))
X sct[x][y].vegetation=(*(veg+n-1));
X if(area_map[x/8][y/8]<=1) sct[x][y].vegetation=VOLCANO;
X }
X else if(sct[x][y].altitude==MOUNTAIN)
X if((rand()%6==4)&&((y>MAPY/2+8)||(y<MAPY/2-8)))
X sct[x][y].vegetation=ICE;
X else sct[x][y].vegetation=(*(veg+2+rand()%3));
X else if(sct[x][y].altitude==PEAK)
X if((rand()%3==0)&&((y>MAPY/2+8)||(y<MAPY/2-8)))
X sct[x][y].vegetation=ICE;
X else sct[x][y].vegetation=VOLCANO;
X }
X
X /*REWORK POLEAR/EQUATORIAL sector.vegetation*/
X /*Determine which areas are North Pole and Equatorial*/
X /*char veg[]="VDW46973JSI~"*/
X /*char veg[]="VDWBLGWFJSI~"*/
X /* 012345678901*/
X
X /*polar work*/
X for(x=0;x<MAPX;x++)
X {
X for(y=0;y<6;y++) if(type[x][y]==LAND)
X {
X if(rand()%4 == 0) sct[x][y].vegetation = ICE;
X else for(n=3;n<10;n++)
X if(sct[x][y].vegetation==(*(veg+n)))
X sct[x][y].vegetation=(*(veg+(n-1)));
X }
X for(y=MAPY-7;y<MAPY;y++) if(type[x][y]==LAND)
X {
X if(rand()%4 == 0) sct[x][y].vegetation = ICE;
X else for(n=3;n<10;n++)
X if(sct[x][y].vegetation==(*(veg+n)) )
X sct[x][y].vegetation=(*(veg+(n-1)));
X }
X }
X
X /*insert equator*/
X for(y=(MAPY/2)-8;y<=(MAPY/2)+8;y++) for(x=0;x<MAPX;x++)
X if(type[x][y]==LAND)
X if(rand()%10 ==0) sct[x][y].vegetation=DESERT;
X /*increment vegetation if between Waste and Jungle*/
X else for(n=2;n<9;n++)
X if((sct[x][y].vegetation==(*(veg+n)))
X &&(sct[x][y].altitude==CLEAR)
X &&(rand()%4==0))
X sct[x][y].vegetation=(*(veg+(n+1)));
X
X /*char veg[]="VDW46973JSI~"*/
X /*char veg[]="VDWBLGWFJSI~"*/
X /* 012345678901*/
X
X for(y=((MAPY/2)-2);y<=((MAPY/2)+2);y++) for(x=0;x<MAPX;x++)
X if((type[x][y]==LAND)&&(sct[x][y].altitude==CLEAR))
X if(rand()%10 == 0) sct[x][y].vegetation=DESERT;
X else if(rand()%10 == 0) sct[x][y].vegetation=JUNGLE;
X else if(rand()%10 == 0) sct[x][y].vegetation=SWAMP;
X /*increment vegetation again, but only Waste to Light*/
X else for(n=2;n<4;n++)
X if(sct[x][y].vegetation==(*(veg+n)))
X sct[x][y].vegetation=(*(veg+(n+1)));
X
X /*expand swamps*/
X for(y=2;y<MAPY;y++) for(x=2;x<MAPX;x++)
X if(sct[x][y].vegetation==SWAMP)
X for(i=0;i<2;i++) for(j=0;j<2;j++)
X if((type[x-i][y-j]==LAND)&&((rand()%3)==0))
X sct[x-i][y-j].vegetation=SWAMP;
X /*expand deserts*/
X for(y=2;y<MAPY;y++) for(x=2;x<MAPX;x++)
X if(sct[x][y].vegetation==DESERT)
X for(i=0;i<2;i++) for(j=0;j<2;j++)
X if((type[x-i][y-j]==LAND)&&((rand()%3)==0))
X sct[x-i][y-j].vegetation=DESERT;
X
X /*change all volcanos to peaks */
X for(y=1;y<MAPY;y++) for(x=1;x<MAPX;x++)
X if(sct[x][y].vegetation==VOLCANO) sct[x][y].altitude=PEAK;
X
X /*make sure no desert is next to water*/
X for(y=1;y<MAPY-1;y++) for(x=1;x<MAPX-1;x++)
X if(sct[x][y].vegetation==DESERT)
X for(i=0;i<=2;i++) for(j=0;j<=2;j++)
X if(sct[x+i-1][y+j-1].altitude==WATER)
X sct[x][y].vegetation=LT_VEG;
X
X /*PLACE EACH SECTOR'S RAW MATERIALS */
X
X printf("\nplacing raw materials\n");
X for(y=0;y<MAPY;y++) for(x=0;x<MAPX;x++) {
X
X /*gold*/
X if(rand()%10==0) sct[x][y].gold=rand()%4+4;
X else if(rand()%4==0) sct[x][y].gold=rand()%4;
X else sct[x][y].gold=0;
X
X /*iron*/
X if(rand()%10==0) sct[x][y].iron=rand()%4+4;
X else if(rand()%4==0) sct[x][y].iron=rand()%4;
X else sct[x][y].iron=0;
X
X /*default designations*/
X sct[x][y].designation=DNODESIG;
X
X /*default owner is unowned*/
X sct[x][y].owner=0;
X }
X printf("populating world\n");
X populate();
X close(tempfd);
X writedata();
X}
X
X/*fill: subroutine to fill in a square edges with land or sea*/
Xvoid
Xfill_edge(AX,AY)
X{
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 register int i;
X int edgearea, X0, Y0, X1, Y1, X2, Y2, X3, Y3, X4, Y4;
X int area;
X
X X0=AX;
X Y0=AY;
X X1=X0-1;
X Y1=Y0;
X X2=X0+1;
X Y2=Y0;
X X3=X0;
X Y3=Y0-1;
X X4=X0;
X Y4=Y0+1;
X
X /*NORMALIZE FOR EDGE OF WORLD*/
X if( X1 < 0 ) X1 = MAXX - 1;
X if( X2 >= 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<NTOTAL;i++) if(i!=NLIZARD) {
X ntn[NLIZARD].dstatus[i]=WAR;
X ntn[i].dstatus[NLIZARD]=WAR;
X }
X
X armynum=0;
X country=NLIZARD;
X /* adjustment to make sure that fair amount of lizards are */
X /* created on the map ... but not too many... */
X while(armynum<(min((MAXARM-2),(MAXARM-2) * MAPX * MAPY / 10000 ))){
X x = (rand()%MAPX);
X y = (rand()%MAPY);
X if(armynum>=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<MAPX&&j<MAPY)
X if(sct[i][j].altitude!=WATER)
X sct[i][j].owner = NLIZARD;
X AMOVE=0;
X AXLOC=x;
X AYLOC=y;
X ASTAT=GARRISON;
X ASOLD=750+100*(rand()%10);
X ATYPE=A_INFANTRY;
X armynum++;
X AMOVE=8;
X AXLOC=x;
X AYLOC=y;
X ASTAT=ATTACK;
X ASOLD=750+100*(rand()%10);
X ATYPE=A_INFANTRY;
X armynum++;
X }
X }
X printf("%d lizards placed\n",armynum/2);
X#endif
X
X /* Place Brigands, Barbarians, and Nomads*/
X#ifdef MONSTER
X armynum=0;
X army2num=0;
X strcpy(ntn[NBARBARIAN].name,"bbarian");
X strcpy(ntn[NBARBARIAN].leader,"shaman");
X strcpy(ntn[NBARBARIAN].passwd,ntn[0].passwd);
X ntn[NBARBARIAN].race=BARBARIAN;
X ntn[NBARBARIAN].powers=KNOWALL;
X ntn[NBARBARIAN].mark='*';
X ntn[NBARBARIAN].active=2;
X ntn[NBARBARIAN].aplus=0;
X ntn[NBARBARIAN].dplus=10;
X ntn[NBARBARIAN].maxmove=4;
X ntn[NBARBARIAN].repro=5;
X for(i=0;i<NTOTAL;i++) if(i!=NBARBARIAN) {
X ntn[NBARBARIAN].dstatus[i]=WAR;
X ntn[i].dstatus[NBARBARIAN]=WAR;
X }
X ntn[NBARBARIAN].dstatus[NBARBARIAN]=NEUTRAL;
X
X strcpy(ntn[NNOMAD].name,"nomad");
X strcpy(ntn[NNOMAD].leader,"khan");
X strcpy(ntn[NNOMAD].passwd,ntn[0].passwd);
X ntn[NNOMAD].powers=KNOWALL;
X ntn[NNOMAD].race=NOMAD;
X ntn[NNOMAD].mark='*';
X ntn[NNOMAD].active=2;
X ntn[NNOMAD].aplus=10;
X ntn[NNOMAD].dplus=0;
X ntn[NNOMAD].maxmove=4;
X ntn[NNOMAD].repro=5;
X for(i=0;i<NTOTAL;i++) if(i!=NNOMAD) {
X ntn[NNOMAD].dstatus[i]=WAR;
X ntn[i].dstatus[NNOMAD]=WAR;
X }
X ntn[NNOMAD].dstatus[NNOMAD]=NEUTRAL;
X
X strcpy(ntn[NPIRATE].name,"pirate");
X strcpy(ntn[NPIRATE].leader,"captain");
X strcpy(ntn[NPIRATE].passwd,ntn[0].passwd);
X ntn[NPIRATE].powers=KNOWALL;
X ntn[NPIRATE].race=PIRATE;
X ntn[NPIRATE].mark='*';
X ntn[NPIRATE].active=2;
X ntn[NPIRATE].aplus=20;
X ntn[NPIRATE].dplus=0;
X ntn[NPIRATE].maxmove=4;
X ntn[NPIRATE].repro=5;
X for(i=0;i<NTOTAL;i++) if(i!=NPIRATE) {
X ntn[NPIRATE].dstatus[i]=WAR;
X ntn[i].dstatus[NPIRATE]=WAR;
X }
X ntn[NPIRATE].dstatus[NPIRATE]=NEUTRAL;
X
X temp=(rand()%10+1)*(rand()%10+1);
X for(i=0;i<temp;i++){
X /*50% chance will be on edge, else anywhere*/
X if(rand()%2==0){
X if(rand()%2==0) {
X x=(rand()%20);
X y=(rand()%20);
X }
X else {
X x=(MAPX-(rand()%20)-1);
X y=(MAPY-(rand()%20)-1);
X }
X if(rand()%2==0) x = rand()%MAPX;
X else y = rand()%MAPY;
X }
X else {
X x = rand()%MAPX;
X y = rand()%MAPY;
X }
X
X /* now place people*/
X if (is_habitable(x,y)&&sct[x][y].owner==0) {
X if(rand()%2==0) {
X sct[x][y].owner = NBARBARIAN;
X country=NBARBARIAN;
X AXLOC=x;
X AYLOC=y;
X ASTAT=ATTACK;
X ASOLD=200+100*(rand()%10);
X ATYPE=A_INFANTRY;
X if(armynum<MAXARM-1) armynum++;
X }
X else {
X sct[x][y].owner = NNOMAD;
X ntn[NNOMAD].arm[army2num].xloc=x;
X ntn[NNOMAD].arm[army2num].yloc=y;
X ntn[NNOMAD].arm[army2num].stat=ATTACK;
X ntn[NNOMAD].arm[army2num].sold=100+100*(rand()%15);
X ntn[NNOMAD].arm[army2num].unittyp=A_CAVALRY;
X if(army2num<MAXARM-1) army2num++;
X }
X }
X else if(nvynum<MAXNAVY) {
X country=NPIRATE;
X NXLOC=x;
X NYLOC=y;
X NWAR=2*(1+rand()%10);
X NCREW=NWAR*SHIPCREW;
X nvynum++;
X }
X }
X printf("all random population placed\n");
X#endif
X
X /*set up god but dont place*/
X strcpy(ntn[0].name,"unowned");
X strcpy(ntn[0].leader,"god");
X ntn[cnum].race=GOD;
X ntn[cnum].mark='-';
X ntn[cnum].active=0;
X ntn[cnum].location=GOD;
X ntn[cnum].powers=KNOWALL;
X cnum++;
X
X if ((fp=fopen(helpfile,"r"))==NULL) {
X printf("\terror on read of %s file\n",helpfile);
X printf("\tdo you wish to use default help file (y or n)?");
X if(getchar()=='y'){
X sprintf(line,"cp %s/%s %s",DEFAULTDIR,helpfile,helpfile);
X printf("\n%s\n",line);
X system(line);
X } else {
X printf("\nOK; no NPC nations used\n");
X return;
X }
X getchar();
X }
X
X#ifdef NPC
X
X /*open npcsfile file*/
X if ((fp=fopen(npcsfile,"r"))==NULL) {
X printf("error on read of %s file\n",npcsfile);
X printf("do you wish to use default NPC nations file (y or n)?");
X if(getchar()=='y'){
X sprintf(line,"%s/%s",DEFAULTDIR,npcsfile);
X if ((fp=fopen(line,"r"))==NULL) {
X printf("\nsorry; error on read of %s file\n",line);
X return;
X } else printf("\nOK; default nations used\n");
X } else {
X printf("\nOK; no NPC nations used\n");
X return;
X }
X }
X else printf("reading npc nation data from file: %s\n",npcsfile);
X
X cnum=1;
X /*set up npc nation*/
X if(fgets(line,80,fp)==NULL) done=TRUE;
X while(done==FALSE) {
X /*read and parse a new line*/
X if(line[0]!='#') {
X sscanf(line,"%s %s %c %c %c %hd %hd %hd %ld %ld %ld %hd %hd",
X ntn[cnum].name,ntn[cnum].leader,&ntn[cnum].race,
X &ntn[cnum].mark,&ntn[cnum].location,&ntn[cnum].aplus,
X &ntn[cnum].dplus,&ntn[cnum].maxmove,&ntn[cnum].tgold,
X &ntn[cnum].tmil,&ntn[cnum].tciv,&ntn[cnum].repro,
X &ntn[cnum].active);
X ntn[cnum].active++;
X ntn[cnum].class=0;
X strcpy(ntn[cnum].passwd,ntn[0].passwd);
X country=cnum;
X if(ntn[country].race==HUMAN){
X ntn[country].powers=WARRIOR;
X exenewmgk(WARRIOR);
X }
X else if(ntn[country].race==DWARF){
X ntn[country].powers=MINER;
X exenewmgk(MINER);
X }
X else if(ntn[country].race==ELF){
X ntn[country].powers=THE_VOID;
X exenewmgk(THE_VOID);
X }
X else if(ntn[country].race==ORC){
X ntn[country].powers=MI_MONST;
X exenewmgk(MI_MONST);
X }
X else ntn[country].powers=WARRIOR;
X ntn[country].tfood= ntn[country].tciv * 3;
X ntn[country].tiron=10000L;
X ntn[country].jewels=10000L;
X printf("\tnation %d: %s",cnum,line);
X cnum++;
X place();
X }
X if(fgets(line,80,fp)==NULL) done=TRUE;
X }
X printf("all npc nations placed\n");
X#endif
X}
END_OF_makeworld.c
if test 22776 -ne `wc -c <makeworld.c`; then
echo shar: \"makeworld.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 4 \(of 8\).
cp /dev/null ark4isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 8 archives.
rm -f ark[1-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0