/
roa/
roa/lib/boards/
roa/lib/config/
roa/lib/edits/
roa/lib/help/
roa/lib/misc/
roa/lib/plrobjs/
roa/lib/quests/
roa/lib/socials/
roa/lib/www/
roa/lib/www/LEDSign/
roa/lib/www/LEDSign/fonts/
roa/lib/www/LEDSign/scripts/
roa/src/s_inc/
roa/src/sclient/
roa/src/sclient/binary/
roa/src/sclient/text/
roa/src/util/
/************************************************************************
	Realms of Aurealis 		James Rhone aka Vall of RoA

clan.c					Clan code.

		******** 100% Completely Original Code ********
		*** BE AWARE OF ALL RIGHTS AND RESERVATIONS ***
		******** 100% Completely Original Code ********
		        All rights reserved henceforth. 

    Please note that no guarantees are associated with any code from
Realms of Aurealis.  All code which has been released to the general
public has been done so with an 'as is' pretense.  RoA is based on both
Diku and CircleMUD and ALL licenses from both *MUST* be adhered to as well
as the RoA license.   *** Read, Learn, Understand, Improve ***

	- original write date: 8/30/95
 	- streamlined 1/2/97
************************************************************************ */
#include "conf.h"
#include "sysdep.h"

#include "structures.h"
#include "utils.h"
#include "comm.h"
#include "interpreter.h"
#include "acmd.h"
#include "handler.h"
#include "db.h"
#include "mudlimits.h"
#include "lists.h"

#define IN_CLAN(ch)     ((ch)->pc_specials->saved.in_clan)
#define CLAN_NUM(ch)    ((ch)->pc_specials->saved.clan_num)
#define CLAN_LEADER(ch) ((ch)->pc_specials->saved.clanleader)
#define CLAN_NAME(ch)   ((ch)->pc_specials->saved.clan)
#define CLAN_ASS(ch)	(PLR2_FLAGGED((ch), PLR2_CLAN_ASS))
#define IN_SAME_CLAN(ch, vict)  (CLAN_NUM(ch) == CLAN_NUM(vict) && \
				 !str_cmp(CLAN_NAME(ch), CLAN_NAME(vict)))

ACMD(do_clan)
{
  struct descriptor_data *d;
  int count = 1;

  if (IS_NPC(ch)) return;

  if (!IN_CLAN(ch))
  {
    send_to_char("You are not a member of any clan.\n\r",ch);
    send_to_char("%BHELP CLAN%0 for more info.\n\r",ch);
    return;
  }

  if (CLAN_LEADER(ch))
  {
    sprintf(buf, "You lead the clan: %s.\n\r",CLAN_NAME(ch));
    S2C();
  } 
  else
  if (CLAN_ASS(ch))
  {
    sprintf(buf, "You are a leader-assistant of the clan: %s.\n\r",
	    CLAN_NAME(ch));
    S2C();
  }
  else
  {
    sprintf(buf, "You are a member of the clan: %s.\n\r",CLAN_NAME(ch));
    S2C();
  }

  for (d = descriptor_list; d; d = d->next)
    if (D_CHECK(d) && d != ch->desc && IS_PC(d->character) && 
	IN_SAME_CLAN(d->character, ch) && 
	GET_LEVEL(ch) >= GET_INVIS_LEV(d->character))
     count++;

   sprintf(buf, "Number of members online: %d.\n\r",count);
   S2C();
   send_to_char("Use %6cs ?%0 for clanmembers online and on channel.\n\r",ch);
   return;
}

ACMD(do_clan_name)
{
  char *argu = argument;

  if (IS_NPC(ch)) return;

  if (!CLAN_LEADER(ch))
  {
    send_to_char("You must be a leader of a clan to create a clan name.\n\r",ch);
    send_to_char("If you wish to become a leader of a clan, speak to an Immortal.\n\r",ch);
    send_to_char("HELP CLANS for more info.\n\r",ch);
    return;
  }

  if (!*argu)
  {
    send_to_char("What do you wish to name your clan?\n\r",ch);
    return;
  }

  skip_spaces(&argu);
  if (strlen(argu) > MAX_CLAN_LENGTH -10) 
  {
    send_to_char("Clan name too long... please select another.\n\r",ch);
    return;
  }

  strcpy(CLAN_NAME(ch), argu);  
  sprintf(buf, "You now lead the clan: %s.\n\r",CLAN_NAME(ch));
  S2C();
  send_to_char("\n\rUse CLANJOIN and CLANDISMISS to enroll/dismiss members.\n\r",ch);
}

ACMD(do_clan_join)
{
  char *argu = argument; 
  chdata *vict;

  if (IS_NPC(ch)) return;

  if (!CLAN_LEADER(ch) && !CLAN_ASS(ch))
  {
    send_to_char("You do not have that ability...\n\r",ch);
    return;
  }

  if (!*argu) 
  {
    sprintf(buf,"Who do you wish to join to clan: %s?\n\r",CLAN_NAME(ch));
    S2C();
    return;
  }

  skip_spaces(&argu);
  if (!(vict = get_char_room_vis(ch, argu)))
  {
    send_to_char("They are not here....\n\r",ch);
    return;
  }

  if (IS_NPC(vict))
  {
    send_to_char("You cannot clanjoin NPC's.\n\r", ch);
    return;
  }
  
  if (ch == vict)
  {
     send_to_char("You wish to join yourself eh?\n\r",ch);
     return;
  }

  if (IN_CLAN(vict))
  {
    sprintf(buf, "%s is already a member of clan: %s !\n\r",GET_NAME(vict), CLAN_NAME(vict));
    S2C();
    return;
  }

  /* ok join a member */
  IN_CLAN(vict) = TRUE; 
  strcpy(CLAN_NAME(vict), CLAN_NAME(ch));  
  CLAN_NUM(vict) = CLAN_NUM(ch);  

  sprintf(buf, "%s has accepted you as a member of clan: %s !\n\r", 
	  GET_NAME(ch), CLAN_NAME(vict));
  send_to_char(buf, vict);

  sprintf(buf, "You accept %s into clan: %s.\n\r",GET_NAME(vict), CLAN_NAME(ch));
  S2C();

  sprintf(buf, "%s has accepted %s into clan: %s !!",GET_NAME(ch), GET_NAME(vict), CLAN_NAME(vict));
  do_gecho(ch, buf, 0, 0);
}

ACMD(do_clan_dis)
{
  char *argu = argument;
  chdata *vict;

  if (IS_NPC(ch)) return;

  if (!CLAN_LEADER(ch) && !CLAN_ASS(ch))
  {
    send_to_char("You do not have that ability...\n\r",ch);
    return;
  }

  if (!*argu) 
  {
    sprintf(buf,"Who do you wish to dismiss from clan: %s?\n\r",CLAN_NAME(ch));
    S2C();
    return;
  }

  skip_spaces(&argu);
  if (!(vict = get_char_room_vis(ch, argu)))
  {
    send_to_char("They are not here....\n\r",ch);
    return;
  }

  if (IS_NPC(vict))
  {
    send_to_char("Mobs do not participate in clan activity.\n\r",ch);
    return;
  }
  
  if (ch == vict)
  {
     send_to_char("You wish to dismiss yourself?\n\r",ch);
     send_to_char("See an immortal for help in this matter.\n\r",ch);
     return;
  }

  if (!IN_SAME_CLAN(ch, vict))
  {
    send_to_char("That person is not a member of your clan!\n\r",ch);
    return;
  }

  // do not let assisstants dismiss leaders  2/5/98 -jtrhone
  if (CLAN_LEADER(vict))
  {
    send_to_char("You cannot dismiss the leader!n\r",ch);
    return;
  }

  /* dismiss a member */
  IN_CLAN(vict) = FALSE;
  REMOVE_BIT(PLR2_FLAGS(vict), PLR2_CLAN_ASS);
  *CLAN_NAME(vict) = '\0';
  CLAN_NUM(vict) = 110;  /* out of range of clan nums 0-100*/  

  sprintf(buf, "%s has dismissed you from clan: %s !\n\r",GET_NAME(ch), CLAN_NAME(ch));
  send_to_char(buf, vict);

  sprintf(buf, "You dismiss %s from clan: %s.\n\r",GET_NAME(vict), CLAN_NAME(ch));
  S2C();

  sprintf(buf, "%s has dismissed %s from clan: %s !!",GET_NAME(ch), GET_NAME(vict), CLAN_NAME(ch));
  do_gecho(ch, buf, 0, 0);
}

ACMD(do_clan_say)
{
  struct descriptor_data *d;
  char *argu = argument;

  if (IS_NPC(ch)) return;

  if (!IN_CLAN(ch))
  {
    send_to_char("You are not a member of any clan!\n\r",ch);
    return;
  }

  if (!*argu)
  {
    send_to_char("What do you wish to clan say??\n\r",ch);
    return;
  }

  skip_spaces(&argu);
  if (*argu == '+')
  {
    SET_BIT(PRF_FLAGS(ch), PRF_CLAN_CH);
    send_to_char("You join your clan channel.\n\r",ch);
    return;
  }
  else
  if (*argu == '-')
  {
    REMOVE_BIT(PRF_FLAGS(ch), PRF_CLAN_CH);
    send_to_char("You turn your clan channel off.\n\r",ch);
    return;
  }

  if (!PRF_FLAGGED(ch, PRF_CLAN_CH))
  {
    send_to_char("You are not on your clan channel! (%6cs +%0 to turn it on)\n\r",ch);
    return;
  }

  if (*argu == '?')
  {
    sprintf(buf, "%s (online and on channel):\n\r",CLAN_NAME(ch)); 
    for (d = descriptor_list; d; d = d->next)
      if (D_CHECK(d) && IS_PC(d->character) && 
          PRF_FLAGGED(d->character, PRF_CLAN_CH) && IN_SAME_CLAN(d->character, ch) &&
          GET_LEVEL(ch) >= GET_INVIS_LEV(d->character))
        sprintf(buf + strlen(buf), "   %s\n\r",GET_NAME(d->character));

    page_string(ch->desc, buf, 1);
    return;
  }

  if (ROOM_FLAGGED2(ch->in_room, SOUNDPROOF))
  {
    send_to_char("This area seems to absorb your words.\n\r",ch);
    return;
  }

  sprintf(buf, "You %%6clan-say%%0 '%s'\n\r", argu);
  S2C();

  for (d = descriptor_list; d; d = d->next)
    if (D_CHECK(d) && d != ch->desc &&
        IS_PC(d->character) && !PLR_FLAGGED(d->character, PLR_BUILDING) &&
        !PLR_FLAGGED(d->character, PLR_WRITING) &&
        PRF_FLAGGED(d->character, PRF_CLAN_CH) &&
        !ROOM_FLAGGED2(d->character->in_room, SOUNDPROOF))
     if (IN_SAME_CLAN(d->character, ch))
     {
       if (can_see(d->character, ch))
        sprintf(buf, "[%s] %s: %s\n\r", CLAN_NAME(ch), GET_NAME(ch), argu);
       else
        sprintf(buf, "[%s] Someone: %s\n\r", CLAN_NAME(ch), argu);
       send_to_char(buf, d->character);
     }        
}

ACMD(do_clan_who)
{
  struct descriptor_data *d;
  char *argu = argument;

  if (IS_NPC(ch)) return;

  if (!*argu)
  {
    send_to_char("CLANWHO: All clanmembers online\n\r",ch);
    send_to_char("-------------------------------\n\r",ch);

    for (*buf = '\0', d = descriptor_list; d; d = d->next)
      if (D_CHECK(d) && IS_PC(d->character) &&
          IN_CLAN(d->character) && GET_LEVEL(ch) >= GET_INVIS_LEV(d->character))
        sprintf(buf + strlen(buf), "[%s] %s\n\r", CLAN_NAME(d->character), 
                GET_NAME(d->character));
    if (*buf)
     page_string(ch->desc, buf, 1);
    else
     send_to_char("%4None.%0\n\r",ch); 
    return;
  }

  skip_spaces(&argu);
  sprintf(buf, "CLANWHO: Members of clan '%s' online:\n\r", argu);
  S2C();
  send_to_char("-------------------------------\n\r",ch);
  for (*buf = '\0', d = descriptor_list; d; d = d->next)
    if (D_CHECK(d) && IS_PC(d->character)) 
     if (IN_CLAN(d->character) && GET_LEVEL(ch) >= GET_INVIS_LEV(d->character) &&
         !str_cmp(CLAN_NAME(d->character), argu))
        sprintf(buf + strlen(buf), "[%s] %s\n\r", CLAN_NAME(d->character), 
                GET_NAME(d->character));
  if (*buf)
    page_string(ch->desc, buf, 1);
  else
    send_to_char("%4None.%0\n\r",ch);
}

ACMD(do_clan_ass)
{
  chdata *vict;
  char *argu = argument;

  if (IS_NPC(ch) || !CLAN_LEADER(ch))
  {
    send_to_char("You do not have that ability.\n\r",ch);
    return;
  }

  skip_spaces(&argu);
  if (!*argu)
  {
    send_to_char("Usage: clanassist <member of your clan>.\n\r",ch);
    return;
  }

  if (!(vict = get_char_room_vis(ch, argu)))
  {
    send_to_char("Who?\n\r",ch);
    return;
  }

  if (IS_NPC(vict))
  {
    send_to_char("Not hardly.\n\r",ch);
    return;
  }

  if (!IN_SAME_CLAN(ch, vict))
  {
    sprintf(buf, "You must be in the same clan as %s.\n\r",GET_NAME(vict));
    S2C();
    return;
  }

  TOGGLE_BIT(PLR2_FLAGS(vict), PLR2_CLAN_ASS);

  if (CLAN_ASS(vict))
  {
    act("You make $N a clan assistant.",FALSE, ch, 0, vict, TO_CHAR);
    act("You have been made a clan assistant by $n.",FALSE,ch,0,vict,TO_VICT);
  }
  else
  {
    act("$N is no longer a clan assistant.",FALSE, ch, 0, vict, TO_CHAR);
    act("You are no longer a clan assistant.",FALSE,ch,0,vict,TO_VICT);
  }
}