comparison clojure/com/aurellem/gb/pokemon.clj @ 192:fd549c8f42ae

fixed compilation problems, added more functionality to pokemon-info
author Robert McIntyre <rlm@mit.edu>
date Thu, 22 Mar 2012 22:35:57 -0500
parents 893c753f8088
children da1a5ed61a8d
comparison
equal deleted inserted replaced
191:893c753f8088 192:fd549c8f42ae
1 (ns com.aurellem.gb.pokemon 1 (ns com.aurellem.gb.pokemon
2 (:use (com.aurellem.gb gb-driver util constants characters 2 (:use (com.aurellem.gb gb-driver util constants characters
3 moves types items status dv species 3 moves types items status dv species
4 experience 4 experience stats
5 )) 5 ))
6 (:import [com.aurellem.gb.gb_driver SaveState])) 6 (:import [com.aurellem.gb.gb_driver SaveState]))
7 7
8 (def pokemon-names-start 0xD2B4) 8 (def pokemon-names-start 0xD2B4)
9 9
64 (map read-name 64 (map read-name
65 (take (party-number state) 65 (take (party-number state)
66 (partition name-width raw-names))))) 66 (partition name-width raw-names)))))
67 ([] (original-trainers @current-state))) 67 ([] (original-trainers @current-state)))
68 68
69 (defn set-original-trainer 69 (defn read-OT-name
70 ([^SaveState state poke-num]
71 (nth (original-trainers state) poke-num))
72 ([poke-num] (read-OT @current-state poke-num)))
73
74 (defn set-OT-name
70 "Set the OT name for a pokemon. 75 "Set the OT name for a pokemon.
71 Note that a pokemon is still considered 'yours' if 76 Note that a pokemon is still considered 'yours' if
72 the OT ID is the same as your own." 77 the OT ID is the same as your own."
73 ([^SaveState state poke-num new-name] 78 ([^SaveState state poke-num new-name]
74 (assert (<= 0 poke-num (dec (party-number state)))) 79 (assert (<= 0 poke-num (dec (party-number state))))
80 ([n new-name] 85 ([n new-name]
81 (set-original-trainer @current-state n new-name))) 86 (set-original-trainer @current-state n new-name)))
82 87
83 (def OT-ID-addresses [0xD176 0xD1A2 0xD1CE 0xD1FA 0xD228 0xD252]) 88 (def OT-ID-addresses [0xD176 0xD1A2 0xD1CE 0xD1FA 0xD228 0xD252])
84 89
85 (defn set-pokemon-id 90 (defn read-OT-id
86 ([^SaveState state n new-id] 91 ([^SaveState state poke-num]
87 (assert (<= 0 n (dec (party-number state)))) 92 (let [mem (memory state)
88 (assert (<= 0 new-id 0xFFFF)) 93 start (OT-ID-addresses poke-num)]
94 (glue-bytes
95 (aget mem start)
96 (aget mem (inc start)))))
97 ([poke-num] (read-OT-id @current-state poke-num)))
98
99 (defn set-OT-id
100 ([^SaveState state poke-num new-OT-num]
101 (assert (<= 0 poke-num 5))
102 (assert (<= 0 new-OT-num 0xFFFF))
89 (set-memory-range 103 (set-memory-range
90 state 104 state
91 (OT-ID-addresses n) 105 (OT-ID-addresses poke-num)
92 [(bit-shift-right (bit-and new-id 0xFF00) 8) 106 (disect-bytes-2 new-OT-num)))
93 (bit-and new-id 0xFF) 107 ([poke-num new-OT-num]
94 ])) 108 (set-pokemon-id @current-state poke-num new-OT-num)))
95 ([n new-id]
96 (set-pokemon-id @current-state n new-id)))
97 109
98 (def unknown "[[[UNKNOWN]]]") 110 (def unknown "[[[UNKNOWN]]]")
99 111
100 (def unknown "") 112 (def unknown "")
101 113
202 moves-pp (mapv (partial read-pp state 214 moves-pp (mapv (partial read-pp state
203 poke-num) 215 poke-num)
204 (range (count moves))) 216 (range (count moves)))
205 nickname (pokemon-nickname state poke-num) 217 nickname (pokemon-nickname state poke-num)
206 status (read-status state poke-num) 218 status (read-status state poke-num)
219 stats (read-stats state poke-num)
207 experience (read-experience state poke-num) 220 experience (read-experience state poke-num)
221 OT-name (read-OT-name state poke-num)
222 ID (read-OT-id state poke-num)
208 ] 223 ]
209 224
210 {:name nickname 225 {:name nickname
211 :species species 226 :species species
212 :species2 species2 227 :species2 species2
213 :type type 228 :type type
214 :dv dv-values 229 :dv dv-values
230 :original-trainer OT-name
231 :ID ID
232
215 :moves (zipmap moves moves-pp) 233 :moves (zipmap moves moves-pp)
216 234
217 :satus status 235 :satus status
236 :stats stats
218 :experience experience 237 :experience experience
238
219 } 239 }
220 )) 240 ))
221 ([poke-num] 241 ([poke-num]
222 (pokemon-info @current-state poke-num))) 242 (pokemon-info @current-state poke-num)))
223 243
244
245 (defn give-status-all
246 ([^SaveState state status]
247 (reduce (fn [state num]
248 (give-status state num status))
249 state
250 (range (party-number state))))
251 ([status]
252 (give-status-all @current-state status)))