view clojure/com/aurellem/gb/items.clj @ 298:95afeea88c3a

found a second good character-item that can serve as a target
author Robert McIntyre <rlm@mit.edu>
date Fri, 30 Mar 2012 22:41:25 -0500
parents b7f682bb3090
children 93e74ed34305
line wrap: on
line source
1 (ns com.aurellem.gb.items
2 (:use (com.aurellem.gb gb-driver util))
3 (:import [com.aurellem.gb.gb_driver SaveState]))
5 (defn game-name
6 "return pokemon-yellow header information"
7 []
8 (map char (subvec (vec (memory)) 0x134 0x142)))
10 (def item-list-start 0xD31C)
12 (defn item-list
13 ([^SaveState state]
14 (subvec
15 (vec (memory state))
16 item-list-start
17 (+ item-list-start 255)))
18 ([] (item-list @current-state)))
20 (def item-code->item-name
21 (hash-map
22 0x01 :master-ball
23 0x02 :ultra-ball
24 0x03 :great-ball
25 0x04 :poke-ball
26 0x05 :town-map
27 0x06 :bicycle
28 0x07 :surfboard
29 0x08 :safari-ball
30 0x09 :pokedex
31 0x0A :moon-stone
32 0x0B :antidote
33 0x0C :burn-heal
34 0x0D :ice-heal
35 0x0E :awakening
36 0x0F :parlyz-heal
37 0x10 :full-restore
38 0x11 :max-potion
39 0x12 :hyper-potion
40 0x13 :super-potion
41 0x14 :potion
42 0x15 :boulderbadge
43 0x16 :cascadebadge
44 0x17 :thunderbadge
45 0x18 :rainbowbadge
46 0x19 :soulbadge
47 0x1A :marshbadge
48 0x1B :volcanobadge
49 0x1C :earthbadge
50 0x1D :escape-rope
51 0x1E :repel
52 0x1F :old-amber
53 0x20 :fire-stone
54 0x21 :thunderstone
55 0x22 :water-stone
56 0x23 :hp-up
57 0x24 :protein
58 0x25 :iron
59 0x26 :carbos
60 0x27 :calcium
61 0x28 :rare-candy
62 0x29 :dome-fossil
63 0x2A :helix-fossil
64 0x2B :secret-key
65 0x2D :bike-voucher
66 0x2E :x-accuracy
67 0x2F :leaf-stone
68 0x30 :card-key
69 0x31 :nugget
70 0x32 :pp-up-glitched
71 0x33 :poke-doll
72 0x34 :full-heal
73 0x35 :revive
74 0x36 :max-revive
75 0x37 :guard-spec
76 0x38 :super-repel
77 0x39 :max-repel
78 0x3A :dire-hit
79 0x3B :coin
80 0x3C :fresh-water
81 0x3D :soda-pop
82 0x3E :lemonade
83 0x3F :s.s.ticket
84 0x40 :gold-teeth
85 0x41 :x-attack
86 0x42 :x-defend
87 0x43 :x-speed
88 0x44 :x-special
89 0x45 :coin-case
90 0x46 :oaks-parcel
91 0x47 :itemfinder
92 0x48 :silph-scope
93 0x49 :poke-flute
94 0x4A :lift-key
95 0x4B :exp.all
96 0x4C :old-rod
97 0x4D :good-rod
98 0x4E :super-rod
99 0x4F :pp-up
100 0x50 :ether
101 0x51 :max-ether
102 0x52 :elixer
103 0x53 :max-elixer
104 0xC4 :HM01 ;; cut
105 0xC5 :HM02 ;; fly
106 0xC6 :HM03 ;; surf
107 0xC7 :HM04 ;; strength
108 0xC8 :HM05 ;; flash
109 0xC9 :TM01 ;; mega punch
110 0xCA :TM02 ;; razor wind
111 0xCB :TM03 ;; swords dance
112 0xCC :TM04 ;; whirlwind
113 0xCD :TM05 ;; mega kick
114 0xCE :TM06 ;; toxic
115 0xCF :TM07 ;; horn drill
116 0xD0 :TM08 ;; body slam
117 0xD1 :TM09 ;; take down
118 0xD2 :TM10 ;; double-edge
119 0xD3 :TM11 ;; bubblebeam
120 0xD4 :TM12 ;; water gun
121 0xD5 :TM13 ;; ice beam
122 0xD6 :TM14 ;; blizzard
123 0xD7 :TM15 ;; hyper beam
124 0xD8 :TM16 ;; pay day
125 0xD9 :TM17 ;; submission
126 0xDA :TM18 ;; counter
127 0xDB :TM19 ;; seismic toss
128 0xDC :TM20 ;; rage
129 0xDD :TM21 ;; mega drain
130 0xDE :TM22 ;; solarbeam
131 0xDF :TM23 ;; dragon rage
132 0xE0 :TM24 ;; thunderbolt
133 0xE1 :TM25 ;; thunder
134 0xE2 :TM26 ;; earthquake
135 0xE3 :TM27 ;; fissure
136 0xE4 :TM28 ;; dig
137 0xE5 :TM29 ;; psychic
138 0xE6 :TM30 ;; teleport
139 0xE7 :TM31 ;; mimic
140 0xE8 :TM32 ;; double team
141 0xE9 :TM33 ;; reflect
142 0xEA :TM34 ;; bide
143 0xEB :TM35 ;; metronome
144 0xEC :TM36 ;; self destruct
145 0xED :TM37 ;; eggbomb
146 0xEE :TM38 ;; fire blast
147 0xEF :TM39 ;; swift
148 0xF0 :TM40 ;; skull bash
149 0xF1 :TM41 ;; softboiled
150 0xF2 :TM42 ;; dream eater
151 0xF3 :TM43 ;; sky attack
152 0xF4 :TM44 ;; rest
153 0xF5 :TM45 ;; thunder wave
154 0xF6 :TM46 ;; psywave
155 0xF7 :TM47 ;; explosion
156 0xF8 :TM48 ;; rock slide
157 0xF9 :TM49 ;; tri attack
158 0xFA :TM50 ;; substitute
159 0xFB :TM51 ;; "cut"
160 0xFC :TM52 ;; "fly"
161 0xFD :TM53 ;; "surf"
162 0xFE :TM54 ;; "strength"
163 0xFF :end-of-list-sentinel ;; also "flash"
164 ))
166 (def item-name->item-code
167 (zipmap (vals item-code->item-name)
168 (keys item-code->item-name)))
170 (defn inventory [^SaveState state]
171 (let [items (item-list state)]
172 (map
173 (fn [[item-code quantity]]
174 [(item-code->item-name
175 item-code
176 item-code)
177 quantity])
178 (partition
179 2
180 (next (take-while (partial not= 255) items))))))
182 (defn print-inventory
183 ([] (print-inventory @current-state))
184 ([^SaveState state]
185 (println
186 (let [inv (inventory state)]
187 (reduce
188 str
189 (concat
190 ["+-------------------+----------+\n"
191 "|##| Item | Quantity |\n"
192 "+--+----------------+----------+\n"]
194 (map
195 (fn [index [item-name quantity]]
196 (str
197 (format "|%-2d| %-14s | %3d |\n" index
198 (apply str (rest (str item-name)))
199 quantity)))
200 (range 0 (count inv)) inv)
201 ["+--+----------------+----------+\n"]))))
202 state))
204 (defn inventory-codes [inventory]
205 (flatten
206 (concat [(count inventory)]
207 (map (fn [[item-name quantity]]
208 [(item-name->item-code item-name item-name)
209 quantity]) inventory)
210 [(item-name->item-code :end-of-list-sentinel)])))
212 (defn set-inv-mem [^SaveState state inv-codes]
213 (set-memory-range state item-list-start
214 inv-codes))
217 (defn set-inventory [^SaveState state new-inventory]
218 (set-inv-mem state (inventory-codes new-inventory)))
220 (defn give-items
221 ([^SaveState state items]
222 (set-inventory state
223 (concat items (inventory state))))
224 ([items]
225 (give-items @current-state items)))
227 (defn clear-inventory
228 ([^SaveState state]
229 (set-inventory state []))
230 ([] (clear-inventory @current-state)))