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.13 by root, Sat Sep 16 22:24:13 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
691 696
692 /* player already knows it */ 697 /* player already knows it */
693 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) 698 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL))
694 return 0; 699 return 0;
695 700
696
697
698 /* now a random change to learn, based on player Int. 701 /* now a random change to learn, based on player Int.
699 * give bonus based on level - otherwise stupid characters 702 * give bonus based on level - otherwise stupid characters
700 * might never be able to learn anything. 703 * might never be able to learn anything.
701 */ 704 */
702 if (random_roll (0, 99, pl, PREFER_LOW) > (learn_spell[pl->stats.Int] + (pl->level / 5))) 705 if (random_roll (0, 99, pl, PREFER_LOW) > (learn_spell[pl->stats.Int] + (pl->level / 5)))
876 return 1; 879 return 1;
877 880
878 return 0; 881 return 0;
879} 882}
880 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;
881 890
891 return 0;
892}
882 893
883/* This finds the best unarmed skill the player has, and returns 894/* 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 */ 895 */
897static object * 896static object *
898find_best_player_hth_skill (object *op) 897find_player_hth_skill (object *op)
899{ 898{
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) 899 for (object *tmp = op->inv; tmp; tmp = tmp->below)
904 { 900 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; 901 return tmp;
909 902
910 /* The order in the array is preferred order. So basically, 903 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} 904}
932 905
933/* do_skill_attack() - We have got an appropriate opponent from either 906/* 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 907 * 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. 908 * attacking, take care of messages from the attack and changes in invisible.
956 */ 929 */
957 if (op->type == PLAYER) 930 if (op->type == PLAYER)
958 { 931 {
959 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 932 if (!QUERY_FLAG (op, FLAG_READY_WEAPON))
960 { 933 {
961 size_t i;
962
963 if (!skill) 934 if (!skill)
964 { 935 {
965 /* 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
966 * it if appropriate. 937 * it if appropriate.
967 */ 938 */
939 if (op->chosen_skill && hth_skill_p (op->chosen_skill))
968 if (op->chosen_skill) 940 skill = op->chosen_skill;
941 else
969 { 942 {
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); 943 skill = find_player_hth_skill (op);
981 944
982 if (!skill) 945 if (!skill)
983 { 946 {
984 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!");
985 return 0; 948 return 0;
986 } 949 }
987 } 950 }
988 } 951 }
989 if (skill != op->chosen_skill) 952
990 {
991 /* now try to ready the new skill */ 953 /* now try to ready the new skill */
992 if (!change_skill (op, skill, 0)) 954 if (!change_skill (op, skill, 0))
993 { /* oh oh, trouble! */ 955 { /* oh oh, trouble! */
994 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);
995 return 0; 957 return 0;
996 }
997 } 958 }
998 } 959 }
999 else 960 else
1000 { 961 {
1001 /* Seen some crashes below where current_weapon is not set, 962 /* Seen some crashes below where current_weapon is not set,
1021 { 982 {
1022 op->current_weapon = tmp; 983 op->current_weapon = tmp;
1023 } 984 }
1024 } 985 }
1025 986
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); 987 change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1);
1030 }
1031 } 988 }
1032 } 989 }
1033 990
1034 /* lose invisiblity/hiding status for running attacks */ 991 /* lose invisiblity/hiding status for running attacks */
1035 992
1075 maptile *m; 1032 maptile *m;
1076 int mflags; 1033 int mflags;
1077 1034
1078 if (!dir) 1035 if (!dir)
1079 dir = pl->facing; 1036 dir = pl->facing;
1037
1080 tx = freearr_x[dir]; 1038 tx = freearr_x[dir];
1081 ty = freearr_y[dir]; 1039 ty = freearr_y[dir];
1082 1040
1083 /* 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.
1084 * 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