rlm@176
|
1 (ns com.aurellem.gb.pokemon
|
rlm@190
|
2 (:use (com.aurellem.gb gb-driver util constants characters
|
rlm@190
|
3 moves types items status dv species
|
rlm@192
|
4 experience stats
|
rlm@190
|
5 ))
|
rlm@176
|
6 (:import [com.aurellem.gb.gb_driver SaveState]))
|
rlm@176
|
7
|
rlm@176
|
8 (def pokemon-names-start 0xD2B4)
|
rlm@176
|
9
|
rlm@179
|
10 (defn set-party-number
|
rlm@179
|
11 ([^SaveState state new-party-num]
|
rlm@179
|
12 (set-memory state 0xD162 new-party-num))
|
rlm@179
|
13 ([new-party-num]
|
rlm@179
|
14 (set-party-number @current-state new-party-num)))
|
rlm@176
|
15
|
rlm@176
|
16 (def party-number-address 0xD162)
|
rlm@176
|
17
|
rlm@176
|
18 (defn party-number
|
rlm@176
|
19 ([^SaveState state]
|
rlm@176
|
20 (aget (memory state) party-number-address))
|
rlm@176
|
21 ([] (party-number @current-state)))
|
rlm@176
|
22
|
rlm@176
|
23 (defn party-names
|
rlm@176
|
24 ([^SaveState state]
|
rlm@176
|
25 (let [raw-names
|
rlm@176
|
26 (subvec (vec (memory state))
|
rlm@176
|
27 pokemon-names-start
|
rlm@176
|
28 (+ pokemon-names-start
|
rlm@176
|
29 (* name-width 6)))]
|
rlm@176
|
30 (map
|
rlm@176
|
31 read-name
|
rlm@176
|
32 (take
|
rlm@176
|
33 (party-number state)
|
rlm@176
|
34 (partition name-width
|
rlm@176
|
35 raw-names)))))
|
rlm@176
|
36 ([] (party-names @current-state)))
|
rlm@176
|
37
|
rlm@191
|
38 (defn pokemon-nickname
|
rlm@191
|
39 ([^SaveState state poke-num]
|
rlm@191
|
40 (nth (party-names state) poke-num))
|
rlm@191
|
41 ([poke-num]
|
rlm@191
|
42 (pokemon-nickname @current-state poke-num)))
|
rlm@191
|
43
|
rlm@176
|
44 (defn rename-pokemon
|
rlm@176
|
45 ([^SaveState state n new-name]
|
rlm@176
|
46 (assert (<= 0 n (dec (party-number state))))
|
rlm@176
|
47 (assert (<= (count new-name) max-name-length))
|
rlm@176
|
48 (set-memory-range
|
rlm@176
|
49 state
|
rlm@176
|
50 (+ (* n name-width) pokemon-names-start)
|
rlm@176
|
51 (concat (str->character-codes new-name) [end-of-name-marker])))
|
rlm@176
|
52 ([n new-name]
|
rlm@176
|
53 (rename-pokemon @current-state n new-name)))
|
rlm@176
|
54
|
rlm@176
|
55 (def OT-start 0xD272)
|
rlm@176
|
56
|
rlm@176
|
57 (defn original-trainers
|
rlm@176
|
58 ([^SaveState state]
|
rlm@176
|
59 (let [raw-names
|
rlm@176
|
60 (subvec (vec (memory state))
|
rlm@176
|
61 OT-start
|
rlm@176
|
62 (+ OT-start
|
rlm@176
|
63 (* name-width 6)))]
|
rlm@176
|
64 (map read-name
|
rlm@176
|
65 (take (party-number state)
|
rlm@176
|
66 (partition name-width raw-names)))))
|
rlm@176
|
67 ([] (original-trainers @current-state)))
|
rlm@176
|
68
|
rlm@192
|
69 (defn read-OT-name
|
rlm@192
|
70 ([^SaveState state poke-num]
|
rlm@192
|
71 (nth (original-trainers state) poke-num))
|
rlm@192
|
72 ([poke-num] (read-OT @current-state poke-num)))
|
rlm@192
|
73
|
rlm@192
|
74 (defn set-OT-name
|
rlm@176
|
75 "Set the OT name for a pokemon.
|
rlm@176
|
76 Note that a pokemon is still considered 'yours' if
|
rlm@176
|
77 the OT ID is the same as your own."
|
rlm@176
|
78 ([^SaveState state poke-num new-name]
|
rlm@176
|
79 (assert (<= 0 poke-num (dec (party-number state))))
|
rlm@176
|
80 (assert (<= (count new-name) max-name-length))
|
rlm@176
|
81 (set-memory-range
|
rlm@176
|
82 state
|
rlm@176
|
83 (+ (* poke-num name-width) OT-start)
|
rlm@176
|
84 (concat (str->character-codes new-name) [end-of-name-marker])))
|
rlm@176
|
85 ([n new-name]
|
rlm@176
|
86 (set-original-trainer @current-state n new-name)))
|
rlm@176
|
87
|
rlm@197
|
88 (def OT-ID-addresses [0xD176 0xD1A2 0xD1CE 0xD1FA 0xD226 0xD252])
|
rlm@176
|
89
|
rlm@192
|
90 (defn read-OT-id
|
rlm@192
|
91 ([^SaveState state poke-num]
|
rlm@192
|
92 (let [mem (memory state)
|
rlm@192
|
93 start (OT-ID-addresses poke-num)]
|
rlm@192
|
94 (glue-bytes
|
rlm@192
|
95 (aget mem start)
|
rlm@192
|
96 (aget mem (inc start)))))
|
rlm@192
|
97 ([poke-num] (read-OT-id @current-state poke-num)))
|
rlm@192
|
98
|
rlm@192
|
99 (defn set-OT-id
|
rlm@192
|
100 ([^SaveState state poke-num new-OT-num]
|
rlm@192
|
101 (assert (<= 0 poke-num 5))
|
rlm@192
|
102 (assert (<= 0 new-OT-num 0xFFFF))
|
rlm@176
|
103 (set-memory-range
|
rlm@176
|
104 state
|
rlm@192
|
105 (OT-ID-addresses poke-num)
|
rlm@192
|
106 (disect-bytes-2 new-OT-num)))
|
rlm@192
|
107 ([poke-num new-OT-num]
|
rlm@192
|
108 (set-pokemon-id @current-state poke-num new-OT-num)))
|
rlm@176
|
109
|
rlm@176
|
110 (def unknown "[[[UNKNOWN]]]")
|
rlm@176
|
111
|
rlm@176
|
112 (def unknown "")
|
rlm@176
|
113
|
rlm@189
|
114 (def pokemon-1-record
|
rlm@176
|
115 {0xD16A "Color Map" ;; 0
|
rlm@176
|
116 0xD16B "Current-HP (h)" ;; 1
|
rlm@176
|
117 0xD16C "Current-HP (l)" ;; 2
|
rlm@182
|
118 0XD16D "Unused" ;; 3
|
rlm@178
|
119 0xD16E "Status" ;; 4
|
rlm@182
|
120 0xD16F "Type 1" ;; 5
|
rlm@182
|
121 0xD170 "Type 2" ;; 6
|
rlm@182
|
122 0xD171 "scratch/C.R." ;; 7
|
rlm@176
|
123 0xD172 "Move 1 ID" ;; 8
|
rlm@176
|
124 0xD173 "Move 2 ID" ;; 9
|
rlm@176
|
125 0xD174 "Move 3 ID" ;; 10
|
rlm@176
|
126 0xD175 "Move 4 ID" ;; 11
|
rlm@176
|
127 0xD176 "OT-ID (h)" ;; 12
|
rlm@176
|
128 0xD177 "OT-ID (l)" ;; 13
|
rlm@176
|
129 0xD178 "Exp. Points (h)" ;; 14
|
rlm@176
|
130 0xD179 "Exp. Points (m)" ;; 15
|
rlm@176
|
131 0xD17A "Exp. Points (l)" ;; 16
|
rlm@176
|
132 0xD17B "HP Exp. (h)" ;; 17
|
rlm@176
|
133 0xD17C "HP Exp. (l)" ;; 18
|
rlm@176
|
134 0xD17D "Attack Exp. (h)" ;; 19
|
rlm@176
|
135 0xD17E "Attack Exp. (l)" ;; 20
|
rlm@176
|
136 0xD17F "Defense Exp. (h)" ;; 21
|
rlm@176
|
137 0xD180 "Defense Exp. (l)" ;; 22
|
rlm@176
|
138 0xD181 "Speed Exp. (h)" ;; 23
|
rlm@176
|
139 0xD182 "Speed Exp. (l)" ;; 24
|
rlm@176
|
140 0xD183 "Special Exp. (h)" ;; 25
|
rlm@176
|
141 0xD184 "Special Exp. (l)" ;; 26
|
rlm@176
|
142 0xD185 "DV Atk/Def" ;; 27
|
rlm@176
|
143 0xD186 "DV Speed/Spc" ;; 28
|
rlm@176
|
144 0xD187 "PP Move 1" ;; 29
|
rlm@176
|
145 0xD188 "PP Move 2" ;; 30
|
rlm@176
|
146 0xD189 "PP Move 3" ;; 31
|
rlm@176
|
147 0xD18A "PP Move 4" ;; 32
|
rlm@176
|
148 0xD18B "Current Level" ;; 33
|
rlm@176
|
149 0xD18C "HP Total (h)" ;; 34
|
rlm@176
|
150 0xD18D "HP Total (l)" ;; 35
|
rlm@176
|
151 0xD18E "Attack (h)" ;; 36
|
rlm@176
|
152 0xD18F "Attack (l)" ;; 37
|
rlm@176
|
153 0xD190 "Defense (h)" ;; 38
|
rlm@176
|
154 0xD191 "Defense (l)" ;; 39
|
rlm@176
|
155 0xD192 "Speed (h)" ;; 40
|
rlm@176
|
156 0xD193 "Speed (l)" ;; 41
|
rlm@176
|
157 0xD194 "Special (h)" ;; 42
|
rlm@176
|
158 0xD195 "Special (l)" ;; 43
|
rlm@176
|
159 })
|
rlm@176
|
160
|
rlm@189
|
161 (defn pokemon-record
|
rlm@176
|
162 ([^SaveState state pokemon-num]
|
rlm@176
|
163 (assert (<= 0 pokemon-num 5))
|
rlm@176
|
164 (let [base (+ (* pokemon-num pokemon-record-width) 0xD16A)]
|
rlm@176
|
165 (subvec (vec (memory state)) base
|
rlm@176
|
166 (+ base pokemon-record-width))))
|
rlm@189
|
167 ([pokemon-num] (pokemon-record @current-state pokemon-num)))
|
rlm@176
|
168
|
rlm@189
|
169 (defn set-pokemon-record
|
rlm@176
|
170 ([^SaveState state pokemon-num new-data]
|
rlm@176
|
171 (assert (<= 0 pokemon-num 5))
|
rlm@176
|
172 (let [base (+ (* pokemon-num pokemon-record-width) 0xD16A)]
|
rlm@176
|
173 (set-memory-range state base new-data)))
|
rlm@176
|
174 ([pokemon-num new-data]
|
rlm@189
|
175 (set-pokemon-record @current-state pokemon-num new-data)))
|
rlm@176
|
176
|
rlm@189
|
177 (defn print-pokemon-record
|
rlm@176
|
178 ([^SaveState state pokemon-num]
|
rlm@176
|
179 (assert (<= 0 pokemon-num 5))
|
rlm@189
|
180 (let [poke-data (pokemon-record state pokemon-num)
|
rlm@189
|
181 backbone (sort (keys pokemon-1-record))]
|
rlm@176
|
182 (println "Pokemon " pokemon-num " -- "
|
rlm@176
|
183 (nth (party-names state)
|
rlm@176
|
184 pokemon-num) \newline)
|
rlm@176
|
185
|
rlm@176
|
186 (println " Desc. | Hex | Dec | Binary |")
|
rlm@176
|
187 (println "-------------------+------+-----+----------+")
|
rlm@176
|
188 (dorun
|
rlm@176
|
189 (map
|
rlm@176
|
190 (comp println
|
rlm@176
|
191 (fn [desc data]
|
rlm@176
|
192 (format "%-16s | 0x%02X | %3d | %s |"
|
rlm@176
|
193 desc data data
|
rlm@176
|
194 (let [s (Integer/toBinaryString data)]
|
rlm@176
|
195 (apply
|
rlm@176
|
196 str
|
rlm@176
|
197 (concat (repeat (- 8 (count s)) "0" )
|
rlm@176
|
198 s))))))
|
rlm@189
|
199 (map pokemon-1-record backbone)
|
rlm@176
|
200 poke-data))))
|
rlm@176
|
201 ([pokemon-num]
|
rlm@189
|
202 (print-pokemon-record @current-state pokemon-num)))
|
rlm@190
|
203
|
rlm@190
|
204 (def mint-berry-item-code-gsc 0x54)
|
rlm@190
|
205
|
rlm@191
|
206 (defn pokemon-info
|
rlm@191
|
207 ([^SaveState state poke-num]
|
rlm@191
|
208 (assert (<= 0 poke-num 5))
|
rlm@191
|
209 (let [dv-values (read-DV state poke-num)
|
rlm@191
|
210 type (read-type state poke-num)
|
rlm@191
|
211 species (read-species state poke-num)
|
rlm@191
|
212 species2 (read-species2 state poke-num)
|
rlm@191
|
213 moves (read-moves state poke-num)
|
rlm@191
|
214 moves-pp (mapv (partial read-pp state
|
rlm@191
|
215 poke-num)
|
rlm@191
|
216 (range (count moves)))
|
rlm@191
|
217 nickname (pokemon-nickname state poke-num)
|
rlm@191
|
218 status (read-status state poke-num)
|
rlm@192
|
219 stats (read-stats state poke-num)
|
rlm@191
|
220 experience (read-experience state poke-num)
|
rlm@192
|
221 OT-name (read-OT-name state poke-num)
|
rlm@193
|
222 ID (read-OT-id state poke-num)]
|
rlm@193
|
223 {;; persistent
|
rlm@193
|
224 :name nickname
|
rlm@191
|
225 :species species
|
rlm@191
|
226 :species2 species2
|
rlm@191
|
227 :type type
|
rlm@191
|
228 :dv dv-values
|
rlm@192
|
229 :original-trainer OT-name
|
rlm@192
|
230 :ID ID
|
rlm@196
|
231 :moves (mapv vector moves moves-pp)
|
rlm@190
|
232
|
rlm@193
|
233 ;; ephemerial
|
rlm@200
|
234 :status status
|
rlm@192
|
235 :stats stats
|
rlm@191
|
236 :experience experience
|
rlm@193
|
237 }))
|
rlm@191
|
238 ([poke-num]
|
rlm@191
|
239 (pokemon-info @current-state poke-num)))
|
rlm@195
|
240
|
rlm@195
|
241 (defn print-pokemon
|
rlm@195
|
242 ([^SaveState state poke-num]
|
rlm@195
|
243 (let [info (pokemon-info state poke-num)]
|
rlm@195
|
244 (printf
|
rlm@195
|
245 (str
|
rlm@195
|
246 "##################################"
|
rlm@195
|
247 "##################################\n"
|
rlm@195
|
248 "# "
|
rlm@195
|
249 " #\n"
|
rlm@195
|
250 "# %-44s"
|
rlm@195
|
251 "%-20s#\n"
|
rlm@195
|
252 "# "
|
rlm@195
|
253 " #\n"
|
rlm@195
|
254 "##################################"
|
rlm@195
|
255 "##################################\n\n")
|
rlm@195
|
256
|
rlm@195
|
257 (str
|
rlm@195
|
258 (:name info)
|
rlm@195
|
259 (str
|
rlm@195
|
260 " (" (.substring (str (:species info)) 1) ")")
|
rlm@195
|
261 (str " Lvl." (format "%-3d" (:level (:stats info)))))
|
rlm@195
|
262 (str (:original-trainer info) " / " (:ID info)))
|
rlm@195
|
263
|
rlm@195
|
264 (println
|
rlm@195
|
265 (str
|
rlm@195
|
266 (str "-----------------------------------"
|
rlm@195
|
267 "---------------------------------\n" )
|
rlm@195
|
268 (str "| Stats | HP | Attack "
|
rlm@195
|
269 "| Defense | Speed | Special |\n")
|
rlm@195
|
270 (str "+-----------+----------+----------"
|
rlm@195
|
271 "+----------+----------+----------+")))
|
rlm@195
|
272
|
rlm@195
|
273 (printf
|
rlm@195
|
274 (str "|%-11s| %5d | %5d "
|
rlm@195
|
275 "| %5d | %5d | %5d |\n")
|
rlm@195
|
276 "DV Values" (:hp (:dv info)) (:attack (:dv info))
|
rlm@195
|
277 (:defense (:dv info)) (:speed (:dv info))
|
rlm@195
|
278 (:special (:dv info)))
|
rlm@195
|
279
|
rlm@195
|
280 (let [c (:stats info)]
|
rlm@195
|
281 (printf
|
rlm@195
|
282 (str "|%-11s| %5d | %5d "
|
rlm@195
|
283 "| %5d | %5d | %5d |\n")
|
rlm@195
|
284 "Current" (:hp c) (:attack c)
|
rlm@195
|
285 (:defense c) (:speed c)
|
rlm@195
|
286 (:special c)))
|
rlm@195
|
287
|
rlm@195
|
288 (let [e (:experience info)]
|
rlm@195
|
289 (printf
|
rlm@195
|
290 (str "|%-11s| %5d | %5d "
|
rlm@195
|
291 "| %5d | %5d | %5d |\n")
|
rlm@195
|
292 "Experience" (:hp-exp e) (:attack-exp e)
|
rlm@195
|
293 (:defense-exp e) (:speed-exp e)
|
rlm@195
|
294 (:special-exp e)))
|
rlm@195
|
295 (println
|
rlm@195
|
296 (str "+-----------+----------+----------"
|
rlm@195
|
297 "+----------+----------+----------+"))
|
rlm@195
|
298
|
rlm@195
|
299 (print "\n")
|
rlm@195
|
300 (println "+------------------+----+--------+--------+")
|
rlm@195
|
301 (println "| Move | PP | Max PP | PP UPs |")
|
rlm@196
|
302 (println "+------------------+----+--------+--------+")
|
rlm@196
|
303
|
rlm@197
|
304 (dorun
|
rlm@197
|
305 (for [[name {:keys [pp-ups current-pp]}] (:moves info)]
|
rlm@197
|
306 (printf
|
rlm@197
|
307 "| %-17s| %2d | %02d | %02d |\n"
|
rlm@197
|
308 (.substring (str name) 1)
|
rlm@197
|
309 current-pp (max-pp name pp-ups) pp-ups)))
|
rlm@195
|
310
|
rlm@200
|
311 (println "+------------------+----+--------+--------+\n")
|
rlm@195
|
312
|
rlm@200
|
313 (println "Total Experience:" (:main-exp (:experience info)))
|
rlm@200
|
314 (if (not= (:species info) (:species2 info))
|
rlm@200
|
315 (println "\nThis pokemon has a secondary species"
|
rlm@200
|
316 (str
|
rlm@200
|
317 "("
|
rlm@200
|
318 (.substring (str (:species2 info)) 1) ")\n")
|
rlm@201
|
319 "that does not match its primary species."))
|
rlm@200
|
320 (if (not= :normal (:status info))
|
rlm@200
|
321 (println "\nThis pokemon is currently"
|
rlm@200
|
322 (.substring (str (:status info) ".") 1)))))
|
rlm@195
|
323 ([poke-num]
|
rlm@195
|
324 (print-pokemon @current-state poke-num)))
|
rlm@192
|
325
|
rlm@192
|
326 (defn give-status-all
|
rlm@192
|
327 ([^SaveState state status]
|
rlm@192
|
328 (reduce (fn [state num]
|
rlm@192
|
329 (give-status state num status))
|
rlm@192
|
330 state
|
rlm@192
|
331 (range (party-number state))))
|
rlm@192
|
332 ([status]
|
rlm@192
|
333 (give-status-all @current-state status)))
|