games@tekred.TEK.COM (06/17/88)
Submitted by: ihnp4!homxc!smile Comp.sources.games: Volume 4, Issue 47 Archive-name: conquer3/Part06 #! /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 6 (of 8)." # Contents: data.h magic.c main.c # Wrapped by billr@saab on Thu Jun 16 09:40:01 1988 PATH=/bin:/usr/bin:/usr/ucb ; export PATH if test -f data.h -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"data.h\" else echo shar: Extracting \"data.h\" \(13697 characters\) sed "s/^X//" >data.h <<'END_OF_data.h' X/* conquer : Copyright (c) 1988 by Ed Barlow. */ X X/*--------I DO BELIEVE IT IS NECESSARY TO ALTER THIS FILE-------------------*/ X#define FAIL 1 /* fail return to shell */ X#define SUCCESS 0 /* successful return to shell */ X#define BIG 500000000L /* BIGGER THAN ANYTHING SHOULD BE */ X X#include <curses.h> X/* sometimes curses.h defines TRUE ...but doesn't */ X/* check if already defined */ X#ifndef TRUE X#define TRUE 1 X#define FALSE 0 X#endif X X/* these defines are for types of magic */ X#define M_MIL 1 X#define M_CIV 2 X#define M_MGK 3 X X/*simple contour map definitions*/ X#define WATER (*(ele+0)) X#define PEAK (*(ele+1)) X#define MOUNTAIN (*(ele+2)) X#define HILL (*(ele+3)) X#define CLEAR (*(ele+4)) X X/*racial types*/ X#define GOD '-' X#define ORC 'O' X#define ELF 'E' X#define DWARF 'D' X#define LIZARD 'L' X#define HUMAN 'H' X#define PIRATE 'P' X#define BARBARIAN 'B' X#define NOMAD 'N' X#define TUNKNOWN '?' X X/*designations*/ X#ifdef 1 X#define DCITY 't' X#define DCAPITOL 'c' X#define DMINE 'm' X#define DFARM 'f' X#define DDEVASTATED 'x' X#define DGOLDMINE '$' X#define DCASTLE '!' X#define DNODESIG '-' X#else X#define DCITY (*(des+0)) X#define DCAPITOL (*(des+1)) X#define DMINE (*(des+2)) X#define DFARM (*(des+3)) X#define DDEVASTATED (*(des+4)) X#define DGOLDMINE (*(des+5)) X#define DCASTLE (*(des+6)) X#define DNODESIG (*(des+7)) X#endif X X/* nation placement variables */ X#define GREAT 'G' X#define FAIR 'F' X#define RANDOM 'R' X#define OOPS 'X' X X/*vegetation types -- these are legal in designations too*/ X#define VOLCANO (*(veg+0)) X#define DESERT (*(veg+1)) X#define TUNDRA (*(veg+2)) X#define BARREN (*(veg+3)) X#define LT_VEG (*(veg+4)) X#define GOOD (*(veg+5)) X#define WOOD (*(veg+6)) X#define FOREST (*(veg+7)) X#define JUNGLE (*(veg+8)) X#define SWAMP (*(veg+9)) X#define ICE (*(veg+10)) X#define NONE (*(veg+11)) X X/*Diplomacy Variables*/ X#define JIHAD 7 X#define WAR 6 X#define HOSTILE 5 X#define NEUTRAL 4 X#define FRIENDLY 3 X#define ALLIED 2 X#define CONFEDERACY 1 X#define UNMET 0 X X/*army status*/ X#define MARCH 1 /*March */ X#define SCOUT 2 /*Scouting--will not engage enemy if possible*/ X#define ATTACK 3 /*Attack anybody (Hostile+) within 2 sectors*/ X#define DEFEND 4 /*Defend */ X#define GARRISON 5 /*Garrison--for a city or Capitol */ X Xstruct s_sector X{ X char designation; /*designation of sector*/ X char altitude; /*sector altitude */ X char vegetation; /*sector vegetation */ X short owner; /*nation id of owner, MAXNTN+? is SPECIAL*/ X int people; /*civilians in sector*/ X short i_people; /* initial civilians in sector */ X unsigned char gold; /*gold production ability*/ X unsigned char fortress; /*fortification level (0 to 9)*/ X unsigned char iron; /*amount of iron produced by sector*/ X}; X#define SOWN sct[xcurs+xoffset][ycurs+yoffset].owner X#define XREAL (xcurs+xoffset) X#define YREAL (ycurs+yoffset) X X#define SCREEN_X_SIZE ( (COLS - 21) / 2 ) X#define SCREEN_Y_SIZE ( LINES - 5 ) X X#define PASSLTH 7 /*one less than the characters in the password*/ X#define NAMELTH 9 /*one less than the characters in the name*/ X#define LEADERLTH 9 /*one less than the characters in the leader*/ X Xstruct navy X{ X short warships; X short merchant; X short xloc; X short yloc; X short smove; X short crew; X short armynum; X}; X X#define A_MILITIA 0 X#define A_GOBLIN 1 X#define A_ORC 2 X#define A_INFANTRY 3 X#define A_SAILOR 4 X#define A_MARINES 5 X#define A_ARCHER 6 X#define A_URUK 7 X#define A_NINJA 8 X#define A_PHALANX 9 X#define A_OLOG 10 X#define A_LEGION 11 X#define A_DRAGOON 12 X#define A_MERCENARY 13 X#define A_TROLL 14 X#define A_ELITE 15 X#define A_LT_CAV 16 X#define A_CAVALRY 17 X#define A_CATAPULT 18 X#define A_SEIGE 19 X#define A_ROC 20 X#define A_KNIGHT 21 X#define A_GRIFFON 22 X#define A_ELEPHANT 23 X#define NOUNITTYPES 23 /*number of unit types*/ X X#define MINLEADER 124 /* min value of a leader -1*/ X#define A_LEADER 124 X#define MAXLEADER 124 /* max value for leader */ X X#define MINMONSTER 225 /* min value of a monster -1*/ X#define SPIRIT 225 X#define ASSASSIN 226 X#define DJINNI 227 X#define GARGOYLE 228 X#define WRAITH 229 X#define HERO 230 X#define CENTAUR 231 X#define GIANT 232 X#define SUPERHERO 233 X#define MUMMY 234 X#define ELEMENTAL 235 X#define MINOTAUR 236 X#define DEMON 237 X#define BALROG 238 X#define DRAGON 239 X#define MAXMONSTER 239 X Xstruct army X{ X short unittyp; X short xloc; X short yloc; X short smove; X int sold; X short stat; X}; X Xstruct nation /* player nation stats */ X{ X char name[NAMELTH+1];/* name */ X char passwd[PASSLTH+1];/* password */ X char leader[LEADERLTH+1];/* leader title */ X char race; /* national race (integer--see header.h)*/ X short class; /* national class*/ X char location; /* location variable gfr */ X char mark; /* unique mark for nation*/ X short capx; /* Capitol x coord */ X short capy; /* Capitol y coord */ X short active; /* activity level of nation, not sure if X i have used this variable consistently: X 1 if PC NATION, X 2+Aggressiveness if NPC, X 0 if inactive, X 999 to represents MONSTER (pirate...)*/ X short aplus; /* attack plus of all soldiers*/ X short dplus; /* attack plus of all soldiers*/ X short maxmove; /* maximum movement of soldiers*/ X short repro; /* reproduction rate of nation*/ X long score; /* score */ X long tgold; /* gold in treasury */ X long jewels; /* raw amount of gold in treasury */ X long tmil; /* total military */ X long tciv; /* total civilians */ X long tiron; /* total real iron in nation*/ X long tfood; /* total food in nation*/ X long powers; X short spellpts; /* spell points */ X short tsctrs; /* total number sectors */ X short tships; /* number warships */ X struct army arm[MAXARM]; X struct navy nvy[MAXNAVY]; X short dstatus[MAXNTN+4]; /*diplomatic status*/ X}; X X#define ATYPE ntn[country].arm[armynum].unittyp X#define AXLOC ntn[country].arm[armynum].xloc X#define AYLOC ntn[country].arm[armynum].yloc X#define AMOVE ntn[country].arm[armynum].smove X#define ASOLD ntn[country].arm[armynum].sold X#define ASTAT ntn[country].arm[armynum].stat X#define NWAR ntn[country].nvy[nvynum].warships X#define NMER ntn[country].nvy[nvynum].merchant X#define NCREW ntn[country].nvy[nvynum].crew X#define NXLOC ntn[country].nvy[nvynum].xloc X#define NYLOC ntn[country].nvy[nvynum].yloc X#define NMOVE ntn[country].nvy[nvynum].smove X Xextern struct s_sector sct[MAPX][MAPY]; Xextern struct nation ntn[MAXNTN+4]; Xextern short movecost[MAPX][MAPY]; X/*is sector occupied, if MAXNTN+1 2+ armies occupy*/ Xextern char occ[ MAPX ][ MAPY ]; X X#define AORN 0 X#define ARMY 1 X#define NAVY 2 X X#define XASTAT 1 X#define XAMEN 2 X#define XALOC 4 X#define XNLOC 5 X#define XNASHP 6 X#define XECNAME 8 X#define XECPAS 9 X#define EDSPL 10 X#define XSADES 11 X#define XSACIV 12 X#define XSIFORT 13 X#define XNAGOLD 14 X#define XAMOV 15 X#define XNMOV 16 X#define XSAOWN 17 X#define EDADJ 18 X#define XNARGOLD 19 X#define XNAIRON 20 X#define INCAPLUS 22 X#define INCDPLUS 23 X#define CHG_MGK 24 X#define DESTRY 25 X X#define DESTROY fprintf(fexe,"DESTROY \t%d \t%d \t%hd \t0 \t0 \t%s\n",DESTRY,save,country,"null") X#define CHGMGK fprintf(fexe,"L_MAGIC \t%d \t%hd \t%ld \t%ld \t0 \t%s\n",CHG_MGK,country,ntn[country].powers,x,"null") X#define I_APLUS fprintf(fexe,"INC_APLUS \t%d \t%hd \t0 \t0 \t0 \t%s\n",INCAPLUS,country,"null") X#define I_DPLUS fprintf(fexe,"INC_DPLUS \t%d \t%hd \t0 \t0 \t0 \t%s\n",INCDPLUS,country,"null") X#define AADJSTAT fprintf(fexe,"A_STAT \t%d \t%hd \t%d \t%d \t0 \t%s\n",XASTAT,country,armynum,ntn[country].arm[armynum].stat,"null") X#define AADJMEN fprintf(fexe,"L_ADJMEN \t%d \t%hd \t%d \t%d \t%d \t%s\n",XAMEN ,country,armynum,ASOLD,ATYPE,"null") X#define NADJSHP fprintf(fexe,"N_ASHP \t%d \t%hd \t%d \t%d \t%d \t%s\n",XNASHP ,country,nvynum,ntn[country].nvy[nvynum].merchant,ntn[country].nvy[nvynum].warships,"null" ) X#define AADJLOC fprintf(fexe,"A_LOC \t%d \t%hd \t%d \t%d \t%d \t%s\n",XALOC ,country,armynum,ntn[country].arm[armynum].xloc,ntn[country].arm[armynum].yloc,"null") X#define NADJLOC fprintf(fexe,"N_LOC \t%d \t%hd \t%d \t%d \t%d \t%s\n",XNLOC ,country,nvynum,ntn[country].nvy[nvynum].xloc,ntn[country].nvy[nvynum].yloc ,"null") X#define AADJMOV fprintf(fexe,"A_MOV \t%d \t%hd \t%d \t%d \t0 \t%s\n",XAMOV ,country,armynum,ntn[country].arm[armynum].smove,"null") X#define NADJMOV fprintf(fexe,"N_MOV \t%d \t%hd \t%d \t%d \t0 \t%s\n",XNMOV ,country,nvynum,ntn[country].nvy[nvynum].smove,"null") X#define ECHGNAME fprintf(fexe,"E_CNAME \t%d \t%hd \t0 \t0 \t0 \t%s\n",XECNAME ,country,ntn[country].name) X#define ECHGPAS fprintf(fexe,"E_CPAS \t%d \t%hd \t0 \t0 \t0 \t%s\n",XECPAS ,country,crypt(string,SALT)) X#define SADJDES fprintf(fexe,"S_ADES \t%d \t%hd \t0 \t%d \t%d \t%c\n",XSADES ,country,xcurs+xoffset,ycurs+yoffset,sct[xcurs+xoffset][ycurs+yoffset].designation) X#define SADJDES2 fprintf(fexe,"S_ADES \t%d \t%hd \t0 \t%d \t%d \t%c\n",XSADES ,country,x,y,sct[x][y].designation) X#define SADJCIV2 fprintf(fexe,"S_ACIV \t%d \t%hd \t%d \t%d \t%d \t%s\n",XSACIV ,country,sct[i][j].people,i,j,"null") X#define SADJCIV fprintf(fexe,"S_ACIV \t%d \t%hd \t%d \t%d \t%d \t%s\n",XSACIV ,country,sct[xcurs+xoffset][ycurs+yoffset].people,xcurs+xoffset,ycurs+yoffset,"null") X#define INCFORT fprintf(fexe,"SIFORT \t%d \t%hd \t0 \t%d \t%d \t%s\n",XSIFORT ,country,xcurs+xoffset,ycurs+yoffset,"null") X#define SADJOWN fprintf(fexe,"S_AOWN \t%d \t%hd \t0 \t%d \t%d \t%s\n",XSAOWN ,country,xcurs+xoffset,ycurs+yoffset,"null") X#define EADJDIP fprintf(fexe,"E_ADJ \t%d \t%hd \t%d \t%d \t0 \t%s\n",EDADJ,country,nation,ntn[country].dstatus[nation],"null") X#define EDECSPL fprintf(fexe,"E_SPL \t%d \t%hd \t%d \t%d \t0 \t%s\n",EDSPL,country,s_cost,0,"null") X X#define S_MIL 0 /* position in powers array */ X#define WARRIOR 0x00000001L X#define CAPTAIN 0x00000002L X#define WARLORD 0x00000004L X#define ARCHER 0x00000008L X#define CAVALRY 0x00000010L X#define SAPPER 0x00000020L X#define ARMOR 0x00000040L X#define AVIAN 0x00000080L X#define MI_MONST 0x00000100L X#define AV_MONST 0x00000200L X#define MA_MONST 0x00000400L X#define E_MIL 11 X /*CIVILIAN POWERS */ X#define S_CIV 11 X#define SLAVER 0x00000800L X#define DERVISH 0x00001000L X#define HIDDEN 0x00002000L X#define ARCHITECT 0x00004000L X#define HEALER 0x00008000L X#define MINER 0x00010000L X#define BREEDER 0x00020000L X#define URBAN 0x00040000L X#define STEEL 0x00080000L X#define NINJA 0x00100000L X#define SAILOR 0x00200000L X#define DEMOCRACY 0x00400000L X#define ROADS 0x00800000L X#define E_CIV 13 X /* MAGICAL SKILLS */ X#define S_MGK 24 X#define THE_VOID 0x01000000L X#define KNOWALL 0x02000000L X#define DESTROYER 0x04000000L X#define VAMPIRE 0x08000000L X#define SUMMON 0x10000000L X#define WYZARD 0x20000000L X#define SORCERER 0x40000000L X#define E_MGK 7 X#define MAXPOWER 31 /* number of powers */ X X/*my first macro: which will return 1 if the nation has that power*/ X#define magic(NATION,POWER) ((ntn[NATION].powers&(POWER))!=0) X X#define ONMAP (x>=0 && y>=0 && x<MAPX && y<MAPY) X X#ifndef HILIGHT X#define standout() X#endif X X#ifdef BEEP X#define beep() putc('\007',stderr) X#else X#define beep() X#endif X X#ifdef SYSV X#define rand() lrand48() X#define srand(x) srand48(x) X#else X#define rand() random() X#define srand(x) srandom(x) X#endif X X#define FOODTHRESH 3 X#define GOLDTHRESH 10 X#define JEWELTHRESH 10 X X#define SALT "aa" /* salt for crypt */ X X Xextern char *ele; Xextern char *elename[]; Xextern char *veg; Xextern int vegfood[]; Xextern char *vegname[]; Xextern char *numbers; Xextern char *Class[]; Xextern char *races[]; Xextern char *diploname[]; Xextern char *soldname[]; Xextern char *unittype[]; Xextern char *shunittype[]; Xextern int unitminsth[]; Xextern int u_eniron[]; Xextern int u_encost[]; Xextern int unitmaint[]; Xextern char *des; Xextern char *desname[]; Xextern char *pwrname[]; Xextern long powers[]; X X#ifdef ADMIN Xextern char *npcsfile; Xextern int unitattack[]; Xextern int unitdefend[]; Xextern int unitmove[]; X#endif ADMIN X X/*file name definitions */ Xextern char *exefile; Xextern char *datafile; Xextern char *msgfile; Xextern char *helpfile; Xextern char *newsfile; Xextern char *isonfile; X X#define abrt() { \ Xfprintf(stderr,"\nSerious Error (File %s, Line %d) - Aborting\n",__FILE__,__LINE__); \ Xexit(FAIL); \ X} X X/* extern everything else */ Xextern long exenewmgk(), getmagic(), getmagic(), getmgkcost(), score_one(); Xextern struct s_sector *rand_sector(); X Xextern void adjarm(),armymove(),armyrpt(),atkattr(),blowup(); Xextern void budget(),change(),cheat(),coffmap(),combat(),construct(); Xextern void defattr(),destroy(),diploscrn(),domagic(),draft(),erupt(); Xextern void fight(),fill_edge(),flee(),fleetrpt(),hangup(),help(); Xextern void highlight(),makemap(),makeside(),makeworld(),monster(),moveciv(); Xextern void mymove(),navalcbt(),newdip(),newdisplay(),newlogin(); Xextern void newspaper(),npcredes(),offmap(),place(),populate(),prep(); Xextern void printele(),printnat(),printscore(),printveg(),pr_ntns(),produce(); Xextern void readdata(),redesignate(),redomil(),reduce(),rmessage(),score(); Xextern void see(),showscore(),update(),updmove(),verifydata(),verify_ntn(); Xextern void verify_sct(),wmessage(),writedata(),getdstatus(),exit(); X Xextern char *crypt(),*strcpy(),*strncpy(),*strcat(),*strncat(); X X#define HI_OWN 0 /* hilight modes */ X#define HI_ARMY 1 X#define HI_NONE 2 X#define HI_YARM 3 X#define HI_MOVE 4 X X#define DI_VEGE 1 /* display modes */ X#define DI_DESI 2 X#define DI_CONT 3 X#define DI_FOOD 4 X#define DI_NATI 5 X#define DI_RACE 6 X#define DI_MOVE 7 X#define DI_DEFE 8 X#define DI_PEOP 9 X#define DI_GOLD 10 X#define DI_IRON 11 X Xextern struct sprd_sht X{ X /* total product at end of turn */ X long food, gold, jewels, iron; X /* revenue this turn */ X long revfood, revjewels, reviron, revcap, revcity; X /* civilians in that type of sector */ X int ingold, iniron, infarm, incity, incap; X int sectors, civilians; X} spread; END_OF_data.h if test 13697 -ne `wc -c <data.h`; then echo shar: \"data.h\" unpacked with wrong size! fi # end of overwriting check fi if test -f magic.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"magic.c\" else echo shar: Extracting \"magic.c\" \(20241 characters\) sed "s/^X//" >magic.c <<'END_OF_magic.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 new login for a new player*/ X#include "header.h" X#include "data.h" X#include <ctype.h> X Xextern short country; Xextern short redraw; Xextern FILE *fexe; Xextern FILE *fnews; X X/*give player one new magic power in current magic (powers)*/ X/*do nothing if that player has that power or it is not permitted*/ X/*getmagic() returns the value of the power gained, and stores it in power*/ X Xlong Xgetmagic(type) Xint type; X{ X long newpower; X int start,end; X switch(type){ X case M_MGK: X start=S_MGK; X end=E_MGK; X break; X case M_CIV: X start=S_CIV; X end=E_CIV; X break; X case M_MIL: X start=S_MIL; X end=E_MIL; X break; X default: X printf("fatal error in num_powers"); X abrt(); X } X newpower=powers[start+(rand()%end)]; X if(newpower==0) { X printf("ILLEGAL POWER"); X abrt(); X } X X if((newpower==WARRIOR)||(newpower==CAPTAIN)||(newpower==WARLORD)){ X if(magic(country,WARRIOR)!=TRUE){ X ntn[country].powers|=WARRIOR; X return(WARRIOR); X } X else if(magic(country,CAPTAIN)!=TRUE){ X ntn[country].powers|=CAPTAIN; X return(CAPTAIN); X } X else if(magic(country,WARLORD)!=TRUE){ X ntn[country].powers|=WARLORD; X return(WARLORD); X } X else return(0L); X }else if((newpower==MI_MONST) ||(newpower==AV_MONST) ||(newpower==MA_MONST)){ X if(ntn[country].race!=ORC) return(0L); X if(magic(country,MI_MONST)!=TRUE){ X ntn[country].powers|=MI_MONST; X return(MI_MONST); X } X else if(magic(country,AV_MONST)!=TRUE){ X ntn[country].powers|=AV_MONST; X return(AV_MONST); X } X else if(magic(country,MA_MONST)==TRUE){ X ntn[country].powers|=MA_MONST; X return(MA_MONST); X } X else return(0L); X }else if(newpower==CAVALRY){ X if(ntn[country].active >= 2) return(0L); /*npc nation*/ X if(magic(country,newpower)==TRUE) return(0L); X ntn[country].powers|=newpower; X return(newpower); X }else if(newpower==URBAN){ X if(magic(country,BREEDER)==TRUE) return(0L); X if(magic(country,newpower)==TRUE) return(0L); X ntn[country].powers|=newpower; X return(newpower); X }else if(newpower==HEALER){ X if(ntn[country].race==ORC) return(0L); X if(magic(country,newpower)==TRUE) return(0L); X ntn[country].powers|=newpower; X return(newpower); X }else if(newpower==KNOWALL){ X#ifdef OGOD X /* only god should have KNOWALL if sectors hidden */ X if(country!=0) return(0L); X#endif X if(magic(country,KNOWALL)==TRUE) return(0L); X ntn[country].powers|=KNOWALL; X return(KNOWALL); X }else if((newpower==SLAVER) X ||(newpower==DERVISH) X ||(newpower==HIDDEN) X ||(newpower==ARCHITECT) X ||(newpower==THE_VOID) X ||(newpower==ARCHER)){ X if(magic(country,newpower)==TRUE) return(0L); X ntn[country].powers|=newpower; X return(newpower); X }else if(newpower==DESTROYER){ X if((ntn[country].race!=ELF)&&(magic(country,DESTROYER)!=TRUE)){ X ntn[country].powers|=DESTROYER; X return(DESTROYER); X } X return(0L); X }else if(newpower==VAMPIRE){ X if((ntn[country].race!=ELF)&&(magic(country,VAMPIRE)!=TRUE)){ X ntn[country].powers|=VAMPIRE; X return(VAMPIRE); X } X return(0L); X }else if(newpower==MINER){ X if((ntn[country].race!=ELF)&&(ntn[country].race!=DWARF)&&(magic(country,MINER)!=TRUE)){ X ntn[country].powers|=MINER; X return(MINER); X } X return(0L); X }else if(newpower==STEEL){ X if(magic(country,STEEL)==TRUE) return(0L); X if(magic(country,MINER)!=TRUE) return(0L); X ntn[country].powers|=STEEL; X return(STEEL); X }else if(newpower==BREEDER){ X if(magic(country,URBAN)==TRUE) return(0L); X if(magic(country,BREEDER)==TRUE) return(0L); X if(ntn[country].race!=ORC) return(0L); X ntn[country].powers|=BREEDER; X return(BREEDER); X } X else if(ntn[country].active >= 2) return(0L); /*npc nation*/ X else if((newpower==NINJA) X ||(newpower==SLAVER) X ||(newpower==SAILOR) X ||(newpower==DEMOCRACY) X ||(newpower==ROADS) X ||(newpower==SUMMON) X ||(newpower==WYZARD) X ||(newpower==SORCERER) X ||(newpower==SAPPER) X ||(newpower==ARMOR) X ||(newpower==AVIAN)){ /* these powers are only for pc's */ X if(magic(country,newpower)==TRUE) return(0L); X ntn[country].powers|=newpower; X return(newpower); X } X else return(0L); X} X#ifdef CONQUER X/*form to interactively get a magic power*/ Xvoid Xdomagic() X{ X int count, done=FALSE, loop=0, i,type; X long price,x; X short isgod=0; X if(country==0) { X isgod=1; X clear(); X mvaddstr(0,0,"WHAT NATION NUMBER:"); X refresh(); X country = get_number(); X } X X while(done==FALSE){ X done=TRUE; X clear(); X count=3; X redraw=TRUE; X standout(); X mvprintw(0,(COLS/2)-15,"MAGIC POWERS FOR %s",ntn[country].name); X mvprintw(count++,30,"1) %d military powers: %ld jewels", X num_powers(country,M_MIL) ,getmgkcost(M_MIL,country)); X mvprintw(count++,30,"2) %d civilian powers: %ld jewels", X num_powers(country,M_CIV) ,getmgkcost(M_CIV,country)); X mvprintw(count++,30,"3) %d magic powers: %ld jewels", X num_powers(country,M_MGK),getmgkcost(M_MGK,country)); X X price = getmgkcost(M_MIL,country); X if(price > getmgkcost(M_CIV,country)) X price = getmgkcost(M_CIV,country); X if(price > getmgkcost(M_MGK,country)) X price = getmgkcost(M_MGK,country); X X standend(); X count=3; X /*print the powers that you have*/ X i=0; X while( powers[i] != 0 ){ X if(magic(country,powers[i])==TRUE) X mvprintw(count++,0,"you have power %s",*(pwrname+i)); X i++; X } X X if(count<=7) count=8; X else count++; X standout(); X mvprintw(count++,0,"YOU HAVE %ld JEWELS IN YOUR TREASURY",ntn[country].jewels); X if(price < ntn[country].jewels){ X mvaddstr(count++,0,"DO YOU WISH TO BUY A RANDOM NEW POWER (enter y or n):"); X standend(); X refresh(); X count++; X if(getch()=='y'){ X done=FALSE; X mvprintw(count++,0,"ENTER SELECTION (1,2,3):"); X refresh(); X type = get_number(); X if(type==M_MIL || type==M_CIV || type==M_MGK){ X price=getmgkcost(type,country); X#ifdef OGOD X if (isgod==TRUE) price=0; X#endif OGOD X if(ntn[country].jewels>=price) { X loop = 0; X while(loop++ < 500) if((x=getmagic(type))!=0){ X ntn[country].jewels -= price; X CHGMGK; X exenewmgk(x); X refresh(); X if (isgod==TRUE) country=0; X return; X } X if (loop >= 500) X mvaddstr(count++,0,"You have too many powers! -- hit any key"); X refresh(); X getch(); X } else { X mvaddstr(count++,0,"NOT ENOUGH JEWELS TO PURCHASE NEW MAGIC -- hit any key"); X refresh(); X getch(); X } X } else { X mvaddstr(count++,0,"INVALID SELECTION -- hit any key"); X refresh(); X getch(); X } X } X } else { X mvaddstr(count++,0,"CAN NOT BUY NEW POWER - hit any key"); X standend(); X refresh(); X getch(); X } X if(magic(country,SUMMON)==TRUE) X done=dosummon(&count); X#ifdef ORCTAKE X if((ntn[country].race==ORC)&&(ntn[country].jewels>=TAKEPRICE)) X done=orctake(&count); X#endif ORCTAKE X#ifdef OGOD X if (isgod==TRUE) { X mvaddstr(count++,0,"GOD: REMOVE A MAGIC POWER? (y or n)"); X refresh(); X if (getch()=='y') killmagk(); X } X#endif OGOD X } X if(isgod==1) country=0; X} X#endif CONQUER X/*do magic for both npcs and pcs in update*/ X/*if target is 0 then it is update and target will be picked randomly*/ Xint Xtakeover(percent,target) Xint percent,target; X{ X int loop=1,y,save,isupdate=0; X save=country; X if(target==country) return(0); X if(target==0) isupdate=1; X country=target; X if(rand()%100<percent){ X loop=0; X y=0; X if (target==0) while(loop==0){ X y++; X country=rand()%MAXNTN; X if((ntn[country].race==ntn[save].race) X &&(ntn[country].active>=2) X &&(country!=save)) loop=1; X else if(y>=500) { X country=save; X return(0); X } X } X sct[ntn[country].capx][ntn[country].capy].owner=save; X if(isupdate==1){ X printf("nation %s taken over by %s\n",ntn[country].name,ntn[save].name); X fprintf(fnews,"1.\tnation %s taken over by %s\n",ntn[country].name,ntn[save].name); X } X else { X DESTROY; X if ((fnews=fopen("/dev/null","w"))==NULL){ X printf("error opening null file\n"); X exit(FAIL); X } X } X destroy(country); X if(isupdate!=1) fclose(fnews); X y=country; X country=save; X return(y); X } X country=save; X return(0); X} X X/*execute new magic*/ Xlong Xexenewmgk(newpower) Xlong newpower; X{ X short x,y; X if(newpower==WARRIOR) { X ntn[country].aplus+=10; X ntn[country].dplus+=10; X return(0L); X } X if(newpower==CAPTAIN) { X ntn[country].aplus+=10; X ntn[country].dplus+=10; X return(0L); X } X if(newpower==WARLORD) { X ntn[country].aplus+=10; X ntn[country].dplus+=10; X return(0L); X } X if(newpower==HEALER) { X if(ntn[country].race==ORC) { X printf("ORCS CANT HAVE HEALER POWER\n"); X abrt(); X } else if(ntn[country].repro<=8){ X ntn[country].repro+=2; X } else if(ntn[country].repro==9){ X ntn[country].repro=10; X ntn[country].dplus+=5; X } else if(ntn[country].repro>=10){ X ntn[country].dplus+=10; X } X return(0L); X } X if(newpower==DESTROYER) { X for(x=ntn[country].capx-3;x<=ntn[country].capx+3;x++) { X for(y=ntn[country].capy-3;y<=ntn[country].capy+3;y++){ X if((ONMAP) X &&(sct[x][y].altitude!=WATER) X#ifdef DERVDESG X &&((rand()%2)==0) X#else X &&(tofood(sct[x][y].vegetation,0)<DESFOOD) X#endif DERVDESG X &&((x!=ntn[country].capx) X ||(y!=ntn[country].capy))){ X sct[x][y].vegetation=DESERT; X sct[x][y].designation=DNODESIG; X } X } X } X updmove(ntn[country].race,country); X return(0L); X } X if(newpower==DERVISH) { X updmove(ntn[country].race,country); X return(0L); X } X if((newpower==MI_MONST) X ||(newpower==AV_MONST) X ||(newpower==MA_MONST) X ||(newpower==KNOWALL) X ||(newpower==HIDDEN) X ||(newpower==THE_VOID) X ||(newpower==ARCHITECT) X ||(newpower==MINER)) X return(0L); X if(newpower==VAMPIRE) { X ntn[country].aplus-=35; X ntn[country].dplus-=35; X ntn[country].maxmove-=2; X return(0L); X } X if(newpower==URBAN) { X if(ntn[country].race==ORC) { X x=ntn[country].repro; X if(ntn[country].repro>=13){ X ntn[country].maxmove+=4; X } X else if(ntn[country].repro>10){ X ntn[country].maxmove+=2*(x-10); X ntn[country].repro=13; X } X else ntn[country].repro+=3; X } X else if(ntn[country].repro<=9){ X ntn[country].repro+=3; X } X else { X ntn[country].maxmove+=2*(ntn[country].repro-9); X ntn[country].repro=12; X } X return(0L); X } X if(newpower==BREEDER) { X ntn[country].repro+=3; X ntn[country].dplus-=10; X ntn[country].aplus-=10; X return(0L); X } X if(newpower==DEMOCRACY){ X ntn[country].repro+=1; X ntn[country].dplus+=10; X ntn[country].aplus+=10; X return(0L); X } X if(newpower==ROADS){ X ntn[country].maxmove+=4; X return(0L); X } X if(newpower==ARMOR){ X ntn[country].maxmove-=3; X if( ntn[country].maxmove<4) ntn[country].maxmove=4; X ntn[country].dplus+=20; X } X if((newpower==NINJA) X ||(newpower==STEEL) X ||(newpower==ARCHER) X ||(newpower==CAVALRY) X ||(newpower==SAILOR) X ||(newpower==SUMMON) X ||(newpower==WYZARD) X ||(newpower==SORCERER) X ||(newpower==SAPPER) X ||(newpower==AVIAN)){ /* these powers are only for pc's */ X return(1L); X } X return(0L); X} X#ifdef CONQUER X/* returns 0 if summon occurred, 1 else */ Xint Xdosummon(count) Xint *count; X{ X int done=TRUE,x,i,armynum; X long e_cost; X int newtype,s_cost; X if((*count)>20) { X (*count)=2; X clear(); X } X mvaddstr((*count)++,0,"YOU HAVE SUMMON POWER"); X mvaddstr((*count)++,0,"DO YOU WISH SUMMON A MONSTER (enter y or n):"); X refresh(); X if(getch()=='y'){ X done=FALSE; X x=0; X mvaddstr((*count)++,x,"options:"); X x+=9; X for(i=MINMONSTER;i<=MAXMONSTER;i++){ X if(unitvalid(i)==TRUE) { X mvprintw((*count),x+2,"%s",*(shunittype+(i%200))); X mvprintw((*count),x,"(%c)",*(shunittype+(i%200))[0]); X x+=7; X if(x>COLS-20){ X x=0; X (*count)++; X } X } X } X (*count)++; X mvaddstr((*count)++,0,"what type of unit do you want to raise:"); X refresh(); X X newtype='0'; X switch(getch()){ X case 's': X newtype=SPIRIT; X break; X case 'A': X newtype=ASSASSIN; X break; X case 'e': X newtype=DJINNI; X break; X case 'G': X newtype=GARGOYLE; X break; X case 'W': X newtype=WRAITH; X break; X case 'H': X newtype=HERO; X break; X case 'C': X newtype=CENTAUR; X break; X case 'g': X newtype=GIANT; X break; X case 'S': X newtype=SUPERHERO; X break; X case 'M': X newtype=MUMMY; X break; X case 'E': X newtype=ELEMENTAL; X break; X case 'm': X newtype=MINOTAUR; X break; X case 'd': X newtype=DEMON; X break; X case 'B': X newtype=BALROG; X break; X case 'D': X newtype=DRAGON; X break; X default: X break; X } X X if(unitvalid(newtype)==FALSE) { X beep(); X mvprintw((*count)++,0,"%d INVALID TYPE",newtype); X refresh(); X sleep(2); X return(done); X } X X e_cost= (long) *(u_encost+(newtype%200)) * *(unitminsth+(newtype%200)); X s_cost= *(u_encost+(newtype%200)); X /*check to see if enough spell points*/ X if(s_cost > ntn[country].spellpts) { X mvprintw((*count)++,0,"you dont have %d spell points",s_cost); X refresh(); X sleep(1); X return(done); X } X X /*check to see if enough gold*/ X if(e_cost > ntn[country].tgold) { X mvprintw((*count)++,0,"you dont have %ld gold in treasury",e_cost); X refresh(); X sleep(1); X return(done); X } X X armynum=0; X while(armynum<MAXARM) { X if(ASOLD<=0) { X ASOLD= *(unitminsth+(newtype%200)); X ATYPE=newtype; X ASTAT=DEFEND; /* set new armies to DEFEND */ X AXLOC=ntn[country].capx; X AYLOC=ntn[country].capy; X AMOVE=0; X AADJLOC; X AADJSTAT; X AADJMEN; X AADJMOV; X armynum=MAXARM; X } else if(armynum==MAXARM-1) { X mvaddstr((*count)++,0,"NO FREE ARMIES"); X refresh(); X sleep(2); X return(done); X } else armynum++; X } X ntn[country].tgold -= e_cost; X ntn[country].spellpts -= s_cost; X EDECSPL; X } X return(done); X} X#endif CONQUER X#ifdef CONQUER X#ifdef ORCTAKE X/* orc takeover routine... returns 0 if run, 1 if not */ Xorctake(count) Xint *count; X{ X int chance=0; X if((*count)>20) { X (*count)=2; X clear(); X } X if(magic((*count)ry,MA_MONST)==TRUE) { X mvaddstr((*count)++,0," You have a 10 percent chance for %ld Jewels take over other orcs",TAKEPRICE); X chance=10; X } else if(magic((*count)ry,AV_MONST)==TRUE) { X mvaddstr((*count)++,0," You have a 6 percent chance for %ld Jewels take over other orcs",TAKEPRICE); X chance=6; X } else if(magic((*count)ry,MI_MONST)==TRUE){ X mvaddstr((*count)++,0," You have a 3 percent chance for %ld Jewels to take over other orcs",TAKEPRICE); X chance=3; X } X if(chance==0) return(1); X X mvprintw((*count)++,0,"DO YOU WISH TO TAKE OVER AN ORC NPC NATION (enter y or n):"); X refresh(); X if(getch()=='y'){ X done=FALSE; X mvaddstr((*count)++,0," What orc nation (number):"); X refresh(); X i=get_number(); X if(ntn[i].race==ORC){ X ntn[(*count)ry].jewels-=TAKEPRICE; X if((i=takeover(chance,i))==1) X mvprintw((*count)++,0," Successful: %d",i); X } X else mvaddstr((*count)++,0," Wrong Race"); X } X return(done); X} X#endif ORCTAKE X#endif CONQUER X#ifdef CONQUER X/* unitvalid tells if nation has powers needed to draft unit */ Xint Xunitvalid(type) Xint type; X{ X int valid=FALSE; X switch(type){ X case GARGOYLE: X case A_GOBLIN: X case A_ORC: if(magic(country,MI_MONST)==TRUE) valid=TRUE; X break; X case A_MARINES: if(magic(country,SAILOR)==TRUE) valid=TRUE; X break; X case A_ARCHER: if(magic(country,ARCHER)==TRUE) valid=TRUE; X break; X case A_URUK: if(magic(country,AV_MONST)==TRUE) valid=TRUE; X break; X case A_NINJA: if(magic(country,NINJA)==TRUE) valid=TRUE; X break; X case A_PHALANX: if(magic(country,CAPTAIN)==TRUE) valid=TRUE; X break; X case A_OLOG: if((magic(country,BREEDER)==TRUE) X &&(magic(country,AV_MONST)==TRUE)) valid=TRUE; X break; X case A_ELEPHANT:if(magic(country,DERVISH)==TRUE) valid=TRUE; X break; X case SUPERHERO: X case A_LEGION: if(magic(country,WARLORD)==TRUE) valid=TRUE; X break; X case A_DRAGOON: if(magic(country,CAVALRY)==TRUE) valid=TRUE; X break; X case A_TROLL: if(magic(country,MA_MONST)==TRUE) valid=TRUE; X break; X case A_ELITE: if(magic(country,STEEL)==TRUE) valid=TRUE; X break; X case A_LT_CAV: X case A_CAVALRY: if(magic(country,CAVALRY)==TRUE) valid=TRUE; X break; X case A_KNIGHT: if((magic(country,ARMOR)==TRUE) X &&(magic(country,CAVALRY)==TRUE)) valid=TRUE; X break; X case A_ROC: X case A_GRIFFON: if(magic(country,AVIAN)==TRUE) valid=TRUE; X break; X case ASSASSIN: if(magic(country,NINJA)==TRUE) valid=TRUE; X break; X case DJINNI: if(magic(country,DERVISH)==TRUE) valid=TRUE; X break; X case HERO: if(magic(country,WARRIOR)==TRUE) valid=TRUE; X break; X case ELEMENTAL: if(magic(country,SORCERER)==TRUE) valid=TRUE; X break; X case WRAITH: X case MUMMY: if(magic(country,VAMPIRE)==TRUE) valid=TRUE; X break; X case MINOTAUR: X case DEMON: if(magic(country,DESTROYER)==TRUE) valid=TRUE; X break; X case BALROG: if((magic(country,WYZARD)==TRUE) X &&(magic(country,VAMPIRE)==TRUE)) valid=TRUE; X break; X case DRAGON: if((magic(country,MA_MONST)==TRUE) X &&(magic(country,WYZARD)==TRUE)) valid=TRUE; X break; X default: valid=TRUE; /* for all unrestricted types */ X } X return(valid); X} X#endif CONQUER X X#ifdef OGOD X/*remove a magic power*/ Xlong Xremovemgk(oldpower) Xlong oldpower; X{ X short x,y; X if((oldpower==WARRIOR) X ||(oldpower==CAPTAIN) X ||(oldpower==WARLORD)) { X ntn[country].aplus-=10; X ntn[country].dplus-=10; X return(0L); X } X if(oldpower==HEALER) { X if(ntn[country].race==ORC) { X printf("ORCS CANT HAVE HEALER POWER\n"); X abrt(); X } else ntn[country].repro -= 2; X return(0L); X } X if(oldpower==DESTROYER) { X for(x=ntn[country].capx-3;x<=ntn[country].capx+3;x++) { X for(y=ntn[country].capy-3;y<=ntn[country].capy+3;y++){ X if((ONMAP) X &&(sct[x][y].altitude!=WATER) X &&((x!=ntn[country].capx) X ||(y!=ntn[country].capy))){ X if (sct[x][y].vegetation==DESERT) X { X /* LT_VEG has medium value*/ X sct[x][y].vegetation=LT_VEG; X sct[x][y].designation=DNODESIG; X } X } X } X } X updmove(ntn[country].race,country); X return(0L); X } X if(oldpower==DERVISH) { X updmove(ntn[country].race,country); X return(0L); X } X if((oldpower==MI_MONST) X ||(oldpower==AV_MONST) X ||(oldpower==MA_MONST) X ||(oldpower==KNOWALL) X ||(oldpower==HIDDEN) X ||(oldpower==THE_VOID) X ||(oldpower==ARCHITECT) X ||(oldpower==MINER)) X return(0L); X if(oldpower==VAMPIRE) { X ntn[country].aplus+=35; X ntn[country].dplus+=35; X ntn[country].maxmove+=2; X return(0L); X } X if(oldpower==URBAN) { X ntn[country].repro -= 3; X return(0L); X } X if(oldpower==BREEDER) { X ntn[country].repro-=3; X ntn[country].dplus+=10; X ntn[country].aplus+=10; X return(0L); X } X if(oldpower==DEMOCRACY){ X ntn[country].repro-=1; X ntn[country].dplus-=10; X ntn[country].aplus-=10; X return(0L); X } X if(oldpower==ROADS){ X ntn[country].maxmove-=4; X return(0L); X } X if(oldpower==ARMOR){ X ntn[country].maxmove+=3; X ntn[country].dplus-=20; X } X if((oldpower==NINJA) X ||(oldpower==STEEL) X ||(oldpower==ARCHER) X ||(oldpower==CAVALRY) X ||(oldpower==SAILOR) X ||(oldpower==SUMMON) X ||(oldpower==WYZARD) X ||(oldpower==SORCERER) X ||(oldpower==SAPPER) X ||(oldpower==AVIAN)){ /* these powers are only for pc's */ X return(1L); X } X return(0L); X} X X#ifdef CONQUER X/* killmagk: this routine removes a magic power */ Xkillmagk() X{ X int count,choice,i; X long holdmagk; X X clear(); X count=3; X standout(); X mvprintw(0,(COLS/2)-15,"MAGIC POWERS FOR %s",ntn[country].name); X standend(); X i=0; X while( powers[i] != 0 ){ X if(magic(country,powers[i])==TRUE) X mvprintw(count,0,"%d: power %s",count-2,*(pwrname+i)); X count++; X i++; X } X count++; X standout(); X mvaddstr(count++,5," Which power to remove? "); X standend(); X refresh(); X choice=get_number(); X if (choice>count-5) choice=0; X mvprintw(count++,0," Remove magic #%d? (y or [n])",choice); X refresh(); X if ((getch()=='y')&&(choice!=0)) { X i=0; X if (magic(country,holdmagk=powers[i])==TRUE) choice--; X while(choice) { X i++; X if (magic(country,holdmagk=powers[i])==TRUE) X choice--; X } X ntn[country].powers ^= holdmagk; X removemgk(holdmagk); X } X} X#endif CONQUER X#endif OGOD END_OF_magic.c if test 20241 -ne `wc -c <magic.c`; then echo shar: \"magic.c\" unpacked with wrong size! fi # end of overwriting check fi if test -f main.c -a "${1}" != "-c" ; then echo shar: Will not over-write existing file \"main.c\" else echo shar: Extracting \"main.c\" \(19741 characters\) sed "s/^X//" >main.c <<'END_OF_main.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/*include files*/ X#include <ctype.h> X#include "header.h" X#include "data.h" X#include <signal.h> X#include <fcntl.h> X#include <pwd.h> X Xextern int armornvy; X X/*Declarations*/ Xchar fison[20]; Xchar *getpass(); Xstruct s_sector sct[MAPX][MAPY]; Xstruct nation ntn[NTOTAL]; /* player nation stats */ X/*is sector occupied by an army?*/ Xchar occ[MAPX][MAPY]; Xshort movecost[MAPX][MAPY]; Xlong startgold=0; X X/*offset of upper left hand corner*/ Xshort xoffset=0,yoffset=0; X/*current cursor postion (relative to 00 in upper corner)*/ X/* position is 2*x,y*/ Xshort xcurs=0,ycurs=0; X/*redraw map in this turn if redraw is a 1*/ Xshort redraw=TRUE; X/*1 if you have quit*/ Xint done=FALSE; X/*display state*/ Xshort hilmode=HI_OWN; Xshort dismode=DI_DESI; Xshort selector=0; /*selector (y vbl) for which army/navy... is "picked"*/ Xshort pager=0; /*pager for selector 0,1,2,3*/ X/* nation id of owner*/ Xshort country=0; Xint owneruid; X XFILE *fexe, *fopen(); X Xint Xmain(argc,argv) Xint argc; Xchar **argv; X{ X int geteuid(), getuid(), setuid(); X register int i; X char *name; X void srand(); X int getopt(); X char passwd[20]; X long time(); X char string[80]; X extern char *optarg; X char defaultdir[256]; X struct passwd *getpwnam(); X int sflag=0; X X owneruid=getuid(); X srand((unsigned) time((long *) 0)); X strcpy(defaultdir, DEFAULTDIR); X name = string; X *name = 0; X X /* process the command line arguments */ X while((i=getopt(argc,argv,"hn:d:s"))!=EOF) switch(i){ X /* process the command line arguments */ X case 'h': /* execute help program*/ X if (chdir(defaultdir)) { X printf("unable to change dir to %s\n",defaultdir); X exit(FAIL); X } X initscr(); X savetty(); X noecho(); X crmode(); /* cbreak mode */ X signal(SIGINT,SIG_IGN); /* disable keyboard signals */ X signal(SIGQUIT,SIG_IGN); X help(); X endwin(); X putchar('\n'); X exit(SUCCESS); X case 'd': X strcpy(defaultdir, optarg); X break; X case 'n': X strcpy(name, optarg); X break; X case 's': /*print the score*/ X sflag++; X break; X case '?': /* print out command line arguments */ X printf("Command line format: %s [-hs -d DIR -nNAT]\n",argv[0]); X printf("\t-n NAT play as nation NAT\n"); X printf("\t-h print help text\n"); X printf("\t-d DIR to use play different game\n"); X printf("\t-s print scores\n"); X exit(SUCCESS); X }; X X /* now that we have parsed the args, we can got to the X * dir where the files are kept and do some work. X */ X if (chdir(defaultdir)) { X printf("unable to change dir to %s\n",defaultdir); X exit(FAIL); X } X X /* read data*/ X readdata(); X verifydata( __FILE__, __LINE__ ); X X if(sflag){ X printscore(); X exit(SUCCESS); X } X X /* X * Set the real uid to the effective. This will avoid a X * number of problems involving file protection if the X * executable is setuid. X */ X (void) setuid (geteuid ()) ; X X /* must be a normal interactive game */ X armornvy=AORN; X X /* identify the player and the country he represents */ X X /* get nation name either from command line or by asking X * if you fail will give you the name of administrator of game X */ X X /* verify existence of nation*/ X printf("conquer %s: Copyright (c) 1988 by Edward M Barlow\n",VERSION); X if (*name == 0) { X printf("what nation would you like to be:"); X scanf("%s",name); X } X#ifdef OGOD X if(strcmp(name,"god")==0) { X if ( owneruid != (getpwnam(LOGIN))->pw_uid ){ X printf("sorry -- you can not login as god\n"); X printf("you need to be logged in as %s\n",LOGIN); X exit(FAIL); X } X strcpy(name,"unowned"); X } X#else X if(strcmp(name,"god")==0) strcpy(name,"unowned"); X#endif OGOD X country=(-1); X for(i=0;i<NTOTAL;i++) X if(strcmp(name,ntn[i].name)==0) country=i; X X if(country==(-1)) { X printf("name not found\n"); X printf("\nfor rules type <conquer -h>"); X printf("\nfor more information please contact %s\n",OWNER); X return; X } X X /*get encrypted password*/ X strcpy(passwd,crypt(getpass("\nwhat is your nations password:"),SALT)); X if((strncmp(passwd,ntn[country].passwd,PASSLTH)!=0) X &&(strncmp(passwd,ntn[0].passwd,PASSLTH)!=0)) { X strcpy(passwd,crypt(getpass("\nerror: reenter your nations password:"),SALT)); X if((strncmp(passwd,ntn[country].passwd,PASSLTH)!=0) X &&(strncmp(passwd,ntn[0].passwd,PASSLTH)!=0)) { X printf("\nsorry:"); X printf("\nfor rules type <conquer -h>"); X printf("\nfor more information on the system please contact %s\n",OWNER); X exit(FAIL); X } X } X X /* check if user is super-user nation[0] */ X /* else setup cursor to capitol*/ X if(country==0) { X printf("welcome super user\n"); X xcurs=1; X xoffset=0; X ycurs=1; X yoffset=0; X } else { X printf("\nloading nation %s\n",ntn[country].name); X if (ntn[country].active==0) { X printf("\nSorry, for some reason, your country no longer exists."); X printf("\nIf there is a problem, please contact %s.\n",OWNER); X exit(FAIL); X } X if(aretheyon()==1) { X printf("\nSorry, country is already logged in.\n"); X printf("Please try again later.\n"); X exit(FAIL); X } X execute(); X if(ntn[country].capx>15) { X xcurs=15; X xoffset= (ntn[country].capx-15); X } X else { X xcurs= ntn[country].capx; X xoffset= 0; X } X if(ntn[country].capy>10) { X ycurs=10; X yoffset= (ntn[country].capy-10); X } X else { X yoffset= 0; X ycurs= ntn[country].capy; X } X } X X updmove(ntn[country].race,country); X X /* open output for future printing*/ X { X char filename[80]; X sprintf(filename,"%s%d",exefile,country); X if ((fexe=fopen(filename,"a"))==NULL) { X beep(); X printf("error opening %s\n",filename); X unlink(fison); X exit(FAIL); X } X } X X /* SET UP THE SCREEN */ X printf("about to set up the screen"); X initscr(); X crmode(); /* cbreak mode */ X signal(SIGINT,SIG_IGN); /* disable keyboard signals */ X signal(SIGQUIT,SIG_IGN); X signal(SIGHUP,hangup); /* must catch hangups */ X X prep(country); X noecho(); X X /*main while routine*/ X done=FALSE; X while (done==FALSE) X { X /* check if cursor is out of bounds*/ X coffmap(); X /*get commands, make moves and input command*/ X parse(); X } X X if(country==0) writedata(); X else { X fprintf(fexe,"L_NGOLD\t%d \t%d \t%ld \t0 \t0 \t%s\n", X XNAGOLD ,country,ntn[country].tgold,"null"); X fprintf(fexe,"L_NIRON\t%d \t%d \t%ld \t0 \t0 \t%s\n", X XNAIRON ,country,ntn[country].tiron,"null"); X fprintf(fexe,"L_NJWLS\t%d \t%d \t%ld \t0 \t0 \t%s\n", X XNARGOLD ,country,ntn[country].jewels,"null"); X } X /*done so quit*/ X unlink(fison); X clear(); X printw("quitting\n"); X refresh(); X nocrmode(); X endwin(); X fclose(fexe); X exit(SUCCESS); X} X X/*make the bottom of the screen*/ Xint Xmakebottom() X{ X move(LINES-4,0); X clrtoeol(); X mvprintw(LINES-3,0,"Conquer: %s",VERSION); X clrtoeol(); X mvaddstr(LINES-1,0," type ? for help"); X clrtoeol(); X mvaddstr(LINES-2,0," type Q to quit"); X clrtoeol(); X if(country==0) mvaddstr(LINES-3,COLS-20,"nation..GOD "); X else { X mvprintw(LINES-3,COLS-20,"nation...%s",ntn[country].name); X mvprintw(LINES-2,COLS-20,"treasury.%ld",ntn[country].tgold); X mvprintw(LINES-1,COLS-20,"score....%ld",ntn[country].score); X } X} X X/* parse */ Xint Xparse() X{ X register int i; X char name[20]; X char passwd[12]; X int ocountry; X X switch(getch()) { X case EXT_CMD: /* extended command */ X ext_cmd(); X break; X case '': /*redraw the screen*/ X redraw=TRUE; X break; X case 'a': /*army report*/ X redraw=TRUE; X armyrpt(0); X break; X case 'A': /*adjust army*/ X adjarm(-1); X makebottom(); X break; X case '1': X case 'b': /*move south west*/ X pager=0; X selector=0; X xcurs--; X ycurs++; X break; X case 'B': /*budget*/ X redraw=TRUE; X budget(); X break; X case 'c': /*change nation stats*/ X redraw=TRUE; X change(); X break; X case 'C': /*construct*/ X construct(); X makebottom(); X break; X case 'd': /*change display*/ X newdisplay(); X break; X case 'D': /*draft*/ X draft(); X makebottom(); X break; X case 'f': /*report on ships and load/unload*/ X redraw=TRUE; X fleetrpt(); X break; X case 'F': /*go to next army*/ X navygoto(); X break; X case 'g': /*group report*/ X redraw=TRUE; X armyrpt(1); X break; X case 'G': /*go to next army*/ X armygoto(); X break; X case 'H': /*scroll west*/ X pager=0; X selector=0; X xcurs-=((COLS-22)/4); X break; X case '4': X case 'h': /*move west*/ X pager=0; X selector=0; X xcurs--; X break; X case 'J': /*scroll down*/ X pager=0; X selector=0; X ycurs+=((SCREEN_Y_SIZE)/2); X break; X case '2': X case 'j': /*move down*/ X pager=0; X selector=0; X ycurs++; X break; X case '8': X case 'k': /*move up*/ X pager=0; X selector=0; X ycurs--; X break; X case 'K': /*scroll up*/ X pager=0; X selector=0; X ycurs-=((SCREEN_Y_SIZE)/2); X break; X case '6': X case 'l': /*move east*/ X pager=0; X selector=0; X xcurs++; X break; X case 'L': /*scroll east*/ X pager=0; X selector=0; X xcurs+=((COLS-22)/4); X break; X case 'm': /*move selected item to new x,y */ X mymove(); X makebottom(); X prep(country); X pager=0; X selector=0; X break; X case 'M': /*magic*/ X redraw=TRUE; X domagic(); X break; X case '3': X case 'n': /*move south-east*/ X pager=0; X selector=0; X ycurs++; X xcurs++; X break; X case 'N': /*read newspaper */ X redraw=TRUE; X newspaper(); X break; X case 'p': /*pick*/ X selector+=2; X if(selector>=10) { X selector=0; X pager+=1; X } X /*current selected unit is selector/2+5*pager*/ X if((selector/2)+(pager*5)>=units_in_sector(XREAL,YREAL,country)) { X pager=0; X selector=0; X } X break; X case 'P': /*production*/ X redraw=TRUE; X produce(); X break; X case 'Q': /*quit*/ X case 'q': /*quit*/ X done=TRUE; X break; X case 'r': /*redesignate*/ X redesignate(); X makemap(); X makebottom(); X break; X /*list*/ X case 'R': /*Read Messages*/ X redraw=TRUE; X rmessage(); X refresh(); X break; X case 's': /*score*/ X redraw=TRUE; X showscore(); X break; X case 'S': /*diplomacy screens*/ X diploscrn(); X redraw=TRUE; X break; X case '9': X case 'u': /*move north-east*/ X pager=0; X selector=0; X ycurs--; X xcurs++; X break; X case 'U': /* scroll north-east */ X pager=0; X selector=0; X xcurs+=((COLS-22)/4); X ycurs-=((SCREEN_Y_SIZE)/2); X break; X case 'W': /*message*/ X redraw=TRUE; X wmessage(); X break; X case '7': X case 'y': /*move north-west*/ X pager=0; X selector=0; X ycurs--; X xcurs--; X break; X case 'Y': /* scroll north-west */ X pager=0; X selector=0; X xcurs-=((COLS-22)/4); X ycurs-=((SCREEN_Y_SIZE)/2); X break; X case 'Z': /*move civilians up to 2 spaces*/ X redraw=TRUE; X moveciv(); X break; X case 'z': /*login as new user */ X#ifdef OGOD X if (owneruid != (getpwnam(LOGIN))->pw_uid) break; X#endif X clear(); X redraw=TRUE; X if(country != 0) { X fprintf(fexe,"L_NGOLD\t%d \t%d \t%ld \t0 \t0 \t%s\n", X XNAGOLD ,country,ntn[country].tgold,"null"); X fprintf(fexe,"L_NIRON\t%d \t%d \t%ld \t0 \t0 \t%s\n", X XNAIRON ,country,ntn[country].tiron,"null"); X fprintf(fexe,"L_NJWLS\t%d \t%d \t%ld \t0 \t0 \t%s\n", X XNARGOLD ,country,ntn[country].jewels,"null"); X } else X mvaddstr(0,0,"SUPER-USER: YOUR CHANGES WILL NOT BE SAVED IF YOU DO THIS!!!"); X standout(); X mvaddstr(2,0,"change login to : "); X standend(); X refresh(); X get_nname(name); X X ocountry=country; X country=(-1); X if(strcmp(name,"god")==0) country=0; X else for(i=1;i<NTOTAL;i++) X if((strcmp(name,ntn[i].name)==0)&&(ntn[i].active>=1)) X country=i; X X if(country==(-1)) { X errormsg("name not found"); X country=ocountry; X break; X } X if(country==ocountry){ X errormsg("same country"); X break; X } X X /*get password*/ X mvaddstr(2,0,"what is your nations password:"); X refresh(); X getstr(passwd); X strcpy(name,crypt(passwd,SALT)); X X if((strncmp(name,ntn[country].passwd,PASSLTH)!=0) X &&(strncmp(name,ntn[0].passwd,PASSLTH)!=0)){ X errormsg("sorry: password invalid"); X country=ocountry; X break; X } X unlink(fison); X if(aretheyon()==1) { X errormsg("sorry: country is already logged in."); X refresh(); X country=ocountry; X break; X } X X fclose(fexe); X /* open output for future printing*/ X sprintf(name,"%s%d",exefile,country); X if ((fexe=fopen(name,"a"))==NULL) { X beep(); X printf("error opening %s\n",name); X unlink(fison); X exit(FAIL); X } X X printf("\n"); X readdata(); X execute(); X X updmove(ntn[country].race,country); X /*go to that nations capitol*/ X if(country!=0) { X if(ntn[country].capx>15) { X xcurs=15; X xoffset= (ntn[country].capx-15); X } X else { X xcurs= ntn[country].capx; X xoffset= 0; X } X if(ntn[country].capy>10) { X ycurs=10; X yoffset= (ntn[country].capy-10); X } X else { X yoffset= 0; X ycurs= ntn[country].capy; X } X } X break; X case '?': /*display help screen*/ X redraw=TRUE; X help(); X break; X default: X beep(); X } X} X Xvoid Xmakeside() X{ X int i; X int armbonus=0; X int found=0,nvyfnd=0; X int enemy; X int y; X short armynum; X short nvynum; X int count; X int nfound=0; X register struct s_sector *sptr = &sct[XREAL][YREAL]; X X /*clear side if you cant see it as you are out of bounds*/ X if(inch()==' ') { X for(i=0;i<LINES-3;i++){ X move(i,COLS-21); X clrtoeol(); X } X return; X } X X /*clear top right hand side each new sector*/ X for(count=0;count<11;count++){ X move(count,COLS-21); X clrtoeol(); X } X X /*check for your armies*/ X count=units_in_sector(XREAL,YREAL,country); X if(pager*5>count) pager=0; X X /*first army found is #0*/ X /*show armies / navies in range pager*5 to pager*5 + 4*/ X /*so if pager=0 show 0 to 4, pager=2 show 10 to 14*/ X /*current selected unit is selector/2+5*pager*/ X X if(count>(5+(pager*5))) mvaddstr(10,COLS-20,"MORE..."); X X nfound=0; X for(armynum=0;armynum<MAXARM;armynum++){ X if((ASOLD>0)&&(AXLOC==XREAL)&&(AYLOC==YREAL)) { X if((nfound>=pager*5)&&(nfound<=4+(pager*5))) { X /*print that army to nfound%5*/ X mvaddch((nfound%5)*2,COLS-21,'>'); X if(selector==(nfound%5)*2) standout(); X /*the mv,for gets the highlighting pretty*/ X move((nfound%5)*2,COLS-10); X for(i=0;i<9;i++) addch(' '); X X mvprintw((nfound%5)*2,COLS-20,"army %d: %d (%s)",armynum,ASOLD,*(shunittype+(ATYPE%100))); X /*the mv,for gets the highlighting pretty*/ X move((nfound%5)*2+1,COLS-10); X for(i=0;i<9;i++) addch(' '); X X mvprintw((nfound%5)*2+1,COLS-20," mv:%d st:%s",AMOVE,*(soldname+ASTAT)); X standend(); X } X nfound++; X } X if((occ[XREAL][YREAL]!=0) X &&(occ[XREAL][YREAL]!=country) X &&((sptr->owner==country)||((ASOLD>0)&&(AXLOC<=XREAL+1) X &&(AXLOC>=XREAL-1)&&(AYLOC<=YREAL+1)&&(AYLOC>=YREAL-1)))) X found=1; X } X X if(nfound<4+(pager*5)) for(nvynum=0;nvynum<MAXNAVY;nvynum++){ X if(((NWAR+NMER)!=0)&&(NXLOC==XREAL)&&(NYLOC==YREAL)) { X if((nfound>=pager*5)&&(nfound<=4+(pager*5))) { X /*print a navy*/ X mvaddch((nfound%5)*2,COLS-21,'>'); X if(selector==(nfound%5)*2) standout(); X mvprintw((nfound%5)*2,COLS-20,"navy %d: move %d",nvynum,NMOVE); X mvprintw((nfound%5)*2+1,COLS-20," war:%d mer:%d",NWAR,NMER); X standend(); X } X nfound++; X } X if((occ[XREAL][YREAL]!=0)&&(occ[XREAL][YREAL]!=country) X &&(sptr->altitude==WATER) X &&(NWAR+NMER>0)&&(NXLOC<=XREAL+1)&&(NXLOC>=XREAL-1) X &&(NYLOC<=YREAL+1)&&(NYLOC>=YREAL-1)) X nvyfnd=1; X } X X count=0; X if(found==1) for(i=0;i<NTOTAL;i++) { X if( !magic(i,HIDDEN) || country == 0 ){ X enemy=0; X for(armynum=0;armynum<MAXARM;armynum++){ X if((i!=country) X &&(ntn[i].arm[armynum].xloc==XREAL) X &&(ntn[i].arm[armynum].yloc==YREAL) X &&(ntn[i].arm[armynum].sold>0)) X enemy+=ntn[i].arm[armynum].sold; X } X if(enemy>0) { X if((magic(country,NINJA)==1) || country == 0 ) X mvprintw(nfound*2+count,COLS-20,"%s: %d men ",ntn[i].name,enemy); X else if(magic(i,THE_VOID)==1){ X mvprintw(nfound*2+count,COLS-20,"%s: ?? men ",ntn[i].name); X clrtoeol(); X } X else mvprintw(nfound*2+count,COLS-20,"%s: %d men ",ntn[i].name,(enemy*(rand()%60+70)/100)); X count++; X } X } X } X if(nvyfnd==1) for(i=0;i<NTOTAL;i++) { X if( magic(i,HIDDEN)!=1 || country == 0 ) X for(nvynum=0;nvynum<MAXNAVY;nvynum++) X if((ntn[i].arm[nvynum].xloc==XREAL) X &&(ntn[i].arm[nvynum].yloc==YREAL) X &&(ntn[i].arm[nvynum].sold>0)){ X if((magic(country,NINJA)==1) || country == 0 ){ X mvprintw(nfound*2+count,COLS-20,"%s: %d ships ", X ntn[i].name,ntn[i].nvy[nvynum].warships+ntn[i].nvy[nvynum].merchant); X } X else if(magic(i,THE_VOID)==1){ X mvprintw(nfound*2+count,COLS-20,"%s: ?? ships",ntn[i].name); X clrtoeol(); X } X else mvprintw(nfound*2+count,COLS-20,"%s: %d ships ", X ntn[i].name,(ntn[i].nvy[nvynum].warships+ntn[i].nvy[nvynum].merchant)*(rand()%6+7)/10); X count++; X } X } X X standend(); X mvprintw(11,COLS-20,"x is %d ",XREAL); X mvprintw(11,COLS-11,"y is %d ",YREAL); X X if((country!=0)&&(sptr->altitude==WATER)){ X for(y=12;y<=20;y++) mvaddstr(y,COLS-20," "); X mvaddstr(14,COLS-9,"WATER"); X } X else { X if((country!=0)&&(country!=sptr->owner) X &&(magic(sptr->owner,THE_VOID)==1)){ X for(y=13;y<=20;y++) mvaddstr(y,COLS-20," "); X } X else { X X for(y=13;y<=14;y++) mvaddstr(y,COLS-20," "); X X for(i=0;i<=7;i++) X if(sptr->designation==*(des+i)){ X mvprintw(13,COLS-20,"%s",*(desname+i)); X clrtoeol(); X } X X if((sptr->owner==country)||(country==0)) X mvprintw(15,COLS-20,"people: %6d",sptr->people); X else X mvprintw(15,COLS-20,"people: %6d",sptr->people*(rand()%60+70)/100); X X if((sptr->owner==country) X ||(sptr->owner==0) X ||(sptr->owner>=MAXNTN)){ X mvprintw(17,COLS-20,"gold is: %3d",sptr->gold); X mvprintw(18,COLS-20,"iron is: %3d",sptr->iron); X if(sptr->fortress == 0) { X mvaddstr(19,COLS-20," "); X } else { X if(sptr->designation==DCASTLE) X armbonus=5 * sptr->fortress; X else X if(sptr->designation==DCITY){ X if(magic(country,ARCHITECT)==1){ X armbonus+=10+16 * sptr->fortress; X } X else armbonus+=10+8 * sptr->fortress; X } X else if(sptr->designation==DCAPITOL){ X if(magic(country,ARCHITECT)==1){ X armbonus+=20+20 * sptr->fortress; X } X else armbonus+=20+10 * sptr->fortress; X } X if(armbonus>0) X mvprintw(19,COLS-20,"fortress: +%2d%%",armbonus); X } X } X else { X for(y=17;y<=19;y++) mvaddstr(y,COLS-20," "); X } X } X X standout(); X if(sptr->owner==0) mvaddstr(12,COLS-20,"unowned"); X else mvprintw(12,COLS-20,"owner: %s",ntn[sptr->owner].name); X standend(); X clrtoeol(); X X for(i=0;i<=10;i++) X if(sptr->vegetation==*(veg+i)) X mvprintw(13,COLS-9,"%s",*(vegname+i)); X X if(tofood(sptr->vegetation,country) != 0) X mvprintw(13,COLS-1,"%d",tofood(sptr->vegetation,country)); X X if(sptr->owner!=0) for(i=1;i<=8;i++) X if(ntn[sptr->owner].race==*(races+i)[0]){ X mvprintw(14,COLS-20,"%s",*(races+i)); X clrtoeol(); X } X X for(i=0;(*(ele+i) != '0');i++) X if( sptr->altitude == *(ele+i) ){ X mvprintw(14,COLS-9,"%s",*(elename+i)); X break; X } X } X X if(movecost[XREAL][YREAL]<0) X mvaddstr(16,COLS-20,"YOU CAN'T ENTER HERE"); X else X mvprintw(16,COLS-20,"move cost: %2d ",movecost[XREAL][YREAL]); X} X X/* returns 1 if they are on, else 0 */ Xint Xaretheyon() X{ X FILE *fon; X /* set up a detection feature for when a country */ X /* is logged on... to prevent multiple logins */ X sprintf(fison,"%s%d",isonfile,country); X if((fon=fopen(fison,"r"))==NULL) { X fon=fopen(fison,"w"); X fprintf(fon,"Arg!"); X fclose(fon); X return(0); X } else { X return(1); X } X} END_OF_main.c if test 19741 -ne `wc -c <main.c`; then echo shar: \"main.c\" unpacked with wrong size! fi # end of overwriting check fi echo shar: End of archive 6 \(of 8\). cp /dev/null ark6isdone 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