… | |
… | |
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 - |
… | |
… | |
169 | if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
155 | if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
170 | { |
156 | { |
171 | if (apply_special (who, skill_tool, 0)) |
157 | if (apply_special (who, skill_tool, 0)) |
172 | return NULL; |
158 | return NULL; |
173 | } |
159 | } |
|
|
160 | |
174 | if (!skill) |
161 | if (!skill) |
175 | { |
162 | { |
176 | skill = give_skill_by_name (who, skill_tool->skill); |
163 | skill = give_skill_by_name (who, skill_tool->skill); |
177 | link_player_skills (who); |
164 | link_player_skills (who); |
178 | } |
165 | } |
|
|
166 | |
179 | return skill; |
167 | return skill; |
180 | } |
168 | } |
|
|
169 | |
181 | return NULL; |
170 | return NULL; |
182 | } |
171 | } |
183 | |
172 | |
184 | |
173 | |
185 | /* This returns the skill pointer of the given name (the |
174 | /* This returns the skill pointer of the given name (the |
… | |
… | |
254 | * flag has the current meaning: |
243 | * flag has the current meaning: |
255 | * 0x1: If set, don't update the range pointer. This is useful when we |
244 | * 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. |
245 | * need to ready a new skill, but don't want to clobber range. |
257 | * return 1 on success, 0 on error |
246 | * return 1 on success, 0 on error |
258 | */ |
247 | */ |
259 | |
|
|
260 | int |
248 | int |
261 | change_skill (object *who, object *new_skill, int flag) |
249 | change_skill (object *who, object *new_skill, int flag) |
262 | { |
250 | { |
263 | int old_range; |
251 | int old_range; |
264 | |
252 | |
265 | if (who->type != PLAYER) |
253 | if (who->type != PLAYER) |
266 | return 0; |
254 | return 0; |
267 | |
255 | |
268 | old_range = who->contr->shoottype; |
256 | player *pl = who->contr; |
269 | |
257 | |
270 | if (who->chosen_skill && who->chosen_skill == new_skill) |
258 | if (pl->ranged_skill && pl->ranged_skill == new_skill) |
271 | { |
259 | return 1; |
272 | /* optimization for changing skill to current skill */ |
|
|
273 | if (who->type == PLAYER && !(flag & 0x1)) |
|
|
274 | who->contr->shoottype = range_skill; |
|
|
275 | |
260 | |
|
|
261 | if (!new_skill) |
|
|
262 | { |
|
|
263 | if (pl->ranged_skill) |
|
|
264 | apply_special (who, pl->ranged_skill, AP_UNAPPLY); |
|
|
265 | |
|
|
266 | /* Only goal in this case was to unapply a skill */ |
276 | return 1; |
267 | return 0; |
277 | } |
268 | } |
278 | |
269 | |
279 | // move skill to front, so it will be preferred next time |
270 | // move skill to front, so it will be preferred next time |
280 | new_skill->remove (); |
271 | new_skill->remove (); |
281 | who->insert (new_skill); |
272 | who->insert (new_skill); |
282 | |
273 | |
283 | if (!new_skill || who->chosen_skill) |
|
|
284 | if (who->chosen_skill) |
|
|
285 | apply_special (who, who->chosen_skill, AP_UNAPPLY); |
|
|
286 | |
|
|
287 | /* Only goal in this case was to unapply a skill */ |
|
|
288 | if (!new_skill) |
|
|
289 | return 0; |
|
|
290 | |
|
|
291 | if (apply_special (who, new_skill, AP_APPLY)) |
274 | if (apply_special (who, new_skill, AP_APPLY)) |
292 | return 0; |
275 | return 0; |
293 | |
276 | |
294 | if (flag & 0x1) |
|
|
295 | who->contr->shoottype = (rangetype)old_range; |
|
|
296 | |
|
|
297 | return 1; |
277 | return 1; |
298 | } |
278 | } |
299 | |
279 | |
300 | /* This function just clears the chosen_skill and range_skill values |
280 | /* This function just clears the chosen_skill and range_skill values |
301 | * inthe player. |
281 | * in the player. |
302 | */ |
282 | */ |
303 | void |
283 | void |
304 | clear_skill (object *who) |
284 | clear_skill (object *who) |
305 | { |
285 | { |
306 | who->chosen_skill = NULL; |
286 | who->chosen_skill = 0; |
307 | CLEAR_FLAG (who, FLAG_READY_SKILL); |
287 | CLEAR_FLAG (who, FLAG_READY_SKILL); |
|
|
288 | |
308 | if (who->type == PLAYER) |
289 | if (who->type == PLAYER) |
309 | { |
290 | { |
|
|
291 | if (who->contr->ranged_skill && who->contr->ranged_skill->type == SKILL) |
|
|
292 | { |
310 | who->contr->ranges[range_skill] = NULL; |
293 | who->contr->ranged_skill = 0; |
311 | if (who->contr->shoottype == range_skill) |
294 | who->contr->ranged_ob = 0; |
312 | who->contr->shoottype = range_none; |
295 | } |
313 | } |
296 | } |
314 | } |
297 | } |
315 | |
298 | |
316 | /* do_skill() - Main skills use function-similar in scope to cast_spell(). |
299 | /* 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. |
300 | * We handle all requests for skill use outside of some combat here. |
… | |
… | |
569 | * op is the object that was 'defeated'. |
552 | * op is the object that was 'defeated'. |
570 | * skill is the skill used. If no skill is used, it should just |
553 | * skill is the skill used. If no skill is used, it should just |
571 | * point back to who. |
554 | * point back to who. |
572 | * |
555 | * |
573 | */ |
556 | */ |
574 | |
|
|
575 | int |
557 | int |
576 | calc_skill_exp (object *who, object *op, object *skill) |
558 | calc_skill_exp (object *who, object *op, object *skill) |
577 | { |
559 | { |
578 | int op_exp = 0, op_lvl = 0; |
560 | int op_exp = 0, op_lvl = 0; |
579 | float base, value, lvl_mult = 0.0; |
561 | float base, value, lvl_mult = 0.0; |
… | |
… | |
668 | * This one actually teaches the player the skill as something |
650 | * This one actually teaches the player the skill as something |
669 | * they can equip. |
651 | * they can equip. |
670 | * Return 0 if the player knows the skill, 1 if the |
652 | * Return 0 if the player knows the skill, 1 if the |
671 | * player learns the skill, 2 otherwise. |
653 | * player learns the skill, 2 otherwise. |
672 | */ |
654 | */ |
673 | |
|
|
674 | int |
655 | int |
675 | learn_skill (object *pl, object *scroll) |
656 | learn_skill (object *pl, object *scroll) |
676 | { |
657 | { |
677 | object *tmp; |
658 | object *tmp; |
678 | |
659 | |
… | |
… | |
875 | } |
856 | } |
876 | |
857 | |
877 | static bool |
858 | static bool |
878 | hth_skill_p (object *skill) |
859 | hth_skill_p (object *skill) |
879 | { |
860 | { |
880 | for (unsigned int i = 0; i < sizeof (unarmed_skills); ++i) |
861 | 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 | } |
862 | } |
886 | |
863 | |
887 | /* This finds the first unarmed skill the player has, and returns it. |
864 | /* This finds the first unarmed skill the player has, and returns it. |
888 | */ |
865 | */ |
889 | static object * |
866 | static object * |