Mercurial > vba-clojure
view clojure/com/aurellem/gb/moves.clj @ 204:43bb461a7419
constructing default types....
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 23 Mar 2012 04:19:38 -0500 |
parents | 5055ec9de278 |
children | 912496041f98 |
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)))268 (def move-name->move-pp269 {270 :absorb 20271 :acid 30272 :acid-armor 40 ;; WTF happens with 3 PP-UPs??!273 :agility 30274 :amnesia 20275 :aurora-beam 20276 :barrage 20277 :barrier 30278 :bide 10279 :bind 20280 :bite 25281 :blizzard 5282 :body-slam 15283 :bone-club 20284 :bonemerang 10285 :bubble 30286 :bubblebeam 20287 :clamp 10288 :comet-punch 15289 :confuse-ray 10290 :confusion 25291 :constrict 35292 :conversion 30293 :counter 20294 :crabhammer 10295 :cut 30296 :defense-curl 40297 :dig 10298 :disable 20299 :dizzy-punch 10300 :double-edge 15301 :double-kick 30302 :double-team 10303 :doubleslap 15304 :dragon-rage 10305 :dream-eater 15306 :drill-peck 20307 :earthquake 10308 :egg-bomb 10309 :ember 25310 :explosion 5311 :fire-blast 5312 :fire-punch 15313 :fire-spin 15314 :fissure 5315 :flamethrower 15316 :flash 20317 :fly 15318 :focus-energy 30319 :fury-attack 20320 :fury-swipes 15321 :glare 30322 :growl 40323 :growth 40324 :guillotine 5325 :gust 35326 :harden 30327 :haze 30328 :headbutt 15329 :hi-jump-kick 20330 :horn-attack 25331 :horn-drill 5332 :hydro-pump 5333 :hyper-beam 5334 :hyper-fang 15335 :hypnosis 20336 :ice-beam 10337 :ice-punch 15338 :jump-kick 25339 :karate-chop 25340 :kinesis 15341 :leech-life 15342 :leech-seed 10343 :leer 30344 :lick 30345 :light-screen 30346 :lovely-kiss 10347 :low-kick 20348 :meditate 40349 :mega-drain 10350 :mega-kick 5351 :mega-punch 20352 :metronome 10353 :mimic 10354 :minimize 20355 :mirror-move 20356 :mist 30357 :night-shade 15358 :pay-day 20359 :peck 35360 :petal-dance 20361 :pin-missle 20362 :poison-gas 40363 :poison-sting 35364 :poisonpowder 35365 :pound 35366 :psybeam 20367 :psychic 10368 :psywave 15369 :quick-attack 30370 :rage 20371 :razor-leaf 25372 :razor-wind 10373 :recover 20374 :reflect 20375 :rest 10376 :roar 20377 :rock-slide 10378 :rock-throw 15379 :rolling-kick 15380 :sand-attack 15381 :scratch 30382 :screech 40383 :seismic-toss 20384 :selfdestruct 5385 :sharpen 30386 :sing 15387 :skull-bash 15388 :sky-attack 5389 :slam 20390 :slash 20391 :sleep-powder 15392 :sludge 20393 :smog 20394 :smokescreen 20395 :softboiled 10396 :solarbeam 10397 :sonicboom 20398 :spike-cannon 15399 :splash 40400 :spore 15401 :stomp 20402 :strength 15403 :string-shot 40404 :struggle 1405 :stun-spore 30406 :submission 25407 :substitute 10408 :super-fang 10409 :supersonic 20410 :surf 15411 :swift 20412 :swords-dance 30413 :tackle 35414 :tail-whip 30415 :take-down 20416 :teleport 20417 :thrash 20418 :thunder 10419 :thunder-wave 20420 :thunderbolt 15421 :thunderpunch 15422 :thundershock 30423 :toxic 10424 :transform 10425 :tri-attack 10426 :twinneedle 20427 :vicegrip 30428 :vine-whip 10429 :water-gun 25430 :waterfall 15431 :whirlwind 20432 :wing-attack 35433 :withdraw 40434 :wrap 20})436 (defn max-pp [name pp-ups]437 (int (* (+ 1 (* (/ 1 5) pp-ups))438 (move-name->move-pp name))))