NEW FEATURE: implement Lance's Schweinchen rule
authorArun Persaud <arun@nubati.net>
Sat, 18 Oct 2008 23:46:59 +0000 (16:46 -0700)
committerArun Persaud <arun@nubati.net>
Sat, 18 Oct 2008 23:46:59 +0000 (16:46 -0700)
new rule that only allows Schweinchen in case one of the teammembers called re/contra.

Signed-off-by: Arun Persaud <arun@nubati.net>
include/functions.php
include/game.php
include/output.php

index ca62cd93b7a756caab1d231faaa882220cb8f214..d09408cd43094b0c0e4ca00b5b460b2442297fbb 100644 (file)
@@ -177,14 +177,27 @@ function compare_cards($a,$b,$game)
            return 1;
          if($b == 19 || $b == 20 )
            return 0;
            return 1;
          if($b == 19 || $b == 20 )
            return 0;
-       };
-      if($RULES['schweinchen']=='second' && $GAME['schweinchen-second'])
+       }
+      else if($RULES['schweinchen']=='second' && $GAME['schweinchen-second'])
        {
          if($a == 19 || $a == 20 )
            return 1;
          if($b == 19 || $b == 20 )
            return 0;
        {
          if($a == 19 || $a == 20 )
            return 1;
          if($b == 19 || $b == 20 )
            return 0;
-       };
+       }
+      else if($RULES['schweinchen']=='secondaftercall' && $GAME['schweinchen-who'] && $GAME['schweinchen-second'] )
+       {
+         /* check if a call was made either by the player or his partner. If so activate Schweinchen rule. */
+         if(DB_get_call_by_hash($GAME['schweinchen-who']) || DB_get_partner_call_by_hash($GAME['schweinchen-who']) )
+           {
+             if($a == 19 || $a == 20 )
+               return 1;
+             if($b == 19 || $b == 20 )
+               return 0;
+           }
+         /* if not, do nothing and the foxes are just handeled as normal trump */
+       }
+       ;
     case "heart":
     case "spade":
     case "club":
     case "heart":
     case "spade":
     case "club":
index 49957b121ec31c81e781425fafa632e87bec97b5..afe61446dd1dec58f7633e2730eb01cf2d45a067 100644 (file)
@@ -1324,7 +1324,11 @@ switch($mystatus)
                else
                  $GAME['schweinchen-second'] = 1; /* this must be the second fox */
 
                else
                  $GAME['schweinchen-second'] = 1; /* this must be the second fox */
 
-               if( ($GAME['schweinchen-second']==1 && $RULES['schweinchen']=='second') || $RULES['schweinchen']=='both')
+               if( $RULES['schweinchen']=='both' ||
+                   ($RULES['schweinchen']=='second' && $GAME['schweinchen-second']==1 )||
+                   ($RULES['schweinchen']=='secondaftercall' && $GAME['schweinchen-second']==1 &&
+                    (DB_get_call_by_hash($GAME['schweinchen-who']) || DB_get_partner_call_by_hash($GAME['schweinchen-who']) ))
+                 )
                  {
                    DB_insert_comment('Schweinchen! ',$playid,$myid);
                    $commentSchweinchen = 'Schweinchen! ';
                  {
                    DB_insert_comment('Schweinchen! ',$playid,$myid);
                    $commentSchweinchen = 'Schweinchen! ';
@@ -1871,9 +1875,15 @@ switch($mystatus)
 
        foreach($mycards as $card)
          {
 
        foreach($mycards as $card)
          {
+           /* display only cards that the player is allowed to play as links, the rest just display normal
+            * also check if we have both schweinchen, in that case only display on of them as playable
+            */
            if( ($followsuit && !same_type($card,$firstcard)) ||
            if( ($followsuit && !same_type($card,$firstcard)) ||
-               ( (int)($card)==19 && ($RULES['schweinchen']=='second'||$RULES['schweinchen']=='secondaftercall')
-                 && $GAME['schweinchen-who']==$me && !$GAME['schweinchen-first'] )
+               ( (int)($card)==19 && !$GAME['schweinchen-first'] &&
+                 ($RULES['schweinchen']=='second'||
+                  ( $RULES['schweinchen']=='secondaftercall' &&
+                    (DB_get_call_by_hash($GAME['schweinchen-who']) || DB_get_partner_call_by_hash($GAME['schweinchen-who']) )))
+                 && $GAME['schweinchen-who']==$me  )
                )
              display_card($card,$PREF['cardset']);
            else
                )
              display_card($card,$PREF['cardset']);
            else
index 1531c77363879916d81685d00b46419a78d5656e..723dd548a8fab68ec26b1a2c02b1cd803a1c2738 100644 (file)
@@ -75,8 +75,8 @@ function output_form_for_new_game($names)
         </li>
         <li> <input type="radio" name="schweinchen" value="second" />
              first one normal, second one becomes highest (call during the game) </li>
         </li>
         <li> <input type="radio" name="schweinchen" value="second" />
              first one normal, second one becomes highest (call during the game) </li>
-        <li> <input type="radio" name="schweinchen" value="secondaftercall"  disabled="disabled" />
-             second one become highest only in case re/contra was announced (not working yet)
+        <li> <input type="radio" name="schweinchen" value="secondaftercall" />
+             second one become highest only in case re/contra was announced
         </li>
       </ul>
       <p> Call Re/Contra, etc.: </p>
         </li>
       </ul>
       <p> Call Re/Contra, etc.: </p>