Mercurial > vba-clojure
comparison clojure/com/aurellem/gb/items.clj @ 363:79252378fd22
saving progress...]
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Mon, 09 Apr 2012 10:35:22 -0500 |
parents | 3b3cd62b6106 |
children | 716752719a78 |
comparison
equal
deleted
inserted
replaced
362:8d8023057b3c | 363:79252378fd22 |
---|---|
177 0xFA :TM50 ;; substitute | 177 0xFA :TM50 ;; substitute |
178 0xFB :TM51 ;; "cut" | 178 0xFB :TM51 ;; "cut" |
179 0xFC :TM52 ;; "fly" | 179 0xFC :TM52 ;; "fly" |
180 0xFD :TM53 ;; "surf" | 180 0xFD :TM53 ;; "surf" |
181 0xFE :TM54 ;; "strength" | 181 0xFE :TM54 ;; "strength" |
182 0xFF :end-of-list-sentinel ;; also "flash" | 182 0xFF :TM55 ;; "flash" (also end-of-list-sentinel) |
183 )) | 183 )) |
184 | 184 |
185 (def item-name->item-code | 185 (def item-name->item-code |
186 (zipmap (vals item-code->item-name) | 186 (zipmap (vals item-code->item-name) |
187 (keys item-code->item-name))) | 187 (keys item-code->item-name))) |
196 quantity]) | 196 quantity]) |
197 (partition | 197 (partition |
198 2 | 198 2 |
199 raw-inventory))) | 199 raw-inventory))) |
200 | 200 |
201 (defn inventory [^SaveState state] | 201 (defn total-held-items [state] |
202 (let [items (item-list state)] | 202 (aget (memory state) item-list-start)) |
203 (raw-inventory->inventory | 203 |
204 (next (take-while (partial not= 255) items))))) | 204 (defn inventory |
205 ([^SaveState state] | |
206 (let [items (item-list state)] | |
207 (raw-inventory->inventory | |
208 (take (* 2 (total-held-items state)) (next items))))) | |
209 ([] (inventory @current-state))) | |
205 | 210 |
206 (defn print-inventory | 211 (defn print-inventory |
207 ([] (print-inventory @current-state)) | 212 ([] (print-inventory @current-state)) |
208 ([^SaveState state] | 213 ([^SaveState state] |
209 (println | 214 (println |
229 (flatten | 234 (flatten |
230 (concat [(count inventory)] | 235 (concat [(count inventory)] |
231 (map (fn [[item-name quantity]] | 236 (map (fn [[item-name quantity]] |
232 [(item-name->item-code item-name item-name) | 237 [(item-name->item-code item-name item-name) |
233 quantity]) inventory) | 238 quantity]) inventory) |
234 [(item-name->item-code :end-of-list-sentinel)]))) | 239 [(item-name->item-code :TM55)]))) |
235 | 240 |
236 (defn set-inv-mem [^SaveState state inv-codes] | 241 (defn set-inv-mem [^SaveState state inv-codes] |
237 (set-memory-range state item-list-start | 242 (set-memory-range state item-list-start |
238 inv-codes)) | 243 inv-codes)) |
239 | 244 |