Mercurial > vba-clojure
view clojure/com/aurellem/run/bootstrap_0.clj @ 317:3c5bf2221ea0
remove crufty functions.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 02 Apr 2012 21:25:24 -0500 |
parents | 8e63b0bb8ea3 |
children | 92c47a9cdaea |
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 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-text18 scroll-text19 scroll-text20 scroll-text21 scroll-text)))23 (defn-memo name-rival-bootstrap24 ([] (name-rival-bootstrap (to-rival-name)))25 ([script]26 (->> script27 (advance [] [:a])28 (advance [] [:r] DE)29 (play-moves30 [[]31 [] [] [:r] [] [:d] [:a] ;; L32 [:r] [] [:r] [] [:r] [] [:r] []33 [:r] [] [:d] [] [:d] [:a] ;; [PK]34 [:u] [] [:l] [] [:l] []35 [:l] [] [:l] [] [:l] [:a] ;; U36 [:r] [] [:r] [] [:r] []37 [:r] [] [:r] [] [:d] [:a] ;; [PK]38 [] [:a] ;; [PK]39 [] [:a] ;; [PK]40 [:r] [] [:d] [:a] ;; END41 ]))))43 (defn-memo leave-house44 ([] (leave-house (name-rival-bootstrap)))45 ([script]46 (->> script47 finish-title48 start-walking49 walk-to-stairs50 walk-to-door51 (walk [↓ ↓]))))53 (defn-memo to-pallet-town-edge54 ([] (to-pallet-town-edge (leave-house)))55 ([script]56 (->> script57 start-walking58 (walk [→ → → → →59 ↑ ↑ ↑ ↑ ↑ ↑]))))61 (defn-memo start-pikachu-battle62 ([] (start-pikachu-battle63 (to-pallet-town-edge)))64 ([script]65 (->> script66 (advance [:b] [:b :a] DE)67 (scroll-text)68 (play-moves [[:b]])69 (scroll-text)70 (end-text) ;; battle begins71 (scroll-text))))73 (defn-memo capture-pikachu74 ([] (capture-pikachu (start-pikachu-battle)))75 ([script]76 (->> script77 (scroll-text 2)78 (end-text))))80 (defn-memo go-to-lab81 ([] (go-to-lab (capture-pikachu)))82 ([script]83 (->> script84 (scroll-text 5)85 (end-text)86 (scroll-text)87 (end-text)88 (scroll-text 8)89 (end-text)90 (scroll-text)91 (end-text))))93 (defn-memo obtain-pikachu94 ([] (obtain-pikachu (go-to-lab)))95 ([script]96 (->> script97 (scroll-text)98 (play-moves99 (concat100 (repeat 51 [])101 [[:a] []]))102 (walk [↓ ↓ → → ↑])103 (play-moves104 (concat [[] [:a]]105 (repeat 100 [])))106 (scroll-text 9)107 (end-text)108 (scroll-text 7)110 (play-moves111 (concat112 (repeat 50 [])113 [[:b] [] []])))))115 (defn-memo begin-battle-with-rival116 ([] (begin-battle-with-rival117 (obtain-pikachu)))118 ([script]119 (->> script120 (walk [↓ ↓ ↓ ↓])121 (scroll-text 3)122 (end-text)123 (scroll-text))))125 (defn-memo battle-with-rival126 ([] (battle-with-rival127 (begin-battle-with-rival)))128 ([script]129 (->> script130 (do-nothing 400)131 (play-moves [[:a]])132 (critical-hit)133 (do-nothing 100)134 (scroll-text)135 (do-nothing 275)136 (play-moves [[:a]])137 (critical-hit)138 (do-nothing 100)139 (scroll-text)140 (do-nothing 270)141 (play-moves [[:a]])142 (critical-hit)143 (do-nothing 100)144 (scroll-text))))146 (defn-memo finish-rival-text147 ([] (finish-rival-text148 (battle-with-rival)))149 ([script]150 (->> script151 (scroll-text 2)152 (end-text)153 (scroll-text 9)154 (end-text))))156 (defn-memo pikachu-comes-out157 ([] (pikachu-comes-out158 (finish-rival-text)))159 ([script]160 (->> script161 (do-nothing 177)162 (end-text)163 (scroll-text 7)164 (end-text))))166 (defn-memo leave-oaks-lab167 ([] (leave-oaks-lab168 (pikachu-comes-out)))169 ([script]170 (->> script171 (walk [← ← ↓ ↓ ↓ ↓ ↓ ↓]))))173 (defn-memo oaks-lab->pallet-town-edge174 ([] (oaks-lab->pallet-town-edge175 (leave-oaks-lab)))176 ([script]177 (->> script178 (walk [← ← ← ←179 ↑ ↑ ↑ ↑180 ↑ ↑ ↑ ↑ ↑ ↑181 → ↑]))))183 (defn-memo pallet-edge->viridian-mart184 ([] (pallet-edge->viridian-mart true185 (oaks-lab->pallet-town-edge)))186 ([dodge-stupid-guy? script]187 (let [dodge-1 (if dodge-stupid-guy?188 [→ →]189 [→])190 dodge-2 (if dodge-stupid-guy?191 [↑ ↑ ←]192 [↑ ↑ ←])]194 (->> script195 ;; leave straight grass196 (walk-thru-grass197 [↑ ↑ ↑ ↑ ↑])199 (walk [↑ ↑ ↑ ↑])201 (walk-thru-grass202 [← ← ↑])204 (walk [↑ ↑ ↑ ↑ → → → ])206 (walk-thru-grass207 [→ ↑ ↑ ←])209 (walk210 [← ←211 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑212 → → → → ])214 ;; this part is dependent on that215 ;; stupid NPC in the grass patch216 (walk-thru-grass217 (concat dodge-1218 [↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ]))220 (walk221 (concat222 dodge-2223 [← ← ←224 ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑225 ← ←226 ↑ ↑ ↑ ↑227 → → → → → → → → → →228 ↑ ↑ ↑ ↑ ↑ ↑ ↑]))))))230 (defn-memo get-oaks-parcel231 ([] (get-oaks-parcel232 (pallet-edge->viridian-mart)))233 ([script]234 (->> script235 (end-text)236 (scroll-text 3)237 (do-nothing 197)238 (play-moves [[:a] []])239 (walk [↓ ↓ → ↓]))))241 (defn-memo viridian-store->oaks-lab242 ([] (viridian-store->oaks-lab243 (get-oaks-parcel)))244 ([script]245 (->> script246 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓247 ← ← ← ← ← ← ← ← ← ←248 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓249 ← ←250 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓251 ↓ ↓ ↓ ↓ ↓ ↓ ↓252 → → → → → → → →253 ↓ ↓ ↓ ↓254 ← ← ← ← ←255 ↓ ↓ ↓ ↓])257 (walk-thru-grass258 [↓ ↓ ↓ ↓ ↓ ↓ ↓])260 (walk [↓ ↓ ← ↓ ↓ ↓ ←261 ↓ ↓ ↓ ↓ ↓262 → → → ↑]))))264 (defn-memo viridian-store->oaks-lab-like-a-boss265 ([] (viridian-store->oaks-lab-like-a-boss266 (get-oaks-parcel)))267 ([script]268 (->> script269 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓270 ← ← ← ← ← ← ← ← ← ←271 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓])273 (walk-thru-grass274 [↓ ↓ ↓ ↓ ↓])276 (walk277 [↓ ↓ ← ↓278 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓279 → →])281 (walk-thru-grass282 [→ ↓ ↓ ↓])284 (walk [↓ ← ← ↓ ↓ ↓ ↓ ↓ ↓])286 (walk-thru-grass287 [↓ ↓ ↓ ↓ ↓ ↓ ↓])289 (walk [↓ ↓ ← ↓ ↓ ↓ ←290 ↓ ↓ ↓ ↓ ↓291 → → → ↑]))))293 (defn-memo deliver-oaks-parcel294 ([] (deliver-oaks-parcel295 (viridian-store->oaks-lab-like-a-boss)))296 ([script]297 (->> script298 (walk [↑ ↑ ↑ ↑ ↑ ↑ ↑ ↑])299 (play-moves [[:a]])300 (scroll-text 11)301 (end-text)302 (end-text)303 (do-nothing 200)304 (end-text)305 (scroll-text 3)306 (end-text)307 (scroll-text 2)308 (end-text)309 (scroll-text 5)310 (end-text)311 (scroll-text 2)312 (end-text)313 (scroll-text 9)314 (end-text)315 (scroll-text 7)316 (end-text)317 (walk [← ← ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓]))))319 (defn-memo return-to-viridian-mart320 ([] (return-to-viridian-mart321 (deliver-oaks-parcel)))322 ([script]323 (->> script324 oaks-lab->pallet-town-edge325 (pallet-edge->viridian-mart false))))327 (defn-memo walk-to-counter328 ([] (walk-to-counter329 (return-to-viridian-mart)))330 ([script]331 (->> script332 (walk [↑ ↑ ← ←]))))334 (defn buy-item335 "Assumes that the main item-screen is up, and buys336 quantity of the nth item in the list, assuming that you337 have enough money."338 [n quantity script]339 (if (= 0 quantity)340 script341 (let [after-initial-pause342 (do-nothing 20 script)343 move-to-item344 (reduce (fn [script _]345 (->> script346 (play-moves [[:d]])347 (do-nothing 3)))348 after-initial-pause349 (range n))350 select-item351 (play-moves [[:a]] move-to-item)352 request-items353 (reduce (fn [script _]354 (->> script355 (play-moves [[:u]])356 (do-nothing 1)))357 select-item358 (range (dec quantity)))359 buy-items360 (->> request-items361 (do-nothing 10)362 (play-moves [[:a]])363 (scroll-text)364 (scroll-text)365 (do-nothing 10)366 (play-moves [[:a]])367 (scroll-text))]368 buy-items)))371 (defn buy-items372 "Given a list of [item-no quantity], buys the quantity373 from the shop's list. Assumes that the item list is374 already up."375 [item-pairs script]376 (let [item-lookup (into {0 0 1 0 2 0 3 0 4 0} item-pairs)377 initial-purchase378 (->> script379 (buy-item 0 (item-lookup 0))380 (buy-item 1 (item-lookup 1))381 (buy-item 2 (item-lookup 2)))]382 (cond383 (and384 (not= 0 (item-lookup 3))385 (not= 0 (item-lookup 4)))386 (->> initial-purchase387 (do-nothing 20)388 (play-moves [[:d]])389 (do-nothing 3)390 (play-moves [[:d]])391 (do-nothing 3)392 (play-moves [[:d]])393 (do-nothing 10)394 (buy-item 0 (item-lookup 3))395 (do-nothing 20)396 (play-moves [[:d]])397 (do-nothing 3)398 (play-moves [[:d]])399 (do-nothing 3)400 (play-moves [[:d]])401 (do-nothing 10)402 (buy-item 0 (item-lookup 4)))403 (and (= 0 (item-lookup 3))404 (not= 0 (item-lookup 4)))405 (->> initial-purchase406 (do-nothing 20)407 (play-moves [[:d]])408 (do-nothing 3)409 (play-moves [[:d]])410 (do-nothing 3)411 (play-moves [[:d]])412 (do-nothing 10)413 (play-moves [[:d]])414 (do-nothing 10)415 (buy-item 0 (item-lookup 4)))416 (and (not= 0 (item-lookup 3))417 (= 0 (item-lookup 4)))418 (->> initial-purchase419 (do-nothing 20)420 (play-moves [[:d]])421 (do-nothing 3)422 (play-moves [[:d]])423 (do-nothing 3)424 (play-moves [[:d]])425 (do-nothing 10)426 (buy-item 0 (item-lookup 3)))427 (and (= 0 (item-lookup 3))428 (= 0 (item-lookup 4)))429 initial-purchase)))432 (defn test-buy-items433 ([] (test-buy-items434 (walk-to-counter)))435 ([script]436 (->> [(first script) (set-money (second script)437 999999)]438 (play-moves439 [[] [:a] []])440 (scroll-text)441 (do-nothing 100)442 (play-moves [[:a]])443 (do-nothing 100)444 (buy-items445 [[0 1]446 [1 15]447 [2 1]448 [3 20]449 [4 95]450 ]))))452 (defn-memo buy-initial-items453 ([] (buy-initial-items454 (walk-to-counter)))455 ([script]456 (->> script457 (play-moves458 [[] [:a] []])459 (scroll-text)460 (do-nothing 100)461 (play-moves [[:a]])462 (do-nothing 100)463 (buy-items464 [[0 1]465 [1 1]466 [2 1]467 [3 1]468 [4 1]])469 (do-nothing 100)470 (play-moves [[:b]])471 (do-nothing 100)472 (play-moves [[:b]])473 (do-nothing 100)474 (play-moves [[:b] []])475 (advance [:b] [:b :start]))))478 (defn-memo do-save-corruption479 ([] (do-save-corruption480 (buy-initial-items)))481 ([script]482 (->> script483 (advance [] [:d])484 (play-moves [[] [] [] [:d]485 [] [] [] [:d]486 [] [] [] [:d]487 [] [] [:a]])488 scroll-text489 (play-moves490 ;; this section is copied from speedrun-2942 and corrupts491 ;; the save so that the total number of pokemon is set to492 ;; 0xFF, allowing manipulation of non-pokemon data in RAM493 ;; via the pokemon interface.494 [[] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] [] []495 [] [] [] [] [] [] [] [] [] [] [] [:select] [:restart]])496 (title)497 (advance [] [:start])498 (advance [] [:a])499 (advance [:a] [:a :start]))))501 (defn-memo corrupt-item-list502 ([] (corrupt-item-list503 (do-save-corruption)))504 ([script]505 (->> script506 (do-nothing 200)507 (menu [↓ [:a]]) ; select "POKEMON" from508 ; from main menu509 (menu [↓ ↓ ↓ ↓ ↓ ↓ ; go to 6th pokemon510 [:a] ↓ [:a] ; select "switch"511 ↓ ↓ ↓ [:a]]) ; switch with 9th "pokemon"513 (do-nothing 1))))515 (defn-memo get-burn-heals516 ([] (get-burn-heals517 (corrupt-item-list)))518 ([script]519 (->> script520 (menu [[:b] [:b]])521 (menu [[:a]])522 (do-nothing 100)523 (menu [↓ [:a]])524 (do-nothing 100)525 (menu [[:a] ↓ [:a]])526 (scroll-text)527 (menu [[:b][:b]])528 (menu [[:a]])530 (do-nothing 50)531 (buy-items [[0 1]])532 (do-nothing 60)533 (menu [[:a]])534 (scroll-text)536 (do-nothing 50)537 (buy-items [[0 1]])538 (do-nothing 60)539 ;;(menu [[:a]])540 ;;(scroll-text)542 ;;(do-nothing 300)543 ;;(menu [[:b] [:b]])544 ;;(do-nothing 300)546 (buy-items [[0 1]547 [1 1]548 [1 1]549 [2 1]550 [3 1]551 [4 97]])553 (do-nothing 10))))555 (defn-memo corrupt-item-list-again556 ([] (corrupt-item-list-again (get-burn-heals)))557 ([script]558 (->> script559 (do-nothing 10)560 (play-moves [[:b]])561 (do-nothing 100)562 (play-moves [[:b]])563 (do-nothing 40)564 (play-moves [[:b]])565 (advance [:b] [:start :b])566 (menu [[:a] ↑ ↑ ↑ ↑ ↑ ; get fifth pokemon567 [:a] ↓ [:a] ; and corrupt the568 ↓ ↓ ↓ ↓ ↓ [:a]]) ; item list again by569 ; switching it to570 ))) ; tenth place.572 (defn-memo viridian-store->viridian-poke-center573 ([] (viridian-store->viridian-poke-center574 (corrupt-item-list-again)))575 ([script]576 (->> script577 (do-nothing 100)578 (play-moves [[:b]])579 (do-nothing 100)580 (play-moves [[:b]])581 (do-nothing 40)582 ;; leave store583 (walk [↓ ↓584 → ↓ ↓])585 (walk [← ← ← ←586 ↓ ↓ ↓ ↓ ↓ ↓587 ← ← ← ↑]))))589 (defn-memo to-poke-center-computer590 ([] (to-poke-center-computer591 (viridian-store->viridian-poke-center)))592 ([script]593 (->> script594 (walk [→ →595 ↑ ↑ ↑596 → → → → → → → → → ↑])597 (do-nothing 1))))599 (defn-memo begin-deposits600 ([] (begin-deposits601 (to-poke-center-computer)))602 ([script]603 (->> script604 ;; access PC605 (scroll-text 2)607 ;; access item storage608 (menu [[:a] [:d] [:a]])609 (scroll-text 2)611 ;; begin deposit612 (menu [[:d] [:a]])613 (do-nothing 40))))615 (defn deposit-n-items616 [n script]617 (->> script618 (do-nothing 100)619 (play-moves [[:a]])620 (do-nothing 80)621 (multiple-times622 (dec n)623 (fn [script]624 (->> script625 (play-moves [[:u]])626 (do-nothing 1))))627 (play-moves [[:a]])628 (scroll-text)))630 (defn deposit-one-item631 [script]632 (->> script633 (do-nothing 100)634 (play-moves [[:a]])635 (do-nothing 80)636 (play-moves [[:a]])637 (scroll-text)))639 (defn-memo create-header640 ([] (create-header (begin-deposits)))641 ([script]642 (->> script643 (multiple-times 33 deposit-one-item)644 (do-nothing 1))))646 (defn bootstrap-init []647 [(read-moves "bootstrap-init")648 (read-state "bootstrap-init")])650 (defn create-bootstrap-program651 ([] (create-bootstrap-program652 (create-header)))653 ([script]654 (->> script655 (do-nothing 120)656 (menu [↓ ↓ ↓ ↓ ↓ ↓ ↓])657 ;;(deposit-n-items 33)659 (menu (repeat 17 ↓))663 (do-nothing 1))))666 (defn test-pc-item-program []667 (-> (read-state "bootstrap-init")668 (set-memory pc-item-list-start 50)669 (set-memory-range670 map-function-address-start [0x8B 0xD5])671 (set-memory-range672 (inc pc-item-list-start)673 (flatten674 [(repeat675 28676 [0xFF 0x01])677 [;; second part of item manipulation program678 0x00 ;; this starts at address 0xD56C679 0x2A ;; save (HL)=(target) to A, increment HL681 0x00682 0x47 ;; save A to B684 0x00685 0x3A ;; save (target+1) to A, decrement HL687 0x00688 0x22 ;; A -> target, increment HL [(target+1) -> target]690 0x00691 0x70 ;; load B into target+1 [(target) -> target+1]693 0x00694 0xC3 ;; first part of absolute jump696 0x0C ;; return control to pokemon kernel697 0x5F]698 (repeat699 5700 [0xFF 0x01])702 [;; first part of item manipulation program703 0x00704 0x21 ;; load target into HL706 0x94 ;; this is the target address707 0xD5709 0x00 ;; relative jump back to first part710 0x18712 0xE1 ;; of program713 0x01715 0xFF ;; spacer716 0x01718 0x04 ;; target ID (pokeball)719 0x3E ;; target Quantity (lemonade)720 ]]))))