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 |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | /* Created July 95 to separate skill utilities from actual skills -b.t. */ |
25 | /* Created July 95 to separate skill utilities from actual skills -b.t. */ |
… | |
… | |
58 | /* init_skills basically just sets up the skill_names table |
59 | /* init_skills basically just sets up the skill_names table |
59 | * above. The index into the array is set up by the |
60 | * above. The index into the array is set up by the |
60 | * subtypes. |
61 | * subtypes. |
61 | */ |
62 | */ |
62 | void |
63 | void |
63 | init_skills (void) |
64 | init_skills () |
64 | { |
65 | { |
65 | for_all_archetypes (at) |
66 | for_all_archetypes (at) |
66 | if (at->type == SKILL) |
67 | if (at->type == SKILL) |
67 | { |
68 | { |
68 | if (skill_names[at->subtype]) |
69 | if (skill_names[at->subtype]) |
… | |
… | |
167 | |
168 | |
168 | if (!skill) |
169 | if (!skill) |
169 | skill = give_skill_by_name (who, skill_tool->skill); |
170 | skill = give_skill_by_name (who, skill_tool->skill); |
170 | |
171 | |
171 | if (!skill_tool->flag [FLAG_APPLIED]) |
172 | if (!skill_tool->flag [FLAG_APPLIED]) |
172 | if (apply_special (who, splay (skill_tool), AP_APPLY | AP_NO_READY)) |
173 | if (!who->apply (splay (skill_tool))) |
173 | return 0; |
174 | return 0; |
174 | |
175 | |
175 | return splay (skill); |
176 | return splay (skill); |
176 | } |
177 | } |
177 | |
178 | |
178 | object * |
179 | object * |
179 | find_skill_by_name_fuzzy (object *who, const char *name) |
180 | find_skill_by_name_fuzzy (object *who, const char *name) |
180 | { |
181 | { |
181 | if (!name) |
182 | if (name) |
182 | return 0; |
|
|
183 | |
|
|
184 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
183 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
185 | if ((tmp->type == SKILL || tmp->type == SKILL_TOOL) |
184 | if ((tmp->type == SKILL || tmp->type == SKILL_TOOL) |
186 | && tmp->skill.starts_with (name)) |
185 | && tmp->skill.starts_with (name)) |
187 | if (object *skop = find_skill_by_name (who, tmp->skill)) |
186 | if (object *skop = find_skill_by_name (who, tmp->skill)) |
188 | return skop; |
187 | return skop; |
189 | |
188 | |
190 | return 0; |
189 | return 0; |
191 | } |
190 | } |
192 | |
191 | |
193 | /* This returns the skill pointer of the given name (the |
192 | /* This returns the skill pointer of the given name (the |
… | |
… | |
461 | case SK_EVOCATION: |
460 | case SK_EVOCATION: |
462 | case SK_PYROMANCY: |
461 | case SK_PYROMANCY: |
463 | case SK_SUMMONING: |
462 | case SK_SUMMONING: |
464 | case SK_CLIMBING: |
463 | case SK_CLIMBING: |
465 | new_draw_info (NDI_UNIQUE, 0, op, "This skill is already in effect."); |
464 | new_draw_info (NDI_UNIQUE, 0, op, "This skill is already in effect."); |
|
|
465 | break; |
|
|
466 | |
|
|
467 | case SK_MINING: |
|
|
468 | success = skill_mining (op, part, skill, dir, string); |
|
|
469 | break; |
|
|
470 | |
|
|
471 | case SK_FISHING: |
|
|
472 | success = skill_fishing (op, part, skill, dir, string); |
466 | break; |
473 | break; |
467 | |
474 | |
468 | default: |
475 | default: |
469 | LOG (llevDebug, "%s attempted to use unknown skill: %d\n", query_name (op), op->chosen_skill->stats.sp); |
476 | LOG (llevDebug, "%s attempted to use unknown skill: %d\n", query_name (op), op->chosen_skill->stats.sp); |
470 | break; |
477 | break; |
… | |
… | |
715 | * it so it doesn't crash the server - otherwise, one character may |
722 | * it so it doesn't crash the server - otherwise, one character may |
716 | * crash the server numerous times. |
723 | * crash the server numerous times. |
717 | */ |
724 | */ |
718 | if (num_skills_found >= NUM_SKILLS) |
725 | if (num_skills_found >= NUM_SKILLS) |
719 | { |
726 | { |
720 | new_draw_info (NDI_RED, 0, op, "Your character has too many skills."); |
727 | new_draw_info (NDI_RED | NDI_REPLY, 0, op, "Your character has too many skills."); |
721 | new_draw_info (NDI_RED, 0, op, "Something isn't right - contact the server admin"); |
728 | new_draw_info (NDI_RED | NDI_REPLY, 0, op, "Something isn't right - contact the server admin"); |
722 | break; |
729 | break; |
723 | } |
730 | } |
724 | } |
731 | } |
725 | } |
732 | } |
726 | |
733 | |
… | |
… | |
759 | |
766 | |
760 | if (!string) |
767 | if (!string) |
761 | return 0; |
768 | return 0; |
762 | |
769 | |
763 | for (skop = op->inv; skop; skop = skop->below) |
770 | for (skop = op->inv; skop; skop = skop->below) |
764 | { |
771 | if ((skop->type == SKILL || skop->type == SKILL_TOOL) |
765 | if (skop->type == SKILL |
|
|
766 | && QUERY_FLAG (skop, FLAG_CAN_USE_SKILL) |
|
|
767 | && !strncasecmp (string, skop->skill, MIN (strlen (string), (size_t) strlen (skop->skill)))) |
772 | && !strncmp (string, skop->skill, min (strlen (string), strlen (skop->skill)))) |
|
|
773 | { |
|
|
774 | skop = find_skill_by_name (op, skop->skill); |
768 | break; |
775 | break; |
769 | else if (skop->type == SKILL_TOOL |
|
|
770 | && !strncasecmp (string, skop->skill, MIN (strlen (string), (size_t) strlen (skop->skill)))) |
|
|
771 | break; |
|
|
772 | } |
776 | } |
773 | |
777 | |
774 | if (!skop) |
778 | if (!skop) |
775 | { |
779 | { |
776 | new_draw_info_format (NDI_UNIQUE, 0, op, "Unable to find skill %s", string); |
780 | op->failmsg (format ("Unable to find skill %s.", string)); |
|
|
781 | return 0; |
|
|
782 | } |
|
|
783 | |
|
|
784 | if (!(skill_flags [skop->subtype] & SF_USE)) |
|
|
785 | { |
|
|
786 | op->failmsg (format ( |
|
|
787 | "You feel as if you wanted to do something funny, but you can't remember what. " |
|
|
788 | "H<The %s skill cannot be C<use_skill>'ed - maybe you need to C<ready_skill> it, " |
|
|
789 | "use it with some item, or it's always active.>", |
|
|
790 | &skop->skill |
|
|
791 | )); |
777 | return 0; |
792 | return 0; |
778 | } |
793 | } |
779 | |
794 | |
780 | len = strlen (skop->skill); |
795 | len = strlen (skop->skill); |
781 | |
796 | |
… | |
… | |
807 | } |
822 | } |
808 | |
823 | |
809 | static bool |
824 | static bool |
810 | hth_skill_p (object *skill) |
825 | hth_skill_p (object *skill) |
811 | { |
826 | { |
812 | return (skill_flags [skill->subtype] & (SF_COMBAT | SF_NEED_WEAPON)) == SF_COMBAT; |
827 | return (skill_flags [skill->subtype] & (SF_COMBAT | SF_NEED_ITEM)) == SF_COMBAT; |
813 | } |
828 | } |
814 | |
829 | |
815 | /* This finds the first unarmed skill the player has, and returns it. |
830 | /* This finds the first unarmed skill the player has, and returns it. |
816 | */ |
831 | */ |
817 | static object * |
832 | static object * |
… | |
… | |
846 | * through that code if skill is set to change to the skill. |
861 | * through that code if skill is set to change to the skill. |
847 | */ |
862 | */ |
848 | if (player *pl = op->contr) |
863 | if (player *pl = op->contr) |
849 | { |
864 | { |
850 | if (skill) |
865 | if (skill) |
851 | op->change_skill (skill); |
866 | { |
|
|
867 | if (!op->apply (skill)) |
|
|
868 | return 0; |
|
|
869 | } |
852 | else |
870 | else |
853 | { |
871 | { |
854 | if (!pl->combat_ob) |
872 | if (!pl->combat_ob) |
855 | { |
873 | { |
856 | if (QUERY_FLAG (op, FLAG_READY_WEAPON)) |
874 | if (QUERY_FLAG (op, FLAG_READY_WEAPON)) |
… | |
… | |
878 | |
896 | |
879 | if (!skill) |
897 | if (!skill) |
880 | new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); |
898 | new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); |
881 | } |
899 | } |
882 | |
900 | |
883 | if (skill) |
901 | op->apply (skill); |
884 | { |
|
|
885 | op->change_skill (0); |
|
|
886 | apply_special (op, skill, AP_APPLY); |
|
|
887 | } |
|
|
888 | } |
902 | } |
889 | |
903 | |
890 | if (!pl->combat_ob) |
904 | if (!pl->combat_ob) |
891 | { |
905 | { |
892 | LOG (llevError, "Could not find anything to attack on %s\n", &op->name); |
906 | LOG (llevError, "Could not find anything to attack on %s\n", &op->name); |
893 | return 0; |
907 | return 0; |
894 | } |
908 | } |
895 | } |
909 | } |
896 | |
910 | |
897 | if (!op->change_weapon (pl->combat_ob)) |
911 | if (!op->apply (pl->combat_ob)) |
898 | return 0; |
912 | return 0; |
899 | } |
913 | } |
900 | |
914 | |
901 | /* lose invisiblity/hiding status for running attacks */ |
915 | /* lose invisiblity/hiding status for running attacks */ |
902 | if (pl->tmp_invis) |
916 | if (pl->tmp_invis) |