legend/
legend/area/
legend/player/
/***************************************************************************
 *  God Wars Mud copyright (C) 1994, 1995, 1996 by Richard Woolcock        *
 *                                                                         *
 *  Legend of Chrystancia copyright (C) 1999, 2000, 2001 by Matthew Little *
 *  This mud is NOT to be copied in whole or in part, or to be run without *
 *  the permission of Matthew Little. Nobody else has permission to        *
 *  authorise the use of this code.                                        *
 ***************************************************************************/

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

/* Local functions... */
void do_notag(CHAR_DATA *ch, char *argument);
void game_in_play(CHAR_DATA *ch, char *name);

void do_tag( CHAR_DATA *ch, char *argument )
 {

   CHAR_DATA *victim;
   char      name[MAX_STRING_LENGTH];
   char      buf[MAX_STRING_LENGTH];

   name[0]='\0';
   game_in_play(ch, name);

   if (IS_NPC(ch))
      return;

   if ( argument[0] == '\0' )
      {
      send_to_char("Who do you want to tag?\n\r", ch);
      return;
      }

   if ( strcmp(argument,"show")==0 )
      {
      if ( name[0] == '\0' )
         {
	 send_to_char("There is no game of tag in progress, why not start one!\n\r", ch);
 	 return;
	 }
      else
	 {
	 sprintf(buf, "%s is currently IT!\n\r", name);
	 send_to_char(buf, ch);
	 return;
	 }
      }

    if ( strcmp(argument,"quit")==0 )
       {
	if (IS_SET(ch->more, MORE_TAG ))
	   {
	   REMOVE_BIT(ch->more, MORE_TAG);
	   send_to_char("You are nolonger playing TAG.\n\r", ch);
	   sprintf(buf, "%s has quit the TAG Game, Tag Over", ch->name);
           do_taginfo(ch, buf);
	   return;
	   }
	else
	   {
	   send_to_char("But you aren't IT!\n\r", ch);
	   return;
	   }
	}
			
			
    victim = get_char_world(ch,argument);
		 
    if ( victim == NULL )
       {
       send_to_char( "They aren't playing!\n\r", ch);
       return;
       }

     if ( IS_NPC(victim) )
        {
        send_to_char("Sorry! NPC's can't play tag!\n\r", ch);
	return;
        }

     if (IS_SET(victim->more, MORE_NOTAG) )
        {
        send_to_char("They don't want to play tag... Spoil sports!\n\r", ch);
        return;
        }

     if ( (name[0] == '\0' ) ) /* No Game in progress... */
        {
        if ( ch->name == victim->name ) /* Player tags self... */
           {
	   SET_BIT(victim->more, MORE_TAG);
			
	   send_to_char("You tag yourself, Now go get someone!\n\r", ch);
	   sprintf(buf,"%s has started a game of TAG, and is IT", ch->name);
           do_taginfo(ch, buf);
	   return;
	   }
        else /* Player tags someone else... */
	   {
	   if ((ch->in_room->vnum == victim->in_room->vnum) && can_see(ch, victim)) /* Players can see eachother... */
              {
	      SET_BIT(victim->more, MORE_TAG );
			
	      sprintf(buf, "%s Pounces on you shouting 'TAG! You're IT!'\n\r", ch->name);
	      send_to_char(buf, victim);
			
	      sprintf(buf, "You pounce on %s and shout 'TAG! You're IT!'\n\r", victim->name);
	      send_to_char(buf, ch);
			
	      sprintf(buf, "%s has started a game of TAG, and %s is IT!\n\r", ch->name, victim->name);
              do_taginfo(ch, buf);
			
	      return;
              }
 	   else /* Players can't see eachother! */
	      {
	      send_to_char("You can't see anyone by that name...\n\r", ch);
	      return;
	      }
			   
	    }
          }
       else /* There is a game in play... */
	  {
	  if (!IS_SET(ch->more, MORE_TAG) ) /* The player calling tag isn't IT */
	     {
	     sprintf(buf, "There is allready a game in play, and %s is IT!\n\r", name);
	     send_to_char(buf, ch);
	     return;
	     }
	   else /* The player calling tag is IT */
             {
	      if (ch->name == victim->name ) /* Player tags self... */
	         {
		 send_to_char("Tagging yourself won't get you anywhere!\n\r", ch);
		 return;
	         }
	      else /* Player Tags someone else... */
	         {
	         if ((ch->in_room->vnum == victim->in_room->vnum) && can_see(ch, victim)) /* Players can see eachother... */
		    {
		    SET_BIT(victim->more, MORE_TAG );
		    REMOVE_BIT(ch->more, MORE_TAG );

		    sprintf(buf, "%s Pounces on you shouting 'TAG! You're IT!'\n\r", ch->name);
		    send_to_char(buf, victim);
		    sprintf(buf, "You pounce on %s and shout 'TAG! You're IT!'\n\r", victim->name);
		    send_to_char(buf, ch);
		    sprintf(buf, "%s has just tagged %s, %s is now IT!", ch->name, victim->name, victim->name);
                    do_taginfo(ch, buf);
		    return;
		    } 
		 else	 /* Players can't see eachother... */
		    {
		    send_to_char("You can't see anyone by that name...\n\r", ch);
		    return;
		    }
		 } /* End of Player Tags someone else... */ 
	      } /* End of Player calling tag is IT */
	   } /* End of there is a game in play */
	} /* End of do_tag */
		
/********************************************************************/

void do_notag(CHAR_DATA *ch, char *argument) /*Removes a players TAG flag if set... */
{
        if (IS_SET (ch->more, MORE_NOTAG ) )
           {
           send_to_char("You now allow people to tag you. (YAY!)\n\r", ch);
           REMOVE_BIT( ch->more, MORE_NOTAG );
           return;
           }
        else
           {
           send_to_char("You nolonger let people tag you... (Spoil Sport!)\n\r", ch);
           SET_BIT( ch->more, MORE_NOTAG );
           return;
           }
}

/********************************************************************/

void game_in_play(CHAR_DATA *ch, char *name)
{
	CHAR_DATA       *on_it;
	DESCRIPTOR_DATA	*d;

        for ( d = first_descriptor; d; d = d->next )
	  {
	  if ( d->connected == CON_PLAYING && IS_SET(d->character->more, MORE_TAG) )
		  {
		  on_it = d->character;
		  strcpy(name, d->character->name);
		  }
	  }
	 return;
}