home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / d / d-linux.zip / dm-dist / act.comm.c next >
C/C++ Source or Header  |  1991-03-01  |  6KB  |  253 lines

  1. /* ************************************************************************
  2. *  file: act.comm.c , Implementation of commands.         Part of DIKUMUD *
  3. *  Usage : Communication.                                                 *
  4. *  Copyright (C) 1990, 1991 - see 'license.doc' for complete information. *
  5. ************************************************************************* */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. #include "structs.h"
  11. #include "utils.h"
  12. #include "comm.h"
  13. #include "interpreter.h"
  14. #include "handler.h"
  15. #include "db.h"
  16. #include "spells.h"
  17.  
  18. /* extern variables */
  19.  
  20. extern struct room_data *world;
  21. extern struct descriptor_data *descriptor_list;
  22.  
  23.  
  24. void do_say(struct char_data *ch, char *argument, int cmd)
  25. {
  26.     int i;
  27.     static char buf[MAX_STRING_LENGTH];
  28.  
  29.     for (i = 0; *(argument + i) == ' '; i++);
  30.  
  31.     if (!*(argument + i))
  32.         send_to_char("Yes, but WHAT do you want to say?\n\r", ch);
  33.     else
  34.     {
  35.         sprintf(buf,"$n says '%s'", argument + i);
  36.         act(buf,FALSE,ch,0,0,TO_ROOM);
  37.         send_to_char("Ok.\n\r", ch);
  38.     }
  39. }
  40.  
  41.  
  42.  
  43.  
  44. void do_shout(struct char_data *ch, char *argument, int cmd)
  45. {
  46.     static char buf1[MAX_STRING_LENGTH];
  47.   struct descriptor_data *i;
  48.  
  49.  
  50.     if (IS_SET(ch->specials.act, PLR_NOSHOUT))
  51.     {
  52.         send_to_char("You can't shout!!\n\r", ch);
  53.         return;
  54.     }
  55.  
  56.     for (; *argument == ' '; argument++);
  57.  
  58.     if (!(*argument))
  59.         send_to_char("Shout? Yes! Fine! Shout we must, but WHAT??\n\r", ch);
  60.     else
  61.     {
  62.         send_to_char("Ok.\n\r", ch);
  63.         sprintf(buf1, "$n shouts '%s'", argument);
  64.  
  65.         for (i = descriptor_list; i; i = i->next)
  66.           if (i->character != ch && !i->connected &&
  67.             !IS_SET(i->character->specials.act, PLR_NOSHOUT))
  68.                 act(buf1, 0, ch, 0, i->character, TO_VICT);
  69.     }
  70. }
  71.  
  72.  
  73. void do_tell(struct char_data *ch, char *argument, int cmd)
  74. {
  75.     struct char_data *vict;
  76.     char name[100], message[MAX_STRING_LENGTH],
  77.         buf[MAX_STRING_LENGTH];
  78.  
  79.     half_chop(argument,name,message);
  80.  
  81.     if(!*name || !*message)
  82.         send_to_char("Who do you wish to tell what??\n\r", ch);
  83.     else if (!(vict = get_char_vis(ch, name)))
  84.         send_to_char("No-one by that name here..\n\r", ch);
  85.     else if (ch == vict)
  86.         send_to_char("You try to tell yourself something.\n\r", ch);
  87.     else if (GET_POS(vict) == POSITION_SLEEPING)
  88.     {
  89.         act("$E can't hear you.",FALSE,ch,0,vict,TO_CHAR);
  90.     }
  91.     else
  92.     {
  93.         sprintf(buf,"%s tells you '%s'\n\r",
  94.           (IS_NPC(ch) ? ch->player.short_descr : GET_NAME(ch)), message);
  95.         send_to_char(buf, vict);
  96.         send_to_char("Ok.\n\r", ch);
  97.     }
  98. }
  99.  
  100.  
  101.  
  102. void do_whisper(struct char_data *ch, char *argument, int cmd)
  103. {
  104.     struct char_data *vict;
  105.     char name[100], message[MAX_STRING_LENGTH],
  106.         buf[MAX_STRING_LENGTH];
  107.  
  108.     half_chop(argument,name,message);
  109.  
  110.     if(!*name || !*message)
  111.         send_to_char("Who do you want to whisper to.. and what??\n\r", ch);
  112.     else if (!(vict = get_char_room_vis(ch, name)))
  113.         send_to_char("No-one by that name here..\n\r", ch);
  114.     else if (vict == ch)
  115.     {
  116.         act("$n whispers quietly to $mself.",FALSE,ch,0,0,TO_ROOM);
  117.         send_to_char(
  118.             "You can't seem to get your mouth close enough to your ear...\n\r",
  119.              ch);
  120.     }
  121.     else
  122.     {
  123.         sprintf(buf,"$n whispers to you, '%s'",message);
  124.         act(buf, FALSE, ch, 0, vict, TO_VICT);
  125.         send_to_char("Ok.\n\r", ch);
  126.         act("$n whispers something to $N.", FALSE, ch, 0, vict, TO_NOTVICT);
  127.     }
  128. }
  129.  
  130.  
  131. void do_ask(struct char_data *ch, char *argument, int cmd)
  132. {
  133.     struct char_data *vict;
  134.     char name[100], message[MAX_STRING_LENGTH],
  135.         buf[MAX_STRING_LENGTH];
  136.  
  137.     half_chop(argument,name,message);
  138.  
  139.     if(!*name || !*message)
  140.         send_to_char("Who do you want to ask something.. and what??\n\r", ch);
  141.     else if (!(vict = get_char_room_vis(ch, name)))
  142.         send_to_char("No-one by that name here..\n\r", ch);
  143.     else if (vict == ch)
  144.     {
  145.         act("$n quietly asks $mself a question.",FALSE,ch,0,0,TO_ROOM);
  146.         send_to_char("You think about it for a while...\n\r", ch);
  147.     }
  148.     else
  149.     {
  150.         sprintf(buf,"$n asks you '%s'",message);
  151.         act(buf, FALSE, ch, 0, vict, TO_VICT);
  152.         send_to_char("Ok.\n\r", ch);
  153.         act("$n asks $N a question.",FALSE,ch,0,vict,TO_NOTVICT);
  154.     }
  155. }
  156.  
  157.  
  158.  
  159. #define MAX_NOTE_LENGTH 1000      /* arbitrary */
  160.  
  161. void do_write(struct char_data *ch, char *argument, int cmd)
  162. {
  163.     struct obj_data *paper = 0, *pen = 0;
  164.     char papername[MAX_INPUT_LENGTH], penname[MAX_INPUT_LENGTH],
  165.         buf[MAX_STRING_LENGTH];
  166.  
  167.     argument_interpreter(argument, papername, penname);
  168.  
  169.     if (!ch->desc)
  170.         return;
  171.  
  172.     if (!*papername)  /* nothing was delivered */
  173.     {   
  174.         send_to_char(
  175.             "Write? with what? ON what? what are you trying to do??\n\r", ch);
  176.         return;
  177.     }
  178.     if (*penname) /* there were two arguments */
  179.     {
  180.         if (!(paper = get_obj_in_list_vis(ch, papername, ch->carrying)))
  181.         {
  182.             sprintf(buf, "You have no %s.\n\r", papername);
  183.             send_to_char(buf, ch);
  184.             return;
  185.         }
  186.         if (!(pen = get_obj_in_list_vis(ch, penname, ch->carrying)))
  187.         {
  188.             sprintf(buf, "You have no %s.\n\r", papername);
  189.             send_to_char(buf, ch);
  190.             return;
  191.         }
  192.     }
  193.     else  /* there was one arg.let's see what we can find */
  194.     {            
  195.         if (!(paper = get_obj_in_list_vis(ch, papername, ch->carrying)))
  196.         {
  197.             sprintf(buf, "There is no %s in your inventory.\n\r", papername);
  198.             send_to_char(buf, ch);
  199.             return;
  200.         }
  201.         if (paper->obj_flags.type_flag == ITEM_PEN)  /* oops, a pen.. */
  202.         {
  203.             pen = paper;
  204.             paper = 0;
  205.         }
  206.         else if (paper->obj_flags.type_flag != ITEM_NOTE)
  207.         {
  208.             send_to_char("That thing has nothing to do with writing.\n\r", ch);
  209.             return;
  210.         }
  211.  
  212.         /* one object was found. Now for the other one. */
  213.         if (!ch->equipment[HOLD])
  214.         {
  215.             sprintf(buf, "You can't write with a %s alone.\n\r", papername);
  216.             send_to_char(buf, ch);
  217.             return;
  218.         }
  219.         if (!CAN_SEE_OBJ(ch, ch->equipment[HOLD]))
  220.         {
  221.             send_to_char("The stuff in your hand is invisible! Yeech!!\n\r", ch);
  222.             return;
  223.         }
  224.         
  225.         if (pen)
  226.             paper = ch->equipment[HOLD];
  227.         else
  228.             pen = ch->equipment[HOLD];
  229.     }
  230.             
  231.     /* ok.. now let's see what kind of stuff we've found */
  232.     if (pen->obj_flags.type_flag != ITEM_PEN)
  233.     {
  234.         act("$p is no good for writing with.",FALSE,ch,pen,0,TO_CHAR);
  235.     }
  236.     else if (paper->obj_flags.type_flag != ITEM_NOTE)
  237.     {
  238.         act("You can't write on $p.", FALSE, ch, paper, 0, TO_CHAR);
  239.     }
  240.     else if (paper->action_description)
  241.         send_to_char("There's something written on it already.\n\r", ch);
  242.     else
  243.     {
  244.         /* we can write - hooray! */
  245.                 
  246.         send_to_char("Ok.. go ahead and write.. end the note with a @.\n\r",
  247.             ch);
  248.         act("$n begins to jot down a note.", TRUE, ch, 0,0,TO_ROOM);
  249.         ch->desc->str = &paper->action_description;
  250.         ch->desc->max_str = MAX_NOTE_LENGTH;
  251.     }
  252. }
  253.