# HG changeset patch # User Robert McIntyre # Date 1332499556 18000 # Node ID 912496041f988b995bd6d4e6327b8f59efe306d1 # Parent 45f1376b578c34e5a247e7e36c0094fdf1899ccb give pokemon appears to work. diff -r 45f1376b578c -r 912496041f98 clojure/com/aurellem/gb/moves.clj --- a/clojure/com/aurellem/gb/moves.clj Fri Mar 23 04:39:24 2012 -0500 +++ b/clojure/com/aurellem/gb/moves.clj Fri Mar 23 05:45:56 2012 -0500 @@ -264,6 +264,20 @@ (give-pp @current-state pokemon-num move-num pp-ups current-pp))) +(defn give-moves-pps + ([^SaveState state poke-num moves-pps] + (let [new-moves + (-> state + (give-moves poke-num (map first moves-pps)))] + (reduce (fn [state move-num] + (let [pp (second (nth moves-pps move-num))] + (give-pp state poke-num move-num + (:pp-ups pp) + (:current-pp pp)))) + new-moves (range (count moves-pps))))) + ([poke-num moves-pps] + (give-moves-pps @current-state poke-num moves-pps))) + (def move-name->move-pp { @@ -378,7 +392,7 @@ :rock-throw 15 :rolling-kick 15 :sand-attack 15 - :scratch 30 + :scratch 35 :screech 40 :seismic-toss 20 :selfdestruct 5 diff -r 45f1376b578c -r 912496041f98 clojure/com/aurellem/gb/pokemon.clj --- a/clojure/com/aurellem/gb/pokemon.clj Fri Mar 23 04:39:24 2012 -0500 +++ b/clojure/com/aurellem/gb/pokemon.clj Fri Mar 23 05:45:56 2012 -0500 @@ -69,7 +69,7 @@ (defn read-OT-name ([^SaveState state poke-num] (nth (original-trainers state) poke-num)) - ([poke-num] (read-OT @current-state poke-num))) + ([poke-num] (read-OT-name @current-state poke-num))) (defn set-OT-name "Set the OT name for a pokemon. @@ -83,7 +83,7 @@ (+ (* poke-num name-width) OT-start) (concat (str->character-codes new-name) [end-of-name-marker]))) ([n new-name] - (set-original-trainer @current-state n new-name))) + (set-OT-name @current-state n new-name))) (def OT-ID-addresses [0xD176 0xD1A2 0xD1CE 0xD1FA 0xD226 0xD252]) @@ -105,7 +105,7 @@ (OT-ID-addresses poke-num) (disect-bytes-2 new-OT-num))) ([poke-num new-OT-num] - (set-pokemon-id @current-state poke-num new-OT-num))) + (set-OT-id @current-state poke-num new-OT-num))) (def unknown "[[[UNKNOWN]]]") @@ -203,7 +203,7 @@ (def mint-berry-item-code-gsc 0x54) -(defn pokemon-info +(defn pokemon ([^SaveState state poke-num] (assert (<= 0 poke-num 5)) (let [dv-values (read-DV state poke-num) @@ -236,7 +236,7 @@ :experience experience })) ([poke-num] - (pokemon-info @current-state poke-num))) + (pokemon @current-state poke-num))) (def status-message {:sleep-6 "sleeping. It will wake in six turns." @@ -253,7 +253,7 @@ (defn print-pokemon ([^SaveState state poke-num] - (let [info (pokemon-info state poke-num)] + (let [info (pokemon state poke-num)] (printf (str "##################################" @@ -373,15 +373,14 @@ :hp-exp 0xFFFF} :stats - ;; TODO recalculate these from a real ditto {:level 7 - :current-hp 50 - :hp 50 - :attack 50 - :defense 50 - :speed 50 - :special 50} - :moves [[:transform {:pp-up 3 :pp 5}]]}) + :current-hp 30 + :hp 30 + :attack 18 + :defense 18 + :speed 18 + :special 18} + :moves [[:transform {:pp-ups 3 :current-pp 5}]]}) (defn expand-pokemon "Given a map describing a pokemon, fill in any missing @@ -401,7 +400,8 @@ ;; same as species. ((fn [pokemon] (if (nil? (:species2 pokemon)) - (assoc pokemon :species2 (:species pokemon))))) + (assoc pokemon :species2 (:species pokemon)) + pokemon))) ;; enable the date in :moves to be any combo of ;; [:move-1 :move-2] @@ -415,11 +415,11 @@ (for [move moves] (cond (keyword? move) - [move {:pp (max-pp move) :pp-up 0}] + [move {:current-pp (max-pp move) :pp-ups 0}] (vector? move) [(first move) - (merge {:pp (max-pp (first move) 0) - :pp-up 0} (second move))])))))) + (merge {:current-pp (max-pp (first move) 0) + :pp-ups 0} (second move))])))))) ;; The game stores the pokemon's type redundantly ;; along with the species. If it's not specified ;; then it should default to that species default type. @@ -429,3 +429,24 @@ (pokemon->type (:species pokemon))) pokemon))))) +(defn give-pokemon + ([^SaveState state poke-num pokemon] + (let [pokemon* (expand-pokemon pokemon)] + (-> state + ;; expand roster if necessary + ((fn [state] + (if (< (dec (party-number state)) poke-num) + (set-party-number state (inc poke-num)) state))) + (rename-pokemon poke-num (:name pokemon*)) + (give-DV poke-num (:dv pokemon*)) + (give-type poke-num (:type pokemon*)) + (set-species poke-num (:species pokemon*)) + (set-species2 poke-num (:species2 pokemon*)) + (set-OT-id poke-num (:ID pokemon*)) + (set-OT-name poke-num (:original-trainer pokemon*)) + (give-moves-pps poke-num (:moves pokemon*)) + (give-status poke-num (:status pokemon*)) + (give-stats poke-num (:stats pokemon*)) + (give-experience poke-num (:experience pokemon*))))) + ([poke-num pokemon] + (give-pokemon @current-state poke-num pokemon))) \ No newline at end of file diff -r 45f1376b578c -r 912496041f98 clojure/com/aurellem/gb/stats.clj --- a/clojure/com/aurellem/gb/stats.clj Fri Mar 23 04:39:24 2012 -0500 +++ b/clojure/com/aurellem/gb/stats.clj Fri Mar 23 05:45:56 2012 -0500 @@ -28,7 +28,7 @@ (defn set-current-hp ([^SaveState state poke-num new-hp] - (set-memory state (current-hp-address poke-num) + (set-memory-range state (current-hp-address poke-num) (disect-bytes-2 new-hp))) ([poke-num new-hp] (set-current-hp @current-state poke-num new-hp))) @@ -71,9 +71,10 @@ (disect-bytes-2 (:defense new-stats*)) (disect-bytes-2 (:speed new-stats*)) (disect-bytes-2 (:special new-stats*))])] - (set-current-hp + (set-current-hp (set-memory-range state (pokemon-stats-address poke-num) raw-stats) + poke-num (:current-hp new-stats*)))) ([poke-num new-stats] (give-stats @current-state poke-num new-stats)))