annotate clojure/com/aurellem/gb/hxc.clj @ 307:872e032949ff

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