view clojure/com/aurellem/gb/moves.clj @ 162:34b518fc7404

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