Mercurial > vba-clojure
comparison clojure/com/aurellem/gb/hxc.clj @ 348:497ca041f5af
finished working for now. i've completed more carving up of code blocks.
author | Dylan Holmes <ocsenave@gmail.com> |
---|---|
date | Sun, 08 Apr 2012 07:55:06 -0500 |
parents | ff65ee0944fe |
children | 5aabbe326eb0 |
comparison
equal
deleted
inserted
replaced
347:ff65ee0944fe | 348:497ca041f5af |
---|---|
1 | 1 |
2 (ns com.aurellem.gb.hxc | 2 (ns com.aurellem.gb.hxc |
3 (:use (com.aurellem.gb assembly characters gb-driver util mem-util | 3 (:use (com.aurellem.gb assembly characters gb-driver util mem-util |
4 constants species)) | 4 constants species)) |
5 (:import [com.aurellem.gb.gb_driver SaveState])) | 5 (:import [com.aurellem.gb.gb_driver SaveState])) |
6 | |
7 | |
8 | |
9 | 6 |
10 ; ************* HANDWRITTEN CONSTANTS | 7 ; ************* HANDWRITTEN CONSTANTS |
11 | 8 |
12 (def pkmn-types | 9 (def pkmn-types |
13 [:normal ;;0 | 10 [:normal ;;0 |
161 hxc-thunk)) | 158 hxc-thunk)) |
162 | 159 |
163 ;; -------------------------------------------------- | 160 ;; -------------------------------------------------- |
164 | 161 |
165 | 162 |
166 | |
167 (defn hxc-pokenames-raw | 163 (defn hxc-pokenames-raw |
168 "The hardcoded names of the 190 species in memory. List begins at | 164 "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 | 165 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" | 166 long, these names are stripped of padding. See also, hxc-pokedex-names" |
171 ([] | 167 ([] |
200 (take (count names) | 196 (take (count names) |
201 (drop 0x410b1 rom)) | 197 (drop 0x410b1 rom)) |
202 | 198 |
203 names))))) | 199 names))))) |
204 | 200 |
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)) | |
205 | 205 |
206 | 206 |
207 ;; http://hax.iimarck.us/topic/581/ | 207 ;; http://hax.iimarck.us/topic/581/ |
208 (defn hxc-cry | 208 (defn hxc-cry |
209 "The pokemon cry data in internal order. List begins at ROM@39462" | 209 "The pokemon cry data in internal order. List begins at ROM@39462" |
246 (vec(rom)) | 246 (vec(rom)) |
247 0x3965D | 247 0x3965D |
248 (map second | 248 (map second |
249 ((hxc-cry) pkmn))))) | 249 ((hxc-cry) pkmn))))) |
250 | 250 |
251 | |
252 | |
253 | |
251 (def hxc-items-raw | 254 (def hxc-items-raw |
252 "The hardcoded names of the items in memory. List begins at | 255 "The hardcoded names of the items in memory. List begins at |
253 ROM@045B7" | 256 ROM@045B7" |
254 (hxc-thunk-words 0x45B7 870)) | 257 (hxc-thunk-words 0x45B7 870)) |
255 | 258 |
256 (def hxc-types | 259 (def hxc-items |
257 "The hardcoded type names in memory. List begins at ROM@27D99, | 260 "The hardcoded names of the items in memory, presented as |
258 shortly before hxc-titles." | 261 keywords. List begins at ROM@045B7. See also, hxc-items-raw." |
259 (hxc-thunk-words 0x27D99 102)) | 262 (comp (partial map format-name) hxc-items-raw)) |
263 | |
264 | |
260 | 265 |
261 (def hxc-titles | 266 (def hxc-titles |
262 "The hardcoded names of the trainer titles in memory. List begins at | 267 "The hardcoded names of the trainer titles in memory. List begins at |
263 ROM@27E77" | 268 ROM@27E77" |
264 (hxc-thunk-words 0x27E77 196)) | 269 (hxc-thunk-words 0x27E77 196)) |
269 ROM@B8000, shortly before move names." | 274 ROM@B8000, shortly before move names." |
270 (hxc-thunk-words 0xB8000 14754)) | 275 (hxc-thunk-words 0xB8000 14754)) |
271 | 276 |
272 | 277 |
273 | 278 |
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)) | |
278 | 279 |
279 (defn hxc-pokedex-text | 280 (defn hxc-pokedex-text |
280 "The hardcoded pokedex entries in memory, presented as an | 281 "The hardcoded pokedex entries in memory, presented as an |
281 associative hash map. List begins at ROM@B8000." | 282 associative hash map. List begins at ROM@B8000." |
282 ([] (hxc-pokedex-text com.aurellem.gb.gb-driver/original-rom)) | 283 ([] (hxc-pokedex-text com.aurellem.gb.gb-driver/original-rom)) |
286 (cons nil ;; for missingno. | 287 (cons nil ;; for missingno. |
287 (hxc-pokedex-text-raw rom))))) | 288 (hxc-pokedex-text-raw rom))))) |
288 | 289 |
289 ;; In red/blue, pokedex stats are in internal order. | 290 ;; In red/blue, pokedex stats are in internal order. |
290 ;; In yellow, pokedex stats are in pokedex order. | 291 ;; In yellow, pokedex stats are in pokedex order. |
291 | |
292 (defn hxc-pokedex-stats | 292 (defn hxc-pokedex-stats |
293 "The hardcoded pokedex stats (species height weight) in memory. List | 293 "The hardcoded pokedex stats (species height weight) in memory. List |
294 begins at ROM@40687" | 294 begins at ROM@40687" |
295 ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom)) | 295 ([] (hxc-pokedex-stats com.aurellem.gb.gb-driver/original-rom)) |
296 ([rom] | 296 ([rom] |
346 (drop 0x40687 rom))) )) | 346 (drop 0x40687 rom))) )) |
347 | 347 |
348 | 348 |
349 | 349 |
350 | 350 |
351 | |
352 | |
353 | |
354 (def hxc-places | 351 (def hxc-places |
355 "The hardcoded place names in memory. List begins at | 352 "The hardcoded place names in memory. List begins at |
356 ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated." | 353 ROM@71500. [Cinnabar] Mansion seems to be dynamically calculated." |
357 (hxc-thunk-words 0x71500 560)) | 354 (hxc-thunk-words 0x71500 560)) |
358 | 355 |
371 | 368 |
372 | 369 |
373 (def hxc-move-names | 370 (def hxc-move-names |
374 "The hardcoded move names in memory. List begins at ROM@BC000" | 371 "The hardcoded move names in memory. List begins at ROM@BC000" |
375 (hxc-thunk-words 0xBC000 1551)) | 372 (hxc-thunk-words 0xBC000 1551)) |
376 | |
377 | |
378 (defn hxc-move-data | 373 (defn hxc-move-data |
379 "The hardcoded (basic (move effects)) in memory. List begins at | 374 "The hardcoded (basic (move effects)) in memory. List begins at |
380 0x38000. Returns a map of {:name :power :accuracy :pp :fx-id | 375 0x38000. Returns a map of {:name :power :accuracy :pp :fx-id |
381 :fx-txt}. The move descriptions are handwritten, not hardcoded." | 376 :fx-txt}. The move descriptions are handwritten, not hardcoded." |
382 ([] | 377 ([] |
455 (take 100 | 450 (take 100 |
456 (drop 0x1232D rom)))))))) | 451 (drop 0x1232D rom)))))))) |
457 | 452 |
458 | 453 |
459 | 454 |
455 | |
460 (defn internal-id | 456 (defn internal-id |
461 ([rom] | 457 ([rom] |
462 (zipmap | 458 (zipmap |
463 (hxc-pokenames rom) | 459 (hxc-pokenames rom) |
464 (range))) | 460 (range))) |
485 ;; ) | 481 ;; ) |
486 | 482 |
487 | 483 |
488 | 484 |
489 | 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 | |
493 | |
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)))))) | |
506 | 486 |
507 | 487 |
508 | 488 |
509 (defn format-evo | 489 (defn format-evo |
510 "Parse a sequence of evolution data, returning a map. First is the | 490 "Parse a sequence of evolution data, returning a map. First is the |
592 [pkmn (map (fn [[lvl mv]] [lvl (moves mv)]) | 572 [pkmn (map (fn [[lvl mv]] [lvl (moves mv)]) |
593 learnset)]) | 573 learnset)]) |
594 (hxc-learnsets rom)))))) | 574 (hxc-learnsets rom)))))) |
595 | 575 |
596 | 576 |
597 | |
598 | |
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 ))))) | |
614 | |
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 ))))] | |
648 | |
649 (into {} | |
650 (map (fn [[pkmn evo-coll]] | |
651 [pkmn (map use-names evo-coll)]) | |
652 (hxc-evolution rom)))))) | |
653 | |
654 | 577 |
655 (defn hxc-pokemon-base | 578 (defn hxc-pokemon-base |
656 ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom)) | 579 ([] (hxc-pokemon-base com.aurellem.gb.gb-driver/original-rom)) |
657 ([rom] | 580 ([rom] |
658 (let [entry-size 28 | 581 (let [entry-size 28 |
749 | 672 |
750 (partition entry-size | 673 (partition entry-size |
751 (take (* entry-size pkmn-count) | 674 (take (* entry-size pkmn-count) |
752 (drop 0x383DE | 675 (drop 0x383DE |
753 rom)))))))) | 676 rom)))))))) |
677 | |
754 | 678 |
755 | 679 |
756 (defn hxc-intro-pkmn | 680 (defn hxc-intro-pkmn |
757 "The hardcoded pokemon to display in Prof. Oak's introduction; the pokemon's | 681 "The hardcoded pokemon to display in Prof. Oak's introduction; the pokemon's |
758 internal id is stored at ROM@5EDB." | 682 internal id is stored at ROM@5EDB." |
824 ))) | 748 ))) |
825 | 749 |
826 | 750 |
827 | 751 |
828 | 752 |
829 | |
830 (defn hxc-ptrs-wild | 753 (defn hxc-ptrs-wild |
831 "A list of the hardcoded wild encounter data in memory. Pointers | 754 "A list of the hardcoded wild encounter data in memory. Pointers |
832 begin at ROM@0CB95; data begins at ROM@0x04D89" | 755 begin at ROM@0CB95; data begins at ROM@0x04D89" |
833 ([] (hxc-ptrs-wild com.aurellem.gb.gb-driver/original-rom)) | 756 ([] (hxc-ptrs-wild com.aurellem.gb.gb-driver/original-rom)) |
834 ([rom] | 757 ([rom] |
858 | 781 |
859 )))))) | 782 )))))) |
860 | 783 |
861 | 784 |
862 | 785 |
863 | |
864 | |
865 | |
866 | |
867 | |
868 | |
869 | |
870 | |
871 | |
872 | |
873 | |
874 ;; ********************** MANIPULATION FNS | 786 ;; ********************** MANIPULATION FNS |
875 | 787 |
876 | 788 |
877 (defn same-type | 789 (defn same-type |
878 ([pkmn move] | 790 ([pkmn move] |