X * SpeedConsts[s->speed] * MoveConsts[s->whatorbits];
X
X
X truedist = movedist = sqrt( Distsq(s->xpos, s->ypos, xdest, ydest));
X
X
X /* keep from ending up in the middle of the system. */
X /* Change the distance so that we
X don't go all the way into the system. */
X if (s->whatorbits==LEVEL_UNIV ||
X (destlevel==LEVEL_STAR && s->storbits!=deststar) ||
X (destlevel==LEVEL_PLAN && s->storbits!=deststar) &&
X truedist >= SYSTEMSIZE)
X movedist -= SYSTEMSIZE * 0.90;
X else if (destlevel==LEVEL_PLAN && s->whatorbits==LEVEL_STAR &&
X s->storbits==deststar && truedist >= PLORBITSIZE)
X /* we're in a system, don't go all the way into a planetary
X orbit */
X movedist -= PLORBITSIZE * 0.90;
X
X
X if (s->whatdest==LEVEL_SHIP && s->owner!=ships[s->destshipno]->owner
X && !isset(races[s->owner-1]->allied, ships[s->destshipno]->owner)
X && truedist > SYSTEMSIZE*4.0) {
X /* (an allied ship lets you follow it..) */
X /* we lost sight of the destination ship. */
X /* should change SYSTEMSIZE*1.0 to calculated gun range.. */
X s->whatdest = LEVEL_UNIV;
X s->protect.evade = 0;
X sprintf(telegram_buf,"Telecomm from ship #%d at %s\n\n",
X shipno, prin_ship_orbits(s));
X sprintf(buf,"%s #%d %s lost sight of destination ship #%d.\n",
X Shipnames[s->type],shipno,s->name,s->destshipno);
X str_cat(telegram_buf, buf);
X push_message(TELEG_PLAYER_AUTO, s->owner, telegram_buf, TELEGRAM);
X return;
X }
X
X
X if (truedist > DIST_TO_LAND) {
X s->fuel -= fuse;
X s->mass -= fuse * MASS_FUEL;
X
X /* dont overshoot */
X sn = sin(heading);
X cs = cos(heading);
X xdest = sn * mfactor;
X ydest = cs * mfactor;
X if (hypot(xdest, ydest) > movedist) {
X xdest = sn * movedist;
X ydest = cs * movedist;
X }
X s->xpos += xdest;
X s->ypos += ydest;
X }
X
X/***** check if far enough away from object it's orbiting to break orbit *****/
X
X if (s->whatorbits==LEVEL_PLAN) {
X dist = sqrt( Distsq(s->xpos, s->ypos,
X ost->xpos+opl->xpos, ost->ypos+opl->ypos ) );
X if (dist > PLORBITSIZE) {
X s->whatorbits = LEVEL_STAR;
X }
X
X } else if (s->whatorbits==LEVEL_STAR) {
X dist = sqrt( Distsq(s->xpos, s->ypos, ost->xpos, ost->ypos ) );
X if (dist > SYSTEMSIZE) {
X s->whatorbits = LEVEL_UNIV;
X s->protect.evade = 0;
X }
X }
X
X /******* check for arriving at destination *******/
X
X if (destlevel==LEVEL_STAR || (destlevel==LEVEL_PLAN
X && !(s->whatorbits!=LEVEL_UNIV && s->storbits==deststar) ) ) {
X /* not in same star system as deststar */
X
X stardist = sqrt(Distsq(s->xpos,s->ypos,dst->xpos,dst->ypos));
X
X if (stardist <= SYSTEMSIZE * 1.5) {
X if (s->type == STYPE_POD)
X s->notified = 1; /* signal to explode */
X /* mark as explored & inhabited by that player */
X setbit(dst->explored, s->owner);
X setbit(dst->inhabited, s->owner);
X s->whatorbits = LEVEL_STAR;
X s->storbits = deststar;
X sprintf(telegram_buf,"%s #%d %s arrived at system %s.\n",
X Shipnames[s->type], shipno, s->name,
X prin_ship_orbits(s));
X push_message(TELEG_PLAYER_AUTO, s->owner, telegram_buf, TELEGRAM);
X
X if (destlevel == LEVEL_STAR)
X s->whatdest = LEVEL_UNIV;
X /* clear orders if the ship is not headed to a planet in
X this system */
X
X
X }
X
X } else if ( destlevel==LEVEL_PLAN &&
X (s->whatorbits!=LEVEL_UNIV && deststar==s->storbits &&
X !(s->whatorbits==LEVEL_PLAN && s->pnumorbits==destpnum)) ) {
X /* headed for a planet in the same system, & not already there.. */
X dist = sqrt( Distsq(s->xpos, s->ypos,
X dst->xpos+dpl->xpos, dst->ypos+dpl->ypos ) ) ;
X
X if (dist<=PLORBITSIZE) {
X /* mark planet as explored by that player */
X dpl->info[s->owner-1].explored = 1;
X /* mark sun as explored too, if the ship might have bypassed it
X (we are trying to be thorough here) */
X setbit(dst->explored, s->owner);
X setbit(dst->inhabited, s->owner);
X s->whatorbits = LEVEL_PLAN;
X s->pnumorbits = destpnum;
X
X sprintf(telegram_buf,"Telecomm from ship #%d\n\n",shipno);
X
X if(dist<=DIST_TO_LAND) {
X sprintf(telegram_buf,"%s #%d %s arrived at planet %s.\n This ship is close enough to land.\n",Shipnames[s->type],shipno, s->name, prin_ship_orbits(s));
X } else {
X sprintf(telegram_buf,"%s #%d %s arriving at planet %s.\n",
X Shipnames[s->type],shipno, s->name, prin_ship_orbits(s));
X }
X
X if (s->type==STYPE_ASS) {
X sprintf(buf,"\nEnslavement of the planet is now possible.\n");
X str_cat(telegram_buf, buf);
X }
X push_message(TELEG_PLAYER_AUTO, s->owner, telegram_buf, TELEGRAM);
X }
X
X }
X
X }
X
X} /* if 'destination' orders */
X
X}
X
X
X
X/*
X * insert the ship into wherever it's supposed to be.
X * this is done every turn, for every ship; as a bonus it puts them in
X * alphabetical order.
X */
Xinsert_sh(sdata, star, pl, s, shipno)
Xstruct stardata *sdata;
Xstartype *star;
Xplanettype *pl;
Xshiptype *s;
Xint shipno;
X{
X
X if (s->is_alive)
X switch (s->whatorbits) {
X case LEVEL_UNIV:
X s->nextship = sdata->ships;
X sdata->ships = shipno;
X break;
X case LEVEL_STAR:
X s->nextship = star->ships;
X star->ships = shipno;
X break;
X case LEVEL_PLAN:
X s->nextship = pl->ships;
X pl->ships = shipno;
X break;
X default:
X break;
X }
X
X}
X
X
X/* deliver an "out of fuel" message. Used by a number of ship-updating
X * code segments; so that code isn't duplicated.
X */
Xmsg_OOF(s, shipno, tbuf)
Xshiptype *s;
Xint shipno;
Xchar *tbuf;
X{
X char buf[200];
X
X sprintf(buf,"%s #%d is out of fuel at %s\n", Shipnames[s->type],
X shipno, prin_ship_orbits(s));
X push_message(TELEG_PLAYER_AUTO, s->owner, buf, TELEGRAM);
X}
X
X
Xinsert_sh_univ(sdata, s, shipno)
Xshiptype *s;
Xstruct stardata *sdata;
X{
X s->nextship = sdata->ships;
X sdata->ships = shipno;
X}
X
X
Xinsert_sh_star(star, s, shipno)
Xstartype *star;
Xshiptype *s;
Xint shipno;
X{
X s->nextship = star->ships;
X star->ships = shipno;
X}
X
X
Xinsert_sh_plan(pl, s, shipno)
Xplanettype *pl;
Xshiptype *s;
Xint shipno;
X{
X s->nextship = pl->ships;
X pl->ships = shipno;
X}
END_OF_FILE
if test 11633 -ne `wc -c <'server/moveship.c'`; then
echo shar: \"'server/moveship.c'\" unpacked with wrong size!
fi
# end of 'server/moveship.c'
if test -f 'server/rst.c' -a "${1}" != "-c" ; then
echo shar: Renaming existing file \"'server/rst.c'\" to \"'server/rst.c.orig'\"