1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
3 | |
3 | |
|
|
4 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copryight (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copryight (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | |
7 | This program is free software; you can redistribute it and/or modify |
8 | This program is free software; you can redistribute it and/or modify |
8 | 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 |
… | |
… | |
39 | |
40 | |
40 | /* #define SKILL_UTIL_DEBUG */ |
41 | /* #define SKILL_UTIL_DEBUG */ |
41 | |
42 | |
42 | #include <global.h> |
43 | #include <global.h> |
43 | #include <object.h> |
44 | #include <object.h> |
44 | #ifndef __CEXTRACT__ |
|
|
45 | # include <sproto.h> |
45 | #include <sproto.h> |
46 | #endif |
|
|
47 | #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. */ |
48 | #include <spells.h> |
47 | #include <spells.h> |
49 | |
48 | |
50 | /* Table of unarmed attack skills. Terminated by -1. This |
49 | /* Table of unarmed attack skills. Terminated by -1. This |
51 | * is also the list that we should try to use skills when |
50 | * is also the list that we should try to use skills when |
52 | * automatically applying one for the player. |
51 | * automatically applying one for the player. |
53 | * Note it is hardcoded in the skill_util.c that dragons always |
|
|
54 | * want clawing if possible. |
|
|
55 | */ |
52 | */ |
56 | static uint8 unarmed_skills[] = { |
53 | static uint8 unarmed_skills[] = { |
57 | SK_KARATE, |
54 | SK_KARATE, |
58 | SK_CLAWING, |
55 | SK_CLAWING, |
59 | SK_FLAME_TOUCH, |
56 | SK_FLAME_TOUCH, |
… | |
… | |
96 | if (!skill_names[i]) |
93 | if (!skill_names[i]) |
97 | LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i); |
94 | LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i); |
98 | } |
95 | } |
99 | } |
96 | } |
100 | |
97 | |
101 | |
|
|
102 | /* This function goes through the player inventory and sets |
98 | /* This function goes through the player inventory and sets |
103 | * up the last_skills[] array in the player object. |
99 | * up the last_skills[] array in the player object. |
104 | * the last_skills[] is used to more quickly lookup skills - |
100 | * the last_skills[] is used to more quickly lookup skills - |
105 | * mostly used for sending exp. |
101 | * mostly used for sending exp. |
106 | */ |
102 | */ |
… | |
… | |
241 | if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
237 | if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) |
242 | { |
238 | { |
243 | if (apply_special (who, skill_tool, 0)) |
239 | if (apply_special (who, skill_tool, 0)) |
244 | return NULL; |
240 | return NULL; |
245 | } |
241 | } |
|
|
242 | |
246 | if (!skill) |
243 | if (!skill) |
247 | { |
244 | { |
248 | skill = give_skill_by_name (who, skill_tool->skill); |
245 | skill = give_skill_by_name (who, skill_tool->skill); |
249 | link_player_skills (who); |
246 | link_player_skills (who); |
250 | } |
247 | } |
|
|
248 | |
251 | return skill; |
249 | return skill; |
252 | } |
250 | } |
|
|
251 | |
253 | return NULL; |
252 | return NULL; |
254 | } |
253 | } |
255 | |
254 | |
256 | /* This changes the objects skill to new_skill. |
255 | /* This changes the objects skill to new_skill. |
257 | * note that this function doesn't always need to get used - |
256 | * note that this function doesn't always need to get used - |
… | |
… | |
278 | if (who->chosen_skill && who->chosen_skill == new_skill) |
277 | if (who->chosen_skill && who->chosen_skill == new_skill) |
279 | { |
278 | { |
280 | /* optimization for changing skill to current skill */ |
279 | /* optimization for changing skill to current skill */ |
281 | if (who->type == PLAYER && !(flag & 0x1)) |
280 | if (who->type == PLAYER && !(flag & 0x1)) |
282 | who->contr->shoottype = range_skill; |
281 | who->contr->shoottype = range_skill; |
|
|
282 | |
283 | return 1; |
283 | return 1; |
284 | } |
284 | } |
|
|
285 | |
|
|
286 | // move skill to front, so it will be preferred next time |
|
|
287 | new_skill->remove (); |
|
|
288 | who->insert (new_skill); |
285 | |
289 | |
286 | if (!new_skill || who->chosen_skill) |
290 | if (!new_skill || who->chosen_skill) |
287 | if (who->chosen_skill) |
291 | if (who->chosen_skill) |
288 | apply_special (who, who->chosen_skill, AP_UNAPPLY); |
292 | apply_special (who, who->chosen_skill, AP_UNAPPLY); |
289 | |
293 | |
290 | /* Only goal in this case was to unapply a skill */ |
294 | /* Only goal in this case was to unapply a skill */ |
291 | if (!new_skill) |
295 | if (!new_skill) |
292 | return 0; |
296 | return 0; |
293 | |
297 | |
294 | if (apply_special (who, new_skill, AP_APPLY)) |
298 | if (apply_special (who, new_skill, AP_APPLY)) |
295 | { |
|
|
296 | return 0; |
299 | return 0; |
297 | } |
300 | |
298 | if (flag & 0x1) |
301 | if (flag & 0x1) |
299 | who->contr->shoottype = (rangetype) old_range; |
302 | who->contr->shoottype = (rangetype)old_range; |
300 | |
303 | |
301 | return 1; |
304 | return 1; |
302 | } |
305 | } |
303 | |
306 | |
304 | /* This function just clears the chosen_skill and range_skill values |
307 | /* This function just clears the chosen_skill and range_skill values |
… | |
… | |
375 | else |
378 | else |
376 | { |
379 | { |
377 | SET_FLAG (skill, FLAG_APPLIED); |
380 | SET_FLAG (skill, FLAG_APPLIED); |
378 | new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!."); |
381 | new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!."); |
379 | } |
382 | } |
380 | fix_player (op); |
383 | op->update_stats (); |
381 | success = 1; |
384 | success = 1; |
382 | break; |
385 | break; |
383 | |
386 | |
384 | case SK_STEALING: |
387 | case SK_STEALING: |
385 | exp = success = steal (op, dir, skill); |
388 | exp = success = steal (op, dir, skill); |
… | |
… | |
464 | case SK_LITERACY: |
467 | case SK_LITERACY: |
465 | case SK_WOODSMAN: |
468 | case SK_WOODSMAN: |
466 | /* first, we try to find a cauldron, and do the alchemy thing. |
469 | /* first, we try to find a cauldron, and do the alchemy thing. |
467 | * failing that, we go and identify stuff. |
470 | * failing that, we go and identify stuff. |
468 | */ |
471 | */ |
469 | for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = next) |
472 | for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = next) |
470 | { |
473 | { |
471 | next = tmp->above; |
474 | next = tmp->above; |
|
|
475 | |
472 | if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) |
476 | if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) |
473 | { |
477 | { |
474 | attempt_do_alchemy (op, tmp); |
478 | attempt_do_alchemy (op, tmp); |
|
|
479 | |
475 | if (QUERY_FLAG (tmp, FLAG_APPLIED)) |
480 | if (QUERY_FLAG (tmp, FLAG_APPLIED)) |
476 | esrv_send_inventory (op, tmp); |
481 | esrv_send_inventory (op, tmp); |
|
|
482 | |
477 | did_alc = 1; |
483 | did_alc = 1; |
478 | } |
484 | } |
479 | } |
485 | } |
|
|
486 | |
480 | if (did_alc == 0) |
487 | if (did_alc == 0) |
481 | exp = success = skill_ident (op, skill); |
488 | exp = success = skill_ident (op, skill); |
|
|
489 | |
482 | break; |
490 | break; |
483 | |
491 | |
484 | case SK_DET_MAGIC: |
492 | case SK_DET_MAGIC: |
485 | case SK_DET_CURSE: |
493 | case SK_DET_CURSE: |
486 | exp = success = skill_ident (op, skill); |
494 | exp = success = skill_ident (op, skill); |
… | |
… | |
691 | |
699 | |
692 | /* player already knows it */ |
700 | /* player already knows it */ |
693 | if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) |
701 | if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) |
694 | return 0; |
702 | return 0; |
695 | |
703 | |
696 | |
|
|
697 | |
|
|
698 | /* now a random change to learn, based on player Int. |
704 | /* now a random change to learn, based on player Int. |
699 | * give bonus based on level - otherwise stupid characters |
705 | * give bonus based on level - otherwise stupid characters |
700 | * might never be able to learn anything. |
706 | * might never be able to learn anything. |
701 | */ |
707 | */ |
702 | if (random_roll (0, 99, pl, PREFER_LOW) > (learn_spell[pl->stats.Int] + (pl->level / 5))) |
708 | if (random_roll (0, 99, pl, PREFER_LOW) > (learn_spell[pl->stats.Int] + (pl->level / 5))) |
… | |
… | |
771 | sprintf (buf, "%s%s", &tmp->name, periods); |
777 | sprintf (buf, "%s%s", &tmp->name, periods); |
772 | buf[40] = 0; |
778 | buf[40] = 0; |
773 | |
779 | |
774 | if (settings.permanent_exp_ratio) |
780 | if (settings.permanent_exp_ratio) |
775 | { |
781 | { |
776 | sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%lld/%lld/%d%%)", |
782 | sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%" PRId64 "/%" PRId64 "/%d%%)", |
777 | buf, tmp->level, |
783 | buf, tmp->level, tmp->stats.exp, |
778 | (long long) tmp->stats.exp, |
|
|
779 | (long long) level_exp (tmp->level + 1, op->expmul), clipped_percent (tmp->perm_exp, tmp->stats.exp)); |
784 | level_exp (tmp->level + 1, op->expmul), clipped_percent (tmp->perm_exp, tmp->stats.exp)); |
780 | } |
785 | } |
781 | else |
786 | else |
782 | { |
787 | { |
783 | sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%lld/%lld)", |
788 | sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%" PRId64 "/%" PRId64 ")", |
784 | buf, tmp->level, (long long) tmp->stats.exp, (long long) level_exp (tmp->level + 1, op->expmul)); |
789 | buf, tmp->level, tmp->stats.exp, level_exp (tmp->level + 1, op->expmul)); |
785 | } |
790 | } |
786 | /* I don't know why some characters get a bunch of skills, but |
791 | /* I don't know why some characters get a bunch of skills, but |
787 | * it sometimes happens (maybe a leftover from bugier earlier code |
792 | * it sometimes happens (maybe a leftover from bugier earlier code |
788 | * and those character are still about). In any case, lets handle |
793 | * and those character are still about). In any case, lets handle |
789 | * it so it doesn't crash the server - otherwise, one character may |
794 | * it so it doesn't crash the server - otherwise, one character may |
… | |
… | |
876 | return 1; |
881 | return 1; |
877 | |
882 | |
878 | return 0; |
883 | return 0; |
879 | } |
884 | } |
880 | |
885 | |
|
|
886 | static bool |
|
|
887 | hth_skill_p (object *skill) |
|
|
888 | { |
|
|
889 | for (unsigned int i = 0; i < sizeof (unarmed_skills); ++i) |
|
|
890 | if (skill->subtype == unarmed_skills[i]) |
|
|
891 | return 1; |
881 | |
892 | |
|
|
893 | return 0; |
|
|
894 | } |
882 | |
895 | |
883 | /* This finds the best unarmed skill the player has, and returns |
896 | /* This finds the first unarmed skill the player has, and returns it. |
884 | * it. Best can vary a little - we consider clawing to always |
|
|
885 | * be the best for dragons. |
|
|
886 | * This could be more intelligent, eg, look at the skill level |
|
|
887 | * of the skill and go from there (eg, a level 40 puncher is |
|
|
888 | * is probably better than level 1 karate). OTOH, if you |
|
|
889 | * don't bother to set up your skill properly, that is the players |
|
|
890 | * problem (although, it might be nice to have a preferred skill |
|
|
891 | * field the player can set. |
|
|
892 | * Unlike the old code, we don't give out any skills - it is |
|
|
893 | * possible you just don't have any ability to get into unarmed |
|
|
894 | * combat. If everyone race/class should have one, this should |
|
|
895 | * be handled in the starting treasurelists, not in the code. |
|
|
896 | */ |
897 | */ |
897 | static object * |
898 | static object * |
898 | find_best_player_hth_skill (object *op) |
899 | find_player_hth_skill (object *op) |
899 | { |
900 | { |
900 | object *tmp, *best_skill = NULL; |
|
|
901 | int dragon = is_dragon_pl (op), last_skill = sizeof (unarmed_skills), i; |
|
|
902 | |
|
|
903 | for (tmp = op->inv; tmp; tmp = tmp->below) |
901 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
904 | { |
902 | if (tmp->type == SKILL && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL) && hth_skill_p (tmp)) |
905 | if (tmp->type == SKILL) |
|
|
906 | { |
|
|
907 | if (dragon && tmp->subtype == SK_CLAWING) |
|
|
908 | return tmp; |
903 | return tmp; |
909 | |
904 | |
910 | /* The order in the array is preferred order. So basically, |
905 | return 0; |
911 | * we just cut down the number to search - eg, if we find a skill |
|
|
912 | * early on in flame touch, then we only need to look into the unarmed_array |
|
|
913 | * to the entry before flame touch - don't care about the entries afterward, |
|
|
914 | * because they are infrerior skills. |
|
|
915 | * if we end up finding the best skill (i==0) might as well return |
|
|
916 | * right away - can't get any better than that. |
|
|
917 | */ |
|
|
918 | for (i = 0; i < last_skill; i++) |
|
|
919 | { |
|
|
920 | if (tmp->subtype == unarmed_skills[i] && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) |
|
|
921 | { |
|
|
922 | best_skill = tmp; |
|
|
923 | last_skill = i; |
|
|
924 | if (i == 0) |
|
|
925 | return best_skill; |
|
|
926 | } |
|
|
927 | } |
|
|
928 | } |
|
|
929 | } |
|
|
930 | return best_skill; |
|
|
931 | } |
906 | } |
932 | |
907 | |
933 | /* do_skill_attack() - We have got an appropriate opponent from either |
908 | /* do_skill_attack() - We have got an appropriate opponent from either |
934 | * move_player_attack() or skill_attack(). In this part we get on with |
909 | * move_player_attack() or skill_attack(). In this part we get on with |
935 | * attacking, take care of messages from the attack and changes in invisible. |
910 | * attacking, take care of messages from the attack and changes in invisible. |
… | |
… | |
956 | */ |
931 | */ |
957 | if (op->type == PLAYER) |
932 | if (op->type == PLAYER) |
958 | { |
933 | { |
959 | if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) |
934 | if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) |
960 | { |
935 | { |
961 | size_t i; |
|
|
962 | |
|
|
963 | if (!skill) |
936 | if (!skill) |
964 | { |
937 | { |
965 | /* See if the players chosen skill is a combat skill, and use |
938 | /* See if the players chosen skill is a combat skill, and use |
966 | * it if appropriate. |
939 | * it if appropriate. |
967 | */ |
940 | */ |
|
|
941 | if (op->chosen_skill && hth_skill_p (op->chosen_skill)) |
968 | if (op->chosen_skill) |
942 | skill = op->chosen_skill; |
|
|
943 | else |
969 | { |
944 | { |
970 | for (i = 0; i < sizeof (unarmed_skills); i++) |
|
|
971 | if (op->chosen_skill->subtype == unarmed_skills[i]) |
|
|
972 | { |
|
|
973 | skill = op->chosen_skill; |
|
|
974 | break; |
|
|
975 | } |
|
|
976 | } |
|
|
977 | /* If we didn't find a skill above, look harder for a good skill */ |
|
|
978 | if (!skill) |
|
|
979 | { |
|
|
980 | skill = find_best_player_hth_skill (op); |
945 | skill = find_player_hth_skill (op); |
981 | |
946 | |
982 | if (!skill) |
947 | if (!skill) |
983 | { |
948 | { |
984 | new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); |
949 | new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); |
985 | return 0; |
950 | return 0; |
986 | } |
951 | } |
987 | } |
952 | } |
988 | } |
953 | } |
989 | if (skill != op->chosen_skill) |
954 | |
990 | { |
|
|
991 | /* now try to ready the new skill */ |
955 | /* now try to ready the new skill */ |
992 | if (!change_skill (op, skill, 0)) |
956 | if (!change_skill (op, skill, 0)) |
993 | { /* oh oh, trouble! */ |
957 | { /* oh oh, trouble! */ |
994 | new_draw_info_format (NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name); |
958 | new_draw_info_format (NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name); |
995 | return 0; |
959 | return 0; |
996 | } |
|
|
997 | } |
960 | } |
998 | } |
961 | } |
999 | else |
962 | else |
1000 | { |
963 | { |
1001 | /* Seen some crashes below where current_weapon is not set, |
964 | /* Seen some crashes below where current_weapon is not set, |
… | |
… | |
1021 | { |
984 | { |
1022 | op->current_weapon = tmp; |
985 | op->current_weapon = tmp; |
1023 | } |
986 | } |
1024 | } |
987 | } |
1025 | |
988 | |
1026 | /* Has ready weapon - make sure chosen_skill is set up properly */ |
|
|
1027 | if (!op->chosen_skill || op->current_weapon->skill != op->chosen_skill->skill) |
|
|
1028 | { |
|
|
1029 | change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1); |
989 | change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1); |
1030 | } |
|
|
1031 | } |
990 | } |
1032 | } |
991 | } |
1033 | |
992 | |
1034 | /* lose invisiblity/hiding status for running attacks */ |
993 | /* lose invisiblity/hiding status for running attacks */ |
1035 | |
994 | |
… | |
… | |
1075 | maptile *m; |
1034 | maptile *m; |
1076 | int mflags; |
1035 | int mflags; |
1077 | |
1036 | |
1078 | if (!dir) |
1037 | if (!dir) |
1079 | dir = pl->facing; |
1038 | dir = pl->facing; |
|
|
1039 | |
1080 | tx = freearr_x[dir]; |
1040 | tx = freearr_x[dir]; |
1081 | ty = freearr_y[dir]; |
1041 | ty = freearr_y[dir]; |
1082 | |
1042 | |
1083 | /* If we don't yet have an opponent, find if one exists, and attack. |
1043 | /* If we don't yet have an opponent, find if one exists, and attack. |
1084 | * Legal opponents are the same as outlined in move_player_attack() |
1044 | * Legal opponents are the same as outlined in move_player_attack() |
… | |
… | |
1096 | |
1056 | |
1097 | /* space must be blocked for there to be anything interesting to do */ |
1057 | /* space must be blocked for there to be anything interesting to do */ |
1098 | if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty))) |
1058 | if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty))) |
1099 | return 0; |
1059 | return 0; |
1100 | |
1060 | |
1101 | for (tmp = get_map_ob (m, tx, ty); tmp; tmp = tmp->above) |
1061 | for (tmp = GET_MAP_OB (m, tx, ty); tmp; tmp = tmp->above) |
1102 | if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR) |
1062 | if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR) |
1103 | { |
1063 | { |
1104 | /* Don't attack party members */ |
1064 | /* Don't attack party members */ |
1105 | if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) |
1065 | if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) |
1106 | return 0; |
1066 | return 0; |
… | |
… | |
1135 | { |
1095 | { |
1136 | if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED)) |
1096 | if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED)) |
1137 | { |
1097 | { |
1138 | CLEAR_FLAG (weapon, FLAG_APPLIED); |
1098 | CLEAR_FLAG (weapon, FLAG_APPLIED); |
1139 | CLEAR_FLAG (pl, FLAG_READY_WEAPON); |
1099 | CLEAR_FLAG (pl, FLAG_READY_WEAPON); |
1140 | fix_player (pl); |
1100 | pl->update_stats (); |
1141 | if (pl->type == PLAYER) |
1101 | if (pl->type == PLAYER) |
1142 | { |
1102 | { |
1143 | new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); |
1103 | new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); |
1144 | esrv_update_item (UPD_FLAGS, pl, weapon); |
1104 | esrv_update_item (UPD_FLAGS, pl, weapon); |
1145 | } |
1105 | } |