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.61 by root, Tue May 6 16:32:34 2008 UTC vs.
Revision 1.66 by root, Mon Sep 22 06:16:41 2008 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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 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
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
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
655 * just dumped this as we found it, this would be a bit 654 * just dumped this as we found it, this would be a bit
656 * simpler. 655 * simpler.
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 *pl, 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
668 object *op = pl->contr->ob;
669
671 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 670 for (object *tmp = op->inv; tmp; tmp = tmp->below)
672 { 671 {
673 if (tmp->type == SKILL) 672 if (tmp->type == SKILL)
674 { 673 {
675 if (search && strstr (tmp->name, search) == NULL) 674 if (search && !strstr (tmp->name, search))
676 continue; 675 continue;
676
677 char buf[30];
678
677 /* Basically want to fill this out to 40 spaces with periods */ 679 /* Basically want to fill this out to 30 spaces with periods */
678 sprintf (buf, "%s%s", &tmp->name, periods); 680 snprintf (buf, sizeof (buf), "%s%s", &tmp->name, periods);
679 buf[40] = 0;
680 681
681 if (settings.permanent_exp_ratio) 682 if (settings.permanent_exp_ratio)
682 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%" PRId64 "/%" PRId64 "/%d%%)", 683 snprintf (skills[num_skills_found++], sizeof (skills [0]), "%slvl:%3d (xp:%" PRId64 "/%" PRId64 "/%d%%)",
683 buf, tmp->level, tmp->stats.exp, 684 buf, tmp->level, tmp->stats.exp,
684 level_exp (tmp->level + 1, op->expmul), clipped_percent (tmp->perm_exp, tmp->stats.exp)); 685 level_exp (tmp->level + 1, op->expmul), clipped_percent (tmp->perm_exp, tmp->stats.exp));
685 else 686 else
686 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%" PRId64 "/%" PRId64 ")", 687 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)); 688 buf, tmp->level, tmp->stats.exp, level_exp (tmp->level + 1, op->expmul));
688 689
689 /* I don't know why some characters get a bunch of skills, but 690 /* I don't know why some characters get a bunch of skills, but
690 * it sometimes happens (maybe a leftover from bugier earlier code 691 * it sometimes happens (maybe a leftover from bugier earlier code
691 * and those character are still about). In any case, lets handle 692 * and those character are still about). In any case, lets handle
692 * it so it doesn't crash the server - otherwise, one character may 693 * it so it doesn't crash the server - otherwise, one character may
699 break; 700 break;
700 } 701 }
701 } 702 }
702 } 703 }
703 704
704 new_draw_info (NDI_UNIQUE, 0, op, "Player skills:"); 705 dynbuf_text msg (4096, 1024);
706
707 msg << "T<Player skills:>\n\n";
705 if (num_skills_found > 1) 708 if (num_skills_found > 1)
706 qsort (skills, num_skills_found, MAX_BUF, (int (*)(const void *, const void *)) std::strcmp); 709 qsort (skills, num_skills_found, sizeof (skills [0]), (int (*)(const void *, const void *)) std::strcmp);
707 710
708 for (i = 0; i < num_skills_found; i++) 711 for (i = 0; i < num_skills_found; i++)
709 new_draw_info (NDI_UNIQUE, 0, op, skills[i]); 712 msg << " C<" << skills [i] << ">\n";
710 713
711 new_draw_info_format (NDI_UNIQUE, 0, op, "You can handle %d weapon improvements.", op->level / 5 + 5); 714 msg << "\nYou can handle " << op->level / 5 + 5 << " weapon improvements.\r";
712 715
713 cp = determine_god (op); 716 cp = determine_god (op);
714 new_draw_info_format (NDI_UNIQUE, 0, op, "You worship %s.", cp ? cp : "no god at current time"); 717 msg << "You worship " << (cp ? cp : "no god at current time") << ".\r";
715 718
716 new_draw_info_format (NDI_UNIQUE, 0, op, "Your equipped item power is %d out of %d\n", 719 msg << "Your equipped item power is " << (int)op->contr->item_power
717 op->contr->item_power, (int) (op->level * settings.item_power_factor)); 720 << " out of " << int (op->level * settings.item_power_factor)
721 << ".\n";
722
723 pl->contr->infobox (MSG_CHANNEL ("skills"), msg);
718} 724}
719 725
720/* use_skill() - similar to invoke command, it executes the skill in the 726/* 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 727 * 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. 728 * 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 823 * 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. 824 * through that code if skill is set to change to the skill.
819 */ 825 */
820 if (player *pl = op->contr) 826 if (player *pl = op->contr)
821 { 827 {
822 if (!pl->combat_ob) 828 if (skill)
829 op->change_skill (skill);
830 else
823 { 831 {
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) 832 if (!pl->combat_ob)
837 { 833 {
834 if (QUERY_FLAG (op, FLAG_READY_WEAPON))
835 {
836 for (tmp = op->inv; tmp; tmp = tmp->below)
837 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED))
838 break;
839
838 if (!skill) 840 if (!tmp)
841 LOG (llevError, "Could not find applied weapon on %s\n", &op->name);
842
843 pl->combat_ob = tmp;
844 }
845
846 if (!pl->combat_ob)
839 { 847 {
840 /* See if the players chosen skill is a combat skill, and use 848 /* See if the players chosen skill is a combat skill, and use
841 * it if appropriate. 849 * it if appropriate.
842 */ 850 */
843 if (op->chosen_skill && hth_skill_p (op->chosen_skill)) 851 if (op->chosen_skill && hth_skill_p (op->chosen_skill))
847 skill = find_player_hth_skill (op); 855 skill = find_player_hth_skill (op);
848 856
849 if (!skill) 857 if (!skill)
850 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); 858 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!");
851 } 859 }
860
861 if (skill)
862 {
863 op->change_skill (0);
864 apply_special (op, skill, AP_APPLY);
865 }
852 } 866 }
853 867
854 if (skill) 868 if (!pl->combat_ob)
855 { 869 {
856 op->change_skill (0); 870 LOG (llevError, "Could not find anything to attack on %s\n", &op->name);
857 apply_special (op, skill, AP_APPLY); 871 return 0;
858 } 872 }
859 } 873 }
860 874
861 if (!pl->combat_ob) 875 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; 876 return 0;
865 }
866 } 877 }
867
868 if (!op->change_weapon (pl->combat_ob))
869 return 0;
870 878
871 /* lose invisiblity/hiding status for running attacks */ 879 /* lose invisiblity/hiding status for running attacks */
872 if (pl->tmp_invis) 880 if (pl->tmp_invis)
873 { 881 {
874 pl->tmp_invis = 0; 882 pl->tmp_invis = 0;
893 return success; 901 return success;
894} 902}
895 903
896/* skill_attack() - Core routine for use when we attack using a skills 904/* skill_attack() - Core routine for use when we attack using a skills
897 * system. In essence, this code handles 905 * system. In essence, this code handles
898 * all skill-based attacks, ie hth, missile and melee weapons should be 906 * 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(), 907 * treated here. If an opponent is already supplied by move_player(),
900 * we move right onto do_skill_attack(), otherwise we find if an 908 * we move right onto do_skill_attack(), otherwise we find if an
901 * appropriate opponent exists. 909 * appropriate opponent exists.
902 * 910 *
903 * This is called by move_player() and attack_hth() 911 * This is called by move_player() and attack_hth()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines