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.social.c < prev    next >
C/C++ Source or Header  |  1991-03-01  |  8KB  |  349 lines

  1. /* ************************************************************************
  2. *  file: act.social.c , Implementation of commands.       Part of DIKUMUD *
  3. *  Usage : Social commands.                                               *
  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. extern struct room_data *world;
  23.  
  24. /* extern functions */
  25.  
  26. void parse_string(char *input, char *output, struct char_data *ch1,
  27.     struct char_data *ch2, struct char_data *to);
  28. int action(int cmd);
  29. char *fread_action(FILE *fl);
  30.  
  31.  
  32. struct social_messg
  33. {
  34.     int act_nr;
  35.     int hide;
  36.     int min_victim_position; /* Position of victim */
  37.  
  38.     /* No argument was supplied */
  39.     char *char_no_arg;
  40.     char *others_no_arg;
  41.  
  42.     /* An argument was there, and a victim was found */
  43.     char *char_found;        /* if NULL, read no further, ignore args */
  44.     char *others_found;
  45.     char *vict_found;
  46.  
  47.     /* An argument was there, but no victim was found */
  48.     char *not_found;
  49.  
  50.     /* The victim turned out to be the character */
  51.     char *char_auto;
  52.     char *others_auto;
  53. } *soc_mess_list = 0;
  54.  
  55.  
  56.  
  57. struct pose_type
  58. {
  59.     int level;          /* minimum level for poser */
  60.     char *poser_msg[4];  /* message to poser        */
  61.     char *room_msg[4];   /* message to room         */
  62. } pose_messages[MAX_MESSAGES];
  63.  
  64. static int list_top = -1;
  65.  
  66.  
  67.  
  68.  
  69. char *fread_action(FILE *fl)
  70. {
  71.     char buf[MAX_STRING_LENGTH], *rslt;
  72.  
  73.     for (;;)
  74.     {
  75.         fgets(buf, MAX_STRING_LENGTH, fl);
  76.         if (feof(fl))
  77.         {
  78.             log("Fread_action - unexpected EOF.");
  79.             exit(0);
  80.         }
  81.  
  82.         if (*buf == '#')
  83.             return(0);
  84.         {
  85.             *(buf + strlen(buf) - 1) = '\0';
  86.             CREATE(rslt, char, strlen(buf) + 1);
  87.             strcpy(rslt, buf);
  88.             return(rslt);
  89.         }
  90.     }
  91. }
  92.     
  93.  
  94.  
  95.  
  96. void boot_social_messages(void)
  97. {
  98.     FILE *fl;
  99.     int tmp, hide, min_pos;
  100.  
  101.     if (!(fl = fopen(SOCMESS_FILE, "r")))
  102.     {
  103.         perror("boot_social_messages");
  104.         exit(0);
  105.     }
  106.  
  107.     for (;;)
  108.     {
  109.         fscanf(fl, " %d ", &tmp);
  110.         if (tmp < 0)
  111.             break;
  112.         fscanf(fl, " %d ", &hide);
  113.         fscanf(fl, " %d \n", &min_pos);
  114.  
  115.         /* alloc a new cell */
  116.         if (!soc_mess_list)
  117.         {
  118.             CREATE(soc_mess_list, struct social_messg, 1);
  119.             list_top = 0;
  120.         }
  121.         else
  122.             if (!(soc_mess_list = (struct social_messg *)
  123.                 realloc(soc_mess_list, sizeof (struct social_messg) *
  124.                 (++list_top + 1))))
  125.             {
  126.                 perror("boot_social_messages. realloc");
  127.                 exit(1);
  128.             }
  129.  
  130.         /* read the stuff */
  131.         soc_mess_list[list_top].act_nr = tmp;
  132.         soc_mess_list[list_top].hide = hide;
  133.         soc_mess_list[list_top].min_victim_position = min_pos;
  134.  
  135.         soc_mess_list[list_top].char_no_arg = fread_action(fl);
  136.         soc_mess_list[list_top].others_no_arg = fread_action(fl);
  137.  
  138.         soc_mess_list[list_top].char_found = fread_action(fl);
  139.  
  140.         /* if no char_found, the rest is to be ignored */
  141.         if (!soc_mess_list[list_top].char_found)
  142.             continue;
  143.  
  144.         soc_mess_list[list_top].others_found = fread_action(fl);    
  145.         soc_mess_list[list_top].vict_found = fread_action(fl);
  146.  
  147.         soc_mess_list[list_top].not_found = fread_action(fl);
  148.  
  149.         soc_mess_list[list_top].char_auto = fread_action(fl);
  150.  
  151.         soc_mess_list[list_top].others_auto = fread_action(fl);
  152.     }
  153.     fclose(fl);
  154. }
  155.  
  156.  
  157.  
  158.  
  159. int find_action(int cmd)
  160. {
  161.     int bot, top, mid;
  162.  
  163.     bot = 0;
  164.     top = list_top;
  165.  
  166.     if (top < 0)
  167.         return(-1);
  168.  
  169.     for(;;)
  170.     {
  171.         mid = (bot + top) / 2;
  172.  
  173.         if (soc_mess_list[mid].act_nr == cmd)
  174.             return(mid);
  175.         if (bot == top)
  176.             return(-1);
  177.  
  178.         if (soc_mess_list[mid].act_nr > cmd)
  179.             top = --mid;
  180.         else
  181.             bot = ++mid;
  182.     }
  183. }
  184.  
  185.  
  186.  
  187.  
  188.  
  189. void do_action(struct char_data *ch, char *argument, int cmd)
  190. {
  191.     int act_nr;
  192.     char buf[MAX_INPUT_LENGTH], tmp[MAX_STRING_LENGTH];
  193.     struct social_messg *action;
  194.     struct char_data *i, *vict;
  195.  
  196.     if ((act_nr = find_action(cmd)) < 0)
  197.     {
  198.         send_to_char("That action is not supported.\n\r", ch);
  199.         return;
  200.     }
  201.  
  202.     action = &soc_mess_list[act_nr];
  203.  
  204.     if (action->char_found)
  205.         one_argument(argument, buf);
  206.     else
  207.         *buf = '\0';
  208.  
  209.     if (!*buf)
  210.     {
  211.         send_to_char(action->char_no_arg, ch);
  212.         send_to_char("\n\r", ch);
  213.         act(action->others_no_arg, action->hide, ch, 0, 0, TO_ROOM);
  214.         return;
  215.     }
  216.  
  217.     if (!(vict = get_char_room_vis(ch, buf)))
  218.     {
  219.         send_to_char(action->not_found, ch);
  220.         send_to_char("\n\r", ch);
  221.     }
  222.     else if (vict == ch)
  223.     {
  224.         send_to_char(action->char_auto, ch);
  225.         send_to_char("\n\r", ch);
  226.         act(action->others_auto, action->hide, ch, 0, 0, TO_ROOM);
  227.     }
  228.     else
  229.     {
  230.         if (GET_POS(vict) < action->min_victim_position) {
  231.             act("$N is not in a proper position for that.",FALSE,ch,0,vict,TO_CHAR);
  232.         } else {
  233.             act(action->char_found, 0, ch, 0, vict, TO_CHAR);
  234.  
  235.             act(action->others_found, action->hide, ch, 0, vict, TO_NOTVICT);
  236.  
  237.             act(action->vict_found, action->hide, ch, 0, vict, TO_VICT);
  238.         }
  239.     }
  240. }
  241.  
  242.  
  243.  
  244. void do_insult(struct char_data *ch, char *argument, int cmd)
  245. {
  246.     static char buf[100];
  247.     static char arg[MAX_STRING_LENGTH];
  248.     struct char_data *victim;
  249.  
  250.     one_argument(argument, arg);
  251.  
  252.     if(*arg) {
  253.         if(!(victim = get_char_room_vis(ch, arg))) {
  254.             send_to_char("Can't hear you!\n\r", ch);
  255.         } else {
  256.             if(victim != ch) { 
  257.                 sprintf(buf, "You insult %s.\n\r",GET_NAME(victim) );
  258.                 send_to_char(buf,ch);
  259.  
  260.                 switch(random()%3) {
  261.                     case 0 : {
  262.                         if (GET_SEX(ch) == SEX_MALE) {
  263.                             if (GET_SEX(victim) == SEX_MALE)
  264.                                 act(
  265.                                 "$n accuses you of fighting like a woman!", FALSE,
  266.                                 ch, 0, victim, TO_VICT);
  267.                           else
  268.                                 act("$n says that women can't fight.",
  269.                                   FALSE, ch, 0, victim, TO_VICT);
  270.                         } else { /* Ch == Woman */
  271.                             if (GET_SEX(victim) == SEX_MALE)
  272.                                 act("$n accuses you of having the smallest.... (brain?)",
  273.                                 FALSE, ch, 0, victim, TO_VICT );
  274.                           else
  275.                                 act("$n tells you that you'd loose a beautycontest against a troll.",
  276.                                 FALSE, ch, 0, victim, TO_VICT );
  277.                         }
  278.                     } break;
  279.                     case 1 : {
  280.                         act("$n calls your mother a bitch!",
  281.                         FALSE, ch, 0, victim, TO_VICT );
  282.                     } break;
  283.                     default : {
  284.                         act("$n tells you to get lost!",FALSE,ch,0,victim,TO_VICT);
  285.                     } break;
  286.                 } /* end switch */
  287.  
  288.                 act("$n insults $N.", TRUE, ch, 0, victim, TO_NOTVICT);
  289.             } else { /* ch == victim */
  290.                 send_to_char("You feel insulted.\n\r", ch);
  291.             }
  292.         }
  293.     } else send_to_char("Sure you don't want to insult everybody.\n\r", ch);
  294. }
  295.  
  296.  
  297.  
  298. void boot_pose_messages(void)
  299. {
  300.   FILE *fl;
  301.   byte counter;
  302.   int tmp;
  303.   byte class;
  304.  
  305.   if (!(fl = fopen(POSEMESS_FILE, "r")))
  306.   {
  307.     perror("boot_pose_messages");
  308.     exit(0);
  309.   }
  310.  
  311.   for (counter = 0;;counter++)
  312.   {
  313.     fscanf(fl, " %d ", &pose_messages[counter].level);
  314.     if (pose_messages[counter].level < 0)
  315.       break;
  316.         for (class = 0;class < 4;class++)
  317.         {
  318.             pose_messages[counter].poser_msg[class] = fread_action(fl);
  319.             pose_messages[counter].room_msg[class] = fread_action(fl);
  320.         }
  321.     }
  322.   
  323.     fclose(fl);
  324. }
  325.  
  326. do_pose(struct char_data *ch, char *argument, int cmd)
  327. {
  328.     byte to_pose;
  329.     byte counter;
  330.  
  331.     send_to_char("Sorry Buggy command.\n\r", ch);
  332.     return;
  333.  
  334.     if ((GET_LEVEL(ch) < pose_messages[0].level) || IS_NPC(ch))
  335.     {
  336.         send_to_char("You can't do that.\n\r", ch);
  337.         return;
  338.     }
  339.  
  340.     for (counter = 0; (pose_messages[counter].level < GET_LEVEL(ch)) && 
  341.                     (pose_messages[counter].level > 0); counter++);
  342.     counter--;
  343.   
  344.     to_pose = number(0, counter);
  345.     
  346.     act(pose_messages[to_pose].poser_msg[GET_CLASS(ch)-1], 0, ch, 0, 0, TO_CHAR);
  347.     act(pose_messages[to_pose].room_msg[GET_CLASS(ch)-1], 0, ch, 0, 0, TO_ROOM);
  348. }
  349.