… | |
… | |
51 | // the vector of other_arch references to be resolved |
51 | // the vector of other_arch references to be resolved |
52 | static std::vector< std::pair<arch_ptr *, shstr> > postponed_arch_ref; |
52 | static std::vector< std::pair<arch_ptr *, shstr> > postponed_arch_ref; |
53 | // the vector of loaded but not yet committed archetypes |
53 | // the vector of loaded but not yet committed archetypes |
54 | static std::vector<archetype *> postponed_arch; |
54 | static std::vector<archetype *> postponed_arch; |
55 | |
55 | |
|
|
56 | //+GPL |
|
|
57 | |
|
|
58 | /* |
|
|
59 | * Creates an object. This function is called by get_archetype() |
|
|
60 | * if it fails to find the appropriate archetype. |
|
|
61 | * Thus get_archetype() will be guaranteed to always return |
|
|
62 | * an object, and never NULL. |
|
|
63 | */ |
|
|
64 | object * |
|
|
65 | create_singularity (const char *name) |
|
|
66 | { |
|
|
67 | LOG (llevError | logBacktrace, "FATAL: creating singularity for '%s'.\n", name); |
|
|
68 | |
|
|
69 | if (!strcmp (name, "bug")) |
|
|
70 | abort (); |
|
|
71 | |
|
|
72 | object *op = archetype::get (shstr_bug); |
|
|
73 | op->name = op->name_pl = format ("bug, please report (missing archetype %s)", name); |
|
|
74 | |
|
|
75 | return op; |
|
|
76 | } |
|
|
77 | |
56 | /** |
78 | /** |
57 | * GROS - This function retrieves an archetype given the name that appears |
79 | * GROS - This function retrieves an archetype given the name that appears |
58 | * during the game (for example, "writing pen" instead of "stylus"). |
80 | * during the game (for example, "writing pen" instead of "stylus"). |
59 | * It does not use the hashtable system, but browse the whole archlist each time. |
81 | * It does not use the hashtable system, but browse the whole archlist each time. |
60 | * I suggest not to use it unless you really need it because of performance issue. |
82 | * I suggest not to use it unless you really need it because of performance issue. |
… | |
… | |
141 | */ |
163 | */ |
142 | object * |
164 | object * |
143 | get_archetype_by_object_name (const char *name) |
165 | get_archetype_by_object_name (const char *name) |
144 | { |
166 | { |
145 | char tmpname[MAX_BUF]; |
167 | char tmpname[MAX_BUF]; |
146 | int i; |
|
|
147 | |
168 | |
148 | assign (tmpname, name); |
169 | assign (tmpname, name); |
149 | |
170 | |
150 | for (i = strlen (tmpname); i > 0; i--) |
171 | for (int i = strlen (tmpname); i > 0; i--) |
151 | { |
172 | { |
152 | tmpname[i] = 0; |
173 | tmpname[i] = 0; |
153 | |
174 | |
154 | if (archetype *at = find_archetype_by_object_name (tmpname)) |
175 | if (archetype *at = find_archetype_by_object_name (tmpname)) |
155 | return at->instance (); |
176 | return at->instance (); |
… | |
… | |
194 | return 1; |
215 | return 1; |
195 | |
216 | |
196 | /* unpaid is a little more specific */ |
217 | /* unpaid is a little more specific */ |
197 | if (!strcmp (cp, "unpaid") && QUERY_FLAG (op, FLAG_UNPAID)) |
218 | if (!strcmp (cp, "unpaid") && QUERY_FLAG (op, FLAG_UNPAID)) |
198 | return 2; |
219 | return 2; |
|
|
220 | |
199 | if (!strcmp (cp, "cursed") && QUERY_FLAG (op, FLAG_KNOWN_CURSED) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) |
221 | if (!strcmp (cp, "cursed") && QUERY_FLAG (op, FLAG_KNOWN_CURSED) && (QUERY_FLAG (op, FLAG_CURSED) || QUERY_FLAG (op, FLAG_DAMNED))) |
200 | return 2; |
222 | return 2; |
201 | |
223 | |
202 | if (!strcmp (cp, "unlocked") && !QUERY_FLAG (op, FLAG_INV_LOCKED)) |
224 | if (!strcmp (cp, "unlocked") && !QUERY_FLAG (op, FLAG_INV_LOCKED)) |
203 | return 2; |
225 | return 2; |
… | |
… | |
225 | * is because of the 'else' handling - we don't want to match on |
247 | * 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 |
248 | * 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 |
249 | * later. So keep it in descending order here, so we try for the best |
228 | * match first, and work downward. |
250 | * match first, and work downward. |
229 | */ |
251 | */ |
|
|
252 | const char *qbn0, *qbn1, *qsn; // query base name/short name caches |
|
|
253 | |
230 | if (!strcasecmp (cp, query_name (op))) |
254 | if (!strcasecmp (cp, query_name (op))) |
231 | retval = 20; |
255 | retval = 20; |
232 | else if (!strcasecmp (cp, query_short_name (op))) |
256 | else if (!strcasecmp (cp, qsn = query_short_name (op))) |
233 | retval = 18; |
257 | retval = 18; |
234 | else if (!strcasecmp (cp, query_base_name (op, 0))) |
258 | else if (!strcasecmp (cp, qbn0 = query_base_name (op, 0))) |
235 | retval = 16; |
259 | retval = 16; |
236 | else if (!strcasecmp (cp, query_base_name (op, 1))) |
260 | else if (!strcasecmp (cp, qbn1 = query_base_name (op, 1))) |
237 | retval = 16; |
261 | retval = 16; |
238 | else if (op->custom_name && !strcasecmp (cp, op->custom_name)) |
262 | else if (op->custom_name && !strcasecmp (cp, op->custom_name)) |
239 | retval = 15; |
263 | retval = 15; |
240 | else if (!strncasecmp (cp, query_base_name (op, 0), strlen (cp))) |
264 | else if (!strncasecmp (cp, qbn0, strlen (cp))) |
241 | retval = 14; |
265 | retval = 14; |
242 | else if (!strncasecmp (cp, query_base_name (op, 1), strlen (cp))) |
266 | else if (!strncasecmp (cp, qbn1, strlen (cp))) |
243 | retval = 14; |
267 | retval = 14; |
244 | /* Do substring checks, so things like 'Str+1' will match. |
268 | /* Do substring checks, so things like 'Str+1' will match. |
245 | * retval of these should perhaps be lower - they are lower |
269 | * retval of these should perhaps be lower - they are lower |
246 | * then the specific strcasecmp aboves, but still higher than |
270 | * then the specific strcasecmp aboves, but still higher than |
247 | * some other match criteria. |
271 | * some other match criteria. |
248 | */ |
272 | */ |
249 | else if (strstr (query_base_name (op, 1), cp)) |
273 | else if (strstr (qbn1, cp)) |
250 | retval = 12; |
274 | retval = 12; |
251 | else if (strstr (query_base_name (op, 0), cp)) |
275 | else if (strstr (qbn0, cp)) |
252 | retval = 12; |
276 | retval = 12; |
253 | else if (strstr (query_short_name (op), cp)) |
277 | else if (strstr (qsn, cp)) |
254 | retval = 12; |
278 | retval = 12; |
255 | /* Check against plural/non plural based on count. */ |
279 | /* Check against plural/non plural based on count. */ |
256 | else if (count > 1 && !strcasecmp (cp, op->name_pl)) |
280 | else if (count > 1 && !strcasecmp (cp, op->name_pl)) |
257 | retval = 6; |
281 | retval = 6; |
258 | else if (count == 1 && !strcasecmp (op->name, cp)) |
282 | else if (count == 1 && !strcasecmp (op->name, cp)) |
… | |
… | |
274 | } |
298 | } |
275 | |
299 | |
276 | return 0; |
300 | return 0; |
277 | } |
301 | } |
278 | |
302 | |
|
|
303 | //-GPL |
|
|
304 | |
279 | archetype::archetype (const char *name) |
305 | archetype::archetype (const char *name) |
280 | { |
306 | { |
281 | arch = this; |
307 | arch = this; |
282 | this->archname = this->name = this->name_pl = name; |
308 | this->archname = this->name = this->name_pl = name; |
283 | } |
309 | } |
… | |
… | |
539 | object *op = clone (); |
565 | object *op = clone (); |
540 | op->instantiate (); |
566 | op->instantiate (); |
541 | return op; |
567 | return op; |
542 | } |
568 | } |
543 | |
569 | |
544 | /* |
570 | //+GPL |
545 | * Creates an object. This function is called by get_archetype() |
|
|
546 | * if it fails to find the appropriate archetype. |
|
|
547 | * Thus get_archetype() will be guaranteed to always return |
|
|
548 | * an object, and never NULL. |
|
|
549 | */ |
|
|
550 | object * |
|
|
551 | create_singularity (const char *name) |
|
|
552 | { |
|
|
553 | LOG (llevError | logBacktrace, "FATAL: creating singularity for '%s'.\n", name); |
|
|
554 | |
|
|
555 | if (!strcmp (name, "bug")) |
|
|
556 | abort (); |
|
|
557 | |
|
|
558 | object *op = archetype::get (shstr_bug); |
|
|
559 | op->name = op->name_pl = format ("bug, please report (missing archetype %s)", name); |
|
|
560 | |
|
|
561 | return op; |
|
|
562 | } |
|
|
563 | |
571 | |
564 | /* |
572 | /* |
565 | * Finds which archetype matches the given name, and returns a new |
573 | * Finds which archetype matches the given name, and returns a new |
566 | * object containing a copy of the archetype. |
574 | * object containing a copy of the archetype. |
567 | */ |
575 | */ |
… | |
… | |
641 | } |
649 | } |
642 | |
650 | |
643 | return head; |
651 | return head; |
644 | } |
652 | } |
645 | |
653 | |
|
|
654 | //-GPL |
|
|
655 | |