translated a handfull of strings and set the codeset to UTF-8 for the translations.
[xboard.git] / zippy.c
diff --git a/zippy.c b/zippy.c
index b1a7fc8..564140e 100644 (file)
--- a/zippy.c
+++ b/zippy.c
@@ -93,6 +93,9 @@ static char zippyLastOpp[MSG_SIZ];
 static int zippyConsecGames;
 static time_t zippyLastGameEnd;
 
+extern void mysrandom(unsigned int seed);
+extern int myrandom(void);
+
 void ZippyInit()
 {
     char *p;
@@ -134,7 +137,7 @@ void ZippyInit()
     if ( p != NULL ) {
       appData.zippyAcceptOnly = p;
     }
-    
+
     /* Should Zippy use "i" command? */
     /* Defaults to 1=true */
     p = getenv("ZIPPYUSEI");
@@ -197,7 +200,7 @@ void ZippyInit()
  */
 
 
-char *swifties[] = { 
+char *swifties[] = {
     "i acclaims:", "i admonishes:", "i advertises:", "i advises:",
     "i advocates:", "i affirms:", "i alleges:", "i anathematizes:",
     "i animadverts:", "i announces:", "i apostrophizes:",
@@ -227,7 +230,8 @@ char *swifties[] = {
     "i enthuses:", "i entreats:", "i enunciates:", "i eulogizes:",
     "i exclaims:", "i execrates:", "i exhorts:", "i expatiates:",
     "i explains:", "i explicates:", "i explodes:", "i exposes:",
-    "i exposits:", "i expounds:", "i expresses:", "i extols:",
+    "i exposits:", "i expostulates: ",
+    "i expounds:", "i expresses:", "i extols:",
     "i exults:", "i fantasizes:", "i fibs:", "i filibusters:",
     "i flatters:", "i flutes:", "i fools:", "i free-associates:",
     "i fulminates:", "i gabbles:", "i gabs:", "i gasps:",
@@ -238,7 +242,7 @@ char *swifties[] = {
     "i hosannas:", "i howls:", "i hums:", "i hypothecates:",
     "i hypothesizes:", "i imagines:", "i implies:", "i implores:",
     "i imprecates:", "i indicates:", "i infers:",
-    "i informs everyone:",  "i instructs:", "i interjects:", 
+    "i informs everyone:",  "i instructs:", "i interjects:",
     "i interposes:", "i intimates:", "i intones:", "i introspects:",
     "i inveighs:", "i jabbers:", "i japes:", "i jests:", "i jibes:",
     "i jives:", "i jokes:", "i joshes:", "i keens:", "i laments:",
@@ -291,7 +295,7 @@ char *swifties[] = {
 
 #define MAX_SPEECH 250
 
-void Speak(how, whom) 
+void Speak(how, whom)
      char *how, *whom;
 {
     static FILE *zipfile = NULL;
@@ -302,13 +306,14 @@ void Speak(how, whom)
     char  *p;
     int c, speechlen;
     Boolean done;
-               
+
     if (strcmp(how, "shout") == 0) {
        now = time((time_t *) NULL);
        if (now - lastShout < 1*60) return;
        lastShout = now;
        if (appData.zippyUseI) {
-           how = swifties[random() % (sizeof(swifties)/sizeof(char *))];
+           how = swifties[(unsigned) random() %
+                          (sizeof(swifties)/sizeof(char *))];
        }
     }
 
@@ -320,9 +325,9 @@ void Speak(how, whom)
        }
        fstat(fileno(zipfile), &zipstat);
     }
-               
+
     for (;;) {
-       fseek(zipfile, random() % zipstat.st_size, 0);
+       fseek(zipfile, (unsigned) random() % zipstat.st_size, 0);
        do {
          c = getc(zipfile);
        } while (c != NULLCHAR && c != '^' && c != EOF);
@@ -405,7 +410,7 @@ int ZippyControl(buf, i)
 
     /* If this is a computer, save the name.  Then later, once the */
     /* game is really started, we will send the "computer" notice to */
-    /* the engine.  */ 
+    /* the engine.  */
     if (appData.zippyPlay &&
        looking_at(buf, i, "* is in the computer list")) {
        int i;
@@ -421,7 +426,7 @@ int ZippyControl(buf, i)
     }
 
     /* Tells and says */
-    if (appData.zippyPlay && 
+    if (appData.zippyPlay &&
        (looking_at(buf, i, "* offers to be your bughouse partner") ||
         looking_at(buf, i, "* tells you: [automatic message] I chose you"))) {
        player = StripHighlightAndTitle(star_match[0]);
@@ -528,7 +533,7 @@ int ZippyControl(buf, i)
            sprintf(reply, "%stell %s %s\n", ics_prefix,
                    player, programVersion);
            SendToICS(reply);
-       } else if (appData.zippyTalk && ((random() % 10) < 9)) {
+       } else if (appData.zippyTalk && (((unsigned) random() % 10) < 9)) {
            if (strcmp(player, ics_handle) != 0) {
                Speak("tell", player);
            }
@@ -571,7 +576,7 @@ int ZippyConverse(buf, i)
     }
 
     if (looking_at(buf, i, "* kibitzes: *")) {
-      if (appData.zippyTalk && (random() % 10) < 9) {
+      if (appData.zippyTalk && ((unsigned) random() % 10) < 9) {
        char *player = StripHighlightAndTitle(star_match[0]);
        if (strcmp(player, ics_handle) != 0) {
            Speak("kibitz", NULL);
@@ -581,7 +586,7 @@ int ZippyConverse(buf, i)
     }
 
     if (looking_at(buf, i, "* whispers: *")) {
-      if (appData.zippyTalk && (random() % 10) < 9) {
+      if (appData.zippyTalk && ((unsigned) random() % 10) < 9) {
        char *player = StripHighlightAndTitle(star_match[0]);
        if (strcmp(player, ics_handle) != 0) {
            Speak("whisper", NULL);
@@ -598,7 +603,7 @@ int ZippyConverse(buf, i)
        char *player = StripHighlightAndTitle(star_match[0]);
 
        if (strcmp(player, ics_handle) != 0) {
-           if ((random() % 10) < 9)
+           if (((unsigned) random() % 10) < 9)
              Speak("message", player);
            f = fopen("zippy.messagelog", "a");
            fprintf(f, "%s (%s:%s): %s\n", player,
@@ -632,7 +637,8 @@ int ZippyConverse(buf, i)
          channel[strlen(channel)-1] = NULLCHAR;
 #if 0
          /* Always tell to the channel (probability 90%) */
-         if (strcmp(player, ics_handle) != 0 && (random() % 10) < 9) {
+         if (strcmp(player, ics_handle) != 0 &&
+             ((unsigned) random() % 10) < 9) {
            Speak("tell", channel);
          }
 #else
@@ -658,22 +664,22 @@ int ZippyConverse(buf, i)
     }
 
     if (looking_at(buf, i, "Notification: * has arrived")) {
-       if ((random() % 3) == 0) {
+       if (((unsigned) random() % 3) == 0) {
            char *player = StripHighlightAndTitle(star_match[0]);
            strcpy(lastgreet, player);
            sprintf(reply, "greet %s\n", player);
            SendToICS(reply);
            Speak("tell", player);
        }
-    }  
+    }
 
     if (looking_at(buf, i, "Notification: * has departed")) {
-       if ((random() % 3) == 0) {
+       if (((unsigned) random() % 3) == 0) {
            char *player = StripHighlightAndTitle(star_match[0]);
            sprintf(reply, "farewell %s\n", player);
            SendToICS(reply);
        }
-    }  
+    }
 
     if (looking_at(buf, i, "Not sent -- * is censoring you")) {
        char *player = StripHighlightAndTitle(star_match[0]);
@@ -681,7 +687,7 @@ int ZippyConverse(buf, i)
            sprintf(reply, "%s-notify %s\n", ics_prefix, player);
            SendToICS(reply);
        }
-    }  
+    }
 
     if (looking_at(buf, i, "command is currently turned off")) {
        appData.zippyUseI = 0;
@@ -739,6 +745,11 @@ void ZippyHandleChallenge(srated, swild, sbase, sincrement, opponent)
     base = atoi(sbase);
     increment = atoi(sincrement);
 
+       /* If icsAnalyzeEngine active 
+          we don't accept automatic games */
+       if (appData.icsActive) 
+           if (appData.icsEngineAnalyze) return;
+
     /* If desired, you can insert more code here to decline matches
        based on rated, variant, base, and increment, but it is
        easier to use the ICS formula feature instead. */
@@ -765,7 +776,7 @@ void ZippyHandleChallenge(srated, swild, sbase, sincrement, opponent)
         /* Yes, and this isn't him.  Ignore challenge. */
        return;
     }
-    
+
     /* Too many consecutive games with same opponent?  If so, make him
        wait until someone else has played or a timeout has elapsed. */
     if (appData.zippyMaxGames &&
@@ -866,12 +877,20 @@ int ZippyMatch(buf, i)
        return TRUE;
     }
 
-    if (looking_at(buf, i, "offers you a draw")) {
-        if (first.sendDrawOffers && first.initDone) {
-           SendToProgram("draw\n", &first);
+       if (ics_type == ICS_ICC) {
+               if (looking_at(buf, i, "Your opponent offers you a draw")) {
+                       if (first.sendDrawOffers && first.initDone)
+                               SendToProgram("draw\n", &first);
+                       return TRUE;
+               }
+       } else {
+           if (looking_at(buf, i, "offers you a draw")) {
+               if (first.sendDrawOffers && first.initDone) {
+                       SendToProgram("draw\n", &first);
+                       }
+                       return TRUE;
+       }
        }
-       return TRUE;
-    }
 
     if (looking_at(buf, i, "requests that the game be aborted") ||
         looking_at(buf, i, "would like to abort")) {
@@ -908,7 +927,7 @@ int ZippyMatch(buf, i)
     return FALSE;
 }
 
-/* Initialize chess program with data from the first board 
+/* Initialize chess program with data from the first board
  * of a new or resumed game.
  */
 void ZippyFirstBoard(moveNum, basetime, increment)
@@ -965,7 +984,7 @@ void ZippyFirstBoard(moveNum, basetime, increment)
        message from ICS." Send 0 in that case */
     w = (gameInfo.whiteRating >= 0) ? gameInfo.whiteRating : 0;
     b = (gameInfo.blackRating >= 0) ? gameInfo.blackRating : 0;
-    
+
     firstMove = FALSE;
     if (gameMode == IcsPlayingWhite) {
         if (first.sendName) {
@@ -1054,7 +1073,7 @@ void ZippyFirstBoard(moveNum, basetime, increment)
        } else {
            /* Position not sent above, move list might be sent later */
            /* Nothing needs to be done here */
-       }       
+       }
     }
 }