Mercurial > vba-clojure
comparison clojure/com/aurellem/gb/pokemon.clj @ 209:912496041f98
give pokemon appears to work.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Fri, 23 Mar 2012 05:45:56 -0500 |
parents | 45f1376b578c |
children | 565f5d17f90a |
comparison
equal
deleted
inserted
replaced
208:45f1376b578c | 209:912496041f98 |
---|---|
67 ([] (original-trainers @current-state))) | 67 ([] (original-trainers @current-state))) |
68 | 68 |
69 (defn read-OT-name | 69 (defn read-OT-name |
70 ([^SaveState state poke-num] | 70 ([^SaveState state poke-num] |
71 (nth (original-trainers state) poke-num)) | 71 (nth (original-trainers state) poke-num)) |
72 ([poke-num] (read-OT @current-state poke-num))) | 72 ([poke-num] (read-OT-name @current-state poke-num))) |
73 | 73 |
74 (defn set-OT-name | 74 (defn set-OT-name |
75 "Set the OT name for a pokemon. | 75 "Set the OT name for a pokemon. |
76 Note that a pokemon is still considered 'yours' if | 76 Note that a pokemon is still considered 'yours' if |
77 the OT ID is the same as your own." | 77 the OT ID is the same as your own." |
81 (set-memory-range | 81 (set-memory-range |
82 state | 82 state |
83 (+ (* poke-num name-width) OT-start) | 83 (+ (* poke-num name-width) OT-start) |
84 (concat (str->character-codes new-name) [end-of-name-marker]))) | 84 (concat (str->character-codes new-name) [end-of-name-marker]))) |
85 ([n new-name] | 85 ([n new-name] |
86 (set-original-trainer @current-state n new-name))) | 86 (set-OT-name @current-state n new-name))) |
87 | 87 |
88 (def OT-ID-addresses [0xD176 0xD1A2 0xD1CE 0xD1FA 0xD226 0xD252]) | 88 (def OT-ID-addresses [0xD176 0xD1A2 0xD1CE 0xD1FA 0xD226 0xD252]) |
89 | 89 |
90 (defn read-OT-id | 90 (defn read-OT-id |
91 ([^SaveState state poke-num] | 91 ([^SaveState state poke-num] |
103 (set-memory-range | 103 (set-memory-range |
104 state | 104 state |
105 (OT-ID-addresses poke-num) | 105 (OT-ID-addresses poke-num) |
106 (disect-bytes-2 new-OT-num))) | 106 (disect-bytes-2 new-OT-num))) |
107 ([poke-num new-OT-num] | 107 ([poke-num new-OT-num] |
108 (set-pokemon-id @current-state poke-num new-OT-num))) | 108 (set-OT-id @current-state poke-num new-OT-num))) |
109 | 109 |
110 (def unknown "[[[UNKNOWN]]]") | 110 (def unknown "[[[UNKNOWN]]]") |
111 | 111 |
112 (def unknown "") | 112 (def unknown "") |
113 | 113 |
201 ([pokemon-num] | 201 ([pokemon-num] |
202 (print-pokemon-record @current-state pokemon-num))) | 202 (print-pokemon-record @current-state pokemon-num))) |
203 | 203 |
204 (def mint-berry-item-code-gsc 0x54) | 204 (def mint-berry-item-code-gsc 0x54) |
205 | 205 |
206 (defn pokemon-info | 206 (defn pokemon |
207 ([^SaveState state poke-num] | 207 ([^SaveState state poke-num] |
208 (assert (<= 0 poke-num 5)) | 208 (assert (<= 0 poke-num 5)) |
209 (let [dv-values (read-DV state poke-num) | 209 (let [dv-values (read-DV state poke-num) |
210 type (read-type state poke-num) | 210 type (read-type state poke-num) |
211 species (read-species state poke-num) | 211 species (read-species state poke-num) |
234 :status status | 234 :status status |
235 :stats stats | 235 :stats stats |
236 :experience experience | 236 :experience experience |
237 })) | 237 })) |
238 ([poke-num] | 238 ([poke-num] |
239 (pokemon-info @current-state poke-num))) | 239 (pokemon @current-state poke-num))) |
240 | 240 |
241 (def status-message | 241 (def status-message |
242 {:sleep-6 "sleeping. It will wake in six turns." | 242 {:sleep-6 "sleeping. It will wake in six turns." |
243 :sleep-5 "sleeping. It will wake in five turns." | 243 :sleep-5 "sleeping. It will wake in five turns." |
244 :sleep-4 "sleeping. It will wake in four turns." | 244 :sleep-4 "sleeping. It will wake in four turns." |
251 :paralyzed "paralyzed."}) | 251 :paralyzed "paralyzed."}) |
252 | 252 |
253 | 253 |
254 (defn print-pokemon | 254 (defn print-pokemon |
255 ([^SaveState state poke-num] | 255 ([^SaveState state poke-num] |
256 (let [info (pokemon-info state poke-num)] | 256 (let [info (pokemon state poke-num)] |
257 (printf | 257 (printf |
258 (str | 258 (str |
259 "##################################" | 259 "##################################" |
260 "##################################\n" | 260 "##################################\n" |
261 "# " | 261 "# " |
371 :speed-exp 0xFFFF | 371 :speed-exp 0xFFFF |
372 :special-exp 0xFFFF | 372 :special-exp 0xFFFF |
373 :hp-exp 0xFFFF} | 373 :hp-exp 0xFFFF} |
374 | 374 |
375 :stats | 375 :stats |
376 ;; TODO recalculate these from a real ditto | |
377 {:level 7 | 376 {:level 7 |
378 :current-hp 50 | 377 :current-hp 30 |
379 :hp 50 | 378 :hp 30 |
380 :attack 50 | 379 :attack 18 |
381 :defense 50 | 380 :defense 18 |
382 :speed 50 | 381 :speed 18 |
383 :special 50} | 382 :special 18} |
384 :moves [[:transform {:pp-up 3 :pp 5}]]}) | 383 :moves [[:transform {:pp-ups 3 :current-pp 5}]]}) |
385 | 384 |
386 (defn expand-pokemon | 385 (defn expand-pokemon |
387 "Given a map describing a pokemon, fill in any missing | 386 "Given a map describing a pokemon, fill in any missing |
388 values based on the ones already present." | 387 values based on the ones already present." |
389 [pokemon] | 388 [pokemon] |
399 pokemon))) | 398 pokemon))) |
400 ;; species2 should almost always just be the | 399 ;; species2 should almost always just be the |
401 ;; same as species. | 400 ;; same as species. |
402 ((fn [pokemon] | 401 ((fn [pokemon] |
403 (if (nil? (:species2 pokemon)) | 402 (if (nil? (:species2 pokemon)) |
404 (assoc pokemon :species2 (:species pokemon))))) | 403 (assoc pokemon :species2 (:species pokemon)) |
404 pokemon))) | |
405 | 405 |
406 ;; enable the date in :moves to be any combo of | 406 ;; enable the date in :moves to be any combo of |
407 ;; [:move-1 :move-2] | 407 ;; [:move-1 :move-2] |
408 ;; [[:move-1 {:pp 20}] :move-2] | 408 ;; [[:move-1 {:pp 20}] :move-2] |
409 ;; [[:move-1 {:pp 20 :pp-up 3}] :move-2] | 409 ;; [[:move-1 {:pp 20 :pp-up 3}] :move-2] |
413 (let [moves (:moves pokemon)] | 413 (let [moves (:moves pokemon)] |
414 (assoc pokemon :moves | 414 (assoc pokemon :moves |
415 (for [move moves] | 415 (for [move moves] |
416 (cond | 416 (cond |
417 (keyword? move) | 417 (keyword? move) |
418 [move {:pp (max-pp move) :pp-up 0}] | 418 [move {:current-pp (max-pp move) :pp-ups 0}] |
419 (vector? move) | 419 (vector? move) |
420 [(first move) | 420 [(first move) |
421 (merge {:pp (max-pp (first move) 0) | 421 (merge {:current-pp (max-pp (first move) 0) |
422 :pp-up 0} (second move))])))))) | 422 :pp-ups 0} (second move))])))))) |
423 ;; The game stores the pokemon's type redundantly | 423 ;; The game stores the pokemon's type redundantly |
424 ;; along with the species. If it's not specified | 424 ;; along with the species. If it's not specified |
425 ;; then it should default to that species default type. | 425 ;; then it should default to that species default type. |
426 ((fn [pokemon] | 426 ((fn [pokemon] |
427 (if (nil? (:type pokemon)) | 427 (if (nil? (:type pokemon)) |
428 (assoc pokemon :type | 428 (assoc pokemon :type |
429 (pokemon->type (:species pokemon))) | 429 (pokemon->type (:species pokemon))) |
430 pokemon))))) | 430 pokemon))))) |
431 | 431 |
432 (defn give-pokemon | |
433 ([^SaveState state poke-num pokemon] | |
434 (let [pokemon* (expand-pokemon pokemon)] | |
435 (-> state | |
436 ;; expand roster if necessary | |
437 ((fn [state] | |
438 (if (< (dec (party-number state)) poke-num) | |
439 (set-party-number state (inc poke-num)) state))) | |
440 (rename-pokemon poke-num (:name pokemon*)) | |
441 (give-DV poke-num (:dv pokemon*)) | |
442 (give-type poke-num (:type pokemon*)) | |
443 (set-species poke-num (:species pokemon*)) | |
444 (set-species2 poke-num (:species2 pokemon*)) | |
445 (set-OT-id poke-num (:ID pokemon*)) | |
446 (set-OT-name poke-num (:original-trainer pokemon*)) | |
447 (give-moves-pps poke-num (:moves pokemon*)) | |
448 (give-status poke-num (:status pokemon*)) | |
449 (give-stats poke-num (:stats pokemon*)) | |
450 (give-experience poke-num (:experience pokemon*))))) | |
451 ([poke-num pokemon] | |
452 (give-pokemon @current-state poke-num pokemon))) |