/* ************************************************ * file: speech.cc * * purpose: performs "intelligent" responses * * (c) 1997-1999 Andrew Hynek and Christopher * * J. Dickey, (c) 2001 The AwakeMUD Consortium * ************************************************ */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include "structs.h" #include "awake.h" #include "utils.h" #include "db.h" #include "comm.h" extern void perform_tell(struct char_data *, struct char_data *, char *); char *keywords[] = { "fuck you", "fuck off", "frag off", "mutherfucker", "fucker", // insults-1 "you fucking ", "you stupid fuck", "you dumb fuck", "you mutherfucking ", "fucker", "bitch", "bastard", "screw you", "piece of shit", // insults-2 "you gay homosexual", "you flaming homosexual", // insults-10 "fuck me", "have sex with me", "let's fuck", "let's have sex", // sex-1 "want to have sex", "want to fuck", "wanna fuck", "wanna have sex", // sex-2 "i want a shadowrun", "i want a run", "i want a job", "shadowrun", // sr-related "help me", "can you help me", "help!", // help "hello", "hey", "hi ", "hi!", "hoi", "hiya", // greetings "thanks", "thank you", // thanks "who are you", "where are you going", "where are you", // gm questions "who am i", "where am i", // idiot questions "where is ", "where are ", // location questions "what do i do", "what am i supposed to do", //help questions-1 "where do i go", "where am i supposed to go", // help questions-2 "can you ", "can i ", "you are ", "you're ", "i don't ", // general stuff "i feel ", "why don't you ", "why can't i ", "are you ", "i can't ", "i am ", "i'm ", "your ", "i want ", "what ", "how ", "who ", "when ", "why ", "name", "cause ", "sorry ", "maybe ", "no ", "not ", "nothing ", "you ", "always ", "think ", "alike ", "yes ", "friend ", "!found" // found nothing }; char *from_char[] = { " are ", " were ", " your ", " i've ", " i'm ", " me ", " am ", " was ", " i ", " my ", " you've ", " you're ", " you " }; char *to_char[] = { " am ", " was ", " my ", " you've ", " you're ", " you ", " are ", " were ", " you ", " your ", " I've ", " I'm ", " me " }; char *replies[] = { "That's it, pal!!", // 0 - insults-1 "Frag off!", "Once more, and count yourself dead!", "Don't anger me, chummer!", "Grrrr.....", "That's the best you can do?!", // 5 "No fucking way!", "I don't know anything, I swear!", "Just type \"help <topic>\".", "Hoi.", "Sure thing.", // 10 - thanks "Null sweat, chummer.", "Why are you so curious?", "You should know that!", "Why are you asking about*?", "You're asking the wrong person.", // 15 "I dunno.", "You doubt that I can*?", // can you ...? "You think I should*?", "I might be able to*...", "Do you want to*?", // 20 - can I ...? "I dunno -- can you*?", "Who told you I am*?!", // you are ...? "What does it matter to you?", "Why? You jealous or something?", "...", // 25 "Neither do I.", // I don't ... "Why don't you*?", "What does it matter?", "Does it trouble you to not*?", "Why do you feel*?", // 30 - I feel "That's a shame.", "Really? You can feel?!", "Do you really believe I don't*?", // why don't you ...? "Perhaps in good time I will*.", "I dunno.", // 35 "Why are you asking me?!", // why can't I ...? "...", "Mind your own business, chum.", // are you ...? "Am I?", "For enough nuyen, chummer, I'll be*.", // 40 "How do you know you can't*?", // I can't ... "Have you tried?", "That sucks.", "Do you think I care that you are*?", // I am, I'm "How long have you been*?", // 45 "I guess so.", "Yes, you are.", "Why are you concerned about my*?", // your "Don't be so inquisitive.", "No one gets what they want anymore.", // 50 - I want "I want you to shut up.", "Why do you want*?", "And...?", "If you want*, then get it.", "Why do you ask?", // 55 - how, who, where, when, why "I could tell you, but I don't want to.", "...", "Don't ask me.", "What do you think?", "Ask someone else.", // 60 "Why do you care?", "You always ask so many damn questions?", "You tell me.", "Names don't interest me.", // name "...", // 65 "I doubt that.", // cause "Don't any other reasons come to mind?", "Does that reason explain anything else?", "What other reasons might there be?", "As well you should be.", // 70 - sorry "Are you just saying that?", "Null sweat.", "Don't be so defensive!", "And maybe I'll just kill you...", // maybe "...", // 75 "What're the chances?", "You aren't sure?", "Don't you know?", "Are you saying that just to be negative?", // no, not nothing "No?", // 80 "Why not?", "Do I care?", "...", "No, you are*.", // you "Oh, I*.", // 85 "What about me?", "Always?", // always "I suppose...", "What are you thinking of?", "Really; always?", // 90 "What? You think?!", // think "Aren't you sure?", "Do you doubt*?", "In what way?", // alike "What resemblance do you see?", // 95 "How so?", "Maybe.", "It's possible.", "How?", "", // 100 - yes "...", "I understand.", "You seem positive.", "", // friend "", // 105 "Why'd you bring that up?", "Are you sure you have any friends?", "You can be annoying.", "Really?", "...", // 110 - !found "I'm not sure I understand you fully.", "That is quite interesting.", "Indeed." }; int num_of_responses[] = { 4,-1,-1,-1,-1, // insults-1 1,-1,-1,-1,-1,-1,-1,-1,-1, // insults-2 1,-1, // insults-10 1,-1,-1,-1,-1,-1,-1,-1, // sex 1,-1,-1,-1, // sr-related 1,-1,-1, // help 1,-1,-1,-1,-1,-1, // greetings 2,-1, /* THANK */ 1,-1,-1, // general questions 1,-1, // idiot questions 1,-1, // location questions 1,-1, // help questions-1 1,-1, // help questions-2 3, /* CAN YOU */ 2, /* CAN I */ 4,-1, /* YOU ARE, YOU'RE */ 4, /* I DON'T */ 3, /* I FEEL */ 3, /* WHY DON'T YOU */ 2, /* WHY CAN'T I */ 3, /* ARE YOU */ 3, /* I CAN'T */ 4,-1, /* I AM, I'M */ 2, /* YOUR */ 5, /* I WANT */ 9,-1,-1,-1,-1, /* WHAT, HOW, WHO, WHEN, WHY */ 2, /* NAME */ 4, /* CAUSE */ 4, /* SORRY */ 5, /* MAYBE */ 5,-1,-1, /* NO, NOT, NOTHING */ 3, /* YOU */ 4, /* ALWAYS */ 3, /* THINK */ 6, /* ALIKE */ 4, /* YES */ 6, /* FRIEND */ 4 /* NOKEYFOUND */ }; int n1, n2, key, speech_state = 1; void init_speech(void) { int one, two; one = sizeof(num_of_responses) / sizeof(int); n1 = sizeof(keywords) / sizeof(char *); n2 = sizeof(from_char) / sizeof(char *); two = sizeof(to_char) / sizeof(char *); if (n1 != one) { sprintf(buf, "The sizes of \"keyword\" (%d) and \"num_of_responses\" (%d) do not match!", n1, one); log(buf); speech_state = 0; } else if (n2 != two) { sprintf(buf, "The sizes of \"from_char\" (%d) and \"to_char\" (%d) do not match!", n2, two); log(buf); speech_state = 0; } if (!speech_state) log("Mob speech disabled."); } void exchange_words(char *string, int word_start, int word_len, char *new_word) { char temp_storage[MAX_INPUT_LENGTH]; strncpy(temp_storage, string, word_start); temp_storage[word_start] = '\0'; strcat(temp_storage, new_word); strcat(temp_storage, string+word_start+word_len); strcpy(string, temp_storage); } void reformat(char *str) { int i, j; for (i = 0; *(str+i); i++) *(str+i) = LOWER(*(str+i)); for (i = strlen(str)-1; *(str+i) && isspace(*(str+i)); i--); *(str+i+1) = '\0'; for (i = 0; *(str+i); i++) while (!isalnum(*(str+i)) && *(str+i) != '\'' && !isspace(*(str+i)) && *(str+i)) for (j = i; *(str+j); j++) *(str+j) = *(str+j+1); for (i = 0; *(str+i); i++) while (isspace(*(str+i)) && *(str+i+1) && isspace(*(str+i+1))) for (j = i+1; *(str+j); j++) *(str+j) = *(str+j+1); } char *find_keyword(char *str) { static char found[MAX_INPUT_LENGTH]; found[0] = '\0'; for (key = 0; key < n1; key++) if (strstr(str, keywords[key])) { strcpy (found, keywords[key]); break; } if (key >= n1) key = n1 - 1; return found; } char *conjugate(char *str, char *found) { static char tail[MAX_INPUT_LENGTH]; char *tail_ptr; char string_pos; int word; tail_ptr = strstr(str, found) + strlen(found); sprintf(tail, " %s ", tail_ptr); for (string_pos = 0; (u_char)string_pos < strlen(tail); string_pos++) for (word = 0; word < n2; word++) { tail_ptr = tail + string_pos; if (!strncmp(from_char[word], tail_ptr, strlen(from_char[word]))) { exchange_words(tail, string_pos, strlen(from_char[word]), to_char[word]); string_pos = string_pos + strlen(to_char[word]) - 2; break; } } return tail; } void response(struct char_data *ch, struct char_data *mob, char *tail) { char output[MAX_INPUT_LENGTH], *rep; int low = 0, high, i; for (high = key; num_of_responses[high] < 1; high--); for (i = 0; i < high; i++) if (num_of_responses[i] != -1) low += num_of_responses[i]; high = num_of_responses[high] - 1; strcpy(output, replies[number(low, low + high)]); if (!(rep = strchr(output, '*'))) { perform_tell(mob, ch, output); return; } if (!strcmp(tail, " ")) { perform_tell(mob, ch, "Could you elaborate on that?"); return; } for (i = strlen(tail)-1; *(tail+i) && isspace(*(tail+i)); i--); *(tail+i+1) = '\0'; strcat(tail, rep+1); *rep = '\0'; strcat(output, tail); perform_tell(mob, ch, output); } void respond(struct char_data *ch, struct char_data *mob, char *str) { if (!ch->desc || !speech_state) return; reformat(str); if (!strcmp(str, ch->desc->last_tell)) { perform_tell(mob, ch, "You always so repetitive?"); return; } strcpy(ch->desc->last_tell, str); response(ch, mob, conjugate(str, find_keyword(str))); }