Mercurial > vba-clojure
comparison clojure/com/aurellem/gb/types.clj @ 190:9a7a46c4aa1b
extending functionality of support namespaces in prepreation of give-pokemon
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Thu, 22 Mar 2012 16:34:10 -0500 |
parents | 4f5ea93cbaca |
children | 85a2c2e2d318 |
comparison
equal
deleted
inserted
replaced
189:d954835b24a4 | 190:9a7a46c4aa1b |
---|---|
21 | 21 |
22 (def type-name->type-code | 22 (def type-name->type-code |
23 (zipmap (vals type-code->type-name) | 23 (zipmap (vals type-code->type-name) |
24 (keys type-code->type-name))) | 24 (keys type-code->type-name))) |
25 | 25 |
26 (def pokemon-1-types-start-address 0xD16F) | 26 (def pokemon-1-type-start-address 0xD16F) |
27 | 27 |
28 (defn pokemon-type-start-address [poke-num] | 28 (defn pokemon-type-start-address [poke-num] |
29 (+ pokemon-1-types-start-address | 29 (+ pokemon-1-type-start-address |
30 (* pokemon-record-width poke-num))) | 30 (* pokemon-record-width poke-num))) |
31 | 31 |
32 (defn give-type | 32 (defn give-type |
33 ([^SaveState state poke-num types] | 33 ([^SaveState state poke-num types] |
34 (assert (<= 0 poke-num 5)) | 34 (assert (<= 0 poke-num 5)) |
41 (pokemon-type-start-address poke-num) | 41 (pokemon-type-start-address poke-num) |
42 (map type-name->type-code types)))) | 42 (map type-name->type-code types)))) |
43 ([poke-num types] | 43 ([poke-num types] |
44 (give-type @current-state poke-num types))) | 44 (give-type @current-state poke-num types))) |
45 | 45 |
46 (defn read-types | 46 (defn read-type |
47 ([^SaveState state poke-num] | 47 ([^SaveState state poke-num] |
48 (assert (<= 0 poke-num 5)) | 48 (assert (<= 0 poke-num 5)) |
49 (let [types-start (pokemon-type-start-address poke-num) | 49 (let [types-start (pokemon-type-start-address poke-num) |
50 [type-1 type-2] | 50 [type-1 type-2] |
51 (subvec (vec (memory state)) | 51 (subvec (vec (memory state)) |
52 types-start (+ 2 types-start))] | 52 types-start (+ 2 types-start))] |
53 (if (= type-1 type-2) | 53 (if (= type-1 type-2) |
54 [(type-code->type-name type-1)] | 54 [(type-code->type-name type-1)] |
55 (mapv type-code->type-name [type-1 type-2])))) | 55 (mapv type-code->type-name [type-1 type-2])))) |
56 ([poke-num] | 56 ([poke-num] |
57 (read-types @current-state poke-num))) | 57 (read-type @current-state poke-num))) |
58 | 58 |