ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/skill_util.C
(Generate patch)

Comparing deliantra/server/server/skill_util.C (file contents):
Revision 1.76 by root, Mon Apr 27 01:38:49 2009 UTC vs.
Revision 1.93 by root, Sat Apr 10 05:12:57 2010 UTC

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 */
62void 63void
63init_skills (void) 64init_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
178object * 179object *
179find_skill_by_name_fuzzy (object *who, const char *name) 180find_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
208 if (tmp->type == SKILL && tmp->subtype == skillno) 207 if (tmp->type == SKILL && tmp->subtype == skillno)
209 if (object *skop = find_skill_by_name (who, tmp->skill)) 208 if (object *skop = find_skill_by_name (who, tmp->skill))
210 return skop; 209 return skop;
211 210
212 return 0; 211 return 0;
213}
214
215/* This changes the objects chosen_skill to new_skill.
216 * return 1 on success, 0 on error
217 */
218bool
219object::change_skill (object *new_skill)
220{
221 if (type != PLAYER)
222 return 0;
223
224 // optimise this supposedly common case
225 if (new_skill == chosen_skill)
226 return 1;
227
228 if (chosen_skill)
229 {
230 chosen_skill->flag [FLAG_APPLIED] = false;
231 change_abil (this, chosen_skill);
232 }
233
234 chosen_skill = new_skill;
235
236 if (chosen_skill)
237 {
238 chosen_skill->flag [FLAG_APPLIED] = true;
239 change_abil (this, chosen_skill);
240 }
241
242 // always clear current weapon, as the selected skill could
243 // conflict with the current weapon skill, which would go
244 // undetected and exp would be given to the wrong skill.
245 current_weapon = 0;
246
247 update_stats ();
248 return 1;
249} 212}
250 213
251/* 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().
252 * 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.
253 * 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
407 { 370 {
408 found_cauldron = true; 371 found_cauldron = true;
409 372
410 if (tmp->skill != skill->skill) 373 if (tmp->skill != skill->skill)
411 { 374 {
412 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!",
413 query_name (tmp), 376 query_name (tmp),
414 query_name (skill))); 377 query_name (skill));
415 break; 378 break;
416 } 379 }
417 380
418 attempt_do_alchemy (op, tmp, skill); 381 attempt_do_alchemy (op, tmp, skill);
419 382
461 case SK_EVOCATION: 424 case SK_EVOCATION:
462 case SK_PYROMANCY: 425 case SK_PYROMANCY:
463 case SK_SUMMONING: 426 case SK_SUMMONING:
464 case SK_CLIMBING: 427 case SK_CLIMBING:
465 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);
466 break; 437 break;
467 438
468 default: 439 default:
469 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);
470 break; 441 break;
715 * it so it doesn't crash the server - otherwise, one character may 686 * it so it doesn't crash the server - otherwise, one character may
716 * crash the server numerous times. 687 * crash the server numerous times.
717 */ 688 */
718 if (num_skills_found >= NUM_SKILLS) 689 if (num_skills_found >= NUM_SKILLS)
719 { 690 {
720 new_draw_info (NDI_RED, 0, op, "Your character has too many skills."); 691 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"); 692 new_draw_info (NDI_RED | NDI_REPLY, 0, op, "Something isn't right - contact the server admin");
722 break; 693 break;
723 } 694 }
724 } 695 }
725 } 696 }
726 697
759 730
760 if (!string) 731 if (!string)
761 return 0; 732 return 0;
762 733
763 for (skop = op->inv; skop; skop = skop->below) 734 for (skop = op->inv; skop; skop = skop->below)
764 { 735 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)))) 736 && !strncmp (string, skop->skill, min (strlen (string), strlen (skop->skill))))
737 {
738 skop = find_skill_by_name (op, skop->skill);
768 break; 739 break;
769 else if (skop->type == SKILL_TOOL
770 && !strncasecmp (string, skop->skill, MIN (strlen (string), (size_t) strlen (skop->skill))))
771 break;
772 } 740 }
773 741
774 if (!skop) 742 if (!skop)
775 { 743 {
776 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 );
777 return 0; 756 return 0;
778 } 757 }
779 758
780 len = strlen (skop->skill); 759 len = strlen (skop->skill);
781 760
807} 786}
808 787
809static bool 788static bool
810hth_skill_p (object *skill) 789hth_skill_p (object *skill)
811{ 790{
812 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;
813} 792}
814 793
815/* 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.
816 */ 795 */
817static object * 796static object *
846 * 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.
847 */ 826 */
848 if (player *pl = op->contr) 827 if (player *pl = op->contr)
849 { 828 {
850 if (skill) 829 if (skill)
851 op->change_skill (skill); 830 {
831 if (!op->apply (skill))
832 return 0;
833 }
852 else 834 else
853 { 835 {
854 if (!pl->combat_ob) 836 if (!pl->combat_ob)
855 { 837 {
856 if (QUERY_FLAG (op, FLAG_READY_WEAPON)) 838 if (QUERY_FLAG (op, FLAG_READY_WEAPON))
878 860
879 if (!skill) 861 if (!skill)
880 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!");
881 } 863 }
882 864
883 if (skill) 865 op->apply (skill);
884 {
885 op->change_skill (0);
886 apply_special (op, skill, AP_APPLY);
887 }
888 } 866 }
889 867
890 if (!pl->combat_ob) 868 if (!pl->combat_ob)
891 { 869 {
892 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);
893 return 0; 871 return 0;
894 } 872 }
895 } 873 }
896 874
897 if (!op->change_weapon (pl->combat_ob)) 875 if (!op->apply (pl->combat_ob))
898 return 0; 876 return 0;
899 } 877 }
900 878
901 /* lose invisiblity/hiding status for running attacks */ 879 /* lose invisiblity/hiding status for running attacks */
902 if (pl->tmp_invis) 880 if (pl->tmp_invis)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines