view clojure/com/aurellem/gb/moves.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 659764a2ea40
line wrap: on
line source
1 (ns com.aurellem.gb.moves
2 (:use (com.aurellem.gb gb-driver util constants))
3 (:import [com.aurellem.gb.gb_driver SaveState]))
5 (def move-code->move-name
6 {
7 0x00 :end-of-moves
8 0x01 :pound
9 0x02 :karate-chop
10 0x03 :doubleslap
11 0x04 :comet-punch
12 0x05 :mega-punch
13 0x06 :pay-day
14 0x07 :fire-punch
15 0x08 :ice-punch
16 0x09 :thunderpunch
17 0x0A :scratch
18 0x0B :vicegrip
19 0x0C :guillotine
20 0x0D :razor-wind
21 0x0E :swords-dance
22 0x0F :cut
23 0x10 :gust
24 0x11 :wing-attack
25 0x12 :whirlwind
26 0x13 :fly
27 0x14 :bind
28 0x15 :slam
29 0x16 :vine-whip
30 0x17 :stomp
31 0x18 :double-kick
32 0x19 :mega-kick
33 0x1A :jump-kick
34 0x1B :rolling-kick
35 0x1C :sand-attack
36 0x1D :headbutt
37 0x1E :horn-attack
38 0x1F :fury-attack
39 0x20 :horn-drill
40 0x21 :tackle
41 0x22 :body-slam
42 0x23 :wrap
43 0x24 :take-down
44 0x25 :thrash
45 0x26 :double-edge
46 0x27 :tail-whip
47 0x28 :poison-sting
48 0x29 :twinneedle
49 0x2A :pin-missle
50 0x2B :leer
51 0x2C :bite
52 0x2D :growl
53 0x2E :roar
54 0x2F :sing
55 0x30 :supersonic
56 0x31 :sonicboom
57 0x32 :disable
58 0x33 :acid
59 0x34 :ember
60 0x35 :flamethrower
61 0x36 :mist
62 0x37 :water-gun
63 0x38 :hydro-pump
64 0x39 :surf
65 0x3A :ice-beam
66 0x3B :blizzard
67 0x3C :psybeam
68 0x3D :bubblebeam
69 0x3E :aurora-beam
70 0x3F :hyper-beam
71 0x40 :peck
72 0x41 :drill-peck
73 0x42 :submission
74 0x43 :low-kick
75 0x44 :counter
76 0x45 :seismic-toss
77 0x46 :strength
78 0x47 :absorb
79 0x48 :mega-drain
80 0x49 :leech-seed
81 0x4A :growth
82 0x4B :razor-leaf
83 0x4C :solarbeam
84 0x4D :poisonpowder
85 0x4E :stun-spore
86 0x4F :sleep-powder
87 0x50 :petal-dance
88 0x51 :string-shot
89 0x52 :dragon-rage
90 0x53 :fire-spin
91 0x54 :thundershock
92 0x55 :thunderbolt
93 0x56 :thunder-wave
94 0x57 :thunder
95 0x58 :rock-throw
96 0x59 :earthquake
97 0x5A :fissure
98 0x5B :dig
99 0x5C :toxic
100 0x5D :confusion
101 0x5E :psychic
102 0x5F :hypnosis
103 0x60 :meditate
104 0x61 :agility
105 0x62 :quick-attack
106 0x63 :rage
107 0x64 :teleport
108 0x65 :night-shade
109 0x66 :mimic
110 0x67 :screech
111 0x68 :double-team
112 0x69 :recover
113 0x6A :harden
114 0x6B :minimize
115 0x6C :smokescreen
116 0x6D :confuse-ray
117 0x6E :withdraw
118 0x6F :defense-curl
119 0x70 :barrier
120 0x71 :light-screen
121 0x72 :haze
122 0x73 :reflect
123 0x74 :focus-energy
124 0x75 :bide
125 0x76 :metronome
126 0x77 :mirror-move
127 0x78 :selfdestruct
128 0x79 :egg-bomb
129 0x7A :lick
130 0x7B :smog
131 0x7C :sludge
132 0x7D :bone-club
133 0x7E :fire-blast
134 0x7F :waterfall
135 0x80 :clamp
136 0x81 :swift
137 0x82 :skull-bash
138 0x83 :spike-cannon
139 0x84 :constrict
140 0x85 :amnesia
141 0x86 :kinesis
142 0x87 :softboiled
143 0x88 :hi-jump-kick
144 0x89 :glare
145 0x8A :dream-eater
146 0x8B :poison-gas
147 0x8C :barrage
148 0x8D :leech-life
149 0x8E :lovely-kiss
150 0x8F :sky-attack
151 0x90 :transform
152 0x91 :bubble
153 0x92 :dizzy-punch
154 0x93 :spore
155 0x94 :flash
156 0x95 :psywave
157 0x96 :splash
158 0x97 :acid-armor
159 0x98 :crabhammer
160 0x99 :explosion
161 0x9A :fury-swipes
162 0x9B :bonemerang
163 0x9C :rest
164 0x9D :rock-slide
165 0x9E :hyper-fang
166 0x9F :sharpen
167 0xA0 :conversion
168 0xA1 :tri-attack
169 0xA2 :super-fang
170 0xA3 :slash
171 0xA4 :substitute
172 0xA5 :struggle})
174 (def move-name->move-code
175 (zipmap (vals move-code->move-name)
176 (keys move-code->move-name)))
178 (def moves-codes-pokemon-1 0xD172)
180 (defn moves-codes-start [pokemon-num]
181 (assert (<= 0 pokemon-num 5))
182 (+ moves-codes-pokemon-1
183 (* pokemon-num pokemon-record-width)))
185 (defn read-moves
186 ([^SaveState state poke-num]
187 (let [start (moves-codes-start poke-num)]
188 (vec
189 (take-while
190 (partial not= :end-of-moves)
191 (map
192 move-code->move-name
193 (subvec (vec (memory state))
194 start (+ start 4)))))))
195 ([poke-num]
196 (read-moves @current-state poke-num)))
198 (defn give-moves
199 ([^SaveState state pokemon-num moves]
200 (assert (<= (count moves) 4))
201 (set-memory-range
202 state
203 (moves-codes-start pokemon-num)
204 (map #(move-name->move-code % %)
205 (concat moves
206 (repeat (- 4 (count moves)) :end-of-moves)))))
207 ([pokemon-num moves]
208 (give-moves @current-state pokemon-num moves))
209 ([moves]
210 (give-moves 0 moves)))
212 ;; Note regarding PP of moves -- both the current PP and the
213 ;; total PP are stored in the same value.
214 ;; they are bit-packed, with the first 2 bits containing the
215 ;; number of pp-ups that have been applied, and the next
216 ;; six bits containing the current pp of the move.
217 ;; thus, a move can have up to 63 current pp and up to
218 ;; three pp-ups applied.
220 (def pokemon-1-pp-start 0xD187)
222 (defn moves-pp-start [pokemon-num]
223 (assert (<= 0 pokemon-num 5))
224 (+ pokemon-1-pp-start (* pokemon-num pokemon-record-width)))
226 (defn read-pp
227 ([^SaveState state pokemon-num move-num]
228 (assert (<= 0 move-num 3))
229 (assert (<= 0 pokemon-num 5))
230 (let [pp-raw
231 (aget (memory state)
232 (+ (moves-pp-start pokemon-num)
233 move-num))
234 pp-up
235 (bit-shift-right
236 (bit-and
237 pp-raw
238 (Integer/parseInt "11000000" 2)) 6)
239 current-pp
240 (bit-and
241 pp-raw
242 (Integer/parseInt "00111111" 2))]
243 {:pp-ups pp-up :current-pp current-pp}))
244 ([pokemon-num move-num]
245 (read-pp @current-state pokemon-num move-num)))
247 (defn give-pp
248 ([^SaveState state pokemon-num move-num pp-ups current-pp]
249 (assert (<= 0 move-num 3))
250 (assert (<= 0 pokemon-num 5))
251 (assert (<= 0 pp-ups 3))
252 (assert (<= 0 current-pp 63))
254 (set-memory
255 state
256 (+ (moves-pp-start pokemon-num)
257 move-num)
258 (+
259 (bit-shift-left pp-ups 6)
260 (bit-and (Integer/parseInt
261 "00111111" 2)
262 current-pp))))
263 ([pokemon-num move-num pp-ups current-pp]
264 (give-pp @current-state
265 pokemon-num move-num pp-ups current-pp)))