Browse Source

Bugz has you. Ok, updated phrases.

We now look at cursor x pos + length.
We also increase the delay for longer
strings (to 5 seconds).
bugz 4 years ago
parent
commit
b66edae94c
1 changed files with 47 additions and 14 deletions
  1. 47 14
      wordplay.cpp

+ 47 - 14
wordplay.cpp

@@ -6,6 +6,7 @@
 #include "terminal.h"
 #include "utils.h"
 #include "zf_log.h"
+#include <ctype.h>
 #include <iomanip>
 #include <regex>
 #include <sstream>
@@ -20,6 +21,16 @@ extern std::string fullname;
 
 #define BSIZE 512
 
+void a_or_an(std::string &word) {
+  /* If it starts with a vowel "an" */
+  char ch = toupper(word[0]);
+  if ((ch == 'A') || (ch == 'E') || (ch == 'I') || (ch == 'O') || (ch == 'U')) {
+    word.insert(0, " an ");
+  } else {
+    word.insert(0, " a ");
+  }
+}
+
 /*
  * harry_idle_event(fd)
  *
@@ -36,18 +47,28 @@ void harry_idle_event(int fd) {
 
   // If the username is something, we have their info!
   bool have_userinfo = !username.empty();
+  int xpos = console.posx;
 
   // This is no where near finished, BUT!
   // Do not put any ^ codes in these -- the strlen() would be wrong.
   const char *phrases[] = {
-      "Hahaha",  "Snicker, snicker", "Boo!",           "Arrooo!", "Ahh-wooo!",
-      "Aaaooo!", "Sorry, I forgot!", "Knock-Knock...",
+      "Hahaha",
+      "Snicker, snicker",
+      "Boo!",
+      "Arrooo!",
+      "Ahh-wooo!",
+      "Aaaooo!",
+      "Sorry, I forgot!",
+      "The Matrix has you...",
+      "Follow the white rabbit.",
   };
   const int total_phrases = sizeof(phrases) / sizeof(char *);
 
   const char *user_phrases[] = {
       "Is USER really here?",
+      "Knock, Knock NICK.",
       "What is a NICK?",
+      "Wake up, NICK...",
       "Here lies USER, rest in peace.",
       "Don't be scared, NICK.",
   };
@@ -68,25 +89,37 @@ void harry_idle_event(int fd) {
   std::string selected;
   if (r >= total_phrases) {
     selected = user_phrases[r - total_phrases];
+    std::string temp = username;
+    a_or_an(temp);
+    replace(selected, " a NICK", temp);
     replace(selected, "USER", fullname);
     replace(selected, "NICK", username);
   } else
     selected = phrases[r];
 
   ZF_LOGD("Selected: %s", selected.c_str());
+  if (selected.size() + xpos > 78) {
+    ZF_LOGD("Sorry, too long (%d)", (int)selected.size() + xpos);
+  } else {
+    int color = randint(15) + 1;
+    int pause = 2;
+    if (selected.size() > 20) {
+      pause = 5;
+    }
 
-  int color = randint(15) + 1;
-  // %02d = std::setfill('0') << std::setw(2) << (int)
-  /*
-  buffer << "^CS^S2^C" << std::setfill('0') << std::setw(2) << color
-         << phrases[r] << "^P2^CR^D" << std::setw(2) << strlen(phrases[r]);
-  */
-  buffer << "^CS^S2^C" << std::setfill('0') << std::setw(2) << color << selected
-         << "^P2^CR^D" << std::setw(2) << selected.size();
-
-  std::string str = buffer.str();
-  ZF_LOGD("harry_event: render(%d, \"%s\")", fd, str.c_str());
-  render(fd, str);
+    // %02d = std::setfill('0') << std::setw(2) << (int)
+    /*
+    buffer << "^CS^S2^C" << std::setfill('0') << std::setw(2) << color
+           << phrases[r] << "^P2^CR^D" << std::setw(2) << strlen(phrases[r]);
+    */
+    buffer << "^CS^S2^C" << std::setfill('0') << std::setw(2) << color
+           << selected << "^P" << pause << "^CR^D" << std::setw(2)
+           << selected.size();
+
+    std::string str = buffer.str();
+    ZF_LOGD("harry_event: render(%d, \"%s\")", fd, str.c_str());
+    render(fd, str);
+  }
 }
 
 void init_harry() {