phone.c

phone.c · 16.8 KB

From the archive cellphones1.1.zip

Download the archive   « Back to the archive contents

/**************************************************************
 * Cell phone code for the Modern MUD v1.1 (November 7, 2002) *
 * --by Selquest of Drug Wars (dwmud.ods.org 2528)            *
 **************************************************************
 * This concept and code originated from Selquest of Drug Wars MUD.
 *
 * You are free to use, modify, or distribute this code as long as you adhere to the following:
 * 1)Please send me an e-mail at selquest05@softhome.net telling me you're using this code,
 *	not for any kind of registration, I just like to know where my code is being used.
 * 2)Please keep this header intact.
 * 3)If you distribute this code, please only distribute in the original zip file, or if you 
 *	have made modifications, keep this readme file in the distribution package.
 *
 * Installation process:
 * 1)Insert phone.c into your src directory, and add obj\phone.o to your Makefile.
 * 2)Add the definitions of MAX_PHONESTORE and ITEM_PHONE in the appropriate places in merc.h
 * 3)Add called, calling, speaking, & requesting to CHAR_DATA in merc.h
 * 4)Add phonestore_label[MAX_PHONESTORE] and phonestore_number[MAX_PHONESTORE] to PC_DATA in merc.h
 * 5)Add the commands phone, pickup, hangup, speak, request, send, keep, phonestore,
 *   phonelist, and phoneremove to interp.c & interp.h
 * 6)Depending on your OLC (or lack of it), you will need to write procedures for ITEM_PHONE,
 *   which requires v0 and v1.
 * That should do it...if you encounter problems or need help, send me an e-mail at the address
 * listed above.  Also, note that these commands have strange names because of conflicts with
 * other commands on my MUD...it might be a good idea to change these to things more suitable.
 *
 * This is my first publicly released snippet, so i may have left something out.  If you find
 * something I overlooked, feel free to send me an e-mail at selquest05@softhome.net. Enjoy!
 *
 * VERSION HISTORY:
 * v1.0 (November 7, 2002): first release
 * v1.1 (November 9, 2002): fixed some minor bugs from v1.0
 */
#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"

void do_phonestore( CHAR_DATA *ch, char *argument)
{
    char arg[MAX_INPUT_LENGTH], buf[MAX_STRING_LENGTH];
    int number;
    int pos;

    if (IS_NPC(ch))
	return;

    argument = one_argument(argument, arg);

    if (arg[0] == '\0' || argument[0] == '\0' || !is_number(argument))
    {
	send_to_char("Syntax: 'phonestore <label> <number>'", ch);
	return;
    }

    for (pos = 0; pos < MAX_PHONESTORE; pos++)
    {
	if (ch->pcdata->phonestore_label[pos] == NULL)
	    break;
    }

    if (pos >= MAX_PHONESTORE)
    {
	send_to_char("Sorry, you have reached the stored numbers limit.\n\r", ch);
	return;
    }
    number = atoi(argument);
    ch->pcdata->phonestore_label[pos]	= str_dup(arg);
    ch->pcdata->phonestore_number[pos]	= number;
    sprintf(buf, "%d is now stored and labeled as %s.\n\r", number, arg);
    send_to_char(buf, ch);
}

void do_phoneremove( CHAR_DATA *ch, char *argument)
{
    char arg[MAX_INPUT_LENGTH];
    int pos;
    bool found = FALSE;

    if (IS_NPC(ch))
	return;

    argument = one_argument(argument, arg);

    if (arg[0] == '\0')
    {
	send_to_char("Syntax: 'phoneremove <label>'", ch);
	return;
    }

    for (pos = 0; pos < MAX_PHONESTORE; pos++)
    {
	if (ch->pcdata->phonestore_label[pos] == NULL)
	    break;

	if (found)
	{
	    ch->pcdata->phonestore_label[pos-1]	= ch->pcdata->phonestore_label[pos];
	    ch->pcdata->phonestore_number[pos-1] = ch->pcdata->phonestore_number[pos];
	    ch->pcdata->phonestore_label[pos]	= NULL;
	    ch->pcdata->phonestore_number[pos]	= 0;
	    continue;
	}

	if (!strcmp(arg, ch->pcdata->phonestore_label[pos]))
	{
	    send_to_char("Number removed.\n\r", ch);
	    free_string(ch->pcdata->phonestore_label[pos]);
	    ch->pcdata->phonestore_label[pos] = NULL;
	    ch->pcdata->phonestore_number[pos] = 0;
	    found = TRUE;
	}
    }

    if (!found)
	send_to_char("No number with that label to remove.\n\r", ch);
}

void do_phonelist( CHAR_DATA *ch, char *arg)
{
    char buf[MAX_STRING_LENGTH];
    int pos;

    if (IS_NPC(ch))
	return;

    if (ch->pcdata->phonestore_label[0] == NULL)
    {
	send_to_char("You have no numbers stored.\n\r", ch);
	return;
    }

    send_to_char("The numbers you currently have stored are:\n\r", ch);

    for (pos = 0; pos < MAX_PHONESTORE; pos++)
    {
	if (ch->pcdata->phonestore_label[pos] == NULL)
	    break;

	sprintf(buf,"	%s:	%d\n\r", ch->pcdata->phonestore_label[pos], ch->pcdata->phonestore_number[pos]);
	send_to_char(buf, ch);
    }
}

void do_phone( CHAR_DATA * ch, char *arg )
{
   CHAR_DATA *victim;
   char buf[MAX_STRING_LENGTH];
   int pos;
   int number;
   bool found;
   DESCRIPTOR_DATA *d;

   if ( !carries_phone(ch) )
   {
	send_to_char("You need a phone to do that.\n\r", ch);
	return;
   }
   if ( ch->calling != NULL ){
	send_to_char( "You're already on the phone silly!\n\r", ch);
	return;
   }
   if ( ch->called != NULL ){
	send_to_char( "You cannot use the line while you have a call waiting.\n\r", ch);
	return;
   }
	if ( IS_SET( ch->comm, COMM_NOTELL ) ) {
      send_to_char( "Your call didn't get through.\n\r", ch );
      return;
   }
   if ( IS_SET( ch->comm, COMM_QUIET ) ) {
      send_to_char( "You must turn off quiet mode first.\n\r", ch );
      return;
   }
   if ( IS_SET( ch->comm, COMM_DEAF ) && !IS_IMMORTAL( ch ) ) {
      send_to_char( "You must turn off deaf mode first.\n\r", ch );
      return;
   }
   
   if ( arg[0] == '\0' ) {
      send_to_char( "Call whom?\n\r", ch );
      return;
   }
    found = FALSE;
    number = 0;

    if ( !is_number(arg) )
    {
	for(pos = 0; pos < MAX_PHONESTORE; pos++)
	{
	    if (ch->pcdata->phonestore_label[pos] == NULL)
		break;

	    if ( !str_cmp(ch->pcdata->phonestore_label[pos], arg))
	    {
		number = ch->pcdata->phonestore_number[pos];
		found = TRUE;
		break;
	    }
	}
    }

    if (!found)
	number = atoi(arg);

    victim = ch;
    found = FALSE;

    for (d = descriptor_list; d != NULL; d = d->next)
    {
	if (d->character != NULL && d->connected == CON_PLAYING
	    &&  d->character->in_room != NULL && can_see(ch,d->character)
	    &&  can_see_room(ch,d->character->in_room))
	{
	    if (d->character->id == number )
	    {
		victim = d->character;
		found = TRUE;
		break;
	    }
	}
    }

    if (!found || !carries_phone(victim))
    {
	send_to_char("Noone seems to be answering at that number.\n\r", ch);
	return;
    }

   if ( victim->speaking != NULL || victim->called != NULL || victim->calling != NULL ){
	send_to_char( "The line is busy.\n\r", ch);
	return;
   }

   if ( victim->desc == NULL && !IS_NPC( victim ) ) {
      act( "$N seems to have misplaced $S link...try again later.", ch,
           NULL, victim, TO_CHAR );
      sprintf( buf, "{y%s called you on the phone.{w\n\r", PERS( ch, victim ) );
      buf[0] = UPPER( buf[0] );
      add_buf( victim->pcdata->buffer, buf );
      return;
   }

   if ( !( IS_IMMORTAL( ch ) && ch->level > LEVEL_IMMORTAL )
        && !IS_AWAKE( victim ) ) {
      act( "$E can't hear you.", ch, 0, victim, TO_CHAR );
      return;
   }
   if ( ( IS_SET( victim->comm, COMM_QUIET )
          || IS_SET( victim->comm, COMM_DEAF ) ) && !IS_IMMORTAL( ch ) ) {
      act( "$E is not receiving calls.", ch, 0, victim, TO_CHAR );
      return;
   }
   if ( ( IS_IMMORTAL( ch ) && ch->level < victim->level )
        && ( IS_SET( victim->comm, COMM_QUIET )
             || IS_SET( victim->comm, COMM_DEAF ) ) ) {
      act( "$E is not receiving calls.", ch, 0, victim, TO_CHAR );
      return;
   }
   if ( IS_SET( victim->comm, COMM_AFK ) ) {
      act( "{w$E is {RAFK{w, but your call will go through when $E returns.", ch, NULL, victim, TO_CHAR );
      sprintf( buf, "{y%s called you.", PERS( ch, victim ) );
      buf[0] = UPPER( buf[0] );
      add_buf( victim->pcdata->buffer, buf );
      return;
   }
   sprintf(buf, "You dial %d.\n\r", number);
   send_to_char(buf, ch);
   act("$n dials a number in $s cell phone.", ch, NULL, NULL, TO_ROOM);
   send_to_char("Your phone rings.\n\r", victim);
   act("$n's phone rings.\n\r", victim, NULL, NULL, TO_ROOM);
   victim->called = ch;
   ch->calling = victim;
   if ( !IS_NPC( ch ) && IS_NPC( victim )
        && HAS_TRIGGER_MOB( victim, TRIG_SPEECH ) )
      p_act_trigger( arg, victim, NULL, NULL, ch, NULL, NULL,
                     TRIG_SPEECH );
   return;
}
void do_pickup( CHAR_DATA * ch, char *argument )
{
   CHAR_DATA *victim;
   char buf[MAX_STRING_LENGTH];

   if ( !carries_phone(ch) )
   {
	send_to_char( "You need a phone to do that.\n\r", ch );
	return;
   }

   if ( ch->called == NULL ){
	send_to_char( "Nobody has called you silly!.\n\r", ch );
	return;
   }
   if ( ch->speaking != NULL ){
	send_to_char( "You're already talking on the phone!\n\r", ch );
	return;
   }
   if ( IS_SET( ch->comm, COMM_NOTELL ) ) {
      send_to_char( "Your message didn't get through.\n\r", ch );
      return;
   }
   if ( ( victim = ch->called ) == NULL ) {
      send_to_char( "They aren't here.\n\r", ch );
      return;
   }
   if ( !carries_phone(victim) )
   {
	send_to_char( "The line is dead.\n\r", ch);
	return;
   }
   if ( victim->desc == NULL && !IS_NPC( victim ) ) {
      act( "They seem to have misplaced their link...try again later.", ch,
           NULL, victim, TO_CHAR );
      sprintf( buf, "{Y%s answered your call.", PERS( ch, victim ));
      buf[0] = UPPER( buf[0] );
      add_buf( victim->pcdata->buffer, buf );
      return;
   }
   if ( !IS_IMMORTAL( ch ) && !IS_AWAKE( victim ) ) {
      act( "$E can't hear you.", ch, 0, victim, TO_CHAR );
      return;
   }
   if ( ( IS_SET( victim->comm, COMM_QUIET )
          || IS_SET( victim->comm, COMM_DEAF ) ) && !IS_IMMORTAL( ch )
        && !IS_IMMORTAL( victim ) ) {
      act_new( "They are not receiving calls.", ch, 0, victim, TO_CHAR,
               POS_DEAD );
      return;
   }
   if ( !IS_IMMORTAL( victim ) && !IS_AWAKE( ch ) ) {
      send_to_char( "In your dreams, or what?\n\r", ch );
      return;
   }
   if ( IS_SET( victim->comm, COMM_AFK ) ) {
      if ( IS_NPC( victim ) ) {
         act_new( "{wThey are {RAFK{w, and not receiving tells.", ch, NULL,
                  victim, TO_CHAR, POS_DEAD );
         return;
      }
      act_new
          ( "They are{RAFK{w, but your call will go through when they return.",
            ch, NULL, victim, TO_CHAR, POS_DEAD );
      sprintf( buf, "{ySomeone answers your call.");
      buf[0] = UPPER( buf[0] );
      add_buf( victim->pcdata->buffer, buf );
      return;
   }
   send_to_char("You answer your cell phone.\n\r", ch);
   send_to_char("Someone picks up the phone.\n\r", victim);
   act("$n answers $s cell phone.", ch, NULL, NULL, TO_ROOM);
   victim->speaking = ch;
   ch->speaking = victim;
   ch->called = NULL;
   ch->calling = NULL;
   victim->called = NULL;
   victim->calling = NULL;
   return;
}

void do_speak( CHAR_DATA * ch, char *arg )
{
    CHAR_DATA *victim;

    if ( !carries_phone(ch) ){
	send_to_char("You need a phone to do that.\n\r", ch);
	return;
    }
    if ( (victim = ch->speaking) == NULL)
    {
	send_to_char("You are not on the phone right now.\n\r", ch);
	return;
    }

    if ( !carries_phone(victim) )
    {
	send_to_char("The line seems to have gone dead.\n\r", ch);
	return;
    }
   act("{BYou speak into your phone: '{r$t{B'{w", ch, arg, victim, TO_CHAR);
   act("{b$n speaks into $s phone: '{R$t{b'{w", ch, arg, victim, TO_ROOM);
   act("{bYou hear over the phone: '{R$t{b'{w", ch, arg, victim, TO_VICT);
   return;
}
    
void do_hangup( CHAR_DATA * ch, char *arg )
{
    CHAR_DATA *victim;
    OBJ_DATA *obj;

    if ( !carries_phone(ch) )
    {
	send_to_char("You need a phone to do that.\n\r", ch);
	return;
    }
    if ((victim = ch->speaking) == NULL)
    {
        send_to_char("You're not on the phone right now!", ch);
        return;
    }

    for ( obj = victim->carrying; obj != NULL; obj = obj->next_content )
    {
        if ( obj->pIndexData->item_type == ITEM_PHONE )
        {
	    if (obj->value[0] != -1){
            obj->value[1] --;
            if ( obj->value[1] == 0 )
            {
                send_to_char("Your cell phone plan expires.\n\r", victim);
                extract_obj( obj );
            }
	    }
            break;
        }
    }

    for ( obj = ch->carrying; obj != NULL; obj = obj->next_content )
    {
        if ( obj->pIndexData->item_type == ITEM_PHONE )
        {
	    if (obj->value[0] != -1){
            obj->value[1] --;
	    if ( obj->value[1] == 0 )
	    {
		send_to_char("Your cell phone plan expires.\n\r", ch);
		extract_obj( obj );
	    }
	    }
	    break;
        }
    }

    ch->calling = NULL;
    ch->speaking = NULL;
    ch->called = NULL;
    victim->calling = NULL;
    victim->speaking = NULL;
    victim->called = NULL;
    send_to_char("The line goes dead.\n\r", victim);
    send_to_char("You hang up the phone.\n\r", ch);
    act("$n hangs up $s phone.\n\r", ch, arg, victim, TO_ROOM);
    return;
}

bool carries_phone( CHAR_DATA * ch )
{
    OBJ_DATA *obj;
    OBJ_DATA *obj2;

    for ( obj = ch->carrying; obj != NULL; obj = obj->next_content )
    {
        if ( obj->pIndexData->item_type == ITEM_PHONE )
        {
            return TRUE;
        }

	if ( obj->pIndexData->item_type == ITEM_CONTAINER )
	{	
	    for ( obj2 = obj->contains; obj2 != NULL; obj2 = obj2->next_content )
	    {
		if ( obj2->pIndexData->item_type == ITEM_PHONE )
		    return TRUE;
	    }
	}
    }

    return FALSE;
}

void do_request( CHAR_DATA * ch, char *arg)
{
    CHAR_DATA *victim;
    char buf[MAX_STRING_LENGTH];

    if (IS_NPC(ch))
	return;
    if (!carries_phone(ch))
    {
	send_to_char("You need a phone to do that.\n\r", ch);
	return;
    }
    if ( arg[0] == '\0' )
    {
	send_to_char("Request who's number?\n\r", ch);
	return;
    }
    if ( ( victim = get_char_world( ch, arg ) ) == NULL
        || ( ( IS_NPC( victim ) && victim->in_room != ch->in_room ) )
                  || !can_see_remote( ch, victim ) )
    {
	send_to_char("They aren't here.\n\r", ch);
	return;
    }
    if ( !carries_phone(victim) )
    {
	send_to_char("They don't have a phone.\n\r", ch);
	return;
    }

    sprintf(buf, "{G%s has requested your phone number.{x\n\r", ch->name);
    send_to_char( buf, victim );
    sprintf(buf, "{GYou request %s's phone number.{x\n\r", victim->name);
    send_to_char( buf, ch );
    ch->requesting = victim;
    return;
}

void do_send( CHAR_DATA * ch, char *arg)
{
    CHAR_DATA *victim;
    char buf[MAX_STRING_LENGTH];

    if ( IS_NPC(ch) )
	return;
    if ( !carries_phone(ch) )
    {
	send_to_char( "You need a phone to do that.\n\r", ch);
	return;
    }
    if ( ( victim = get_char_world( ch, arg ) ) == NULL
        || ( ( IS_NPC( victim ) && victim->in_room != ch->in_room ) )
                  || !can_see_remote( ch, victim ) )
    {
	send_to_char( "They aren't here.\n\r", ch);
	return;
    }
    if ( !carries_phone(victim) )
    {
	send_to_char( "They don't have a phone!\n\r", ch);
	return;
    }
    if ( victim->requesting != ch )
    {
	send_to_char( "They aren't requesting your number!\n\r", ch);
	return;
    }

    sprintf( buf, "{G%s sends you their phone number: {R%ld{x\n\r", ch->name, ch->id);
    send_to_char( buf, victim );
    sprintf( buf, "{GYou send your phone number to %s.{x\n\r", victim->name);
    send_to_char( buf, ch );

    victim->requesting = NULL;
    return;
}

void do_keep( CHAR_DATA * ch, char *arg)
{
    CHAR_DATA *victim;
    char buf[MAX_STRING_LENGTH];

    if ( IS_NPC(ch) )
        return;
    if ( !carries_phone(ch) )
    {
        send_to_char( "You need a phone to do that.\n\r", ch);
        return;
    }
    if ( ( victim = get_char_world( ch, arg ) ) == NULL
        || ( ( IS_NPC( victim ) && victim->in_room != ch->in_room ) )
                  || !can_see_remote( ch, victim ) )
    {
        send_to_char( "They aren't here.\n\r", ch);
        return;
    }
    if ( !carries_phone(victim) )
    {
        send_to_char( "They don't have a phone!\n\r", ch);
        return;
    }
    if ( victim->requesting != ch )
    {
        send_to_char( "They aren't requesting your number!\n\r", ch);
        return;
    }

    sprintf( buf, "{G%s has denied you their phone number.{x\n\r", ch->name);
    send_to_char( buf, victim );
    sprintf( buf, "{GYou deny your phone number from %s.{x\n\r", victim->name);
    send_to_char( buf, ch );

    victim->requesting = NULL;
    return;
}

Site Stats

Snippets: 1791
Codebases: 571