view 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
line wrap: on
line source
1 (ns com.aurellem.gb.types
2 (:use (com.aurellem.gb gb-driver util constants))
3 (:import [com.aurellem.gb.gb_driver SaveState]))
5 (def type-code->type-name
6 {0x00 :normal
7 0x01 :fighting
8 0x02 :flying
9 0x03 :poision
10 0x04 :ground
11 0x05 :rock
12 0x07 :bug
13 0x08 :ghost
14 0x14 :fire
15 0x15 :water
16 0x16 :grass
17 0x17 :electric
18 0x18 :psychic
19 0x19 :ice
20 0x1A :dragon})
22 (def type-name->type-code
23 (zipmap (vals type-code->type-name)
24 (keys type-code->type-name)))
26 (def pokemon-1-type-start-address 0xD16F)
28 (defn pokemon-type-start-address [poke-num]
29 (+ pokemon-1-type-start-address
30 (* pokemon-record-width poke-num)))
32 (defn give-type
33 ([^SaveState state poke-num types]
34 (assert (<= 0 poke-num 5))
35 (let [types*
36 (if (= (count types) 1)
37 [(first types) (first types)]
38 types)]
39 (set-memory-range
40 state
41 (pokemon-type-start-address poke-num)
42 (map type-name->type-code types))))
43 ([poke-num types]
44 (give-type @current-state poke-num types)))
46 (defn read-type
47 ([^SaveState state poke-num]
48 (assert (<= 0 poke-num 5))
49 (let [types-start (pokemon-type-start-address poke-num)
50 [type-1 type-2]
51 (subvec (vec (memory state))
52 types-start (+ 2 types-start))]
53 (if (= type-1 type-2)
54 [(type-code->type-name type-1)]
55 (mapv type-code->type-name [type-1 type-2]))))
56 ([poke-num]
57 (read-type @current-state poke-num)))