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 |
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 |
… | |
… | |
109 | } |
109 | } |
110 | } |
110 | } |
111 | } |
111 | } |
112 | |
112 | |
113 | static object * |
113 | static object * |
114 | find_skill (object *who, const shstr &name) |
114 | find_skill (object *who, shstr_cmp name) |
115 | { |
115 | { |
116 | if (who->chosen_skill |
116 | if (who->chosen_skill |
117 | && who->chosen_skill->skill == name |
117 | && who->chosen_skill->skill == name |
118 | && who->chosen_skill->type == SKILL) |
118 | && who->chosen_skill->type == SKILL) |
119 | return who->chosen_skill; |
119 | return who->chosen_skill; |
… | |
… | |
123 | return splay (tmp); |
123 | return splay (tmp); |
124 | |
124 | |
125 | return 0; |
125 | return 0; |
126 | } |
126 | } |
127 | |
127 | |
128 | object *player::find_skill (const shstr &name) const |
128 | object *player::find_skill (shstr_cmp name) const |
129 | { |
129 | { |
130 | // might want to use last_skill_obj at one point, or maybe not |
130 | // might want to use last_skill_obj at one point, or maybe not |
131 | return ::find_skill (ob, name); |
131 | return ::find_skill (ob, name); |
132 | } |
|
|
133 | |
|
|
134 | object *player::find_skill (const char *name) const |
|
|
135 | { |
|
|
136 | return find_skill (shstr (name)); |
|
|
137 | } |
132 | } |
138 | |
133 | |
139 | /* This returns the skill pointer of the given name (the |
134 | /* This returns the skill pointer of the given name (the |
140 | * one that accumulates exp, has the level, etc). |
135 | * one that accumulates exp, has the level, etc). |
141 | * |
136 | * |
142 | * It is presumed that the player will be needing to actually |
137 | * It is presumed that the player will be needing to actually |
143 | * use the skill, so thus if use of the skill requires a skill |
138 | * use the skill, so thus if use of the skill requires a skill |
144 | * tool, this code will equip it. |
139 | * tool, this code will equip it. |
145 | */ |
140 | */ |
146 | object * |
141 | object * |
147 | find_skill_by_name (object *who, const shstr &sh) |
142 | find_skill_by_name (object *who, shstr_cmp sh) |
148 | { |
143 | { |
149 | object *skill_tool = 0; |
144 | object *skill_tool = 0; |
150 | |
145 | |
151 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
146 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
152 | if (tmp->skill == sh) |
147 | if (tmp->skill == sh) |
… | |
… | |
179 | |
174 | |
180 | return splay (skill); |
175 | return splay (skill); |
181 | } |
176 | } |
182 | |
177 | |
183 | object * |
178 | object * |
184 | find_skill_by_name (object *who, const char *name) |
179 | find_skill_by_name_fuzzy (object *who, const char *name) |
185 | { |
180 | { |
186 | if (!name) |
181 | if (!name) |
187 | return 0; |
182 | return 0; |
188 | |
183 | |
189 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
184 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
190 | if ((tmp->type == SKILL || tmp->type == SKILL_TOOL) |
185 | if ((tmp->type == SKILL || tmp->type == SKILL_TOOL) |
191 | && tmp->skill.begins_with (name)) |
186 | && tmp->skill.starts_with (name)) |
192 | if (object *skop = find_skill_by_name (who, tmp->skill)) |
187 | if (object *skop = find_skill_by_name (who, tmp->skill)) |
193 | return skop; |
188 | return skop; |
194 | |
189 | |
195 | return 0; |
190 | return 0; |
196 | } |
191 | } |
… | |
… | |
265 | */ |
260 | */ |
266 | int |
261 | int |
267 | do_skill (object *op, object *part, object *skill, int dir, const char *string) |
262 | do_skill (object *op, object *part, object *skill, int dir, const char *string) |
268 | { |
263 | { |
269 | int success = 0, exp = 0; |
264 | int success = 0, exp = 0; |
270 | int did_alc = 0; |
|
|
271 | |
265 | |
272 | if (!skill) |
266 | if (!skill) |
273 | return 0; |
267 | return 0; |
274 | |
268 | |
275 | /* The code below presumes that the skill points to the object that |
269 | /* The code below presumes that the skill points to the object that |
… | |
… | |
400 | case SK_LITERACY: |
394 | case SK_LITERACY: |
401 | case SK_WOODSMAN: |
395 | case SK_WOODSMAN: |
402 | /* first, we try to find a cauldron, and do the alchemy thing. |
396 | /* first, we try to find a cauldron, and do the alchemy thing. |
403 | * failing that, we go and identify stuff. |
397 | * failing that, we go and identify stuff. |
404 | */ |
398 | */ |
|
|
399 | { |
|
|
400 | bool found_cauldron = false; |
|
|
401 | |
405 | for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next) |
402 | for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next) |
406 | { |
403 | { |
407 | next = tmp->above; |
404 | next = tmp->above; |
408 | |
405 | |
409 | if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) |
406 | if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) |
410 | { |
407 | { |
|
|
408 | found_cauldron = true; |
|
|
409 | |
|
|
410 | if (tmp->skill != skill->skill) |
|
|
411 | { |
|
|
412 | op->failmsg (format ("You can't use the %s with the %s skill!", |
|
|
413 | query_name (tmp), |
|
|
414 | query_name (skill))); |
|
|
415 | break; |
|
|
416 | } |
|
|
417 | |
411 | attempt_do_alchemy (op, tmp); |
418 | attempt_do_alchemy (op, tmp, skill); |
412 | |
419 | |
413 | if (QUERY_FLAG (tmp, FLAG_APPLIED)) |
420 | if (QUERY_FLAG (tmp, FLAG_APPLIED)) |
414 | esrv_send_inventory (op, tmp); |
421 | esrv_send_inventory (op, tmp); |
415 | |
|
|
416 | did_alc = 1; |
|
|
417 | } |
422 | } |
418 | } |
423 | } |
419 | |
424 | |
420 | if (did_alc == 0) |
425 | if (!found_cauldron) |
421 | exp = success = skill_ident (op, skill); |
426 | exp = success = skill_ident (op, skill); |
422 | |
427 | } |
423 | break; |
428 | break; |
424 | |
429 | |
425 | case SK_DET_MAGIC: |
430 | case SK_DET_MAGIC: |
426 | case SK_DET_CURSE: |
431 | case SK_DET_CURSE: |
427 | exp = success = skill_ident (op, skill); |
432 | exp = success = skill_ident (op, skill); |
… | |
… | |
686 | |
691 | |
687 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
692 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
688 | { |
693 | { |
689 | if (tmp->type == SKILL) |
694 | if (tmp->type == SKILL) |
690 | { |
695 | { |
691 | if (search && !strstr (tmp->name, search)) |
696 | if (search && !tmp->name.contains (search)) |
692 | continue; |
697 | continue; |
693 | |
698 | |
694 | char buf[30]; |
699 | char buf[30]; |
695 | |
700 | |
696 | /* Basically want to fill this out to 30 spaces with periods */ |
701 | /* Basically want to fill this out to 30 spaces with periods */ |
… | |
… | |
717 | break; |
722 | break; |
718 | } |
723 | } |
719 | } |
724 | } |
720 | } |
725 | } |
721 | |
726 | |
722 | dynbuf_text msg (4096, 1024); |
727 | dynbuf_text &msg = msg_dynbuf; msg.clear (); |
723 | |
728 | |
724 | msg << "T<Player skills:>\n\n"; |
729 | msg << "T<Player skills:>\n\n"; |
725 | if (num_skills_found > 1) |
730 | if (num_skills_found > 1) |
726 | qsort (skills, num_skills_found, sizeof (skills [0]), (int (*)(const void *, const void *)) std::strcmp); |
731 | qsort (skills, num_skills_found, sizeof (skills [0]), (int (*)(const void *, const void *)) std::strcmp); |
727 | |
732 | |
… | |
… | |
896 | /* lose invisiblity/hiding status for running attacks */ |
901 | /* lose invisiblity/hiding status for running attacks */ |
897 | if (pl->tmp_invis) |
902 | if (pl->tmp_invis) |
898 | { |
903 | { |
899 | pl->tmp_invis = 0; |
904 | pl->tmp_invis = 0; |
900 | op->invisible = 0; |
905 | op->invisible = 0; |
901 | op->hide = 0; |
906 | op->flag [FLAG_HIDDEN] = 0; |
902 | update_object (op, UP_OBJ_CHANGE); |
907 | update_object (op, UP_OBJ_CHANGE); |
903 | } |
908 | } |
904 | } |
909 | } |
905 | |
910 | |
906 | int success = attack_ob (tmp, op); |
911 | int success = attack_ob (tmp, op); |