/***************************************************************************
 *  Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,        *
 *  Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.   *
 *                                                                         *
 *  Merc Diku Mud improvments 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          *
 *  benefitting.  We hope that you share your changes too.  What goes      *
 *  around, comes around.                                                  *
 ***************************************************************************/
/***************************************************************************
*	ROM 2.4 is copyright 1993-1996 Russ Taylor			   *
*	ROM has been brought to you by the ROM consortium		   *
*	    Russ Taylor (rtaylor@efn.org)				   *
*	    Gabrielle Taylor						   *
*	    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			   *
***************************************************************************/
/***************************************************************************
*	EotN is copyright (C) 1997 by Marcus Speight                       *
*	EotN has been brought to you by the EotN team                      *
*	    Marcus Speight (zortax@usa.net)                                *
*	    Jonathan White (aldarion@mindless.com)                         *
*	    Martin Dibble  (maetar@earthling.net)                          *
*	    Paul Seward    (voltec@cyberdude.com)                          *
*	By using this code, you have agreed to follow the terms of the     *
*	EotN license, in the file eotn/doc/eotn.license                    *
***************************************************************************/
/***************************************************************************
*	MARRY.C written by Ryouga for Vilaross Mud (baby.indstate.edu 4000)*
*	Please leave this and all other credit include in this package.    *
*	Email questions/comments to ryouga@jessi.indstate.edu		   *
***************************************************************************/
/***************************************************************************
 * EotN Implementation, alterations and re-write - Voltec 98               *
 * These headders get longer and longer, but hey ho!  If you use this,     *
 * please leave me (Voltec) and Ryouga some credit in the code and help    *
 * files.  See the help file for information on how to implement the RP    *
 * side of Mud Marriage.... - Voltec 98                                    *
 **************************************************************************/

#include "eotn_pref.h"

void do_marry( CHAR_DATA *ch, char *argument)
   {
   /* Tweaked from Ryougas original code by Voltec -98 *
    * Players now loose their consent flags when they  *
    * get married, and anyone in the room sees them    *
    * get married!  Also now skill based (priests?)    *
    * and generally a bit neater! (well I think so ;>  */

    char arg1[MAX_INPUT_LENGTH],arg2[MAX_INPUT_LENGTH];
    CHAR_DATA *victim;
    CHAR_DATA *victim2;
    int skill;

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

    skill = get_skill(ch,gsn_marry);

    if (IS_IMMORTAL(ch) || skill >= 60)  /* Qualified to perform ceremony */
       { 
       if ( arg1[0] == '\0' || arg2[0] == '\0' )
          {
             send_to_char( "Syntax: marry <char1> <char2>\n\r",ch);
             return;
          }

       if ( ((victim = get_char_world(ch,arg1)) == NULL) ||
            ((victim2 = get_char_world(ch,arg2)) == NULL))
          {
          send_to_char("Both characters must be playing!\n\r", ch );
          return;
          }
    
       if ( IS_NPC(victim) || IS_NPC(victim2))
          {
          send_to_char("Sorry! Mobs can't get married!\n\r", ch);
          return;
          }        
    
       if (!IS_SET(victim->act, PLR_CONSENT) || 
           !IS_SET(victim2->act, PLR_CONSENT))
          {
          send_to_char( "The Gods have not granted consent.\n\r", ch);
          return;
          }
    
       if (victim->pcdata->spouse > 0 || victim2->pcdata->spouse > 0)
          {
          send_to_char( "They are already married! \n\r", ch);
          return;
          }
   

       if (victim->level < 12 || victim2->level < 12)
          {
          send_to_char( "They are not of the proper level to marry.\n\r", ch);
          return;
          }
        
       send_to_char( "You pronounce them man and wife!\n\r", ch);
       send_to_char( "You say the big 'I do.'\n\r", victim);
       send_to_char( "You say the big 'I do.'\n\r", victim2);

       act("$n and $N are now declared married!\n\r", victim, NULL, victim2, TO_NOTVICT);

       strcpy(victim2->name, victim->pcdata->spouse);
       strcpy(victim->name, victim2->pcdata->spouse);
       REMOVE_BIT(victim->act, PLR_CONSENT);    /* So that they can't immediately *
       REMOVE_BIT(victim2->act, PLR_CONSENT);    * Get Divorced - Voltec          */
       return;
       } 
     else /* Not qualified to preform marry! */
       {
       if (skill < 60)
          {
          send_to_char( "You don't yet know enough to preform a marriage.\n\r", ch);
          return;
          }

       send_to_char( "You do not have marrying power.\n\r", ch);
       return;
     }
   }

void do_divorce( CHAR_DATA *ch, char *argument)
   {
   /* Tweaked from Ryougas original code by Voltec -98    *
    * Players now loose their consent flags when they     *
    * get divorced, and anyone in the room sees them      *
    * swap papers.  Only Immortals can sign divorce       *
    * papers, oh and I've tidied up some of the code too  */

    char arg1[MAX_INPUT_LENGTH], arg2[MAX_INPUT_LENGTH];
    CHAR_DATA *victim;
    CHAR_DATA *victim2;
    
    argument = one_argument( argument, arg1 );
    argument = one_argument( argument, arg2 );

    if (IS_IMMORTAL(ch))  /* Qualified to sign divorce papers! */
       { 
       if ( arg1[0] == '\0' || arg2[0] == '\0' )
          {
          send_to_char( "Syntax: divorce <char1> <char2>\n\r",ch);
          return;
          }
       if ( ((victim = get_char_world(ch,arg1)) == NULL) ||
            ((victim2 = get_char_world(ch,arg2)) == NULL))
          {
          send_to_char("Both characters must be playing!\n\r", ch );
          return;
          }
    
       if ( IS_NPC(victim) || IS_NPC(victim2))
          {
          send_to_char("I don't think they're Married to the Mob!\n\r", ch);
          return;
          }
            
       if (!IS_SET(victim->act, PLR_CONSENT) || !IS_SET(victim2->act, PLR_CONSENT))
          {
          send_to_char( "The Gods have not given consent.\n\r", ch);
          return;
          }
    
       if (victim->pcdata->spouse != victim2->name)
          {
          send_to_char( "They aren't even married!!\n\r",ch);
          return;
          }
       
       send_to_char( "You hand them their papers.\n\r", ch);
       send_to_char( "Your divorce is final.\n\r", victim);
       send_to_char( "Your divorce is final.\n\r", victim2);

       act("$n and $N swap divorce papers, they are no-longer married.",
           victim, NULL, victim2, TO_NOTVICT)

       victim->pcdata->spouse = NULL;
       victim2->pcdata->spouse = NULL;
       REMOVE_BIT(victim->act, PLR_CONSENT);    /* So that they can't immediately *
       REMOVE_BIT(victim2->act, PLR_CONSENT);    * Re-Marry - Voltec              */
       return;

       } 
    else /* not qualified! */
       {
       send_to_char( "Only the Gods may grant a divorce.\n\r", ch);
       return;
       }
   }


void do_consent( CHAR_DATA *ch, char *argument )

/* Voltecs "all new" version of the consent command    *
 * This time it's imm only to encourage RP (Players    *
 * must Petition their god for the marrage / divorce   *
 * to be legal.) Voltec -98                            */

{
    char arg1[MAX_INPUT_LENGTH];
    char arg2[MAX_INPUT_LENGTH];

    CHAR_DATA *victim;

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

    if (IS_NPC(ch))
    return;

    if (IS_IMMORTAL(ch))  /* can grant consent */
       {

       if ( arg1[0] == '\0' || arg2[0] == '\0' )
    	  {
          send_to_char( "Syntax: consent <char>\n\r",ch);
          return;
    	  }
       if ( ( victim = get_char_world( ch, arg1 ) ) == NULL )
    	  {
          send_to_char( "They're must be playing!\n\r", ch );
          return;
          }
       if (IS_NPC(victim))
	  {
	  send_to_char( "Not on Mobiles!\n\r", ch);
          }
       if ( IS_SET(ch->act, PLR_CONSENT) )
   	  {
    	  send_to_char( "You deny marital consent.\n\r", ch);
	  send_to_char( "The Gods have now denied you marital consent.\n\r", victim);
    	  REMOVE_BIT(victim->act, PLR_CONSENT);
    	  return;
   	  }
       else
          {                   
          send_to_char( "You now grant marital consent.\n\r", ch);
	  send_to_char( "The Gods have granted you marital consent.\n\r", victim);
   	  SET_BIT(victim->act, PLR_CONSENT);
   	  return;
          }
       }
    else  /* not able to grant consent */
       {
       send_to_char( "Only the Gods may grant marital consent.\n\r", ch);
       }
    }

void do_spousetalk( CHAR_DATA *ch, char *argument )
{
   /* Voltecs Version of the spousetalk command, original idea by     *
    * Ryouga - I think my version is smaller, neater, and only tells  *
    * the calling character that they've sent the message if they     *
    * actually have... one day I'll decide on a colour scheme for it! *
    * Unlike the other routines, I wrote this from scratch Voltec -98 */

   CHAR_DATA *spouse;
   char       buf[MAX_STRING_LENGTH];

   if (argument[0] == '\0' )
      {
      send_to_char("What do you wish to tell your other half?\n\r", ch);
      return;
      }
   else   /* Message to be sent */
      {
      if (spouse = get_char_world(ch, ch->pcdata->spouse)
         {
         sprintf(buf, "You say to %s, '%s'\n\r", ch->pcdata->spouse, argument );
         send_to_char(buf, ch);
         sprintf(buf, "%s says to you '%s'\n\r", ch->name, argument );
         send_to_char(buf, spouse);
         }
      else
         send_to_char("Your spouse doesn't seem to be here!", ch);
      }
}

/********************************************************************************
 * Ryougas spousetalk, incase mine falls over!                                  *
 * Voltec -98                                                                   *
 ********************************************************************************/

void do_old_spousetalk( CHAR_DATA *ch, char *argument )
{
    char buf[MAX_STRING_LENGTH];
    DESCRIPTOR_DATA *d;
 
    if (argument[0] == '\0' )
    {
     send_to_char("What do you wish to tell your other half?\n\r", ch);
     return;
    }
    else  /* message sent */
    {
       
      sprintf( buf, "You say to %s, '%s'\n\r", ch->pcdata->spouse, argument );
      send_to_char( buf, ch );
      for ( d = descriptor_list; d != NULL; d = d->next )
      {
        CHAR_DATA *victim;
 
        victim = d->original ? d->original : d->character;
 
        if ( d->connected == CON_PLAYING &&
             d->character != ch &&
             d->character->name == ch->pcdata->spouse)
        {
          act_new( "$n says to you, '$t'", 
		   ch, argument, d->character, TO_VICT, POS_SLEEPING );
        }
        else
        {
         send_to_char("Your spouse is not here.\n\r", ch);
         return;
        }
      }
    }
}
