2005-02-23 15:19:54 +00:00
/* WarServ - War Card Game Service - NeoStats Addon Module
2008-03-10 07:39:20 +00:00
* * Copyright ( c ) 2004 - 2008 Justin Hammond , Mark Hetherington , Jeff Lang
2005-02-23 15:19:54 +00:00
* *
* * This program is free software ; you can redistribute it and / or modify
* * it under the terms of the GNU General Public License as published by
* * the Free Software Foundation ; either version 2 of the License , or
* * ( at your option ) any later version .
* *
* * This program is distributed in the hope that it will be useful ,
* * but WITHOUT ANY WARRANTY ; without even the implied warranty of
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* * GNU General Public License for more details .
* *
* * You should have received a copy of the GNU General Public License
* * along with this program ; if not , write to the Free Software
* * Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307
* * USA
* *
* * WarServ CVS Identification
* * $ Id $
*/
# include "neostats.h" /* Required for bot support */
# include "warserv.h"
2005-10-18 20:45:51 +00:00
char warroom [ MAXCHANLEN ] ;
int currentwargamestatus ;
int currentwarplayercount ;
char wplayernick [ 10 ] [ MAXNICK ] ;
int wplayercardstotal [ 10 ] ;
2005-10-18 21:11:37 +00:00
int warinprogress ;
int currentplayer ;
int wpln ;
2005-10-18 20:57:13 +00:00
static int wplayercardsinhand [ 10 ] [ 52 ] ;
static int wplayercardplayed [ 10 ] ;
static int wplayeratwar [ 10 ] ;
static int wplayerwarcardsplayed [ 10 ] [ 3 ] ;
static int wstackcards [ 52 ] ;
static int wstackcardscurrent ;
static char csuit [ 10 ] ;
static char csuitcolour [ 10 ] ;
static char csuitcard [ 10 ] ;
static void checkhandwinner ( void ) ;
static void checkwarwinner ( void ) ;
static void clearstack ( void ) ;
static void playershufflecards ( void ) ;
static void wardealcards ( void ) ;
static void askplaycard ( void ) ;
int startwar ( void * userptr ) ;
2005-10-18 20:45:51 +00:00
2005-02-23 15:19:54 +00:00
/*
* Stop Game
* resets everything to default as if no game running
*/
2005-10-18 21:14:41 +00:00
void stopwar ( void )
{
int i ;
2005-02-23 15:19:54 +00:00
if ( currentwargamestatus = = WS_GAME_STARTING ) {
DelTimer ( " startwar " ) ;
}
for ( wpln = 0 ; wpln < 10 ; wpln + + ) {
strlcpy ( wplayernick [ wpln ] , " " , MAXNICK ) ;
wplayercardstotal [ wpln ] = 0 ;
wplayercardplayed [ wpln ] = 0 ;
wplayeratwar [ wpln ] = 0 ;
2005-10-18 21:14:41 +00:00
for ( i = 0 ; i < 52 ; i + + ) {
wplayercardsinhand [ wpln ] [ i ] = 0 ;
2005-02-23 15:19:54 +00:00
}
2005-10-18 21:14:41 +00:00
for ( i = 0 ; i < 3 ; i + + ) {
wplayerwarcardsplayed [ wpln ] [ i ] = 0 ;
2005-02-23 15:19:54 +00:00
}
}
for ( wpln = 0 ; wpln < 52 ; wpln + + ) {
wstackcards [ wpln ] = 0 ;
}
warinprogress = 0 ;
wstackcardscurrent = 0 ;
currentwarplayercount = 0 ;
currentwargamestatus = WS_GAME_STOPPED ;
currentplayer = 0 ;
return ;
}
/*
* Start Game Countdown
* Starts a timer to allow 30 seconds for people to join the game
*/
void startcountdowntimer ( char * nic ) {
currentwargamestatus = WS_GAME_STARTING ;
irc_chanprivmsg ( ws_bot , warroom , " \003 7A new game of \003 4WAR \003 7 has been started by %s. Game will start in 30 seconds, type ' \2 \003 !Join \2 \003 7' to play. " , nic ) ;
2005-08-09 13:05:00 +00:00
AddTimer ( TIMER_TYPE_COUNTDOWN , startwar , " startwar " , 30 , NULL ) ;
2005-02-23 15:19:54 +00:00
return ;
}
/*
* Start Game
* Initializes variables and starts game
*/
2005-10-18 20:57:13 +00:00
int startwar ( void * userptr )
2005-02-23 15:19:54 +00:00
{
/* DelTimer ("startwar"); */
if ( currentwargamestatus = = WS_GAME_STARTING ) {
if ( currentwarplayercount < 1 ) {
irc_chanprivmsg ( ws_bot , warroom , " \003 4No Players joined to current Game, Exiting " ) ;
currentwargamestatus = WS_GAME_STOPPING ;
stopwar ( ) ;
2005-02-24 21:18:11 +00:00
return NS_SUCCESS ;
2005-02-23 15:19:54 +00:00
}
if ( currentwarplayercount < 10 ) {
joinwar ( ws_bot - > name ) ;
}
irc_chanprivmsg ( ws_bot , warroom , " \003 4WAR \003 10 is now starting, current players are \003 7%s %s %s %s %s %s %s %s %s %s " , wplayernick [ 0 ] , wplayernick [ 1 ] , wplayernick [ 2 ] , wplayernick [ 3 ] , wplayernick [ 4 ] , wplayernick [ 5 ] , wplayernick [ 6 ] , wplayernick [ 7 ] , wplayernick [ 8 ] , wplayernick [ 9 ] ) ;
irc_chanprivmsg ( ws_bot , warroom , " \003 9Shuffling Deck and Dealing Cards " ) ;
currentplayer = 0 ;
currentwargamestatus = WS_GAME_PLAYING ;
wardealcards ( ) ;
wstackcardscurrent = 0 ;
askplaycard ( ) ;
}
2005-02-24 21:18:11 +00:00
return NS_SUCCESS ;
2005-02-23 15:19:54 +00:00
}
/*
* Join Game
* adds new player to game during countdown
*/
void joinwar ( char * nic ) {
if ( currentwarplayercount < 10 ) {
for ( wpln = 0 ; wpln < 10 ; wpln + + ) {
if ( ! ircstrcasecmp ( wplayernick [ wpln ] , nic ) ) {
return ;
}
}
strlcpy ( wplayernick [ currentwarplayercount ] , nic , MAXNICK ) ;
currentwarplayercount + + ;
irc_chanprivmsg ( ws_bot , warroom , " \003 8Welcome to \003 4WAR \003 7%s " , nic ) ;
} else {
irc_chanprivmsg ( ws_bot , warroom , " \003 4Sorry all places are filled \003 7%s \003 4, your welcome to try the next game though " , nic ) ;
}
}
/*
* Remove Player
* removes player from game and adds any cards they have to the stack
*/
2005-10-18 21:14:41 +00:00
void removewar ( char * nic )
{
int i ;
2005-02-23 15:19:54 +00:00
int tfrpacp ;
int tfrpacpn ;
int wplnht ;
int cpfp ;
tfrpacp = 0 ;
tfrpacpn = 0 ;
if ( currentwarplayercount < 1 ) {
return ;
}
for ( wpln = 0 ; wpln < currentwarplayercount ; wpln + + ) {
if ( ! ircstrcasecmp ( wplayernick [ wpln ] , nic ) ) {
irc_chanprivmsg ( ws_bot , warroom , " \003 7%s \003 8Removed from the current game of \003 4War " , nic ) ;
if ( wpln = = currentplayer ) {
tfrpacp = 1 ;
} else if ( wpln < currentplayer ) {
tfrpacp = 2 ;
tfrpacpn = wpln ;
}
for ( wplnht = 0 ; wplnht < wplayercardstotal [ wpln ] ; wplnht + + ) {
wstackcards [ wstackcardscurrent ] = wplayercardsinhand [ wpln ] [ wplnht ] ;
wstackcardscurrent + + ;
}
2005-10-18 21:14:41 +00:00
for ( i = wpln ; i < currentwarplayercount ; i + + ) {
cpfp = ( i + 1 ) ;
2005-02-23 15:19:54 +00:00
if ( cpfp = = currentwarplayercount ) {
2005-10-18 21:14:41 +00:00
strlcpy ( wplayernick [ i ] , " " , MAXNICK ) ;
for ( wplnht = 0 ; wplnht < wplayercardstotal [ i ] ; wplnht + + ) {
wplayercardsinhand [ i ] [ wplnht ] = 0 ;
2005-02-23 15:19:54 +00:00
}
2005-10-18 21:14:41 +00:00
wplayercardstotal [ i ] = 0 ;
2005-02-23 15:19:54 +00:00
} else {
2005-10-18 21:14:41 +00:00
strlcpy ( wplayernick [ i ] , wplayernick [ cpfp ] , MAXNICK ) ;
2005-02-23 15:19:54 +00:00
for ( wplnht = 0 ; wplnht < 52 ; wplnht + + ) {
2005-10-18 21:14:41 +00:00
wplayercardsinhand [ i ] [ wplnht ] = wplayercardsinhand [ cpfp ] [ wplnht ] ;
2005-02-23 15:19:54 +00:00
}
2005-10-18 21:14:41 +00:00
wplayercardstotal [ i ] = wplayercardstotal [ cpfp ] ;
2005-02-23 15:19:54 +00:00
}
}
currentwarplayercount - - ;
}
}
if ( currentwarplayercount < 2 ) {
irc_chanprivmsg ( ws_bot , warroom , " \003 9Stopping Current Game , \003 7%s \003 9 wins. " , wplayernick [ 0 ] ) ;
stopwar ( ) ;
} else if ( tfrpacp = = 1 ) {
if ( currentplayer > ( currentwarplayercount - 1 ) ) {
currentplayer = 0 ;
}
if ( currentwargamestatus = = WS_GAME_STARTING ) {
askplaycard ( ) ;
}
} else if ( tfrpacp = = 2 ) {
if ( currentplayer > tfrpacpn ) {
currentplayer - - ;
}
}
}
/*
* Deal Cards
*/
2005-10-18 20:57:13 +00:00
static void wardealcards ( void ) {
2005-02-23 15:19:54 +00:00
int cd ;
int cnd ;
int cndn ;
int ptdt = 0 ;
for ( wpln = 0 ; wpln < 52 ; wpln + + ) {
wstackcards [ wpln ] = wpln ;
}
for ( cd = 52 ; cd > 0 ; cd - - ) {
cnd = rand ( ) % cd ;
cndn = wstackcards [ cnd ] ;
for ( wpln = cnd ; wpln < ( cd - 1 ) ; wpln + + ) {
wstackcards [ wpln ] = wstackcards [ ( wpln + 1 ) ] ;
}
wstackcards [ ( cd - 1 ) ] = 0 ;
wplayercardsinhand [ ptdt ] [ wplayercardstotal [ ptdt ] ] = cndn ;
wplayercardstotal [ ptdt ] + + ;
ptdt + + ;
if ( ptdt = = currentwarplayercount ) {
ptdt = 0 ;
}
}
}
/*
* Shuffle Players Cards
*/
2005-10-18 21:14:41 +00:00
void playershufflecards ( void )
{
2005-02-23 15:19:54 +00:00
int tcs ;
int tcsp ;
int tcsps ;
2005-10-18 21:14:41 +00:00
int i ;
2005-02-23 15:19:54 +00:00
for ( wpln = 0 ; wpln < currentwarplayercount ; wpln + + ) {
2005-10-18 21:14:41 +00:00
for ( i = 0 ; i < wplayercardstotal [ wpln ] ; i + + ) {
2005-02-23 15:19:54 +00:00
tcsps = 0 ;
tcsp = rand ( ) % wplayercardstotal [ wpln ] ;
2005-10-18 21:14:41 +00:00
if ( tcsp = = i ) {
2005-02-23 15:19:54 +00:00
tcsps = 1 ;
}
if ( tcsps = = 0 ) {
tcs = wplayercardsinhand [ wpln ] [ tcsp ] ;
2005-10-18 21:14:41 +00:00
wplayercardsinhand [ wpln ] [ tcsp ] = wplayercardsinhand [ wpln ] [ i ] ;
wplayercardsinhand [ wpln ] [ i ] = tcs ;
2005-02-23 15:19:54 +00:00
}
}
}
}
/*
* asks each player for card to play
* or check war results if in war
* or removes player if no cards left
*/
2005-10-18 20:57:13 +00:00
static void askplaycard ( void )
{
2005-02-23 15:19:54 +00:00
int trn ;
int wspa [ 5 ] ;
int nwp = ( currentwarplayercount + 1 ) ;
if ( wplayercardstotal [ currentplayer ] = = 0 ) {
removewar ( wplayernick [ currentplayer ] ) ;
}
if ( wplayercardstotal [ currentplayer ] = = 52 ) {
currentplayer + + ;
removewar ( wplayernick [ currentplayer ] ) ;
}
if ( currentwarplayercount < 2 ) {
return ;
}
if ( warinprogress = = 1 ) {
if ( currentplayer < currentwarplayercount ) {
for ( wpln = currentplayer ; wpln < currentwarplayercount ; wpln + + ) {
if ( wplayeratwar [ wpln ] = = 1 ) {
nwp = wpln ;
wpln = currentwarplayercount ;
}
}
currentplayer = nwp ;
}
if ( nwp > currentwarplayercount ) {
checkwarwinner ( ) ;
} else {
if ( ! ircstrcasecmp ( wplayernick [ currentplayer ] , ws_bot - > name ) ) {
trn = wplayercardstotal [ currentplayer ] ;
wspa [ 2 ] = ( ( rand ( ) % trn ) + 1 ) ;
trn - - ;
wspa [ 3 ] = ( ( rand ( ) % trn ) + 1 ) ;
if ( wspa [ 3 ] = = wspa [ 2 ] ) {
wspa [ 3 ] + + ;
}
trn - - ;
wspa [ 4 ] = ( ( rand ( ) % trn ) + 1 ) ;
if ( ( wspa [ 4 ] = = wspa [ 2 ] ) | | ( wspa [ 4 ] = = wspa [ 3 ] ) ) {
wspa [ 4 ] + + ;
}
if ( ( wspa [ 4 ] = = wspa [ 2 ] ) | | ( wspa [ 4 ] = = wspa [ 3 ] ) ) {
wspa [ 4 ] + + ;
}
2005-10-18 21:03:37 +00:00
playwarcards ( wspa [ 2 ] , wspa [ 3 ] , wspa [ 4 ] ) ;
2005-02-23 15:19:54 +00:00
} else {
irc_chanprivmsg ( ws_bot , warroom , " \003 7%s \003 9 you hold \003 11 %d \003 9 cards, and are currently at \003 4WAR \003 9 which three would you like to play ? " , wplayernick [ currentplayer ] , wplayercardstotal [ currentplayer ] ) ;
}
}
} else {
if ( ! ircstrcasecmp ( wplayernick [ currentplayer ] , ws_bot - > name ) ) {
2005-10-18 21:03:37 +00:00
playcard ( ( ( rand ( ) % wplayercardstotal [ currentplayer ] ) + 1 ) ) ;
2005-02-23 15:19:54 +00:00
} else {
irc_chanprivmsg ( ws_bot , warroom , " \003 7%s \003 9 you currently hold \003 11 %d \003 9 cards, which would you like to play ? " , wplayernick [ currentplayer ] , wplayercardstotal [ currentplayer ] ) ;
}
}
}
/*
* Player War Play Card
*/
2005-10-18 21:03:37 +00:00
void playwarcards ( int cnp1 , int cnp2 , int cnp3 )
{
2005-10-18 21:14:41 +00:00
int i ;
2005-02-23 15:19:54 +00:00
int cnp [ 3 ] ;
2005-10-18 21:03:37 +00:00
cnp [ 0 ] = cnp1 ;
cnp [ 1 ] = cnp2 ;
cnp [ 2 ] = cnp3 ;
2005-02-23 15:19:54 +00:00
for ( wpln = 0 ; wpln < 3 ; wpln + + ) {
if ( ( cnp [ wpln ] < 1 ) | | ( cnp [ wpln ] > wplayercardstotal [ currentplayer ] ) ) {
return ;
}
}
if ( wplayercardsinhand [ currentplayer ] [ ( cnp [ 2 ] - 1 ) ] < 13 ) {
strlcpy ( csuitcolour , " \003 4 " , 10 ) ;
strlcpy ( csuit , " Hearts " , 10 ) ;
} else if ( wplayercardsinhand [ currentplayer ] [ ( cnp [ 2 ] - 1 ) ] < 26 ) {
strlcpy ( csuitcolour , " \003 7 " , 10 ) ;
strlcpy ( csuit , " Diamonds " , 10 ) ;
} else if ( wplayercardsinhand [ currentplayer ] [ ( cnp [ 2 ] - 1 ) ] < 39 ) {
strlcpy ( csuitcolour , " \003 14 " , 10 ) ;
strlcpy ( csuit , " Clubs " , 10 ) ;
} else {
strlcpy ( csuitcolour , " \003 15 " , 10 ) ;
strlcpy ( csuit , " Spades " , 10 ) ;
}
switch ( ( wplayercardsinhand [ currentplayer ] [ ( cnp [ 2 ] - 1 ) ] % 13 ) ) {
case 12 :
strlcpy ( csuitcard , " Ace " , 10 ) ;
break ;
case 11 :
strlcpy ( csuitcard , " King " , 10 ) ;
break ;
case 10 :
strlcpy ( csuitcard , " Queen " , 10 ) ;
break ;
case 9 :
strlcpy ( csuitcard , " Jack " , 10 ) ;
break ;
default :
ircsnprintf ( csuitcard , 10 , " %d " , ( ( wplayercardsinhand [ currentplayer ] [ ( cnp [ 2 ] - 1 ) ] % 13 ) + 2 ) ) ;
break ;
}
irc_chanprivmsg ( ws_bot , warroom , " \003 7%s \003 9 played Cards \003 11 %d , %d , %d \003 9(%s %s of %s \003 9) " , wplayernick [ currentplayer ] , cnp [ 0 ] , cnp [ 1 ] , cnp [ 2 ] , csuitcolour , csuitcard , csuit ) ;
for ( wpln = 0 ; wpln < 3 ; wpln + + ) {
cnp [ wpln ] - - ;
wstackcards [ wstackcardscurrent ] = wplayercardsinhand [ currentplayer ] [ cnp [ wpln ] ] ;
wstackcardscurrent + + ;
wplayerwarcardsplayed [ currentplayer ] [ wpln ] = wplayercardsinhand [ currentplayer ] [ cnp [ wpln ] ] ;
}
if ( cnp [ 2 ] > cnp [ 0 ] )
cnp [ 2 ] - - ;
if ( cnp [ 2 ] > cnp [ 1 ] )
cnp [ 2 ] - - ;
if ( cnp [ 1 ] > cnp [ 0 ] )
cnp [ 1 ] - - ;
for ( wpln = 0 ; wpln < 3 ; wpln + + ) {
wplayercardstotal [ currentplayer ] - - ;
2005-10-18 21:14:41 +00:00
for ( i = cnp [ wpln ] ; i < wplayercardstotal [ currentplayer ] ; i + + ) {
wplayercardsinhand [ currentplayer ] [ i ] = wplayercardsinhand [ currentplayer ] [ ( i + 1 ) ] ;
2005-02-23 15:19:54 +00:00
}
wplayercardsinhand [ currentplayer ] [ wplayercardstotal [ currentplayer ] ] = 0 ;
}
currentplayer + + ;
if ( currentplayer < currentwarplayercount ) {
askplaycard ( ) ;
} else {
checkwarwinner ( ) ;
}
}
/*
* Player Plays Card
*/
2005-10-18 21:03:37 +00:00
void playcard ( int cnp )
{
2005-02-23 15:19:54 +00:00
if ( ( cnp > 0 ) & & ( cnp < ( wplayercardstotal [ currentplayer ] + 1 ) ) ) {
if ( wplayercardsinhand [ currentplayer ] [ ( cnp - 1 ) ] < 13 ) {
strlcpy ( csuitcolour , " \003 4 " , 10 ) ;
strlcpy ( csuit , " Hearts " , 10 ) ;
} else if ( wplayercardsinhand [ currentplayer ] [ ( cnp - 1 ) ] < 26 ) {
strlcpy ( csuitcolour , " \003 7 " , 10 ) ;
strlcpy ( csuit , " Diamonds " , 10 ) ;
} else if ( wplayercardsinhand [ currentplayer ] [ ( cnp - 1 ) ] < 39 ) {
strlcpy ( csuitcolour , " \003 14 " , 10 ) ;
strlcpy ( csuit , " Clubs " , 10 ) ;
} else {
strlcpy ( csuitcolour , " \003 15 " , 10 ) ;
strlcpy ( csuit , " Spades " , 10 ) ;
}
switch ( ( wplayercardsinhand [ currentplayer ] [ ( cnp - 1 ) ] % 13 ) ) {
case 12 :
strlcpy ( csuitcard , " Ace " , 10 ) ;
break ;
case 11 :
strlcpy ( csuitcard , " King " , 10 ) ;
break ;
case 10 :
strlcpy ( csuitcard , " Queen " , 10 ) ;
break ;
case 9 :
strlcpy ( csuitcard , " Jack " , 10 ) ;
break ;
default :
ircsnprintf ( csuitcard , 10 , " %d " , ( ( wplayercardsinhand [ currentplayer ] [ ( cnp - 1 ) ] % 13 ) + 2 ) ) ;
break ;
}
irc_chanprivmsg ( ws_bot , warroom , " \003 7%s \003 9 played Card \003 11 %d \003 9(%s %s of %s \003 9) " , wplayernick [ currentplayer ] , cnp , csuitcolour , csuitcard , csuit ) ;
cnp - - ;
wstackcards [ wstackcardscurrent ] = wplayercardsinhand [ currentplayer ] [ cnp ] ;
wstackcardscurrent + + ;
wplayercardplayed [ currentplayer ] = wplayercardsinhand [ currentplayer ] [ cnp ] ;
wplayercardstotal [ currentplayer ] - - ;
for ( wpln = cnp ; wpln < wplayercardstotal [ currentplayer ] ; wpln + + ) {
wplayercardsinhand [ currentplayer ] [ wpln ] = wplayercardsinhand [ currentplayer ] [ ( wpln + 1 ) ] ;
}
wplayercardsinhand [ currentplayer ] [ wplayercardstotal [ currentplayer ] ] = 0 ;
currentplayer + + ;
if ( currentplayer < currentwarplayercount ) {
askplaycard ( ) ;
} else {
checkhandwinner ( ) ;
}
}
}
/*
* Checks standard hand for a winner ( not a war hand )
*/
2005-10-18 20:57:13 +00:00
static void checkhandwinner ( void )
{
2005-10-18 21:14:41 +00:00
int i ;
2005-02-23 15:19:54 +00:00
int hcnp = 0 ;
int hcnpt = 0 ;
for ( wpln = 0 ; wpln < currentwarplayercount ; wpln + + ) {
if ( warinprogress = = wplayeratwar [ wpln ] ) {
if ( ( wplayercardplayed [ wpln ] % 13 ) > hcnp ) {
hcnp = ( wplayercardplayed [ wpln ] % 13 ) ;
hcnpt = 1 ;
} else if ( ( wplayercardplayed [ wpln ] % 13 ) = = hcnp ) {
hcnpt + + ;
}
}
}
if ( hcnpt = = 1 ) {
for ( wpln = 0 ; wpln < currentwarplayercount ; wpln + + ) {
if ( warinprogress = = wplayeratwar [ wpln ] ) {
if ( ( wplayercardplayed [ wpln ] % 13 ) = = hcnp ) {
if ( warinprogress = = 1 ) {
irc_chanprivmsg ( ws_bot , warroom , " \003 7%s \003 9 wins the \003 4WAR \003 9. " , wplayernick [ wpln ] ) ;
} else {
irc_chanprivmsg ( ws_bot , warroom , " \003 7%s \003 9 takes the hand. " , wplayernick [ wpln ] ) ;
}
2005-10-18 21:14:41 +00:00
for ( i = 0 ; i < wstackcardscurrent ; i + + ) {
wplayercardsinhand [ wpln ] [ wplayercardstotal [ wpln ] ] = wstackcards [ i ] ;
2005-02-23 15:19:54 +00:00
wplayercardstotal [ wpln ] + + ;
}
clearstack ( ) ;
wpln = currentwarplayercount ;
}
}
}
for ( wpln = 0 ; wpln < currentwarplayercount ; wpln + + ) {
wplayeratwar [ wpln ] = 0 ;
}
warinprogress = 0 ;
} else {
irc_chanprivmsg ( ws_bot , warroom , " \003 4WAR DECLARED " ) ;
for ( wpln = 0 ; wpln < currentwarplayercount ; wpln + + ) {
if ( warinprogress = = wplayeratwar [ wpln ] ) {
wplayeratwar [ wpln ] = 0 ;
if ( ( wplayercardplayed [ wpln ] % 13 ) = = hcnp ) {
wplayeratwar [ wpln ] = 1 ;
if ( wplayercardstotal [ wpln ] < 3 ) {
irc_chanprivmsg ( ws_bot , warroom , " \003 7%s \003 8 Surrenders \003 9 (Insufficient Cards) " , wplayernick [ wpln ] ) ;
hcnpt - - ;
removewar ( wplayernick [ wpln ] ) ;
if ( currentwarplayercount < 2 ) {
wpln = currentwarplayercount ;
return ;
}
}
}
}
}
warinprogress = 1 ;
}
currentplayer = 0 ;
playershufflecards ( ) ;
askplaycard ( ) ;
}
/*
* copy war hand to normal for checking
*/
2005-10-18 21:14:41 +00:00
static void checkwarwinner ( void )
{
int i ;
2005-02-23 15:19:54 +00:00
for ( wpln = 0 ; wpln < currentwarplayercount ; wpln + + ) {
if ( wplayeratwar [ wpln ] = = 1 ) {
wplayercardplayed [ wpln ] = wplayerwarcardsplayed [ wpln ] [ 2 ] ;
} else {
wplayercardplayed [ wpln ] = 0 ;
}
2005-10-18 21:14:41 +00:00
for ( i = 0 ; i < 3 ; i + + ) {
wplayerwarcardsplayed [ wpln ] [ i ] = 0 ;
2005-02-23 15:19:54 +00:00
}
}
checkhandwinner ( ) ;
}
/*
* clears the stack
*/
2005-10-18 20:57:13 +00:00
static void clearstack ( void ) {
2005-02-23 15:19:54 +00:00
for ( wpln = 0 ; wpln < 52 ; wpln + + ) {
wstackcards [ wpln ] = 0 ;
}
wstackcardscurrent = 0 ;
}