view clojure/com/aurellem/gb/hxc.clj @ 308:de172acc5a03

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