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.91 by root, Tue Apr 6 00:39:26 2010 UTC vs.
Revision 1.94 by root, Sun Apr 11 00:34:06 2010 UTC

209 return skop; 209 return skop;
210 210
211 return 0; 211 return 0;
212} 212}
213 213
214/* This changes the objects chosen_skill to new_skill.
215 * return 1 on success, 0 on error
216 */
217bool
218object::change_skill (object *new_skill)
219{
220 if (type != PLAYER)
221 return 0;
222
223 // optimise this supposedly common case
224 if (new_skill == chosen_skill)
225 return 1;
226
227 if (chosen_skill)
228 {
229 chosen_skill->flag [FLAG_APPLIED] = false;
230 change_abil (this, chosen_skill);
231 }
232
233 chosen_skill = new_skill;
234
235 if (chosen_skill)
236 {
237 chosen_skill->flag [FLAG_APPLIED] = true;
238 change_abil (this, chosen_skill);
239 }
240
241 // always clear current weapon, as the selected skill could
242 // conflict with the current weapon skill, which would go
243 // undetected and exp would be given to the wrong skill.
244 current_weapon = 0;
245
246 update_stats ();
247 return 1;
248}
249
250/* do_skill() - Main skills use function-similar in scope to cast_spell(). 214/* do_skill() - Main skills use function-similar in scope to cast_spell().
251 * We handle all requests for skill use outside of some combat here. 215 * We handle all requests for skill use outside of some combat here.
252 * We require a separate routine outside of fire() so as to allow monsters 216 * We require a separate routine outside of fire() so as to allow monsters
253 * to utilize skills. Returns 1 on use of skill, otherwise 0. 217 * to utilize skills. Returns 1 on use of skill, otherwise 0.
254 * This is changed (2002-11-30) from the old method that returned 218 * This is changed (2002-11-30) from the old method that returned
293 /* Not 100% sure if this will work with new movement code - 257 /* Not 100% sure if this will work with new movement code -
294 * the levitation skill has move_type for flying, so when 258 * the levitation skill has move_type for flying, so when
295 * equipped, that should transfer to player, when not, 259 * equipped, that should transfer to player, when not,
296 * shouldn't. 260 * shouldn't.
297 */ 261 */
298 if (QUERY_FLAG (skill, FLAG_APPLIED)) 262 if (skill->flag [FLAG_APPLIED])
299 { 263 {
300 CLEAR_FLAG (skill, FLAG_APPLIED); 264 skill->clr_flag (FLAG_APPLIED);
301 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth."); 265 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth.");
302 } 266 }
303 else 267 else
304 { 268 {
305 SET_FLAG (skill, FLAG_APPLIED); 269 skill->set_flag (FLAG_APPLIED);
306 new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!"); 270 new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!");
307 } 271 }
308 272
309 op->update_stats (); 273 op->update_stats ();
310 success = 1; 274 success = 1;
400 364
401 for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next) 365 for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next)
402 { 366 {
403 next = tmp->above; 367 next = tmp->above;
404 368
405 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 369 if (tmp->flag [FLAG_IS_CAULDRON])
406 { 370 {
407 found_cauldron = true; 371 found_cauldron = true;
408 372
409 if (tmp->skill != skill->skill) 373 if (tmp->skill != skill->skill)
410 { 374 {
411 op->failmsg (format ("You can't use the %s with the %s skill!", 375 op->failmsgf ("You can't use the %s with the %s skill!",
412 query_name (tmp), 376 query_name (tmp),
413 query_name (skill))); 377 query_name (skill));
414 break; 378 break;
415 } 379 }
416 380
417 attempt_do_alchemy (op, tmp, skill); 381 attempt_do_alchemy (op, tmp, skill);
418 382
419 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 383 if (tmp->flag [FLAG_APPLIED])
420 esrv_send_inventory (op, tmp); 384 esrv_send_inventory (op, tmp);
421 } 385 }
422 } 386 }
423 387
424 if (!found_cauldron) 388 if (!found_cauldron)
553 } 517 }
554 else 518 else
555 { /* all other items/living creatures */ 519 { /* all other items/living creatures */
556 op_exp = op->stats.exp; 520 op_exp = op->stats.exp;
557 op_lvl = op->level; 521 op_lvl = op->level;
558 if (!QUERY_FLAG (op, FLAG_ALIVE)) 522 if (!op->flag [FLAG_ALIVE])
559 op_lvl += 5 * abs (op->magic); /* for ident/make items */ 523 op_lvl += 5 * abs (op->magic); /* for ident/make items */
560 } 524 }
561 525
562 if (op_lvl < 1) 526 if (op_lvl < 1)
563 op_lvl = 1; 527 op_lvl = 1;
627 } 591 }
628 592
629 object *tmp = find_skill (pl, scroll->skill); 593 object *tmp = find_skill (pl, scroll->skill);
630 594
631 /* player already knows it */ 595 /* player already knows it */
632 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) 596 if (tmp && tmp->flag [FLAG_CAN_USE_SKILL])
633 return 0; 597 return 0;
634 598
635 /* now a random change to learn, based on player Int. 599 /* now a random change to learn, based on player Int.
636 * give bonus based on level - otherwise stupid characters 600 * give bonus based on level - otherwise stupid characters
637 * might never be able to learn anything. 601 * might never be able to learn anything.
646 { 610 {
647 LOG (llevError, "skill scroll %s does not have valid skill name (%s).\n", &scroll->name, &scroll->skill); 611 LOG (llevError, "skill scroll %s does not have valid skill name (%s).\n", &scroll->name, &scroll->skill);
648 return 2; 612 return 2;
649 } 613 }
650 614
651 SET_FLAG (tmp, FLAG_CAN_USE_SKILL); 615 tmp->set_flag (FLAG_CAN_USE_SKILL);
652 616
653 return 1; 617 return 1;
654} 618}
655 619
656/* Gives a percentage clipped to 0% -> 100% of a/b. */ 620/* Gives a percentage clipped to 0% -> 100% of a/b. */
775 break; 739 break;
776 } 740 }
777 741
778 if (!skop) 742 if (!skop)
779 { 743 {
780 op->failmsg (format ("Unable to find skill %s.", string)); 744 op->failmsgf ("Unable to find skill %s.", string);
781 return 0; 745 return 0;
782 } 746 }
783 747
784 if (!(skill_flags [skop->subtype] & SF_USE)) 748 if (!(skill_flags [skop->subtype] & SF_USE))
785 { 749 {
786 op->failmsg (format ( 750 op->failmsgf (
787 "You feel as if you wanted to do something funny, but you can't remember what. " 751 "You feel as if you wanted to do something funny, but you can't remember what. "
788 "H<The %s skill cannot be C<use_skill>'ed - maybe you need to C<ready_skill> it, " 752 "H<The %s skill cannot be C<use_skill>'ed - maybe you need to C<ready_skill> it, "
789 "use it with some item, or it's always active.>", 753 "use it with some item, or it's always active.>",
790 &skop->skill 754 &skop->skill
791 )); 755 );
792 return 0; 756 return 0;
793 } 757 }
794 758
795 len = strlen (skop->skill); 759 len = strlen (skop->skill);
796 760
831 */ 795 */
832static object * 796static object *
833find_player_hth_skill (object *op) 797find_player_hth_skill (object *op)
834{ 798{
835 for (object *tmp = op->inv; tmp; tmp = tmp->below) 799 for (object *tmp = op->inv; tmp; tmp = tmp->below)
836 if (tmp->type == SKILL && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL) && hth_skill_p (tmp)) 800 if (tmp->type == SKILL && tmp->flag [FLAG_CAN_USE_SKILL] && hth_skill_p (tmp))
837 return tmp; 801 return tmp;
838 802
839 return 0; 803 return 0;
840} 804}
841 805
869 } 833 }
870 else 834 else
871 { 835 {
872 if (!pl->combat_ob) 836 if (!pl->combat_ob)
873 { 837 {
874 if (QUERY_FLAG (op, FLAG_READY_WEAPON)) 838 if (op->flag [FLAG_READY_WEAPON])
875 { 839 {
876 for (tmp = op->inv; tmp; tmp = tmp->below) 840 for (tmp = op->inv; tmp; tmp = tmp->below)
877 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED)) 841 if (tmp->type == WEAPON && tmp->flag [FLAG_APPLIED])
878 break; 842 break;
879 843
880 if (!tmp) 844 if (!tmp)
881 LOG (llevError, "Could not find applied weapon on %s\n", &op->name); 845 LOG (llevError, "Could not find applied weapon on %s\n", &op->name);
882 846
924 888
925 int success = attack_ob (tmp, op); 889 int success = attack_ob (tmp, op);
926 890
927 /* print appropriate messages to the player */ 891 /* print appropriate messages to the player */
928 892
929 if (success && string && tmp && !QUERY_FLAG (tmp, FLAG_FREED)) 893 if (success && string && tmp && !tmp->flag [FLAG_FREED])
930 { 894 {
931 if (op->type == PLAYER) 895 if (op->type == PLAYER)
932 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp)); 896 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp));
933 else if (tmp->type == PLAYER) 897 else if (tmp->type == PLAYER)
934 new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string); 898 new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string);
977 /* space must be blocked for there to be anything interesting to do */ 941 /* space must be blocked for there to be anything interesting to do */
978 if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty))) 942 if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty)))
979 return 0; 943 return 0;
980 944
981 for (tmp = GET_MAP_OB (m, tx, ty); tmp; tmp = tmp->above) 945 for (tmp = GET_MAP_OB (m, tx, ty); tmp; tmp = tmp->above)
982 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR) 946 if ((tmp->flag [FLAG_ALIVE] && tmp->stats.hp >= 0) || tmp->flag [FLAG_CAN_ROLL] || tmp->type == LOCKED_DOOR)
983 { 947 {
984 /* Don't attack party members */ 948 /* Don't attack party members */
985 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) 949 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party))
986 return 0; 950 return 0;
987 951
1009static int 973static int
1010attack_hth (object *pl, int dir, const char *string, object *skill) 974attack_hth (object *pl, int dir, const char *string, object *skill)
1011{ 975{
1012 object *enemy = NULL, *weapon; 976 object *enemy = NULL, *weapon;
1013 977
1014 if (QUERY_FLAG (pl, FLAG_READY_WEAPON)) 978 if (pl->flag [FLAG_READY_WEAPON])
1015 for (weapon = pl->inv; weapon; weapon = weapon->below) 979 for (weapon = pl->inv; weapon; weapon = weapon->below)
1016 { 980 {
1017 if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED)) 981 if (weapon->type == WEAPON && weapon->flag [FLAG_APPLIED])
1018 { 982 {
1019 CLEAR_FLAG (weapon, FLAG_APPLIED); 983 weapon->clr_flag (FLAG_APPLIED);
1020 CLEAR_FLAG (pl, FLAG_READY_WEAPON); 984 pl->clr_flag (FLAG_READY_WEAPON);
1021 pl->update_stats (); 985 pl->update_stats ();
1022 if (pl->type == PLAYER) 986 if (pl->type == PLAYER)
1023 { 987 {
1024 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); 988 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack.");
1025 esrv_update_item (UPD_FLAGS, pl, weapon); 989 esrv_update_item (UPD_FLAGS, pl, weapon);
1043 */ 1007 */
1044static int 1008static int
1045attack_melee_weapon (object *op, int dir, const char *string, object *skill) 1009attack_melee_weapon (object *op, int dir, const char *string, object *skill)
1046{ 1010{
1047 1011
1048 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 1012 if (!op->flag [FLAG_READY_WEAPON])
1049 { 1013 {
1050 if (op->type == PLAYER) 1014 if (op->type == PLAYER)
1051 new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!"); 1015 new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!");
1052 1016
1053 return 0; 1017 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines