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.1 by root, Fri Feb 3 07:11:30 2006 UTC vs.
Revision 1.2 by root, Mon Mar 13 21:00:22 2006 UTC

1/* 1/*
2 * static char *rcsid_arch_c = 2 * static char *rcsid_arch_c =
3 * "$Id: arch.c,v 1.1 2006/02/03 07:11:30 root Exp $"; 3 * "$Id: arch.c,v 1.2 2006/03/13 21:00:22 root Exp $";
4 */ 4 */
5 5
6/* 6/*
7 CrossFire, A Multiplayer game for X-windows 7 CrossFire, A Multiplayer game for X-windows
8 8
31#include <funcpoint.h> 31#include <funcpoint.h>
32#include <loader.h> 32#include <loader.h>
33 33
34/* IF set, does a little timing on the archetype load. */ 34/* IF set, does a little timing on the archetype load. */
35#define TIME_ARCH_LOAD 0 35#define TIME_ARCH_LOAD 0
36
37static void add_arch(archetype *at);
36 38
37static archetype *arch_table[ARCHTABLE]; 39static archetype *arch_table[ARCHTABLE];
38int arch_cmp=0; /* How many strcmp's */ 40int arch_cmp=0; /* How many strcmp's */
39int arch_search=0; /* How many searches */ 41int arch_search=0; /* How many searches */
40int arch_init; /* True if doing arch initialization */ 42int arch_init; /* True if doing arch initialization */
66 68
67 for(at = first_archetype;at!=NULL;at=at->next) { 69 for(at = first_archetype;at!=NULL;at=at->next) {
68 if (!strcmp(at->clone.name, name)) 70 if (!strcmp(at->clone.name, name))
69 return at; 71 return at;
70 } 72 }
73 return NULL;
74}
75
76/**
77 * This function retrieves an archetype by type and name that appears during
78 * the game. It is basically the same as find_archetype_by_object_name()
79 * except that it considers only items of the given type.
80 */
81archetype *find_archetype_by_object_type_name(int type, const char *name) {
82 archetype *at;
83
84 if (name == NULL)
85 return NULL;
86
87 for (at = first_archetype; at != NULL; at = at->next) {
88 if (at->clone.type == type && strcmp(at->clone.name, name) == 0)
89 return at;
90 }
91
71 return NULL; 92 return NULL;
72} 93}
73 94
74/* This is a lot like the above function. Instead, we are trying to match 95/* This is a lot like the above function. Instead, we are trying to match
75 * the arch->skill values. type is the type of object to match 96 * the arch->skill values. type is the type of object to match
613 634
614unsigned long 635unsigned long
615hasharch(const char *str, int tablesize) { 636hasharch(const char *str, int tablesize) {
616 unsigned long hash = 0; 637 unsigned long hash = 0;
617 int i = 0; 638 int i = 0;
618 unsigned rot = 0;
619 const char *p; 639 const unsigned char *p;
620 640
641 /* use the one-at-a-time hash function, which supposedly is
642 * better than the djb2-like one used by perl5.005, but
643 * certainly is better then the bug used here before.
644 * see http://burtleburtle.net/bob/hash/doobs.html
645 */
621 for (p = str; i < MAXSTRING && *p; p++, i++) { 646 for (p = str; i < MAXSTRING && *p; p++, i++) {
622 hash ^= (unsigned long) *p << rot; 647 hash += *p;
623 rot += 2; 648 hash += hash << 10;
624 if (rot >= (sizeof(long) - sizeof(char)) * 8) 649 hash ^= hash >> 6;
625 rot = 0;
626 } 650 }
651 hash += hash << 3;
652 hash ^= hash >> 11;
653 hash += hash << 15;
627 return (hash % tablesize); 654 return hash % tablesize;
628} 655}
629 656
630/* 657/*
631 * Finds, using the hashtable, which archetype matches the given name. 658 * Finds, using the hashtable, which archetype matches the given name.
632 * returns a pointer to the found archetype, otherwise NULL. 659 * returns a pointer to the found archetype, otherwise NULL.
658 685
659/* 686/*
660 * Adds an archetype to the hashtable. 687 * Adds an archetype to the hashtable.
661 */ 688 */
662 689
663void add_arch(archetype *at) { 690static void add_arch(archetype *at) {
664 int index=hasharch(at->name, ARCHTABLE),org_index=index; 691 int index=hasharch(at->name, ARCHTABLE),org_index=index;
665 for(;;) { 692 for(;;) {
666 if(arch_table[index]==NULL) { 693 if(arch_table[index]==NULL) {
667 arch_table[index]=at; 694 arch_table[index]=at;
668 return; 695 return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines