Mercurial > vba-clojure
view clojure/com/aurellem/gb/moves.clj @ 221:2fac825a4de9
extended range of catrography.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 24 Mar 2012 00:13:06 -0500 |
parents | 62969eb07e04 |
children | 0587f266a735 |
line wrap: on
line source
1 (ns com.aurellem.gb.moves2 (:use (com.aurellem.gb gb-driver util constants))3 (:import [com.aurellem.gb.gb_driver SaveState]))5 (def move-code->move-name6 {7 0x00 :end-of-moves8 0x01 :pound9 0x02 :karate-chop10 0x03 :doubleslap11 0x04 :comet-punch12 0x05 :mega-punch13 0x06 :pay-day14 0x07 :fire-punch15 0x08 :ice-punch16 0x09 :thunderpunch17 0x0A :scratch18 0x0B :vicegrip19 0x0C :guillotine20 0x0D :razor-wind21 0x0E :swords-dance22 0x0F :cut23 0x10 :gust24 0x11 :wing-attack25 0x12 :whirlwind26 0x13 :fly27 0x14 :bind28 0x15 :slam29 0x16 :vine-whip30 0x17 :stomp31 0x18 :double-kick32 0x19 :mega-kick33 0x1A :jump-kick34 0x1B :rolling-kick35 0x1C :sand-attack36 0x1D :headbutt37 0x1E :horn-attack38 0x1F :fury-attack39 0x20 :horn-drill40 0x21 :tackle41 0x22 :body-slam42 0x23 :wrap43 0x24 :take-down44 0x25 :thrash45 0x26 :double-edge46 0x27 :tail-whip47 0x28 :poison-sting48 0x29 :twinneedle49 0x2A :pin-missle50 0x2B :leer51 0x2C :bite52 0x2D :growl53 0x2E :roar54 0x2F :sing55 0x30 :supersonic56 0x31 :sonicboom57 0x32 :disable58 0x33 :acid59 0x34 :ember60 0x35 :flamethrower61 0x36 :mist62 0x37 :water-gun63 0x38 :hydro-pump64 0x39 :surf65 0x3A :ice-beam66 0x3B :blizzard67 0x3C :psybeam68 0x3D :bubblebeam69 0x3E :aurora-beam70 0x3F :hyper-beam71 0x40 :peck72 0x41 :drill-peck73 0x42 :submission74 0x43 :low-kick75 0x44 :counter76 0x45 :seismic-toss77 0x46 :strength78 0x47 :absorb79 0x48 :mega-drain80 0x49 :leech-seed81 0x4A :growth82 0x4B :razor-leaf83 0x4C :solarbeam84 0x4D :poisonpowder85 0x4E :stun-spore86 0x4F :sleep-powder87 0x50 :petal-dance88 0x51 :string-shot89 0x52 :dragon-rage90 0x53 :fire-spin91 0x54 :thundershock92 0x55 :thunderbolt93 0x56 :thunder-wave94 0x57 :thunder95 0x58 :rock-throw96 0x59 :earthquake97 0x5A :fissure98 0x5B :dig99 0x5C :toxic100 0x5D :confusion101 0x5E :psychic102 0x5F :hypnosis103 0x60 :meditate104 0x61 :agility105 0x62 :quick-attack106 0x63 :rage107 0x64 :teleport108 0x65 :night-shade109 0x66 :mimic110 0x67 :screech111 0x68 :double-team112 0x69 :recover113 0x6A :harden114 0x6B :minimize115 0x6C :smokescreen116 0x6D :confuse-ray117 0x6E :withdraw118 0x6F :defense-curl119 0x70 :barrier120 0x71 :light-screen121 0x72 :haze122 0x73 :reflect123 0x74 :focus-energy124 0x75 :bide125 0x76 :metronome126 0x77 :mirror-move127 0x78 :selfdestruct128 0x79 :egg-bomb129 0x7A :lick130 0x7B :smog131 0x7C :sludge132 0x7D :bone-club133 0x7E :fire-blast134 0x7F :waterfall135 0x80 :clamp136 0x81 :swift137 0x82 :skull-bash138 0x83 :spike-cannon139 0x84 :constrict140 0x85 :amnesia141 0x86 :kinesis142 0x87 :softboiled143 0x88 :hi-jump-kick144 0x89 :glare145 0x8A :dream-eater146 0x8B :poison-gas147 0x8C :barrage148 0x8D :leech-life149 0x8E :lovely-kiss150 0x8F :sky-attack151 0x90 :transform152 0x91 :bubble153 0x92 :dizzy-punch154 0x93 :spore155 0x94 :flash156 0x95 :psywave157 0x96 :splash158 0x97 :acid-armor159 0x98 :crabhammer160 0x99 :explosion161 0x9A :fury-swipes162 0x9B :bonemerang163 0x9C :rest164 0x9D :rock-slide165 0x9E :hyper-fang166 0x9F :sharpen167 0xA0 :conversion168 0xA1 :tri-attack169 0xA2 :super-fang170 0xA3 :slash171 0xA4 :substitute172 0xA5 :struggle })174 (def move-name->move-code175 (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-1183 (* pokemon-num pokemon-record-width)))185 (defn read-moves186 ([^SaveState state poke-num]187 (let [start (moves-codes-start poke-num)]188 (vec189 (take-while190 (partial not= :end-of-moves)191 (map192 move-code->move-name193 (subvec (vec (memory state))194 start (+ start 4)))))))195 ([poke-num]196 (read-moves @current-state poke-num)))198 (defn give-moves199 ([^SaveState state pokemon-num moves]200 (assert (<= (count moves) 4))201 (set-memory-range202 state203 (moves-codes-start pokemon-num)204 (map #(move-name->move-code % %)205 (concat moves206 (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 the213 ;; total PP are stored in the same value.214 ;; they are bit-packed, with the first 2 bits containing the215 ;; number of pp-ups that have been applied, and the next216 ;; six bits containing the current pp of the move.217 ;; thus, a move can have up to 63 current pp and up to218 ;; 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-pp227 ([^SaveState state pokemon-num move-num]228 (assert (<= 0 move-num 3))229 (assert (<= 0 pokemon-num 5))230 (let [pp-raw231 (aget (memory state)232 (+ (moves-pp-start pokemon-num)233 move-num))234 pp-up235 (bit-shift-right236 (bit-and237 pp-raw238 (Integer/parseInt "11000000" 2)) 6)239 current-pp240 (bit-and241 pp-raw242 (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-pp248 ([^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-memory255 state256 (+ (moves-pp-start pokemon-num)257 move-num)258 (+259 (bit-shift-left pp-ups 6)260 (bit-and (Integer/parseInt261 "00111111" 2)262 current-pp))))263 ([pokemon-num move-num pp-ups current-pp]264 (give-pp @current-state265 pokemon-num move-num pp-ups current-pp)))267 (defn give-moves-pps268 ([^SaveState state poke-num moves-pps]269 (let [new-moves270 (-> state271 ;; zero out the pp of the pokemon's moves272 (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-num280 (: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-pp288 {289 :absorb 20290 :acid 30291 :acid-armor 40 ;; WTF happens with 3 PP-UPs??!292 :agility 30293 :amnesia 20294 :aurora-beam 20295 :barrage 20296 :barrier 30297 :bide 10298 :bind 20299 :bite 25300 :blizzard 5301 :body-slam 15302 :bone-club 20303 :bonemerang 10304 :bubble 30305 :bubblebeam 20306 :clamp 10307 :comet-punch 15308 :confuse-ray 10309 :confusion 25310 :constrict 35311 :conversion 30312 :counter 20313 :crabhammer 10314 :cut 30315 :defense-curl 40316 :dig 10317 :disable 20318 :dizzy-punch 10319 :double-edge 15320 :double-kick 30321 :double-team 10322 :doubleslap 15323 :dragon-rage 10324 :dream-eater 15325 :drill-peck 20326 :earthquake 10327 :egg-bomb 10328 :ember 25329 :explosion 5330 :fire-blast 5331 :fire-punch 15332 :fire-spin 15333 :fissure 5334 :flamethrower 15335 :flash 20336 :fly 15337 :focus-energy 30338 :fury-attack 20339 :fury-swipes 15340 :glare 30341 :growl 40342 :growth 40343 :guillotine 5344 :gust 35345 :harden 30346 :haze 30347 :headbutt 15348 :hi-jump-kick 20349 :horn-attack 25350 :horn-drill 5351 :hydro-pump 5352 :hyper-beam 5353 :hyper-fang 15354 :hypnosis 20355 :ice-beam 10356 :ice-punch 15357 :jump-kick 25358 :karate-chop 25359 :kinesis 15360 :leech-life 15361 :leech-seed 10362 :leer 30363 :lick 30364 :light-screen 30365 :lovely-kiss 10366 :low-kick 20367 :meditate 40368 :mega-drain 10369 :mega-kick 5370 :mega-punch 20371 :metronome 10372 :mimic 10373 :minimize 20374 :mirror-move 20375 :mist 30376 :night-shade 15377 :pay-day 20378 :peck 35379 :petal-dance 20380 :pin-missle 20381 :poison-gas 40382 :poison-sting 35383 :poisonpowder 35384 :pound 35385 :psybeam 20386 :psychic 10387 :psywave 15388 :quick-attack 30389 :rage 20390 :razor-leaf 25391 :razor-wind 10392 :recover 20393 :reflect 20394 :rest 10395 :roar 20396 :rock-slide 10397 :rock-throw 15398 :rolling-kick 15399 :sand-attack 15400 :scratch 35401 :screech 40402 :seismic-toss 20403 :selfdestruct 5404 :sharpen 30405 :sing 15406 :skull-bash 15407 :sky-attack 5408 :slam 20409 :slash 20410 :sleep-powder 15411 :sludge 20412 :smog 20413 :smokescreen 20414 :softboiled 10415 :solarbeam 10416 :sonicboom 20417 :spike-cannon 15418 :splash 40419 :spore 15420 :stomp 20421 :strength 15422 :string-shot 40423 :struggle 1424 :stun-spore 30425 :submission 25426 :substitute 10427 :super-fang 10428 :supersonic 20429 :surf 15430 :swift 20431 :swords-dance 30432 :tackle 35433 :tail-whip 30434 :take-down 20435 :teleport 20436 :thrash 20437 :thunder 10438 :thunder-wave 20439 :thunderbolt 15440 :thunderpunch 15441 :thundershock 30442 :toxic 10443 :transform 10444 :tri-attack 10445 :twinneedle 20446 :vicegrip 30447 :vine-whip 10448 :water-gun 25449 :waterfall 15450 :whirlwind 20451 :wing-attack 35452 :withdraw 40453 :wrap 20})455 (defn max-pp [name pp-ups]456 (int (* (+ 1 (* (/ 1 5) pp-ups))457 (move-name->move-pp name))))