… | |
… | |
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)) |
… | |
… | |
234 | } |
234 | } |
235 | |
235 | |
236 | /* This changes the objects skill to new_skill. |
236 | /* This changes the objects skill to new_skill. |
237 | * note that this function doesn't always need to get used - |
237 | * note that this function doesn't always need to get used - |
238 | * you can now add skill exp to the player without the chosen_skill being |
238 | * you can now add skill exp to the player without the chosen_skill being |
239 | * set. This function is of most interest to players to update |
239 | * set. This function is of most interest to players to update |
240 | * the various range information. |
240 | * the various range information. |
241 | * return 1 on success, 0 on error |
241 | * return 1 on success, 0 on error |
242 | */ |
242 | */ |
243 | int |
243 | int |
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 | |
|
|
249 | #if 0 |
|
|
250 | // optimise this supposedly common case |
|
|
251 | if (new_skill == who->chosen_skill) |
|
|
252 | return 1; |
|
|
253 | #endif |
248 | |
254 | |
249 | if (!new_skill) |
255 | if (!new_skill) |
250 | { |
256 | { |
251 | 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", |
252 | who->debug_desc ()); |
258 | who->debug_desc ()); |
253 | return 0; |
259 | return 0; |
254 | } |
260 | } |
255 | |
261 | |
256 | player *pl = who->contr; |
262 | // the skill could be readied already because it is used by a weapon. |
257 | |
263 | who->change_weapon (0); |
258 | // move skill to front, so it will be preferred next time |
264 | new_skill->inv_splay (); |
259 | new_skill->remove (); |
|
|
260 | who->insert (new_skill); |
|
|
261 | |
265 | |
262 | if (apply_special (who, new_skill, AP_APPLY)) |
266 | if (apply_special (who, new_skill, AP_APPLY)) |
263 | return 0; |
267 | return 0; |
264 | |
268 | |
265 | return 1; |
269 | return 1; |
… | |
… | |
292 | int |
296 | int |
293 | 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) |
294 | { |
298 | { |
295 | int success = 0, exp = 0; |
299 | int success = 0, exp = 0; |
296 | int did_alc = 0; |
300 | int did_alc = 0; |
297 | object *tmp, *next; |
|
|
298 | |
301 | |
299 | if (!skill) |
302 | if (!skill) |
300 | return 0; |
303 | return 0; |
301 | |
304 | |
302 | /* 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 |
… | |
… | |
304 | * 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 |
305 | * the player doesn't have a bucket for that, create one. |
308 | * the player doesn't have a bucket for that, create one. |
306 | */ |
309 | */ |
307 | if (skill->type != SKILL && op->type == PLAYER) |
310 | if (skill->type != SKILL && op->type == PLAYER) |
308 | { |
311 | { |
309 | for (tmp = op->inv; tmp != NULL; tmp = tmp->below) |
312 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
310 | if (tmp->type == SKILL && tmp->skill == skill->skill) |
313 | if (tmp->type == SKILL && tmp->skill == skill->skill) |
311 | break; |
314 | { |
|
|
315 | skill = tmp; |
|
|
316 | goto found; |
|
|
317 | } |
312 | |
318 | |
313 | if (!tmp) |
|
|
314 | tmp = give_skill_by_name (op, skill->skill); |
319 | skill = give_skill_by_name (op, skill->skill); |
315 | |
320 | found: ; |
316 | skill = tmp; |
|
|
317 | } |
321 | } |
318 | |
322 | |
319 | // skill, by_whom, on_which_object, which direction, skill_argument |
323 | // skill, by_whom, on_which_object, which direction, skill_argument |
320 | 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))) |
321 | return 0; |
325 | return 0; |
… | |
… | |
426 | case SK_LITERACY: |
430 | case SK_LITERACY: |
427 | case SK_WOODSMAN: |
431 | case SK_WOODSMAN: |
428 | /* 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. |
429 | * failing that, we go and identify stuff. |
433 | * failing that, we go and identify stuff. |
430 | */ |
434 | */ |
431 | 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) |
432 | { |
436 | { |
433 | next = tmp->above; |
437 | next = tmp->above; |
434 | |
438 | |
435 | if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) |
439 | if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) |
436 | { |
440 | { |
… | |
… | |
497 | * If certain skills should take more/less time, that should be |
501 | * If certain skills should take more/less time, that should be |
498 | * in the code for the skill itself. |
502 | * in the code for the skill itself. |
499 | */ |
503 | */ |
500 | |
504 | |
501 | if (op->type == PLAYER) |
505 | if (op->type == PLAYER) |
502 | op->speed_left -= 1.0; |
506 | op->speed_left -= 1.f; |
503 | |
507 | |
504 | /* 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. |
505 | * Note that add_exp() will figure out player/monster experience |
509 | * Note that add_exp() will figure out player/monster experience |
506 | * gain problems. |
510 | * gain problems. |
507 | */ |
511 | */ |
… | |
… | |
678 | link_player_skills (pl); |
682 | link_player_skills (pl); |
679 | return 1; |
683 | return 1; |
680 | } |
684 | } |
681 | |
685 | |
682 | /* Gives a percentage clipped to 0% -> 100% of a/b. */ |
686 | /* Gives a percentage clipped to 0% -> 100% of a/b. */ |
683 | |
|
|
684 | /* Probably belongs in some global utils-type file? */ |
687 | /* Probably belongs in some global utils-type file? */ |
685 | static int |
688 | static int |
686 | clipped_percent (sint64 a, sint64 b) |
689 | clipped_percent (sint64 a, sint64 b) |
687 | { |
690 | { |
688 | int rv; |
691 | int rv; |
… | |
… | |
781 | * direction that the user is facing. Returns false if we are unable to |
784 | * direction that the user is facing. Returns false if we are unable to |
782 | * change to the requested skill, or were unable to use the skill properly. |
785 | * change to the requested skill, or were unable to use the skill properly. |
783 | * This is tricky because skills can have spaces. We basically roll |
786 | * This is tricky because skills can have spaces. We basically roll |
784 | * our own find_skill_by_name so we can try to do better string matching. |
787 | * our own find_skill_by_name so we can try to do better string matching. |
785 | */ |
788 | */ |
786 | |
|
|
787 | int |
789 | int |
788 | use_skill (object *op, const char *string) |
790 | use_skill (object *op, const char *string) |
789 | { |
791 | { |
790 | object *skop; |
792 | object *skop; |
791 | size_t len; |
793 | size_t len; |
… | |
… | |
929 | 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); |
930 | return 0; |
932 | return 0; |
931 | } |
933 | } |
932 | } |
934 | } |
933 | |
935 | |
934 | op->set_weapon (pl->combat_ob); |
936 | if (!op->change_weapon (pl->combat_ob)) |
|
|
937 | return 0; |
935 | |
938 | |
936 | /* lose invisiblity/hiding status for running attacks */ |
939 | /* lose invisiblity/hiding status for running attacks */ |
937 | if (pl->tmp_invis) |
940 | if (pl->tmp_invis) |
938 | { |
941 | { |
939 | pl->tmp_invis = 0; |
942 | pl->tmp_invis = 0; |