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.73 by root, Thu Jan 1 19:42:43 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 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
210 return skop; 209 return skop;
211 210
212 return 0; 211 return 0;
213} 212}
214 213
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}
250
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
254 * to utilize skills. Returns 1 on use of skill, otherwise 0. 217 * to utilize skills. Returns 1 on use of skill, otherwise 0.
255 * This is changed (2002-11-30) from the old method that returned 218 * This is changed (2002-11-30) from the old method that returned
260 */ 223 */
261int 224int
262do_skill (object *op, object *part, object *skill, int dir, const char *string) 225do_skill (object *op, object *part, object *skill, int dir, const char *string)
263{ 226{
264 int success = 0, exp = 0; 227 int success = 0, exp = 0;
265 int did_alc = 0;
266 228
267 if (!skill) 229 if (!skill)
268 return 0; 230 return 0;
269 231
270 /* The code below presumes that the skill points to the object that 232 /* The code below presumes that the skill points to the object that
395 case SK_LITERACY: 357 case SK_LITERACY:
396 case SK_WOODSMAN: 358 case SK_WOODSMAN:
397 /* first, we try to find a cauldron, and do the alchemy thing. 359 /* first, we try to find a cauldron, and do the alchemy thing.
398 * failing that, we go and identify stuff. 360 * failing that, we go and identify stuff.
399 */ 361 */
362 {
363 bool found_cauldron = false;
364
400 for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next) 365 for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next)
401 { 366 {
402 next = tmp->above; 367 next = tmp->above;
403 368
404 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 369 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON))
405 { 370 {
371 found_cauldron = true;
372
373 if (tmp->skill != skill->skill)
374 {
375 op->failmsgf ("You can't use the %s with the %s skill!",
376 query_name (tmp),
377 query_name (skill));
378 break;
379 }
380
406 attempt_do_alchemy (op, tmp); 381 attempt_do_alchemy (op, tmp, skill);
407 382
408 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 383 if (QUERY_FLAG (tmp, FLAG_APPLIED))
409 esrv_send_inventory (op, tmp); 384 esrv_send_inventory (op, tmp);
410
411 did_alc = 1;
412 } 385 }
413 } 386 }
414 387
415 if (did_alc == 0) 388 if (!found_cauldron)
416 exp = success = skill_ident (op, skill); 389 exp = success = skill_ident (op, skill);
417 390 }
418 break; 391 break;
419 392
420 case SK_DET_MAGIC: 393 case SK_DET_MAGIC:
421 case SK_DET_CURSE: 394 case SK_DET_CURSE:
422 exp = success = skill_ident (op, skill); 395 exp = success = skill_ident (op, skill);
451 case SK_EVOCATION: 424 case SK_EVOCATION:
452 case SK_PYROMANCY: 425 case SK_PYROMANCY:
453 case SK_SUMMONING: 426 case SK_SUMMONING:
454 case SK_CLIMBING: 427 case SK_CLIMBING:
455 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);
456 break; 437 break;
457 438
458 default: 439 default:
459 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);
460 break; 441 break;
705 * 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
706 * crash the server numerous times. 687 * crash the server numerous times.
707 */ 688 */
708 if (num_skills_found >= NUM_SKILLS) 689 if (num_skills_found >= NUM_SKILLS)
709 { 690 {
710 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.");
711 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");
712 break; 693 break;
713 } 694 }
714 } 695 }
715 } 696 }
716 697
717 dynbuf_text msg (4096, 1024); 698 dynbuf_text &msg = msg_dynbuf; msg.clear ();
718 699
719 msg << "T<Player skills:>\n\n"; 700 msg << "T<Player skills:>\n\n";
720 if (num_skills_found > 1) 701 if (num_skills_found > 1)
721 qsort (skills, num_skills_found, sizeof (skills [0]), (int (*)(const void *, const void *)) std::strcmp); 702 qsort (skills, num_skills_found, sizeof (skills [0]), (int (*)(const void *, const void *)) std::strcmp);
722 703
749 730
750 if (!string) 731 if (!string)
751 return 0; 732 return 0;
752 733
753 for (skop = op->inv; skop; skop = skop->below) 734 for (skop = op->inv; skop; skop = skop->below)
754 { 735 if ((skop->type == SKILL || skop->type == SKILL_TOOL)
755 if (skop->type == SKILL
756 && QUERY_FLAG (skop, FLAG_CAN_USE_SKILL)
757 && !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);
758 break; 739 break;
759 else if (skop->type == SKILL_TOOL
760 && !strncasecmp (string, skop->skill, MIN (strlen (string), (size_t) strlen (skop->skill))))
761 break;
762 } 740 }
763 741
764 if (!skop) 742 if (!skop)
765 { 743 {
766 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 );
767 return 0; 756 return 0;
768 } 757 }
769 758
770 len = strlen (skop->skill); 759 len = strlen (skop->skill);
771 760
797} 786}
798 787
799static bool 788static bool
800hth_skill_p (object *skill) 789hth_skill_p (object *skill)
801{ 790{
802 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;
803} 792}
804 793
805/* 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.
806 */ 795 */
807static object * 796static object *
836 * 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.
837 */ 826 */
838 if (player *pl = op->contr) 827 if (player *pl = op->contr)
839 { 828 {
840 if (skill) 829 if (skill)
841 op->change_skill (skill); 830 {
831 if (!op->apply (skill))
832 return 0;
833 }
842 else 834 else
843 { 835 {
844 if (!pl->combat_ob) 836 if (!pl->combat_ob)
845 { 837 {
846 if (QUERY_FLAG (op, FLAG_READY_WEAPON)) 838 if (QUERY_FLAG (op, FLAG_READY_WEAPON))
868 860
869 if (!skill) 861 if (!skill)
870 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!");
871 } 863 }
872 864
873 if (skill) 865 op->apply (skill);
874 {
875 op->change_skill (0);
876 apply_special (op, skill, AP_APPLY);
877 }
878 } 866 }
879 867
880 if (!pl->combat_ob) 868 if (!pl->combat_ob)
881 { 869 {
882 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);
883 return 0; 871 return 0;
884 } 872 }
885 } 873 }
886 874
887 if (!op->change_weapon (pl->combat_ob)) 875 if (!op->apply (pl->combat_ob))
888 return 0; 876 return 0;
889 } 877 }
890 878
891 /* lose invisiblity/hiding status for running attacks */ 879 /* lose invisiblity/hiding status for running attacks */
892 if (pl->tmp_invis) 880 if (pl->tmp_invis)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines