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.26 by pippijn, Mon Jan 15 21:06:20 2007 UTC vs.
Revision 1.34 by root, Mon Apr 30 05:54:14 2007 UTC

44#include <object.h> 44#include <object.h>
45#include <sproto.h> 45#include <sproto.h>
46#include <living.h> /* for defs of STR,CON,DEX,etc. -b.t. */ 46#include <living.h> /* for defs of STR,CON,DEX,etc. -b.t. */
47#include <spells.h> 47#include <spells.h>
48 48
49/* Table of unarmed attack skills. Terminated by -1. This 49const uint8_t skill_flags[NUM_SKILLS] = {
50 * is also the list that we should try to use skills when 50 0, // SK_NONE
51 * automatically applying one for the player. 51# define def(uc, flags) flags,
52 */ 52# include "skillinc.h"
53static uint8 unarmed_skills[] = { 53# undef def
54 SK_KARATE,
55 SK_CLAWING,
56 SK_FLAME_TOUCH,
57 SK_SPARK_TOUCH,
58 SK_SHIVER,
59 SK_ACID_SPLASH,
60 SK_POISON_NAIL,
61 SK_PUNCHING,
62 (uint8)-1
63}; 54};
64 55
65static int attack_hth (object *pl, int dir, const char *string, object *skill); 56static int attack_hth (object *pl, int dir, const char *string, object *skill);
66static int attack_melee_weapon (object *op, int dir, const char *string, object *skill); 57static int attack_melee_weapon (object *op, int dir, const char *string, object *skill);
67 58
70 * subtypes. 61 * subtypes.
71 */ 62 */
72void 63void
73init_skills (void) 64init_skills (void)
74{ 65{
75 int i;
76 archetype *at;
77
78 for (at = first_archetype; at != NULL; at = at->next) 66 for (archetype *at = first_archetype; at; at = at->next)
79 if (at->clone.type == SKILL) 67 if (at->clone.type == SKILL)
80 { 68 {
81 if (skill_names[at->clone.subtype] != NULL) 69 if (skill_names[at->clone.subtype])
82 LOG (llevError, "init_skills: multiple skill using same subtype %d, %s, %s\n", 70 LOG (llevError, "init_skills: multiple skill using same subtype %d, %s, %s\n",
83 at->clone.subtype, &skill_names[at->clone.subtype], &at->clone.skill); 71 at->clone.subtype, &skill_names[at->clone.subtype], &at->clone.skill);
84 else 72 else
85 skill_names[at->clone.subtype] = at->clone.skill; 73 skill_names[at->clone.subtype] = at->clone.skill;
86 } 74 }
87 75
88 /* This isn't really an error if there is no skill subtype set, but 76 /* This isn't really an error if there is no skill subtype set, but
89 * checking for this may catch some user errors. 77 * checking for this may catch some user errors.
90 */ 78 */
91 for (i = 1; i < NUM_SKILLS; i++) 79 for (int i = 1; i < NUM_SKILLS; i++)
92 {
93 if (!skill_names[i]) 80 if (!skill_names[i])
94 LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i); 81 LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i);
95 }
96} 82}
97 83
98/* This function goes through the player inventory and sets 84/* This function goes through the player inventory and sets
99 * up the last_skills[] array in the player object. 85 * up the last_skills[] array in the player object.
100 * the last_skills[] is used to more quickly lookup skills - 86 * the last_skills[] is used to more quickly lookup skills -
169 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) 155 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED))
170 { 156 {
171 if (apply_special (who, skill_tool, 0)) 157 if (apply_special (who, skill_tool, 0))
172 return NULL; 158 return NULL;
173 } 159 }
160
174 if (!skill) 161 if (!skill)
175 { 162 {
176 skill = give_skill_by_name (who, skill_tool->skill); 163 skill = give_skill_by_name (who, skill_tool->skill);
177 link_player_skills (who); 164 link_player_skills (who);
178 } 165 }
166
179 return skill; 167 return skill;
180 } 168 }
169
181 return NULL; 170 return NULL;
182} 171}
183 172
184 173
185/* This returns the skill pointer of the given name (the 174/* This returns the skill pointer of the given name (the
254 * flag has the current meaning: 243 * flag has the current meaning:
255 * 0x1: If set, don't update the range pointer. This is useful when we 244 * 0x1: If set, don't update the range pointer. This is useful when we
256 * need to ready a new skill, but don't want to clobber range. 245 * need to ready a new skill, but don't want to clobber range.
257 * return 1 on success, 0 on error 246 * return 1 on success, 0 on error
258 */ 247 */
259
260int 248int
261change_skill (object *who, object *new_skill, int flag) 249change_skill (object *who, object *new_skill, int flag)
262{ 250{
263 int old_range; 251 int old_range;
264 252
265 if (who->type != PLAYER) 253 if (who->type != PLAYER)
266 return 0; 254 return 0;
267 255
268 old_range = who->contr->shoottype; 256 player *pl = who->contr;
269 257
270 if (who->chosen_skill && who->chosen_skill == new_skill) 258 if (pl->ranged_skill && pl->ranged_skill == new_skill)
271 { 259 return 1;
272 /* optimization for changing skill to current skill */
273 if (who->type == PLAYER && !(flag & 0x1))
274 who->contr->shoottype = range_skill;
275 260
261 if (!new_skill)
262 {
263 if (pl->ranged_skill)
264 apply_special (who, pl->ranged_skill, AP_UNAPPLY);
265
266 /* Only goal in this case was to unapply a skill */
276 return 1; 267 return 0;
277 } 268 }
278 269
279 // move skill to front, so it will be preferred next time 270 // move skill to front, so it will be preferred next time
280 new_skill->remove (); 271 new_skill->remove ();
281 who->insert (new_skill); 272 who->insert (new_skill);
282 273
283 if (!new_skill || who->chosen_skill)
284 if (who->chosen_skill)
285 apply_special (who, who->chosen_skill, AP_UNAPPLY);
286
287 /* Only goal in this case was to unapply a skill */
288 if (!new_skill)
289 return 0;
290
291 if (apply_special (who, new_skill, AP_APPLY)) 274 if (apply_special (who, new_skill, AP_APPLY))
292 return 0; 275 return 0;
293 276
294 if (flag & 0x1)
295 who->contr->shoottype = (rangetype)old_range;
296
297 return 1; 277 return 1;
298} 278}
299 279
300/* This function just clears the chosen_skill and range_skill values 280/* This function just clears the chosen_skill and range_skill values
301 * inthe player. 281 * in the player.
302 */ 282 */
303void 283void
304clear_skill (object *who) 284clear_skill (object *who)
305{ 285{
306 who->chosen_skill = NULL; 286 who->chosen_skill = 0;
307 CLEAR_FLAG (who, FLAG_READY_SKILL); 287 CLEAR_FLAG (who, FLAG_READY_SKILL);
288
308 if (who->type == PLAYER) 289 if (who->type == PLAYER)
309 { 290 {
291 if (who->contr->ranged_skill && who->contr->ranged_skill->type == SKILL)
292 {
310 who->contr->ranges[range_skill] = NULL; 293 who->contr->ranged_skill = 0;
311 if (who->contr->shoottype == range_skill) 294 who->contr->ranged_ob = 0;
312 who->contr->shoottype = range_none; 295 }
313 } 296 }
314} 297}
315 298
316/* do_skill() - Main skills use function-similar in scope to cast_spell(). 299/* do_skill() - Main skills use function-similar in scope to cast_spell().
317 * We handle all requests for skill use outside of some combat here. 300 * We handle all requests for skill use outside of some combat here.
321 * exp - no caller needed that info, but it also prevented the callers 304 * exp - no caller needed that info, but it also prevented the callers
322 * from know if a skill was actually used, as many skills don't 305 * from know if a skill was actually used, as many skills don't
323 * give any exp for their direct use (eg, throwing). 306 * give any exp for their direct use (eg, throwing).
324 * It returns 0 if no skill was used. 307 * It returns 0 if no skill was used.
325 */ 308 */
326
327int 309int
328do_skill (object *op, object *part, object *skill, int dir, const char *string) 310do_skill (object *op, object *part, object *skill, int dir, const char *string)
329{ 311{
330 int success = 0, exp = 0; 312 int success = 0, exp = 0;
331 int did_alc = 0; 313 int did_alc = 0;
340 * the player doesn't have a bucket for that, create one. 322 * the player doesn't have a bucket for that, create one.
341 */ 323 */
342 if (skill->type != SKILL && op->type == PLAYER) 324 if (skill->type != SKILL && op->type == PLAYER)
343 { 325 {
344 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 326 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
345 {
346 if (tmp->type == SKILL && tmp->skill == skill->skill) 327 if (tmp->type == SKILL && tmp->skill == skill->skill)
347 break; 328 break;
348 } 329
349 if (!tmp) 330 if (!tmp)
350 tmp = give_skill_by_name (op, skill->skill); 331 tmp = give_skill_by_name (op, skill->skill);
332
351 skill = tmp; 333 skill = tmp;
352 } 334 }
353 335
354 // skill, by_whom, on_which_object, which direction, skill_argument 336 // skill, by_whom, on_which_object, which direction, skill_argument
355 if (INVOKE_OBJECT (USE_SKILL, skill, ARG_OBJECT (op), ARG_OBJECT (part), ARG_INT (dir), ARG_STRING (string))) 337 if (INVOKE_OBJECT (USE_SKILL, skill, ARG_OBJECT (op), ARG_OBJECT (part), ARG_INT (dir), ARG_STRING (string)))
356 return 0; 338 return 0;
357 339
358 switch (skill->subtype) 340 switch (skill->subtype)
359 { 341 {
360 case SK_LEVITATION: 342 case SK_LEVITATION:
361 /* Not 100% sure if this will work with new movement code - 343 /* Not 100% sure if this will work with new movement code -
362 * the levitation skill has move_type for flying, so when 344 * the levitation skill has move_type for flying, so when
363 * equipped, that should transfer to player, when not, 345 * equipped, that should transfer to player, when not,
364 * shouldn't. 346 * shouldn't.
365 */ 347 */
366 if (QUERY_FLAG (skill, FLAG_APPLIED)) 348 if (QUERY_FLAG (skill, FLAG_APPLIED))
367 { 349 {
368 CLEAR_FLAG (skill, FLAG_APPLIED); 350 CLEAR_FLAG (skill, FLAG_APPLIED);
369 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth."); 351 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth.");
370 } 352 }
371 else 353 else
372 { 354 {
373 SET_FLAG (skill, FLAG_APPLIED); 355 SET_FLAG (skill, FLAG_APPLIED);
374 new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!."); 356 new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!.");
375 } 357 }
358
376 op->update_stats (); 359 op->update_stats ();
377 success = 1; 360 success = 1;
378 break; 361 break;
379 362
380 case SK_STEALING: 363 case SK_STEALING:
381 exp = success = steal (op, dir, skill); 364 exp = success = steal (op, dir, skill);
382 break; 365 break;
383 366
384 case SK_LOCKPICKING: 367 case SK_LOCKPICKING:
385 exp = success = pick_lock (op, dir, skill); 368 exp = success = pick_lock (op, dir, skill);
386 break; 369 break;
387 370
388 case SK_HIDING: 371 case SK_HIDING:
389 exp = success = hide (op, skill); 372 exp = success = hide (op, skill);
390 break; 373 break;
391 374
392 case SK_JUMPING: 375 case SK_JUMPING:
393 success = jump (op, dir, skill); 376 success = jump (op, dir, skill);
394 break; 377 break;
395 378
396 case SK_INSCRIPTION: 379 case SK_INSCRIPTION:
397 exp = success = write_on_item (op, string, skill); 380 exp = success = write_on_item (op, string, skill);
398 break; 381 break;
399 382
400 case SK_MEDITATION: 383 case SK_MEDITATION:
401 meditate (op, skill); 384 meditate (op, skill);
402 success = 1; 385 success = 1;
403 break; 386 break;
404 /* note that the following 'attack' skills gain exp through hit_player() */ 387 /* note that the following 'attack' skills gain exp through hit_player() */
405 388
406 case SK_KARATE: 389 case SK_KARATE:
407 (void) attack_hth (op, dir, "karate-chopped", skill); 390 attack_hth (op, dir, "karate-chopped", skill);
408 break; 391 break;
409 392
410 case SK_PUNCHING: 393 case SK_PUNCHING:
411 (void) attack_hth (op, dir, "punched", skill); 394 attack_hth (op, dir, "punched", skill);
412 break; 395 break;
413 396
414 case SK_FLAME_TOUCH: 397 case SK_FLAME_TOUCH:
415 (void) attack_hth (op, dir, "flamed", skill); 398 attack_hth (op, dir, "flamed", skill);
416 break; 399 break;
417 400
418 case SK_SPARK_TOUCH: 401 case SK_SPARK_TOUCH:
419 (void) attack_hth (op, dir, "zapped", skill); 402 attack_hth (op, dir, "zapped", skill);
420 break; 403 break;
421 404
422 case SK_SHIVER: 405 case SK_SHIVER:
423 (void) attack_hth (op, dir, "froze", skill); 406 attack_hth (op, dir, "froze", skill);
424 break; 407 break;
425 408
426 case SK_ACID_SPLASH: 409 case SK_ACID_SPLASH:
427 (void) attack_hth (op, dir, "dissolved", skill); 410 attack_hth (op, dir, "dissolved", skill);
428 break; 411 break;
429 412
430 case SK_POISON_NAIL: 413 case SK_POISON_NAIL:
431 (void) attack_hth (op, dir, "injected poison into", skill); 414 attack_hth (op, dir, "injected poison into", skill);
432 break; 415 break;
433 416
434 case SK_CLAWING: 417 case SK_CLAWING:
435 (void) attack_hth (op, dir, "clawed", skill); 418 attack_hth (op, dir, "clawed", skill);
436 break; 419 break;
437 420
438 case SK_ONE_HANDED_WEAPON: 421 case SK_ONE_HANDED_WEAPON:
439 case SK_TWO_HANDED_WEAPON: 422 case SK_TWO_HANDED_WEAPON:
440 (void) attack_melee_weapon (op, dir, NULL, skill); 423 attack_melee_weapon (op, dir, NULL, skill);
441 break; 424 break;
442 425
443 case SK_FIND_TRAPS: 426 case SK_FIND_TRAPS:
444 exp = success = find_traps (op, skill); 427 exp = success = find_traps (op, skill);
445 break; 428 break;
446 429
447 case SK_SINGING: 430 case SK_SINGING:
448 exp = success = singing (op, dir, skill); 431 exp = success = singing (op, dir, skill);
449 break; 432 break;
450 433
451 case SK_ORATORY: 434 case SK_ORATORY:
452 exp = success = use_oratory (op, dir, skill); 435 exp = success = use_oratory (op, dir, skill);
453 break; 436 break;
454 437
455 case SK_SMITHERY: 438 case SK_SMITHERY:
456 case SK_BOWYER: 439 case SK_BOWYER:
457 case SK_JEWELER: 440 case SK_JEWELER:
458 case SK_ALCHEMY: 441 case SK_ALCHEMY:
459 case SK_THAUMATURGY: 442 case SK_THAUMATURGY:
460 case SK_LITERACY: 443 case SK_LITERACY:
461 case SK_WOODSMAN: 444 case SK_WOODSMAN:
462 /* first, we try to find a cauldron, and do the alchemy thing. 445 /* first, we try to find a cauldron, and do the alchemy thing.
463 * failing that, we go and identify stuff. 446 * failing that, we go and identify stuff.
464 */ 447 */
465 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = next) 448 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = next)
466 { 449 {
467 next = tmp->above; 450 next = tmp->above;
468 451
469 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 452 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON))
470 { 453 {
471 attempt_do_alchemy (op, tmp); 454 attempt_do_alchemy (op, tmp);
472 455
473 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 456 if (QUERY_FLAG (tmp, FLAG_APPLIED))
474 esrv_send_inventory (op, tmp); 457 esrv_send_inventory (op, tmp);
475 458
476 did_alc = 1; 459 did_alc = 1;
477 } 460 }
478 } 461 }
479 462
480 if (did_alc == 0) 463 if (did_alc == 0)
481 exp = success = skill_ident (op, skill);
482
483 break;
484
485 case SK_DET_MAGIC:
486 case SK_DET_CURSE:
487 exp = success = skill_ident (op, skill); 464 exp = success = skill_ident (op, skill);
465
488 break; 466 break;
489 467
468 case SK_DET_MAGIC:
469 case SK_DET_CURSE:
470 exp = success = skill_ident (op, skill);
471 break;
472
490 case SK_DISARM_TRAPS: 473 case SK_DISARM_TRAPS:
491 exp = success = remove_trap (op, dir, skill); 474 exp = success = remove_trap (op, dir, skill);
492 break; 475 break;
493 476
494 case SK_THROWING: 477 case SK_THROWING:
495 success = skill_throw (op, part, dir, string, skill); 478 success = skill_throw (op, part, dir, string, skill);
496 break; 479 break;
497 480
498 case SK_SET_TRAP: 481 case SK_SET_TRAP:
499 new_draw_info (NDI_UNIQUE, 0, op, "This skill is not currently implemented."); 482 new_draw_info (NDI_UNIQUE, 0, op, "This skill is not currently implemented.");
500 break; 483 break;
501 484
502 case SK_USE_MAGIC_ITEM: 485 case SK_USE_MAGIC_ITEM:
503 case SK_MISSILE_WEAPON: 486 case SK_MISSILE_WEAPON:
504 new_draw_info (NDI_UNIQUE, 0, op, "There is no special attack for this skill."); 487 new_draw_info (NDI_UNIQUE, 0, op, "There is no special attack for this skill.");
505 break; 488 break;
506 489
507 case SK_PRAYING: 490 case SK_PRAYING:
508 success = pray (op, skill); 491 success = pray (op, skill);
509 break; 492 break;
510 493
511 case SK_BARGAINING: 494 case SK_BARGAINING:
512 success = describe_shop (op); 495 success = describe_shop (op);
513 break; 496 break;
514 497
515 case SK_SORCERY: 498 case SK_SORCERY:
516 case SK_EVOCATION: 499 case SK_EVOCATION:
517 case SK_PYROMANCY: 500 case SK_PYROMANCY:
518 case SK_SUMMONING: 501 case SK_SUMMONING:
519 case SK_CLIMBING: 502 case SK_CLIMBING:
520 new_draw_info (NDI_UNIQUE, 0, op, "This skill is already in effect."); 503 new_draw_info (NDI_UNIQUE, 0, op, "This skill is already in effect.");
521 break; 504 break;
522 505
523 default: 506 default:
524 LOG (llevDebug, "%s attempted to use unknown skill: %d\n", query_name (op), op->chosen_skill->stats.sp); 507 LOG (llevDebug, "%s attempted to use unknown skill: %d\n", query_name (op), op->chosen_skill->stats.sp);
525 break; 508 break;
526 } 509 }
527 510
528 /* For players we now update the speed_left from using the skill. 511 /* For players we now update the speed_left from using the skill.
529 * Monsters have no skill use time because of the random nature in 512 * Monsters have no skill use time because of the random nature in
530 * which use_monster_skill is called already simulates this. 513 * which use_monster_skill is called already simulates this.
569 * op is the object that was 'defeated'. 552 * op is the object that was 'defeated'.
570 * skill is the skill used. If no skill is used, it should just 553 * skill is the skill used. If no skill is used, it should just
571 * point back to who. 554 * point back to who.
572 * 555 *
573 */ 556 */
574
575int 557int
576calc_skill_exp (object *who, object *op, object *skill) 558calc_skill_exp (object *who, object *op, object *skill)
577{ 559{
578 int op_exp = 0, op_lvl = 0; 560 int op_exp = 0, op_lvl = 0;
579 float base, value, lvl_mult = 0.0; 561 float base, value, lvl_mult = 0.0;
668 * This one actually teaches the player the skill as something 650 * This one actually teaches the player the skill as something
669 * they can equip. 651 * they can equip.
670 * Return 0 if the player knows the skill, 1 if the 652 * Return 0 if the player knows the skill, 1 if the
671 * player learns the skill, 2 otherwise. 653 * player learns the skill, 2 otherwise.
672 */ 654 */
673
674int 655int
675learn_skill (object *pl, object *scroll) 656learn_skill (object *pl, object *scroll)
676{ 657{
677 object *tmp; 658 object *tmp;
678 659
797 } 778 }
798 779
799 clear_win_info (op); 780 clear_win_info (op);
800 new_draw_info (NDI_UNIQUE, 0, op, "Player skills:"); 781 new_draw_info (NDI_UNIQUE, 0, op, "Player skills:");
801 if (num_skills_found > 1) 782 if (num_skills_found > 1)
802 qsort (skills, num_skills_found, MAX_BUF, (int (*)(const void *, const void *)) strcmp); 783 qsort (skills, num_skills_found, MAX_BUF, (int (*)(const void *, const void *)) std::strcmp);
803 784
804 for (i = 0; i < num_skills_found; i++) 785 for (i = 0; i < num_skills_found; i++)
805 {
806 new_draw_info (NDI_UNIQUE, 0, op, skills[i]); 786 new_draw_info (NDI_UNIQUE, 0, op, skills[i]);
807 }
808 787
809 new_draw_info_format (NDI_UNIQUE, 0, op, "You can handle %d weapon improvements.", op->level / 5 + 5); 788 new_draw_info_format (NDI_UNIQUE, 0, op, "You can handle %d weapon improvements.", op->level / 5 + 5);
810 789
811 cp = determine_god (op); 790 cp = determine_god (op);
812 new_draw_info_format (NDI_UNIQUE, 0, op, "You worship %s.", cp ? cp : "no god at current time"); 791 new_draw_info_format (NDI_UNIQUE, 0, op, "You worship %s.", cp ? cp : "no god at current time");
877} 856}
878 857
879static bool 858static bool
880hth_skill_p (object *skill) 859hth_skill_p (object *skill)
881{ 860{
882 for (unsigned int i = 0; i < sizeof (unarmed_skills); ++i) 861 return (skill_flags [skill->subtype] & (SF_COMBAT | SF_NEED_WEAPON)) == SF_COMBAT;
883 if (skill->subtype == unarmed_skills[i])
884 return 1;
885
886 return 0;
887} 862}
888 863
889/* This finds the first unarmed skill the player has, and returns it. 864/* This finds the first unarmed skill the player has, and returns it.
890 */ 865 */
891static object * 866static object *
905 * tmp is the targetted monster. 880 * tmp is the targetted monster.
906 * op is what is attacking 881 * op is what is attacking
907 * string is passed along to describe what messages to describe 882 * string is passed along to describe what messages to describe
908 * the damage. 883 * the damage.
909 */ 884 */
910
911static int 885static int
912do_skill_attack (object *tmp, object *op, const char *string, object *skill) 886do_skill_attack (object *tmp, object *op, const char *string, object *skill)
913{ 887{
914 int success;
915
916 if (INVOKE_OBJECT (SKILL_ATTACK, op, ARG_OBJECT (tmp), ARG_STRING (string), ARG_OBJECT (skill))) 888 if (INVOKE_OBJECT (SKILL_ATTACK, op, ARG_OBJECT (tmp), ARG_STRING (string), ARG_OBJECT (skill)))
917 return RESULT_INT (0); 889 return RESULT_INT (0);
918 890
919 /* For Players only: if there is no ready weapon, and no "attack" skill 891 /* For Players only: if there is no ready weapon, and no "attack" skill
920 * is readied either then try to find a skill for the player to use. 892 * is readied either then try to find a skill for the player to use.
972 LOG (llevError, "Could not find applied weapon on %s\n", &op->name); 944 LOG (llevError, "Could not find applied weapon on %s\n", &op->name);
973 op->current_weapon = NULL; 945 op->current_weapon = NULL;
974 return 0; 946 return 0;
975 } 947 }
976 else 948 else
977 {
978 op->current_weapon = tmp; 949 op->current_weapon = tmp;
979 }
980 } 950 }
981 951
982 change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1); 952 change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1);
983 } 953 }
984 } 954 }
988 if (op->type == PLAYER && op->contr->tmp_invis) 958 if (op->type == PLAYER && op->contr->tmp_invis)
989 { 959 {
990 op->contr->tmp_invis = 0; 960 op->contr->tmp_invis = 0;
991 op->invisible = 0; 961 op->invisible = 0;
992 op->hide = 0; 962 op->hide = 0;
993 update_object (op, UP_OBJ_FACE); 963 update_object (op, UP_OBJ_CHANGE);
994 } 964 }
995 965
996 success = attack_ob (tmp, op); 966 int success = attack_ob (tmp, op);
997 967
998 /* print appropriate messages to the player */ 968 /* print appropriate messages to the player */
999 969
1000 if (success && string != NULL && tmp && !QUERY_FLAG (tmp, FLAG_FREED)) 970 if (success && string && tmp && !QUERY_FLAG (tmp, FLAG_FREED))
1001 { 971 {
1002 if (op->type == PLAYER) 972 if (op->type == PLAYER)
1003 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp)); 973 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp));
1004 else if (tmp->type == PLAYER) 974 else if (tmp->type == PLAYER)
1005 new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string); 975 new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string);
1006 } 976 }
977
1007 return success; 978 return success;
1008} 979}
1009
1010 980
1011/* skill_attack() - Core routine for use when we attack using a skills 981/* skill_attack() - Core routine for use when we attack using a skills
1012 * system. In essence, this code handles 982 * system. In essence, this code handles
1013 * all skill-based attacks, ie hth, missile and melee weapons should be 983 * all skill-based attacks, ie hth, missile and melee weapons should be
1014 * treated here. If an opponent is already supplied by move_player(), 984 * treated here. If an opponent is already supplied by move_player(),
1017 * 987 *
1018 * This is called by move_player() and attack_hth() 988 * This is called by move_player() and attack_hth()
1019 * 989 *
1020 * Initial implementation by -bt thomas@astro.psu.edu 990 * Initial implementation by -bt thomas@astro.psu.edu
1021 */ 991 */
1022
1023int 992int
1024skill_attack (object *tmp, object *pl, int dir, const char *string, object *skill) 993skill_attack (object *tmp, object *pl, int dir, const char *string, object *skill)
1025{ 994{
1026 sint16 tx, ty; 995 sint16 tx, ty;
1027 maptile *m; 996 maptile *m;
1034 ty = freearr_y[dir]; 1003 ty = freearr_y[dir];
1035 1004
1036 /* If we don't yet have an opponent, find if one exists, and attack. 1005 /* If we don't yet have an opponent, find if one exists, and attack.
1037 * Legal opponents are the same as outlined in move_player_attack() 1006 * Legal opponents are the same as outlined in move_player_attack()
1038 */ 1007 */
1039 1008 if (!tmp)
1040 if (tmp == NULL)
1041 { 1009 {
1042 m = pl->map; 1010 m = pl->map;
1043 tx = pl->x + freearr_x[dir]; 1011 tx = pl->x + freearr_x[dir];
1044 ty = pl->y + freearr_y[dir]; 1012 ty = pl->y + freearr_y[dir];
1045 1013
1055 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR) 1023 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR)
1056 { 1024 {
1057 /* Don't attack party members */ 1025 /* Don't attack party members */
1058 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) 1026 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party))
1059 return 0; 1027 return 0;
1028
1060 break; 1029 break;
1061 } 1030 }
1062 } 1031 }
1032
1063 if (!tmp) 1033 if (!tmp)
1064 { 1034 {
1065 if (pl->type == PLAYER) 1035 if (pl->type == PLAYER)
1066 new_draw_info (NDI_UNIQUE, 0, pl, "There is nothing to attack!"); 1036 new_draw_info (NDI_UNIQUE, 0, pl, "There is nothing to attack!");
1037
1067 return 0; 1038 return 0;
1068 } 1039 }
1069 1040
1070 return do_skill_attack (tmp, pl, string, skill); 1041 return do_skill_attack (tmp, pl, string, skill);
1071} 1042}
1097 esrv_update_item (UPD_FLAGS, pl, weapon); 1068 esrv_update_item (UPD_FLAGS, pl, weapon);
1098 } 1069 }
1099 break; 1070 break;
1100 } 1071 }
1101 } 1072 }
1073
1102 return skill_attack (enemy, pl, dir, string, skill); 1074 return skill_attack (enemy, pl, dir, string, skill);
1103} 1075}
1104
1105 1076
1106/* attack_melee_weapon() - this handles melee weapon attacks -b.t. 1077/* attack_melee_weapon() - this handles melee weapon attacks -b.t.
1107 * For now we are just checking to see if we have a ready weapon here. 1078 * For now we are just checking to see if we have a ready weapon here.
1108 * But there is a real neato possible feature of this scheme which 1079 * But there is a real neato possible feature of this scheme which
1109 * bears mentioning: 1080 * bears mentioning:
1110 * Since we are only calling this from do_skill() in the future 1081 * Since we are only calling this from do_skill() in the future
1111 * we may make this routine handle 'special' melee weapons attacks 1082 * we may make this routine handle 'special' melee weapons attacks
1112 * (like disarming manuever with sai) based on player SK_level and 1083 * (like disarming manuever with sai) based on player SK_level and
1113 * weapon type. 1084 * weapon type.
1114 */ 1085 */
1115
1116static int 1086static int
1117attack_melee_weapon (object *op, int dir, const char *string, object *skill) 1087attack_melee_weapon (object *op, int dir, const char *string, object *skill)
1118{ 1088{
1119 1089
1120 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 1090 if (!QUERY_FLAG (op, FLAG_READY_WEAPON))
1121 { 1091 {
1122 if (op->type == PLAYER) 1092 if (op->type == PLAYER)
1123 new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!"); 1093 new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!");
1094
1124 return 0; 1095 return 0;
1125 } 1096 }
1097
1126 return skill_attack (NULL, op, dir, string, skill); 1098 return skill_attack (NULL, op, dir, string, skill);
1127 1099
1128} 1100}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines