comparison clojure/com/aurellem/run/bootstrap_1.clj @ 368:08f8284e2f1b

cleaning up code
author Robert McIntyre <rlm@mit.edu>
date Tue, 10 Apr 2012 03:32:47 -0500
parents 845b2d88bef9
children abcc522a3242
comparison
equal deleted inserted replaced
367:845b2d88bef9 368:08f8284e2f1b
106 0x18 ;; relative jump backwards 106 0x18 ;; relative jump backwards
107 0xCD ;; literal -51 == TM05; go back to input section 107 0xCD ;; literal -51 == TM05; go back to input section
108 0x01 ;; (item-hack) will never reach this instruction 108 0x01 ;; (item-hack) will never reach this instruction
109 109
110 ] 110 ]
111 (repeat 8 [0x00 0x01]) 111 (repeat 8 [0x00 0x02]);; these can be anything
112 112
113 [;; jump to actual program 113 [;; jump to actual program
114 0x00 114 0x00
115 0x37 ;; (item-hack) set carry flag no-op 115 0x37 ;; (item-hack) set carry flag no-op
116 116
203 (defn wait-for-quantity 203 (defn wait-for-quantity
204 [[moves state :as script]] 204 [[moves state :as script]]
205 (if (not= (item-quantity-selected state) 1) 205 (if (not= (item-quantity-selected state) 1)
206 (repeat-until-different [] item-quantity-selected script) 206 (repeat-until-different [] item-quantity-selected script)
207 script)) 207 script))
208
209 ;; TODO use this:
210 ;;(wait-until (partial set-cursor-relative 1))
208 211
209 (defn wait-for-cursor 212 (defn wait-for-cursor
210 [[moves state :as script]] 213 [[moves state :as script]]
211 (if (not= (list-offset state) 0) 214 (if (not= (list-offset state) 0)
212 (repeat-until-different [] list-offset script) 215 (repeat-until-different [] list-offset script)
382 "Assumes that you are facing something that initiates text and 385 "Assumes that you are facing something that initiates text and
383 causes it to do so." 386 causes it to do so."
384 [script] 387 [script]
385 (->> script 388 (->> script
386 (delayed-difference [] [:a] 100 389 (delayed-difference [] [:a] 100
387 #(aget (memory %) text-address)))) 390 first-character)))
388 391
389 (defn-memo get-money-floor-two 392 (defn-memo get-money-floor-two
390 ([] (get-money-floor-two (go-to-floor-two))) 393 ([] (get-money-floor-two (go-to-floor-two)))
391 ([script] 394 ([script]
392 (->> script 395 (->> script
644 activate-rlm-pc 647 activate-rlm-pc
645 begin-withdraw 648 begin-withdraw
646 (widthdraw-pc-item 0 99) 649 (widthdraw-pc-item 0 99)
647 (widthdraw-pc-item 0 1) 650 (widthdraw-pc-item 0 1)
648 (widthdraw-pc-item 2 0xFE) 651 (widthdraw-pc-item 2 0xFE)
649 (widthdraw-pc-item 3 0xFE)))) 652 (widthdraw-pc-item 3 0xFE)
653 close-menu)))
650 654
651 (defn-memo hacking-4 655 (defn-memo hacking-4
652 ([] (hacking-4 (hacking-3))) 656 ([] (hacking-4 (hacking-3)))
653 ([script] 657 ([script]
654 (->> script 658 (->> script
655 close-menu
656 begin-deposit 659 begin-deposit
657 (deposit-held-item 19 243) 660 (deposit-held-item 19 243)
658 (deposit-held-item-named :lemonade 16) 661 (deposit-held-item-named :lemonade 16)
659 (deposit-held-item 18 224)))) 662 (deposit-held-item 18 224))))
660 663
694 (deposit-held-item-named :ice-heal 55) 697 (deposit-held-item-named :ice-heal 55)
695 (deposit-held-item-named :fire-stone 23) 698 (deposit-held-item-named :fire-stone 23)
696 (deposit-held-item-named :burn-heal 12) 699 (deposit-held-item-named :burn-heal 12)
697 close-menu))) 700 close-menu)))
698 701
702 (defn switch-items [item-fn idx-1 idx-2 script]
703 (->> script
704 (wait-until select-menu-entry)
705 (set-cursor idx-1)
706 (wait-until select-menu-entry)
707 (play-moves [[][:select][]])
708 (set-cursor idx-2)
709 (delayed-difference [] [:select] 100
710 #(item-fn % (list-offset %)))))
711
712 (def switch-pc-items (partial switch-items nth-pc-item))
713 (def switch-held-items (partial switch-items nth-item))
714
715 (defn combine-pc-items [idx-1 script]
716 (->> script
717 (switch-pc-items idx-1 (inc idx-1))))
718
699 (defn combine-items [idx-1 script] 719 (defn combine-items [idx-1 script]
700 (->> script 720 (->> script
701 (wait-until select-menu-entry) 721 (wait-until select-menu-entry)
702 (set-cursor idx-1) 722 (set-cursor idx-1)
703 (wait-until select-menu-entry) 723 (wait-until select-menu-entry)
729 (widthdraw-pc-item 8 1) 749 (widthdraw-pc-item 8 1)
730 (widthdraw-pc-item 8 1) 750 (widthdraw-pc-item 8 1)
731 (widthdraw-pc-item 9 0xFE) 751 (widthdraw-pc-item 9 0xFE)
732 (multiple-times 752 (multiple-times
733 7 753 7
734 (partial combine-items 2)) 754 (partial combine-pc-items 2))
735 close-menu))) 755 close-menu)))
736 756
737 (defn-memo hacking-10 757 (defn-memo hacking-10
738 ([] (hacking-10 (hacking-9))) 758 ([] (hacking-10 (hacking-9)))
739 ([script] 759 ([script]
800 (delayed-difference [] [:a] 100 #(search-string % "Is")) 820 (delayed-difference [] [:a] 100 #(search-string % "Is"))
801 (scroll-text) 821 (scroll-text)
802 select-menu-entry 822 select-menu-entry
803 (scroll-text)))) 823 (scroll-text))))
804 824
805 (defn hacking-13 825 (defn-memo hacking-13
806 ([] (hacking-13 (hacking-12))) 826 ([] (hacking-13 (hacking-12)))
807 ([script] 827 ([script]
808 (->> script 828 (->> script
809 (set-cursor-relative 1) 829 (set-cursor-relative 1)
810 (select-menu-entry) 830 (select-menu-entry)
811 (toss-pc-item 1 1) 831 (toss-pc-item 1 1)
812 (toss-pc-item 0 156) 832 (toss-pc-item 0 156)
813 (toss-pc-item 0 11) 833 (toss-pc-item 0 11))))
814 close-menu))) 834
815 835 (defn confirm-pattern []
836 (let [start-address (inc pc-item-list-start)
837 target-pattern (pc-item-writer-program)
838 actual-pattern
839 (subvec (vec (memory (second (hacking-13))))
840 start-address
841 (+ start-address (count target-pattern)))]
842 (println target-pattern)
843 (println actual-pattern)
844 (= target-pattern actual-pattern)))
845
846 ;; this will be useful for starting program
847
848
849 (defn-memo go-to-mansion-for-the-lulz
850 ([] (go-to-mansion-for-the-lulz (hacking-13)))
851 ([script]
852 (->> script
853 close-menu
854 close-menu
855 end-text ;;grr
856 (walk [↓ ← ← ← ← ← ← ← ← ← ↓ ↓ ↓])
857 (walk (repeat 17 ←))
858 (walk [↑ → → → → ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑])
859 (walk [↓ ← ↑])
860 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓
861 ← ← ← ← ↑ ↑ ↑ ← ↑])
862 (talk)
863 (scroll-text 2)
864 close-menu)))
865
866 (defn get-cursor [script]
867 (wait-until (partial set-cursor-relative 1) script))
868
869 (defn-memo launch-bootstrap-program
870 ([] (launch-bootstrap-program
871 (go-to-mansion-for-the-lulz)))
872 ([script]
873 (->> script
874 ;; must corrupt item list again by switching pokemon
875 activate-start-menu
876 ;;get-cursor
877 (set-cursor 0)
878 select-menu-entry
879 ;;get-cursor
880 (select-menu-entry)
881 ;;get-cursor
882 (set-cursor 1)
883 (select-menu-entry)
884 ;;get-cursor
885 (set-cursor 3)
886 (delayed-difference [] [:a] 50 first-character)
887 close-menu
888 ;; now, open items and set map-function
889 ;;get-cursor
890 (set-cursor 1)
891 (select-menu-entry)
892 (toss-held-item 22 12)
893 (switch-held-items 22 40)
894 close-all-menus)))
816 895
817 896
818 897
819 898
820
821
822
823