… | |
… | |
65 | * - the archetype found or null if nothing was found. |
65 | * - the archetype found or null if nothing was found. |
66 | */ |
66 | */ |
67 | archetype * |
67 | archetype * |
68 | find_archetype_by_object_name (const char *name) |
68 | find_archetype_by_object_name (const char *name) |
69 | { |
69 | { |
70 | archetype *at; |
70 | shstr_cmp name_cmp (name); |
71 | |
71 | |
72 | if (name == NULL) |
|
|
73 | return (archetype *) NULL; |
|
|
74 | |
|
|
75 | for (at = first_archetype; at != NULL; at = at->next) |
72 | for (archetype *at = first_archetype; at; at = at->next) |
76 | { |
73 | if (at->clone.name == name_cmp) |
77 | if (!strcmp (at->clone.name, name)) |
|
|
78 | return at; |
74 | return at; |
79 | } |
75 | |
80 | return NULL; |
76 | return 0; |
81 | } |
77 | } |
82 | |
78 | |
83 | /** |
79 | /** |
84 | * This function retrieves an archetype by type and name that appears during |
80 | * This function retrieves an archetype by type and name that appears during |
85 | * the game. It is basically the same as find_archetype_by_object_name() |
81 | * the game. It is basically the same as find_archetype_by_object_name() |
86 | * except that it considers only items of the given type. |
82 | * except that it considers only items of the given type. |
87 | */ |
83 | */ |
88 | archetype * |
84 | archetype * |
89 | find_archetype_by_object_type_name (int type, const char *name) |
85 | find_archetype_by_object_type_name (int type, const char *name) |
90 | { |
86 | { |
91 | archetype *at; |
87 | shstr_cmp name_cmp (name); |
92 | |
88 | |
93 | if (name == NULL) |
|
|
94 | return NULL; |
|
|
95 | |
|
|
96 | for (at = first_archetype; at != NULL; at = at->next) |
89 | for (archetype *at = first_archetype; at; at = at->next) |
97 | { |
90 | if (at->clone.name == name_cmp && at->clone.type == type) |
98 | if (at->clone.type == type && strcmp (at->clone.name, name) == 0) |
|
|
99 | return at; |
91 | return at; |
100 | } |
|
|
101 | |
92 | |
102 | return NULL; |
93 | return 0; |
103 | } |
94 | } |
104 | |
95 | |
105 | /* This is a lot like the above function. Instead, we are trying to match |
96 | /* This is a lot like the above function. Instead, we are trying to match |
106 | * the arch->skill values. type is the type of object to match |
97 | * the arch->skill values. type is the type of object to match |
107 | * against (eg, to only match against skills or only skill objects for example). |
98 | * against (eg, to only match against skills or only skill objects for example). |
108 | * If type is -1, ew don't match on type. |
99 | * If type is -1, ew don't match on type. |
109 | */ |
100 | */ |
110 | object * |
101 | object * |
111 | get_archetype_by_skill_name (const char *skill, int type) |
102 | get_archetype_by_skill_name (const char *skill, int type) |
112 | { |
103 | { |
113 | archetype *at; |
104 | shstr_cmp skill_cmp (skill); |
114 | |
105 | |
115 | if (skill) |
|
|
116 | for (at = first_archetype; at; at = at->next) |
106 | for (archetype *at = first_archetype; at; at = at->next) |
117 | if (((type == -1) || (type == at->clone.type)) && (!strcmp (at->clone.skill, skill))) |
107 | if (at->clone.skill == skill_cmp && (type == -1 || type == at->clone.type)) |
118 | return arch_to_object (at); |
108 | return arch_to_object (at); |
119 | |
109 | |
120 | return 0; |
110 | return 0; |
121 | } |
111 | } |
122 | |
112 | |
123 | /* similiar to above - this returns the first archetype |
113 | /* similiar to above - this returns the first archetype |
… | |
… | |
128 | * (eg, skills) |
118 | * (eg, skills) |
129 | */ |
119 | */ |
130 | archetype * |
120 | archetype * |
131 | get_archetype_by_type_subtype (int type, int subtype) |
121 | get_archetype_by_type_subtype (int type, int subtype) |
132 | { |
122 | { |
133 | archetype * |
|
|
134 | at; |
|
|
135 | |
|
|
136 | for (at = first_archetype; at != NULL; at = at->next) |
123 | for (archetype *at = first_archetype; at; at = at->next) |
137 | { |
|
|
138 | if (((type == -1) || (type == at->clone.type)) && (subtype == -1 || subtype == at->clone.subtype)) |
124 | if ((type == -1 || type == at->clone.type) && (subtype == -1 || subtype == at->clone.subtype)) |
139 | return at; |
125 | return at; |
140 | } |
126 | |
141 | return NULL; |
127 | return 0; |
142 | } |
128 | } |
143 | |
129 | |
144 | /** |
130 | /** |
145 | * GROS - this returns a new object given the name that appears during the game |
131 | * GROS - this returns a new object given the name that appears during the game |
146 | * (for example, "writing pen" instead of "stylus"). |
132 | * (for example, "writing pen" instead of "stylus"). |
… | |
… | |
154 | * but it otherwise had a big memory leak. |
140 | * but it otherwise had a big memory leak. |
155 | */ |
141 | */ |
156 | object * |
142 | object * |
157 | get_archetype_by_object_name (const char *name) |
143 | get_archetype_by_object_name (const char *name) |
158 | { |
144 | { |
159 | archetype *at; |
|
|
160 | char tmpname[MAX_BUF]; |
145 | char tmpname[MAX_BUF]; |
161 | int i; |
146 | int i; |
162 | |
147 | |
163 | assign (tmpname, name); |
148 | assign (tmpname, name); |
164 | |
149 | |
165 | for (i = strlen (tmpname); i > 0; i--) |
150 | for (i = strlen (tmpname); i > 0; i--) |
166 | { |
151 | { |
167 | tmpname[i] = 0; |
152 | tmpname[i] = 0; |
|
|
153 | |
168 | at = find_archetype_by_object_name (tmpname); |
154 | if (archetype *at = find_archetype_by_object_name (tmpname)) |
169 | |
|
|
170 | if (at) |
|
|
171 | return arch_to_object (at); |
155 | return arch_to_object (at); |
172 | } |
156 | } |
173 | |
157 | |
174 | return create_singularity (name); |
158 | return create_singularity (name); |
175 | } |
159 | } |