[mw-devel] MW3 r945 - trunk/src

arthur at sucs.org arthur at sucs.org
Thu Apr 12 11:10:53 BST 2007


Author: arthur
Date: 2007-04-12 11:10:51 +0100 (Thu, 12 Apr 2007)
New Revision: 945

Modified:
   trunk/src/gags.c
   trunk/src/gags.h
   trunk/src/talker_privs.c
Log:
Mars Attacks! gag written by flagg


Modified: trunk/src/gags.c
===================================================================
--- trunk/src/gags.c	2007-03-29 19:39:49 UTC (rev 944)
+++ trunk/src/gags.c	2007-04-12 10:10:51 UTC (rev 945)
@@ -417,3 +417,117 @@
 	snprintf(text, MAXTEXTLENGTH-1, "%s", apply_bork(text, nosport, 0));
 }
 
+#define MAX_WORDS 30
+
+/* Mars Attacks! */
+void gag_ack(char *text)
+{
+    if(strlen(text))
+    {
+        char *words[MAX_WORDS];
+        memset(words, 0, MAX_WORDS * sizeof(char *));
+
+        /* Tokenise string. */
+        {
+            char *p = text;
+            char *tok = NULL;
+            int i = 0;
+
+            do
+            {
+                tok = strsep(&p, " \t");
+            
+                if(p && *p)
+                {
+                    words[i] = tok;
+                    i++;
+                }
+            } while((i < MAX_WORDS) && (tok));
+        }
+        
+        /* Convert to martian. */
+        {
+            char tmp_text[MAXTEXTLENGTH];
+            int i = 0;
+            tmp_text[0] = 0;
+            int first = 1;
+
+            while((i < MAX_WORDS) && words[i])
+            {
+                char tmp_buf[MAXTEXTLENGTH]; /*No good reason to be this big.*/
+                
+                if((*words[i]))
+                { 
+                    int word_len;
+                    int punctuation;
+                    int shouting;
+    
+                    punctuation = shouting = 0;                
+    
+                    word_len = strlen(words[i]);
+                    word_len = (word_len / 4) + 1; /* cheap syllable count */
+    
+                    if(word_len > (MAXTEXTLENGTH / 6))
+                    {
+                        word_len = MAXTEXTLENGTH / 6;
+                    }
+    
+                    if(strrchr(words[i], '.') || 
+                       strrchr(words[i], ',') ||
+                       strrchr(words[i], '!'))
+                    {
+                        punctuation = 1;
+                        word_len++;
+                    }
+    
+                    if(strrchr(words[i], '!') ||
+                       (!first && isupper(*(words[i]))))
+                    { 
+                        shouting = 1;
+                    }
+    
+                    tmp_buf[0] = 0;
+    
+                    while(word_len)
+                    {
+                        if(shouting)
+                        {
+                            strcat(tmp_buf, "ACK!");
+                        }
+                        else
+                        {
+                            if(first)
+                            {
+                                strcat(tmp_buf, "Ack");
+                                first = 0;
+                            }
+                            else
+                            {
+                                strcat(tmp_buf, "ack");
+                            }
+                        }
+                        word_len--;
+                    }
+                    strcat(tmp_buf, "! ");
+    
+                    if(punctuation)
+                    {
+                        first = 1;
+                    }
+    
+                    /* Crap range check.  Rewrite! */
+                    if((strlen(tmp_text) + strlen(tmp_buf)) >= MAXTEXTLENGTH)
+                    {
+                        break;
+                    }
+                    else
+                    { 
+                        strcat(tmp_text, tmp_buf);
+                    }
+                }
+                i++;
+            }
+            strcpy(text, tmp_text);
+        }
+    }
+}

Modified: trunk/src/gags.h
===================================================================
--- trunk/src/gags.h	2007-03-29 19:39:49 UTC (rev 944)
+++ trunk/src/gags.h	2007-04-12 10:10:51 UTC (rev 945)
@@ -21,6 +21,7 @@
 void gag_french(char *text);
 void gag_babel(char *text);
 void gag_nosport(char *text);
+void gag_ack(char *text);
 
 /* maximum gag flag used */
 #define MAX_GAG_FLAG	6

Modified: trunk/src/talker_privs.c
===================================================================
--- trunk/src/talker_privs.c	2007-03-29 19:39:49 UTC (rev 944)
+++ trunk/src/talker_privs.c	2007-04-12 10:10:51 UTC (rev 945)
@@ -105,6 +105,10 @@
    "Be a good sport, sport, and dont mention sport okay?",
    "You have been granted the power to mention sport again",
    gag_nosport},
+{"martian","Martian","De-Martian",
+   "You have been zapped by a ray-gun and turned into a martian",
+   "You are human again",
+   gag_ack},
 
 {NULL, NULL, NULL, NULL, NULL, NULL},
 };





More information about the mw-devel mailing list