|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T m
Length: 5790 (0x169e) Types: TextFile Names: »makeuniv.c.orig«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Gb/makeuniv.c.orig«
/* * Galactic Bloodshed (Robert Chansky, smq@b) * makeuniv.c -- make data files for the game */ #include "vars.h" #include "ships.h" #include "races.h" #include "power.h" /* (for power) */ #include <math.h> FILE *fopen(); planettype Makeplanet(); int ftell(); /* not a long */ char *Romannums[] = { "I","II","III","IV","V","VI","VII","IIX","IX","X","XI", "XII","XIII","XIV","XV" }; /* for planet naming*/ main(argc,argv) int argc; char *argv[]; { FILE *teledata,*racedata,*stardata,*planetdata,*sectordata,*shipdata; planettype planet; startype *Star; int star,e,e2,type,lowp,hip; register int i,y,x; char types[MAXPLANETS], str[50]; float att,xspeed[NUMSTARS],yspeed[NUMSTARS]; srandom(getpid()); Bzero(Sdata); printf("# of stars(1-%d):",NUMSTARS-1); scanf("%d",&(Sdata.numstars)); printf("low # of planets (1-%d):",MAXPLANETS-1); scanf("%d",&lowp); printf("hi # of planets (%d-%d):",lowp,MAXPLANETS-1); scanf("%d",&hip); printf("approx # of habitable planets:"); scanf("%d",&e); getchr(); sprintf(str, "/bin/mkdir %s", DATADIR ); system(str); if ( (planetdata = fopen(PLANETDATAFL,"w+"))==NULL) printf("unable to open %s\n",PLANETDATAFL); if ( (sectordata = fopen(SECTORDATAFL,"w+")) == NULL ) printf("unable to open %s\n",SECTORDATAFL); /* get names, positions of stars first */ for (star=0; star<Sdata.numstars; star++) { Stars[star]=(startype *)malloc(sizeof(startype)); Bzero(*Stars[star]); Star = Stars[star]; Star->numplanets=int_rand(lowp,hip); Star->gravity = (float)int_rand(100000,1000000) / 100; printf("name of star (%d planets):",Star->numplanets); for (i=0; i<NAMESIZE-4; i++) putchr('.'); for (i=0; i<NAMESIZE-4; i++) putchr('\010'); scanf("%10[^\n]",Star->name); getchr(); Star->xpos=(float)int_rand(-UNIVSIZE,UNIVSIZE); xspeed[star] = 0; Star->ypos=(float)int_rand(-UNIVSIZE,UNIVSIZE); yspeed[star] = 0; } for (star=0; star<Sdata.numstars; star++) { Star=Stars[star]; for (i=0; i<=Star->numplanets; i++) types[i] = 200; e2=e; while (e2--) { types[int_rand(0,Star->numplanets-1)] = TYPE_EARTH; } for (i=0; i<Star->numplanets; i++) if (types[i]!=TYPE_EARTH) types[i]=int_rand(1,3); for (i=0; i<Star->numplanets; i++) { sprintf(Star->pnames[i],"%s-%s",Star->name,Romannums[i]); if (argc==2 && argv[1][1]=='v') printf("planet %s is type %d\n",Star->pnames[i],types[i]); planet = Makeplanet(types[i]); do { planet.xpos=(float)int_rand(-SYSTEMSIZE,SYSTEMSIZE); planet.ypos=(float)int_rand(-SYSTEMSIZE,SYSTEMSIZE); } while ( sqrt(Distsq( planet.xpos, planet.ypos, 0, 0)) >= SYSTEMSIZE ); if (argc==2 && argv[1][1]=='v') { printf("at %f,%f relative to %s.\n",planet.xpos,planet.ypos,Star->name); printf("sect map(%d X %d):\n",planet.Maxx,planet.Maxy); for (y=0; y<planet.Maxy; y++) { for (x=0; x<planet.Maxx; x++) { switch (Smap[y*planet.Maxx+x].des) { case DES_LAND: putchr(CHAR_UNOWNED_LAND); break; case DES_SEA: putchr(CHAR_SEA); break; case DES_MOUNT: putchr(CHAR_MOUNT); break; case DES_GAS: putchr(CHAR_GAS); break; } } putchr('\n'); } } Star->planetpos[i] = ftell(planetdata); /* posn of file-last write*/ planet.sectormappos = ftell(sectordata); /* sector map pos */ fwrite(&planet,sizeof(planettype),1,planetdata); /* write planet */ for (y=0; y<planet.Maxy; y++) fwrite(&(Smap[y*planet.Maxx]),sizeof(sectortype),planet.Maxx,sectordata); } } fchmod(planetdata,00660); /* change data files to group readwrite */ fclose(planetdata); fchmod(sectordata,00660); fclose(sectordata); /* get rid of this */ stardata = fopen("data.starB","w+"); fwrite(&(Sdata),sizeof(Sdata),1,stardata); for (star=0; star<Sdata.numstars; star++) { fwrite(Stars[star],sizeof(startype),1,stardata); } fchmod(stardata,00660); fclose(stardata); /* try to (more or less) evenly space the stars */ for (i=0; i<CREAT_UNIV_ITERAT; i++) for (star=0; star<Sdata.numstars; star++) { for (x=0; x<Sdata.numstars; x++) /* star2 */ if (x!=star) { /* find inverse of distance squared */ att = 10*UNIVSIZE / Distsq(Stars[star]->xpos, Stars[star]->ypos, Stars[x]->xpos, Stars[x]->ypos); xspeed[star] += att * (Stars[star]->xpos - Stars[x]->xpos); if (Stars[star]->xpos>UNIVSIZE || Stars[star]->xpos< -UNIVSIZE) xspeed[star] *= -1; yspeed[star] += att * (Stars[star]->ypos - Stars[x]->ypos); if (Stars[star]->ypos>UNIVSIZE || Stars[star]->ypos< -UNIVSIZE) yspeed[star] *= -1; } Stars[star]->xpos += xspeed[star]; Stars[star]->ypos += yspeed[star]; } stardata = fopen(STARDATAFL,"w+"); fwrite(&(Sdata),sizeof(Sdata),1,stardata); for (star=0; star<Sdata.numstars; star++) { fwrite(Stars[star],sizeof(startype),1,stardata); } fchmod(stardata,00660); fclose(stardata); shipdata = fopen(SHIPDATAFL,"w+"); fchmod(shipdata,00660); fclose(shipdata); /* put top ship # in front of ship data file */ shipdata = fopen(SHIPFREEDATAFL,"w+"); fchmod(shipdata,00660); fclose(shipdata); /* touch ship free position file */ shipdata = fopen(PLAYERDATAFL,"w+"); fchmod(shipdata,00660); fclose(shipdata); /* touch player file */ racedata = fopen(RACEDATAFL,"w+"); fchmod(racedata,00660); fclose(racedata); /* touch race data file */ { struct power p[MAXPLAYERS]; bzero((char *)p, sizeof(p)); racedata = fopen(POWFL,"w+"); fwrite(p,sizeof(p),1,racedata); fchmod(racedata,00660); fclose(racedata); /* touch power data file */ } sprintf(str, "/bin/mkdir %s", TELEGRAMDIR ); system(str); chmod(TELEGRAMDIR, 00770); /* make telegram files for each player */ for (i=1; i<=MAXPLAYERS; i++) { sprintf(str, "%s.%d", TELEGRAMFL, i ); teledata = fopen(str, "w+"); fchmod(teledata,00660); fclose(teledata); } }