view clojure/com/aurellem/gb/hxc.clj @ 370:5aabbe326eb0

fixed a few blocks that were not tangling properly.
author Dylan Holmes <ocsenave@gmail.com>
date Sun, 08 Apr 2012 07:59:15 -0500
parents 497ca041f5af
children b477970d0b7a
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]))
7 ; ************* HANDWRITTEN CONSTANTS
9 (def pkmn-types
10 [:normal ;;0
11 :fighting ;;1
12 :flying ;;2
13 :poison ;;3
14 :ground ;;4
15 :rock ;;5
16 :bird ;;6
17 :bug ;;7
18 :ghost ;;8
19 :A
20 :B
21 :C
22 :D
23 :E
24 :F
25 :G
26 :H
27 :I
28 :J
29 :K
30 :fire ;;20 (0x14)
31 :water ;;21 (0x15)
32 :grass ;;22 (0x16)
33 :electric ;;23 (0x17)
34 :psychic ;;24 (0x18)
35 :ice ;;25 (0x19)
36 :dragon ;;26 (0x1A)
37 ])
40 ;; question: when status effects claim to take
41 ;; their accuracy from the move accuracy, does
42 ;; this mean that the move always "hits" but the
43 ;; status effect may not?
45 (def move-effects
46 ["normal damage"
47 "no damage, just opponent sleep" ;; how many turns? is atk power ignored?
48 "0x4C chance of poison"
49 "leech half of inflicted damage"
50 "0x19 chance of burn"
51 "0x19 chance of freeze"
52 "0x19 chance of paralyze"
53 "user faints; opponent defense halved during attack."
54 "leech half of inflicted damage ONLY if sleeping opponent."
55 "imitate last attack"
56 "user atk +1"
57 "user def +1"
58 "user spd +1"
59 "user spc +1"
60 "user acr +1" ;; unused?!
61 "user evd +1"
62 "get post-battle $ = 2*level*uses"
63 "0xFE acr, no matter what."
64 "opponent atk -1" ;; acr taken from move acr?
65 "opponent def -1" ;;
66 "opponent spd -1" ;;
67 "opponent spc -1" ;;
68 "opponent acr -1";;
69 "opponent evd -1"
70 "converts user's type to opponent's."
71 "(haze)"
72 "(bide)"
73 "(thrash)"
74 "(teleport)"
75 "(fury swipes)"
76 "attacks 2-5 turns" ;; unused? like rollout?
77 "0x19 chance of flinch"
78 "opponent sleep for 1-7 turns"
79 "0x66 chance of poison"
80 "0x4D chance of burn"
81 "0x4D chance of freeze"
82 "0x4D chance of paralyze"
83 "0x4D chance of flinch"
84 "one-hit KO"
85 "charge one turn, atk next."
86 "fixed damage, leaves 1HP." ;; how is dmg determined?
87 "fixed damage." ;; cf seismic toss, dragon rage, psywave.
88 "atk 2-5 turns; opponent can't attack" ;; unnormalized? (0 0x60 0x60 0x20 0x20)
89 "charge one turn, atk next. (can't be hit when charging)"
90 "atk hits twice."
91 "user takes 1 damage if misses."
92 "evade status-lowering effects" ;;caused by you or also your opponent?
93 "(broken) if user is slower than opponent, makes critical hit impossible, otherwise has no effect"
94 "atk causes recoil dmg = 1/4 dmg dealt"
95 "confuses opponent" ;; acr taken from move acr
96 "user atk +2"
97 "user def +2"
98 "user spd +2"
99 "user spc +2"
100 "user acr +2" ;; unused!
101 "user evd +2" ;; unused!
102 "restores up to half of user's max hp." ;; broken: fails if the difference
103 ;; b/w max and current hp is one less than a multiple of 256.
104 "(transform)"
105 "opponent atk -2"
106 "opponent def -2"
107 "opponent spd -2"
108 "opponent spc -2"
109 "opponent acr -2"
110 "opponent evd -2"
111 "doubles user spc when attacked"
112 "doubles user def when attacked"
113 "just poisons opponent" ;;acr taken from move acr
114 "just paralyzes opponent" ;;
115 "0x19 chance opponent atk -1"
116 "0x19 chance opponent def -1"
117 "0x19 chance opponent spd -1"
118 "0x4C chance opponent spc -1" ;; context suggest chance is 0x19
119 "0x19 chance opponent acr -1"
120 "0x19 chance opponent evd -1"
121 "???" ;; unused? no effect?
122 "???" ;; unused? no effect?
123 "0x19 chance opponent confused"
124 "atk hits twice. 0x33 chance opponent poisioned."
125 "broken. crash the game after attack."
126 "(substitute)"
127 "unless opponent faints, user must recharge after atk. some
128 exceptions apply."
129 "(rage)"
130 "(mimic)"
131 "(metronome)"
132 "(leech seed)"
133 "does nothing (splash)"
134 "(disable)"
135 ])
137 ;; ************** HARDCODED DATA
139 (defn hxc-thunk
140 "Creates a thunk (nullary fn) that grabs data in a certain region of rom and
141 splits it into a collection by 0x50. If rom is not supplied, uses the
142 original rom data."
143 [start length]
144 (fn self
145 ([rom]
146 (take-nth 2
147 (partition-by #(= % 0x50)
148 (take length
149 (drop start rom)))))
150 ([]
151 (self com.aurellem.gb.gb-driver/original-rom))))
153 (def hxc-thunk-words
154 "Same as hxc-thunk, except it interprets the rom data as characters,
155 returning a collection of strings."
156 (comp
157 (partial comp (partial map character-codes->str))
158 hxc-thunk))
160 ;; --------------------------------------------------
163 (defn hxc-pokenames-raw
164 "The hardcoded names of the 190 species in memory. List begins at
165 ROM@E8000. Although names in memory are padded with 0x50 to be 10 characters
166 long, these names are stripped of padding. See also, hxc-pokedex-names"
167 ([]
168 (hxc-pokenames-raw com.aurellem.gb.gb-driver/original-rom))
169 ([rom]
170 (let [count-species 190
171 name-length 10]
172 (map character-codes->str
173 (partition name-length
174 (map #(if (= 0x50 %) 0x00 %)
175 (take (* count-species name-length)
176 (drop 0xE8000
177 rom))))))))
178 (def hxc-pokenames
179 (comp
180 (partial map format-name)
181 hxc-pokenames-raw))
186 (defn hxc-pokedex-names
187 "The names of the pokemon in hardcoded pokedex order. List begins at
188 ROM@410B1. See also, hxc-pokenames."
189 ([] (hxc-pokedex-names
190 com.aurellem.gb.gb-driver/original-rom))
191 ([rom]
192 (let [names (hxc-pokenames rom)]
193 (#(mapv %
194 ((comp range count keys) %))
195 (zipmap
196 (take (count names)
197 (drop 0x410b1 rom))
199 names)))))
201 (def hxc-types
202 "The hardcoded type names in memory. List begins at ROM@27D99,
203 shortly before hxc-titles."
204 (hxc-thunk-words 0x27D99 102))
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)))))
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-items
260 "The hardcoded names of the items in memory, presented as
261 keywords. List begins at ROM@045B7. See also, hxc-items-raw."
262 (comp (partial map format-name) hxc-items-raw))
266 (def hxc-titles
267 "The hardcoded names of the trainer titles in memory. List begins at
268 ROM@27E77"
269 (hxc-thunk-words 0x27E77 196))
272 (def hxc-pokedex-text-raw
273 "The hardcoded pokedex entries in memory. List begins at
274 ROM@B8000, shortly before move names."
275 (hxc-thunk-words 0xB8000 14754))
280 (defn hxc-pokedex-text
281 "The hardcoded pokedex entries in memory, presented as an
282 associative hash map. List begins at ROM@B8000."
283 ([] (hxc-pokedex-text com.aurellem.gb.gb-driver/original-rom))
284 ([rom]
285 (zipmap
286 (hxc-pokedex-names rom)
287 (cons nil ;; for missingno.
288 (hxc-pokedex-text-raw rom)))))
290 ;; In red/blue, pokedex stats are in internal order.
291 ;; 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))) ))
351 (def hxc-places
352 "The hardcoded place names in memory. List begins at
353 ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated."
354 (hxc-thunk-words 0x71500 560))
357 (defn hxc-dialog
358 "The hardcoded dialogue in memory, including in-game alerts. Dialog
359 seems to be separated by 0x57 instead of 0x50 (END). Begins at ROM@98000."
360 ([rom]
361 (map character-codes->str
362 (take-nth 2
363 (partition-by #(= % 0x57)
364 (take 0x0F728
365 (drop 0x98000 rom))))))
366 ([]
367 (hxc-dialog com.aurellem.gb.gb-driver/original-rom)))
370 (def hxc-move-names
371 "The hardcoded move names in memory. List begins at ROM@BC000"
372 (hxc-thunk-words 0xBC000 1551))
373 (defn hxc-move-data
374 "The hardcoded (basic (move effects)) in memory. List begins at
375 0x38000. Returns a map of {:name :power :accuracy :pp :fx-id
376 :fx-txt}. The move descriptions are handwritten, not hardcoded."
377 ([]
378 (hxc-move-data com.aurellem.gb.gb-driver/original-rom))
379 ([rom]
380 (let [names (vec (hxc-move-names rom))
381 move-count (count names)
382 move-size 6
383 types pkmn-types ;;; !! hardcoded types
384 ]
385 (zipmap (map format-name names)
386 (map
387 (fn [[idx effect power type-id accuracy pp]]
388 {:name (names (dec idx))
389 :power power
390 :accuracy accuracy
391 :pp pp
392 :type (types type-id)
393 :fx-id effect
394 :fx-txt (get move-effects effect)
395 }
396 )
398 (partition move-size
399 (take (* move-size move-count)
400 (drop 0x38000 rom))))))))
404 (defn hxc-move-data*
405 "Like hxc-move-data, but reports numbers as hexadecimal symbols instead."
406 ([]
407 (hxc-move-data* com.aurellem.gb.gb-driver/original-rom))
408 ([rom]
409 (let [names (vec (hxc-move-names rom))
410 move-count (count names)
411 move-size 6
412 format-name (fn [s]
413 (keyword (.toLowerCase
414 (apply str
415 (map #(if (= % \space) "-" %) s)))))
416 ]
417 (zipmap (map format-name names)
418 (map
419 (fn [[idx effect power type accuracy pp]]
420 {:name (names (dec idx))
421 :power power
422 :accuracy (hex accuracy)
423 :pp pp
424 :fx-id (hex effect)
425 :fx-txt (get move-effects effect)
426 }
427 )
429 (partition move-size
430 (take (* move-size move-count)
431 (drop 0x38000 rom))))))))
434 (defn hxc-machines
435 "The hardcoded moves taught by TMs and HMs. List begins at ROM@1232D."
436 ([] (hxc-machines
437 com.aurellem.gb.gb-driver/original-rom))
438 ([rom]
439 (let [moves (hxc-move-names rom)]
440 (zipmap
441 (range)
442 (take-while
443 (comp not nil?)
444 (map (comp
445 format-name
446 (zipmap
447 (range)
448 moves)
449 dec)
450 (take 100
451 (drop 0x1232D rom))))))))
456 (defn internal-id
457 ([rom]
458 (zipmap
459 (hxc-pokenames rom)
460 (range)))
461 ([]
462 (internal-id com.aurellem.gb.gb-driver/original-rom)))
468 ;; nidoran gender change upon levelup
469 ;; (->
470 ;; @current-state
471 ;; rom
472 ;; vec
473 ;; (rewrite-memory
474 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♂))
475 ;; [1 1 15])
476 ;; (rewrite-memory
477 ;; (nth (hxc-ptrs-evolve) ((internal-id) :nidoran♀))
478 ;; [1 1 3])
479 ;; (write-rom!)
481 ;; )
485 (defn hxc-advantage
486 ;; in-game multipliers are stored as 10x their effective value
487 ;; to allow for fractional multipliers like 1/2
489 "The hardcoded type advantages in memory, returned as tuples of
490 atk-type def-type multiplier. By default (i.e. if not listed here),
491 the multiplier is 1. List begins at 0x3E62D."
492 ([] (hxc-advantage com.aurellem.gb.gb-driver/original-rom))
493 ([rom]
494 (map
495 (fn [[atk def mult]] [(get pkmn-types atk (hex atk))
496 (get pkmn-types def (hex def))
497 (/ mult 10)])
498 (partition 3
499 (take-while (partial not= 0xFF)
500 (drop 0x3E62D rom))))))
504 (defn format-evo
505 "Parse a sequence of evolution data, returning a map. First is the
506 method: 0 = end-evolution-data. 1 = level-up, 2 = item, 3 = trade. Next is an item id, if the
507 method of evolution is by item (only stones will actually make pokemon
508 evolve, for some auxillary reason.) Finally, the minimum level for
509 evolution to occur (level 1 means no limit, which is used for trade
510 and item evolutions), followed by the internal id of the pokemon
511 into which to evolve. Hence, level up and trade evolutions are
512 described with 3
513 bytes; item evolutions with four."
514 [coll]
515 (let [method (first coll)]
516 (cond (empty? coll) []
517 (= 0 method) [] ;; just in case
518 (= 1 method) ;; level-up evolution
519 (conj (format-evo (drop 3 coll))
520 {:method :level-up
521 :min-level (nth coll 1)
522 :into (dec (nth coll 2))})
524 (= 2 method) ;; item evolution
525 (conj (format-evo (drop 4 coll))
526 {:method :item
527 :item (dec (nth coll 1))
528 :min-level (nth coll 2)
529 :into (dec (nth coll 3))})
531 (= 3 method) ;; trade evolution
532 (conj (format-evo (drop 3 coll))
533 {:method :trade
534 :min-level (nth coll 1) ;; always 1 for trade.
535 :into (dec (nth coll 2))}))))
538 (defn hxc-ptrs-evolve
539 "A hardcoded collection of 190 pointers to alternating evolution/learnset data,
540 in internal order."
541 ([]
542 (hxc-ptrs-evolve com.aurellem.gb.gb-driver/original-rom))
543 ([rom]
544 (let [
545 pkmn-count (count (hxc-pokenames-raw)) ;; 190
546 ptrs
547 (map (fn [[a b]] (low-high a b))
548 (partition 2
549 (take (* 2 pkmn-count)
550 (drop 0x3b1e5 rom))))]
551 (map (partial + 0x34000) ptrs)
553 )))
555 (defn hxc-evolution
556 "Hardcoded evolution data in memory. The data exists at ROM@34000,
557 sorted by internal order. Pointers to the data exist at ROM@3B1E5; see also, hxc-ptrs-evolve."
558 ([] (hxc-evolution com.aurellem.gb.gb-driver/original-rom))
559 ([rom]
560 (apply assoc {}
561 (interleave
562 (hxc-pokenames rom)
563 (map
564 (comp
565 format-evo
566 (partial take-while (comp not zero?))
567 #(drop % rom))
568 (hxc-ptrs-evolve rom)
569 )))))
571 (defn hxc-evolution-pretty
572 "Like hxc-evolution, except it uses the names of items and pokemon
573 --- grabbed from ROM --- rather than their numerical identifiers."
574 ([] (hxc-evolution-pretty com.aurellem.gb.gb-driver/original-rom))
575 ([rom]
576 (let
577 [poke-names (vec (hxc-pokenames rom))
578 item-names (vec (hxc-items rom))
579 use-names
580 (fn [m]
581 (loop [ks (keys m) new-map m]
582 (let [k (first ks)]
583 (cond (nil? ks) new-map
584 (= k :into)
585 (recur
586 (next ks)
587 (assoc new-map
588 :into
589 (poke-names
590 (:into
591 new-map))))
592 (= k :item)
593 (recur
594 (next ks)
595 (assoc new-map
596 :item
597 (item-names
598 (:item new-map))))
599 :else
600 (recur
601 (next ks)
602 new-map)
603 ))))]
605 (into {}
606 (map (fn [[pkmn evo-coll]]
607 [pkmn (map use-names evo-coll)])
608 (hxc-evolution rom))))))
613 (defn hxc-learnsets
614 "Hardcoded map associating pokemon names to lists of pairs [lvl
615 move] of abilities they learn as they level up. The data
616 exists at ROM@34000, sorted by internal order. Pointers to the data
617 exist at ROM@3B1E5; see also, hxc-ptrs-evolve"
618 ([] (hxc-learnsets com.aurellem.gb.gb-driver/original-rom))
619 ([rom]
620 (apply assoc
621 {}
622 (interleave
623 (hxc-pokenames rom)
624 (map (comp
625 (partial map
626 (fn [[lvl mv]] [lvl (dec mv)]))
627 (partial partition 2)
628 ;; keep the learnset data
629 (partial take-while (comp not zero?))
630 ;; skip the evolution data
631 rest
632 (partial drop-while (comp not zero?)))
633 (map #(drop % rom)
634 (hxc-ptrs-evolve rom)))))))
636 (defn hxc-learnsets-pretty
637 "Live hxc-learnsets except it reports the name of each move --- as
638 it appears in rom --- rather than the move index."
639 ([] (hxc-learnsets-pretty com.aurellem.gb.gb-driver/original-rom))
640 ([rom]
641 (let [moves (vec(map format-name (hxc-move-names)))]
642 (into {}
643 (map (fn [[pkmn learnset]]
644 [pkmn (map (fn [[lvl mv]] [lvl (moves mv)])
645 learnset)])
646 (hxc-learnsets rom))))))
650 (defn hxc-pokemon-base
651 ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom))
652 ([rom]
653 (let [entry-size 28
654 pkmn-count (count (hxc-pokedex-text rom))
655 pokemon (rest (hxc-pokedex-names))
656 types (apply assoc {}
657 (interleave
658 (range)
659 pkmn-types)) ;;!! softcoded
660 moves (apply assoc {}
661 (interleave
662 (range)
663 (map format-name
664 (hxc-move-names rom))))
665 machines (hxc-machines)
666 ]
667 (zipmap
668 pokemon
669 (map
670 (fn [[n
671 rating-hp
672 rating-atk
673 rating-def
674 rating-speed
675 rating-special
676 type-1
677 type-2
678 rarity
679 rating-xp
680 pic-dimensions ;; tile_width|tile_height (8px/tile)
681 ptr-pic-obverse-1
682 ptr-pic-obverse-2
683 ptr-pic-reverse-1
684 ptr-pic-reverse-2
685 move-1
686 move-2
687 move-3
688 move-4
689 growth-rate
690 &
691 TMs|HMs]]
692 (let
693 [base-moves
694 (mapv moves
695 ((comp
696 ;; since the game uses zero as a delimiter,
697 ;; it must also increment all move indices by 1.
698 ;; heren we decrement to correct this.
699 (partial map dec)
700 (partial take-while (comp not zero?)))
701 [move-1 move-2 move-3 move-4]))
703 types
704 (set (list (types type-1)
705 (types type-2)))
706 TMs|HMs
707 (map
708 (comp
709 (partial map first)
710 (partial remove (comp zero? second)))
711 (split-at
712 50
713 (map vector
714 (rest(range))
715 (reduce concat
716 (map
717 #(take 8
718 (concat (bit-list %)
719 (repeat 0)))
721 TMs|HMs)))))
723 TMs (vec (first TMs|HMs))
724 HMs (take 5 (map (partial + -50) (vec (second TMs|HMs))))
727 ]
730 {:dex# n
731 :base-moves base-moves
732 :types types
733 :TMs TMs
734 :HMs HMs
735 :base-hp rating-hp
736 :base-atk rating-atk
737 :base-def rating-def
738 :base-speed rating-speed
739 :base-special rating-special
740 :o0 pic-dimensions
741 :o1 ptr-pic-obverse-1
742 :o2 ptr-pic-obverse-2
743 }))
745 (partition entry-size
746 (take (* entry-size pkmn-count)
747 (drop 0x383DE
748 rom))))))))
752 (defn hxc-intro-pkmn
753 "The hardcoded pokemon to display in Prof. Oak's introduction; the pokemon's
754 internal id is stored at ROM@5EDB."
755 ([] (hxc-intro-pkmn
756 com.aurellem.gb.gb-driver/original-rom))
757 ([rom]
758 (nth (hxc-pokenames rom) (nth rom 0x5EDB))))
760 (defn sxc-intro-pkmn!
761 "Set the hardcoded pokemon to display in Prof. Oak's introduction."
762 [pokemon]
763 (write-rom!
764 (rewrite-rom 0x5EDB
765 [
766 (inc
767 ((zipmap
768 (hxc-pokenames)
769 (range))
770 pokemon))])))
773 (defn hxc-item-prices
774 "The hardcoded list of item prices in memory. List begins at ROM@4495"
775 ([] (hxc-item-prices com.aurellem.gb.gb-driver/original-rom))
776 ([rom]
777 (let [items (hxc-items rom)
778 price-size 3]
779 (zipmap items
780 (map (comp
781 ;; zero-cost items are "priceless"
782 #(if (zero? %) :priceless %)
783 decode-bcd butlast)
784 (partition price-size
785 (take (* price-size (count items))
786 (drop 0x4495 rom))))))))
788 (defn hxc-shops
789 ([] (hxc-shops com.aurellem.gb.gb-driver/original-rom))
790 ([rom]
791 (let [items (zipmap (range) (hxc-items rom))
793 ;; temporarily softcode the TM items
794 items (into
795 items
796 (map (juxt identity
797 (comp keyword
798 (partial str "tm-")
799 (partial + 1 -200)
800 ))
801 (take 200 (drop 200 (range)))))
803 ]
805 ((fn parse-shop [coll [num-items & items-etc]]
806 (let [inventory (take-while
807 (partial not= 0xFF)
808 items-etc)
809 [separator & items-etc] (drop num-items (rest items-etc))]
810 (if (= separator 0x50)
811 (map (partial mapv (comp items dec)) (conj coll inventory))
812 (recur (conj coll inventory) items-etc)
813 )
814 ))
816 '()
817 (drop 0x233C rom))
820 )))
825 (defn hxc-ptrs-wild
826 "A list of the hardcoded wild encounter data in memory. Pointers
827 begin at ROM@0CB95; data begins at ROM@0x04D89"
828 ([] (hxc-ptrs-wild com.aurellem.gb.gb-driver/original-rom))
829 ([rom]
830 (let [ptrs
831 (map (fn [[a b]] (+ a (* 0x100 b)))
832 (take-while (partial not= (list 0xFF 0xFF))
833 (partition 2 (drop 0xCB95 rom))))]
834 ptrs)))
838 (defn hxc-wilds
839 "A list of the hardcoded wild encounter data in memory. Pointers
840 begin at ROM@0CB95; data begins at ROM@0x04D89"
841 ([] (hxc-wilds com.aurellem.gb.gb-driver/original-rom))
842 ([rom]
843 (let [pokenames (zipmap (range) (hxc-pokenames rom))]
844 (map
845 (partial map (fn [[a b]] {:species (pokenames (dec b)) :level
846 a}))
847 (partition 10
849 (take-while (comp (partial not= 1)
850 first)
851 (partition 2
852 (drop 0xCD8C rom))
854 ))))))
858 ;; ********************** MANIPULATION FNS
861 (defn same-type
862 ([pkmn move]
863 (same-type
864 com.aurellem.gb.gb-driver/original-rom pkmn move))
865 ([rom pkmn move]
866 (((comp :types (hxc-pokemon-base rom)) pkmn)
867 ((comp :type (hxc-move-data rom)) move))))
872 (defn submap?
873 "Compares the two maps. Returns true if map-big has the same associations as map-small, otherwise false."
874 [map-small map-big]
875 (cond (empty? map-small) true
876 (and
877 (contains? map-big (ffirst map-small))
878 (= (get map-big (ffirst map-small))
879 (second (first map-small))))
880 (recur (next map-small) map-big)
882 :else false))
885 (defn search-map [proto-map maps]
886 "Returns all the maps that make the same associations as proto-map."
887 (some (partial submap? proto-map) maps))
889 (defn filter-vals
890 "Returns a map consisting of all the pairs [key val] for
891 which (pred key) returns true."
892 [pred map]
893 (reduce (partial apply assoc) {}
894 (filter (fn [[k v]] (pred v)) map)))
897 (defn search-moves
898 "Returns a subcollection of all hardcoded moves with the
899 given attributes. Attributes consist of :name :power
900 :accuracy :pp :fx-id
901 (and also :fx-txt, but it contains the same information
902 as :fx-id)"
903 ([attribute-map]
904 (search-moves
905 com.aurellem.gb.gb-driver/original-rom attribute-map))
906 ([rom attribute-map]
907 (filter-vals (partial submap? attribute-map)
908 (hxc-move-data rom))))
914 ;; note: 0x2f31 contains the names "TM" "HM"?
916 ;; note for later: credits start at F1290
918 ;; note: DADB hyper-potion-hp _ _ _ super-potion-hp _ _ _ potion-hp ??
920 ;; note: DD4D spells out pokemon vital stat names ("speed", etc.)
922 ;; note: 1195C-6A says ABLE#NOT ABLE#, but so does 119C0-119CE.
923 ;; The first instance is for Machines; the second, for stones.
925 ;; 0x251A (in indexable mem): image decompression routine seems to begin here.
928 (comment
930 (def hxc-later
931 "Running this code produces, e.g. hardcoded names NPCs give
932 their pokemon. Will sort through it later."
933 (print (character-codes->str(take 10000
934 (drop 0x71597
935 (rom (root)))))))
937 (let [dex
938 (partition-by #(= 0x50 %)
939 (take 2540
940 (drop 0x40687
941 (rom (root)))))]
942 (def dex dex)
943 (def hxc-species
944 (map character-codes->str
945 (take-nth 4 dex))))
946 )