1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
59 | /* init_skills basically just sets up the skill_names table |
59 | /* init_skills basically just sets up the skill_names table |
60 | * above. The index into the array is set up by the |
60 | * above. The index into the array is set up by the |
61 | * subtypes. |
61 | * subtypes. |
62 | */ |
62 | */ |
63 | void |
63 | void |
64 | init_skills (void) |
64 | init_skills () |
65 | { |
65 | { |
66 | for_all_archetypes (at) |
66 | for_all_archetypes (at) |
67 | if (at->type == SKILL) |
67 | if (at->type == SKILL) |
68 | { |
68 | { |
69 | if (skill_names[at->subtype]) |
69 | if (skill_names[at->subtype]) |
… | |
… | |
168 | |
168 | |
169 | if (!skill) |
169 | if (!skill) |
170 | skill = give_skill_by_name (who, skill_tool->skill); |
170 | skill = give_skill_by_name (who, skill_tool->skill); |
171 | |
171 | |
172 | if (!skill_tool->flag [FLAG_APPLIED]) |
172 | if (!skill_tool->flag [FLAG_APPLIED]) |
173 | if (apply_special (who, splay (skill_tool), AP_APPLY | AP_NO_READY)) |
173 | if (!who->apply (splay (skill_tool))) |
174 | return 0; |
174 | return 0; |
175 | |
175 | |
176 | return splay (skill); |
176 | return splay (skill); |
177 | } |
177 | } |
178 | |
178 | |
179 | object * |
179 | object * |
180 | find_skill_by_name_fuzzy (object *who, const char *name) |
180 | find_skill_by_name_fuzzy (object *who, const char *name) |
181 | { |
181 | { |
182 | if (!name) |
182 | if (name) |
183 | return 0; |
|
|
184 | |
|
|
185 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
183 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
186 | if ((tmp->type == SKILL || tmp->type == SKILL_TOOL) |
184 | if ((tmp->type == SKILL || tmp->type == SKILL_TOOL) |
187 | && tmp->skill.starts_with (name)) |
185 | && tmp->skill.starts_with (name)) |
188 | if (object *skop = find_skill_by_name (who, tmp->skill)) |
186 | if (object *skop = find_skill_by_name (who, tmp->skill)) |
189 | return skop; |
187 | return skop; |
190 | |
188 | |
191 | return 0; |
189 | return 0; |
192 | } |
190 | } |
193 | |
191 | |
194 | /* This returns the skill pointer of the given name (the |
192 | /* This returns the skill pointer of the given name (the |
… | |
… | |
209 | if (tmp->type == SKILL && tmp->subtype == skillno) |
207 | if (tmp->type == SKILL && tmp->subtype == skillno) |
210 | if (object *skop = find_skill_by_name (who, tmp->skill)) |
208 | if (object *skop = find_skill_by_name (who, tmp->skill)) |
211 | return skop; |
209 | return skop; |
212 | |
210 | |
213 | return 0; |
211 | return 0; |
214 | } |
|
|
215 | |
|
|
216 | /* This changes the objects chosen_skill to new_skill. |
|
|
217 | * return 1 on success, 0 on error |
|
|
218 | */ |
|
|
219 | bool |
|
|
220 | object::change_skill (object *new_skill) |
|
|
221 | { |
|
|
222 | if (type != PLAYER) |
|
|
223 | return 0; |
|
|
224 | |
|
|
225 | // optimise this supposedly common case |
|
|
226 | if (new_skill == chosen_skill) |
|
|
227 | return 1; |
|
|
228 | |
|
|
229 | if (chosen_skill) |
|
|
230 | { |
|
|
231 | chosen_skill->flag [FLAG_APPLIED] = false; |
|
|
232 | change_abil (this, chosen_skill); |
|
|
233 | } |
|
|
234 | |
|
|
235 | chosen_skill = new_skill; |
|
|
236 | |
|
|
237 | if (chosen_skill) |
|
|
238 | { |
|
|
239 | chosen_skill->flag [FLAG_APPLIED] = true; |
|
|
240 | change_abil (this, chosen_skill); |
|
|
241 | } |
|
|
242 | |
|
|
243 | // always clear current weapon, as the selected skill could |
|
|
244 | // conflict with the current weapon skill, which would go |
|
|
245 | // undetected and exp would be given to the wrong skill. |
|
|
246 | current_weapon = 0; |
|
|
247 | |
|
|
248 | update_stats (); |
|
|
249 | return 1; |
|
|
250 | } |
212 | } |
251 | |
213 | |
252 | /* do_skill() - Main skills use function-similar in scope to cast_spell(). |
214 | /* do_skill() - Main skills use function-similar in scope to cast_spell(). |
253 | * We handle all requests for skill use outside of some combat here. |
215 | * We handle all requests for skill use outside of some combat here. |
254 | * We require a separate routine outside of fire() so as to allow monsters |
216 | * We require a separate routine outside of fire() so as to allow monsters |
… | |
… | |
408 | { |
370 | { |
409 | found_cauldron = true; |
371 | found_cauldron = true; |
410 | |
372 | |
411 | if (tmp->skill != skill->skill) |
373 | if (tmp->skill != skill->skill) |
412 | { |
374 | { |
413 | op->failmsg (format ("You can't use the %s with the %s skill!", |
375 | op->failmsgf ("You can't use the %s with the %s skill!", |
414 | query_name (tmp), |
376 | query_name (tmp), |
415 | query_name (skill))); |
377 | query_name (skill)); |
416 | break; |
378 | break; |
417 | } |
379 | } |
418 | |
380 | |
419 | attempt_do_alchemy (op, tmp, skill); |
381 | attempt_do_alchemy (op, tmp, skill); |
420 | |
382 | |
… | |
… | |
462 | case SK_EVOCATION: |
424 | case SK_EVOCATION: |
463 | case SK_PYROMANCY: |
425 | case SK_PYROMANCY: |
464 | case SK_SUMMONING: |
426 | case SK_SUMMONING: |
465 | case SK_CLIMBING: |
427 | case SK_CLIMBING: |
466 | new_draw_info (NDI_UNIQUE, 0, op, "This skill is already in effect."); |
428 | new_draw_info (NDI_UNIQUE, 0, op, "This skill is already in effect."); |
|
|
429 | break; |
|
|
430 | |
|
|
431 | case SK_MINING: |
|
|
432 | success = skill_mining (op, part, skill, dir, string); |
|
|
433 | break; |
|
|
434 | |
|
|
435 | case SK_FISHING: |
|
|
436 | success = skill_fishing (op, part, skill, dir, string); |
467 | break; |
437 | break; |
468 | |
438 | |
469 | default: |
439 | default: |
470 | LOG (llevDebug, "%s attempted to use unknown skill: %d\n", query_name (op), op->chosen_skill->stats.sp); |
440 | LOG (llevDebug, "%s attempted to use unknown skill: %d\n", query_name (op), op->chosen_skill->stats.sp); |
471 | break; |
441 | break; |
… | |
… | |
760 | |
730 | |
761 | if (!string) |
731 | if (!string) |
762 | return 0; |
732 | return 0; |
763 | |
733 | |
764 | for (skop = op->inv; skop; skop = skop->below) |
734 | for (skop = op->inv; skop; skop = skop->below) |
765 | { |
735 | if ((skop->type == SKILL || skop->type == SKILL_TOOL) |
766 | if (skop->type == SKILL |
|
|
767 | && QUERY_FLAG (skop, FLAG_CAN_USE_SKILL) |
|
|
768 | && !strncasecmp (string, skop->skill, min (strlen (string), (size_t) strlen (skop->skill)))) |
736 | && !strncmp (string, skop->skill, min (strlen (string), strlen (skop->skill)))) |
|
|
737 | { |
|
|
738 | skop = find_skill_by_name (op, skop->skill); |
769 | break; |
739 | break; |
770 | else if (skop->type == SKILL_TOOL |
|
|
771 | && !strncasecmp (string, skop->skill, min (strlen (string), (size_t) strlen (skop->skill)))) |
|
|
772 | break; |
|
|
773 | } |
740 | } |
774 | |
741 | |
775 | if (!skop) |
742 | if (!skop) |
776 | { |
743 | { |
777 | new_draw_info_format (NDI_UNIQUE, 0, op, "Unable to find skill %s", string); |
744 | op->failmsgf ("Unable to find skill %s.", string); |
|
|
745 | return 0; |
|
|
746 | } |
|
|
747 | |
|
|
748 | if (!(skill_flags [skop->subtype] & SF_USE)) |
|
|
749 | { |
|
|
750 | op->failmsgf ( |
|
|
751 | "You feel as if you wanted to do something funny, but you can't remember what. " |
|
|
752 | "H<The %s skill cannot be C<use_skill>'ed - maybe you need to C<ready_skill> it, " |
|
|
753 | "use it with some item, or it's always active.>", |
|
|
754 | &skop->skill |
|
|
755 | ); |
778 | return 0; |
756 | return 0; |
779 | } |
757 | } |
780 | |
758 | |
781 | len = strlen (skop->skill); |
759 | len = strlen (skop->skill); |
782 | |
760 | |
… | |
… | |
808 | } |
786 | } |
809 | |
787 | |
810 | static bool |
788 | static bool |
811 | hth_skill_p (object *skill) |
789 | hth_skill_p (object *skill) |
812 | { |
790 | { |
813 | return (skill_flags [skill->subtype] & (SF_COMBAT | SF_NEED_WEAPON)) == SF_COMBAT; |
791 | return (skill_flags [skill->subtype] & (SF_COMBAT | SF_NEED_ITEM)) == SF_COMBAT; |
814 | } |
792 | } |
815 | |
793 | |
816 | /* This finds the first unarmed skill the player has, and returns it. |
794 | /* This finds the first unarmed skill the player has, and returns it. |
817 | */ |
795 | */ |
818 | static object * |
796 | static object * |
… | |
… | |
847 | * through that code if skill is set to change to the skill. |
825 | * through that code if skill is set to change to the skill. |
848 | */ |
826 | */ |
849 | if (player *pl = op->contr) |
827 | if (player *pl = op->contr) |
850 | { |
828 | { |
851 | if (skill) |
829 | if (skill) |
852 | op->change_skill (skill); |
830 | { |
|
|
831 | if (!op->apply (skill)) |
|
|
832 | return 0; |
|
|
833 | } |
853 | else |
834 | else |
854 | { |
835 | { |
855 | if (!pl->combat_ob) |
836 | if (!pl->combat_ob) |
856 | { |
837 | { |
857 | if (QUERY_FLAG (op, FLAG_READY_WEAPON)) |
838 | if (QUERY_FLAG (op, FLAG_READY_WEAPON)) |
… | |
… | |
879 | |
860 | |
880 | if (!skill) |
861 | if (!skill) |
881 | new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); |
862 | new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); |
882 | } |
863 | } |
883 | |
864 | |
884 | if (skill) |
865 | op->apply (skill); |
885 | { |
|
|
886 | op->change_skill (0); |
|
|
887 | apply_special (op, skill, AP_APPLY); |
|
|
888 | } |
|
|
889 | } |
866 | } |
890 | |
867 | |
891 | if (!pl->combat_ob) |
868 | if (!pl->combat_ob) |
892 | { |
869 | { |
893 | LOG (llevError, "Could not find anything to attack on %s\n", &op->name); |
870 | LOG (llevError, "Could not find anything to attack on %s\n", &op->name); |
894 | return 0; |
871 | return 0; |
895 | } |
872 | } |
896 | } |
873 | } |
897 | |
874 | |
898 | if (!op->change_weapon (pl->combat_ob)) |
875 | if (!op->apply (pl->combat_ob)) |
899 | return 0; |
876 | return 0; |
900 | } |
877 | } |
901 | |
878 | |
902 | /* lose invisiblity/hiding status for running attacks */ |
879 | /* lose invisiblity/hiding status for running attacks */ |
903 | if (pl->tmp_invis) |
880 | if (pl->tmp_invis) |