diff --git a/aisleriot/game.c b/aisleriot/game.c index 7245c25..38e2c0e 100644 --- a/aisleriot/game.c +++ b/aisleriot/game.c @@ -569,6 +569,8 @@ cscmi_add_slot (SCM slot_data) gboolean expanded_down = FALSE; gboolean expanded_right = FALSE; int expansion_depth = 0; + AisleriotSlotType type = AISLERIOT_SLOT_UNKNOWN; + SCM slot_placement, slot_type; if (game->state > GAME_BEGIN) { return scm_throw (scm_from_locale_symbol ("game-started"), @@ -577,30 +579,53 @@ cscmi_add_slot (SCM slot_data) } #ifdef HAVE_GUILE_1_8 -#define CHECK_EXPANSION(string,object) (scm_is_true (scm_equal_p (scm_from_locale_symbol (string), object))) +#define EQUALS_SYMBOL(string,object) (scm_is_true (scm_equal_p (scm_from_locale_symbol (string), object))) #else -#define CHECK_EXPANSION(string,object) (!strcmp (string, SCM_CHARS (object))) +#define EQUALS_SYMBOL(string,object) (!strcmp (string, SCM_CHARS (object))) #endif - if (CHECK_EXPANSION ("expanded", SCM_CAR (SCM_CADDR (slot_data)))) { + slot_placement = SCM_CADDR (slot_data); + if (EQUALS_SYMBOL ("expanded", SCM_CAR (slot_placement))) { expanded_down = TRUE; - } else if (CHECK_EXPANSION ("expanded-right", SCM_CAR (SCM_CADDR (slot_data)))) { + } else if (EQUALS_SYMBOL ("expanded-right", SCM_CAR (slot_placement))) { expanded_right = TRUE; - } else if (CHECK_EXPANSION ("partially-expanded", SCM_CAR (SCM_CADDR (slot_data)))) { + } else if (EQUALS_SYMBOL ("partially-expanded", SCM_CAR (slot_placement))) { expanded_down = TRUE; - expansion_depth = scm_to_int (SCM_CADDR (SCM_CADDR (slot_data))); - } else if (CHECK_EXPANSION ("partially-expanded-right", SCM_CAR (SCM_CADDR (slot_data)))) { + expansion_depth = scm_to_int (SCM_CADDR (slot_placement)); + } else if (EQUALS_SYMBOL ("partially-expanded-right", SCM_CAR (slot_placement))) { expanded_right = TRUE; - expansion_depth = scm_to_int (SCM_CADDR (SCM_CADDR (slot_data))); + expansion_depth = scm_to_int (SCM_CADDR (slot_placement)); } -#undef CHECK_EXPANSION + /* 3rd argument is the slot type (optionally) */ + slot_type = SCM_CDDDR (slot_data); + if (slot_type != SCM_EOL) { + if (EQUALS_SYMBOL ("foundation", SCM_CAR (slot_type))) { + type = AISLERIOT_SLOT_FOUNDATION; + } else if (EQUALS_SYMBOL ("reserve", SCM_CAR (slot_type))) { + type = AISLERIOT_SLOT_RESERVE; + } else if (EQUALS_SYMBOL ("stock", SCM_CAR (slot_type))) { + type = AISLERIOT_SLOT_STOCK; + } else if (EQUALS_SYMBOL ("tableau", SCM_CAR (slot_type))) { + type = AISLERIOT_SLOT_TABLEAU; + } else if (EQUALS_SYMBOL ("waste", SCM_CAR (slot_type))) { + type = AISLERIOT_SLOT_WASTE; + } + } + +#undef EQUALS_SYMBOL + + { + static const char *types[] = { "unknown", "foundation", "reserve", "stock", "tableau", "waste" }; + g_print ("add-slot ID %d type %s\n", scm_to_int (SCM_CAR (slot_data)), types[type]); + } /* create and initialize slot */ slot = g_slice_new0 (Slot); g_ptr_array_add (game->slots, slot); slot->id = scm_to_int (SCM_CAR (slot_data)); + slot->type = type; slot->cards = g_byte_array_sized_new (SLOT_CARDS_N_PREALLOC); slot->exposed = 0; diff --git a/aisleriot/game.h b/aisleriot/game.h index 541e34a..ba63bfa 100644 --- a/aisleriot/game.h +++ b/aisleriot/game.h @@ -29,10 +29,20 @@ G_BEGIN_DECLS +typedef enum { + AISLERIOT_SLOT_UNKNOWN, + AISLERIOT_SLOT_FOUNDATION, + AISLERIOT_SLOT_RESERVE, + AISLERIOT_SLOT_STOCK, + AISLERIOT_SLOT_TABLEAU, + AISLERIOT_SLOT_WASTE +} AisleriotSlotType; + /* A slot */ typedef struct { int id; + AisleriotSlotType type; GByteArray *cards; #ifdef HAVE_CLUTTER diff --git a/aisleriot/sol.scm b/aisleriot/sol.scm index b60f9b2..b53f6de 100644 --- a/aisleriot/sol.scm +++ b/aisleriot/sol.scm @@ -163,8 +163,8 @@ ; The real slots come in three varieties: ; A slot in which only the topmost card is visible: (define (add-normal-slot cards) - (add-slot (set-tag! (new-slot cards - (list 'normal (get-and-increment-position)))))) + (add-slot (set-tag! (new-slot cards + (list 'normal (get-and-increment-position)) 'unknown)))) ; A slot in which all the cards are visible, arranged as an overlapped pile: ; (either proceeding to the right or down). @@ -172,20 +172,20 @@ (if (= right direction) (add-slot (set-tag! (new-slot cards (list 'expanded-right - (get-and-increment-position))))) + (get-and-increment-position)) 'unknown))) (add-slot (set-tag! (new-slot cards (list 'expanded - (get-and-increment-position))))))) + (get-and-increment-position)) 'unknown))))) ; A slot in only the n topmost cards are visible: (define (add-partially-extended-slot cards direction n) (if (= right direction) (add-slot (set-tag! (new-slot cards (list 'partially-expanded-right - (get-and-increment-position) n)))) + (get-and-increment-position) n) 'unknown))) (add-slot (set-tag! (new-slot cards (list 'partially-expanded - (get-and-increment-position) n)))))) + (get-and-increment-position) n) 'unknown))))) ; Cards may be dealt off one slot (usually the one containing the deck) ; and onto a list of other slots using these procedures: @@ -516,8 +516,8 @@ (vector-set! deck ref2 (vector-ref deck ref1)) (shuffle-deck-helper deck (cons val-at-ref2 result) (+ ref1 1) (- len 1))))) -(define (new-slot deck placement) - (list #f deck placement)) +(define (new-slot deck placement type) + (list #f deck placement type)) (define (set-tag! slot) (set! SLOTS (+ 1 SLOTS))