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.88 by root, Mon Apr 5 02:05:32 2010 UTC vs.
Revision 1.94 by root, Sun Apr 11 00:34:06 2010 UTC

168 168
169 if (!skill) 169 if (!skill)
170 skill = give_skill_by_name (who, skill_tool->skill); 170 skill = give_skill_by_name (who, skill_tool->skill);
171 171
172 if (!skill_tool->flag [FLAG_APPLIED]) 172 if (!skill_tool->flag [FLAG_APPLIED])
173 if (apply_special (who, splay (skill_tool), AP_APPLY)) 173 if (!who->apply (splay (skill_tool)))
174 return 0; 174 return 0;
175 175
176 return splay (skill); 176 return splay (skill);
177} 177}
178 178
179object * 179object *
180find_skill_by_name_fuzzy (object *who, const char *name) 180find_skill_by_name_fuzzy (object *who, const char *name)
181{ 181{
182 if (!name) 182 if (name)
183 return 0;
184
185 for (object *tmp = who->inv; tmp; tmp = tmp->below) 183 for (object *tmp = who->inv; tmp; tmp = tmp->below)
186 if ((tmp->type == SKILL || tmp->type == SKILL_TOOL) 184 if ((tmp->type == SKILL || tmp->type == SKILL_TOOL)
187 && tmp->skill.starts_with (name)) 185 && tmp->skill.starts_with (name))
188 if (object *skop = find_skill_by_name (who, tmp->skill)) 186 if (object *skop = find_skill_by_name (who, tmp->skill))
189 return skop; 187 return skop;
190 188
191 return 0; 189 return 0;
192} 190}
193 191
194/* This returns the skill pointer of the given name (the 192/* This returns the skill pointer of the given name (the
211 return skop; 209 return skop;
212 210
213 return 0; 211 return 0;
214} 212}
215 213
216/* This changes the objects chosen_skill to new_skill.
217 * return 1 on success, 0 on error
218 */
219bool
220object::change_skill (object *new_skill)
221{
222 if (type != PLAYER)
223 return 0;
224
225 // optimise this supposedly common case
226 if (new_skill == chosen_skill)
227 return 1;
228
229 if (chosen_skill)
230 {
231 chosen_skill->flag [FLAG_APPLIED] = false;
232 change_abil (this, chosen_skill);
233 }
234
235 chosen_skill = new_skill;
236
237 if (chosen_skill)
238 {
239 chosen_skill->flag [FLAG_APPLIED] = true;
240 change_abil (this, chosen_skill);
241 }
242
243 // always clear current weapon, as the selected skill could
244 // conflict with the current weapon skill, which would go
245 // undetected and exp would be given to the wrong skill.
246 current_weapon = 0;
247
248 update_stats ();
249 return 1;
250}
251
252/* 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().
253 * 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.
254 * 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
255 * to utilize skills. Returns 1 on use of skill, otherwise 0. 217 * to utilize skills. Returns 1 on use of skill, otherwise 0.
256 * 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
295 /* Not 100% sure if this will work with new movement code - 257 /* Not 100% sure if this will work with new movement code -
296 * the levitation skill has move_type for flying, so when 258 * the levitation skill has move_type for flying, so when
297 * equipped, that should transfer to player, when not, 259 * equipped, that should transfer to player, when not,
298 * shouldn't. 260 * shouldn't.
299 */ 261 */
300 if (QUERY_FLAG (skill, FLAG_APPLIED)) 262 if (skill->flag [FLAG_APPLIED])
301 { 263 {
302 CLEAR_FLAG (skill, FLAG_APPLIED); 264 skill->clr_flag (FLAG_APPLIED);
303 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth."); 265 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth.");
304 } 266 }
305 else 267 else
306 { 268 {
307 SET_FLAG (skill, FLAG_APPLIED); 269 skill->set_flag (FLAG_APPLIED);
308 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!");
309 } 271 }
310 272
311 op->update_stats (); 273 op->update_stats ();
312 success = 1; 274 success = 1;
402 364
403 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)
404 { 366 {
405 next = tmp->above; 367 next = tmp->above;
406 368
407 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 369 if (tmp->flag [FLAG_IS_CAULDRON])
408 { 370 {
409 found_cauldron = true; 371 found_cauldron = true;
410 372
411 if (tmp->skill != skill->skill) 373 if (tmp->skill != skill->skill)
412 { 374 {
413 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!",
414 query_name (tmp), 376 query_name (tmp),
415 query_name (skill))); 377 query_name (skill));
416 break; 378 break;
417 } 379 }
418 380
419 attempt_do_alchemy (op, tmp, skill); 381 attempt_do_alchemy (op, tmp, skill);
420 382
421 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 383 if (tmp->flag [FLAG_APPLIED])
422 esrv_send_inventory (op, tmp); 384 esrv_send_inventory (op, tmp);
423 } 385 }
424 } 386 }
425 387
426 if (!found_cauldron) 388 if (!found_cauldron)
555 } 517 }
556 else 518 else
557 { /* all other items/living creatures */ 519 { /* all other items/living creatures */
558 op_exp = op->stats.exp; 520 op_exp = op->stats.exp;
559 op_lvl = op->level; 521 op_lvl = op->level;
560 if (!QUERY_FLAG (op, FLAG_ALIVE)) 522 if (!op->flag [FLAG_ALIVE])
561 op_lvl += 5 * abs (op->magic); /* for ident/make items */ 523 op_lvl += 5 * abs (op->magic); /* for ident/make items */
562 } 524 }
563 525
564 if (op_lvl < 1) 526 if (op_lvl < 1)
565 op_lvl = 1; 527 op_lvl = 1;
629 } 591 }
630 592
631 object *tmp = find_skill (pl, scroll->skill); 593 object *tmp = find_skill (pl, scroll->skill);
632 594
633 /* player already knows it */ 595 /* player already knows it */
634 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) 596 if (tmp && tmp->flag [FLAG_CAN_USE_SKILL])
635 return 0; 597 return 0;
636 598
637 /* now a random change to learn, based on player Int. 599 /* now a random change to learn, based on player Int.
638 * give bonus based on level - otherwise stupid characters 600 * give bonus based on level - otherwise stupid characters
639 * might never be able to learn anything. 601 * might never be able to learn anything.
648 { 610 {
649 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);
650 return 2; 612 return 2;
651 } 613 }
652 614
653 SET_FLAG (tmp, FLAG_CAN_USE_SKILL); 615 tmp->set_flag (FLAG_CAN_USE_SKILL);
654 616
655 return 1; 617 return 1;
656} 618}
657 619
658/* Gives a percentage clipped to 0% -> 100% of a/b. */ 620/* Gives a percentage clipped to 0% -> 100% of a/b. */
768 730
769 if (!string) 731 if (!string)
770 return 0; 732 return 0;
771 733
772 for (skop = op->inv; skop; skop = skop->below) 734 for (skop = op->inv; skop; skop = skop->below)
735 if ((skop->type == SKILL || skop->type == SKILL_TOOL)
736 && !strncmp (string, skop->skill, min (strlen (string), strlen (skop->skill))))
773 { 737 {
774 if (skop->type == SKILL 738 skop = find_skill_by_name (op, skop->skill);
775 && skop->flag [FLAG_CAN_USE_SKILL]
776 && skop->skill.starts_with (string))
777 break; 739 break;
778 else if (skop->type == SKILL_TOOL
779 && skop->skill.starts_with (string)
780 && op->apply (skop))
781 break;
782 } 740 }
783 741
784 if (!skop) 742 if (!skop)
785 { 743 {
786 op->failmsg (format ("Unable to find skill %s.", string)); 744 op->failmsgf ("Unable to find skill %s.", string);
787 return 0; 745 return 0;
788 } 746 }
789 747
790 if (!(skill_flags [skop->subtype] & SF_USE)) 748 if (!(skill_flags [skop->subtype] & SF_USE))
791 { 749 {
792 op->failmsg (format ( 750 op->failmsgf (
793 "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. "
794 "H<The %s skill cannot be used - maybe you need to ready it, use it with some item, or it's always active.>", 752 "H<The %s skill cannot be C<use_skill>'ed - maybe you need to C<ready_skill> it, "
753 "use it with some item, or it's always active.>",
795 &skop->skill 754 &skop->skill
796 )); 755 );
797 return 0; 756 return 0;
798 } 757 }
799 758
800 len = strlen (skop->skill); 759 len = strlen (skop->skill);
801 760
836 */ 795 */
837static object * 796static object *
838find_player_hth_skill (object *op) 797find_player_hth_skill (object *op)
839{ 798{
840 for (object *tmp = op->inv; tmp; tmp = tmp->below) 799 for (object *tmp = op->inv; tmp; tmp = tmp->below)
841 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))
842 return tmp; 801 return tmp;
843 802
844 return 0; 803 return 0;
845} 804}
846 805
874 } 833 }
875 else 834 else
876 { 835 {
877 if (!pl->combat_ob) 836 if (!pl->combat_ob)
878 { 837 {
879 if (QUERY_FLAG (op, FLAG_READY_WEAPON)) 838 if (op->flag [FLAG_READY_WEAPON])
880 { 839 {
881 for (tmp = op->inv; tmp; tmp = tmp->below) 840 for (tmp = op->inv; tmp; tmp = tmp->below)
882 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED)) 841 if (tmp->type == WEAPON && tmp->flag [FLAG_APPLIED])
883 break; 842 break;
884 843
885 if (!tmp) 844 if (!tmp)
886 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);
887 846
929 888
930 int success = attack_ob (tmp, op); 889 int success = attack_ob (tmp, op);
931 890
932 /* print appropriate messages to the player */ 891 /* print appropriate messages to the player */
933 892
934 if (success && string && tmp && !QUERY_FLAG (tmp, FLAG_FREED)) 893 if (success && string && tmp && !tmp->flag [FLAG_FREED])
935 { 894 {
936 if (op->type == PLAYER) 895 if (op->type == PLAYER)
937 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));
938 else if (tmp->type == PLAYER) 897 else if (tmp->type == PLAYER)
939 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);
982 /* 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 */
983 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)))
984 return 0; 943 return 0;
985 944
986 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)
987 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)
988 { 947 {
989 /* Don't attack party members */ 948 /* Don't attack party members */
990 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))
991 return 0; 950 return 0;
992 951
1014static int 973static int
1015attack_hth (object *pl, int dir, const char *string, object *skill) 974attack_hth (object *pl, int dir, const char *string, object *skill)
1016{ 975{
1017 object *enemy = NULL, *weapon; 976 object *enemy = NULL, *weapon;
1018 977
1019 if (QUERY_FLAG (pl, FLAG_READY_WEAPON)) 978 if (pl->flag [FLAG_READY_WEAPON])
1020 for (weapon = pl->inv; weapon; weapon = weapon->below) 979 for (weapon = pl->inv; weapon; weapon = weapon->below)
1021 { 980 {
1022 if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED)) 981 if (weapon->type == WEAPON && weapon->flag [FLAG_APPLIED])
1023 { 982 {
1024 CLEAR_FLAG (weapon, FLAG_APPLIED); 983 weapon->clr_flag (FLAG_APPLIED);
1025 CLEAR_FLAG (pl, FLAG_READY_WEAPON); 984 pl->clr_flag (FLAG_READY_WEAPON);
1026 pl->update_stats (); 985 pl->update_stats ();
1027 if (pl->type == PLAYER) 986 if (pl->type == PLAYER)
1028 { 987 {
1029 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.");
1030 esrv_update_item (UPD_FLAGS, pl, weapon); 989 esrv_update_item (UPD_FLAGS, pl, weapon);
1048 */ 1007 */
1049static int 1008static int
1050attack_melee_weapon (object *op, int dir, const char *string, object *skill) 1009attack_melee_weapon (object *op, int dir, const char *string, object *skill)
1051{ 1010{
1052 1011
1053 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 1012 if (!op->flag [FLAG_READY_WEAPON])
1054 { 1013 {
1055 if (op->type == PLAYER) 1014 if (op->type == PLAYER)
1056 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!");
1057 1016
1058 return 0; 1017 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines