Cedit2.0/
---------------Bug fixes
After changing all these, make sure you
take the new clan.c file and put it into
your mud before doing a make assuming you
havent edited since then. Btw this is an update
to my previous cedit clan system, if you
havent ever installed cedit before, open 
the installation file instead.


NOTE: I commented out all the pendingapp parts
because it crashes the game and probably mem
leaks. I havent come up with a new method yet.
If you can find a different route, send me a pm,
Bojack, on mudbytes.net


---------------act_comm.c

-Change any clan_table[ch->clan].name to:
ch->clan->name

-Change any clan_table[ch->clan].c_rank[ch->c_rank].rankname to:
ch->clan->c_rank[ch->c_rank].rankname

-After, find: void do_clantalk
-Change the if statement to:
    if (!is_clan (ch) ) {
        sendch ("You aren't in a clan.\n\r", ch);
        return;
    }

---------------act_info.c

-replace clanlist to this:
void do_clanlist (CHAR_DATA * ch, char *argument)
{
    CLAN_DATA *clan;
    char buf[MAX_STRING_LENGTH];
    int col;

    if (IS_NPC(ch))
    return;

    buf[0] = '\0';
    sendch ("{b================================================================={x\n\r", ch);
    sendch ("{CN{came                           {CL{cogo                        {CL{ceader{x\n\r", ch);
    sendch ("{b================================================================={x\n\r", ch);

    col = 0;

        for (clan = clan_first; clan != NULL; clan = clan->next)
        {
            if (IS_IMMORTAL(ch) )
            {
                if (clan->name != NULL)
                {
                    sprintf (buf, "{c%-27.27s{x %8s {r%26s{x",
                        clan->name,
                        clan->who_name,
                        clan->leader );
                    page_to_char (buf, ch);
                }
                if (++col % 1 == 0)
                        sendch ("\n\r", ch);
            }
            else
            {
                if (!IS_SET(clan->flags, CLAN_IMMORTAL) )
                {
                    sprintf (buf, "{c%-27.27s{x %8s {r%26s{x",
                        clan->name,
                        clan->who_name,
                        clan->leader );
                    sendch (buf, ch);
                }
                if (++col % 1 == 0)
                        sendch ("\n\r", ch);
            }
        }

        if (col % 1 != 0)
            sendch ("\n\r", ch);

    return;
}


-in do_score
-change after immortal stuff if there:
    if (ch->clan)
    {
        sendch("{Y------------------------------{BCLAN{Y-------------------------------{x\n\r",ch);

        sprintf(buf,"{cClan:{W %-27s{x", ch->clan->name);
        sendch(buf, ch);
        if (IS_SET(ch->act, PLR_LEADER))
            sendch("{cLeader    :{W Yes{x\n\r",ch);
        sprintf(buf,"{cRank:{W %-20d", ch->c_rank);
        sendch(buf, ch);
        if(IS_IMMORTAL(ch))
            sprintf(buf,"{cClan Title:{W %s{x\n\r", "Deity");
        else
            sprintf(buf,"{cClan Title:{W %s{x\n\r", ch->clan->c_rank[ch->c_rank].rankname);
        sendch(buf,ch);
    }

-IF YOU HAVE THIS
-In do_whois
-At bottom of it find:  clan_table[wch->clan].who_name,
-Change to:             wch->clan == NULL ? "" : wch->clan->who_name,

-IF YOU HAVE THIS
-In do_cwho
-Change both of these:
 if (ch->clan == 0), if (ch->clan == 1)
-To:
 if (ch->clan == NULL)
 if (IS_SET(ch->clan->flags, CLAN_INDEPENDENT) )

-A bit lower change: clan_table[ch->clan].name 
-To: ch->clan->name);

-Now find clan_table[wch->clan].c_rank[wch->c_rank].rankname,
-Change to: wch->clan->c_rank[wch->c_rank].rankname,

-In do_who
-At top 

-For the int defines, make: iClan = 0,

-After DESCRIPTOR_DATA add:
    CLAN_DATA *pClan, *Clan;

-Change bool rgfClan[MAX_CLAN] or rgfClan[top_clan],
 whichever it is to:
    bool rgfClan[iClan];

-Change this:
//    for (iClan = 0; iClan < (1 + top_clan); iClan++)
-To:
    for (pClan = clan_first; pClan != NULL; pClan = pClan->next)
	rgfClan[iClan++] = FALSE;

-A bit lower you should find this: iClan = clan_lookup(arg);
-Change to:
                    Clan = clan_lookup(arg);
                    if (Clan)
                    {
                        fClanRestrict = TRUE;
                        rgfClan[iClan++] = TRUE;
                    }

-further down find:
                    || (fClanRestrict && !rgfClan[wch->clan]))
-Change to:
                    || (fClanRestrict && !rgfClan[iClan] && wch->clan == NULL ) )
-Again a bit down find:
                    || (fClanRestrict && !rgfClan[wch->clan])
-Change to:
                    || (fClanRestrict && !rgfClan[iClan] && wch->clan == NULL)
-Find down by the format it up part:
                clan_table[wch->clan].who_name, wch->name,
-Change to:
                wch->clan == NULL ? "" : wch->clan->who_name, wch->name,

-Under // Now the players, find:
                 || (fClanRestrict && !rgfClan[wch->clan])
-Change to:
                 || (fClanRestrict && !rgfClan[iClan] && wch->clan == NULL)
-Lower again find:
                clan_table[wch->clan].who_name, wch->name,
-Change to:
                wch->clan == NULL ? "" : wch->clan->who_name, wch->name,


---------------act_wiz.c

-Replace void do_save_clans with this:

//Added this to use later as a do_function();
void do_save_clans (CHAR_DATA *ch, char *argument)
{
    CLAN_DATA *clan;
    bool found = FALSE;

    if (argument[0] != '\0')
    {
	sendch ("To use this function simply type 'csave'\n\r", ch);
	return;
    }

    for (clan = clan_first; clan != NULL; clan = clan->next)
        if (IS_SET (clan->flags, CLAN_CHANGED) )
            found = TRUE;

    if (!found)
    {
        sendch ("No modified clans to save.\n\rClan file up to date.\n\r", ch);
        return;
    }

    save_clans (NULL);
    sendch ("Clans file saved.\n\r", ch);
    return;
}


-For do_guild
-Replace do_guild with this:
void do_guild (CHAR_DATA * ch, char *argument)
{
    char arg1[MAX_INPUT_LENGTH], arg2[MAX_INPUT_LENGTH];
    char buf[MAX_STRING_LENGTH];
    CHAR_DATA *victim;
    CLAN_DATA *clan;

    argument = one_argument (argument, arg1);
    argument = one_argument (argument, arg2);

    if (arg1[0] == '\0' || arg2[0] == '\0')
    {
        sendch ("Syntax: guild <char> <clan name>\n\r", ch);
        return;
    }
    if ((victim = get_char_world (ch, arg1)) == NULL)
    {
        sendch ("They aren't playing.\n\r", ch);
        return;
    }

    if (!str_prefix (arg2, "none"))
    {
        sendch ("They are now clanless.\n\r", ch);
        sendch ("You are now a member of no clan!\n\r", victim);
        victim->clan = NULL;
        victim->c_rank = 0;
        return;
    }

    if ((clan = clan_lookup (arg2)) == NULL)
    {
        sendch ("No such clan exists.\n\r", ch);
        return;
    }

    if (IS_SET(clan->flags, CLAN_INDEPENDENT))
    {
        sprintf (buf, "They are now a '%s'.\n\r", clan->name);
        sendch (buf, ch);
        sprintf (buf, "You are now a '%s'.\n\r", clan->name);
        sendch (buf, victim);
        victim->c_rank = 1;
    }
    else
    {
        sprintf (buf, "They are now a member of clan '%s'.\n\r",
                 clan->name);
        sendch (buf, ch);
        sprintf (buf, "You are now a member of '%s'.\n\r",
                 clan->name);
        sendch (buf, victim);

        if (IS_SET(victim->act, PLR_LEADER))
            victim->c_rank = 7;
        else
            victim->c_rank = 1;
    }
    victim->clan = clan;
    return;
}

-In do_mstat
-Add or change below the immortal stuff:
    if (victim->clan)
    {
        sendch("{Y-----------------------------------------------------------------{x\n\r",ch);

        sprintf(buf,"{cClan:{W %-27s{x",victim->clan->name);
        sendch(buf, ch);
        if (IS_SET(ch->act, PLR_LEADER))
            sendch("{cLeader    :{W Yes{x\n\r",ch);
        sprintf(buf,"{cRank:{W %-20d", victim->c_rank);
        sendch(buf, ch);
        if(IS_IMMORTAL(ch))
            sprintf(buf,"{cClan Title:{W %s{x\n\r", "Deity");
        else
            sprintf(buf,"{cClan Title:{W %s{x\n\r", victim->clan->c_rank[victim->c_rank].rankname);
        sendch(buf,ch);
    }

---------------clan.c

-Replace the whole file with the one given.


---------------interp.c

-Find do_promote
-Add before it:
//    {"pending",   do_pending,   POS_RESTING,  0, LOG_NORMAL, 1, FALSE},
    {"petition",  do_petition,  POS_RESTING,  0, LOG_NORMAL, 1, FALSE},


---------------interp.h

-Find do_pick
-Add before it:
//DECLARE_DO_FUN( do_pending		);
DECLARE_DO_FUN( do_petition             );


----------------mem.c

-IF YOU HAVE THIS
-Find ROOM_INDEX_DATA *new_room_index
-Change pRoom->clan = 0; to:
pRoom->clan = NULL;

-In void free_room_index
-Add this with the free_strings
    pRoom->clan = NULL;


---------------merc.h

-Find and change this:
//typedef struct    clan_type        CLAN_DATA;
typedef struct    clan_data	   CLAN_DATA;

-Find this:
#define DATA_DIR        "../data/"

-Add this after:
#define CLAN_DAT        "../data/guild.dat" //Decided to set it here if wanting to change it

-IF you use profile data like we do
-Find this:
struct profile_data
{
        long long int   pl;
        int             home;
        char            title;
        char    *       background;
        int             clan;
        long long int   played;
        long            mdeaths;
        long            mkills;
        long            pkills;
        long            pdeaths;
        long            relics;
        long            profile_age;
};
 and change int clan to:
        CLAN_DATA *     clan;

-Find this:
struct clan_type
{
    long flags;                 /* flags for clan */
    char *name;                 /* name of clan */
    char *who_name;             /* name sent for "who" command */
    char *leader;               /* leader of clan */
    rankdata c_rank[MAX_RANK];  /* clans rank system */
};

-Change it to:
struct clan_data
{
    CLAN_DATA *next;
    CLAN_DATA *prev;		/* For clan deletion only */
    long flags;                 /* flags for clan 	  */
    char *name;                 /* name of clan 	  */
    char *who_name;             /* name for "who" command */
    char *leader;               /* leader of clan 	  */
    rankdata c_rank[MAX_RANK];  /* clans rank system 	  */
};

-In: One character (PC or NPC).
struct   char_data {

 change     sh_int             clan;
 to:    CLAN_DATA *        clan;

-If     sh_int             petition;
 isnt there add with, otherwise add:
//    char *             pendingapp;


-IF YOU HAVE THIS, In: 
/*
 * Room type.
 */
struct    room_index_data

-Change     sh_int            clan;
 to:    CLAN_DATA *        clan;
 then put it above sh_int     vnum;

-Under /* clan.c */
-Find and delete this: struct  clan_type       clan_table[MAX_CLAN];

-Also change clan_lookup to this:
CLAN_DATA * clan_lookup args( ( char *name ) );

-Find void    save_clans and change to:
void    save_clans      args( ( CLAN_DATA *pClan ) );

-At very bottom with Global variables, add:
extern        CLAN_DATA *  clan_first;
extern	      CLAN_DATA *  clan_last;


-Now search for MAX_RANK the define,
 make sure its set at 8.

---------------olc.c

Btw side note on this, get_clan_data really isnt necessary now 
since clan_lookup can be used within the cedit function but I 
dont feel like editing all that and changing it to use clan_lookup.
If you want you can take out get_clan_data and just replace
it with clan_lookups but its up to you.

-Find and replace CLAN_DATA *get_clan_data( char *name )
 to:
CLAN_DATA *get_clan_data( char *name )
{
    CLAN_DATA *clan;

    for (clan = clan_first; clan != NULL; clan = clan->next)
    {
        if ( !str_prefix (name, clan->name) )
        return clan;
    }
    return NULL;
}

-In void do_cedit( CHAR_DATA *ch, char *argument )
-Change if ((clan_lookup(argument)) != 0) to:
if ((clan_lookup(argument)) != NULL)

-Further down for: if ((pClan->name == NULL) || pClan->name[0] == '\0')
-Change to:
        if (pClan == NULL)

---------------olc.h

-Add at the bottom:
CLAN_DATA       *new_clan               args ( ( void ) );
void            free_clan               args ( ( CLAN_DATA *pClan ) );


---------------olc_act.c

-In REDIT (redit_show)
-If you have this there, change it to this
 otherwise skip this step:
    if (pRoom->clan != NULL)
    {
        sprintf (buf, "Clan      : %s\n\r",
                 pRoom->clan->name);
        strcat (buf1, buf);
    }

-If REDIT (redit_clan) exists, change it to this:
REDIT (redit_clan)
{
    ROOM_INDEX_DATA *pRoom;

    EDIT_ROOM (ch, pRoom);

    if (argument[0] == '\0')
    {
        sendch ("Syntax: clan <name>\n\r", ch);
        return FALSE;
    }

    if ((clan_lookup(argument)) == NULL)
    {
        sendch ("Clan doesn't exist.\n\r", ch);
        return FALSE;
    }

    pRoom->clan = clan_lookup(argument);
    sendch ("Clan set.\n\r", ch);
    return TRUE;
}

-For CEDIT( cedit_create )
-Change it all to this:
CEDIT( cedit_create )
{
    CLAN_DATA *pClan;
    int i;

    if (IS_NULLSTR (argument) )
    {
        sendch ("Syntax: create <name>\n\r", ch);
        return FALSE;
    }

    if ((clan_lookup(argument)) != NULL)
    {
        sendch ("That clan already exists.\n\r", ch);
        return FALSE;
    }

    pClan = new_clan();
    if (pClan != NULL)
    {
        free_string (pClan->name);
        pClan->name = str_dup(capitalize(argument));
        pClan->who_name = str_dup("[Unknown ]");
        pClan->leader = str_dup("Unknown");

        for (i = 1; i < MAX_RANK; i++)
            pClan->c_rank[i].rankname = str_dup("Not assigned");

        ch->desc->pEdit = pClan;

        sendch("Clan created.\n\r", ch);
        return TRUE;
    }
    else
        sendch("Creating clan failed, can't allocate memory for new clan.\n\r", ch);
    return FALSE;
}


-For CEDIT( cedit_delete )
-Change it all to this:
CEDIT( cedit_delete )
{
    CLAN_DATA *pClan, *clan;
    DESCRIPTOR_DATA *d;
    CHAR_DATA *pch;
    bool found = FALSE;

    EDIT_CLAN (ch, pClan);

    for (d = descriptor_list; d; d = d->next)
    {
        if (d->editor == ED_CLAN && pClan == d->pEdit)
                edit_done (d->character);
    }

    // Check to see if someone else deleted it
    for (clan = clan_first; clan; clan = clan->next)
    {
        if (clan != NULL && clan->name == pClan->name)
        {
                found = TRUE;
                break;
        }
    }

    if (!found)
    {
        sendch ("Clan has already been deleted.\n\r", ch);
        return FALSE;
    }

    // Incase the clan we delete is still being used by players
    for (pch = char_list; pch != NULL; pch = pch->next)
    {
        if (pch->clan != NULL && pch->clan->name == pClan->name)
            pch->clan = NULL;
    }

    free_clan (pClan);
    top_clan--;

    sendch ("Clan deleted.\n\r", ch);
    return TRUE;
}


-Change CEDIT( cedit_list ) to this:
CEDIT( cedit_list )
{
    CLAN_DATA *pClan;
    char buf[MAX_INPUT_LENGTH], buf1[MIL];
    int col = 0;

    buf1[0] = '\0';
    sendch("================== Active Clans ==================\n\r", ch);

    for (pClan = clan_first; pClan; pClan = pClan->next)
    {
        if (pClan != NULL)
        {
                sprintf (buf, "{c%-27.27s %s{x",
                        pClan->name, pClan->leader);
                strcat (buf1, buf);

                if (++col % 1 == 0)
                        strcat (buf1, "\n\r");
        }
    }
    if (col % 1 != 0)
        strcat (buf1, "\n\r");
    sendch(buf1, ch);
    return FALSE;
}

-In CEDIT( cedit_show )
-Delete all of the "Who Name:" part then
 change it to this:
    sprintf (buf, "Who Name:   %s\n\r", pClan->who_name);
    strcat (buf1, buf);


-Find CEDIT( cedit_name ) and change it to this:
CEDIT( cedit_name )
{
    CLAN_DATA *pClan;

    EDIT_CLAN(ch, pClan);

    if (argument[0] == '\0')
    {
        sendch("Syntax: name <name of clan>\n\r", ch);
        return FALSE;
    }

    if ( (clan_lookup (argument)) != NULL)
    {
        sendch("That clan already exists.\n\r", ch);
        return FALSE;
    }

    free_string(pClan->name);
    pClan->name = str_dup(argument);

    sendch("Name set.\n\r", ch);
    return TRUE;
}

-Change CEDIT( cedit_who_name ) to this:
CEDIT( cedit_who_name )
{
    CLAN_DATA *pClan;
    char buf[MSL];
    int i;

    EDIT_CLAN(ch, pClan);

    if (argument[0] == '\0')
    {
        sendch("Syntax: who <name>\n\r", ch);
        return FALSE;
    }

    if (pClan->who_name != NULL || pClan->who_name[0] != '\0')
        free_string(pClan->who_name);

    i = strlen_color(argument);
/*
    This is the old method below, if you use it you have
    to take out if (i < 8) because this method doesnt count
    the string correctly.

    i = strlen(argument);
    if (argument[i-2] != '{' && argument[i-1] == '{')
        argument[i-1] = '\0';

    if (argument[i-2] != '{' || argument[i-1] != 'x')
        strcat (argument, "{x");
*/
    if (i <= 8)
    {
        int l = (8 - i)/2;
        int r = (8 - i)-l;

        sprintf (buf, "[%*s%s%*s]", l, "", argument, r, "");
        pClan->who_name = str_dup(buf);

        sendch("Who name set.\n\r", ch);
        return TRUE;
    }

    sendch ("Who name cannot be more than 8 characters.\n\r"
                "Color codes don't count as a character.\n\r", ch);
    return FALSE;
}

Btw if you do not have strlen_color (argument),
you can find strlen_color in mud repository at
DikuMud/Merc/Rom/Snippets/String Handling
its called strlen_color. If you do use this,
add this: int      strlen_color         args( ( char *argument ) );
under /* act_wiz.c */ part in merc.h.

-In CEDIT( cedit_leader )
-Change this line     if (pClan->leader[0] != '\0') to this:
    if (pClan->leader != NULL || pClan->leader[0] != '\0')


---------------olc_save.c

-IF YOU HAVE THIS, find: if (pRoomIndex->clan > 0)
-Change to:
                if (pRoomIndex->clan != NULL)
                    fprintf (fp, "C %s~\n", pRoomIndex->clan->name);

-Find void save_clans and delete all of it then
 add these functions:
void save_clan (FILE *fp, CLAN_DATA *pClan)
{
    char buf[MSL];
    int i;

    fprintf (fp, "#CLAN\n");
    fprintf (fp, "Clan %s~\n", pClan->name);
    fprintf (fp, "Who %s~\n", pClan->who_name);
    fprintf (fp, "Leader %s~\n", pClan->leader);
    for (i = 1; i < MAX_RANK; i++)
	fprintf (fp, "Rank %d %s~\n", i, (pClan->c_rank[i].rankname == NULL) ? "Not assigned" : pClan->c_rank[i].rankname);

    //Just incase
    if (IS_SET(pClan->flags, CLAN_CHANGED) )
	REMOVE_BIT (pClan->flags, CLAN_CHANGED);
    fprintf (fp, "Flags %s\n", fwrite_flag(pClan->flags, buf) );

    fprintf (fp, "End\n\n");
    return;
}

void save_clans (CLAN_DATA *pClan)
{
    FILE *fp;

    if (!(fp = fopen(CLAN_DAT, "w")) )
    {
	logstr (LOG_BUG, "Open_clan: can't open clan file.", 0);
	return;
    }
    else
    {
	for (pClan = clan_first; pClan != NULL; pClan = pClan->next)
	    save_clan (fp, pClan);

	fprintf (fp, "$\n");
    }
    fclose(fp);
    return;
}

-In void do_asave, find     if (!str_cmp ("world", arg1))
 and change save_clans (ch, argument) to:
	    save_clans (NULL);

-In     if (!str_cmp ("changed", arg1))
-Find the clan_lookup(clan_table[i].name) part
 and change to:
	CLAN_DATA *pClan;
        char buf1[MIL];

        for (pClan = clan_first; pClan != NULL; pClan = pClan->next)
        {
            if (IS_SET(pClan->flags, CLAN_CHANGED)
                && !IS_SET(pClan->flags, CLAN_DELETED) )
            {
                sprintf (buf1, "\n\rClan '%s' saved.", pClan->name);
                if (ch)
                    sendch (buf1, ch);
                else
                    logstr (LOG_GAME, buf1);
            }

        }
	save_clans (NULL);


---------------profile.c

-IF YOU HAVE PROFILES
-Find     if (vict->clan) {
        printf_to_char(ch, "{BMember of Clan: {x%s\r\n", clan_table[vict->clan].name);
 then change that section to this:
    if (vict->clan) 
    {
        printf_to_char(ch, "{BMember of Clan: {x%s\r\n", vict->clan->name);
	if (!IS_SET (vict->clan->flags, CLAN_INDEPENDENT) ) //Not a Loner clan
	{
	    if(IS_IMMORTAL(vict))
                printf_to_char(ch, "{B    Clan Title: {x%s %s{x\n\r", "Deity", vict->name);
	    else
		printf_to_char(ch, "{B    Clan Title: {x%s %s{x\n\r", vict->clan->c_rank[vict->c_rank].rankname, vict->name);
	}
    	else
            printf_to_char(ch, "{B    Clan Title: {xLoner %s{x\n\r", vict->name);
    }

-After that, change all references of clan_table to
 either vict->clan->name or vict->clan->c_rank[vict->c_rank].rankname


---------------save.c

-In fwrite_char
-Find         fprintf (fp, "Clan %s~\n", clan_table[ch->clan].name);
 and change to:
        fprintf (fp, "Clan %s~\n", ch->clan->name);

-After that part add this:
    fprintf (fp, "Petition %d\n", ch->petition);

//    if (ch->pending != '\0')
//        fprintf(fp, "Pending_clan %s~\n", ch->pendingapp);

-IF you have void fwrite_profile
 change            fprintf( fp, "Clan %d\n", pro->clan); to:
           fprintf( fp, "Clan %s~\n", pro->clan->name);


-In fread_char
-Find case 'P':
-Add before ("Played", ch->played
//                if (!str_cmp (word, "Pending_clan") )
//		    ch->pendingapp = fread_string(fp));
                KEY ("Petition", ch->petition, fread_number(fp));


--------------End of Bug Corrections