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.77 by root, Sat Oct 3 22:38:17 2009 UTC vs.
Revision 1.94 by root, Sun Apr 11 00:34:06 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
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
294 /* Not 100% sure if this will work with new movement code - 257 /* Not 100% sure if this will work with new movement code -
295 * the levitation skill has move_type for flying, so when 258 * the levitation skill has move_type for flying, so when
296 * equipped, that should transfer to player, when not, 259 * equipped, that should transfer to player, when not,
297 * shouldn't. 260 * shouldn't.
298 */ 261 */
299 if (QUERY_FLAG (skill, FLAG_APPLIED)) 262 if (skill->flag [FLAG_APPLIED])
300 { 263 {
301 CLEAR_FLAG (skill, FLAG_APPLIED); 264 skill->clr_flag (FLAG_APPLIED);
302 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth."); 265 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth.");
303 } 266 }
304 else 267 else
305 { 268 {
306 SET_FLAG (skill, FLAG_APPLIED); 269 skill->set_flag (FLAG_APPLIED);
307 new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!"); 270 new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!");
308 } 271 }
309 272
310 op->update_stats (); 273 op->update_stats ();
311 success = 1; 274 success = 1;
401 364
402 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)
403 { 366 {
404 next = tmp->above; 367 next = tmp->above;
405 368
406 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 369 if (tmp->flag [FLAG_IS_CAULDRON])
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
420 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 383 if (tmp->flag [FLAG_APPLIED])
421 esrv_send_inventory (op, tmp); 384 esrv_send_inventory (op, tmp);
422 } 385 }
423 } 386 }
424 387
425 if (!found_cauldron) 388 if (!found_cauldron)
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;
546 } 517 }
547 else 518 else
548 { /* all other items/living creatures */ 519 { /* all other items/living creatures */
549 op_exp = op->stats.exp; 520 op_exp = op->stats.exp;
550 op_lvl = op->level; 521 op_lvl = op->level;
551 if (!QUERY_FLAG (op, FLAG_ALIVE)) 522 if (!op->flag [FLAG_ALIVE])
552 op_lvl += 5 * abs (op->magic); /* for ident/make items */ 523 op_lvl += 5 * abs (op->magic); /* for ident/make items */
553 } 524 }
554 525
555 if (op_lvl < 1) 526 if (op_lvl < 1)
556 op_lvl = 1; 527 op_lvl = 1;
620 } 591 }
621 592
622 object *tmp = find_skill (pl, scroll->skill); 593 object *tmp = find_skill (pl, scroll->skill);
623 594
624 /* player already knows it */ 595 /* player already knows it */
625 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) 596 if (tmp && tmp->flag [FLAG_CAN_USE_SKILL])
626 return 0; 597 return 0;
627 598
628 /* now a random change to learn, based on player Int. 599 /* now a random change to learn, based on player Int.
629 * give bonus based on level - otherwise stupid characters 600 * give bonus based on level - otherwise stupid characters
630 * might never be able to learn anything. 601 * might never be able to learn anything.
639 { 610 {
640 LOG (llevError, "skill scroll %s does not have valid skill name (%s).\n", &scroll->name, &scroll->skill); 611 LOG (llevError, "skill scroll %s does not have valid skill name (%s).\n", &scroll->name, &scroll->skill);
641 return 2; 612 return 2;
642 } 613 }
643 614
644 SET_FLAG (tmp, FLAG_CAN_USE_SKILL); 615 tmp->set_flag (FLAG_CAN_USE_SKILL);
645 616
646 return 1; 617 return 1;
647} 618}
648 619
649/* Gives a percentage clipped to 0% -> 100% of a/b. */ 620/* Gives a percentage clipped to 0% -> 100% of a/b. */
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 *
818find_player_hth_skill (object *op) 797find_player_hth_skill (object *op)
819{ 798{
820 for (object *tmp = op->inv; tmp; tmp = tmp->below) 799 for (object *tmp = op->inv; tmp; tmp = tmp->below)
821 if (tmp->type == SKILL && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL) && hth_skill_p (tmp)) 800 if (tmp->type == SKILL && tmp->flag [FLAG_CAN_USE_SKILL] && hth_skill_p (tmp))
822 return tmp; 801 return tmp;
823 802
824 return 0; 803 return 0;
825} 804}
826 805
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 (op->flag [FLAG_READY_WEAPON])
857 { 839 {
858 for (tmp = op->inv; tmp; tmp = tmp->below) 840 for (tmp = op->inv; tmp; tmp = tmp->below)
859 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED)) 841 if (tmp->type == WEAPON && tmp->flag [FLAG_APPLIED])
860 break; 842 break;
861 843
862 if (!tmp) 844 if (!tmp)
863 LOG (llevError, "Could not find applied weapon on %s\n", &op->name); 845 LOG (llevError, "Could not find applied weapon on %s\n", &op->name);
864 846
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)
910 888
911 int success = attack_ob (tmp, op); 889 int success = attack_ob (tmp, op);
912 890
913 /* print appropriate messages to the player */ 891 /* print appropriate messages to the player */
914 892
915 if (success && string && tmp && !QUERY_FLAG (tmp, FLAG_FREED)) 893 if (success && string && tmp && !tmp->flag [FLAG_FREED])
916 { 894 {
917 if (op->type == PLAYER) 895 if (op->type == PLAYER)
918 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp)); 896 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp));
919 else if (tmp->type == PLAYER) 897 else if (tmp->type == PLAYER)
920 new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string); 898 new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string);
963 /* space must be blocked for there to be anything interesting to do */ 941 /* space must be blocked for there to be anything interesting to do */
964 if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty))) 942 if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty)))
965 return 0; 943 return 0;
966 944
967 for (tmp = GET_MAP_OB (m, tx, ty); tmp; tmp = tmp->above) 945 for (tmp = GET_MAP_OB (m, tx, ty); tmp; tmp = tmp->above)
968 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR) 946 if ((tmp->flag [FLAG_ALIVE] && tmp->stats.hp >= 0) || tmp->flag [FLAG_CAN_ROLL] || tmp->type == LOCKED_DOOR)
969 { 947 {
970 /* Don't attack party members */ 948 /* Don't attack party members */
971 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) 949 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party))
972 return 0; 950 return 0;
973 951
995static int 973static int
996attack_hth (object *pl, int dir, const char *string, object *skill) 974attack_hth (object *pl, int dir, const char *string, object *skill)
997{ 975{
998 object *enemy = NULL, *weapon; 976 object *enemy = NULL, *weapon;
999 977
1000 if (QUERY_FLAG (pl, FLAG_READY_WEAPON)) 978 if (pl->flag [FLAG_READY_WEAPON])
1001 for (weapon = pl->inv; weapon; weapon = weapon->below) 979 for (weapon = pl->inv; weapon; weapon = weapon->below)
1002 { 980 {
1003 if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED)) 981 if (weapon->type == WEAPON && weapon->flag [FLAG_APPLIED])
1004 { 982 {
1005 CLEAR_FLAG (weapon, FLAG_APPLIED); 983 weapon->clr_flag (FLAG_APPLIED);
1006 CLEAR_FLAG (pl, FLAG_READY_WEAPON); 984 pl->clr_flag (FLAG_READY_WEAPON);
1007 pl->update_stats (); 985 pl->update_stats ();
1008 if (pl->type == PLAYER) 986 if (pl->type == PLAYER)
1009 { 987 {
1010 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); 988 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack.");
1011 esrv_update_item (UPD_FLAGS, pl, weapon); 989 esrv_update_item (UPD_FLAGS, pl, weapon);
1029 */ 1007 */
1030static int 1008static int
1031attack_melee_weapon (object *op, int dir, const char *string, object *skill) 1009attack_melee_weapon (object *op, int dir, const char *string, object *skill)
1032{ 1010{
1033 1011
1034 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 1012 if (!op->flag [FLAG_READY_WEAPON])
1035 { 1013 {
1036 if (op->type == PLAYER) 1014 if (op->type == PLAYER)
1037 new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!"); 1015 new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!");
1038 1016
1039 return 0; 1017 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines