22 Jul, 2009, Terraco wrote in the 1st comment:
Votes: 0
Okay guys, i need to know some info from deleting clans on a ROM. How would you all come up with a delete command that dosnt have to use numbers but would allow you to delete a clan of your choice. Not the first one or the last one.

CEDIT( cedit_delete )
{
CLAN_DATA *pClan;
DESCRIPTOR_DATA *d;
int i, j;
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);
}
/*
for (i = 1; clan_table[i].name != 0; i++)
{
if (clan_table[i].name[0] == pClan->name[0])
{
found = TRUE;
pClan = &clan_table[i]; // Set the clan
break;
}
}
*/
for (top_clan = 0; clan_table[top_clan].name != 0; top_clan++)
if (!str_prefix (pClan->name, clan_table[top_clan].name))
{
found = TRUE;
pClan = &clan_table[top_clan];
break;
}

if (!found)
{
logstr (LOG_BUG, "cedit_delete: clan '%s' not found", pClan->name);
sendch ("Clan has already been deleted.\n\r", ch);
return FALSE;
}
/*
free_string (clan_table[i].name);
free_string (clan_table[i].who_name);
free_string (clan_table[i].leader);

for (j = 1; j < MAX_RANK; j++)
free_string (clan_table[i].c_rank[j].rankname);
*/

//Deleting it out of memory and file.
free_string (pClan->name);
free_string (pClan->who_name);
free_string (pClan->leader);

for (j = 1; j < MAX_RANK; j++)
{
free_string (pClan->c_rank[j].rankname);
}

pClan->flags = 0;

// pClan = &clan_table[0]; //Change it to null
save_clans(ch, argument); //Updating file

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

CODE BY BOJACK OF DBA!
22 Jul, 2009, Igabod wrote in the 2nd comment:
Votes: 0
Take a look at how swr does it. I don't recall exactly the process at the moment, but I do believe you can delete clans by name on swr.
22 Jul, 2009, Banner wrote in the 3rd comment:
Votes: 0
void do_remclan( CHAR_DATA * ch, char *argument )
{
CLAN_DATA *clan;

if( ( clan = get_clan( argument ) ) == NULL )
{
send_to_char( "No such clan.\n\r", ch );
return;
}

UNLINK( clan, first_clan, last_clan, next, prev );
STRFREE( clan->name );
DISPOSE( clan );
write_clan_list( );
}
22 Jul, 2009, Guest wrote in the 4th comment:
Votes: 0
Banner said:
void do_remclan( CHAR_DATA * ch, char *argument )
{
CLAN_DATA *clan;

if( ( clan = get_clan( argument ) ) == NULL )
{
send_to_char( "No such clan.\n\r", ch );
return;
}

UNLINK( clan, first_clan, last_clan, next, prev );
STRFREE( clan->name );
DISPOSE( clan );
write_clan_list( );
}


Minimalistic and would get the job done as far as the online game is concerned. But there should really be a whole lotta extra code at line 10 in the quoted block. Extra code that would deal with properly removing the clan's data file, ousting any online members from it, clearing any extras the codebase may support like housing, shops, etc, and also clearing any tie-ins to the deities. Rom may not have all that, but whatever it does have should be properly cleaned out.
22 Jul, 2009, Davion wrote in the 5th comment:
Votes: 0
in ROM, clans aren't stored in datafiles. You'd have to convert your clans to save to a file. I -believe- that there's a snippet out there called either gedit, or clan editor.

http://www.mudbytes.net/index.php?a=file...
22 Jul, 2009, David Haley wrote in the 6th comment:
Votes: 0
All those little gotchas are the kind of thing that make what should be simple functions turn into hundred-line-long monsters dealing with tiny details all over the place…
22 Jul, 2009, Guest wrote in the 7th comment:
Votes: 0
Yes, but all of those tiny details left unfixed leads to goop left in place that you may not be able to identify in 6 months. Much like that head of lettuce you forgot was in the fridge :)
22 Jul, 2009, kiasyn wrote in the 8th comment:
Votes: 0
that would still be wrong, all the deleting clan stuff should be refactored into a separate function as it is functionality that shouldnt be reserved for a command.
23 Jul, 2009, Guest wrote in the 9th comment:
Votes: 0
Yes, that's how the clan delete function in AFKMud works. "delete" is just another option in the do_setclan code, which simply calls up the delete_clan() function. That's how i'd recommend it be done as well because then you can also use the delete function for automated cleanup in the future too.
23 Jul, 2009, David Haley wrote in the 10th comment:
Votes: 0
One of SMAUG's biggest annoyances is how "business logic" is embedded within command handling, instead of commands being very simply 'windows' onto functions that handle these processes for you. It makes code sharing difficult/impossible (unless you rewrite or copy/paste things), and it also means that if some command happens to implement crucial logic, and you happen to forget that logic somewhere else when implementing a similar command, you're kind of screwed.
26 Jul, 2009, Terraco wrote in the 11th comment:
Votes: 0
Well folks… I know it isn't much of a item thats looked for. But here is a fully working clan delete for ya all.

CEDIT( cedit_delete )
{
CLAN_DATA *pClan;
DESCRIPTOR_DATA *d;
int i, j, location;
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);
}

for (i = 0; i < (1 + top_clan); i++)
{
if (clan_table[i].name == pClan->name)
{
found = TRUE;
location = i;
break;
}
}

if (!found)
{
logstr (LOG_BUG, "cedit_delete: clan '%s' not found", pClan->name);
sendch ("Clan has already been deleted.\n\r", ch);
return FALSE;
}

for (i = location; i < (1 + top_clan); ++i)
{
clan_table[i] = clan_table[i + 1];
clan_table[i].name = clan_table[i + 1].name;
clan_table[i].who_name = clan_table[i + 1].who_name;
clan_table[i].leader = clan_table[i + 1].leader;

for (j = 0; j < MAX_RANK; j++)
clan_table[i].c_rank[j].rankname = clan_table[i + 1].c_rank[j].rankname;

clan_table[i].flags = clan_table[i + 1].flags;
}

clan_table[top_clan] = clan_table[0];
top_clan–;

save_clans(ch, argument); //Updating file
sendch ("Clan deleted.\n\r", ch);
return TRUE;
}


And so you know this is a static array not a dynamic structure.
Hope someone can use it.
26 Jul, 2009, Lobotomy wrote in the 12th comment:
Votes: 0
Terraco said:
for (i = location; i < (1 + top_clan); ++i)
{
clan_table[i] = clan_table[i + 1];
clan_table[i].name = clan_table[i + 1].name;
clan_table[i].who_name = clan_table[i + 1].who_name;
clan_table[i].leader = clan_table[i + 1].leader;

for (j = 0; j < MAX_RANK; j++)
clan_table[i].c_rank[j].rankname = clan_table[i + 1].c_rank[j].rankname;

clan_table[i].flags = clan_table[i + 1].flags;
}

While your compiler may already be optimizing it for you, one thing you may want to look at doing to optimize a section of code like this is to create another integer to store the value of ( i + 1 ). After all, the value of ( i + 1 ) isn't going to change at all inside that for loop, so having the program re-compute the same value over and over again is a waste. Also, the condition in the for loop "i < ( 1 + top_clan )" can be changed to "i <= top_clan" and mean the same thing while removing another calculation which may or may not be repeated unnecessarily.

I.e,
int x;
for (i = location; i <= top_clan; ++i)
{
x = i + 1;
clan_table[i] = clan_table[x];
clan_table[i].name = clan_table[x].name;
clan_table[i].who_name = clan_table[x].who_name;
clan_table[i].leader = clan_table[x].leader;

for (j = 0; j < MAX_RANK; j++)
clan_table[i].c_rank[j].rankname = clan_table[x].c_rank[j].rankname;

clan_table[i].flags = clan_table[x].flags;
}
26 Jul, 2009, David Haley wrote in the 13th comment:
Votes: 0
Isn't this going out of bounds on the clan_table array? If top_clan is the highest one, and you're looking at that plus one, aren't you going overboard?
28 Jul, 2009, Bojack wrote in the 14th comment:
Votes: 0
Finally, took forever for the account activation, anyways no its not going out of the clan array cuz the clan array uses max_clan.. top_clan is just a number counting how many clans we have at file loading. Max_clan is the array define. Also yes I could use <= top_clan as long as 0 aint counted which is null for the array. Anyways an update for that ill post here but the full clan editor ill submit for download.

CEDIT( cedit_delete )
{
CLAN_DATA *pClan;
DESCRIPTOR_DATA *d;
CHAR_DATA *pch;
int i, j, x, location;
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);
}

// Set clan location
for (i = 0; i < (1 + top_clan); i++)
{
if (clan_table[i].name == pClan->name)
{
found = TRUE;
location = i;
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 (clan_table[pch->clan].name == pClan->name)
{
pch->clan = 0;
}
}

// Shift the clans up
for (i = location; i < (1 + top_clan); ++i)
{
x = i + 1;
clan_table[i] = clan_table[x];
clan_table[i].name = clan_table[x].name;
clan_table[i].who_name = clan_table[x].who_name;
clan_table[i].leader = clan_table[x].leader;

for (j = 0; j < MAX_RANK; j++)
clan_table[i].c_rank[j].rankname = clan_table[x].c_rank[j].rankname;

clan_table[i].flags = clan_table[x].flags;
}

clan_table[top_clan] = clan_table[0]; // Set last clan to null
top_clan–; // Change null from being accessed

save_clans(ch, argument); //Updating file
sendch ("Clan deleted.\n\r", ch);
return TRUE;
}
0.0/14