view clojure/com/aurellem/gb/items.clj @ 207:a67f1df5d096

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