ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/skill_util.C
(Generate patch)

Comparing deliantra/server/server/skill_util.C (file contents):
Revision 1.15 by root, Mon Dec 4 20:39:32 2006 UTC vs.
Revision 1.16 by root, Wed Dec 6 13:59:01 2006 UTC

48#include <spells.h> 48#include <spells.h>
49 49
50/* Table of unarmed attack skills. Terminated by -1. This 50/* Table of unarmed attack skills. Terminated by -1. This
51 * is also the list that we should try to use skills when 51 * is also the list that we should try to use skills when
52 * automatically applying one for the player. 52 * 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 */ 53 */
56static uint8 unarmed_skills[] = { 54static uint8 unarmed_skills[] = {
57 SK_KARATE, 55 SK_KARATE,
58 SK_CLAWING, 56 SK_CLAWING,
59 SK_FLAME_TOUCH, 57 SK_FLAME_TOUCH,
241 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) 239 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED))
242 { 240 {
243 if (apply_special (who, skill_tool, 0)) 241 if (apply_special (who, skill_tool, 0))
244 return NULL; 242 return NULL;
245 } 243 }
244
246 if (!skill) 245 if (!skill)
247 { 246 {
248 skill = give_skill_by_name (who, skill_tool->skill); 247 skill = give_skill_by_name (who, skill_tool->skill);
249 link_player_skills (who); 248 link_player_skills (who);
250 } 249 }
250
251 return skill; 251 return skill;
252 } 252 }
253
253 return NULL; 254 return NULL;
254} 255}
255 256
256/* This changes the objects skill to new_skill. 257/* This changes the objects skill to new_skill.
257 * note that this function doesn't always need to get used - 258 * note that this function doesn't always need to get used -
278 if (who->chosen_skill && who->chosen_skill == new_skill) 279 if (who->chosen_skill && who->chosen_skill == new_skill)
279 { 280 {
280 /* optimization for changing skill to current skill */ 281 /* optimization for changing skill to current skill */
281 if (who->type == PLAYER && !(flag & 0x1)) 282 if (who->type == PLAYER && !(flag & 0x1))
282 who->contr->shoottype = range_skill; 283 who->contr->shoottype = range_skill;
284
283 return 1; 285 return 1;
284 } 286 }
287
288 // move skill to front, so it will be preferred next time
289 new_skill->remove ();
290 who->insert (new_skill);
285 291
286 if (!new_skill || who->chosen_skill) 292 if (!new_skill || who->chosen_skill)
287 if (who->chosen_skill) 293 if (who->chosen_skill)
288 apply_special (who, who->chosen_skill, AP_UNAPPLY); 294 apply_special (who, who->chosen_skill, AP_UNAPPLY);
289 295
290 /* Only goal in this case was to unapply a skill */ 296 /* Only goal in this case was to unapply a skill */
291 if (!new_skill) 297 if (!new_skill)
292 return 0; 298 return 0;
293 299
294 if (apply_special (who, new_skill, AP_APPLY)) 300 if (apply_special (who, new_skill, AP_APPLY))
295 {
296 return 0; 301 return 0;
297 } 302
298 if (flag & 0x1) 303 if (flag & 0x1)
299 who->contr->shoottype = (rangetype) old_range; 304 who->contr->shoottype = (rangetype)old_range;
300 305
301 return 1; 306 return 1;
302} 307}
303 308
304/* This function just clears the chosen_skill and range_skill values 309/* This function just clears the chosen_skill and range_skill values
874 return 1; 879 return 1;
875 880
876 return 0; 881 return 0;
877} 882}
878 883
884static bool
885hth_skill_p (object *skill)
886{
887 for (int i = 0; i < sizeof (unarmed_skills); ++i)
888 if (skill->subtype == unarmed_skills[i])
889 return 1;
890
891 return 0;
892}
893
879/* This finds the best unarmed skill the player has, and returns 894/* This finds the first unarmed skill the player has, and returns it.
880 * it. Best can vary a little - we consider clawing to always
881 * be the best for dragons.
882 * This could be more intelligent, eg, look at the skill level
883 * of the skill and go from there (eg, a level 40 puncher is
884 * is probably better than level 1 karate). OTOH, if you
885 * don't bother to set up your skill properly, that is the players
886 * problem (although, it might be nice to have a preferred skill
887 * field the player can set.
888 * Unlike the old code, we don't give out any skills - it is
889 * possible you just don't have any ability to get into unarmed
890 * combat. If everyone race/class should have one, this should
891 * be handled in the starting treasurelists, not in the code.
892 */ 895 */
893static object * 896static object *
894find_best_player_hth_skill (object *op) 897find_player_hth_skill (object *op)
895{ 898{
896 object *tmp, *best_skill = NULL;
897 int dragon = is_dragon_pl (op), last_skill = sizeof (unarmed_skills), i;
898
899 for (tmp = op->inv; tmp; tmp = tmp->below) 899 for (object *tmp = op->inv; tmp; tmp = tmp->below)
900 { 900 if (tmp->type == SKILL && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL) && hth_skill_p (tmp))
901 if (tmp->type == SKILL)
902 {
903 if (dragon && tmp->subtype == SK_CLAWING)
904 return tmp; 901 return tmp;
905 902
906 /* The order in the array is preferred order. So basically, 903 return 0;
907 * we just cut down the number to search - eg, if we find a skill
908 * early on in flame touch, then we only need to look into the unarmed_array
909 * to the entry before flame touch - don't care about the entries afterward,
910 * because they are inferior skills.
911 */
912 for (i = 0; i < last_skill; i++)
913 if (tmp->subtype == unarmed_skills[i] && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL))
914 {
915 best_skill = tmp;
916 last_skill = i;
917 }
918 }
919 }
920
921 return best_skill;
922} 904}
923 905
924/* do_skill_attack() - We have got an appropriate opponent from either 906/* do_skill_attack() - We have got an appropriate opponent from either
925 * move_player_attack() or skill_attack(). In this part we get on with 907 * move_player_attack() or skill_attack(). In this part we get on with
926 * attacking, take care of messages from the attack and changes in invisible. 908 * attacking, take care of messages from the attack and changes in invisible.
947 */ 929 */
948 if (op->type == PLAYER) 930 if (op->type == PLAYER)
949 { 931 {
950 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 932 if (!QUERY_FLAG (op, FLAG_READY_WEAPON))
951 { 933 {
952 size_t i;
953
954 if (!skill) 934 if (!skill)
955 { 935 {
956 /* See if the players chosen skill is a combat skill, and use 936 /* See if the players chosen skill is a combat skill, and use
957 * it if appropriate. 937 * it if appropriate.
958 */ 938 */
939 if (op->chosen_skill && hth_skill_p (op->chosen_skill))
959 if (op->chosen_skill) 940 skill = op->chosen_skill;
941 else
960 { 942 {
961 for (i = 0; i < sizeof (unarmed_skills); i++)
962 if (op->chosen_skill->subtype == unarmed_skills[i])
963 {
964 skill = op->chosen_skill;
965 break;
966 }
967 }
968 /* If we didn't find a skill above, look harder for a good skill */
969 if (!skill)
970 {
971 skill = find_best_player_hth_skill (op); 943 skill = find_player_hth_skill (op);
972 944
973 if (!skill) 945 if (!skill)
974 { 946 {
975 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); 947 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!");
976 return 0; 948 return 0;
977 } 949 }
978 } 950 }
979 } 951 }
980 if (skill != op->chosen_skill) 952
981 {
982 /* now try to ready the new skill */ 953 /* now try to ready the new skill */
983 if (!change_skill (op, skill, 0)) 954 if (!change_skill (op, skill, 0))
984 { /* oh oh, trouble! */ 955 { /* oh oh, trouble! */
985 new_draw_info_format (NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name); 956 new_draw_info_format (NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name);
986 return 0; 957 return 0;
987 }
988 } 958 }
989 } 959 }
990 else 960 else
991 { 961 {
992 /* Seen some crashes below where current_weapon is not set, 962 /* Seen some crashes below where current_weapon is not set,
1012 { 982 {
1013 op->current_weapon = tmp; 983 op->current_weapon = tmp;
1014 } 984 }
1015 } 985 }
1016 986
1017 /* Has ready weapon - make sure chosen_skill is set up properly */
1018 if (!op->chosen_skill || op->current_weapon->skill != op->chosen_skill->skill)
1019 {
1020 change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1); 987 change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1);
1021 }
1022 } 988 }
1023 } 989 }
1024 990
1025 /* lose invisiblity/hiding status for running attacks */ 991 /* lose invisiblity/hiding status for running attacks */
1026 992
1066 maptile *m; 1032 maptile *m;
1067 int mflags; 1033 int mflags;
1068 1034
1069 if (!dir) 1035 if (!dir)
1070 dir = pl->facing; 1036 dir = pl->facing;
1037
1071 tx = freearr_x[dir]; 1038 tx = freearr_x[dir];
1072 ty = freearr_y[dir]; 1039 ty = freearr_y[dir];
1073 1040
1074 /* If we don't yet have an opponent, find if one exists, and attack. 1041 /* If we don't yet have an opponent, find if one exists, and attack.
1075 * Legal opponents are the same as outlined in move_player_attack() 1042 * Legal opponents are the same as outlined in move_player_attack()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines