comparison clojure/com/aurellem/exp/pokemon.clj @ 148:06426d25c65b

can now get/set pokemon OT name
author Robert McIntyre <rlm@mit.edu>
date Mon, 19 Mar 2012 23:14:21 -0500
parents 279e9ee6fccb
children 79ffbd639b41
comparison
equal deleted inserted replaced
147:279e9ee6fccb 148:06426d25c65b
90 90
91 (def end-of-name-marker 0x50) 91 (def end-of-name-marker 0x50)
92 (def max-name-length 10) 92 (def max-name-length 10)
93 (def name-width 11) 93 (def name-width 11)
94 94
95 (defn read-pokemon-name [codes] 95 (defn read-name [codes]
96 (character-codes->str 96 (character-codes->str
97 (take-while 97 (take-while
98 (partial not= end-of-name-marker) codes))) 98 (partial not= end-of-name-marker) codes)))
99 99
100 100
101 (defn sixth-pokemon-name [^SaveState state] 101 (defn sixth-pokemon-name [^SaveState state]
102 (read-pokemon-name 102 (read-name
103 (subvec (vec (memory state)) 103 (subvec (vec (memory state))
104 sixth-pokemon-name-start 104 sixth-pokemon-name-start
105 (+ (inc max-name-length) 105 (+ (inc max-name-length)
106 sixth-pokemon-name-start)))) 106 sixth-pokemon-name-start))))
107 107
125 (range begin end))) 125 (range begin end)))
126 state) 126 state)
127 ([begin end] 127 ([begin end]
128 (print-text @current-state begin end))) 128 (print-text @current-state begin end)))
129 129
130
131
132
133 (defn examine-name-memory [] 130 (defn examine-name-memory []
134 (print-text 131 (print-text
135 named-A 132 named-A
136 (- sixth-pokemon-name-start 100) 133 (- sixth-pokemon-name-start 100)
137 (+ sixth-pokemon-name-start 100))) 134 (+ sixth-pokemon-name-start 100)))
138
139 135
140 ;; results: 136 ;; results:
141 ;; 0xD287: end-of-name-sentinel 137 ;; 0xD287: end-of-name-sentinel
142 ;; 0xD288: R 138 ;; 0xD288: R
143 ;; 0xD289: L 139 ;; 0xD289: L
434 ([^SaveState state] 430 ([^SaveState state]
435 (let [raw-names 431 (let [raw-names
436 (subvec (vec (memory state)) 432 (subvec (vec (memory state))
437 pokemon-names-start 433 pokemon-names-start
438 (+ pokemon-names-start 434 (+ pokemon-names-start
439 (* name-width 6)))] 435 (* name-width 6)))]
440 (map 436 (map
441 read-pokemon-name 437 read-name
442 (take 438 (take
443 (party-number state) 439 (party-number state)
444 (partition name-width 440 (partition name-width
445 raw-names))))) 441 raw-names)))))
446 ([] (party-names @current-state))) 442 ([] (party-names @current-state)))
447 443
448 444
445 (defn rename-pokemon
446 ([^SaveState state n new-name]
447 (assert (<= 0 n (dec (party-number state))))
448 (assert (<= (count new-name) max-name-length))
449 (set-memory-range
450 state
451 (+ (* n name-width) pokemon-names-start)
452 (concat (str->character-codes new-name) [end-of-name-marker])))
453 ([n new-name]
454 (rename-pokemon @current-state n new-name)))
455
456
457 ;; on further analysis, it appears that the original
458 ;; trainer info for each pokemon is also stored together,
459 ;; starting at 0xD272 and continuing to 0xD2B3, with
460 ;; 11 bytes reserved for each OT name.
461
462 (def OT-start 0xD272)
463
464 (defn original-trainers
465 ([^SaveState state]
466 (let [raw-names
467 (subvec (vec (memory state))
468 OT-start
469 (+ OT-start
470 (* name-width 6)))]
471 (map read-name
472 (take (party-number state)
473 (partition name-width raw-names)))))
474 ([] (original-trainers @current-state)))
475
476 (defn set-original-trainer
477 "Set the OT name for a pokemon.
478 Note that a pokemon is still considered 'yours' if
479 the OT ID is the same as your own."
480 ([^SaveState state n new-name]
481 (assert (<= 0 n (dec (party-number state))))
482 (assert (<= (count new-name) max-name-length))
483 (set-memory-range
484 state
485 (+ (* n name-width) OT-start)
486 (concat (str->character-codes new-name) [end-of-name-marker])))
487 ([n new-name]
488 (set-original-trainer @current-state n new-name)))
489
490 ;; PIKACHU stops following if you set it's OT to another name
491 ;; and then back to you own.
492 ;; But not if you set it to your own name, obviously.
493