/************************************************************************
 * Meta store procedure.		By Rafiq "JurniMan" Premji	*
 * (Implementor After Armageddon MUD - jurniman.com 6666)		*
 * Originally by Cris Jacobin (jacobin@bellatlantic.net)		*
 *									*
 * This procedure needs to go into your spec_procs.c file.  Also,	*
 * please give due credit if you use this function in your MUD.		*
 *									*
 * (Reformatted/Struct-urized by George Greer, greerga@circlemud.org)	*
 ************************************************************************/

#include "conf.h"
#include "sysdep.h"
#include "structs.h"
#include "utils.h"

SPECIAL(meta_store)
{
  /*
   * This would be far easier if hmv/sdciwc where the same data type. -gg
   */
  struct char_data *mob = (struct char_data *)me;
  int i, mod, meta_type;
  sh_int *hmv = NULL;
  sbyte *statmod = NULL;

  struct {
    int cost;		/* Cost of change, in gold pieces. 		*/
    int exp;		/* Experience deduction for this service.	*/
    char *message;	/* Success message.				*/
    int apply;		/* APPLY_xxx number, from structs.h.		*/
    int max_app;	/* Maximum value of number to change.		*/
    int mod_min;	/* Smallest addition to increase.		*/
    int mod_max;	/* Maximum increase to give.			*/
    char *cannot;	/* Already at maximum message.			*/
  } metastoof[] = {
    /*
     * Tweak these to suit your MUD because you will be different. -gg
     */
    { 50000, 1000000, "Your maximum hitpoints increase!\r\n", APPLY_HIT, 
		-1, 20, 40, NULL },
    { 50000, 1000000, "You your mana raise!\r\n", APPLY_MANA,
		-1, 30, 50, NULL },
    { 50000, 1000000, "You feel more endurance ability!\r\n", APPLY_MOVE,
		-1, 20, 40, NULL },
    { 100000, 3000000, "You feel stronger!\r\n", APPLY_STR,
		25, 1, 1, "You are as naturally strong as you can be.\r\n" },
    { 100000, 3000000, "You feel smarter!\r\n", APPLY_INT,
		25, 1, 1, "Sorry, you cannot understand any more.\r\n" },
    { 100000, 3000000, "You feel more wise!\r\n", APPLY_WIS,
		25, 1, 1, "Sorry, I cannot make you any more wise.\r\n" },
    { 100000, 3000000, "You feel faster!\r\n", APPLY_DEX,
		25, 1, 1, "Sorry, you are already as agile as you can be.\r\n" },
    { 100000, 3000000, "You suddenly feel more hardy.\r\n", APPLY_CON,
		25, 1, 1, "Sorry, you are as hardy as you can be.\r\n" },
    { 100000, 3000000, "Your social skills increase!\r\n", APPLY_CHA,
		25, 1, 1, "Sorry, your charisma is already godlike.\r\n" },
/*
 * Example for exchanging 100 gold for 1 platinum, make sure to add an
 * APPLY_PLATINUM #define to structs.h where you see APPLY_GOLD.
 *
 *  { 100, 0, "Your gold has been exchanged.\r\n", APPLY_PLATINUM,
 *		-1, 1, 1, NULL },
 */
    { -1, -1, NULL, -1, -1, -1, -1, NULL }
  };

  if (CMD_IS("meta")) {
    meta_type = atoi(argument) - 1;
    for (i = 0; metastoof[i].cost != -1 && i != meta_type; i++);
    /*
     * The ordering (and number) is completely arbitrary now.  In fact,
     * if you added another field to the structure, you could use words. -gg
     */
    if (i != meta_type) {
      send_to_char(	"____________________________________\r\n"
			"#  Stat Raised:   Exp:        Gold: \r\n"
			"____________________________________\r\n"
			"1  health         1,000,000   50,000\r\n"
			"2  mana           1,000,000   50,000\r\n"
			"3  movement       1,000,000   50,000\r\n"
			"-  -------------  ---------  -------\r\n"
			"4  str (max: 25)  3,000,000  100,000\r\n"
			"5  dex (max: 25)  3,000,000  100,000\r\n"
			"6  con (max: 25)  3,000,000  100,000\r\n"
			"7  int (max: 25)  3,000,000  100,000\r\n"
			"8  wis (max: 25)  3,000,000  100,000\r\n"
			"9  cha (max: 25)  3,000,000  100,000\r\n"
			"That option does not exist.\r\n", ch);
      return TRUE;
    }

    /* i is now valid. */
    if (GET_GOLD(ch) < metastoof[i].cost)
      do_say(me, "You don't have enough gold for that.", 0, 0);
    else if (GET_EXP(ch) < metastoof[i].exp)
      do_say(me, "You don't have enough experience for that option.", 0, 0);
    else {
      switch (metastoof[i].apply) {
      case APPLY_STR: statmod = &GET_STR(ch); break;
      case APPLY_DEX: statmod = &GET_DEX(ch); break;
      case APPLY_CON: statmod = &GET_CON(ch); break;
      case APPLY_INT: statmod = &GET_INT(ch); break;
      case APPLY_WIS: statmod = &GET_WIS(ch); break;
      case APPLY_CHA: statmod = &GET_CHA(ch); break;
      case APPLY_HIT: hmv = &GET_MAX_HIT(ch); break;
      case APPLY_MANA: hmv = &GET_MAX_MANA(ch); break;
      case APPLY_MOVE: hmv = &GET_MAX_MOVE(ch); break;
      /*
       * Add more APPLY_xxx's here if you need more.
       */
      default:
        log("SYSERR: metaphysician: unknown modification.");
        return TRUE;
      }

      if ((hmv && metastoof[i].max_app <= *hmv) || (statmod && metastoof[i].max_app <= *statmod)) {
	send_to_char(metastoof[i].cannot, ch);
	return TRUE;
      }
      GET_EXP(ch) -= metastoof[i].exp;
      GET_GOLD(ch) -= metastoof[i].cost;
      mod = number(metastoof[i].mod_min, metastoof[i].mod_max);
      if (hmv)
	*hmv += mod;
      if (statmod)
	*statmod += mod;
      send_to_char(metastoof[i].message, ch);
    }	/* end of valid metastoof and enough gold/exp */
    return TRUE;
  }	/* end of valid metastoof */

  return FALSE;		/* Person didn't type 'meta' */
}
