/**************************************************************
 *  Myth Mud improvements ALL by David Spink aka Morglum.     *
 *  This mud is NOT to be copied in whole or in part! No one  *
 *  has the permission to authorise the use of this code.     *
 *  In order to use this code you MUST comply with the terms  *
 *  and conditions in 'license.myth' (as shipped).            *
 **************************************************************/

#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "merc.h"


DO_COM( do_autostance )
 {
    char arg      [MAX_INPUT_LENGTH];
    char buf      [MAX_STRING_LENGTH];
    int  stn;
    bool got_adv = FALSE;

	if (IS_NPC(ch)) return;
    argument = one_argument( argument, arg );
	stn = -1;

    if (!str_cmp(arg,"none")    ) stn = STANCE_NONE;
    else if (!str_cmp(arg,"viper")   ) stn = STANCE_VIPER;
    else if (!str_cmp(arg,"crane")   ) stn = STANCE_CRANE;
    else if (!str_cmp(arg,"crab")    ) stn = STANCE_CRAB;
    else if (!str_cmp(arg,"mongoose")) stn = STANCE_MONGOOSE;
    else if (!str_cmp(arg,"bull")    ) stn = STANCE_BULL;
	if (stn == -1) {
		strcpy(buf, "Advanced stances:");
		if (ch->stance[STANCE_CRANE] >= 200 &&
		 ch->stance[STANCE_VIPER] >= 200) {
			strcat(buf, " Mantis"); got_adv = TRUE;
			if (!str_cmp(arg, "mantis"))
				stn = STANCE_MANTIS;
		}
		if (ch->stance[STANCE_BULL] >= 200 &&
		 ch->stance[STANCE_CRAB] >= 200) {
			strcat(buf, " Dragon"); got_adv = TRUE;
			if (!str_cmp(arg, "dragon"))
				stn = STANCE_DRAGON;
		}
		if (ch->stance[STANCE_BULL] >= 200 &&
		 ch->stance[STANCE_VIPER] >= 200) {
			strcat(buf, " Tiger"); got_adv = TRUE;
			if (!str_cmp(arg, "tiger"))
				stn = STANCE_TIGER;
		}
		if (ch->stance[STANCE_CRANE] >= 200 &&
		 ch->stance[STANCE_MONGOOSE]>= 200) {
			strcat(buf, " Monkey"); got_adv = TRUE;
			if (!str_cmp(arg, "monkey"))
				stn = STANCE_MONKEY;
		}
		if (ch->stance[STANCE_CRAB] >= 200 &&
		 ch->stance[STANCE_MONGOOSE] >= 200) {
			strcat(buf, " Swallow"); got_adv = TRUE;
			if (!str_cmp(arg, "swallow"))
				stn = STANCE_SWALLOW;
		}
		strcat(buf, ".\n\r");

		if (stn == -1 && strlen(ch->pcdata->stancelist) > 1) {
			int namecount = loc_name(arg, ch->pcdata->stancelist);
			if (namecount > -1 && namecount < 5)
				if (IS_SET(ch->pcdata->qstats[namecount], QS_DONE))
					stn = namecount + 11;
		}

		if (stn == -1) {
			send_to_char("Syntax: autostance <name>.\n\r",ch);
			send_to_char("Basic stances: Viper Crane Crab Mongoose Bull.\n\r", ch);
			if (got_adv) send_to_char(buf, ch);
			if (strlen(ch->pcdata->stancelist) > 1) {
				sprintf(buf,"Super stances: %s.\n\r",ch->pcdata->stancelist);
				send_to_char(buf, ch);
			}
			return;
		}
	}
    ch->pcdata->autostance = stn;
	strcpy(buf, "Autostance set to: ");
	switch (stn) {
	case 0: strcat(buf, "None"); break;
	case 1: strcat(buf, "Viper"); break;
	case 2: strcat(buf, "Crane"); break;
	case 3: strcat(buf, "Crab"); break;
	case 4: strcat(buf, "Mongoose"); break;
	case 5: strcat(buf, "Bull"); break;
	case 6: strcat(buf, "Mantis"); break;
	case 7: strcat(buf, "Dragon"); break;
	case 8: strcat(buf, "Tiger"); break;
	case 9: strcat(buf, "Monkey"); break;
	case 10: strcat(buf, "Swallow"); break;
	case 11: case 12: case 13: case 14: case 15:
		strcat(buf, capitalize(arg)); break;
	}
	strcat(buf, "\n");
	send_to_char(buf, ch);
    return;
}

void autodrop(CHAR_DATA *ch) {

        int st;
        char buf [MAX_INPUT_LENGTH];
        char buf2 [MAX_INPUT_LENGTH];
        char stancename [10];

        if (IS_NPC(ch)) return;

        st = ch->pcdata->autostance;
        if (st == STANCE_VIPER) sprintf(stancename,"viper");
        else if (st == STANCE_CRANE) sprintf(stancename,"crane");
        else if (st == STANCE_CRAB) sprintf(stancename,"crab");
        else if (st == STANCE_MONGOOSE) sprintf(stancename,"mongoose");
        else if (st == STANCE_BULL) sprintf(stancename,"bull");
        else if (st == STANCE_MANTIS) sprintf(stancename,"mantis");
        else if (st == STANCE_DRAGON) sprintf(stancename,"dragon");
        else if (st == STANCE_TIGER) sprintf(stancename,"tiger");
        else if (st == STANCE_MONKEY) sprintf(stancename,"monkey");
        else if (st == STANCE_SWALLOW) sprintf(stancename,"swallow");
        else if (st == STANCE_SUPER1) sprintf(stancename,"1st super");
        else if (st == STANCE_SUPER2) sprintf(stancename,"2nd super");
        else if (st == STANCE_SUPER3) sprintf(stancename,"3rd super");
        else if (st == STANCE_SUPER4) sprintf(stancename,"4th super");
        else if (st == STANCE_SUPER5) sprintf(stancename,"5th super");

        else return;

        if (ch->stance[0] < 1) {
        ch->stance[0] = st;

        sprintf(buf, "You autodrop into the %s stance.", stancename);
        act(buf, ch, NULL, NULL, TO_CHAR);
        sprintf(buf2, "$n autodrops into the %s stance.", stancename);
        act(buf2, ch, NULL, NULL, TO_ROOM);
}
}