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,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 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. */ |
… | |
… | |
50 | # define def(uc, flags) flags, |
51 | # define def(uc, flags) flags, |
51 | # include "skillinc.h" |
52 | # include "skillinc.h" |
52 | # undef def |
53 | # undef def |
53 | }; |
54 | }; |
54 | |
55 | |
|
|
56 | vector<object_ptr> skillvec; |
|
|
57 | |
55 | static int attack_hth (object *pl, int dir, const char *string, object *skill); |
58 | static int attack_hth (object *pl, int dir, const char *string, object *skill); |
56 | static int attack_melee_weapon (object *op, int dir, const char *string, object *skill); |
59 | static int attack_melee_weapon (object *op, int dir, const char *string, object *skill); |
57 | |
60 | |
58 | /* init_skills basically just sets up the skill_names table |
61 | /* init_skills basically just sets up the skill_names table |
59 | * above. The index into the array is set up by the |
62 | * above. The index into the array is set up by the |
60 | * subtypes. |
63 | * subtypes. |
61 | */ |
64 | */ |
62 | void |
65 | void |
63 | init_skills (void) |
66 | init_skills () |
64 | { |
67 | { |
65 | for_all_archetypes (at) |
68 | // nop |
66 | if (at->type == SKILL) |
69 | } |
|
|
70 | |
|
|
71 | void |
|
|
72 | add_skill_archetype (object *o) |
|
|
73 | { |
|
|
74 | printf ("<%s><%s>\n", &o->name, &o->skill);//D |
|
|
75 | |
|
|
76 | assert (("skill name must equal skill skill", o->name == o->skill)); |
|
|
77 | |
|
|
78 | for (vector<object_ptr>::iterator i = skillvec.begin (); i != skillvec.end (); ++i) |
|
|
79 | if ((*i)->name == o->name) |
67 | { |
80 | { |
68 | if (skill_names[at->subtype]) |
81 | // replace existing entry |
69 | LOG (llevError, "init_skills: multiple skill using same subtype %d, %s, %s\n", |
82 | SKILL_INDEX (o) = i - skillvec.begin (); |
70 | at->subtype, &skill_names[at->subtype], &at->skill); |
83 | *i = o; |
71 | else |
84 | return; |
72 | skill_names[at->subtype] = at->skill; |
|
|
73 | } |
85 | } |
74 | |
86 | |
75 | /* This isn't really an error if there is no skill subtype set, but |
87 | // add new entry |
76 | * checking for this may catch some user errors. |
88 | assert (("only CS_NUM_SKILLS skills supported by client protocol", skillvec.size () < CS_NUM_SKILLS)); |
77 | */ |
89 | SKILL_INDEX (o) = skillvec.size (); |
78 | for (int i = 1; i < NUM_SKILLS; i++) |
90 | skillvec.push_back (o); |
79 | if (!skill_names[i]) |
|
|
80 | LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i); |
|
|
81 | } |
91 | } |
82 | |
92 | |
83 | /* This function goes through the player inventory and sets |
93 | /* This function goes through the player inventory and sets |
84 | * up the last_skills[] array in the player object. |
94 | * up the last_skills[] array in the player object. |
85 | * the last_skills[] is used to more quickly lookup skills - |
95 | * the last_skills[] is used to more quickly lookup skills - |
86 | * mostly used for sending exp. |
96 | * mostly used for sending exp. |
87 | */ |
97 | */ |
88 | void |
98 | void |
89 | player::link_skills () |
99 | player::link_skills () |
90 | { |
100 | { |
91 | for (int i = 0; i < NUM_SKILLS; ++i) |
101 | for (int i = 0; i < CS_NUM_SKILLS; ++i) |
92 | last_skill_ob [i] = 0; |
102 | last_skill_ob [i] = 0; |
93 | |
103 | |
94 | for (object *tmp = ob->inv; tmp; tmp = tmp->below) |
104 | for (object *tmp = ob->inv; tmp; tmp = tmp->below) |
95 | if (tmp->type == SKILL) |
105 | if (tmp->type == SKILL) |
96 | { |
106 | { |
|
|
107 | int idx = SKILL_INDEX (tmp); |
|
|
108 | |
97 | assert (IN_RANGE_EXC (tmp->subtype, 0, NUM_SKILLS)); |
109 | assert (IN_RANGE_EXC (idx, 0, CS_NUM_SKILLS)); |
98 | |
110 | |
99 | if (last_skill_ob [tmp->subtype] != tmp) |
111 | if (last_skill_ob [idx] != tmp) |
100 | { |
112 | { |
101 | /* This is really a warning, hence no else below */ |
|
|
102 | if (last_skill_ob [tmp->subtype]) |
|
|
103 | LOG (llevError, "Multiple skills with the same subtype? %s, %s\n", |
|
|
104 | &last_skill_ob [tmp->subtype]->skill, &tmp->skill); |
|
|
105 | |
|
|
106 | last_skill_ob [tmp->subtype] = tmp; |
113 | last_skill_ob [idx] = tmp; |
107 | if (ns) |
114 | if (ns) |
108 | ns->last_skill_exp [tmp->subtype] = -1; |
115 | ns->last_skill_exp [idx] = -1; |
109 | } |
116 | } |
110 | } |
117 | } |
111 | } |
118 | } |
112 | |
119 | |
113 | static object * |
120 | static object * |
114 | find_skill (object *who, const shstr &name) |
121 | find_skill (object *who, shstr_cmp name) |
115 | { |
122 | { |
116 | if (who->chosen_skill |
123 | if (who->chosen_skill |
117 | && who->chosen_skill->skill == name |
124 | && who->chosen_skill->skill == name |
118 | && who->chosen_skill->type == SKILL) |
125 | && who->chosen_skill->type == SKILL) |
119 | return who->chosen_skill; |
126 | return who->chosen_skill; |
… | |
… | |
123 | return splay (tmp); |
130 | return splay (tmp); |
124 | |
131 | |
125 | return 0; |
132 | return 0; |
126 | } |
133 | } |
127 | |
134 | |
128 | object *player::find_skill (const shstr &name) const |
135 | object * |
|
|
136 | player::find_skill (shstr_cmp name) const |
129 | { |
137 | { |
130 | // might want to use last_skill_obj at one point, or maybe not |
138 | // might want to use last_skill_obj at one point, or maybe not |
131 | return ::find_skill (ob, name); |
139 | return ::find_skill (ob, name); |
132 | } |
|
|
133 | |
|
|
134 | object *player::find_skill (const char *name) const |
|
|
135 | { |
|
|
136 | return find_skill (shstr (name)); |
|
|
137 | } |
140 | } |
138 | |
141 | |
139 | /* This returns the skill pointer of the given name (the |
142 | /* This returns the skill pointer of the given name (the |
140 | * one that accumulates exp, has the level, etc). |
143 | * one that accumulates exp, has the level, etc). |
141 | * |
144 | * |
142 | * It is presumed that the player will be needing to actually |
145 | * 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 |
146 | * use the skill, so thus if use of the skill requires a skill |
144 | * tool, this code will equip it. |
147 | * tool, this code will equip it. |
145 | */ |
148 | */ |
146 | object * |
149 | object * |
147 | find_skill_by_name (object *who, const shstr &sh) |
150 | find_skill_by_name (object *who, shstr_cmp sh) |
148 | { |
151 | { |
149 | object *skill_tool = 0; |
152 | object *skill_tool = 0; |
150 | |
153 | |
151 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
154 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
152 | if (tmp->skill == sh) |
155 | if (tmp->skill == sh) |
… | |
… | |
166 | |
169 | |
167 | /* Player has a tool to use the skill. If not applied, apply it - |
170 | /* Player has a tool to use the skill. If not applied, apply it - |
168 | * if not successful, return null. If they do have the skill tool |
171 | * if not successful, return null. If they do have the skill tool |
169 | * but not the skill itself, give it to them. |
172 | * but not the skill itself, give it to them. |
170 | */ |
173 | */ |
171 | object *skill = find_skill (who, skill_tool->skill); |
174 | object *skill = who->give_skill (skill_tool->skill); |
172 | |
|
|
173 | if (!skill) |
|
|
174 | skill = give_skill_by_name (who, skill_tool->skill); |
|
|
175 | |
175 | |
176 | if (!skill_tool->flag [FLAG_APPLIED]) |
176 | if (!skill_tool->flag [FLAG_APPLIED]) |
177 | if (apply_special (who, splay (skill_tool), AP_APPLY | AP_NO_READY)) |
177 | if (!who->apply (splay (skill_tool))) |
178 | return 0; |
178 | return 0; |
179 | |
179 | |
180 | return splay (skill); |
180 | return splay (skill); |
181 | } |
181 | } |
182 | |
182 | |
183 | object * |
183 | object * |
184 | find_skill_by_name (object *who, const char *name) |
184 | find_skill_by_name_fuzzy (object *who, const char *name) |
185 | { |
185 | { |
186 | if (!name) |
186 | if (name) |
187 | return 0; |
|
|
188 | |
|
|
189 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
187 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
190 | if ((tmp->type == SKILL || tmp->type == SKILL_TOOL) |
188 | if ((tmp->type == SKILL || tmp->type == SKILL_TOOL) |
191 | && tmp->skill.begins_with (name)) |
189 | && tmp->skill.starts_with (name)) |
192 | if (object *skop = find_skill_by_name (who, tmp->skill)) |
190 | if (object *skop = find_skill_by_name (who, tmp->skill)) |
193 | return skop; |
191 | return skop; |
194 | |
192 | |
195 | return 0; |
193 | return 0; |
196 | } |
194 | } |
197 | |
195 | |
198 | /* This returns the skill pointer of the given name (the |
196 | /* This returns the skill pointer of the given name (the |
… | |
… | |
203 | * tool, this code will equip it. |
201 | * tool, this code will equip it. |
204 | * |
202 | * |
205 | * This code is basically the same as find_skill_by_name() above, |
203 | * This code is basically the same as find_skill_by_name() above, |
206 | * but instead a skill name, we search by matching number. |
204 | * but instead a skill name, we search by matching number. |
207 | * this replaces find_skill. |
205 | * this replaces find_skill. |
|
|
206 | * |
|
|
207 | * MUST NOT BE USED IN NEW CODE! (schmorp) |
208 | */ |
208 | */ |
209 | object * |
209 | object * |
210 | find_skill_by_number (object *who, int skillno) |
210 | find_skill_by_number (object *who, int skillno) |
211 | { |
211 | { |
212 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
212 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
… | |
… | |
215 | return skop; |
215 | return skop; |
216 | |
216 | |
217 | return 0; |
217 | return 0; |
218 | } |
218 | } |
219 | |
219 | |
220 | /* This changes the objects chosen_skill to new_skill. |
220 | object * |
221 | * return 1 on success, 0 on error |
221 | object::give_skill (shstr_cmp name, bool can_use) |
222 | */ |
|
|
223 | bool |
|
|
224 | object::change_skill (object *new_skill) |
|
|
225 | { |
222 | { |
226 | if (type != PLAYER) |
223 | object *skill = find_skill (this, name); |
227 | return 0; |
|
|
228 | |
224 | |
229 | // optimise this supposedly common case |
|
|
230 | if (new_skill == chosen_skill) |
|
|
231 | return 1; |
|
|
232 | |
|
|
233 | if (chosen_skill) |
225 | if (!skill) |
234 | { |
226 | skill = give_skill_by_name (this, name); |
235 | chosen_skill->flag [FLAG_APPLIED] = false; |
|
|
236 | change_abil (this, chosen_skill); |
|
|
237 | } |
|
|
238 | |
227 | |
239 | chosen_skill = new_skill; |
228 | if (skill && can_use) |
|
|
229 | skill->flag [FLAG_CAN_USE_SKILL] = true; |
240 | |
230 | |
241 | if (chosen_skill) |
|
|
242 | { |
|
|
243 | chosen_skill->flag [FLAG_APPLIED] = true; |
|
|
244 | change_abil (this, chosen_skill); |
|
|
245 | } |
|
|
246 | |
|
|
247 | // always clear current weapon, as the selected skill could |
|
|
248 | // conflict with the current weapon skill, which would go |
|
|
249 | // undetected and exp would be given to the wrong skill. |
|
|
250 | current_weapon = 0; |
|
|
251 | |
|
|
252 | update_stats (); |
|
|
253 | return 1; |
231 | return skill; |
254 | } |
232 | } |
255 | |
233 | |
256 | /* do_skill() - Main skills use function-similar in scope to cast_spell(). |
234 | /* do_skill() - Main skills use function-similar in scope to cast_spell(). |
257 | * We handle all requests for skill use outside of some combat here. |
235 | * We handle all requests for skill use outside of some combat here. |
258 | * We require a separate routine outside of fire() so as to allow monsters |
236 | * We require a separate routine outside of fire() so as to allow monsters |
… | |
… | |
265 | */ |
243 | */ |
266 | int |
244 | int |
267 | do_skill (object *op, object *part, object *skill, int dir, const char *string) |
245 | do_skill (object *op, object *part, object *skill, int dir, const char *string) |
268 | { |
246 | { |
269 | int success = 0, exp = 0; |
247 | int success = 0, exp = 0; |
270 | int did_alc = 0; |
|
|
271 | |
248 | |
272 | if (!skill) |
249 | if (!skill) |
273 | return 0; |
250 | return 0; |
274 | |
251 | |
275 | /* The code below presumes that the skill points to the object that |
252 | /* The code below presumes that the skill points to the object that |
… | |
… | |
300 | /* Not 100% sure if this will work with new movement code - |
277 | /* Not 100% sure if this will work with new movement code - |
301 | * the levitation skill has move_type for flying, so when |
278 | * the levitation skill has move_type for flying, so when |
302 | * equipped, that should transfer to player, when not, |
279 | * equipped, that should transfer to player, when not, |
303 | * shouldn't. |
280 | * shouldn't. |
304 | */ |
281 | */ |
305 | if (QUERY_FLAG (skill, FLAG_APPLIED)) |
282 | if (skill->flag [FLAG_APPLIED]) |
306 | { |
283 | { |
307 | CLEAR_FLAG (skill, FLAG_APPLIED); |
284 | skill->clr_flag (FLAG_APPLIED); |
308 | new_draw_info (NDI_UNIQUE, 0, op, "You come to earth."); |
285 | new_draw_info (NDI_UNIQUE, 0, op, "You come to earth."); |
309 | } |
286 | } |
310 | else |
287 | else |
311 | { |
288 | { |
312 | SET_FLAG (skill, FLAG_APPLIED); |
289 | skill->set_flag (FLAG_APPLIED); |
313 | new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!"); |
290 | new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!"); |
314 | } |
291 | } |
315 | |
292 | |
316 | op->update_stats (); |
293 | op->update_stats (); |
317 | success = 1; |
294 | success = 1; |
… | |
… | |
400 | case SK_LITERACY: |
377 | case SK_LITERACY: |
401 | case SK_WOODSMAN: |
378 | case SK_WOODSMAN: |
402 | /* first, we try to find a cauldron, and do the alchemy thing. |
379 | /* first, we try to find a cauldron, and do the alchemy thing. |
403 | * failing that, we go and identify stuff. |
380 | * failing that, we go and identify stuff. |
404 | */ |
381 | */ |
|
|
382 | { |
|
|
383 | bool found_cauldron = false; |
|
|
384 | |
405 | for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next) |
385 | for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next) |
406 | { |
386 | { |
407 | next = tmp->above; |
387 | next = tmp->above; |
408 | |
388 | |
409 | if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) |
389 | if (tmp->flag [FLAG_IS_CAULDRON]) |
410 | { |
390 | { |
|
|
391 | found_cauldron = true; |
|
|
392 | |
|
|
393 | if (tmp->skill != skill->skill) |
|
|
394 | { |
|
|
395 | op->failmsgf ("You can't use the %s with the %s skill!", |
|
|
396 | query_name (tmp), |
|
|
397 | query_name (skill)); |
|
|
398 | break; |
|
|
399 | } |
|
|
400 | |
411 | attempt_do_alchemy (op, tmp); |
401 | attempt_do_alchemy (op, tmp, skill); |
412 | |
402 | |
413 | if (QUERY_FLAG (tmp, FLAG_APPLIED)) |
403 | if (tmp->flag [FLAG_APPLIED]) |
414 | esrv_send_inventory (op, tmp); |
404 | esrv_send_inventory (op, tmp); |
415 | |
|
|
416 | did_alc = 1; |
|
|
417 | } |
405 | } |
418 | } |
406 | } |
419 | |
407 | |
420 | if (did_alc == 0) |
408 | if (!found_cauldron) |
421 | exp = success = skill_ident (op, skill); |
409 | exp = success = skill_ident (op, skill); |
422 | |
410 | } |
423 | break; |
411 | break; |
424 | |
412 | |
425 | case SK_DET_MAGIC: |
413 | case SK_DET_MAGIC: |
426 | case SK_DET_CURSE: |
414 | case SK_DET_CURSE: |
427 | exp = success = skill_ident (op, skill); |
415 | exp = success = skill_ident (op, skill); |
… | |
… | |
456 | case SK_EVOCATION: |
444 | case SK_EVOCATION: |
457 | case SK_PYROMANCY: |
445 | case SK_PYROMANCY: |
458 | case SK_SUMMONING: |
446 | case SK_SUMMONING: |
459 | case SK_CLIMBING: |
447 | case SK_CLIMBING: |
460 | new_draw_info (NDI_UNIQUE, 0, op, "This skill is already in effect."); |
448 | new_draw_info (NDI_UNIQUE, 0, op, "This skill is already in effect."); |
|
|
449 | break; |
|
|
450 | |
|
|
451 | case SK_MINING: |
|
|
452 | success = skill_mining (op, part, skill, dir, string); |
461 | break; |
453 | break; |
462 | |
454 | |
463 | default: |
455 | default: |
464 | LOG (llevDebug, "%s attempted to use unknown skill: %d\n", query_name (op), op->chosen_skill->stats.sp); |
456 | LOG (llevDebug, "%s attempted to use unknown skill: %d\n", query_name (op), op->chosen_skill->stats.sp); |
465 | break; |
457 | break; |
… | |
… | |
541 | } |
533 | } |
542 | else |
534 | else |
543 | { /* all other items/living creatures */ |
535 | { /* all other items/living creatures */ |
544 | op_exp = op->stats.exp; |
536 | op_exp = op->stats.exp; |
545 | op_lvl = op->level; |
537 | op_lvl = op->level; |
546 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
538 | if (!op->flag [FLAG_ALIVE]) |
547 | op_lvl += 5 * abs (op->magic); /* for ident/make items */ |
539 | op_lvl += 5 * abs (op->magic); /* for ident/make items */ |
548 | } |
540 | } |
549 | |
541 | |
550 | if (op_lvl < 1) |
542 | if (op_lvl < 1) |
551 | op_lvl = 1; |
543 | op_lvl = 1; |
… | |
… | |
615 | } |
607 | } |
616 | |
608 | |
617 | object *tmp = find_skill (pl, scroll->skill); |
609 | object *tmp = find_skill (pl, scroll->skill); |
618 | |
610 | |
619 | /* player already knows it */ |
611 | /* player already knows it */ |
620 | if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) |
612 | if (tmp && tmp->flag [FLAG_CAN_USE_SKILL]) |
621 | return 0; |
613 | return 0; |
622 | |
614 | |
623 | /* now a random change to learn, based on player Int. |
615 | /* now a random change to learn, based on player Int. |
624 | * give bonus based on level - otherwise stupid characters |
616 | * give bonus based on level - otherwise stupid characters |
625 | * might never be able to learn anything. |
617 | * might never be able to learn anything. |
… | |
… | |
634 | { |
626 | { |
635 | LOG (llevError, "skill scroll %s does not have valid skill name (%s).\n", &scroll->name, &scroll->skill); |
627 | LOG (llevError, "skill scroll %s does not have valid skill name (%s).\n", &scroll->name, &scroll->skill); |
636 | return 2; |
628 | return 2; |
637 | } |
629 | } |
638 | |
630 | |
639 | SET_FLAG (tmp, FLAG_CAN_USE_SKILL); |
631 | tmp->set_flag (FLAG_CAN_USE_SKILL); |
640 | |
632 | |
641 | return 1; |
633 | return 1; |
642 | } |
634 | } |
643 | |
635 | |
644 | /* Gives a percentage clipped to 0% -> 100% of a/b. */ |
636 | /* Gives a percentage clipped to 0% -> 100% of a/b. */ |
… | |
… | |
686 | |
678 | |
687 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
679 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
688 | { |
680 | { |
689 | if (tmp->type == SKILL) |
681 | if (tmp->type == SKILL) |
690 | { |
682 | { |
691 | if (search && !strstr (tmp->name, search)) |
683 | if (search && !tmp->name.contains (search)) |
692 | continue; |
684 | continue; |
693 | |
685 | |
694 | char buf[30]; |
686 | char buf[30]; |
695 | |
687 | |
696 | /* Basically want to fill this out to 30 spaces with periods */ |
688 | /* Basically want to fill this out to 30 spaces with periods */ |
… | |
… | |
710 | * it so it doesn't crash the server - otherwise, one character may |
702 | * it so it doesn't crash the server - otherwise, one character may |
711 | * crash the server numerous times. |
703 | * crash the server numerous times. |
712 | */ |
704 | */ |
713 | if (num_skills_found >= NUM_SKILLS) |
705 | if (num_skills_found >= NUM_SKILLS) |
714 | { |
706 | { |
715 | new_draw_info (NDI_RED, 0, op, "Your character has too many skills."); |
707 | new_draw_info (NDI_RED | NDI_REPLY, 0, op, "Your character has too many skills."); |
716 | new_draw_info (NDI_RED, 0, op, "Something isn't right - contact the server admin"); |
708 | new_draw_info (NDI_RED | NDI_REPLY, 0, op, "Something isn't right - contact the server admin"); |
717 | break; |
709 | break; |
718 | } |
710 | } |
719 | } |
711 | } |
720 | } |
712 | } |
721 | |
713 | |
722 | dynbuf_text msg (4096, 1024); |
714 | dynbuf_text &msg = msg_dynbuf; msg.clear (); |
723 | |
715 | |
724 | msg << "T<Player skills:>\n\n"; |
716 | msg << "T<Player skills:>\n\n"; |
725 | if (num_skills_found > 1) |
717 | if (num_skills_found > 1) |
726 | qsort (skills, num_skills_found, sizeof (skills [0]), (int (*)(const void *, const void *)) std::strcmp); |
718 | qsort (skills, num_skills_found, sizeof (skills [0]), (int (*)(const void *, const void *)) std::strcmp); |
727 | |
719 | |
… | |
… | |
754 | |
746 | |
755 | if (!string) |
747 | if (!string) |
756 | return 0; |
748 | return 0; |
757 | |
749 | |
758 | for (skop = op->inv; skop; skop = skop->below) |
750 | for (skop = op->inv; skop; skop = skop->below) |
759 | { |
751 | if ((skop->type == SKILL || skop->type == SKILL_TOOL) |
760 | if (skop->type == SKILL |
|
|
761 | && QUERY_FLAG (skop, FLAG_CAN_USE_SKILL) |
|
|
762 | && !strncasecmp (string, skop->skill, MIN (strlen (string), (size_t) strlen (skop->skill)))) |
752 | && !strncmp (string, skop->skill, min (strlen (string), strlen (skop->skill)))) |
|
|
753 | { |
|
|
754 | skop = find_skill_by_name (op, skop->skill); |
763 | break; |
755 | break; |
764 | else if (skop->type == SKILL_TOOL |
|
|
765 | && !strncasecmp (string, skop->skill, MIN (strlen (string), (size_t) strlen (skop->skill)))) |
|
|
766 | break; |
|
|
767 | } |
756 | } |
768 | |
757 | |
769 | if (!skop) |
758 | if (!skop) |
770 | { |
759 | { |
771 | new_draw_info_format (NDI_UNIQUE, 0, op, "Unable to find skill %s", string); |
760 | op->failmsgf ("Unable to find skill %s.", string); |
|
|
761 | return 0; |
|
|
762 | } |
|
|
763 | |
|
|
764 | if (!(skill_flags [skop->subtype] & SF_USE)) |
|
|
765 | { |
|
|
766 | op->failmsgf ( |
|
|
767 | "You feel as if you wanted to do something funny, but you can't remember what. " |
|
|
768 | "H<The %s skill cannot be C<use_skill>'ed - maybe you need to C<ready_skill> it, " |
|
|
769 | "use it with some item, or it's always active.>", |
|
|
770 | &skop->skill |
|
|
771 | ); |
772 | return 0; |
772 | return 0; |
773 | } |
773 | } |
774 | |
774 | |
775 | len = strlen (skop->skill); |
775 | len = strlen (skop->skill); |
776 | |
776 | |
… | |
… | |
802 | } |
802 | } |
803 | |
803 | |
804 | static bool |
804 | static bool |
805 | hth_skill_p (object *skill) |
805 | hth_skill_p (object *skill) |
806 | { |
806 | { |
807 | return (skill_flags [skill->subtype] & (SF_COMBAT | SF_NEED_WEAPON)) == SF_COMBAT; |
807 | return (skill_flags [skill->subtype] & (SF_COMBAT | SF_NEED_ITEM)) == SF_COMBAT; |
808 | } |
808 | } |
809 | |
809 | |
810 | /* This finds the first unarmed skill the player has, and returns it. |
810 | /* This finds the first unarmed skill the player has, and returns it. |
811 | */ |
811 | */ |
812 | static object * |
812 | static object * |
813 | find_player_hth_skill (object *op) |
813 | find_player_hth_skill (object *op) |
814 | { |
814 | { |
815 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
815 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
816 | if (tmp->type == SKILL && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL) && hth_skill_p (tmp)) |
816 | if (tmp->type == SKILL && tmp->flag [FLAG_CAN_USE_SKILL] && hth_skill_p (tmp)) |
817 | return tmp; |
817 | return tmp; |
818 | |
818 | |
819 | return 0; |
819 | return 0; |
820 | } |
820 | } |
821 | |
821 | |
… | |
… | |
841 | * through that code if skill is set to change to the skill. |
841 | * through that code if skill is set to change to the skill. |
842 | */ |
842 | */ |
843 | if (player *pl = op->contr) |
843 | if (player *pl = op->contr) |
844 | { |
844 | { |
845 | if (skill) |
845 | if (skill) |
846 | op->change_skill (skill); |
846 | { |
|
|
847 | if (!op->apply (skill)) |
|
|
848 | return 0; |
|
|
849 | } |
847 | else |
850 | else |
848 | { |
851 | { |
849 | if (!pl->combat_ob) |
852 | if (!pl->combat_ob) |
850 | { |
853 | { |
851 | if (QUERY_FLAG (op, FLAG_READY_WEAPON)) |
854 | if (op->flag [FLAG_READY_WEAPON]) |
852 | { |
855 | { |
853 | for (tmp = op->inv; tmp; tmp = tmp->below) |
856 | for (tmp = op->inv; tmp; tmp = tmp->below) |
854 | if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED)) |
857 | if (tmp->type == WEAPON && tmp->flag [FLAG_APPLIED]) |
855 | break; |
858 | break; |
856 | |
859 | |
857 | if (!tmp) |
860 | if (!tmp) |
858 | LOG (llevError, "Could not find applied weapon on %s\n", &op->name); |
861 | LOG (llevError, "Could not find applied weapon on %s\n", &op->name); |
859 | |
862 | |
… | |
… | |
873 | |
876 | |
874 | if (!skill) |
877 | if (!skill) |
875 | new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); |
878 | new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); |
876 | } |
879 | } |
877 | |
880 | |
878 | if (skill) |
881 | op->apply (skill); |
879 | { |
|
|
880 | op->change_skill (0); |
|
|
881 | apply_special (op, skill, AP_APPLY); |
|
|
882 | } |
|
|
883 | } |
882 | } |
884 | |
883 | |
885 | if (!pl->combat_ob) |
884 | if (!pl->combat_ob) |
886 | { |
885 | { |
887 | LOG (llevError, "Could not find anything to attack on %s\n", &op->name); |
886 | LOG (llevError, "Could not find anything to attack on %s\n", &op->name); |
888 | return 0; |
887 | return 0; |
889 | } |
888 | } |
890 | } |
889 | } |
891 | |
890 | |
892 | if (!op->change_weapon (pl->combat_ob)) |
891 | if (!op->apply (pl->combat_ob)) |
893 | return 0; |
892 | return 0; |
894 | } |
893 | } |
895 | |
894 | |
896 | /* lose invisiblity/hiding status for running attacks */ |
895 | /* lose invisiblity/hiding status for running attacks */ |
897 | if (pl->tmp_invis) |
896 | if (pl->tmp_invis) |
898 | { |
897 | { |
899 | pl->tmp_invis = 0; |
898 | pl->tmp_invis = 0; |
900 | op->invisible = 0; |
899 | op->invisible = 0; |
901 | op->hide = 0; |
900 | op->flag [FLAG_HIDDEN] = 0; |
902 | update_object (op, UP_OBJ_CHANGE); |
901 | update_object (op, UP_OBJ_CHANGE); |
903 | } |
902 | } |
904 | } |
903 | } |
905 | |
904 | |
906 | int success = attack_ob (tmp, op); |
905 | int success = attack_ob (tmp, op); |
907 | |
906 | |
908 | /* print appropriate messages to the player */ |
907 | /* print appropriate messages to the player */ |
909 | |
908 | |
910 | if (success && string && tmp && !QUERY_FLAG (tmp, FLAG_FREED)) |
909 | if (success && string && tmp && !tmp->flag [FLAG_FREED]) |
911 | { |
910 | { |
912 | if (op->type == PLAYER) |
911 | if (op->type == PLAYER) |
913 | new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp)); |
912 | new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp)); |
914 | else if (tmp->type == PLAYER) |
913 | else if (tmp->type == PLAYER) |
915 | new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string); |
914 | new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string); |
… | |
… | |
958 | /* space must be blocked for there to be anything interesting to do */ |
957 | /* space must be blocked for there to be anything interesting to do */ |
959 | if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty))) |
958 | if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty))) |
960 | return 0; |
959 | return 0; |
961 | |
960 | |
962 | for (tmp = GET_MAP_OB (m, tx, ty); tmp; tmp = tmp->above) |
961 | for (tmp = GET_MAP_OB (m, tx, ty); tmp; tmp = tmp->above) |
963 | if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR) |
962 | if ((tmp->flag [FLAG_ALIVE] && tmp->stats.hp >= 0) || tmp->flag [FLAG_CAN_ROLL] || tmp->type == LOCKED_DOOR) |
964 | { |
963 | { |
965 | /* Don't attack party members */ |
964 | /* Don't attack party members */ |
966 | if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) |
965 | if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) |
967 | return 0; |
966 | return 0; |
968 | |
967 | |
… | |
… | |
990 | static int |
989 | static int |
991 | attack_hth (object *pl, int dir, const char *string, object *skill) |
990 | attack_hth (object *pl, int dir, const char *string, object *skill) |
992 | { |
991 | { |
993 | object *enemy = NULL, *weapon; |
992 | object *enemy = NULL, *weapon; |
994 | |
993 | |
995 | if (QUERY_FLAG (pl, FLAG_READY_WEAPON)) |
994 | if (pl->flag [FLAG_READY_WEAPON]) |
996 | for (weapon = pl->inv; weapon; weapon = weapon->below) |
995 | for (weapon = pl->inv; weapon; weapon = weapon->below) |
997 | { |
996 | { |
998 | if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED)) |
997 | if (weapon->type == WEAPON && weapon->flag [FLAG_APPLIED]) |
999 | { |
998 | { |
1000 | CLEAR_FLAG (weapon, FLAG_APPLIED); |
999 | weapon->clr_flag (FLAG_APPLIED); |
1001 | CLEAR_FLAG (pl, FLAG_READY_WEAPON); |
1000 | pl->clr_flag (FLAG_READY_WEAPON); |
1002 | pl->update_stats (); |
1001 | pl->update_stats (); |
1003 | if (pl->type == PLAYER) |
1002 | if (pl->type == PLAYER) |
1004 | { |
1003 | { |
1005 | new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); |
1004 | new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); |
1006 | esrv_update_item (UPD_FLAGS, pl, weapon); |
1005 | esrv_update_item (UPD_FLAGS, pl, weapon); |
… | |
… | |
1024 | */ |
1023 | */ |
1025 | static int |
1024 | static int |
1026 | attack_melee_weapon (object *op, int dir, const char *string, object *skill) |
1025 | attack_melee_weapon (object *op, int dir, const char *string, object *skill) |
1027 | { |
1026 | { |
1028 | |
1027 | |
1029 | if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) |
1028 | if (!op->flag [FLAG_READY_WEAPON]) |
1030 | { |
1029 | { |
1031 | if (op->type == PLAYER) |
1030 | if (op->type == PLAYER) |
1032 | new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!"); |
1031 | new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!"); |
1033 | |
1032 | |
1034 | return 0; |
1033 | return 0; |