diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/clojure/com/aurellem/gb/moves.clj	Tue Mar 20 17:18:22 2012 -0500
     1.3 @@ -0,0 +1,242 @@
     1.4 +(ns com.aurellem.gb.moves
     1.5 +  (:use (com.aurellem.gb gb-driver util constants))
     1.6 +  (:import [com.aurellem.gb.gb_driver SaveState]))
     1.7 +
     1.8 +(def move-code->move-name
     1.9 +  {
    1.10 +   0x01   :pound
    1.11 +   0x02   :karate-chop
    1.12 +   0x03   :doubleslap
    1.13 +   0x04   :comet-punch
    1.14 +   0x05   :mega-punch
    1.15 +   0x06   :pay-day
    1.16 +   0x07   :fire-punch
    1.17 +   0x08   :ice-punch
    1.18 +   0x09   :thunderpunch
    1.19 +   0x0A   :scratch
    1.20 +   0x0B   :vicegrip
    1.21 +   0x0C   :guillotine
    1.22 +   0x0D   :razor-wind
    1.23 +   0x0E   :swords-dance
    1.24 +   0x0F   :cut
    1.25 +   0x10   :gust
    1.26 +   0x11   :wing-attack
    1.27 +   0x12   :whirlwind
    1.28 +   0x13   :fly
    1.29 +   0x14   :bind
    1.30 +   0x15   :slam
    1.31 +   0x16   :vine-whip
    1.32 +   0x17   :stomp
    1.33 +   0x18   :double-kick
    1.34 +   0x19   :mega-kick
    1.35 +   0x1A   :jump-kick
    1.36 +   0x1B   :rolling-kick
    1.37 +   0x1C   :sand-attack
    1.38 +   0x1D   :headbutt
    1.39 +   0x1E   :horn-attack
    1.40 +   0x1F   :fury-attack
    1.41 +   0x20   :horn-drill
    1.42 +   0x21   :tackle
    1.43 +   0x22   :body-slam
    1.44 +   0x23   :wrap
    1.45 +   0x24   :take-down
    1.46 +   0x25   :thrash
    1.47 +   0x26   :double-edge
    1.48 +   0x27   :tail-whip
    1.49 +   0x28   :poison-sting
    1.50 +   0x29   :twinneedle
    1.51 +   0x2A   :pin-missle
    1.52 +   0x2B   :leer
    1.53 +   0x2C   :bite
    1.54 +   0x2D   :growl
    1.55 +   0x2E   :roar
    1.56 +   0x2F   :sing
    1.57 +   0x30   :supersonic
    1.58 +   0x31   :sonicboom
    1.59 +   0x32   :disable
    1.60 +   0x33   :acid
    1.61 +   0x34   :ember
    1.62 +   0x35   :flamethrower
    1.63 +   0x36   :mist
    1.64 +   0x37   :water-gun
    1.65 +   0x38   :hydro-pump
    1.66 +   0x39   :surf
    1.67 +   0x3A   :ice-beam
    1.68 +   0x3B   :blizzard
    1.69 +   0x3C   :psybeam
    1.70 +   0x3D   :bubblebeam
    1.71 +   0x3E   :aurora-beam
    1.72 +   0x3F   :hyper-beam
    1.73 +   0x40   :peck
    1.74 +   0x41   :drill-peck
    1.75 +   0x42   :submission
    1.76 +   0x43   :low-kick
    1.77 +   0x44   :counter
    1.78 +   0x45   :seismic-toss
    1.79 +   0x46   :strength
    1.80 +   0x47   :absorb
    1.81 +   0x48   :mega-drain
    1.82 +   0x49   :leech-seed
    1.83 +   0x4A   :growth
    1.84 +   0x4B   :razor-leaf
    1.85 +   0x4C   :solarbeam
    1.86 +   0x4D   :poisonpowder
    1.87 +   0x4E   :stun-spore
    1.88 +   0x4F   :sleep-powder
    1.89 +   0x50   :petal-dance
    1.90 +   0x51   :string-shot
    1.91 +   0x52   :dragon-rage
    1.92 +   0x53   :fire-spin
    1.93 +   0x54   :thundershock
    1.94 +   0x55   :thunderbolt
    1.95 +   0x56   :thunder-wave
    1.96 +   0x57   :thunder
    1.97 +   0x58   :rock-throw
    1.98 +   0x59   :earthquake
    1.99 +   0x5A   :fissure
   1.100 +   0x5B   :dig
   1.101 +   0x5C   :toxic
   1.102 +   0x5D   :confusion
   1.103 +   0x5E   :psychic
   1.104 +   0x5F   :hypnosis
   1.105 +   0x60   :meditate
   1.106 +   0x61   :agility
   1.107 +   0x62   :quick-attack
   1.108 +   0x63   :rage
   1.109 +   0x64   :teleport
   1.110 +   0x65   :night-shade
   1.111 +   0x66   :mimic
   1.112 +   0x67   :screech
   1.113 +   0x68   :double-team
   1.114 +   0x69   :recover
   1.115 +   0x6A   :harden
   1.116 +   0x6B   :minimize
   1.117 +   0x6C   :smokescreen
   1.118 +   0x6D   :confuse-ray
   1.119 +   0x6E   :withdraw
   1.120 +   0x6F   :defense-curl
   1.121 +   0x70   :barrier
   1.122 +   0x71   :light-screen
   1.123 +   0x72   :haze
   1.124 +   0x73   :reflect
   1.125 +   0x74   :focus-energy
   1.126 +   0x75   :bide
   1.127 +   0x76   :metronome
   1.128 +   0x77   :mirror-move
   1.129 +   0x78   :selfdestruct
   1.130 +   0x79   :egg-bomb
   1.131 +   0x7A   :lick
   1.132 +   0x7B   :smog
   1.133 +   0x7C   :sludge
   1.134 +   0x7D   :bone-club
   1.135 +   0x7E   :fire-blast
   1.136 +   0x7F   :waterfall
   1.137 +   0x80   :clamp
   1.138 +   0x81   :swift
   1.139 +   0x82   :skull-bash
   1.140 +   0x83   :spike-cannon
   1.141 +   0x84   :constrict
   1.142 +   0x85   :amnesia
   1.143 +   0x86   :kinesis
   1.144 +   0x87   :softboiled
   1.145 +   0x88   :hi-jump-kick
   1.146 +   0x89   :glare
   1.147 +   0x8A   :dream-eater
   1.148 +   0x8B   :poison-gas
   1.149 +   0x8C   :barrage
   1.150 +   0x8D   :leech-life
   1.151 +   0x8E   :lovely-kiss
   1.152 +   0x8F   :sky-attack
   1.153 +   0x90   :transform
   1.154 +   0x91   :bubble
   1.155 +   0x92   :dizzy-punch
   1.156 +   0x93   :spore
   1.157 +   0x94   :flash
   1.158 +   0x95   :psywave
   1.159 +   0x96   :splash
   1.160 +   0x97   :acid-armor
   1.161 +   0x98   :crabhammer
   1.162 +   0x99   :explosion
   1.163 +   0x9A   :fury-swipes
   1.164 +   0x9B   :bonemerang
   1.165 +   0x9C   :rest
   1.166 +   0x9D   :rock-slide
   1.167 +   0x9E   :hyper-fang
   1.168 +   0x9F   :sharpen
   1.169 +   0xA0   :conversion
   1.170 +   0xA1   :tri-attack
   1.171 +   0xA2   :super-fang
   1.172 +   0xA3   :slash
   1.173 +   0xA4   :substitute
   1.174 +   0xA5   :struggle})
   1.175 +
   1.176 +(def move-name->move-code
   1.177 +  (zipmap (vals move-code->move-name)
   1.178 +          (keys move-code->move-name)))
   1.179 +
   1.180 +(defn give-moves
   1.181 +  ([^SaveState state pokemon-num moves]
   1.182 +     (set-memory-range
   1.183 +      state
   1.184 +      (moves-codes-start pokemon-num)
   1.185 +      (map #(move-name->move-code % %) moves)))
   1.186 +  ([pokemon-num moves]
   1.187 +     (give-moves @current-state pokemon-num moves))
   1.188 +  ([moves]
   1.189 +     (give-moves 0 moves)))
   1.190 +
   1.191 +;; Note regarding PP of moves -- both the current PP and the
   1.192 +;; total PP are stored in the same value.
   1.193 +;; they are bit-packed, with the first 2 bits containing the
   1.194 +;; number of pp-ups that have been applied, and the next
   1.195 +;; six bits containing the current pp of the move.
   1.196 +;; thus, a move can have up to 63 current pp and up to
   1.197 +;; three pp-ups applied.
   1.198 +
   1.199 +
   1.200 +(def pokemon-1-pp-start 0xD187)
   1.201 +
   1.202 +(defn moves-pp-start [pokemon-num]
   1.203 +  (assert (<= 0 pokemon-num 5))
   1.204 +  (+ pokemon-1-pp-start (* pokemon-num pokemon-record-width)))
   1.205 +
   1.206 +(defn read-pp
   1.207 +  ([^SaveState state pokemon-num move-num]
   1.208 +     (assert (<= 0 move-num 3))
   1.209 +     (assert (<= 0 pokemon-num 5))
   1.210 +     (let [pp-raw
   1.211 +           (aget (memory state)
   1.212 +                 (+ (moves-pp-start pokemon-num)
   1.213 +                    move-num))
   1.214 +           pp-up
   1.215 +           (bit-shift-right
   1.216 +            (bit-and
   1.217 +             pp-raw
   1.218 +             (Integer/parseInt "11000000" 2)) 6)
   1.219 +           current-pp
   1.220 +           (bit-and
   1.221 +            pp-raw
   1.222 +            (Integer/parseInt "00111111" 2))]
   1.223 +       [pp-up current-pp]))
   1.224 +  ([pokemon-num move-num]
   1.225 +     (read-pp @current-state pokemon-num move-num)))
   1.226 +
   1.227 +(defn give-pp
   1.228 +  ([^SaveState state pokemon-num move-num pp-ups current-pp]
   1.229 +     (assert (<= 0 move-num 3))
   1.230 +     (assert (<= 0 pokemon-num 5))
   1.231 +     (assert (<= 0 pp-ups 3))
   1.232 +     (assert (<= 0 current-pp 63))
   1.233 +
   1.234 +     (set-memory
   1.235 +      state
   1.236 +      (+ (moves-pp-start pokemon-num)
   1.237 +         move-num)
   1.238 +      (+
   1.239 +       (bit-shift-left pp-ups 6)
   1.240 +       (bit-and (Integer/parseInt
   1.241 +                 "00111111" 2)
   1.242 +                current-pp))))
   1.243 +  ([pokemon-num move-num pp-ups current-pp]
   1.244 +     (set-pp @current-state
   1.245 +             pokemon-num move-num pp-ups current-pp)))