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.92 by root, Sat Apr 10 04:54:10 2010 UTC vs.
Revision 1.96 by root, Wed Apr 14 22:35:41 2010 UTC

124 return splay (tmp); 124 return splay (tmp);
125 125
126 return 0; 126 return 0;
127} 127}
128 128
129object *
129object *player::find_skill (shstr_cmp name) const 130player::find_skill (shstr_cmp name) const
130{ 131{
131 // might want to use last_skill_obj at one point, or maybe not 132 // might want to use last_skill_obj at one point, or maybe not
132 return ::find_skill (ob, name); 133 return ::find_skill (ob, name);
133} 134}
134 135
162 163
163 /* Player has a tool to use the skill. If not applied, apply it - 164 /* Player has a tool to use the skill. If not applied, apply it -
164 * if not successful, return null. If they do have the skill tool 165 * if not successful, return null. If they do have the skill tool
165 * but not the skill itself, give it to them. 166 * but not the skill itself, give it to them.
166 */ 167 */
167 object *skill = find_skill (who, skill_tool->skill); 168 object *skill = who->give_skill (skill_tool->skill);
168
169 if (!skill)
170 skill = give_skill_by_name (who, skill_tool->skill);
171 169
172 if (!skill_tool->flag [FLAG_APPLIED]) 170 if (!skill_tool->flag [FLAG_APPLIED])
173 if (!who->apply (splay (skill_tool))) 171 if (!who->apply (splay (skill_tool)))
174 return 0; 172 return 0;
175 173
209 return skop; 207 return skop;
210 208
211 return 0; 209 return 0;
212} 210}
213 211
214/* This changes the objects chosen_skill to new_skill. 212object *
215 * return 1 on success, 0 on error 213object::give_skill (shstr_cmp name, bool can_use)
216 */
217bool
218object::change_skill (object *new_skill)
219{ 214{
220 if (type != PLAYER) 215 object *skill = find_skill (this, name);
221 return 0;
222 216
223 // optimise this supposedly common case
224 if (new_skill == chosen_skill)
225 return 1;
226
227 if (chosen_skill) 217 if (!skill)
228 { 218 skill = give_skill_by_name (this, name);
229 chosen_skill->flag [FLAG_APPLIED] = false;
230 change_abil (this, chosen_skill);
231 }
232 219
233 chosen_skill = new_skill; 220 if (skill && can_use)
221 skill->flag [FLAG_CAN_USE_SKILL] = true;
234 222
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; 223 return skill;
248} 224}
249 225
250/* do_skill() - Main skills use function-similar in scope to cast_spell(). 226/* 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. 227 * 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 228 * We require a separate routine outside of fire() so as to allow monsters
293 /* Not 100% sure if this will work with new movement code - 269 /* Not 100% sure if this will work with new movement code -
294 * the levitation skill has move_type for flying, so when 270 * the levitation skill has move_type for flying, so when
295 * equipped, that should transfer to player, when not, 271 * equipped, that should transfer to player, when not,
296 * shouldn't. 272 * shouldn't.
297 */ 273 */
298 if (QUERY_FLAG (skill, FLAG_APPLIED)) 274 if (skill->flag [FLAG_APPLIED])
299 { 275 {
300 CLEAR_FLAG (skill, FLAG_APPLIED); 276 skill->clr_flag (FLAG_APPLIED);
301 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth."); 277 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth.");
302 } 278 }
303 else 279 else
304 { 280 {
305 SET_FLAG (skill, FLAG_APPLIED); 281 skill->set_flag (FLAG_APPLIED);
306 new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!"); 282 new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!");
307 } 283 }
308 284
309 op->update_stats (); 285 op->update_stats ();
310 success = 1; 286 success = 1;
400 376
401 for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next) 377 for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next)
402 { 378 {
403 next = tmp->above; 379 next = tmp->above;
404 380
405 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 381 if (tmp->flag [FLAG_IS_CAULDRON])
406 { 382 {
407 found_cauldron = true; 383 found_cauldron = true;
408 384
409 if (tmp->skill != skill->skill) 385 if (tmp->skill != skill->skill)
410 { 386 {
414 break; 390 break;
415 } 391 }
416 392
417 attempt_do_alchemy (op, tmp, skill); 393 attempt_do_alchemy (op, tmp, skill);
418 394
419 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 395 if (tmp->flag [FLAG_APPLIED])
420 esrv_send_inventory (op, tmp); 396 esrv_send_inventory (op, tmp);
421 } 397 }
422 } 398 }
423 399
424 if (!found_cauldron) 400 if (!found_cauldron)
464 new_draw_info (NDI_UNIQUE, 0, op, "This skill is already in effect."); 440 new_draw_info (NDI_UNIQUE, 0, op, "This skill is already in effect.");
465 break; 441 break;
466 442
467 case SK_MINING: 443 case SK_MINING:
468 success = skill_mining (op, part, skill, dir, string); 444 success = skill_mining (op, part, skill, dir, string);
469 break;
470
471 case SK_FISHING:
472 success = skill_fishing (op, part, skill, dir, string);
473 break; 445 break;
474 446
475 default: 447 default:
476 LOG (llevDebug, "%s attempted to use unknown skill: %d\n", query_name (op), op->chosen_skill->stats.sp); 448 LOG (llevDebug, "%s attempted to use unknown skill: %d\n", query_name (op), op->chosen_skill->stats.sp);
477 break; 449 break;
553 } 525 }
554 else 526 else
555 { /* all other items/living creatures */ 527 { /* all other items/living creatures */
556 op_exp = op->stats.exp; 528 op_exp = op->stats.exp;
557 op_lvl = op->level; 529 op_lvl = op->level;
558 if (!QUERY_FLAG (op, FLAG_ALIVE)) 530 if (!op->flag [FLAG_ALIVE])
559 op_lvl += 5 * abs (op->magic); /* for ident/make items */ 531 op_lvl += 5 * abs (op->magic); /* for ident/make items */
560 } 532 }
561 533
562 if (op_lvl < 1) 534 if (op_lvl < 1)
563 op_lvl = 1; 535 op_lvl = 1;
627 } 599 }
628 600
629 object *tmp = find_skill (pl, scroll->skill); 601 object *tmp = find_skill (pl, scroll->skill);
630 602
631 /* player already knows it */ 603 /* player already knows it */
632 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) 604 if (tmp && tmp->flag [FLAG_CAN_USE_SKILL])
633 return 0; 605 return 0;
634 606
635 /* now a random change to learn, based on player Int. 607 /* now a random change to learn, based on player Int.
636 * give bonus based on level - otherwise stupid characters 608 * give bonus based on level - otherwise stupid characters
637 * might never be able to learn anything. 609 * might never be able to learn anything.
646 { 618 {
647 LOG (llevError, "skill scroll %s does not have valid skill name (%s).\n", &scroll->name, &scroll->skill); 619 LOG (llevError, "skill scroll %s does not have valid skill name (%s).\n", &scroll->name, &scroll->skill);
648 return 2; 620 return 2;
649 } 621 }
650 622
651 SET_FLAG (tmp, FLAG_CAN_USE_SKILL); 623 tmp->set_flag (FLAG_CAN_USE_SKILL);
652 624
653 return 1; 625 return 1;
654} 626}
655 627
656/* Gives a percentage clipped to 0% -> 100% of a/b. */ 628/* Gives a percentage clipped to 0% -> 100% of a/b. */
831 */ 803 */
832static object * 804static object *
833find_player_hth_skill (object *op) 805find_player_hth_skill (object *op)
834{ 806{
835 for (object *tmp = op->inv; tmp; tmp = tmp->below) 807 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)) 808 if (tmp->type == SKILL && tmp->flag [FLAG_CAN_USE_SKILL] && hth_skill_p (tmp))
837 return tmp; 809 return tmp;
838 810
839 return 0; 811 return 0;
840} 812}
841 813
869 } 841 }
870 else 842 else
871 { 843 {
872 if (!pl->combat_ob) 844 if (!pl->combat_ob)
873 { 845 {
874 if (QUERY_FLAG (op, FLAG_READY_WEAPON)) 846 if (op->flag [FLAG_READY_WEAPON])
875 { 847 {
876 for (tmp = op->inv; tmp; tmp = tmp->below) 848 for (tmp = op->inv; tmp; tmp = tmp->below)
877 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED)) 849 if (tmp->type == WEAPON && tmp->flag [FLAG_APPLIED])
878 break; 850 break;
879 851
880 if (!tmp) 852 if (!tmp)
881 LOG (llevError, "Could not find applied weapon on %s\n", &op->name); 853 LOG (llevError, "Could not find applied weapon on %s\n", &op->name);
882 854
924 896
925 int success = attack_ob (tmp, op); 897 int success = attack_ob (tmp, op);
926 898
927 /* print appropriate messages to the player */ 899 /* print appropriate messages to the player */
928 900
929 if (success && string && tmp && !QUERY_FLAG (tmp, FLAG_FREED)) 901 if (success && string && tmp && !tmp->flag [FLAG_FREED])
930 { 902 {
931 if (op->type == PLAYER) 903 if (op->type == PLAYER)
932 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp)); 904 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp));
933 else if (tmp->type == PLAYER) 905 else if (tmp->type == PLAYER)
934 new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string); 906 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 */ 949 /* 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))) 950 if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty)))
979 return 0; 951 return 0;
980 952
981 for (tmp = GET_MAP_OB (m, tx, ty); tmp; tmp = tmp->above) 953 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) 954 if ((tmp->flag [FLAG_ALIVE] && tmp->stats.hp >= 0) || tmp->flag [FLAG_CAN_ROLL] || tmp->type == LOCKED_DOOR)
983 { 955 {
984 /* Don't attack party members */ 956 /* Don't attack party members */
985 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) 957 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party))
986 return 0; 958 return 0;
987 959
1009static int 981static int
1010attack_hth (object *pl, int dir, const char *string, object *skill) 982attack_hth (object *pl, int dir, const char *string, object *skill)
1011{ 983{
1012 object *enemy = NULL, *weapon; 984 object *enemy = NULL, *weapon;
1013 985
1014 if (QUERY_FLAG (pl, FLAG_READY_WEAPON)) 986 if (pl->flag [FLAG_READY_WEAPON])
1015 for (weapon = pl->inv; weapon; weapon = weapon->below) 987 for (weapon = pl->inv; weapon; weapon = weapon->below)
1016 { 988 {
1017 if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED)) 989 if (weapon->type == WEAPON && weapon->flag [FLAG_APPLIED])
1018 { 990 {
1019 CLEAR_FLAG (weapon, FLAG_APPLIED); 991 weapon->clr_flag (FLAG_APPLIED);
1020 CLEAR_FLAG (pl, FLAG_READY_WEAPON); 992 pl->clr_flag (FLAG_READY_WEAPON);
1021 pl->update_stats (); 993 pl->update_stats ();
1022 if (pl->type == PLAYER) 994 if (pl->type == PLAYER)
1023 { 995 {
1024 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); 996 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack.");
1025 esrv_update_item (UPD_FLAGS, pl, weapon); 997 esrv_update_item (UPD_FLAGS, pl, weapon);
1043 */ 1015 */
1044static int 1016static int
1045attack_melee_weapon (object *op, int dir, const char *string, object *skill) 1017attack_melee_weapon (object *op, int dir, const char *string, object *skill)
1046{ 1018{
1047 1019
1048 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 1020 if (!op->flag [FLAG_READY_WEAPON])
1049 { 1021 {
1050 if (op->type == PLAYER) 1022 if (op->type == PLAYER)
1051 new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!"); 1023 new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!");
1052 1024
1053 return 0; 1025 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines