/**************************************************************************
* Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer, *
* Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe. *
* *
* Merc Diku Mud improvements copyright (C) 1992, 1993 by Michael *
* Chastain, Michael Quan, and Mitchell Tse. *
* *
* In order to use any part of this Merc Diku Mud, you must comply with *
* both the original Diku license in 'license.doc' as well the Merc *
* license in 'license.txt'. In particular, you may not remove either of *
* these copyright notices. *
* *
* Much time and thought has gone into this software and you are *
* benefiting. We hope that you share your changes too. What goes *
* around, comes around. *
***************************************************************************
* ROM 2.4 is copyright 1993-1998 Russ Taylor *
* ROM has been brought to you by the ROM consortium *
* Russ Taylor (rtaylor@hypercube.org) *
* Gabrielle Taylor (gtaylor@hypercube.org) *
* Brian Moore (zump@rom.org) *
* By using this code, you have agreed to follow the terms of the *
* ROM license, in the file Rom24/doc/rom.license *
***************************************************************************
* 1stMUD ROM Derivative (c) 2001-2003 by Ryan Jennings *
* http://1stmud.dlmud.com/ <r-jenn@shaw.ca> *
***************************************************************************/
#include "merc.h"
#include "interp.h"
#include "lookup.h"
#include "tables.h"
#include "recycle.h"
#include "tablesave.h"
CLAN_DATA clan;
MBR_DATA mbr;
const struct savetable_type mbrsavetable[] = {
{"name", FIELD_STRING, (void *) &mbr.name, NULL, NULL},
{"clan", FIELD_FUNCTION_INT_TO_STR, (void *) &mbr.clan, (void *) clan_rw,
NULL},
{"rank", FIELD_INT, (void *) &mbr.rank, NULL, NULL},
{"level", FIELD_INT, (void *) &mbr.level, NULL, NULL},
{NULL, 0, NULL, NULL, NULL}
};
const struct savetable_type clansavetable[] = {
{"name", FIELD_STRING, (void *) &clan.name, NULL, NULL},
{"whoname", FIELD_STRING, (void *) &clan.who_name, NULL, NULL},
{"hall", FIELD_LONG, (void *) &clan.hall, NULL, NULL},
{"indep", FIELD_BOOL, (void *) &clan.independent, NULL, NULL},
{"rank", FIELD_RANK_DATA, (void *) &clan.rank, (void *) MAX_RANK, NULL},
{NULL, 0, NULL, NULL, NULL}
};
TABLESAVE(rw_members)
{
rw_list(type, MBR_FILE, MBR_DATA, mbr_first, mbr_last, next, prev, new_mbr,
"MBR", mbr, mbrsavetable);
}
TABLESAVE(rw_clans)
{
rw_list(type, CLAN_FILE, CLAN_DATA, clan_first, clan_last, next, prev,
new_clan, "CLAN", clan, clansavetable);
}
bool is_leader(CHAR_DATA * ch)
{
return ch->rank == (MAX_RANK - 1);
}
CH_CMD(do_promote)
{
char arg1[MIL];
CHAR_DATA *victim;
int rank;
if (IS_NPC(ch))
return;
argument = one_argument(argument, arg1);
if ((!is_clan(ch) || !is_leader(ch)) && !IS_IMMORTAL(ch))
{
chprintln(ch, "You must be a clan Leader to promote someone.");
return;
}
if (IS_NULLSTR(arg1))
{
chprintln(ch, "Syntax: promote <char> <rank #>");
return;
}
if ((victim = get_char_world(ch, arg1)) == NULL || IS_NPC(victim))
{
chprintln(ch, "They aren't playing.");
return;
}
if (!is_clan(victim) || is_leader(victim)
|| (!is_same_clan(ch, victim) && !IS_IMMORTAL(ch)))
{
chprintln(ch, "You can't promote them.");
return;
}
if (!is_number(argument) || (atoi(argument) > MAX_RANK)
|| (atoi(argument) < 1))
{
chprintlnf(ch, "Rank must be between 1 and %d.", MAX_RANK);
return;
}
if ((rank = (atoi(argument) - 1)) == MAX_RANK - 1)
{
if ((number_classes(victim) < 3) && (victim->level < LEVEL_HERO / 4))
{
chprintlnf
(ch,
"Only second or third tier players may be clan leaders before level %d.",
LEVEL_HERO / 4);
return;
}
}
if (victim->rank > rank)
{
chprintlnf(ch, "They have been demoted to %s.",
victim->clan->rank[rank].rankname);
chprintlnf(victim, "You have been demoted to %s, by %s.",
victim->clan->rank[rank].rankname, ch->name);
victim->rank = rank;
update_members(victim, FALSE);
}
else
{
chprintlnf(ch, "They are now a %s of clan %s.",
victim->clan->rank[rank].rankname,
capitalize(victim->clan->name));
chprintlnf(victim, "You are now a %s of clan %s.",
victim->clan->rank[rank].rankname,
capitalize(victim->clan->name));
victim->rank = rank;
update_members(victim, FALSE);
}
}
CH_CMD(do_clist)
{
CLAN_DATA *i;
MBR_DATA *pmbr;
char buf[MSL];
char buf2[MSL];
chprintln(ch, "Clans available:");
chprintln(ch, draw_line(ch, NULL, 0));
for (i = clan_first; i; i = i->next)
{
chprint(ch, i->who_name);
buf[0] = '\0';
buf2[0] = '\0';
for (pmbr = mbr_first; pmbr != NULL; pmbr = pmbr->next)
{
if (pmbr->clan != i || pmbr->rank != (MAX_RANK - 1))
continue;
sprintf(buf2, " %s,", pmbr->name);
strcat(buf, buf2);
}
if (!IS_NULLSTR(buf))
{
buf[strlen(buf) - 1] = '\0';
chprintf(ch, " (Leaders:%s)", buf);
}
chprintln(ch, "{x");
}
chprintln(ch, draw_line(ch, NULL, 0));
chprintln(ch, "For more info use 'cinfo <clan>'.");
}
CH_CMD(do_cinfo)
{
int r;
CLAN_DATA *i;
if (IS_NULLSTR(argument))
{
chprintln(ch, "Syntax: cinfo <clan name>");
return;
}
if ((i = clan_lookup(argument)) == NULL)
{
chprintln(ch, "That is not a valid clan.");
return;
}
chprintlnf(ch, "Name : %s", i->name);
chprintlnf(ch, "WhoName : %s", i->who_name);
chprintlnf(ch, "Indep : %s", i->independent ? "TRUE" : "FALSE");
if (IS_IMMORTAL(ch))
chprintlnf(ch, "Hall : %ld", i->hall);
for (r = 0; r < MAX_RANK; r++)
{
chprintlnf(ch, "Rank %d : %s", r + 1, i->rank[r].rankname);
}
}
CH_CMD(do_clanrecall)
{
CHAR_DATA *victim;
ROOM_INDEX_DATA *location;
if (!is_clan(ch) || ch->clan->independent)
{
chprintln(ch, "You're not in a clan.");
return;
}
if (IS_NPC(ch) && !IS_SET(ch->act, ACT_PET))
{
chprintln(ch, "Only player can recall.");
return;
}
if (IS_SET(ch->in_room->room_flags, ROOM_ARENA))
{
chprintln(ch, "You can't recall while in the arena!");
return;
}
act("$n prays for transportation!", ch, 0, 0, TO_ROOM);
if ((location = get_room_index(ch->clan->hall)) == NULL)
{
chprintln(ch, "Your clan doesnt seem to have a clan hall.");
return;
}
if (ch->in_room == location)
return;
if (IS_SET(ch->in_room->room_flags, ROOM_NO_RECALL) ||
IS_AFFECTED(ch, AFF_CURSE))
{
act("$g has forsaken you.", ch, NULL, NULL, TO_CHAR);
return;
}
if ((victim = ch->fighting) != NULL)
{
int lose, skill;
skill = get_skill(ch, gsn_recall);
if (number_percent() < 80 * skill / 100)
{
check_improve(ch, gsn_recall, FALSE, 6);
WAIT_STATE(ch, 4);
chprintln(ch, "You failed!");
return;
}
lose = (ch->desc != NULL) ? 25 : 50;
gain_exp(ch, 0 - lose);
check_improve(ch, gsn_recall, TRUE, 4);
chprintlnf(ch, "You recall from combat! You lose %d exps.", lose);
stop_fighting(ch, TRUE);
}
ch->move /= 2;
act("$n disappears.", ch, NULL, NULL, TO_ROOM);
char_from_room(ch);
char_to_room(ch, location);
act("$n appears in the room.", ch, NULL, NULL, TO_ROOM);
do_function(ch, &do_look, "auto");
if (ch->pet != NULL)
{
act("$n disappears.", ch->pet, NULL, NULL, TO_ROOM);
char_from_room(ch->pet);
char_to_room(ch->pet, ch->in_room);
act("$n appears in the room.", ch->pet, NULL, NULL, TO_ROOM);
}
return;
}
CH_CMD(do_clanadmin)
{
CHAR_DATA *victim;
char arg1[MIL];
CLAN_DATA *clan;
if (IS_NPC(ch))
return;
if ((!is_clan(ch) || ch->clan->independent || !is_leader(ch))
&& !IS_IMMORTAL(ch))
{
chprintln(ch, "You must be a valid clan leader to use this command.");
return;
}
argument = one_argument(argument, arg1);
if (IS_NULLSTR(arg1))
{
chprintln
(ch,
" : clanadmin where - show location of all members online.");
chprintln(ch,
" : clanadmin promote <char> <rank#> - promote/demote a character.");
chprintln(ch,
" : clanadmin invite <char> - invite a character to your clan.");
chprintln(ch,
" : clanadmin outcast <char> - kick a person out of your clan.");
chprintln(ch,
" : clanadmin members - list members in clan.");
if (IS_IMMORTAL(ch))
chprintln
(ch,
"Imm Syntax: clanadmin <clan> <command> - do a clanadmin command for a specific clan.");
return;
}
if (IS_IMMORTAL(ch))
{
char arg2[MIL];
if ((clan = clan_lookup(arg1)) == NULL)
{
chprintln(ch, "Invalid clan.");
return;
}
argument = one_argument(argument, arg2);
strcpy(arg1, arg2);
}
else
{
clan = ch->clan;
}
if (!str_cmp(arg1, "where"))
{
bool found = FALSE;
chprintln(ch, "Name Position Area");
chprintln(ch, "---- -------- ----");
for (victim = player_first; victim != NULL;
victim = victim->next_player)
{
if (!IS_NPC(victim) && can_see(ch, victim)
&& !IS_SWITCHED(victim) && is_clan(victim)
&& victim->clan == clan)
{
chprintlnf(ch, "%-12s %-8s %s", victim->name,
position_table[victim->position].name,
victim->in_room ? victim->in_room->area->
name : "Unknown");
found = TRUE;
}
}
if (!found)
chprintln(ch, "No members found online.");
return;
}
else if (!str_prefix(arg1, "promote"))
{
do_function(ch, &do_promote, argument);
return;
}
else if (!str_prefix(arg1, "members"))
{
MBR_DATA *mbr;
bool found = FALSE;
chprintln(ch, "Lev Name Rank");
chprintln(ch, "--- ------------ ------------");
for (mbr = mbr_first; mbr != NULL; mbr = mbr->next)
{
if (mbr->clan != clan)
continue;
chprintlnf(ch, "%3d %12s %12s", mbr->level, mbr->name,
mbr->clan->rank[mbr->rank].rankname);
found = TRUE;
}
if (!found)
chprintln(ch, "No one in the clan.");
return;
}
else if (!str_prefix(arg1, "invite"))
{
if ((victim = get_char_world(ch, argument)) == NULL)
{
chprintln(ch, "They aren't playing.");
return;
}
if (IS_NPC(victim))
{
chprintln(ch, "NPC's cannot join clans.");
return;
}
if (victim == ch)
{
chprintln(ch, "You're stuck...only a god can help you now!");
return;
}
if (is_clan(victim) && !victim->clan->independent)
{
chprintln(ch, "They are in a clan already.");
return;
}
if (victim->invited != NULL)
{
chprintln(ch, "They have already been invited to join a clan.");
return;
}
chprintlnf(ch, "%s has been invited to join your clan.", victim->name);
chprintlnf(victim, "{RYou have been invited to join {x%s{x",
clan->who_name);
chprintln(victim, "{YUse {Gjoin accept{Y to join this clan,{x");
chprintln(victim, "{Yor {Gjoin deny{Y to turn down the invitation.{x");
victim->invited = clan;
return;
}
else if (!str_prefix(arg1, "outcast"))
{
if ((victim = get_char_world(ch, argument)) == NULL)
{
chprintln(ch, "There is no such player.");
return;
}
if (IS_NPC(victim))
{
chprintln(ch, "NPC's cannot join clans.");
return;
}
if (victim == ch)
{
chprintln(ch, "You're stuck...only a god can help you now!");
return;
}
if (!is_clan(victim) || victim->clan != clan)
{
chprintln(ch, "They aren't in your clan.");
return;
}
if (is_leader(victim) && !IS_IMMORTAL(ch))
{
chprintln(ch, "You can't kick out another leader.");
return;
}
chprintln(ch, "They are now clanless.");
chprintln(victim, "Your clan leader has kicked you out!");
update_members(victim, TRUE);
victim->clan = NULL;
victim->rank = 0;
char_from_room(victim);
char_to_room(victim, get_room_index(ROOM_VNUM_TEMPLE));
do_function(victim, &do_look, "auto");
return;
}
else
do_function(ch, &do_clanadmin, "");
}
CH_CMD(do_join)
{
char arg1[MIL];
CHAR_DATA *victim;
argument = one_argument(argument, arg1);
if (IS_NPC(ch))
{
return;
}
if (is_clan(ch) && !ch->clan->independent)
{
chprintln(ch, "You are already in a clan.");
return;
}
if (ch->invited == NULL)
{
chprintln(ch, "You have not been invited to join a clan.");
return;
}
if (!str_cmp(arg1, "accept"))
{
for (victim = player_first; victim != NULL;
victim = victim->next_player)
if (is_clan(victim) && victim->clan == ch->invited)
chprintlnf(victim, "%s accepts the invitation to join %s.",
PERS(ch, victim), victim->clan->name);
ch->clan = ch->invited;
ch->rank = 0;
chprintlnf(ch, "{RYou are now a %s of {x%s{x",
ch->clan->rank[ch->rank].rankname, ch->clan->who_name);
ch->invited = NULL;
update_members(ch, FALSE);
return;
}
else if (!str_cmp(arg1, "deny"))
{
chprintln(ch, "You turn down the invitation.");
for (victim = player_first; victim != NULL;
victim = victim->next_player)
if (is_clan(victim) && victim->clan == ch->invited
&& victim->rank >= MAX_RANK - 2)
chprintlnf(victim, "%s denies the invitation to join %s.",
PERS(ch, victim), victim->clan->name);
ch->invited = NULL;
return;
}
else
{
chprintln(ch, "Syntax: join <accept|deny>");
return;
}
}
void update_members(CHAR_DATA * ch, bool pdelete)
{
MBR_DATA *curr, *next;
if (IS_NPC(ch))
return;
for (curr = mbr_first; curr != NULL; curr = next)
{
next = curr->next;
if (!str_cmp(ch->name, curr->name))
{
UNLINK(curr, mbr_first, mbr_last, next, prev);
free_mbr(curr);
rw_members(action_write);
}
}
if (pdelete || !is_clan(ch) || ch->clan->independent)
return;
curr = new_mbr();
replace_string(curr->name, ch->name);
curr->rank = ch->rank;
curr->clan = ch->clan;
curr->level = ch->level;
LINK(curr, mbr_first, mbr_last, next, prev);
rw_members(action_write);
return;
}
CH_CMD(do_roster)
{
int i, count = 0;
CLAN_DATA *clan;
MBR_DATA *pmbr;
char buf[MSL], buf2[MSL];
char arg[MIL];
char *rcol[MAX_RANK] = { "{R", "{B", "{Y", "{M", "{G", "{C" };
argument = one_argument(argument, arg);
if (IS_NULLSTR(arg))
{
chprintln(ch, "Syntax: roster <clan name>");
if (IS_IMMORTAL(ch))
chprintln(ch, " roster delete <name>");
return;
}
if (!str_cmp(arg, "delete") && IS_IMMORTAL(ch))
{
MBR_DATA *next = NULL;
MBR_DATA *curr = NULL;
bool found = FALSE;
for (curr = mbr_first; curr != NULL; curr = next)
{
next = curr->next;
if (!str_cmp(argument, curr->name))
{
UNLINK(curr, mbr_first, mbr_last, next, prev);
free_mbr(curr);
rw_members(action_write);
found = TRUE;
}
}
if (!found)
chprintlnf(ch, "Error deleting %s.", argument);
else
chprintlnf(ch, "%s removed from member list.", argument);
return;
}
if ((clan = clan_lookup(arg)) == NULL)
{
chprintln(ch, "That clan does not exist.");
return;
}
if (clan->independent)
{
chprintln(ch, "That is not a real clan.");
return;
}
chprintlnf(ch, "{W%s{x\n\r",
stringf(ch, 0, ALIGN_CENTER, "-", FORMATF("[ %s{W Roster ]",
clan->who_name)));
for (i = MAX_RANK - 1; i >= 0; i--)
{
chprintf(ch, "%s%12ss {W:%s", rcol[i], clan->rank[i].rankname, rcol[i]);
buf[0] = '\0';
buf2[0] = '\0';
count = 0;
for (pmbr = mbr_first; pmbr != NULL; pmbr = pmbr->next)
{
if (pmbr->rank != i || pmbr->clan != clan || IS_NULLSTR(pmbr->name))
continue;
sprintf(buf2, " %s%12s {W({wLvl:{R%3d{W) ", rcol[i],
pmbr->name, pmbr->level);
strcat(buf, buf2);
if (++count % 2 == 0)
{
sprintf(buf2, "\n\r%15s", " ");
strcat(buf, buf2);
}
}
if (IS_NULLSTR(buf))
chprintlnf(ch, " %12s\n\r", "No one.");
else
{
sprintf(buf2, "\n\r%s", count % 2 != 0 ? "\n\r" : "");
strcat(buf, buf2);
chprint(ch, buf);
}
}
chprintlnf(ch, "{W%s", draw_line(ch, NULL, 0));
return;
}