|
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: 9182 (0x23de) Types: TextFile Names: »moveship.c.orig«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Gb/moveship.c.orig«
/* * Galactic Bloodshed (Robert Chansky, smq@b) * moveship -- moves specified ship according to its orders. * also deducts fuel from the ship's stores. */ #include "vars.h" #include "ships.h" #include "shipdata.h" #include <math.h> extern char telegram_buf[AUTO_TELEG_SIZE]; /* amount to move for each dir level. I arrived on these #'s only after hours of dilligent tweaking */ /* amount to move for each directory level */ float MoveConsts[] = { 3500.0, 300.0, 13.0 }; /* amnt to move for each ship speed level (ordered) */ float SpeedConsts[] = { 0.0, 0.80, 1.0, 1.2, 1.3 }; /* amount of fuel it costs to move at speed level */ float FuelConsts[] = { 0.0, 0.75, 1.0, 1.3, 1.4 }; Moveship(shipno,s,ost,dst,opl,dpl,dsh/*,sdatamod,stomod,stdmod,plomod,pldmod*/) int shipno; shiptype *s,*dsh; startype *ost,*dst; planettype *opl,*dpl; /*bool *sdatamod,*stomod,*stdmod,*plomod,*pldmod;*/ { double heading,stardist,Ddist,dist,xdest,ydest,mfactor; char buf[100]; float oldxpos,oldypos,fuse; register int i; bool move_err = 0; /*sdatamod = *stomod = *stdmod = *plomod = *pldmod = 0;*/ printf("moving ship #%d\n",shipno); if (can_move(s) && !s->is_docked && !s->is_dead && s->whatdest!=LEVEL_UNIV) { /* subtract fuel from the ship */ fuse = FuelConsts[s->speed] * FUEL_USE; if (s->type == STYPE_POD) fuse *= 0.4; if (s->fuel < fuse) { /* ship is out of fuel; do whatever it is to do */ if (!s->notified) { s->notified = 1; teleg_add("",telegram_buf); /* clear telegram buffer */ sprintf(buf,"Telecomm from %s #%d\n\n",Shipnames[s->type],shipno); teleg_add(buf,telegram_buf); sprintf(buf,"%s #%d is out of fuel at ", Shipnames[s->type],shipno, prin_ship_orbits(s)); teleg_add(buf,telegram_buf); teleg_send(TELEG_PLAYER_AUTO, s->owner, telegram_buf); } return; } /******* move the ship towards dest ******/ oldxpos = s->xpos; /* used in case of inablility to insert into data */ oldypos = s->ypos; switch (s->whatdest) { case LEVEL_STAR: xdest = dst->xpos; ydest = dst->ypos; break; case LEVEL_PLAN: /* dpl only defined & referenced if dest is a planet */ xdest = dst->xpos + dpl->xpos; ydest = dst->ypos + dpl->ypos; break; case LEVEL_SHIP: xdest = dsh->xpos; ydest = dsh->ypos; } /* update new xpos,ypos */ heading = atan2( xdest-s->xpos, (ydest - s->ypos)==0.0?0.000001:(ydest-s->ypos) ); mfactor = SpeedConsts[s->speed] * MoveConsts[s->whatorbits] / (logscale((int)s->mass * 10) ); if (s->type == STYPE_POD) mfactor *= 0.4; /* keep from ending up in the middle of the system */ Ddist = sqrt( Distsq(s->xpos, s->ypos, xdest, ydest)); if (s->whatdest==LEVEL_UNIV) Ddist -= (SYSTEMSIZE - 1.0); else if (s->whatdest==LEVEL_STAR) Ddist -= PLORBITSIZE - 1.0; else if (s->whatdest==LEVEL_SHIP && Ddist > SYSTEMSIZE) { if (!s->notified) { s->notified = 1; teleg_add("",telegram_buf); sprintf(buf,"Telecomm from ship #%d at %s\n\n",shipno, prin_ship_orbits(s)); teleg_add(buf,telegram_buf); sprintf(buf,"%s #%d cannot find destination ship #%d.\n", Shipnames[s->type],shipno,s->destshipno); teleg_add(buf,telegram_buf); teleg_send(TELEG_PLAYER_AUTO, s->owner, telegram_buf); return; } } if (Ddist <= 0.0) Ddist = 0.0; else if (Ddist > DIST_TO_LAND) { s->fuel -= fuse; printf(" subtracting %f fuel \n",fuse); /* subtract the fuel's mass */ s->mass -= fuse * MASS_FUEL; /* dont overshoot */ xdest = sin(heading) * mfactor; if (abs(xdest) > Ddist) xdest = sgn(xdest) * Ddist; ydest = cos(heading) * mfactor; if (abs(ydest) > Ddist) ydest = sgn(ydest) * Ddist; s->xpos += xdest; s->ypos += ydest; } /***** check if far enough away from object it's orbiting to break orbit *****/ if (s->whatorbits==LEVEL_PLAN) { printf("dist from orbts planet is %lf\n",dist = sqrt( Distsq(s->xpos, s->ypos, ost->xpos+opl->xpos, ost->ypos+opl->ypos ) ) ); if (dist > PLORBITSIZE) { s->whatorbits = LEVEL_STAR; /* insert ship to star data */ for (i=0; i<MAXSSHIPS && ost->shipnums[i]; i++) ; if (i<MAXSSHIPS) { ost->shipnums[i] = shipno; ost->numships++; /**stomod = 1;*/ printf("ship #%d now in system %s slot %d.\n",shipno,ost->name,i); /* delete ship from planet list */ for (i=0; i<MAXPSHIPS && opl->shipnums[i]!=shipno; i++) ; if (i<MAXPSHIPS) { opl->shipnums[i]=0; opl->numships--; /*plomod = 1;*/ printf("ship #%d departed from planet /%s/%s.\n",shipno, ost->name, ost->pnames[s->pnumorbits]); } else {move_err=1;printf("WARNING#1.. ship %d not found,pos%d.\n",shipno,i);} } else { printf("WARNING#2..ship %d unable to insert.\n",shipno); move_err = 1; s->xpos = oldxpos; /* cant insert, instead leave ship */ s->ypos = oldypos; /* where it was.. */ } } } else if (s->whatorbits==LEVEL_STAR) { printf("star orbits dist is %lf\n",dist = sqrt( Distsq(s->xpos, s->ypos, ost->xpos, ost->ypos ) ) ); if (dist > SYSTEMSIZE) { s->whatorbits = LEVEL_UNIV; /* insert ship into universe data */ for (i=0; i<MAXUSHIPS && Sdata.shipnums[i]; i++) ; if (i<MAXUSHIPS) { Sdata.shipnums[i] = shipno; Sdata.numships++; /*sdatamod = 1; /* alert client program */ printf("ship #%d departed from system %s.\n",shipno, ost->name); /* delete ship from star data */ for (i=0; i<MAXSSHIPS && ost->shipnums[i]!=shipno; i++) ; if (i<MAXSSHIPS) { ost->shipnums[i]=0; ost->numships--; /*stomod = 1;*/ } else {move_err=1;printf("WARNING#3.. ship %d not found,pos %d.\n",shipno,i);} } else { /* leave ship back where it was.. */ printf("WARNING#4:cant insert into universe.\n"); move_err = 1; s->xpos = oldxpos; s->ypos = oldypos; } } } /******* check for arriving at destination *******/ if ( s->whatorbits==LEVEL_UNIV && (s->whatdest==LEVEL_STAR || s->whatdest==LEVEL_PLAN) ) { /* dist to star not planet */ stardist = (s->whatdest==LEVEL_PLAN) ? sqrt(Distsq(s->xpos,s->ypos,Stars[s->deststar]->xpos,Stars[s->deststar]->ypos)) : Ddist; printf("dist from dest syst is %lf\n",stardist); if (stardist <= SYSTEMSIZE) { s->whatorbits = LEVEL_STAR; s->storbits = s->deststar; if (s->type == STYPE_POD) s->notified = 1; /* signal to explode */ /* clear orders if the ship is not headed to a planet in this system */ /* insert the ship */ for (i=0; i<MAXSSHIPS && dst->shipnums[i]; i++) ; if (i<MAXSSHIPS) { dst->shipnums[i] = shipno; dst->numships++; /**stdmod = 1;*/ /* mark as explored by that player */ setbit(dst->explored, s->owner); printf(" ship #%d arrived at system %s.\n",shipno,dst->name); if (s->whatdest == LEVEL_STAR) { s->whatdest = LEVEL_UNIV; teleg_add("",telegram_buf); sprintf(buf,"Telecomm from ship #%d\n\n",shipno); teleg_add(buf,telegram_buf); sprintf(buf,"%s #%d arrived at system %s.\n", Shipnames[s->type], shipno, prin_ship_orbits(s)); teleg_add(buf,telegram_buf); teleg_send(TELEG_PLAYER_AUTO, s->owner, telegram_buf); } /* delete ship from Sdata */ for (i=0; i<MAXUSHIPS && Sdata.shipnums[i]!=shipno; i++) ; if (i<MAXUSHIPS) { Sdata.shipnums[i] = 0; Sdata.numships--; /**sdatamod = 1;*/ } else printf("can't delete ship #%d from univ.data\n",shipno); } else { printf("ship #%d cannot be inserted into star %d!\n",shipno,s->deststar); move_err = 1; s->xpos = oldxpos; s->ypos = oldypos; } } } else if ( (s->whatdest==LEVEL_PLAN) && (s->deststar==s->storbits) && !(s->whatorbits==LEVEL_PLAN && s->pnumorbits==s->destpnum)) { /* headed for a planet in this system & we are not already there.. */ printf("dist from target planet is %lf\n",Ddist ); if (Ddist<=PLORBITSIZE) { s->whatorbits = LEVEL_PLAN; s->pnumorbits = s->destpnum; /* don't clear orders */ /* insert the ship */ for (i=0; dpl->shipnums[i] && i<MAXPSHIPS; i++) ; if (i<MAXPSHIPS) { dpl->shipnums[i] = shipno; dpl->numships++; /* mark as explored by that player */ dpl->info[s->owner-1].explored = 1; teleg_add("",telegram_buf); sprintf(buf,"Telecomm from ship #%d\n\n",shipno); teleg_add(buf,telegram_buf); sprintf(buf,"%s #%d arrived at planet %s.\n",Shipnames[s->type], shipno, prin_ship_orbits(s)); teleg_add(buf,telegram_buf); teleg_send(TELEG_PLAYER_AUTO, s->owner, telegram_buf); /**pldmod = 1;*/ printf("ship #%d arrived at planet /%s/%s,slot %d.\n",shipno, ost->name, ost->pnames[s->pnumorbits],i); /* delete the ship from star */ for (i=0; ost->shipnums[i]!=shipno && i<MAXSSHIPS; i++) ; if (i<MAXSSHIPS) { ost->shipnums[i] = 0; ost->numships--; /**stomod = 1;*/ } else { move_err=1; printf("WARNING #5: can't delete from deststar!\n"); s->xpos = oldxpos; s->ypos = oldypos; } } else { printf(" WARNING #6! can't insert\n"); move_err = 1; s->xpos = oldxpos; s->ypos = oldypos; } } } } }