group.txt
snippets · 3.5 KB · 2010-03-30
group.c: an odd group display piece of code (by Thri).
Download « Back to the snippets list
/* File: Group.c
* Usefulness: None, unless your lazy like Thri.
*
* Description:
* Ok this is the oddest piece of code ive ever writen.
* Basicly, what it does, is.. takes all your Skill names defined
* in skill_table, and writes them into a group_table, into the file
* group.c.
*
* Why would you use this?:
* If your like me, your extremely lazy. And, since your like me,
* you also extremely dislike the group table thingy and find its only
* an annoyance meant to piss off coders even more when they just want
* to add a new skill. This, is my answer to 'fixing' the group table.
* Since I dont care about groupings of skills in my mud, and would
* rather setskill mage identify 2, actually GIVE the spell at level 2
* instead of having to recomplie every time to add it to that damn
* group_table. So, instead of removing the group_table, i worked around it.
*
* Installation:
* Ok first things first. Make sure your MAX_SKILL is right.
* Then, make MAX_IN_GROUP the same as max_skill.
* (since everything is going to be in one group now)
* Add the appropirate number of 0's into the
* "rom basics" line in group_table_update
* Add do_print_skills to interp.h and interp.c
* Recomplie.
* do your do_print_skills command.
* Now, group.c will be in ../src/ directory.
* Now open const.c and delete that awful group_table
* Make clean
* make
* Start the mud.
* And your done!
*
* Credits: Russ Taylor for making that annoying group thing.
* I know he meant well, amd it was probably alot of work.
* but its turned into an annoyance ;)
*
* Nebesini of Clandestine Mud. Used his webspells.c file
* for the file output code. I also thank him daily for the
* contributions he has made to the community.
*
* My Cat, Squiggy, for knocking over my bottle of coke on
* my floor, making me goto the store to buy a new one
* and think this strange idea up.
*
* I require no credit for this one. Not even sure if others will
* remotly find it useful. All in all, it shows you how to print
* to a file ;)
*
* Next Up: Figure out how to append to the center of a file... Hmmm
*/
void do_print_skills (CHAR_DATA * ch, char* argument)
{
group_table_update();
send_to_char("Ship? Out of danger?\n\r", ch);
}
void group_table_update (void)
{
FILE *fp;
char buf[MSL];
int i = MAX_SKILL;
fclose(fpReserve);
if ( (fp = fopen("../src/group.c", "w") ) == NULL)
{
bug( "group.c: fopen", 0 );
perror( "group.c" );
}
else
{
fprintf(fp, "#if defined(macintosh)\n");
fprintf(fp, "#include <types.h>\n");
fprintf(fp, "#else\n");
fprintf(fp, "#include <sys/types.h>\n");
fprintf(fp, "#endif\n");
fprintf(fp, "#include <stdio.h>\n");
fprintf(fp, "#include <time.h>\n");
fprintf(fp, "#include \"merc.h\"\n");
fprintf(fp, "#include \"magic.h\"\n");
fprintf(fp, "#include \"interp.h\"\n\n");
fprintf(fp, "/* Generated by Thri */\n\n\n");
fprintf(fp, "const struct group_type group_table[MAX_GROUP] = { // Begin Table\n\n");
fprintf(fp, " \n");
fprintf(fp, " { \n");
fprintf(fp, " \"rom basics\", {0, 0, 0, 0, 0}, \n");
fprintf(fp, " { /* Start Skills */ \n");
while (i > 0)
{
sprintf(buf, " \"%s\", // Skill Number: %d\n", skill_table[i].name, i);
fprintf(fp, buf);
i--;
}
fprintf(fp, " }, // End Skills\n");
fprintf(fp, " } // End Table\n");
fprintf(fp, "}; // End file \n");
fclose( fp );
fpReserve = fopen( NULL_FILE, "r" );
}
}