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.62 by root, Tue May 6 16:55:26 2008 UTC vs.
Revision 1.65 by root, Mon Sep 22 05:45:55 2008 UTC

311 case SK_HIDING: 311 case SK_HIDING:
312 exp = success = hide (op, skill); 312 exp = success = hide (op, skill);
313 break; 313 break;
314 314
315 case SK_JUMPING: 315 case SK_JUMPING:
316 success = jump (op, dir, skill); 316 exp = success = jump (op, dir, skill);
317 break; 317 break;
318 318
319 case SK_INSCRIPTION: 319 case SK_INSCRIPTION:
320 exp = success = write_on_item (op, string, skill); 320 exp = success = write_on_item (op, string, skill);
321 break; 321 break;
452 * Monsters have no skill use time because of the random nature in 452 * Monsters have no skill use time because of the random nature in
453 * which use_monster_skill is called already simulates this. 453 * which use_monster_skill is called already simulates this.
454 * If certain skills should take more/less time, that should be 454 * If certain skills should take more/less time, that should be
455 * in the code for the skill itself. 455 * in the code for the skill itself.
456 */ 456 */
457
458 if (op->type == PLAYER) 457 if (op->type == PLAYER)
459 op->speed_left -= 1.f; 458 op->speed_left -= 1.f;
460 459
461 /* this is a good place to add experience for successfull use of skills. 460 /* this is a good place to add experience for successfull use of skills.
462 * Note that add_exp() will figure out player/monster experience 461 * Note that add_exp() will figure out player/monster experience
657 */ 656 */
658//TODO: egad, do it in perl, do not suffer from the big buffer on stack, make it one single drawinfo. 657//TODO: egad, do it in perl, do not suffer from the big buffer on stack, make it one single drawinfo.
659void 658void
660show_skills (object *op, const char *search) 659show_skills (object *op, const char *search)
661{ 660{
662 object *tmp = NULL;
663 char buf[MAX_BUF];
664 const char *cp; 661 const char *cp;
665 int i, num_skills_found = 0; 662 int i, num_skills_found = 0;
666 static const char *const periods = "........................................"; 663 const char *const periods = ".............................."; // 30
667 664
668 /* Need to have a pointer and use strdup for qsort to work properly */ 665 /* Need to have a pointer and use strdup for qsort to work properly */
669 char skills[NUM_SKILLS][MAX_BUF]; 666 char skills[NUM_SKILLS][128]; // d'oh
670 667
671 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 668 for (object *tmp = op->inv; tmp; tmp = tmp->below)
672 { 669 {
673 if (tmp->type == SKILL) 670 if (tmp->type == SKILL)
674 { 671 {
675 if (search && strstr (tmp->name, search) == NULL) 672 if (search && !strstr (tmp->name, search))
676 continue; 673 continue;
674
675 char buf[30];
676
677 /* Basically want to fill this out to 40 spaces with periods */ 677 /* Basically want to fill this out to 30 spaces with periods */
678 sprintf (buf, "%s%s", &tmp->name, periods); 678 snprintf (buf, sizeof (buf), "%s%s", &tmp->name, periods);
679 buf[40] = 0;
680 679
681 if (settings.permanent_exp_ratio) 680 if (settings.permanent_exp_ratio)
682 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%" PRId64 "/%" PRId64 "/%d%%)", 681 snprintf (skills[num_skills_found++], sizeof (skills [0]), "%slvl:%3d (xp:%" PRId64 "/%" PRId64 "/%d%%)",
683 buf, tmp->level, tmp->stats.exp, 682 buf, tmp->level, tmp->stats.exp,
684 level_exp (tmp->level + 1, op->expmul), clipped_percent (tmp->perm_exp, tmp->stats.exp)); 683 level_exp (tmp->level + 1, op->expmul), clipped_percent (tmp->perm_exp, tmp->stats.exp));
685 else 684 else
686 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%" PRId64 "/%" PRId64 ")", 685 snprintf (skills[num_skills_found++], sizeof (skills [0]), "%slvl:%3d (xp:%" PRId64 "/%" PRId64 ")",
687 buf, tmp->level, tmp->stats.exp, level_exp (tmp->level + 1, op->expmul)); 686 buf, tmp->level, tmp->stats.exp, level_exp (tmp->level + 1, op->expmul));
688 687
689 /* I don't know why some characters get a bunch of skills, but 688 /* I don't know why some characters get a bunch of skills, but
690 * it sometimes happens (maybe a leftover from bugier earlier code 689 * it sometimes happens (maybe a leftover from bugier earlier code
691 * and those character are still about). In any case, lets handle 690 * and those character are still about). In any case, lets handle
692 * it so it doesn't crash the server - otherwise, one character may 691 * it so it doesn't crash the server - otherwise, one character may
699 break; 698 break;
700 } 699 }
701 } 700 }
702 } 701 }
703 702
704 new_draw_info (NDI_UNIQUE, 0, op, "Player skills:"); 703 dynbuf_text msg (4096, 1024);
704
705 msg << "T<Player skills:>\n\n";
705 if (num_skills_found > 1) 706 if (num_skills_found > 1)
706 qsort (skills, num_skills_found, MAX_BUF, (int (*)(const void *, const void *)) std::strcmp); 707 qsort (skills, num_skills_found, sizeof (skills [0]), (int (*)(const void *, const void *)) std::strcmp);
707 708
708 for (i = 0; i < num_skills_found; i++) 709 for (i = 0; i < num_skills_found; i++)
709 new_draw_info (NDI_UNIQUE, 0, op, skills[i]); 710 msg << " C<" << skills [i] << ">\n";
710 711
711 new_draw_info_format (NDI_UNIQUE, 0, op, "You can handle %d weapon improvements.", op->level / 5 + 5); 712 msg << "\nYou can handle " << op->level / 5 + 5 << " weapon improvements.\r";
712 713
713 cp = determine_god (op); 714 cp = determine_god (op);
714 new_draw_info_format (NDI_UNIQUE, 0, op, "You worship %s.", cp ? cp : "no god at current time"); 715 msg << "You worship " << (cp ? cp : "no god at current time") << ".\r";
715 716
716 new_draw_info_format (NDI_UNIQUE, 0, op, "Your equipped item power is %d out of %d\n", 717 msg << "Your equipped item power is " << (int)op->contr->item_power
717 op->contr->item_power, (int) (op->level * settings.item_power_factor)); 718 << " out of " << int (op->level * settings.item_power_factor)
719 << ".\n";
720
721 op->contr->infobox (MSG_CHANNEL ("skills"), msg);
718} 722}
719 723
720/* use_skill() - similar to invoke command, it executes the skill in the 724/* use_skill() - similar to invoke command, it executes the skill in the
721 * direction that the user is facing. Returns false if we are unable to 725 * direction that the user is facing. Returns false if we are unable to
722 * change to the requested skill, or were unable to use the skill properly. 726 * change to the requested skill, or were unable to use the skill properly.
817 * the caller should have set it appropriately). We still want to pass 821 * the caller should have set it appropriately). We still want to pass
818 * through that code if skill is set to change to the skill. 822 * through that code if skill is set to change to the skill.
819 */ 823 */
820 if (player *pl = op->contr) 824 if (player *pl = op->contr)
821 { 825 {
822 if (!pl->combat_ob) 826 if (skill)
827 op->change_skill (skill);
828 else
823 { 829 {
824 if (QUERY_FLAG (op, FLAG_READY_WEAPON))
825 {
826 for (tmp = op->inv; tmp; tmp = tmp->below)
827 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED))
828 break;
829
830 if (!tmp)
831 LOG (llevError, "Could not find applied weapon on %s\n", &op->name);
832
833 pl->combat_ob = tmp;
834 }
835
836 if (!pl->combat_ob) 830 if (!pl->combat_ob)
837 { 831 {
832 if (QUERY_FLAG (op, FLAG_READY_WEAPON))
833 {
834 for (tmp = op->inv; tmp; tmp = tmp->below)
835 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED))
836 break;
837
838 if (!skill) 838 if (!tmp)
839 LOG (llevError, "Could not find applied weapon on %s\n", &op->name);
840
841 pl->combat_ob = tmp;
842 }
843
844 if (!pl->combat_ob)
839 { 845 {
840 /* See if the players chosen skill is a combat skill, and use 846 /* See if the players chosen skill is a combat skill, and use
841 * it if appropriate. 847 * it if appropriate.
842 */ 848 */
843 if (op->chosen_skill && hth_skill_p (op->chosen_skill)) 849 if (op->chosen_skill && hth_skill_p (op->chosen_skill))
847 skill = find_player_hth_skill (op); 853 skill = find_player_hth_skill (op);
848 854
849 if (!skill) 855 if (!skill)
850 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); 856 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!");
851 } 857 }
858
859 if (skill)
860 {
861 op->change_skill (0);
862 apply_special (op, skill, AP_APPLY);
863 }
852 } 864 }
853 865
854 if (skill) 866 if (!pl->combat_ob)
855 { 867 {
856 op->change_skill (0); 868 LOG (llevError, "Could not find anything to attack on %s\n", &op->name);
857 apply_special (op, skill, AP_APPLY); 869 return 0;
858 } 870 }
859 } 871 }
860 872
861 if (!pl->combat_ob) 873 if (!op->change_weapon (pl->combat_ob))
862 {
863 LOG (llevError, "Could not find anything to attack on %s\n", &op->name);
864 return 0; 874 return 0;
865 }
866 } 875 }
867
868 if (!op->change_weapon (pl->combat_ob))
869 return 0;
870 876
871 /* lose invisiblity/hiding status for running attacks */ 877 /* lose invisiblity/hiding status for running attacks */
872 if (pl->tmp_invis) 878 if (pl->tmp_invis)
873 { 879 {
874 pl->tmp_invis = 0; 880 pl->tmp_invis = 0;
893 return success; 899 return success;
894} 900}
895 901
896/* skill_attack() - Core routine for use when we attack using a skills 902/* skill_attack() - Core routine for use when we attack using a skills
897 * system. In essence, this code handles 903 * system. In essence, this code handles
898 * all skill-based attacks, ie hth, missile and melee weapons should be 904 * all skill-based attacks, i.e. hth, missile and melee weapons should be
899 * treated here. If an opponent is already supplied by move_player(), 905 * treated here. If an opponent is already supplied by move_player(),
900 * we move right onto do_skill_attack(), otherwise we find if an 906 * we move right onto do_skill_attack(), otherwise we find if an
901 * appropriate opponent exists. 907 * appropriate opponent exists.
902 * 908 *
903 * This is called by move_player() and attack_hth() 909 * This is called by move_player() and attack_hth()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines