Mercurial > vba-clojure
view clojure/com/aurellem/run/bootstrap_0.clj @ 319:92c47a9cdaea
adapting bootstrap to new util functions.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 03 Apr 2012 04:16:20 -0500 |
parents | 8e63b0bb8ea3 |
children | 9637a0f52e7b |
line wrap: on
line source
1 (ns com.aurellem.run.bootstrap-02 (:use (com.aurellem.gb gb-driver util items vbm characters money))3 (:use (com.aurellem.run util title save-corruption))4 (:use (com.aurellem.exp item-bridge))5 (:import [com.aurellem.gb.gb_driver SaveState]))7 (defn-memo boot-root []8 [ [] (root)])10 (defn-memo to-rival-name11 ([] (to-rival-name (boot-root)))12 ([script]13 (->> script14 title15 oak16 name-entry-rlm17 (scroll-text 5))))19 (defn-memo name-rival-bootstrap20 ([] (name-rival-bootstrap (to-rival-name)))21 ([script]22 (->> script23 (first-difference [] [:a] AF)24 (first-difference [] [:r] DE)25 (play-moves26 [[]27 [] [] [:r] [] [:d] [:a] ;; L28 [:r] [] [:r] [] [:r] [] [:r] []29 [:r] [] [:d] [] [:d] [:a] ;; [PK]30 [:u] [] [:l] [] [:l] []31 [:l] [] [:l] [] [:l] [:a] ;; U32 [:r] [] [:r] [] [:r] []33 [:r] [] [:r] [] [:d] [:a] ;; [PK]34 [] [:a] ;; [PK]35 [] [:a] ;; [PK]36 [:r] [] [:d] [:a] ;; END37 ]))))39 (defn-memo leave-house40 ([] (leave-house (name-rival-bootstrap)))41 ([script]42 (->> script43 finish-title44 walk-to-stairs45 walk-to-door46 (walk [↓ ↓]))))48 (defn-memo to-pallet-town-edge49 ([] (to-pallet-town-edge (leave-house)))50 ([script]51 (->> script52 (walk [→ → → → →53 ↑ ↑ ↑ ↑ ↑ ↑]))))55 (defn-memo start-pikachu-battle56 ([] (start-pikachu-battle57 (to-pallet-town-edge)))58 ([script]59 (->> script60 (first-difference [:b] [:b :a] DE)61 scroll-text62 (do-nothing 200)63 (play-moves [[:b]]))))65 (defn-memo capture-pikachu66 ([] (capture-pikachu (start-pikachu-battle)))67 ([script]68 (->> script69 (scroll-text 3))))71 (defn-memo go-to-lab72 ([] (go-to-lab (capture-pikachu)))73 ([script]74 (->> script75 end-text76 (scroll-text 5)77 end-text78 ;; oak walks you to his lab; no input required.79 (do-nothing 400))))81 (defn-memo talk-to-oak-in-lab82 ([] (talk-to-oak-in-lab (go-to-lab)))83 ([script]84 (->> script85 (scroll-text 14)86 end-text)))88 (defn-memo try-to-get-eevee89 ([] (try-to-get-eevee (talk-to-oak-in-lab)))90 ([script]91 (->> script92 ;; walk to pokeball93 (walk [↓ → →])94 ;; and try to grab it95 (play-moves96 (concat [↑ ↑ [:a]]97 (repeat 100 [])))98 (scroll-text 10)99 (end-text))))101 (defn-memo obtain-pikachu102 ([] (obtain-pikachu (try-to-get-eevee)))103 ([script]104 (->> script105 (scroll-text 6)106 (end-text))))109 (defn-memo begin-battle-with-rival110 ([] (begin-battle-with-rival111 (obtain-pikachu)))112 ([script]113 (->> script114 (walk [↓ ↓ ↓])115 (scroll-text 3)116 (end-text)117 (scroll-text))))119 (defn-memo defeat-eevee120 ([] (defeat-eevee121 (begin-battle-with-rival)))122 ([script]123 (->> script124 (do-nothing 400)125 (play-moves [[:a]])126 (critical-hit)127 (do-nothing 200)128 (scroll-text 2) ;; for eevee's tail-whip129 (do-nothing 10)130 (play-moves [[:a]])131 (critical-hit)132 (do-nothing 200)133 (scroll-text 2) ;; tail whip again134 (do-nothing 10)135 (play-moves [[:a]])136 (critical-hit)137 (do-nothing 200))))139 (defn-memo finish-rival-text140 ([] (finish-rival-text141 (defeat-eevee)))142 ([script]143 (->> script144 (scroll-text 12)145 (end-text))))147 (defn-memo pikachu-comes-out148 ([] (pikachu-comes-out149 (finish-rival-text)))150 ([script]151 (->> script152 (scroll-text 8)153 (end-text))))155 (defn-memo leave-oaks-lab156 ([] (leave-oaks-lab157 (pikachu-comes-out)))158 ([script]159 (->> script160 (walk [↓ ↓ ↓ ↓ ↓ ↓]))))162 (defn-memo oaks-lab->pallet-town-edge163 ([] (oaks-lab->pallet-town-edge164 (leave-oaks-lab)))165 ([script]166 (->> script167 (walk [← ← ←168 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ →]))))170 (defn-memo pallet-edge->viridian-mart171 ([] (pallet-edge->viridian-mart true172 (oaks-lab->pallet-town-edge)))173 ([dodge-stupid-guy? script]174 (let [dodge-1 (if dodge-stupid-guy?175 [→ →]176 [→])177 dodge-2 (if dodge-stupid-guy?178 [↑ ↑ ←]179 [↑ ↑])]181 (->> script182 ;; leave straight grass183 (walk-thru-grass184 [↑ ↑ ↑ ↑ ↑])186 (walk [↑ ↑ ↑ ↑])188 (walk-thru-grass189 [← ← ↑])191 (walk [↑ ↑ ↑ ↑ → → → ])193 (walk-thru-grass194 [→ ↑ ↑ ←])196 (walk197 [← ←198 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑199 → → → → ])201 ;; this part is dependent on that202 ;; stupid NPC in the grass patch203 (walk-thru-grass204 (concat dodge-1205 [↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ]))207 (walk208 (concat209 dodge-2210 [← ← ←211 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑212 ← ←213 ↑ ↑ ↑ ↑214 → → → → → → → → → →215 ↑ ↑ ↑ ↑ ↑ ↑ ↑]))))))217 (defn-memo get-oaks-parcel218 ([] (get-oaks-parcel219 (pallet-edge->viridian-mart)))220 ([script]221 (->> script222 (do-nothing 50)223 (end-text)224 (scroll-text 3)225 (do-nothing 197)226 (play-moves [[:a] []])227 (walk [↓ ↓ → ↓]))))229 (defn-memo viridian-store->oaks-lab230 ([] (viridian-store->oaks-lab231 (get-oaks-parcel)))232 ([script]233 (->> script234 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓235 ← ← ← ← ← ← ← ← ←236 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓237 ← ←238 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓239 ↓ ↓ ↓ ↓ ↓ ↓ ↓240 → → → → → → → →241 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓242 ← ← ← ← ←243 ↓ ↓ ↓ ↓244 ])245 (walk-thru-grass246 [↓ ↓ ↓ ↓ ↓ ↓ ↓])247 (walk [↓ ↓ ← ↓ ↓ ↓ ←248 ↓ ↓ ↓ ↓ ↓ ↓249 → → → ↑])251 (do-nothing 1))))254 (defn-memo viridian-store->oaks-lab-like-a-boss255 ([] (viridian-store->oaks-lab-like-a-boss256 (get-oaks-parcel)))257 ([script]258 (->> script259 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓260 ← ← ← ← ← ← ← ← ←261 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓])263 (walk-thru-grass264 [↓ ↓ ↓ ↓ ↓])266 (walk267 [↓ ↓ ← ↓268 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓269 → → → ↓])271 (walk-thru-grass272 [↓ ↓ ↓])274 (walk [↓ ← ← ↓ ↓ ↓ ↓ ↓ ↓])276 (walk-thru-grass277 [↓ ↓ ↓ ↓ ↓ ↓])279 (walk [↓ ↓ ↓ ← ↓ ↓ ↓280 ↓ ↓ ↓ ↓ ↓281 → → → ↑]))))283 (defn-memo deliver-oaks-parcel284 ([] (deliver-oaks-parcel285 (viridian-store->oaks-lab-like-a-boss)))286 ([script]287 (->> script288 (walk [↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑])289 (play-moves [[] [:a]])290 (scroll-text 13)291 (end-text)292 (do-nothing 200)293 (scroll-text 2)294 (end-text)295 (scroll-text 2)296 (end-text)297 (scroll-text 8)298 (end-text)299 (scroll-text 9)300 (end-text)301 (scroll-text 7)302 (end-text)303 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓]))))305 (defn-memo return-to-viridian-mart306 ([] (return-to-viridian-mart307 (deliver-oaks-parcel)))308 ([script]309 (->> script310 oaks-lab->pallet-town-edge311 (pallet-edge->viridian-mart false))))313 (defn-memo walk-to-counter314 ([] (walk-to-counter315 (return-to-viridian-mart)))316 ([script]317 (->> script318 (walk [↑ ↑ ←]))))320 (defn buy-item321 "Assumes that the main item-screen is up, and buys322 quantity of the nth item in the list, assuming that you323 have enough money."324 [n quantity script]325 (if (= 0 quantity)326 script327 (let [after-initial-pause328 (do-nothing 20 script)329 move-to-item330 (reduce (fn [script _]331 (->> script332 (play-moves [[:d]])333 (do-nothing 3)))334 after-initial-pause335 (range n))336 select-item337 (play-moves [[:a]] move-to-item)338 request-items339 (reduce (fn [script _]340 (->> script341 (play-moves [[:u]])342 (do-nothing 1)))343 select-item344 (range (dec quantity)))345 buy-items346 (->> request-items347 (do-nothing 10)348 (play-moves [[:a]])349 (scroll-text)350 (scroll-text)351 (do-nothing 10)352 (play-moves [[:a]])353 (scroll-text))]354 buy-items)))357 (defn buy-items358 "Given a list of [item-no quantity], buys the quantity359 from the shop's list. Assumes that the item list is360 already up."361 [item-pairs script]362 (let [item-lookup (into {0 0 1 0 2 0 3 0 4 0} item-pairs)363 initial-purchase364 (->> script365 (buy-item 0 (item-lookup 0))366 (buy-item 1 (item-lookup 1))367 (buy-item 2 (item-lookup 2)))]368 (cond369 (and370 (not= 0 (item-lookup 3))371 (not= 0 (item-lookup 4)))372 (->> initial-purchase373 (do-nothing 20)374 (play-moves [[:d]])375 (do-nothing 3)376 (play-moves [[:d]])377 (do-nothing 3)378 (play-moves [[:d]])379 (do-nothing 10)380 (buy-item 0 (item-lookup 3))381 (do-nothing 20)382 (play-moves [[:d]])383 (do-nothing 3)384 (play-moves [[:d]])385 (do-nothing 3)386 (play-moves [[:d]])387 (do-nothing 10)388 (buy-item 0 (item-lookup 4)))389 (and (= 0 (item-lookup 3))390 (not= 0 (item-lookup 4)))391 (->> initial-purchase392 (do-nothing 20)393 (play-moves [[:d]])394 (do-nothing 3)395 (play-moves [[:d]])396 (do-nothing 3)397 (play-moves [[:d]])398 (do-nothing 10)399 (play-moves [[:d]])400 (do-nothing 10)401 (buy-item 0 (item-lookup 4)))402 (and (not= 0 (item-lookup 3))403 (= 0 (item-lookup 4)))404 (->> initial-purchase405 (do-nothing 20)406 (play-moves [[:d]])407 (do-nothing 3)408 (play-moves [[:d]])409 (do-nothing 3)410 (play-moves [[:d]])411 (do-nothing 10)412 (buy-item 0 (item-lookup 3)))413 (and (= 0 (item-lookup 3))414 (= 0 (item-lookup 4)))415 initial-purchase)))418 (defn test-buy-items419 ([] (test-buy-items420 (walk-to-counter)))421 ([script]422 (->> [(first script) (set-money (second script)423 999999)]424 (play-moves425 [[] [:a] []])426 (scroll-text)427 (do-nothing 100)428 (play-moves [[:a]])429 (do-nothing 100)430 (buy-items431 [[0 1]432 [1 15]433 [2 1]434 [3 20]435 [4 95]436 ]))))438 (defn-memo buy-initial-items439 ([] (buy-initial-items440 (walk-to-counter)))441 ([script]442 (->> script443 (play-moves444 [[] [:a] []])445 (scroll-text)446 (do-nothing 100)447 (play-moves [[:a]])448 (do-nothing 100)449 (buy-items450 [[0 1]451 [1 1]452 [2 1]453 [3 1]454 [4 1]])455 (do-nothing 100)456 (play-moves [[:b]])457 (do-nothing 100)458 (play-moves [[:b]])459 (do-nothing 100)460 (play-moves [[:b] []])461 (first-difference [:b] [:b :start] AF))))464 (defn-memo do-save-corruption465 ([] (do-save-corruption466 (buy-initial-items)))467 ([script]468 (->> script469 (first-difference [] [:d] AF)470 (play-moves [[] [] [] [:d]471 [] [] [] [:d]472 [] [] [] [:d]473 [] [] [:a]])474 scroll-text475 (play-moves476 ;; this section is copied from speedrun-2942 and corrupts477 ;; the save so that the total number of pokemon is set to478 ;; 0xFF, allowing manipulation of non-pokemon data in RAM479 ;; via the pokemon interface.480 [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []481 [] [] [] [] [] [] [] [] [] [] [] [:select] [:restart]])482 (title)483 (first-difference [] [:start] AF)484 (first-difference [] [:a] AF)485 (first-difference [:a] [:a :start] AF))))487 (def menu do-nothing )489 (defn-memo corrupt-item-list490 ([] (corrupt-item-list491 (do-save-corruption)))492 ([script]493 (->> script494 (do-nothing 200)495 (menu [↓ [:a]]) ; select "POKEMON" from496 ; from main menu497 (menu [↓ ↓ ↓ ↓ ↓ ↓ ; go to 6th pokemon498 [:a] ↓ [:a] ; select "switch"499 ↓ ↓ ↓ [:a]]) ; switch with 9th "pokemon"501 (do-nothing 1))))503 (defn-memo get-burn-heals504 ([] (get-burn-heals505 (corrupt-item-list)))506 ([script]507 (->> script508 (menu [[:b] [:b]])509 (menu [[:a]])510 (do-nothing 100)511 (menu [↓ [:a]])512 (do-nothing 100)513 (menu [[:a] ↓ [:a]])514 (scroll-text)515 (menu [[:b][:b]])516 (menu [[:a]])518 (do-nothing 50)519 (buy-items [[0 1]])520 (do-nothing 60)521 (menu [[:a]])522 (scroll-text)524 (do-nothing 50)525 (buy-items [[0 1]])526 (do-nothing 60)527 ;;(menu [[:a]])528 ;;(scroll-text)530 ;;(do-nothing 300)531 ;;(menu [[:b] [:b]])532 ;;(do-nothing 300)534 (buy-items [[0 1]535 [1 1]536 [1 1]537 [2 1]538 [3 1]539 [4 97]])541 (do-nothing 10))))543 (defn-memo corrupt-item-list-again544 ([] (corrupt-item-list-again (get-burn-heals)))545 ([script]546 (->> script547 (do-nothing 10)548 (play-moves [[:b]])549 (do-nothing 100)550 (play-moves [[:b]])551 (do-nothing 40)552 (play-moves [[:b]])553 (first-difference [:b] [:start :b] AF)554 (menu [[:a] ↑ ↑ ↑ ↑ ↑ ; get fifth pokemon555 [:a] ↓ [:a] ; and corrupt the556 ↓ ↓ ↓ ↓ ↓ [:a]]) ; item list again by557 ; switching it to558 ))) ; tenth place.560 (defn-memo viridian-store->viridian-poke-center561 ([] (viridian-store->viridian-poke-center562 (corrupt-item-list-again)))563 ([script]564 (->> script565 (do-nothing 100)566 (play-moves [[:b]])567 (do-nothing 100)568 (play-moves [[:b]])569 (do-nothing 40)570 ;; leave store571 (walk [↓ ↓572 → ↓ ↓])573 (walk [← ← ← ←574 ↓ ↓ ↓ ↓ ↓ ↓575 ← ← ← ↑]))))577 (defn-memo to-poke-center-computer578 ([] (to-poke-center-computer579 (viridian-store->viridian-poke-center)))580 ([script]581 (->> script582 (walk [→ →583 ↑ ↑ ↑584 → → → → → → → → → ↑])585 (do-nothing 1))))587 (defn-memo begin-deposits588 ([] (begin-deposits589 (to-poke-center-computer)))590 ([script]591 (->> script592 ;; access PC593 (scroll-text 2)595 ;; access item storage596 (menu [[:a] [:d] [:a]])597 (scroll-text 2)599 ;; begin deposit600 (menu [[:d] [:a]])601 (do-nothing 40))))603 (defn deposit-n-items604 [n script]605 (->> script606 (do-nothing 100)607 (play-moves [[:a]])608 (do-nothing 80)609 (multiple-times610 (dec n)611 (fn [script]612 (->> script613 (play-moves [[:u]])614 (do-nothing 1))))615 (play-moves [[:a]])616 (scroll-text)))618 (defn deposit-one-item619 [script]620 (->> script621 (do-nothing 100)622 (play-moves [[:a]])623 (do-nothing 80)624 (play-moves [[:a]])625 (scroll-text)))627 (defn-memo create-header628 ([] (create-header (begin-deposits)))629 ([script]630 (->> script631 (multiple-times 33 deposit-one-item)632 (do-nothing 1))))634 (defn bootstrap-init []635 [(read-moves "bootstrap-init")636 (read-state "bootstrap-init")])638 (defn create-bootstrap-program639 ([] (create-bootstrap-program640 (create-header)))641 ([script]642 (->> script643 (do-nothing 120)644 (menu [↓ ↓ ↓ ↓ ↓ ↓ ↓])645 ;;(deposit-n-items 33)647 (menu (repeat 17 ↓))651 (do-nothing 1))))654 (defn test-pc-item-program []655 (-> (read-state "bootstrap-init")656 (set-memory pc-item-list-start 50)657 (set-memory-range658 map-function-address-start [0x8B 0xD5])659 (set-memory-range660 (inc pc-item-list-start)661 (flatten662 [(repeat663 28664 [0xFF 0x01])665 [;; second part of item manipulation program666 0x00 ;; this starts at address 0xD56C667 0x2A ;; save (HL)=(target) to A, increment HL669 0x00670 0x47 ;; save A to B672 0x00673 0x3A ;; save (target+1) to A, decrement HL675 0x00676 0x22 ;; A -> target, increment HL [(target+1) -> target]678 0x00679 0x70 ;; load B into target+1 [(target) -> target+1]681 0x00682 0xC3 ;; first part of absolute jump684 0x0C ;; return control to pokemon kernel685 0x5F]686 (repeat687 5688 [0xFF 0x01])690 [;; first part of item manipulation program691 0x00692 0x21 ;; load target into HL694 0x94 ;; this is the target address695 0xD5697 0x00 ;; relative jump back to first part698 0x18700 0xE1 ;; of program701 0x01703 0xFF ;; spacer704 0x01706 0x04 ;; target ID (pokeball)707 0x3E ;; target Quantity (lemonade)708 ]]))))