space.c
swrip200/src/space.c · 389.7 KB
From the archive swrip200.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. *
* ------------------------------------------------------------------------ *
* Space Module *
****************************************************************************/
#include <math.h>
#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/dir.h>
#include "mud.h"
SHIP_DATA * first_ship;
SHIP_DATA * last_ship;
MISSILE_DATA * first_missile;
MISSILE_DATA * last_missile;
SPACE_DATA * first_spaceobject;
SPACE_DATA * last_spaceobject;
int bus_pos =0;
int bus_planet =0;
int bus2_planet = 8;
int bus3_planet = 11;
int bus4_planet = 3;
int turbocar_stop =0;
int corus_shuttle =0;
int baycount = 0;
int currrentalvnum = 6000; // increments as rentals are created
#define RENTALSTORAGEROOM 44 // Room where unused rentals are stored
#define DEGMULTI 149760
#define MAX_COORD 15000000
#define MAX_COORD_S 14000000
#define MAX_STATION 10
#define MAX_BUS_STOP 14
#define SHIPDAM_MINPLATFORM 100
#define SHIPDAM_MAXPLATFORM 250
#define SHIPDAM_MINCAP 100
#define SHIPDAM_MAXCAP 200
#define SHIPDAM_MINDEF 5
#define SHIPDAM_MAXDEF 10
#define STOP_PLANET 202
#define STOP_SHIPYARD 32015
#define SENATEPAD 32055
#define OUTERPAD 2064
struct serin_shuttle
{
char name [20];
int startingloc;
int cockpitvnum;
int planetloc;
int const bus_vnum [12];
char * const bus_stop [12];
};
/* New Serin system, makes it much easier to add new ones - Darrik Vequir, May, 01 */
/* MAX_BUS defined in mud.h */
struct serin_shuttle serin[MAX_BUS] =
{
{
"Pluogus", 0, 32140, 0,
{ 201, 21943, 28613, 21100, 28038, 10500, 201 },
{ "Coruscant", "Corulag", "Kashyyyk", "Mon Calamari", "Gamorr", "Corellia", "Coruscant" }
},
{
"Tocca", 0, 32410, 0,
{ 5550, 21943, 10500, 29001, 11800, 4100, 23082, 5550 },
{ "Ord Mantell", "Corulag", "Corellia", "Adari", "Roche", "Sullust", "Kuat", "Ord Mantell" }
},
{
"Cassia", 0, 32425, 0,
{ 28247, 10500, 5200, 9729, 31872, 822, 28038, 10500, 28247 },
{ "Byss", "Corellia", "Af'el", "Uvena III", "Tatooine", "Ryloth", "Gamorr", "Corellia", "Byss" }
},
{
"Siego", 0, 32435, 0,
{ 201, 10500, 6264, 11206, 2300, 4305, 28247, 201 },
{ "Coruscant", "Corellia", "Bespin", "Hoth", "Endor", "Wroona", "Byss", "Coruscant"}
},
{
"Amose", 0, 32445, 0,
{ 2300, 6264, 4100, 31872, 9729, 28038, 21100, 5550, 2300 },
{ "Endor", "Bespin", "Sullust", "Tatooine", "Uvena III", "Gamorr", "Mon Calamari", "Ord Mantell", "Endor"}
},
{
"Edena", 0, 32440, 0,
{ 28247, 201, 21943, 23082, 10500, 29001, 4305, 28247 },
{ "Byss", "Coruscant", "Corulag", "Kuat", "Corellia", "Adari", "Wroona", "Byss"}
},
{
"Odani", 0, 32450, 0,
{ 4305, 11800, 28613, 5550, 23082, 10500, 29001, 4305 },
{ "Wroona", "Roche", "Kashyyyk", "Ord Mantell", "Kuat", "Corellia", "Adari", "Wroona"}
}
};
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 , 822 , 6264, 28613 , 3060 , 28247, 32297, 2065, 10500, 11206
};
int const bus_vnum2 [MAX_BUS_STOP] =
{
201, 11206 , 10500 , 2065 , 32297 , 28247 , 3060 , 28613 , 6264, 822 , 31872, 28038, 29001, 21100
};
char * const bus_stop [MAX_BUS_STOP+1] =
{
"Coruscant",
"Mon Calamari", "Adari", "Gamorr", "Tatooine" , "Ryloth", "Bespin",
"Kashyyyk", "Endor", "Byss", "Cloning Facilities", "Kuat", "Corellia", "Hoth", "Coruscant" /* last should always be same as first */
};
char * const bus_stoprev [MAX_BUS_STOP+1] =
{
"Coruscant",
"Hoth", "Corellia", "Kuat", "Cloning Facilities" , "Byss" , "Endor", "Kashyyyk",
"Bespin", "Ryloth", "Tatooine", "Gamorr", "Adari", "Mon Calamari", "Coruscant" /* last should always be same as first */
};
RENTAL_DATA rentals[MAX_RENTALS] =
{
{
HOPPER_RENTAL, 6030
},
{
TWING_RENTAL, 32200
}
};
// TURBOLASER_TURRET, QUAD_TURRET, MAX_TURRET_TYPE, ION_TURRET, MISSILE_TURRET, TRACTOR_TURRET
struct turret_type turretstats[MAX_TURRET_TYPE] =
{
{ TURBOLASER_TURRET, 100, 250,
"Turbo-laser Mount",
"You are hit by turbolasers from %s!",
"Turboasers fire from %s, hitting %s.",
"The turbo-laser fires at %s, scoring a hit.",
"Turbolasers fire from %s at you but miss.",
"Turbolasers fire from %s at %s but miss.",
"The turbo-laser fires at %s and misses."
},
{ QUAD_TURRET, 25, 50,
"Quad-cannon Mount",
"You are hit by a quad cannon from %s!",
"Laser cannon fire from %s, hitting %s.",
"The laser cannon fires at %s, scoring a hit.",
"Laser cannon fire from %s at flash by you but miss.",
"Laser cannon fire from %s flash at %s but miss.",
"The laser cannon fires at %s and misses."
},
{ ION_TURRET, -25, -50,
"Ion-cannon Mount",
"You are hit by an ion cannon from %s!",
"Ion cannon fire from %s, hitting %s.",
"The ion cannon fires at %s, scoring a hit.",
"Ion cannon fire from %s at flash by you but miss.",
"Ion cannon fire from %s flash at %s but miss.",
"The ion cannon fires at %s and misses."
},
{ MISSILE_TURRET, 1, 1,
"Missile Launcher Mount",
"You are launched on by a missile turret from %s!",
"A missile launcher fires from %s.",
"The launcher fires at %s.",
"Not used",
"Not used",
"The launcher attempts to launch on %s but misfires."
},
{ TRACTOR_TURRET, 1, 1,
"Tractor Beam Mount",
"You are captured by a tractor beam from %s!",
"%s captures %s with a tractor beam.",
"The tractor beam locks on to %s.",
"A tractor beam from %s attempts to capture you but loses lock.",
"A tractor beam from %s attempts to capture %s, but loses lock.",
"The tractor beam attempts to capture %s but loses lock."
}
};
/* local routines */
void fread_ship args( ( SHIP_DATA *ship, FILE *fp ) );
void write_ship_list args( ( void ) );
void fread_spaceobject args( ( SPACE_DATA *spaceobject, FILE *fp ) );
bool load_spaceobject args( ( char *spaceobjectfile ) );
void write_spaceobject_list args( ( void ) );
void resetship args( ( SHIP_DATA *ship ) );
void approachland args( ( SHIP_DATA *ship, char *arg ) );
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 *exit , int fall );
bool is_facing( SHIP_DATA *ship , SHIP_DATA *target );
void sound_to_ship( SHIP_DATA *ship , char *argument );
void modtrainer( SHIP_DATA *ship, sh_int shipclass );
void makedebris( SHIP_DATA *ship );
bool space_in_range_h( SHIP_DATA *ship, SPACE_DATA *space);
void dumpship( SHIP_DATA *ship, int destination );
void shipdelete( SHIP_DATA *ship, bool shiplist );
void storeship( SHIP_DATA *ship );
/* 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_LANDED;
if (ship->spaceobject)
ship_from_spaceobject( ship, ship->spaceobject );
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;
}
bool is_bus_stop( int vnum )
{
int bus, stop;
for ( bus = 0; bus < MAX_BUS; bus++ )
for( stop = 0; ( stop < 12 || serin[bus].bus_vnum[stop] != '\0') ; stop++ )
if ( vnum == serin[bus].bus_vnum[stop] )
return TRUE;
return FALSE;
}
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 Kuat Shipyard." );
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 planet of Kuat." );
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_LANDED;
if (turbocar->spaceobject)
ship_from_spaceobject( turbocar, turbocar->spaceobject );
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[MAX_BUS];
/* SHIP_DATA *ship2;
SHIP_DATA *ship3;
SHIP_DATA *ship4;
*/
SHIP_DATA *target;
int destination, bus;
char buf[MAX_STRING_LENGTH];
for( bus = 0; bus < MAX_BUS; bus++ )
ship[bus] = ship_from_cockpit( serin[bus].cockpitvnum );
switch (bus_pos)
{
case 0:
for( bus = 0; bus < MAX_BUS; bus++ )
{
if( ship_from_cockpit( serin[bus].cockpitvnum ) == NULL )
continue;
target = ship_from_hanger( serin[bus].bus_vnum[serin[bus].planetloc] );
if ( target != NULL && !target->spaceobject )
{
sprintf( buf, "An electronic voice says, 'Cannot land at %s ... it seems to have dissapeared.'", serin[bus].bus_stop[serin[bus].planetloc] );
echo_to_ship( AT_CYAN , ship[bus] , buf );
bus_pos = 5;
}
}
/*
target = ship_from_hanger( bus_vnum[bus_planet] );
if ( target != NULL && !target->spaceobject )
{
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->spaceobject )
{
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_vnum2[bus3_planet] );
if ( target != NULL && !target->spaceobject )
{
sprintf( buf, "An electronic voice says, 'Cannot land at %s ... it seems to have dissapeared.'", bus_stoprev[bus_planet] );
echo_to_ship( AT_CYAN , ship3 , buf );
bus_pos = 5;
}
target = ship_from_hanger( bus_vnum2[bus4_planet] );
if ( target != NULL && !target->spaceobject )
{
sprintf( buf, "An electronic voice says, 'Cannot land at %s ... it seems to have dissapeared.'", bus_stoprev[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 );
*/
for( bus = 0; bus < MAX_BUS; bus++ )
{
if( ship_from_cockpit( serin[bus].cockpitvnum ) == NULL )
continue;
launch_bus( ship[bus] );
}
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.");
*/
for( bus = 0; bus < MAX_BUS; bus++ )
{
if( ship_from_cockpit( serin[bus].cockpitvnum ) == NULL )
continue;
echo_to_ship( AT_YELLOW , ship[bus] , "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..");
*/
for( bus = 0; bus < MAX_BUS; bus++ )
{
if( ship_from_cockpit( serin[bus].cockpitvnum ) == NULL )
continue;
echo_to_ship( AT_YELLOW , ship[bus] , "The ship lurches slightly as it comes out of hyperspace.");
}
bus_pos++;
break;
case 1:
for( bus = 0; bus < MAX_BUS; bus++ )
{
if( ship_from_cockpit( serin[bus].cockpitvnum ) == NULL )
continue;
destination = serin[bus].bus_vnum[serin[bus].planetloc];
if ( !land_bus( ship[bus], destination ) )
{
sprintf( buf, "An electronic voice says, 'Oh My, %s seems to have dissapeared.'" , serin[bus].bus_stop[serin[bus].planetloc] );
echo_to_ship( AT_CYAN , ship[bus] , buf );
echo_to_ship( AT_CYAN , ship[bus] , "An electronic voice says, 'Alderaan was bad enough... Landing aborted.'");
}
else
{
sprintf( buf, "An electronic voice says, 'Welcome to %s'" , serin[bus].bus_stop[serin[bus].planetloc] );
echo_to_ship( AT_CYAN , ship[bus] , buf);
echo_to_ship( AT_CYAN , ship[bus] , "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[bus2_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_vnum2[bus3_planet];
if ( !land_bus( ship3, destination ) )
{
sprintf( buf, "An electronic voice says, 'Oh My, %s seems to have dissapeared.'" , bus_stoprev[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_stoprev[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_vnum2[bus4_planet];
if ( !land_bus( ship4, destination ) )
{
sprintf( buf, "An electronic voice says, 'Oh My, %s seems to have dissapeared.'" , bus_stoprev[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_stoprev[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:
for( bus = 0; bus < MAX_BUS; bus++)
{
if( ship_from_cockpit( serin[bus].cockpitvnum ) == NULL )
continue;
sprintf( buf, "It continues, 'Next stop, %s'" , serin[bus].bus_stop[serin[bus].planetloc+1] );
echo_to_ship( AT_CYAN , ship[bus] , "An electronic voice says, 'Preparing for launch.'");
echo_to_ship( AT_CYAN , ship[bus] , 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_stoprev[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_stoprev[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;
for( bus = 0; bus < MAX_BUS; bus++ )
{
serin[bus].planetloc++;
if( serin[bus].bus_vnum[serin[bus].planetloc] == serin[bus].bus_vnum[0] )
serin[bus].planetloc = 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;
SPACE_DATA *spaceobj;
float dx, dy, dz, change;
char buf[MAX_STRING_LENGTH];
CHAR_DATA *ch;
bool ch_found = FALSE;
sh_int crashsun = 0;
int speed;
for( spaceobj = first_spaceobject; spaceobj; spaceobj = spaceobj->next )
{
if ( spaceobj->speed > 0 )
{
change = sqrt( spaceobj->hx*spaceobj->hx + spaceobj->hy*spaceobj->hy + spaceobj->hz*spaceobj->hz );
if (change > 0)
{
dx = spaceobj->hx/change;
dy = spaceobj->hy/change;
dz = spaceobj->hz/change;
spaceobj->xpos += (dx * spaceobj->speed/5);
spaceobj->ypos += (dy * spaceobj->speed/5);
spaceobj->zpos += (dz * spaceobj->speed/5);
}
}
if( spaceobj->xpos > MAX_COORD )
spaceobj->xpos = -MAX_COORD_S;
if( spaceobj->ypos > MAX_COORD )
spaceobj->ypos = -MAX_COORD_S;
if( spaceobj->zpos > MAX_COORD )
spaceobj->zpos = -MAX_COORD_S;
if( spaceobj->xpos < -MAX_COORD )
spaceobj->xpos = MAX_COORD_S;
if( spaceobj->ypos < -MAX_COORD )
spaceobj->ypos = MAX_COORD_S;
if( spaceobj->zpos < -MAX_COORD )
spaceobj->zpos = MAX_COORD_S;
}
for ( missile = first_missile; missile; missile = m_next )
{
m_next = missile->next;
ship = missile->fired_from;
target = missile->target;
if ( target->spaceobject && missile_in_range( ship, missile ) )
{
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( (int) ( missile->mx-target->vx )) <= 20 && abs( (int) ( missile->mx-target->vx )) >= -20
&& abs( (int) ( missile->my-target->vy )) <= 20 && abs( (int) ( missile->my-target->vy )) >= -20
&& abs((int) ( missile->mz-target->vz )) <= 20 && abs( (int) ( missile->mz-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 , 30+missile->missiletype*missile->missiletype*30 ,
50+missile->missiletype*missile->missiletype*missile->missiletype*50 , ch );
}
if ( !ch_found )
damage_ship( target , ship, 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
{
missile->age++;
if (missile->age >= 50)
extract_missile( missile );
}
}
for ( ship = first_ship; ship; ship = ship->next )
{
if ( ship->shipstate != SHIP_HYPERSPACE && ship->accel && ship->currspeed != ship->goalspeed )
{
if( ship->goalspeed > ship->currspeed )
{
ship->currspeed += ship->accel;
if ( ship->currspeed > ship->goalspeed )
ship->currspeed = ship->goalspeed;
}
else if( ship->goalspeed < ship->currspeed )
{
ship->currspeed -= ship->accel;
if ( ship->currspeed < ship->goalspeed )
ship->currspeed = ship->goalspeed;
}
else if ( ship->currspeed <= 0 && ship->goalspeed <= 0 && ship->accel )
{
ship->accel = 0;
echo_to_cockpit( AT_YELLOW, ship, "Your computer beeps as the ship reaches a stop.");
sprintf( buf, "%s slows to a stop." , ship->name );
echo_to_system( AT_ORANGE , ship , buf , NULL );
}
else if ( ship->currspeed >= ship->realspeed && ship->goalspeed >= ship->realspeed && ship->accel )
{
ship->accel = 0;
echo_to_cockpit( AT_YELLOW, ship, "Your computer beeps as the ship reaches max speed.");
sprintf( buf, "%s steadies its speed." , ship->name );
echo_to_system( AT_ORANGE , ship , buf , NULL );
}
else if( ship->goalspeed == ship->currspeed && ship->accel )
{
ship->accel = 0;
echo_to_cockpit( AT_YELLOW, ship, "Your computer beeps as the ship reaches designated speed.");
sprintf( buf, "%s steadies its speed." , ship->name );
echo_to_system( AT_ORANGE , ship , buf , NULL );
}
}
if ( !ship->spaceobject )
continue;
if( ship->shipstate == SHIP_LANDED && ship->spaceobject )
ship->shipstate = SHIP_READY;
if ( ship->currspeed > 0 && ship->shipstate != SHIP_LAND && ship->shipstate != SHIP_LAND_2)
{
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 ( ship->tractoredby && ( ship->tractoredby->shipclass <= ship->shipclass || ship->shipclass == SHIP_DEBRIS ) )
{
ship->tractoredby->currspeed = (ship->tractoredby->mod->tractorbeam)/4;
ship->tractoredby->currspeed = UMAX( ship->tractoredby->currspeed, ship->currspeed );
ship->tractoredby->hx = ship->vx - ship->tractoredby->vx;
ship->tractoredby->hy = ship->vy - ship->tractoredby->vy;
ship->tractoredby->hz = ship->vz - ship->tractoredby->vz;
/*
float hx,hy,hz;
hx = ship->tractoredby->vx - ship->vx;
hy = ship->tractoredby->vy - ship->vy;
hz = ship->tractoredby->vz - ship->vz;
change = sqrt( hx*hx + hy*hy + hz*hz );
if (change > 0)
{
dx = hx/change;
dy = hy/change;
dz = hz/change;
ship->vx += UMIN( hx, (dx * (ship->tractoredby->currspeed+25)/5));
ship->vy += UMIN( hy, (dy * (ship->tractoredby->currspeed+25)/5));
ship->vz += UMIN( hz, (dz * (ship->tractoredby->currspeed+25)/5));
}
*/
}
if ( ship->tractoredby && ship->tractoredby->shipclass > ship->shipclass )
{
ship->currspeed = ship->tractoredby->mod->tractorbeam/4;
ship->currspeed = UMAX( ship->currspeed, ship->tractoredby->currspeed );
ship->hx = ship->tractoredby->vx - ship->vx;
ship->hy = ship->tractoredby->vy - ship->vy;
ship->hz = ship->tractoredby->vz - ship->vz;
/*
float hx,hy,hz;
hx = ship->tractored->vx - ship->vx;
hy = ship->tractored->vy - ship->vy;
hz = ship->tractored->vz - ship->vz;
change = sqrt( hx*hx + hy*hy + hz*hz );
if (change > 0)
{
dx = hx/change;
dy = hy/change;
dz = hz/change;
ship->vx += UMIN( hx, (dx * (ship->tractored->currspeed+25)/5));
ship->vy += UMIN( hy, (dy * (ship->tractored->currspeed+25)/5));
ship->vz += UMIN( hz, (dz * (ship->tractored->currspeed+25)/5));
}
*/
}
if ( ship->tractoredby )
{
if ( abs( (int) ( ship->vx - ship->tractoredby->vx )) < 10 &&
abs( (int) ( ship->vy - ship->tractoredby->vy )) < 10 &&
abs( (int) ( ship->vz - ship->tractoredby->vz )) < 10 )
{
if ( ship->shipclass < ship->tractoredby->shipclass )
{
ship->vx = ship->tractoredby->vx;
ship->vy = ship->tractoredby->vy;
ship->vz = ship->tractoredby->vz;
}
if ( ship->shipclass >= ship->tractoredby->shipclass )
{
ship->tractoredby->vx = ship->vx;
ship->tractoredby->vy = ship->vy;
ship->tractoredby->vz = ship->vz;
}
}
}
if ( autofly(ship) )
continue;
for( spaceobj = first_spaceobject; spaceobj; spaceobj = spaceobj->next )
{
/* if ( ship->shipclass != SHIP_PLATFORM && !autofly(ship) && ship->currspeed < 50)
{
if ( (spaceobj->gravity > 50) && strcmp(spaceobj->name,"") && space_in_range( ship, spaceobj ) )
{
if (ship->vx >= spaceobj->xpos + 1 || ship->vx <= spaceobj->xpos - 1 )
ship->vx -= URANGE(-3,(spaceobj->gravity)/(ship->vx - spaceobj->xpos)/2,3);
if (ship->vy >= spaceobj->ypos + 1 || ship->vy <= spaceobj->ypos - 1 )
ship->vy -= URANGE(-3,(spaceobj->gravity)/(ship->vy - spaceobj->ypos)/2,3);
if (ship->vz >= spaceobj->zpos + 1 || ship->vz <= spaceobj->zpos - 1 )
ship->vz -= URANGE(-3,(spaceobj->gravity)/(ship->vz - spaceobj->zpos)/2,3);
}
}
*/
/*
for ( target = ship->spaceobject->first_ship; target; target = target->next_in_spaceobject)
{
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 ( spaceobj->type == SPACE_SUN && spaceobj->name && strcmp(spaceobj->name,"") &&
abs( (int) ( ship->vx - spaceobj->xpos )) < 10 &&
abs( (int) ( ship->vy - spaceobj->ypos )) < 10 &&
abs( (int) ( ship->vz - spaceobj->zpos )) < 10 )
{
/* Why the redundence of code here?
Only need to evade once. Darrik Vequir */
crashsun = 1;
}
if (crashsun == 1)
{
/* Evading the sun added by Darrik Vequir */
ship->hx = 10 * ship->vx;
ship->hy = 10 * ship->vy;
ship->hz = 10 * ship->vz;
ship->energy -= ship->currspeed/10;
ship->goalspeed = ship->mod->realspeed;
ship->accel = get_acceleration(ship);
echo_to_room( AT_RED , get_room_index(ship->pilotseat), "Automatic Override: Evading to avoid collision with sun!\n\r" );
if ( ship->shipclass == FIGHTER_SHIP || ( ship->shipclass == MIDSIZE_SHIP && ship->mod->manuever > 50 ) )
ship->shipstate = SHIP_BUSY_3;
else if ( ship->shipclass == MIDSIZE_SHIP || ( ship->shipclass == CAPITAL_SHIP && ship->mod->manuever > 50 ) )
ship->shipstate = SHIP_BUSY_2;
else
ship->shipstate = SHIP_BUSY;
}
/*
echo_to_cockpit( AT_BLOOD+AT_BLINK, ship, "You fly directly into the sun.");
sprintf( buf , "%s flys directly into %s!", ship->name, ship->spaceobject->star2);
echo_to_system( AT_ORANGE , ship , buf , NULL );
destroy_ship(ship , NULL);
continue;
*/
if ( ship->currspeed > 0 )
{
if ( spaceobj->type >= SPACE_PLANET && spaceobj->name && strcmp(spaceobj->name,"") &&
abs( (int) ( ship->vx - spaceobj->xpos )) < 10 &&
abs( (int) ( ship->vy - spaceobj->ypos )) < 10 &&
abs( (int) ( ship->vz - spaceobj->zpos )) < 10 )
{
sprintf( buf , "You begin orbitting %s.", spaceobj->name);
echo_to_cockpit( AT_YELLOW, ship, buf);
sprintf( buf , "%s begins orbiting %s.", ship->name, spaceobj->name);
echo_to_system( AT_ORANGE , ship , buf , NULL );
ship->inorbitof = spaceobj;
ship->currspeed = 0;
}
}
}
}
for ( ship = first_ship; ship; ship = ship->next )
{
if (ship->shipstate == SHIP_HYPERSPACE)
{
float tx, ty, tz;
float dist, origdist;
ship->hyperdistance -= ship->mod->hyperspeed;
dist = (float) ship->hyperdistance;
origdist = (float) ship->orighyperdistance;
if ( dist == 0)
dist = -1;
tx = ( ship->vx - ship->jx );
ty = ( ship->vy - ship->jy );
tz = ( ship->vz - ship->jz );
ship->cx = ship->vx - (tx*(dist/origdist));
ship->cy = ship->vy - (ty*(dist/origdist));
ship->cz = ship->vz - (tz*(dist/origdist));
ship->count++;
for( spaceobj = first_spaceobject; spaceobj; spaceobj = spaceobj->next )
if( space_in_range_h( ship, spaceobj ) )
{
int damage;
echo_to_room( AT_YELLOW, get_room_index(ship->pilotseat), "Hyperjump complete.");
echo_to_ship( AT_YELLOW, ship, "The ship slams to a halt as it comes out of hyperspace.");
// 2/18/04 - Johnson - Modified call to reflect origin of object entering the system
//sprintf( buf ,"%s enters the starsystem at %.0f %.0f %.0f" , ship->name, ship->vx, ship->vy, ship->vz );
sprintf( buf ,"%s enters the starsystem from hyperspace at %.0f %.0f %.0f" , ship->name, ship->vx, ship->vy, ship->vz );
damage = 15* number_range( 1, 4 );
ship->hull -= damage;
echo_to_ship( AT_YELLOW, ship, "The hull cracks from the pressure.");
ship->vx = ship->cx;
ship->vy = ship->cy;
ship->vz = ship->cz;
ship_to_spaceobject( ship, ship->currjump );
ship->currjump = NULL;
echo_to_system( AT_YELLOW, ship, buf , NULL );
ship->shipstate = SHIP_READY;
STRFREE( ship->home );
ship->home = STRALLOC( ship->spaceobject->name );
}
for( target = first_ship; target; target= target->next )
if (target && ship && target != ship )
{
if ( target->spaceobject && ship->spaceobject &&
target->shipstate != SHIP_LANDED &&
target->mod && target->mod->gravproj && target->mod->gravitypower &&
abs( (int) ( ship->vx - target->vx )) < 10*target->mod->gravproj &&
abs( (int) ( ship->vy - target->vy )) < 10*target->mod->gravproj &&
abs( (int) ( ship->vz - target->vz )) < 10*target->mod->gravproj)
break;
}
if( target )
{
echo_to_room( AT_YELLOW, get_room_index(ship->pilotseat), "Hyperjump complete.");
echo_to_ship( AT_YELLOW, ship, "The ship slams to a halt as it comes out of hyperspace. An artificial gravity well surrounds you!");
// 2/18/04 - Johnson - Modified call to reflect origin of object entering the system
//sprintf( buf ,"%s enters the starsystem at %.0f %.0f %.0f" , ship->name, ship->vx, ship->vy, ship->vz );
sprintf( buf ,"%s slams into a gravity well at %.0f %.0f %.0f" , ship->name, ship->vx, ship->vy, ship->vz );
ship->vx = ship->cx;
ship->vy = ship->cy;
ship->vz = ship->cz;
ship_to_spaceobject( ship, ship->currjump );
ship->currjump = NULL;
echo_to_system( AT_YELLOW, ship, buf , NULL );
ship->shipstate = SHIP_READY;
STRFREE( ship->home );
ship->home = STRALLOC( ship->spaceobject->name );
}
if (ship->shipstate == SHIP_HYPERSPACE && ship->hyperdistance <= 0 && !ship->tracking)
{
ship->count = 0;
ship_to_spaceobject (ship, ship->currjump);
if (ship->spaceobject == 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.");
// 2/18/04 - Johnson - Modified call to reflect origin of object entering the system
//sprintf( buf ,"%s enters the starsystem at %.0f %.0f %.0f" , ship->name, ship->vx, ship->vy, ship->vz );
sprintf( buf ,"%s enters the starsystem from hyperspace at %.0f %.0f %.0f" , ship->name, ship->vx, ship->vy, ship->vz );
ship->cx = ship->vx;
ship->cy = ship->vy;
ship->cz = ship->vz;
ship_to_spaceobject( ship, ship->currjump );
ship->currjump = NULL;
echo_to_system( AT_YELLOW, ship, buf , NULL );
ship->shipstate = SHIP_READY;
STRFREE( ship->home );
ship->home = STRALLOC( ship->spaceobject->name );
}
}
else if ( ( ship->count >= (ship->tcount ? ship->tcount : 10 ) ) && ship->shipstate == SHIP_HYPERSPACE && ship->tracking == TRUE)
{
ship_to_spaceobject (ship, ship->currjump);
if (ship->spaceobject == 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.");
// 2/18/04 - Johnson - Modified call to reflect origin of object entering the system
//sprintf( buf ,"%s enters the starsystem at %.0f %.0f %.0f" , ship->name, ship->vx, ship->vy, ship->vz );
sprintf( buf ,"%s enters the starsystem from hyperspace at %.0f %.0f %.0f" , ship->name, ship->vx, ship->vy, ship->vz );
ship->vx = ship->cx;
ship->vy = ship->cy;
ship->vz = ship->cz;
ship_to_spaceobject( ship, ship->currjump );
ship->currjump = NULL;
echo_to_system( AT_YELLOW, ship, buf , NULL );
ship->shipstate = SHIP_READY;
STRFREE( ship->home );
ship->home = STRALLOC( ship->spaceobject->name );
speed = ship->mod->hyperspeed;
ship->jx = ship->vx + ship->tx;
ship->jy = ship->vy + ship->ty;
ship->jz = ship->vz + ship->tz;
for( spaceobj = first_spaceobject; spaceobj; spaceobj = spaceobj->next )
if( space_in_range( ship, spaceobj ) )
{
ship->currjump = spaceobj;
break;
}
if( !spaceobj )
ship->currjump = ship->spaceobject;
ship->hyperdistance = abs( (int) ( ship->vx - ship->jx )) ;
ship->hyperdistance += abs( (int) ( ship->vy - ship->jy )) ;
ship->hyperdistance += abs( (int) ( ship->vz - ship->jz )) ;
ship->hyperdistance /= 50;
ship->orighyperdistance = ship->hyperdistance;
ship->count = 0;
do_radar( ship->ch, "" );
}
}
else if (ship->count >= 10 && ship->shipstate == SHIP_HYPERSPACE)
{
ship->count = 0;
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 );
}
if( ship->shipstate == SHIP_HYPERSPACE )
if( ship->count%2 && ship->hyperdistance < 10*ship->mod->hyperspeed && ship->hyperdistance > 0 )
{
sprintf( buf ,"An alarm sounds. Your hyperjump is ending: %d" , ship->hyperdistance );
echo_to_ship( AT_RED , ship, buf );
}
}
if( ship->docked )
{
ship->vx = ship->docked->vx;
ship->vy = ship->docked->vy;
ship->vz = ship->docked->vz;
ship->cx = ship->docked->cx;
ship->cy = ship->docked->cy;
ship->cz = ship->docked->cz;
ship->ox = ship->docked->ox;
ship->oy = ship->docked->oy;
ship->oz = ship->docked->oz;
ship->jx = ship->docked->jx;
ship->jy = ship->docked->jy;
ship->jz = ship->docked->jz;
ship->hx = ship->docked->hx;
ship->hy = ship->docked->hy;
ship->hz = ship->docked->hz;
ship->shipstate = ship->docked->shipstate;
ship->hyperdistance = ship->docked->hyperdistance;
ship->currspeed = ship->docked->currspeed;
ship->orighyperdistance = ship->docked->orighyperdistance;
ship->location = ship->docked->location;
ship->dest = ship->docked->dest;
ship->spaceobject = ship->docked->spaceobject;
ship->currjump = ship->docked->currjump;
}
if( ship->vx > MAX_COORD)
ship->vx = -MAX_COORD_S;
if( ship->vy > MAX_COORD)
ship->vy = -MAX_COORD_S;
if( ship->vz > MAX_COORD)
ship->vz = -MAX_COORD_S;
if( ship->vx > MAX_COORD)
ship->vx = MAX_COORD_S;
if( ship->vy > MAX_COORD)
ship->vy = MAX_COORD_S;
if( ship->vz > MAX_COORD)
ship->vz = MAX_COORD_S;
}
/*
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 , NULL, ship->collision , ship->collision );
ship->collision = 0;
}
*/
}
void recharge_ships( )
{
SHIP_DATA *ship;
char buf[MAX_STRING_LENGTH];
bool closeem = FALSE;
int distance, origchance = 100;
TURRET_DATA *turret;
baycount++;
if ( baycount >= 60 )
{
closeem = TRUE;
baycount = 0;
}
for ( ship = first_ship; ship; ship = ship->next )
{
if ( ship->shipclass == 3 )
if ( closeem && ship->guard )
ship->bayopen = FALSE;
if (ship->statet0 > 0)
{
ship->energy -= ship->statet0;
ship->statet0 = 0;
}
if (ship->statei0 > 0)
{
ship->energy -= 10*ship->statei0;
ship->statei0 = 0;
}
if (ship->first_turret)
for( turret = ship->first_turret; turret; turret = turret->next )
if (turret->state > 0)
{
ship->energy -= turret->state;
turret->state = 0;
}
if( ship->docked && ship->docked->shipclass == SHIP_PLATFORM )
{
if( ship->mod->maxenergy - ship->energy > 500 )
ship->energy += 500;
else
ship->energy = ship->mod->maxenergy;
}
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->spaceobject && ship->shipclass != SHIP_DEBRIS )
{
if (ship->target0 && ship->statet0 != LASER_DAMAGED )
{
int chance = 75;
SHIP_DATA * target = ship->target0;
int shots, guns, laserguns, ionguns;
int whichguns = 0;
int laserhits = 0, lasermisses = 0;
int ionhits = 0, ionmisses = 0;
int laserdamage = 0, iondamage = 0;
int damage = 0;
if ( ship->mod->lasers && ship->mod->ions && ship->mod->lasers < 7 && ship->mod->ions < 7 )
{
whichguns = 2;
guns = ship->mod->lasers + ship->mod->ions;
laserguns = ship->mod->lasers;
ionguns = ship->mod->ions;
}
else if ( ship->target0->shield > 0 && ship->mod->ions )
{
whichguns = 1;
guns = ship->mod->ions;
laserguns = 0;
ionguns = ship->mod->ions;
}
else
{
guns = ship->mod->lasers;
laserguns = ship->mod->lasers;
ionguns = 0;
}
for ( shots=0 ; shots < guns; shots++ )
{
if ( !ship->target0 )
break;
if (ship->shipstate != SHIP_HYPERSPACE && ship->energy > 25
&& ship_in_range( ship, target )
&& abs( (int) ( target->vx - ship->vx )) <= 1000
&& abs( (int) ( target->vy - ship->vy )) <= 1000
&& abs( (int) ( target->vz - ship->vz )) <= 1000 )
{
if ( ship->shipclass > 1 || is_facing ( ship , target ) )
{
distance = abs( (int) ( target->vx - ship->vx ))
+ abs( (int) ( target->vy - ship->vy ))
+ abs( (int) ( target->vz - ship->vz ));
distance /= 3;
chance += target->shipclass - ship->shipclass;
chance += ship->currspeed - target->currspeed;
chance += ship->mod->manuever - target->mod->manuever;
chance -= distance/(10*(target->shipclass+1));
chance -= origchance;
chance /= 2;
chance += origchance;
chance = URANGE( 1 , chance , 99 );
if ( number_percent( ) > chance )
{
whichguns == 0 ? lasermisses++ : ( whichguns == 1 ? ionmisses++ : ( shots < ship->mod->lasers ? lasermisses++ : ionmisses++ ) );
}
else
{
if( whichguns == 0 )
{
laserhits++;
if ( ship->shipclass == SHIP_PLATFORM )
{
damage = number_range( SHIPDAM_MINPLATFORM , SHIPDAM_MAXPLATFORM );
}
else if( ship->shipclass == CAPITAL_SHIP && target->shipclass != CAPITAL_SHIP )
damage = number_range( SHIPDAM_MINCAP, SHIPDAM_MAXCAP );
else
damage = number_range( SHIPDAM_MINDEF , SHIPDAM_MAXDEF );
laserdamage += damage;
}
else if( whichguns == 1 )
{
ionhits++;
if ( ship->shipclass == SHIP_PLATFORM )
{
damage = number_range( SHIPDAM_MINPLATFORM , SHIPDAM_MAXPLATFORM );
}
else if( ship->shipclass == CAPITAL_SHIP && target->shipclass != CAPITAL_SHIP )
damage = number_range( SHIPDAM_MINCAP, SHIPDAM_MAXCAP );
else
damage = number_range( SHIPDAM_MINDEF , SHIPDAM_MAXDEF );
iondamage += damage;
}
else if( whichguns == 2 )
{
if( shots < ship->mod->lasers )
{
laserhits++;
if ( ship->shipclass == SHIP_PLATFORM )
{
damage = number_range( SHIPDAM_MINPLATFORM , SHIPDAM_MAXPLATFORM );
}
else if( ship->shipclass == CAPITAL_SHIP && target->shipclass != CAPITAL_SHIP )
damage = number_range( SHIPDAM_MINCAP, SHIPDAM_MAXCAP );
else
damage = number_range( SHIPDAM_MINDEF , SHIPDAM_MAXDEF );
laserdamage += damage;
}
else
{
ionhits++;
if ( ship->shipclass == SHIP_PLATFORM )
{
damage = number_range( SHIPDAM_MINPLATFORM , SHIPDAM_MAXPLATFORM );
}
else if( ship->shipclass == CAPITAL_SHIP && target->shipclass != CAPITAL_SHIP )
damage = number_range( SHIPDAM_MINCAP, SHIPDAM_MAXCAP );
else
damage = number_range( SHIPDAM_MINDEF , SHIPDAM_MAXDEF );
iondamage += damage;
}
}
}
}
}
}
if ( laserhits )
{
if ( lasermisses )
{
sprintf( buf, "%s fires %d lasers at you, hitting you %d times.\n\r",
ship->name, laserguns, laserhits );
echo_to_cockpit( AT_BLOOD , target , buf );
sprintf( buf, "%s fires %d lasers at %s, hitting %d times.\n\r",
ship->name, laserguns, target->name, laserhits );
echo_to_system( AT_ORANGE , target , buf , NULL );
}
else
{
sprintf( buf, "%s fires %d lasers at you, hitting you %d times.\n\r",
ship->name, laserguns, laserhits );
echo_to_cockpit( AT_BLOOD , target , buf );
sprintf( buf, "%s fires %d lasers at %s, hitting %d times.\n\r",
ship->name, laserguns, target->name, laserhits );
echo_to_system( AT_ORANGE , target , buf , NULL );
}
damage_ship ( target, ship, laserdamage, laserdamage+1 );
}
else if ( lasermisses )
{
sprintf( buf, "%s fires its lasers at you, missing you %d times.\n\r",
ship->name, lasermisses );
echo_to_cockpit( AT_BLOOD , target , buf );
sprintf( buf, "%s fires its lasers at %s, missing %d times.\n\r",
ship->name, target->name, lasermisses );
echo_to_system( AT_ORANGE , target , buf , NULL );
}
if ( ionhits )
{
if ( ionmisses )
{
sprintf( buf, "%s fires %d ion cannons at you, hitting you %d times.\n\r",
ship->name, ionguns, ionhits );
echo_to_cockpit( AT_BLOOD , target , buf );
sprintf( buf, "%s fires %d ion cannons at %s, hitting %d times.\n\r",
ship->name, ionguns, target->name, ionhits );
echo_to_system( AT_ORANGE , target , buf , NULL );
}
else
{
sprintf( buf, "%s fires %d ion cannons at you, hitting you %d times.\n\r",
ship->name, ionguns, ionhits );
echo_to_cockpit( AT_BLOOD , target , buf );
sprintf( buf, "%s fires %d ion cannons at %s, hitting %d times.\n\r",
ship->name, ionguns, target->name, ionhits );
echo_to_system( AT_ORANGE , target , buf , NULL );
}
damage_ship ( target, ship, -1*iondamage, -1*(iondamage-1) );
}
else if ( ionmisses )
{
sprintf( buf, "%s fires its ion cannons at you, missing you %d times.\n\r",
ship->name, ionmisses );
echo_to_cockpit( AT_BLOOD , target , buf );
sprintf( buf, "%s fires its ions cannons at %s, missing %d times.\n\r",
ship->name, target->name, ionmisses );
echo_to_system( AT_ORANGE , target , buf , NULL );
}
}
}
}
if ( autofly(ship) )
{
if ( ship->spaceobject && ship->shipclass != SHIP_DEBRIS )
{
if (ship->target0 && ship->statet0 != LASER_DAMAGED )
{
int chance = 75;
SHIP_DATA * target = ship->target0;
int shots, guns, laserguns, ionguns;
int whichguns = 0;
int laserhits = 0, lasermisses = 0;
int ionhits = 0, ionmisses = 0;
int laserdamage = 0, iondamage = 0;
int damage = 0;
if ( ship->mod->lasers && ship->mod->ions && ship->mod->lasers < 7 && ship->mod->ions < 7 )
{
whichguns = 2;
guns = ship->mod->lasers + ship->mod->ions;
laserguns = ship->mod->lasers;
ionguns = ship->mod->ions;
}
else if ( ship->target0->shield > 0 && ship->mod->ions )
{
whichguns = 1;
guns = ship->mod->ions;
laserguns = 0;
ionguns = ship->mod->ions;
}
else
{
guns = ship->mod->lasers;
laserguns = ship->mod->lasers;
ionguns = 0;
}
for ( shots=0 ; shots < guns; shots++ )
{
if ( !ship->target0 )
break;
if (ship->shipstate != SHIP_HYPERSPACE && ship->energy > 25
&& ship_in_range( ship, target )
&& abs( (int) ( target->vx - ship->vx )) <= 1000
&& abs( (int) ( target->vy - ship->vy )) <= 1000
&& abs( (int) ( target->vz - ship->vz )) <= 1000 )
{
if ( ship->shipclass > 1 || is_facing ( ship , target ) )
{
distance = abs( (int) ( target->vx - ship->vx ))
+ abs( (int) ( target->vy - ship->vy ))
+ abs( (int) ( target->vz - ship->vz ));
distance /= 3;
chance += target->shipclass - ship->shipclass;
chance += ship->currspeed - target->currspeed;
chance += ship->mod->manuever - target->mod->manuever;
chance -= distance/(10*(target->shipclass+1));
chance -= origchance;
chance /= 2;
chance += origchance;
chance = URANGE( 1 , chance , 99 );
if ( number_percent( ) > chance )
{
whichguns == 0 ? lasermisses++ : ( whichguns == 1 ? ionmisses++ : ( shots < ship->mod->lasers ? lasermisses++ : ionmisses++ ) );
}
else
{
if( whichguns == 0 )
{
laserhits++;
if ( ship->shipclass == SHIP_PLATFORM )
{
damage = number_range( SHIPDAM_MINPLATFORM , SHIPDAM_MAXPLATFORM );
}
else if( ship->shipclass == CAPITAL_SHIP && target->shipclass != CAPITAL_SHIP )
damage = number_range( SHIPDAM_MINCAP, SHIPDAM_MAXCAP );
else
damage = number_range( SHIPDAM_MINDEF , SHIPDAM_MAXDEF );
laserdamage += damage;
}
else if( whichguns == 1 )
{
ionhits++;
if ( ship->shipclass == SHIP_PLATFORM )
{
damage = number_range( SHIPDAM_MINPLATFORM , SHIPDAM_MAXPLATFORM );
}
else if( ship->shipclass == CAPITAL_SHIP && target->shipclass != CAPITAL_SHIP )
damage = number_range( SHIPDAM_MINCAP, SHIPDAM_MAXCAP );
else
damage = number_range( SHIPDAM_MINDEF , SHIPDAM_MAXDEF );
iondamage += damage;
}
else if( whichguns == 2 )
{
if( shots < ship->mod->lasers )
{
laserhits++;
if ( ship->shipclass == SHIP_PLATFORM )
{
damage = number_range( SHIPDAM_MINPLATFORM , SHIPDAM_MAXPLATFORM );
}
else if( ship->shipclass == CAPITAL_SHIP && target->shipclass != CAPITAL_SHIP )
damage = number_range( SHIPDAM_MINCAP, SHIPDAM_MAXCAP );
else
damage = number_range( SHIPDAM_MINDEF , SHIPDAM_MAXDEF );
laserdamage += damage;
}
else
{
ionhits++;
if ( ship->shipclass == SHIP_PLATFORM )
{
damage = number_range( SHIPDAM_MINPLATFORM , SHIPDAM_MAXPLATFORM );
}
else if( ship->shipclass == CAPITAL_SHIP && target->shipclass != CAPITAL_SHIP )
damage = number_range( SHIPDAM_MINCAP, SHIPDAM_MAXCAP );
else
damage = number_range( SHIPDAM_MINDEF , SHIPDAM_MAXDEF );
iondamage += damage;
}
}
}
}
}
}
if ( laserhits )
{
if ( lasermisses )
sprintf( buf, "%s fires %d lasers at you, hitting you %d times and missing you %d times.\n\r",
ship->name, laserguns, laserhits, lasermisses );
else
sprintf( buf, "%s fires %d lasers at you, hitting you %d times.\n\r",
ship->name, laserguns, laserhits );
damage_ship ( target, ship, laserdamage, laserdamage+1 );
}
else if ( lasermisses )
{
sprintf( buf, "%s fires its lasers at you, missing you %d times.\n\r",
ship->name, lasermisses );
}
if ( ionhits )
{
if ( ionmisses )
sprintf( buf, "%s fires %d ion cannons at you, hitting you %d times and missing you %d times.\n\r",
ship->name, ionguns, ionhits, ionmisses );
else
sprintf( buf, "%s fires %d ion cannons at you, hitting you %d times.\n\r",
ship->name, ionguns, ionhits );
damage_ship ( target, ship, -1*iondamage, -1*(iondamage-1) );
}
else if ( ionmisses )
{
sprintf( buf, "%s fires its ion cannons at you, missing you %d times.\n\r",
ship->name, ionmisses );
}
}
}
}
}
}
void update_space( )
{
SHIP_DATA *ship;
SHIP_DATA *target;
char buf[MAX_STRING_LENGTH];
int too_close, target_too_close;
SPACE_DATA *spaceobj;
TURRET_DATA *turret;
int recharge;
for ( ship = first_ship; ship; ship = ship->next )
{
if ( ship->spaceobject && ship->energy > 0 && ship->shipstate == SHIP_DISABLED && ship->shipclass != SHIP_PLATFORM )
ship->energy -= 100;
else if (ship->energy > 0 && ( !ship->mod || !ship->mod->gravproj ) ) // Energy does not recharge when gravity wells are activated - DV 8/7/02
ship->energy += (5 + ship->shipclass * 5);
else if (ship->mod && ship->mod->gravproj ) // Energy drains 1/100th of gravity power every space pulse - DV 8/7/02
ship->energy -= ship->mod->gravproj/100;
else
ship->energy = 0;
if ( ship->chaff_released > 0 )
ship->chaff_released--;
/* 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_READY && ship->tracking == TRUE )
{
if( ship->count == 0 )
{
ship->count++;
}
else
{
do_hyperspace( ship->ch, "" );
ship->count = 0;
}
}
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)
{
approachland( ship, ship->dest );
ship->shipstate = SHIP_LAND_2;
}
if (ship->shipstate == SHIP_LAUNCH_2)
launchship( ship );
if (ship->shipstate == SHIP_LAUNCH)
ship->shipstate = SHIP_LAUNCH_2;
if (ship->docking == SHIP_DOCK_2)
dockship( ship->ch , ship );
if (ship->docking == SHIP_DOCK)
ship->docking = SHIP_DOCK_2;
ship->shield = UMAX( 0 , ship->shield-1-ship->shipclass);
if (ship->autorecharge && ship->mod->maxshield > ship->shield && ship->energy > 100)
{
recharge = UMIN( ship->mod->maxshield-ship->shield, 10 + ship->shipclass*10 );
recharge = UMIN( recharge , ship->energy/2 -100 );
recharge = UMAX( 1, recharge );
ship->shield += recharge;
ship->energy -= recharge;
}
if ( autofly(ship) && ( ship->energy >= ((25+ship->shipclass*25)*(2+ship->shipclass) ) )
&& ((ship->mod->maxshield - ship->shield) >= ( 25+ship->shipclass*25 ) ) )
{
recharge = 25+ship->shipclass*25;
recharge = UMIN( ship->mod->maxshield-ship->shield , recharge );
ship->shield += recharge;
ship->energy -= ( recharge*2 + recharge * ship->shipclass );
}
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->spaceobject && 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->spaceobject )
{
too_close = ship->currspeed + 50;
too_close = ship->currspeed + 50;
for( spaceobj = first_spaceobject; spaceobj; spaceobj = spaceobj->next )
if ( spaceobj->name && strcmp(spaceobj->name,"") &&
abs( (int) ( ship->vx - spaceobj->xpos )) < too_close &&
abs( (int) ( ship->vy - spaceobj->ypos )) < too_close &&
abs( (int) ( ship->vz - spaceobj->zpos )) < too_close )
{
sprintf( buf, "Proximity alert: %s %.0f %.0f %.0f", spaceobj->name,
spaceobj->xpos, spaceobj->ypos, spaceobj->zpos);
echo_to_room( AT_RED , get_room_index(ship->pilotseat), buf );
}
for ( target = first_ship; target; target = target->next )
{
if( (target->docked && target->docked == ship) || (ship->docked && ship->docked == target ) )
continue;
if ( ship->docked && target->docked &&
target->docked == ship->docked )
continue;
target_too_close = too_close+target->currspeed;
if( target->spaceobject )
if ( target != ship &&
abs( (int) ( ship->vx - target->vx )) < target_too_close &&
abs( (int) ( ship->vy - target->vy )) < target_too_close &&
abs( (int) ( ship->vz - target->vz )) < target_too_close &&
ship->docked != target && target->docked != ship )
{
sprintf( buf, "Proximity alert: %s %.0f %.0f %.0f"
, target->name, target->vx - ship->vx, target->vy - ship->vy, target->vz - ship->vz);
echo_to_room( AT_RED , get_room_index(ship->pilotseat), buf );
}
}
too_close = ship->currspeed + 100;
}
if (ship->target0 && ship->shipclass <= SHIP_PLATFORM)
{
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_in_range( ship, ship->target0 ) )
{
echo_to_room( AT_LBLUE , get_room_index(ship->gunseat), "Your target seems to have left.");
ship->target0 = NULL;
}
}
if ( ship->first_turret )
for( turret = ship->first_turret; turret; turret = turret->next )
if( turret->target && ship->shipclass <= SHIP_PLATFORM )
{
sprintf( buf, "%s %.0f %.0f %.0f", turret->target->name,
turret->target->vx , turret->target->vy, turret->target->vz );
echo_to_room_dnr( AT_BLUE , get_room_index(turret->roomvnum), "Target: " );
echo_to_room( AT_LBLUE , get_room_index(turret->roomvnum), buf );
if (!ship_in_range( ship, turret->target ) )
{
turret->target = NULL;
echo_to_room( AT_LBLUE , get_room_index(turret->roomvnum), "Your target seems to have left.");
}
}
/* if (ship->target1 && ship->shipclass <= SHIP_PLATFORM)
{
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_in_range( ship, ship->target1 ) )
ship->target1 = NULL;
}
if (ship->target2 && ship->shipclass <= SHIP_PLATFORM)
{
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_in_range( ship, ship->target2 ) )
ship->target2 = NULL;
}
*/
if (ship->energy < 100 && ship->spaceobject )
{
echo_to_cockpit( AT_RED , ship, "Warning: Ship fuel low." );
}
ship->energy = URANGE( 0 , ship->energy, ship->mod->maxenergy );
}
for ( ship = first_ship; ship; ship = ship->next )
{
if( ship->target0 && autofly(ship) )
if( !ship_in_range( ship->target0, ship ) )
{
echo_to_room( AT_BLUE , get_room_index(ship->pilotseat), "Target left, returning to NORMAL condition.\n\r" );
ship->goalspeed = 0;
ship->accel = get_acceleration( ship );
ship->target0 = NULL;
}
if (ship->autotrack && ship->docking == SHIP_READY && ship->target0 && ship->shipclass < 3 )
{
target = ship->target0;
too_close = ship->currspeed + 10;
target_too_close = too_close+target->currspeed;
if ( target != ship && ship->shipstate == SHIP_READY &&
ship->docked == NULL && ship->shipstate != SHIP_DOCKED &&
abs( (int) ( ship->vx - target->vx )) < target_too_close &&
abs( (int) ( ship->vy - target->vy )) < target_too_close &&
abs( (int) ( 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->shipclass == FIGHTER_SHIP || ( ship->shipclass == MIDSIZE_SHIP && ship->mod->manuever > 50 ) )
ship->shipstate = SHIP_BUSY_3;
else if ( ship->shipclass == MIDSIZE_SHIP || ( ship->shipclass == CAPITAL_SHIP && ship->mod->manuever > 50 ) )
ship->shipstate = SHIP_BUSY_2;
else
ship->shipstate = SHIP_BUSY;
}
else if ( !is_facing(ship, ship->target0)
&& ship->docked == NULL && ship->shipstate != SHIP_DOCKED )
{
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->shipclass == FIGHTER_SHIP || ( ship->shipclass == MIDSIZE_SHIP && ship->mod->manuever > 50 ) )
ship->shipstate = SHIP_BUSY_3;
else if ( ship->shipclass == MIDSIZE_SHIP || ( ship->shipclass == CAPITAL_SHIP && ship->mod->manuever > 50 ) )
ship->shipstate = SHIP_BUSY_2;
else
ship->shipstate = SHIP_BUSY;
}
}
if ( autofly(ship) && ship->shipclass != SHIP_DEBRIS )
{
if ( ship->spaceobject )
{
check_hostile( ship );
if (ship->target0 )
{
int chance = 50;
int projectiles = -1;
if ( !ship->target0->target0 && autofly(ship->target0))
ship->target0->target0 = ship;
/* auto assist ships */
for ( target = first_ship; target; target = target->next)
{
if( ship_in_range( ship, target ) )
if ( autofly(target) && target->docked == NULL && target->shipstate != SHIP_DOCKED )
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->shipclass != SHIP_PLATFORM && !ship->guard
&& ship->docked == NULL && ship->shipstate != SHIP_DOCKED )
{
ship->goalspeed = ship->mod->realspeed;
ship->accel = get_acceleration( ship );
}
if ( ship->energy >200 )
ship->autorecharge=TRUE;
if (ship->shipstate != SHIP_HYPERSPACE && ship->energy > 25
&& ship->missilestate == MISSILE_READY && ship_in_range( ship, target )
&& abs( (int) ( target->vx - ship->vx )) <= 1200
&& abs( (int) ( target->vy - ship->vy )) <= 1200
&& abs( (int) ( target->vz - ship->vz )) <= 1200 )
{
if ( ship->shipclass > 1 || is_facing( ship , target ) )
{
chance -= target->mod->manuever/5;
chance -= target->currspeed/20;
chance += target->shipclass*target->shipclass*25;
chance -= ( abs( (int) ( target->vx - ship->vx ))/100 );
chance -= ( abs( (int) ( target->vy - ship->vy ))/100 );
chance -= ( abs( (int) ( target->vz - ship->vz ))/100 );
chance += ( 30 );
chance = URANGE( 10 , chance , 90 );
if( ( target->shipclass == SHIP_PLATFORM || ( target->shipclass == CAPITAL_SHIP && target->currspeed < 50 )) && ship->rockets > 0 )
projectiles = HEAVY_ROCKET;
else if ( ( target->shipclass == MIDSIZE_SHIP || ( target->shipclass == CAPITAL_SHIP) ) && ship->torpedos > 0 )
projectiles = PROTON_TORPEDO;
else if ( ship->missiles < 0 && ship->torpedos > 0 )
projectiles = PROTON_TORPEDO;
else if ( ship->missiles < 0 && ship->rockets > 0 )
projectiles = HEAVY_ROCKET;
else if ( ship->missiles > 0 )
projectiles = CONCUSSION_MISSILE;
else
projectiles = -1;
if ( number_percent( ) > chance || projectiles == -1 )
{
}
else
{
new_missile( ship , target , NULL , projectiles );
if( projectiles == CONCUSSION_MISSILE ) ship->missiles--;
if( projectiles == PROTON_TORPEDO ) ship->torpedos--;
if( projectiles == HEAVY_ROCKET ) ship->rockets--;
sprintf( buf , "Incoming projectile from %s." , ship->name);
echo_to_cockpit( AT_BLOOD , target , buf );
sprintf( buf, "%s fires a projectile towards %s." , ship->name, target->name );
echo_to_system( AT_ORANGE , target , buf , NULL );
if ( ship->shipclass == CAPITAL_SHIP || ship->shipclass == 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->statei0 == LASER_DAMAGED )
ship->statei0 = LASER_READY;
if( ship->shipstate == SHIP_DISABLED )
ship->shipstate = SHIP_READY;
}
else
if( ship->currspeed )
{
ship->goalspeed = 0;
ship->accel = get_acceleration( ship );
}
}
else
{
if ( number_range(1, 25) == 25 )
{
ship_to_spaceobject(ship, spaceobject_from_name(ship->home) );
if( ship->spaceobject )
{
ship->vx = ship->spaceobject->xpos + number_range( -5000 , 5000 );
ship->vy = ship->spaceobject->ypos + number_range( -5000 , 5000 );
ship->vz = ship->spaceobject->zpos + number_range( -5000 , 5000 );
ship->hx = 1;
ship->hy = 1;
ship->hz = 1;
}
}
}
}
if ( ( ship->shipclass == CAPITAL_SHIP || ship->shipclass == SHIP_PLATFORM )
&& ship->target0 == NULL )
{
int ammo = ship->missiles + ship->torpedos*2 + ship->rockets*3;
if( ammo < ship->mod->launchers * 8 )
ship->missiles++;
if( ammo < ship->mod->launchers * 8 * 2 )
ship->torpedos++;
if( ammo < ship->mod->launchers * 8 * 3 )
ship->rockets++;
if( ship->chaff < ship->mod->defenselaunchers * 6 )
ship->chaff++;
}
save_ship( ship );
}
}
void write_spaceobject_list( )
{
SPACE_DATA *tspaceobject;
FILE *fpout;
char filename[256];
sprintf( filename, "%s%s", SPACE_DIR, SPACE_LIST );
fpout = fopen( filename, "w" );
if ( !fpout )
{
bug( "FATAL: cannot open space.lst for writing!\n\r", 0 );
return;
}
for ( tspaceobject = first_spaceobject; tspaceobject; tspaceobject = tspaceobject->next )
fprintf( fpout, "%s\n", tspaceobject->filename );
fprintf( fpout, "$\n" );
fclose( fpout );
}
/*
* Get pointer to space structure from spaceobject name.
*/
SPACE_DATA *spaceobject_from_name( char *name )
{
SPACE_DATA *spaceobject;
for ( spaceobject = first_spaceobject; spaceobject; spaceobject = spaceobject->next )
if ( !str_cmp( name, spaceobject->name ) )
return spaceobject;
for ( spaceobject = first_spaceobject; spaceobject; spaceobject = spaceobject->next )
if ( !str_prefix( name, spaceobject->name ) )
return spaceobject;
return NULL;
}
/*
* Get pointer to space structure from the dock vnun.
*/
SPACE_DATA *spaceobject_from_vnum( int vnum )
{
SPACE_DATA *spaceobject;
SHIP_DATA *ship;
for ( spaceobject = first_spaceobject; spaceobject; spaceobject = spaceobject->next )
if ( vnum == spaceobject->doca ||
vnum == spaceobject->docb ||
vnum == spaceobject->docc )
return spaceobject;
for ( ship = first_ship; ship; ship = ship->next )
if ( vnum == ship->hanger )
{
if( !(ship->bayopen) )
return NULL;
return ship->spaceobject;
}
return NULL;
}
/*
* Save a spaceobject's data to its data file
*/
void save_spaceobject( SPACE_DATA *spaceobject )
{
FILE *fp;
char filename[256];
char buf[MAX_STRING_LENGTH];
CARGO_DATA_LIST *cargolist;
if ( !spaceobject )
{
bug( "save_spaceobject: null pointer!", 0 );
return;
}
if ( !spaceobject->filename || spaceobject->filename[0] == '\0' )
{
sprintf( buf, "save_spaceobject: %s has no filename", spaceobject->name );
bug( buf, 0 );
return;
}
sprintf( filename, "%s%s", SPACE_DIR, spaceobject->filename );
fclose( fpReserve );
if ( ( fp = fopen( filename, "w" ) ) == NULL )
{
bug( "save_spaceobject: fopen", 0 );
perror( filename );
}
else
{
fprintf( fp, "#SPACE\n" );
fprintf( fp, "Name %s~\n", spaceobject->name );
fprintf( fp, "Filename %s~\n", spaceobject->filename );
fprintf( fp, "Type %d\n", spaceobject->type );
fprintf( fp, "Locationa %s~\n", spaceobject->locationa );
fprintf( fp, "Locationb %s~\n", spaceobject->locationb );
fprintf( fp, "Locationc %s~\n", spaceobject->locationc );
fprintf( fp, "Doca %d\n", spaceobject->doca );
fprintf( fp, "Docb %d\n", spaceobject->docb );
fprintf( fp, "Docc %d\n", spaceobject->docc );
fprintf( fp, "Seca %d\n", spaceobject->seca );
fprintf( fp, "Secb %d\n", spaceobject->secb );
fprintf( fp, "Secc %d\n", spaceobject->secc );
fprintf( fp, "Gravity %d\n", spaceobject->gravity );
fprintf( fp, "Xpos %.0f\n", spaceobject->xpos );
fprintf( fp, "Ypos %.0f\n", spaceobject->ypos );
fprintf( fp, "Zpos %.0f\n", spaceobject->zpos );
fprintf( fp, "HX %.0f\n", spaceobject->hx );
fprintf( fp, "HY %.0f\n", spaceobject->hy );
fprintf( fp, "HZ %.0f\n", spaceobject->hz );
fprintf( fp, "SP %d\n", spaceobject->speed );
fprintf( fp, "Trainer %d\n", spaceobject->trainer );
if ( spaceobject->first_cargo )
{
for( cargolist = spaceobject->first_cargo; cargolist; cargolist = cargolist->next )
{
fprintf( fp, "Cargo %d %d\n",
cargolist->cargo->cargotype, cargolist->cargo->price );
}
}
fprintf( fp, "End\n\n" );
fprintf( fp, "#END\n" );
}
fclose( fp );
fpReserve = fopen( NULL_FILE, "r" );
return;
}
/*
* Read in actual spaceobject data.
*/
#if defined(KEY)
#undef KEY
#endif
#define KEY( literal, field, value ) \
if ( !str_cmp( word, literal ) ) \
{ \
field = value; \
fMatch = TRUE; \
break; \
}
void fread_spaceobject( SPACE_DATA *spaceobject, FILE *fp )
{
char buf[MAX_STRING_LENGTH];
const char *word;
bool fMatch;
CARGO_DATA_LIST *cargolist;
CARGO_DATA *cargo;
for ( ; ; )
{
word = feof( fp ) ? "End" : fread_word( fp );
fMatch = FALSE;
switch ( UPPER(word[0]) )
{
case '*':
fMatch = TRUE;
fread_to_eol( fp );
break;
case 'C':
if ( !str_cmp( word, "Cargo" ) )
{
int x1,x2;
char *ln = fread_line( fp );
x1=x2=0;
sscanf( ln, "%d %d", &x1, &x2 );
CREATE( cargolist, CARGO_DATA_LIST, 1 );
LINK( cargolist, spaceobject->first_cargo, spaceobject->last_cargo, next, prev );
CREATE( cargo, CARGO_DATA, 1 );
cargolist->cargo = cargo;
cargolist->cargo->cargotype = x1;
cargolist->cargo->price = x2;
fMatch = TRUE;
break;
}
case 'D':
KEY( "Doca", spaceobject->doca, fread_number( fp ) );
KEY( "Docb", spaceobject->docb, fread_number( fp ) );
KEY( "Docc", spaceobject->docc, fread_number( fp ) );
break;
case 'E':
if ( !str_cmp( word, "End" ) )
{
if (!spaceobject->name)
spaceobject->name = STRALLOC( "" );
if (!spaceobject->locationa)
spaceobject->locationa = STRALLOC( "" );
if (!spaceobject->locationb)
spaceobject->locationb = STRALLOC( "" );
if (!spaceobject->locationc)
spaceobject->locationc = STRALLOC( "" );
return;
}
break;
case 'F':
KEY( "Filename", spaceobject->filename, fread_string_nohash( fp ) );
break;
case 'G':
KEY( "Gravity", spaceobject->gravity, fread_number( fp ) );
break;
case 'H':
KEY( "HX", spaceobject->hx, fread_number( fp ) );
KEY( "HY", spaceobject->hy, fread_number( fp ) );
KEY( "HZ", spaceobject->hz, fread_number( fp ) );
break;
case 'L':
KEY( "Locationa", spaceobject->locationa, fread_string( fp ) );
KEY( "Locationb", spaceobject->locationb, fread_string( fp ) );
KEY( "Locationc", spaceobject->locationc, fread_string( fp ) );
break;
case 'N':
KEY( "Name", spaceobject->name, fread_string( fp ) );
break;
/*
case 'P':
break;
KEY( "Star1", spaceobject->star1, fread_string( fp ) );
KEY( "Star2", spaceobject->star2, fread_string( fp ) );
KEY( "S1x", spaceobject->s1x, fread_number( fp ) );
KEY( "S1y", spaceobject->s1y, fread_number( fp ) );
KEY( "S1z", spaceobject->s1z, fread_number( fp ) );
KEY( "S2x", spaceobject->s2x, fread_number( fp ) );
KEY( "S2y", spaceobject->s2y, fread_number( fp ) );
KEY( "S2z", spaceobject->s2z, fread_number( fp ) );
*/
case 'S':
KEY( "Seca", spaceobject->seca, fread_number( fp ) );
KEY( "Secb", spaceobject->secb, fread_number( fp ) );
KEY( "Secc", spaceobject->secc, fread_number( fp ) );
KEY( "SP", spaceobject->speed, fread_number( fp ) );
case 'T':
KEY( "Trainer", spaceobject->trainer, fread_number( fp ) );
KEY( "Type", spaceobject->type, fread_number( fp ) );
case 'X':
KEY( "Xpos", spaceobject->xpos, fread_number( fp ) );
case 'Y':
KEY( "Ypos", spaceobject->ypos, fread_number( fp ) );
case 'Z':
KEY( "Zpos", spaceobject->zpos, fread_number( fp ) );
}
if ( !fMatch )
{
sprintf( buf, "Fread_spaceobject: no match: %s", word );
bug( buf, 0 );
}
}
}
/*
* Load a spaceobject file
*/
bool load_spaceobject( char *spaceobjectfile )
{
char filename[256];
SPACE_DATA *spaceobject;
FILE *fp;
bool found;
CREATE( spaceobject, SPACE_DATA, 1 );
found = FALSE;
sprintf( filename, "%s%s", SPACE_DIR, spaceobjectfile );
if ( ( fp = fopen( filename, "r" ) ) != NULL )
{
found = TRUE;
LINK( spaceobject, first_spaceobject, last_spaceobject, next, prev );
for ( ; ; )
{
char letter;
char *word;
letter = fread_letter( fp );
if ( letter == '*' )
{
fread_to_eol( fp );
continue;
}
if ( letter != '#' )
{
bug( "Load_spaceobject_file: # not found.", 0 );
break;
}
word = fread_word( fp );
if ( !str_cmp( word, "SPACE" ) )
{
fread_spaceobject( spaceobject, fp );
break;
}
else
if ( !str_cmp( word, "END" ) )
break;
else
{
char buf[MAX_STRING_LENGTH];
sprintf( buf, "Load_spaceobject_file: bad section: %s.", word );
bug( buf, 0 );
break;
}
}
fclose( fp );
}
if ( !(found) )
DISPOSE( spaceobject );
return found;
}
/*
* Load in all the spaceobject files.
*/
void load_space( )
{
FILE *fpList;
const char *filename;
char spaceobjectlist[256];
char buf[MAX_STRING_LENGTH];
first_spaceobject = NULL;
last_spaceobject = NULL;
log_string( "Loading space..." );
sprintf( spaceobjectlist, "%s%s", SPACE_DIR, SPACE_LIST );
fclose( fpReserve );
if ( ( fpList = fopen( spaceobjectlist, "r" ) ) == NULL )
{
perror( spaceobjectlist );
exit( 1 );
}
for ( ; ; )
{
filename = feof( fpList ) ? "$" : fread_word( fpList );
if ( filename[0] == '$' )
break;
if ( !load_spaceobject( (char*) filename ) )
{
sprintf( buf, "Cannot load spaceobject file: %s", filename );
bug( buf, 0 );
}
}
fclose( fpList );
log_string(" Done spaceobjects " );
fpReserve = fopen( NULL_FILE, "r" );
return;
}
void do_setspaceobject( CHAR_DATA *ch, char *argument )
{
char arg1[MAX_INPUT_LENGTH];
char arg2[MAX_INPUT_LENGTH];
SPACE_DATA *spaceobject;
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: setspaceobject <spaceobject> <field> <values>\n\r", ch );
send_to_char( "\n\rField being one of:\n\r", ch );
send_to_char( "name filename type trainer,\n\r", ch );
send_to_char( "xpos ypos zpos gravity seca secb secc,\n\r", ch );
send_to_char( "locationa locationb locationc doca docb docc\n\r", ch );
send_to_char( "", ch );
return;
}
spaceobject = spaceobject_from_name( arg1 );
if ( !spaceobject )
{
send_to_char( "No such spaceobject.\n\r", ch );
return;
}
if ( !str_cmp( arg2, "trainer" ) )
{
if ( spaceobject->trainer )
spaceobject->trainer = 0;
else
spaceobject->trainer = 1;
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "seca" ) )
{
if ( spaceobject->seca )
spaceobject->seca = 0;
else
spaceobject->seca = 1;
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "secb" ) )
{
if ( spaceobject->secb )
spaceobject->secb = 0;
else
spaceobject->secb = 1;
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "secc" ) )
{
if ( spaceobject->secc )
spaceobject->secc = 0;
else
spaceobject->secc = 1;
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "type" ) )
{
spaceobject->type = atoi( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "doca" ) )
{
spaceobject->doca = atoi( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "docb" ) )
{
spaceobject->docb = atoi( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "docc" ) )
{
spaceobject->docc = atoi( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "xpos" ) )
{
spaceobject->xpos = atoi( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "ypos" ) )
{
spaceobject->ypos = atoi( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "zpos" ) )
{
spaceobject->zpos = atoi( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "gravity" ) )
{
spaceobject->gravity = atoi( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "hx" ) )
{
spaceobject->hx = atoi( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "hy" ) )
{
spaceobject->hy = atoi( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "hz" ) )
{
spaceobject->hz = atoi( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "speed" ) )
{
spaceobject->speed = atoi( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "name" ) )
{
STRFREE( spaceobject->name );
spaceobject->name = STRALLOC( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "filename" ) )
{
DISPOSE( spaceobject->filename );
spaceobject->filename = strdup( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "locationa" ) )
{
STRFREE( spaceobject->locationa );
spaceobject->locationa = STRALLOC( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "locationb" ) )
{
STRFREE( spaceobject->locationb );
spaceobject->locationb = STRALLOC( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
if ( !str_cmp( arg2, "locationc" ) )
{
STRFREE( spaceobject->locationc );
spaceobject->locationc = STRALLOC( argument );
send_to_char( "Done.\n\r", ch );
save_spaceobject( spaceobject );
return;
}
do_setspaceobject( ch, "" );
return;
}
void showspaceobject( CHAR_DATA *ch , SPACE_DATA *spaceobject )
{
ch_printf( ch, "Space object:%s Trainer: %s Filename: %s Type %d\n\r",
spaceobject->name,
(spaceobject->trainer ? "Yes" : "No"),
spaceobject->filename, spaceobject->type );
ch_printf( ch, "Coordinates: %.0f %0.f %.0f\n\rGravity: %d\n\r",
spaceobject->xpos , spaceobject->ypos, spaceobject->zpos, spaceobject->gravity);
ch_printf( ch, " doca: %5d (%s)\n\r",
spaceobject->doca, spaceobject->locationa);
ch_printf( ch, " docb: %5d (%s)\n\r",
spaceobject->docb, spaceobject->locationb);
ch_printf( ch, " docc: %5d (%s)\n\r",
spaceobject->docc, spaceobject->locationc);
return;
}
void do_showspaceobject( CHAR_DATA *ch, char *argument )
{
SPACE_DATA *spaceobject;
spaceobject = spaceobject_from_name( argument );
if ( spaceobject == NULL )
send_to_char("&RNo such spaceobject.\n\r",ch);
else
showspaceobject(ch , spaceobject);
}
void do_makespaceobject( CHAR_DATA *ch, char *argument )
{
char arg[MAX_INPUT_LENGTH];
char filename[256];
SPACE_DATA *spaceobject;
if ( !argument || argument[0] == '\0' )
{
send_to_char( "Usage: makespaceobject <spaceobject name>\n\r", ch );
return;
}
CREATE( spaceobject, SPACE_DATA, 1 );
LINK( spaceobject, first_spaceobject, last_spaceobject, next, prev );
spaceobject->name = STRALLOC( argument );
spaceobject->locationa = STRALLOC( "" );
spaceobject->locationb = STRALLOC( "" );
spaceobject->locationc = STRALLOC( "" );
argument = one_argument( argument, arg );
sprintf( filename, "%s.system" , strlower(arg) );
spaceobject->filename = str_dup( filename );
save_spaceobject( spaceobject );
write_spaceobject_list();
}
void do_spaceobjects( CHAR_DATA *ch, char *argument )
{
SPACE_DATA *spaceobject;
int count = 0;
set_char_color( AT_RED, ch );
for ( spaceobject = first_spaceobject; spaceobject; spaceobject = spaceobject->next )
{
if( spaceobject->type > SPACE_SUN )
continue;
if ( !(spaceobject->trainer && (!IS_GOD(ch))) )
ch_printf( ch, "%s\n\r", spaceobject->name );
count++;
}
ch_printf( ch, "\n\r" );
set_char_color( AT_NOTE, ch );
for ( spaceobject = first_spaceobject; spaceobject; spaceobject = spaceobject->next )
{
if( spaceobject->type != SPACE_PLANET )
continue;
if ( !(spaceobject->trainer && (!IS_GOD(ch))) )
ch_printf( ch, "%s\n\r", spaceobject->name );
count++;
}
if ( !count )
{
send_to_char( "There are no spaceobjects 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_docked( int color , SHIP_DATA *ship , char *argument )
{
SHIP_DATA *dship;
for( dship = first_ship; dship; dship = dship->next )
if( dship->docked && dship->docked == ship)
echo_to_cockpit( color, dship, argument );
}
void echo_to_cockpit( int color , SHIP_DATA *ship , char *argument )
{
int room;
TURRET_DATA *turret;
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 )
echo_to_room( color , get_room_index(room) , argument );
if( ship->first_turret )
for( turret = ship->first_turret; turret; turret = turret->next )
if( turret->roomvnum == room )
echo_to_room( color , get_room_index(room) , argument );
}
}
bool ship_in_range( SHIP_DATA *ship, SHIP_DATA *target )
{
if (target && ship && target != ship )
if ( target->spaceobject && ship->spaceobject &&
target->shipstate != SHIP_LANDED &&
abs( (int) (Showing the first 100 KB of 389.7 KB. Download the archive for the full file.