FindShip v1.1 by Odis
==================================================================
http://ew.xidus.net

Disclaimer
==========
This should work on all Smaug derivitives.
This code was tested on a heavily modified version of SWR 1.0, but is should work on
everyones code anyway. I retain no responsibility if this code does anything to
your code, your game, or the system it's running on.

This code may need to be modified, do to its nature and how its really set up. Anyways, yeah.

All code (eg. the flag system) copyrights and w/e belong to its/their respective owners. I'd
just like to say that I didn't write the flag system, so I don't want any credit for it.

Description
===========
Changes in V1.1:
Just changed a few format things, nothing big, and I realized I forgot that it said that it
would log it, so I added that in also. See Part 3: Instructions for adding logfs.

I forgot to do this in my last snippet, but then again, that one was pretty straight forward.
This code will allow a player who doesn't already own a ship to "find" a hidden ship. While,
its hidden, it will not show up on ships or allships, but will show up for immortals. The code
below will tell how to add in the ship flag system (if you haven't already, and if you
added in the cargo system or simulators or w/e then you prolly have it..) and how to add the
function and what not. Anyways, hope you like it.

Note: if you have the flag system skip down..don't forget to add the bit for it..

==================================================
Part 1: Instructions for adding in the flag system
==================================================

(1) mud.h

 Find:
 int          maxhull;

 Add (under):
 int          flags;          /* Ship Flags */


 Find:
 #define MOB_VNUM_BOUNCER        25

 Note: if thats not there add it above the ACT_ defines

 Add (couple lines under):

 /* Ship Flags */
 #define SHIP_HIDDEN             BV00

(2) space.c

 Find (in save_ship):
 fprintf( fp, "Navseat         %d\n",   ship->navseat            );

 Add (directly under):
 fprintf( fp, "Flags           %d\n", ship->flags       		 );
 

 Find:
 void fread_ship( SHIP_DATA *ship, FILE *fp )

 Scroll down a to  case 'F':

 Find:
 KEY( "Firstroom",   ship->firstroom,        fread_number( fp ) );

 Add (directly above):
 KEY( "Flags",   ship->flags,        fread_number( fp ) );
 

 Find:
 void do_showship( CHAR_DATA *ch, char *argument )

 Stick it where you want, or just make a new line like this:
 ch_printf( ch, "Flags: %s\n\r", flag_string(ship->flags, ship_flags) );

 Find:

 char *  const   bus_stop [MAX_BUS_STOP+1] =
 {
    /* last should always be same as first */
 };

Note: Yours will likely have stuff in there, I just don't use mine.

Add under:

char *  const   ship_flags [] =
{
"hidden","r01","r02","r03","r04","r05","r06","r07","r08","r09",
"r10","r11","r12","r13","r14","r15","r16","r17","r18","r19","r20",
"r21","r22","r23","r24","r25","r26","r27","r28","r29","r30","r31"
};

int get_shipflag( char *flag )
{
    int x;

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

 Find:
 void    sound_to_ship( SHIP_DATA *ship , char *argument );

 Add under:
 int     get_shipflag(char *flag );

 Find:
    if ( !str_cmp( arg2, "chaff" ) )
    {
        ship->chaff = URANGE( 0, atoi(argument) , 250 );
        ship->maxchaff = URANGE( 0, atoi(argument) , 250 );
        send_to_char( "Done.\n\r", ch );
        save_ship( ship );
        return;
    }

 Add under:
        if ( !str_cmp( arg2, "flags" ) )
        {
           char arg3[MAX_INPUT_LENGTH];

           if ( !argument || argument[0] == '\0' )
           {
               send_to_char( "Usage: setship <ship> flags <flag> [flag]...\n\r", ch );
               send_to_char( "Valid flags are: hidden\n\r", ch );
               return;
           }

           while ( argument[0] != '\0' )
           {
                argument = one_argument( argument, arg3 );
                tempnum = get_shipflag( arg3 );

                if ( tempnum < 0 || tempnum > 31 )
                {
                   ch_printf( ch, "Unknown flag: %s\n\r", arg3 );
                   return;
                }
                TOGGLE_BIT( ship->flags, 1 << tempnum );
           }
           send_to_char( "Done.\n\r", ch );
           save_ship( ship );
           return;
         }

=========================================================
End of Part 1: Instructions for adding in the flag system
=========================================================

================================================
Part 2: Instructions for adding findship command
================================================

(1) mud.h

 Find:
 DECLARE_DO_FUN( do_jail );

 Add:
 DECLARE_DO_FUN( do_findship );

(2) tables.c

 Find:
 if ( !str_cmp( name, "do_fill" ))               return do_fill;

 Add under:
 if ( !str_cmp( name, "do_findship" ))           return do_findship;

 Find:
 if ( skill == do_fill )             return "do_fill";
 
 Add under:
 if ( skill == do_findship )         return "do_findship";

 (3) space.c

 Find:
 void do_ships( CHAR_DATA *ch, char *argument )

 Go down a bit past:
 send_to_char( "&Y\n\rThe following ships are docked here:\n\r", ch );

 and into the for loop which looks like this:
 for ( ship = first_ship; ship; ship = ship->next )

 Find in the for loop:
 if (ship->type == MOB_SHIP)
 continue;

 Add under:
 else if ( IS_SET(ship->flags, SHIP_HIDDEN) && ch->top_level < LEVEL_IMMORTAL)
 continue;

 Now, find this:
 void do_allships( CHAR_DATA *ch, char *argument )

 Go down and find this:
 for ( ship = first_ship; ship; ship = ship->next )

 Find this in the loop:
 if (ship->type == MOB_SHIP)
 continue;

 Add under:
 if ( IS_SET(ship->flags, SHIP_HIDDEN) && ch->top_level < LEVEL_IMMORTAL)
 continue;


 Add this where ever, in fact it doesn't have to go in space.c even.

 Add this function:

 /*
 * Used in conjunction with the hidden flag so that players can find ships. When they find 
 * them they type foundship <ship name>. It will then take off the hidden flag and set the 
 * finder as owner. All of this is sent to a log file.				~Odis
 */

void  do_findship(CHAR_DATA *ch, char *argument )
{
     SHIP_DATA *ship;
     char buf[MAX_STRING_LENGTH];
 
     if (argument[0] == '\0')
     {
	send_to_char("Syntax: findship <ship name>\n\r", ch );
	return;
     }

     for ( ship = first_ship; ship; ship = ship->next )
     {
   	if ( !str_cmp(ship->owner,ch->name) )
	{
	    send_to_char("&RYou own a ship already!\n\r", ch );
	    return;
	}
     }

     ship = get_ship( argument );

     if (ship == NULL)
     {
        send_to_char("&RNo such ship!\n\r",ch);
        return;
     } 

     if (!IS_SET(ship->flags, SHIP_HIDDEN) )
     {
	send_to_char("&RThat ship isn't hidden! Try typing allships!\n\r", ch );
	return;
     }

/*
 * I decided against giving them a heads up, because this would tell them if that ship
 * existed and they only needed to find it, so it just returns. Sneaky, eh?	~Odis
 */

     if (IS_SET(ship->flags, SHIP_HIDDEN) && (ch->in_room->vnum != ship->location) )
     {
	return;
     }
     else if ( str_cmp(ship->owner,"") )
	return;

// Here's the good stuff...
     else
     {    
        STRFREE( ship->owner );
        STRFREE( ship->pilot );
        STRFREE( ship->copilot );
        ship->owner = STRALLOC( ch->name );
        ship->pilot = STRALLOC( "" );
        ship->copilot = STRALLOC( "" );
 	    REMOVE_BIT(ship->flags, SHIP_HIDDEN);
        sprintf( buf, "%s found by %s.", ship->name, ch->name );
        logfs( buf, 0 );
	    ch_printf( ch, "You have just found and now own %s!\n\r", ship->name );	
        return;
     }
}

Compile
=======
Make clean, then a Make (recompile).


In the mud type this:
cedit findship create do_findship
cedit findship level 1 (or what ever level you want it to be)
cedit save

Not much else you have to do to it. Of course its yours to do what you want with.

=======================================================
End of Part 2: Instructions for adding findship command
=======================================================

=====================================
Part 3: Instructions for adding logfs
=====================================

(1) mud.h

    Find this line:
    #define BUG_FILE        SYSTEM_DIR "bugs.txt"     /* For 'bug' and bug( )*/

    Add under it:
    #define LOGFS_FILE      SYSTEM_DIR "logfs.txt"    /* For logfs           */

    Find:
    void    bug             args( ( const char *str, ... ) );

    Add under:
    void    logfs           args( ( const char *str, ... ) );

(2) db.c

    Find the show_file function.

	Add -ABOVE- that:

/*
 * Add a string to the logfs log                                ~Odis
 */
void logfs( const char *str, ... )
{
    char filename[256];
    char buf[MAX_STRING_LENGTH];
    FILE *fp;
    va_list param;

    strcpy( buf, "[***] LOGFS: " );
    va_start(param, str);
    vsprintf( buf+strlen(buf), str, param );
    va_end(param);
    log_string( buf );

    fclose( fpLOG );

    sprintf( filename, "%s%s", SYSTEM_DIR, LOGFS_FILE );

    if ( ( fp = fopen( filename, "a" ) ) != NULL )
    {
        fprintf( fp, "%s\n", buf );
        fclose( fp );
    }
    fpLOG = fopen( NULL_FILE, "r" );

    return;
}

============================================
End of Part 3: Instructions for adding logfs
============================================

Ending Notes
============
V1.1 Change:
Go into the system folder and make a logfs.txt file. Just leave it blank. Every time someone
finds a ship it will say which ship was found by who. Its up to you to clear this log every
so often.

Alright, now, if you wan't it so they can find the ship even if they own one just delete
the for loop. To use just setship <ship> flags hidden to turn the flag on. As for
getting a ship where you want it, I recommend using transship. If you don't have it installed,
get it. Its available on kyndig.com. Go get it, its very useful. Anyways, yeah, hope you like
the code.

Compile
=======
Make clean, then a Make (recompile).


Contact Information:
===================

Please send comments, suggestions, bugs, etc. to my e-mail.

Odis, Owner, Coder, and Head Immortal of Gundam Wing: The Awakening
http://ew.xidus.net
huhahua@yahoo.com