]> Pileus Git - ~andy/rhawk/blobdiff - spades.awk
Fix .look while passing cards
[~andy/rhawk] / spades.awk
index 9a1332e0c28d87bdf783987dec95b8ea34a25b86..fa79e88dd6d27654ec8e3cce7a63934ef08d7f1d 100644 (file)
@@ -17,7 +17,7 @@ function sp_init(cards, tmp0, tmp1)
 function sp_reset(type)
 {
        # Per message
-       if (type >= 0) {
+       if (type  0) {
                sp_from     = ""    #    The speakers player name
                sp_valid    = ""    #    It is the speaker turn
        }
@@ -52,7 +52,7 @@ function sp_reset(type)
                sp_limit    = 10    #     Bag out limit
                delete sp_hands     # [p] Each players cards
                delete sp_players   # [p] Player names players["name"] -> i
-               delete sp_cloaks    # [c] Player cloaks cloaks["cloak"] -> "name"
+               delete sp_auths     # [c] Player auth names auths["auth"] -> "name"
                delete sp_order     # [i] Player order order[i] -> "name"
                delete sp_scores    # [i] Teams score
        }
@@ -91,7 +91,7 @@ function sp_save(file,        game)
        game["limit"]   = sp_limit;
        json_copy(game, "hands",   sp_hands);
        json_copy(game, "players", sp_players);
-       json_copy(game, "cloaks",  sp_cloaks);
+       json_copy(game, "auths",   sp_auths);
        json_copy(game, "order",   sp_order);
        json_copy(game, "scores",  sp_scores);
 
@@ -102,7 +102,8 @@ function sp_save(file,      game)
 function sp_load(file, game)
 {
        # Load
-       json_load(file, game);
+       if (!json_load(file, game))
+               return
 
        # Per hand
        sp_suit    = game["suit"];
@@ -128,7 +129,7 @@ function sp_load(file,      game)
        sp_limit   = game["limit"];
        sp_acopy(sp_hands,   game["hands"]);
        sp_acopy(sp_players, game["players"]);
-       sp_acopy(sp_cloaks,  game["cloaks"]);
+       sp_acopy(sp_auths,   game["auths"]);
        sp_acopy(sp_order,   game["order"]);
        sp_acopy(sp_scores,  game["scores"]);
 }
@@ -168,13 +169,13 @@ function sp_deal( shuf)
        say("Bidding starts with " sp_player "!")
 }
 
-function sp_hand(who,  sort, str)
+function sp_hand(to, who,      sort, str)
 {
        asorti(sp_hands[who], sort, "sp_csort")
        for (i=0; i<length(sort); i++)
                str = str "" sprintf("%4s", sort[i])
        gsub(/^ +| +$/, "", str)
-       return sp_pretty(str, who)
+       return sp_pretty(str, to)
 }
 
 function sp_hasa(who, expr)
@@ -331,27 +332,28 @@ BEGIN {
        sp_init()
        sp_reset(2)
        sp_load("var/sp_cur.json");
-       if (sp_channel)
-               say(sp_channel, "Game restored.")
+       #if (sp_channel)
+       #       say(sp_channel, "Game restored.")
 }
 
 // {
-       sp_from  = AUTH in sp_cloaks ? sp_cloaks[AUTH] : FROM
+       sp_from  = AUTH in sp_auths ? sp_auths[AUTH] : FROM
        sp_valid = sp_from && sp_from == sp_player
 }
 
+CMD == "PRIVMSG" &&
 ! /help/ &&
 /[Ss]pades/ {
        say("Spades! " sp_pretty("As,Ah,Ad,Ac", FROM))
 }
 
-FROM == OWNER &&
+AUTH == OWNER &&
 /^\.savegame/ {
        sp_save("var/sp_save.json");
        say("Game saved.")
 }
 
-FROM == OWNER &&
+AUTH == OWNER &&
 /^\.loadgame/ {
        sp_load("var/sp_save.json");
        say("Game loaded.")
@@ -376,7 +378,7 @@ FROM == OWNER &&
 }
 
 # Debugging
-FROM == OWNER &&
+AUTH == OWNER &&
 /^\.deal (\w+) (.*)/ {
        delete sp_hands[$2]
        for (i=3; i<=NF; i++)
@@ -400,7 +402,7 @@ FROM == OWNER &&
        }
 }
 
-(sp_from == sp_owner || FROM == OWNER) &&
+(sp_from == sp_owner || AUTH == OWNER) &&
 /^\.endgame$/ {
        if (sp_state == "new") {
                reply("There is no game in progress.")
@@ -424,7 +426,7 @@ FROM == OWNER &&
                i = sp_next()
                sp_players[FROM] = i
                if (AUTH)
-                       sp_cloaks[AUTH] = FROM
+                       sp_auths[AUTH] = FROM
                sp_order[i] = FROM
                say(FROM " joins the game!")
        }
@@ -462,7 +464,7 @@ sp_state == "bid" &&
                        say("Bidding goes to " sp_player "!")
                } else {
                        for (p in sp_players)
-                               say(p, "You have: " sp_hand(p))
+                               say(p, "You have: " sp_hand(p, p))
                        sp_state = "play"
                        for (i=0; i<2; i++) {
                                if (sp_nil[i] == 2 || sp_nil[i+2] == 2) {
@@ -514,18 +516,18 @@ sp_state == "pass" &&
                }
                say(sp_channel, "Cards have been passed, play starts with " sp_player "!")
                for (p in sp_players)
-                       say(p, "You have: " sp_hand(p))
+                       say(p, "You have: " sp_hand(p, p))
                sp_state = "play"
        }
 }
 
-sp_state ~ "(play|bid)" &&
+sp_state ~ "(bid|pass|play)" &&
 /^\.look$/ {
        if (!(sp_from in sp_players)) {
                say(".slap " FROM ", you are not playing.")
        } else {
                sp_looked[sp_players[sp_from]] = 1
-               say(FROM, "You have: " sp_hand(sp_from))
+               say(FROM, "You have: " sp_hand(FROM, sp_from))
        }
 }
 
@@ -552,7 +554,7 @@ sp_state == "play" &&
                sp_play(card)
                if (sp_state == "play") {
                        if (length(sp_hands[sp_from]))
-                               say(FROM, "You have: " sp_hand(sp_from))
+                               say(FROM, "You have: " sp_hand(FROM, sp_from))
                        if (sp_piles)
                                say(sp_player ": it is your turn! " \
                                    "(" sp_pretty(sp_piles, sp_player) ")")
@@ -602,6 +604,9 @@ sp_state == "play" &&
                    sp_order[2] " " sp_order[3])
        }
        if (sp_state == "bid" || sp_state == "play") {
+               say("playing to: " \
+                   sp_playto " points, " \
+                   sp_limit  " bags")
                say(sp_team(0) ": " \
                    int(sp_scores[0]) " points, " \
                    int(sp_bags(0))   " bags")