home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
games
/
volume6
/
gb
/
patch1
/
build.c
next >
Wrap
C/C++ Source or Header
|
1989-07-06
|
8KB
|
290 lines
/*
* Galactic Bloodshed (Robert Chansky, smq@ucscb.ucsc.EDU)
* build -- build a ship
*/
#include "vars.h"
#include "ships.h"
#include "races.h"
#include <curses.h>
#include <setjmp.h>
#include <signal.h>
extern jmp_buf main_jenv;
extern int Ignore_filelocks, God;
int build_shdata,build_pdata,build_sectdata;
build(APcount, argn,args)
int APcount;
int argn;
char args[MAXARGS][COMMANDSIZE];
{
int j,i,x= -1 ,y= -1 ,shipno, planet_slot,mask;
int picked=0;
char shipc;
planettype *planet;
sectortype *sect;
shiptype s,*dirship;
int build_handler();
build_shdata = build_pdata = build_sectdata = NEUTRAL_FD;
signal(SIGINT, build_handler);
if (Dir.level==LEVEL_PLAN) {
} else if (Dir.level==LEVEL_SHIP) {
openshdata(&build_shdata);
if (!getship(build_shdata, &dirship, Dir.shipno)) {
printf("Illegal dir value.\n");
build_handler();
}
if (dirship->is_docked) {
if (dirship->whatdest==LEVEL_PLAN)
printf("This ship is landed.\n");
else
printf("There is already a ship docked here (#%d).\n",
dirship->destshipno);
build_handler();
}
} else {
printf("You can't build anything here.\n");
build_handler();
}
if (Dir.level==LEVEL_PLAN) {
if (!enufAP(Stars[Dir.snum]->AP, APcount))
build_handler();
} else if (dirship->whatorbits==LEVEL_UNIV) {
if (!enufAP(Sdata.AP, APcount))
build_handler();
} else
if (!enufAP(Stars[dirship->storbits]->AP, APcount))
build_handler();
do {
tty_on();
printf("What ship type (? for help):");
shipc=getchr(); putchr('\n');
tty_off();
if (shipc=='?') {
printf("ltr ship carg armr dstcap guns mass fuelcap mintech cost ^crew\n");
for (i=0; i<NUMSTYPES; i++)
if (Race->tech >= Shipdata[i][ABIL_TECH] || God)
if ((i==STYPE_POD && Race->Thing) || i!=STYPE_POD)
printf(" %c %18s %5d%5d%7d%5d%6d%8d%8d%5d%6d\n",Shipltrs[i],
Shipnames[i],Shipdata[i][ABIL_CARGO],
Shipdata[i][ABIL_ARMOR],
Shipdata[i][ABIL_DESTCAP],
Shipdata[i][ABIL_GUNS],Shipdata[i][ABIL_MASS],
Shipdata[i][ABIL_FUELCAP],Shipdata[i][ABIL_TECH],
Shipdata[i][ABIL_COST],Shipdata[i][ABIL_MAXCREW] );
} else {
i=0;
while ((Shipltrs[i]!=shipc) && (i<NUMSTYPES)) i++;
picked = 1;
if (i<0 || i>=NUMSTYPES || (i==STYPE_POD && !Race->Thing) ) {
printf("Illegal ship letter.\n");
picked = 0;
} else if (Race->tech < Shipdata[i][ABIL_TECH]) {
printf("You don't have enough technology to build one of those.\n");
if (!God)
picked = 0;
} else if (i==STYPE_MIRROR && Dir.level==LEVEL_PLAN) {
printf("You can't build one of those on a planet.\n");
picked = 0;
}
}
} while (!picked);
if (Dir.level==LEVEL_PLAN) {
openpdata(&build_pdata);
getplanet(build_pdata,&planet,Stars[Dir.snum]->planetpos[Dir.pnum]);
/* see if the ship can be made on the planet */
j = 0;
while (planet->shipnums[j++]) ;
if (j<=MAXPSHIPS) {
planet_slot = j-1;
} else {
printf("too many ships are already here.\n");
free(planet);
build_handler();
}
if (planet->info[Playernum-1].resource < Shipdata[i][ABIL_COST]) {
printf("not enough resources in stock.\n");
free(planet);
build_handler();
}
} else {
if (dirship->resource < Shipdata[i][ABIL_COST]) {
printf("not enough resources on this ship.\n");
build_handler();
}
}
if (Dir.level==LEVEL_PLAN)
do {
printf("Build %s on planet %s,", Shipnames[i],
Stars[Dir.snum]->pnames[Dir.pnum] );
GetMapSector(planet, &x, &y);
opensectdata(&build_sectdata);
getsector(build_sectdata, §, planet->sectormappos+(y*planet->Maxx+x)*sizeof(sectortype) );
close(build_sectdata);
free(sect);
} while ( sect->owner != Playernum );
/* keep people from fucking up the data files */
mask = sigblock(SIGINT | SIGQUIT | SIGSTOP);
Bzero(s);
s.type = i;
s.xpos = (float)x;
s.ypos = (float)y;
/*s.augmented = 0;*/
if (s.type==STYPE_POD)
s.speed = 1;
else
s.speed = 2; /* starting speed default */
s.owner = Playernum;
/*for (l=0; l < NUMABILS-3; l++)
s.abils[l]=Shipdata[i][l];*/
s.mass = (float)Shipdata[i][ABIL_MASS];
s.fuel = s.destruct = s.resource = 0;
s.is_docked = 1;
if (Dir.level==LEVEL_PLAN) {
/* docked on the planet */
s.whatorbits = LEVEL_PLAN;
s.whatdest = LEVEL_PLAN;
s.deststar = Dir.snum;
s.destpnum = Dir.pnum;
} else {
s.whatdest = LEVEL_SHIP;
s.destshipno = Dir.shipno;
s.whatorbits = dirship->whatorbits;
}
s.storbits = Dir.snum;
s.pnumorbits = Dir.pnum;
s.rad = 0;
if (Shipdata[s.type][ABIL_MAXCREW]==0)
s.damage = 0;
else
s.damage = 50;
if (has_switch(&s)) {
s.orders.object.on = 0;
}
switch (s.type) {
case OTYPE_VN:
s.orders.object.number = 1; /* one of them */
s.orders.object.number2 = 1; /* we have an assignment */
s.orders.object.on = 1;
break;
case STYPE_MINE:
s.orders.object.number = 100; /* trigger radius */
printf("Trigger radius set to 100.\n");
break;
case OTYPE_TRANSDEV:
printf("Receive OFF. Change with order.\n");
break;
case OTYPE_TERRA:
printf("Processor OFF.\n");
break;
default:
break;
}
/* deduct resource cost */
if (Dir.level==LEVEL_PLAN)
planet->info[Playernum-1].resource -= Shipdata[i][ABIL_COST];
else
dirship->resource -= Shipdata[i][ABIL_COST];
/* load new ship with fuel */
if (Dir.level==LEVEL_PLAN) {
if (planet->info[Playernum-1].fuel >= Shipdata[i][ABIL_FUELCAP]) {
planet->info[Playernum-1].fuel-=Shipdata[i][ABIL_FUELCAP];
s.fuel = (float)Shipdata[i][ABIL_FUELCAP];
s.mass += s.fuel*MASS_FUEL;
printf("%s Loaded with %.2f fuel.\n",Shipnames[s.type],s.fuel);
} else {
s.fuel = 0;
printf("No fuel available!\n");
}
/* put crew in ship */
opensectdata(&build_sectdata);
getsector(build_sectdata,§,planet->sectormappos+(y*planet->Maxx+x)*sizeof(sectortype));
if (sect->popn > Shipdata[i][ABIL_MAXCREW]) {
sect->popn -= Shipdata[i][ABIL_MAXCREW];
s.popn = Shipdata[i][ABIL_MAXCREW];
s.mass += (float)s.popn*Race->mass;
putsector(build_sectdata,sect,planet->sectormappos+(y*planet->Maxx+x)*sizeof(sectortype));
printf("Loaded with %d crew members.\n",Shipdata[i][ABIL_MAXCREW]);
} else {
s.popn = 1;
printf("Only one crewmember available.\n");
}
close(build_sectdata);
free(sect);
}
/* check for dead ships in the data files */
if (Dir.level==LEVEL_SHIP)
Ignore_filelocks = 1;
else
openshdata(&build_shdata);
if ( (shipno = getdeadship(build_shdata)) == -1) {
/* otherwise recycle topmost dead ship in data file */
/* no dead ships to recycle */
shipno = Numships(build_shdata) + 1;
}
printf("Ship #%d is %s %.0f,%.0f.\n",shipno,
Dir.level==LEVEL_SHIP ? "at" : "on sector", s.xpos,s.ypos);
putship(build_shdata,&s,shipno);
/* Insert ship into planet's orbit (actually landed) */
if (Dir.level==LEVEL_PLAN) {
planet->shipnums[planet_slot] = shipno;
planet->numships++;
putplanet(build_pdata,planet,Stars[Dir.snum]->planetpos[Dir.pnum]);
close(build_pdata);
free(planet);
} else {
dirship->is_docked = 1;
dirship->whatdest = LEVEL_SHIP;
dirship->destshipno = shipno;
putship(build_shdata, dirship, Dir.shipno);
free(dirship);
}
close(build_shdata);
Ignore_filelocks = 0;
if (Dir.level==LEVEL_SHIP && dirship->whatorbits==LEVEL_UNIV)
deductAPs(APcount, 0, 1);
else
deductAPs(APcount, Dir.snum, 0);
sigsetmask(mask);
}
build_handler()
{
close(build_shdata );
close(build_pdata );
close(build_sectdata );
Ignore_filelocks = 0;
longjmp(main_jenv,1);
}