BUGFIX: couldn't unclick no90 call
[e-DoKo.git] / functions.php
index b1ed09fabf0c5df3f92be136aa2bd0042845748d..2f2e07d6ee9713893b1dce079101682ed63cd4b1 100644 (file)
@@ -58,6 +58,9 @@ function mymail($To,$Subject,$message,$header="")
 
   if($debug)
     {
+      /* display email on screen,
+       * change txt -> html
+       */
       $message = str_replace("\n","<br />\n",$message);
       $message = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]",
                      "<a href=\"\\0\">\\0</a>", $message);
@@ -157,11 +160,12 @@ function compare_cards($a,$b,$game)
   if( $b/2 - (int)($b/2) != 0.5)
     $b--;
 
-  /* some special cases */
+  /* check for schweinchen and ten of hearts*/
   switch($game)
     {
     case "normal":
     case "silent":
+    case "trump":
       if($RULES["schweinchen"]=="both" && $GAME["schweinchen"])
        {
          if($a == 19 || $a == 20 )
@@ -176,13 +180,17 @@ function compare_cards($a,$b,$game)
          if($b == 19 || $b == 20 )
            return 0;
        };
-    case "trump":
     case "heart":
     case "spade":
     case "club":
+      /* check for ten of hearts rule */
       if($RULES["dullen"]=="secondwins")
        if($a==1 && $b==1) /* both 10 of hearts */
          return 0;        /* second one wins.*/
+    case "trumpless":
+    case "jack":
+    case "queen":
+      /* no special cases here */
     }
 
   /* normal case */
@@ -309,28 +317,38 @@ function count_trump($cards)
 
   $trump = 0;
 
-  /* count each trump */
+  /* count each trump, including the foxes */
   foreach($cards as $c)
     if( (int)($c) <27)
       $trump++;
 
-  switch($RULES["schweinchen"])
-    {
-    case "none":
-      break;
-    case "second":
-    case "secondaftercall":
-      /* add one, in case the player has both foxes (schweinchen) */
-      if( in_array("19",$cards) && in_array("20",$cards) )
+  /* normally foxes don't count as trump, so we substract them here
+   * in case someone has schweinchen, one or two of them should count as trump 
+   * though, so we need to add one trump for those cases */
+  
+  /* subtract foxes */
+  if( in_array("19",$cards))
+    $trump--;
+  if( in_array("20",$cards) )
+    $trump--;
+
+  /* handle case where player has schweinchen */
+  if( in_array("19",$cards) && in_array("20",$cards) )
+    switch($RULES["schweinchen"])
+      {
+      case "both":
+       /* add two, in case the player has both foxes (schweinchen) */
        $trump++;
-    case "both":
-      /* subtract foxes */
-      if( in_array("19",$cards))
-       $trump--;
-      if( in_array("20",$cards) )
-       $trump--;
-      break;
-    }
+       $trump++;
+       break;
+      case "second":
+      case "secondaftercall":
+       /* add one, in case the player has both foxes (schweinchen) */
+       $trump++;
+       break;
+      case "none":
+       break;
+      }
 
   return $trump;
 }
@@ -640,7 +658,7 @@ function can_call($what,$hash)
 
 function display_table ()
 {
-  global $gameid, $GT, $debug,$host,$defaulttimezone;
+  global $gameid, $GT, $debug,$INDEX,$defaulttimezone;
 
   $result = mysql_query("SELECT  User.fullname as name,".
                        "        Hand.position as position, ".
@@ -677,7 +695,7 @@ function display_table ()
       if(!$debug)
        echo "   $name \n";
       else
-       echo "   <a href=\"".$host."?me=".$hash."\">$name</a>\n";
+       echo "   <a href=\"".$INDEX."?me=".$hash."\">$name</a>\n";
 
       /* add hints for poverty, wedding, solo, etc */
       if($GT=="poverty" && $party=="re")
@@ -785,9 +803,9 @@ function display_table ()
 
 function display_user_menu()
 {
-  global $wiki,$myid,$host;
+  global $WIKI,$myid,$INDEX,$STATS;
   echo "<div class=\"usermenu\">\n".
-    "<a href=\"index.php\"> Go to my user page </a>";
+    "<a href=\"".$INDEX."\"> Go to my user page </a>";
 
   $result = mysql_query("SELECT Hand.hash,Hand.game_id,Game.player from Hand".
                        " LEFT JOIN Game On Hand.game_id=Game.id".
@@ -800,15 +818,15 @@ function display_user_menu()
 
   while( $r = mysql_fetch_array($result,MYSQL_NUM))
     {
-      echo "<a href=\"".$host."?me=".$r[0]."\">game ".DB_format_gameid($r[1])." </a><br />\n";
+      echo "<a href=\"".$INDEX."?me=".$r[0]."\">game ".DB_format_gameid($r[1])." </a><br />\n";
     }
 
-  echo "<hr /> <a href=\"".$host."?new\">Start a new game</a>\n";
+  echo "<hr /> <a href=\"".$INDEX."?new\">Start a new game</a>\n";
 
-  echo "<hr /> <a href=\"".substr($host,0,-9)."stats.php\">Statistics</a>\n";
+  echo "<hr /> <a href=\"".$STATS."\">Statistics</a>\n";
 
   echo
-    "<hr />Report bugs in the <a href=\"". $wiki."\">wiki</a>\n";
+    "<hr />Report bugs in the <a href=\"".$WIKI."\">wiki</a>\n";
   echo  "</div>\n";
   return;
 }