diff clojure/com/aurellem/exp/pokemon.clj @ 176:95b2758dd517

wrote functions to read and write pokemon DV values and status
author Robert McIntyre <rlm@mit.edu>
date Wed, 21 Mar 2012 22:13:43 -0500
parents 63ec3db6f6d1
children 4f5ea93cbaca
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/exp/pokemon.clj	Wed Mar 21 18:17:37 2012 -0500
     1.2 +++ b/clojure/com/aurellem/exp/pokemon.clj	Wed Mar 21 22:13:43 2012 -0500
     1.3 @@ -116,18 +116,6 @@
     1.4    ([new-name]
     1.5       (rename-sixth-pokemon @current-state new-name)))
     1.6  
     1.7 -(defn print-text
     1.8 -  ([^SaveState state begin end]
     1.9 -     (dorun
    1.10 -      (map (fn [character-code line]
    1.11 -             (println
    1.12 -              (format "0x%04X: " line)
    1.13 -              (str (character-code->character character-code))))
    1.14 -           (subvec (vec (memory state)) begin end)
    1.15 -           (range begin end)))
    1.16 -     state)
    1.17 -  ([begin end]
    1.18 -     (print-text @current-state begin end)))
    1.19  
    1.20  (defn examine-name-memory []
    1.21    (print-text
    1.22 @@ -517,9 +505,6 @@
    1.23       (set-pokemon-id @current-state n new-id)))
    1.24  
    1.25  
    1.26 -
    1.27 -
    1.28 -
    1.29  (defn get-pokemon-1-info
    1.30    ([state]
    1.31       (subvec (vec (memory state))
    1.32 @@ -733,117 +718,33 @@
    1.33  ;; 10000000
    1.34  ;; Speed => 210   (+16)
    1.35  
    1.36 -(def pokemon-1-DV-start 0xD185)
    1.37  
    1.38 -(defn pokemon-DV-start-point [poke-num]
    1.39 -  (+ (* poke-num pokemon-record-width)
    1.40 -     pokemon-1-DV-start))
    1.41 +;; investigating status effects
    1.42  
    1.43 -(def reverse-4-bit
    1.44 -  {0   0
    1.45 -   1   8
    1.46 -   2   4
    1.47 -   3   12
    1.48 -   5   10
    1.49 -   6   6
    1.50 -   7   14
    1.51 -   9   9
    1.52 -   15  15
    1.53 -   13  11
    1.54 +;; status of pokemon 1 appears to be
    1.55 +;; 0xD16E
    1.56  
    1.57 -   8   1 
    1.58 -   4   2 
    1.59 -   12  3 
    1.60 -   10  5
    1.61 -   11  13
    1.62 -   14  7 })
    1.63 -   
    1.64 -(defn read-DV
    1.65 -  ([^SaveState state poke-num]
    1.66 -     (assert (<= 0 poke-num 5))
    1.67 -     (let [[raw-DV-1
    1.68 -            raw-DV-2]
    1.69 -           (subvec (vec (memory state))
    1.70 -                   (pokemon-DV-start-point poke-num)
    1.71 -                   (+ 2 (pokemon-DV-start-point poke-num)))
    1.72 -           defense-DV (bit-and raw-DV-1 0x0F)
    1.73 -           attack-DV (bit-shift-right
    1.74 -                       (bit-and raw-DV-1 0xF0)
    1.75 -                        4)
    1.76 -           special-DV (bit-and raw-DV-2 0x0F)
    1.77 -           speed-DV (bit-shift-right
    1.78 -                        (bit-and raw-DV-2 0xF0)
    1.79 -                        4)
    1.80 -           HP-DV
    1.81 -           (+
    1.82 -            (if (bit-test special-DV 0)   1 0)
    1.83 -            (if (bit-test speed-DV 0)     2 0)
    1.84 -            (if (bit-test defense-DV 0)   4 0)
    1.85 -            (if (bit-test attack-DV 0)    8 0))]
    1.86 -       {:attack  attack-DV
    1.87 -        :defense  defense-DV
    1.88 -        :speed  speed-DV
    1.89 -        :special  special-DV
    1.90 -        :hp  HP-DV}))
    1.91 -  ([poke-num]
    1.92 -     (read-DV @current-state poke-num)))
    1.93 -     
    1.94 +;; with pidgeot
    1.95 +;; 00000000 -- normal
    1.96 +;; 00000001 -- sleep (wake-immediately)
    1.97 +;; 00000010 -- sleep 
    1.98 +;; 00000100 -- sleep
    1.99 +;; 00001000 -- poisoned
   1.100 +;; 00010000 -- burned
   1.101 +;; 00100000 -- frozen
   1.102 +;; 01000000 -- paralyzed
   1.103 +;; 10000000 -- ball is dark, but no status
   1.104  
   1.105 -(defn give-DV
   1.106 -  ([^SaveState state poke-num dv-values]
   1.107 -     
   1.108 -     (assert (<= 0 poke-num 5))
   1.109 -     (map #(assert (<= 0 % 15)) (vals dv-values))
   1.110 -     (let [raw-dv-1*
   1.111 -           (+ (:defense dv-values)
   1.112 -              (bit-shift-left (:attack dv-values) 4))
   1.113 -           raw-dv-2*
   1.114 -           (+ (:special dv-values)
   1.115 -              (bit-shift-left (:speed dv-values) 4))
   1.116 -           hp-dv (:hp dv-values)
   1.117 -           hp-masks-1
   1.118 -           [[0 (bit-test hp-dv 2)]
   1.119 -            [4 (bit-test hp-dv 3)]]
   1.120 -           hp-masks-2
   1.121 -           [[0 (bit-test hp-dv 0)]
   1.122 -            [4 (bit-test hp-dv 1)]]
   1.123 -           set-hp-bits
   1.124 -           (fn [init [index hp?]]
   1.125 -             (if hp?
   1.126 -               (bit-set init index)
   1.127 -               (bit-clear init index)))
   1.128 +;; with pikachu
   1.129 +;; 00000000 -- normal
   1.130 +;; 00000001 -- sleep (1 turn wasted)   \
   1.131 +;; 00000010 -- sleep (2 turns wasted)  |-- additive
   1.132 +;; 00000100 -- sleep (3 turns wasted)  /
   1.133 +;; 00001000 -- poisoned
   1.134 +;; 00010000 -- burned
   1.135 +;; 00100000 -- frozen
   1.136 +;; 01000000 -- paralyzed
   1.137 +;; 10000000 -- ball is dark, but no status
   1.138  
   1.139 -           raw-dv-1 (reduce set-hp-bits raw-dv-1*
   1.140 -                            hp-masks-1)
   1.141 -                     
   1.142 -           raw-dv-2 (reduce set-hp-bits raw-dv-2*
   1.143 -                            hp-masks-2)
   1.144 -           
   1.145 -           dv-start (pokemon-DV-start-point poke-num)]
   1.146  
   1.147 -       (if (or (not= raw-dv-1* raw-dv-1)
   1.148 -               (not= raw-dv-2* raw-dv-2))
   1.149 -         (println "Warning: inconsistent DV-values."
   1.150 -                  "Using HP settings."))
   1.151 -       
   1.152 -       (set-memory 
   1.153 -        (set-memory state dv-start raw-dv-1)
   1.154 -        (inc dv-start) raw-dv-2)))
   1.155 -  ([poke-num dv-values]
   1.156 -     (give-DV @current-state poke-num dv-values)))
   1.157 -
   1.158 -(def good-DVs
   1.159 -  {:attack  15
   1.160 -   :defense 15
   1.161 -   :speed   15
   1.162 -   :special 15
   1.163 -   :hp      15})
   1.164 -
   1.165 -(def bad-DVs
   1.166 -  {:attack  0
   1.167 -   :defense 0
   1.168 -   :speed   0
   1.169 -   :special 0
   1.170 -   :hp      0})
   1.171 -
   1.172 -   
   1.173 \ No newline at end of file
   1.174 +      
   1.175 \ No newline at end of file