+function set_gametype($gametype)
+{
+ global $CARDS;
+ global $RULES;
+
+ switch($gametype)
+ {
+ case "normal":
+ case "wedding":
+ case "poverty":
+ case "dpoverty":
+ case "trump":
+ case "silent":
+ $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
+ '17','18','19','20','21','22','23','24','25','26');
+ $CARDS["diamonds"] = array();
+ $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
+ $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
+ $CARDS["hearts"] = array('43','44','45','46','47','48');
+ $CARDS["foxes"] = array('19','20');
+ if($RULES["dullen"]=='none')
+ {
+ $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
+ '17','18','19','20','21','22','23','24','25','26');
+ $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
+ }
+ break;
+ case "queen":
+ $CARDS["trump"] = array('3','4','5','6','7','8','9','10');
+ $CARDS["clubs"] = array('27','28','29','30','31','32','11','12','33','34');
+ $CARDS["spades"] = array('35','36','37','38','39','40','13','14','41','42');
+ $CARDS["hearts"] = array('43','44', '1', '2','45','46','15','16','47','48');
+ $CARDS["diamonds"] = array('19','20','21','22','23','24','17','18','25','26');
+ $CARDS["foxes"] = array();
+ break;
+ case "jack":
+ $CARDS["trump"] = array('11','12','13','14','15','16','17','18');
+ $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','33','34');
+ $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','41','42');
+ $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','47','48');
+ $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','25','26');
+ $CARDS["foxes"] = array();
+ break;
+ case "trumpless":
+ $CARDS["trump"] = array();
+ $CARDS["clubs"] = array('27','28','29','30','31','32','3', '4','11','12','33','34');
+ $CARDS["spades"] = array('35','36','37','38','39','40','5', '6','13','14','41','42');
+ $CARDS["hearts"] = array('43','44', '1', '2','45','46','7', '8','15','16','47','48');
+ $CARDS["diamonds"] = array('19','20','21','22','23','24','9','10','17','18','25','26');
+ $CARDS["foxes"] = array();
+ break;
+ case "club":
+ $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
+ '17','18','27','28','29','30','31','32','33','34');
+ $CARDS["clubs"] = array();
+ $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
+ $CARDS["hearts"] = array('43','44','45','46','47','48');
+ $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
+ $CARDS["foxes"] = array();
+ if($RULES["dullen"]=='none')
+ {
+ $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
+ '17','18','27','28','29','30','31','32','33','34');
+ $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
+ }
+ break;
+ case "spade":
+ $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
+ '17','18','35','36','37','38','39','40','41','42');
+ $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
+ $CARDS["spades"] = array();
+ $CARDS["hearts"] = array('43','44','45','46','47','48');
+ $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
+ $CARDS["foxes"] = array();
+ if($RULES["dullen"]=='none')
+ {
+ $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
+ '17','18','35','36','37','38','39','40','41','42');
+ $CARDS["hearts"] = array('43','44','1','2','45','46','47','48');
+ }
+ break;
+ case "heart":
+ $CARDS["trump"] = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16',
+ '17','18','43','44','45','46','47','48');
+ $CARDS["clubs"] = array('27','28','29','30','31','32','33','34');
+ $CARDS["spades"] = array('35','36','37','38','39','40','41','42');
+ $CARDS["hearts"] = array();
+ $CARDS["diamonds"] = array('19','20','21','22','23','24','25','26');
+ $CARDS["foxes"] = array();
+ if($RULES["dullen"]=='none')
+ {
+ $CARDS["trump"] = array('3','4','5','6','7','8','9','10','11','12','13','14','15','16',
+ '17','18','43','44','1','2','45','46','47','48');
+ }
+ break;
+ }
+}
+
+function mysort($cards,$gametype)
+{
+ usort ( $cards, "sort_comp" );
+ return $cards;
+}
+
+function sort_comp($a,$b)
+{
+ global $CARDS;
+
+ $ALL = array();
+ $ALL = array_merge($CARDS["trump"],$CARDS["diamonds"],$CARDS["clubs"],
+ $CARDS["hearts"],$CARDS["spades"],$CARDS["diamonds"]);
+
+ return pos_array($a,$ALL)-pos_array($b,$ALL);
+}
+
+function can_call($what,$hash)
+{
+ global $RULES;
+
+ /*TODO: check if this already has been call by teammate */
+
+ $gameid = DB_get_gameid_by_hash($hash);
+ $gametype = DB_get_gametype_by_gameid($gameid);
+
+ $NRcards = count(DB_get_hand($me));
+
+ $NRallcards = 0;
+ for ($i=1;$i<5;$i++)
+ {
+ $user = DB_get_hash_from_game_and_pos($gameid,$i);
+ $NRallcards += count(DB_get_hand($user));
+ };
+
+ /* in case of a wedding, everything will be delayed by an offset */
+ $offset = 0;
+ if($gametype=="wedding")
+ {
+ $offset = DB_get_sickness_by_gameid($gameid);
+ if ($offset <0) /* not resolved */
+ return 0;
+ };
+
+ switch ($RULES["call"])
+ {
+ case "1st-own-card":
+ if( 4-($what/30) >= 12 - $NRcards + $offset)
+ return 1;
+ break;
+ case "5th-card":
+ if( 27+4*($what/30)) <= $NRallcards + $offset*4)
+ return 1;
+ break;
+ case "9-cards":
+ if( ($what/10) <= $NRcards + $offset)
+ return 1;
+ break;
+ }
+
+ return 0;
+}
+
+?>