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

Comparing cf.schmorp.de/server/common/arch.C (file contents):
Revision 1.20 by root, Thu Sep 14 21:16:11 2006 UTC vs.
Revision 1.23 by root, Thu Sep 14 23:13:48 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);
391 */ 382 */
392 383
393void 384void
394dump_all_archetypes (void) 385dump_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
406void 396void
407free_all_archs (void) 397free_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 */
445void 432void
446first_arch_pass (object_thawer & fp) 433first_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
526void 511void
527second_arch_pass (object_thawer & thawer) 512second_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;
579 561
580#ifdef DEBUG 562#ifdef DEBUG
581void 563void
582check_generators (void) 564check_generators (void)
583{ 565{
584 archetype * 566 archetype *at;
585 at;
586 567
587 for (at = first_archetype; at != NULL; at = at->next) 568 for (at = first_archetype; at != NULL; at = at->next)
588 if (QUERY_FLAG (&at->clone, FLAG_GENERATOR) && at->clone.other_arch == NULL) 569 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); 570 LOG (llevError, "Warning: %s is generator but lacks other_arch.\n", &at->name);
590} 571}
598 */ 579 */
599 580
600void 581void
601load_archetypes (void) 582load_archetypes (void)
602{ 583{
603 char
604 filename[MAX_BUF]; 584 char filename[MAX_BUF];
605 585
606#if TIME_ARCH_LOAD 586#if TIME_ARCH_LOAD
607 struct timeval 587 struct timeval
608 tv1, 588 tv1,
609 tv2; 589 tv2;
647 */ 627 */
648 628
649object * 629object *
650arch_to_object (archetype *at) 630arch_to_object (archetype *at)
651{ 631{
652 object * 632 object *op;
653 op;
654 633
655 if (at == NULL) 634 if (at == NULL)
656 { 635 {
657 if (warn_archetypes) 636 if (warn_archetypes)
658 LOG (llevError, "Couldn't find archetype.\n"); 637 LOG (llevError, "Couldn't find archetype.\n");
675 */ 654 */
676 655
677object * 656object *
678create_singularity (const char *name) 657create_singularity (const char *name)
679{ 658{
680 object * op; 659 object *op;
681 char buf[MAX_BUF]; 660 char buf[MAX_BUF];
682 661
683 sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name); 662 sprintf (buf, "%s (%s)", ARCH_SINGULARITY, name);
684 op = get_object (); 663 op = get_object ();
685 op->name = op->name_pl = buf; 664 op->name = op->name_pl = buf;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines