asteroids.c
asteroids.c · 30.9 KB
From the archive Asteroids.zip
Download the archive « Back to the archive contents
/*
*
* Asteroid Code v1.0 by Odis
*
* See include file also...
*
* Last updated: 6/19/04
*
* Note: This code is 100% original, however, it was based on some existing code (no
* point in reinventing the wheel ) or ripped.
*/
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "mud.h"
ASTEROID_DATA * first_asteroid;
ASTEROID_DATA * last_asteroid;
/*
* Local Functions
*/
// Individual Asteroid's
void write_asteroid_list args( ( void ) );
bool load_asteroid_file args( ( char *asteroidfile ) );
void fread_asteroid args( ( ASTEROID_DATA *asteroid, FILE *fp ) );
///////////////////////////////////////////////////////////////////////////////////////////
/*
* Asteroid v1.0 By: Odis
*/
/*
Reference...
Asteroid types:
0 = unknown
1 = small
2 = medium
3 = large
Asteroid special types (stypes):
0 = unknown
1 = ice
2 = rock
*/
/*
* Get pointer to area structure from the area's filename.
* Uncomment this if you do not have this function in your mud already...
*/
/*
AREA_DATA *get_area(char *argument)
{
AREA_DATA *pArea;
for( pArea = first_area ; pArea ; pArea = pArea->next )
if (pArea->filename && !str_cmp(pArea->filename , argument ) )
return pArea;
return NULL;
}
*/
/*
* Get the asteroid to which the area belongs that the character is in
*/
ASTEROID_DATA *get_asteroid_area( CHAR_DATA *ch )
{
AREA_DATA *area = ch->in_room->area;
ASTEROID_DATA *asteroid;
if ( area == NULL )
return NULL;
for ( asteroid = first_asteroid; asteroid; asteroid = asteroid->next )
if ( area == asteroid->area )
return asteroid;
return NULL;
}
/*
* Flags, for expandability
*/
char *const ast_flags [] =
{
"a00", "a01", "a02", "a03", "a04", "a05", "a06", "a07", "a08", "a09",
"a10", "a11", "a12", "a13", "a14", "a15", "a16", "a17", "a18", "a19",
"a20", "a21", "a22", "a23", "a24", "a25", "a26", "a27", "a28", "a29",
"a30", "a31"
};
/*
* Lets find that flag! See previous table.
*/
int get_astflag( char *flag )
{
int x;
for ( x = 0; x < 32; x++ )
if ( !str_cmp(flag, ast_flags[x] ) )
return x;
return -1;
}
/*
* Get pointer to asteroid structure from the asteroid name
*/
ASTEROID_DATA *get_asteroid( char *name )
{
ASTEROID_DATA *asteroid;
for ( asteroid = first_asteroid; asteroid; asteroid = asteroid->next )
if ( !str_cmp( name, asteroid->name ) )
return asteroid;
for ( asteroid = first_asteroid; asteroid; asteroid = asteroid->next )
if ( nifty_is_name_prefix( name, asteroid->name ) )
return asteroid;
return NULL;
}
/*
* Checks if asteroids in a starsystem and returns poiner if it is.
*/
ASTEROID_DATA *get_asteroid_here( char *name , SPACE_DATA *starsystem)
{
ASTEROID_DATA *asteroid;
if ( starsystem == NULL )
return NULL;
for ( asteroid = starsystem->first_asteroid ; asteroid; asteroid = asteroid->next_in_system )
if ( !str_cmp( name, asteroid->name ) )
return asteroid;
for ( asteroid = starsystem->first_asteroid; asteroid; asteroid = asteroid->next_in_system )
if ( nifty_is_name_prefix( name, asteroid->name ) )
return asteroid;
return NULL;
}
void damage_asteroid_ch( ASTEROID_DATA *asteroid , int min , int max , CHAR_DATA *ch )
{
int damage,rand;
long xp;
char buf[MAX_STRING_LENGTH];
damage = number_range( min , max );
xp = ( exp_level( ch->skill_level[PILOTING_ABILITY]+1) - exp_level( ch->skill_level[PILOTING_ABILITY]) ) / 25 ;
xp = UMIN( asteroid->hp/100 , xp ) ;
gain_exp( ch , xp , PILOTING_ABILITY );
asteroid->hp -= damage*2;
if ( asteroid->hp <= 0 )
{
rand = number_range( 100, 200 ); // Roughly 5-10 minutes
asteroid->timer = rand;
// Tell all ships in the system its gone..
sprintf( buf, "%s turns to space dust...\n\r", asteroid->name );
echo_to_asystem( AT_RED, asteroid, buf );
xp = asteroid->exp;
extract_asteroid( asteroid );
gain_exp( ch , xp , PILOTING_ABILITY);
ch_printf( ch, "&WYou gain %ld piloting experience!\n\r", xp );
return;
}
return;
}
void damage_asteroid( ASTEROID_DATA *asteroid , int min , int max )
{
int damage;
sh_int rand;
char buf[MAX_STRING_LENGTH];
damage = number_range( min , max );
asteroid->hp -= damage*2;
if ( asteroid->hp <= 0 )
{
rand = number_range( 100, 200 ); // Roughly 5-10 minutes
asteroid->timer = rand;
// Tell all ships in the system its gone..
sprintf( buf, "%s turns to space dust...\n\r", asteroid->name );
echo_to_asystem( AT_RED, asteroid, buf );
extract_asteroid( asteroid );
return;
}
return;
}
/*
* Extract the asteroid from a starsystem
*/
bool extract_asteroid( ASTEROID_DATA *asteroid )
{
SPACE_DATA *starsystem;
starsystem = asteroid->starsystem;
if ( asteroid == NULL || starsystem == NULL )
return FALSE;
UNLINK( asteroid, starsystem->first_asteroid, starsystem->last_asteroid, next_in_system, prev_in_system );
/* if ( starsystem != NULL )
{
if ( starsystem->last_asteroid == asteroid )
starsystem->last_asteroid = asteroid->prev_in_system;
if ( starsystem->first_asteroid == asteroid )
starsystem->first_asteroid = asteroid->next_in_system;
if ( asteroid->prev_in_system )
asteroid->prev_in_system->next_in_system = asteroid->next_in_system;
if ( asteroid->next_in_system)
asteroid->next_in_system->prev_in_system = asteroid->prev_in_system;
}*/
asteroid->starsystem = NULL;
return TRUE;
}
/*
* Echo a message to the system that an asteroid is in.
*/
void echo_to_asystem( int color , ASTEROID_DATA *asteroid , char *argument )
{
SHIP_DATA *ship;
SPACE_DATA *system;
system = asteroid->starsystem;
if ( asteroid == NULL || system == NULL)
return;
for ( ship = system->first_ship; ship; ship = ship->next_in_starsystem )
echo_to_cockpit( color , ship , argument );
}
/*
* Transfer an asteroid to a certain starsystem
*/
void asteroid_to_system( ASTEROID_DATA *asteroid , SPACE_DATA *starsystem )
{
if ( starsystem == NULL )
return;
if ( asteroid == NULL )
return;
if ( starsystem->first_asteroid == NULL )
starsystem->first_asteroid = asteroid;
if ( starsystem->last_asteroid )
{
starsystem->last_asteroid->next_in_system = asteroid;
asteroid->prev_in_system = starsystem->last_asteroid;
}
starsystem->last_asteroid = asteroid;
asteroid->starsystem = starsystem;
generate_coordinates( 1, asteroid );
return;
}
/*
* Reset_asteroid syntax: reset_asteroid( name, type, stype, experience, save ); (Filename is automatically generated using the name)
* -1 on experience allows makeasteroid to calculate it.
*/
void reset_asteroid( char *name, sh_int type, sh_int stype, long experience, bool save)
{
SPACE_DATA *starsystem;
ASTEROID_DATA *asteroid;
if ( (asteroid = get_asteroid(name))== NULL )
return;
if ( ( starsystem = starsystem_from_name( asteroid->home_system ) ) == NULL )
return;
asteroid->hp = generate_hp( type, stype );
asteroid->maxhp = asteroid->hp;
if ( experience == -1 )
{
// to simple? I think so too...
asteroid->exp = asteroid->hp*5;
}
else
asteroid->exp = experience;
extract_asteroid( asteroid );
asteroid_to_system( asteroid, starsystem );
// should it save the asteroid?
if ( save == TRUE )
save_asteroid( asteroid );
return;
}
/*
* Generate hp of asteroids....alsmost to simple for my taste...
*/
int generate_hp( sh_int type, sh_int stype )
{
sh_int mod=0;
if ( type == 0 || stype == 0 )
return 1;
if ( stype == 1 )
mod = mod+2;
else
mod = mod+1;
mod = mod+type;
mod++;
return mod*1000;
}
/*
* Generate coordinates for asteroids
*/
void generate_coordinates( int num, ASTEROID_DATA *asteroid )
{
int rand;
int amount;
float x, y, z;
if ( asteroid == NULL )
return;
x = number_range( -30000, 30000 );
y = number_range( -30000, 30000 );
z = number_range( -30000, 30000 );
amount = num*1000;
rand = number_range( 0, 1 );
// Get coordinates that the asteroid will be at, make sure its not ON another asteroid
// or mysteriously pop up and collide with a ship accidently...
// x
if ( rand == 0 )
asteroid->x = number_range( x, x+amount );
else
asteroid->x = number_range( x-amount, x );
// y
rand = number_range( 0, 1 );
if ( rand == 0 )
asteroid->y = number_range( y, y+amount );
else
asteroid->y = number_range( y-amount, y );
// z
rand = number_range( 0, 1 );
if ( rand == 0 )
asteroid->z = number_range( z, z+amount );
else
asteroid->z = number_range( z-amount, z );
save_asteroid( asteroid );
return;
}
/*
* Called roughly every 3 seconds..
*/
void update_asteroids( void )
{
ASTEROID_DATA *asteroid;
float x, y, z, change;
for ( asteroid = first_asteroid; asteroid; asteroid = asteroid->next )
{
// This asteroid hit something!
if ( asteroid->collision )
{
damage_asteroid( asteroid, asteroid->collision, asteroid->collision );
asteroid->collision = 0;
}
// See if the asteroid needs to be put back in its home system
if ( asteroid->timer > 1 )
{
// Not time yet..
asteroid->timer--;
continue;
}
else if ( asteroid->timer < 0 || asteroid->timer == 1 )
{
// reset the timer
asteroid->timer = 0;
// Reset asteroid hp
asteroid->hp = asteroid->maxhp;
// Root out all the asteroids with no systems (extracted, hopefully)
// Then stick them back in their home system
if ( asteroid->starsystem == NULL )
{
asteroid_to_system( asteroid, starsystem_from_name( asteroid->home_system ) );
continue;
}
}
if ( asteroid->speed > 0 && asteroid->timer == 0 && asteroid->hp > 0)
{
change = sqrt( asteroid->x*asteroid->x + asteroid->y*asteroid->y + asteroid->z*asteroid->z );
if (change > 0)
{
x = asteroid->x/change;
y = asteroid->y/change;
z = asteroid->z/change;
asteroid->x += (x * asteroid->speed/5);
asteroid->y += (y * asteroid->speed/5);
asteroid->z += (z * asteroid->speed/5);
}
}
save_asteroid( asteroid );
// Close loop
}
// Close function
}
//=============================================================================
//=================== Read, load, save, and write functions ===================
//=============================================================================
/*
* Save asteroid to a data file
*/
void save_asteroid( ASTEROID_DATA *asteroid )
{
FILE *fp;
char filename[256];
char buf[MAX_STRING_LENGTH];
if ( !asteroid )
{
bug( "save_asteroid: Null asteroid pointer!", 0 );
return;
}
if ( !asteroid->filename || asteroid->filename[0] == '\0' )
{
sprintf( buf, "save_asteroid: %s has no filename", asteroid->name );
bug( buf, 0 );
return;
}
sprintf( filename, "%s%s", AST_DIR, asteroid->filename );
fclose( fpReserve );
if ( ( fp = fopen( filename, "w" ) ) == NULL )
{
bug( "save_asteroid: fopen", 0 );
perror( filename );
}
else
{
fprintf( fp, "#ASTEROID\n" );
fprintf( fp, "Name %s~\n", asteroid->name );
fprintf( fp, "Filename %s~\n", asteroid->filename );
fprintf( fp, "Home %s~\n", asteroid->home_system );
fprintf( fp, "Type %d\n", asteroid->type );
fprintf( fp, "Stype %d\n", asteroid->stype );
fprintf( fp, "Hp %d\n", asteroid->hp );
fprintf( fp, "Maxhp %d\n", asteroid->maxhp );
fprintf( fp, "Speed %d\n", asteroid->speed );
fprintf( fp, "Timer %d\n", asteroid->timer );
fprintf( fp, "Exp %ld\n", asteroid->exp );
#ifdef ORE
fprintf( fp, "Ore1 %d\n", asteroid->ore1 );
fprintf( fp, "Ore2 %d\n", asteroid->ore2 );
fprintf( fp, "Ore1ammount %d\n", asteroid->ore1ammount );
fprintf( fp, "Ore2ammount %d\n", asteroid->ore2ammount );
#endif
if (asteroid->area)
fprintf( fp, "Area %s~\n", asteroid->area->filename );
fprintf( fp, "End\n\n" );
fprintf( fp, "#END\n" );
}
fclose( fp );
fpReserve = fopen( NULL_FILE, "r" );
return;
}
/*
* Read in actual asteroid data
*/
#if defined(KEY)
#undef KEY
#endif
#define KEY( literal, field, value ) \
if ( !str_cmp( word, literal ) ) \
{ \
field = value; \
fMatch = TRUE; \
break; \
}
void fread_asteroid( ASTEROID_DATA *asteroid, 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 'A':
if ( !str_cmp( word, "Area" ) )
{
char *aName;
AREA_DATA *pArea;
aName = fread_string(fp);
// bad way to check how valid the area is...need to change later
for( pArea = first_area ; pArea ; pArea = pArea->next )
if (pArea->filename && !str_cmp(pArea->filename , aName ) )
asteroid->area = pArea;
STRFREE( aName );
fMatch = TRUE;
}
break;
case 'E':
KEY( "Exp", asteroid->exp, fread_number( fp ) );
/*
* Make sure this asteroid is ready to go! If it has null data, fill it in!
*/
if ( !str_cmp( word, "End" ) )
{
if ( !asteroid->home_system)
asteroid->home_system = STRALLOC( "Terra" ); // Terra Default
if ( !asteroid->exp || asteroid->exp < 0 )
asteroid->exp = 0;
if ( !asteroid->name )
asteroid->name = STRALLOC( "" );
if ( !asteroid->filename )
asteroid->filename = str_dup("");
if ( !asteroid->type || asteroid->type < 1 )
asteroid->type = 1;
if ( !asteroid->stype || asteroid->stype < 1 )
asteroid->stype = 1;
if ( (!asteroid->hp || asteroid->hp < 1) && (!asteroid->maxhp || asteroid->maxhp < 1 ) )
asteroid->hp = generate_hp( asteroid->type, asteroid->stype );
if ( !asteroid->speed || asteroid->speed < 1 )
asteroid->speed = 100;
if ( !asteroid->starsystem )
asteroid->starsystem = NULL;
if ( !asteroid->area )
asteroid->area = NULL;
if ( !asteroid->timer || asteroid->timer < 0 )
asteroid->timer = 0;
if ( ( !asteroid->hp || asteroid->hp < 0 ) && asteroid->maxhp >= 10 )
asteroid->hp = asteroid->maxhp;
if ( ( !asteroid->maxhp || asteroid->maxhp < 0 ) && asteroid->hp >= 10 )
asteroid->maxhp = asteroid->hp;
return;
}
break;
case 'F':
KEY( "Filename", asteroid->filename, fread_string_nohash( fp ) );
case 'H':
KEY( "Hp" , asteroid->hp, fread_number( fp ) );
KEY( "Home" , asteroid->home_system, fread_string( fp ) );
break;
case 'M':
KEY( "Maxhp", asteroid->maxhp, fread_number( fp ) );
break;
case 'N':
KEY( "Name", asteroid->name, fread_string( fp ) );
break;
#ifdef ORE
case 'O':
KEY( "Ore1", asteroid->ore1, fread_number( fp ) );
KEY( "Ore2", asteroid->ore2, fread_number( fp ) );
KEY( "Ore1ammount", asteroid->ore1ammount, fread_number( fp ) );
KEY( "Ore2ammount", asteroid->ore2ammount, fread_number( fp ) );
break;
#endif
case 'S':
KEY( "Speed", asteroid->speed, fread_number( fp ) );
KEY( "Stype", asteroid->stype, fread_number( fp ) );
break;
case 'T':
KEY( "Timer", asteroid->timer, fread_number( fp ) );
KEY( "Type", asteroid->type, fread_number( fp ) );
break;
}
if ( !fMatch )
{
sprintf( buf, "Fread_asteroid: no match: %s", word );
bug( buf, 0 );
}
}
}
/*
* Load an asteroid file
*/
bool load_asteroid_file( char *asteroidfile )
{
char filename[256];
ASTEROID_DATA *asteroid;
FILE *fp;
bool found;
CREATE( asteroid, ASTEROID_DATA, 1 );
found = FALSE;
sprintf( filename, "%s%s", AST_DIR, asteroidfile );
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_asteroid_file: # not found.", 0 );
break;
}
word = fread_word( fp );
if ( !str_cmp( word, "ASTEROID" ) )
{
fread_asteroid( asteroid, fp );
break;
}
else
if ( !strcmp( word, "END" ) )
break;
else
{
char buf[MAX_STRING_LENGTH];
sprintf( buf, "Load_asteroid_file: bad section: %s.", word );
bug( buf, 0 );
break;
}
}
fclose( fp );
}
if ( !found )
DISPOSE( asteroid );
else
{
LINK( asteroid, first_asteroid, last_asteroid, next, prev );
if ( asteroid->timer == 0 )
asteroid->timer = -1;
asteroid->starsystem = NULL; //requiered to be placed in the system, this is just a safety measure
}
return found;
}
/*
* Load in all the asteroid files.
* Add to the load functions in db.c/comm.c, I forget which
*/
void load_asteroids( )
{
FILE *fpList;
const char *filename="\0";
char astlist[256];
char buf[MAX_STRING_LENGTH];
first_asteroid = NULL;
last_asteroid = NULL;
log_string( "Loading asteroids..." );
sprintf( astlist, "%s%s", AST_DIR, AST_LIST );
fclose( fpReserve );
if ( ( fpList = fopen( astlist, "r" ) ) == NULL )
{
perror( astlist );
exit( 1 );
}
for ( ; ; )
{
filename = feof( fpList ) ? "$" : fread_word( fpList );
if ( filename[0] == '$' )
break;
log_string( filename );
if ( !load_asteroid_file( (char *)filename ) )
{
sprintf( buf, "Cannot load asteroid file: %s", filename );
bug( buf, 0 );
}
}
fclose( fpList );
log_string(" Done asteroids" );
fpReserve = fopen( NULL_FILE, "r" );
return;
}
void write_asteroid_list( )
{
ASTEROID_DATA *tasteroid;
FILE *fpout;
char filename[256];
sprintf( filename, "%s%s", AST_DIR, AST_LIST );
fpout = fopen( filename, "w" );
if ( !fpout )
{
bug( "FATAL: cannot open asteroid.lst for writing!\n\r", 0 );
return;
}
for ( tasteroid = first_asteroid; tasteroid; tasteroid = tasteroid->next )
fprintf( fpout, "%s\n", tasteroid->filename );
fprintf( fpout, "$\n" );
fclose( fpout );
}
//=============================================================================
//=================== End of Read, Load, and Save Functions ===================
//=============================================================================
//
//=============================================================================
//=================== Start of make, copy, and set functions ==================
//=============================================================================
void do_makeasteroid( CHAR_DATA *ch, char *argument )
{
ASTEROID_DATA *asteroid;
char arg[MAX_INPUT_LENGTH];
argument = one_argument( argument, arg );
if ( !argument || argument[0] == '\0' )
{
send_to_char( "Usage: makeasteroid <filename> <asteroid name>\n\r", ch );
return;
}
CREATE( asteroid, ASTEROID_DATA, 1 );
LINK( asteroid, first_asteroid, last_asteroid, next, prev );
asteroid->name = STRALLOC( argument );
asteroid->home_system = STRALLOC( "Terra" );
asteroid->starsystem = NULL;
asteroid->area = NULL;
asteroid->type = 0;
asteroid->stype = 0;
asteroid->exp = 0;
#ifdef ORE
asteroid->ore1 = NONE;
asteroid->ore2 = NONE;
asteroid->ore1ammount = 0;
asteroid->ore2ammount = 0;
#endif
asteroid->speed = 100;
asteroid->hp = 1000;
asteroid->maxhp = 1000;
asteroid->filename = str_dup( arg );
save_asteroid( asteroid );
write_asteroid_list( );
}
/*
* Show the asteroid
*/
void do_showasteroid( CHAR_DATA *ch, char *argument )
{
ASTEROID_DATA *asteroid;
char arg1[MAX_INPUT_LENGTH];
argument = one_argument( argument, arg1 );
asteroid = get_asteroid( arg1 );
if ( asteroid == NULL )
{
send_to_char( "No Asteroid!\n\r", ch );
return;
}
/*
* Lots of flashy bullshit here that doesn't do anything...its 1:51 AM!
*/
ch_printf( ch, "Name: %s Filename: %s\n\r", asteroid->name, asteroid->filename );
if ( asteroid->starsystem && asteroid->starsystem != NULL )
ch_printf( ch, "Starsystem: %s\n\r", asteroid->starsystem->name );
ch_printf( ch, "Home System: %s\n\r", asteroid->home_system );
ch_printf( ch, "Type: %d Stype: %d Hp: %d MaxHp: %d\n\r", asteroid->type,
asteroid->stype,
asteroid->hp,
asteroid->maxhp );
ch_printf( ch, "Speed: %d Exp: %ld Timer: %d\n\r", asteroid->speed, asteroid->exp, asteroid->timer );
#ifdef ORE
ch_printf( ch, "Ore 1: %s Ore 2: %s\n\r", asteroid->ore1 == TIN ? "Tin" :
(asteroid->ore1 == COPPER ? "Copper" :
(asteroid->ore1 == IRON ? "Iron" :
(asteroid->ore1 == SILVER ? "Silver" :
(asteroid->ore1 == GOLD ? "Gold" :
(asteroid->ore1 == PLATINUM ? "Platinum" :
(asteroid->ore1 == COAL ? "Coal" : "None")))))),
asteroid->ore2 == TIN ? "Tin" :
(asteroid->ore2 == COPPER ? "Copper" :
(asteroid->ore2 == IRON ? "Iron" :
(asteroid->ore2 == SILVER ? "Silver" :
(asteroid->ore2 == GOLD ? "Gold" :
(asteroid->ore2 == PLATINUM ? "Platinum" :
(asteroid->ore2 == COAL ? "Coal" : "None")))))));
ch_printf( ch, "Ammount of Ore 1 left: %d\n\r", asteroid->ore1ammount );
ch_printf( ch, "Ammount of Ore 2 left: %d\n\r", asteroid->ore2ammount );
#endif
if ( asteroid->area && asteroid->area->filename )
ch_printf( ch, "Area: %s\n\r", asteroid->area->filename );
return;
}
/*
* Let the code reset the asteroid for us.
*/
void do_resetasteroid( CHAR_DATA *ch, char *argument )
{
ASTEROID_DATA *asteroid;
char arg1[MAX_INPUT_LENGTH];
char arg2[MAX_INPUT_LENGTH];
char arg3[MAX_INPUT_LENGTH];
char arg4[MAX_INPUT_LENGTH];
argument = one_argument( argument, arg1 );
argument = one_argument( argument, arg2 );
argument = one_argument( argument, arg3 );
argument = one_argument( argument, arg4 );
if ( !argument || argument[0] == '\0' ||
!arg1 || argument[0] == '\0' ||
!arg2 || argument[0] == '\0' ||
!arg3 || argument[0] == '\0' ||
!arg4 || argument[0] == '\0' )
{
send_to_char( "Usage: resetasteroid <name> <type> <stype> <exp> <save?:y/n>\n\r", ch );
return;
}
asteroid = get_asteroid( arg1 );
if ( !str_cmp("y",argument) || !str_cmp("yes",argument ) )
reset_asteroid( asteroid->name, atoi(arg2), atoi(arg3), atoi(arg4), TRUE);
else if ( !str_cmp("n",argument) || !str_cmp("no",argument ) )
reset_asteroid( asteroid->name, atoi(arg2), atoi(arg3), atoi(arg4), FALSE);
else
return;
send_to_char("Done.\n\r", ch);
return;
}
void do_copyasteroid( CHAR_DATA *ch, char *argument )
{
ASTEROID_DATA *asteroid;
ASTEROID_DATA *old;
char arg[MAX_INPUT_LENGTH];
char arg2[MAX_INPUT_LENGTH];
argument = one_argument( argument, arg );
argument = one_argument( argument, arg2 );
if ( !argument || argument[0] == '\0' )
{
send_to_char( "Usage: copyasteroid <oldasteroidname> <newfilename> <newname>\n\r", ch );
return;
}
old = get_asteroid( arg );
if (!old)
{
send_to_char( "Thats not an asteroid!\n\r", ch );
return;
}
CREATE( asteroid, ASTEROID_DATA, 1 );
LINK( asteroid, first_asteroid, last_asteroid, next, prev );
asteroid->name = STRALLOC( argument );
asteroid->home_system = STRALLOC( old->home_system );
asteroid->starsystem = old->starsystem;
asteroid->area = NULL;
asteroid->type = old->type;
asteroid->stype = old->stype;
asteroid->timer = old->timer;
asteroid->exp = old->exp;
asteroid->speed = old->speed;
asteroid->hp = old->hp;
asteroid->maxhp = old->maxhp;
#ifdef ORE
asteroid->ore1 = old->ore1;
asteroid->ore2 = old->ore2;
asteroid->ore1ammount = old->ore1ammount;
asteroid->ore2ammount = old->ore2ammount;
#endif
asteroid->filename = str_dup(arg2);
if ( asteroid->type == 0 || asteroid->stype == 0 )
reset_asteroid( asteroid->name, 3, 2, -1, TRUE);
save_asteroid( asteroid );
write_asteroid_list();
}
void do_setasteroid( CHAR_DATA *ch, char *argument )
{
char arg1[MAX_INPUT_LENGTH];
char arg2[MAX_INPUT_LENGTH];
ASTEROID_DATA *asteroid;
int tempnum;
if ( IS_NPC( ch ) )
{
send_to_char( "Huh?\n\r", ch );
return;
}
argument = one_argument( argument, arg1 );
argument = one_argument( argument, arg2 );
if ( arg1[0] == '\0' || arg2[0] == '\0' || arg1[0] == '\0' )
{
send_to_char( "Usage: setasteroid <asteroid> <field> <values>\n\r", ch );
send_to_char( "\n\rField being one of:\n\r", ch );
send_to_char( "name, homesystem, starsystem, type, stype, exp, filename\n\r", ch );
send_to_char( "speed, hp, maxhp, area\n\r", ch );
#ifdef ORE
send_to_char( "Ore Module: ore1, ore2, ore1ammount, ore2ammount\n\r", ch );
#endif
return;
}
asteroid = get_asteroid( arg1 );
if ( !asteroid )
{
send_to_char( "No such asteroid.\n\r", ch );
return;
}
#ifdef ORE
if ( !str_cmp( arg2, "ore1" ) )
{
asteroid->ore1 = URANGE( NONE, atoi(argument) , COAL );
send_to_char( "Done.\n\r", ch );
save_asteroid( asteroid );
return;
}
if ( !str_cmp( arg2, "ore2" ) )
{
asteroid->ore2 = URANGE( NONE, atoi(argument) , COAL );
send_to_char( "Done.\n\r", ch );
save_asteroid( asteroid );
return;
}
if ( !str_cmp( arg2, "ore1ammount" ) )
{
asteroid->ore1ammount = URANGE( 1, atoi(argument) , 32000 );
send_to_char( "Done.\n\r", ch );
save_asteroid( asteroid );
return;
}
if ( !str_cmp( arg2, "ore2ammount" ) )
{
asteroid->ore2ammount = URANGE( 1, atoi(argument) , 32000 );
send_to_char( "Done.\n\r", ch );
save_asteroid( asteroid );
return;
}
#endif
if ( !str_cmp( arg2, "starsystem" ) )
{
extract_asteroid( asteroid );
asteroid_to_system( asteroid, starsystem_from_name(argument) );
send_to_char( "Asteroid Sent.\n\r", ch );
save_asteroid( asteroid );
return;
}
if ( !str_cmp( arg2, "homesystem" ) )
{
STRFREE( asteroid->home_system );
asteroid->home_system = STRALLOC( argument );
send_to_char( "Done.\n\r", ch );
save_asteroid( asteroid );
return;
}
if ( !str_cmp( arg2, "type" ) )
{
if ( !str_cmp( argument, "small" ) || atoi(argument) == 1 )
asteroid->type = 1;
else
if ( !str_cmp( argument, "medium" ) || !str_cmp( argument, "med") || atoi(argument) == 2 )
asteroid->type = 2;
else
if ( !str_cmp( argument, "large" ) || atoi(argument) == 3 )
asteroid->type = 3;
else
{
send_to_char( "Asteroid type must be either: small(1), medium(med,2), or large(3).\n\r", ch );
return;
}
send_to_char( "Done.\n\r", ch );
save_asteroid( asteroid );
return;
}
if ( !str_cmp( arg2, "name" ) )
{
STRFREE( asteroid->name );
asteroid->name = STRALLOC( argument );
send_to_char( "Done.\n\r", ch );
save_asteroid( asteroid );
return;
}
if ( !str_cmp( arg2, "filename" ) )
{
DISPOSE( asteroid->filename );
asteroid->filename = str_dup( argument );
send_to_char( "Done.\n\r", ch );
save_asteroid( asteroid );
write_asteroid_list( );
return;
}
if ( !str_cmp( arg2, "exp" ) )
{
asteroid->exp = URANGE( 0, atoi(argument) , 50000000 );
send_to_char( "Done.\n\r", ch );
save_asteroid( asteroid );
return;
}
if ( !str_cmp( arg2, "hp" ) )
{
asteroid->hp = URANGE( 1, atoi(argument) , 32000 );
send_to_char( "Done.\n\r", ch );
save_asteroid( asteroid );
return;
}
if ( !str_cmp( arg2, "maxhp" ) )
{
asteroid->maxhp = URANGE( 1, atoi(argument) , 32000 );
send_to_char( "Done.\n\r", ch );
save_asteroid( asteroid );
return;
}
if ( !str_cmp( arg2, "speed" ) )
{
asteroid->speed = URANGE( 0, atoi(argument) , 300 );
send_to_char( "Done.\n\r", ch );
save_asteroid( asteroid );
return;
}
if ( !str_cmp( arg2, "stype" ) )
{
if ( !str_cmp( argument, "ice" ) || atoi(argument) == 1 )
asteroid->stype = 1;
else
if ( !str_cmp( argument, "rock" ) || atoi(argument) == 2 )
asteroid->stype = 2;
else
{
send_to_char( "Asteroid stype must be either: ice(1) or rock(2).\n\r", ch );
return;
}
send_to_char( "Done.\n\r", ch );
save_asteroid( asteroid );
return;
}
if ( !str_cmp( arg2, "area" ) )
{
AREA_DATA *area = get_area( argument );
if ( area->filename )
asteroid->area = area;
else
{
send_to_char("That area doesn't exist!\n\r", ch );
return;
}
send_to_char( "Done.\n\r", ch );
save_asteroid( asteroid );
return;
}
if ( !str_cmp( arg2, "flags" ) )
{
char arg3[MAX_INPUT_LENGTH];
if ( !argument || argument[0] == '\0' )
{
send_to_char( "Usage: setasteroid <asteroid> flags <flag> [flag]...\n\r", ch );
send_to_char( "Valid flags are:\n\r", ch );
return;
}
while ( argument[0] != '\0' )
{
argument = one_argument( argument, arg3 );
tempnum = get_astflag( arg3 );
if ( tempnum < 0 || tempnum > 31 )
{
ch_printf( ch, "Unknown flag: %s\n\r", arg3 );
return;
}
TOGGLE_BIT( asteroid->flags, 1 << tempnum );
}
send_to_char( "Done.\n\r", ch );
save_asteroid( asteroid );
return;
}
do_setasteroid( ch, "" );
return;
}
//==============================================================================
//=================== End of make, copy, and set functions ====================
//=============================================================================
////////////////////////////////////////////////////////////////////////////////////////////