space.c
src/space.c · 269.9 KB
From the archive swrsql0.1alpha.tgz
Download the archive « Back to the archive contents
/***************************************************************************
* STAR WARS REALITY 1.0 *
*--------------------------------------------------------------------------*
* Star Wars Reality Code Additions and changes from the Smaug Code *
* copyright (c) 1997 by Sean Cooper *
* -------------------------------------------------------------------------*
* Starwars and Starwars Names copyright(c) Lucas Film Ltd. *
*--------------------------------------------------------------------------*
* SMAUG 1.0 (C) 1994, 1995, 1996 by Derek Snider *
* SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus, *
* Scryn, Rennard, Swordbearer, Gorog, Grishnakh and Tricops *
* ------------------------------------------------------------------------ *
* Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* ------------------------------------------------------------------------ *
* All SWR:SQL additions/modifications added by Rojan *
* ------------------------------------------------------------------------ *
* Space Module *
****************************************************************************/
#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;
int bus_pos = 0;
int bus_planet = 0;
int bus2_planet = 4;
int turbocar_stop = 0;
int corus_shuttle = 0;
#define MAX_STATION 10
#define MAX_BUS_STOP 10
#define STOP_PLANET 202
#define STOP_SHIPYARD 32015
#define SENATEPAD 10196
#define OUTERPAD 10195
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] = {
201, 21100, 29001, 28038, 31872, 1001, 28613, 3060, 28247, 32297
};
char *const bus_stop[MAX_BUS_STOP + 1] = {
"Coruscant",
"Mon Calamari", "Adari", "Gamorr", "Tatooine", "Honoghr", /* "Ryloth", */
"Kashyyyk", "Endor", "Byss", "Cloning Facilities", "Coruscant" /* last should always be same as first */
};
/* 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 ) );
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 * pexit, 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 );
/* 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_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 save_starsystem( SPACE_DATA *starsystem, int flags )
{
char updatequery[MAX_STRING_LENGTH*2];
char selectquery[MAX_STRING_LENGTH*2];
MYSQL_RES *qresult;
sprintf(selectquery, "SELECT * FROM starsystems where id='%d'", starsystem->id);
qresult = query_db(selectquery);
if (!sql_data_returned(qresult))
sprintf(updatequery, "INSERT INTO starsystems SET");
else
sprintf(updatequery, "UPDATE starsystems SET");
if (IS_SET(flags, STARSYSDATA_NAME) || IS_SET(flags, STARSYSDATA_ALL))
{
sprintf(updatequery, "%s name='%s',", updatequery, starsystem->name);
}
if (IS_SET(flags, STARSYSDATA_XPOS) || IS_SET(flags, STARSYSDATA_ALL))
{
sprintf(updatequery, "%s x='%d',", updatequery, starsystem->xpos);
}
if (IS_SET(flags, STARSYSDATA_YPOS) || IS_SET(flags, STARSYSDATA_ALL))
{
sprintf(updatequery, "%s y='%d',", updatequery, starsystem->ypos);
}
if (IS_SET(flags, STARSYSDATA_FLAGS) || IS_SET(flags, STARSYSDATA_ALL))
{
sprintf(updatequery, "%s flags='%d',", updatequery, starsystem->flags);
}
updatequery[strlen(updatequery) - 1] = '\0';
if (sql_data_returned(qresult))
sprintf(updatequery, "%s where id='%d'", updatequery, starsystem->id);
query_db(updatequery);
log_string(updatequery);
return;
}
void update_traffic( )
{
SHIP_DATA *shuttle, *senate;
SHIP_DATA *turbocar;
char buf[MAX_STRING_LENGTH];
shuttle = ship_from_cockpit( ROOM_CORUSCANT_SHUTTLE );
senate = ship_from_cockpit( ROOM_SENATE_SHUTTLE );
if( senate != NULL && shuttle != NULL )
{
switch ( corus_shuttle )
{
default:
corus_shuttle++;
break;
case 0:
land_bus( shuttle, STOP_PLANET );
land_bus( senate, SENATEPAD );
corus_shuttle++;
echo_to_ship( AT_CYAN, shuttle, "Welcome to Menari Spaceport." );
echo_to_ship( AT_CYAN, senate, "Welcome to The Senate Halls." );
break;
case 4:
launch_bus( shuttle );
launch_bus( senate );
corus_shuttle++;
break;
case 5:
land_bus( shuttle, STOP_SHIPYARD );
land_bus( senate, OUTERPAD );
echo_to_ship( AT_CYAN, shuttle, "Welcome to Coruscant Shipyard." );
echo_to_ship( AT_CYAN, senate, "Welcome to The Outer System Landing Area." );
corus_shuttle++;
break;
case 9:
launch_bus( shuttle );
launch_bus( senate );
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 *target;
int destination;
char buf[MAX_STRING_LENGTH];
ship = ship_from_cockpit( ROOM_SHUTTLE_BUS );
ship2 = ship_from_cockpit( ROOM_SHUTTLE_BUS_2 );
if( ship == NULL && ship2 == 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;
}
bus_pos++;
break;
case 6:
launch_bus( ship );
launch_bus( ship2 );
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." );
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.." );
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.'" );
}
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 );
bus_pos++;
break;
default:
bus_pos++;
break;
}
if( bus_pos >= 10 )
{
bus_pos = 0;
bus_planet++;
bus2_planet++;
}
if( bus_planet >= MAX_BUS_STOP )
bus_planet = 0;
if( bus2_planet >= MAX_BUS_STOP )
bus2_planet = 0;
}
int get_pprox( SHIP_DATA *ship, PLANET_DATA *planet )
{
int x, y, z;
x = abs(ship->vx - planet->xpos);
y = abs(ship->vy - planet->ypos);
z = abs(ship->vz - planet->zpos);
return sqrt((sqrt(pow(x,2) + pow(y,2))) + pow(z,2));
}
int get_sprox( SHIP_DATA *ship1, SHIP_DATA *ship2 )
{
int x, y, z;
x = abs(ship1->vx - ship2->vx);
y = abs(ship1->vy - ship2->vy);
z = abs(ship1->vz - ship2->vz);
return sqrt((sqrt(pow(x,2) + pow(y,2))) + pow(z,2));
}
void move_ships( )
{
SHIP_DATA *ship;
MISSILE_DATA *missile;
MISSILE_DATA *m_next;
SHIP_DATA *target;
PLANET_DATA *planet;
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->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 )
{
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 thee 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;
}
else
{
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->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_PLATFORM && !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;
}
}
*/
for ( planet = first_planet; planet; planet = planet->next )
{
if ( ship->starsystem != planet->starsystem )
continue;
if ( planet->type == PLANETTYPE_STAR )
{
if ( get_pprox( ship, planet ) <= 10 )
{
echo_to_cockpit( AT_BLOOD + AT_BLINK, ship, "You fly directly into the sun." );
sprintf( buf, "%s flys directly into %s!", ship->name, planet->name );
echo_to_system( AT_ORANGE, ship, buf, NULL );
destroy_ship( ship, NULL );
continue;
}
}
if( ship->currspeed > 0 )
{
if ( get_pprox( ship, planet ) <= 10 )
{
sprintf( buf, "You begin orbitting %s.", planet->name );
echo_to_cockpit( AT_YELLOW, ship, buf );
sprintf( buf, "%s begins orbiting %s.", ship->name, planet->name );
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];
for( ship = first_ship; ship; ship = ship->next )
{
if( ship->statet0 > 0 )
{
ship->energy -= ship->statet0;
ship->statet0 = 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->missilestate == MISSILE_RELOAD_2 )
{
ship->missilestate = MISSILE_READY;
if( ship->missiles > 0 )
echo_to_room( AT_YELLOW, get_room_index( ship->gunseat ), "Missile launcher reloaded." );
}
if( ship->missilestate == MISSILE_RELOAD )
{
ship->missilestate = MISSILE_RELOAD_2;
}
if( ship->missilestate == MISSILE_FIRED )
ship->missilestate = MISSILE_RELOAD;
if( autofly( ship ) )
{
if( ship->starsystem )
{
if( ship->target0 && ship->statet0 != LASER_DAMAGED )
{
int schance = 50;
SHIP_DATA *target = ship->target0;
int shots;
for( shots = 0; shots <= ship->lasers; 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->statet0 < ship->lasers )
{
if( ship->class > 1 || is_facing( ship, target ) )
{
schance += target->class * 25;
schance -= target->manuever / 10;
schance -= target->currspeed / 20;
schance -= ( abs( target->vx - ship->vx ) / 70 );
schance -= ( abs( target->vy - ship->vy ) / 70 );
schance -= ( abs( target->vz - ship->vz ) / 70 );
schance = URANGE( 10, schance, 90 );
if( number_percent( ) > schance )
{
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->statet0++;
}
}
}
}
}
}
}
}
void update_space( )
{
SHIP_DATA *ship;
SHIP_DATA *target;
PLANET_DATA *planet;
char buf[MAX_STRING_LENGTH];
int too_close, target_too_close;
int recharge;
for( ship = first_ship; ship; ship = ship->next )
{
if( ship->starsystem )
{
if( ship->energy > 0 && ship->shipstate == SHIP_DISABLED && ship->class != SHIP_PLATFORM )
ship->energy -= 100;
else if( ship->energy > 0 )
ship->energy += ( 5 + ship->class * 5 );
else
destroy_ship( ship, NULL );
}
if( ship->chaff_released > 0 )
ship->chaff_released--;
if( ship->shipstate == SHIP_HYPERSPACE )
{
ship->hyperdistance -= ship->hyperspeed * 2;
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 ) )
{
EXT_BV flags;
xSET_BIT(flags, SHIPDATA_HOME);
xSET_BIT(flags, SHIPDATA_OWNER);
xSET_BIT(flags, SHIPDATA_SHIPSTATE);
xSET_BIT(flags, SHIPDATA_STARSYSTEM);
xSET_BIT(flags, SHIPDATA_ENERGY);
xSET_BIT(flags, SHIPDATA_CHAFF_RELEASED);
xSET_BIT(flags, SHIPDATA_HYPERDISTANCE);
save_ship( ship, flags );
}
}
}
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_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 );
sprintf( buf, "%.0f %.0f %.0f", ship->vx, ship->vy, ship->vz );
echo_to_room_dnr( AT_BLUE, get_room_index( ship->pilotseat ), " Coords: " );
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 );
sprintf( buf, "%.0f %.0f %.0f", ship->vx, ship->vy, ship->vz );
echo_to_room_dnr( AT_BLUE, get_room_index( ship->coseat ), " Coords: " );
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;
for ( planet = first_planet; planet; planet = planet->next )
{
if (get_pprox(ship, planet) < too_close)
{
sprintf( buf, "Proximity alert: %s %d %d %d", planet->name,
planet->xpos, planet->ypos, planet->zpos );
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 < 3 )
{
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 == FIGHTER_SHIP || ( ship->class == MIDSIZE_SHIP && ship->manuever > 50 ) )
ship->shipstate = SHIP_BUSY_3;
else if( ship->class == MIDSIZE_SHIP || ( ship->class == CAPITAL_SHIP && ship->manuever > 50 ) )
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 == FIGHTER_SHIP || ( ship->class == MIDSIZE_SHIP && ship->manuever > 50 ) )
ship->shipstate = SHIP_BUSY_3;
else if( ship->class == MIDSIZE_SHIP || ( ship->class == CAPITAL_SHIP && ship->manuever > 50 ) )
ship->shipstate = SHIP_BUSY_2;
else
ship->shipstate = SHIP_BUSY;
}
}
if( autofly( ship ) )
{
if( ship->starsystem )
{
if( ship->target0 )
{
int schance = 50;
/*
* auto assist ships
*/
for( target = ship->starsystem->first_ship; target; target = target->next_in_starsystem )
{
if( autofly( target ) )
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_PLATFORM )
ship->currspeed = ship->realspeed;
if( ship->energy > 200 )
ship->autorecharge = TRUE;
if( ship->shipstate != SHIP_HYPERSPACE && ship->energy > 25
&& ship->missilestate == 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->missiles > 0 )
{
if( ship->class > 1 || is_facing( ship, target ) )
{
schance -= target->manuever / 5;
schance -= target->currspeed / 20;
schance += target->class * target->class * 25;
schance -= ( abs( target->vx - ship->vx ) / 100 );
schance -= ( abs( target->vy - ship->vy ) / 100 );
schance -= ( abs( target->vz - ship->vz ) / 100 );
schance += ( 30 );
schance = URANGE( 10, schance, 90 );
if( number_percent( ) > schance )
{
}
else
{
new_missile( ship, target, NULL, CONCUSSION_MISSILE );
ship->missiles--;
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 == CAPITAL_SHIP || ship->class == SHIP_PLATFORM )
ship->missilestate = MISSILE_RELOAD_2;
else
ship->missilestate = MISSILE_FIRED;
}
}
}
if( ship->missilestate == MISSILE_DAMAGED )
ship->missilestate = MISSILE_READY;
if( ship->statet0 == LASER_DAMAGED )
ship->statet0 = LASER_READY;
if( ship->shipstate == SHIP_DISABLED )
ship->shipstate = SHIP_READY;
}
else
{
ship->currspeed = 0;
if( !str_cmp( ship->owner, "The Empire" ) )
for( target = first_ship; target; target = target->next )
if( ship->starsystem == target->starsystem )
if( !str_cmp( target->owner, "The New 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 New Republic" ) )
for( target = first_ship; target; target = target->next )
if( ship->starsystem == target->starsystem )
if( !str_cmp( target->owner, "The Empire" ) )
{
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;
}
}
}
if( ( ship->class == CAPITAL_SHIP || ship->class == SHIP_PLATFORM ) && ship->target0 == NULL )
{
if( ship->missiles < ship->maxmissiles )
ship->missiles++;
if( ship->torpedos < ship->maxtorpedos )
ship->torpedos++;
if( ship->rockets < ship->maxrockets )
ship->rockets++;
}
}
}
/*
void write_starsystem_list( void )
{
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;
}
SPACE_DATA *starsystem_from_id( int id )
{
SPACE_DATA *starsystem;
for( starsystem = first_starsystem; starsystem; starsystem = starsystem->next )
if( starsystem->id == id )
return starsystem;
return NULL;
}
/*
* Get pointer to space structure from the dock vnun.
*/
SPACE_DATA *starsystem_from_vnum( int vnum )
{
ROOM_INDEX_DATA * room;
room = get_room_index( vnum );
if ( room == NULL )
return NULL;
if ( room->area != NULL && room->area->planet != NULL )
return room->area->planet->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 );
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, "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, "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, "Xpos %d\n", starsystem->xpos );
fprintf( fp, "Ypos %d\n", starsystem->ypos );
fprintf( fp, "End\n\n" );
fprintf( fp, "#END\n" );
fclose( fp );
fp = NULL;
}
return;
}
*
* Read in actual starsystem data.
*
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->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 ) );
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 ) );
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 );
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 " );
return;
}
*/
void load_space()
{
char selectquery[MAX_STRING_LENGTH*2];
SPACE_DATA *starsystem;
// PLANET_DATA *planet;
MYSQL_RES *qresult;
MYSQL_ROW systemdata;
sprintf(selectquery, "SELECT * FROM starsystems");
qresult = query_db(selectquery);
if (!sql_data_returned(qresult))
{
return;
}
else
{
while( (systemdata = mysql_fetch_row(qresult)) )
{
CREATE( starsystem, SPACE_DATA, 1 );
starsystem->name = systemdata[1];
starsystem->id = atoi(systemdata[0]);
starsystem->xpos = atoi(systemdata[2]);
starsystem->ypos = atoi(systemdata[3]);
starsystem->flags = atoi(systemdata[4]);
LINK( starsystem, first_starsystem, last_starsystem, next, prev );
}
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 xpos ypos flags\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, "xpos" ) )
{
starsystem->xpos = atoi( argument );
send_to_char( "Done.\n\r", ch );
save_starsystem( starsystem, STARSYSDATA_XPOS );
return;
}
if( !str_cmp( arg2, "ypos" ) )
{
starsystem->ypos = atoi( argument );
send_to_char( "Done.\n\r", ch );
save_starsystem( starsystem, STARSYSDATA_YPOS );
return;
}
if( !str_cmp( arg2, "name" ) )
{
STRFREE( starsystem->name );
starsystem->name = STRALLOC( argument );
send_to_char( "Done.\n\r", ch );
save_starsystem( starsystem, STARSYSDATA_NAME );
return;
}
if( !strcmp( arg2, "flags" ) )
{
char farg[MAX_INPUT_LENGTH];
argument = one_argument( argument, farg );
if( farg[0] == '\0' )
{
send_to_char( "Possible flags: hidden\n\r", ch );
return;
}
for( ; farg[0] != '\0'; argument = one_argument( argument, farg ) )
{
if( !str_cmp( farg, "hidden" ) )
SET_BIT( starsystem->flags, STARSYSTEM_HIDDEN );
else
ch_printf( ch, "No such flag: %s\n\r", farg );
}
send_to_char( "Done.\n\r", ch );
save_starsystem( starsystem, STARSYSDATA_FLAGS );
return;
}
do_setstarsystem( ch, "" );
return;
}
void showstarsystem( CHAR_DATA * ch, SPACE_DATA * starsystem )
{
ch_printf( ch, "Starsystem:%s ID: %d Xpos: %d Ypos: %d\n\r",
starsystem->name, starsystem->id, starsystem->xpos, starsystem->ypos );
/*
ch_printf( ch, "Star1: %s Gravity: %d Coordinates: %d %d %d\n\r",
starsystem->star1, starsystem->gravitys1, starsystem->s1x, starsystem->s1y, starsystem->s1z );
ch_printf( ch, "Star2: %s Gravity: %d Coordinates: %d %d %d\n\r",
starsystem->star2, starsystem->gravitys2, starsystem->s2x, starsystem->s2y, starsystem->s2z );
ch_printf( ch, "Planet1: %s Gravity: %d Coordinates: %d %d %d\n\r",
starsystem->planet1, starsystem->gravityp1, starsystem->p1x, starsystem->p1y, starsystem->p1z );
ch_printf( ch, " Doc1a: %5d (%s)\n\r", starsystem->doc1a, starsystem->location1a );
ch_printf( ch, " Doc1b: %5d (%s)\n\r", starsystem->doc1b, starsystem->location1b );
ch_printf( ch, " Doc1c: %5d (%s)\n\r", starsystem->doc1c, starsystem->location1c );
ch_printf( ch, "Planet2: %s Gravity: %d Coordinates: %d %d %d\n\r",
starsystem->planet2, starsystem->gravityp2, starsystem->p2x, starsystem->p2y, starsystem->p2z );
ch_printf( ch, " Doc2a: %5d (%s)\n\r", starsystem->doc2a, starsystem->location2a );
ch_printf( ch, " Doc2b: %5d (%s)\n\r", starsystem->doc2b, starsystem->location2b );
ch_printf( ch, " Doc2c: %5d (%s)\n\r", starsystem->doc2c, starsystem->location2c );
ch_printf( ch, "Planet3: %s Gravity: %d Coordinates: %d %d %d\n\r",
starsystem->planet3, starsystem->gravityp3, starsystem->p3x, starsystem->p3y, starsystem->p3z );
ch_printf( ch, " Doc3a: %5d (%s)\n\r", starsystem->doc3a, starsystem->location3a );
ch_printf( ch, " Doc3b: %5d (%s)\n\r", starsystem->doc3b, starsystem->location3b );
ch_printf( ch, " Doc3c: %5d (%s)\n\r", starsystem->doc3c, starsystem->location3c );*/
return;
}
void do_showstarsystem( CHAR_DATA * ch, char *argument )
{
SPACE_DATA *starsystem;
starsystem = starsystem_from_name( argument );
if( starsystem == NULL )
send_to_char( "&RNo such starsystem.\n\r", ch );
else
showstarsystem( ch, starsystem );
}
void do_makestarsystem( CHAR_DATA * ch, char *argument )
{
char arg[MAX_INPUT_LENGTH];
//char filename[256];
SPACE_DATA *starsystem;
if( !argument || argument[0] == '\0' )
{
send_to_char( "Usage: makestarsystem <starsystem name>\n\r", ch );
return;
}
CREATE( starsystem, SPACE_DATA, 1 );
LINK( starsystem, first_starsystem, last_starsystem, next, prev );
starsystem->name = STRALLOC( argument );
/*
starsystem->location1a = STRALLOC( "" );
starsystem->location2a = STRALLOC( "" );
starsystem->location3a = STRALLOC( "" );
starsystem->location1b = STRALLOC( "" );
starsystem->location2b = STRALLOC( "" );
starsystem->location3b = STRALLOC( "" );
starsystem->location1c = STRALLOC( "" );
starsystem->location2c = STRALLOC( "" );
starsystem->location3c = STRALLOC( "" );
starsystem->planet1 = STRALLOC( "" );
starsystem->planet2 = STRALLOC( "" );
starsystem->planet3 = STRALLOC( "" );
starsystem->star1 = STRALLOC( "" );
starsystem->star2 = STRALLOC( "" );
*/
argument = one_argument( argument, arg );
// sprintf( filename, "%s.system", strlower( arg ) );
// starsystem->filename = str_dup( filename );
save_starsystem( starsystem, STARSYSDATA_ALL );
// write_starsystem_list( );
}
void do_starsystems( CHAR_DATA * ch, char *argument )
{
SPACE_DATA *starsystem;
int count = 0;
for( starsystem = first_starsystem; starsystem; starsystem = starsystem->next )
{
if (!IS_SET( starsystem->flags, STARSYSTEM_HIDDEN))
{
set_char_color( AT_NOTE, ch );
ch_printf( ch, "%s\n\r", starsystem->name );
count++;
}
}
if( !count )
{
send_to_char( "There are no starsystems currently formed.\n\r", ch );
return;
}
}
void echo_to_ship( int color, SHIP_DATA * ship, char *argument )
{
int room;
for( room = ship->firstroom; room <= ship->lastroom; room++ )
{
echo_to_room( color, get_room_index( room ), argument );
}
}
void sound_to_ship( SHIP_DATA * ship, char *argument )
{
int roomnum;
ROOM_INDEX_DATA *room;
CHAR_DATA *vic;
for( roomnum = ship->firstroom; roomnum <= ship->lastroom; roomnum++ )
{
room = get_room_index( roomnum );
if( room == NULL )
continue;
for( vic = room->first_person; vic; vic = vic->next_in_room )
{
if( !IS_NPC( vic ) && IS_SET( vic->act, PLR_SOUND ) )
send_to_char( argument, vic );
}
}
}
void echo_to_cockpit( int color, SHIP_DATA * ship, char *argument )
{
int room;
for( room = ship->firstroom; room <= ship->lastroom; room++ )
{
if( room == ship->cockpit || room == ship->navseat
|| room == ship->pilotseat || room == ship->coseat
|| room == ship->gunseat || room == ship->engineroom || room == ship->turret1 || room == ship->turret2 )
echo_to_room( color, get_room_index( room ), argument );
}
}
void echo_to_system( int color, SHIP_DATA * ship, char *argument, SHIP_DATA * ignore )
{
SHIP_DATA *target;
if( !ship->starsystem )
return;
for( target = ship->starsystem->first_ship; target; target = target->next_in_starsystem )
{
if( target != ship && target != ignore )
echo_to_cockpit( color, target, argument );
}
}
bool is_facing( SHIP_DATA * ship, SHIP_DATA * target )
{
float dy, dx, dz, hx, hy, hz;
float cosofa;
hx = ship->hx;
hy = ship->hy;
hz = ship->hz;
dx = target->vx - ship->vx;
dy = target->vy - ship->vy;
dz = target->vz - ship->vz;
cosofa = ( hx * dx + hy * dy + hz * dz ) / ( sqrt( hx * hx + hy * hy + hz * hz ) + sqrt( dx * dx + dy * dy + dz * dz ) );
if( cosofa > 0.75 )
return TRUE;
return FALSE;
}
long int get_ship_value( SHIP_DATA * ship )
{
long int price;
if( ship->class == FIGHTER_SHIP )
price = 5000;
else if( ship->class == MIDSIZE_SHIP )
price = 50000;
else if( ship->class == CAPITAL_SHIP )
price = 500000;
else
price = 2000;
if( ship->class <= CAPITAL_SHIP )
price += ( ship->manuever * 100 * ( 1 + ship->class ) );
price += ( ship->tractorbeam * 100 );
price += ( ship->realspeed * 10 );
price += ( ship->astro_array * 5 );
price += ( 5 * ship->maxhull );
price += ( 2 * ship->maxenergy );
price += ( 100 * ship->maxchaff );
if( ship->maxenergy > 5000 )
price += ( ( ship->maxenergy - 5000 ) * 20 );
if( ship->maxenergy > 10000 )
price += ( ( ship->maxenergy - 10000 ) * 50 );
if( ship->maxhull > 1000 )
price += ( ( ship->maxhull - 1000 ) * 10 );
if( ship->maxhull > 10000 )
price += ( ( ship->maxhull - 10000 ) * 20 );
if( ship->maxshield > 200 )
price += ( ( ship->maxshield - 200 ) * 50 );
if( ship->maxshield > 1000 )
price += ( ( ship->maxshield - 1000 ) * 100 );
if( ship->realspeed > 100 )
price += ( ( ship->realspeed - 100 ) * 500 );
if( ship->lasers > 5 )
price += ( ( ship->lasers - 5 ) * 500 );
if( ship->maxshield )
price += ( 1000 + 10 * ship->maxshield );
if( ship->lasers )
price += ( 500 + 500 * ship->lasers );
if( ship->maxmissiles )
price += ( 1000 + 100 * ship->maxmissiles );
if( ship->maxrockets )
price += ( 2000 + 200 * ship->maxmissiles );
if( ship->maxtorpedos )
price += ( 1500 + 150 * ship->maxmissiles );
if( ship->missiles )
price += ( 250 * ship->missiles );
else if( ship->torpedos )
price += ( 500 * ship->torpedos );
else if( ship->rockets )
price += ( 1000 * ship->rockets );
if( ship->turret1 )
price += 5000;
if( ship->turret2 )
price += 5000;
if( ship->hyperspeed )
price += ( 1000 + ship->hyperspeed * 10 );
if( ship->hanger )
price += ( ship->class == MIDSIZE_SHIP ? 50000 : 100000 );
price *= 1.5;
return price;
}
/*
void write_ship_list( )
{
SHIP_DATA *tship;
FILE *fpout;
char filename[256];
sprintf( filename, "%s%s", SHIP_DIR, SHIP_LIST );
fpout = fopen( filename, "w" );
if( !fpout )
{
bug( "FATAL: cannot open ship.lst for writing!\n\r", 0 );
return;
}
for( tship = first_ship; tship; tship = tship->next )
fprintf( fpout, "%s\n", tship->filename );
fprintf( fpout, "$\n" );
fclose( fpout );
}
*/
SHIP_DATA *ship_in_room( ROOM_INDEX_DATA * room, char *name )
{
SHIP_DATA *ship;
if( !room )
return NULL;
for( ship = room->first_ship; ship; ship = ship->next_in_room )
if( !str_cmp( name, ship->name ) )
return ship;
for( ship = room->first_ship; ship; ship = ship->next_in_room )
if( nifty_is_name_prefix( name, ship->name ) )
return ship;
return NULL;
}
/*
* Get pointer to ship structure from ship name.
*/
SHIP_DATA *get_ship( char *name )
{
SHIP_DATA *ship;
for( ship = first_ship; ship; ship = ship->next )
if( !str_cmp( name, ship->name ) )
return ship;
for( ship = first_ship; ship; ship = ship->next )
if( nifty_is_name_prefix( name, ship->name ) )
return ship;
return NULL;
}
/*
* Checks if ships in a starsystem and returns poiner if it is.
*/
SHIP_DATA *get_ship_here( char *name, SPACE_DATA * starsystem )
{
SHIP_DATA *ship;
if( starsystem == NULL )
return NULL;
for( ship = starsystem->first_ship; ship; ship = ship->next_in_starsystem )
if( !str_cmp( name, ship->name ) )
return ship;
for( ship = starsystem->first_ship; ship; ship = ship->next_in_starsystem )
if( nifty_is_name_prefix( name, ship->name ) )
return ship;
return NULL;
}
/*
* Get pointer to ship structure from ship name.
*/
SHIP_DATA *ship_from_pilot( char *name )
{
SHIP_DATA *ship;
for( ship = first_ship; ship; ship = ship->next )
if( !str_cmp( name, ship->pilot ) )
return ship;
if( !str_cmp( name, ship->copilot ) )
return ship;
if( !str_cmp( name, ship->owner ) )
return ship;
return NULL;
}
SHIP_DATA *ship_from_id( int id )
{
SHIP_DATA *ship;
for( ship = first_ship; ship; ship = ship->next )
if( ship->id == id )
return ship;
return NULL;
}
/*
* Get pointer to ship structure from cockpit, turret, or entrance ramp vnum.
*/
SHIP_DATA *ship_from_cockpit( int vnum )
{
SHIP_DATA *ship;
for( ship = first_ship; ship; ship = ship->next )
if( vnum == ship->cockpit || vnum == ship->turret1 || vnum == ship->turret2
|| vnum == ship->pilotseat || vnum == ship->coseat || vnum == ship->navseat
|| vnum == ship->gunseat || vnum == ship->engineroom )
return ship;
return NULL;
}
SHIP_DATA *ship_from_pilotseat( int vnum )
{
SHIP_DATA *ship;
for( ship = first_ship; ship; ship = ship->next )
if( vnum == ship->pilotseat )
return ship;
return NULL;
}
SHIP_DATA *ship_from_coseat( int vnum )
{
SHIP_DATA *ship;
for( ship = first_ship; ship; ship = ship->next )
if( vnum == ship->coseat )
return ship;
return NULL;
}
SHIP_DATA *ship_from_navseat( int vnum )
{
SHIP_DATA *ship;
for( ship = first_ship; ship; ship = ship->next )
if( vnum == ship->navseat )
return ship;
return NULL;
}
SHIP_DATA *ship_from_gunseat( int vnum )
{
SHIP_DATA *ship;
for( ship = first_ship; ship; ship = ship->next )
if( vnum == ship->gunseat )
return ship;
return NULL;
}
SHIP_DATA *ship_from_engine( int vnum )
{
SHIP_DATA *ship;
for( ship = first_ship; ship; ship = ship->next )
{
if( ship->engineroom )
{
if( vnum == ship->engineroom )
return ship;
}
else
{
if( vnum == ship->cockpit )
return ship;
}
}
return NULL;
}
SHIP_DATA *ship_from_turret( int vnum )
{
SHIP_DATA *ship;
for( ship = first_ship; ship; ship = ship->next )
if( vnum == ship->gunseat || vnum == ship->turret1 || vnum == ship->turret2 )
return ship;
return NULL;
}
SHIP_DATA *ship_from_entrance( int vnum )
{
SHIP_DATA *ship;
for( ship = first_ship; ship; ship = ship->next )
if( vnum == ship->entrance )
return ship;
return NULL;
}
SHIP_DATA *ship_from_hanger( int vnum )
{
SHIP_DATA *ship;
for( ship = first_ship; ship; ship = ship->next )
if( vnum == ship->hanger )
return ship;
return NULL;
}
/*
void save_ship( SHIP_DATA * ship )
{
FILE *fp;
char filename[256];
char buf[MAX_STRING_LENGTH];
if( !ship )
{
bug( "save_ship: null ship pointer!", 0 );
return;
}
if( !ship->filename || ship->filename[0] == '\0' )
{
sprintf( buf, "save_ship: %s has no filename", ship->name );
bug( buf, 0 );
return;
}
sprintf( filename, "%s%s", SHIP_DIR, ship->filename );
if( ( fp = fopen( filename, "w" ) ) == NULL )
{
bug( "save_ship: fopen", 0 );
perror( filename );
}
else
{
fprintf( fp, "#SHIP\n" );
fprintf( fp, "Name %s~\n", ship->name );
fprintf( fp, "Filename %s~\n", ship->filename );
fprintf( fp, "Description %s~\n", ship->description );
fprintf( fp, "Owner %s~\n", ship->owner );
fprintf( fp, "Pilot %s~\n", ship->pilot );
fprintf( fp, "Copilot %s~\n", ship->copilot );
fprintf( fp, "Class %d\n", ship->class );
fprintf( fp, "Tractorbeam %d\n", ship->tractorbeam );
fprintf( fp, "Shipyard %d\n", ship->shipyard );
fprintf( fp, "Hanger %d\n", ship->hanger );
fprintf( fp, "Turret1 %d\n", ship->turret1 );
fprintf( fp, "Turret2 %d\n", ship->turret2 );
fprintf( fp, "Statet0 %d\n", ship->statet0 );
fprintf( fp, "Statet1 %d\n", ship->statet1 );
fprintf( fp, "Statet2 %d\n", ship->statet2 );
fprintf( fp, "Lasers %d\n", ship->lasers );
fprintf( fp, "Missiles %d\n", ship->missiles );
fprintf( fp, "Maxmissiles %d\n", ship->maxmissiles );
fprintf( fp, "Rockets %d\n", ship->rockets );
fprintf( fp, "Maxrockets %d\n", ship->maxrockets );
fprintf( fp, "Torpedos %d\n", ship->torpedos );
fprintf( fp, "Maxtorpedos %d\n", ship->maxtorpedos );
fprintf( fp, "Lastdoc %d\n", ship->lastdoc );
fprintf( fp, "Firstroom %d\n", ship->firstroom );
fprintf( fp, "Lastroom %d\n", ship->lastroom );
fprintf( fp, "Shield %d\n", ship->shield );
fprintf( fp, "Maxshield %d\n", ship->maxshield );
fprintf( fp, "Hull %d\n", ship->hull );
fprintf( fp, "Maxhull %d\n", ship->maxhull );
fprintf( fp, "Maxenergy %d\n", ship->maxenergy );
fprintf( fp, "Hyperspeed %d\n", ship->hyperspeed );
fprintf( fp, "Comm %d\n", ship->comm );
fprintf( fp, "Chaff %d\n", ship->chaff );
fprintf( fp, "Maxchaff %d\n", ship->maxchaff );
fprintf( fp, "Sensor %d\n", ship->sensor );
fprintf( fp, "Astro_array %d\n", ship->astro_array );
fprintf( fp, "Realspeed %d\n", ship->realspeed );
fprintf( fp, "Type %d\n", ship->type );
fprintf( fp, "Cockpit %d\n", ship->cockpit );
fprintf( fp, "Coseat %d\n", ship->coseat );
fprintf( fp, "Pilotseat %d\n", ship->pilotseat );
fprintf( fp, "Gunseat %d\n", ship->gunseat );
fprintf( fp, "Navseat %d\n", ship->navseat );
fprintf( fp, "Engineroom %d\n", ship->engineroom );
fprintf( fp, "Entrance %d\n", ship->entrance );
fprintf( fp, "Shipstate %d\n", ship->shipstate );
fprintf( fp, "Missilestate %d\n", ship->missilestate );
fprintf( fp, "Energy %d\n", ship->energy );
fprintf( fp, "Manuever %d\n", ship->manuever );
fprintf( fp, "Home %s~\n", ship->home );
fprintf( fp, "End\n\n" );
fprintf( fp, "#END\n" );
fclose( fp );
fp = NULL;
}
return;
}
*
* Read in actual ship data.
*
void fread_ship( SHIP_DATA * ship, FILE * fp )
{
char buf[MAX_STRING_LENGTH];
char *word;
bool fMatch;
int dummy_number;
for( ;; )
{
word = feof( fp ) ? "End" : fread_word( fp );
fMatch = FALSE;
switch ( UPPER( word[0] ) )
{
case '*':
fMatch = TRUE;
fread_to_eol( fp );
break;
case 'A':
KEY( "Astro_array", ship->astro_array, fread_number( fp ) );
break;
case 'C':
KEY( "Cockpit", ship->cockpit, fread_number( fp ) );
KEY( "Coseat", ship->coseat, fread_number( fp ) );
KEY( "Class", ship->class, fread_number( fp ) );
KEY( "Copilot", ship->copilot, fread_string( fp ) );
KEY( "Comm", ship->comm, fread_number( fp ) );
KEY( "Chaff", ship->chaff, fread_number( fp ) );
break;
case 'D':
KEY( "Description", ship->description, fread_string( fp ) );
break;
case 'E':
KEY( "Engineroom", ship->engineroom, fread_number( fp ) );
KEY( "Entrance", ship->entrance, fread_number( fp ) );
KEY( "Energy", ship->energy, fread_number( fp ) );
if( !str_cmp( word, "End" ) )
{
if( !ship->home )
ship->home = STRALLOC( "" );
if( !ship->name )
ship->name = STRALLOC( "" );
if( !ship->owner )
ship->owner = STRALLOC( "" );
if( !ship->description )
ship->description = STRALLOC( "" );
if( !ship->copilot )
ship->copilot = STRALLOC( "" );
if( !ship->pilot )
ship->pilot = STRALLOC( "" );
if( ship->shipstate != SHIP_DISABLED )
ship->shipstate = SHIP_DOCKED;
if( ship->statet0 != LASER_DAMAGED )
ship->statet0 = LASER_READY;
if( ship->statet1 != LASER_DAMAGED )
ship->statet1 = LASER_READY;
if( ship->statet2 != LASER_DAMAGED )
ship->statet2 = LASER_READY;
if( ship->missilestate != MISSILE_DAMAGED )
ship->missilestate = MISSILE_READY;
if( ship->shipyard <= 0 )
ship->shipyard = ROOM_LIMBO_SHIPYARD;
if( ship->lastdoc <= 0 )
ship->lastdoc = ship->shipyard;
ship->bayopen = TRUE;
ship->autopilot = FALSE;
ship->hatchopen = FALSE;
if( ship->navseat <= 0 )
ship->navseat = ship->cockpit;
if( ship->gunseat <= 0 )
ship->gunseat = ship->cockpit;
if( ship->coseat <= 0 )
ship->coseat = ship->cockpit;
if( ship->pilotseat <= 0 )
ship->pilotseat = ship->cockpit;
if( ship->missiletype == 1 )
{
ship->torpedos = ship->missiles; * for back compatability *
ship->missiles = 0;
}
ship->starsystem = NULL;
ship->energy = ship->maxenergy;
ship->hull = ship->maxhull;
ship->in_room = NULL;
ship->next_in_room = NULL;
ship->prev_in_room = NULL;
return;
}
break;
case 'F':
KEY( "Filename", ship->filename, fread_string_nohash( fp ) );
KEY( "Firstroom", ship->firstroom, fread_number( fp ) );
break;
case 'G':
KEY( "Gunseat", ship->gunseat, fread_number( fp ) );
break;
case 'H':
KEY( "Home", ship->home, fread_string( fp ) );
KEY( "Hyperspeed", ship->hyperspeed, fread_number( fp ) );
KEY( "Hull", ship->hull, fread_number( fp ) );
KEY( "Hanger", ship->hanger, fread_number( fp ) );
break;
case 'L':
KEY( "Laserstr", ship->lasers, ( short )( fread_number( fp ) / 10 ) );
KEY( "Lasers", ship->lasers, fread_number( fp ) );
KEY( "Lastdoc", ship->lastdoc, fread_number( fp ) );
KEY( "Lastroom", ship->lastroom, fread_number( fp ) );
break;
case 'M':
KEY( "Manuever", ship->manuever, fread_number( fp ) );
KEY( "Maxmissiles", ship->maxmissiles, fread_number( fp ) );
KEY( "Maxtorpedos", ship->maxtorpedos, fread_number( fp ) );
KEY( "Maxrockets", ship->maxrockets, fread_number( fp ) );
KEY( "Missiles", ship->missiles, fread_number( fp ) );
KEY( "Missiletype", ship->missiletype, fread_number( fp ) );
KEY( "Maxshield", ship->maxshield, fread_number( fp ) );
KEY( "Maxenergy", ship->maxenergy, fread_number( fp ) );
KEY( "Missilestate", ship->missilestate, fread_number( fp ) );
KEY( "Maxhull", ship->maxhull, fread_number( fp ) );
KEY( "Maxchaff", ship->maxchaff, fread_number( fp ) );
break;
case 'N':
KEY( "Name", ship->name, fread_string( fp ) );
KEY( "Navseat", ship->navseat, fread_number( fp ) );
break;
case 'O':
KEY( "Owner", ship->owner, fread_string( fp ) );
KEY( "Objectnum", dummy_number, fread_number( fp ) );
break;
case 'P':
KEY( "Pilot", ship->pilot, fread_string( fp ) );
KEY( "Pilotseat", ship->pilotseat, fread_number( fp ) );
break;
case 'R':
KEY( "Realspeed", ship->realspeed, fread_number( fp ) );
KEY( "Rockets", ship->rockets, fread_number( fp ) );
break;
case 'S':
KEY( "Shipyard", ship->shipyard, fread_number( fp ) );
KEY( "Sensor", ship->sensor, fread_number( fp ) );
KEY( "Shield", ship->shield, fread_number( fp ) );
KEY( "Shipstate", ship->shipstate, fread_number( fp ) );
KEY( "Statet0", ship->statet0, fread_number( fp ) );
KEY( "Statet1", ship->statet1, fread_number( fp ) );
KEY( "Statet2", ship->statet2, fread_number( fp ) );
break;
case 'T':
KEY( "Type", ship->type, fread_number( fp ) );
KEY( "Tractorbeam", ship->tractorbeam, fread_number( fp ) );
KEY( "Turret1", ship->turret1, fread_number( fp ) );
KEY( "Turret2", ship->turret2, fread_number( fp ) );
KEY( "Torpedos", ship->torpedos, fread_number( fp ) );
break;
}
if( !fMatch )
{
sprintf( buf, "Fread_ship: no match: %s", word );
bug( buf, 0 );
}
}
}
*
* Load a ship file
*
bool load_ship_file( char *shipfile )
{
char filename[256];
SHIP_DATA *ship;
FILE *fp;
bool found;
ROOM_INDEX_DATA *pRoomIndex;
CLAN_DATA *clan;
CREATE( ship, SHIP_DATA, 1 );
found = FALSE;
sprintf( filename, "%s%s", SHIP_DIR, shipfile );
if( ( fp = fopen( filename, "r" ) ) != NULL )
{
found = TRUE;
for( ;; )
{
char letter;
char *word;
letter = fread_letter( fp );
if( letter == '*' )
{
fread_to_eol( fp );
continue;
}
if( letter != '#' )
{
bug( "Load_ship_file: # not found.", 0 );
break;
}
word = fread_word( fp );
if( !str_cmp( word, "SHIP" ) )
{
fread_ship( ship, fp );
break;
}
else if( !str_cmp( word, "END" ) )
break;
else
{
char buf[MAX_STRING_LENGTH];
sprintf( buf, "Load_ship_file: bad section: %s.", word );
bug( buf, 0 );
break;
}
}
fclose( fp );
}
if( !( found ) )
DISPOSE( ship );
else
{
LINK( ship, first_ship, last_ship, next, prev );
if( !str_cmp( "Public", ship->owner ) || ship->type == MOB_SHIP )
{
if( ship->class != SHIP_PLATFORM && ship->type != MOB_SHIP && ship->class != CAPITAL_SHIP )
{
extract_ship( ship );
ship_to_room( ship, ship->shipyard );
ship->location = ship->shipyard;
ship->lastdoc = ship->shipyard;
ship->shipstate = SHIP_DOCKED;
}
ship->currspeed = 0;
ship->energy = ship->maxenergy;
ship->chaff = ship->maxchaff;
ship->hull = ship->maxhull;
ship->shield = 0;
ship->statet1 = LASER_READY;
ship->statet2 = LASER_READY;
ship->statet0 = LASER_READY;
ship->missilestate = LASER_READY;
ship->currjump = NULL;
ship->target0 = NULL;
ship->target1 = NULL;
ship->target2 = NULL;
ship->hatchopen = FALSE;
ship->bayopen = TRUE;
ship->missiles = ship->maxmissiles;
ship->torpedos = ship->maxtorpedos;
ship->rockets = ship->maxrockets;
ship->autorecharge = FALSE;
ship->autotrack = FALSE;
ship->autospeed = FALSE;
}
else if( ship->cockpit == ROOM_SHUTTLE_BUS ||
ship->cockpit == ROOM_SHUTTLE_BUS_2 ||
ship->cockpit == ROOM_SENATE_SHUTTLE ||
ship->cockpit == ROOM_CORUSCANT_TURBOCAR || ship->cockpit == ROOM_CORUSCANT_SHUTTLE )
{
}
else if( ( pRoomIndex = get_room_index( ship->lastdoc ) ) != NULL
&& ship->class != CAPITAL_SHIP && ship->class != SHIP_PLATFORM )
{
LINK( ship, pRoomIndex->first_ship, pRoomIndex->last_ship, next_in_room, prev_in_room );
ship->in_room = pRoomIndex;
ship->location = ship->lastdoc;
}
if( ship->class == SHIP_PLATFORM || ship->type == MOB_SHIP || ship->class == CAPITAL_SHIP )
{
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;
ship->shipstate = SHIP_READY;
ship->autopilot = TRUE;
ship->autorecharge = TRUE;
ship->shield = ship->maxshield;
}
if( ship->type != MOB_SHIP && ( clan = get_clan( ship->owner ) ) != NULL )
{
if( ship->class <= SHIP_PLATFORM )
clan->spacecraft++;
else
clan->vehicles++;
}
}
return found;
}
*
* Load in all the ship files.
*
void load_ships( )
{
FILE *fpList;
char *filename;
char shiplist[256];
char buf[MAX_STRING_LENGTH];
first_ship = NULL;
last_ship = NULL;
first_missile = NULL;
last_missile = NULL;
log_string( "Loading ships..." );
sprintf( shiplist, "%s%s", SHIP_DIR, SHIP_LIST );
if( ( fpList = fopen( shiplist, "r" ) ) == NULL )
{
perror( shiplist );
exit( 1 );
}
for( ;; )
{
filename = feof( fpList ) ? "$" : fread_word( fpList );
if( filename[0] == '$' )
break;
if( !load_ship_file( filename ) )
{
sprintf( buf, "Cannot load ship file: %s", filename );
bug( buf, 0 );
}
}
fclose( fpList );
log_string( " Done ships " );
return;
}
*/
void load_ships()
{
char selectquery[MAX_STRING_LENGTH*2];
SHIP_DATA *ship;
MYSQL_RES *qresult;
MYSQL_ROW shipdata;
ROOM_INDEX_DATA *pRoomIndex;
CLAN_DATA *clan;
sprintf(selectquery, "SELECT * FROM ships");
qresult = query_db(selectquery);
if (!sql_data_returned(qresult))
{
return;
}
else
{
while( (shipdata = mysql_fetch_row(qresult)) )
{
CREATE( ship, SHIP_DATA, 1 );
ship->starsystem = starsystem_from_id(atoi(shipdata[1]));
ship->name = shipdata[2];
ship->home = shipdata[3];
ship->description = shipdata[4];
ship->owner = shipdata[5];
ship->pilot = shipdata[6];
ship->copilot = shipdata[7];
ship->dest = shipdata[8];
ship->type = atoi(shipdata[9]);
ship->class = atoi(shipdata[10]);
ship->comm = atoi(shipdata[11]);
ship->sensor = atoi(shipdata[12]);
ship->astro_array = atoi(shipdata[13]);
ship->hyperspeed = atoi(shipdata[14]);
ship->hyperdistance = atoi(shipdata[15]);
ship->realspeed = atoi(shipdata[16]);
ship->currspeed = atoi(shipdata[17]);
ship->shipstate = atoi(shipdata[18]);
ship->statet0 = atoi(shipdata[19]);
ship->statet1 = atoi(shipdata[20]);
ship->statet2 = atoi(shipdata[21]);
ship->missiletype = atoi(shipdata[22]);
ship->missilestate = atoi(shipdata[23]);
ship->missiles = atoi(shipdata[24]);
ship->maxmissiles = atoi(shipdata[25]);
ship->torpedos = atoi(shipdata[26]);
ship->maxtorpedos = atoi(shipdata[27]);
ship->rockets = atoi(shipdata[28]);
ship->maxrockets = atoi(shipdata[29]);
ship->lasers = atoi(shipdata[30]);
ship->tractorbeam = atoi(shipdata[31]);
ship->manuever = atoi(shipdata[32]);
ship->bayopen = atoi(shipdata[33]);
ship->hatchopen = atoi(shipdata[34]);
ship->autorecharge = atoi(shipdata[35]);
ship->autotrack = atoi(shipdata[36]);
ship->autospeed = atoi(shipdata[37]);
ship->vx = atoi(shipdata[38]);
ship->vy = atoi(shipdata[39]);
ship->vz = atoi(shipdata[30]);
ship->hx = atoi(shipdata[31]);
ship->hy = atoi(shipdata[32]);
ship->hz = atoi(shipdata[33]);
ship->jx = atoi(shipdata[34]);
ship->jy = atoi(shipdata[35]);
ship->jz = atoi(shipdata[36]);
ship->maxenergy = atoi(shipdata[37]);
ship->energy = atoi(shipdata[38]);
ship->shield = atoi(shipdata[39]);
ship->maxshield = atoi(shipdata[40]);
ship->hull = atoi(shipdata[41]);
ship->maxhull = atoi(shipdata[42]);
ship->cockpit = atoi(shipdata[43]);
ship->id = atoi(shipdata[0]);
ship->turret1 = atoi(shipdata[44]);
ship->turret2 = atoi(shipdata[45]);
ship->location = atoi(shipdata[46]);
ship->lastdoc = atoi(shipdata[47]);
ship->shipyard = atoi(shipdata[48]);
ship->entrance = atoi(shipdata[49]);
ship->hanger = atoi(shipdata[50]);
ship->engineroom = atoi(shipdata[51]);
ship->firstroom = atoi(shipdata[52]);
ship->lastroom = atoi(shipdata[53]);
ship->navseat = atoi(shipdata[54]);
ship->pilotseat = atoi(shipdata[55]);
ship->coseat = atoi(shipdata[56]);
ship->gunseat = atoi(shipdata[57]);
ship->collision = atoi(shipdata[58]);
ship->chaff = atoi(shipdata[59]);
ship->maxchaff = atoi(shipdata[60]);
ship->chaff_released = atoi(shipdata[61]);
ship->autopilot = atoi(shipdata[62]);
ship->target0 = ship_from_id(atoi(shipdata[63]));
ship->target1 = ship_from_id(atoi(shipdata[64]));
ship->target2 = ship_from_id(atoi(shipdata[65]));
ship->in_room = get_room_index(atoi(shipdata[66]));
ship->currjump = starsystem_from_id(atoi(shipdata[67]));
if( !str_cmp( "Public", ship->owner ) || ship->type == MOB_SHIP )
{
if( ship->class != SHIP_PLATFORM && ship->type != MOB_SHIP && ship->class != CAPITAL_SHIP )
{
extract_ship( ship );
ship_to_room( ship, ship->shipyard );
ship->location = ship->shipyard;
ship->lastdoc = ship->shipyard;
ship->shipstate = SHIP_DOCKED;
}
ship->currspeed = 0;
ship->energy = ship->maxenergy;
ship->chaff = ship->maxchaff;
ship->hull = ship->maxhull;
ship->shield = 0;
ship->statet1 = LASER_READY;
ship->statet2 = LASER_READY;
ship->statet0 = LASER_READY;
ship->missilestate = LASER_READY;
ship->currjump = NULL;
ship->target0 = NULL;
ship->target1 = NULL;
ship->target2 = NULL;
ship->hatchopen = FALSE;
ship->bayopen = TRUE;
ship->missiles = ship->maxmissiles;
ship->torpedos = ship->maxtorpedos;
ship->rockets = ship->maxrockets;
ship->autorecharge = FALSE;
ship->autotrack = FALSE;
ship->autospeed = FALSE;
}
else if( ship->cockpit == ROOM_SHUTTLE_BUS ||
ship->cockpit == ROOM_SHUTTLE_BUS_2 ||
ship->cockpit == ROOM_SENATE_SHUTTLE ||
ship->cockpit == ROOM_CORUSCANT_TURBOCAR || ship->cockpit == ROOM_CORUSCANT_SHUTTLE )
{
}
else if( ( pRoomIndex = get_room_index( ship->lastdoc ) ) != NULL
&& ship->class != CAPITAL_SHIP && ship->class != SHIP_PLATFORM )
{
LINK( ship, pRoomIndex->first_ship, pRoomIndex->last_ship, next_in_room, prev_in_room );
ship->in_room = pRoomIndex;
ship->location = ship->lastdoc;
}
if( ship->class == SHIP_PLATFORM || ship->type == MOB_SHIP || ship->class == CAPITAL_SHIP )
{
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;
ship->shipstate = SHIP_READY;
ship->autopilot = TRUE;
ship->autorecharge = TRUE;
ship->shield = ship->maxshield;
}
if( ship->type != MOB_SHIP && ( clan = get_clan( ship->owner ) ) != NULL )
{
if( ship->class <= SHIP_PLATFORM )
clan->spacecraft++;
else
clan->vehicles++;
}
LINK( ship, first_ship, last_ship, next, prev );
}
return;
}
}
void save_ship( SHIP_DATA *ship, EXT_BV flags )
{
char updatequery[MAX_STRING_LENGTH*2];
char selectquery[MAX_STRING_LENGTH*2];
MYSQL_RES *qresult;
sprintf(selectquery, "SELECT * FROM ships where id='%d'", ship->id);
qresult = query_db(selectquery);
if (!sql_data_returned(qresult))
sprintf(updatequery, "INSERT INTO ships SET");
else
sprintf(updatequery, "UPDATE ships SET");
if (xIS_SET(flags, SHIPDATA_NAME ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s name ='%s',", updatequery, ship->name );
}
if (xIS_SET(flags, SHIPDATA_HOME ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s home ='%s',", updatequery, ship->home );
}
if (xIS_SET(flags, SHIPDATA_DESCRIPTION ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s description ='%s',", updatequery, ship->description );
}
if (xIS_SET(flags, SHIPDATA_OWNER ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s owner ='%s',", updatequery, ship->owner );
}
/*if (xIS_SET(flags, SHIPDATA_STARSYSTEM ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s starystem ='%d',", updatequery, ship->starystem->name );
}*/
if ((xIS_SET(flags, SHIPDATA_INROOM ) || xIS_SET(flags, SHIPDATA_ALL)) && ship->in_room != NULL)
{
sprintf(updatequery, "%s inroom ='%d',", updatequery, ship->in_room->vnum );
}
if (xIS_SET(flags, SHIPDATA_PILOT ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s pilot ='%s',", updatequery, ship->pilot );
}
if (xIS_SET(flags, SHIPDATA_COPILOT ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s copilot ='%s',", updatequery, ship->copilot );
}
if (xIS_SET(flags, SHIPDATA_DEST ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s dest ='%s',", updatequery, ship->dest );
}
if (xIS_SET(flags, SHIPDATA_TYPE ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s type ='%d',", updatequery, ship->type );
}
if (xIS_SET(flags, SHIPDATA_CLASS ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s class ='%d',", updatequery, ship->class );
}
if (xIS_SET(flags, SHIPDATA_COMM ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s comm ='%d',", updatequery, ship->comm );
}
if (xIS_SET(flags, SHIPDATA_SENSOR ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s sensor ='%d',", updatequery, ship->sensor );
}
if (xIS_SET(flags, SHIPDATA_ASTRO_ARRAY ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s astro_array ='%d',", updatequery, ship->astro_array );
}
if (xIS_SET(flags, SHIPDATA_HYPERSPEED ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s hyperspeed ='%d',", updatequery, ship->hyperspeed );
}
if (xIS_SET(flags, SHIPDATA_HYPERDISTANCE ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s hyperdistance ='%d',", updatequery, ship->hyperdistance );
}
if (xIS_SET(flags, SHIPDATA_REALSPEED ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s realspeed ='%d',", updatequery, ship->realspeed );
}
if (xIS_SET(flags, SHIPDATA_CURRSPEED ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s currspeed ='%d',", updatequery, ship->currspeed );
}
if (xIS_SET(flags, SHIPDATA_SHIPSTATE ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s shipstate ='%d',", updatequery, ship->shipstate );
}
if (xIS_SET(flags, SHIPDATA_STATET0 ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s statet0 ='%d',", updatequery, ship->statet0 );
}
if (xIS_SET(flags, SHIPDATA_STATET1 ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s statet1 ='%d',", updatequery, ship->statet1 );
}
if (xIS_SET(flags, SHIPDATA_STATET2 ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s statet2 ='%d',", updatequery, ship->statet2 );
}
if (xIS_SET(flags, SHIPDATA_MISSILETYPE ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s missiletype ='%d',", updatequery, ship->missiletype );
}
if (xIS_SET(flags, SHIPDATA_MISSILESTATE ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s missilestate ='%d',", updatequery, ship->missilestate );
}
if (xIS_SET(flags, SHIPDATA_MISSILES ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s missiles ='%d',", updatequery, ship->missiles );
}
if (xIS_SET(flags, SHIPDATA_MAXMISSILES ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s maxmissiles ='%d',", updatequery, ship->maxmissiles );
}
if (xIS_SET(flags, SHIPDATA_TORPEDOS ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s torpedos ='%d',", updatequery, ship->torpedos );
}
if (xIS_SET(flags, SHIPDATA_MAXTORPEDOS ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s maxtorpedos ='%d',", updatequery, ship->maxtorpedos );
}
if (xIS_SET(flags, SHIPDATA_ROCKETS ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s rockets ='%d',", updatequery, ship->rockets );
}
if (xIS_SET(flags, SHIPDATA_MAXROCKETS ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s maxrockets ='%d',", updatequery, ship->maxrockets );
}
if (xIS_SET(flags, SHIPDATA_LASERS ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s lasers ='%d',", updatequery, ship->lasers );
}
if (xIS_SET(flags, SHIPDATA_TRACTORBEAM ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s tractorbeam ='%d',", updatequery, ship->tractorbeam );
}
if (xIS_SET(flags, SHIPDATA_MANUEVER ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s manuever ='%d',", updatequery, ship->manuever );
}
if (xIS_SET(flags, SHIPDATA_BAYOPEN ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s bayopen ='%d',", updatequery, ship->bayopen );
}
if (xIS_SET(flags, SHIPDATA_HATCHOPEN ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s hatchopen ='%d',", updatequery, ship->hatchopen );
}
if (xIS_SET(flags, SHIPDATA_AUTORECHARGE ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s autorecharge ='%d',", updatequery, ship->autorecharge );
}
if (xIS_SET(flags, SHIPDATA_AUTOTRACK ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s autotrack ='%d',", updatequery, ship->autotrack );
}
if (xIS_SET(flags, SHIPDATA_AUTOSPEED ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s autospeed ='%d',", updatequery, ship->autospeed );
}
if (xIS_SET(flags, SHIPDATA_VX ) || xIS_SET(flags, SHIPDATA_ALL))
{
sprintf(updatequery, "%s vx ='%f',", updatequery, ship->vx );
}Showing the first 100 KB of 269.9 KB. Download the archive for the full file.