annotate 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
rev   line source
ocsenave@227 1 (ns com.aurellem.gb.badges
ocsenave@227 2 (:use (com.aurellem.gb gb-driver util constants))
ocsenave@227 3 (:use (com.aurellem.world practice))
ocsenave@227 4 (:import [com.aurellem.gb.gb_driver SaveState]))
ocsenave@227 5
ocsenave@227 6 (def badges '(:boulder :cascade :thunder :marsh :rainbow :soul :volcano
ocsenave@227 7 :earth))
ocsenave@227 8
ocsenave@227 9 (defn get-badges
ocsenave@227 10 "Returns a list of the current badges held by the player."
ocsenave@227 11 ([state]
ocsenave@227 12 ((fn this [coll n]
ocsenave@227 13 (cond (zero? n) '()
ocsenave@227 14 (zero? (rem n 2)) (recur (pop coll) (int (/ n 2)))
ocsenave@227 15 :else (cons (peek coll) (this (pop coll) (int (/ n
ocsenave@227 16 2))))))
ocsenave@227 17 badges
ocsenave@227 18 (aget (memory state) 0xD355)
ocsenave@227 19 ))
ocsenave@227 20 ([] (get-badges @current-state)))
ocsenave@227 21
ocsenave@227 22 (defn set-badges
ocsenave@227 23 "Sets the badges held by the player. badge-list may contain :boulder
ocsenave@227 24 :cascade :thunder :marsh :rainbow :soul :volcano."
ocsenave@227 25 ([state badge-list]
ocsenave@227 26 (let [has-badge (set badge-list)]
ocsenave@227 27 (->>
ocsenave@227 28 ((fn [n coll]
ocsenave@227 29 (cond
ocsenave@227 30 (empty? coll) n
ocsenave@227 31 (has-badge (peek coll)) (recur (inc(* 2 n)) (pop coll))
ocsenave@227 32 :else (recur (* 2 n) (pop coll))))
ocsenave@227 33
ocsenave@227 34 0
ocsenave@227 35 (vec badges))
ocsenave@227 36 (set-memory state 0xD355))))
ocsenave@227 37
ocsenave@227 38
ocsenave@227 39 ([badge-list] (set-badges @current-state badge-list)))
ocsenave@227 40
ocsenave@227 41
ocsenave@227 42
ocsenave@227 43
ocsenave@227 44
ocsenave@227 45
ocsenave@227 46
ocsenave@227 47 ;; (let [mem (aget (memory state) 0xD354)]
ocsenave@227 48 ;; ((fn this [coll n]
ocsenave@227 49 ;; (cond (zero? n) '()
ocsenave@227 50 ;; (zero? (rem n 2)) (recur (pop coll) (int (/ n 2)))
ocsenave@227 51 ;; :else (cons (peek coll) (this (pop coll) (int (/ n
ocsenave@227 52 ;; 2))))))
ocsenave@227 53 ;; badges
ocsenave@227 54 ;; (aget (memory state) 0xD354)
ocsenave@227 55 ;; )))
ocsenave@227 56