annotate clojure/com/aurellem/gb/hxc.clj @ 283:516acb83410f

Added the hardcoded list of moves that the TMs and HMs teach.
author Dylan Holmes <ocsenave@gmail.com>
date Wed, 28 Mar 2012 04:52:09 -0500
parents 0c3fbb313e49
children 33c546273619
rev   line source
rlm@218 1 (ns com.aurellem.gb.hxc
rlm@218 2 (:use (com.aurellem.gb assembly characters gb-driver util
ocsenave@281 3 constants species))
rlm@218 4 (:use (com.aurellem.world practice))
rlm@218 5 (:import [com.aurellem.gb.gb_driver SaveState]))
rlm@218 6
rlm@218 7
ocsenave@243 8
ocsenave@249 9
ocsenave@249 10 ; ************* HANDWRITTEN CONSTANTS
ocsenave@249 11
ocsenave@259 12
ocsenave@259 13
ocsenave@259 14 (defn low-high
ocsenave@259 15 [low high]
ocsenave@259 16 (+ low (* 256 high)))
ocsenave@259 17
ocsenave@259 18
ocsenave@259 19 (defn format-name
ocsenave@259 20 "Convert the string of alphabetic/space characters into a keyword by
ocsenave@259 21 replacing spaces with hyphens and converting to lowercase."
ocsenave@259 22 [s]
ocsenave@283 23 (if (nil? s) nil
ocsenave@259 24 (keyword (.toLowerCase
ocsenave@259 25 (apply str
ocsenave@283 26 (map #(if (= % \space) "-" %) s))))))
ocsenave@259 27
ocsenave@282 28
ocsenave@282 29 ;; used to decode item prices
ocsenave@282 30
ocsenave@282 31 (defn decode-bcd
ocsenave@282 32 "Take a sequence of binary-coded digits (in written order) and return the number they represent."
ocsenave@282 33 [digits]
ocsenave@282 34 ((fn self [coll]
ocsenave@282 35 (if (empty? coll) 0
ocsenave@282 36 (+ (first coll) (* 100 (self (rest coll))))))
ocsenave@282 37 (map
ocsenave@282 38 #(+ (* 10 (int (/ % 16)))
ocsenave@282 39 (rem % 16))
ocsenave@282 40 (reverse digits))))
ocsenave@282 41
ocsenave@282 42
ocsenave@259 43
ocsenave@259 44
ocsenave@243 45 (def pkmn-types
ocsenave@272 46 [:normal ;;0
ocsenave@272 47 :fighting ;;1
ocsenave@272 48 :flying ;;2
ocsenave@272 49 :poison ;;3
ocsenave@272 50 :ground ;;4
ocsenave@272 51 :rock ;;5
ocsenave@272 52 :bird ;;6
ocsenave@272 53 :bug ;;7
ocsenave@272 54 :ghost ;;8
ocsenave@244 55 :A
ocsenave@244 56 :B
ocsenave@244 57 :C
ocsenave@244 58 :D
ocsenave@244 59 :E
ocsenave@244 60 :F
ocsenave@244 61 :G
ocsenave@244 62 :H
ocsenave@244 63 :I
ocsenave@244 64 :J
ocsenave@244 65 :K
ocsenave@272 66 :fire ;;20 (0x14)
ocsenave@272 67 :water ;;21 (0x15)
ocsenave@272 68 :grass ;;22 (0x16)
ocsenave@272 69 :electric ;;23 (0x17)
ocsenave@272 70 :psychic ;;24 (0x18)
ocsenave@272 71 :ice ;;25 (0x19)
ocsenave@272 72 :dragon ;;26 (0x1A)
ocsenave@244 73 ])
ocsenave@243 74
ocsenave@243 75
ocsenave@246 76 ;; question: when status effects claim to take
ocsenave@246 77 ;; their accuracy from the move accuracy, does
ocsenave@246 78 ;; this mean that the move always "hits" but the
ocsenave@246 79 ;; status effect may not?
ocsenave@246 80
ocsenave@246 81 (def move-effects
ocsenave@246 82 ["normal damage"
ocsenave@246 83 "no damage, just opponent sleep" ;; how many turns? is atk power ignored?
ocsenave@246 84 "0x4C chance of poison"
ocsenave@246 85 "leech half of inflicted damage"
ocsenave@246 86 "0x19 chance of burn"
ocsenave@246 87 "0x19 chance of freeze"
ocsenave@246 88 "0x19 chance of paralyze"
ocsenave@259 89 "user faints; opponent defense halved during attack."
ocsenave@246 90 "leech half of inflicted damage ONLY if sleeping opponent."
ocsenave@246 91 "imitate last attack"
ocsenave@246 92 "user atk +1"
ocsenave@246 93 "user def +1"
ocsenave@246 94 "user spd +1"
ocsenave@246 95 "user spc +1"
ocsenave@246 96 "user acr +1" ;; unused?!
ocsenave@246 97 "user evd +1"
ocsenave@246 98 "get post-battle $ = 2*level*uses"
ocsenave@246 99 "0xFE acr, no matter what."
ocsenave@246 100 "opponent atk -1" ;; acr taken from move acr?
ocsenave@246 101 "opponent def -1" ;;
ocsenave@246 102 "opponent spd -1" ;;
ocsenave@246 103 "opponent spc -1" ;;
ocsenave@246 104 "opponent acr -1";;
ocsenave@246 105 "opponent evd -1"
ocsenave@246 106 "converts user's type to opponent's."
ocsenave@246 107 "(haze)"
ocsenave@246 108 "(bide)"
ocsenave@246 109 "(thrash)"
ocsenave@246 110 "(teleport)"
ocsenave@246 111 "(fury swipes)"
ocsenave@246 112 "attacks 2-5 turns" ;; unused? like rollout?
ocsenave@246 113 "0x19 chance of flinch"
ocsenave@246 114 "opponent sleep for 1-7 turns"
ocsenave@246 115 "0x66 chance of poison"
ocsenave@246 116 "0x4D chance of burn"
ocsenave@246 117 "0x4D chance of freeze"
ocsenave@246 118 "0x4D chance of paralyze"
ocsenave@246 119 "0x4D chance of flinch"
ocsenave@246 120 "one-hit KO"
ocsenave@246 121 "charge one turn, atk next."
ocsenave@246 122 "fixed damage, leaves 1HP." ;; how is dmg determined?
ocsenave@246 123 "fixed damage." ;; cf seismic toss, dragon rage, psywave.
ocsenave@246 124 "atk 2-5 turns; opponent can't attack" ;; unnormalized? (0 0x60 0x60 0x20 0x20)
ocsenave@246 125 "charge one turn, atk next. (can't be hit when charging)"
ocsenave@246 126 "atk hits twice."
ocsenave@246 127 "user takes 1 damage if misses."
ocsenave@246 128 "evade status-lowering effects" ;;caused by you or also your opponent?
ocsenave@246 129 "(broken) if user is slower than opponent, makes critical hit impossible, otherwise has no effect"
ocsenave@246 130 "atk causes recoil dmg = 1/4 dmg dealt"
ocsenave@246 131 "confuses opponent" ;; acr taken from move acr
ocsenave@246 132 "user atk +2"
ocsenave@246 133 "user def +2"
ocsenave@246 134 "user spd +2"
ocsenave@246 135 "user spc +2"
ocsenave@246 136 "user acr +2" ;; unused!
ocsenave@246 137 "user evd +2" ;; unused!
ocsenave@246 138 "restores up to half of user's max hp." ;; broken: fails if the difference
ocsenave@246 139 ;; b/w max and current hp is one less than a multiple of 256.
ocsenave@246 140 "(transform)"
ocsenave@246 141 "opponent atk -2"
ocsenave@246 142 "opponent def -2"
ocsenave@246 143 "opponent spd -2"
ocsenave@246 144 "opponent spc -2"
ocsenave@246 145 "opponent acr -2"
ocsenave@246 146 "opponent evd -2"
ocsenave@246 147 "doubles user spc when attacked"
ocsenave@246 148 "doubles user def when attacked"
ocsenave@249 149 "just poisons opponent" ;;acr taken from move acr
ocsenave@249 150 "just paralyzes opponent" ;;
ocsenave@246 151 "0x19 chance opponent atk -1"
ocsenave@246 152 "0x19 chance opponent def -1"
ocsenave@246 153 "0x19 chance opponent spd -1"
ocsenave@246 154 "0x4C chance opponent spc -1" ;; context suggest chance is 0x19
ocsenave@246 155 "0x19 chance opponent acr -1"
ocsenave@246 156 "0x19 chance opponent evd -1"
ocsenave@246 157 "???" ;; unused? no effect?
ocsenave@246 158 "???" ;; unused? no effect?
ocsenave@246 159 "0x19 chance opponent confused"
ocsenave@246 160 "atk hits twice. 0x33 chance opponent poisioned."
ocsenave@246 161 "broken. crash the game after attack."
ocsenave@246 162 "(substitute)"
ocsenave@246 163 "unless opponent faints, user must recharge after atk. some
ocsenave@246 164 exceptions apply."
ocsenave@246 165 "(rage)"
ocsenave@246 166 "(mimic)"
ocsenave@246 167 "(metronome)"
ocsenave@246 168 "(leech seed)"
ocsenave@246 169 "does nothing (splash)"
ocsenave@246 170 "(disable)"
ocsenave@246 171 ])
ocsenave@246 172
ocsenave@246 173
ocsenave@249 174 ;; ************** HARDCODED DATA
ocsenave@246 175
ocsenave@249 176 (defn hxc-thunk
ocsenave@259 177 "Creates a thunk (nullary fn) that grabs data in a certain region of rom and
ocsenave@249 178 splits it into a collection by 0x50. If rom is not supplied, uses the
ocsenave@249 179 original rom data."
ocsenave@249 180 [start length]
ocsenave@249 181 (fn self
ocsenave@249 182 ([rom]
ocsenave@249 183 (take-nth 2
ocsenave@249 184 (partition-by #(= % 0x50)
ocsenave@249 185 (take length
ocsenave@249 186 (drop start rom)))))
ocsenave@249 187 ([]
ocsenave@249 188 (self com.aurellem.gb.gb-driver/original-rom))))
ocsenave@246 189
ocsenave@249 190 (def hxc-thunk-words
ocsenave@249 191 "Same as hxc-thunk, except it interprets the rom data as characters,
ocsenave@249 192 returning a collection of strings."
ocsenave@249 193 (comp
ocsenave@249 194 (partial comp (partial map character-codes->str))
ocsenave@249 195 hxc-thunk))
ocsenave@249 196
ocsenave@249 197
ocsenave@249 198 ;; --------------------------------------------------
ocsenave@246 199
ocsenave@246 200 (def hxc-items
ocsenave@249 201 "The hardcoded names of the items in memory. List begins at
ocsenave@249 202 ROM@045B7"
ocsenave@249 203 (hxc-thunk-words 0x45B7 870))
ocsenave@246 204
ocsenave@246 205 (def hxc-types
ocsenave@246 206 "The hardcoded type names in memory. List begins at ROM@27D99,
ocsenave@246 207 shortly before hxc-titles."
ocsenave@249 208 (hxc-thunk-words 0x27D99 102))
ocsenave@246 209
ocsenave@246 210 (def hxc-titles
ocsenave@246 211 "The hardcoded names of the trainer titles in memory. List begins at
ocsenave@246 212 ROM@27E77"
ocsenave@249 213 (hxc-thunk-words 0x27E77 196))
ocsenave@246 214
ocsenave@259 215
ocsenave@259 216 (def hxc-pokedex-text
ocsenave@259 217 "The hardcoded pokedex entries in memory. List begins at
ocsenave@259 218 ROM@B8000, shortly before move names."
ocsenave@259 219 (hxc-thunk-words 0xB8000 14754))
ocsenave@259 220
ocsenave@259 221
ocsenave@272 222 ;; In red/blue, pokedex stats are in internal order.
ocsenave@272 223 ;; In yellow, pokedex stats are in pokedex order.
ocsenave@259 224
ocsenave@259 225 (defn hxc-pokedex-stats
ocsenave@272 226 "The hardcoded pokedex stats (species height weight) in memory. List
ocsenave@272 227 begins at ROM@40687"
ocsenave@259 228 ;; uses hxc-pokedex-text to count pokemon
ocsenave@259 229 ;; since hxc-pokenames includes several missingno"
ocsenave@259 230 ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom))
ocsenave@259 231 ([rom]
ocsenave@259 232 (let [poketext (hxc-pokedex-text)
ocsenave@259 233 pkmn-count (count poketext)
ocsenave@259 234 ]
ocsenave@259 235 ((fn capture-stats
ocsenave@259 236 [n stats data]
ocsenave@259 237 (if (zero? n) stats
ocsenave@259 238 (let [[species
ocsenave@259 239 [_
ocsenave@259 240 height-ft
ocsenave@259 241 height-in
ocsenave@259 242 weight-1
ocsenave@259 243 weight-2
ocsenave@259 244 _
ocsenave@259 245 dex-ptr-1
ocsenave@259 246 dex-ptr-2
ocsenave@259 247 dex-bank
ocsenave@259 248 _
ocsenave@259 249 & data]]
ocsenave@259 250 (split-with (partial not= 0x50) data)]
ocsenave@259 251 (recur (dec n)
ocsenave@259 252 (assoc stats
ocsenave@259 253 (- pkmn-count n)
ocsenave@259 254 {:species
ocsenave@259 255 (character-codes->str species)
ocsenave@259 256 :height-ft
ocsenave@259 257 height-ft
ocsenave@259 258 :height-in
ocsenave@259 259 height-in
ocsenave@259 260 :weight
ocsenave@259 261 (/ (low-high weight-1 weight-2) 10.)
ocsenave@259 262
ocsenave@259 263 ;; :text
ocsenave@259 264 ;; (character-codes->str
ocsenave@259 265 ;; (take-while
ocsenave@259 266 ;; (partial not= 0x50)
ocsenave@259 267 ;; (drop
ocsenave@259 268 ;; (+ 0xB8000
ocsenave@259 269 ;; -0x4000
ocsenave@259 270 ;; (low-high dex-ptr-1 dex-ptr-2))
ocsenave@259 271 ;; rom)))
ocsenave@259 272 })
ocsenave@259 273
ocsenave@259 274 data)
ocsenave@259 275
ocsenave@259 276
ocsenave@259 277 )))
ocsenave@259 278
ocsenave@259 279 pkmn-count
ocsenave@259 280 {}
ocsenave@259 281 (drop 0x40687 rom))) ))
ocsenave@259 282
ocsenave@259 283
ocsenave@259 284
ocsenave@259 285
ocsenave@259 286
ocsenave@259 287
ocsenave@259 288
ocsenave@246 289 (def hxc-places
ocsenave@246 290 "The hardcoded place names in memory. List begins at
ocsenave@249 291 ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated."
ocsenave@249 292 (hxc-thunk-words 0x71500 560))
ocsenave@246 293
ocsenave@246 294
ocsenave@249 295 (defn hxc-dialog
ocsenave@249 296 "The hardcoded dialogue in memory, including in-game alerts. Dialog
ocsenave@249 297 seems to be separated by 0x57 instead of 0x50 (END). Begins at ROM@98000."
ocsenave@249 298 ([rom]
ocsenave@249 299 (map character-codes->str
ocsenave@249 300 (take-nth 2
ocsenave@249 301 (partition-by #(= % 0x57)
ocsenave@249 302 (take 0x0F728
ocsenave@249 303 (drop 0x98000 rom))))))
ocsenave@249 304 ([]
ocsenave@249 305 (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))
ocsenave@249 306
ocsenave@246 307
ocsenave@246 308 (def hxc-move-names
ocsenave@246 309 "The hardcoded move names in memory. List begins at ROM@BC000"
ocsenave@249 310 (hxc-thunk-words 0xBC000 1551))
ocsenave@246 311
ocsenave@249 312
ocsenave@249 313 (defn hxc-move-data
ocsenave@246 314 "The hardcoded (basic (move effects)) in memory. List begins at
ocsenave@249 315 0x38000. Returns a map of {:name :power :accuracy :pp :fx-id
ocsenave@249 316 :fx-txt}. The move descriptions are handwritten, not hardcoded."
ocsenave@249 317 ([]
ocsenave@249 318 (hxc-move-data com.aurellem.gb.gb-driver/original-rom))
ocsenave@249 319 ([rom]
ocsenave@249 320 (let [names (vec (hxc-move-names rom))
ocsenave@249 321 move-count (count names)
ocsenave@281 322 move-size 6
ocsenave@281 323 types pkmn-types ;;; !! hardcoded types
ocsenave@281 324 ]
ocsenave@249 325 (zipmap (map format-name names)
ocsenave@249 326 (map
ocsenave@281 327 (fn [[idx effect power type-id accuracy pp]]
ocsenave@249 328 {:name (names (dec idx))
ocsenave@249 329 :power power
ocsenave@249 330 :accuracy accuracy
ocsenave@249 331 :pp pp
ocsenave@281 332 :type (types type-id)
ocsenave@249 333 :fx-id effect
ocsenave@249 334 :fx-txt (get move-effects effect)
ocsenave@249 335 }
ocsenave@249 336 )
ocsenave@249 337
ocsenave@249 338 (partition move-size
ocsenave@249 339 (take (* move-size move-count)
ocsenave@249 340 (drop 0x38000 rom))))))))
ocsenave@246 341
ocsenave@246 342
ocsenave@246 343
ocsenave@249 344 (defn hxc-move-data*
ocsenave@249 345 "Like hxc-move-data, but reports numbers as hexadecimal symbols instead."
ocsenave@249 346 ([]
ocsenave@249 347 (hxc-move-data* com.aurellem.gb.gb-driver/original-rom))
ocsenave@249 348 ([rom]
ocsenave@249 349 (let [names (vec (hxc-move-names rom))
ocsenave@249 350 move-count (count names)
ocsenave@249 351 move-size 6
ocsenave@249 352 format-name (fn [s]
ocsenave@249 353 (keyword (.toLowerCase
ocsenave@249 354 (apply str
ocsenave@249 355 (map #(if (= % \space) "-" %) s)))))
ocsenave@249 356 ]
ocsenave@249 357 (zipmap (map format-name names)
ocsenave@249 358 (map
ocsenave@249 359 (fn [[idx effect power type accuracy pp]]
ocsenave@249 360 {:name (names (dec idx))
ocsenave@249 361 :power power
ocsenave@249 362 :accuracy (hex accuracy)
ocsenave@249 363 :pp pp
ocsenave@249 364 :fx-id (hex effect)
ocsenave@249 365 :fx-txt (get move-effects effect)
ocsenave@249 366 }
ocsenave@249 367 )
ocsenave@249 368
ocsenave@249 369 (partition move-size
ocsenave@249 370 (take (* move-size move-count)
ocsenave@249 371 (drop 0x38000 rom))))))))
ocsenave@243 372
ocsenave@243 373
ocsenave@283 374 (defn hxc-machines
ocsenave@283 375 "The hardcoded moves taught by TMs and HMs. List begins at ROM@0x1232D."
ocsenave@283 376 ([] (hxc-machines
ocsenave@283 377 com.aurellem.gb.gb-driver/original-rom))
ocsenave@283 378 ([rom]
ocsenave@283 379 (let [moves (hxc-move-names rom)]
ocsenave@283 380 (zipmap
ocsenave@283 381 (range)
ocsenave@283 382 (take-while
ocsenave@283 383 (comp not nil?)
ocsenave@283 384 (map (comp
ocsenave@283 385 format-name
ocsenave@283 386 (zipmap
ocsenave@283 387 (range)
ocsenave@283 388 moves)
ocsenave@283 389 dec)
ocsenave@283 390 (take 100
ocsenave@283 391 (drop 0x1232D rom))))))))
ocsenave@283 392
ocsenave@249 393 (defn hxc-pokenames
ocsenave@249 394 "The hardcoded names of the 190 species in memory. List begins at
ocsenave@249 395 ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters
ocsenave@249 396 long, these names are stripped of padding."
ocsenave@249 397 ([]
ocsenave@249 398 (hxc-pokenames com.aurellem.gb.gb-driver/original-rom))
ocsenave@249 399 ([rom]
ocsenave@249 400 (let [count-species 190
ocsenave@249 401 name-length 10]
ocsenave@249 402 (map character-codes->str
ocsenave@249 403 (partition name-length
ocsenave@249 404 (map #(if (= 0x50 %) 0x00 %)
ocsenave@249 405 (take (* count-species name-length)
ocsenave@249 406 (drop 0xE8000
ocsenave@249 407 rom))))))))
ocsenave@243 408
ocsenave@259 409
ocsenave@259 410
ocsenave@259 411
ocsenave@259 412 (defn internal-id
ocsenave@259 413 ([rom]
ocsenave@259 414 (zipmap
ocsenave@259 415 (map format-name (hxc-pokenames rom))
ocsenave@259 416 (range)))
ocsenave@259 417 ([]
ocsenave@259 418 (internal-id com.aurellem.gb.gb-driver/original-rom)))
ocsenave@259 419
ocsenave@259 420
ocsenave@259 421
ocsenave@263 422 ;; nidoran gender change upon levelup
ocsenave@263 423 ;; (->
ocsenave@263 424 ;; @current-state
ocsenave@263 425 ;; rom
ocsenave@263 426 ;; vec
ocsenave@263 427 ;; (rewrite-memory
ocsenave@263 428 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♂))
ocsenave@263 429 ;; [1 1 15])
ocsenave@263 430 ;; (rewrite-memory
ocsenave@263 431 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♀))
ocsenave@263 432 ;; [1 1 3])
ocsenave@263 433 ;; (write-rom!)
ocsenave@263 434
ocsenave@263 435 ;; )
ocsenave@263 436
ocsenave@259 437
ocsenave@259 438
ocsenave@259 439
ocsenave@249 440 (defn hxc-advantage
ocsenave@249 441 "The hardcoded type advantages in memory, returned as tuples of atk-type def-type multiplier. By default (i.e. if not listed here),
ocsenave@249 442 the multiplier is 1."
ocsenave@249 443 ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom))
ocsenave@249 444 ([rom]
ocsenave@249 445 (map
ocsenave@249 446 (fn [[atk def mult]] [(get pkmn-types atk (hex atk))
ocsenave@249 447 (get pkmn-types def (hex def))
ocsenave@249 448 (/ mult 10)])
ocsenave@249 449 (partition 3
ocsenave@249 450 (take-while (partial not= 0xFF)
ocsenave@249 451 (drop 0x3E62D rom))))))
ocsenave@243 452
ocsenave@243 453
ocsenave@281 454
ocsenave@263 455 (defn format-evo
ocsenave@263 456 [coll]
ocsenave@263 457 (let [method (first coll)]
ocsenave@263 458 (cond (empty? coll) []
ocsenave@263 459 (= 0 method) [] ;; just in case
ocsenave@263 460 (= 1 method) ;; level-up evolution
ocsenave@263 461 (conj (format-evo (drop 3 coll))
ocsenave@263 462 {:method :level-up
ocsenave@263 463 :min-level (nth coll 1)
ocsenave@263 464 :into (dec (nth coll 2))})
ocsenave@263 465
ocsenave@263 466 (= 2 method) ;; item evolution
ocsenave@263 467 (conj (format-evo (drop 4 coll))
ocsenave@263 468 {:method :item
ocsenave@263 469 :item (dec (nth coll 1))
ocsenave@263 470 :min-level (nth coll 2)
ocsenave@263 471 :into (dec (nth coll 3))})
ocsenave@243 472
ocsenave@263 473 (= 3 method) ;; trade evolution
ocsenave@263 474 (conj (format-evo (drop 3 coll))
ocsenave@263 475 {:method :trade
ocsenave@263 476 :min-level (nth coll 1) ;; always 1 for trade.
ocsenave@263 477 :into (dec (nth coll 2))}))))
ocsenave@243 478
ocsenave@243 479
ocsenave@263 480 (defn hxc-ptrs-evolve
ocsenave@267 481 "A hardcoded collection of 190 pointers to alternating evolution/learnset data,
ocsenave@263 482 in internal order."
ocsenave@263 483 ([]
ocsenave@263 484 (hxc-ptrs-evolve com.aurellem.gb.gb-driver/original-rom))
ocsenave@259 485 ([rom]
ocsenave@259 486 (let [names (hxc-pokenames rom)
ocsenave@259 487 pkmn-count (count names)
ocsenave@259 488 ptrs
ocsenave@263 489 (map (fn [[a b]] (low-high a b))
ocsenave@259 490 (partition 2
ocsenave@259 491 (take (* 2 pkmn-count)
ocsenave@263 492 (drop 0x3b1e5 rom))))]
ocsenave@263 493 (map (partial + 0x34000) ptrs)
ocsenave@263 494
ocsenave@263 495 )))
ocsenave@263 496
ocsenave@267 497
ocsenave@267 498 (defn hxc-learnsets
ocsenave@267 499 "Hardcoded map associating pokemon names to lists of pairs [lvl
ocsenave@267 500 move] of abilities they learn as they level up. The data
ocsenave@267 501 exists at ROM@3400, sorted by internal order. Pointers to the data
ocsenave@267 502 exist at ROM@3B1E5; see also, hxc-ptrs-evolve"
ocsenave@267 503 ([] (hxc-learnsets com.aurellem.gb.gb-driver/original-rom))
ocsenave@267 504 ([rom]
ocsenave@267 505 (apply assoc
ocsenave@267 506 {}
ocsenave@267 507 (interleave
ocsenave@267 508 (map format-name (hxc-pokenames rom))
ocsenave@267 509 (map (comp
ocsenave@268 510 (partial map
ocsenave@268 511 (fn [[lvl mv]] [lvl (dec mv)]))
ocsenave@267 512 (partial partition 2)
ocsenave@267 513 ;; keep the learnset data
ocsenave@267 514 (partial take-while (comp not zero?))
ocsenave@267 515 ;; skip the evolution data
ocsenave@267 516 rest
ocsenave@267 517 (partial drop-while (comp not zero?)))
ocsenave@267 518 (map #(drop % rom)
ocsenave@267 519 (hxc-ptrs-evolve rom)))))))
ocsenave@267 520
ocsenave@267 521 (defn hxc-learnsets-pretty
ocsenave@267 522 "Live hxc-learnsets except it reports the name of each move --- as
ocsenave@267 523 it appears in rom --- rather than the move index."
ocsenave@267 524 ([] (hxc-learnsets-pretty com.aurellem.gb.gb-driver/original-rom))
ocsenave@267 525 ([rom]
ocsenave@267 526 (let [moves (vec(map format-name (hxc-move-names)))]
ocsenave@267 527 (into {}
ocsenave@267 528 (map (fn [[pkmn learnset]]
ocsenave@268 529 [pkmn (map (fn [[lvl mv]] [lvl (moves mv)])
ocsenave@267 530 learnset)])
ocsenave@267 531 (hxc-learnsets rom))))))
ocsenave@267 532
ocsenave@267 533
ocsenave@267 534
ocsenave@267 535
ocsenave@263 536 (defn hxc-evolution
ocsenave@263 537 "Hardcoded evolution data in memory. The data exists at ROM@34000,
ocsenave@263 538 sorted by internal order. Pointers to the data exist at ROM@3B1E5; see also, hxc-ptrs-evolve."
ocsenave@263 539 ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))
ocsenave@263 540 ([rom]
ocsenave@259 541 (apply assoc {}
ocsenave@259 542 (interleave
ocsenave@267 543 (map format-name (hxc-pokenames rom))
ocsenave@259 544 (map
ocsenave@259 545 (comp
ocsenave@259 546 format-evo
ocsenave@263 547 (partial take-while (comp not zero?))
ocsenave@263 548 #(drop % rom))
ocsenave@263 549 (hxc-ptrs-evolve rom)
ocsenave@263 550 )))))
ocsenave@259 551
ocsenave@263 552 (defn hxc-evolution-pretty
ocsenave@263 553 "Like hxc-evolution, except it uses the names of items and pokemon
ocsenave@263 554 --- grabbed from ROM --- rather than their numerical identifiers."
ocsenave@263 555 ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom))
ocsenave@263 556 ([rom]
ocsenave@263 557 (let
ocsenave@263 558 [poke-names (vec (map format-name (hxc-pokenames rom)))
ocsenave@263 559 item-names (vec (map format-name (hxc-items rom)))
ocsenave@263 560 use-names
ocsenave@263 561 (fn [m]
ocsenave@263 562 (loop [ks (keys m) new-map m]
ocsenave@263 563 (let [k (first ks)]
ocsenave@263 564 (cond (nil? ks) new-map
ocsenave@263 565 (= k :into)
ocsenave@263 566 (recur
ocsenave@263 567 (next ks)
ocsenave@263 568 (assoc new-map
ocsenave@263 569 :into
ocsenave@263 570 (poke-names
ocsenave@263 571 (:into
ocsenave@263 572 new-map))))
ocsenave@263 573 (= k :item)
ocsenave@263 574 (recur
ocsenave@263 575 (next ks)
ocsenave@263 576 (assoc new-map
ocsenave@263 577 :item
ocsenave@263 578 (item-names
ocsenave@263 579 (:item new-map))))
ocsenave@263 580 :else
ocsenave@263 581 (recur
ocsenave@263 582 (next ks)
ocsenave@263 583 new-map)
ocsenave@263 584 ))))]
ocsenave@259 585
ocsenave@263 586 (into {}
ocsenave@263 587 (map (fn [[pkmn evo-coll]]
ocsenave@263 588 [pkmn (map use-names evo-coll)])
ocsenave@263 589 (hxc-evolution rom))))))
ocsenave@263 590
ocsenave@243 591
ocsenave@243 592
ocsenave@243 593
ocsenave@243 594
ocsenave@273 595 (defn hxc-pokemon-base
ocsenave@273 596 ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom))
ocsenave@273 597 ([rom]
ocsenave@273 598 (let [entry-size 28
ocsenave@273 599 pkmn-count (count (hxc-pokedex-text rom))
ocsenave@273 600 types (apply assoc {}
ocsenave@273 601 (interleave
ocsenave@273 602 (range)
ocsenave@273 603 pkmn-types)) ;;!! softcoded
ocsenave@273 604 moves (apply assoc {}
ocsenave@273 605 (interleave
ocsenave@273 606 (range)
ocsenave@273 607 (map format-name
ocsenave@273 608 (hxc-move-names rom))))
ocsenave@273 609 ]
ocsenave@273 610 (map
ocsenave@273 611
ocsenave@273 612 (fn [[n
ocsenave@273 613 rating-hp
ocsenave@273 614 rating-atk
ocsenave@273 615 rating-def
ocsenave@273 616 rating-speed
ocsenave@273 617 rating-special
ocsenave@273 618 type-1
ocsenave@273 619 type-2
ocsenave@273 620 rarity
ocsenave@273 621 rating-xp
ocsenave@283 622 pic-dimensions ;; tile_width|tile_height (8px/tile)
ocsenave@273 623 ptr-pic-obverse-1
ocsenave@273 624 ptr-pic-obverse-2
ocsenave@273 625 ptr-pic-reverse-1
ocsenave@273 626 ptr-pic-reverse-2
ocsenave@273 627 move-1
ocsenave@273 628 move-2
ocsenave@273 629 move-3
ocsenave@273 630 move-4
ocsenave@273 631 growth-rate
ocsenave@273 632 &
ocsenave@273 633 TMs|HMs]]
ocsenave@273 634 (let
ocsenave@273 635 [base-moves
ocsenave@273 636 (mapv moves
ocsenave@273 637 ((comp
ocsenave@273 638 ;; since the game uses zero as a delimiter,
ocsenave@273 639 ;; it must also increment all move indices by 1.
ocsenave@273 640 ;; heren we decrement to correct this.
ocsenave@273 641 (partial map dec)
ocsenave@273 642 (partial take-while (comp not zero?)))
ocsenave@273 643 [move-1 move-2 move-3 move-4]))
ocsenave@273 644
ocsenave@273 645 types
ocsenave@273 646 (set (list (types type-1)
ocsenave@273 647 (types type-2)))
ocsenave@273 648 TMs|HMs
ocsenave@273 649 (map
ocsenave@273 650 (comp
ocsenave@273 651 (partial map first)
ocsenave@273 652 (partial remove (comp zero? second)))
ocsenave@273 653 (split-at
ocsenave@273 654 50
ocsenave@273 655 (map vector
ocsenave@273 656 (rest(range))
ocsenave@273 657 (reduce concat
ocsenave@273 658 (map
ocsenave@273 659 #(take 8
ocsenave@273 660 (concat (bit-list %)
ocsenave@273 661 (repeat 0)))
ocsenave@273 662
ocsenave@273 663 TMs|HMs)))))
ocsenave@273 664
ocsenave@273 665 TMs (vec (first TMs|HMs))
ocsenave@273 666 HMs (take 5 (map (partial + -50) (vec (second TMs|HMs))))
ocsenave@273 667
ocsenave@273 668
ocsenave@273 669 ]
ocsenave@273 670
ocsenave@273 671
ocsenave@273 672 {:dex# n
ocsenave@273 673 :base-moves base-moves
ocsenave@273 674 :types types
ocsenave@273 675 :TMs TMs
ocsenave@273 676 :HMs HMs
ocsenave@273 677 :base-hp rating-hp
ocsenave@273 678 :base-atk rating-atk
ocsenave@273 679 :base-def rating-def
ocsenave@273 680 :base-speed rating-speed
ocsenave@273 681 :base-special rating-special
ocsenave@273 682 }))
ocsenave@273 683
ocsenave@273 684 (partition entry-size
ocsenave@273 685 (take (* entry-size pkmn-count)
ocsenave@273 686 (drop 0x383DE
ocsenave@273 687 rom)))))))
ocsenave@282 688
ocsenave@282 689
ocsenave@282 690
ocsenave@282 691 (defn hxc-item-prices
ocsenave@282 692 "The hardcoded list of item prices in memory. List begins at ROM@4495"
ocsenave@282 693 ([] (hxc-item-prices com.aurellem.gb.gb-driver/original-rom))
ocsenave@282 694 ([rom]
ocsenave@282 695 (let [items (map format-name (hxc-items rom))
ocsenave@282 696 price-size 3]
ocsenave@282 697 (zipmap items
ocsenave@282 698 (map (comp
ocsenave@282 699 ;; zero-cost items are "priceless"
ocsenave@282 700 #(if (zero? %) :priceless %)
ocsenave@282 701 decode-bcd butlast)
ocsenave@282 702 (partition price-size
ocsenave@282 703 (take (* price-size (count items))
ocsenave@282 704 (drop 0x4495 rom))))))))
ocsenave@273 705
ocsenave@281 706 (defn hxc-shops
ocsenave@281 707 ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom))
ocsenave@281 708 ([rom]
ocsenave@281 709 (let [items (zipmap (range) (map format-name (hxc-items rom)))
ocsenave@281 710
ocsenave@281 711 ;; temporarily softcode the TM items
ocsenave@281 712 items (into
ocsenave@281 713 items
ocsenave@281 714 (map (juxt identity
ocsenave@281 715 (comp keyword
ocsenave@281 716 (partial str "tm-")
ocsenave@281 717 (partial + 1 -200)
ocsenave@281 718 ))
ocsenave@281 719 (take 200 (drop 200 (range)))))
ocsenave@282 720
ocsenave@281 721 ]
ocsenave@281 722
ocsenave@281 723 ((fn parse-shop [coll [num-items & items-etc]]
ocsenave@282 724 (let [inventory (take-while
ocsenave@282 725 (partial not= 0xFF)
ocsenave@282 726 items-etc)
ocsenave@281 727 [separator & items-etc] (drop num-items (rest items-etc))]
ocsenave@281 728 (if (= separator 0x50)
ocsenave@281 729 (map (partial mapv (comp items dec)) (conj coll inventory))
ocsenave@281 730 (recur (conj coll inventory) items-etc)
ocsenave@281 731 )
ocsenave@281 732 ))
ocsenave@281 733
ocsenave@281 734 '()
ocsenave@282 735 (drop 0x233C rom))
ocsenave@281 736
ocsenave@281 737
ocsenave@281 738 )))
ocsenave@281 739
ocsenave@281 740
ocsenave@273 741
ocsenave@249 742 ;; ********************** MANIPULATION FNS
ocsenave@249 743
ocsenave@249 744
ocsenave@249 745
ocsenave@249 746
ocsenave@249 747 (defn submap?
ocsenave@249 748 "Compares the two maps. Returns true if map-big has the same associations as map-small, otherwise false."
ocsenave@249 749 [map-small map-big]
ocsenave@249 750 (cond (empty? map-small) true
ocsenave@249 751 (and
ocsenave@249 752 (contains? map-big (ffirst map-small))
ocsenave@249 753 (= (get map-big (ffirst map-small))
ocsenave@249 754 (second (first map-small))))
ocsenave@249 755 (recur (next map-small) map-big)
ocsenave@249 756
ocsenave@249 757 :else false))
ocsenave@249 758
ocsenave@249 759
ocsenave@249 760 (defn search-map [proto-map maps]
ocsenave@249 761 "Returns all the maps that make the same associations as proto-map."
ocsenave@249 762 (some (partial submap? proto-map) maps))
ocsenave@249 763
rlm@252 764 (defn filter-vals
rlm@252 765 "Returns a map consisting of all the pairs [key val] for
rlm@252 766 which (pred key) returns true."
rlm@252 767 [pred map]
rlm@252 768 (reduce (partial apply assoc) {}
rlm@252 769 (filter (fn [[k v]] (pred v)) map)))
ocsenave@249 770
ocsenave@249 771
ocsenave@249 772 (defn search-moves
rlm@252 773 "Returns a subcollection of all hardcoded moves with the
rlm@252 774 given attributes. Attributes consist of :name :power
rlm@252 775 :accuracy :pp :fx-id
rlm@252 776 (and also :fx-txt, but it contains the same information
rlm@252 777 as :fx-id)"
ocsenave@249 778 ([attribute-map]
rlm@252 779 (search-moves
rlm@252 780 com.aurellem.gb.gb-driver/original-rom attribute-map))
ocsenave@249 781 ([rom attribute-map]
rlm@252 782 (filter-vals (partial submap? attribute-map)
rlm@252 783 (hxc-move-data rom))))
ocsenave@249 784
ocsenave@249 785
ocsenave@249 786
ocsenave@249 787
ocsenave@243 788
ocsenave@283 789 ;; note: 0x2f31 contains the names "TM" "HM"?
ocsenave@283 790
ocsenave@246 791 ;; note for later: credits start at F1290
ocsenave@243 792
ocsenave@243 793
ocsenave@243 794
ocsenave@281 795
ocsenave@281 796 ;; (def dex-order
ocsenave@281 797 ;; [:bulbasaur
ocsenave@281 798 ;; :ivysaur
ocsenave@281 799 ;; :venusaur
ocsenave@281 800 ;; :charmander
ocsenave@281 801 ;; :charmeleon
ocsenave@281 802 ;; :charizard])
ocsenave@281 803
ocsenave@281 804
ocsenave@281 805 ;; (defn same-type-attack-bonus?
ocsenave@281 806 ;; ([pkmn move]
ocsenave@281 807 ;; (same-type-attack-bonus?
ocsenave@281 808 ;; com.aurellem.gb.gb-driver/original-rom pkmn move))
ocsenave@281 809 ;; ([rom pkmn move]
ocsenave@281 810 ;; (hxc-pokemon-base rom)))
ocsenave@281 811
ocsenave@281 812
ocsenave@281 813
ocsenave@281 814
ocsenave@281 815
ocsenave@281 816
ocsenave@246 817 (comment
ocsenave@243 818
rlm@218 819 (def hxc-later
rlm@218 820 "Running this code produces, e.g. hardcoded names NPCs give
rlm@218 821 their pokemon. Will sort through it later."
rlm@218 822 (print (character-codes->str(take 10000
rlm@218 823 (drop 0x71597
rlm@218 824 (rom (root)))))))
rlm@218 825
rlm@218 826 (let [dex
rlm@218 827 (partition-by #(= 0x50 %)
rlm@218 828 (take 2540
rlm@218 829 (drop 0x40687
rlm@218 830 (rom (root)))))]
rlm@218 831 (def dex dex)
rlm@218 832 (def hxc-species
rlm@218 833 (map character-codes->str
rlm@218 834 (take-nth 4 dex))))
ocsenave@259 835 )
ocsenave@259 836
ocsenave@259 837
ocsenave@259 838
ocsenave@281 839
ocsenave@281 840
ocsenave@281 841