1 | /* |
1 | /* |
2 | * CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game |
3 | * |
3 | * |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
5 | * Copryight (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copryight (C) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
7 | * |
7 | * |
… | |
… | |
44 | #include <object.h> |
44 | #include <object.h> |
45 | #include <sproto.h> |
45 | #include <sproto.h> |
46 | #include <living.h> /* for defs of STR,CON,DEX,etc. -b.t. */ |
46 | #include <living.h> /* for defs of STR,CON,DEX,etc. -b.t. */ |
47 | #include <spells.h> |
47 | #include <spells.h> |
48 | |
48 | |
49 | /* Table of unarmed attack skills. Terminated by -1. This |
49 | const uint8_t skill_flags[NUM_SKILLS] = { |
50 | * is also the list that we should try to use skills when |
50 | 0, // SK_NONE |
51 | * automatically applying one for the player. |
51 | # define def(uc, flags) flags, |
52 | */ |
52 | # include "skillinc.h" |
53 | static uint8 unarmed_skills[] = { |
53 | # undef def |
54 | SK_KARATE, |
|
|
55 | SK_CLAWING, |
|
|
56 | SK_FLAME_TOUCH, |
|
|
57 | SK_SPARK_TOUCH, |
|
|
58 | SK_SHIVER, |
|
|
59 | SK_ACID_SPLASH, |
|
|
60 | SK_POISON_NAIL, |
|
|
61 | SK_PUNCHING, |
|
|
62 | (uint8)-1 |
|
|
63 | }; |
54 | }; |
64 | |
55 | |
65 | static int attack_hth (object *pl, int dir, const char *string, object *skill); |
56 | static int attack_hth (object *pl, int dir, const char *string, object *skill); |
66 | static int attack_melee_weapon (object *op, int dir, const char *string, object *skill); |
57 | static int attack_melee_weapon (object *op, int dir, const char *string, object *skill); |
67 | |
58 | |
… | |
… | |
70 | * subtypes. |
61 | * subtypes. |
71 | */ |
62 | */ |
72 | void |
63 | void |
73 | init_skills (void) |
64 | init_skills (void) |
74 | { |
65 | { |
75 | int i; |
|
|
76 | archetype *at; |
|
|
77 | |
|
|
78 | for (at = first_archetype; at != NULL; at = at->next) |
66 | for (archetype *at = first_archetype; at; at = at->next) |
79 | if (at->clone.type == SKILL) |
67 | if (at->clone.type == SKILL) |
80 | { |
68 | { |
81 | if (skill_names[at->clone.subtype] != NULL) |
69 | if (skill_names[at->clone.subtype]) |
82 | LOG (llevError, "init_skills: multiple skill using same subtype %d, %s, %s\n", |
70 | LOG (llevError, "init_skills: multiple skill using same subtype %d, %s, %s\n", |
83 | at->clone.subtype, &skill_names[at->clone.subtype], &at->clone.skill); |
71 | at->clone.subtype, &skill_names[at->clone.subtype], &at->clone.skill); |
84 | else |
72 | else |
85 | skill_names[at->clone.subtype] = at->clone.skill; |
73 | skill_names[at->clone.subtype] = at->clone.skill; |
86 | } |
74 | } |
87 | |
75 | |
88 | /* This isn't really an error if there is no skill subtype set, but |
76 | /* This isn't really an error if there is no skill subtype set, but |
89 | * checking for this may catch some user errors. |
77 | * checking for this may catch some user errors. |
90 | */ |
78 | */ |
91 | for (i = 1; i < NUM_SKILLS; i++) |
79 | for (int i = 1; i < NUM_SKILLS; i++) |
92 | { |
|
|
93 | if (!skill_names[i]) |
80 | if (!skill_names[i]) |
94 | LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i); |
81 | LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i); |
95 | } |
|
|
96 | } |
82 | } |
97 | |
83 | |
98 | /* This function goes through the player inventory and sets |
84 | /* This function goes through the player inventory and sets |
99 | * up the last_skills[] array in the player object. |
85 | * up the last_skills[] array in the player object. |
100 | * the last_skills[] is used to more quickly lookup skills - |
86 | * the last_skills[] is used to more quickly lookup skills - |
… | |
… | |
129 | * tool, this code will equip it. |
115 | * tool, this code will equip it. |
130 | */ |
116 | */ |
131 | object * |
117 | object * |
132 | find_skill_by_name (object *who, const char *name) |
118 | find_skill_by_name (object *who, const char *name) |
133 | { |
119 | { |
134 | object *skill = NULL, *skill_tool = NULL, *tmp; |
|
|
135 | |
|
|
136 | if (!name) |
120 | if (!name) |
137 | return NULL; |
121 | return 0; |
|
|
122 | |
|
|
123 | object *skill = 0, *skill_tool = 0; |
138 | |
124 | |
139 | /* We make sure the length of the string in the object is greater |
125 | /* We make sure the length of the string in the object is greater |
140 | * in length than the passed string. Eg, if we have a skill called |
126 | * in length than the passed string. Eg, if we have a skill called |
141 | * 'hi', we don't want to match if the user passed 'high' |
127 | * 'hi', we don't want to match if the user passed 'high' |
142 | */ |
128 | */ |
143 | for (tmp = who->inv; tmp != NULL; tmp = tmp->below) |
129 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
144 | { |
130 | { |
145 | if (tmp->type == SKILL && !strncasecmp (name, tmp->skill, strlen (name)) && (size_t) strlen (tmp->skill) >= strlen (name)) |
131 | if (tmp->type == SKILL && !strncasecmp (name, tmp->skill, strlen (name)) && strlen (tmp->skill) >= strlen (name)) |
146 | skill = tmp; |
132 | skill = tmp; |
147 | |
133 | |
148 | /* Try to find appropriate skilltool. If the player has one already |
134 | /* Try to find appropriate skilltool. If the player has one already |
149 | * applied, we try to keep using that one. |
135 | * applied, we try to keep using that one. |
150 | */ |
136 | */ |
151 | else if (tmp->type == SKILL_TOOL && !strncasecmp (name, tmp->skill, strlen (name)) && (size_t) strlen (tmp->skill) >= strlen (name)) |
137 | else if (tmp->type == SKILL_TOOL && !strncasecmp (name, tmp->skill, strlen (name)) && strlen (tmp->skill) >= strlen (name)) |
152 | { |
138 | { |
153 | if (QUERY_FLAG (tmp, FLAG_APPLIED)) |
139 | if (QUERY_FLAG (tmp, FLAG_APPLIED)) |
154 | skill_tool = tmp; |
140 | skill_tool = tmp; |
155 | else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
141 | else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
156 | skill_tool = tmp; |
142 | skill_tool = tmp; |
157 | } |
143 | } |
158 | } |
144 | } |
|
|
145 | |
159 | /* If this is a skill that can be used without a tool, return it */ |
146 | /* If this is a skill that can be used without a tool, return it */ |
160 | if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL)) |
147 | if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL)) |
161 | return skill; |
148 | return skill; |
162 | |
149 | |
163 | /* Player has a tool to use the skill. IF not applied, apply it - |
150 | /* Player has a tool to use the skill. If not applied, apply it - |
164 | * if not successful, return null. If they do have the skill tool |
151 | * if not successful, return null. If they do have the skill tool |
165 | * but not the skill itself, give it to them. |
152 | * but not the skill itself, give it to them. |
166 | */ |
153 | */ |
167 | if (skill_tool) |
154 | if (skill_tool) |
168 | { |
155 | { |
169 | if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
156 | if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
170 | { |
|
|
171 | if (apply_special (who, skill_tool, 0)) |
157 | if (apply_special (who, skill_tool, 0)) |
172 | return NULL; |
158 | return 0; |
173 | } |
159 | |
174 | if (!skill) |
160 | if (!skill) |
175 | { |
161 | { |
176 | skill = give_skill_by_name (who, skill_tool->skill); |
162 | skill = give_skill_by_name (who, skill_tool->skill); |
177 | link_player_skills (who); |
163 | link_player_skills (who); |
178 | } |
164 | } |
|
|
165 | |
179 | return skill; |
166 | return skill; |
180 | } |
167 | } |
|
|
168 | |
181 | return NULL; |
169 | return 0; |
182 | } |
170 | } |
183 | |
|
|
184 | |
171 | |
185 | /* This returns the skill pointer of the given name (the |
172 | /* This returns the skill pointer of the given name (the |
186 | * one that accumlates exp, has the level, etc). |
173 | * one that accumlates exp, has the level, etc). |
187 | * |
174 | * |
188 | * It is presumed that the player will be needing to actually |
175 | * It is presumed that the player will be needing to actually |
… | |
… | |
194 | * this replaces find_skill. |
181 | * this replaces find_skill. |
195 | */ |
182 | */ |
196 | object * |
183 | object * |
197 | find_skill_by_number (object *who, int skillno) |
184 | find_skill_by_number (object *who, int skillno) |
198 | { |
185 | { |
|
|
186 | if (!IN_RANGE_EXC (skillno, 1, NUM_SKILLS)) |
|
|
187 | return 0; |
|
|
188 | |
199 | object *skill = NULL, *skill_tool = NULL, *tmp; |
189 | object *skill = NULL, *skill_tool = NULL; |
200 | |
190 | |
201 | if (skillno < 1 || skillno >= NUM_SKILLS) |
|
|
202 | return NULL; |
|
|
203 | |
|
|
204 | for (tmp = who->inv; tmp != NULL; tmp = tmp->below) |
191 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
205 | { |
192 | { |
206 | if (tmp->type == SKILL && tmp->subtype == skillno) |
193 | if (tmp->type == SKILL && tmp->subtype == skillno) |
207 | skill = tmp; |
194 | skill = tmp; |
208 | |
195 | |
209 | /* Try to find appropriate skilltool. If the player has one already |
196 | /* Try to find appropriate skilltool. If the player has one already |
… | |
… | |
215 | skill_tool = tmp; |
202 | skill_tool = tmp; |
216 | else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
203 | else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
217 | skill_tool = tmp; |
204 | skill_tool = tmp; |
218 | } |
205 | } |
219 | } |
206 | } |
|
|
207 | |
220 | /* If this is a skill that can be used without a tool, return it */ |
208 | /* If this is a skill that can be used without a tool, return it */ |
221 | if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL)) |
209 | if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL)) |
222 | return skill; |
210 | return skill; |
223 | |
211 | |
224 | /* Player has a tool to use the skill. IF not applied, apply it - |
212 | /* Player has a tool to use the skill. If not applied, apply it - |
225 | * if not successful, return null. If they do have the skill tool |
213 | * if not successful, return null. If they do have the skill tool |
226 | * but not the skill itself, give it to them. |
214 | * but not the skill itself, give it to them. |
227 | */ |
215 | */ |
228 | if (skill_tool) |
216 | if (skill_tool) |
229 | { |
217 | { |
230 | if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
218 | if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
… | |
… | |
246 | } |
234 | } |
247 | |
235 | |
248 | /* This changes the objects skill to new_skill. |
236 | /* This changes the objects skill to new_skill. |
249 | * note that this function doesn't always need to get used - |
237 | * note that this function doesn't always need to get used - |
250 | * you can now add skill exp to the player without the chosen_skill being |
238 | * you can now add skill exp to the player without the chosen_skill being |
251 | * set. This function is of most interest to players to update |
239 | * set. This function is of most interest to players to update |
252 | * the various range information. |
240 | * the various range information. |
253 | * if new_skill is null, this just unapplies the skill. |
|
|
254 | * flag has the current meaning: |
|
|
255 | * 0x1: If set, don't update the range pointer. This is useful when we |
|
|
256 | * need to ready a new skill, but don't want to clobber range. |
|
|
257 | * return 1 on success, 0 on error |
241 | * return 1 on success, 0 on error |
258 | */ |
242 | */ |
259 | int |
243 | int |
260 | change_skill (object *who, object *new_skill, int flag) |
244 | change_skill (object *who, object *new_skill, int flag) |
261 | { |
245 | { |
262 | int old_range; |
|
|
263 | |
|
|
264 | if (who->type != PLAYER) |
246 | if (who->type != PLAYER) |
265 | return 0; |
247 | return 0; |
266 | |
248 | |
267 | old_range = who->contr->shoottype; |
249 | #if 0 |
268 | |
250 | // optimise this supposedly common case |
269 | if (who->chosen_skill && who->chosen_skill == new_skill) |
251 | if (new_skill == who->chosen_skill) |
270 | { |
|
|
271 | /* optimization for changing skill to current skill */ |
|
|
272 | if (!(flag & 0x1)) |
|
|
273 | who->contr->set_range (range_skill); |
|
|
274 | |
|
|
275 | return 1; |
252 | return 1; |
276 | } |
253 | #endif |
277 | |
|
|
278 | // move skill to front, so it will be preferred next time |
|
|
279 | new_skill->remove (); |
|
|
280 | who->insert (new_skill); |
|
|
281 | |
254 | |
282 | if (!new_skill) |
255 | if (!new_skill) |
283 | { |
256 | { |
284 | if (who->chosen_skill) |
257 | LOG (llevError | logBacktrace, "change_skill called on %s with NULL skill\n", |
285 | apply_special (who, who->chosen_skill, AP_UNAPPLY); |
258 | who->debug_desc ()); |
286 | |
|
|
287 | /* Only goal in this case was to unapply a skill */ |
|
|
288 | return 0; |
259 | return 0; |
289 | } |
260 | } |
|
|
261 | |
|
|
262 | // the skill could be readied already because it is used by a weapon. |
|
|
263 | who->change_weapon (0); |
|
|
264 | new_skill->inv_splay (); |
290 | |
265 | |
291 | if (apply_special (who, new_skill, AP_APPLY)) |
266 | if (apply_special (who, new_skill, AP_APPLY)) |
292 | return 0; |
267 | return 0; |
293 | |
268 | |
294 | if (!(flag & 0x1)) |
|
|
295 | who->contr->set_range ((rangetype) old_range); |
|
|
296 | |
|
|
297 | return 1; |
269 | return 1; |
298 | } |
270 | } |
299 | |
271 | |
300 | /* This function just clears the chosen_skill and range_skill values |
272 | /* This function just clears the chosen_skill and range_skill values |
301 | * inthe player. |
273 | * in the player. |
302 | */ |
274 | */ |
303 | void |
275 | void |
304 | clear_skill (object *who) |
276 | clear_skill (object *who) |
305 | { |
277 | { |
306 | who->chosen_skill = NULL; |
278 | who->chosen_skill = 0; |
307 | CLEAR_FLAG (who, FLAG_READY_SKILL); |
279 | CLEAR_FLAG (who, FLAG_READY_SKILL); |
|
|
280 | |
308 | if (who->type == PLAYER) |
281 | if (who->type == PLAYER) |
309 | { |
282 | if (who->contr->ranged_ob && who->contr->ranged_ob->type == SKILL) |
310 | who->contr->ranges[range_skill] = NULL; |
283 | who->contr->ranged_ob = 0; |
311 | if (who->contr->shoottype == range_skill) |
|
|
312 | who->contr->shoottype = range_none; |
|
|
313 | } |
|
|
314 | } |
284 | } |
315 | |
285 | |
316 | /* do_skill() - Main skills use function-similar in scope to cast_spell(). |
286 | /* do_skill() - Main skills use function-similar in scope to cast_spell(). |
317 | * We handle all requests for skill use outside of some combat here. |
287 | * We handle all requests for skill use outside of some combat here. |
318 | * We require a separate routine outside of fire() so as to allow monsters |
288 | * We require a separate routine outside of fire() so as to allow monsters |
… | |
… | |
326 | int |
296 | int |
327 | do_skill (object *op, object *part, object *skill, int dir, const char *string) |
297 | do_skill (object *op, object *part, object *skill, int dir, const char *string) |
328 | { |
298 | { |
329 | int success = 0, exp = 0; |
299 | int success = 0, exp = 0; |
330 | int did_alc = 0; |
300 | int did_alc = 0; |
331 | object *tmp, *next; |
|
|
332 | |
301 | |
333 | if (!skill) |
302 | if (!skill) |
334 | return 0; |
303 | return 0; |
335 | |
304 | |
336 | /* The code below presumes that the skill points to the object that |
305 | /* The code below presumes that the skill points to the object that |
… | |
… | |
338 | * go and try to find the actual real skill pointer, and if the |
307 | * go and try to find the actual real skill pointer, and if the |
339 | * the player doesn't have a bucket for that, create one. |
308 | * the player doesn't have a bucket for that, create one. |
340 | */ |
309 | */ |
341 | if (skill->type != SKILL && op->type == PLAYER) |
310 | if (skill->type != SKILL && op->type == PLAYER) |
342 | { |
311 | { |
343 | for (tmp = op->inv; tmp != NULL; tmp = tmp->below) |
312 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
344 | if (tmp->type == SKILL && tmp->skill == skill->skill) |
313 | if (tmp->type == SKILL && tmp->skill == skill->skill) |
345 | break; |
314 | { |
|
|
315 | skill = tmp; |
|
|
316 | goto found; |
|
|
317 | } |
346 | |
318 | |
347 | if (!tmp) |
|
|
348 | tmp = give_skill_by_name (op, skill->skill); |
319 | skill = give_skill_by_name (op, skill->skill); |
349 | |
320 | found: ; |
350 | skill = tmp; |
|
|
351 | } |
321 | } |
352 | |
322 | |
353 | // skill, by_whom, on_which_object, which direction, skill_argument |
323 | // skill, by_whom, on_which_object, which direction, skill_argument |
354 | if (INVOKE_OBJECT (USE_SKILL, skill, ARG_OBJECT (op), ARG_OBJECT (part), ARG_INT (dir), ARG_STRING (string))) |
324 | if (INVOKE_OBJECT (USE_SKILL, skill, ARG_OBJECT (op), ARG_OBJECT (part), ARG_INT (dir), ARG_STRING (string))) |
355 | return 0; |
325 | return 0; |
… | |
… | |
460 | case SK_LITERACY: |
430 | case SK_LITERACY: |
461 | case SK_WOODSMAN: |
431 | case SK_WOODSMAN: |
462 | /* first, we try to find a cauldron, and do the alchemy thing. |
432 | /* first, we try to find a cauldron, and do the alchemy thing. |
463 | * failing that, we go and identify stuff. |
433 | * failing that, we go and identify stuff. |
464 | */ |
434 | */ |
465 | for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = next) |
435 | for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next) |
466 | { |
436 | { |
467 | next = tmp->above; |
437 | next = tmp->above; |
468 | |
438 | |
469 | if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) |
439 | if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) |
470 | { |
440 | { |
… | |
… | |
531 | * If certain skills should take more/less time, that should be |
501 | * If certain skills should take more/less time, that should be |
532 | * in the code for the skill itself. |
502 | * in the code for the skill itself. |
533 | */ |
503 | */ |
534 | |
504 | |
535 | if (op->type == PLAYER) |
505 | if (op->type == PLAYER) |
536 | op->speed_left -= 1.0; |
506 | op->speed_left -= 1.f; |
537 | |
507 | |
538 | /* this is a good place to add experience for successfull use of skills. |
508 | /* this is a good place to add experience for successfull use of skills. |
539 | * Note that add_exp() will figure out player/monster experience |
509 | * Note that add_exp() will figure out player/monster experience |
540 | * gain problems. |
510 | * gain problems. |
541 | */ |
511 | */ |
… | |
… | |
569 | * op is the object that was 'defeated'. |
539 | * op is the object that was 'defeated'. |
570 | * skill is the skill used. If no skill is used, it should just |
540 | * skill is the skill used. If no skill is used, it should just |
571 | * point back to who. |
541 | * point back to who. |
572 | * |
542 | * |
573 | */ |
543 | */ |
574 | |
|
|
575 | int |
544 | int |
576 | calc_skill_exp (object *who, object *op, object *skill) |
545 | calc_skill_exp (object *who, object *op, object *skill) |
577 | { |
546 | { |
578 | int op_exp = 0, op_lvl = 0; |
547 | int op_exp = 0, op_lvl = 0; |
579 | float base, value, lvl_mult = 0.0; |
548 | float base, value, lvl_mult = 0.0; |
… | |
… | |
668 | * This one actually teaches the player the skill as something |
637 | * This one actually teaches the player the skill as something |
669 | * they can equip. |
638 | * they can equip. |
670 | * Return 0 if the player knows the skill, 1 if the |
639 | * Return 0 if the player knows the skill, 1 if the |
671 | * player learns the skill, 2 otherwise. |
640 | * player learns the skill, 2 otherwise. |
672 | */ |
641 | */ |
673 | |
|
|
674 | int |
642 | int |
675 | learn_skill (object *pl, object *scroll) |
643 | learn_skill (object *pl, object *scroll) |
676 | { |
644 | { |
677 | object *tmp; |
645 | object *tmp; |
678 | |
646 | |
… | |
… | |
714 | link_player_skills (pl); |
682 | link_player_skills (pl); |
715 | return 1; |
683 | return 1; |
716 | } |
684 | } |
717 | |
685 | |
718 | /* Gives a percentage clipped to 0% -> 100% of a/b. */ |
686 | /* Gives a percentage clipped to 0% -> 100% of a/b. */ |
719 | |
|
|
720 | /* Probably belongs in some global utils-type file? */ |
687 | /* Probably belongs in some global utils-type file? */ |
721 | static int |
688 | static int |
722 | clipped_percent (sint64 a, sint64 b) |
689 | clipped_percent (sint64 a, sint64 b) |
723 | { |
690 | { |
724 | int rv; |
691 | int rv; |
… | |
… | |
817 | * direction that the user is facing. Returns false if we are unable to |
784 | * direction that the user is facing. Returns false if we are unable to |
818 | * change to the requested skill, or were unable to use the skill properly. |
785 | * change to the requested skill, or were unable to use the skill properly. |
819 | * This is tricky because skills can have spaces. We basically roll |
786 | * This is tricky because skills can have spaces. We basically roll |
820 | * our own find_skill_by_name so we can try to do better string matching. |
787 | * our own find_skill_by_name so we can try to do better string matching. |
821 | */ |
788 | */ |
822 | |
|
|
823 | int |
789 | int |
824 | use_skill (object *op, const char *string) |
790 | use_skill (object *op, const char *string) |
825 | { |
791 | { |
826 | object *skop; |
792 | object *skop; |
827 | size_t len; |
793 | size_t len; |
… | |
… | |
875 | } |
841 | } |
876 | |
842 | |
877 | static bool |
843 | static bool |
878 | hth_skill_p (object *skill) |
844 | hth_skill_p (object *skill) |
879 | { |
845 | { |
880 | for (unsigned int i = 0; i < sizeof (unarmed_skills); ++i) |
846 | return (skill_flags [skill->subtype] & (SF_COMBAT | SF_NEED_WEAPON)) == SF_COMBAT; |
881 | if (skill->subtype == unarmed_skills[i]) |
|
|
882 | return 1; |
|
|
883 | |
|
|
884 | return 0; |
|
|
885 | } |
847 | } |
886 | |
848 | |
887 | /* This finds the first unarmed skill the player has, and returns it. |
849 | /* This finds the first unarmed skill the player has, and returns it. |
888 | */ |
850 | */ |
889 | static object * |
851 | static object * |
… | |
… | |
915 | * is readied either then try to find a skill for the player to use. |
877 | * is readied either then try to find a skill for the player to use. |
916 | * it is presumed that if skill is set, it is a valid attack skill (eg, |
878 | * it is presumed that if skill is set, it is a valid attack skill (eg, |
917 | * the caller should have set it appropriately). We still want to pass |
879 | * the caller should have set it appropriately). We still want to pass |
918 | * through that code if skill is set to change to the skill. |
880 | * through that code if skill is set to change to the skill. |
919 | */ |
881 | */ |
920 | if (op->type == PLAYER) |
882 | if (player *pl = op->contr) |
921 | { |
883 | { |
922 | if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) |
884 | if (!pl->combat_ob) |
923 | { |
885 | { |
924 | if (!skill) |
886 | if (QUERY_FLAG (op, FLAG_READY_WEAPON)) |
925 | { |
887 | { |
926 | /* See if the players chosen skill is a combat skill, and use |
888 | for (tmp = op->inv; tmp; tmp = tmp->below) |
927 | * it if appropriate. |
889 | if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED)) |
928 | */ |
890 | break; |
929 | if (op->chosen_skill && hth_skill_p (op->chosen_skill)) |
891 | |
930 | skill = op->chosen_skill; |
892 | if (!tmp) |
931 | else |
|
|
932 | { |
893 | { |
933 | skill = find_player_hth_skill (op); |
894 | LOG (llevError, "Could not find applied weapon on %s\n", &op->name); |
|
|
895 | return 0; |
|
|
896 | } |
934 | |
897 | |
|
|
898 | change_skill (op, find_skill_by_name (op, tmp->skill), 1); |
|
|
899 | } |
|
|
900 | else |
|
|
901 | { |
935 | if (!skill) |
902 | if (!skill) |
|
|
903 | { |
|
|
904 | /* See if the players chosen skill is a combat skill, and use |
|
|
905 | * it if appropriate. |
|
|
906 | */ |
|
|
907 | if (op->chosen_skill && hth_skill_p (op->chosen_skill)) |
|
|
908 | skill = op->chosen_skill; |
|
|
909 | else |
936 | { |
910 | { |
|
|
911 | skill = find_player_hth_skill (op); |
|
|
912 | |
|
|
913 | if (!skill) |
|
|
914 | { |
937 | new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); |
915 | new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); |
938 | return 0; |
916 | return 0; |
|
|
917 | } |
939 | } |
918 | } |
940 | } |
919 | } |
|
|
920 | |
|
|
921 | /* now try to ready the new skill */ |
|
|
922 | if (!change_skill (op, skill, 0)) |
|
|
923 | { /* oh oh, trouble! */ |
|
|
924 | new_draw_info_format (NDI_UNIQUE, 0, op, "Couldn't change to skill %s", &skill->name); |
|
|
925 | return 0; |
|
|
926 | } |
941 | } |
927 | } |
942 | |
928 | |
943 | /* now try to ready the new skill */ |
929 | if (!pl->combat_ob) |
944 | if (!change_skill (op, skill, 0)) |
930 | { |
945 | { /* oh oh, trouble! */ |
931 | LOG (llevError, "Could not find anything to attack on %s\n", &op->name); |
946 | new_draw_info_format (NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name); |
|
|
947 | return 0; |
932 | return 0; |
948 | } |
933 | } |
949 | } |
934 | } |
950 | else |
935 | |
|
|
936 | if (!op->change_weapon (pl->combat_ob)) |
|
|
937 | return 0; |
|
|
938 | |
|
|
939 | /* lose invisiblity/hiding status for running attacks */ |
|
|
940 | if (pl->tmp_invis) |
951 | { |
941 | { |
952 | /* Seen some crashes below where current_weapon is not set, |
942 | pl->tmp_invis = 0; |
953 | * even though the flag says it is. So if current weapon isn't set, |
943 | op->invisible = 0; |
954 | * do some work in trying to find the object to use. |
944 | op->hide = 0; |
955 | */ |
945 | update_object (op, UP_OBJ_CHANGE); |
956 | if (!op->current_weapon) |
|
|
957 | { |
|
|
958 | object *tmp; |
|
|
959 | |
|
|
960 | LOG (llevError, "Player %s does not have current weapon set but flag_ready_weapon is set\n", &op->name); |
|
|
961 | for (tmp = op->inv; tmp; tmp = tmp->below) |
|
|
962 | if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED)) |
|
|
963 | break; |
|
|
964 | |
|
|
965 | if (!tmp) |
|
|
966 | { |
|
|
967 | LOG (llevError, "Could not find applied weapon on %s\n", &op->name); |
|
|
968 | op->current_weapon = NULL; |
|
|
969 | return 0; |
|
|
970 | } |
|
|
971 | else |
|
|
972 | op->current_weapon = tmp; |
|
|
973 | } |
|
|
974 | |
|
|
975 | change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1); |
|
|
976 | } |
946 | } |
977 | } |
|
|
978 | |
|
|
979 | /* lose invisiblity/hiding status for running attacks */ |
|
|
980 | |
|
|
981 | if (op->type == PLAYER && op->contr->tmp_invis) |
|
|
982 | { |
|
|
983 | op->contr->tmp_invis = 0; |
|
|
984 | op->invisible = 0; |
|
|
985 | op->hide = 0; |
|
|
986 | update_object (op, UP_OBJ_CHANGE); |
|
|
987 | } |
947 | } |
988 | |
948 | |
989 | int success = attack_ob (tmp, op); |
949 | int success = attack_ob (tmp, op); |
990 | |
950 | |
991 | /* print appropriate messages to the player */ |
951 | /* print appropriate messages to the player */ |
… | |
… | |
1062 | } |
1022 | } |
1063 | |
1023 | |
1064 | return do_skill_attack (tmp, pl, string, skill); |
1024 | return do_skill_attack (tmp, pl, string, skill); |
1065 | } |
1025 | } |
1066 | |
1026 | |
1067 | |
|
|
1068 | /* attack_hth() - this handles all hand-to-hand attacks -b.t. */ |
1027 | /* attack_hth() - this handles all hand-to-hand attacks -b.t. */ |
1069 | |
1028 | |
1070 | /* July 5, 1995 - I broke up attack_hth() into 2 parts. In the first |
1029 | /* July 5, 1995 - I broke up attack_hth() into 2 parts. In the first |
1071 | * (attack_hth) we check for weapon use, etc in the second (the new |
1030 | * (attack_hth) we check for weapon use, etc in the second (the new |
1072 | * function skill_attack() we actually attack. |
1031 | * function skill_attack() we actually attack. |
1073 | */ |
1032 | */ |
1074 | |
|
|
1075 | static int |
1033 | static int |
1076 | attack_hth (object *pl, int dir, const char *string, object *skill) |
1034 | attack_hth (object *pl, int dir, const char *string, object *skill) |
1077 | { |
1035 | { |
1078 | object *enemy = NULL, *weapon; |
1036 | object *enemy = NULL, *weapon; |
1079 | |
1037 | |
… | |
… | |
1088 | if (pl->type == PLAYER) |
1046 | if (pl->type == PLAYER) |
1089 | { |
1047 | { |
1090 | new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); |
1048 | new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); |
1091 | esrv_update_item (UPD_FLAGS, pl, weapon); |
1049 | esrv_update_item (UPD_FLAGS, pl, weapon); |
1092 | } |
1050 | } |
|
|
1051 | |
1093 | break; |
1052 | break; |
1094 | } |
1053 | } |
1095 | } |
1054 | } |
1096 | |
1055 | |
1097 | return skill_attack (enemy, pl, dir, string, skill); |
1056 | return skill_attack (enemy, pl, dir, string, skill); |