Mercurial > vba-clojure
view clojure/com/aurellem/gb/hxc.clj @ 258:2a46422902be
script: got pikachu.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 26 Mar 2012 18:01:39 -0500 |
parents | 2b6bd03feb4f |
children | b2f9a0cb13e3 |
line wrap: on
line source
1 (ns com.aurellem.gb.hxc2 (:use (com.aurellem.gb assembly characters gb-driver util3 constants))4 (:use (com.aurellem.world practice))5 (:import [com.aurellem.gb.gb_driver SaveState]))10 ; ************* HANDWRITTEN CONSTANTS12 (def pkmn-types13 [:normal14 :fighting15 :flying16 :poison17 :ground18 :rock19 :bird20 :bug21 :ghost22 :A23 :B24 :C25 :D26 :E27 :F28 :G29 :H30 :I31 :J32 :K33 :fire34 :water35 :grass36 :electric37 :psychic38 :ice39 :dragon40 ])43 ;; question: when status effects claim to take44 ;; their accuracy from the move accuracy, does45 ;; this mean that the move always "hits" but the46 ;; status effect may not?48 (def move-effects49 ["normal damage"50 "no damage, just opponent sleep" ;; how many turns? is atk power ignored?51 "0x4C chance of poison"52 "leech half of inflicted damage"53 "0x19 chance of burn"54 "0x19 chance of freeze"55 "0x19 chance of paralyze"56 "user faints; opponent defense halved."57 "leech half of inflicted damage ONLY if sleeping opponent."58 "imitate last attack"59 "user atk +1"60 "user def +1"61 "user spd +1"62 "user spc +1"63 "user acr +1" ;; unused?!64 "user evd +1"65 "get post-battle $ = 2*level*uses"66 "0xFE acr, no matter what."67 "opponent atk -1" ;; acr taken from move acr?68 "opponent def -1" ;;69 "opponent spd -1" ;;70 "opponent spc -1" ;;71 "opponent acr -1";;72 "opponent evd -1"73 "converts user's type to opponent's."74 "(haze)"75 "(bide)"76 "(thrash)"77 "(teleport)"78 "(fury swipes)"79 "attacks 2-5 turns" ;; unused? like rollout?80 "0x19 chance of flinch"81 "opponent sleep for 1-7 turns"82 "0x66 chance of poison"83 "0x4D chance of burn"84 "0x4D chance of freeze"85 "0x4D chance of paralyze"86 "0x4D chance of flinch"87 "one-hit KO"88 "charge one turn, atk next."89 "fixed damage, leaves 1HP." ;; how is dmg determined?90 "fixed damage." ;; cf seismic toss, dragon rage, psywave.91 "atk 2-5 turns; opponent can't attack" ;; unnormalized? (0 0x60 0x60 0x20 0x20)92 "charge one turn, atk next. (can't be hit when charging)"93 "atk hits twice."94 "user takes 1 damage if misses."95 "evade status-lowering effects" ;;caused by you or also your opponent?96 "(broken) if user is slower than opponent, makes critical hit impossible, otherwise has no effect"97 "atk causes recoil dmg = 1/4 dmg dealt"98 "confuses opponent" ;; acr taken from move acr99 "user atk +2"100 "user def +2"101 "user spd +2"102 "user spc +2"103 "user acr +2" ;; unused!104 "user evd +2" ;; unused!105 "restores up to half of user's max hp." ;; broken: fails if the difference106 ;; b/w max and current hp is one less than a multiple of 256.107 "(transform)"108 "opponent atk -2"109 "opponent def -2"110 "opponent spd -2"111 "opponent spc -2"112 "opponent acr -2"113 "opponent evd -2"114 "doubles user spc when attacked"115 "doubles user def when attacked"116 "just poisons opponent" ;;acr taken from move acr117 "just paralyzes opponent" ;;118 "0x19 chance opponent atk -1"119 "0x19 chance opponent def -1"120 "0x19 chance opponent spd -1"121 "0x4C chance opponent spc -1" ;; context suggest chance is 0x19122 "0x19 chance opponent acr -1"123 "0x19 chance opponent evd -1"124 "???" ;; unused? no effect?125 "???" ;; unused? no effect?126 "0x19 chance opponent confused"127 "atk hits twice. 0x33 chance opponent poisioned."128 "broken. crash the game after attack."129 "(substitute)"130 "unless opponent faints, user must recharge after atk. some131 exceptions apply."132 "(rage)"133 "(mimic)"134 "(metronome)"135 "(leech seed)"136 "does nothing (splash)"137 "(disable)"138 ])141 ;; ************** HARDCODED DATA143 (defn hxc-thunk144 "Creates a thunk (unary fn) that grabs data in a certain region of rom and145 splits it into a collection by 0x50. If rom is not supplied, uses the146 original rom data."147 [start length]148 (fn self149 ([rom]150 (take-nth 2151 (partition-by #(= % 0x50)152 (take length153 (drop start rom)))))154 ([]155 (self com.aurellem.gb.gb-driver/original-rom))))157 (def hxc-thunk-words158 "Same as hxc-thunk, except it interprets the rom data as characters,159 returning a collection of strings."160 (comp161 (partial comp (partial map character-codes->str))162 hxc-thunk))165 ;; --------------------------------------------------167 (def hxc-items168 "The hardcoded names of the items in memory. List begins at169 ROM@045B7"170 (hxc-thunk-words 0x45B7 870))172 (def hxc-types173 "The hardcoded type names in memory. List begins at ROM@27D99,174 shortly before hxc-titles."175 (hxc-thunk-words 0x27D99 102))177 (def hxc-titles178 "The hardcoded names of the trainer titles in memory. List begins at179 ROM@27E77"180 (hxc-thunk-words 0x27E77 196))182 (def hxc-places183 "The hardcoded place names in memory. List begins at184 ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated."185 (hxc-thunk-words 0x71500 560))188 (defn hxc-dialog189 "The hardcoded dialogue in memory, including in-game alerts. Dialog190 seems to be separated by 0x57 instead of 0x50 (END). Begins at ROM@98000."191 ([rom]192 (map character-codes->str193 (take-nth 2194 (partition-by #(= % 0x57)195 (take 0x0F728196 (drop 0x98000 rom))))))197 ([]198 (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))201 (def hxc-pokedex202 "The hardcoded pokedex entries in memory. List begins at203 ROM@B8000, shortly before move names."204 (hxc-thunk-words 0xB8000 14754))206 (def hxc-move-names207 "The hardcoded move names in memory. List begins at ROM@BC000"208 (hxc-thunk-words 0xBC000 1551))211 (defn hxc-move-data212 "The hardcoded (basic (move effects)) in memory. List begins at213 0x38000. Returns a map of {:name :power :accuracy :pp :fx-id214 :fx-txt}. The move descriptions are handwritten, not hardcoded."215 ([]216 (hxc-move-data com.aurellem.gb.gb-driver/original-rom))217 ([rom]218 (let [names (vec (hxc-move-names rom))219 move-count (count names)220 move-size 6221 format-name (fn [s]222 (keyword (.toLowerCase223 (apply str224 (map #(if (= % \space) "-" %) s)))))]225 (zipmap (map format-name names)226 (map227 (fn [[idx effect power type accuracy pp]]228 {:name (names (dec idx))229 :power power230 :accuracy accuracy231 :pp pp232 :fx-id effect233 :fx-txt (get move-effects effect)234 }235 )237 (partition move-size238 (take (* move-size move-count)239 (drop 0x38000 rom))))))))243 (defn hxc-move-data*244 "Like hxc-move-data, but reports numbers as hexadecimal symbols instead."245 ([]246 (hxc-move-data* com.aurellem.gb.gb-driver/original-rom))247 ([rom]248 (let [names (vec (hxc-move-names rom))249 move-count (count names)250 move-size 6251 format-name (fn [s]252 (keyword (.toLowerCase253 (apply str254 (map #(if (= % \space) "-" %) s)))))255 ]256 (zipmap (map format-name names)257 (map258 (fn [[idx effect power type accuracy pp]]259 {:name (names (dec idx))260 :power power261 :accuracy (hex accuracy)262 :pp pp263 :fx-id (hex effect)264 :fx-txt (get move-effects effect)265 }266 )268 (partition move-size269 (take (* move-size move-count)270 (drop 0x38000 rom))))))))274 (defn hxc-pokenames275 "The hardcoded names of the 190 species in memory. List begins at276 ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters277 long, these names are stripped of padding."278 ([]279 (hxc-pokenames com.aurellem.gb.gb-driver/original-rom))280 ([rom]281 (let [count-species 190282 name-length 10]283 (map character-codes->str284 (partition name-length285 (map #(if (= 0x50 %) 0x00 %)286 (take (* count-species name-length)287 (drop 0xE8000288 rom))))))))290 (defn hxc-advantage291 "The hardcoded type advantages in memory, returned as tuples of atk-type def-type multiplier. By default (i.e. if not listed here),292 the multiplier is 1."293 ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom))294 ([rom]295 (map296 (fn [[atk def mult]] [(get pkmn-types atk (hex atk))297 (get pkmn-types def (hex def))298 (/ mult 10)])299 (partition 3300 (take-while (partial not= 0xFF)301 (drop 0x3E62D rom))))))312 ;; ********************** MANIPULATION FNS317 (defn submap?318 "Compares the two maps. Returns true if map-big has the same associations as map-small, otherwise false."319 [map-small map-big]320 (cond (empty? map-small) true321 (and322 (contains? map-big (ffirst map-small))323 (= (get map-big (ffirst map-small))324 (second (first map-small))))325 (recur (next map-small) map-big)327 :else false))330 (defn search-map [proto-map maps]331 "Returns all the maps that make the same associations as proto-map."332 (some (partial submap? proto-map) maps))334 (defn filter-vals335 "Returns a map consisting of all the pairs [key val] for336 which (pred key) returns true."337 [pred map]338 (reduce (partial apply assoc) {}339 (filter (fn [[k v]] (pred v)) map)))342 (defn search-moves343 "Returns a subcollection of all hardcoded moves with the344 given attributes. Attributes consist of :name :power345 :accuracy :pp :fx-id346 (and also :fx-txt, but it contains the same information347 as :fx-id)"348 ([attribute-map]349 (search-moves350 com.aurellem.gb.gb-driver/original-rom attribute-map))351 ([rom attribute-map]352 (filter-vals (partial submap? attribute-map)353 (hxc-move-data rom))))365 ;; note for later: credits start at F1290369 (comment371 (def hxc-later372 "Running this code produces, e.g. hardcoded names NPCs give373 their pokemon. Will sort through it later."374 (print (character-codes->str(take 10000375 (drop 0x71597376 (rom (root)))))))378 (let [dex379 (partition-by #(= 0x50 %)380 (take 2540381 (drop 0x40687382 (rom (root)))))]383 (def dex dex)384 (def hxc-species385 (map character-codes->str386 (take-nth 4 dex))))387 )