comparison clojure/com/aurellem/gb/moves.clj @ 190:9a7a46c4aa1b

extending functionality of support namespaces in prepreation of give-pokemon
author Robert McIntyre <rlm@mit.edu>
date Thu, 22 Mar 2012 16:34:10 -0500
parents 9c3769060201
children 893c753f8088
comparison
equal deleted inserted replaced
189:d954835b24a4 190:9a7a46c4aa1b
2 (:use (com.aurellem.gb gb-driver util constants)) 2 (:use (com.aurellem.gb gb-driver util constants))
3 (:import [com.aurellem.gb.gb_driver SaveState])) 3 (:import [com.aurellem.gb.gb_driver SaveState]))
4 4
5 (def move-code->move-name 5 (def move-code->move-name
6 { 6 {
7 0x00 :end-of-moves
7 0x01 :pound 8 0x01 :pound
8 0x02 :karate-chop 9 0x02 :karate-chop
9 0x03 :doubleslap 10 0x03 :doubleslap
10 0x04 :comet-punch 11 0x04 :comet-punch
11 0x05 :mega-punch 12 0x05 :mega-punch
168 0xA2 :super-fang 169 0xA2 :super-fang
169 0xA3 :slash 170 0xA3 :slash
170 0xA4 :substitute 171 0xA4 :substitute
171 0xA5 :struggle}) 172 0xA5 :struggle})
172 173
174 (def move-name->move-code
175 (zipmap (vals move-code->move-name)
176 (keys move-code->move-name)))
177
173 (def moves-codes-pokemon-1 0xD172) 178 (def moves-codes-pokemon-1 0xD172)
174 179
175 (defn moves-codes-start [pokemon-num] 180 (defn moves-codes-start [pokemon-num]
176 (assert (<= 0 pokemon-num 5)) 181 (assert (<= 0 pokemon-num 5))
177 (+ moves-codes-pokemon-1 182 (+ moves-codes-pokemon-1
178 (* pokemon-num pokemon-record-width))) 183 (* pokemon-num pokemon-record-width)))
179 184
180 (def move-name->move-code 185 (defn read-moves
181 (zipmap (vals move-code->move-name) 186 ([^SaveState state poke-num]
182 (keys move-code->move-name))) 187 (let [start (moves-codes-start poke-num)]
188 (vec
189 (take-while
190 (partial not= (move-name->move-code :end-of-moves))
191 (map
192 move-code->move-name
193 (subvec (vec (memory state))
194 start (+ start (num-moves state poke-num))))))))
195 ([poke-num]
196 (read-moves @current-state poke-num)))
197
198
183 199
184 (defn give-moves 200 (defn give-moves
185 ([^SaveState state pokemon-num moves] 201 ([^SaveState state pokemon-num moves]
186 (set-memory-range 202 (set-memory-range
187 state 203 state
245 "00111111" 2) 261 "00111111" 2)
246 current-pp)))) 262 current-pp))))
247 ([pokemon-num move-num pp-ups current-pp] 263 ([pokemon-num move-num pp-ups current-pp]
248 (give-pp @current-state 264 (give-pp @current-state
249 pokemon-num move-num pp-ups current-pp))) 265 pokemon-num move-num pp-ups current-pp)))
266