DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T l

⟦a8b261a29⟧ TextFile

    Length: 7653 (0x1de5)
    Types: TextFile
    Names: »land.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/General/Gb/land.c« 

TextFile

/*
** Galactic Bloodshed (Robert Chansky, smq@b)
**  land.c -- land a ship
**  also.... dock -- dock a ship w/ another ship 
**  and..... assault -- a very un-PC version of land
*/

#include "vars.h"
#include "ships.h"
#include "races.h"
#include <setjmp.h>
#include <math.h>
#include <curses.h>
extern jmp_buf main_jenv;
#include <signal.h>

int land_sectdata,land_shfdata,land_shdata,land_pdata;
extern char telegram_buf[AUTO_TELEG_SIZE];
extern int Ignore_filelocks;


land(APcount, argn,args, assault)
int APcount;
int argn;
char args[MAXARGS][COMMANDSIZE];
int assault;	/* unfriendly land */
{
int land_handler();
char c;
shiptype *s,*s2;
planettype *p;
sectortype *sect;
placetype where;
bool cont,planetmod=0,sectmod=0;
int shipno,x= -1,y= -1,i;
float fuel;
double Dist;
char buf[200];

land_sectdata = land_shfdata = land_shdata = land_pdata = NEUTRAL_FD;
signal(SIGINT, land_handler);

  if (argn!=2) {
	printf("%s what ship #", args[0]);
	scanf("%d",&shipno);
	getchr();
  } else {
	i = (args[1][0]=='#');
	sscanf(args[1]+i,"%d",&shipno);
  }
  openshdata(&land_shdata);
  if (!getship(land_shdata, &s, shipno)) {
	land_handler();
  }
  if (s->owner!=Playernum) {
	DontOwnErr(shipno);
	land_handler();
  }
  if (s->rad) {
	printf("%s is irradiated and inactive.\n",Shipnames[s->type]);
	land_handler();
  }
  if (!enufAP(Stars[s->storbits]->AP, APcount)) 
	land_handler();
  if (s->is_docked) {
	printf("Ship #%d is already docked.\n",shipno);
	land_handler();
  }

  printf("%s %s #%d on: ", args[0], Shipnames[s->type], shipno);
  scanf("%100s", buf);
  getchr();
  Ignore_filelocks = 1;
  where = Getplace(buf, 0);
  Ignore_filelocks = 0;
  if (where.err)
	land_handler();

  if (where.level==LEVEL_SHIP) {
	free(where.shipptr);
	Ignore_filelocks = 1;
	if (!getship(land_shdata, &where.shipptr, where.shipno))
		land_handler();
	Ignore_filelocks = 0;
	if (where.shipptr->is_docked) {
		printf("ship #%d is already docked.\n",where.shipno);
		land_handler();
	}
	printf("Distance to ship #%d: %.2g.\n", where.shipno,
  		Dist = sqrt((double)Distsq(where.shipptr->xpos, 
  		      where.shipptr->ypos, s->xpos, s->ypos ) ) );
	if (Dist > DIST_TO_LAND) {
	     printf("Ship #%d must be %.3g or closer to ship #%d.(%.2f).\n",
			shipno, DIST_TO_LAND, where.shipno, Dist);
	     land_handler();
	}

	fuel = 0.05 + Dist * 0.5;
	printf("This maneuver will take %g fuel (of %.2f.)\n",fuel,s->fuel);
	if (fuel > s->fuel) {
		printf("Not enough fuel.\n");
		land_handler();
	}
	s->fuel -= fuel;
	s->mass -= fuel * MASS_FUEL;
	s->is_docked = 1;
	s->whatdest = LEVEL_SHIP;
	s->destshipno = where.shipno;
	s->xpos = where.shipptr->xpos + 1.0;
	s->ypos = where.shipptr->ypos;
	putship(land_shdata, s, shipno);
	where.shipptr->is_docked = 1;
	where.shipptr->whatdest = LEVEL_SHIP;
	where.shipptr->destshipno = shipno;
	putship(land_shdata, where.shipptr, where.shipno);
	close(land_shdata);
	printf("ship #%d docked.\n",shipno);
	land_handler();
  } else 
    if (where.shipptr->whatorbits!=LEVEL_PLAN) {
	printf("Huh?\n");
	land_handler();
    }

  openpdata(&land_pdata);
  getplanet(land_pdata, &p, Stars[s->storbits]->planetpos[s->pnumorbits]);
  
  printf("Planet /%s/%s has gravity field of %.2f.\n", Stars[s->storbits]->name,
	Stars[s->storbits]->pnames[s->pnumorbits], gravity(p));

  printf("Distance to planet: %.2f.\n",
  	Dist = sqrt((double)Distsq(Stars[s->storbits]->xpos + p->xpos, 
  		      Stars[s->storbits]->ypos + p->ypos, 
  		      s->xpos, s->ypos ) )
  	);

  if (Dist > DIST_TO_LAND) {
     printf("Ship #%d must be %.3g or closer to the planet (%.2f).\n",shipno, DIST_TO_LAND, Dist);
     land_handler();
  }

  fuel = 0.05 + logscale(s->mass)*gravity(p) * LAND_GRAV_MASS_FACTOR + assault;

  printf("That maneuver will cost you %.2f fuel (of %.2f).\n",fuel, s->fuel);

  if (s->fuel < fuel) {
	  tty_on();
	  printf("NOT ENOUGH FUEL-- continue? (y/n) ");
	  putchr(c = getchr());
	  if (c != 'y') {
		land_handler();
		tty_off();
	  }
  }
  tty_off();

  cont = 0;
  do {
    printf("%s on",(s->fuel < fuel) ? "CRASH" : args[0]);
    GetMapSector(p, &x, &y);
    if (assault) {
	    opensectdata(&land_sectdata);
	    getsector(land_sectdata,&sect,p->sectormappos+(y*p->Maxx+x)*sizeof(sectortype));
	    if (sect->owner==Playernum) {
		printf("You cannot assault your own sector.\n");
		close(land_sectdata);
		free(sect);
	    } else if (sect->popn > 0) {
		printf("The assaulted sector must have no population.\n");
		close(land_sectdata);
		free(sect);
	    } else 
		cont = 1;
    }
    if (sect->des != Race->likesbest) {
	printf("Your ship cannot land on a %c sector.\n",desshow(sect));
	close(land_sectdata);
	free(sect);
    }
  } while (!cont);

  if (s->fuel < fuel) {

	where.level = LEVEL_PLAN;
	where.snum = s->storbits;
	where.pnum = s->pnumorbits;

	printf("BO\007OM!! Ship #%d crashes on sector %d,%d with blast radius of %d.\n",
		shipno, x, y, (int)(s->mass/15+1+s->destruct/3) );

	if (!fork()) {
		/* fork off a child process to do damage */
	  blast(where, p, x, y, (int)(s->mass/15+1+s->destruct/3+s->fuel/5), 
			(int)(s->destruct/3+2) );

	  openshfdata(&land_shfdata);
	  destroyship(land_shfdata,shipno);	/* kill the ship */
	  close(land_shfdata);

	  for (i=0; i<MAXPSHIPS && p->shipnums[i]!=shipno; i++)
		if (p->shipnums[i] == shipno) {
			planetmod = 1;
			p->shipnums[i] = 0;
			p->numships--;
		}
	  
	  deductAPs(APcount, s->storbits, 0);
	  launch_handler();

	  exit(0);
	}
  }
  s->xpos = (float)x;
  s->ypos = (float)y;

  s->fuel -= fuel;
  s->mass -= fuel * MASS_FUEL;
  s->is_docked = 1;
  s->whatdest = LEVEL_PLAN;	/* no destination */
  s->deststar = s->storbits;
  s->destpnum = s->pnumorbits;

  if (assault) {
		/* assault on planet increases combat readiness, */
		/* but only if we aren't already well-established there */
	if (!p->info[Playernum-1].numsectsowned && p->info[Playernum-1].comread < 50) {
		p->info[Playernum-1].comread = 100;
		p->info[Playernum-1].mob_set = 100;
		sect->mobilization = 100;
		sect->is_wasted = 0;
	}
	sectmod = planetmod = 1;
	  /* unload some people onto the sector */
	sect->popn = s->popn-1;
	sect->owner = Playernum;
	p->info[Playernum-1].numsectsowned++;
	s->mass -= (s->popn-1) * Race->mass;
	s->popn = 1;
  }

 /* } */

  deductAPs(APcount, s->storbits, 0);

  putship(land_shdata, s, shipno);
  close(land_shdata);

  if (planetmod) {
	  putplanet(land_pdata,p,Stars[s->storbits]->planetpos[s->pnumorbits]);
  }
  close(land_pdata);
  free(p);

  if (sectmod)
	  putsector(land_sectdata,sect,p->sectormappos+(y*p->Maxx+x)*sizeof(sectortype));
  if (assault) {
	  close(land_sectdata);
	  free(sect);
  }

	/* send telegs to anyone there */
  if (s->whatdest == LEVEL_PLAN) {
	  teleg_add("",telegram_buf);
	  if (assault)
		  sprintf(buf,"BULLETIN!\n\nPlanet /%s/%s ASSAULTED by ship #%d on sector %.0f,%.0f!!\n", Stars[s->storbits]->name,
			Stars[s->storbits]->pnames[s->pnumorbits], shipno,
			s->xpos, s->ypos);
	  else
		  sprintf(buf,"Bulletin...\n\nShip #%d observed landing on sector %.0f,%.0f,\nplanet /%s/%s.\n",shipno,s->xpos,s->ypos,Stars[s->storbits]->name,
			Stars[s->storbits]->pnames[s->pnumorbits]);
	  teleg_add(buf,telegram_buf);
	  for (i=1; i<MAXPLAYERS; i++)
		if (p->info[i-1].numsectsowned && i!=Playernum)
		     teleg_send(TELEG_PLAYER_AUTO, i, telegram_buf);
  }

  if (s->whatdest==LEVEL_PLAN)
  	printf("ship #%d landed on planet.\n",shipno);
  else
	printf("ship #%d docked.\n",shipno);
  free(s);
}



land_handler(sig, code, scp)
int sig,code;
struct sigcontext *scp;
{
 close(land_pdata);
 close(land_shdata);
 close(land_sectdata);
 close(land_shfdata);
 Ignore_filelocks = 0;
 longjmp(main_jenv,1);
}