changeset 323:92ee94945327

created functions to set the cursor to any position in any list
author Robert McIntyre <rlm@mit.edu>
date Wed, 04 Apr 2012 00:56:53 -0500
parents d604bd3c122c
children 7876781520ea
files clojure/com/aurellem/run/bootstrap_0.clj
diffstat 1 files changed, 28 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
     1.1 --- a/clojure/com/aurellem/run/bootstrap_0.clj	Wed Apr 04 00:35:44 2012 -0500
     1.2 +++ b/clojure/com/aurellem/run/bootstrap_0.clj	Wed Apr 04 00:56:53 2012 -0500
     1.3 @@ -337,11 +337,15 @@
     1.4                  "up-6"]))))
     1.5  
     1.6  
     1.7 +;; turns out that these addresses are the cursor position
     1.8 +;; for all lists in the game (start list, pokemon list, shop
     1.9 +;; lists, inventory lists, battle list, basically
    1.10 +;; everything!)
    1.11  
    1.12 -(def item-cursor-offset-address 52262)
    1.13 -(def item-screen-offset-address 52278)
    1.14 +(def list-cursor-offset-address 52262)
    1.15 +(def list-screen-offset-address 52278)
    1.16  
    1.17 -(defn item-offset
    1.18 +(defn list-offset
    1.19    ([^SaveState state]
    1.20       (let [mem (memory state)]
    1.21         (+ (aget mem item-screen-offset-address)
    1.22 @@ -349,6 +353,7 @@
    1.23    ([] (item-offset @current-state)))
    1.24  
    1.25  
    1.26 +
    1.27  (defn exp-item-selection []
    1.28    (clojure.pprint/pprint
    1.29     (apply memory-compare
    1.30 @@ -366,7 +371,27 @@
    1.31       (aget (memory state) item-quantity-selected-address))
    1.32    ([] (item-quantity-selected @current-state)))
    1.33  
    1.34 +(defn set-cursor-relative
    1.35 +  "Assumes the arrow keys currently control the cursor.
    1.36 +   Moves the cursor n steps relative to its current
    1.37 +   position."
    1.38 +  [n script]
    1.39 +  (let [key (if (< 0 n) ↓ ↑)]
    1.40 +    (multiple-times
    1.41 +     n (partial repeat-until-different
    1.42 +                key list-offset) script)))
    1.43  
    1.44 +(defn set-cursor
    1.45 +  "Assumes the arrow keys currently control the cursor. Sets
    1.46 +   the cursor to the desired position. Works for any menu
    1.47 +   that uses a cursor including the start menu, item menu,
    1.48 +   pokemon menu, and battle menu."
    1.49 +  [n [moves state :as script]]
    1.50 +  (let [current-position (list-offset state)
    1.51 +        difference (- n current-position)]
    1.52 +    (println difference)
    1.53 +    (set-cursor-relative difference script)))
    1.54 +  
    1.55  (defn buy-item
    1.56    "Assumes that the main item-screen is up, and buys
    1.57     quantity of the nth item in the list, assuming that you