|
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 o
Length: 12715 (0x31ab) Types: TextFile Names: »orbit.c.orig«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Gb/orbit.c.orig«
/* * Galactic Bloodshed (Robert Chansky, smq@b) * orbit.c -- display orbits of planets (graphic representation) * * OPTIONS * -p : If this option is set, ``orbit'' will not display planet names. * * -S : Do not display star names. * * -s : Do not display ships. * * -(number) : Do not display that #'d ship or planet (in case it obstructs * the view of another object) */ #define Midx ((stdscr->_maxx-NAMESIZE)/2.0) #define Midy ((stdscr->_maxy-1)/2.0) #define S_X (stdscr->_maxx-NAMESIZE) #define S_Y (stdscr->_maxy) #include "vars.h" #include "ships.h" #include <curses.h> extern char Shipltrs[]; float Lastx, Lasty, Zoom; orbit(APcount, argn,args) int APcount; int argn; char args[MAXARGS][COMMANDSIZE]; { register int i; int DontDispNum= -1, t, flag; planettype *p; shiptype *s; placetype where,shipwhere; bool err, DontDispPlanets, DontDispShips, DontDispStars; char str[PLACENAMESIZE]; int orbit_shdata,orbit_pdata,orbit_stardata; DontDispPlanets = DontDispShips = DontDispStars = 0; printf(" orbit:called |%s|\n",args[1]); /* find options, set flags accordingly */ for (flag=1; flag<=argn-1; flag++) if (*args[flag]=='-') { for (i=1; args[flag][i]!='\0'; i++) switch (args[flag][i]) { case 's': DontDispShips = 1; break; case 'S': DontDispStars = 1; break; case 'p': DontDispPlanets = 1; break; default : if (sscanf(args[flag]+1,"%d",&DontDispNum)!=1) { printf("Bad number %s.\n",args[flag]+1); DontDispNum = -1; } if (DontDispNum) DontDispNum--; /* make a '1' into a '0' */ break; } } if (argn==1) { where = Getplace(":",0); Lastx = Dir.lastx; Lasty = Dir.lasty; Zoom = Dir.zoom; } else { printf(" trying to orbit %s\n",args[argn-1]); where = Getplace(args[argn-1],0); Lastx = Lasty = 0.0; Zoom = 1.0; } if (where.err) { printf("orbit: error in args.\n"); return; } clear(); switch (where.level) { case LEVEL_UNIV: /* may be necessary to put (below) */ openstardata(&orbit_stardata); getsdata(orbit_stardata,&Sdata); close(orbit_stardata); for (i=0; i<Sdata.numstars; i++) if (DontDispNum!=i) DispStar(LEVEL_UNIV,Stars[i],DontDispStars); if (!DontDispShips && Sdata.numships) { openshdata(&orbit_shdata); for (i=0; i<MAXUSHIPS; i++) { if (Sdata.shipnums[i]) { if (DontDispNum != Sdata.shipnums[i]) { (void)getship(orbit_shdata,&s,Sdata.shipnums[i]); DispShip(&where, s, Sdata.shipnums[i], NULL ); free(s); } } } close(orbit_shdata); } break; case LEVEL_STAR: openstardata(&orbit_stardata); free(Stars[where.snum]); getstar(orbit_stardata,&Stars[where.snum], where.snum); close(orbit_stardata); DispStar(LEVEL_STAR, Stars[where.snum], DontDispStars); openpdata(&orbit_pdata); for (i=0; i<Stars[where.snum]->numplanets; i++) { if (DontDispNum!=i) { getplanet(orbit_pdata,&p,Stars[where.snum]->planetpos[i]); DispPlanet(LEVEL_STAR,p,Stars[where.snum]->pnames[i],DontDispPlanets); free(p); } } close(orbit_pdata); if (!DontDispShips && Stars[where.snum]->numships) { openshdata(&orbit_shdata); for (i=0; i<MAXSSHIPS; i++) if (Stars[where.snum]->shipnums[i]) if (DontDispNum != Stars[where.snum]->shipnums[i]) { (void)getship(orbit_shdata,&s,Stars[where.snum]->shipnums[i]); DispShip(&where, s, Stars[where.snum]->shipnums[i], NULL ); free(s); } close(orbit_shdata); } break; case LEVEL_PLAN: openpdata(&orbit_pdata); getplanet(orbit_pdata,&p,Stars[where.snum]->planetpos[where.pnum]); close(orbit_pdata); DispPlanet(LEVEL_PLAN, p, Stars[where.snum]->pnames[where.pnum], DontDispPlanets); if (!DontDispShips && p->numships) { openshdata(&orbit_shdata); for (i=0; i<MAXPSHIPS; i++) if (p->shipnums[i]) { if (DontDispNum!=p->shipnums[i]) { (void)getship(orbit_shdata,&s,p->shipnums[i]); /* don't print out landed ships */ if ( DontDispNum != p->shipnums[i] && !(s->is_docked && s->whatdest==LEVEL_PLAN) ) { DispShip(&where, s, p->shipnums[i], p); } free(s); } } close(orbit_shdata); } free(p); break; case LEVEL_SHIP: { char gs[MAXARGS][COMMANDSIZE]; shipwhere.level = where.shipptr->whatorbits; shipwhere.snum = where.shipptr->storbits; shipwhere.pnum = where.shipptr->pnumorbits; sprintf(gs[1],"%s",Dispplace(&shipwhere) ); printf(" orbiting %s\n",gs[1]); orbit(0,2,gs); } break; default: printf("bleah!!!\n"); exit(-1); } /* move to bottom of screen and draw */ move(S_Y-1,0); refresh(); } char *Novae[16][7] = { " ", " ", " ", " %* ", " ", " ", " ", " ", " ", " % ", " %*% ", " % ", " ", " ", " ", " ", " %% ", " %%*%% ", " %% ", " ", " ", " ", " ", " %%% ", " %*%%% ", " %%% ", " ", " ", " ", " ", " %%% ", " %%*%%% ", " %%%% ", " ", " ", " ", " % ", " %%%% ", " %%%*%%% ", " %%%%% ", " ", " ", " ", " % ", " %%%%% ", " %% *%%% ", " %%%%% ", " % ", " ", " ", " % ", " %%%%%%% ", " %%% * %%% ", " %%%%% ", " %% ", " ", " ", " %%% ", " %%%%%%% ", " %%% * %%% ", " %%% %%% ", " %%% ", " ", " ", " %%%% ", " %%% %%% ", " %%% * %%% ", " %%% %%%% ", " %%%%%% ", " %% ", " ", " %%%% ", " %%% %%% ", " %%% * %%% ", " %%% %%% ", " %%%%%% ", " %% ", " %% ", " %%%%%% ", " %% %%% ", " %%% * %%%", " %%%% %%% ", " %%%%%%%% ", " %%% ", " %%%% ", " %%%%%%%% ", " %%% % %%%", " %% * %%", " %%% %%%", " %%%%%% % ", " % %%% ", " %%% %% ", " %%% %% %% ", "%% %%%", "%%% * % %%", " % % %%", " %%% % % % ", " %%%%%%% ", "% % % %% ", " % % ", "%% % %", "% * % ", " % %", " % % % ", " % %%% ", " % % ", " %", "% ", " * %", "% ", " % %", " % % % " }; DispStar(level, star, DontDispStars) int level; startype *star; int DontDispStars; { int x,y; register int x2,y2; float fac; char *c; if (level==LEVEL_UNIV) { fac = 1.0; x = (int)(Midx+(star->xpos-Lastx)*(Midx/UNIVSIZE) / Zoom); y = (int)(Midy+(star->ypos-Lasty)*(Midy/UNIVSIZE) / Zoom); } else if (level==LEVEL_STAR) { fac = 1000.0; x = (int)(Midx+(-Lastx)*(Midx/SYSTEMSIZE) / Zoom); y = (int)(Midy+(-Lasty)*(Midy/SYSTEMSIZE) / Zoom); } if (star->nova_stage) DispArray(x, y, 11,7, Novae[star->nova_stage-1], fac); else if (y>=0 && y<=S_Y && x>=0 && x<=S_X) { move(y,x); addch('*'); if (!DontDispStars) { move(y, x+2); addstr(star->name); } } } DispPlanet(level, p, name, DontDispPlanets) int level; planettype *p; char *name; int DontDispPlanets; { int x,y; if (level==LEVEL_STAR) { y = (int)(Midy +(p->ypos-Lasty)*(Midy/SYSTEMSIZE) / Zoom); x = (int)(Midx +(p->xpos-Lastx)*(Midx/SYSTEMSIZE) / Zoom); } else if (level==LEVEL_PLAN) { y = (int)(Midy +(-Lasty)*(Midy/PLORBITSIZE) / Zoom); x = (int)(Midx +(-Lastx)*(Midx/PLORBITSIZE) / Zoom); } if (x>=0 && x<=S_X && y>=0 && y<=S_Y) { mvaddch(y,x,'@'); if (!DontDispPlanets) { addch(' '); addstr(name); } } } char *Mirror[8][5] = { " ", " ", "\\===m===/", " ", " ", " | ", " \\\\ ", " m ", " \\\\ ", " \\__", " / ", " || ", " m ", " || ", " \\ ", " __", " // ", " m ", " // ", " | ", " ", " ", "/===m===\\", /* cc thinks this is a quoted " w/o the \ */ " ", " ", "__ ", " \\\\ ", /* weird stuff again */ " m ", " \\\\ ", " | ", " \\ ", " || ", " m ", " || ", " / ", " | ", " // ", " m ", "__// ", " " }; DispShip(where, ship, shipnum, pl ) placetype *where; shiptype *ship; int shipnum; planettype *pl; /* orbits planet */ { int x,y,x2,y2,wm,pdata,shipdata; shiptype *aship; planettype *apl; float xt,yt,slope; char *c; if (ship->is_dead) return; switch (where->level) { case LEVEL_PLAN: x = Midx + (ship->xpos-(Stars[where->snum]->xpos+pl->xpos) - Lastx)*(Midx/PLORBITSIZE) / Zoom; y = Midy + (ship->ypos-(Stars[where->snum]->ypos+pl->ypos) - Lasty)*(Midy/PLORBITSIZE) / Zoom; break; case LEVEL_STAR: x = Midx + (ship->xpos-Stars[where->snum]->xpos - Lastx)*(Midx/SYSTEMSIZE) / Zoom; y = Midy + (ship->ypos-Stars[where->snum]->ypos - Lasty)*(Midy/SYSTEMSIZE) / Zoom; break; case LEVEL_UNIV: x = Midx + (ship->xpos-Lastx)*(Midx/UNIVSIZE) / Zoom; y = Midy + (ship->ypos-Lasty)*(Midy/UNIVSIZE) / Zoom; break; default: printf("WHOA! error.\n"); exit(-1); } switch (ship->type) { case STYPE_MIRROR: if (ship->orders.aimed_at.level==LEVEL_STAR) { xt = Stars[ship->orders.aimed_at.snum]->xpos; yt = Stars[ship->orders.aimed_at.snum]->ypos; } else if (ship->orders.aimed_at.level==LEVEL_PLAN) { if (ship->orders.aimed_at.pnum == where->pnum) { /* same planet */ xt = Stars[ship->orders.aimed_at.snum]->xpos + pl->xpos; yt = Stars[ship->orders.aimed_at.snum]->ypos + pl->ypos; } else { /* different planet */ openpdata(&pdata); getplanet(pdata,&apl,Stars[where->snum]->planetpos[where->pnum]); close(pdata); xt = Stars[ship->orders.aimed_at.snum]->xpos + apl->xpos; yt = Stars[ship->orders.aimed_at.snum]->ypos + apl->ypos; free(apl); } } else if (ship->orders.aimed_at.level==LEVEL_SHIP) { openshdata(&shipdata); if (getship(shipdata,&aship,ship->orders.aimed_at.shipno)) { xt = aship->xpos; yt = aship->ypos; } else xt = yt = 0.0; close(shipdata); free(aship); } slope = (xt - ship->xpos) / (yt - ship->ypos); if (yt - ship->ypos > 0) { if (slope > 0) { if (slope > 1) { if (slope > 2) wm = 0; else wm = 1; } else { if (slope > .5) wm = 1; else wm = 2; } } else { if (slope < -1) { if (slope < -2) wm = 0; else wm = 7; } else { if (slope < .5) wm = 7; else wm = 6; } } } else { if (slope > 0) { if (slope > 1) { if (slope > 2) wm = 4; else wm = 5; } else { if (slope > .5) wm = 5; else wm = 6; } } else { if (slope < -1) { if (slope < -2) wm = 4; else wm = 3; } else { if (slope < .5) wm = 3; else wm = 2; } } } DispArray(x,y, 9,5, Mirror[wm], ship->whatorbits==LEVEL_UNIV ? (float)100.0 : (ship->whatorbits==LEVEL_STAR ? (float)10.0 : (ship->whatorbits==LEVEL_PLAN ? (float)1.0 :0))); /* (magnification) */ if (x>=0 && x<=S_X && y>=0 && y<=S_Y) { move(y,x+1); printw("%d",shipnum); } break; case OTYPE_CANIST: break; case OTYPE_VN: { register int n,xa,ya; register float fac; /* make a cloud of Von Neumann machines */ fac = ship->orders.object.number / ((ship->whatorbits==LEVEL_UNIV ? 100.0 : (ship->whatorbits==LEVEL_STAR ? 30.0 : 4.0)) * Zoom); for (n=1; n<=ship->orders.object.number && n<267; n++) { xa = int_rand(x - (int)fac, x + (int)fac); ya = int_rand(y - (int)(fac*S_Y/S_X), y + (int)(fac*S_Y/S_X)); if (xa>=0 && xa<=S_X && ya>=0 && ya<=S_Y) { mvaddch(ya,xa, Shipltrs[ship->type]); printw("%d",shipnum); } } } break; default: if (x>=0 && x<=S_X && y>=0 && y<=S_Y) { mvaddch(y,x, Shipltrs[ship->type]); printw("%d",shipnum); } break; } } /* display array on screen. at the moment magnification is not * implemented. */ DispArray(x, y, maxx,maxy, array, mag) int x,y; int maxx,maxy; char *array[]; float mag; { register int x2,y2,curx,cury, Cx,Cy,cx,cy; for (cury=y-maxy/2,y2=0; y2<maxy; cury++) { if (cury >= 0 && cury <= S_Y) { move(cury, curx = x - maxx / 2 ); for (x2=0; x2<maxx; curx++) { if (curx>=0 && curx <= S_X) if (inch()==' ') addch( array[y2][x2] ); else move(cury, curx); /* one to right */ x2++; } } y2++; } }