view clojure/com/aurellem/gb/hxc.clj @ 347:ff65ee0944fe

more progess: now rom.org tangles into hxc.clj; i'll be subdividing the code blocks as I write more.
author Dylan Holmes <ocsenave@gmail.com>
date Sun, 08 Apr 2012 06:13:39 -0500
parents 5639312a393f
children 497ca041f5af
line wrap: on
line source

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