home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / tinymud2.zip / SPEECH.C < prev    next >
C/C++ Source or Header  |  1990-09-02  |  5KB  |  215 lines

  1. #include "copyright.h"
  2.  
  3. /* Commands which involve speaking */
  4.  
  5. #include "db.h"
  6. #include "interface.h"
  7. #include "match.h"
  8. #include "config.h"
  9. #include "externs.h"
  10.  
  11. /* this function is a kludge for regenerating messages split by '=' */
  12. const char *reconstruct_message(const char *arg1, const char *arg2)
  13. {
  14.     static char buf[BUFFER_LEN];
  15.  
  16.     if(arg2 && *arg2) {
  17.     strcpy(buf, arg1);
  18.     strcat(buf, " = ");
  19.     strcat(buf, arg2);
  20.     return buf;
  21.     } else {
  22.     return arg1;
  23.     }
  24. }
  25.  
  26. void do_say(dbref player, const char *arg1, const char *arg2)
  27. {
  28.     dbref loc;
  29.     const char *message;
  30.     char buf[BUFFER_LEN];
  31.  
  32.     if((loc = getloc(player)) == NOTHING) return;
  33.  
  34.     message = reconstruct_message(arg1, arg2);
  35.  
  36.     /* notify everybody */
  37.     sprintf(buf, "You say \"%s\"", message);
  38.     notify(player, buf);
  39.     sprintf(buf, "%s says \"%s\"", db[player].name, message);
  40.     notify_except(db[loc].contents, player, buf);
  41. }
  42.  
  43. void do_whisper(dbref player, const char *arg1, const char *arg2)
  44. {
  45. #ifndef QUIET_WHISPER
  46.     dbref loc;
  47. #endif QUIET_WHISPER
  48.     dbref who;
  49.     char buf[BUFFER_LEN];
  50.     char *det;
  51.     int result;
  52.  
  53.     init_match(player, arg1, TYPE_PLAYER);
  54.     match_neighbor();
  55.     match_me();
  56.     if(Wizard(player)) {
  57.     match_absolute();
  58.     match_player();
  59.     }
  60.     switch(who = match_result()) {
  61.       case NOTHING:
  62.     notify(player, "Whisper to whom?");
  63.     break;
  64.       case AMBIGUOUS:
  65.     notify(player, "I don't know who you mean!");
  66.     break;
  67.       default:
  68.         if (Typeof(who) == TYPE_PLAYER) {
  69.         sprintf(buf, "%s whispers \"%s\"", db[player].name, arg2);
  70.         if (notify(who, buf)) {
  71.         sprintf(buf, "You whisper \"%s\" to %s.", arg2, db[who].name);
  72.             notify(player, buf);
  73. #ifndef QUIET_WHISPER
  74.         sprintf(buf, "%s whispers something to %s.",
  75.             db[player].name, db[who].name);
  76.         if((loc = getloc(player)) != NOTHING) {
  77.             notify_except2(db[loc].contents, player, who, buf);
  78.         }
  79. #endif /* QUIET_WHISPER */
  80.         }
  81.         else
  82.         notify(player, "That person is not connected.");
  83.     } else {
  84.         if (string_prefix (db[who].name, "a ") ||
  85.             string_prefix (db[who].name, "an ") ||
  86.             string_prefix (db[who].name, "the ") ||
  87.             string_prefix (db[who].name, "some ")) {
  88.         det = "";
  89.         } else if (lookup_player (db[who].name) != NOTHING) {
  90.                det = "the thing called ";
  91.             } else {
  92.         det = "the ";
  93.         }
  94.         sprintf(buf, "You feel silly about whispering to %s%s.",
  95.             det, db[who].name);
  96.         notify(player, buf);
  97.     }
  98.     break;
  99.     }
  100. }
  101.  
  102. void do_pose(dbref player, const char *arg1, const char *arg2)
  103. {
  104.     dbref loc;
  105.     const char *message;
  106.     char buf[BUFFER_LEN];
  107.  
  108.     if((loc = getloc(player)) == NOTHING) return;
  109.  
  110.     message = reconstruct_message(arg1, arg2);
  111.  
  112.     /* notify everybody */
  113.     sprintf(buf, "%s %s", db[player].name, message);
  114.     notify_except(db[loc].contents, NOTHING, buf);
  115. }
  116.  
  117. void do_wall(dbref player, const char *arg1, const char *arg2)
  118. {
  119.     dbref i;
  120.     const char *message;
  121.     char buf[512];
  122.  
  123.     message = reconstruct_message(arg1, arg2);
  124.     if(Wizard(player)) {
  125.     writelog("WALL from %s(%d): %s\n",
  126.         db[player].name, player, message);
  127.     sprintf(buf, "%s shouts \"%s\"", db[player].name, message);
  128.     for(i = 0; i < db_top; i++) {
  129.         if(Typeof(i) == TYPE_PLAYER) {
  130.         notify(i, buf);
  131.         }
  132.     }
  133.     } else {
  134.     notify(player, "But what do you want to do with the wall?");
  135.     }
  136. }
  137.  
  138. void do_gripe(dbref player, const char *arg1, const char *arg2)
  139. {
  140.     dbref loc;
  141.     const char *message;
  142.  
  143.     loc = db[player].location;
  144.     message = reconstruct_message(arg1, arg2);
  145.     writelog("GRIPE from %s(%d) in %s(%d): %s\n",
  146.         db[player].name, player,
  147.         db[loc].name, loc,
  148.         message);
  149.     fflush(stderr);
  150.  
  151. #ifdef GOD_PRIV
  152.     /* try telling GOD about it */
  153.     if (!Flag(GOD,HAVEN)) {
  154.     char buf[BUFFER_LEN];
  155.     sprintf(buf, "%s gripes: \"%s\"",
  156.         unparse_object(GOD, player), message);
  157.     notify(GOD, buf);
  158.     }
  159. #endif GOD_PRIV    
  160.  
  161.     notify(player, "Your complaint has been duly noted.");
  162. }
  163.  
  164. /* doesn't really belong here, but I couldn't figure out where else */
  165. void do_page(dbref player, const char *arg1, const char *arg2)
  166. {
  167.     char buf[BUFFER_LEN];
  168.     dbref target;
  169.     int result;
  170.  
  171.     if(!payfor(player, PAGE_COST)) {
  172.     notify(player, "You don't have enough pennies.");
  173.     } else if((target = lookup_player(arg1)) == NOTHING) {
  174.     notify(player, "I don't recognize that name.");
  175.     } else if (db[target].flags & HAVEN) {
  176.     notify(player, "That player is not accepting pages.");
  177.     } else if (arg2 && *arg2) {
  178.     sprintf(buf, "%s pages: %s", db[player].name, arg2);
  179.     result = notify(target, buf);
  180.     if (result) 
  181.         notify(player, "Your message has been sent.");
  182.     else
  183.         notify(player, "That person is not connected.");
  184.     } else {
  185.     sprintf(buf, "You sense that %s is looking for you in %s.",
  186.         db[player].name, db[db[player].location].name);
  187.     result = notify(target, buf);
  188.     if (result)
  189.         notify(player, "Your message has been sent.");
  190.     else
  191.         notify(player, "That person is not connected.");
  192.     }
  193. }
  194.  
  195. void notify_except(dbref first, dbref exception, const char *msg)
  196. {
  197.     DOLIST (first, first) {
  198.     if ((db[first].flags & TYPE_MASK) == TYPE_PLAYER
  199.         && first != exception) {
  200.         notify (first, msg);
  201.     }
  202.     }
  203. }
  204.  
  205. void notify_except2(dbref first, dbref exc1, dbref exc2, const char *msg)
  206. {
  207.     DOLIST (first, first) {
  208.     if ((db[first].flags & TYPE_MASK) == TYPE_PLAYER
  209.         && first != exc1
  210.         && first != exc2) {
  211.         notify (first, msg);
  212.     }
  213.     }
  214. }
  215.