… | |
… | |
115 | * tool, this code will equip it. |
115 | * tool, this code will equip it. |
116 | */ |
116 | */ |
117 | object * |
117 | object * |
118 | find_skill_by_name (object *who, const char *name) |
118 | find_skill_by_name (object *who, const char *name) |
119 | { |
119 | { |
120 | object *skill = NULL, *skill_tool = NULL, *tmp; |
|
|
121 | |
|
|
122 | if (!name) |
120 | if (!name) |
123 | return NULL; |
121 | return 0; |
|
|
122 | |
|
|
123 | object *skill = 0, *skill_tool = 0; |
124 | |
124 | |
125 | /* We make sure the length of the string in the object is greater |
125 | /* We make sure the length of the string in the object is greater |
126 | * in length than the passed string. Eg, if we have a skill called |
126 | * in length than the passed string. Eg, if we have a skill called |
127 | * 'hi', we don't want to match if the user passed 'high' |
127 | * 'hi', we don't want to match if the user passed 'high' |
128 | */ |
128 | */ |
129 | for (tmp = who->inv; tmp != NULL; tmp = tmp->below) |
129 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
130 | { |
130 | { |
131 | if (tmp->type == SKILL && !strncasecmp (name, tmp->skill, strlen (name)) && (size_t) strlen (tmp->skill) >= strlen (name)) |
131 | if (tmp->type == SKILL && !strncasecmp (name, tmp->skill, strlen (name)) && strlen (tmp->skill) >= strlen (name)) |
132 | skill = tmp; |
132 | skill = tmp; |
133 | |
133 | |
134 | /* Try to find appropriate skilltool. If the player has one already |
134 | /* Try to find appropriate skilltool. If the player has one already |
135 | * applied, we try to keep using that one. |
135 | * applied, we try to keep using that one. |
136 | */ |
136 | */ |
137 | else if (tmp->type == SKILL_TOOL && !strncasecmp (name, tmp->skill, strlen (name)) && (size_t) strlen (tmp->skill) >= strlen (name)) |
137 | else if (tmp->type == SKILL_TOOL && !strncasecmp (name, tmp->skill, strlen (name)) && strlen (tmp->skill) >= strlen (name)) |
138 | { |
138 | { |
139 | if (QUERY_FLAG (tmp, FLAG_APPLIED)) |
139 | if (QUERY_FLAG (tmp, FLAG_APPLIED)) |
140 | skill_tool = tmp; |
140 | skill_tool = tmp; |
141 | else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
141 | else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
142 | skill_tool = tmp; |
142 | skill_tool = tmp; |
143 | } |
143 | } |
144 | } |
144 | } |
|
|
145 | |
145 | /* If this is a skill that can be used without a tool, return it */ |
146 | /* If this is a skill that can be used without a tool, return it */ |
146 | if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL)) |
147 | if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL)) |
147 | return skill; |
148 | return skill; |
148 | |
149 | |
149 | /* Player has a tool to use the skill. IF not applied, apply it - |
150 | /* Player has a tool to use the skill. If not applied, apply it - |
150 | * if not successful, return null. If they do have the skill tool |
151 | * if not successful, return null. If they do have the skill tool |
151 | * but not the skill itself, give it to them. |
152 | * but not the skill itself, give it to them. |
152 | */ |
153 | */ |
153 | if (skill_tool) |
154 | if (skill_tool) |
154 | { |
155 | { |
155 | if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
156 | if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
156 | { |
|
|
157 | if (apply_special (who, skill_tool, 0)) |
157 | if (apply_special (who, skill_tool, 0)) |
158 | return NULL; |
158 | return 0; |
159 | } |
|
|
160 | |
159 | |
161 | if (!skill) |
160 | if (!skill) |
162 | { |
161 | { |
163 | skill = give_skill_by_name (who, skill_tool->skill); |
162 | skill = give_skill_by_name (who, skill_tool->skill); |
164 | link_player_skills (who); |
163 | link_player_skills (who); |
165 | } |
164 | } |
166 | |
165 | |
167 | return skill; |
166 | return skill; |
168 | } |
167 | } |
169 | |
168 | |
170 | return NULL; |
169 | return 0; |
171 | } |
170 | } |
172 | |
171 | |
173 | |
172 | |
174 | /* This returns the skill pointer of the given name (the |
173 | /* This returns the skill pointer of the given name (the |
175 | * one that accumlates exp, has the level, etc). |
174 | * one that accumlates exp, has the level, etc). |