Mercurial > vba-clojure
comparison clojure/com/aurellem/exp/pokemon.clj @ 176:95b2758dd517
wrote functions to read and write pokemon DV values and status
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Wed, 21 Mar 2012 22:13:43 -0500 |
parents | 63ec3db6f6d1 |
children | 4f5ea93cbaca |
comparison
equal
deleted
inserted
replaced
175:5d9a7a0ca09a | 176:95b2758dd517 |
---|---|
114 (concat (str->character-codes new-name) | 114 (concat (str->character-codes new-name) |
115 [end-of-name-marker]))) | 115 [end-of-name-marker]))) |
116 ([new-name] | 116 ([new-name] |
117 (rename-sixth-pokemon @current-state new-name))) | 117 (rename-sixth-pokemon @current-state new-name))) |
118 | 118 |
119 (defn print-text | |
120 ([^SaveState state begin end] | |
121 (dorun | |
122 (map (fn [character-code line] | |
123 (println | |
124 (format "0x%04X: " line) | |
125 (str (character-code->character character-code)))) | |
126 (subvec (vec (memory state)) begin end) | |
127 (range begin end))) | |
128 state) | |
129 ([begin end] | |
130 (print-text @current-state begin end))) | |
131 | 119 |
132 (defn examine-name-memory [] | 120 (defn examine-name-memory [] |
133 (print-text | 121 (print-text |
134 named-A | 122 named-A |
135 (- sixth-pokemon-name-start 100) | 123 (- sixth-pokemon-name-start 100) |
515 ])) | 503 ])) |
516 ([n new-id] | 504 ([n new-id] |
517 (set-pokemon-id @current-state n new-id))) | 505 (set-pokemon-id @current-state n new-id))) |
518 | 506 |
519 | 507 |
520 | |
521 | |
522 | |
523 (defn get-pokemon-1-info | 508 (defn get-pokemon-1-info |
524 ([state] | 509 ([state] |
525 (subvec (vec (memory state)) | 510 (subvec (vec (memory state)) |
526 0xD162 0xD197)) | 511 0xD162 0xD197)) |
527 ([] (get-pokemon-1-info @current-state))) | 512 ([] (get-pokemon-1-info @current-state))) |
731 ;; Speed => 202 (+8) | 716 ;; Speed => 202 (+8) |
732 | 717 |
733 ;; 10000000 | 718 ;; 10000000 |
734 ;; Speed => 210 (+16) | 719 ;; Speed => 210 (+16) |
735 | 720 |
736 (def pokemon-1-DV-start 0xD185) | 721 |
737 | 722 ;; investigating status effects |
738 (defn pokemon-DV-start-point [poke-num] | 723 |
739 (+ (* poke-num pokemon-record-width) | 724 ;; status of pokemon 1 appears to be |
740 pokemon-1-DV-start)) | 725 ;; 0xD16E |
741 | 726 |
742 (def reverse-4-bit | 727 ;; with pidgeot |
743 {0 0 | 728 ;; 00000000 -- normal |
744 1 8 | 729 ;; 00000001 -- sleep (wake-immediately) |
745 2 4 | 730 ;; 00000010 -- sleep |
746 3 12 | 731 ;; 00000100 -- sleep |
747 5 10 | 732 ;; 00001000 -- poisoned |
748 6 6 | 733 ;; 00010000 -- burned |
749 7 14 | 734 ;; 00100000 -- frozen |
750 9 9 | 735 ;; 01000000 -- paralyzed |
751 15 15 | 736 ;; 10000000 -- ball is dark, but no status |
752 13 11 | 737 |
753 | 738 ;; with pikachu |
754 8 1 | 739 ;; 00000000 -- normal |
755 4 2 | 740 ;; 00000001 -- sleep (1 turn wasted) \ |
756 12 3 | 741 ;; 00000010 -- sleep (2 turns wasted) |-- additive |
757 10 5 | 742 ;; 00000100 -- sleep (3 turns wasted) / |
758 11 13 | 743 ;; 00001000 -- poisoned |
759 14 7 }) | 744 ;; 00010000 -- burned |
760 | 745 ;; 00100000 -- frozen |
761 (defn read-DV | 746 ;; 01000000 -- paralyzed |
762 ([^SaveState state poke-num] | 747 ;; 10000000 -- ball is dark, but no status |
763 (assert (<= 0 poke-num 5)) | 748 |
764 (let [[raw-DV-1 | 749 |
765 raw-DV-2] | 750 |
766 (subvec (vec (memory state)) | |
767 (pokemon-DV-start-point poke-num) | |
768 (+ 2 (pokemon-DV-start-point poke-num))) | |
769 defense-DV (bit-and raw-DV-1 0x0F) | |
770 attack-DV (bit-shift-right | |
771 (bit-and raw-DV-1 0xF0) | |
772 4) | |
773 special-DV (bit-and raw-DV-2 0x0F) | |
774 speed-DV (bit-shift-right | |
775 (bit-and raw-DV-2 0xF0) | |
776 4) | |
777 HP-DV | |
778 (+ | |
779 (if (bit-test special-DV 0) 1 0) | |
780 (if (bit-test speed-DV 0) 2 0) | |
781 (if (bit-test defense-DV 0) 4 0) | |
782 (if (bit-test attack-DV 0) 8 0))] | |
783 {:attack attack-DV | |
784 :defense defense-DV | |
785 :speed speed-DV | |
786 :special special-DV | |
787 :hp HP-DV})) | |
788 ([poke-num] | |
789 (read-DV @current-state poke-num))) | |
790 | |
791 | |
792 (defn give-DV | |
793 ([^SaveState state poke-num dv-values] | |
794 | |
795 (assert (<= 0 poke-num 5)) | |
796 (map #(assert (<= 0 % 15)) (vals dv-values)) | |
797 (let [raw-dv-1* | |
798 (+ (:defense dv-values) | |
799 (bit-shift-left (:attack dv-values) 4)) | |
800 raw-dv-2* | |
801 (+ (:special dv-values) | |
802 (bit-shift-left (:speed dv-values) 4)) | |
803 hp-dv (:hp dv-values) | |
804 hp-masks-1 | |
805 [[0 (bit-test hp-dv 2)] | |
806 [4 (bit-test hp-dv 3)]] | |
807 hp-masks-2 | |
808 [[0 (bit-test hp-dv 0)] | |
809 [4 (bit-test hp-dv 1)]] | |
810 set-hp-bits | |
811 (fn [init [index hp?]] | |
812 (if hp? | |
813 (bit-set init index) | |
814 (bit-clear init index))) | |
815 | |
816 raw-dv-1 (reduce set-hp-bits raw-dv-1* | |
817 hp-masks-1) | |
818 | |
819 raw-dv-2 (reduce set-hp-bits raw-dv-2* | |
820 hp-masks-2) | |
821 | |
822 dv-start (pokemon-DV-start-point poke-num)] | |
823 | |
824 (if (or (not= raw-dv-1* raw-dv-1) | |
825 (not= raw-dv-2* raw-dv-2)) | |
826 (println "Warning: inconsistent DV-values." | |
827 "Using HP settings.")) | |
828 | |
829 (set-memory | |
830 (set-memory state dv-start raw-dv-1) | |
831 (inc dv-start) raw-dv-2))) | |
832 ([poke-num dv-values] | |
833 (give-DV @current-state poke-num dv-values))) | |
834 | |
835 (def good-DVs | |
836 {:attack 15 | |
837 :defense 15 | |
838 :speed 15 | |
839 :special 15 | |
840 :hp 15}) | |
841 | |
842 (def bad-DVs | |
843 {:attack 0 | |
844 :defense 0 | |
845 :speed 0 | |
846 :special 0 | |
847 :hp 0}) | |
848 | |
849 |