Snippet Name - Dynamic assignment of spells/skills
Orignal Creator - Erwin <erwin@andreasen.org>
Reformatted - Famine <admin@malicex.org>
Codebase - Rogue25b2 ONLY!


-----Notes-----
This was reformatted for new programmers using RogueMUD directives.
This will work and compile CLEAN under this codebase. 
This will also contain better DETAILED instructions on how to install this snippet.
Please include the credit of the original owner where it is needed.



-----Desc--------
This is a command for a easy way to set skills/spells to classes from within the mud.
Sometimes you will make new classes and don't feel like editing every single coloum in const.cpp
So this is used to add the skills/spells to each class.
This will include some functions as well to help save the classes to a directory for editing/loading.
So when you are done installing this code. All your classes will be saved in ASCII form to a directory.
Then you can use the command to edit these classes as easy as pie!
I hope you enjoy what Erwin has created!



-----Install-----

(Merc.h)

1 - Find this line "extern    const    struct  skill_type      skill_table     [MAX_SKILL];" and remove the word "Const" from it.

2 - Add in these 2 lines anywhere in this file. 
void    save_classes(); 
void    load_classes();

3 - Find this line "#define LCMD_FILE       DATA_DIR "last_command.txt"" and add this under it on a new line. #define CLASS_DIR       "../data/class/"




(act_wiz.cpp)

1 - Copy and paste this whole seg of code at the  bottom of act_wiz.cpp.



// COPY TILL END!!!!!!!!!!

void save_class (int num)
{
        FILE *fp;
        char buf[MAX_STRING_LENGTH];
        int lev, i;

        sprintf (buf, "%s%s", CLASS_DIR, class_table[num].name);

        if (!(fp = fopen (buf, "w")))
        {
                log ("Could not open file %s in order to save class %s.", buf, class_table[num].name);
                return;
        }


        for (lev = 0; lev < LVL_IMMORT; lev++)
                for (i = 0; i < MAX_SKILL; i++)
                {
                        if (!skill_table[i].name || !skill_table[i].name[0])
                                continue;

                        if (skill_table[i].skill_level[num] == lev)
                                fprintf (fp, "%d %s\n", lev, skill_table[i].name);
                }

        fprintf (fp, "-1"); /* EOF -1 */
        fclose (fp);
}

void load_class (int num)
{
        char buf[MAX_STRING_LENGTH];
        int level,n;
        FILE *fp;

        sprintf (buf, "%s%s", CLASS_DIR, class_table[num].name);

        if (!(fp = fopen (buf, "r")))
        {
                log ("Could not open file %s in order to load class %s.", buf, class_table[num].name);
                return;
        }

        fscanf (fp, "%d", &level);

        while (level != -1)
        {
                fscanf (fp, " %[^\n]\n", buf); /* read name of skill into buf */

                n = skill_lookup (buf); /* find index */

                if (n == -1)
                {
                        char buf2[200];
                        sprintf (buf2, "Class %s: unknown spell %s", class_table[num].name, buf);
                        bug (buf2, 0);
                }
                else
                        skill_table[n].skill_level[num] = level;

                fscanf (fp, "%d", &level);
        }

        fclose (fp);
}

void save_classes()
{
        int i;

        for (i = 0; i < MAX_CLASS; i++)
                save_class (i);
}

void load_classes ()
{
        int i,j;

        for (i = 0; i < MAX_CLASS; i++)
        {
                for (j = 0; j < MAX_SKILL; j++)
                        skill_table[j].skill_level[i] = LVL_IMMORT;

                load_class (i);
        }
}



ACMD (do_skillset)
{
   char class_name[MAX_INPUT_LENGTH], skill_name[MAX_INPUT_LENGTH], buf[MSL];
   int level, class_no, sn;

   argument = one_argument (argument, class_name);
   argument = one_argument (argument, skill_name);

   if (!argument[0])
   {
      send_to_char ("Syntax is: SKILL <class> <skill> <level>.\n\r",ch);
      return;
   }

   level = atoi (argument);

   if (!is_number(argument) || level < 0 || level > LVL_IMMORT)
   {
      sprintf (buf, "Level range is from 0 to %d\n\r", LVL_IMMORT);
      send_to_char(buf,ch);
      return;

   }

   if ( (sn = skill_lookup (skill_name)) == -1)
   {
      sprintf (buf, "There is no such spell/skill as '%s'.\n\r", skill_name);
      send_to_char(buf,ch);
      return;
   }

        for (class_no = 0; class_no < MAX_CLASS; class_no++)
                if (!str_cmp(class_name, class_table[class_no].who_name))
                        break;

   if (class_no == MAX_CLASS)
   {
      sprintf (buf, "No class named '%s' exists. Use the 3-letter WHO names\n\r", class_name);
      send_to_char(buf,ch);
      return;
   }

        skill_table[sn].skill_level[class_no] = level;


          sprintf (buf, "OK, %ss will now gain %s at level %d%s.\n\r", class_table[class_no].name, skill_table[sn].name, level, level == LVL_IMMORT ? " (i.e. never)" : "");
          send_to_char(buf,ch);

save_classes();

}

// END OF CODE!!!!!!!!!!!!!!!!!!!!!

2 - Save





(Const.cpp)

1 - Find this line "const struct  skill_type      skill_table     [MAX_SKILL]     =" and remove "Const".
2 - Save


(Db.cpp)

1 - Find this line "load_clan_table();" and add "save_classes();" under it.
2 - Save.




----Instructions on Booting/Compiling-----

Ok you should be done with the installation part. Now we must compile and reboot the mud so "Save_Classes" will save to the correct directory.
So when you reboot and all goes well then check your "/data/class/" directory to make sure your classes saved.
Once that is done. You want to go ahead and add "Skillset" to the commands. You should be familar with Rogues "cmdedit" by now.
Just in case you're not. Type "cmdedit create skillset" and set the command for immortal use. So your mortals wont have this command :)

Next you will now need to remove "save_classes();" from db.cpp. In it's replace add this.

    log("Loading Classes");
    load_classes();

Now you should be all set to reboot again. Good Luck!
If you have any problems with this snippet because I forgot something then please contact me by e-mail or aim "ifamiinie".
Enjoy!

-Famine