… | |
… | |
16 | |
16 | |
17 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
18 | along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
20 | |
21 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <cassert> |
24 | #include <cassert> |
25 | |
25 | |
26 | #include <tr1/unordered_map> |
26 | #include <tr1/unordered_map> |
… | |
… | |
206 | * Last, make a check on the full name. |
206 | * Last, make a check on the full name. |
207 | */ |
207 | */ |
208 | int |
208 | int |
209 | item_matched_string (object *pl, object *op, const char *name) |
209 | item_matched_string (object *pl, object *op, const char *name) |
210 | { |
210 | { |
211 | char * |
|
|
212 | cp, |
|
|
213 | local_name[MAX_BUF]; |
211 | char *cp, local_name[MAX_BUF]; |
214 | int |
212 | int count, retval = 0; |
215 | count, |
|
|
216 | retval = 0; |
|
|
217 | |
213 | |
218 | strcpy (local_name, name); /* strtok is destructive to name */ |
214 | strcpy (local_name, name); /* strtok is destructive to name */ |
219 | |
215 | |
220 | for (cp = strtok (local_name, ","); cp; cp = strtok (NULL, ",")) |
216 | for (cp = strtok (local_name, ","); cp; cp = strtok (NULL, ",")) |
221 | { |
217 | { |
… | |
… | |
273 | retval = 15; |
269 | retval = 15; |
274 | else if (!strncasecmp (cp, query_base_name (op, 0), strlen (cp))) |
270 | else if (!strncasecmp (cp, query_base_name (op, 0), strlen (cp))) |
275 | retval = 14; |
271 | retval = 14; |
276 | else if (!strncasecmp (cp, query_base_name (op, 1), strlen (cp))) |
272 | else if (!strncasecmp (cp, query_base_name (op, 1), strlen (cp))) |
277 | retval = 14; |
273 | retval = 14; |
278 | |
|
|
279 | /* Do substring checks, so things like 'Str+1' will match. |
274 | /* Do substring checks, so things like 'Str+1' will match. |
280 | * retval of these should perhaps be lower - they are lower |
275 | * retval of these should perhaps be lower - they are lower |
281 | * then the specific strcasecmp aboves, but still higher than |
276 | * then the specific strcasecmp aboves, but still higher than |
282 | * some other match criteria. |
277 | * some other match criteria. |
283 | */ |
278 | */ |
… | |
… | |
285 | retval = 12; |
280 | retval = 12; |
286 | else if (strstr (query_base_name (op, 0), cp)) |
281 | else if (strstr (query_base_name (op, 0), cp)) |
287 | retval = 12; |
282 | retval = 12; |
288 | else if (strstr (query_short_name (op), cp)) |
283 | else if (strstr (query_short_name (op), cp)) |
289 | retval = 12; |
284 | retval = 12; |
290 | |
|
|
291 | /* Check against plural/non plural based on count. */ |
285 | /* Check against plural/non plural based on count. */ |
292 | else if (count > 1 && !strcasecmp (cp, op->name_pl)) |
286 | else if (count > 1 && !strcasecmp (cp, op->name_pl)) |
293 | { |
|
|
294 | retval = 6; |
287 | retval = 6; |
295 | } |
|
|
296 | else if (count == 1 && !strcasecmp (op->name, cp)) |
288 | else if (count == 1 && !strcasecmp (op->name, cp)) |
297 | { |
|
|
298 | retval = 6; |
289 | retval = 6; |
299 | } |
|
|
300 | /* base name matched - not bad */ |
290 | /* base name matched - not bad */ |
301 | else if (strcasecmp (cp, op->name) == 0 && !count) |
291 | else if (strcasecmp (cp, op->name) == 0 && !count) |
302 | retval = 4; |
292 | retval = 4; |
303 | /* Check for partial custom name, but give a real low priority */ |
293 | /* Check for partial custom name, but give a real low priority */ |
304 | else if (op->custom_name && strstr (op->custom_name, cp)) |
294 | else if (op->custom_name && strstr (op->custom_name, cp)) |
… | |
… | |
306 | |
296 | |
307 | if (retval) |
297 | if (retval) |
308 | { |
298 | { |
309 | if (pl->type == PLAYER) |
299 | if (pl->type == PLAYER) |
310 | pl->contr->count = count; |
300 | pl->contr->count = count; |
|
|
301 | |
311 | return retval; |
302 | return retval; |
312 | } |
303 | } |
313 | } |
304 | } |
|
|
305 | |
314 | return 0; |
306 | return 0; |
315 | } |
307 | } |
316 | |
308 | |
317 | /* |
309 | /* |
318 | * Initialises the internal linked list of archetypes (read from file). |
310 | * Initialises the internal linked list of archetypes (read from file). |
… | |
… | |
361 | */ |
353 | */ |
362 | |
354 | |
363 | void |
355 | void |
364 | init_archetable (void) |
356 | init_archetable (void) |
365 | { |
357 | { |
366 | archetype * |
358 | archetype *at; |
367 | at; |
|
|
368 | |
359 | |
369 | LOG (llevDebug, " Setting up archetable...\n"); |
360 | LOG (llevDebug, " Setting up archetable...\n"); |
370 | |
361 | |
371 | for (at = first_archetype; at != NULL; at = (at->more == NULL) ? at->next : at->more) |
362 | for (at = first_archetype; at != NULL; at = (at->more == NULL) ? at->next : at->more) |
372 | add_arch (at); |
363 | add_arch (at); |
… | |
… | |
391 | */ |
382 | */ |
392 | |
383 | |
393 | void |
384 | void |
394 | dump_all_archetypes (void) |
385 | dump_all_archetypes (void) |
395 | { |
386 | { |
396 | archetype * |
387 | archetype *at; |
397 | at; |
|
|
398 | |
388 | |
399 | for (at = first_archetype; at != NULL; at = (at->more == NULL) ? at->next : at->more) |
389 | for (at = first_archetype; at != NULL; at = (at->more == NULL) ? at->next : at->more) |
400 | { |
390 | { |
401 | dump_arch (at); |
391 | dump_arch (at); |
402 | fprintf (logfile, "%s\n", errmsg); |
392 | fprintf (logfile, "%s\n", errmsg); |
… | |
… | |
404 | } |
394 | } |
405 | |
395 | |
406 | void |
396 | void |
407 | free_all_archs (void) |
397 | free_all_archs (void) |
408 | { |
398 | { |
409 | archetype * |
399 | archetype *at, *next; |
410 | at, * |
|
|
411 | next; |
|
|
412 | int |
|
|
413 | i = 0, f = 0; |
400 | int i = 0, f = 0; |
414 | |
401 | |
415 | for (at = first_archetype; at != NULL; at = next) |
402 | for (at = first_archetype; at != NULL; at = next) |
416 | { |
403 | { |
417 | if (at->more) |
404 | if (at->more) |
418 | next = at->more; |
405 | next = at->more; |
… | |
… | |
443 | * of archetype-structures. |
430 | * of archetype-structures. |
444 | */ |
431 | */ |
445 | void |
432 | void |
446 | first_arch_pass (object_thawer & fp) |
433 | first_arch_pass (object_thawer & fp) |
447 | { |
434 | { |
448 | archetype * |
|
|
449 | at, * |
|
|
450 | head = NULL, *last_more = NULL; |
435 | archetype *at, *head = NULL, *last_more = NULL; |
451 | |
436 | |
452 | at->clone.arch = first_archetype = at = new archetype; |
437 | at->clone.arch = first_archetype = at = new archetype; |
453 | |
438 | |
454 | while (int i = load_object (fp, &at->clone, 0)) |
439 | while (int i = load_object (fp, &at->clone, 0)) |
455 | { |
440 | { |
… | |
… | |
524 | */ |
509 | */ |
525 | |
510 | |
526 | void |
511 | void |
527 | second_arch_pass (object_thawer & thawer) |
512 | second_arch_pass (object_thawer & thawer) |
528 | { |
513 | { |
529 | char |
|
|
530 | buf[MAX_BUF], * |
|
|
531 | variable = buf, *argument, *cp; |
514 | char buf[MAX_BUF], *variable = buf, *argument, *cp; |
532 | archetype * |
|
|
533 | at = NULL, *other; |
515 | archetype *at = NULL, *other; |
534 | |
516 | |
535 | while (fgets (buf, MAX_BUF, thawer) != NULL) |
517 | while (fgets (buf, MAX_BUF, thawer) != NULL) |
536 | { |
518 | { |
537 | if (*buf == '#') |
519 | if (*buf == '#') |
538 | continue; |
520 | continue; |
… | |
… | |
563 | } |
545 | } |
564 | else if (!strcmp ("randomitems", variable)) |
546 | else if (!strcmp ("randomitems", variable)) |
565 | { |
547 | { |
566 | if (at != NULL) |
548 | if (at != NULL) |
567 | { |
549 | { |
568 | treasurelist * |
|
|
569 | tl = find_treasurelist (argument); |
550 | treasurelist *tl = find_treasurelist (argument); |
570 | |
551 | |
571 | if (tl == NULL) |
552 | if (tl == NULL) |
572 | LOG (llevError, "Failed to link treasure to arch (%s): %s\n", &at->name, argument); |
553 | LOG (llevError, "Failed to link treasure to arch (%s): %s\n", &at->name, argument); |
573 | else |
554 | else |
574 | at->clone.randomitems = tl; |
555 | at->clone.randomitems = tl; |
… | |
… | |
579 | |
560 | |
580 | #ifdef DEBUG |
561 | #ifdef DEBUG |
581 | void |
562 | void |
582 | check_generators (void) |
563 | check_generators (void) |
583 | { |
564 | { |
584 | archetype * |
565 | archetype *at; |
585 | at; |
|
|
586 | |
566 | |
587 | for (at = first_archetype; at != NULL; at = at->next) |
567 | for (at = first_archetype; at != NULL; at = at->next) |
588 | if (QUERY_FLAG (&at->clone, FLAG_GENERATOR) && at->clone.other_arch == NULL) |
568 | if (QUERY_FLAG (&at->clone, FLAG_GENERATOR) && at->clone.other_arch == NULL) |
589 | LOG (llevError, "Warning: %s is generator but lacks other_arch.\n", &at->name); |
569 | LOG (llevError, "Warning: %s is generator but lacks other_arch.\n", &at->name); |
590 | } |
570 | } |
… | |
… | |
598 | */ |
578 | */ |
599 | |
579 | |
600 | void |
580 | void |
601 | load_archetypes (void) |
581 | load_archetypes (void) |
602 | { |
582 | { |
603 | char |
|
|
604 | filename[MAX_BUF]; |
583 | char filename[MAX_BUF]; |
605 | |
584 | |
606 | #if TIME_ARCH_LOAD |
585 | #if TIME_ARCH_LOAD |
607 | struct timeval |
586 | struct timeval |
608 | tv1, |
587 | tv1, |
609 | tv2; |
588 | tv2; |
… | |
… | |
647 | */ |
626 | */ |
648 | |
627 | |
649 | object * |
628 | object * |
650 | arch_to_object (archetype *at) |
629 | arch_to_object (archetype *at) |
651 | { |
630 | { |
652 | object * |
631 | object *op; |
653 | op; |
|
|
654 | |
632 | |
655 | if (at == NULL) |
633 | if (at == NULL) |
656 | { |
634 | { |
657 | if (warn_archetypes) |
635 | if (warn_archetypes) |
658 | LOG (llevError, "Couldn't find archetype.\n"); |
636 | LOG (llevError, "Couldn't find archetype.\n"); |
… | |
… | |
675 | */ |
653 | */ |
676 | |
654 | |
677 | object * |
655 | object * |
678 | create_singularity (const char *name) |
656 | create_singularity (const char *name) |
679 | { |
657 | { |
680 | object * op; |
658 | object *op; |
681 | char buf[MAX_BUF]; |
659 | char buf[MAX_BUF]; |
682 | |
660 | |
683 | sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name); |
661 | sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name); |
684 | op = get_object (); |
662 | op = get_object (); |
685 | op->name = op->name_pl = buf; |
663 | op->name = op->name_pl = buf; |