… | |
… | |
264 | * returns the matching spell object, or NULL. |
264 | * returns the matching spell object, or NULL. |
265 | * If we match multiple spells but don't get an |
265 | * If we match multiple spells but don't get an |
266 | * exact match, we also return NULL. |
266 | * exact match, we also return NULL. |
267 | */ |
267 | */ |
268 | object * |
268 | object * |
269 | object::find_spell (shstr_cmp name) const |
269 | object::find_spell (const_utf8_string prefix) const |
270 | { |
270 | { |
|
|
271 | if (shstr_cmp name = prefix) |
|
|
272 | { |
|
|
273 | // case 1, match spell name exactly |
271 | for (object *spob = inv; spob; spob = spob->below) |
274 | for (object *spob = inv; spob; spob = spob->below) |
272 | if (spob->name == name && spob->type == SPELL) |
275 | if (spob->name == name && spob->type == SPELL) |
273 | return spob; |
276 | return spob; |
|
|
277 | } |
|
|
278 | else |
|
|
279 | { |
|
|
280 | // case 2, match prefix |
|
|
281 | int len = strlen (prefix); |
|
|
282 | |
|
|
283 | for (object *spob = inv; spob; spob = spob->below) |
|
|
284 | if (spob->type == SPELL |
|
|
285 | && spob->name.length () < len |
|
|
286 | && prefix [spob->name.length ()] <= ' ' |
|
|
287 | && !memcmp (prefix, spob->name, spob->name.length ())) |
|
|
288 | return spob; |
|
|
289 | } |
274 | |
290 | |
275 | return 0; |
291 | return 0; |
276 | } |
292 | } |
277 | |
293 | |
278 | /* reflwall - decides weither the (spell-)object sp_op will |
294 | /* reflwall - decides weither the (spell-)object sp_op will |