ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/arch.C
(Generate patch)

Comparing deliantra/server/common/arch.C (file contents):
Revision 1.20 by root, Thu Sep 14 21:16:11 2006 UTC vs.
Revision 1.25 by root, Tue Nov 7 16:30:54 2006 UTC

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 */
208int 208int
209item_matched_string (object *pl, object *op, const char *name) 209item_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
363void 355void
364init_archetable (void) 356init_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);
373 364
374 LOG (llevDebug, "done\n"); 365 LOG (llevDebug, "done\n");
375} 366}
376 367
377/*
378 * Dumps an archetype to debug-level output.
379 */
380
381void
382dump_arch (archetype *at)
383{
384 dump_object (&at->clone);
385}
386
387/*
388 * Dumps _all_ archetypes to debug-level output.
389 * If you run crossfire with debug, and enter DM-mode, you can trigger
390 * this with the O key.
391 */
392
393void
394dump_all_archetypes (void)
395{
396 archetype *
397 at;
398
399 for (at = first_archetype; at != NULL; at = (at->more == NULL) ? at->next : at->more)
400 {
401 dump_arch (at);
402 fprintf (logfile, "%s\n", errmsg);
403 }
404}
405
406void 368void
407free_all_archs (void) 369free_all_archs (void)
408{ 370{
409 archetype * 371 archetype *at, *next;
410 at, *
411 next;
412 int
413 i = 0, f = 0; 372 int i = 0, f = 0;
414 373
415 for (at = first_archetype; at != NULL; at = next) 374 for (at = first_archetype; at != NULL; at = next)
416 { 375 {
417 if (at->more) 376 if (at->more)
418 next = at->more; 377 next = at->more;
443 * of archetype-structures. 402 * of archetype-structures.
444 */ 403 */
445void 404void
446first_arch_pass (object_thawer & fp) 405first_arch_pass (object_thawer & fp)
447{ 406{
448 archetype *
449 at, *
450 head = NULL, *last_more = NULL; 407 archetype *at, *head = NULL, *last_more = NULL;
451 408
452 at->clone.arch = first_archetype = at = new archetype; 409 at->clone.arch = first_archetype = at = new archetype;
453 410
454 while (int i = load_object (fp, &at->clone, 0)) 411 while (int i = load_object (fp, &at->clone, 0))
455 { 412 {
524 */ 481 */
525 482
526void 483void
527second_arch_pass (object_thawer & thawer) 484second_arch_pass (object_thawer & thawer)
528{ 485{
529 char
530 buf[MAX_BUF], *
531 variable = buf, *argument, *cp; 486 char buf[MAX_BUF], *variable = buf, *argument, *cp;
532 archetype *
533 at = NULL, *other; 487 archetype *at = NULL, *other;
534 488
535 while (fgets (buf, MAX_BUF, thawer) != NULL) 489 while (fgets (buf, MAX_BUF, thawer) != NULL)
536 { 490 {
537 if (*buf == '#') 491 if (*buf == '#')
538 continue; 492 continue;
563 } 517 }
564 else if (!strcmp ("randomitems", variable)) 518 else if (!strcmp ("randomitems", variable))
565 { 519 {
566 if (at != NULL) 520 if (at != NULL)
567 { 521 {
568 treasurelist *
569 tl = find_treasurelist (argument); 522 treasurelist *tl = find_treasurelist (argument);
570 523
571 if (tl == NULL) 524 if (tl == NULL)
572 LOG (llevError, "Failed to link treasure to arch (%s): %s\n", &at->name, argument); 525 LOG (llevError, "Failed to link treasure to arch (%s): %s\n", &at->name, argument);
573 else 526 else
574 at->clone.randomitems = tl; 527 at->clone.randomitems = tl;
579 532
580#ifdef DEBUG 533#ifdef DEBUG
581void 534void
582check_generators (void) 535check_generators (void)
583{ 536{
584 archetype * 537 archetype *at;
585 at;
586 538
587 for (at = first_archetype; at != NULL; at = at->next) 539 for (at = first_archetype; at != NULL; at = at->next)
588 if (QUERY_FLAG (&at->clone, FLAG_GENERATOR) && at->clone.other_arch == NULL) 540 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); 541 LOG (llevError, "Warning: %s is generator but lacks other_arch.\n", &at->name);
590} 542}
598 */ 550 */
599 551
600void 552void
601load_archetypes (void) 553load_archetypes (void)
602{ 554{
603 char
604 filename[MAX_BUF]; 555 char filename[MAX_BUF];
605 556
606#if TIME_ARCH_LOAD 557#if TIME_ARCH_LOAD
607 struct timeval 558 struct timeval
608 tv1, 559 tv1,
609 tv2; 560 tv2;
647 */ 598 */
648 599
649object * 600object *
650arch_to_object (archetype *at) 601arch_to_object (archetype *at)
651{ 602{
652 object * 603 object *op;
653 op;
654 604
655 if (at == NULL) 605 if (at == NULL)
656 { 606 {
657 if (warn_archetypes) 607 if (warn_archetypes)
658 LOG (llevError, "Couldn't find archetype.\n"); 608 LOG (llevError, "Couldn't find archetype.\n");
675 */ 625 */
676 626
677object * 627object *
678create_singularity (const char *name) 628create_singularity (const char *name)
679{ 629{
680 object * op; 630 object *op;
681 char buf[MAX_BUF]; 631 char buf[MAX_BUF];
682 632
683 sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name); 633 sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name);
684 op = get_object (); 634 op = get_object ();
685 op->name = op->name_pl = buf; 635 op->name = op->name_pl = buf;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines