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 d

⟦5d3e7d87b⟧ TextFile

    Length: 6938 (0x1b1a)
    Types: TextFile
    Names: »dosector.c«

Derivation

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

TextFile

/*
 * Galactic Bloodshed (Robert Chansky, smq@b)
 *  dosector.c 
 *  dosector() -- do spread, produce, stuff like that, on a sector.
 *  explore()  -- mark sector and surrounding sectors as having been explored.
 */ 

#include "vars.h"
#include "races.h"
#include "ships.h"
#include "doturn.h"
#include <math.h>
extern int tot_resdep,tot_eff,tot_res,tot_fuel,tot_destruct,
	tot_captured,tot_mob;
extern float avg_mob[MAXPLAYERS];
extern char sects_gained[MAXPLAYERS], sects_lost[MAXPLAYERS];
extern bool Claims;

		/* produce stuff in sector */
produce(planet,s)
reg planettype *planet;
reg sectortype *s;
{
reg float factor;
reg int eff;
reg struct plinfo *pinf;
reg int new;

	 factor = logscale(s->popn)*s->resource * races[s->owner]->metabolism;

	 pinf = &planet->info[s->owner-1];

	 if (planet->type==TYPE_GASGIANT)
		tot_fuel = pinf->fuel = 1000000;
	 else {
		pinf->fuel+=(new = round_rand(logscale(s->eff)*factor*FUEL_PRODUCTION) );
		tot_fuel += new;
	 }

	 pinf->resource += (new = round_rand( logscale(s->eff)*factor*RESOURCE_PRODUCTION ) );
	 tot_res += new;

		/* increase mobilization to planetary quota */
	 if (s->mobilization < pinf->mob_set)
		if (pinf->resource) {
			s->mobilization++;
			pinf->resource -= round_rand(MOB_COST);
			tot_mob++;
	 	}


	 pinf->destruct += (new = round_rand( logscale(s->eff)*factor*(s->mobilization/100.0)*DEST_PRODUCTION ) );
	 tot_destruct += new;
	   /* deplete resources for making weapons */
	 tot_resdep += (new = (s->resource<=1) ? 0 : round_rand((1.1-logscale(s->eff))*factor*RESOURCE_DEPLETION) );
	 s->resource -= new;

	  /* add mobilization to get average mobilization */
	 avg_mob[s->owner] += s->mobilization;

	  /* do efficiency */
	 if (s->eff<100) {
	   if (!s->eff) {
		tot_eff += s->eff = 1;
	   } else {
	     /*tot_eff += eff = round_rand(races[s->owner]->metabolism*s->popn*(0.95-logscale(s->eff))*EFF_PROD);*/
	     tot_eff += eff = round_rand(races[s->owner]->metabolism*s->popn*EFF_PROD/100.0);
		if (s->eff+eff >= 100) {
			s->eff=100;	/* dont go past 100%*/
			tot_eff -= s->eff+eff-100;
			s->des = DES_PLATED;
		} else 
			s->eff += eff;
	   }
	}

	  /* add population to sector */
	 if (s->popn >= races[s->owner]->number_sexes)
	    /*if (s->popn < maxsupport(s) )*/
	       s->popn += round_rand((float)s->popn*races[s->owner]->birthrate * Compat[s->owner]/100.0 * (50.0-planet->conditions[TOXIC])/50.0 );
	    /*else 
	       s->popn += round_rand((float)s->popn*races[s->owner]->overbirthrate * Compat[s->owner]/100.0 * (50.0-planet->conditions[TOXIC])/50.0 );*/
	 else
		s->popn -= round_rand(s->popn * .01);
	
}


/*
 * spread population to surrounding sects. 
 *
 *	the way people move depends on the population of the planet unless 
 *	NO_SLIDING_SCALE_AUTOMOVE is set (again for reasons of computer 
 *	power).  Otherwise, the populace will automatically migrate to all 
 *	available surrounding areas if the planetary population is less than
 *	POPN_MOVE_SCALE_1, to either north-south or east-west areas if the
 *	population is less than POPN_MOVE_SCALE_2, and to only one adjacent
 *	random sector if it is greater.
 */


spread(pl,s,x,y)
reg planettype *pl;
reg sectortype *s;
reg int x,y;
{
reg int peep;

   /* peep == number of people who want to move */
if (peep = round_rand((float)s->popn * races[s->owner]->nonhomebodies) ) {

#if NO_SLIDING_SCALE_AUTOMOVE
 if (pl->popn < POPN_MOVE_SCALE_1) {
#endif
	Migrate2(pl,x+1,y,s,peep/4);
	Migrate2(pl,x-1,y,s,peep/4);
	Migrate2(pl,x,y+1,s,peep/4);
	Migrate2(pl,x,y-1,s,peep/4);
#if NO_SLIDING_SCALE_AUTOMOVE
 }
 else if (pl->popn < POPN_MOVE_SCALE_2) {
   x2 = int_rand(-1,1);
   y2 = (!x2) ? rposneg() : 0;	 /* 1/3 chance of migrating n-s*/
	Migrate2(pl,x+x2,y+y2,s,peep/2);   
	Migrate2(pl,x-x2,y-y2,s,peep/2);
			/* migrate to destination, from source */
 } else {
	Migrate2(pl, x + rposneg(), y + rposneg(), s, peep);
 }

#endif
}
}



Migrate2(planet,xd,yd,ps,people)
planettype *planet;
reg int xd,yd;
sectortype *ps;
reg int people;
{
reg sectortype *pd;

	/* attempt to migrate beyond screen */
 if ((yd>=planet->Maxy) || (yd<0) || !people ) 
	return;	

 if (xd<0) 
	xd=planet->Maxx-1;
 else if (xd>=planet->Maxx) 
	xd=0;

 pd = &Sector(*planet,xd,yd);

	/* check for planetary compatibility */
 if (float_rand()*100.0 > Compat[ps->owner] * races[ps->owner]->likes[pd->des]) {
	/*printf("%d,%d incomp C %.2f,l %.f-- returning\n",xd,yd,Compat[ps->owner],races[ps->owner]->likes[pd->des]);*/
	return;
 }

 if ( (ps->owner==pd->owner || !pd->owner) && !pd->is_wasted) {

 	if (!pd->owner) {
		printf("claiming %d,%d (%d), %d people\n",xd,yd,ps->owner,people);
        	pd->popn += people;
        	ps->popn -= people;	/* move people */
		pd->owner = ps->owner;
		tot_captured++;
		planet->info[pd->owner-1].numsectsowned++;
		Claims = 1;
 	} else if (pd->owner==ps->owner) {
        	pd->popn += people;
        	ps->popn -= people;
	} else if (isset(races[ps->owner]->atwar, pd->owner) || races[ps->owner]->Thing) {
			/* we are at war with them; do land combat */
		reg float dfac;

		ps->popn -= round_rand(((float)ps->popn * pd->mobilization * 
			planet->info[pd->owner-1].comread + races[pd->owner]->fighters*20)/200.0);
		dfac = ( (float)pd->popn * ps->mobilization * 
			planet->info[ps->owner-1].comread + races[pd->owner]->fighters*20)/200.0;
		printf(" att %d lost %g people of %d.\n",ps->owner,
			((float)ps->popn * pd->mobilization * 
			planet->info[pd->owner-1].comread + races[pd->owner]->fighters*20)/200.0, pd->popn);
		if (pd->popn - dfac <= 0.0) {
			    /* the invasion was successful */
			if (races[ps->owner]->Thing) {
				 /* mesos absorb the bodies of enemies */
				pd->popn += MIN(people, ps->popn);
				ps->popn -= MIN(people, ps->popn);
			} else {
				pd->popn = MIN(people, ps->popn);
				ps->popn -= MIN(people, ps->popn);
			}
			sects_lost[pd->owner]++;
			sects_gained[ps->owner]++;
			pd->owner = ps->owner;
			pd->eff *= 0.75;
			pd->mobilization *= 0.75;
			tot_captured++;
			printf(" sec %d,%d CAPTURED",xd,yd);
		} else 
		   pd->popn -= round_rand(dfac);
			
		printf(" def %d lost %g people of %d,",pd->owner,
			((float)pd->popn * ps->mobilization * 
			planet->info[ps->owner-1].comread + races[pd->owner]->fighters*20)/200.0, pd->popn);
 	}
   }
}


/* mark sectors on the planet as having been "explored." for sea exploration
	on earthtype planets.  */

explore(planet, s, x, y, p)
reg planettype *planet;
reg sectortype *s;
reg int x,y,p;
{
reg int d;

	/* explore sectors surrounding sectors currently explored. */
 if (Sectinfo[x][y].explored[p]) {

    Sectinfo[mod(x-1,planet->Maxx,d)][y].explored[p] = 1;
    Sectinfo[mod(x+1,planet->Maxx,d)][y].explored[p] = 1;
    if (y==0) {
	Sectinfo[x][1].explored[p] = 1;
    } else if (y==planet->Maxy-1) {
	Sectinfo[x][y-1].explored[p] = 1;
    } else {
	Sectinfo[x][y-1].explored[p] = Sectinfo[x][y+1].explored[p] = 1;
    }
 
 } else if (s->owner==p)
	Sectinfo[x][y].explored[p] = 1;

}