/
roa/
roa/lib/boards/
roa/lib/config/
roa/lib/edits/
roa/lib/help/
roa/lib/misc/
roa/lib/plrobjs/
roa/lib/quests/
roa/lib/socials/
roa/lib/www/
roa/lib/www/LEDSign/
roa/lib/www/LEDSign/fonts/
roa/lib/www/LEDSign/scripts/
roa/src/s_inc/
roa/src/sclient/
roa/src/sclient/binary/
roa/src/sclient/text/
roa/src/util/
/************************************************************************
	Realms of Aurealis 		James Rhone aka Vall of RoA

madept.c				Code relating to the Madept class

		******** 100% Completely Original Code ********
		*** BE AWARE OF ALL RIGHTS AND RESERVATIONS ***
		******** 100% Completely Original Code ********
		        All rights reserved henceforth. 

    Please note that no guarantees are associated with any code from
Realms of Aurealis.  All code which has been released to the general
public has been done so with an 'as is' pretense.  RoA is based on both
Diku and CircleMUD and ALL licenses from both *MUST* be adhered to as well
as the RoA license.   *** Read, Learn, Understand, Improve ***
*************************************************************************/
#include "conf.h"
#include "sysdep.h"

#include "structures.h"
#include "utils.h"
#include "comm.h"
#include "interpreter.h"
#include "acmd.h"
#include "handler.h"
#include "db.h"
#include "roaolc.h"
#include "magic.h"
#include "madept.h"
#include "affect.h"
#include "fight.h"
#include "global.h"

// internal functions...
ROA_MENU(madedit_top_menu);
ROA_MENU(madedit_circle_menu);
ROA_MENU(madedit_confirm_quit);
ROA_MENU(madedit_confirm_quit_final);

// assign initial creation points, send intro, etc
void init_madept(chdata *ch)
{
  // determine CP based on INT and WIS
  CP(ch) = (GET_INT(ch) + GET_WIS(ch)) * 15;

  // ok allocate && assign
  CREATE(ch->tmp_skills, skl_info, MAX_SKILLS);
  memcpy(ch->tmp_skills, ch->skills, sizeof(skl_info) * MAX_SKILLS);

  // set this flag... won't be able to choose 
  SET_BIT(PLR_FLAGS(ch), PLR_BUILDING);
  MENU_DEPTH(ch) = 0;
  ch->pc_specials->field_changed = FALSE;
  menu_jump(ch, madedit_top_menu);
}

ACMD(do_madept)
{
  if (IS_IMMORTAL(ch))
    init_madept(ch);
  else
  if (IS_NAT_MADEPT(ch) && GET_LEVEL(ch) <= 1 && !PRF2_FLAGGED(ch, PRF2_CHOSEN))
    init_madept(ch);
  else
    send_to_char("You are unable to do such.\n\r",ch);
}

// how much CP do spells in this circle cost?
int madept_cost(int circle)
{
  return circle * 10; 
}

ROA_MENU(madedit_top_menu)
{
  char *p;
  int field, i;
  
  if (!input_str)
  {
    if (PLR_FLAGGED(ch, PLR_REFRESH))
      clrscr(ch);
    send_to_char("\n\r    %B%5Madept Main Menu%0\n\n\r",ch);

    sprintf(buf, "%%B%%5Creation Points%%0: %d\n\n\r", CP(ch));
    S2C();

    for (i = 1; i < 8; i++)
    {
      sprintf(buf, "%d.) %%6Circle %d%%0: levels %d - %d, %d pts per spell.\n\r",
              i, i, (i*10)-9, (i*10), madept_cost(i));
      S2C();
    }

    send_to_char("\n\r", ch);

    CIRCLE_NUM(ch) = 0;
    MENU_PROMPT(ch) = "Enter your choice: ";
    return;
  }

  strcpy(buf, input_str);
  p = strtok(buf, "   \n\r");
  if (p)
    field = atoi(p);
  else
    field = 0;

  if (!field)
    menu_jump(ch, madedit_confirm_quit);
  else
  if (field < 1 || field > 7)
    send_to_char("That field cannot be changed.\n\r", ch);
  else
  {
    CIRCLE_NUM(ch) = field;
    menu_push_jump(ch, madedit_circle_menu);
  }
}

ROA_MENU(madedit_circle_menu)
{
  char *p;
  int field, i, j, k, low, high;
  int top;
  
  // each circle / range is 10 levels
  low = CIRCLE_NUM(ch) * 10 - 9;
  high= CIRCLE_NUM(ch) * 10;

  if (!input_str)
  {
    if (PLR_FLAGGED(ch, PLR_REFRESH))
      clrscr(ch);

    send_to_char("\n\r    %B%5Madept Spell Choice Menu%0\n\n\r",ch);

    sprintf(buf, "%%B%%5Creation Points%%0: %d\n\n\r", CP(ch));
    S2C();

    for (i = k = 0, j = 1; i < MAX_SKILLS; i++)
      if (clarray[CLASS_MADEPT].skills[i].minlevel >= low && clarray[CLASS_MADEPT].skills[i].minlevel <= high)
      {
        sprintf(buf, "%d.) %%B%s%%0%%5%-20.20s%%0", j, ch->tmp_skills[i].learned ? "* ":"", skill_names[i]);

        if ( (k = !k) )
          strcat(buf, "\t");
        else
          strcat(buf, "\n\r");

        S2C();
        j++; 
      }

    send_to_char("\n\r", ch);
    MENU_PROMPT(ch) = "Enter your choice: ";
    return;
  }

  // get choice bounds...
  for (i = 0, top = 1; i < MAX_SKILLS; i++)
    if (clarray[CLASS_MADEPT].skills[i].minlevel >= low && clarray[CLASS_MADEPT].skills[i].minlevel <= high)
      top++;
  
  strcpy(buf, input_str);
  p = strtok(buf, "   \n\r");
  if (p)
    field = atoi(p);
  else
    field = 0;

  if (!field)
  {
    menu_back(ch);
    return;
  }
  else
  if (field < 1 || field >= top)
    send_to_char("That field cannot be changed.\n\r", ch);
  else
  {
    for (i = 0, k = 1; i < MAX_SKILLS; i++)
      if (clarray[CLASS_MADEPT].skills[i].minlevel >= low && clarray[CLASS_MADEPT].skills[i].minlevel <= high)
      {
        if (k == field) 
          break;
        else
          k++; 
      }

    if (k != field) return;

    if (!ch->tmp_skills[i].learned) 
    {
      if (CP(ch) >= madept_cost(CIRCLE_NUM(ch)))
      {
        ch->tmp_skills[i].learned = TRUE;
        CP(ch) -= madept_cost(CIRCLE_NUM(ch));
      }
    }
    else
    {
      ch->tmp_skills[i].learned = FALSE;
      CP(ch) += madept_cost(CIRCLE_NUM(ch));
    }
  }

  menu_jump(ch, madedit_circle_menu);
}

ROA_MENU(madedit_confirm_quit_final)
{
  char buf[MAX_STRING_LENGTH];
  char *p;

  if (!input_str)
  {
    MENU_PROMPT(ch) = "Are you ABSOLUTELY sure (yes/NO)? ";
    return;
  }

  strcpy(buf, input_str);
  p = strtok(buf, "     \n\r");
  if (p && strncasecmp("yes", p, strlen(p)) == 0)
  {
    // copy back now... and free the temps
    if (ch->tmp_skills)
      memcpy(ch->skills, ch->tmp_skills, sizeof(skl_info) * MAX_SKILLS);

    FREENULL(ch->tmp_skills);
    MENU_PROMPT(ch)  = NULL;
    MENU_HANDLER(ch) = NULL;
    MENU_DEPTH(ch)   = 0;
    REMOVE_BIT(PLR_FLAGS(ch), PLR_BUILDING);

    SET_BIT(PRF2_FLAGS(ch), PRF2_CHOSEN);
  }
  else
    menu_jump(ch, madedit_top_menu);
}

// first quit called...
ROA_MENU(madedit_confirm_quit)
{
  char buf[MAX_STRING_LENGTH];
  char *p;

  if (!input_str)
  {
    MENU_PROMPT(ch) = "Are you finished (yes/NO)? ";
    return;
  }

  strcpy(buf, input_str);
  p = strtok(buf, "     \n\r");
  if (p && strncasecmp("yes", p, strlen(p)) == 0)
    menu_jump(ch, madedit_confirm_quit_final);
  else
    menu_jump(ch, madedit_top_menu);
}