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.95 by root, Tue Apr 13 03:44:21 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)
553 } 529 }
554 else 530 else
555 { /* all other items/living creatures */ 531 { /* all other items/living creatures */
556 op_exp = op->stats.exp; 532 op_exp = op->stats.exp;
557 op_lvl = op->level; 533 op_lvl = op->level;
558 if (!QUERY_FLAG (op, FLAG_ALIVE)) 534 if (!op->flag [FLAG_ALIVE])
559 op_lvl += 5 * abs (op->magic); /* for ident/make items */ 535 op_lvl += 5 * abs (op->magic); /* for ident/make items */
560 } 536 }
561 537
562 if (op_lvl < 1) 538 if (op_lvl < 1)
563 op_lvl = 1; 539 op_lvl = 1;
627 } 603 }
628 604
629 object *tmp = find_skill (pl, scroll->skill); 605 object *tmp = find_skill (pl, scroll->skill);
630 606
631 /* player already knows it */ 607 /* player already knows it */
632 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) 608 if (tmp && tmp->flag [FLAG_CAN_USE_SKILL])
633 return 0; 609 return 0;
634 610
635 /* now a random change to learn, based on player Int. 611 /* now a random change to learn, based on player Int.
636 * give bonus based on level - otherwise stupid characters 612 * give bonus based on level - otherwise stupid characters
637 * might never be able to learn anything. 613 * might never be able to learn anything.
646 { 622 {
647 LOG (llevError, "skill scroll %s does not have valid skill name (%s).\n", &scroll->name, &scroll->skill); 623 LOG (llevError, "skill scroll %s does not have valid skill name (%s).\n", &scroll->name, &scroll->skill);
648 return 2; 624 return 2;
649 } 625 }
650 626
651 SET_FLAG (tmp, FLAG_CAN_USE_SKILL); 627 tmp->set_flag (FLAG_CAN_USE_SKILL);
652 628
653 return 1; 629 return 1;
654} 630}
655 631
656/* Gives a percentage clipped to 0% -> 100% of a/b. */ 632/* Gives a percentage clipped to 0% -> 100% of a/b. */
831 */ 807 */
832static object * 808static object *
833find_player_hth_skill (object *op) 809find_player_hth_skill (object *op)
834{ 810{
835 for (object *tmp = op->inv; tmp; tmp = tmp->below) 811 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)) 812 if (tmp->type == SKILL && tmp->flag [FLAG_CAN_USE_SKILL] && hth_skill_p (tmp))
837 return tmp; 813 return tmp;
838 814
839 return 0; 815 return 0;
840} 816}
841 817
869 } 845 }
870 else 846 else
871 { 847 {
872 if (!pl->combat_ob) 848 if (!pl->combat_ob)
873 { 849 {
874 if (QUERY_FLAG (op, FLAG_READY_WEAPON)) 850 if (op->flag [FLAG_READY_WEAPON])
875 { 851 {
876 for (tmp = op->inv; tmp; tmp = tmp->below) 852 for (tmp = op->inv; tmp; tmp = tmp->below)
877 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED)) 853 if (tmp->type == WEAPON && tmp->flag [FLAG_APPLIED])
878 break; 854 break;
879 855
880 if (!tmp) 856 if (!tmp)
881 LOG (llevError, "Could not find applied weapon on %s\n", &op->name); 857 LOG (llevError, "Could not find applied weapon on %s\n", &op->name);
882 858
924 900
925 int success = attack_ob (tmp, op); 901 int success = attack_ob (tmp, op);
926 902
927 /* print appropriate messages to the player */ 903 /* print appropriate messages to the player */
928 904
929 if (success && string && tmp && !QUERY_FLAG (tmp, FLAG_FREED)) 905 if (success && string && tmp && !tmp->flag [FLAG_FREED])
930 { 906 {
931 if (op->type == PLAYER) 907 if (op->type == PLAYER)
932 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp)); 908 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp));
933 else if (tmp->type == PLAYER) 909 else if (tmp->type == PLAYER)
934 new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string); 910 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 */ 953 /* 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))) 954 if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty)))
979 return 0; 955 return 0;
980 956
981 for (tmp = GET_MAP_OB (m, tx, ty); tmp; tmp = tmp->above) 957 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) 958 if ((tmp->flag [FLAG_ALIVE] && tmp->stats.hp >= 0) || tmp->flag [FLAG_CAN_ROLL] || tmp->type == LOCKED_DOOR)
983 { 959 {
984 /* Don't attack party members */ 960 /* Don't attack party members */
985 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) 961 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party))
986 return 0; 962 return 0;
987 963
1009static int 985static int
1010attack_hth (object *pl, int dir, const char *string, object *skill) 986attack_hth (object *pl, int dir, const char *string, object *skill)
1011{ 987{
1012 object *enemy = NULL, *weapon; 988 object *enemy = NULL, *weapon;
1013 989
1014 if (QUERY_FLAG (pl, FLAG_READY_WEAPON)) 990 if (pl->flag [FLAG_READY_WEAPON])
1015 for (weapon = pl->inv; weapon; weapon = weapon->below) 991 for (weapon = pl->inv; weapon; weapon = weapon->below)
1016 { 992 {
1017 if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED)) 993 if (weapon->type == WEAPON && weapon->flag [FLAG_APPLIED])
1018 { 994 {
1019 CLEAR_FLAG (weapon, FLAG_APPLIED); 995 weapon->clr_flag (FLAG_APPLIED);
1020 CLEAR_FLAG (pl, FLAG_READY_WEAPON); 996 pl->clr_flag (FLAG_READY_WEAPON);
1021 pl->update_stats (); 997 pl->update_stats ();
1022 if (pl->type == PLAYER) 998 if (pl->type == PLAYER)
1023 { 999 {
1024 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); 1000 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack.");
1025 esrv_update_item (UPD_FLAGS, pl, weapon); 1001 esrv_update_item (UPD_FLAGS, pl, weapon);
1043 */ 1019 */
1044static int 1020static int
1045attack_melee_weapon (object *op, int dir, const char *string, object *skill) 1021attack_melee_weapon (object *op, int dir, const char *string, object *skill)
1046{ 1022{
1047 1023
1048 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 1024 if (!op->flag [FLAG_READY_WEAPON])
1049 { 1025 {
1050 if (op->type == PLAYER) 1026 if (op->type == PLAYER)
1051 new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!"); 1027 new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!");
1052 1028
1053 return 0; 1029 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines