diff clojure/com/aurellem/gb/badges.clj @ 227:d5dddf33543c

Added functions for getting and setting badges.
author Dylan Holmes <ocsenave@gmail.com>
date Sat, 24 Mar 2012 05:45:06 -0500
parents
children edce489c3c21
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/clojure/com/aurellem/gb/badges.clj	Sat Mar 24 05:45:06 2012 -0500
     1.3 @@ -0,0 +1,56 @@
     1.4 +(ns com.aurellem.gb.badges
     1.5 +  (:use (com.aurellem.gb gb-driver util constants))
     1.6 +  (:use (com.aurellem.world practice))
     1.7 +  (:import [com.aurellem.gb.gb_driver SaveState]))
     1.8 +
     1.9 +(def badges '(:boulder :cascade :thunder :marsh :rainbow :soul :volcano
    1.10 +     :earth))
    1.11 +
    1.12 +(defn get-badges
    1.13 +  "Returns a list of the current badges held by the player."
    1.14 +  ([state]
    1.15 +    ((fn this [coll n]
    1.16 +      (cond (zero? n) '()
    1.17 +            (zero? (rem n 2)) (recur (pop coll) (int (/ n 2)))
    1.18 +            :else (cons (peek coll) (this (pop coll) (int (/ n
    1.19 +                                                             2))))))
    1.20 +     badges
    1.21 +     (aget (memory state) 0xD355)
    1.22 +     ))
    1.23 +  ([] (get-badges @current-state)))
    1.24 +
    1.25 +(defn set-badges
    1.26 +  "Sets the badges held by the player. badge-list may contain :boulder
    1.27 +:cascade :thunder :marsh :rainbow :soul :volcano."
    1.28 +  ([state badge-list]
    1.29 +     (let [has-badge (set badge-list)]
    1.30 +       (->>
    1.31 +        ((fn [n coll]
    1.32 +           (cond
    1.33 +             (empty? coll) n
    1.34 +             (has-badge (peek coll)) (recur (inc(* 2 n)) (pop coll))
    1.35 +             :else (recur (* 2 n) (pop coll))))
    1.36 +      
    1.37 +         0
    1.38 +         (vec badges))
    1.39 +        (set-memory state 0xD355))))
    1.40 +     
    1.41 +    
    1.42 +  ([badge-list] (set-badges @current-state badge-list)))
    1.43 +
    1.44 +
    1.45 +  
    1.46 +
    1.47 +    
    1.48 +
    1.49 +  
    1.50 +  ;; (let [mem (aget (memory state) 0xD354)]
    1.51 +  ;;   ((fn this [coll n]
    1.52 +  ;;     (cond (zero? n) '()
    1.53 +  ;;           (zero? (rem n 2)) (recur (pop coll) (int (/ n 2)))
    1.54 +  ;;           :else (cons (peek coll) (this (pop coll) (int (/ n
    1.55 +  ;;                                                            2))))))
    1.56 +  ;;    badges
    1.57 +  ;;    (aget (memory state) 0xD354)
    1.58 +  ;;    )))
    1.59 +  
    1.60 \ No newline at end of file