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,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * 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 Affero GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * 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> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | /* 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. */ |
26 | |
26 | |
… | |
… | |
69 | } |
69 | } |
70 | |
70 | |
71 | void |
71 | void |
72 | add_skill_archetype (object *o) |
72 | add_skill_archetype (object *o) |
73 | { |
73 | { |
74 | printf ("<%s><%s>\n", &o->name, &o->skill);//D |
|
|
75 | |
|
|
76 | assert (("skill name must equal skill skill", o->name == o->skill)); |
74 | assert (("skill name must equal skill skill", o->name == o->skill)); |
77 | |
75 | |
78 | for (vector<object_ptr>::iterator i = skillvec.begin (); i != skillvec.end (); ++i) |
76 | for (vector<object_ptr>::iterator i = skillvec.begin (); i != skillvec.end (); ++i) |
79 | if ((*i)->name == o->name) |
77 | if ((*i)->name == o->name) |
80 | { |
78 | { |
… | |
… | |
197 | * one that accumulates exp, has the level, etc). |
195 | * one that accumulates exp, has the level, etc). |
198 | * |
196 | * |
199 | * It is presumed that the player will be needing to actually |
197 | * It is presumed that the player will be needing to actually |
200 | * use the skill, so thus if use of the skill requires a skill |
198 | * use the skill, so thus if use of the skill requires a skill |
201 | * tool, this code will equip it. |
199 | * tool, this code will equip it. |
202 | * |
200 | * |
203 | * This code is basically the same as find_skill_by_name() above, |
201 | * This code is basically the same as find_skill_by_name() above, |
204 | * but instead a skill name, we search by matching number. |
202 | * but instead a skill name, we search by matching number. |
205 | * this replaces find_skill. |
203 | * this replaces find_skill. |
206 | * |
204 | * |
207 | * MUST NOT BE USED IN NEW CODE! (schmorp) |
205 | * MUST NOT BE USED IN NEW CODE! (schmorp) |
… | |
… | |
651 | return 100; |
649 | return 100; |
652 | |
650 | |
653 | return rv; |
651 | return rv; |
654 | } |
652 | } |
655 | |
653 | |
|
|
654 | static int |
|
|
655 | cmp_skillp (const void *sk1, const void *sk2) |
|
|
656 | { |
|
|
657 | return strcmp (&((*(const object **) sk1)->name), |
|
|
658 | &((*(const object **) sk2)->name)); |
|
|
659 | } |
|
|
660 | |
656 | /* show_skills() - Meant to allow players to examine |
661 | /* show_skills() - Meant to allow players to examine |
657 | * their current skill list. |
662 | * their current skill list. |
658 | * This shows the amount of exp they have in the skills. |
663 | * This shows the amount of exp they have in the skills. |
659 | * we also include some other non skill related info (god, |
664 | * we also include some other non skill related info (god, |
660 | * max weapon improvments, item power). |
665 | * max weapon improvments, item power). |
661 | * Note this function is a bit more complicated becauase we |
666 | * Note this function is a bit more complicated because we |
662 | * we want ot sort the skills before printing them. If we |
667 | * we want to sort the skills before printing them. If we |
663 | * just dumped this as we found it, this would be a bit |
668 | * just dumped this as we found it, this would be a bit |
664 | * simpler. |
669 | * simpler. |
665 | */ |
670 | */ |
666 | //TODO: egad, do it in perl, do not suffer from the big buffer on stack, make it one single drawinfo. |
|
|
667 | void |
671 | void |
668 | show_skills (object *pl, const char *search) |
672 | show_skills (object *pl, const char *search) |
669 | { |
673 | { |
670 | const char *cp; |
674 | const char *cp; |
671 | int i, num_skills_found = 0; |
675 | int i, num_skills_found = 0; |
672 | const char *const periods = ".............................."; // 30 |
676 | object *skills[CS_NUM_SKILLS]; |
673 | |
|
|
674 | /* Need to have a pointer and use strdup for qsort to work properly */ |
|
|
675 | char skills[NUM_SKILLS][128]; // d'oh |
|
|
676 | |
|
|
677 | object *op = pl->contr->ob; |
677 | object *op = pl->contr->ob; |
678 | |
678 | |
|
|
679 | /* find the skills */ |
679 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
680 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
680 | { |
681 | { |
681 | if (tmp->type == SKILL) |
682 | if (tmp->type == SKILL) |
682 | { |
683 | { |
683 | if (search && !tmp->name.contains (search)) |
684 | if (search && !tmp->name.contains (search)) |
684 | continue; |
685 | continue; |
685 | |
686 | |
686 | char buf[30]; |
687 | skills[num_skills_found++] = tmp; |
687 | |
|
|
688 | /* Basically want to fill this out to 30 spaces with periods */ |
|
|
689 | snprintf (buf, sizeof (buf), "%s%s", &tmp->name, periods); |
|
|
690 | |
|
|
691 | if (settings.permanent_exp_ratio) |
|
|
692 | snprintf (skills[num_skills_found++], sizeof (skills [0]), "%slvl:%3d (xp:%" PRId64 "/%" PRId64 "/%d%%)", |
|
|
693 | buf, tmp->level, tmp->stats.exp, |
|
|
694 | level_exp (tmp->level + 1, op->expmul), clipped_percent (tmp->perm_exp, tmp->stats.exp)); |
|
|
695 | else |
|
|
696 | snprintf (skills[num_skills_found++], sizeof (skills [0]), "%slvl:%3d (xp:%" PRId64 "/%" PRId64 ")", |
|
|
697 | buf, tmp->level, tmp->stats.exp, level_exp (tmp->level + 1, op->expmul)); |
|
|
698 | |
688 | |
699 | /* I don't know why some characters get a bunch of skills, but |
689 | /* I don't know why some characters get a bunch of skills, but |
700 | * it sometimes happens (maybe a leftover from bugier earlier code |
690 | * it sometimes happens (maybe a leftover from bugier earlier code |
701 | * and those character are still about). In any case, lets handle |
691 | * and those character are still about). In any case, lets handle |
702 | * it so it doesn't crash the server - otherwise, one character may |
692 | * it so it doesn't crash the server - otherwise, one character may |
703 | * crash the server numerous times. |
693 | * crash the server numerous times. |
704 | */ |
694 | */ |
705 | if (num_skills_found >= NUM_SKILLS) |
695 | if (num_skills_found >= CS_NUM_SKILLS) |
706 | { |
696 | { |
707 | new_draw_info (NDI_RED | NDI_REPLY, 0, op, "Your character has too many skills."); |
697 | new_draw_info (NDI_RED | NDI_REPLY, 0, op, "Your character has too many skills."); |
708 | new_draw_info (NDI_RED | NDI_REPLY, 0, op, "Something isn't right - contact the server admin"); |
698 | new_draw_info (NDI_RED | NDI_REPLY, 0, op, "Something isn't right - contact the server admin"); |
709 | break; |
699 | break; |
710 | } |
700 | } |
… | |
… | |
713 | |
703 | |
714 | dynbuf_text &msg = msg_dynbuf; msg.clear (); |
704 | dynbuf_text &msg = msg_dynbuf; msg.clear (); |
715 | |
705 | |
716 | msg << "T<Player skills:>\n\n"; |
706 | msg << "T<Player skills:>\n\n"; |
717 | if (num_skills_found > 1) |
707 | if (num_skills_found > 1) |
718 | qsort (skills, num_skills_found, sizeof (skills [0]), (int (*)(const void *, const void *)) std::strcmp); |
708 | qsort (skills, num_skills_found, sizeof (skills [0]), cmp_skillp); |
719 | |
709 | |
|
|
710 | char buf[31]; /* +1 for '\0' */ |
|
|
711 | const char *const periods = ".............................."; // 30 |
|
|
712 | |
720 | for (i = 0; i < num_skills_found; i++) |
713 | for (i = 0; i < num_skills_found; i++) { |
721 | msg << " C<" << skills [i] << ">\n"; |
714 | object *tmp = skills[i]; |
|
|
715 | |
|
|
716 | /* Basically want to fill this out to 30 spaces with periods */ |
|
|
717 | snprintf (buf, sizeof (buf), "%s%s", &tmp->name, periods); |
|
|
718 | |
|
|
719 | msg << " C<"; |
|
|
720 | |
|
|
721 | if (settings.permanent_exp_ratio) |
|
|
722 | msg.printf ("%slvl:%3d (xp:%" PRId64 "/%" PRId64 "/%d%%)", |
|
|
723 | buf, tmp->level, tmp->stats.exp, level_exp (tmp->level + 1, op->expmul), |
|
|
724 | clipped_percent (tmp->perm_exp, tmp->stats.exp)); |
|
|
725 | else |
|
|
726 | msg.printf ("%slvl:%3d (xp:%" PRId64 "/%" PRId64 ")", |
|
|
727 | buf, tmp->level, tmp->stats.exp, level_exp (tmp->level + 1, op->expmul)); |
|
|
728 | |
|
|
729 | msg << ">\n"; |
|
|
730 | } |
722 | |
731 | |
723 | msg << "\nYou can handle " << op->level / 5 + 5 << " weapon improvements.\r"; |
732 | msg << "\nYou can handle " << op->level / 5 + 5 << " weapon improvements.\r"; |
724 | |
733 | |
725 | cp = determine_god (op); |
734 | cp = determine_god (op); |
726 | msg << "You worship " << (cp ? cp : "no god at current time") << ".\r"; |
735 | msg << "You worship " << (cp ? cp : "no god at current time") << ".\r"; |
… | |
… | |
888 | } |
897 | } |
889 | } |
898 | } |
890 | |
899 | |
891 | if (!op->apply (pl->combat_ob)) |
900 | if (!op->apply (pl->combat_ob)) |
892 | return 0; |
901 | return 0; |
|
|
902 | |
|
|
903 | if (!op->chosen_skill) |
|
|
904 | { |
|
|
905 | LOG (llevError, "do_skill_attack: weapon has no skill (%s)", pl->combat_ob->debug_desc ()); |
|
|
906 | new_draw_info (NDI_RED | NDI_REPLY, 0, op, "You hit a bug in the server, please contact an admin!"); |
|
|
907 | return 0; |
|
|
908 | } |
893 | } |
909 | } |
894 | |
910 | |
895 | /* lose invisiblity/hiding status for running attacks */ |
911 | /* lose invisiblity/hiding status for running attacks */ |
896 | if (pl->tmp_invis) |
912 | if (pl->tmp_invis) |
897 | { |
913 | { |