view clojure/com/aurellem/gb/items.clj @ 173:8665160f0f3d

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