X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=zippy.c;h=aed634e8e3a0b94060a1feaa684e9b05573dd0c3;hb=refs%2Ftags%2Fv4.3.4;hp=b1a7fc84dfcded89d8c8db042079c2c5f730b9e3;hpb=05bc30b15e31c427ce208495a889e9ff36e6642b;p=xboard.git diff --git a/zippy.c b/zippy.c index b1a7fc8..aed634e 100644 --- a/zippy.c +++ b/zippy.c @@ -1,6 +1,6 @@ /* * zippy.c -- Implements Zippy the Pinhead chess player on ICS in XBoard - * $Id$ + * $Id: zippy.c,v 2.2 2003/11/25 05:25:20 mann Exp $ * * Copyright 1991 by Digital Equipment Corporation, Maynard, Massachusetts. * Enhancements Copyright 1992-2001 Free Software Foundation, Inc. @@ -308,7 +308,8 @@ void Speak(how, whom) 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 *))]; } } @@ -322,7 +323,7 @@ void Speak(how, whom) } 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); @@ -376,6 +377,21 @@ int ZippyCalled(str) static char opp_name[128][32]; static int num_opps=0; +extern ColorClass curColor; + +static void SetCurColor( ColorClass color ) +{ + curColor = color; +} + +static void ColorizeEx( ColorClass color, int cont ) +{ + if( appData.colorize ) { + Colorize( color, cont ); + SetCurColor( color ); + } +} + int ZippyControl(buf, i) char *buf; int *i; @@ -389,7 +405,8 @@ int ZippyControl(buf, i) /* Possibly reject Crafty as opponent */ if (appData.zippyPlay && appData.zippyNoplayCrafty && forwardMostMove < 4 - && looking_at(buf, i, "* kibitzes: Hello from Crafty")) { + && looking_at(buf, i, "* kibitzes: Hello from Crafty")) + { player = StripHighlightAndTitle(star_match[0]); if ((gameMode == IcsPlayingWhite && StrCaseCmp(player, gameInfo.black) == 0) || @@ -490,7 +507,8 @@ int ZippyControl(buf, i) } if (looking_at(buf, i, "* tells you: *") || - looking_at(buf, i, "* says: *")) { + looking_at(buf, i, "* says: *")) + { player = StripHighlightAndTitle(star_match[0]); if (appData.zippyPassword[0] != NULLCHAR && strncmp(star_match[1], appData.zippyPassword, @@ -528,19 +546,28 @@ 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); } } + + ColorizeEx( ColorTell, FALSE ); + return TRUE; } + if( appData.colorize && looking_at(buf, i, "* (*) seeking") ) { + ColorizeEx(ColorSeek, FALSE); + return FALSE; + } + if (looking_at(buf, i, "* spoofs you:")) { player = StripHighlightAndTitle(star_match[0]); sprintf(reply, "spoofedby %s\n", player); SendToICS(reply); } + return FALSE; } @@ -554,7 +581,8 @@ int ZippyConverse(buf, i) /* Shouts and emotes */ if (looking_at(buf, i, "--> * *") || - looking_at(buf, i, "* shouts: *")) { + looking_at(buf, i, "* shouts: *")) + { if (appData.zippyTalk) { char *player = StripHighlightAndTitle(star_match[0]); if (strcmp(player, ics_handle) == 0) { @@ -567,26 +595,35 @@ int ZippyConverse(buf, i) Speak("shout", NULL); } } + + ColorizeEx(ColorShout, FALSE); + return TRUE; } 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); } } + + ColorizeEx(ColorKibitz, FALSE); + return TRUE; } 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); } } + + ColorizeEx(ColorKibitz, FALSE); + return TRUE; } @@ -598,7 +635,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 +669,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 @@ -641,6 +679,8 @@ int ZippyConverse(buf, i) Speak("tell", channel); } #endif + + ColorizeEx( atoi(channel) == 1 ? ColorChannel1 : ColorChannel, FALSE ); } return TRUE; } @@ -658,7 +698,7 @@ 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); @@ -668,7 +708,7 @@ int ZippyConverse(buf, i) } 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);