… | |
… | |
167 | } |
167 | } |
168 | |
168 | |
169 | return 0; |
169 | return 0; |
170 | } |
170 | } |
171 | |
171 | |
172 | |
|
|
173 | /* This returns the skill pointer of the given name (the |
172 | /* This returns the skill pointer of the given name (the |
174 | * one that accumlates exp, has the level, etc). |
173 | * one that accumlates exp, has the level, etc). |
175 | * |
174 | * |
176 | * It is presumed that the player will be needing to actually |
175 | * It is presumed that the player will be needing to actually |
177 | * use the skill, so thus if use of the skill requires a skill |
176 | * use the skill, so thus if use of the skill requires a skill |
… | |
… | |
182 | * this replaces find_skill. |
181 | * this replaces find_skill. |
183 | */ |
182 | */ |
184 | object * |
183 | object * |
185 | find_skill_by_number (object *who, int skillno) |
184 | find_skill_by_number (object *who, int skillno) |
186 | { |
185 | { |
|
|
186 | if (!IN_RANGE_EXC (skillno, 1, NUM_SKILLS)) |
|
|
187 | return 0; |
|
|
188 | |
187 | object *skill = NULL, *skill_tool = NULL, *tmp; |
189 | object *skill = NULL, *skill_tool = NULL; |
188 | |
190 | |
189 | if (skillno < 1 || skillno >= NUM_SKILLS) |
|
|
190 | return NULL; |
|
|
191 | |
|
|
192 | for (tmp = who->inv; tmp != NULL; tmp = tmp->below) |
191 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
193 | { |
192 | { |
194 | if (tmp->type == SKILL && tmp->subtype == skillno) |
193 | if (tmp->type == SKILL && tmp->subtype == skillno) |
195 | skill = tmp; |
194 | skill = tmp; |
196 | |
195 | |
197 | /* Try to find appropriate skilltool. If the player has one already |
196 | /* Try to find appropriate skilltool. If the player has one already |
… | |
… | |
203 | skill_tool = tmp; |
202 | skill_tool = tmp; |
204 | else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
203 | else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
205 | skill_tool = tmp; |
204 | skill_tool = tmp; |
206 | } |
205 | } |
207 | } |
206 | } |
|
|
207 | |
208 | /* 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 */ |
209 | if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL)) |
209 | if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL)) |
210 | return skill; |
210 | return skill; |
211 | |
211 | |
212 | /* 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 - |
213 | * 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 |
214 | * but not the skill itself, give it to them. |
214 | * but not the skill itself, give it to them. |
215 | */ |
215 | */ |
216 | if (skill_tool) |
216 | if (skill_tool) |
217 | { |
217 | { |
218 | if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
218 | if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
… | |
… | |
244 | change_skill (object *who, object *new_skill, int flag) |
244 | change_skill (object *who, object *new_skill, int flag) |
245 | { |
245 | { |
246 | if (who->type != PLAYER) |
246 | if (who->type != PLAYER) |
247 | return 0; |
247 | return 0; |
248 | |
248 | |
|
|
249 | #if 0 |
249 | // optimise this supposedly common case |
250 | // optimise this supposedly common case |
250 | if (new_skill == who->chosen_skill) |
251 | if (new_skill == who->chosen_skill) |
251 | return 1; |
252 | return 1; |
252 | |
253 | #endif |
253 | if (who->chosen_skill) |
|
|
254 | apply_special (who, who->chosen_skill, AP_UNAPPLY); |
|
|
255 | |
254 | |
256 | if (!new_skill) |
255 | if (!new_skill) |
257 | { |
256 | { |
258 | 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", |
259 | who->debug_desc ()); |
258 | who->debug_desc ()); |
260 | return 0; |
259 | return 0; |
261 | } |
260 | } |
262 | |
261 | |
263 | player *pl = who->contr; |
262 | // the skill could be readied already because it is used by a weapon. |
264 | |
263 | who->change_weapon (0); |
265 | // move skill to front, so it will be prefered next time |
264 | new_skill->inv_splay (); |
266 | new_skill->remove (); |
|
|
267 | who->insert (new_skill); |
|
|
268 | |
265 | |
269 | if (apply_special (who, new_skill, AP_APPLY)) |
266 | if (apply_special (who, new_skill, AP_APPLY)) |
270 | return 0; |
267 | return 0; |
271 | |
268 | |
272 | return 1; |
269 | return 1; |
… | |
… | |
299 | int |
296 | int |
300 | do_skill (object *op, object *part, object *skill, int dir, const char *string) |
297 | do_skill (object *op, object *part, object *skill, int dir, const char *string) |
301 | { |
298 | { |
302 | int success = 0, exp = 0; |
299 | int success = 0, exp = 0; |
303 | int did_alc = 0; |
300 | int did_alc = 0; |
304 | object *tmp, *next; |
|
|
305 | |
301 | |
306 | if (!skill) |
302 | if (!skill) |
307 | return 0; |
303 | return 0; |
308 | |
304 | |
309 | /* The code below presumes that the skill points to the object that |
305 | /* The code below presumes that the skill points to the object that |
… | |
… | |
311 | * go and try to find the actual real skill pointer, and if the |
307 | * go and try to find the actual real skill pointer, and if the |
312 | * the player doesn't have a bucket for that, create one. |
308 | * the player doesn't have a bucket for that, create one. |
313 | */ |
309 | */ |
314 | if (skill->type != SKILL && op->type == PLAYER) |
310 | if (skill->type != SKILL && op->type == PLAYER) |
315 | { |
311 | { |
316 | for (tmp = op->inv; tmp != NULL; tmp = tmp->below) |
312 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
317 | if (tmp->type == SKILL && tmp->skill == skill->skill) |
313 | if (tmp->type == SKILL && tmp->skill == skill->skill) |
318 | break; |
314 | { |
|
|
315 | skill = tmp; |
|
|
316 | goto found; |
|
|
317 | } |
319 | |
318 | |
320 | if (!tmp) |
|
|
321 | tmp = give_skill_by_name (op, skill->skill); |
319 | skill = give_skill_by_name (op, skill->skill); |
322 | |
320 | found: ; |
323 | skill = tmp; |
|
|
324 | } |
321 | } |
325 | |
322 | |
326 | // skill, by_whom, on_which_object, which direction, skill_argument |
323 | // skill, by_whom, on_which_object, which direction, skill_argument |
327 | if (INVOKE_OBJECT (USE_SKILL, skill, ARG_OBJECT (op), ARG_OBJECT (part), ARG_INT (dir), ARG_STRING (string))) |
324 | if (INVOKE_OBJECT (USE_SKILL, skill, ARG_OBJECT (op), ARG_OBJECT (part), ARG_INT (dir), ARG_STRING (string))) |
328 | return 0; |
325 | return 0; |
… | |
… | |
433 | case SK_LITERACY: |
430 | case SK_LITERACY: |
434 | case SK_WOODSMAN: |
431 | case SK_WOODSMAN: |
435 | /* first, we try to find a cauldron, and do the alchemy thing. |
432 | /* first, we try to find a cauldron, and do the alchemy thing. |
436 | * failing that, we go and identify stuff. |
433 | * failing that, we go and identify stuff. |
437 | */ |
434 | */ |
438 | for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = next) |
435 | for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next) |
439 | { |
436 | { |
440 | next = tmp->above; |
437 | next = tmp->above; |
441 | |
438 | |
442 | if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) |
439 | if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) |
443 | { |
440 | { |
… | |
… | |
504 | * If certain skills should take more/less time, that should be |
501 | * If certain skills should take more/less time, that should be |
505 | * in the code for the skill itself. |
502 | * in the code for the skill itself. |
506 | */ |
503 | */ |
507 | |
504 | |
508 | if (op->type == PLAYER) |
505 | if (op->type == PLAYER) |
509 | op->speed_left -= 1.0; |
506 | op->speed_left -= 1.f; |
510 | |
507 | |
511 | /* 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. |
512 | * Note that add_exp() will figure out player/monster experience |
509 | * Note that add_exp() will figure out player/monster experience |
513 | * gain problems. |
510 | * gain problems. |
514 | */ |
511 | */ |
… | |
… | |
934 | LOG (llevError, "Could not find anything to attack on %s\n", &op->name); |
931 | LOG (llevError, "Could not find anything to attack on %s\n", &op->name); |
935 | return 0; |
932 | return 0; |
936 | } |
933 | } |
937 | } |
934 | } |
938 | |
935 | |
939 | op->set_weapon (pl->combat_ob); |
936 | if (!op->change_weapon (pl->combat_ob)) |
|
|
937 | return 0; |
940 | |
938 | |
941 | /* lose invisiblity/hiding status for running attacks */ |
939 | /* lose invisiblity/hiding status for running attacks */ |
942 | if (pl->tmp_invis) |
940 | if (pl->tmp_invis) |
943 | { |
941 | { |
944 | pl->tmp_invis = 0; |
942 | pl->tmp_invis = 0; |