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.84 by root, Fri Apr 2 03:41:25 2010 UTC vs.
Revision 1.94 by root, Sun Apr 11 00:34:06 2010 UTC

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)) 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
179object * 179object *
180find_skill_by_name_fuzzy (object *who, const char *name) 180find_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
211 return skop; 209 return skop;
212 210
213 return 0; 211 return 0;
214} 212}
215 213
216/* This changes the objects chosen_skill to new_skill.
217 * return 1 on success, 0 on error
218 */
219bool
220object::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}
251
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
255 * to utilize skills. Returns 1 on use of skill, otherwise 0. 217 * to utilize skills. Returns 1 on use of skill, otherwise 0.
256 * 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
295 /* Not 100% sure if this will work with new movement code - 257 /* Not 100% sure if this will work with new movement code -
296 * the levitation skill has move_type for flying, so when 258 * the levitation skill has move_type for flying, so when
297 * equipped, that should transfer to player, when not, 259 * equipped, that should transfer to player, when not,
298 * shouldn't. 260 * shouldn't.
299 */ 261 */
300 if (QUERY_FLAG (skill, FLAG_APPLIED)) 262 if (skill->flag [FLAG_APPLIED])
301 { 263 {
302 CLEAR_FLAG (skill, FLAG_APPLIED); 264 skill->clr_flag (FLAG_APPLIED);
303 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth."); 265 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth.");
304 } 266 }
305 else 267 else
306 { 268 {
307 SET_FLAG (skill, FLAG_APPLIED); 269 skill->set_flag (FLAG_APPLIED);
308 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!");
309 } 271 }
310 272
311 op->update_stats (); 273 op->update_stats ();
312 success = 1; 274 success = 1;
402 364
403 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)
404 { 366 {
405 next = tmp->above; 367 next = tmp->above;
406 368
407 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 369 if (tmp->flag [FLAG_IS_CAULDRON])
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
421 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 383 if (tmp->flag [FLAG_APPLIED])
422 esrv_send_inventory (op, tmp); 384 esrv_send_inventory (op, tmp);
423 } 385 }
424 } 386 }
425 387
426 if (!found_cauldron) 388 if (!found_cauldron)
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;
547 } 517 }
548 else 518 else
549 { /* all other items/living creatures */ 519 { /* all other items/living creatures */
550 op_exp = op->stats.exp; 520 op_exp = op->stats.exp;
551 op_lvl = op->level; 521 op_lvl = op->level;
552 if (!QUERY_FLAG (op, FLAG_ALIVE)) 522 if (!op->flag [FLAG_ALIVE])
553 op_lvl += 5 * abs (op->magic); /* for ident/make items */ 523 op_lvl += 5 * abs (op->magic); /* for ident/make items */
554 } 524 }
555 525
556 if (op_lvl < 1) 526 if (op_lvl < 1)
557 op_lvl = 1; 527 op_lvl = 1;
621 } 591 }
622 592
623 object *tmp = find_skill (pl, scroll->skill); 593 object *tmp = find_skill (pl, scroll->skill);
624 594
625 /* player already knows it */ 595 /* player already knows it */
626 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) 596 if (tmp && tmp->flag [FLAG_CAN_USE_SKILL])
627 return 0; 597 return 0;
628 598
629 /* now a random change to learn, based on player Int. 599 /* now a random change to learn, based on player Int.
630 * give bonus based on level - otherwise stupid characters 600 * give bonus based on level - otherwise stupid characters
631 * might never be able to learn anything. 601 * might never be able to learn anything.
640 { 610 {
641 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);
642 return 2; 612 return 2;
643 } 613 }
644 614
645 SET_FLAG (tmp, FLAG_CAN_USE_SKILL); 615 tmp->set_flag (FLAG_CAN_USE_SKILL);
646 616
647 return 1; 617 return 1;
648} 618}
649 619
650/* Gives a percentage clipped to 0% -> 100% of a/b. */ 620/* Gives a percentage clipped to 0% -> 100% of a/b. */
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
817 */ 795 */
818static object * 796static object *
819find_player_hth_skill (object *op) 797find_player_hth_skill (object *op)
820{ 798{
821 for (object *tmp = op->inv; tmp; tmp = tmp->below) 799 for (object *tmp = op->inv; tmp; tmp = tmp->below)
822 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))
823 return tmp; 801 return tmp;
824 802
825 return 0; 803 return 0;
826} 804}
827 805
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 (op->flag [FLAG_READY_WEAPON])
858 { 839 {
859 for (tmp = op->inv; tmp; tmp = tmp->below) 840 for (tmp = op->inv; tmp; tmp = tmp->below)
860 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED)) 841 if (tmp->type == WEAPON && tmp->flag [FLAG_APPLIED])
861 break; 842 break;
862 843
863 if (!tmp) 844 if (!tmp)
864 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);
865 846
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);
911 888
912 int success = attack_ob (tmp, op); 889 int success = attack_ob (tmp, op);
913 890
914 /* print appropriate messages to the player */ 891 /* print appropriate messages to the player */
915 892
916 if (success && string && tmp && !QUERY_FLAG (tmp, FLAG_FREED)) 893 if (success && string && tmp && !tmp->flag [FLAG_FREED])
917 { 894 {
918 if (op->type == PLAYER) 895 if (op->type == PLAYER)
919 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));
920 else if (tmp->type == PLAYER) 897 else if (tmp->type == PLAYER)
921 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);
964 /* 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 */
965 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)))
966 return 0; 943 return 0;
967 944
968 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)
969 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)
970 { 947 {
971 /* Don't attack party members */ 948 /* Don't attack party members */
972 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))
973 return 0; 950 return 0;
974 951
996static int 973static int
997attack_hth (object *pl, int dir, const char *string, object *skill) 974attack_hth (object *pl, int dir, const char *string, object *skill)
998{ 975{
999 object *enemy = NULL, *weapon; 976 object *enemy = NULL, *weapon;
1000 977
1001 if (QUERY_FLAG (pl, FLAG_READY_WEAPON)) 978 if (pl->flag [FLAG_READY_WEAPON])
1002 for (weapon = pl->inv; weapon; weapon = weapon->below) 979 for (weapon = pl->inv; weapon; weapon = weapon->below)
1003 { 980 {
1004 if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED)) 981 if (weapon->type == WEAPON && weapon->flag [FLAG_APPLIED])
1005 { 982 {
1006 CLEAR_FLAG (weapon, FLAG_APPLIED); 983 weapon->clr_flag (FLAG_APPLIED);
1007 CLEAR_FLAG (pl, FLAG_READY_WEAPON); 984 pl->clr_flag (FLAG_READY_WEAPON);
1008 pl->update_stats (); 985 pl->update_stats ();
1009 if (pl->type == PLAYER) 986 if (pl->type == PLAYER)
1010 { 987 {
1011 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.");
1012 esrv_update_item (UPD_FLAGS, pl, weapon); 989 esrv_update_item (UPD_FLAGS, pl, weapon);
1030 */ 1007 */
1031static int 1008static int
1032attack_melee_weapon (object *op, int dir, const char *string, object *skill) 1009attack_melee_weapon (object *op, int dir, const char *string, object *skill)
1033{ 1010{
1034 1011
1035 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 1012 if (!op->flag [FLAG_READY_WEAPON])
1036 { 1013 {
1037 if (op->type == PLAYER) 1014 if (op->type == PLAYER)
1038 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!");
1039 1016
1040 return 0; 1017 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines