area/
#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#include <sys/time.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include "merc.h"

DECLARE_DO_FUN(do_look     );
int     wrestle;

/*=======================================================================*
 * function: do_wrestle                                                  *
 * purpose: Challenges person to wrestling match                         *
 * written by:  Zaphonite                                                *
 *=======================================================================*/
void do_wrestle(CHAR_DATA *ch, char *argument)
{
  CHAR_DATA *victim; 
  char buf[MAX_STRING_LENGTH]; 
  DESCRIPTOR_DATA *d;

 if(IS_NPC(ch))
  return; 

 if( wrestle == WRESTLE_START )
  {
  send_to_char("The wrestling ring is already being used.\n\r",ch);
  return;
  }

 if( wrestle == WRESTLE_BUSY )
  {
  send_to_char("There is a match in progress at the moment, try in a few minutes.\n\r",ch);
  return; 
  }

 if( wrestle == WRESTLE_LOCK )
  {
  send_to_char("The wrestling ring is currently closed.\n\r",ch);
  return;
  }

 if(IS_SET(ch->act,PLR_CHALLENGED))
  {
  send_to_char("You have already been challenged, either AGREE or DECLINE first.\n\r",ch);
  return; 
  }

 if(ch->hit < ch->max_hit)
  {
  send_to_char("You must be fully healed to wrestle in the ring.\n\r",ch);
  return;
  }


 if(argument[0] == '\0')
  {
  send_to_char("You must specify whom you wish to challenge.\n\r",ch);
  return;
  }

 if((victim = get_char_world(ch,argument)) == NULL)
  {
  send_to_char("They are not playing.\n\r",ch);
  return;
  }



 if(IS_NPC(victim) || IS_IMMORTAL(victim) || victim == ch )
  {
  send_to_char("You cannot challenge NPC's or yourself.\n\r",ch);
  return;
  }


 if(IS_SET(victim->act,PLR_CHALLENGER))
  {
  send_to_char("They are currently challenging someone else in the arena or in wrestling.\n\r",ch);
  return;
  }

 if(victim->fighting != NULL )
  {
  send_to_char("That person is engaged in battle right now.\n\r",ch); 
  return; 
  }

 if(victim->hit < victim->max_hit)
  {
  send_to_char("That player is not healthy enough to wrestle right now.\n\r",ch);
  return;
  }


 if ( victim->desc == NULL )
  {
  send_to_char("That player is linkdead at the moment, try them later.\n\r",ch);
  return;
  }

 ch->challenged = victim;
 SET_BIT(ch->act,PLR_CHALLENGER);
 victim->challenger = ch;
 SET_BIT(victim->act,PLR_CHALLENGED);
 wrestle == WRESTLE_START;
 send_to_char("Your wrestling challenge has been sent\n\r",ch);
 act("$n has challenged you to a wrestling match.",ch,NULL,victim,TO_VICT);
 sprintf(buf,"[Wrestling] %s has challenged %s to a wrestling match.\n\r",
         ch->name, victim->name);
 for ( d = descriptor_list; d; d = d->next )
  {
    if( d->connected == CON_PLAYING)
     {
        ADD_COLOUR(ch,buf,L_RED);
        send_to_char( buf, d->character );
     }
  }
 sprintf(buf,"type: WAGREE %s to meet them in the ring.\n\r",ch->name);
 send_to_char(buf,victim);
 sprintf(buf,"type: WDECLINE %s to run away.\n\r",ch->name); 
 send_to_char(buf,victim);
 return;
}

/*=======================================================================*
 * function: do_wagree                                                   *
 * purpose: to accept the wrestling challenge                            *
 * written by: Zaphonite                                                 *
 *=======================================================================*/
void do_wagree(CHAR_DATA *ch, char *argument)
{
 DESCRIPTOR_DATA *d;
 CHAR_DATA *victim; 
 char buf1[MAX_STRING_LENGTH]; 
 char buf2[MAX_STRING_LENGTH];
 char buf3[MAX_STRING_LENGTH];
 int char_room; 
 int vict_room; 

 char_room = 40001;
 vict_room = 40001;

 if(IS_NPC(ch))
 return;

 if( !IS_SET(ch->act,PLR_CHALLENGED) )
  {
  send_to_char("You have not been challenged.\n\r",ch);
  return;
  }

 if( wrestle == WRESTLE_BUSY )
  {
  send_to_char("Sorry, there is a fight in progress, please wait a few moments.\n\r",ch);
  return;
  }

 if( wrestle == WRESTLE_LOCK )
  {
  send_to_char("Sorry, the wrestling ring is currently closed.\n\r",ch);
  return;
  }

 if(argument[0]=='\0')
  {
  send_to_char("You must specify whose challenge you wish to accept.\n\r",ch);
  return;
  }

 if((victim = get_char_world(ch,argument)) == NULL)
  {
  send_to_char("They aren't logged in!\n\r",ch);
  return;
  }

 if(victim == ch)
  {
  send_to_char("You haven't challenged yourself!\n\r",ch);
  return;
  }

 if(!IS_SET(victim->act,PLR_CHALLENGER) || victim != ch->challenger )
  {
  send_to_char("That player hasn't challenged you!\n\r",ch); 
  return; 
  }

send_to_char("You have accepted the wrestling challenge!\n\r",ch);
act("$n accepts your wrestling challenge!",ch,NULL,victim,TO_VICT);
sprintf(buf1, "[Wrestling] %s (%d wins) (%d losses)\n\r", victim->name,victim->pcdata->wwins,victim->pcdata->wlosses );
sprintf(buf2, "[Wrestling] %s (%d wins) (%d losses)\n\r", ch->name,ch->pcdata->wwins,ch->pcdata->wlosses ); 
for ( d = descriptor_list; d; d = d->next )
  {
     if( d->connected == CON_PLAYING)
     {
        ADD_COLOUR(ch,buf1,L_RED);
        ADD_COLOUR(ch,buf2,L_RED);
        ADD_COLOUR(ch,buf3,L_RED);
        send_to_char( buf1, d->character );
        send_to_char( buf2, d->character );
        send_to_char( buf3, d->character );
        d->character->gladiator = NULL;
     }
  }
send_to_char("You enter the wrestling ring.\n\r",ch);
char_from_room(ch); 
char_to_room(ch,get_room_index(char_room));
do_look(ch, "auto");
send_to_char("You enter the wrestling ring.\n\r",victim); 
char_from_room(victim); 
char_to_room(victim,get_room_index(vict_room)); 
do_look(victim, "auto");
clear_stats(ch);
clear_stats(victim);
wrestle == WRESTLE_BUSY; 
return; 
}

/*=======================================================================*
 * function: do_wdecline                                                 *
 * purpose: to decline a wrestling challenge                             *
 * written by: Zaphonite                                                 *
 *=======================================================================*/
void do_wdecline(CHAR_DATA *ch, char *argument )
{
  CHAR_DATA *victim; 
  char buf[MAX_STRING_LENGTH];
  DESCRIPTOR_DATA *d;

  if(IS_NPC(ch))
   return;

 if( !IS_SET(ch->act,PLR_CHALLENGED) )
  {
  send_to_char("You have not been challenged.\n\r",ch);
  return;
  }

 if(argument[0]=='\0')
  {
  send_to_char("You must specify whose challenge you wish to decline.\n\r",ch);
  return;
  }
  
 if((victim = get_char_world(ch,argument)) == NULL)
  {
  send_to_char("They aren't logged in!\n\r",ch);
  return;
  }

 if(!IS_SET(victim->act,PLR_CHALLENGER) || victim != ch->challenger )
  {
  send_to_char("That player hasn't challenged you.\n\r",ch);
  return;
  }

 if(victim == ch)
 return; 

victim->challenged = NULL;
REMOVE_BIT(victim->act,PLR_CHALLENGER); 
ch->challenger = NULL;
REMOVE_BIT(ch->act,PLR_CHALLENGED);
wrestle == WRESTLE_OPEN;
send_to_char("Challenge declined!\n\r",ch);
act("$n has declined your wrestling match.",ch,NULL,victim,TO_VICT);
sprintf(buf,"[Wrestling] %s has declined %s's wrestling challenge.\n\r",
        ch->name, victim->name);
 for ( d = descriptor_list; d; d = d->next )
  {
     if( d->connected == CON_PLAYING)
     {
        ADD_COLOUR(ch,buf,L_RED);
        send_to_char( buf, d->character );
     }
  }

return;
}