\n".
+ echo "
\n".
"
\n";
};
@@ -1282,6 +1433,14 @@ switch($mystatus)
/* display card */
echo "
\n";
+ /* for the first card, we also need to display calls from other players */
+ if($seq==1 && $trickNR==1)
+ {
+ $commentPreCalls=DB_get_pre_comment_call($gameid);
+ foreach ($commentPreCalls as $pre )
+ $comment .= $pre[1].": ".$pre[0]."
";
+ }
+
/* display comments */
if($comment!='')
echo " \n";
@@ -1295,7 +1454,7 @@ switch($mystatus)
if($seq==4)
{
$winner = get_winner($play,$gametype); /* returns the position */
- echo "
\n \n"; /* end div trick, end li trick */
+ echo "
\n"; /* end div trick, end li trick */
}
}
@@ -1364,7 +1523,7 @@ switch($mystatus)
(DB_get_call_by_hash($GAME['schweinchen-who']) || DB_get_partner_call_by_hash($GAME['schweinchen-who']) ))
)
{
- DB_insert_comment('Schweinchen! ',$playid,$myid);
+ DB_insert_comment('Schweinchen! ',$playid,$gameid,$myid);
$commentSchweinchen = 'Schweinchen! ';
}
if ($debug)
@@ -1413,7 +1572,10 @@ switch($mystatus)
$play = DB_get_cards_by_trick($trickid);
$winner = get_winner($play,$gametype); /* returns the position */
- /* check if someone caught a fox */
+ /*
+ * check if someone caught a fox
+ *******************************/
+
/* first check if we should account for solos at all,
* since it doesn't make sense in some games
*/
@@ -1446,32 +1608,41 @@ switch($mystatus)
}
}
- /* check for karlchen (jack of clubs in the last trick)*/
+ /*
+ * check for karlchen (jack of clubs in the last trick)
+ ******************************************************/
+
/* same as for foxes, karlchen doesn't always make sense
* check what kind of game it is and set karlchen accordingly */
- $ok = 1; /* default: karlchen should be accounted for */
- if($tricknr != 12 )
- $ok = 0; /* Karlchen works only in the last trick */
- if($ok && DB_get_gametype_by_gameid($gameid)=='solo' )
+
+ if($tricknr == 12 ) /* Karlchen works only in the last trick */
{
- $solo = DB_get_solo_by_gameid($gameid);
- if($solo == 'trumpless' || $solo == 'jack' || $solo == 'queen' )
- $ok = 0; /* no Karlchen in these solos */
- }
+ /* check for solo */
+ $solo = 'none';
+ if(DB_get_gametype_by_gameid($gameid)=='solo' )
+ $solo = DB_get_solo_by_gameid($gameid);
- if($ok)
- foreach($play as $played)
- if ( $played['card']==11 || $played['card']==12 )
- if ($played['pos'] == $winner )
- {
- /* possible caught a fox, check party */
- $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
- $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
+ /* no Karlchen in these solos */
+ if($solo != 'trumpless' && $solo != 'jack' && $solo != 'queen' )
+ {
+ foreach($play as $played)
+ if ( $played['card']==11 || $played['card']==12 )
+ if ($played['pos'] == $winner )
+ {
+ /* save Karlchen */
+ $uid1 = DB_get_userid('gameid-position',$gameid,$winner);
+ $party1 = DB_get_party_by_gameid_and_userid($gameid,$uid1);
+
+ DB_query("INSERT INTO Score".
+ " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'karlchen')");
+ };
+ };
+ }; /* end scoring Karlchen */
+
+ /*
+ * check for doppelopf (>40 points)
+ ***********************************/
- DB_query("INSERT INTO Score".
- " VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'karlchen')");
- }
- /* check for doppelopf (>40 points)*/
$points = 0;
foreach($play as $played)
{
@@ -1486,16 +1657,21 @@ switch($mystatus)
" VALUES( NULL,NULL,$gameid,'$party1',$uid1,NULL,'doko')");
}
+ /*
+ * set winner (for this trick)
+ */
+
if($winner>0)
DB_query("UPDATE Trick SET winner='$winner' WHERE id='$trickid'");
else
- echo "ERROR during scoring";
+ $messages[] = "ERROR during scoring";
if($debug)
echo "DEBUG: position $winner won the trick
";
/* who is the next player? */
$next = $winner;
+ $firstcard = ''; /* unset firstcard, so followsuit doesn't trigger with the last trick */
}
else
{
@@ -1508,17 +1684,18 @@ switch($mystatus)
{
$comment = $_REQUEST['comment'];
if($comment != '')
- DB_insert_comment($comment,$playid,$myid);
+ DB_insert_comment($comment,$playid,$gameid,$myid);
if($commentSchweinchen)
$comment = $commentSchweinchen . $comment;
+ if($commentCall != '')
+ $comment = $commentCall . $comment;
};
/* display played card */
$pos = DB_get_pos_by_hash($me);
if($sequence==1)
{
- echo "
Trick ".($tricknr)."\n".
- " \n".
+ echo "
\n".
"
\n";
}
@@ -1530,7 +1707,7 @@ switch($mystatus)
echo "\n \n";
echo "
\n";
- echo "
\n \n"; /* end div trick, end li trick */
+ echo "
\n"; /* end div trick, end li trick */
/*check if we still have cards left, else set status to gameover */
if(sizeof(DB_get_hand($me))==0)
@@ -1560,13 +1737,12 @@ switch($mystatus)
$who = DB_get_userid('hash',$next_hash);
DB_set_player_by_gameid($gameid,$who);
- $message = "A card has been played in game ".DB_format_gameid($gameid).".\n\n".
+ $email_message = "A card has been played in game ".DB_format_gameid($gameid).".\n\n".
"It's your turn now.\n".
"Use this link to play a card: ".$HOST.$INDEX."?action=game&me=".$next_hash."\n\n" ;
if( DB_get_email_pref_by_uid($who)!='emailaddict' )
{
- $subject = 'A card has been played in game '.DB_format_gameid($gameid);
- mymail($who,$subject,$message);
+ mymail($who,$gameid, GAME_YOUR_TURN, $email_message);
}
}
else /* send out final email */
@@ -1580,10 +1756,10 @@ switch($mystatus)
" LEFT JOIN Card ON Card.id=Hand_Card.card_id".
" WHERE Hand.game_id='$gameid'".
" GROUP BY User.fullname" );
- $message = "The game is over. Thanks for playing :)\n";
- $message .= "Final score:\n";
+ $email_message = "The game is over. Thanks for playing :)\n";
+ $email_message .= "Final score:\n";
while( $r = DB_fetch_array($result) )
- $message .= " ".$r[0]."(".$r[2].") ".$r[1]."\n";
+ $email_message .= " ".$r[0]."(".$r[2].") ".$r[1]."\n";
$result = DB_query("SELECT Hand.party, IFNULL(SUM(Card.points),0) FROM Hand".
" LEFT JOIN Trick ON Trick.winner=Hand.position AND Trick.game_id=Hand.game_id".
@@ -1593,12 +1769,12 @@ switch($mystatus)
" LEFT JOIN Card ON Card.id=Hand_Card.card_id".
" WHERE Hand.game_id='$gameid'".
" GROUP BY Hand.party" );
- $message .= "\nTotals:\n";
+ $email_message .= "\nTotals:\n";
$re = 0;
$contra = 0;
while( $r = DB_fetch_array($result) )
{
- $message .= " ".$r[0]." ".$r[1]."\n";
+ $email_message .= " ".$r[0]." ".$r[1]."\n";
if($r[0] == 're')
$re = $r[1];
else if($r[0] == 'contra')
@@ -1611,8 +1787,8 @@ switch($mystatus)
*/
/* get calls from re/contra */
- $call_re = NULL;
- $call_contra = NULL;
+ $call_re = -1;
+ $call_contra = -1;
foreach($userids as $user)
{
$hash = DB_get_hash_from_gameid_and_userid($gameid,$user);
@@ -1625,14 +1801,14 @@ switch($mystatus)
if($party=='re')
{
- if($call_re==NULL)
+ if($call_re== -1)
$call_re = $call;
else if( $call < $call_re)
$call_re = $call;
}
else if($party=='contra')
{
- if($call_contra==NULL)
+ if($call_contra== -1)
$call_contra = $call;
else if( $call < $call_contra)
$call_contra = $call;
@@ -1643,7 +1819,7 @@ switch($mystatus)
/* figure out who one */
$winning_party = NULL;
- if($call_re == NULL && $call_contra==NULL)
+ if($call_re == -1 && $call_contra == -1)
{
/* nobody made a call, so it's easy to figure out who won */
if($re>120)
@@ -1657,7 +1833,7 @@ switch($mystatus)
* if only one party made a call, the other one wins,
* if the first one didn't make it
*/
- if($call_re)
+ if($call_re != -1)
{
$offset = 120 - $call_re;
if($call_re == 0)
@@ -1665,11 +1841,11 @@ switch($mystatus)
if($re > 120+$offset)
$winning_party='re';
- else if ($call_contra == NULL )
+ else if ($call_contra == -1 )
$winning_party='contra';
}
- if($call_contra)
+ if($call_contra != -1)
{
$offset = 120 - $call_contra;
if($call_contra == 0)
@@ -1677,7 +1853,7 @@ switch($mystatus)
if($contra > 120+$offset)
$winning_party='contra';
- else if ($call_re == NULL )
+ else if ($call_re == -1 )
$winning_party='re';
}
}
@@ -1685,7 +1861,7 @@ switch($mystatus)
/* one point for each call of the other party in case the other party didn't win
* and one point each in case the party made more than points than one of the calls
*/
- if($winning_party!='contra' && $call_contra!=NULL)
+ if($winning_party!='contra' && $call_contra!= -1)
{
for( $p=$call_contra;$p<=120; $p+=30 )
{
@@ -1700,7 +1876,7 @@ switch($mystatus)
" VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'made$p')");
}
}
- if($winning_party!='re' and $call_re!=NULL)
+ if($winning_party!='re' and $call_re!= -1)
{
for( $p=$call_re;$p<=120; $p+=30 )
{
@@ -1729,7 +1905,7 @@ switch($mystatus)
foreach(array(120,150,180,210,240) as $p)
{
$offset = 0;
- if($p==240 || $call_contra!=NULL)
+ if($p==240 || $call_contra != -1)
$offset = 1;
if($re>$p-$offset)
@@ -1739,7 +1915,7 @@ switch($mystatus)
/* re called something and won */
foreach(array(0,30,60,90,120) as $p)
{
- if($call_re!=NULL && $call_re<$p+1)
+ if($call_re!= -1 && $call_re<$p+1)
DB_query("INSERT INTO Score".
" VALUES( NULL,NULL,$gameid,'re',NULL,NULL,'call$p')");
}
@@ -1749,7 +1925,7 @@ switch($mystatus)
foreach(array(120,150,180,210,240) as $p)
{
$offset = 0;
- if($p==240 || $call_re!=NULL)
+ if($p==240 || $call_re != -1)
$offset = 1;
if($contra>$p-$offset)
@@ -1759,7 +1935,7 @@ switch($mystatus)
/* re called something and won */
foreach(array(0,30,60,90,120) as $p)
{
- if($call_contra!=NULL && $call_contra<$p+1)
+ if($call_contra != -1 && $call_contra<$p+1)
DB_query("INSERT INTO Score".
" VALUES( NULL,NULL,$gameid,'contra',NULL,NULL,'call$p')");
}
@@ -1767,35 +1943,35 @@ switch($mystatus)
/* add score points to email */
- $message .= "\n";
+ $email_message .= "\n";
$Tpoint = 0;
- $message .= " Points Re: \n";
+ $email_message .= " Points Re: \n";
$queryresult = DB_query("SELECT score FROM Score ".
" WHERE game_id=$gameid AND party='re'".
" ");
while($r = DB_fetch_array($queryresult) )
{
- $message .= " ".$r[0]."\n";
+ $email_message .= " ".$r[0]."\n";
$Tpoint ++;
}
- $message .= " Points Contra: \n";
+ $email_message .= " Points Contra: \n";
$queryresult = DB_query("SELECT score FROM Score ".
" WHERE game_id=$gameid AND party='contra'".
" ");
while($r = DB_fetch_array($queryresult) )
{
- $message .= " ".$r[0]."\n";
+ $email_message .= " ".$r[0]."\n";
$Tpoint --;
}
- $message .= " Total Points (from the Re point of view): $Tpoint\n";
- $message .= "\n";
+ $email_message .= " Total Points (from the Re point of view): $Tpoint\n";
+ $email_message .= "\n";
$session = DB_get_session_by_gameid($gameid);
$score = generate_score_table($session);
- $message .= "Score Table:\n";
- $message .= format_score_table_ascii($score);
- $message .= "\nUse these links to have a look at game ".DB_format_gameid($gameid).": \n";
+ $email_message .= "Score Table:\n";
+ $email_message .= format_score_table_ascii($score);
+ $email_message .= "\nUse these links to have a look at game ".DB_format_gameid($gameid).": \n";
/* send out final email */
foreach($userids as $user)
@@ -1805,31 +1981,29 @@ switch($mystatus)
$name = DB_get_name('userid',$user);
$link = "$name: ".$HOST.$INDEX."?action=game&me=".$hash."\n" ;
- $message .= $link;
+ $email_message .= $link;
}
- $message .= "\n\n (you can use reply all on this email to reach all the players.)\n\n";
- $subject = ' Game over (game '.DB_format_gameid($gameid).') ';
- mymail($userids,$subject,$message);
+ $email_message .= "\n\n (you can use reply all on this email to reach all the players.)\n\n";
+ mymail($userids,$gameid, GAME_OVER, $email_message);
}
}
else
{
- echo "can't find that card?!