… | |
… | |
181 | * this replaces find_skill. |
181 | * this replaces find_skill. |
182 | */ |
182 | */ |
183 | object * |
183 | object * |
184 | find_skill_by_number (object *who, int skillno) |
184 | find_skill_by_number (object *who, int skillno) |
185 | { |
185 | { |
|
|
186 | if (!IN_RANGE_EXC (skillno, 1, NUM_SKILLS)) |
|
|
187 | return 0; |
|
|
188 | |
186 | object *skill = NULL, *skill_tool = NULL, *tmp; |
189 | object *skill = NULL, *skill_tool = NULL; |
187 | |
190 | |
188 | if (skillno < 1 || skillno >= NUM_SKILLS) |
|
|
189 | return NULL; |
|
|
190 | |
|
|
191 | for (tmp = who->inv; tmp != NULL; tmp = tmp->below) |
191 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
192 | { |
192 | { |
193 | if (tmp->type == SKILL && tmp->subtype == skillno) |
193 | if (tmp->type == SKILL && tmp->subtype == skillno) |
194 | skill = tmp; |
194 | skill = tmp; |
195 | |
195 | |
196 | /* Try to find appropriate skilltool. If the player has one already |
196 | /* Try to find appropriate skilltool. If the player has one already |
… | |
… | |
202 | skill_tool = tmp; |
202 | skill_tool = tmp; |
203 | else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
203 | else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
204 | skill_tool = tmp; |
204 | skill_tool = tmp; |
205 | } |
205 | } |
206 | } |
206 | } |
|
|
207 | |
207 | /* If this is a skill that can be used without a tool, return it */ |
208 | /* If this is a skill that can be used without a tool, return it */ |
208 | if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL)) |
209 | if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL)) |
209 | return skill; |
210 | return skill; |
210 | |
211 | |
211 | /* Player has a tool to use the skill. IF not applied, apply it - |
212 | /* Player has a tool to use the skill. If not applied, apply it - |
212 | * if not successful, return null. If they do have the skill tool |
213 | * if not successful, return null. If they do have the skill tool |
213 | * but not the skill itself, give it to them. |
214 | * but not the skill itself, give it to them. |
214 | */ |
215 | */ |
215 | if (skill_tool) |
216 | if (skill_tool) |
216 | { |
217 | { |
217 | if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
218 | if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
… | |
… | |
243 | change_skill (object *who, object *new_skill, int flag) |
244 | change_skill (object *who, object *new_skill, int flag) |
244 | { |
245 | { |
245 | if (who->type != PLAYER) |
246 | if (who->type != PLAYER) |
246 | return 0; |
247 | return 0; |
247 | |
248 | |
|
|
249 | #if 0 |
248 | // optimise this supposedly common case |
250 | // optimise this supposedly common case |
249 | if (new_skill == who->chosen_skill) |
251 | if (new_skill == who->chosen_skill) |
250 | return 1; |
252 | return 1; |
251 | |
253 | #endif |
252 | if (who->chosen_skill) |
|
|
253 | { |
|
|
254 | apply_special (who, who->chosen_skill, AP_UNAPPLY); |
|
|
255 | who->chosen_skill = 0;//D verify wether necessary |
|
|
256 | } |
|
|
257 | |
254 | |
258 | if (!new_skill) |
255 | if (!new_skill) |
259 | { |
256 | { |
260 | LOG (llevError | logBacktrace, "change_skill called on %s with NULL skill\n", |
257 | LOG (llevError | logBacktrace, "change_skill called on %s with NULL skill\n", |
261 | who->debug_desc ()); |
258 | who->debug_desc ()); |
262 | return 0; |
259 | return 0; |
263 | } |
260 | } |
264 | |
261 | |
|
|
262 | // the skill could be readied already because it is used by a weapon. |
|
|
263 | who->change_weapon (0); |
265 | new_skill->inv_splay (); |
264 | new_skill->inv_splay (); |
266 | |
265 | |
267 | if (apply_special (who, new_skill, AP_APPLY)) |
266 | if (apply_special (who, new_skill, AP_APPLY)) |
268 | return 0; |
267 | return 0; |
269 | |
268 | |
… | |
… | |
502 | * If certain skills should take more/less time, that should be |
501 | * If certain skills should take more/less time, that should be |
503 | * in the code for the skill itself. |
502 | * in the code for the skill itself. |
504 | */ |
503 | */ |
505 | |
504 | |
506 | if (op->type == PLAYER) |
505 | if (op->type == PLAYER) |
507 | op->speed_left -= 1.0; |
506 | op->speed_left -= 1.f; |
508 | |
507 | |
509 | /* this is a good place to add experience for successfull use of skills. |
508 | /* this is a good place to add experience for successfull use of skills. |
510 | * Note that add_exp() will figure out player/monster experience |
509 | * Note that add_exp() will figure out player/monster experience |
511 | * gain problems. |
510 | * gain problems. |
512 | */ |
511 | */ |