[comp.sources.games] v06i094: conquer4 - middle earth multi-player game

billr@saab.CNA.TEK.COM (Bill Randle) (06/24/89)

Submitted-by: adb@bu-it.bu.edu (Adam Bryant)
Posting-number: Volume 6, Issue 94
Archive-name: conquer4/Part12
Superseeds: conquer3; Volume 4, Issue 42-49



#! /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 12 (of 14)."
# Contents:  newhelp.c rules spew.c trade.c
# Wrapped by billr@saab on Thu Jun 15 15:20:21 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'newhelp.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'newhelp.c'\"
else
echo shar: Extracting \"'newhelp.c'\" \(10352 characters\)
sed "s/^X//" >'newhelp.c' <<'END_OF_FILE'
X/*conquer : Copyright (c) 1988 by Ed Barlow.
X *  I spent a long time writing this code & I hope that you respect this.
X *  I give permission to alter the code, but not to copy or redistribute
X *  it without my explicit permission.  If you alter the code,
X *  please document changes and send me a copy, so all can have it.
X *  This code, to the best of my knowledge works well,  but it is my first
X *  'C' program and should be treated as such.  I disclaim any
X *  responsibility for the codes actions (use at your own risk).  I guess
X *  I am saying "Happy gaming", and am trying not to get sued in the process.
X *                                                Ed
X*/
X
X/*include files*/
X#include <stdio.h>
X#include "header.h"
X#include "data.h"
X#include "patchlevel.h"
X
Xvoid
Xmain()
X{
X	FILE *fp, *fp2, *fopen();
X	if((fp=fopen("sed.1","w"))==NULL) {
X		printf("cant open sed.1 file\n");
X		exit(FAIL);
X	}
X	/* needed as sed was reaching its limit on number of commands */
X	if((fp2=fopen("sed.2","w"))==NULL) {	
X		printf("cant open sed.2 file\n");
X		exit(FAIL);
X	}
X
X	/* create sed script */
X	fprintf(fp,"s/XOWNER/%s/g\n",OWNER);
X	fprintf(fp,"s/XLOGIN/%s/g\n",LOGIN);
X	fprintf(fp,"s/XVERSION/%s.%d/g\n",VERSION,PATCHLEVEL);
X	fprintf(fp,"s/XPVULCAN/%d/g\n",PVULCAN);
X	fprintf(fp,"s/XPMOUNT/%d/g\n",PMOUNT);
X	fprintf(fp,"s/XDEPLETE/%d/g\n",PDEPLETE);
X	fprintf(fp,"s/XPSTORM/%d/g\n",PSTORM);
X	fprintf(fp,"s/XNTOTAL/%d/g\n",NTOTAL);
X	fprintf(fp,"s/XMAXPTS/%d/g\n",MAXPTS);
X	fprintf(fp,"s/XMAXARM/%d/g\n",MAXARM);
X	fprintf(fp,"s/XTRADEPCT/%d/g\n",TRADEPCT);
X	fprintf(fp,"s/XMAXNAVY/%d/g\n",MAXNAVY);
X	fprintf(fp,"s/XBREAKJIHAD/%ld/g\n",BREAKJIHAD);
X
X	/* check all the defined options */
X#ifdef OGOD
X	fprintf(fp,"s/XOGOD/(True )/g\n");
X#else
X	fprintf(fp,"s/XOGOD/(False)/g\n");
X#endif	
X#ifdef DERVDESG
X	fprintf(fp,"s/XDERVDESG/Dervish can/g\n");
X#else
X	fprintf(fp,"s/XDERVDESG/Dervish cannot/g\n");
X#endif
X#ifdef SYSMAIL
X	fprintf(fp,"s/XSYSMAIL/(True )/g\n");
X#else
X	fprintf(fp,"s/XSYSMAIL/(False)/g\n");
X#endif
X#ifdef SYSV
X	fprintf(fp,"s/XSYSV/(True ) /g\n");
X#endif
X#ifdef BSD
X	fprintf(fp,"s/XSYSV/(False:BSD)/g\n");
X#endif
X#ifdef MONSTER
X	fprintf(fp,"s/XMONSTER/(True )/g\n");
X#else
X	fprintf(fp,"s/XMONSTER/(False)/g\n");
X#endif
X#ifdef NPC
X	fprintf(fp,"s/XNPC/(True )/g\n");
X#else
X	fprintf(fp,"s/XNPC/(False)/g\n");
X#endif
X#ifdef CHEAT
X	fprintf(fp,"s/XCHEAT/(True )/g\n");
X#else
X	fprintf(fp,"s/XCHEAT/(False)/g\n");
X#endif
X#ifdef CMOVE
X	fprintf(fp,"s/XCMOVE/(True )/g\n");
X#else
X	fprintf(fp,"s/XCMOVE/(False)/g\n");
X#endif
X#ifdef RANEVENT
X	fprintf(fp,"s/XRANEVENT/(True )/g\n");
X#else
X	fprintf(fp,"s/XRANEVENT/(False)/g\n");
X#endif
X#ifdef VULCANIZE
X	fprintf(fp,"s/XVULCANIZE/(True )/g\n");
X#else
X	fprintf(fp,"s/XVULCANIZE/(False)/g\n");
X#endif
X#ifdef STORMS
X	fprintf(fp,"s/XSTORMS/(True )/g\n");
X#else
X	fprintf(fp,"s/XSTORMS/(False)/g\n");
X#endif
X#ifdef ORCTAKE
X	fprintf(fp,"s/XORCTAKE/(True )/g\n");
X#else
X	fprintf(fp,"s/XORCTAKE/(False)/g\n");
X#endif
X#ifdef HIDELOC
X	fprintf(fp,"s/XHIDELOC/(True )/g\n");
X#else
X	fprintf(fp,"s/XHIDELOC/(False)/g\n");
X#endif
X#ifdef TRADE
X	fprintf(fp,"s/XTRADE/(True )/g\n");
X#else
X	fprintf(fp,"s/XTRADE/(False)/g\n");
X#endif
X	/* map sectors */
X	fprintf(fp,"s/ZMOUNTAIN/MOUNTAIN (%c)/g\n",MOUNTAIN);
X	fprintf(fp,"s/ZHILL/HILL (%c)/g\n",HILL);
X	fprintf(fp,"s/ZCLEAR/CLEAR (%c)/g\n",CLEAR);
X	fprintf(fp,"s/ZWATER/WATER (%c)/g\n",WATER);
X	fprintf(fp,"s/ZPEAK/PEAK (%c)/g\n",PEAK);
X	fprintf(fp,"s/ZVOLCANO/VOLCANO (%c)/g\n",VOLCANO);
X	fprintf(fp,"s/ZDESERT/DESERT (%c)/g\n",DESERT);
X	fprintf(fp,"s/ZJUNGLE/JUNGLE (%c)/g\n",JUNGLE);
X	fprintf(fp,"s/ZTUNDRA/TUNDRA (%c)/g\n",TUNDRA);
X	fprintf(fp,"s/ZICE/ICE (%c)/g\n",ICE);
X	fprintf(fp,"s/ZSWAMP/SWAMP (%c)/g\n",SWAMP);
X	fprintf(fp,"s/ZGOOD/GOOD (%c)/g\n",GOOD);
X	fprintf(fp,"s/ZFOREST/FOREST (%c)/g\n",FOREST);
X	fprintf(fp,"s/ZLIGHT/LIGHT VEG (%c)/g\n",LT_VEG);
X	fprintf(fp,"s/ZWOOD/WOOD (%c)/g\n",WOOD);
X	fprintf(fp,"s/ZBARREN/BARREN (%c)/g\n",BARREN);
X
X	/* designations */
X	fprintf(fp,"s/ZMINE/MINE      (%c)/g\n",DMINE);
X	fprintf(fp,"s/ZFARM/FARM      (%c)/g\n",DFARM);
X	fprintf(fp,"s/ZGOLD/GOLD MINE (%c)/g\n",DGOLDMINE);
X	fprintf(fp,"s/ZFORT/FORT      (%c)/g\n",DFORT);
X	fprintf(fp,"s/ZDEVASTATED/DEVASTATED(%c)/g\n",DDEVASTATED);
X	fprintf(fp,"s/ZTOWN/TOWN      (%c)/g\n",DTOWN);
X	fprintf(fp,"s/ZCITY/CITY      (%c)/g\n",DCITY);
X	fprintf(fp,"s/ZCAPITOL/CAPITOL   (%c)/g\n",DCAPITOL);
X	fprintf(fp,"s/ZSPECIAL/SPECIAL   (%c)/g\n",DSPECIAL);
X	if (DRUIN=='&')
X	fprintf(fp,"s/ZRUIN/RUIN      (\\%c)/g\n",DRUIN);
X	else
X	fprintf(fp,"s/ZRUIN/RUIN      (%c)/g\n",DRUIN);
X	fprintf(fp,"s/ZUNIVERSITY/UNIVERSITY(%c)/g\n",DUNIVERSITY);
X	fprintf(fp,"s/ZBLACKSMITH/BLACKSMITH(%c)/g\n",DBLKSMITH);
X	fprintf(fp,"s/ZLUMBERYARD/LUMBERYARD(%c)/g\n",DLUMBERYD);
X	fprintf(fp,"s/ZROAD/ROAD      (%c)/g\n",DROAD);
X	fprintf(fp,"s/ZMILL/MILL      (%c)/g\n",DMILL);
X	fprintf(fp,"s/ZGRANARY/GRANARY   (%c)/g\n",DGRANARY);
X	fprintf(fp,"s/ZCHURCH/CHURCH    (%c)/g\n",DCHURCH);
X	fprintf(fp,"s/ZSTOCKADE/STOCKADE  (%c)/g\n",DSTOCKADE);
X	fprintf(fp,"s/ZSTOCKCOST/%d/g\n",STOCKCOST);
X	
X	/* other defines */
X	fprintf(fp,"s/XNORANDEVENTS/%d/g\n",RANEVENT);
X	fprintf(fp,"s/XLANDSEE/%d/g\n",LANDSEE);
X	fprintf(fp,"s/XNAVYSEE/%d/g\n",NAVYSEE);
X	fprintf(fp,"s/XARMYSEE/%d/g\n",ARMYSEE);
X	fprintf(fp,"s/XTAXFOOD/%ld/g\n",TAXFOOD);
X	fprintf(fp,"s/XTAXMETAL/%ld/g\n",TAXMETAL);
X	fprintf(fp,"s/XTAXGOLD/%ld/g\n",TAXGOLD);
X	fprintf(fp,"s/XTAXCITY/%ld/g\n",TAXCITY);
X	fprintf(fp,"s/XTAXTOWN/%ld/g\n",TAXTOWN);
X	fprintf(fp,"s/XSHIPMAINT/%ld/g\n",SHIPMAINT);
X	fprintf(fp,"s/XSHIPCP/%ld/g\n",SHIPHOLD);
X	fprintf(fp,"s/XDESCOST/%ld/g\n",DESCOST);
X	fprintf(fp,"s/XFORTCOST/%ld/g\n",FORTCOST);
X	fprintf(fp,"s/XWARSHPCOST/%ld/g\n",WARSHPCOST);
X	fprintf(fp,"s/XMERSHPCOST/%ld/g\n",MERSHPCOST);
X	fprintf(fp,"s/XGALSHPCOST/%ld/g\n",GALSHPCOST);
X	fprintf(fp,"s/XSHIPCREW/%ld/g\n",SHIPCREW);
X	fprintf(fp,"s/XSHIPHOLD/%d/g\n",SHIPHOLD);
X	fprintf(fp,"s/XWARSPD/%d/g\n",N_WSPD);
X	fprintf(fp,"s/XGALSPD/%d/g\n",N_GSPD);
X	fprintf(fp,"s/XMERSPD/%d/g\n",N_MSPD);
X	fprintf(fp,"s/XSIZESPD/%d/g\n",N_SIZESPD);
X	fprintf(fp,"s/XNMASK/%d/g\n",(int)N_MASK);
X	fprintf(fp,"s/XCITYLIMIT/%d/g\n",CITYLIMIT);
X	fprintf(fp,"s/XMILRATIO/%d/g\n",MILRATIO);
X	fprintf(fp,"s/XMILINCAP/%d/g\n",MILINCAP);
X	fprintf(fp,"s/XBRIBE/%ld/g\n",BRIBE);
X	fprintf(fp,"s/XDESFOOD/%d/g\n",DESFOOD);
X	fprintf(fp,"s/XTOMUCHMINED/%d/g\n",TOMUCHMINED);
X	fprintf(fp,"s/XTOMANYPEOPLE/%d/g\n",TOMANYPEOPLE);
X	fprintf(fp,"s/XABSMAXPEOPLE/%d/g\n",ABSMAXPEOPLE);
X	fprintf(fp,"s/XFINDPERCENT/%d/g\n",FINDPERCENT);
X	fprintf(fp,"s/XTAKEPRICE/%d/g\n",ORCTAKE);
X
X	fprintf(fp,"s/XTGATTR/%d/g\n",TGATTR);
X	fprintf(fp,"s/XOTHRATTR/%d/g\n",OTHRATTR);
X	fprintf(fp2,"s/XGOLDATTR/%d/g\n",GOLDATTR);
X	fprintf(fp2,"s/XFARMATTR/%d/g\n",FARMATTR);
X	fprintf(fp2,"s/XMINEATTR/%d/g\n",MINEATTR);
X	fprintf(fp2,"s/XTOWNATTR/%d/g\n",TOWNATTR);
X	fprintf(fp2,"s/XCITYATTR/%d/g\n",CITYATTR);
X	fprintf(fp2,"s/XCAPATTR/%d/g\n",CITYATTR);
X
X	fprintf(fp2,"s/XDMNTNATTR/%3d/g\n",DMNTNATTR);
X	fprintf(fp2,"s/XDHILLATTR/%3d/g\n",DHILLATTR);
X	fprintf(fp2,"s/XDCLERATTR/%3d/g\n",DCLERATTR);
X	fprintf(fp2,"s/XDCITYATTR/%3d/g\n",DCITYATTR);
X	fprintf(fp2,"s/XDTOWNATTR/%3d/g\n",DTOWNATTR);
X	fprintf(fp2,"s/XDGOLDATTR/%3d/g\n",DGOLDATTR);
X	fprintf(fp2,"s/XDMINEATTR/%3d/g\n",DMINEATTR);
X	fprintf(fp2,"s/XDFOREATTR/%3d/g\n",DFOREATTR);
X	fprintf(fp2,"s/XDWOODATTR/%3d/g\n",DWOODATTR);
X
X	fprintf(fp2,"s/XEMNTNATTR/%3d/g\n",EMNTNATTR);
X	fprintf(fp2,"s/XEHILLATTR/%3d/g\n",EHILLATTR);
X	fprintf(fp2,"s/XECLERATTR/%3d/g\n",ECLERATTR);
X	fprintf(fp2,"s/XECITYATTR/%3d/g\n",ECITYATTR);
X	fprintf(fp2,"s/XETOWNATTR/%3d/g\n",ETOWNATTR);
X	fprintf(fp2,"s/XEGOLDATTR/%3d/g\n",EGOLDATTR);
X	fprintf(fp2,"s/XEMINEATTR/%3d/g\n",EMINEATTR);
X	fprintf(fp2,"s/XEFOREATTR/%3d/g\n",EFOREATTR);
X	fprintf(fp2,"s/XEWOODATTR/%3d/g\n",EWOODATTR);
X
X	fprintf(fp2,"s/XOMNTNATTR/%3d/g\n",OMNTNATTR);
X	fprintf(fp2,"s/XOHILLATTR/%3d/g\n",OHILLATTR);
X	fprintf(fp2,"s/XOCLERATTR/%3d/g\n",OCLERATTR);
X	fprintf(fp2,"s/XOCITYATTR/%3d/g\n",OCITYATTR);
X	fprintf(fp2,"s/XOTOWNATTR/%3d/g\n",OTOWNATTR);
X	fprintf(fp2,"s/XOGOLDATTR/%3d/g\n",OGOLDATTR);
X	fprintf(fp2,"s/XOMINEATTR/%3d/g\n",OMINEATTR);
X	fprintf(fp2,"s/XOFOREATTR/%3d/g\n",OFOREATTR);
X	fprintf(fp2,"s/XOWOODATTR/%3d/g\n",OWOODATTR);
X
X	fprintf(fp2,"s/XHMNTNATTR/%3d/g\n",HMNTNATTR);
X	fprintf(fp2,"s/XHHILLATTR/%3d/g\n",HHILLATTR);
X	fprintf(fp2,"s/XHCLERATTR/%3d/g\n",HCLERATTR);
X	fprintf(fp2,"s/XHCITYATTR/%3d/g\n",HCITYATTR);
X	fprintf(fp2,"s/XHTOWNATTR/%3d/g\n",HTOWNATTR);
X	fprintf(fp2,"s/XHGOLDATTR/%3d/g\n",HGOLDATTR);
X	fprintf(fp2,"s/XHMINEATTR/%3d/g\n",HMINEATTR);
X	fprintf(fp2,"s/XHFOREATTR/%3d/g\n",HFOREATTR);
X	fprintf(fp2,"s/XHWOODATTR/%3d/g\n",HWOODATTR);
X
X	/* magical power costs for races */
X#ifdef ELFMAGIC
X	fprintf(fp2,"s/XEMMAG/%3ldK/g\n",ELFMAGIC/1000L);
X#else
X	fprintf(fp2,"s/XEMMAG/%3ldK/g\n",BASEMAGIC/1000L);
X#endif
X#ifdef DWFMAGIC
X	fprintf(fp2,"s/XDMMAG/%3ldK/g\n",DWFMAGIC/1000L);
X#else
X	fprintf(fp2,"s/XDMMAG/%3ldK/g\n",BASEMAGIC/1000L);
X#endif
X#ifdef HUMMAGIC
X	fprintf(fp2,"s/XHMMAG/%3ldK/g\n",HUMMAGIC/1000L);
X#else
X	fprintf(fp2,"s/XHMMAG/%3ldK/g\n",BASEMAGIC/1000L);
X#endif
X#ifdef ORCMAGIC
X	fprintf(fp2,"s/XOMMAG/%3ldK/g\n",ORCMAGIC/1000L);
X#else
X	fprintf(fp2,"s/XOMMAG/%3ldK/g\n",BASEMAGIC/1000L);
X#endif
X
X	/* civilian power costs for races */
X#ifdef ELFCIVIL
X	fprintf(fp2,"s/XECMAG/%3ldK/g\n",ELFCIVIL/1000L);
X#else
X	fprintf(fp2,"s/XECMAG/%3ldK/g\n",BASEMAGIC/1000L);
X#endif
X#ifdef DWFCIVIL
X	fprintf(fp2,"s/XDCMAG/%3ldK/g\n",DWFCIVIL/1000L);
X#else
X	fprintf(fp2,"s/XDCMAG/%3ldK/g\n",BASEMAGIC/1000L);
X#endif
X#ifdef HUMCIVIL
X	fprintf(fp2,"s/XHCMAG/%3ldK/g\n",HUMCIVIL/1000L);
X#else
X	fprintf(fp2,"s/XHCMAG/%3ldK/g\n",BASEMAGIC/1000L);
X#endif
X#ifdef ORCCIVIL
X	fprintf(fp2,"s/XOCMAG/%3ldK/g\n",ORCCIVIL/1000L);
X#else
X	fprintf(fp2,"s/XOCMAG/%3ldK/g\n",BASEMAGIC/1000L);
X#endif
X
X	/* military power costs for races */
X#ifdef ELFMILIT
X	fprintf(fp2,"s/XEWMAG/%3ldK/g\n",ELFMILIT/1000L);
X#else
X	fprintf(fp2,"s/XEWMAG/%3ldK/g\n",BASEMAGIC/1000L);
X#endif
X#ifdef DWFMILIT
X	fprintf(fp2,"s/XDWMAG/%3ldK/g\n",DWFMILIT/1000L);
X#else
X	fprintf(fp2,"s/XDWMAG/%3ldK/g\n",BASEMAGIC/1000L);
X#endif
X#ifdef HUMMILIT
X	fprintf(fp2,"s/XHWMAG/%3ldK/g\n",HUMMILIT/1000L);
X#else
X	fprintf(fp2,"s/XHWMAG/%3ldK/g\n",BASEMAGIC/1000L);
X#endif
X#ifdef ORCMILIT
X	fprintf(fp2,"s/XOWMAG/%3ldK/g\n",ORCMILIT/1000L);
X#else
X	fprintf(fp2,"s/XOWMAG/%3ldK/g\n",BASEMAGIC/1000L);
X#endif
X	fclose(fp);
X	fclose(fp2);
X	exit(SUCCESS);
X}
END_OF_FILE
if test 10352 -ne `wc -c <'newhelp.c'`; then
    echo shar: \"'newhelp.c'\" unpacked with wrong size!
fi
# end of 'newhelp.c'
fi
if test -f 'rules' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'rules'\"
else
echo shar: Extracting \"'rules'\" \(2497 characters\)
sed "s/^X//" >'rules' <<'END_OF_FILE'
X%PERSON
XPaul Davison
XEd Barlow
XArthur Askey
XFrodo Baggins
XCharlie Chaplin
XRonald McDonald
XJerry Lee Lewis
Xthe Student Union President
XPapa Smurf
XKen Thompson
Xthe government
XEdwina Currie
XMargaret Thatcher
XGeorge Bush
XDickie Davies
XAnne Diamond
XBugs Bunny
X%RUNNING
Xrunning
Xcontrolling
Xbuggering up
Xco-ordinating
Xorganising
X%ILL
Xvomit
Xlaugh
Xcry
Xweep
Xthrow up
Xnausiated
Xwant to puke my guts out
Xsick
Xwant to die when I just look at you
X%PATHETIC
Xpathetic
Xpaltry
Xlaughable
Xinneffective
Xuseless
Xtimewasting
X%THINGS
Xdegenerates
Xreprobates
Xidiots
Xstreet-cleaners
Xtiolet-cleaners
Xmiscreants
Xfreeloaders
Xdrunkards
XConservative voters
Xincompetents
X%GIVEUP
Xgive up
Xfly your armies into the water
Xdouble your tax rate
Xgo to war with me
Xgo to war with everyone but me
Xsell half your land to me
Xburn the capital
Xrelocate your capital
Xget rid of all those stupid farms
Xbuild lots of churches and start praying
Xwait for the black plague
Xlet them eat cake
X%SOLDIERS
Xtroops
Xwarriors
Xpeople
Xpuny peasants
X%RUDETHING
Xkilling children
Xscrewing donkeys
Xraping innocent peasants
Xstamping on ants
Xsleeping
Xdrinking
Xsweeping the floor
Xbanking
X%POWERS
Xmagic powers
Xcombat powers
Xcivilian powers
Xcombat bonuses
Xarmies
Xshrubberies
Xknights who say 'Ni'
X%ANATOMY
Xprivate parts
Xface
Xdouble chin
Xbeer gut
Xfoot
Xleg
Xelbow
Xarm
Xhead
Xbottom
Xlibido
X%THING{a}
X{|a }bucket
X{|an }oven
X{|a }milling machine
X{|a }vat of acid
X{|a }bottomless pit
X{|a }vorpal sword
X{|an }abacus
X{|a }large purple elephant
X{|a }sheep
X{|a }pig
X{|an }albatross
X{|a }dodo
X{|an }IBM PC
X%DESTROYED
Xdestroyed
Xdecimated
Xhappy
Xholding a free rock festival
Xgiving away all its money
Xcommitting suicide
Xchanging its password
Xmore careful
Xless cautious
Xa bit more bloody respectful
X%THOUGHT
Xtold me
Xthought
Xsaid
Xinsisted
Xsuspected
Xwere certain
X%DOING
Xdrafting an army of gorillas
Xdrafting an army of chimpanzees
Xrunning out of food
Xflying into the sea
Xheadbanging all night
Xon the road to ruin
Xreally being stupid
Xbeing amazingly thick
X%ACTION
Xfind your asshole
Xswat a fly
Xhit the broadside of a barn
Xstop a slug
Xkill a dead man
X%MAIN
XEven \PERSON could make a better job of \RUNNING your nation! \!
XYou really make me \ILL! \!
XWhat a \PATHETIC nation of \THINGS you have! \!
XIf I were you I'd \GIVEUP. \!
XYou probably couldn't \ACTION with \THING/a. \!
XYour \SOLDIERS are only good at \RUDETHING. \!
XWhat a \PATHETIC collection of \POWERS you've got. \!
XGo stick your \ANATOMY up \THING/a \!
XYour nation should be \DESTROYED. \!
XMy spies \THOUGHT you were \DOING! \!
X%%
END_OF_FILE
if test 2497 -ne `wc -c <'rules'`; then
    echo shar: \"'rules'\" unpacked with wrong size!
fi
# end of 'rules'
fi
if test -f 'spew.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'spew.c'\"
else
echo shar: Extracting \"'spew.c'\" \(11303 characters\)
sed "s/^X//" >'spew.c' <<'END_OF_FILE'
X/*
X * SPEW.C
X */
X#ifndef lint
Xstatic char *cpr[]={
X"  Copyright 1987 Greg Smith",
X"  Permission is granted to freely use and distribute this software",
X"provided this notice is left attached and no monetary gain is made."
X};
X#endif
X
X/* This file has been adapted from the "spew" program by Paul Davison,
X   pd@cs.qmc.ac.uk, on 1st March 1989. It is part of the conquer game
X   and is subject to the same conditions of use as that game. 	*/
X
X/* This in no way supersceedes the copyright notice noted above */
X
X#include "header.h"
X#include "data.h"
X#ifdef SPEW
X#include <stdio.h>
X#include <ctype.h>
X
Xextern char *malloc();
Xextern int atoi();
Xchar *my_alloc();
Xchar *save();
X
X#ifdef BSD
Xextern char	*index();	/* This may be strchr	*/
Xextern char	*rindex();	/* This may be strrchr	*/
X#else
X#define index(s,c)	strchr(s,c)
X#define rindex(s,c)	strrchr(s,c)
Xextern char	*strchr();	/* This may be index	*/
Xextern char	*strrchr();	/* This may be rindex	*/
X#endif
X
X/*--------------- system configuration ------------------*/
X
X/* define some parameters */
X
X#define MAXCLASS 300		/* max # of classes */
X#define MAXLINE 256		/* max size of input line */
X#define MAXDEF 1000		/* max # bytes in a definition */
X
X/* Define the default rulesfile */
X
X#ifndef DEFFILE
X# define DEFFILE "rules"
X#endif
X
X/* Define the random number generator */
X
Xextern long getpid();
X	/* ROLL(n) returns integer 0..n-1 */
X#define ROLL(n) ((((long)rand()&0x7ffffff)>>5)%(n))
X
X/*---------------------------------------------------*/
X
XFILE *InFile;
X
Xtypedef struct def_struct{
X	int cumul;			/* cumulative weights */
X	char *string;			/* string which defines it */
X	struct def_struct *next;	/* link to next */
X} defn;
Xdefn *process();
X/*
X * within a definition, names of subdefinitions are bracketed in BSLASH
X * and SLASH chars. The whole definition ends with a '\0'.
X * The SLASH character is always follwed by a variant tag - default is ' '.
X */
X#define BSLASH '\\'
X#define SLASH  '/'
X#define VBAR	 '|'
X
Xtypedef struct{
X	int weight;	/* total weight of definitions in class */
X	defn *list;	/* list of them */
X	char *name;	/* name of this class */
X	char *tags;	/* pointer to list of tags */
X} classrec;
X
Xclassrec * Classptr;	/* pointer to array of class records */
Xchar *NullTags = " ";	/* default tags ( shared ) */
Xint Classes;	/* number of them */
Xint HowMany = 1;
Xint CompIn = FALSE;	/* is input file in compressed format? */
Xint CompMain;		/* class # of MAIN class when compressed */
X
Xchar InLine[MAXLINE];
X
Xmakemess(n,fp)
Xint n;
XFILE *fp;
X{
X	char *fname;
X	char main_class[20];
X	int i;
X	HowMany = n;
X
X	fname = DEFFILE;
X	InFile = fopen( fname, "r" );
X	if( InFile == NULL ){
X		fprintf( stderr, "Can\'t open: %s\n", fname );
X		exit(1);
X	}
X	init();
X	if( CompIn ) sprintf( main_class, "%d/ ", CompMain);
X	else	     strcpy( main_class, "MAIN/ ");
X		for(i=0; i<HowMany; ++i) display(main_class,' ',fp);
X}
X
Xinit(){
X	readtext();
X}
Xreadtext(){
X	register classrec *cp;
X	register defn *dp;
X	defn **update;
X	int clcomp();
X
X	Classptr = (classrec *)my_alloc( (unsigned)(MAXCLASS * sizeof(classrec)) );
X	Classes = 0;
X
X	cp = Classptr;
X	readline();
X	if( InLine[0]!='%'){
X		fprintf( stderr,"Class definition expected at: %s\n", InLine);
X		exit(1);
X	}
X	while( InLine[1] != '%' ){
X		if( Classes == MAXCLASS ){
X			fprintf(stderr,"Too many classes -- max = %d\n", MAXCLASS);
X			exit(1);
X		}
X		setup( cp );		/* set up the class struct */
X		readline();
X		if( InLine[0] == '%' ){
X			fprintf( stderr, "Expected class instance at: %s\n", InLine);
X			exit(1);
X		}
X		update = &(cp->list);	/* update pointer */
X		do{
X			dp = process();
X			*update = dp;
X			cp->weight += dp->cumul;	/* add new stuff */
X			dp->cumul = cp->weight;		/* set breakpoint */
X			update = &(dp->next);
X		}while( readline(), InLine[0]!= '%' );
X		++Classes;		/* count them */
X		++cp;
X		*update = NULL;
X	}
X	qsort( (char*)Classptr, Classes, sizeof( classrec ), clcomp);
X}
X/*
X * display is given a class name ( delimited by SLASH, not '\0' ),
X * and will (1) find its class descriptor, by calling lookup
X * (2) pick a definition  (3) output that definition, and
X * recursively display any definitions in it, and convert any escapes.
X * The variant tag after the SLASH is used to pick out the appropriate
X * variants. If that variant tag is '&', the tag 'deftag' is used, which
X * is the active variant of the containing activation.
X */
Xdisplay(s,deftag,fp)
Xchar *s;
Xint deftag;
XFILE *fp;
X{
X	register classrec *cp;
X	register defn *dp;
X	register char *p;
X	classrec *lookup();
X	int i,variant,incurly;
X	register int c,writing;
X
X	if( CompIn ){		/* input is compressed */
X		cp = &Classptr[ atoi(s) ];		/* explicit class # */
X	}else{
X		cp = lookup(s);
X		if( cp == NULL ) {		/* none found */
X			fprintf(fp,"???");
X			while( *s != SLASH ) putc( *s++,fp );
X			fprintf(fp,"???");
X			return;
X		}
X	}
X	c = index(s,SLASH)[1];		/* get variant tag */
X	if( c != '&' ) deftag=c;	/* use given tag */
X	p = index(cp->tags, deftag);		/* look it up */
X	if(p == NULL ){
X		variant = 0;
X		fprintf(fp,"??/%c??", deftag );
X		deftag = ' ';		/* for passing as deftag */
X	}else variant = p - cp->tags;
X
X	i = ROLL( cp->weight );
X	dp = cp->list;
X	while(dp->cumul <= i){	/* pick one based on cumul. weights */
X		dp = dp->next;
X	}
X
X	incurly = 0;		/* not in curlies */
X	writing = 1;		/* writing */
X	p = dp->string;		/* this is the string */
X	for(;;)switch(c = *p++){
X		case '\0': return;
X		case BSLASH:
X			if(( c = *p++) == '\0' ) return; /* ?? */
X			else if( c == '!' ){
X				 if(writing)putc('\n',fp); /* \! = newline */
X			}else if( isalnum(c) ){	/* reference */
X				if(writing)display(p-1,deftag,fp);  /* recurse */
X				while( *p!=SLASH )++p;
X				p += 2;		/* skip variant tag */
X			}else{
X				if(writing) putc(c,fp);
X			}
X			break;
X		case '{':
X			if( !incurly ){
X				incurly = 1;
X				writing = (variant == 0 );
X			}else{
X				if( writing )putc('{',fp);
X			}
X			break;
X		case VBAR:
X			if( incurly ){
X				writing = ( variant == incurly++ );
X			}else{
X				putc(VBAR,fp);
X			}
X			break;
X		case '}':
X			if( incurly ){
X				writing = 1;
X				incurly = 0;
X			}else putc('}',fp);
X			break;
X		default:
X			if( writing) putc(c,fp);
X	}
X}
Xclassrec *
Xlookup( str )		/* delimited by SLASH, not '\0' */
Xchar *str;
X{
X	int first, last, try, comp;
X	int namecomp();
X
X	first = 0;
X	last = Classes-1;
X	while( first <= last ){
X		try = (first+last)>>1;
X		comp = namecomp( str, Classptr[try].name );
X		if( comp == 0 ) return &Classptr[try];
X		if( comp > 0 ) first = try+1;
X		else last = try-1;
X	}
X	return NULL;
X}
Xint namecomp(a,b)	/* 'a' is delim. by SLASH, 'b' by NULL */
Xregister char *a,*b;
X{
X	register int ac;
X	for(;;){
X		ac = *a++;
X		if(ac == SLASH ) ac = '\0';
X		if( ac < *b ) return -1;
X		if( ac > *b++ ) return 1;
X		if( ac == '\0' ) return 0;
X	}
X}
Xreadline(){
X	register char *p;
X	do{
X		if( fgets( InLine, MAXLINE, InFile ) == NULL ){
X			InLine[0] = InLine[1] = '%';
X			InLine[2] = '\0';	/* create EOF */
X		}else if( (p=rindex( InLine, '\n'))!= NULL ) *p = '\0';
X		p = InLine;
X		while( (p = index( p, BSLASH )) != NULL ){
X			if(p[1] == '*' ){
X				*p = 0;	/* kill comment */
X				break;
X			}else ++p;
X		}
X	}while( InLine[0] == '\0' );
X}
X
Xint clcomp(a,b)			
Xregister classrec *a,*b;
X{
X	if( a==b) return 0;
X	return strcmp( a->name, b->name );
X}
Xchar *save(str)
Xchar *str;
X{
X	register char *p;
X	p = (char *) my_alloc( (unsigned)((strlen(str)+1)*sizeof(char)));
X	return strcpy(p,str);
X}
X/*
X * setup a class record. The 'class' line is in InLine.
X */
Xsetup(cp)
Xregister classrec *cp;
X{
X	char temp[100];
X	register char *p,*p2;
X
X	p = &InLine[1];		/* point after the % */
X	while( *p == ' ' )++p;
X	if( !isalnum(*p) ) goto baddec;
X	p2 = temp;
X	do *p2++ = *p++; while( isalnum(*p));
X	*p2 = '\0';
X	cp->weight = 0;		/* save the name of it */
X	cp->name = save( temp );
X	cp->list = NULL;
X	cp->tags = NullTags;	/* by default */
X	for(;;)switch(*p++){
X	case '\0':
X		return;	/* all done; */
X	case ' ':
X		break;		/* allowed those */
X	case '{':		/* tags list */
X		if( cp->tags  != NullTags ) goto baddec; /* already */
X		p2 = temp;
X		*p2++ = ' ';	/* provide null tag */
X		while(*p!='}'){
X			if( !isalnum(*p)) goto baddec;
X			*p2++ = *p++;
X		}
X		++p;	/* junk rh brace */
X		*p2 = 0;
X		cp->tags = save(temp);
X		break;
X	default: goto baddec;
X	}
X  baddec:
X	fprintf(stderr,"Bad class header: %s\n", InLine );
X	exit(1);
X}
X/*
X * create a 'processed' version of the InLine, and return a pointer to
X * the definition. The 'cumul' field is temporarily used to hold the
X * assigned weight of the line.
X */
Xdefn *process(){
X	static char stuff[ MAXDEF ];
X	register char *p,*pout;
X	register defn *dp;
X	register int c;
X
X	dp = (defn *) my_alloc( (unsigned) sizeof( defn ));
X
X	p = InLine;
X	pout = stuff;
X	if( *p == '(' ){		/* get a weight */
X		while(*++p ==' ');	/* scan */
X		if(!isdigit(*p)) goto badweight;
X		c = *p - '0';
X		while(isdigit(*++p)) c = c*10 + (*p - '0' );
X		while( *p == ' ')++p;
X		if( *p != ')') goto badweight;
X		++p;
X		dp->cumul = c;
X	}else{
X		dp->cumul = 1;	/* default weight */
X	}
X	while((c = *p++)!='\0')switch(c){
X	case BSLASH:
X		*pout++ = BSLASH;
X		if( isalnum(*p)){	/* is a ref */
X			do{ *pout++ = *p++;
X			}while( isalnum(*p));
X			*pout++ = SLASH;		/* delimit */
X			if( *p == SLASH ){	/* get variant char */
X				++p;
X				if( !isalnum(*p)&& *p!= ' ' && *p!= '&' ){
X					*pout++ = ' ';
X				}else *pout++ = *p++;
X			}else *pout++ = ' ';
X		}else{
X			*pout++ = *p;
X			if( *p!= '\0'){
X				 ++p;
X			}else{
X				--pout;	/* delete spurious '\' */
X				readline();	/* get new line */
X				p = InLine;	/* point to it */
X			}
X		}
X		break;
X	default:
X		*pout++ = c;
X	}
X	*pout = '\0';
X	dp->string = save( stuff );
X	return dp;
X
X  badweight:
X	fprintf(stderr, "Bad line weight: %s\n", InLine );
X	exit(1);
X	/*NOTREACHED*/
X}
X
Xchar *my_alloc(n)
Xunsigned n;
X{
X	register char *p;
X	p = (char *) malloc( n );
X	if( p==NULL ){
X		fprintf(stderr, "Out Of Memory\n");
X		exit(1);
X	}
X	return p;
X}
X
X
Xcompdef(dp)
Xregister defn *dp;
X{
X	register char *p;
X	register int c;
X	putw( dp-> cumul , stdout );	/* write its cumul weight */
X	p = dp->string;
X	while( (c = *p++) != '\0' ){
X		if( c==BSLASH){
X			if(!CompIn && isalnum(*p) ){	/* a ref */
X				classrec *cp;
X				cp = lookup(p);		/* find it */
X				if( cp == NULL ){
X					fprintf( stderr, "Undefined class: ");
X					while( *p != SLASH ) fputc( *p++, stderr);
X					fputc('\n', stderr );
X					exit(1);
X				}else{
X					printf("%c%d", BSLASH, cp-Classptr );
X					while( *p != SLASH ) ++p;
X				}
X			}else{		/* is escape seq */
X				putchar( BSLASH );
X				putchar( *p++ );
X			}
X		}else{
X			putchar(c);
X		}
X	}
X	putchar(0);
X}
X
Xreadcclass(cp)
Xregister classrec *cp;
X{
X	register int n;
X	register defn *dp;
X	defn **dput;
X
X	char store[MAXDEF];	/* for tags */
X	cp->weight = getw( InFile );
X	instring(store,MAXDEF);
X	cp->tags = ( store[0] == '\0' )? NullTags: save( store );
X	n = getw( InFile );
X	if( n<=0 ) badfile();
X	dput = &(cp->list);	/* link on here */
X	while(n--){
X		dp = (defn *)my_alloc( (unsigned) sizeof( defn));
X		*dput = dp;
X		dp->cumul = getw( InFile );
X		instring(store, MAXDEF );
X		dp->string = save( store );
X		dput = &(dp->next);
X	}
X	*dput = NULL;		/* last one */
X}
X
Xinstring( where, how_many )
Xregister char *where;
Xregister int how_many;
X{
X	register int c;
X	do{
X		c = getc( InFile );
X		if( c == EOF ) badfile();
X		*where++ = c;
X		if( c== '\0' ) return;
X	}while(--how_many);
X	badfile();
X}
Xbadfile(){
X	fprintf(stderr,"Bad file format\n");
X	exit(1);
X}
X#endif SPEW
END_OF_FILE
if test 11303 -ne `wc -c <'spew.c'`; then
    echo shar: \"'spew.c'\" unpacked with wrong size!
fi
# end of 'spew.c'
fi
if test -f 'trade.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'trade.c'\"
else
echo shar: Extracting \"'trade.c'\" \(28415 characters\)
sed "s/^X//" >'trade.c' <<'END_OF_FILE'
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/*
X *  The following file "trade.c" was written by Adam Bryant who
X *  gives all rights to this code to Ed Barlow provided that this
X *  message remains intact.
X */
X
X/* thanks adam -- Ed */
X
X/*	trade.c		*/
X
X/*include files*/
X#include "header.h"
X#include "data.h"
X
X#ifdef TRADE		
X
X/* possible commodities */
X#define TDGOLD   0
X#define TDFOOD   1
X#define TDMETAL  2
X#define TDJEWL   3
X#define TDLAND   4
X#define TDARMY   5
X#define TDSHIP   6
X
X/* constants and indicators */
X#define	NUMPRODUCTS	7
X#define	MAXITM	30
X#define	SELL	0
X#define	BUY	1
X#define	NODEAL	2
X#define	NOSALE	3
X#define TRADECOST(cost)	(100-cost)/100	/* twenty percent cost is normal*/
X
Xextern short country;
X
Xchar *commodities[NUMPRODUCTS] = { "Gold", "Food", "Metal", "Jewels",
X		"Land", "Soldiers", "Ships"};
X#ifdef ADMIN
Xchar *tradefail[NUMPRODUCTS] = { "lack of gold", "lack of food",
X	"lack of metal", "lack of jewels", "land not owned",
X	"no available armies", "no available navies"};
X#endif ADMIN
X#ifdef CONQUER
X/* Use this when you wish to bid something */
Xchar *buylist[NUMPRODUCTS] = { "Bid how much gold? ", "Bid how much food? ",
X	"Bid how much metal? ", "Bid how many jewels? ", "What X location? ",
X	"Bid what army? ", "Bid what navy? "};
X
Xvoid
Xtrade()
X{
X	FILE *tfile;
X	int count, done=FALSE, notopen=FALSE;
X	int buysell, holdint, holdint2, extint, inloop;
X	int type1[MAXITM], type2[MAXITM], deal[MAXITM], extra[MAXITM];
X	int natn[MAXITM], itemnum, getland(), gettrade(), checkland();
X	int tradable();
X	long lvar1[MAXITM], lvar2[MAXITM], holdlong, holdlong2, armyvalue();
X	void tradeerr(), setaside(), takeback();
X	
X	while (done==FALSE) {
X		itemnum=0;
X		done=TRUE;
X		/* open trading file */
X		if ((tfile=fopen(tradefile,"r")) == NULL ) {
X			notopen=TRUE;
X		}
X		/* read in all of the data */
X		while (notopen==FALSE && !feof(tfile)) {
X			fscanf(tfile,"%d %d %d %d %ld %ld %d\n",&deal[itemnum],
X				&natn[itemnum],&type1[itemnum],&type2[itemnum],&lvar1[itemnum],&lvar2[itemnum],&extra[itemnum]);
X			if (deal[itemnum]==NOSALE) {
X				/* remove item from sales list */
X				deal[type1[itemnum]]=NOSALE;
X			} else if (deal[itemnum]==SELL) {
X				itemnum++;
X			}
X		}
X		if (notopen==FALSE) fclose(tfile);
X		clear();
X		/* display header */
X		standout();
X		mvaddstr(0,27,"COMMODITIES EXCHANGE");
X		mvaddstr(1,20,"No Guarantees... All Trades Final");
X		standend();
X		count=3;
X		mvprintw(count,0,"    Nation                       Item            Price");
X		/* give some minor items for purchase */
X		mvprintw(++count,0,"%2d) %-20s",GETFOOD,"Merchants Guild");
X		mvprintw(count,30,"%9ld %s",GODFOOD,commodities[TDFOOD]);
X		mvprintw(count,50,"%9ld %s",GODPRICE,commodities[TDGOLD]);
X		mvprintw(++count,0,"%2d) %-20s",GETMETAL,"Merchants Guild");
X		mvprintw(count,30,"%9ld %s",GODMETAL,commodities[TDMETAL]);
X		mvprintw(count,50,"%9ld %s",GODPRICE,commodities[TDGOLD]);
X		mvprintw(++count,0,"%2d) %-20s",GETJEWL,"Merchants Guild");
X		mvprintw(count,30,"%9ld %s",GODJEWL,commodities[TDJEWL]);
X		mvprintw(count,50,"%9ld %s",GODPRICE,commodities[TDGOLD]);
X
X		/* go through list of commodities */
X		for (holdint=0;holdint<itemnum;holdint++) {
X			if (deal[holdint]==SELL) {
X				count++;
X				mvprintw(count,0,"%2d) %-20s",
X					holdint+1,
X					ntn[natn[holdint]].name);
X
X				if (type1[holdint]==TDLAND) {
X					holdlong = (long) tofood( &sct[(int)lvar1[holdint]][extra[holdint]],0);
X					mvprintw(count,30,"(food=%2ld) %s",
X						holdlong,
X						commodities[type1[holdint]]);
X				} else {
X					holdlong = lvar1[holdint];
X					mvprintw(count,30,"%9ld %s",
X						holdlong,
X						commodities[type1[holdint]]);
X				}
X				if (type2[holdint]==TDLAND) {
X					mvprintw(count,50,"(food=%2ld) %s",
X						lvar2[holdint],
X						commodities[type2[holdint]]);
X				} else {
X				mvprintw(count,50,"%9ld %s",
X					lvar2[holdint],
X					commodities[type2[holdint]]);
X				}
X				if (count>16) {
X					standout();
X					mvaddstr(LINES-2,30,"Hit Any Key to Continue");
X					standend();
X					refresh();
X					getch();
X					clear();
X					standout();
X					mvaddstr(0,27,"COMMODITIES EXCHANGE");
X					standend();
X			    		mvprintw(2,0,"    Nation                       Item            Minimum Price");
X					count=2;
X				}
X			}
X		}
X		standout();
X		count++;
X		count++;
X		mvaddstr(count++,0,"Do you wish to (B)uy, (S)ell, or (U)nsell?");
X		standend();
X		refresh();
X		inloop=TRUE;
X		while (inloop==TRUE) switch(getch()) {
X		case 'b':
X		case 'B':
X			buysell=BUY;
X			mvaddstr(count++,0,"What item number do you want to purchase? ");
X			refresh();
X			holdint = get_number();
X			/* check for minor sales */
X			if (holdint==GETFOOD || holdint==GETMETAL || holdint==GETJEWL) {
X				/* strange flow but less control needed */
X				curntn->tgold-=GODPRICE;
X				if (curntn->tgold<0L) {
X					curntn->tgold+=GODPRICE;
X					tradeerr("You do not have enough gold");
X				}
X				else switch (holdint) {
X				case GETFOOD:
X					curntn->tfood+=GODFOOD;
X					if ( (tfile = fopen(tradefile,"a+"))==NULL) {
X						tradeerr("Error opening file for trading");
X						abrt();
X					}
X					fprintf(tfile, "%d %d %d %d %ld %ld %d\n",BUY, country, GETFOOD, 0, 0, 0, 0);
X					fclose(tfile);
X					break;
X				case GETMETAL:
X					curntn->metals+=GODMETAL;
X					break;
X				case GETJEWL:
X					curntn->jewels+=GODJEWL;
X					break;
X				}
X				inloop=FALSE;
X				done=FALSE;
X				break;
X			} else if (holdint<1 || holdint>itemnum) {
X				tradeerr("Invalid Item Number");
X				return;
X			}
X			holdint--;
X			if (deal[holdint]!=SELL) {
X				tradeerr("Sorry, that item is not on the market.");
X				return;
X			}
X			if (ntn[natn[holdint]].dstatus[country]==UNMET) {
X				tradeerr("That nation has not been met by you");
X				return;
X			}
X			if (ntn[natn[holdint]].dstatus[country]>HOSTILE) {
X				tradeerr("That nation is not doing business with you");
X				return;
X			}
X			/* obtain bid */
X			mvprintw(count++,0,"%s",buylist[type2[holdint]]);
X			refresh();
X			holdlong2 = 0L;
X			holdlong = (long) get_number();
X			/* check for valid bid */
X			switch(type2[holdint]) {
X			case TDGOLD:
X				if (holdlong < lvar2[holdint]) {
X					tradeerr("You underbid the minimum.");
X					buysell=NODEAL;
X				} else if (holdlong > curntn->tgold) {
X					tradeerr("Not Enough Gold");
X					buysell=NODEAL;
X				}
X				break;
X			case TDFOOD:
X				if (holdlong < lvar2[holdint]) {
X					tradeerr("You underbid the minimum.");
X					buysell=NODEAL;
X				} else if (holdlong > curntn->tfood) {
X					tradeerr("Not Enough Food");
X					buysell=NODEAL;
X				}
X				break;
X			case TDMETAL:
X				if (holdlong < lvar2[holdint]) {
X					tradeerr("You underbid the minimum.");
X					buysell=NODEAL;
X				} else if (holdlong > curntn->metals) {
X					tradeerr("Not Enough Iron");
X					buysell=NODEAL;
X				}
X				break;
X			case TDJEWL:
X				if (holdlong < lvar2[holdint]) {
X					tradeerr("You underbid the minimum.");
X					buysell=NODEAL;
X				} else if (holdlong > curntn->jewels) {
X					tradeerr("Not Enough Jewels");
X					buysell=NODEAL;
X				}
X				break;
X			case TDLAND:
X				mvaddstr(count++,0,"What Y position? ");
X				refresh();
X				holdlong2 = (long) get_number();
X				if (checkland(BUY,(int)(holdlong),(int)(holdlong2))==NODEAL) {
X					buysell=NODEAL;
X				} else if (tofood( &sct[(int)holdlong][(int)holdlong2],natn[holdint]) < lvar2[holdint]) {
X					tradeerr("You underbid the minimum");
X					buysell=NODEAL;
X				}
X				break;
X			case TDARMY:
X				if ((int)holdlong > MAXARM) {
X					tradeerr("Invalid Unit");
X					buysell=NODEAL;
X				} else if (tradable(country,(int)holdlong)==FALSE) {
X					tradeerr("That unit type is non-tradable.");
X					buysell=NODEAL;
X				} else if (armyvalue(country,(int)holdlong) < lvar2[holdint]) {
X					tradeerr("You underbid the minimum.");
X					buysell=NODEAL;
X				}
X				holdlong2=holdlong;
X				break;
X			case TDSHIP:
X				if ((int)holdlong >= MAXNAVY) {
X					tradeerr("Invalid Navy");
X					buysell=NODEAL;
X				} else if (flthold((int)holdlong) < (int)lvar2[holdint]) {
X					tradeerr("You underbid the minimum.");
X					buysell=NODEAL;
X				} else if((curntn->nvy[(int)holdlong].armynum!=MAXARM)||(curntn->nvy[(int)holdlong].people!=0)) {
X					tradeerr("Navy must be unloaded first.");
X					buysell=NODEAL;
X				}
X				holdlong2=holdlong;
X				break;
X			default:
X				tradeerr("Invalid Commodity");
X				buysell=NODEAL;
X				break;
X			}
X			if (buysell==BUY) {
X				if ( (tfile = fopen(tradefile,"a+"))==NULL) {
X					tradeerr("Error opening file for trading");
X					abrt();
X				}
X				setaside(country,type2[holdint],holdlong,(int)holdlong,FALSE);
X				fprintf(tfile, "%d %d %d %d %ld %ld %d\n",BUY, country, holdint, 0, holdlong, holdlong2, 0);
X				fclose(tfile);
X			}
X			return;
X		case 's':
X		case 'S':
X			/* sell an item */
X			/* only allow MAXITM on market */
X			if (itemnum>=MAXITM) {
X				standout();
X				if (itemnum==0) mvaddstr(count++,0,"Market Congested.  Hit any key to continue");
X				else mvaddstr(count++,0,"Market Congested.  (B)uy or any key to continue");
X				standend();
X				refresh();
X				break;
X			}
X			buysell=SELL;
X			holdint = gettrade("Selling",&count);
X			if (holdint==(-1)) {
X				tradeerr("Invalid Option");
X				return;
X			}
X
X			mvprintw(count++,0,"%s",buylist[holdint]);
X			refresh();
X			/* find out how much commodities */
X			holdlong = (long) get_number();
X			extint = 0;
X			if (holdint< TDLAND && holdlong==0L)
X				return;
X
X			/* check for valid items */
X			switch(holdint) {
X			case TDGOLD:
X				if (holdlong > curntn->tgold) {
X					tradeerr("Not Enough Gold");
X					buysell=NODEAL;
X				}
X				break;
X			case TDFOOD:
X				if (holdlong > curntn->tfood) {
X					tradeerr("Not Enough Food");
X					buysell=NODEAL;
X				}
X				break;
X			case TDMETAL:
X				if (holdlong > curntn->metals) {
X					tradeerr("Not Enough Iron");
X					buysell=NODEAL;
X				}
X				break;
X			case TDJEWL:
X				if (holdlong > curntn->jewels) {
X					tradeerr("Not Enough Jewels");
X					buysell=NODEAL;
X				}
X				break;
X			case TDLAND:
X				mvprintw(count++,0,"What Y position? ");
X				refresh();
X				extint = get_number();
X				buysell = checkland(SELL,(int)holdlong,extint);
X				break;
X			case TDARMY:
X				if (holdlong>=MAXARM || curntn->arm[(int)holdlong].sold <= 0) {
X					tradeerr("Invalid Army");
X					buysell=NODEAL;
X				} else if (tradable(country,(int)holdlong)==FALSE) {
X					tradeerr("That unit is non-tradable.");
X					buysell=NODEAL;
X				}
X				break;
X			case TDSHIP:
X				if (holdlong>=MAXNAVY || flthold((int)holdlong) <= 0) {
X					tradeerr("Invalid Navy");
X					buysell=NODEAL;
X				} else if((curntn->nvy[(int)holdlong].armynum!=MAXARM)||(curntn->nvy[(int)holdlong].people!=0)) {
X					tradeerr("Navy must be unloaded first.");
X					buysell=NODEAL;
X				}
X				break;
X			default:
X				tradeerr("Invalid Commodity");
X				buysell=NODEAL;
X				break;
X			}
X			/* invalid commodity */
X			if (buysell==NODEAL) return;
X
X			/* find out what they want in trade */
X			holdint2 = gettrade("In Trade For",&count);
X			if (holdint2==(-1)) {
X				tradeerr("Invalid Option");
X				return;
X			}
X			if (holdint2==TDLAND) {
X				holdlong2 = (long) getland(&count);
X				if (holdlong2==(-1L)) {
X					tradeerr("Invalid Vegetation");
X					return;
X				}
X			} else {
X				/* find out for what value */
X				mvprintw(count++,0,"Minimum Amount of %s? "
X					,commodities[holdint2]);
X				refresh();
X				holdlong2 = (long) get_number();
X				if (holdlong2 == 0L) return;
X			}
X
X			/* make sure what was bid is unusable */
X			setaside(country,holdint,holdlong,(int)holdlong,FALSE);
X
X			/* set up output properly */
X			if (holdint==TDARMY) {
X				extint = (int) holdlong;
X				holdlong = armyvalue(country,(int)holdlong);
X			}
X			else if (holdint==TDSHIP) {
X				extint = (int)holdlong;
X				holdlong = (long)flthold(extint);
X			}
X
X			/* send it out */
X			if ( (tfile = fopen(tradefile,"a+"))==NULL) {
X				tradeerr("Error opening file for trading");
X				abrt();
X			}
X			fprintf(tfile, "%d %d %d %d %ld %ld %d\n", SELL, country, holdint, holdint2, holdlong, holdlong2, extint);
X			fclose(tfile);
X			inloop=FALSE;
X			done=FALSE;
X			break;
X		case 'u':
X		case 'U':
X			/* unsell an item */
X			if (itemnum==0) break;
X			mvaddstr(count++,0,"What item number to remove? ");
X			refresh();
X			holdint = get_number();
X			if (holdint==0 || holdint>itemnum) {
X				tradeerr("Invalid Item Number");
X				return;
X			}
X			holdint--;
X#ifdef OGOD
X			/* allow god to remove commodities */
X			if (country!=0 && country!=natn[holdint]) 
X#else 
X			if (country != natn[holdint]) 
X#endif OGOD
X			{
X				tradeerr("That is not your item");
X				return;
X			}
X
X			if (deal[holdint]!=SELL) {
X				tradeerr("That item is not up for sale");
X				return;
X			}
X			
X			/* remove it from market */
X			if ( (tfile = fopen(tradefile,"a+"))==NULL) {
X				tradeerr("Error opening file for trading");
X				abrt();
X			}
X			fprintf(tfile, "%d %d %d %d %ld %ld %d\n", NOSALE, natn[holdint], holdint, 0, 0L, 0L, 0);
X			fclose(tfile);
X			takeback(natn[holdint],type1[holdint],lvar1[holdint],extra[holdint],FALSE);
X			/*redraw the commodities board so removal is seen*/
X			inloop=FALSE;
X			done=FALSE;
X			break;
X		default:
X			/* return on no choice */
X			return;
X		}
X	}
X}
X
Xvoid
Xtradeerr(mesg)
Xchar *mesg;
X{
X	clear_bottom(0);
X	standout();
X	mvaddstr(21,0,mesg);
X	standend();
X	mvaddstr(22,0,"Hit any key to continue");
X	refresh();
X	getch();
X}
X
Xint
Xcheckland(tradestat,xspot,yspot)
Xint tradestat,xspot,yspot;
X{
X	int newstat=tradestat;
X	if (!ONMAP(xspot,yspot)) {
X		tradeerr("That is off the map");
X		newstat=NODEAL;
X	} 
X	else if (sct[xspot][yspot].owner != country) {
X		tradeerr("You don't own it");
X		newstat=NODEAL;
X	}
X	else if (curntn->capx==xspot && curntn->capy==yspot) {
X		tradeerr("That is your capitol");
X		newstat=NODEAL;
X	}
X	else if (sct[xspot][yspot].designation == DTOWN) {
X		tradeerr("Towns may not be sold");
X		newstat=NODEAL;
X	}
X	else if (sct[xspot][yspot].designation == DCITY) {
X		tradeerr("Cities may not be sold");
X		newstat=NODEAL;
X	}
X	return(newstat);
X}
X
X/* get minimum foodvalue for land */
Xint
Xgetland(count)
Xint *count;
X{
X	int	temp;
X	int	i,j;
X	char	entered;
X
X	mvprintw((*count)++,0,"MINIMUM VEGETATION: %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
X	refresh();
X	entered=getch();
X	if(entered!=VOLCANO       &&entered!=JUNGLE
X		&&entered!=DESERT &&entered!=TUNDRA
X		&&entered!=BARREN &&entered!=LT_VEG
X		&&entered!=NONE   &&entered!=GOOD
X		&&entered!=WOOD   &&entered!=FOREST
X		&&entered!=SWAMP  &&entered!=ICE) temp=(-1);
X	else {
X		for(i=0;i<MAPX;i++)
X		for(j=0;j<MAPY;j++) if(sct[i][j].vegetation == entered) {
X			temp = tofood( &sct[i][j],country );
X			i=MAPX+1;
X			j=MAPY+1;
X		}
X	}
X	mvprintw((*count)++,0," JUST ENTERED %c so food value is %d", entered,temp);
X	return(temp);
X}
X
Xint
Xgettrade(saletype,count)
Xchar *saletype;
Xint *count;
X{
X	int hold=(-1);
X
X	mvprintw((*count)++,0,"%s: (G)old, (F)ood, (I)ron, (J)ewels, (L)and, (A)rmy, (S)hips?",saletype);
X	refresh();
X	switch(getch()) {
X	case 'g':
X	case 'G':
X		hold=TDGOLD;
X		break;
X	case 'f':
X	case 'F':
X		/* hold=TDFOOD; */
X		/* temporarily not allow */
X		mvaddstr((*count)++,0," Food Trades Suspended");
X		break;
X	case 'i':
X	case 'I':
X		hold=TDMETAL;
X		break;
X	case 'j':
X	case 'J':
X		hold=TDJEWL;
X		break;
X	case 'l':
X	case 'L':
X		hold=TDLAND;
X		break;
X	case 'a':
X	case 'A':
X		hold=TDARMY;
X		break;
X	case 's':
X	case 'S':
X		/* hold=TDSHIP; */
X		/* temporarily not allow */
X		mvaddstr((*count)++,0," Ship Trades Suspended");
X		break;
X	default:
X		break;
X	}
X	return(hold);
X}
X#endif CONQUER
X
X/* set aside things that are up for bid */
Xvoid
Xsetaside(cntry,item,longval,extint,isup)
Xint cntry,item,isup,extint;
Xlong longval;
X{
X	switch(item)
X	{
X	case TDGOLD:
X		if (isup==FALSE) ntn[cntry].tgold -= longval;
X		break;
X	case TDFOOD:
X		ntn[cntry].tfood -= longval;
X		break;
X	case TDMETAL:
X		if (isup==FALSE) ntn[cntry].metals -= longval;
X		break;
X	case TDJEWL:
X		if (isup==FALSE) ntn[cntry].jewels -= longval;
X		break;
X	case TDLAND:
X		break;
X	case TDARMY:
X		ntn[cntry].arm[extint].smove = 0;
X		ntn[cntry].arm[extint].stat = TRADED;
X		break;
X	case TDSHIP:
X		/* use commodity to hold indicator */
X		ntn[cntry].nvy[extint].smove = 0;
X		ntn[cntry].nvy[extint].commodity = TRADED;
X		break;
X	}
X}
X
X/* regain things that are up for bid */
Xvoid
Xtakeback(cntry,item,longval,extint,isup)
Xint cntry,item,isup,extint;
Xlong longval;
X{
X	switch(item)
X	{
X	case TDGOLD:
X		if (isup==FALSE) ntn[cntry].tgold += longval;
X		break;
X	case TDFOOD:
X		ntn[cntry].tfood += longval;
X		break;
X	case TDMETAL:
X		if (isup==FALSE) ntn[cntry].metals += longval;
X		break;
X	case TDJEWL:
X		if (isup==FALSE) ntn[cntry].jewels += longval;
X		break;
X	case TDLAND:
X		break;
X	case TDARMY:
X		ntn[cntry].arm[extint].stat = DEFEND;
X		break;
X	case TDSHIP:
X		/* use commodity to hold indicator */
X		ntn[cntry].nvy[extint].commodity = 0;
X		break;
X	}
X}
X
X#ifdef ADMIN
X/* give things that were purchased from cntry1 to cntry2 */
Xlong
Xtradeit(cntry1,cntry2,item,longval,extra)
Xint cntry1,cntry2,item,extra;
Xlong longval;
X{
X	int unitnum=(-1),unitcount=0;
X	/* error for -1 returned */
X	long returnval=(-1);
X	switch(item)
X	{
X	case TDGOLD:
X		returnval = longval;
X		ntn[cntry2].tgold += longval * TRADECOST(20);
X		break;
X	case TDFOOD:
X		returnval = longval;
X		ntn[cntry2].tfood += longval * TRADECOST(20);
X		break;
X	case TDMETAL:
X		ntn[cntry2].metals += longval * TRADECOST(20);
X		returnval = longval;
X		break;
X	case TDJEWL:
X		ntn[cntry2].jewels += longval * TRADECOST(20);
X		returnval = longval;
X		break;
X	case TDLAND:
X		if (sct[(int)longval][extra].owner==cntry1) {
X			sct[(int)longval][extra].owner = cntry2;
X			returnval = longval;
X		}
X		break;
X	case TDARMY:
X		/* find army number for cntry2 */
X		/* give army to cntry2 */
X		while(unitnum==(-1)&&unitcount<MAXARM) {
X			if (ntn[cntry2].arm[unitcount].sold<=0) {
X				/* give army to cntry2 */
X				ntn[cntry2].arm[unitcount].sold = ntn[cntry1].arm[extra].sold;
X				ntn[cntry2].arm[unitcount].unittyp = ntn[cntry1].arm[extra].unittyp;
X				ntn[cntry2].arm[unitcount].xloc = ntn[cntry2].capx;
X				ntn[cntry2].arm[unitcount].yloc = ntn[cntry2].capy;
X				ntn[cntry2].arm[unitcount].stat = DEFEND;
X				ntn[cntry2].arm[unitcount].smove = 0;
X				/* remove army from cntry1 */
X				ntn[cntry1].arm[extra].sold = 0;
X				ntn[cntry1].arm[extra].smove = 0;
X				ntn[cntry1].arm[extra].stat = DEFEND;
X				unitnum=unitcount;
X			}
X			unitcount++;
X		}
X		returnval=(long)unitnum;
X		break;
X	case TDSHIP:
X		/* give navy to cntry1 */
X		while(unitnum==(-1)&&unitcount<MAXARM){
X			if ((int)ntn[cntry2].nvy[unitcount].merchant+ntn[cntry2].nvy[unitcount].warships+ntn[cntry2].nvy[unitcount].galleys == 0) {
X				/* give navy to cntry2 */
X				ntn[cntry2].nvy[unitcount].warships = ntn[cntry1].nvy[extra].warships;
X				ntn[cntry2].nvy[unitcount].merchant = ntn[cntry1].nvy[extra].merchant;
X				ntn[cntry2].nvy[unitcount].galleys = ntn[cntry1].nvy[extra].galleys;
X				ntn[cntry2].nvy[unitcount].crew = ntn[cntry1].nvy[extra].crew;
X				ntn[cntry2].nvy[unitcount].xloc = ntn[cntry1].nvy[extra].xloc;
X				ntn[cntry2].nvy[unitcount].yloc = ntn[cntry1].nvy[extra].yloc;
X				ntn[cntry2].nvy[unitcount].commodity = 0;
X				ntn[cntry2].nvy[unitcount].smove = 0;
X				/* remove navy from cntry1 */
X				ntn[cntry1].nvy[extra].smove = 0;
X				ntn[cntry1].nvy[extra].merchant = 0;
X				ntn[cntry1].nvy[extra].warships = 0;
X				ntn[cntry1].nvy[extra].galleys = 0;
X				ntn[cntry1].nvy[extra].crew = 0;
X				ntn[cntry1].nvy[extra].commodity = 0;
X				unitnum=unitcount;
X			}
X			unitcount++;
X		}
X		returnval=(long)unitnum;
X		break;
X	}
X	return(returnval);
X}
X
Xlong
Xgettval(cntry1,cntry2,type,longval,extint)
Xint cntry1, cntry2, extint;
Xlong longval;
X{
X	int returnval=(-1);
X	long armyvalue();
X
X	switch(type) {
X	case TDGOLD:
X	case TDFOOD:
X	case TDMETAL:
X	case TDJEWL:
X		returnval=longval;
X		break;
X	case TDLAND:
X		if (cntry2!=sct[(int)longval][extint].owner)
X		returnval=(long)tofood( &sct[(int)longval][extint],cntry1);
X		break;
X	case TDARMY:
X		if (armyvalue(cntry2,extint)>0)
X		returnval=armyvalue(cntry2,extint);
X		break;
X	case TDSHIP:
X		if (flthold(extint)>0)
X		returnval = (long)flthold(extint);
X		break;
X	}
X	return(returnval);
X}
X
X/* this function sends detailed message to players */
X/* upon completion of a trade */
Xvoid
Xtrademail(cntry1,cntry2,item1,item2,lvar1,lvar2,lvar3,lvar4)
Xint cntry1,cntry2,item1,item2;
Xlong lvar1,lvar2,lvar3,lvar4;
X{
X	FILE *fp[2];
X	int count;
X	char cname[2][12],filename[2][80];
X
X	sprintf(filename[0],"%s%d",msgfile,cntry1);
X	sprintf(filename[1],"%s%d",msgfile,cntry2);
X	strcpy(cname[0],ntn[cntry1].name);
X	strcpy(cname[1],ntn[cntry2].name);
X
X	if ((fp[0]=fopen(filename[0],"a+"))==NULL) {
X		printf("error opening <%s>\n",filename[0]);
X		abrt();
X	}
X	if ((fp[1]=fopen(filename[1],"a+"))==NULL) {
X		printf("error opening <%s>\n",filename[1]);
X		abrt();
X	}
X
X	for (count=0;count<2;count++) {
X		fprintf(fp[count],"Message to %s from Conquer Commerce Commision\n",cname[count]);
X		fprintf(fp[count],"Dated: %s of Year %d\n",PSEASON(TURN),YEAR(TURN));
X		fprintf(fp[count],"\n");
X		fprintf(fp[count],"   Trade transaction between %s and %s completed.\n",cname[1],cname[0]);
X		if (item1<=TDJEWL)
X		fprintf(fp[count],"       Nation %s receives %ld %s\n",cname[1],lvar1,commodities[item1]);
X		else if (item1==TDLAND)
X		fprintf(fp[count],"       Nation %s receives sector %ld, %ld\n",cname[1],lvar1,lvar2);
X		else if (item1==TDARMY)
X		fprintf(fp[count],"       Nation %s receives army #%ld\n",cname[1],lvar1);
X		else if (item1==TDSHIP)
X		fprintf(fp[count],"       Nation %s receives navy #%ld\n",cname[1],lvar1);
X		if (item2<=TDJEWL)
X		fprintf(fp[count],"       Nation %s receives %ld %s\n",cname[0],lvar3,commodities[item2]);
X		else if (item2==TDLAND)
X		fprintf(fp[count],"       Nation %s receives sector %ld, %ld\n",cname[0],lvar3,lvar4);
X		else if (item2==TDARMY)
X		fprintf(fp[count],"       Nation %s receives army #%ld\n",cname[0],lvar3);
X		else if (item2==TDSHIP)
X		fprintf(fp[count],"       Nation %s receives navy #%ld\n",cname[0],lvar3);
X		fprintf(fp[count],"END\n");
X		fclose(fp[count]);
X	}
X}
X#endif ADMIN
X
X#ifdef CONQUER
X/* routine to determine whether or not an army type is tradable */
Xint
Xtradable(cntry,armynum)
Xint cntry,armynum;
X{
X	int oldcntry=country,returnval=FALSE;
X	country=cntry;
X	if ( (ASTAT!=TRADED) && (ASTAT!=ONBOARD) && (ATYPE==A_MERCENARY
X		|| ATYPE==A_SIEGE || ATYPE==A_CATAPULT
X		|| ATYPE==A_ELEPHANT || ATYPE>=MINMONSTER) ) returnval=TRUE;
X	country=oldcntry;
X	return(returnval);
X}
X#endif CONQUER
X
X/* routine to determine commercial value of army */
Xlong armyvalue(cntry,unit)
Xint cntry,unit;
X{
X	long returnval;
X	
X	returnval = ntn[cntry].arm[unit].sold*100 +
X		ntn[cntry].arm[unit].sold * unitattack[ntn[cntry].arm[unit].unittyp%UTYPE];
X	if (ntn[cntry].arm[unit].unittyp >= MINMONSTER) returnval+=ntn[cntry].arm[unit].sold*10;
X	returnval/=100;
X	return(returnval);
X}
X
Xvoid
Xchecktrade()
X{
X	FILE *tfile;
X	int count, itemnum=0, natn[MAXITM];
X	int type1[MAXITM], type2[MAXITM], deal[MAXITM], extra[MAXITM];
X	long lvar1[MAXITM], lvar2[MAXITM];
X	void takeback();
X	void setaside();
X	/* initialize purchase list */
X	for (count=0; count<MAXITM; count++) {
X		deal[count]=(-1);
X	}
X	/* open trading file */
X	if ((tfile = fopen(tradefile,"r")) == NULL) {
X		/* no commodities - no transactions */
X		return;
X	}
X	/* read in all of the transactions */
X	while(!feof(tfile)) {
X		fscanf(tfile,"%d %d %d %d %ld %ld %d\n",&deal[itemnum],
X			&natn[itemnum],&type1[itemnum],&type2[itemnum],&lvar1[itemnum],&lvar2[itemnum],&extra[itemnum]);
X		if (deal[itemnum]==NOSALE) {
X			if (natn[itemnum]==country)
X			takeback(country,type1[type1[itemnum]],lvar1[type1[itemnum]],extra[type1[itemnum]],TRUE);
X		} else if (deal[itemnum]==SELL) {
X			if (natn[itemnum]==country)
X			setaside(country,type1[itemnum],lvar1[itemnum],extra[itemnum],TRUE);
X			itemnum++;
X		} else if (deal[itemnum]==BUY) {
X			if (natn[itemnum]==country) {
X				if (type1[itemnum]==GETFOOD) ntn[country].tfood+=GODFOOD;
X				else setaside(country,type2[type1[itemnum]],lvar1[itemnum],(int)lvar1[itemnum],TRUE);
X			}
X		}
X	}
X	fclose(tfile);
X}
X
X#ifdef ADMIN
Xvoid
Xuptrade()
X{
X	FILE *tfile;
X	int count, itemnum=0, natn[MAXITM];
X	int type1[MAXITM], type2[MAXITM], deal[MAXITM], extra[MAXITM];
X	extern FILE *fnews;
X	void trademail();
X	int whobuy[MAXITM];
X	long tradeit(), buy1[MAXITM], buy2[MAXITM];
X	long price[MAXITM], gettval(), longval1, longval2;
X	long lvar1[MAXITM], lvar2[MAXITM];
X	void takeback();
X
X	/* initialize purchase list */
X	for (count=0; count<MAXITM; count++) {
X		deal[count]=(-1);
X		whobuy[count]=(-1);
X		price[count]=(-1);
X	}
X	/* open trading file */
X	if ((tfile = fopen(tradefile,"r")) == NULL) {
X		/* no commodities - no transactions */
X		return;
X	}
X	/* read in all of the transactions */
X	while(!feof(tfile)) {
X		fscanf(tfile,"%d %d %d %d %ld %ld %d\n",&deal[itemnum],
X			&natn[itemnum],&type1[itemnum],&type2[itemnum],&lvar1[itemnum],&lvar2[itemnum],&extra[itemnum]);
X		if (deal[itemnum]==NOSALE) {
X			/* remove item from sales list */
X			deal[type1[itemnum]]=NOSALE;
X		} else if (deal[itemnum]==SELL) {
X			itemnum++;
X		} else if (deal[itemnum]==BUY) {
X			if (type1[itemnum]==GETFOOD) /* just ignore food */;
X			else if (deal[type1[itemnum]]==SELL &&
X			(price[type1[itemnum]] <
X			gettval(natn[type1[itemnum]],natn[itemnum],
X			type2[type1[itemnum]],lvar1[itemnum],(int)lvar2[itemnum]))) {
X				deal[type1[itemnum]]=BUY;
X				/* highest bid so far */
X				price[type1[itemnum]]=gettval(natn[type1[itemnum]],natn[itemnum],type2[type1[itemnum]],lvar1[itemnum],(int)lvar2[itemnum]);
X				/* return bid to loser */
X				takeback(whobuy[type1[itemnum]],
X					type2[type1[itemnum]],
X					buy1[type1[itemnum]],(int)buy2[type1[itemnum]],FALSE);
X				/* record details of trade */
X				buy1[type1[itemnum]]=lvar1[itemnum];
X				buy2[type1[itemnum]]=lvar2[itemnum];
X				whobuy[type1[itemnum]]=natn[itemnum];
X			} else {
X				/* return bid */
X				takeback(whobuy[itemnum],
X					type2[type1[itemnum]],
X					lvar1[itemnum],(int)lvar2[itemnum],FALSE);
X			}
X		}
X	}
X	unlink(tradefile);
X	/* reopen the file for unsold commodities */
X	if ((tfile=fopen(tradefile,"w")) == NULL) {
X		/* error on opening file */
X		printf("Error opening <%s> for trade update\n",tradefile);
X		abrt();
X	}
X
X	/* compute the trading */
X	for (count=0;count<itemnum;count++) {
X		if (deal[count]==SELL) {
X			/* adjust the displayed value */
X			lvar1[count]=gettval(0,natn[count],type1[count],lvar1[count],extra[count]);
X			/* keep unsold items up for sale */
X			if(lvar1[count]>=0) fprintf(tfile,"%d %d %d %d %ld %ld %d\n", deal[count], natn[count],type1[count],type2[count],lvar1[count],lvar2[count],extra[count]);
X		} else if (deal[count]==BUY) {
X			/* do the trading */
X			longval1 = tradeit(natn[count],whobuy[count],type1[count],lvar1[count],extra[count]);
X			if (longval1!=(-1)) longval2 = tradeit(whobuy[count],natn[count],type2[count],buy1[count],(int)buy2[count]);
X			if (longval1==(-1)) {
X				/* abort due to seller */
X				fprintf(fnews,"2.\tTrade between %s and %s breaks down due to %s.\n",
X					ntn[natn[count]].name,ntn[whobuy[count]].name,tradefail[type1[count]]);
X			} else if (longval2==(-1)) {
X				/* abort due to buyer */
X				tradeit(whobuy[count],natn[count],type1[count],longval1,extra[count]);
X				fprintf(fnews,"2.\tTrade between %s and %s breaks down due to %s.\n",
X					ntn[whobuy[count]].name,ntn[natn[count]].name,tradefail[type2[count]]);
X				/* place it on the list for next turn */
X				/* adjust the displayed value */
X				lvar1[count]=gettval(0,natn[count],type1[count],lvar1[count],extra[count]);
X				if(lvar1[count]>=0) fprintf(tfile,"%d %d %d %d %ld %ld %d\n", SELL, natn[count],type1[count],type2[count],lvar1[count],lvar2[count],extra[count]);
X			} else {
X				/* trade completed send mail */
X				fprintf(fnews,"2.\tNation %s sells %s to %s for %s\n"
X					,ntn[natn[count]].name,commodities[type1[count]],ntn[whobuy[count]].name,commodities[type2[count]]);
X				trademail(natn[count],whobuy[count],type1[count],
X					type2[count],longval1,(long)extra[count],
X					longval2,buy2[count]);
X			}
X		}
X	}
X	fclose(tfile);
X}
X#endif ADMIN
X#endif TRADE
END_OF_FILE
if test 28415 -ne `wc -c <'trade.c'`; then
    echo shar: \"'trade.c'\" unpacked with wrong size!
fi
# end of 'trade.c'
fi
echo shar: End of archive 12 \(of 14\).
cp /dev/null ark12isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 14 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0