annotate clojure/com/aurellem/gb/hxc.clj @ 282:0c3fbb313e49

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