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.67 by root, Thu Sep 25 04:09:57 2008 UTC vs.
Revision 1.79 by root, Sat Nov 7 18:30:06 2009 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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009 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 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. */
109 } 110 }
110 } 111 }
111} 112}
112 113
113static object * 114static object *
114find_skill (object *who, const shstr &sh) 115find_skill (object *who, shstr_cmp name)
115{ 116{
117 if (who->chosen_skill
118 && who->chosen_skill->skill == name
119 && who->chosen_skill->type == SKILL)
120 return who->chosen_skill;
121
116 for (object *tmp = who->inv; tmp; tmp = tmp->below) 122 for (object *tmp = who->inv; tmp; tmp = tmp->below)
117 if (tmp->skill == sh && tmp->type == SKILL) 123 if (tmp->skill == name && tmp->type == SKILL)
118 return tmp; 124 return splay (tmp);
119 125
120 return 0; 126 return 0;
127}
128
129object *player::find_skill (shstr_cmp name) const
130{
131 // might want to use last_skill_obj at one point, or maybe not
132 return ::find_skill (ob, name);
121} 133}
122 134
123/* This returns the skill pointer of the given name (the 135/* This returns the skill pointer of the given name (the
124 * one that accumulates exp, has the level, etc). 136 * one that accumulates exp, has the level, etc).
125 * 137 *
126 * It is presumed that the player will be needing to actually 138 * It is presumed that the player will be needing to actually
127 * use the skill, so thus if use of the skill requires a skill 139 * use the skill, so thus if use of the skill requires a skill
128 * tool, this code will equip it. 140 * tool, this code will equip it.
129 */ 141 */
130object * 142object *
131find_skill_by_name (object *who, const shstr &sh) 143find_skill_by_name (object *who, shstr_cmp sh)
132{ 144{
133 object *skill_tool = 0; 145 object *skill_tool = 0;
134 146
135 for (object *tmp = who->inv; tmp; tmp = tmp->below) 147 for (object *tmp = who->inv; tmp; tmp = tmp->below)
136 if (tmp->skill == sh) 148 if (tmp->skill == sh)
163 175
164 return splay (skill); 176 return splay (skill);
165} 177}
166 178
167object * 179object *
168find_skill_by_name (object *who, const char *name) 180find_skill_by_name_fuzzy (object *who, const char *name)
169{ 181{
170 if (!name) 182 if (!name)
171 return 0; 183 return 0;
172 184
173 for (object *tmp = who->inv; tmp; tmp = tmp->below) 185 for (object *tmp = who->inv; tmp; tmp = tmp->below)
174 if ((tmp->type == SKILL || tmp->type == SKILL_TOOL) 186 if ((tmp->type == SKILL || tmp->type == SKILL_TOOL)
175 && tmp->skill.begins_with (name)) 187 && tmp->skill.starts_with (name))
176 if (object *skop = find_skill_by_name (who, tmp->skill)) 188 if (object *skop = find_skill_by_name (who, tmp->skill))
177 return skop; 189 return skop;
178 190
179 return 0; 191 return 0;
180} 192}
249 */ 261 */
250int 262int
251do_skill (object *op, object *part, object *skill, int dir, const char *string) 263do_skill (object *op, object *part, object *skill, int dir, const char *string)
252{ 264{
253 int success = 0, exp = 0; 265 int success = 0, exp = 0;
254 int did_alc = 0;
255 266
256 if (!skill) 267 if (!skill)
257 return 0; 268 return 0;
258 269
259 /* The code below presumes that the skill points to the object that 270 /* The code below presumes that the skill points to the object that
384 case SK_LITERACY: 395 case SK_LITERACY:
385 case SK_WOODSMAN: 396 case SK_WOODSMAN:
386 /* first, we try to find a cauldron, and do the alchemy thing. 397 /* first, we try to find a cauldron, and do the alchemy thing.
387 * failing that, we go and identify stuff. 398 * failing that, we go and identify stuff.
388 */ 399 */
400 {
401 bool found_cauldron = false;
402
389 for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next) 403 for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next)
390 { 404 {
391 next = tmp->above; 405 next = tmp->above;
392 406
393 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 407 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON))
394 { 408 {
409 found_cauldron = true;
410
411 if (tmp->skill != skill->skill)
412 {
413 op->failmsg (format ("You can't use the %s with the %s skill!",
414 query_name (tmp),
415 query_name (skill)));
416 break;
417 }
418
395 attempt_do_alchemy (op, tmp); 419 attempt_do_alchemy (op, tmp, skill);
396 420
397 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 421 if (QUERY_FLAG (tmp, FLAG_APPLIED))
398 esrv_send_inventory (op, tmp); 422 esrv_send_inventory (op, tmp);
399
400 did_alc = 1;
401 } 423 }
402 } 424 }
403 425
404 if (did_alc == 0) 426 if (!found_cauldron)
405 exp = success = skill_ident (op, skill); 427 exp = success = skill_ident (op, skill);
406 428 }
407 break; 429 break;
408 430
409 case SK_DET_MAGIC: 431 case SK_DET_MAGIC:
410 case SK_DET_CURSE: 432 case SK_DET_CURSE:
411 exp = success = skill_ident (op, skill); 433 exp = success = skill_ident (op, skill);
670 692
671 for (object *tmp = op->inv; tmp; tmp = tmp->below) 693 for (object *tmp = op->inv; tmp; tmp = tmp->below)
672 { 694 {
673 if (tmp->type == SKILL) 695 if (tmp->type == SKILL)
674 { 696 {
675 if (search && !strstr (tmp->name, search)) 697 if (search && !tmp->name.contains (search))
676 continue; 698 continue;
677 699
678 char buf[30]; 700 char buf[30];
679 701
680 /* Basically want to fill this out to 30 spaces with periods */ 702 /* Basically want to fill this out to 30 spaces with periods */
694 * it so it doesn't crash the server - otherwise, one character may 716 * it so it doesn't crash the server - otherwise, one character may
695 * crash the server numerous times. 717 * crash the server numerous times.
696 */ 718 */
697 if (num_skills_found >= NUM_SKILLS) 719 if (num_skills_found >= NUM_SKILLS)
698 { 720 {
699 new_draw_info (NDI_RED, 0, op, "Your character has too many skills."); 721 new_draw_info (NDI_RED | NDI_REPLY, 0, op, "Your character has too many skills.");
700 new_draw_info (NDI_RED, 0, op, "Something isn't right - contact the server admin"); 722 new_draw_info (NDI_RED | NDI_REPLY, 0, op, "Something isn't right - contact the server admin");
701 break; 723 break;
702 } 724 }
703 } 725 }
704 } 726 }
705 727
706 dynbuf_text msg (4096, 1024); 728 dynbuf_text &msg = msg_dynbuf; msg.clear ();
707 729
708 msg << "T<Player skills:>\n\n"; 730 msg << "T<Player skills:>\n\n";
709 if (num_skills_found > 1) 731 if (num_skills_found > 1)
710 qsort (skills, num_skills_found, sizeof (skills [0]), (int (*)(const void *, const void *)) std::strcmp); 732 qsort (skills, num_skills_found, sizeof (skills [0]), (int (*)(const void *, const void *)) std::strcmp);
711 733
741 763
742 for (skop = op->inv; skop; skop = skop->below) 764 for (skop = op->inv; skop; skop = skop->below)
743 { 765 {
744 if (skop->type == SKILL 766 if (skop->type == SKILL
745 && QUERY_FLAG (skop, FLAG_CAN_USE_SKILL) 767 && QUERY_FLAG (skop, FLAG_CAN_USE_SKILL)
746 && !strncasecmp (string, skop->skill, MIN (strlen (string), (size_t) strlen (skop->skill)))) 768 && !strncasecmp (string, skop->skill, min (strlen (string), (size_t) strlen (skop->skill))))
747 break; 769 break;
748 else if (skop->type == SKILL_TOOL 770 else if (skop->type == SKILL_TOOL
749 && !strncasecmp (string, skop->skill, MIN (strlen (string), (size_t) strlen (skop->skill)))) 771 && !strncasecmp (string, skop->skill, min (strlen (string), (size_t) strlen (skop->skill))))
750 break; 772 break;
751 } 773 }
752 774
753 if (!skop) 775 if (!skop)
754 { 776 {
880 /* lose invisiblity/hiding status for running attacks */ 902 /* lose invisiblity/hiding status for running attacks */
881 if (pl->tmp_invis) 903 if (pl->tmp_invis)
882 { 904 {
883 pl->tmp_invis = 0; 905 pl->tmp_invis = 0;
884 op->invisible = 0; 906 op->invisible = 0;
885 op->hide = 0; 907 op->flag [FLAG_HIDDEN] = 0;
886 update_object (op, UP_OBJ_CHANGE); 908 update_object (op, UP_OBJ_CHANGE);
887 } 909 }
888 } 910 }
889 911
890 int success = attack_ob (tmp, op); 912 int success = attack_ob (tmp, op);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines