view clojure/com/aurellem/gb/moves.clj @ 225:0587f266a735

added functions for setting rival's name and text speed
author Robert McIntyre <rlm@mit.edu>
date Sat, 24 Mar 2012 05:26:33 -0500
parents 62969eb07e04
children ca1afcef3542
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)))
267 (defn give-moves-pps
268 ([^SaveState state poke-num moves-pps]
269 (let [new-moves
270 (-> state
271 ;; zero out the pp of the pokemon's moves
272 (give-pp poke-num 0 0 0)
273 (give-pp poke-num 1 0 0)
274 (give-pp poke-num 2 0 0)
275 (give-pp poke-num 3 0 0)
276 (give-moves poke-num (map first moves-pps)))]
277 (reduce (fn [state move-num]
278 (let [pp (second (nth moves-pps move-num))]
279 (give-pp state poke-num move-num
280 (:pp-ups pp)
281 (:current-pp pp))))
282 new-moves (range (count moves-pps)))))
283 ([poke-num moves-pps]
284 (give-moves-pps @current-state poke-num moves-pps)))
287 (def move-name->move-pp
288 {
289 :absorb 20
290 :acid 30
291 :acid-armor 40 ;; WTF happens with 3 PP-UPs??! (answer: 61PP!)
292 :agility 30
293 :amnesia 20
294 :aurora-beam 20
295 :barrage 20
296 :barrier 30
297 :bide 10
298 :bind 20
299 :bite 25
300 :blizzard 5
301 :body-slam 15
302 :bone-club 20
303 :bonemerang 10
304 :bubble 30
305 :bubblebeam 20
306 :clamp 10
307 :comet-punch 15
308 :confuse-ray 10
309 :confusion 25
310 :constrict 35
311 :conversion 30
312 :counter 20
313 :crabhammer 10
314 :cut 30
315 :defense-curl 40
316 :dig 10
317 :disable 20
318 :dizzy-punch 10
319 :double-edge 15
320 :double-kick 30
321 :double-team 10
322 :doubleslap 15
323 :dragon-rage 10
324 :dream-eater 15
325 :drill-peck 20
326 :earthquake 10
327 :egg-bomb 10
328 :ember 25
329 :explosion 5
330 :fire-blast 5
331 :fire-punch 15
332 :fire-spin 15
333 :fissure 5
334 :flamethrower 15
335 :flash 20
336 :fly 15
337 :focus-energy 30
338 :fury-attack 20
339 :fury-swipes 15
340 :glare 30
341 :growl 40
342 :growth 40
343 :guillotine 5
344 :gust 35
345 :harden 30
346 :haze 30
347 :headbutt 15
348 :hi-jump-kick 20
349 :horn-attack 25
350 :horn-drill 5
351 :hydro-pump 5
352 :hyper-beam 5
353 :hyper-fang 15
354 :hypnosis 20
355 :ice-beam 10
356 :ice-punch 15
357 :jump-kick 25
358 :karate-chop 25
359 :kinesis 15
360 :leech-life 15
361 :leech-seed 10
362 :leer 30
363 :lick 30
364 :light-screen 30
365 :lovely-kiss 10
366 :low-kick 20
367 :meditate 40
368 :mega-drain 10
369 :mega-kick 5
370 :mega-punch 20
371 :metronome 10
372 :mimic 10
373 :minimize 20
374 :mirror-move 20
375 :mist 30
376 :night-shade 15
377 :pay-day 20
378 :peck 35
379 :petal-dance 20
380 :pin-missle 20
381 :poison-gas 40
382 :poison-sting 35
383 :poisonpowder 35
384 :pound 35
385 :psybeam 20
386 :psychic 10
387 :psywave 15
388 :quick-attack 30
389 :rage 20
390 :razor-leaf 25
391 :razor-wind 10
392 :recover 20
393 :reflect 20
394 :rest 10
395 :roar 20
396 :rock-slide 10
397 :rock-throw 15
398 :rolling-kick 15
399 :sand-attack 15
400 :scratch 35
401 :screech 40
402 :seismic-toss 20
403 :selfdestruct 5
404 :sharpen 30
405 :sing 15
406 :skull-bash 15
407 :sky-attack 5
408 :slam 20
409 :slash 20
410 :sleep-powder 15
411 :sludge 20
412 :smog 20
413 :smokescreen 20
414 :softboiled 10
415 :solarbeam 10
416 :sonicboom 20
417 :spike-cannon 15
418 :splash 40
419 :spore 15
420 :stomp 20
421 :strength 15
422 :string-shot 40
423 :struggle 1
424 :stun-spore 30
425 :submission 25
426 :substitute 10
427 :super-fang 10
428 :supersonic 20
429 :surf 15
430 :swift 20
431 :swords-dance 30
432 :tackle 35
433 :tail-whip 30
434 :take-down 20
435 :teleport 20
436 :thrash 20
437 :thunder 10
438 :thunder-wave 20
439 :thunderbolt 15
440 :thunderpunch 15
441 :thundershock 30
442 :toxic 10
443 :transform 10
444 :tri-attack 10
445 :twinneedle 20
446 :vicegrip 30
447 :vine-whip 10
448 :water-gun 25
449 :waterfall 15
450 :whirlwind 20
451 :wing-attack 35
452 :withdraw 40
453 :wrap 20})
455 (defn max-pp [name pp-ups]
456 (if (= 40 (move-name->move-pp name))
457 (+ 40 (* 7 pp-ups))
458 (int (* (+ 1 (* (/ 1 5) pp-ups))
459 (move-name->move-pp name)))))