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 p

⟦379eb7dda⟧ TextFile

    Length: 988 (0x3dc)
    Types: TextFile
    Names: »perm.c«

Derivation

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

TextFile


/*
 * Galactic Bloodshed (Robert Chansky, smq@ucscb.ucsc.edu)
 * perm.c -- randomly permute a sector list
 */

#include "vars.h"

struct map {
	char x,y;
} xymap[(MAX_X+1) * (MAX_Y+1)];


/* make a random list of sectors. */
PermuteSects(planet)
planettype *planet;
{
register int i,j,x,y;
struct map sw;

  for (i=x=y=0; i < planet->Maxy*planet->Maxx; i++) {
	xymap[i].x = x;
	xymap[i].y = y;
	if (++x >= planet->Maxx)
		x=0,y++;
  }
  for (i=0; i<planet->Maxy*planet->Maxx; i++) {
  	sw = xymap[i];
	xymap[i] = xymap[j = int_rand(0,planet->Maxy*planet->Maxx - 1)];
	xymap[j] = sw;
  }

}


/* get the next x,y sector in the list.  if r=1, reset the counter.
**  increments the counter & returns whether or not this reset it to 0.
*/

int Getxysect(p,x,y,r)
reg planettype *p;
reg int *x,*y,r;
{
  static int getxy,max;

  if (r) {
	getxy = 0;
	max = p->Maxx * p->Maxy;
  } else {
	  *x = xymap[getxy].x;
	  *y = xymap[getxy].y;
	  if (++getxy > max)
		getxy = 0;
  }
  return getxy;
}