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

⟦a84d40f0f⟧ TextFile

    Length: 8731 (0x221b)
    Types: TextFile
    Names: »load.c«

Derivation

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

TextFile


/*
 * Galactic Bloodshed (Robert Chansky, smq@b)
 *  load.c -- load/unload stuff
 */

#include "vars.h"
#include "ships.h"
#include "races.h"
#include <curses.h>
#include <signal.h>
#include <setjmp.h>
extern jmp_buf main_jenv;
extern int Ignore_filelocks;
extern char telegram_buf[AUTO_TELEG_SIZE];
int load_shdata,load_pdata,load_sectdata;


load(APcount, argn,args)
int APcount;
int argn;
char args[MAXARGS][COMMANDSIZE];
{
bool jett=0,sh=0;
int first=1,proc,Mod=0,lolim,uplim,shipno,amt;
char commod, buf[100],bufr[70],bufd[70],buff[70],bufc[70];
shiptype *s,*s2;
planettype *p;
sectortype *sect;
int load_handler();

    load_shdata = load_pdata = load_sectdata = NEUTRAL_FD;
    signal(SIGINT, load_handler);

    if (argn==1) {
      printf("ship #");
      scanf("%d",&shipno);
      getchr();
    } else 
	shipno = atoi(args[1] + ((args[1][0])=='#') ? 1 : 0);

    openshdata(&load_shdata);
    if (!getship(load_shdata,&s,shipno)) {
	load_handler();
    }
    if (s->owner!=Playernum || s->is_dead) {
	DontOwnErr(shipno);
	printf("(%d)\n",s->owner);
	free(s);
	load_handler();
    }
    if (s->rad) {
	printf("%s #%d is irradiated and inactive.\n", Shipnames[s->type],shipno);
	free(s);
	load_handler();
    }


   do {

    proc = 0;

    if (s->type == OTYPE_TRANSDEV) {
	Ignore_filelocks = 1;
	if (!getship(load_shdata,&s2, s->orders.object.number)) {
		printf("The hopper seems to be blocked.\n");
		load_handler();
	}
	Ignore_filelocks = 0;
	if (s2->is_dead) {
		printf("The target device does not exist.\n");
		load_handler();
	}
	if (s2->type!=OTYPE_TRANSDEV || !s2->orders.object.on) {
		printf("The target device is not receiving.\n");
		load_handler();
	}
    } else if (!s->is_docked) {
	if (s->type==OTYPE_TRANSDEV) {
		printf("It does not seem to work in zero-g environments.\n");
		load_handler();
	}
	printf("%s #%d is not landed.\n",is_object(s)?"object":"ship",shipno);
      	tty_on();
	printf("  jettison into open space (y/n)?");
	jett = 1;
      	commod=getchr();
      	tty_off();
      	if (commod!='y')
		load_handler();
    } else {
	if (s->whatdest==LEVEL_PLAN)
		printf("Ship #%d at %.2f,%.2f\n", shipno,s->xpos, s->ypos);
	else {
		Ignore_filelocks = 1;
		if (!getship(load_shdata, &s2, s->destshipno) || s2->is_dead ||
			!(s2->is_docked && s2->whatdest==LEVEL_SHIP) ) {
				/* the ship it was docked with died or
				   something. */
			s->is_docked = 0;
			s->whatdest = LEVEL_UNIV;
			putship(load_shdata, &s, shipno);
			printf("ship is not docked.\n");
			load_handler();
		}
		Ignore_filelocks = 0;
		printf("Ship #%d docked with %s #%d\n", shipno, 
				Shipnames[s2->type], s->destshipno);
		sh = 1;
	}
    }


    if (!jett && !sh) {
    	openpdata(&load_pdata);
    	getplanet(load_pdata,&p,Stars[Dir.snum]->planetpos[Dir.pnum]);
    }

    if (first) {
      if (s->whatorbits==LEVEL_UNIV)
    	if (!enufAP(Sdata.AP, APcount))
		load_handler();
      else 
	if (!enufAP(Stars[s->storbits]->AP, APcount))
		load_handler();
    }


   do {

    tty_on();
    printf("%s #%d:(rfdc? q) >", Shipnames[s->type], shipno);
    commod = getchr();
    putchr('\n');
    tty_off();

    if (!jett && !sh && commod=='c') {
    	opensectdata(&load_sectdata);
    	getsector(load_sectdata,&sect,p->sectormappos + ( (int)s->ypos*p->Maxx+(int)s->xpos) * sizeof(sectortype) );
    }

    switch (commod) {
	case 'c': lolim = - s->popn;
		  uplim = jett ? 0 : sh ? s2->popn :
			MIN(sect->popn, 
				 Shipdata[s->type][ABIL_MAXCREW] - s->popn);
		  proc = 1;
		  break;
	case 'd': lolim = - s->destruct;
		  uplim = jett ? 0 : sh ? s2->destruct :
			MIN(p->info[Playernum-1].destruct,
			         Shipdata[s->type][ABIL_DESTCAP] - s->destruct);
		  proc = 1;
		  break;
	case 'f': lolim = - s->fuel;
		  uplim = jett ? 0 : sh ? s2->fuel :
			MIN(p->info[Playernum-1].fuel,
			         Shipdata[s->type][ABIL_FUELCAP] - s->fuel);
		  proc = 1;
		  break;
	case 'r': lolim = - s->resource;
		  uplim = jett ? 0 : sh ? s->resource :
			MIN(p->info[Playernum-1].resource,
			         Shipdata[s->type][ABIL_CARGO] - s->resource);
		  proc = 1;
		  break;
	case '?': printf("\nship #%3d:\n",shipno);
		  printf("       res:%u\n       fuel:%.1f\n       crew:%u\n       dest:%u\n", s->xpos,s->ypos, s->resource, s->fuel, s->popn, s->destruct);
		  if (sh) {
			printf("docked with %s #%d:\n",s->destshipno);
			printf("       res:%u\n       fuel:%.1f\n       crew:%u\n       dest:%u\n", s2->xpos,s2->ypos, s2->resource, s2->fuel, s2->popn, s2->destruct);
		  }
		  proc = 0;
		  break;
	case 'q':
	case ' ':
		  load_handler();
		  break;
	default:  printf("%c not valid.\n",commod);
		  proc = 0;
		  load_handler();
      }
     } while (!proc);

      tty_off();
      amt = uplim + 1;
      while (amt<lolim || amt>uplim) {
	  printf("      amount (%d to %d) ",lolim,uplim);
	  if (scanf("%d",&amt)!=1) 
		amt=uplim+1;	/* force error */
	  getchr();
      }
    if (amt == 0)
	 load_handler();

    switch (commod) {
	case 'c': if (!jett) {
			if (sh) {
				s2->popn -= amt;
				s2->mass -= amt*Race->mass;
			} else {
		  	   if (sect->popn==0 && amt<0) {
				p->info[Playernum-1].numsectsowned++;
				sect->owner = Playernum;
				printf("sector %.0f,%.0f COLONIZED.\n",s->xpos,s->ypos);
		  	   }
		  	   sect->popn -= (us)amt;
		  	   p->popn -= amt;
		  	   if (sect->popn==0) {
				p->info[Playernum-1].numsectsowned--;
				sect->owner = 0;
				printf("sector %.0f,%.0f evacuated.\n",s->xpos,s->ypos);
		  	   }
			}
		  }
		  printf("crew complement of ship #%d is now %u.\n", 
			shipno, s->popn+amt);
		  s->popn += amt;
		  s->mass += amt*Race->mass;
		  Mod = 1;
		  break;
	case 'd': s->destruct += amt;
		  s->mass += amt*MASS_DESTRUCT;
		  if (!jett)
		  	p->info[Playernum-1].destruct -= amt;
		  else if (sh) {
			s2->destruct -= amt;
			s2->mass -= amt*MASS_DESTRUCT;
		  }
		  Mod = 1;
		  break;
	case 'f': s->fuel += amt;
		  s->mass += amt*MASS_FUEL;
		  if (!jett)
		  	p->info[Playernum-1].fuel -= amt;
		  else if (sh) {
			s2->fuel -= amt;
			s2->mass -= amt*MASS_FUEL;
		  }
		  Mod = 1;
		  break;
	case 'r': s->resource += amt;
		  s->mass += amt*MASS_RESOURCE;
		  if (!jett)
		  	p->info[Playernum-1].resource -= amt;
		  else if (sh) {
			s2->resource -= amt;
			s2->mass -= amt*MASS_FUEL;
		  }
		  Mod = 1;
		  break;
	case 'q':
	case ' ':
	case '?':
	default:
		break;
    }

    putship(load_shdata,s,shipno);

    if (s->type==OTYPE_TRANSDEV || sh) {
	/* send stuff to other transport device */
	if (s->resource) {
		printf("Zap! %d resources sent.\n", s->resource);
		sprintf(bufr, "%d Resources\n",s->resource);
		s2->mass += s->resource * MASS_RESOURCE;
		s2->resource += s->resource;
		s->mass -= s->resource * MASS_RESOURCE;
		s->resource = 0;
	} else
		bufr[0] = '\0';
	if (s->fuel) {
		printf("Zap! %g fuel sent.\n", s->fuel);
		sprintf(buff, "%g Fuel\n",s->fuel);
		s2->fuel += s->fuel;
		s2->mass += s->fuel * MASS_FUEL;
		s->mass -= s->fuel * MASS_FUEL;
		s->fuel = 0.0;
	} else
		buff[0] = '\0';
	if (s->destruct) {
		printf("Zap! %d destruct sent.\n", s->destruct);
		sprintf(bufd, "%d Destruct\n",s->destruct);
		s2->mass += s->destruct * MASS_DESTRUCT;
		s2->destruct += s->destruct;
		s->mass -= s->destruct * MASS_DESTRUCT;
		s->destruct = 0;
	} else
		bufd[0] = '\0';
	if (s->popn) {
		printf("Zap! %d popn sent.\n", s->popn);
		sprintf(bufc, "%d %s\n",s->destruct,Race->Thing?"tons of biomass" : "population");
		s2->mass += s->popn * Race->mass;
		s2->popn += s->popn;
		s->mass -= s->popn * Race->mass;
		s->popn = 0;
	} else
		bufc[0] = '\0';
	putship(load_shdata,s2,s->orders.object.number);

      if (s2->owner!=s->owner) {
	teleg_add("", telegram_buf);
	teleg_add("BULLETIN!\n\n Audio-vibatory-physio-molecular transport device #",telegram_buf);
	sprintf(buf,"%d just gave your ship #%d the following:\n", shipno, s->orders.object.number);
	teleg_add(buf,telegram_buf);
	teleg_add(bufr,telegram_buf);
	teleg_add(bufd,telegram_buf);
	teleg_add(buff,telegram_buf);
	teleg_add(bufc,telegram_buf);
	teleg_send(TELEG_PLAYER_AUTO, s2->owner, telegram_buf);
      }
    }


    if (!jett && !sh) {

      if (commod=='c') {
	putsector(load_sectdata,sect,p->sectormappos + ( (int)s->ypos*p->Maxx+(int)s->xpos) * sizeof(sectortype) );
    	close(load_sectdata);
	free(sect);
       }

       putplanet(load_pdata,p,Stars[Dir.snum]->planetpos[Dir.pnum]);
       close(load_pdata);
       free(p);
     }

    if (Mod && first) {
         first = 0;
         if (s->whatorbits==LEVEL_UNIV)
		deductAPs(APcount, 0, 1);	/* ded from sdata */
         else 
		deductAPs(APcount, s->storbits, 0);

    }

   } while (1);



}



load_handler()
{
 Ignore_filelocks = 0;
 close(load_shdata);
 close(load_pdata);
 close(load_sectdata);
 longjmp(main_jenv,1);
}