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 m

⟦46decbd7d⟧ TextFile

    Length: 9536 (0x2540)
    Types: TextFile
    Names: »makeplanet.c.orig«

Derivation

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

TextFile

/*
 * Galactic Bloodshed (Robert Chansky, smq@b)
 *	makeplanet.c -- makes one planet.  used with makeuniv
 */

#include "tweakables.h"
#include "vars.h"
#include <math.h>
long random();
double Distmap();	/* (different distmap from the shell one */


planettype Makeplanet(type)
int type;
{
register int x,y;
sectortype *s;
planettype planet;
int i, atmos;

  Bzero(planet);
  bzero((char *)Smap, sizeof(Smap));
  planet.type = type;
  planet.expltimer = 5;

if (type==TYPE_GASGIANT) {			/* gas giant */
  planet.Maxx = GASGIANT_RANGE;
  planet.Maxy = round_rand((float)planet.Maxx / RATIOXY);

  planet.conditions[TEMP] = 		/* change to more real range */
  	planet.conditions[RTEMP] = int_rand(-50,50);	
	/* either lots of meth or not too much */
  if (random()&01) {	/* methane planet */
    atmos = 100 - (planet.conditions[METHANE] = int_rand(70,80)); 
    atmos -= planet.conditions[HYDROGEN] = int_rand(1,atmos/2);
    atmos -= planet.conditions[HELIUM] = 1;
    atmos -= planet.conditions[OXYGEN] = 0;
    atmos -= planet.conditions[CO2] = 1;
    atmos -= planet.conditions[NITROGEN] = int_rand(1,atmos/2);
    atmos -= planet.conditions[SULFUR] = 0;
    planet.conditions[OTHER] = atmos;
  } else {
    atmos = 100 - (planet.conditions[HYDROGEN] = int_rand(30,55));
    atmos -= planet.conditions[HELIUM] = int_rand(30,atmos/2);
    atmos -= planet.conditions[METHANE] = random()&01;
    atmos -= planet.conditions[OXYGEN] = 0;
    atmos -= planet.conditions[CO2] = random()&01;
    atmos -= planet.conditions[NITROGEN] = int_rand(1,atmos/2);
    atmos -= planet.conditions[SULFUR] = 0;
    planet.conditions[OTHER] = atmos;
  }

  for (y=0; y<planet.Maxy; y++)
     for (x=0; x<planet.Maxx; x++) {
	s = &Sector(planet,x,y);
	s->des = DES_GAS;	/* for gasgiant */
	s->fert=1;
     }
 if (planet.Maxx > MAP_GASGIANT_BANDMIN) {
    int nbands;
    nbands = MAX(1,planet.Maxy/5);
    for (i=1; i<=nbands; i++) {
     y=int_rand(1,planet.Maxy-2);
     for (x=0; x<planet.Maxx; x++) {
	s = &Sector(planet,x,y);
	s->des = DES_SEA;	/* make random bands of water */
	s->fert += int_rand(2,3);
     }
    }
    for (i=0; i<=MAP_ISLANDS*2; i++) {
     y=int_rand(1,planet.Maxy-2);
     x=int_rand(1,planet.Maxx-2);
	s = &Sector(planet,x,y);
	s->des = DES_SEA;	/* make random spots of water */
	s->fert += int_rand(2,3);
    }
 } else {
    for (i=0; i<MAP_ISLANDS*2; i++) {
	s = &Sector(planet, int_rand(1,planet.Maxx-2), int_rand(1,planet.Maxy-2));
	if (random()&01) {
		s->des=DES_MOUNT;
		s->is_wasted = 1;
		s->resource=int_rand(5,12);
		s->fert=int_rand(5,12);
	} else {
		s->des=DES_SEA;
		s->fert=int_rand(5,12);
	}
    }
  Smashup(&planet,int_rand(2,4),DES_SEA,0,0,0);
  Smashup(&planet,int_rand(1,2),DES_LAND,2,3,1);
 }

} else if (type==TYPE_AIRLESS) {	/* make airless wasted planet */
    planet.conditions[RTEMP] = 
    	planet.conditions[TEMP] = int_rand(-50,50);
    planet.conditions[HYDROGEN] = 0;
    planet.conditions[HELIUM] = 0;
    planet.conditions[METHANE] = 0;
    planet.conditions[OXYGEN] = 0;
    atmos = 100 - (planet.conditions[CO2] = int_rand(30,45));
    atmos -= planet.conditions[NITROGEN] = int_rand(10, atmos/2);
    atmos-=planet.conditions[SULFUR] = random()&01 ? 0 : int_rand(20, atmos/2);
    atmos-=planet.conditions[OTHER] = atmos;

  planet.Maxx = AIRLESS_RANGE;
  planet.Maxy = round_rand(planet.Maxx / RATIOXY);
  for (y=0; y<planet.Maxy; y++)
     for (x=0; x<planet.Maxx; x++) {
	s = &Sector(planet,x,y);
	s->des = DES_MOUNT;	/* for airless */
	/*s->is_wasted=1;	/* is wasteland */
	s->resource=int_rand(25,35);
	s->fert=1;
     }
     for (i=0; i<MAP_ISLANDS; i++) {
	s = &Sector(planet, int_rand(1,planet.Maxx-2), int_rand(1,planet.Maxy-2));
	s->des = DES_LAND;
	s->fert += random()&01;
	s->resource+=int_rand(15,22);
     }
  Smashup(&planet,6,DES_LAND,5,1,1);	/* make meteor impacts */

} else if (type==TYPE_ASTEROID) {   /* asteroid */
	/* no atmosphere */
    planet.conditions[HYDROGEN] = 0;
    planet.conditions[HELIUM] = 0;
    planet.conditions[METHANE] = 0;
    planet.conditions[OXYGEN] = 0;
    planet.conditions[CO2] = 0;
    planet.conditions[NITROGEN] = 0;
    planet.conditions[SULFUR] = 0;
    planet.conditions[OTHER] = 0;
  planet.Maxx = ASTEROID_RANGE_X;
  planet.Maxy = ASTEROID_RANGE_Y;
  for (y=0; y<planet.Maxy; y++)
     for (x=0; x<planet.Maxx; x++) {
	s = &Sector(planet,x,y);
	s->des = int_rand(0,3) ? DES_MOUNT : DES_LAND;
	s->is_wasted=1;
	s->resource=int_rand(55,85);
	s->fert=(char)random()&01;
     }
  
} else if (type==TYPE_EARTH) {	/* make an earthtype planet */
  int i,landsects,Numlandsects;
    planet.conditions[RTEMP] =
    	planet.conditions[TEMP] = int_rand(-50,50);
  if (random()&01) {
	/* oxygen-reducing atmosphere (Earth type) */
    atmos = 100 - (planet.conditions[OXYGEN] = int_rand(10,25));
    atmos -= planet.conditions[NITROGEN] = int_rand(20,atmos/2);
    atmos -= planet.conditions[CO2] = int_rand(20,atmos/2);
    atmos -= planet.conditions[HELIUM] = int_rand(2,atmos/8+1);
    atmos -= planet.conditions[METHANE] = random()&01;
    atmos -= planet.conditions[SULFUR] = 0;
    atmos -= planet.conditions[HYDROGEN] = 0;
    planet.conditions[OTHER] = atmos;
  } else {
	/* methane atmosphere */
    atmos = 100 - (planet.conditions[METHANE] = int_rand(70,80)); 
    atmos -= planet.conditions[HYDROGEN] = int_rand(1,atmos/2);
    atmos -= planet.conditions[HELIUM] = 1;
    atmos -= planet.conditions[OXYGEN] = 0;
    atmos -= planet.conditions[CO2] = 1;
    atmos -= planet.conditions[NITROGEN] = int_rand(1,atmos/2);
    atmos -= planet.conditions[SULFUR] = 0;
    planet.conditions[OTHER] = atmos;
  }
  planet.Maxx=EARTHTYPE_RANGE;
  planet.Maxy=round_rand(planet.Maxx/RATIOXY);	/* may haveta change this */
  Numlandsects=planet.Maxx*planet.Maxy*LANDPERCENTAGE;

  for (y=0; y<planet.Maxy; y++)
     for (x=0; x<planet.Maxx; x++) {
	s = &Sector(planet,x,y);
	s->des=DES_SEA;	/* make all water first */
     }
		/* make first isolated islands */
  for (i=0; i<=MAP_ISLANDS; i++) {
     s = &Sector(planet, int_rand(planet.Maxx/5,planet.Maxx-planet.Maxx/5),
	     int_rand(1,planet.Maxy-2));
     s->des = DES_LAND;  
     s->resource = 100;
     s->fert = int_rand(6,20);
  }

  PermuteSects(&planet);	/* mix up map */
  (void)Getxysect(&planet,0,0,1);	/* reset index */

  landsects=0;
  while (landsects<=Numlandsects)
       landsects += Volcano(&planet,landsects,Numlandsects); 
		   /* pick rndm locn, return whether island or not */


		/* make more isolated islands */
  for (i=0; i<=MAP_ISLANDS*4; i++) {
     x=int_rand(0,planet.Maxx-1);
     y=int_rand(0,planet.Maxy-1);
     s = &Sector(planet,x,y);
     s->des = DES_LAND;
     s->resource = 55;	/* nice odd number */
		  /* min content prop to dist from sea */
     s->fert = 45;
  }
	/* make some wasteland sectors (polar caps ) */
	/* do s pole */
  for (y=planet.Maxy; y>=planet.Maxy-4; y--)
     for (x=0; x<planet.Maxx; x++)
	if ( ((y==planet.Maxy-1) && int_rand(0,1)) ||
		((y==planet.Maxy-2) && !int_rand(0,2) && Sector(planet,x,planet.Maxy).is_wasted) ) {
	  Sector(planet,x,y).is_wasted=1;
	  Smap[y*planet.Maxx+x].fert /= 6;
     	}
	/* do n pole */
  for (y=0; y<=3; y++)
     for (x=0; x<planet.Maxx; x++)
	if ( ((y==0) && int_rand(0,1)) ||
		((y==1) && !int_rand(0,2) && Smap[x].is_wasted) ) {
	  Smap[y*planet.Maxx+x].is_wasted=1;
	  Smap[y*planet.Maxx+x].fert /= 6;
        }
 }
/*###222 [lint] syntax error at or near word "return"%%%*/
 return ( planet );
/*###223 [lint] syntax error at or near symbol }%%%*/
}


Smashup(pptr,n,desig,res,fert,waste)	
planettype *pptr;
int n;
char desig;
bool res,fert,waste;
		/* smash psuedo-meteors into the place */
{
char r,x,y;
register int x2,y2;
sectortype *s;

 while (n--) {
    x=int_rand(1,pptr->Maxx-2);
    y=int_rand(1,pptr->Maxy-2);
    r=int_rand(2,int_rand(2,pptr->Maxy/3+1));
    for (y2=y-r-1; y2<=y+r+1; y2++)
       for (x2=x-r-1; x2<=x+r+1; x2++)
	  if (Distmap(x,y,x2,y2) < r) 
	     if ((x2<pptr->Maxx)&&(x2>=0)&&(y2<pptr->Maxy)&&(y2>=0)) {
		s = (&(Smap[y2*pptr->Maxx+x2]));
		if (desig==DES_LAND && s->des==DES_MOUNT)
			s->des = DES_LAND;
		else if (desig==DES_LAND && s->des==DES_LAND)
			s->des = DES_MOUNT;
		if (waste) s->is_wasted=1;
		if (res) s->resource+=int_rand(res/2,res*2);
		if (fert) s->fert+=int_rand(fert/2,fert*2);
	     }
 }

}



double Distmap(x,y,x2,y2)
register int x,y,x2,y2;
{
 return fabs((double)x-x2) / RATIOXY + fabs( (double)y-y2);
}


int Volcano(pptr,landsectors,Numlandsects)
planettype *pptr;
int landsectors,Numlandsects;
{
int x,y;
sectortype *s;

  (void)Getxysect(pptr,&x,&y,0);
  /*x = int_rand(0,pptr->Maxx-1);
  y = int_rand(0,pptr->Maxy-1);*/
  s = &Sector(*pptr,x,y);

  if (s->des==DES_SEA) {
    if (Numneighbors(pptr,x,y,DES_LAND)||Numneighbors(pptr,x,y,DES_MOUNT)) {
	s->des=(landsectors>(MAP_MOUNT_PERCENT*Numlandsects))?DES_LAND:DES_MOUNT;
	s->resource = round_rand((float)(Numlandsects - landsectors + 5) / (float)Numlandsects * 100);
		  /* min content prop to dist from sea */
	s->fert = (float)(landsectors + 5) / (float)Numlandsects * 100;
		  /* fert content prop to dist from center of continent */
       return(1);
    } else return(0);
   } else return(0);
}



/* return # of neighbors of a given designation that a sector has. */
int Numneighbors(p,x,y,des)
planettype *p;
register int x,y,des;
{
register int d;
  return (Sector(*p,mod(x-1,p->Maxx,d),y).des==des) + 
  	 (Sector(*p,mod(x+1,p->Maxx,d),y).des==des) + 
  	 ((y==0) ? 0 : (Sector(*p,x,y-1).des==des)) + 
  	 ((y==p->Maxy-1) ? 0 : (Sector(*p,x,y+1).des==des));
}