/*
//////////////////////////////////////////////////////////////////////
// Author: Ed Langenback  apostle@pokynet.com
// Version: 1.0
// Date: 02/25/02
// setup help for the connected state blacksmith system included 
// in arcmod 1.0 by Mike Smullins  (smote@mindless.com)
// Code originally written for Aarchon Mud.  mud.aarchonmud.com:7000
// (arcmod 1.0 can be found on kyndig.com, search for 'arcmod.zip')
// http://www.kyndig.com/cgi-bin/codes/search.cgi?query=arcmod
// you WILL need smith.c from this file!
//////////////////////////////////////////////////////////////////////
*/


/*
Why did I make this up?  That's easy, when arcmod.zip was distributed,
it was with VERY little in the way of documentation or install instructions.
I spent longer than I will admit trying to get this thing to work, and
now that I have, I decided that I would make something available to make
installation of this blacksmith easier for others like myself.

If anyone has done a similar file for the rest of the arcmod 1.0 
package, then I'd be interested in hearing about successful implementations
of it, or better yet.. a copy of a file like this written for it.
I am particularly interested in good methods to evenly integrate all
10 stats into the mud as smoothly as is done on Aarchon.

NOTE: you WILL need the file 'smith.c' from arcmod.zip, which you can find
at http://www.kyndig.com/cgi-bin/codes/search.cgi?query=arcmod
*/


/*
put smith.c into your src directory and
add smith.o to the o-files listed in your makefile
*/


/* Grep for these declarations */
bool get_name            args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool get_old_password         args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool confirm_new_name         args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool get_new_password         args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool confirm_new_password     args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool get_new_race        args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool get_new_sex              args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool get_new_class       args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool get_alignment       args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool default_choice      args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool gen_groups               args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool pick_weapon              args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool read_imotd               args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool read_motd           args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool break_connect       args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool get_creation_mode        args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool roll_stats               args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool get_stat_priority        args( ( DESCRIPTOR_DATA *d, char *argument ) );

/* ...And add these to them */

void do_smith		 args( (CHAR_DATA *ch, char *argument) );
bool smith_welcome       args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool smith_type               args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool smith_subtype       args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool smith_purchase      args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool smith_material      args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool smith_quality       args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool smith_color              args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool smith_personal      args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool smith_level              args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool smith_keywords      args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool smith_select        args( ( DESCRIPTOR_DATA *d, char *argument ) );
bool smith_inventory          args( ( DESCRIPTOR_DATA *d, char *argument ) );

int creation_mode        args((DESCRIPTOR_DATA *d) );
int con_state            args((DESCRIPTOR_DATA *d) );
void set_creation_state  args((DESCRIPTOR_DATA *d, int cmode) );
void remort_complete     args((CHAR_DATA *ch ) );

/* i've got nanny(); split off into it's own file (nanny.c)
[this is recomended, makes it easier to deal with.]
locate yours . . .
*/


void nanny( DESCRIPTOR_DATA *d, char *argument )
{
	switch (creation_mode(d) )
	{

	default:
		switch ( con_state(d) )
		{

		default:
		bug( "Nanny: bad d->connected %d.", d->connected );
		close_socket( d );
		return;
[snip . . .]

/*
If you're not using the nanny.c file from arcmod.zip, you may or may not
have a creation_mode switch in your nanny() function, if you don't, you'll
need to add one.  see nanny.c from arcmod.zip for a look at how it needs
to work.

In switch(creation_mode(d) ), add a new case for CREATION_BLACKSMITH
and plug this code in there.

*/
   
	case CREATION_BLACKSMITH:
		switch ( con_state(d) )
		{

		default:
		bug( "Nanny: bad d->connected %d.", d->connected );
		close_socket( d );
		return;

		case CON_SMITH_WELCOME:
			if (smith_welcome(d, argument)) smith_level(d, "");
			break;

		case CON_SMITH_LEVEL:
			if (smith_level(d, argument)) smith_type(d, "");
			break;

		case CON_SMITH_TYPE:
			if (smith_type(d, argument)) smith_subtype(d, "");
			break;

		case CON_SMITH_SUBTYPE:
			if (smith_subtype(d, argument)) smith_quality(d, "");
			break;

		case CON_SMITH_QUALITY:
			if (smith_quality(d, argument)) smith_material(d, "");
			break;

		case CON_SMITH_MATERIAL:
			if (smith_material(d, argument)) smith_purchase(d, "");
			break;

		case CON_SMITH_PURCHASE:
			if (smith_purchase(d, argument)) d->connected=CON_PLAYING;
			break;

		case CON_SMITH_COLOR:
			if (smith_color(d, argument)) smith_purchase(d, "");
			break;

		case CON_SMITH_PERSONAL:
			if (smith_personal(d, argument)) smith_keywords(d, "");
			break;
	
		case CON_SMITH_KEYWORDS:
			if (smith_keywords(d, argument)) smith_purchase(d, "");
			break;

		case CON_SMITH_SELECT:
			if (smith_select(d, argument)) smith_inventory(d, "");
			break;

		case CON_SMITH_INVENTORY:
			if (smith_inventory(d, argument)) d->connected=CON_PLAYING;
			break;
	
		}


		break;

/*
At the end of nanny.c, or in the same file as the nanny()function,
add this routine.  */


/*
do_smith originally written by Thomas Langenback,
fine tuned by me.

-Ed
*/

void do_smith (CHAR_DATA *ch, char *argument)

{
	DESCRIPTOR_DATA	*d=ch->desc;
	CHAR_DATA	*pMob;
	bool		found=FALSE;
	
	for (pMob = ch->in_room->people;pMob != NULL;pMob = pMob->next_in_room)
	{
		if (!IS_NPC(pMob))
			continue;
		if (IS_SET(pMob->act, ACT_SMITH))
			found = TRUE;

	set_creation_state(d, CREATION_BLACKSMITH);
	set_con_state(d, CON_SMITH_WELCOME); 
	smith_welcome(d,"");
			break;
			return;
	}

	if (!found)
	{
		send_to_char("There's no Smith here.\n\r", ch);
		return;
	}	
}


/* 
add declarations for the smith command 
to the command tables in interp.h
*/

DECLARE_DO_FUN( do_smith        );

/*
 and interp.c
*/

    { "smith",          do_smith,       POS_STANDING,    0,  LOG_NORMAL, 1 },


/*
In merc.h, define the following con_states and increase
MAX_CON_STATE apropriately.
*/


#define CON_SMITH_WELCOME       26
#define CON_SMITH_TYPE          27
#define CON_SMITH_SUBTYPE       28
#define CON_SMITH_PURCHASE      29
#define CON_SMITH_MATERIAL      30
#define CON_SMITH_QUALITY       31
#define CON_SMITH_COLOR         32
#define CON_SMITH_PERSONAL      33
#define CON_SMITH_LEVEL         34
#define CON_SMITH_KEYWORDS      35
#define CON_SMITH_SELECT        36
#define CON_SMITH_INVENTORY     37

/*
if you're adding the rest of the stuff from arcmod.zip,
you'll need all of these.  otherwise you just need 
CREATION_BLACKSMITH
*/

#define CREATION_UNKNOWN         0
#define CREATION_INSTANT         1
#define CREATION_QUICK           2
#define CREATION_NORMAL          3
#define CREATION_REMORT          4
#define CREATION_BLACKSMITH     5

/*
add the needed ACT_ (or ACT2_) bit:
if you make it an ACT2_ be sure to change do_smith to reflect this.
*/
#define ACT_SMITH             (ee)




/*
make this value whatever you use to define
a dummy prototype object in limbo.are
for the smith to build from
*/

#define OBJ_VNUM_BLACKSMITH        30  


/*
add this field to struct    pc_data
*/

    OBJ_DATA  *         smith;

/*
add these fields to struct    obj_data
*/

    int             durability;
    bool            smith;



/*
in tables.c, locate 
const struct flag_type act_flags[] =
look for:
    {     "gain",             bb,  TRUE },
    {     "update_always",    cc,  TRUE },
    {     "changer",          dd,  TRUE },
*/

/* and add: */

    {     "smith",            ee,  TRUE },

/*
this will make ACT_SMITH a valid choice in olc for mob editing.
*/

/*
create a mob, make sure ACT_SMITH is set on it,
set ACT_SENTINEL (unless you WANT a wandering smith),
make it's level high enough so that you wont have players killing 
it all the time... or not.. it's up to you.  <cackle>
and put in a reset to load it where-ever you want your smith to be.
do a clean compile and restart.

now when a player is in the same room as the smith they can use the 'smith' command
to start the blacksmith routine.

*note*  this code assumes that you have bank code in, and so extracts
the cost of the item from the players bank account if they dont have it on them.
if you don't have a bank, I would recommend thinking about it.
it also assumes that players can have quest points, because some things 
require quest points in addition to large ammounts of gold.

to keep from having ultra powerfull players really fast, you might consider
making the smith more expensive, or gold harder to come by.  I'm certain 
however that the second option will go over like a turd in a punchbowl at
a wedding, and therefore cannot recommend it.

*/



/*
DISCLAIMER & LICENCE:
I *THINK* that i've covered everything here, but anything's possible, and 
I could have missed something.  If so it shouldn't be too difficult to 
track down whatever it is.

this file may be freely re-distributed intact
so long as proper credit is given.

as for arcmod.zip, you'll have to ask Mike Smullins about that, i've tried 
the email he gave in his file, but there was never any indication that it was 
recieved.
*/