|
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 d
Length: 5974 (0x1756) Types: TextFile Names: »doturn.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Gb/doturn.c«
/* * Galactic Bloodshed (Robert Chansky, smq@b) * doturn -- does one turn. */ #include "vars.h" #include "ships.h" #include "races.h" #include "doturn.h" #include "power.h" struct power Power[MAXPLAYERS]; #include <math.h> char telegram_buf[AUTO_TELEG_SIZE]; shiptype *ships[MAXTOTALSHIPS]; planettype *planets[NUMSTARS][MAXPLANETS]; racetype *races[MAXPLAYERS]; us Sdatanumships[MAXPLAYERS]; ul Sdatapopns[MAXPLAYERS]; us starnumships[NUMSTARS][MAXPLAYERS]; ul starpopns[NUMSTARS][MAXPLAYERS]; int Num_races,Num_ships; extern int Ignore_lockfile; doturn(command) int command; /* if run from a shell by super user */ { int star,i,fd; int shdata,stardata,pdata,sectdata; bool err=0; char buf[80]; shiptype *ship; Ignore_lockfile = 1; /* make all 0 for first iteration of doplanet */ bzero((char *)starpopns, sizeof(starpopns)); bzero((char *)starnumships, sizeof(starnumships)); bzero((char *)Sdatanumships, sizeof(Sdatanumships)); bzero((char *)Stinfo, sizeof(Stinfo)); bzero((char *)Power, sizeof(Power)); /* create lock file that locks all file reads */ if ( (fd = open(LOCK_ALL, O_EXCL|O_CREAT, 0000) ) < 0) { printf("lock file already exists!\n"); exit(-1); } close(fd); /* close it--have to do it this way or we get too many files open*/ Num_races = Numraces(); printf(" Num_races = %d\n",Num_races); openshdata(&shdata); Num_ships = Numships(shdata); /* i<MAXTOTALSHIPS is to prevent daemon allocating all mem to itself in case of accidental write onto position 0 */ for (i=1; i<=Num_ships && i<MAXTOTALSHIPS; i++) getship(shdata,&ships[i],i); close(shdata); /* get all stars & planets */ openstardata(&stardata); getsdata(stardata,&Sdata); openpdata(&pdata); for (star=0; star<Sdata.numstars; star++) { getstar(stardata, &(Stars[star]), star); fix_stability(Stars[star]); /* nova */ for (i=0; i<Stars[star]->numplanets; i++) { getplanet(pdata,&planets[star][i],Stars[star]->planetpos[i]); } } close(stardata); close(pdata); for (i=1; i<=Num_races; i++) { printf(" numraces=%d\n",Num_races); getrace(&(races[i]),i); /* increase tech; change to something else */ races[i]->tech += (float)races[i]->IQ / 100.0; if (races[i]->tech >= TECH_EXPLORE) planets[races[i]->homesystem][races[i]->homeplanetnum]->is_explored = 1; } for (i=1; i<=Num_ships && i<MAXTOTALSHIPS; i++) doship(i,ships[i]); openstardata(&stardata); openpdata(&pdata); /* add APs to sdata for ea. player */ for (i=0; i<=Num_races; i++) { int a; if ( (a = Sdata.AP[i] + APadd((int)Sdatanumships[i], (int)Sdatapopns[i]) + 1) > LIMIT_APs) Sdata.AP[i] = LIMIT_APs; else Sdata.AP[i] = a; } for (star=0; star<Sdata.numstars; star++) { for (i=0; i<Stars[star]->numplanets; i++) { int ppp,pppp; /*for (ppp=0; ppp<Sdata.numstars; ppp++) for (pppp=0; pppp<Stars[star]->numplanets; pppp++) printf(" 8Pointer %d,%d= %x\n",ppp,pppp,planets[ppp][pppp]);*/ if (doplanet(star, planets[star][i], i, command)) { /* save smap gotten & altered by doplanet only if the planet is expl*/ opensectdata(§data); putsmap(sectdata,Smap,planets[star][i]->sectormappos,planets[star][i]->Maxx*planets[star][i]->Maxy); close(sectdata); } putplanet(pdata,planets[star][i],Stars[star]->planetpos[i]); free(planets[star][i]); } /* do AP's for ea. player */ for (i=0; i<=Num_races; i++) { if (isset(Stars[star]->explored, i) ) { int a; if ((a = Stars[star]->AP[i] + APadd((int)starnumships[star][i], (int)starpopns[star][i]) + 1) > LIMIT_APs) Stars[star]->AP[i] = LIMIT_APs; else Stars[star]->AP[i] = a; } } if (starpopns[star][i]) setbit(Stars[star]->inhabited,i); else clrbit(Stars[star]->inhabited,i); putstar(stardata, Stars[star], star); if (!command) free(Stars[star]); } close(pdata); putsdata(stardata,&Sdata); close(stardata); for (i=1; i<=Num_races; i++) { /*printf(" putting race %d -- ",i);*/ putrace(races[i]); if (!(command && i==Race->Playernum)) free(races[i]); } Putpower(Power); /* put power report to disk */ openshdata(&shdata); /* put all ships back */ for (i=1; i<=Num_ships && i<MAXTOTALSHIPS; i++) { putship(shdata,ships[i],i); free(ships[i]); } close(shdata); unlink(LOCK_ALL); /* remove the LOCK_ALL file */ Ignore_lockfile = 0; /* not realy needed for daemon but needed for doturn */ /* as shell command */ /* readjust pointers to star; Dir now points to dead memory */ if (command) { free(Race); Race = races[Race->Playernum]; } } /* routine for number of AP's to add to each player in ea. system */ int APadd(ships, popn) int ships, popn; { return round_rand((float)(ships)/5.0 + popn / 10000.0); } /* fix stability for stars */ fix_stability(s) startype *s; { char buf[100]; int a,i; if (s->nova_stage > 0) { if (s->nova_stage > 14) { s->stability = 30; s->nova_stage = 0; teleg_add("",telegram_buf); teleg_add("Notice\n",telegram_buf ); sprintf(buf,"\n Scientists report that star %s\n", s->name); teleg_add(buf,telegram_buf); teleg_add("is no longer undergoing nova.\n",telegram_buf); for (i=1; i<=Num_races; i++) teleg_send(TELEG_PLAYER_AUTO, i, telegram_buf); /* telegram everyone when nova over? */ } else s->nova_stage++; } else if (s->stability > 50) { a = int_rand(-1,3); /* nova just starting; notify everyone */ if ( (s->stability + a) > 100) { s->stability = 100; s->nova_stage = 1; teleg_add("",telegram_buf); teleg_add( "***** BULLETIN! ******\n",telegram_buf ); sprintf(buf,"\n Scientists report that star %s\n", s->name); teleg_add(buf,telegram_buf); teleg_add("is undergoing nova.\n",telegram_buf); for (i=1; i<=Num_races; i++) teleg_send(TELEG_PLAYER_AUTO, i, telegram_buf); } else s->stability += a; } else a = int_rand(-3,2); if ( (s->stability + a) < 0) s->stability = 0; else s->stability += a; }