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.22 by root, Fri Dec 22 16:34:00 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,
96 if (!skill_names[i]) 94 if (!skill_names[i])
97 LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i); 95 LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i);
98 } 96 }
99} 97}
100 98
101
102/* This function goes through the player inventory and sets 99/* This function goes through the player inventory and sets
103 * up the last_skills[] array in the player object. 100 * up the last_skills[] array in the player object.
104 * the last_skills[] is used to more quickly lookup skills - 101 * the last_skills[] is used to more quickly lookup skills -
105 * mostly used for sending exp. 102 * mostly used for sending exp.
106 */ 103 */
241 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) 238 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED))
242 { 239 {
243 if (apply_special (who, skill_tool, 0)) 240 if (apply_special (who, skill_tool, 0))
244 return NULL; 241 return NULL;
245 } 242 }
243
246 if (!skill) 244 if (!skill)
247 { 245 {
248 skill = give_skill_by_name (who, skill_tool->skill); 246 skill = give_skill_by_name (who, skill_tool->skill);
249 link_player_skills (who); 247 link_player_skills (who);
250 } 248 }
249
251 return skill; 250 return skill;
252 } 251 }
252
253 return NULL; 253 return NULL;
254} 254}
255 255
256/* This changes the objects skill to new_skill. 256/* This changes the objects skill to new_skill.
257 * note that this function doesn't always need to get used - 257 * note that this function doesn't always need to get used -
278 if (who->chosen_skill && who->chosen_skill == new_skill) 278 if (who->chosen_skill && who->chosen_skill == new_skill)
279 { 279 {
280 /* optimization for changing skill to current skill */ 280 /* optimization for changing skill to current skill */
281 if (who->type == PLAYER && !(flag & 0x1)) 281 if (who->type == PLAYER && !(flag & 0x1))
282 who->contr->shoottype = range_skill; 282 who->contr->shoottype = range_skill;
283
283 return 1; 284 return 1;
284 } 285 }
286
287 // move skill to front, so it will be preferred next time
288 new_skill->remove ();
289 who->insert (new_skill);
285 290
286 if (!new_skill || who->chosen_skill) 291 if (!new_skill || who->chosen_skill)
287 if (who->chosen_skill) 292 if (who->chosen_skill)
288 apply_special (who, who->chosen_skill, AP_UNAPPLY); 293 apply_special (who, who->chosen_skill, AP_UNAPPLY);
289 294
290 /* Only goal in this case was to unapply a skill */ 295 /* Only goal in this case was to unapply a skill */
291 if (!new_skill) 296 if (!new_skill)
292 return 0; 297 return 0;
293 298
294 if (apply_special (who, new_skill, AP_APPLY)) 299 if (apply_special (who, new_skill, AP_APPLY))
295 {
296 return 0; 300 return 0;
297 } 301
298 if (flag & 0x1) 302 if (flag & 0x1)
299 who->contr->shoottype = (rangetype) old_range; 303 who->contr->shoottype = (rangetype)old_range;
300 304
301 return 1; 305 return 1;
302} 306}
303 307
304/* This function just clears the chosen_skill and range_skill values 308/* This function just clears the chosen_skill and range_skill values
375 else 379 else
376 { 380 {
377 SET_FLAG (skill, FLAG_APPLIED); 381 SET_FLAG (skill, FLAG_APPLIED);
378 new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!."); 382 new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!.");
379 } 383 }
380 fix_player (op); 384 op->update_stats ();
381 success = 1; 385 success = 1;
382 break; 386 break;
383 387
384 case SK_STEALING: 388 case SK_STEALING:
385 exp = success = steal (op, dir, skill); 389 exp = success = steal (op, dir, skill);
464 case SK_LITERACY: 468 case SK_LITERACY:
465 case SK_WOODSMAN: 469 case SK_WOODSMAN:
466 /* first, we try to find a cauldron, and do the alchemy thing. 470 /* first, we try to find a cauldron, and do the alchemy thing.
467 * failing that, we go and identify stuff. 471 * failing that, we go and identify stuff.
468 */ 472 */
469 for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = next) 473 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = next)
470 { 474 {
471 next = tmp->above; 475 next = tmp->above;
476
472 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 477 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON))
473 { 478 {
474 attempt_do_alchemy (op, tmp); 479 attempt_do_alchemy (op, tmp);
480
475 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 481 if (QUERY_FLAG (tmp, FLAG_APPLIED))
476 esrv_send_inventory (op, tmp); 482 esrv_send_inventory (op, tmp);
483
477 did_alc = 1; 484 did_alc = 1;
478 } 485 }
479 } 486 }
487
480 if (did_alc == 0) 488 if (did_alc == 0)
481 exp = success = skill_ident (op, skill); 489 exp = success = skill_ident (op, skill);
490
482 break; 491 break;
483 492
484 case SK_DET_MAGIC: 493 case SK_DET_MAGIC:
485 case SK_DET_CURSE: 494 case SK_DET_CURSE:
486 exp = success = skill_ident (op, skill); 495 exp = success = skill_ident (op, skill);
691 700
692 /* player already knows it */ 701 /* player already knows it */
693 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) 702 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL))
694 return 0; 703 return 0;
695 704
696
697
698 /* now a random change to learn, based on player Int. 705 /* now a random change to learn, based on player Int.
699 * give bonus based on level - otherwise stupid characters 706 * give bonus based on level - otherwise stupid characters
700 * might never be able to learn anything. 707 * might never be able to learn anything.
701 */ 708 */
702 if (random_roll (0, 99, pl, PREFER_LOW) > (learn_spell[pl->stats.Int] + (pl->level / 5))) 709 if (random_roll (0, 99, pl, PREFER_LOW) > (learn_spell[pl->stats.Int] + (pl->level / 5)))
771 sprintf (buf, "%s%s", &tmp->name, periods); 778 sprintf (buf, "%s%s", &tmp->name, periods);
772 buf[40] = 0; 779 buf[40] = 0;
773 780
774 if (settings.permanent_exp_ratio) 781 if (settings.permanent_exp_ratio)
775 { 782 {
776 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%lld/%lld/%d%%)", 783 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%" PRId64 "/%" PRId64 "/%d%%)",
777 buf, tmp->level, 784 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)); 785 level_exp (tmp->level + 1, op->expmul), clipped_percent (tmp->perm_exp, tmp->stats.exp));
780 } 786 }
781 else 787 else
782 { 788 {
783 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%lld/%lld)", 789 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)); 790 buf, tmp->level, tmp->stats.exp, level_exp (tmp->level + 1, op->expmul));
785 } 791 }
786 /* I don't know why some characters get a bunch of skills, but 792 /* I don't know why some characters get a bunch of skills, but
787 * it sometimes happens (maybe a leftover from bugier earlier code 793 * it sometimes happens (maybe a leftover from bugier earlier code
788 * and those character are still about). In any case, lets handle 794 * and those character are still about). In any case, lets handle
789 * it so it doesn't crash the server - otherwise, one character may 795 * it so it doesn't crash the server - otherwise, one character may
876 return 1; 882 return 1;
877 883
878 return 0; 884 return 0;
879} 885}
880 886
887static bool
888hth_skill_p (object *skill)
889{
890 for (unsigned int i = 0; i < sizeof (unarmed_skills); ++i)
891 if (skill->subtype == unarmed_skills[i])
892 return 1;
881 893
894 return 0;
895}
882 896
883/* This finds the best unarmed skill the player has, and returns 897/* 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 */ 898 */
897static object * 899static object *
898find_best_player_hth_skill (object *op) 900find_player_hth_skill (object *op)
899{ 901{
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) 902 for (object *tmp = op->inv; tmp; tmp = tmp->below)
904 { 903 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; 904 return tmp;
909 905
910 /* The order in the array is preferred order. So basically, 906 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} 907}
932 908
933/* do_skill_attack() - We have got an appropriate opponent from either 909/* 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 910 * 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. 911 * attacking, take care of messages from the attack and changes in invisible.
956 */ 932 */
957 if (op->type == PLAYER) 933 if (op->type == PLAYER)
958 { 934 {
959 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 935 if (!QUERY_FLAG (op, FLAG_READY_WEAPON))
960 { 936 {
961 size_t i;
962
963 if (!skill) 937 if (!skill)
964 { 938 {
965 /* See if the players chosen skill is a combat skill, and use 939 /* See if the players chosen skill is a combat skill, and use
966 * it if appropriate. 940 * it if appropriate.
967 */ 941 */
942 if (op->chosen_skill && hth_skill_p (op->chosen_skill))
968 if (op->chosen_skill) 943 skill = op->chosen_skill;
944 else
969 { 945 {
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); 946 skill = find_player_hth_skill (op);
981 947
982 if (!skill) 948 if (!skill)
983 { 949 {
984 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); 950 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!");
985 return 0; 951 return 0;
986 } 952 }
987 } 953 }
988 } 954 }
989 if (skill != op->chosen_skill) 955
990 {
991 /* now try to ready the new skill */ 956 /* now try to ready the new skill */
992 if (!change_skill (op, skill, 0)) 957 if (!change_skill (op, skill, 0))
993 { /* oh oh, trouble! */ 958 { /* oh oh, trouble! */
994 new_draw_info_format (NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name); 959 new_draw_info_format (NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name);
995 return 0; 960 return 0;
996 }
997 } 961 }
998 } 962 }
999 else 963 else
1000 { 964 {
1001 /* Seen some crashes below where current_weapon is not set, 965 /* Seen some crashes below where current_weapon is not set,
1021 { 985 {
1022 op->current_weapon = tmp; 986 op->current_weapon = tmp;
1023 } 987 }
1024 } 988 }
1025 989
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); 990 change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1);
1030 }
1031 } 991 }
1032 } 992 }
1033 993
1034 /* lose invisiblity/hiding status for running attacks */ 994 /* lose invisiblity/hiding status for running attacks */
1035 995
1075 maptile *m; 1035 maptile *m;
1076 int mflags; 1036 int mflags;
1077 1037
1078 if (!dir) 1038 if (!dir)
1079 dir = pl->facing; 1039 dir = pl->facing;
1040
1080 tx = freearr_x[dir]; 1041 tx = freearr_x[dir];
1081 ty = freearr_y[dir]; 1042 ty = freearr_y[dir];
1082 1043
1083 /* If we don't yet have an opponent, find if one exists, and attack. 1044 /* 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() 1045 * Legal opponents are the same as outlined in move_player_attack()
1096 1057
1097 /* space must be blocked for there to be anything interesting to do */ 1058 /* 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))) 1059 if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty)))
1099 return 0; 1060 return 0;
1100 1061
1101 for (tmp = get_map_ob (m, tx, ty); tmp; tmp = tmp->above) 1062 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) 1063 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR)
1103 { 1064 {
1104 /* Don't attack party members */ 1065 /* Don't attack party members */
1105 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) 1066 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party))
1106 return 0; 1067 return 0;
1135 { 1096 {
1136 if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED)) 1097 if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED))
1137 { 1098 {
1138 CLEAR_FLAG (weapon, FLAG_APPLIED); 1099 CLEAR_FLAG (weapon, FLAG_APPLIED);
1139 CLEAR_FLAG (pl, FLAG_READY_WEAPON); 1100 CLEAR_FLAG (pl, FLAG_READY_WEAPON);
1140 fix_player (pl); 1101 pl->update_stats ();
1141 if (pl->type == PLAYER) 1102 if (pl->type == PLAYER)
1142 { 1103 {
1143 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); 1104 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack.");
1144 esrv_update_item (UPD_FLAGS, pl, weapon); 1105 esrv_update_item (UPD_FLAGS, pl, weapon);
1145 } 1106 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines