space.c

swrots/src/space.c · 486.2 KB

From the archive swrots.tgz

Download the archive   « Back to the archive contents

#include <math.h> 
#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "mud.h"

SHIP_DATA * first_ship;
SHIP_DATA * last_ship;

MISSILE_DATA * first_missile;
MISSILE_DATA * last_missile;

SPACE_DATA * first_starsystem;
SPACE_DATA * last_starsystem;

extern char bname[MAX_STRING_LENGTH];
char *primary_beam_name    args ( ( SHIP_DATA *ship ) );
char *secondary_beam_name  args ( ( SHIP_DATA *ship ) );

int bus_pos =0;
int bus_planet = 0;
int bus2_planet = 5;
int bus3_planet = 3;
int bus4_planet = 8;
int turbocar_stop =0;
int corus_shuttle =0;
 
#define MAX_STATION    10
#define MAX_BUS_STOP 10

#define STOP_PLANET     1057
#define STOP_SHIPYARD   1057

int     const   station_vnum [MAX_STATION] =
{
    215 , 216 , 217 , 218 , 219 , 220 , 221 ,222 , 223 , 224
};

char *  const   station_name [MAX_STATION] =
{
   "Menari Spaceport" , "Skydome Botanical Gardens" , "Grand Towers" , 
   "Grandis Mon Theater" , "Palace Station" , "Great Galactic Museum" , 
   "College Station" , "Holographic Zoo of Extinct Animals" , 
   "Dometown Station " , "Monument Plaza"  
};

int     const   bus_vnum [MAX_BUS_STOP] =
{
    1006, 1850, 250, 4556, 28613, 9701, 7801, 9000, 10154, 18003
};

char *  const   bus_stop [MAX_BUS_STOP+1] =
{
   "Coruscant", "Yavin IV", "Tatooine", "Endor",
   "Kashyyyk", "Mon Calamari", "Nal Hutta", "Ord Mantell", "Corellia",
"Bakura", "Coruscant"  /* last should always be same as first */  
};

char *  const   ship_flags [] =
{
"nohijack", "shield_boost", "torp_boost", "chaff_boost", "hull_boost",
"laser_boost", "missile_boost", "rocket_boost", "simulator", "nodestroy", "noslicer", "ion_lasers",
"ion_drive", "ion_ion", "ion_turret1", "ion_turret2", "ion_turret3",
"ion_turret4", "ion_turret5", "ion_turret6", "ion_turret7", "ion_turret8",
"ion_turret9", "ion_turret10", "respawn", "ion_misiles", "ion_hyper", "cloak", "armor_boost",
"prototype", "r26", "r27", "r28", "r29",
"r30", "r31"
};

char * const    c_flags2 [] =
{
"art", "bacta", "semi-precious gems", "precious gems", "common ore", "rare ore",
"spice", "slaves", "weapons"
};

int get_cflags2( char *flag )
{
    int x;

    for ( x = 0; x < 10; x++ )
      if ( !str_cmp( flag, c_flags2[x] ) )
        return x;
    return -1;
};

int get_shipflag( char *flag )
{
    int x;

    for ( x = 0; x < 32; x++ )
      if ( !str_cmp( flag, ship_flags[x] ) )
        return x;
    return -1;
}

/* local routines */
void	fread_ship	args( ( SHIP_DATA *ship, FILE *fp ) );
bool	load_ship_file	args( ( char *shipfile ) );
void	write_ship_list	args( ( void ) );
void    fread_starsystem      args( ( SPACE_DATA *starsystem, FILE *fp ) );
bool    load_starsystem  args( ( char *starsystemfile ) );
void    write_starsystem_list args( ( void ) );
void    resetship args( ( SHIP_DATA *ship ) );
void    landship args( ( SHIP_DATA *ship, char *arg ) );
void    launchship args( ( SHIP_DATA *ship ) );
void    dockship args( ( SHIP_DATA *ship ) );
void    undockship args( ( SHIP_DATA *ship ) );
bool    land_bus args( ( SHIP_DATA *ship, int destination ) );
void    launch_bus args( ( SHIP_DATA *ship ) );
void    echo_to_room_dnr args( ( int ecolor , ROOM_INDEX_DATA *room ,  char *argument ) );
ch_ret drive_ship( CHAR_DATA *ch, SHIP_DATA *ship, EXIT_DATA  *exit , int fall );
bool    autofly(SHIP_DATA *ship);
bool is_facing( SHIP_DATA *ship , SHIP_DATA *target );
void sound_to_ship( SHIP_DATA *ship , char *argument );
int	get_shipflag(char *flag );

/* from comm.c */
bool    write_to_descriptor     args( ( int desc, char *txt, int length ) );

ROOM_INDEX_DATA *generate_exit( ROOM_INDEX_DATA *in_room, EXIT_DATA **pexit );

void echo_to_room_dnr ( int ecolor , ROOM_INDEX_DATA *room ,  char *argument ) 
{
    CHAR_DATA *vic;
    
    if ( room == NULL )
    	return;
    	
    for ( vic = room->first_person; vic; vic = vic->next_in_room )
    {
	set_char_color( ecolor, vic );
	send_to_char( argument, vic );
    }
}



bool  land_bus( SHIP_DATA *ship, int destination )
{
    char buf[MAX_STRING_LENGTH];
    
	if(ship)  extract_ship(ship);

    if ( !ship_to_room( ship , destination ) )
    {
       return FALSE;
    }
         
    echo_to_ship( AT_YELLOW , ship , "You feel a slight thud as the ship sets down on the ground."); 
    ship->location = destination;
    ship->lastdoc = ship->location;
    ship->shipstate = SHIP_DOCKED;
    if (ship->starsystem)
        ship_from_starsystem( ship, ship->starsystem );  
    sprintf( buf, "%s lands on the platform.", ship->name );
    echo_to_room( AT_YELLOW , get_room_index(ship->location) , buf );
    sprintf( buf , "The hatch on %s opens." , ship->name);  
    echo_to_room( AT_YELLOW , get_room_index(ship->location) , buf );
    echo_to_room( AT_YELLOW , get_room_index(ship->entrance) , "The hatch opens." );	
    ship->hatchopen = TRUE;
    sound_to_room( get_room_index(ship->entrance) , "!!SOUND(door)" );
    sound_to_room( get_room_index(ship->location) , "!!SOUND(door)" );
    return TRUE;
}

void    launch_bus( SHIP_DATA *ship )
{
      char buf[MAX_STRING_LENGTH];
      
      sound_to_room( get_room_index(ship->entrance) , "!!SOUND(door)" );
       sound_to_room( get_room_index(ship->location) , "!!SOUND(door)" );
      sprintf( buf , "The hatch on %s closes and it begins to launch." , ship->name);  
      echo_to_room( AT_YELLOW , get_room_index(ship->location) , buf );
      echo_to_room( AT_YELLOW , get_room_index(ship->entrance) , "The hatch slides shut." );	
      ship->hatchopen = FALSE;
      extract_ship( ship );
      echo_to_ship( AT_YELLOW , ship , "The ship begins to launch."); 
      ship->location = 0;
      ship->shipstate = SHIP_READY;
}

void update_traffic( )
{
    SHIP_DATA *shuttle;
    SHIP_DATA *turbocar;
    char       buf[MAX_STRING_LENGTH];

    shuttle = ship_from_cockpit( ROOM_CORUSCANT_SHUTTLE );
    if ( shuttle != NULL )
    {
        switch (corus_shuttle)
        {
             default:
                corus_shuttle++;
                break;
             
             case 0: 
                land_bus( shuttle , STOP_PLANET );
                corus_shuttle++;
                echo_to_ship( AT_CYAN , shuttle , "Welcome to Bulova Spaceport." ); 
                break;
                
             case 4:
                launch_bus( shuttle );
                corus_shuttle++;
                break;
                
             case 5:
                land_bus( shuttle , STOP_SHIPYARD );
                echo_to_ship( AT_CYAN , shuttle , "Welcome to Coruscant Shipyard." );
                corus_shuttle++;
                break;
                
             case 9:
                launch_bus( shuttle );
                corus_shuttle++;
                break;
                        
        }
        
        if ( corus_shuttle >= 10 )
              corus_shuttle = 0;
    }
    
    turbocar = ship_from_cockpit( ROOM_CORUSCANT_TURBOCAR );
    if ( turbocar != NULL )
    {
      	sprintf( buf , "The turbocar doors close and it speeds out of the station.");  
      	echo_to_room( AT_YELLOW , get_room_index(turbocar->location) , buf );
      	extract_ship( turbocar );
      	turbocar->location = 0;
       	ship_to_room( turbocar , station_vnum[turbocar_stop] );
       	echo_to_ship( AT_YELLOW , turbocar , "The turbocar makes a quick journey to the next station."); 
       	turbocar->location = station_vnum[turbocar_stop];
       	turbocar->lastdoc = turbocar->location;
       	turbocar->shipstate = SHIP_DOCKED;
       	if (turbocar->starsystem)
          ship_from_starsystem( turbocar, turbocar->starsystem );  
    	sprintf( buf, "A turbocar pulls into the platform and the doors slide open.");
    	echo_to_room( AT_YELLOW , get_room_index(turbocar->location) , buf );
    	sprintf( buf, "Welcome to %s." , station_name[turbocar_stop] );
    	echo_to_ship( AT_CYAN , turbocar , buf );
        turbocar->hatchopen = TRUE;
        
        turbocar_stop++;
        if ( turbocar_stop >= MAX_STATION )
           turbocar_stop = 0;
    }
       
}

void update_bus( )
{
    SHIP_DATA *ship;
    SHIP_DATA *ship2;
	SHIP_DATA *ship3;
	SHIP_DATA *ship4;
    SHIP_DATA *target;
    int        destination;
    char       buf[MAX_STRING_LENGTH];
    
    ship = ship_from_cockpit( ROOM_SHUTTLE_BUS );
    ship2 = ship_from_cockpit( ROOM_SHUTTLE_BUS_2 );
	ship3 = ship_from_cockpit( ROOM_SHUTTLE_BUS_3 );
	ship4 = ship_from_cockpit( ROOM_SHUTTLE_BUS_4 );

    if ( ship == NULL )
     {
	bug("update_bus: Ship is NULL");
    	return;
     }
    else if ( ship2 == NULL )
     {
	bug("update_bus: Ship2 is NULL");
    	return;
     }
    if ( ship3 == NULL )
     {
	bug("update_bus: Ship3 is NULL");
    	return;
     }
    if ( ship4 == NULL )
     {
	bug("update_bus: Ship4 is NULL");
    	return;
     }
    
    switch (bus_pos)
    {  

       case 0:
            target = ship_from_hanger( bus_vnum[bus_planet] );
            if ( target != NULL && !target->starsystem )
            {
               sprintf( buf,  "An electronic voice says, 'Cannot land at %s ... it seems to have dissapeared.'", bus_stop[bus_planet] );
               echo_to_ship( AT_CYAN , ship , buf );    
               bus_pos = 5;
            }   
            
            target = ship_from_hanger( bus_vnum[bus2_planet] );
            if ( target != NULL && !target->starsystem )
            {
               sprintf( buf,  "An electronic voice says, 'Cannot land at %s ... it seems to have dissapeared.'", bus_stop[bus_planet] );
               echo_to_ship( AT_CYAN , ship2 , buf );    
               bus_pos = 5;
            }   
			target = ship_from_hanger(bus_vnum[bus3_planet]);
			if(target != NULL && !target->starsystem)
		{
				sprintf(buf, "An electronic voice says, 'Cannot land at %s ... it seems to have disappeared.'", bus_stop[bus_planet]);
				echo_to_ship(AT_CYAN, ship3, buf);
				bus_pos = 5;
		}
			target = ship_from_hanger(bus_vnum[bus4_planet]);
			if(target != NULL && !target->starsystem)
		{
				sprintf(buf, "An electronic voice says, 'Cannot land at %s ... it seems to have disappeared.'", bus_stop[bus_planet]);
				echo_to_ship(AT_CYAN, ship4, buf);
				bus_pos = 5;
		}
            bus_pos++;
            break;
       
       case 6:
            launch_bus ( ship );
            launch_bus ( ship2 );
			launch_bus ( ship3 );
			launch_bus ( ship4 );
            bus_pos++;
            break; 
       
       case 7:
            echo_to_ship( AT_YELLOW , ship , "The ship lurches slightly as it makes the jump to lightspeed.");
            echo_to_ship( AT_YELLOW , ship2 , "The ship lurches slightly as it makes the jump to lightspeed.");
		    echo_to_ship( AT_YELLOW , ship3 , "The ship lurches slightly as it makes the jump to lightspeed.");
			echo_to_ship( AT_YELLOW , ship4 , "The ship lurches slightly as it makes the jump to lightspeed.");

            bus_pos++;
            break; 
       
       case 9:
            
            echo_to_ship( AT_YELLOW , ship , "The ship lurches slightly as it comes out of hyperspace..");
            echo_to_ship( AT_YELLOW , ship2 , "The ship lurches slightly as it comes out of hyperspace..");
			echo_to_ship( AT_YELLOW , ship3 , "The ship lurches slightly as it comes out of hyperspace..");
			echo_to_ship( AT_YELLOW , ship4 , "The ship lurches slightly as it comes out of hyperspace..");
            bus_pos++;
            break; 
       
       case 1:
            destination = bus_vnum[bus_planet];
            if ( !land_bus( ship, destination ) )
            {
               sprintf( buf, "An electronic voice says, 'Oh My, %s seems to have dissapeared.'" , bus_stop[bus_planet] );
               echo_to_ship( AT_CYAN , ship , buf ); 
               echo_to_ship( AT_CYAN , ship , "An electronic voice says, 'I do hope it wasn't a superlaser. Landing aborted.'"); 
            }
            else 
            {
               sprintf( buf,  "An electronic voice says, 'Welcome to %s'" , bus_stop[bus_planet] );
               echo_to_ship( AT_CYAN , ship , buf); 
               echo_to_ship( AT_CYAN , ship , "It continues, 'Please exit through the main ramp. Enjoy your stay.'");             
            }
            
            destination = bus_vnum[bus2_planet];
            if ( !land_bus( ship2, destination ) )
            {
               sprintf( buf, "An electronic voice says, 'Oh My, %s seems to have dissapeared.'" , bus_stop[bus_planet] );
               echo_to_ship( AT_CYAN , ship2 , buf ); 
               echo_to_ship( AT_CYAN , ship2 , "An electronic voice says, 'I do hope it wasn't a superlaser. Landing aborted.'"); 
            }
            else 
            {
               sprintf( buf,  "An electronic voice says, 'Welcome to %s'" , bus_stop[bus2_planet] );
               echo_to_ship( AT_CYAN , ship2 , buf); 
               echo_to_ship( AT_CYAN , ship2 , "It continues, 'Please exit through the main ramp. Enjoy your stay.'");             
            }
            
			destination = bus_vnum[bus3_planet];
            if ( !land_bus( ship3, destination ) )
            {
               sprintf( buf, "An electronic voice says, 'Oh My, %s seems to have dissapeared.'" , bus_stop[bus3_planet] );
               echo_to_ship( AT_CYAN , ship3 , buf ); 
               echo_to_ship( AT_CYAN , ship3 , "An electronic voice says, 'I do hope it wasn't a superlaser. Landing aborted.'"); 
            }
            else 
            {
               sprintf( buf,  "An electronic voice says, 'Welcome to %s'" , bus_stop[bus3_planet] );
               echo_to_ship( AT_CYAN , ship3 , buf); 
               echo_to_ship( AT_CYAN , ship3 , "It continues, 'Please exit through the main ramp. Enjoy your stay.'");             
            }

			destination = bus_vnum[bus4_planet];
            if ( !land_bus( ship4, destination ) )
            {
               sprintf( buf, "An electronic voice says, 'Oh My, %s seems to have dissapeared.'" , bus_stop[bus4_planet] );
               echo_to_ship( AT_CYAN , ship4 , buf ); 
               echo_to_ship( AT_CYAN , ship4 , "An electronic voice says, 'I do hope it wasn't a superlaser. Landing aborted.'"); 
            }
            else 
            {
               sprintf( buf,  "An electronic voice says, 'Welcome to %s'" , bus_stop[bus4_planet] );
               echo_to_ship( AT_CYAN , ship4 , buf); 
               echo_to_ship( AT_CYAN , ship4 , "It continues, 'Please exit through the main ramp. Enjoy your stay.'");             
            }

            bus_pos++;
            break;
               
       case 5:
            sprintf( buf, "It continues, 'Next stop, %s'" , bus_stop[bus_planet+1] );
            echo_to_ship( AT_CYAN , ship , "An electronic voice says, 'Preparing for launch.'");
            echo_to_ship( AT_CYAN , ship , buf);
            
            sprintf( buf, "It continues, 'Next stop, %s'" , bus_stop[bus2_planet+1] );
            echo_to_ship( AT_CYAN , ship2 , "An electronic voice says, 'Preparing for launch.'");
            echo_to_ship( AT_CYAN , ship2 , buf);
            
			sprintf( buf, "It continues, 'Next stop, %s'" , bus_stop[bus3_planet+1] );
            echo_to_ship( AT_CYAN , ship3 , "An electronic voice says, 'Preparing for launch.'");
            echo_to_ship( AT_CYAN , ship3 , buf);

			sprintf( buf, "It continues, 'Next stop, %s'" , bus_stop[bus4_planet+1] );
            echo_to_ship( AT_CYAN , ship4 , "An electronic voice says, 'Preparing for launch.'");
            echo_to_ship( AT_CYAN , ship4 , buf);

            bus_pos++;
            break;
                    
       default:
            bus_pos++;
            break;
    }
    
    if ( bus_pos >= 10 )
    {
       bus_pos = 0;
       bus_planet++;
       bus2_planet++;
	   bus3_planet++;
	   bus4_planet++;
    }
    
    if ( bus_planet >= MAX_BUS_STOP )
       bus_planet = 0;
    if ( bus2_planet >= MAX_BUS_STOP )
       bus2_planet = 0;
	if ( bus3_planet >= MAX_BUS_STOP)
	   bus3_planet = 0;
	if(bus4_planet >= MAX_BUS_STOP)
	   bus4_planet = 0;
    
}

void move_ships( )
{
   SHIP_DATA *ship;
   MISSILE_DATA *missile;
   MISSILE_DATA *m_next;
   SHIP_DATA *target;
   float dx, dy, dz, change;
   char buf[MAX_STRING_LENGTH];
   CHAR_DATA *ch;
   bool ch_found = FALSE;
   
   for ( missile = first_missile; missile; missile = m_next )
   {
           m_next = missile->next;
           
              ship = missile->fired_from;
              target = missile->target;
              if (!target) {  extract_missile (missile); 
              continue; 
              }
              
           if ( target->starsystem && target->starsystem == missile->starsystem )
              {
 
           if ( missile->mx < target->vx ) 
                  missile->mx += UMIN( missile->speed/5 , target->vx - missile->mx );
                else if ( missile->mx > target->vx ) 
                  missile->mx -= UMIN( missile->speed/5 , missile->mx - target->vx );  
                if ( missile->my < target->vy ) 
                  missile->my += UMIN( missile->speed/5 , target->vy - missile->my );
                else if ( missile->my > target->vy ) 
                  missile->my -= UMIN( missile->speed/5 , missile->my - target->vy );  
                if ( missile->mz < target->vz ) 
                  missile->mz += UMIN( missile->speed/5 , target->vz - missile->mz );
                else if ( missile->mz > target->vz ) 
                  missile->mz -= UMIN( missile->speed/5 , missile->mz - target->vz );  
              
                if ( abs(missile->mx) - abs(target->vx) <= 20 && abs(missile->mx) - abs(target->vx) >= -20
                && abs(missile->my) - abs(target->vy) <= 20 && abs(missile->my) - abs(target->vy) >= -20
                && abs(missile->mz) - abs(target->vz) <= 20 && abs(missile->mz) - abs(target->vz) >= -20 )
                {  
            if ( target->chaff_released <= 0)
            { 
	            if ( target->manuever/2 > number_range(1, 100) )
				{
					if(target->juking == TRUE)
					{
					 if(number_range(1, 11) != 11)
						{
						 echo_to_room(AT_YELLOW, get_room_index(ship->gunseat), "Your missile barely misses its target." );
						 echo_to_cockpit(AT_ORANGE, target, "An incoming missile is barely evaded.");
						 sprintf(buf, "%s quickly evades an incoming missile.", target->name);
						 echo_to_system(AT_ORANGE, target, buf, ship);
						 extract_missile(missile);
						}
					}
					else
					{
						
                    	echo_to_room( AT_YELLOW , get_room_index(ship->gunseat), "Your missile hits its target dead on!" );
                    	echo_to_cockpit( AT_BLOOD, target, "The ship is hit by a missile.");
                    	echo_to_ship( AT_RED , target , "A loud explosion shakes the ship violently!" );
                    	sprintf( buf, "You see a small explosion as %s is hit by a missile" , target->name );
                    	echo_to_system( AT_ORANGE , target , buf , ship );
                    	for ( ch = first_char; ch; ch = ch->next )
                      	if ( !IS_NPC( ch ) && nifty_is_name( missile->fired_by, ch->name ) )
                     	{   
                   	     ch_found = TRUE; 
                    	   	damage_ship_ch( target , 20+missile->missiletype*missile->missiletype*20 , 
                    	       30+missile->missiletype*missile->missiletype*missile->missiletype*30 , ch );
                      	}
                    	if ( !ch_found )
                       	damage_ship( target , 20+missile->missiletype*missile->missiletype*20 , 
                       	    30+missile->missiletype*missile->missiletype*ship->missiletype*30 );   
                    	extract_missile( missile );
						}
                  }
			  }
                   else
                   {
                    echo_to_room( AT_YELLOW , get_room_index(ship->gunseat), "Your missile explodes harmlessly in a cloud of chaff!" );
                    echo_to_cockpit( AT_YELLOW, target, "A missile explodes in your chaff.");
                    extract_missile( missile );
                   }
                   continue;
                }

               missile->age++;
               if (missile->age >= 50)
               {
                 extract_missile( missile );
                 continue;
               }
              }
              else
              { 
                extract_missile( missile );
                continue;
              }

   }
   
   for ( ship = first_ship; ship; ship = ship->next )
   {

     if ( !ship || !ship->starsystem )
        continue;
          
     if ( ship->currspeed > 0 )
        {
          
          change = sqrt( ship->hx*ship->hx + ship->hy*ship->hy + ship->hz*ship->hz ); 

           if (change > 0)
           {
             dx = ship->hx/change;     
             dy = ship->hy/change;     
             dz = ship->hz/change;
             ship->vx += (dx * ship->currspeed/5);
             ship->vy += (dy * ship->currspeed/5);
             ship->vz += (dz * ship->currspeed/5);
           }
           
        } 

        if ( autofly(ship) )
           continue;
        
/*           
          if ( ship->class != SHIP_SPACE_STATION && !autofly(ship) )
          {
            if ( ship->starsystem->star1 && strcmp(ship->starsystem->star1,"") )
            {
              if (ship->vx >= ship->starsystem->s1x + 1 || ship->vx <= ship->starsystem->s1x - 1 )
                ship->vx -= URANGE(-3,(ship->starsystem->gravitys1)/(ship->vx - ship->starsystem->s1x)/2,3);
              if (ship->vy >= ship->starsystem->s1y + 1 || ship->vy <= ship->starsystem->s1y - 1 )
                ship->vy -= URANGE(-3,(ship->starsystem->gravitys1)/(ship->vy - ship->starsystem->s1y)/2,3);
              if (ship->vz >= ship->starsystem->s1z + 1 || ship->vz <= ship->starsystem->s1z - 1 )
                ship->vz -= URANGE(-3,(ship->starsystem->gravitys1)/(ship->vz - ship->starsystem->s1z)/2,3);
            }
          
            if ( ship->starsystem->star2 && strcmp(ship->starsystem->star2,"") )
            {
              if (ship->vx >= ship->starsystem->s2x + 1 || ship->vx <= ship->starsystem->s2x - 1 )
                ship->vx -= URANGE(-3,(ship->starsystem->gravitys2)/(ship->vx - ship->starsystem->s2x)/2,3);
              if (ship->vy >= ship->starsystem->s2y + 1 || ship->vy <= ship->starsystem->s2y - 1 )
                ship->vy -= URANGE(-3,(ship->starsystem->gravitys2)/(ship->vy - ship->starsystem->s2y)/2,3);
              if (ship->vz >= ship->starsystem->s2z + 1 || ship->vz <= ship->starsystem->s2z - 1 )
                ship->vz -= URANGE(-3,(ship->starsystem->gravitys2)/(ship->vz - ship->starsystem->s2z)/2,3);
            }
          
            if ( ship->starsystem->planet1 && strcmp(ship->starsystem->planet1,"") )
            {
              if (ship->vx >= ship->starsystem->p1x + 1 || ship->vx <= ship->starsystem->p1x - 1 )
                ship->vx -= URANGE(-3,(ship->starsystem->gravityp1)/(ship->vx - ship->starsystem->p1x)/2,3);
              if (ship->vy >= ship->starsystem->p1y + 1 || ship->vy <= ship->starsystem->p1y - 1 )
                ship->vy -= URANGE(-3,(ship->starsystem->gravityp1)/(ship->vy - ship->starsystem->p1y)/2,3);
              if (ship->vz >= ship->starsystem->p1z + 1 || ship->vz <= ship->starsystem->p1z - 1 )
                ship->vz -= URANGE(-3,(ship->starsystem->gravityp1)/(ship->vz - ship->starsystem->p1z)/2,3);
            }
          
            if ( ship->starsystem->planet2 && strcmp(ship->starsystem->planet2,"") )
            {
              if (ship->vx >= ship->starsystem->p2x + 1 || ship->vx <= ship->starsystem->p2x - 1 )
                ship->vx -= URANGE(-3,(ship->starsystem->gravityp2)/(ship->vx - ship->starsystem->p2x)/2,3);
              if (ship->vy >= ship->starsystem->p2y + 1 || ship->vy <= ship->starsystem->p2y - 1 )
                ship->vy -= URANGE(-3,(ship->starsystem->gravityp2)/(ship->vy - ship->starsystem->p2y)/2,3);
              if (ship->vz >= ship->starsystem->p2z + 1 || ship->vz <= ship->starsystem->p2z - 1 )
                ship->vz -= URANGE(-3,(ship->starsystem->gravityp2)/(ship->vz - ship->starsystem->p2z)/2,3);
            }
          
            if ( ship->starsystem->planet3 && strcmp(ship->starsystem->planet3,"") )
            {
              if (ship->vx >= ship->starsystem->p3x + 1 || ship->vx <= ship->starsystem->p3x - 1 )
                ship->vx -= URANGE(-3,(ship->starsystem->gravityp3)/(ship->vx - ship->starsystem->p3x)/2,3);
              if (ship->vy >= ship->starsystem->p3y + 1 || ship->vy <= ship->starsystem->p3y - 1 )
                ship->vy -= URANGE(-3,(ship->starsystem->gravityp3)/(ship->vy - ship->starsystem->p3y)/2,3);
              if (ship->vz >= ship->starsystem->p3z + 1 || ship->vz <= ship->starsystem->p3z - 1 )
                ship->vz -= URANGE(-3,(ship->starsystem->gravityp3)/(ship->vz - ship->starsystem->p3z)/2,3);
            }
          }

*/          
/*
          for ( target = ship->starsystem->first_ship; target; target = target->next_in_starsystem)
          { 
                if ( target != ship &&
                    abs(ship->vx - target->vx) < 1 &&
                    abs(ship->vy - target->vy) < 1 &&
                    abs(ship->vz - target->vz) < 1 )
                {
                    ship->collision = target->maxhull;
                    target->collision = ship->maxhull;
                }                   
          }
*/
          if ( ship->starsystem->star1 && strcmp(ship->starsystem->star1,"") && 
                     abs(ship->vx - ship->starsystem->s1x) < 10 && 
                     abs(ship->vy - ship->starsystem->s1y) < 10 &&
                     abs(ship->vz - ship->starsystem->s1z) < 10 )
                {
                    echo_to_cockpit( AT_BLOOD+AT_BLINK, ship, "You fly directly into the sun.");
                    sprintf( buf , "%s flies directly into %s!", ship->name, ship->starsystem->star1); 
                    echo_to_system( AT_ORANGE , ship , buf , NULL );
                    destroy_ship(ship, NULL, "flew into sun");
                    continue;
                }              
          if ( ship->starsystem->star2 && strcmp(ship->starsystem->star2,"") && 
               abs(ship->vx - ship->starsystem->s2x) < 10 && 
                     abs(ship->vy - ship->starsystem->s2y) < 10 &&
                     abs(ship->vz - ship->starsystem->s2z) < 10 )
                {
                    echo_to_cockpit( AT_BLOOD+AT_BLINK, ship, "You fly directly into the sun.");
                    sprintf( buf , "%s flys directly into %s!", ship->name, ship->starsystem->star2); 
                    echo_to_system( AT_ORANGE , ship , buf , NULL );
                    destroy_ship(ship , NULL, "flew into sun");
                    continue;
                }            

        if ( ship->currspeed > 0 )
        {       
          if ( ship->starsystem->planet1 && strcmp(ship->starsystem->planet1,"") && 
               abs(ship->vx - ship->starsystem->p1x) < 10 && 
                     abs(ship->vy - ship->starsystem->p1y) < 10 &&
                     abs(ship->vz - ship->starsystem->p1z) < 10 )
                {
                    sprintf( buf , "You begin orbitting %s.", ship->starsystem->planet1); 
                    echo_to_cockpit( AT_YELLOW, ship, buf);
                    sprintf( buf , "%s begins orbitting %s.", ship->name, ship->starsystem->planet1); 
                    echo_to_system( AT_ORANGE , ship , buf , NULL );
                    ship->currspeed = 0;
                    continue;
                }            
          if ( ship->starsystem->planet2 && strcmp(ship->starsystem->planet2,"") && 
               abs(ship->vx - ship->starsystem->p2x) < 10 && 
                     abs(ship->vy - ship->starsystem->p2y) < 10 &&
                     abs(ship->vz - ship->starsystem->p2z) < 10 )
                {
                    sprintf( buf , "You begin orbitting %s.", ship->starsystem->planet2); 
                    echo_to_cockpit( AT_YELLOW, ship, buf);
                    sprintf( buf , "%s begins orbitting %s.", ship->name, ship->starsystem->planet2); 
                    echo_to_system( AT_ORANGE , ship , buf , NULL );
                    ship->currspeed = 0;
                    continue;
                }            
          if ( ship->starsystem->planet3 && strcmp(ship->starsystem->planet3,"") && 
               abs(ship->vx - ship->starsystem->p3x) < 10 && 
                     abs(ship->vy - ship->starsystem->p3y) < 10 &&
                     abs(ship->vz - ship->starsystem->p3z) < 10 )
                {
                    sprintf( buf , "You begin orbitting %s.", ship->starsystem->planet2); 
                    echo_to_cockpit( AT_YELLOW, ship, buf);
                    sprintf( buf , "%s begins orbitting %s.", ship->name, ship->starsystem->planet2); 
                    echo_to_system( AT_ORANGE , ship , buf , NULL );
                    ship->currspeed = 0;
                    continue;
                }            
        }
   }

   for ( ship = first_ship; ship; ship = ship->next )
       if (ship->collision) 
       {
           echo_to_cockpit( AT_WHITE+AT_BLINK , ship,  "You have collided with another ship!" );
           echo_to_ship( AT_RED , ship , "A loud explosion shakes the ship violently!" );   
           damage_ship( ship , ship->collision , ship->collision );
           ship->collision = 0;
       }
}   

void recharge_ships( )
{
   SHIP_DATA *ship;
   char buf[MAX_STRING_LENGTH];
   int weapon;

   for ( ship = first_ship; ship; ship = ship->next )
   {                
           
        if (ship->primaryState > 0)
        {
		  if(ship->primaryType != AUTOBLASTER)
           ship->energy -= ship->primaryState;
		    
           ship->primaryState = 0;
        }
		if(ship->secondaryState > 0)
	   {
			if(ship->secondaryType != AUTOBLASTER)
				ship->energy -= ship->secondaryState;

			ship->secondaryState = 0;
	   }
        if (ship->statet1 > 0)
        {
           ship->energy -= ship->statet1;
           ship->statet1 = 0;
        }
        if (ship->statet2 > 0)
        {
           ship->energy -= ship->statet2;
           ship->statet2 = 0;
        }
        if (ship->statet3 > 0)
        {
           ship->energy -= ship->statet3;
           ship->statet3 = 0;
        }
        if (ship->statet4 > 0)
        {
           ship->energy -= ship->statet4;
           ship->statet4 = 0;
        }
        if (ship->statet5 > 0)
        {
           ship->energy -= ship->statet5;
           ship->statet5 = 0;
        }
        if (ship->statet6 > 0)
        {
           ship->energy -= ship->statet6;
           ship->statet6 = 0;
        }
        if (ship->statet7 > 0)
        {
           ship->energy -= ship->statet7;
           ship->statet7 = 0;
        }
        if (ship->statet8 > 0)
        {
           ship->energy -= ship->statet8;
           ship->statet8 = 0;
        }
        if (ship->statet9 > 0)
        {
           ship->energy -= ship->statet9;
           ship->statet9 = 0;
        }
        if (ship->statet10 > 0)
        {
           ship->energy -= ship->statet10;
           ship->statet10 = 0;
        }
        
     for( weapon=0; weapon < MAX_MISSILES; weapon++ )
      {
        if (ship->missilestate[weapon] == MISSILE_RELOAD_2)
        {
           ship->missilestate[weapon] = MISSILE_READY;
           if ( ship->missile_quant[weapon] > 0 )
               echo_to_room( AT_YELLOW, get_room_index(ship->gunseat), "Missile launcher reloaded.");
        }
        
        if (ship->missilestate[weapon]== MISSILE_RELOAD )
           ship->missilestate[weapon] = MISSILE_RELOAD_2;
              
        if (ship->missilestate[weapon] == MISSILE_FIRED )
           ship->missilestate[weapon] = MISSILE_RELOAD;
      }

       if ( autofly(ship) )
       {
          if ( ship->starsystem )
          {
             if (ship->target0 && ship->primaryState != LASER_DAMAGED )
             {
                 int chance = 50;
                 SHIP_DATA * target = ship->target0;
                 int shots;
                 
                  for ( shots=0 ; shots <= ship->primaryCount && ship->target0; shots++ )
                {   
                  if (ship->shipstate != SHIP_HYPERSPACE && ship->energy > 25 
                  && ship->target0->starsystem == ship->starsystem
                  && abs(target->vx - ship->vx) <= 1000 
                  && abs(target->vy - ship->vy) <= 1000
                  && abs(target->vz - ship->vz) <= 1000 
                  && ship->primaryState < ship->primaryCount )
                  {
                    if ( ship->class >= SHIP_MIDSHIP || is_facing ( ship , target ) )
                    {
             		chance += target->class*25;
             		chance -= target->manuever/10;
             		chance -= target->currspeed/20;
             		chance -= ( abs(target->vx - ship->vx)/70 );
             		chance -= ( abs(target->vy - ship->vy)/70 );
             		chance -= ( abs(target->vz - ship->vz)/70 );
             		chance = URANGE( 10 , chance , 90 );
             		if ( number_percent( ) > chance )
             		{	  
           		    sprintf( buf , "%s fires at you but misses." , ship->name);  
             		    echo_to_cockpit( AT_ORANGE , target , buf );
      	                    sprintf( buf, "Laserfire from %s barely misses %s." , ship->name , target->name );
                            echo_to_system( AT_ORANGE , target , buf , NULL );	
             		} 
             		else
             		{
             		    sprintf( buf, "Laserfire from %s hits %s." , ship->name, target->name );
             		    echo_to_system( AT_ORANGE , target , buf , NULL );
                            sprintf( buf , "You are hit by lasers from %s!" , ship->name);  
                            echo_to_cockpit( AT_BLOOD , target , buf );           
                            echo_to_ship( AT_RED , target , "A small explosion vibrates through the ship." );           
                            damage_ship( target , 5 , 10 );
                        }
                        ship->primaryState++;
                    }
                  }
                }
             }
          }
       }
       
   }
}

void update_space( )
{
   SHIP_DATA *ship;
   SHIP_DATA *target;
   char buf[MAX_STRING_LENGTH];
   int too_close, target_too_close;
   int recharge;
   int weapon;
 
   for ( ship = first_ship; ship; ship = ship->next )
   {    
        if (ship->starsystem)
        {
          if ( ship->energy > 0 && ship->shipstate == SHIP_DISABLED && ship->class != SHIP_SPACE_STATION )
             ship->energy -= 100;
          else if ( ship->energy > 0 )
             ship->energy += ( 5 + ship->class*5 );
          else if(ship->type == MOB_SHIP)
			 ship->energy = ship->maxenergy;
		  else
             destroy_ship(ship , NULL, "destroyed by lack of energy");
        }
        
        if ( ship->chaff_released > 0 )
           ship->chaff_released--;
                
        if (ship->shipstate == SHIP_HYPERSPACE)
        {
		   switch(ship->hyperspeed)
			{
			   case 1: ship->hyperdistance -= number_range(170, 225); break;
			   case 2: ship->hyperdistance -= number_range(135, 180); break;
			   case 3: ship->hyperdistance -= number_range(80, 110); break;
			   case 4: ship->hyperdistance -= number_range(60, 100); break;
			   case 5: ship->hyperdistance -= number_range(40, 60); break;
			   case 6: ship->hyperdistance -= number_range(20, 45); break;
			   case 7: ship->hyperdistance -= number_range(1,  25);
			   default: ship->hyperdistance -= 20; break;
			}
            if (ship->hyperdistance <= 0)
            {
            	ship_to_starsystem (ship, ship->currjump);
            	
            	if (ship->starsystem == NULL)
            	{
            	    echo_to_cockpit( AT_RED, ship, "Ship lost in Hyperspace. Make new calculations.");
            	}
            	else
            	{
            	    echo_to_room( AT_YELLOW, get_room_index(ship->pilotseat), "Hyperjump complete.");
            	    echo_to_ship( AT_YELLOW, ship, "The ship lurches slightly as it comes out of hyperspace.");
            	    sprintf( buf ,"%s enters the starsystem at %.0f %.0f %.0f" , ship->name, ship->vx, ship->vy, ship->vz );
            	    echo_to_system( AT_YELLOW, ship, buf , NULL );
            	    ship->shipstate = SHIP_READY;
            	    STRFREE( ship->home );
            	    ship->home = STRALLOC( ship->starsystem->name );
            	    if ( str_cmp("Public",ship->owner) )
                        save_ship(ship);
                    
            	}
            }
            else
            {
               sprintf( buf ,"%d" , ship->hyperdistance );
               echo_to_room_dnr( AT_YELLOW , get_room_index(ship->pilotseat), "Remaining jump distance: " );
               echo_to_room( AT_WHITE , get_room_index(ship->pilotseat),  buf );
               
            }
        }
        
        /* following was originaly to fix ships that lost their pilot 
           in the middle of a manuever and are stuck in a busy state 
           but now used for timed manouevers such as turning */
    
    	if (ship->shipstate == SHIP_BUSY_3)
           {
              echo_to_room( AT_YELLOW, get_room_index(ship->pilotseat), "Manuever complete.");  
              ship->shipstate = SHIP_READY;
           }
        if (ship->shipstate == SHIP_BUSY_2)
           ship->shipstate = SHIP_BUSY_3;
        if (ship->shipstate == SHIP_BUSY)
           ship->shipstate = SHIP_BUSY_2;
        
        if (ship->shipstate == SHIP_LAND_2)
           landship( ship , ship->dest );
        if (ship->shipstate == SHIP_LAND)
           ship->shipstate = SHIP_LAND_2;
        
        if (ship->shipstate == SHIP_DOCKED3)
	   dockship( ship );
	if (ship->shipstate == SHIP_DOCKED2)
	   ship->shipstate = SHIP_DOCKED3;

	if (ship->shipstate == SHIP_UNDOCK3)
	   undockship( ship );
	if (ship->shipstate == SHIP_UNDOCK2)
	   ship->shipstate = SHIP_UNDOCK3;

        if (ship->shipstate == SHIP_LAUNCH_2)
           launchship( ship );
        if (ship->shipstate == SHIP_LAUNCH)
           ship->shipstate = SHIP_LAUNCH_2;
        
        
        ship->shield = UMAX( 0 , ship->shield-1-ship->class);
                
        if (ship->autorecharge && ship->maxshield > ship->shield && ship->energy > 100)
        {
           recharge  = UMIN( ship->maxshield-ship->shield, 10 + ship->class*10 );           
           recharge  = UMIN( recharge , ship->energy/2 -100 );
           recharge  = UMAX( 1, recharge );
           ship->shield += recharge;
           ship->energy -= recharge;        
        }
        
        if (ship->shield > 0)
        {
          if (ship->energy < 200)
          {
          	ship->shield = 0;
          	echo_to_cockpit( AT_RED, ship,"The ships shields fizzle and die.");
                ship->autorecharge = FALSE;
          }
        }        
        
        if ( ship->starsystem && ship->currspeed > 0 )
        {
               sprintf( buf, "%d  ",
                          ship->currspeed );
               echo_to_room_dnr( AT_BLUE , get_room_index(ship->pilotseat),  "Speed: " );
               echo_to_room_dnr( AT_LBLUE , get_room_index(ship->pilotseat),  buf );
			   if(ship->maxhull > 0){

			   sprintf( buf, "%d%%  ", (ship->hull*100)/ship->maxhull);
			   echo_to_room_dnr( AT_BLUE, get_room_index(ship->pilotseat), "Hull: ");
			   echo_to_room_dnr( AT_LBLUE, get_room_index(ship->pilotseat), buf);
			   }

			   if(ship->maxshield > 0){
				   sprintf(buf, "%d%%  ", (ship->shield*100)/ship->maxshield);
				   echo_to_room_dnr(AT_BLUE, get_room_index(ship->pilotseat), "Shields: ");
				   echo_to_room_dnr(AT_LBLUE, get_room_index(ship->pilotseat), buf);
			   }
			   if(ship->maxenergy > 0){
			   sprintf( buf, "%d%%  ", (ship->energy*100)/ship->maxenergy);
			   echo_to_room_dnr(AT_BLUE, get_room_index(ship->pilotseat), "Energy: ");
			   echo_to_room(AT_LBLUE, get_room_index(ship->pilotseat), buf);
			   }
               echo_to_room_dnr( AT_BLUE , get_room_index(ship->pilotseat),  "Coordinates in " );
			   if(ship->starsystem)
				   sprintf(buf, "&C%s&B system: ", ship->starsystem->name);
			   else
				   sprintf(buf, "system: ");
			   echo_to_room_dnr(AT_BLUE, get_room_index(ship->pilotseat), buf);
               sprintf( buf, "%.0f %.0f %.0f",
                           ship->vx , ship->vy, ship->vz );
               echo_to_room( AT_LBLUE , get_room_index(ship->pilotseat),  buf );
			 
				   
            if ( ship->pilotseat != ship->coseat )
            {
               sprintf( buf, "%d  ",
                          ship->currspeed );
               echo_to_room_dnr( AT_BLUE , get_room_index(ship->coseat),  "Speed: " );
               echo_to_room_dnr( AT_LBLUE , get_room_index(ship->coseat),  buf );
			   if(ship->maxhull > 0){

			   sprintf( buf, "%d%%  ", (ship->hull*100)/ship->maxhull);
			   echo_to_room_dnr( AT_BLUE, get_room_index(ship->coseat), "Hull: ");
			   echo_to_room_dnr( AT_LBLUE, get_room_index(ship->coseat), buf);
			   }

			   if(ship->maxshield > 0){
				   sprintf(buf, "%d%%  ", (ship->shield*100)/ship->maxshield);
				   echo_to_room_dnr(AT_BLUE, get_room_index(ship->coseat), "Shields: ");
				   echo_to_room_dnr(AT_LBLUE, get_room_index(ship->coseat), buf);
			   }
			   if(ship->maxenergy > 0){
			   sprintf( buf, "%d%%  ", (ship->energy*100)/ship->maxenergy);
			   echo_to_room_dnr(AT_BLUE, get_room_index(ship->coseat), "Energy: ");
			   echo_to_room(AT_LBLUE, get_room_index(ship->coseat), buf);
			   }
               echo_to_room_dnr( AT_BLUE , get_room_index(ship->coseat),  "Coordinates in " );
			   if(ship->starsystem)
				   sprintf(buf, "&C%s&B system: ", ship->starsystem->name);
			   else
				   sprintf(buf, "system: ");
			   echo_to_room_dnr(AT_BLUE, get_room_index(ship->coseat), buf);
               sprintf( buf, "%.0f %.0f %.0f",
                           ship->vx , ship->vy, ship->vz );
               echo_to_room( AT_LBLUE , get_room_index(ship->coseat),  buf );
            }
        } 

        if ( ship->starsystem )
        {
          too_close = ship->currspeed + 50;
          for ( target = ship->starsystem->first_ship; target; target = target->next_in_starsystem)
          { 
            target_too_close = too_close+target->currspeed;
            if ( target != ship &&
                 abs(ship->vx - target->vx) < target_too_close &&
                 abs(ship->vy - target->vy) < target_too_close &&
                 abs(ship->vz - target->vz) < target_too_close )
            {
                sprintf( buf, "Proximity alert: %s  %.0f %.0f %.0f"
                            , target->name, target->vx, target->vy, target->vz);
                echo_to_room( AT_RED , get_room_index(ship->pilotseat),  buf );    
            }                
          }    
          too_close = ship->currspeed + 100;
          if ( ship->starsystem->star1 &&  strcmp(ship->starsystem->star1,"") && 
               abs(ship->vx - ship->starsystem->s1x) < too_close && 
               abs(ship->vy - ship->starsystem->s1y) < too_close &&
               abs(ship->vz - ship->starsystem->s1z) < too_close )
          {
                sprintf( buf, "Proximity alert: %s  %d %d %d", ship->starsystem->star1,
                         ship->starsystem->s1x, ship->starsystem->s1y, ship->starsystem->s1z);
                echo_to_room( AT_RED , get_room_index(ship->pilotseat),  buf );
          }               
          if ( ship->starsystem->star2 && strcmp(ship->starsystem->star2,"") && 
               abs(ship->vx - ship->starsystem->s2x) < too_close && 
               abs(ship->vy - ship->starsystem->s2y) < too_close &&
               abs(ship->vz - ship->starsystem->s2z) < too_close )
          {
                sprintf( buf, "Proximity alert: %s  %d %d %d", ship->starsystem->star2,
                         ship->starsystem->s2x, ship->starsystem->s2y, ship->starsystem->s2z);
                echo_to_room( AT_RED , get_room_index(ship->pilotseat),  buf );
          }               
          if ( ship->starsystem->planet1 && strcmp(ship->starsystem->planet1,"") && 
               abs(ship->vx - ship->starsystem->p1x) < too_close && 
               abs(ship->vy - ship->starsystem->p1y) < too_close &&
               abs(ship->vz - ship->starsystem->p1z) < too_close )
          {
                sprintf( buf, "Proximity alert: %s  %d %d %d", ship->starsystem->planet1,
                         ship->starsystem->p1x, ship->starsystem->p1y, ship->starsystem->p1z);
                echo_to_room( AT_RED , get_room_index(ship->pilotseat),  buf );
          }               
          if ( ship->starsystem->planet2 && strcmp(ship->starsystem->planet2,"") && 
               abs(ship->vx - ship->starsystem->p2x) < too_close && 
               abs(ship->vy - ship->starsystem->p2y) < too_close &&
               abs(ship->vz - ship->starsystem->p2z) < too_close )
          {
                sprintf( buf, "Proximity alert: %s  %d %d %d", ship->starsystem->planet2,
                         ship->starsystem->p2x, ship->starsystem->p2y, ship->starsystem->p2z);
                echo_to_room( AT_RED , get_room_index(ship->pilotseat),  buf );
          }               
          if ( ship->starsystem->planet3 && strcmp(ship->starsystem->planet3,"") && 
               abs(ship->vx - ship->starsystem->p3x) < too_close && 
               abs(ship->vy - ship->starsystem->p3y) < too_close &&
               abs(ship->vz - ship->starsystem->p3z) < too_close )
          {
                sprintf( buf, "Proximity alert: %s  %d %d %d", ship->starsystem->planet3,
                         ship->starsystem->p3x, ship->starsystem->p3y, ship->starsystem->p3z);
                echo_to_room( AT_RED , get_room_index(ship->pilotseat),  buf );
          }               
        }
       

        if (ship->target0)
        {
               sprintf( buf, "%s   %.0f %.0f %.0f", ship->target0->name,
                          ship->target0->vx , ship->target0->vy, ship->target0->vz );
               echo_to_room_dnr( AT_BLUE , get_room_index(ship->gunseat), "Target: " );
               echo_to_room( AT_LBLUE , get_room_index(ship->gunseat),  buf );
               if (ship->starsystem != ship->target0->starsystem)
               		ship->target0 = NULL;
         }
         
        if (ship->target1)
        {
               sprintf( buf, "%s   %.0f %.0f %.0f", ship->target1->name,
                          ship->target1->vx , ship->target1->vy, ship->target1->vz );
               echo_to_room_dnr( AT_BLUE , get_room_index(ship->turret1), "Target: " );
               echo_to_room( AT_LBLUE , get_room_index(ship->turret1),  buf );
               if (ship->starsystem != ship->target1->starsystem)
               		ship->target1 = NULL;
         }
        
        if (ship->target2)
        {
               sprintf( buf, "%s   %.0f %.0f %.0f", ship->target2->name,
                          ship->target2->vx , ship->target2->vy, ship->target2->vz );
               echo_to_room_dnr( AT_BLUE , get_room_index(ship->turret2), "Target: " );
               echo_to_room( AT_LBLUE , get_room_index(ship->turret2),  buf );
               if (ship->starsystem != ship->target2->starsystem)
               		ship->target2 = NULL;
         }
         
   	if (ship->energy < 100 && ship->starsystem )
   	{
   	    echo_to_cockpit( AT_RED , ship,  "Warning: Ship fuel low." );
        }
                    
        ship->energy = URANGE( 0 , ship->energy, ship->maxenergy );
   } 

   for ( ship = first_ship; ship; ship = ship->next )
   {
       
       if (ship->autotrack && ship->target0 && ship->class < SHIP_CAPITAL )    
       {
           target = ship->target0;
           too_close = ship->currspeed + 10; 
           target_too_close = too_close+target->currspeed;
           if ( target != ship && ship->shipstate == SHIP_READY && 
                 abs(ship->vx - target->vx) < target_too_close &&
                 abs(ship->vy - target->vy) < target_too_close &&
                 abs(ship->vz - target->vz) < target_too_close )
           {
              ship->hx = 0-(ship->target0->vx - ship->vx);
              ship->hy = 0-(ship->target0->vy - ship->vy);
              ship->hz = 0-(ship->target0->vz - ship->vz);
              ship->energy -= ship->currspeed/10;
              echo_to_room( AT_RED , get_room_index(ship->pilotseat), "Autotrack: Evading to avoid collision!\n\r" );  
    	      if ( ship->class == SHIP_FIGHTER || ship->class == SHIP_MIDSHIP )
        	ship->shipstate = SHIP_BUSY_3;
              else if ( ship->class >= SHIP_CAPITAL )
        	ship->shipstate = SHIP_BUSY_2;
    	      else
        	ship->shipstate = SHIP_BUSY;     
           }
           else if  ( !is_facing(ship, ship->target0) )
           {
              ship->hx = ship->target0->vx - ship->vx;
              ship->hy = ship->target0->vy - ship->vy;
              ship->hz = ship->target0->vz - ship->vz;
              ship->energy -= ship->currspeed/10;
              echo_to_room( AT_BLUE , get_room_index(ship->pilotseat), "Autotracking target ... setting new course.\n\r" );      
    	      if ( ship->class == SHIP_FIGHTER || ship->class == SHIP_MIDSHIP ) 
        	ship->shipstate = SHIP_BUSY_3;
              else if ( ship->class >= SHIP_CAPITAL )
        	ship->shipstate = SHIP_BUSY_2;
    	      else
        	ship->shipstate = SHIP_BUSY;  
           }
       }

       if ( autofly(ship) )
       {
          if ( ship->starsystem )
          {
             if (ship->target0)
             {
                 int chance = 50;
             
                 /* auto assist ships */
                  
                 for ( target = ship->starsystem->first_ship; target; target = target->next_in_starsystem)
                 {
                    if ( autofly(target) )
		    {
			if(IS_SET(target->flags, SHIP_SIMULATOR))  continue;
                       if ( !str_cmp ( target->owner , ship->owner ) && target != ship )
                         if ( target->target0 == NULL && ship->target0 != target )
                         {  
                           target->target0 = ship->target0;
                           sprintf( buf , "You are being targetted by %s." , target->name);  
                           echo_to_cockpit( AT_BLOOD , target->target0 , buf );
                           break;
                        }   
                    }
		}
                   
                 target = ship->target0;
                 ship->autotrack = TRUE;
                 if( ship->class != SHIP_SPACE_STATION )
                      ship->currspeed = ship->realspeed;
                 if ( ship->energy >200  )
                    ship->autorecharge=TRUE;
                    
            for( weapon=0; weapon < MAX_MISSILES; weapon++ )
	     {
	      if( ship->missile[weapon] > 0 )
		{
                 if (ship->shipstate != SHIP_HYPERSPACE && ship->energy > 25 
                 && ship->missilestate[weapon] == MISSILE_READY && ship->target0->starsystem == ship->starsystem
                 && abs(target->vx - ship->vx) <= 1200 
                 && abs(target->vy - ship->vy) <= 1200
                 && abs(target->vz - ship->vz) <= 1200
                 && ship->missile_quant[weapon] > 0 )
                 {
                   if ( ship->class >= SHIP_CAPITAL )
                   {
             		chance -= target->manuever/5;
                        chance -= target->currspeed/20;
                        chance += target->class*target->class*25;
                        chance -= ( abs(target->vx - ship->vx)/100 );
                        chance -= ( abs(target->vy - ship->vy)/100 );
                        chance -= ( abs(target->vz - ship->vz)/100 );                          
                        chance += ( 30 );
                        chance = URANGE( 10 , chance , 90 );

             		if ( number_percent( ) > chance )
             		{
             		} 
                        else
                        {       
                                new_missile( ship , target , NULL , CONCUSSION_MISSILE );
             		        sprintf( buf , "Incoming missile from %s." , ship->name);  
             		        echo_to_cockpit( AT_BLOOD , target , buf );
             		        sprintf( buf, "%s fires a missile towards %s." , ship->name, target->name );
             		        echo_to_system( AT_ORANGE , target , buf , NULL );

            		 	if ( ship->class >= SHIP_CAPITAL)
                                    ship->missilestate[weapon] = MISSILE_RELOAD_2;
                                else
                                    ship->missilestate[weapon] = MISSILE_FIRED;
                        }
                   }
                 }           
             }
             else
             {
                 ship->currspeed = 0;
                 
                 if ( !str_cmp( ship->owner , "Hutt Crime Syndicate" ) )
                   for ( target = first_ship; target; target = target->next )
                     if ( ship->starsystem == target->starsystem )
                        if ( !str_cmp( target->owner , "The Republic" ) )       
                        {  
                          ship->target0 = target; 
                          sprintf( buf , "You are being targetted by %s." , ship->name);  
                          echo_to_cockpit( AT_BLOOD , target , buf );
                          break;
                        }
                if ( !str_cmp( ship->owner , "The Republic" ) )
                   for ( target = first_ship; target; target = target->next )
                     if ( ship->starsystem == target->starsystem )
                        if ( !str_cmp( target->owner , "Hutt Crime Syndicate" ) )
                        {  
                          sprintf( buf , "You are being targetted by %s." , ship->name);  
                          echo_to_cockpit( AT_BLOOD , target , buf );
                          ship->target0 = target;
                          break;
                        }
               
               if ( !str_cmp( ship->owner , "Pirates" ) )
                   for ( target = first_ship; target; target = target->next )
                     if ( ship->starsystem == target->starsystem )
                     {  
                          sprintf( buf , "You are being targetted by %s." , ship->name);  
                          echo_to_cockpit( AT_BLOOD , target , buf );
                          ship->target0 = target;
                          break;
                     }         
                        
             }
	    }
	   }
          }   
          else
          {
               if ( number_range(1, 25) == 25 )
               {
          	  ship_to_starsystem(ship, starsystem_from_name(ship->home) );  
          	  ship->vx = number_range( -5000 , 5000 );
          	  ship->vy = number_range( -5000 , 5000 );
          	  ship->vz = number_range( -5000 , 5000 );
                  ship->hx = 1;
                  ship->hy = 1;
                  ship->hz = 1;
               }
          }   
       }
       
   }

}



void write_starsystem_list( )
{
    SPACE_DATA *tstarsystem;
    FILE *fpout;
    char filename[256];
    
    sprintf( filename, "%s%s", SPACE_DIR, SPACE_LIST );
    fpout = fopen( filename, "w" );
    if ( !fpout )
    {
         bug( "FATAL: cannot open starsystem.lst for writing!\n\r", 0 );
         return;
    }
    for ( tstarsystem = first_starsystem; tstarsystem; tstarsystem = tstarsystem->next )
    fprintf( fpout, "%s\n", tstarsystem->filename );
    fprintf( fpout, "$\n" );
    fclose( fpout );
}
                                                                    

/*
 * Get pointer to space structure from starsystem name.
 */
SPACE_DATA *starsystem_from_name( char *name )
{
    SPACE_DATA *starsystem;
    
    for ( starsystem = first_starsystem; starsystem; starsystem = starsystem->next )
       if ( !str_cmp( name, starsystem->name ) )
         return starsystem;
    
    for ( starsystem = first_starsystem; starsystem; starsystem = starsystem->next )
       if ( !str_prefix( name, starsystem->name ) )
         return starsystem;
    
    return NULL;
}

/*
 * Get pointer to space structure from the dock vnun.
 */
SPACE_DATA *starsystem_from_vnum( int vnum )
{
    SPACE_DATA *starsystem;
    SHIP_DATA *ship;
    
    for ( starsystem = first_starsystem; starsystem; starsystem = starsystem->next )
       if ( vnum == starsystem->doc1a || vnum == starsystem->doc2a    || vnum == starsystem->doc3a ||
            vnum == starsystem->doc1b || vnum == starsystem->doc2b    || vnum == starsystem->doc3b ||   
            vnum == starsystem->doc1c || vnum == starsystem->doc2c    || vnum == starsystem->doc3c )
         return starsystem;

    for ( ship = first_ship; ship; ship = ship->next )
       if ( vnum == ship->hanger1 || vnum == ship->hanger2
		 || vnum == ship->hanger3 || vnum == ship->hanger4)
            return ship->starsystem;
                                
    return NULL;
}
SPACE_DATA *starsystem_from_room( ROOM_INDEX_DATA *room )
{
    SHIP_DATA * ship;
//    ROOM_INDEX_DATA  *sRoom;
        
    if ( room == NULL )
        return NULL;
    
    if ( room->area != NULL && room->area->planet != NULL )
          return room->area->planet->starsystem;

    for ( ship = first_ship; ship; ship = ship->next )

        //for ( sRoom->vnum = ship->firstroom ; sRoom ; sRoom = sRoom->next_in_ship )
			//if ( room == sRoom )
	{
		if(room->vnum == ship->hanger1 || room->vnum == ship->hanger2
			|| room->vnum == ship->hanger3 || room->vnum == ship->hanger4)
              return ship->starsystem;
	}
                                
    return NULL;
}



/*
 * Save a starsystem's data to its data file
 */
void save_starsystem( SPACE_DATA *starsystem )
{
    FILE *fp;
    char filename[256];
    char buf[MAX_STRING_LENGTH];

    if ( !starsystem )
    {
	bug( "save_starsystem: null starsystem pointer!", 0 );
	return;
    }
        
    if ( !starsystem->filename || starsystem->filename[0] == '\0' )
    {
	sprintf( buf, "save_starsystem: %s has no filename", starsystem->name );
	bug( buf, 0 );
	return;
    }
 
    sprintf( filename, "%s%s", SPACE_DIR, starsystem->filename );
    
    fclose( fpReserve );
    if ( ( fp = fopen( filename, "w" ) ) == NULL )
    {
    	bug( "save_starsystem: fopen", 0 );
    	perror( filename );
    }
    else
    {
	fprintf( fp, "#SPACE\n" );
	fprintf( fp, "Name         %s~\n",	starsystem->name	);
	fprintf( fp, "Filename     %s~\n",	starsystem->filename	);
	fprintf( fp, "Planet1      %s~\n",	starsystem->planet1	);
	fprintf( fp, "Planet2      %s~\n",	starsystem->planet2	);
	fprintf( fp, "Planet3      %s~\n",	starsystem->planet3	);
        fprintf( fp, "Planet4      %s~\n",	starsystem->planet4	);
        fprintf( fp, "Planet5      %s~\n",	starsystem->planet5	);
        fprintf( fp, "Planet6      %s~\n",	starsystem->planet6	);
        fprintf( fp, "Planet7      %s~\n",	starsystem->planet7	);
        fprintf( fp, "Planet8      %s~\n",	starsystem->planet8	);
        fprintf( fp, "Planet9      %s~\n",	starsystem->planet9	);
        fprintf( fp, "Planet10     %s~\n",	starsystem->planet10	);
        fprintf( fp, "Planet11     %s~\n",	starsystem->planet11	);
        fprintf( fp, "Planet12     %s~\n",	starsystem->planet12	);
        fprintf( fp, "Planet13     %s~\n",	starsystem->planet13	);
        fprintf( fp, "Planet14     %s~\n",	starsystem->planet14	);
        fprintf( fp, "Planet15     %s~\n",	starsystem->planet15    );
        fprintf( fp, "Planet16     %s~\n",	starsystem->planet16	);
        fprintf( fp, "Planet17     %s~\n",	starsystem->planet17	);
        fprintf( fp, "Planet18     %s~\n",	starsystem->planet18	);
        fprintf( fp, "Planet19     %s~\n",	starsystem->planet19	);
        fprintf( fp, "Planet20     %s~\n",	starsystem->planet20	);
        fprintf( fp, "Planet21     %s~\n",	starsystem->planet21	);
        fprintf( fp, "Planet22     %s~\n",	starsystem->planet22	);
        fprintf( fp, "Planet23     %s~\n",	starsystem->planet23	);
        fprintf( fp, "Planet24     %s~\n",	starsystem->planet24	);
        fprintf( fp, "Planet25     %s~\n",	starsystem->planet25	);
	fprintf( fp, "Star1        %s~\n",	starsystem->star1	);
	fprintf( fp, "Star2        %s~\n",	starsystem->star2	);
	fprintf( fp, "Location1a      %s~\n",	starsystem->location1a	);
	fprintf( fp, "Location1b      %s~\n",	starsystem->location1b	);
	fprintf( fp, "Location1c      %s~\n",	starsystem->location1c	);
	fprintf( fp, "Location2a       %s~\n",	starsystem->location2a	);
	fprintf( fp, "Location2b      %s~\n",	starsystem->location2b	);
	fprintf( fp, "Location2c      %s~\n",	starsystem->location2c	);
	fprintf( fp, "Location3a      %s~\n",	starsystem->location3a	);
	fprintf( fp, "Location3b      %s~\n",	starsystem->location3b	);
	fprintf( fp, "Location3c      %s~\n",	starsystem->location3c	);
	fprintf( fp, "Doc1a          %d\n",	starsystem->doc1a	);
	fprintf( fp, "Doc2a          %d\n",      starsystem->doc2a       );
	fprintf( fp, "Doc3a          %d\n",      starsystem->doc3a       );        	
	fprintf( fp, "Doc1b          %d\n", 	 starsystem->doc1b	);
	fprintf( fp, "Doc2b          %d\n",      starsystem->doc2b       );
	fprintf( fp, "Doc3b          %d\n",      starsystem->doc3b       );        	
	fprintf( fp, "Doc1c          %d\n",	 starsystem->doc1c	);
	fprintf( fp, "Doc2c          %d\n",      starsystem->doc2c       );
	fprintf( fp, "Doc3c          %d\n",      starsystem->doc3c       );        	
	fprintf( fp, "P1x          %d\n",       starsystem->p1x         );
	fprintf( fp, "P1y          %d\n",       starsystem->p1y         );
	fprintf( fp, "P1z          %d\n",       starsystem->p1z         );
	fprintf( fp, "P2x          %d\n",       starsystem->p2x         );
	fprintf( fp, "P2y          %d\n",       starsystem->p2y         );
	fprintf( fp, "P2z          %d\n",       starsystem->p2z         );
	fprintf( fp, "P3x          %d\n",       starsystem->p3x         );
	fprintf( fp, "P3y          %d\n",       starsystem->p3y         );
	fprintf( fp, "P3z          %d\n",       starsystem->p3z         );
	fprintf( fp, "P4x	   %d\n",	starsystem->p4x		);
	fprintf( fp, "P4y	   %d\n",	starsystem->p4y		);
	fprintf( fp, "P4z	   %d\n",	starsystem->p4z		);
	fprintf( fp, "P5x	   %d\n",	starsystem->p5x		);
	fprintf( fp, "P5y	   %d\n",	starsystem->p5y		);
	fprintf( fp, "P5z	   %d\n",	starsystem->p5z		);
	fprintf( fp, "P6x	   %d\n",	starsystem->p6x		);
	fprintf( fp, "P6y	   %d\n",	starsystem->p6y		);
	fprintf( fp, "P6z	   %d\n",	starsystem->p6z		);
	fprintf( fp, "P7x	   %d\n",	starsystem->p7x		);
	fprintf( fp, "P7y	   %d\n",	starsystem->p7y		);
	fprintf( fp, "P7z	   %d\n",	starsystem->p7z		);
	fprintf( fp, "P8x	   %d\n",	starsystem->p8x		);
	fprintf( fp, "P8y	   %d\n",	starsystem->p8y		);
	fprintf( fp, "P8z	   %d\n",	starsystem->p8z		);
	fprintf( fp, "P9x	   %d\n",	starsystem->p9x		);
	fprintf( fp, "P9y	   %d\n",	starsystem->p9y		);
	fprintf( fp, "P9z	   %d\n",	starsystem->p9z		);
	fprintf( fp, "P10x	   %d\n",	starsystem->p10x	);
	fprintf( fp, "P10y	   %d\n",	starsystem->p10y	);
	fprintf( fp, "P10z	   %d\n",	starsystem->p10z	);
	fprintf( fp, "P11x	   %d\n",	starsystem->p11x	);
	fprintf( fp, "P11y	   %d\n",	starsystem->p11y	);
	fprintf( fp, "P11z	   %d\n",	starsystem->p11z	);
	fprintf( fp, "P12x	   %d\n",	starsystem->p12x	);
	fprintf( fp, "P12y	   %d\n",	starsystem->p12y	);
	fprintf( fp, "P12z	   %d\n",	starsystem->p12z	);
	fprintf( fp, "P13x	   %d\n",	starsystem->p13x	);
	fprintf( fp, "P13y	   %d\n",	starsystem->p13y	);
	fprintf( fp, "P13z	   %d\n",	starsystem->p13z	);
	fprintf( fp, "P14x	   %d\n",	starsystem->p14x	);
	fprintf( fp, "P14y	   %d\n",	starsystem->p14y	);
	fprintf( fp, "P14z	   %d\n",	starsystem->p14z	);
	fprintf( fp, "P15x	   %d\n",	starsystem->p15x	);
	fprintf( fp, "P15y	   %d\n",	starsystem->p15y	);
	fprintf( fp, "P15z	   %d\n",	starsystem->p15z	);
	fprintf( fp, "P16x	   %d\n",	starsystem->p16x	);
	fprintf( fp, "P16y	   %d\n",	starsystem->p16y	);
	fprintf( fp, "P16z	   %d\n",	starsystem->p16z	);
	fprintf( fp, "P17x	   %d\n",	starsystem->p17x	);
	fprintf( fp, "P17y	   %d\n",	starsystem->p17y	);
	fprintf( fp, "P17z	   %d\n",	starsystem->p17z	);
	fprintf( fp, "P18x	   %d\n",	starsystem->p18x	);
	fprintf( fp, "P18y	   %d\n",	starsystem->p18y	);
	fprintf( fp, "P18z	   %d\n",	starsystem->p18z	);
	fprintf( fp, "P19x	   %d\n",	starsystem->p19x	);
	fprintf( fp, "P19y	   %d\n",	starsystem->p19y	);
	fprintf( fp, "P19z	   %d\n",	starsystem->p19z	);
	fprintf( fp, "P20x	   %d\n",	starsystem->p20x	);
	fprintf( fp, "P20y	   %d\n",	starsystem->p20y	);
	fprintf( fp, "P20z	   %d\n",	starsystem->p20z	);
	fprintf( fp, "P21x	   %d\n",	starsystem->p21x	);
	fprintf( fp, "P21y	   %d\n",	starsystem->p21y	);
	fprintf( fp, "P21z	   %d\n",	starsystem->p21z	);
	fprintf( fp, "P22x	   %d\n",	starsystem->p22x	);
	fprintf( fp, "P22y	   %d\n",	starsystem->p22y	);
	fprintf( fp, "P22z	   %d\n",	starsystem->p22z	);
	fprintf( fp, "P23x	   %d\n",	starsystem->p23x	);
	fprintf( fp, "P23y	   %d\n",	starsystem->p23y	);
	fprintf( fp, "P23z	   %d\n",	starsystem->p23z	);
	fprintf( fp, "P24x	   %d\n",	starsystem->p24x	);
	fprintf( fp, "P24y	   %d\n",	starsystem->p24y	);
	fprintf( fp, "P24z	   %d\n",	starsystem->p24z	);
	fprintf( fp, "P25x	   %d\n",	starsystem->p25x	);
	fprintf( fp, "P25y	   %d\n",	starsystem->p25y	);
	fprintf( fp, "P252z	   %d\n",	starsystem->p25z	);
	fprintf( fp, "S1x          %d\n",       starsystem->s1x         );
	fprintf( fp, "S1y          %d\n",       starsystem->s1y         );
	fprintf( fp, "S1z          %d\n",       starsystem->s1z         );
	fprintf( fp, "S2x          %d\n",       starsystem->s2x         );
	fprintf( fp, "S2y          %d\n",       starsystem->s2y         );
	fprintf( fp, "S2z          %d\n",       starsystem->s2z         );
	fprintf( fp, "Gravitys1     %d\n",       starsystem->gravitys1    );
	fprintf( fp, "Gravitys2     %d\n",       starsystem->gravitys2    );
	fprintf( fp, "Gravityp1     %d\n",       starsystem->gravityp1    );
	fprintf( fp, "Gravityp2     %d\n",       starsystem->gravityp2    );
	fprintf( fp, "Gravityp3     %d\n",       starsystem->gravityp3    );
	fprintf( fp, "Gravityp4     %d\n",	 starsystem->gravityp4	  );
	fprintf( fp, "Gravityp5     %d\n",	 starsystem->gravityp5	  );
	fprintf( fp, "Gravityp6     %d\n",	 starsystem->gravityp6	  );
	fprintf( fp, "Gravityp7     %d\n",	 starsystem->gravityp7	  );
	fprintf( fp, "Gravityp8     %d\n",	 starsystem->gravityp8	  );
	fprintf( fp, "Gravityp9     %d\n",	 starsystem->gravityp9	  );
	fprintf( fp, "Gravityp10    %d\n",	 starsystem->gravityp10	  );
	fprintf( fp, "Gravityp11    %d\n",	 starsystem->gravityp11	  );
	fprintf( fp, "Gravityp12    %d\n",	 starsystem->gravityp12	  );
	fprintf( fp, "Gravityp13    %d\n",	 starsystem->gravityp13	  );
	fprintf( fp, "Gravityp14    %d\n",	 starsystem->gravityp14	  );
	fprintf( fp, "Gravityp15    %d\n",	 starsystem->gravityp15	  );
	fprintf( fp, "Gravityp16    %d\n",	 starsystem->gravityp16	  );
	fprintf( fp, "Gravityp17    %d\n",	 starsystem->gravityp17	  );
	fprintf( fp, "Gravityp18    %d\n",	 starsystem->gravityp18	  );
	fprintf( fp, "Gravityp19    %d\n",	 starsystem->gravityp19   );
	fprintf( fp, "Gravityp20    %d\n",	 starsystem->gravityp20	  );
	fprintf( fp, "Gravityp21    %d\n",	 starsystem->gravityp21	  );
	fprintf( fp, "Gravityp22    %d\n",	 starsystem->gravityp22	  );
	fprintf( fp, "Gravityp23    %d\n",	 starsystem->gravityp23	  );
	fprintf( fp, "Gravityp24    %d\n",	 starsystem->gravityp24	  );
	fprintf( fp, "Gravityp25    %d\n",	 starsystem->gravityp25	  );
	fprintf( fp, "Xpos          %d\n",       starsystem->xpos    );
	fprintf( fp, "Ypos          %d\n",       starsystem->ypos    );	
	fprintf( fp, "End\n\n"						);
	fprintf( fp, "#END\n"						);
    }
    fclose( fp );
    fpReserve = fopen( NULL_FILE, "r" );
    return;
}


/*
 * Read in actual starsystem data.
 */

#if defined(KEY)
#undef KEY
#endif

#define KEY( literal, field, value )					\
				if ( !str_cmp( word, literal ) )	\
				{					\
				    field  = value;			\
				    fMatch = TRUE;			\
				    break;				\
				}

void fread_starsystem( SPACE_DATA *starsystem, FILE *fp )
{
    char buf[MAX_STRING_LENGTH];
    char *word;
    bool fMatch;

 
    for ( ; ; )
    {
	word   = feof( fp ) ? "End" : fread_word( fp );
	fMatch = FALSE;

	switch ( UPPER(word[0]) )
	{
	case '*':
	    fMatch = TRUE;
	    fread_to_eol( fp );
	    break;

        case 'D':
             KEY( "Doc1a",  starsystem->doc1a,          fread_number( fp ) );
             KEY( "Doc2a",  starsystem->doc2a,          fread_number( fp ) );
             KEY( "Doc3a",  starsystem->doc3a,          fread_number( fp ) ); 
             KEY( "Doc1b",  starsystem->doc1b,          fread_number( fp ) );
             KEY( "Doc2b",  starsystem->doc2b,          fread_number( fp ) );
             KEY( "Doc3b",  starsystem->doc3b,          fread_number( fp ) ); 
             KEY( "Doc1c",  starsystem->doc1c,          fread_number( fp ) );
             KEY( "Doc2c",  starsystem->doc2c,          fread_number( fp ) );
             KEY( "Doc3c",  starsystem->doc3c,          fread_number( fp ) ); 
             break;
                                

	case 'E':
	    if ( !str_cmp( word, "End" ) )
	    {
		if (!starsystem->name)
		  starsystem->name		= STRALLOC( "" );
		if (!starsystem->location1a)
		  starsystem->location1a            = STRALLOC( "" );  
		if (!starsystem->location2a)
		  starsystem->location2a            = STRALLOC( "" );
		if (!starsystem->location3a)
		  starsystem->location3a            = STRALLOC( "" );
		if (!starsystem->location1b)
		  starsystem->location1b            = STRALLOC( "" );  
		if (!starsystem->location2b)
		  starsystem->location2b            = STRALLOC( "" );
		if (!starsystem->location3b)
		  starsystem->location3b            = STRALLOC( "" );
		if (!starsystem->location1c)
		  starsystem->location1c            = STRALLOC( "" );  
		if (!starsystem->location2c)
		  starsystem->location2c            = STRALLOC( "" );
		if (!starsystem->location3c)
		  starsystem->location3c            = STRALLOC( "" );
		if (!starsystem->planet1)
		  starsystem->planet1            = STRALLOC( "" );  
		if (!starsystem->planet2)
		  starsystem->planet2            = STRALLOC( "" );
		if (!starsystem->planet3)
		  starsystem->planet3            = STRALLOC( "" );
		if (!starsystem->planet4)
		  starsystem->planet4            = STRALLOC( "" );
		if (!starsystem->planet5)
		  starsystem->planet5            = STRALLOC( "" );
		if (!starsystem->planet6)
		  starsystem->planet6            = STRALLOC( "" );
		if (!starsystem->planet7)
		  starsystem->planet7            = STRALLOC( "" );
		if (!starsystem->planet8)
		  starsystem->planet8            = STRALLOC( "" );
		if (!starsystem->planet9)
		  starsystem->planet9            = STRALLOC( "" );
		if (!starsystem->planet10)
		  starsystem->planet10           = STRALLOC( "" );
		if (!starsystem->planet11)
		  starsystem->planet11           = STRALLOC( "" );
		if (!starsystem->planet12)
		  starsystem->planet12           = STRALLOC( "" );
		if (!starsystem->planet13)
		  starsystem->planet13           = STRALLOC( "" );
		if (!starsystem->planet14)
		  starsystem->planet14           = STRALLOC( "" );
		if (!starsystem->planet15)
		  starsystem->planet15           = STRALLOC( "" );
		if (!starsystem->planet16)
		  starsystem->planet16           = STRALLOC( "" );
		if (!starsystem->planet17)
		  starsystem->planet17           = STRALLOC( "" );
		if (!starsystem->planet18)
		  starsystem->planet18           = STRALLOC( "" );
		if (!starsystem->planet19)
		  starsystem->planet19           = STRALLOC( "" );
		if (!starsystem->planet20)
		  starsystem->planet20           = STRALLOC( "" );
		if (!starsystem->planet21)
		  starsystem->planet21           = STRALLOC( "" );
		if (!starsystem->planet22)
		  starsystem->planet22           = STRALLOC( "" );
		if (!starsystem->planet23)
		  starsystem->planet23           = STRALLOC( "" );
		if (!starsystem->planet24)
		  starsystem->planet24           = STRALLOC( "" );
		if (!starsystem->planet25)
		  starsystem->planet25           = STRALLOC( "" );
		if (!starsystem->star1)
		  starsystem->star1            = STRALLOC( "" );  
		if (!starsystem->star2)
		  starsystem->star2            = STRALLOC( "" );
		return;
	    }
	    break;
	    
	case 'F':
	    KEY( "Filename",	starsystem->filename,		fread_string_nohash( fp ) );
	    break;
        
        case 'G':
            KEY( "Gravitys1",  starsystem->gravitys1,     fread_number( fp ) ); 
            KEY( "Gravitys2",  starsystem->gravitys2,     fread_number( fp ) ); 
            KEY( "Gravityp1",  starsystem->gravityp1,     fread_number( fp ) ); 
            KEY( "Gravityp2",  starsystem->gravityp2,     fread_number( fp ) ); 
            KEY( "Gravityp3",  starsystem->gravityp3,     fread_number( fp ) );
            KEY( "Gravityp4",  starsystem->gravityp4,     fread_number( fp ) );
            KEY( "Gravityp5",  starsystem->gravityp5,     fread_number( fp ) );
            KEY( "Gravityp6",  starsystem->gravityp6,     fread_number( fp ) );
            KEY( "Gravityp7",  starsystem->gravityp7,     fread_number( fp ) );
            KEY( "Gravityp8",  starsystem->gravityp8,     fread_number( fp ) );
            KEY( "Gravityp9",  starsystem->gravityp9,     fread_number( fp ) );
            KEY( "Gravityp10",  starsystem->gravityp10,     fread_number( fp ) );
            KEY( "Gravityp11",  starsystem->gravityp11,     fread_number( fp ) );
            KEY( "Gravityp12",  starsystem->gravityp12,     fread_number( fp ) );
            KEY( "Gravityp13",  starsystem->gravityp13,     fread_number( fp ) );
            KEY( "Gravityp14",  starsystem->gravityp14,     fread_number( fp ) );
            KEY( "Gravityp15",  starsystem->gravityp15,     fread_number( fp ) );
            KEY( "Gravityp16",  starsystem->gravityp16,     fread_number( fp ) );
            KEY( "Gravityp17",  starsystem->gravityp17,     fread_number( fp ) );
            KEY( "Gravityp18",  starsystem->gravityp18,     fread_number( fp ) );
            KEY( "Gravityp19",  starsystem->gravityp19,     fread_number( fp ) );
            KEY( "Gravityp20",  starsystem->gravityp20,     fread_number( fp ) );
            KEY( "Gravityp21",  starsystem->gravityp21,     fread_number( fp ) );
            KEY( "Gravityp22",  starsystem->gravityp22,     fread_number( fp ) );
            KEY( "Gravityp23",  starsystem->gravityp23,     fread_number( fp ) );
            KEY( "Gravityp24",  starsystem->gravityp24,     fread_number( fp ) );
            KEY( "Gravityp25",  starsystem->gravityp25,     fread_number( fp ) );
            break;  
        
        case 'L':
	    KEY( "Location1a",	starsystem->location1a,	fread_string( fp ) );
	    KEY( "Location2a",	starsystem->location2a,	fread_string( fp ) );
	    KEY( "Location3a",	starsystem->location3a,	fread_string( fp ) );
	    KEY( "Location1b",	starsystem->location1b,	fread_string( fp ) );
	    KEY( "Location2b",	starsystem->location2b,	fread_string( fp ) );
	    KEY( "Location3b",	starsystem->location3b,	fread_string( fp ) );
	    KEY( "Location1c",	starsystem->location1c,	fread_string( fp ) );
	    KEY( "Location2c",	starsystem->location2c,	fread_string( fp ) );
	    KEY( "Location3c",	starsystem->location3c,	fread_string( fp ) );
	    break;
  
	case 'N':
	    KEY( "Name",	starsystem->name,		fread_string( fp ) );
	    break;
        
        case 'P':
             KEY( "Planet1",	starsystem->planet1,	fread_string( fp ) );
	     KEY( "Planet2",	starsystem->planet2,	fread_string( fp ) );
	     KEY( "Planet3",	starsystem->planet3,	fread_string( fp ) );
	     KEY( "P1x",  starsystem->p1x,          fread_number( fp ) ); 
             KEY( "P1y",  starsystem->p1y,          fread_number( fp ) ); 
             KEY( "P1z",  starsystem->p1z,          fread_number( fp ) ); 
             KEY( "P2x",  starsystem->p2x,          fread_number( fp ) ); 
             KEY( "P2y",  starsystem->p2y,          fread_number( fp ) );
             KEY( "P2z",  starsystem->p2z,          fread_number( fp ) );
             KEY( "P3x",  starsystem->p3x,          fread_number( fp ) );
             KEY( "P3y",  starsystem->p3y,          fread_number( fp ) );
             KEY( "P3z",  starsystem->p3z,          fread_number( fp ) );
             KEY( "P4x",  starsystem->p4x,          fread_number( fp ) );
             KEY( "P4y",  starsystem->p4y,          fread_number( fp ) );
             KEY( "P4z",  starsystem->p4z,          fread_number( fp ) );
             KEY( "P5x",  starsystem->p5x,          fread_number( fp ) );
             KEY( "P5y",  starsystem->p5y,          fread_number( fp ) );
             KEY( "P5z",  starsystem->p5z,          fread_number( fp ) );
             KEY( "P6x",  starsystem->p6x,          fread_number( fp ) );
             KEY( "P6y",  starsystem->p6y,          fread_number( fp ) );
             KEY( "P6z",  starsystem->p6z,          fread_number( fp ) );
             KEY( "P7x",  starsystem->p7x,          fread_number( fp ) );
             KEY( "P7y",  starsystem->p7y,          fread_number( fp ) );
             KEY( "P7z",  starsystem->p7z,          fread_number( fp ) );
             KEY( "P8x",  starsystem->p8x,          fread_number( fp ) );
             KEY( "P8y",  starsystem->p8y,          fread_number( fp ) );
             KEY( "P8z",  starsystem->p8z,          fread_number( fp ) );
             KEY( "P9x",  starsystem->p9x,          fread_number( fp ) );
             KEY( "P9y",  starsystem->p9y,          fread_number( fp ) );
             KEY( "P9z",  starsystem->p9z,          fread_number( fp ) );
             KEY( "P10x",  starsystem->p10x,        fread_number( fp ) );
             KEY( "P10y",  starsystem->p10y,        fread_number( fp ) );
             KEY( "P10z",  starsystem->p10z,        fread_number( fp ) );
             KEY( "P11x",  starsystem->p11x,        fread_number( fp ) );
             KEY( "P11y",  starsystem->p11y,        fread_number( fp ) );
             KEY( "P11z",  starsystem->p11z,        fread_number( fp ) );
             KEY( "P12x",  starsystem->p12x,        fread_number( fp ) );
             KEY( "P12y",  starsystem->p12y,        fread_number( fp ) );
             KEY( "P12z",  starsystem->p12z,        fread_number( fp ) );
             KEY( "P13x",  starsystem->p13x,        fread_number( fp ) );
             KEY( "P13y",  starsystem->p13y,        fread_number( fp ) );
             KEY( "P13z",  starsystem->p13z,        fread_number( fp ) );
             KEY( "P14x",  starsystem->p14x,        fread_number( fp ) );
             KEY( "P14y",  starsystem->p14y,        fread_number( fp ) );
             KEY( "P14z",  starsystem->p14z,        fread_number( fp ) );
             KEY( "P15x",  starsystem->p15x,        fread_number( fp ) );
             KEY( "P15y",  starsystem->p15y,        fread_number( fp ) );
             KEY( "P15z",  starsystem->p15z,        fread_number( fp ) );
             KEY( "P16x",  starsystem->p16x,        fread_number( fp ) );
             KEY( "P16y",  starsystem->p16y,        fread_number( fp ) );
             KEY( "P16z",  starsystem->p16z,        fread_number( fp ) );
             KEY( "P17x",  starsystem->p17x,        fread_number( fp ) );
             KEY( "P17y",  starsystem->p17y,        fread_number( fp ) );
             KEY( "P17z",  starsystem->p17z,        fread_number( fp ) );
             KEY( "P18x",  starsystem->p18x,        fread_number( fp ) );
             KEY( "P18y",  starsystem->p18y,        fread_number( fp ) );
             KEY( "P18z",  starsystem->p18z,        fread_number( fp ) );
             KEY( "P19x",  starsystem->p19x,        fread_number( fp ) );
             KEY( "P19y",  starsystem->p19y,        fread_number( fp ) );
             KEY( "P19z",  starsystem->p19z,        fread_number( fp ) );
             KEY( "P20x",  starsystem->p20x,        fread_number( fp ) );
             KEY( "P20y",  starsystem->p20y,        fread_number( fp ) );
             KEY( "P20z",  starsystem->p20z,        fread_number( fp ) );
             KEY( "P21x",  starsystem->p21x,        fread_number( fp ) );
             KEY( "P21y",  starsystem->p21y,        fread_number( fp ) );
             KEY( "P21z",  starsystem->p21z,        fread_number( fp ) );
             KEY( "P22x",  starsystem->p22x,        fread_number( fp ) );
             KEY( "P22y",  starsystem->p22y,        fread_number( fp ) );
             KEY( "P22z",  starsystem->p22z,        fread_number( fp ) );
             KEY( "P23x",  starsystem->p23x,        fread_number( fp ) );
             KEY( "P23y",  starsystem->p23y,        fread_number( fp ) );
             KEY( "P23z",  starsystem->p23z,        fread_number( fp ) );
             KEY( "P24x",  starsystem->p24x,        fread_number( fp ) );
             KEY( "P24y",  starsystem->p24y,        fread_number( fp ) );
             KEY( "P24z",  starsystem->p24z,        fread_number( fp ) );
             KEY( "P25x",  starsystem->p25x,        fread_number( fp ) );
             KEY( "P25y",  starsystem->p25y,        fread_number( fp ) );
             KEY( "P25z",  starsystem->p25z,        fread_number( fp ) );
             break;
       	
       	case 'S':
       	     KEY( "Star1",	starsystem->star1,	fread_string( fp ) );
	     KEY( "Star2",	starsystem->star2,	fread_string( fp ) );
	     KEY( "S1x",  starsystem->s1x,          fread_number( fp ) ); 
             KEY( "S1y",  starsystem->s1y,          fread_number( fp ) ); 
             KEY( "S1z",  starsystem->s1z,          fread_number( fp ) ); 
             KEY( "S2x",  starsystem->s2x,          fread_number( fp ) ); 
             KEY( "S2y",  starsystem->s2y,          fread_number( fp ) );
             KEY( "S2z",  starsystem->s2z,          fread_number( fp ) );
            
        case 'X':
            KEY( "Xpos",  starsystem->xpos,     fread_number( fp ) ); 
        
        case 'Y':
            KEY( "Ypos",  starsystem->ypos,     fread_number( fp ) ); 
                 
       	}
	
	if ( !fMatch )
	{
	    sprintf( buf, "Fread_starsystem: no match: %s", word );
	    bug( buf, 0 );
	}
    }
}

/*
 * Load a starsystem file
 */

bool load_starsystem( char *starsystemfile )
{
    char filename[256];
    SPACE_DATA *starsystem;
    FILE *fp;
    bool found;

    CREATE( starsystem, SPACE_DATA, 1 );

    found = FALSE;
    sprintf( filename, "%s%s", SPACE_DIR, starsystemfile );

    if ( ( fp = fopen( filename, "r" ) ) != NULL )
    {

	found = TRUE;
        LINK( starsystem, first_starsystem, last_starsystem, next, prev );
	for ( ; ; )
	{
	    char letter;
	    char *word;

	    letter = fread_letter( fp );
	    if ( letter == '*' )
	    {
		fread_to_eol( fp );
		continue;
	    }

	    if ( letter != '#' )
	    {
		bug( "Load_starsystem_file: # not found.", 0 );
		break;
	    }

	    word = fread_word( fp );
	    if ( !str_cmp( word, "SPACE"	) )
	    {
	    	fread_starsystem( starsystem, fp );
	    	break;
	    }
	    else
	    if ( !str_cmp( word, "END"	) )
	        break;
	    else
	    {
		char buf[MAX_STRING_LENGTH];

		sprintf( buf, "Load_starsystem_file: bad section: %s.", word );
		bug( buf, 0 );
		break;
	    }
	}
	fclose( fp );
    }

    if ( !(found) )
      DISPOSE( starsystem );

    return found;
}

/*
 * Load in all the starsystem files.
 */
void load_space( )
{
    FILE *fpList;
    char *filename;
    char starsystemlist[256];
    char buf[MAX_STRING_LENGTH];
    
    
    first_starsystem	= NULL;
    last_starsystem	= NULL;

    log_string( "Loading space..." );

    sprintf( starsystemlist, "%s%s", SPACE_DIR, SPACE_LIST );
    fclose( fpReserve );
    if ( ( fpList = fopen( starsystemlist, "r" ) ) == NULL )
    {
	perror( starsystemlist );
	exit( 1 );
    }

    for ( ; ; )
    {
	filename = feof( fpList ) ? "$" : fread_word( fpList );
	if ( filename[0] == '$' )
	  break;
	  
       
	if ( !load_starsystem( filename ) )
	{
	  sprintf( buf, "Cannot load starsystem file: %s", filename );
	  bug( buf, 0 );
	}
    }
    fclose( fpList );
    log_string(" Done starsystems " );
    fpReserve = fopen( NULL_FILE, "r" );
    return;
}

void do_setstarsystem( CHAR_DATA *ch, char *argument )
{
    char arg1[MAX_INPUT_LENGTH];
    char arg2[MAX_INPUT_LENGTH];
    SPACE_DATA *starsystem;

    if ( IS_NPC( ch ) )
    {
	send_to_char( "Huh?\n\r", ch );
	return;
    }

    argument = one_argument( argument, arg1 );
    argument = one_argument( argument, arg2 );

    if ( arg2[0] == '\0' || arg1[0] == '\0' )
    {
	send_to_char( "Usage: setstarsystem <starsystem> <field> <values>\n\r", ch );
	send_to_char( "\n\rField being one of:\n\r", ch );
	send_to_char( "name filename xpos ypos,\n\r", ch );
	send_to_char( "star1 s1x s1y s1z gravitys1\n\r", ch );
	send_to_char( "star2 s2x s2y s2z gravitys2\n\r", ch );
	send_to_char( "planet1 p1x p1y p1z gravityp1\n\r", ch );
	send_to_char( "planet2 p2x p2y p2z gravityp2\n\r", ch );
	send_to_char( "planet3 p3x p3y p3z gravityp3\n\r", ch );
	send_to_char( "location1a location1b location1c doc1a doc1b doc1c\n\r", ch );
	send_to_char( "location2a location2b location2c doc2a doc2b doc2c\n\r", ch );
	send_to_char( "location3a location3b location3c doc3a doc3b doc3c\n\r", ch );
	send_to_char( "", ch );
	return;
    }

    starsystem = starsystem_from_name( arg1 );
    if ( !starsystem )
    {
	send_to_char( "No such starsystem.\n\r", ch );
	return;
    }


    if ( !str_cmp( arg2, "doc1a" ) )
    {
	starsystem->doc1a = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "doc1b" ) )
    {
	starsystem->doc1b = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "doc1c" ) )
    {
	starsystem->doc1c = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }

    if ( !str_cmp( arg2, "doc2a" ) )
    {
	starsystem->doc2a = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "doc2b" ) )
    {
	starsystem->doc2b = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "doc2c" ) )
    {
	starsystem->doc2c = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }

    if ( !str_cmp( arg2, "doc3a" ) )
    {
	starsystem->doc3a = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "doc3b" ) )
    {
	starsystem->doc3b = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "doc3c" ) )
    {
	starsystem->doc3c = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    
    if ( !str_cmp( arg2, "s1x" ) )
    {
	starsystem->s1x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "s1y" ) )
    {
	starsystem->s1y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "s1z" ) )
    {
	starsystem->s1z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }

    if ( !str_cmp( arg2, "s2x" ) )
    {
	starsystem->s2x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "s2y" ) )
    {
	starsystem->s2y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "s2z" ) )
    {
	starsystem->s2z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }

    if ( !str_cmp( arg2, "p1x" ) )
    {
	starsystem->p1x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p1y" ) )
    {
	starsystem->p1y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p1z" ) )
    {
	starsystem->p1z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }

    if ( !str_cmp( arg2, "p2x" ) )
    {
	starsystem->p2x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p2y" ) )
    {
	starsystem->p2y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p2z" ) )
    {
	starsystem->p2z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p3x" ) )
    {
	starsystem->p3x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p3y" ) )
    {
	starsystem->p3y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p3z" ) )
    {
	starsystem->p3z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p4x" ) )
    {
	starsystem->p4x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p4y" ) )
    {
	starsystem->p4y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p4z" ) )
    {
	starsystem->p4z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p5x" ) )
    {
	starsystem->p5x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p5y" ) )
    {
	starsystem->p5y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p5z" ) )
    {
	starsystem->p5z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p6x" ) )
    {
	starsystem->p6x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p6y" ) )
    {
	starsystem->p6y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p6z" ) )
    {
	starsystem->p6z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p7x" ) )
    {
	starsystem->p7x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p7y" ) )
    {
	starsystem->p7y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p7z" ) )
    {
	starsystem->p7z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p8x" ) )
    {
	starsystem->p8x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p8y" ) )
    {
	starsystem->p8y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p8z" ) )
    {
	starsystem->p8z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p9x" ) )
    {
	starsystem->p9x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p9y" ) )
    {
	starsystem->p9y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p9z" ) )
    {
	starsystem->p9z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p10x" ) )
    {
	starsystem->p10x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p10y" ) )
    {
	starsystem->p10y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p10z" ) )
    {
	starsystem->p10z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p11x" ) )
    {
	starsystem->p11x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p11y" ) )
    {
	starsystem->p11y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p11z" ) )
    {
	starsystem->p11z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p12x" ) )
    {
	starsystem->p12x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p12y" ) )
    {
	starsystem->p12y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p12z" ) )
    {
	starsystem->p12z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p13x" ) )
    {
	starsystem->p13x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p13y" ) )
    {
	starsystem->p13y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p13z" ) )
    {
	starsystem->p13z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p14x" ) )
    {
	starsystem->p14x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p14y" ) )
    {
	starsystem->p14y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p14z" ) )
    {
	starsystem->p14z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p15x" ) )
    {
	starsystem->p15x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p15y" ) )
    {
	starsystem->p15y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p15z" ) )
    {
	starsystem->p15z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p16x" ) )
    {
	starsystem->p16x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p16y" ) )
    {
	starsystem->p16y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p16z" ) )
    {
	starsystem->p16z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p17x" ) )
    {
	starsystem->p17x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p17y" ) )
    {
	starsystem->p17y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p17z" ) )
    {
	starsystem->p17z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p18x" ) )
    {
	starsystem->p18x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p18y" ) )
    {
	starsystem->p18y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p18z" ) )
    {
	starsystem->p18z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p19x" ) )
    {
	starsystem->p19x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p19y" ) )
    {
	starsystem->p19y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p19z" ) )
    {
	starsystem->p19z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p20x" ) )
    {
	starsystem->p20x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p20y" ) )
    {
	starsystem->p20y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p20z" ) )
    {
	starsystem->p20z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p21x" ) )
    {
	starsystem->p21x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p21y" ) )
    {
	starsystem->p21y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p21z" ) )
    {
	starsystem->p21z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p22x" ) )
    {
	starsystem->p22x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p22y" ) )
    {
	starsystem->p22y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p22z" ) )
    {
	starsystem->p22z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p23x" ) )
    {
	starsystem->p23x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p23y" ) )
    {
	starsystem->p23y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p23z" ) )
    {
	starsystem->p23z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p24x" ) )
    {
	starsystem->p24x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p24y" ) )
    {
	starsystem->p24y = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
    if ( !str_cmp( arg2, "p24z" ) )
    {
	starsystem->p24z = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }    if ( !str_cmp( arg2, "p25x" ) )
    {
	starsystem->p25x = atoi( argument );
	send_to_char( "Done.\n\r", ch );
	save_starsystem( starsystem );
	return;
    }
 

Showing the first 100 KB of 486.2 KB. Download the archive for the full file.

Site Stats

Snippets: 1791
Codebases: 571