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