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.19 by pippijn, Mon Dec 11 21:06:59 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
467 * failing that, we go and identify stuff. 472 * failing that, we go and identify stuff.
468 */ 473 */
469 for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = next) 474 for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = next)
470 { 475 {
471 next = tmp->above; 476 next = tmp->above;
477
472 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 478 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON))
473 { 479 {
474 attempt_do_alchemy (op, tmp); 480 attempt_do_alchemy (op, tmp);
481
475 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 482 if (QUERY_FLAG (tmp, FLAG_APPLIED))
476 esrv_send_inventory (op, tmp); 483 esrv_send_inventory (op, tmp);
484
477 did_alc = 1; 485 did_alc = 1;
478 } 486 }
479 } 487 }
488
480 if (did_alc == 0) 489 if (did_alc == 0)
481 exp = success = skill_ident (op, skill); 490 exp = success = skill_ident (op, skill);
491
482 break; 492 break;
483 493
484 case SK_DET_MAGIC: 494 case SK_DET_MAGIC:
485 case SK_DET_CURSE: 495 case SK_DET_CURSE:
486 exp = success = skill_ident (op, skill); 496 exp = success = skill_ident (op, skill);
691 701
692 /* player already knows it */ 702 /* player already knows it */
693 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) 703 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL))
694 return 0; 704 return 0;
695 705
696
697
698 /* now a random change to learn, based on player Int. 706 /* now a random change to learn, based on player Int.
699 * give bonus based on level - otherwise stupid characters 707 * give bonus based on level - otherwise stupid characters
700 * might never be able to learn anything. 708 * might never be able to learn anything.
701 */ 709 */
702 if (random_roll (0, 99, pl, PREFER_LOW) > (learn_spell[pl->stats.Int] + (pl->level / 5))) 710 if (random_roll (0, 99, pl, PREFER_LOW) > (learn_spell[pl->stats.Int] + (pl->level / 5)))
771 sprintf (buf, "%s%s", &tmp->name, periods); 779 sprintf (buf, "%s%s", &tmp->name, periods);
772 buf[40] = 0; 780 buf[40] = 0;
773 781
774 if (settings.permanent_exp_ratio) 782 if (settings.permanent_exp_ratio)
775 { 783 {
776 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%lld/%lld/%d%%)", 784 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%" I64_PFd "/%" I64_PFd "/%d%%)",
777 buf, tmp->level, 785 buf, tmp->level,
778 (long long) tmp->stats.exp, 786 (long long) tmp->stats.exp,
779 (long long) level_exp (tmp->level + 1, op->expmul), clipped_percent (tmp->perm_exp, tmp->stats.exp)); 787 (long long) level_exp (tmp->level + 1, op->expmul), clipped_percent (tmp->perm_exp, tmp->stats.exp));
780 } 788 }
781 else 789 else
782 { 790 {
783 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%lld/%lld)", 791 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%" I64_PFd "/%" I64_PFd ")",
784 buf, tmp->level, (long long) tmp->stats.exp, (long long) level_exp (tmp->level + 1, op->expmul)); 792 buf, tmp->level, (long long) tmp->stats.exp, (long long) level_exp (tmp->level + 1, op->expmul));
785 } 793 }
786 /* I don't know why some characters get a bunch of skills, but 794 /* I don't know why some characters get a bunch of skills, but
787 * it sometimes happens (maybe a leftover from bugier earlier code 795 * it sometimes happens (maybe a leftover from bugier earlier code
788 * and those character are still about). In any case, lets handle 796 * and those character are still about). In any case, lets handle
876 return 1; 884 return 1;
877 885
878 return 0; 886 return 0;
879} 887}
880 888
889static bool
890hth_skill_p (object *skill)
891{
892 for (unsigned int i = 0; i < sizeof (unarmed_skills); ++i)
893 if (skill->subtype == unarmed_skills[i])
894 return 1;
881 895
896 return 0;
897}
882 898
883/* This finds the best unarmed skill the player has, and returns 899/* 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 */ 900 */
897static object * 901static object *
898find_best_player_hth_skill (object *op) 902find_player_hth_skill (object *op)
899{ 903{
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) 904 for (object *tmp = op->inv; tmp; tmp = tmp->below)
904 { 905 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; 906 return tmp;
909 907
910 /* The order in the array is preferred order. So basically, 908 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} 909}
932 910
933/* do_skill_attack() - We have got an appropriate opponent from either 911/* 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 912 * 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. 913 * attacking, take care of messages from the attack and changes in invisible.
956 */ 934 */
957 if (op->type == PLAYER) 935 if (op->type == PLAYER)
958 { 936 {
959 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 937 if (!QUERY_FLAG (op, FLAG_READY_WEAPON))
960 { 938 {
961 size_t i;
962
963 if (!skill) 939 if (!skill)
964 { 940 {
965 /* See if the players chosen skill is a combat skill, and use 941 /* See if the players chosen skill is a combat skill, and use
966 * it if appropriate. 942 * it if appropriate.
967 */ 943 */
944 if (op->chosen_skill && hth_skill_p (op->chosen_skill))
968 if (op->chosen_skill) 945 skill = op->chosen_skill;
946 else
969 { 947 {
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); 948 skill = find_player_hth_skill (op);
981 949
982 if (!skill) 950 if (!skill)
983 { 951 {
984 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); 952 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!");
985 return 0; 953 return 0;
986 } 954 }
987 } 955 }
988 } 956 }
989 if (skill != op->chosen_skill) 957
990 {
991 /* now try to ready the new skill */ 958 /* now try to ready the new skill */
992 if (!change_skill (op, skill, 0)) 959 if (!change_skill (op, skill, 0))
993 { /* oh oh, trouble! */ 960 { /* oh oh, trouble! */
994 new_draw_info_format (NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name); 961 new_draw_info_format (NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name);
995 return 0; 962 return 0;
996 }
997 } 963 }
998 } 964 }
999 else 965 else
1000 { 966 {
1001 /* Seen some crashes below where current_weapon is not set, 967 /* Seen some crashes below where current_weapon is not set,
1021 { 987 {
1022 op->current_weapon = tmp; 988 op->current_weapon = tmp;
1023 } 989 }
1024 } 990 }
1025 991
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); 992 change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1);
1030 }
1031 } 993 }
1032 } 994 }
1033 995
1034 /* lose invisiblity/hiding status for running attacks */ 996 /* lose invisiblity/hiding status for running attacks */
1035 997
1075 maptile *m; 1037 maptile *m;
1076 int mflags; 1038 int mflags;
1077 1039
1078 if (!dir) 1040 if (!dir)
1079 dir = pl->facing; 1041 dir = pl->facing;
1042
1080 tx = freearr_x[dir]; 1043 tx = freearr_x[dir];
1081 ty = freearr_y[dir]; 1044 ty = freearr_y[dir];
1082 1045
1083 /* If we don't yet have an opponent, find if one exists, and attack. 1046 /* 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() 1047 * Legal opponents are the same as outlined in move_player_attack()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines