… | |
… | |
141 | */ |
141 | */ |
142 | object * |
142 | object * |
143 | get_archetype_by_object_name (const char *name) |
143 | get_archetype_by_object_name (const char *name) |
144 | { |
144 | { |
145 | char tmpname[MAX_BUF]; |
145 | char tmpname[MAX_BUF]; |
146 | int i; |
|
|
147 | |
146 | |
148 | assign (tmpname, name); |
147 | assign (tmpname, name); |
149 | |
148 | |
150 | for (i = strlen (tmpname); i > 0; i--) |
149 | for (int i = strlen (tmpname); i > 0; i--) |
151 | { |
150 | { |
152 | tmpname[i] = 0; |
151 | tmpname[i] = 0; |
153 | |
152 | |
154 | if (archetype *at = find_archetype_by_object_name (tmpname)) |
153 | if (archetype *at = find_archetype_by_object_name (tmpname)) |
155 | return at->instance (); |
154 | return at->instance (); |
… | |
… | |
194 | return 1; |
193 | return 1; |
195 | |
194 | |
196 | /* unpaid is a little more specific */ |
195 | /* unpaid is a little more specific */ |
197 | if (!strcmp (cp, "unpaid") && QUERY_FLAG (op, FLAG_UNPAID)) |
196 | if (!strcmp (cp, "unpaid") && QUERY_FLAG (op, FLAG_UNPAID)) |
198 | return 2; |
197 | return 2; |
|
|
198 | |
199 | if (!strcmp (cp, "cursed") && QUERY_FLAG (op, FLAG_KNOWN_CURSED) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) |
199 | if (!strcmp (cp, "cursed") && QUERY_FLAG (op, FLAG_KNOWN_CURSED) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) |
200 | return 2; |
200 | return 2; |
201 | |
201 | |
202 | if (!strcmp (cp, "unlocked") && !QUERY_FLAG (op, FLAG_INV_LOCKED)) |
202 | if (!strcmp (cp, "unlocked") && !QUERY_FLAG (op, FLAG_INV_LOCKED)) |
203 | return 2; |
203 | return 2; |
… | |
… | |
225 | * is because of the 'else' handling - we don't want to match on |
225 | * is because of the 'else' handling - we don't want to match on |
226 | * something and set a low retval, even though it may match a higher retcal |
226 | * something and set a low retval, even though it may match a higher retcal |
227 | * later. So keep it in descending order here, so we try for the best |
227 | * later. So keep it in descending order here, so we try for the best |
228 | * match first, and work downward. |
228 | * match first, and work downward. |
229 | */ |
229 | */ |
|
|
230 | const char *qbn0, *qbn1, *qsn; // query base name/short name caches |
|
|
231 | |
230 | if (!strcasecmp (cp, query_name (op))) |
232 | if (!strcasecmp (cp, query_name (op))) |
231 | retval = 20; |
233 | retval = 20; |
232 | else if (!strcasecmp (cp, query_short_name (op))) |
234 | else if (!strcasecmp (cp, qsn = query_short_name (op))) |
233 | retval = 18; |
235 | retval = 18; |
234 | else if (!strcasecmp (cp, query_base_name (op, 0))) |
236 | else if (!strcasecmp (cp, qbn0 = query_base_name (op, 0))) |
235 | retval = 16; |
237 | retval = 16; |
236 | else if (!strcasecmp (cp, query_base_name (op, 1))) |
238 | else if (!strcasecmp (cp, qbn1 = query_base_name (op, 1))) |
237 | retval = 16; |
239 | retval = 16; |
238 | else if (op->custom_name && !strcasecmp (cp, op->custom_name)) |
240 | else if (op->custom_name && !strcasecmp (cp, op->custom_name)) |
239 | retval = 15; |
241 | retval = 15; |
240 | else if (!strncasecmp (cp, query_base_name (op, 0), strlen (cp))) |
242 | else if (!strncasecmp (cp, qbn0, strlen (cp))) |
241 | retval = 14; |
243 | retval = 14; |
242 | else if (!strncasecmp (cp, query_base_name (op, 1), strlen (cp))) |
244 | else if (!strncasecmp (cp, qbn1, strlen (cp))) |
243 | retval = 14; |
245 | retval = 14; |
244 | /* Do substring checks, so things like 'Str+1' will match. |
246 | /* Do substring checks, so things like 'Str+1' will match. |
245 | * retval of these should perhaps be lower - they are lower |
247 | * retval of these should perhaps be lower - they are lower |
246 | * then the specific strcasecmp aboves, but still higher than |
248 | * then the specific strcasecmp aboves, but still higher than |
247 | * some other match criteria. |
249 | * some other match criteria. |
248 | */ |
250 | */ |
249 | else if (strstr (query_base_name (op, 1), cp)) |
251 | else if (strstr (qbn1, cp)) |
250 | retval = 12; |
252 | retval = 12; |
251 | else if (strstr (query_base_name (op, 0), cp)) |
253 | else if (strstr (qbn0, cp)) |
252 | retval = 12; |
254 | retval = 12; |
253 | else if (strstr (query_short_name (op), cp)) |
255 | else if (strstr (qsn, cp)) |
254 | retval = 12; |
256 | retval = 12; |
255 | /* Check against plural/non plural based on count. */ |
257 | /* Check against plural/non plural based on count. */ |
256 | else if (count > 1 && !strcasecmp (cp, op->name_pl)) |
258 | else if (count > 1 && !strcasecmp (cp, op->name_pl)) |
257 | retval = 6; |
259 | retval = 6; |
258 | else if (count == 1 && !strcasecmp (op->name, cp)) |
260 | else if (count == 1 && !strcasecmp (op->name, cp)) |