1,000,000 stars

By Jo Jaquinta ·

TML message #899From bundle 83

	The program in the following shell archive will allow one to
	explore a universe of over 1,000,000 stars. The idea was for it
	to be used as a campaign setting and would be ideal for anyone
	running a PBeM game on more than one world. The program should
	generate the same universe for everyone allowing mutual exploration
	and discussion.

	This program is level-1 and only generates mainworlds. Later
	levels will generate entire systems, geological data and all the
	way down to regional and city maps. If characteers can turn to their
	library data and pull up info on almost anywhere in the galaxy then
	why not the players?

	I don't mean to tread on the system-generation sublist's toes but
	this is rather different. Instead of a suite of programs to
	generate systems to suit the flexibility of individual's campaigns
	I have accepted rigidity for scope. The code is built in such
	a way that a host of subsidiary programs can be generated based on the
	central routines (sector maps, trade routes, ...).

	I have the later levels planned and specified but time pressure
	will delay their release. Any volunteers are most welcome.

					Jo Jaquinta
					[email removed]

			cut here
- --------------------------><--><--><-------------------------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  exist.c lang.c magic.c magic.h mainwrld.c readme sysgen.h
#   sysgen1.c
# Wrapped by [email removed] on Thu Feb  1 11:47:49 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'exist.c' -a "${1}" != "-c" ; then
  echo shar: Will not clobber existing file \"'exist.c'\"
else
echo shar: Extracting \"'exist.c'\" \(451 characters\)
sed "s/^X//" >'exist.c' <<'END_OF_FILE'
X#include "sysgen.h"
X
X#define abs(t) ((t<0L)?(-t):(t))
X
Xint	exist(x, y, z)
Xlong	x, y, z;
X{
X	int	chance, roll;
X	long	mag;
X
X	mag = abs(x) + abs(y) + abs(z);
X	chance = 80 - (int)(80L*mag/GAL_RADIUS);
X	xyzmagic(x>>4, y>>4, z>>4, EXIST_MAGIC);	/* sector density variation */
X	chance += (rand()%40) - 20;
X	xyzmagic(x, y, z, EXIST_MAGIC);
X	roll = rand()%100;
X	if (roll > chance)
X		return(0);
X	chance /= 20;
X	if (++chance > 4)
X		chance = 4;
X	return(chance);
X}
END_OF_FILE
if test 451 -ne `wc -c <'exist.c'`; then
    echo shar: \"'exist.c'\" unpacked with wrong size!
fi
# end of 'exist.c'
fi
if test -f 'lang.c' -a "${1}" != "-c" ; then
  echo shar: Will not clobber existing file \"'lang.c'\"
else
echo shar: Extracting \"'lang.c'\" \(2457 characters\)
sed "s/^X//" >'lang.c' <<'END_OF_FILE'
X#include "sysgen.h"
X
Xint	olen[6] = { 19, 11, 5, 1, 0, 0 };
Xint	oinitial[4] = { 5, 11, 8, 12 };
Xint	ofinal[4] = { 17, 3, 8, 8 };
Xint	ofcon[29] = { 10, 2, 13, 3, 9, 10, 2, 8, 2, 14, 2, 4, 13, 12, 6, 7,
X	2, 2, 7, 10, 7, 3, 13, 21, 2, 9, 13, 3, 7 };
Xchar	*afcon[29] = { "b", "br", "c", "ch", "d", "f", "fr", "g", "gr", "h",
X	"j", "k", "l", "m", "n", "p", "pl", "pr", "r", "s", "sh", "st",
X	"t", "th", "tr", "v", "w", "wh", "y" };
Xint	ovowel[6] = { 49, 73, 40, 38, 7, 9 };
Xchar	*avowel[6] = { "a", "e", "i", "o", "ou", "u" };
Xint	olcon[29] = { 3, 3, 22, 5, 2, 3, 2, 3, 2, 5, 2, 4, 41, 9, 9, 2,
X	3, 3, 36, 2, 2, 16, 2, 4, 21, 2, 3, 2, 3 };
Xchar	*alcon[29] = { "c", "ck", "d", "f", "ft", "gh", "ht", "l", "ld",
X	"ll", "ly", "m", "n", "nd", "ng", "ns", "nt", "p", "r", "rd",
X	"rs", "s", "ss", "st", "t", "th", "w", "x", "y" };
X
Xint	len[6];
Xint	initial[4];
Xint	final[4];
Xint	fcon[29];
Xint	vowel[6];
Xint	lcon[29];
X
Xvoid	seedlang(), drift(), scatter();
Xint	lookup();
X
Xvoid	seedlang(x, y, z)
Xlong	x, y, z;
X{
X	int	i;
X
X	for (i = 0; i < 6; i++)
X		len[i] = olen[i];
X	for (i = 0; i < 4; i++)
X	{
X		initial[i] = oinitial[i];
X		final[i] = ofinal[i];
X	}
X	for (i = 0; i < 6; i++)
X		vowel[i] = ovowel[i];
X	for (i = 0; i < 29; i++)
X	{
X		fcon[i] = ofcon[i];
X		lcon[i] = olcon[i];
X	}
X	/* sector drift */
X	xyzmagic(x>>6, y>>6, z>>6, LANG_MAGIC);
X	drift();
X	/* sub-sector drift */
X	xyzmagic(x>>4, y>>4, z>>4, LANG_MAGIC);
X	drift();
X	/* local drift */
X	xyzmagic(x, y, z, LANG_MAGIC);
X	drift();
X}
X
Xvoid	drift()
X{
X	scatter(initial, 4, 6);
X	scatter(len, 6, 6);
X	scatter(final, 4, 6);
X	scatter(fcon, 29, 36);
X	scatter(vowel, 6, 36);
X	scatter(lcon, 29, 36);
X}
X
Xvoid	scatter(arr, max_arr, slide)
Xint	arr[], max_arr, slide;
X{
X	int	i;
X
X	while (slide--)
X	{
X		/* take one away */
X		do {
X			i = rand()%max_arr;
X		} while (arr[i] == 0);
X		arr[i]--;
X		/* add back on */
X		i = rand()%max_arr;
X		arr[i]++;
X	}
X}
X
Xint	lookup(arr, tot)
Xint	arr[];
Xint	tot;
X{
X	int	i;
X
X	i = 0;
X	do {
X		tot -= arr[i++];
X	} while (tot >= 0);
X	return(i - 1);
X}
X
Xchar	*getname()
X{
X	static char	nbuf[40];
X	int	leng, type;
X
X	leng = lookup(len, rand()%36) + 1; /* assume names one extra syllable */
X	nbuf[0] = 0;
X	type = 0;
X	do {
X		type = lookup(type ? final : initial, rand()%36);
X		if (type%2)
X		{
X			strcat(nbuf, afcon[lookup(fcon, rand()%216)]);
X		}
X		strcat(nbuf, avowel[lookup(vowel, rand()%216)]);
X		if (type>1)
X		{
X			strcat(nbuf, alcon[lookup(lcon, rand()%216)]);
X		}
X		type = type/2;
X	} while (leng--);
X	return(nbuf);
X}
END_OF_FILE
if test 2457 -ne `wc -c <'lang.c'`; then
    echo shar: \"'lang.c'\" unpacked with wrong size!
fi
# end of 'lang.c'
fi
if test -f 'magic.c' -a "${1}" != "-c" ; then
  echo shar: Will not clobber existing file \"'magic.c'\"
else
echo shar: Extracting \"'magic.c'\" \(532 characters\)
sed "s/^X//" >'magic.c' <<'END_OF_FILE'
X#include "sysgen.h"
X
Xvoid	xyzmagic(x, y, z, magic)
Xlong	x, y, z, magic;
X{
X	long	seed;
X
X	x &= 0x07ff;
X	x <<= (32 - 11);
X	y &= 0x07ff;
X	y <<= (32 - 11 - 11);
X	z &= 0x03ff;
X	seed = x|y|z;
X	srand(seed + magic);
X}
X
Xint	D(n)
X{
X	int	sum;
X
X	sum = n;
X	while (n--)
X		sum += rand()%6;
X	return(sum);
X}
X
Xstatic long	randx;
Xstatic char	randf = 0;
X
Xvoid	srand(seed)
Xlong	seed;
X{
X	randx = seed;
X	randf = 1;
X}
X
Xunsigned int	rand()
X{
X	if (!randf)
X		srand(1L);
X	randx = randx*1103515245L + 12345L;
X	return ((unsigned int)(((randx)>>16) & 0777777));
X}
END_OF_FILE
if test 532 -ne `wc -c <'magic.c'`; then
    echo shar: \"'magic.c'\" unpacked with wrong size!
fi
# end of 'magic.c'
fi
if test -f 'magic.h' -a "${1}" != "-c" ; then
  echo shar: Will not clobber existing file \"'magic.h'\"
else
echo shar: Extracting \"'magic.h'\" \(73 characters\)
sed "s/^X//" >'magic.h' <<'END_OF_FILE'
X#define GAL_RADIUS 100000L
X
X#define LANG_MAGIC 1L
X#define EXIST_MAGIC 2L
END_OF_FILE
if test 73 -ne `wc -c <'magic.h'`; then
    echo shar: \"'magic.h'\" unpacked with wrong size!
fi
# end of 'magic.h'
fi
if test -f 'mainwrld.c' -a "${1}" != "-c" ; then
  echo shar: Will not clobber existing file \"'mainwrld.c'\"
else
echo shar: Extracting \"'mainwrld.c'\" \(2303 characters\)
sed "s/^X//" >'mainwrld.c' <<'END_OF_FILE'
X#include "sysgen.h"
X
Xchar	*strprt[4] = {
X	"AABBCCCDEEX",	/* backwater */
X	"AAABBCCDEEX",	/* standard */
X	"AAABBCCDEEE",	/* mature */
X	"AAAABBCCDEX"	/* cluster */
X	};
X
Xint	mainwrld(mw, x, y, z)
Xmainworld	*mw;
Xlong	x, y, z;
X{
X	int	roll;
X
X	roll = exist(x, y, z);
X	if (roll == 0)
X		return(0);
X	mw->starport = strprt[roll - 1][D(2) - 2];
X
X	mw->size = D(2) - 2;
X
X	if (mw->size == 0)
X		mw->atmos = 0;
X	else
X	{
X		mw->atmos = D(2) - 7 + mw->size;
X		if (mw->atmos < 0)
X			mw->atmos =0;
X	}
X
X	if (mw->size <= 1)
X		mw->hydro = 0;
X	else
X	{
X		roll = D(2) - 7 + mw->size;
X		if ((mw->atmos <= 1) || (mw->atmos >= 0xa))
X			roll -= 4;
X		if (roll < 0)
X			mw->hydro = 0;
X		else if (roll > 10)
X			mw->hydro = 10;
X		else
X			mw->hydro = roll;
X	}
X
X	mw->pop = D(2) - 2;
X
X	mw->gov = D(2) - 7 + mw->pop;
X	if ((mw->pop == 0) || (mw->gov < 0))
X		mw->gov = 0;
X
X	mw->law = D(2) - 7 + mw->gov;
X	if ((mw->gov == 0) || (mw->law < 0))
X		mw->law = 0;
X
X	roll = D(1);
X	if (mw->starport == 'A')
X		roll += 6;
X	else if (mw->starport == 'B')
X		roll += 4;
X	else if (mw->starport == 'C')
X		roll += 2;
X	else if (mw->starport == 'X')
X		roll -= 4;
X	if (mw->size <= 1)
X		roll += 2;
X	else if (mw->size <= 4)
X		roll++;
X	if ((mw->atmos <= 3) || (mw->atmos >= 10))
X		roll++;
X	if (mw->hydro >= 10)
X		roll += 2;
X	else if (mw->hydro >= 9)
X		roll++;
X	if ((mw->pop >= 1) && (mw->pop <= 5))
X		roll++;
X	else if (mw->pop >= 10)
X		roll += 4;
X	else if (mw->pop >= 9)
X		roll += 2;
X	else if (mw->pop == 0)
X		roll = -99;
X	if ((mw->gov == 0) || (mw->gov == 5))
X		roll++;
X	else if (mw->gov == 0xd)
X		roll -= 2;
X	if (roll < 0)
X		mw->tech = 0;
X	else
X		mw->tech = roll;
X
X	mw->bases = 0;
X	if ((mw->starport == 'A') || (mw->starport == 'B'))
X		if (D(2) >= 8)
X			mw->bases |= NAVAL_BASE;
X	if ((mw->starport == 'A') && (D(2) >= 10))
X		mw->bases |= SCOUT_BASE;
X	else if ((mw->starport == 'B') && (D(2) >= 9))
X		mw->bases |= SCOUT_BASE;
X	else if ((mw->starport == 'C') && (D(2) >= 8))
X		mw->bases |= SCOUT_BASE;
X	else if ((mw->starport == 'D') && (D(2) >= 7))
X		mw->bases |= SCOUT_BASE;
X	if ((mw->starport == 'A') && (D(2) >= 10))
X		mw->bases |= LOCAL_BASE;
X	else if ((mw->starport == 'B') && (D(2) >= 9))
X		mw->bases |= LOCAL_BASE;
X	else if ((mw->starport == 'C') && (D(2) >= 8))
X		mw->bases |= LOCAL_BASE;
X
X	seedlang(x, y, z);
X        strcpy(mw->name, getname());
X	return(1);
X}
END_OF_FILE
if test 2303 -ne `wc -c <'mainwrld.c'`; then
    echo shar: \"'mainwrld.c'\" unpacked with wrong size!
fi
# end of 'mainwrld.c'
fi
if test -f 'readme' -a "${1}" != "-c" ; then
  echo shar: Will not clobber existing file \"'readme'\"
else
echo shar: Extracting \"'readme'\" \(860 characters\)
sed "s/^X//" >'readme' <<'END_OF_FILE'
X	SYSTEM GENERATOR LEVEL 1
X	RELEASE 0
X	1 February, 1990
X	[email removed]
X
X	This code was written on a PC and tested under the Lattice-C,
X	Microsoft-C and Turbo-C compilers. It should work under most
X	C compilers but be careful of long arithmetic. I would be most
X	keen to know modifications that are needed for various compilers.
X	To check your executable is 100% correct the system at coordinates
X	10000,10000,10000 should be:
X		C200100-a        10000    10000    10000 dete
X	I strongly encourage people to write subsidiary programs, e.g.
X	to map a subsector, plot trade routes, .... Usefull programs
X	will be added to later releases.
X
X	Planed releases: (subject to bugs, help and excess revisions)
X
X	Level-1:	Main-world generation		February
X	Level-2:	Extended system generation	March
X	Level-3:	World builder's generation	May
X	Level-4:	Surface maps			June
END_OF_FILE
if test 860 -ne `wc -c <'readme'`; then
    echo shar: \"'readme'\" unpacked with wrong size!
fi
# end of 'readme'
fi
if test -f 'sysgen.h' -a "${1}" != "-c" ; then
  echo shar: Will not clobber existing file \"'sysgen.h'\"
else
echo shar: Extracting \"'sysgen.h'\" \(343 characters\)
sed "s/^X//" >'sysgen.h' <<'END_OF_FILE'
X#include "magic.h"
X
X#define MAX_NAME 40
X#define mainworld	struct MW
X
X#define NAVAL_BASE 0x0001
X#define SCOUT_BASE 0x0002
X#define LOCAL_BASE 0x0004
X
Xmainworld {
X	char	name[MAX_NAME];
X	char	starport;
X	int	size;
X	int	atmos;
X	int	hydro;
X	int	pop;
X	int	gov;
X	int	law;
X	int	tech;
X	int	bases;
X	};
X
Xchar	*getname();
Xvoid	srand();
Xunsigned int	rand();
END_OF_FILE
if test 343 -ne `wc -c <'sysgen.h'`; then
    echo shar: \"'sysgen.h'\" unpacked with wrong size!
fi
# end of 'sysgen.h'
fi
if test -f 'sysgen1.c' -a "${1}" != "-c" ; then
  echo shar: Will not clobber existing file \"'sysgen1.c'\"
else
echo shar: Extracting \"'sysgen1.c'\" \(613 characters\)
sed "s/^X//" >'sysgen1.c' <<'END_OF_FILE'
X#include "sysgen.h"
X
Xvoid	main(argc, argv)
Xint	argc;
Xchar	**argv;
X{
X	mainworld	mw;
X	long	x, y, z, atol();
X
X	if ((argc < 3) || (argc > 4))
X	{
X		printf("Usage: sysgen X Y [Z]\n");
X		exit(1);
X	}
X	x = atol(argv[1]);
X	y = atol(argv[2]);
X	if (argc == 4)
X		z = atol(argv[3]);
X	else
X		z = 0L;
X
X	if (mainwrld(&mw, x, y, z) == 0)
X		exit(0);
X	printf("%c%1x%1x%1x%1x%1x%1x-%x %c%c%c %8ld %8ld %8ld %s\n",
X		mw.starport, mw.size,
X		mw.atmos, mw.hydro, mw.pop, mw.gov, mw.law,
X		mw.tech, (mw.bases&NAVAL_BASE)? 'N' : ' ',
X		(mw.bases&SCOUT_BASE)? 'S' : ' ',
X		(mw.bases&LOCAL_BASE)? 'M' : ' ',
X		x, y, z, mw.name);
X	exit(1);
X}
END_OF_FILE
if test 613 -ne `wc -c <'sysgen1.c'`; then
    echo shar: \"'sysgen1.c'\" unpacked with wrong size!
fi
# end of 'sysgen1.c'
fi
echo shar: End of shell archive.
exit 0

All opinions and material above is the responsibility of the originator.
Submissions: [email removed], or [email removed]
Administrator: [email removed] (James Perkins)
The TML is made possible by facilities provided by Tektronix, Inc.