… | |
… | |
177 | } |
177 | } |
178 | |
178 | |
179 | object * |
179 | object * |
180 | find_skill_by_name_fuzzy (object *who, const char *name) |
180 | find_skill_by_name_fuzzy (object *who, const char *name) |
181 | { |
181 | { |
182 | if (!name) |
182 | if (name) |
183 | return 0; |
|
|
184 | |
|
|
185 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
183 | for (object *tmp = who->inv; tmp; tmp = tmp->below) |
186 | if ((tmp->type == SKILL || tmp->type == SKILL_TOOL) |
184 | if ((tmp->type == SKILL || tmp->type == SKILL_TOOL) |
187 | && tmp->skill.starts_with (name)) |
185 | && tmp->skill.starts_with (name)) |
188 | if (object *skop = find_skill_by_name (who, tmp->skill)) |
186 | if (object *skop = find_skill_by_name (who, tmp->skill)) |
189 | return skop; |
187 | return skop; |
190 | |
188 | |
191 | return 0; |
189 | return 0; |
192 | } |
190 | } |
193 | |
191 | |
194 | /* This returns the skill pointer of the given name (the |
192 | /* This returns the skill pointer of the given name (the |
… | |
… | |
211 | return skop; |
209 | return skop; |
212 | |
210 | |
213 | return 0; |
211 | return 0; |
214 | } |
212 | } |
215 | |
213 | |
216 | /* This changes the objects chosen_skill to new_skill. |
|
|
217 | * return 1 on success, 0 on error |
|
|
218 | */ |
|
|
219 | bool |
|
|
220 | object::change_skill (object *new_skill) |
|
|
221 | { |
|
|
222 | if (type != PLAYER) |
|
|
223 | return 0; |
|
|
224 | |
|
|
225 | // optimise this supposedly common case |
|
|
226 | if (new_skill == chosen_skill) |
|
|
227 | return 1; |
|
|
228 | |
|
|
229 | if (chosen_skill) |
|
|
230 | { |
|
|
231 | chosen_skill->flag [FLAG_APPLIED] = false; |
|
|
232 | change_abil (this, chosen_skill); |
|
|
233 | } |
|
|
234 | |
|
|
235 | chosen_skill = new_skill; |
|
|
236 | |
|
|
237 | if (chosen_skill) |
|
|
238 | { |
|
|
239 | chosen_skill->flag [FLAG_APPLIED] = true; |
|
|
240 | change_abil (this, chosen_skill); |
|
|
241 | } |
|
|
242 | |
|
|
243 | // always clear current weapon, as the selected skill could |
|
|
244 | // conflict with the current weapon skill, which would go |
|
|
245 | // undetected and exp would be given to the wrong skill. |
|
|
246 | current_weapon = 0; |
|
|
247 | |
|
|
248 | update_stats (); |
|
|
249 | return 1; |
|
|
250 | } |
|
|
251 | |
|
|
252 | /* do_skill() - Main skills use function-similar in scope to cast_spell(). |
214 | /* do_skill() - Main skills use function-similar in scope to cast_spell(). |
253 | * We handle all requests for skill use outside of some combat here. |
215 | * We handle all requests for skill use outside of some combat here. |
254 | * We require a separate routine outside of fire() so as to allow monsters |
216 | * We require a separate routine outside of fire() so as to allow monsters |
255 | * to utilize skills. Returns 1 on use of skill, otherwise 0. |
217 | * to utilize skills. Returns 1 on use of skill, otherwise 0. |
256 | * This is changed (2002-11-30) from the old method that returned |
218 | * This is changed (2002-11-30) from the old method that returned |
… | |
… | |
295 | /* Not 100% sure if this will work with new movement code - |
257 | /* Not 100% sure if this will work with new movement code - |
296 | * the levitation skill has move_type for flying, so when |
258 | * the levitation skill has move_type for flying, so when |
297 | * equipped, that should transfer to player, when not, |
259 | * equipped, that should transfer to player, when not, |
298 | * shouldn't. |
260 | * shouldn't. |
299 | */ |
261 | */ |
300 | if (QUERY_FLAG (skill, FLAG_APPLIED)) |
262 | if (skill->flag [FLAG_APPLIED]) |
301 | { |
263 | { |
302 | CLEAR_FLAG (skill, FLAG_APPLIED); |
264 | skill->clr_flag (FLAG_APPLIED); |
303 | new_draw_info (NDI_UNIQUE, 0, op, "You come to earth."); |
265 | new_draw_info (NDI_UNIQUE, 0, op, "You come to earth."); |
304 | } |
266 | } |
305 | else |
267 | else |
306 | { |
268 | { |
307 | SET_FLAG (skill, FLAG_APPLIED); |
269 | skill->set_flag (FLAG_APPLIED); |
308 | new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!"); |
270 | new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!"); |
309 | } |
271 | } |
310 | |
272 | |
311 | op->update_stats (); |
273 | op->update_stats (); |
312 | success = 1; |
274 | success = 1; |
… | |
… | |
402 | |
364 | |
403 | for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next) |
365 | for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next) |
404 | { |
366 | { |
405 | next = tmp->above; |
367 | next = tmp->above; |
406 | |
368 | |
407 | if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) |
369 | if (tmp->flag [FLAG_IS_CAULDRON]) |
408 | { |
370 | { |
409 | found_cauldron = true; |
371 | found_cauldron = true; |
410 | |
372 | |
411 | if (tmp->skill != skill->skill) |
373 | if (tmp->skill != skill->skill) |
412 | { |
374 | { |
413 | op->failmsg (format ("You can't use the %s with the %s skill!", |
375 | op->failmsgf ("You can't use the %s with the %s skill!", |
414 | query_name (tmp), |
376 | query_name (tmp), |
415 | query_name (skill))); |
377 | query_name (skill)); |
416 | break; |
378 | break; |
417 | } |
379 | } |
418 | |
380 | |
419 | attempt_do_alchemy (op, tmp, skill); |
381 | attempt_do_alchemy (op, tmp, skill); |
420 | |
382 | |
421 | if (QUERY_FLAG (tmp, FLAG_APPLIED)) |
383 | if (tmp->flag [FLAG_APPLIED]) |
422 | esrv_send_inventory (op, tmp); |
384 | esrv_send_inventory (op, tmp); |
423 | } |
385 | } |
424 | } |
386 | } |
425 | |
387 | |
426 | if (!found_cauldron) |
388 | if (!found_cauldron) |
… | |
… | |
555 | } |
517 | } |
556 | else |
518 | else |
557 | { /* all other items/living creatures */ |
519 | { /* all other items/living creatures */ |
558 | op_exp = op->stats.exp; |
520 | op_exp = op->stats.exp; |
559 | op_lvl = op->level; |
521 | op_lvl = op->level; |
560 | if (!QUERY_FLAG (op, FLAG_ALIVE)) |
522 | if (!op->flag [FLAG_ALIVE]) |
561 | op_lvl += 5 * abs (op->magic); /* for ident/make items */ |
523 | op_lvl += 5 * abs (op->magic); /* for ident/make items */ |
562 | } |
524 | } |
563 | |
525 | |
564 | if (op_lvl < 1) |
526 | if (op_lvl < 1) |
565 | op_lvl = 1; |
527 | op_lvl = 1; |
… | |
… | |
629 | } |
591 | } |
630 | |
592 | |
631 | object *tmp = find_skill (pl, scroll->skill); |
593 | object *tmp = find_skill (pl, scroll->skill); |
632 | |
594 | |
633 | /* player already knows it */ |
595 | /* player already knows it */ |
634 | if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) |
596 | if (tmp && tmp->flag [FLAG_CAN_USE_SKILL]) |
635 | return 0; |
597 | return 0; |
636 | |
598 | |
637 | /* now a random change to learn, based on player Int. |
599 | /* now a random change to learn, based on player Int. |
638 | * give bonus based on level - otherwise stupid characters |
600 | * give bonus based on level - otherwise stupid characters |
639 | * might never be able to learn anything. |
601 | * might never be able to learn anything. |
… | |
… | |
648 | { |
610 | { |
649 | LOG (llevError, "skill scroll %s does not have valid skill name (%s).\n", &scroll->name, &scroll->skill); |
611 | LOG (llevError, "skill scroll %s does not have valid skill name (%s).\n", &scroll->name, &scroll->skill); |
650 | return 2; |
612 | return 2; |
651 | } |
613 | } |
652 | |
614 | |
653 | SET_FLAG (tmp, FLAG_CAN_USE_SKILL); |
615 | tmp->set_flag (FLAG_CAN_USE_SKILL); |
654 | |
616 | |
655 | return 1; |
617 | return 1; |
656 | } |
618 | } |
657 | |
619 | |
658 | /* Gives a percentage clipped to 0% -> 100% of a/b. */ |
620 | /* Gives a percentage clipped to 0% -> 100% of a/b. */ |
… | |
… | |
777 | break; |
739 | break; |
778 | } |
740 | } |
779 | |
741 | |
780 | if (!skop) |
742 | if (!skop) |
781 | { |
743 | { |
782 | op->failmsg (format ("Unable to find skill %s.", string)); |
744 | op->failmsgf ("Unable to find skill %s.", string); |
783 | return 0; |
745 | return 0; |
784 | } |
746 | } |
785 | |
747 | |
786 | if (!(skill_flags [skop->subtype] & SF_USE)) |
748 | if (!(skill_flags [skop->subtype] & SF_USE)) |
787 | { |
749 | { |
788 | op->failmsg (format ( |
750 | op->failmsgf ( |
789 | "You feel as if you wanted to do something funny, but you can't remember what. " |
751 | "You feel as if you wanted to do something funny, but you can't remember what. " |
790 | "H<The %s skill cannot be C<use_skill>'ed - maybe you need to C<ready_skill> it, " |
752 | "H<The %s skill cannot be C<use_skill>'ed - maybe you need to C<ready_skill> it, " |
791 | "use it with some item, or it's always active.>", |
753 | "use it with some item, or it's always active.>", |
792 | &skop->skill |
754 | &skop->skill |
793 | )); |
755 | ); |
794 | return 0; |
756 | return 0; |
795 | } |
757 | } |
796 | |
758 | |
797 | len = strlen (skop->skill); |
759 | len = strlen (skop->skill); |
798 | |
760 | |
… | |
… | |
833 | */ |
795 | */ |
834 | static object * |
796 | static object * |
835 | find_player_hth_skill (object *op) |
797 | find_player_hth_skill (object *op) |
836 | { |
798 | { |
837 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
799 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
838 | if (tmp->type == SKILL && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL) && hth_skill_p (tmp)) |
800 | if (tmp->type == SKILL && tmp->flag [FLAG_CAN_USE_SKILL] && hth_skill_p (tmp)) |
839 | return tmp; |
801 | return tmp; |
840 | |
802 | |
841 | return 0; |
803 | return 0; |
842 | } |
804 | } |
843 | |
805 | |
… | |
… | |
871 | } |
833 | } |
872 | else |
834 | else |
873 | { |
835 | { |
874 | if (!pl->combat_ob) |
836 | if (!pl->combat_ob) |
875 | { |
837 | { |
876 | if (QUERY_FLAG (op, FLAG_READY_WEAPON)) |
838 | if (op->flag [FLAG_READY_WEAPON]) |
877 | { |
839 | { |
878 | for (tmp = op->inv; tmp; tmp = tmp->below) |
840 | for (tmp = op->inv; tmp; tmp = tmp->below) |
879 | if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED)) |
841 | if (tmp->type == WEAPON && tmp->flag [FLAG_APPLIED]) |
880 | break; |
842 | break; |
881 | |
843 | |
882 | if (!tmp) |
844 | if (!tmp) |
883 | LOG (llevError, "Could not find applied weapon on %s\n", &op->name); |
845 | LOG (llevError, "Could not find applied weapon on %s\n", &op->name); |
884 | |
846 | |
… | |
… | |
926 | |
888 | |
927 | int success = attack_ob (tmp, op); |
889 | int success = attack_ob (tmp, op); |
928 | |
890 | |
929 | /* print appropriate messages to the player */ |
891 | /* print appropriate messages to the player */ |
930 | |
892 | |
931 | if (success && string && tmp && !QUERY_FLAG (tmp, FLAG_FREED)) |
893 | if (success && string && tmp && !tmp->flag [FLAG_FREED]) |
932 | { |
894 | { |
933 | if (op->type == PLAYER) |
895 | if (op->type == PLAYER) |
934 | new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp)); |
896 | new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp)); |
935 | else if (tmp->type == PLAYER) |
897 | else if (tmp->type == PLAYER) |
936 | new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string); |
898 | new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string); |
… | |
… | |
979 | /* space must be blocked for there to be anything interesting to do */ |
941 | /* space must be blocked for there to be anything interesting to do */ |
980 | if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty))) |
942 | if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty))) |
981 | return 0; |
943 | return 0; |
982 | |
944 | |
983 | for (tmp = GET_MAP_OB (m, tx, ty); tmp; tmp = tmp->above) |
945 | for (tmp = GET_MAP_OB (m, tx, ty); tmp; tmp = tmp->above) |
984 | if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR) |
946 | if ((tmp->flag [FLAG_ALIVE] && tmp->stats.hp >= 0) || tmp->flag [FLAG_CAN_ROLL] || tmp->type == LOCKED_DOOR) |
985 | { |
947 | { |
986 | /* Don't attack party members */ |
948 | /* Don't attack party members */ |
987 | if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) |
949 | if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) |
988 | return 0; |
950 | return 0; |
989 | |
951 | |
… | |
… | |
1011 | static int |
973 | static int |
1012 | attack_hth (object *pl, int dir, const char *string, object *skill) |
974 | attack_hth (object *pl, int dir, const char *string, object *skill) |
1013 | { |
975 | { |
1014 | object *enemy = NULL, *weapon; |
976 | object *enemy = NULL, *weapon; |
1015 | |
977 | |
1016 | if (QUERY_FLAG (pl, FLAG_READY_WEAPON)) |
978 | if (pl->flag [FLAG_READY_WEAPON]) |
1017 | for (weapon = pl->inv; weapon; weapon = weapon->below) |
979 | for (weapon = pl->inv; weapon; weapon = weapon->below) |
1018 | { |
980 | { |
1019 | if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED)) |
981 | if (weapon->type == WEAPON && weapon->flag [FLAG_APPLIED]) |
1020 | { |
982 | { |
1021 | CLEAR_FLAG (weapon, FLAG_APPLIED); |
983 | weapon->clr_flag (FLAG_APPLIED); |
1022 | CLEAR_FLAG (pl, FLAG_READY_WEAPON); |
984 | pl->clr_flag (FLAG_READY_WEAPON); |
1023 | pl->update_stats (); |
985 | pl->update_stats (); |
1024 | if (pl->type == PLAYER) |
986 | if (pl->type == PLAYER) |
1025 | { |
987 | { |
1026 | new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); |
988 | new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); |
1027 | esrv_update_item (UPD_FLAGS, pl, weapon); |
989 | esrv_update_item (UPD_FLAGS, pl, weapon); |
… | |
… | |
1045 | */ |
1007 | */ |
1046 | static int |
1008 | static int |
1047 | attack_melee_weapon (object *op, int dir, const char *string, object *skill) |
1009 | attack_melee_weapon (object *op, int dir, const char *string, object *skill) |
1048 | { |
1010 | { |
1049 | |
1011 | |
1050 | if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) |
1012 | if (!op->flag [FLAG_READY_WEAPON]) |
1051 | { |
1013 | { |
1052 | if (op->type == PLAYER) |
1014 | if (op->type == PLAYER) |
1053 | new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!"); |
1015 | new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!"); |
1054 | |
1016 | |
1055 | return 0; |
1017 | return 0; |