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.9 by root, Sun Sep 10 15:59:57 2006 UTC vs.
Revision 1.29 by root, Wed Mar 14 04:12:29 2007 UTC

1
2/* 1/*
3 * static char *rcsid_skill_util_c =
4 * "$Id: skill_util.C,v 1.9 2006/09/10 15:59:57 root Exp $";
5 */
6
7/*
8 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
9 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
10 Copryight (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copryight (C) 2002 Mark Wedel & Crossfire Development Team
11 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
12 7 *
13 This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version. 11 * (at your option) any later version.
17 12 *
18 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details. 16 * GNU General Public License for more details.
22 17 *
23 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 21 *
27 The author can be reached via e-mail to crossfire-devel@real-time.com 22 * The author can be reached via e-mail to <crossfire@schmorp.de>
28*/ 23 */
29 24
30/* Created July 95 to separate skill utilities from actual skills -b.t. */ 25/* Created July 95 to separate skill utilities from actual skills -b.t. */
31 26
32/* Reconfigured skills code to allow linking of skills to experience 27/* Reconfigured skills code to allow linking of skills to experience
33 * categories. This is done solely through the init_new_exp_system() fctn. 28 * categories. This is done solely through the init_new_exp_system() fctn.
43 38
44/* define the following for skills utility debuging */ 39/* define the following for skills utility debuging */
45 40
46/* #define SKILL_UTIL_DEBUG */ 41/* #define SKILL_UTIL_DEBUG */
47 42
48#define WANT_UNARMED_SKILLS
49
50#include <global.h> 43#include <global.h>
51#include <object.h> 44#include <object.h>
52#ifndef __CEXTRACT__
53# include <sproto.h> 45#include <sproto.h>
54#endif
55#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. */
56#include <spells.h> 47#include <spells.h>
57 48
49/* Table of unarmed attack skills. Terminated by -1. This
50 * is also the list that we should try to use skills when
51 * automatically applying one for the player.
52 */
53static uint8 unarmed_skills[] = {
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};
64
58static int attack_hth (object *pl, int dir, const char *string, object *skill); 65static int attack_hth (object *pl, int dir, const char *string, object *skill);
59static int attack_melee_weapon (object *op, int dir, const char *string, object *skill); 66static int attack_melee_weapon (object *op, int dir, const char *string, object *skill);
60
61shstr skill_names[NUM_SKILLS];
62 67
63/* init_skills basically just sets up the skill_names table 68/* init_skills basically just sets up the skill_names table
64 * above. The index into the array is set up by the 69 * above. The index into the array is set up by the
65 * subtypes. 70 * subtypes.
66 */ 71 */
69{ 74{
70 int i; 75 int i;
71 archetype *at; 76 archetype *at;
72 77
73 for (at = first_archetype; at != NULL; at = at->next) 78 for (at = first_archetype; at != NULL; at = at->next)
74 {
75 if (at->clone.type == SKILL) 79 if (at->clone.type == SKILL)
76 { 80 {
77 if (skill_names[at->clone.subtype] != NULL) 81 if (skill_names[at->clone.subtype] != NULL)
78 {
79 LOG (llevError, "init_skills: multiple skill using same subtype %d, %s, %s\n", 82 LOG (llevError, "init_skills: multiple skill using same subtype %d, %s, %s\n",
80 at->clone.subtype, &skill_names[at->clone.subtype], &at->clone.skill); 83 at->clone.subtype, &skill_names[at->clone.subtype], &at->clone.skill);
81 }
82 else 84 else
83 {
84 skill_names[at->clone.subtype] = at->clone.skill; 85 skill_names[at->clone.subtype] = at->clone.skill;
85 }
86 } 86 }
87 }
88 87
89 /* This isn't really an error if there is no skill subtype set, but 88 /* This isn't really an error if there is no skill subtype set, but
90 * checking for this may catch some user errors. 89 * checking for this may catch some user errors.
91 */ 90 */
92 for (i = 1; i < NUM_SKILLS; i++) 91 for (i = 1; i < NUM_SKILLS; i++)
93 { 92 {
94 if (!skill_names[i]) 93 if (!skill_names[i])
95 LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i); 94 LOG (llevError, "init_skills: skill subtype %d doesn't have a name?\n", i);
96 } 95 }
97} 96}
98
99 97
100/* This function goes through the player inventory and sets 98/* This function goes through the player inventory and sets
101 * up the last_skills[] array in the player object. 99 * up the last_skills[] array in the player object.
102 * the last_skills[] is used to more quickly lookup skills - 100 * the last_skills[] is used to more quickly lookup skills -
103 * mostly used for sending exp. 101 * mostly used for sending exp.
104 */ 102 */
105void 103void
106link_player_skills (object *op) 104link_player_skills (object *op)
107{ 105{
108 object *tmp;
109
110 for (tmp = op->inv; tmp; tmp = tmp->below) 106 for (object *tmp = op->inv; tmp; tmp = tmp->below)
111 {
112 if (tmp->type == SKILL) 107 if (tmp->type == SKILL)
113 { 108 {
114 /* This is really a warning, hence no else below */ 109 /* This is really a warning, hence no else below */
115 if (op->contr->last_skill_ob[tmp->subtype] && op->contr->last_skill_ob[tmp->subtype] != tmp) 110 if (op->contr->last_skill_ob[tmp->subtype] && op->contr->last_skill_ob[tmp->subtype] != tmp)
116 {
117 LOG (llevError, "Multiple skills with the same subtype? %s, %s\n", 111 LOG (llevError, "Multiple skills with the same subtype? %s, %s\n",
118 &op->contr->last_skill_ob[tmp->subtype]->skill, &tmp->skill); 112 &op->contr->last_skill_ob[tmp->subtype]->skill, &tmp->skill);
119 } 113
120 if (tmp->subtype >= NUM_SKILLS) 114 if (tmp->subtype >= NUM_SKILLS)
121 {
122 LOG (llevError, "Invalid subtype number %d (range 0-%d)\n", tmp->subtype, NUM_SKILLS); 115 LOG (llevError, "Invalid subtype number %d (range 0-%d)\n", tmp->subtype, NUM_SKILLS);
123 }
124 else 116 else
125 { 117 {
126 op->contr->last_skill_ob[tmp->subtype] = tmp; 118 op->contr->last_skill_ob[tmp->subtype] = tmp;
127 op->contr->last_skill_exp[tmp->subtype] = -1; 119 op->contr->ns->last_skill_exp[tmp->subtype] = -1; //TODO: this should go
128 } 120 }
129 } 121 }
130 }
131} 122}
132 123
133/* This returns the skill pointer of the given name (the 124/* This returns the skill pointer of the given name (the
134 * one that accumlates exp, has the level, etc). 125 * one that accumlates exp, has the level, etc).
135 * 126 *
239 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) 230 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED))
240 { 231 {
241 if (apply_special (who, skill_tool, 0)) 232 if (apply_special (who, skill_tool, 0))
242 return NULL; 233 return NULL;
243 } 234 }
235
244 if (!skill) 236 if (!skill)
245 { 237 {
246 skill = give_skill_by_name (who, skill_tool->skill); 238 skill = give_skill_by_name (who, skill_tool->skill);
247 link_player_skills (who); 239 link_player_skills (who);
248 } 240 }
241
249 return skill; 242 return skill;
250 } 243 }
244
251 return NULL; 245 return NULL;
252} 246}
253 247
254/* This changes the objects skill to new_skill. 248/* This changes the objects skill to new_skill.
255 * note that this function doesn't always need to get used - 249 * note that this function doesn't always need to get used -
276 if (who->chosen_skill && who->chosen_skill == new_skill) 270 if (who->chosen_skill && who->chosen_skill == new_skill)
277 { 271 {
278 /* optimization for changing skill to current skill */ 272 /* optimization for changing skill to current skill */
279 if (who->type == PLAYER && !(flag & 0x1)) 273 if (who->type == PLAYER && !(flag & 0x1))
280 who->contr->shoottype = range_skill; 274 who->contr->shoottype = range_skill;
275
281 return 1; 276 return 1;
282 } 277 }
278
279 // move skill to front, so it will be preferred next time
280 new_skill->remove ();
281 who->insert (new_skill);
283 282
284 if (!new_skill || who->chosen_skill) 283 if (!new_skill || who->chosen_skill)
285 if (who->chosen_skill) 284 if (who->chosen_skill)
286 apply_special (who, who->chosen_skill, AP_UNAPPLY); 285 apply_special (who, who->chosen_skill, AP_UNAPPLY);
287 286
288 /* Only goal in this case was to unapply a skill */ 287 /* Only goal in this case was to unapply a skill */
289 if (!new_skill) 288 if (!new_skill)
290 return 0; 289 return 0;
291 290
292 if (apply_special (who, new_skill, AP_APPLY)) 291 if (apply_special (who, new_skill, AP_APPLY))
293 {
294 return 0; 292 return 0;
295 } 293
296 if (flag & 0x1) 294 if (flag & 0x1)
297 who->contr->shoottype = (rangetype) old_range; 295 who->contr->shoottype = (rangetype)old_range;
298 296
299 return 1; 297 return 1;
300} 298}
301 299
302/* This function just clears the chosen_skill and range_skill values 300/* This function just clears the chosen_skill and range_skill values
342 * the player doesn't have a bucket for that, create one. 340 * the player doesn't have a bucket for that, create one.
343 */ 341 */
344 if (skill->type != SKILL && op->type == PLAYER) 342 if (skill->type != SKILL && op->type == PLAYER)
345 { 343 {
346 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 344 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
347 {
348 if (tmp->type == SKILL && tmp->skill == skill->skill) 345 if (tmp->type == SKILL && tmp->skill == skill->skill)
349 break; 346 break;
350 } 347
351 if (!tmp) 348 if (!tmp)
352 tmp = give_skill_by_name (op, skill->skill); 349 tmp = give_skill_by_name (op, skill->skill);
350
353 skill = tmp; 351 skill = tmp;
354 } 352 }
355 353
356 // skill, by_whom, on_which_object, which direction, skill_argument 354 // skill, by_whom, on_which_object, which direction, skill_argument
357 if (INVOKE_OBJECT (USE_SKILL, skill, ARG_OBJECT (op), ARG_OBJECT (part), ARG_INT (dir), ARG_STRING (string))) 355 if (INVOKE_OBJECT (USE_SKILL, skill, ARG_OBJECT (op), ARG_OBJECT (part), ARG_INT (dir), ARG_STRING (string)))
358 return 0; 356 return 0;
359 357
360 switch (skill->subtype) 358 switch (skill->subtype)
361 { 359 {
362 case SK_LEVITATION: 360 case SK_LEVITATION:
363 /* Not 100% sure if this will work with new movement code - 361 /* Not 100% sure if this will work with new movement code -
364 * the levitation skill has move_type for flying, so when 362 * the levitation skill has move_type for flying, so when
365 * equipped, that should transfer to player, when not, 363 * equipped, that should transfer to player, when not,
366 * shouldn't. 364 * shouldn't.
367 */ 365 */
368 if (QUERY_FLAG (skill, FLAG_APPLIED)) 366 if (QUERY_FLAG (skill, FLAG_APPLIED))
369 { 367 {
370 CLEAR_FLAG (skill, FLAG_APPLIED); 368 CLEAR_FLAG (skill, FLAG_APPLIED);
371 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth."); 369 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth.");
372 } 370 }
373 else 371 else
374 { 372 {
375 SET_FLAG (skill, FLAG_APPLIED); 373 SET_FLAG (skill, FLAG_APPLIED);
376 new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!."); 374 new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!.");
377 } 375 }
378 fix_player (op); 376
377 op->update_stats ();
379 success = 1; 378 success = 1;
380 break; 379 break;
381 380
382 case SK_STEALING: 381 case SK_STEALING:
383 exp = success = steal (op, dir, skill); 382 exp = success = steal (op, dir, skill);
384 break; 383 break;
385 384
386 case SK_LOCKPICKING: 385 case SK_LOCKPICKING:
387 exp = success = pick_lock (op, dir, skill); 386 exp = success = pick_lock (op, dir, skill);
388 break; 387 break;
389 388
390 case SK_HIDING: 389 case SK_HIDING:
391 exp = success = hide (op, skill); 390 exp = success = hide (op, skill);
392 break; 391 break;
393 392
394 case SK_JUMPING: 393 case SK_JUMPING:
395 success = jump (op, dir, skill); 394 success = jump (op, dir, skill);
396 break; 395 break;
397 396
398 case SK_INSCRIPTION: 397 case SK_INSCRIPTION:
399 exp = success = write_on_item (op, string, skill); 398 exp = success = write_on_item (op, string, skill);
400 break; 399 break;
401 400
402 case SK_MEDITATION: 401 case SK_MEDITATION:
403 meditate (op, skill); 402 meditate (op, skill);
404 success = 1; 403 success = 1;
405 break; 404 break;
406 /* note that the following 'attack' skills gain exp through hit_player() */ 405 /* note that the following 'attack' skills gain exp through hit_player() */
407 406
408 case SK_KARATE: 407 case SK_KARATE:
409 (void) attack_hth (op, dir, "karate-chopped", skill); 408 (void) attack_hth (op, dir, "karate-chopped", skill);
410 break; 409 break;
411 410
412 case SK_PUNCHING: 411 case SK_PUNCHING:
413 (void) attack_hth (op, dir, "punched", skill); 412 (void) attack_hth (op, dir, "punched", skill);
414 break; 413 break;
415 414
416 case SK_FLAME_TOUCH: 415 case SK_FLAME_TOUCH:
417 (void) attack_hth (op, dir, "flamed", skill); 416 (void) attack_hth (op, dir, "flamed", skill);
418 break; 417 break;
419 418
420 case SK_SPARK_TOUCH: 419 case SK_SPARK_TOUCH:
421 (void) attack_hth (op, dir, "zapped", skill); 420 (void) attack_hth (op, dir, "zapped", skill);
422 break; 421 break;
423 422
424 case SK_SHIVER: 423 case SK_SHIVER:
425 (void) attack_hth (op, dir, "froze", skill); 424 (void) attack_hth (op, dir, "froze", skill);
426 break; 425 break;
427 426
428 case SK_ACID_SPLASH: 427 case SK_ACID_SPLASH:
429 (void) attack_hth (op, dir, "dissolved", skill); 428 (void) attack_hth (op, dir, "dissolved", skill);
430 break; 429 break;
431 430
432 case SK_POISON_NAIL: 431 case SK_POISON_NAIL:
433 (void) attack_hth (op, dir, "injected poison into", skill); 432 (void) attack_hth (op, dir, "injected poison into", skill);
434 break; 433 break;
435 434
436 case SK_CLAWING: 435 case SK_CLAWING:
437 (void) attack_hth (op, dir, "clawed", skill); 436 (void) attack_hth (op, dir, "clawed", skill);
438 break; 437 break;
439 438
440 case SK_ONE_HANDED_WEAPON: 439 case SK_ONE_HANDED_WEAPON:
441 case SK_TWO_HANDED_WEAPON: 440 case SK_TWO_HANDED_WEAPON:
442 (void) attack_melee_weapon (op, dir, NULL, skill); 441 (void) attack_melee_weapon (op, dir, NULL, skill);
443 break; 442 break;
444 443
445 case SK_FIND_TRAPS: 444 case SK_FIND_TRAPS:
446 exp = success = find_traps (op, skill); 445 exp = success = find_traps (op, skill);
447 break; 446 break;
448 447
449 case SK_SINGING: 448 case SK_SINGING:
450 exp = success = singing (op, dir, skill); 449 exp = success = singing (op, dir, skill);
451 break; 450 break;
452 451
453 case SK_ORATORY: 452 case SK_ORATORY:
454 exp = success = use_oratory (op, dir, skill); 453 exp = success = use_oratory (op, dir, skill);
455 break; 454 break;
456 455
457 case SK_SMITHERY: 456 case SK_SMITHERY:
458 case SK_BOWYER: 457 case SK_BOWYER:
459 case SK_JEWELER: 458 case SK_JEWELER:
460 case SK_ALCHEMY: 459 case SK_ALCHEMY:
461 case SK_THAUMATURGY: 460 case SK_THAUMATURGY:
462 case SK_LITERACY: 461 case SK_LITERACY:
463 case SK_WOODSMAN: 462 case SK_WOODSMAN:
464 /* first, we try to find a cauldron, and do the alchemy thing. 463 /* first, we try to find a cauldron, and do the alchemy thing.
465 * failing that, we go and identify stuff. 464 * failing that, we go and identify stuff.
466 */ 465 */
467 for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = next) 466 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = next)
468 { 467 {
469 next = tmp->above; 468 next = tmp->above;
469
470 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 470 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON))
471 { 471 {
472 attempt_do_alchemy (op, tmp); 472 attempt_do_alchemy (op, tmp);
473
473 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 474 if (QUERY_FLAG (tmp, FLAG_APPLIED))
474 esrv_send_inventory (op, tmp); 475 esrv_send_inventory (op, tmp);
476
475 did_alc = 1; 477 did_alc = 1;
476 } 478 }
477 } 479 }
480
478 if (did_alc == 0) 481 if (did_alc == 0)
479 exp = success = skill_ident (op, skill);
480 break;
481
482 case SK_DET_MAGIC:
483 case SK_DET_CURSE:
484 exp = success = skill_ident (op, skill); 482 exp = success = skill_ident (op, skill);
483
485 break; 484 break;
486 485
486 case SK_DET_MAGIC:
487 case SK_DET_CURSE:
488 exp = success = skill_ident (op, skill);
489 break;
490
487 case SK_DISARM_TRAPS: 491 case SK_DISARM_TRAPS:
488 exp = success = remove_trap (op, dir, skill); 492 exp = success = remove_trap (op, dir, skill);
489 break; 493 break;
490 494
491 case SK_THROWING: 495 case SK_THROWING:
492 success = skill_throw (op, part, dir, string, skill); 496 success = skill_throw (op, part, dir, string, skill);
493 break; 497 break;
494 498
495 case SK_SET_TRAP: 499 case SK_SET_TRAP:
496 new_draw_info (NDI_UNIQUE, 0, op, "This skill is not currently implemented."); 500 new_draw_info (NDI_UNIQUE, 0, op, "This skill is not currently implemented.");
497 break; 501 break;
498 502
499 case SK_USE_MAGIC_ITEM: 503 case SK_USE_MAGIC_ITEM:
500 case SK_MISSILE_WEAPON: 504 case SK_MISSILE_WEAPON:
501 new_draw_info (NDI_UNIQUE, 0, op, "There is no special attack for this skill."); 505 new_draw_info (NDI_UNIQUE, 0, op, "There is no special attack for this skill.");
502 break; 506 break;
503 507
504 case SK_PRAYING: 508 case SK_PRAYING:
505 success = pray (op, skill); 509 success = pray (op, skill);
506 break; 510 break;
507 511
508 case SK_BARGAINING: 512 case SK_BARGAINING:
509 success = describe_shop (op); 513 success = describe_shop (op);
510 break; 514 break;
511 515
512 case SK_SORCERY: 516 case SK_SORCERY:
513 case SK_EVOCATION: 517 case SK_EVOCATION:
514 case SK_PYROMANCY: 518 case SK_PYROMANCY:
515 case SK_SUMMONING: 519 case SK_SUMMONING:
516 case SK_CLIMBING: 520 case SK_CLIMBING:
517 new_draw_info (NDI_UNIQUE, 0, op, "This skill is already in effect."); 521 new_draw_info (NDI_UNIQUE, 0, op, "This skill is already in effect.");
518 break; 522 break;
519 523
520 default: 524 default:
521 LOG (llevDebug, "%s attempted to use unknown skill: %d\n", query_name (op), op->chosen_skill->stats.sp); 525 LOG (llevDebug, "%s attempted to use unknown skill: %d\n", query_name (op), op->chosen_skill->stats.sp);
522 break; 526 break;
523 } 527 }
524 528
525 /* For players we now update the speed_left from using the skill. 529 /* For players we now update the speed_left from using the skill.
526 * Monsters have no skill use time because of the random nature in 530 * Monsters have no skill use time because of the random nature in
527 * which use_monster_skill is called already simulates this. 531 * which use_monster_skill is called already simulates this.
689 693
690 /* player already knows it */ 694 /* player already knows it */
691 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) 695 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL))
692 return 0; 696 return 0;
693 697
694
695
696 /* now a random change to learn, based on player Int. 698 /* now a random change to learn, based on player Int.
697 * give bonus based on level - otherwise stupid characters 699 * give bonus based on level - otherwise stupid characters
698 * might never be able to learn anything. 700 * might never be able to learn anything.
699 */ 701 */
700 if (random_roll (0, 99, pl, PREFER_LOW) > (learn_spell[pl->stats.Int] + (pl->level / 5))) 702 if (random_roll (0, 99, pl, PREFER_LOW) > (learn_spell[pl->stats.Int] + (pl->level / 5)))
769 sprintf (buf, "%s%s", &tmp->name, periods); 771 sprintf (buf, "%s%s", &tmp->name, periods);
770 buf[40] = 0; 772 buf[40] = 0;
771 773
772 if (settings.permanent_exp_ratio) 774 if (settings.permanent_exp_ratio)
773 { 775 {
774 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%lld/%lld/%d%%)", 776 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%" PRId64 "/%" PRId64 "/%d%%)",
775 buf, tmp->level, 777 buf, tmp->level, tmp->stats.exp,
776 (long long) tmp->stats.exp,
777 (long long) level_exp (tmp->level + 1, op->expmul), clipped_percent (tmp->perm_exp, tmp->stats.exp)); 778 level_exp (tmp->level + 1, op->expmul), clipped_percent (tmp->perm_exp, tmp->stats.exp));
778 } 779 }
779 else 780 else
780 { 781 {
781 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%lld/%lld)", 782 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%" PRId64 "/%" PRId64 ")",
782 buf, tmp->level, (long long) tmp->stats.exp, (long long) level_exp (tmp->level + 1, op->expmul)); 783 buf, tmp->level, tmp->stats.exp, level_exp (tmp->level + 1, op->expmul));
783 } 784 }
784 /* I don't know why some characters get a bunch of skills, but 785 /* I don't know why some characters get a bunch of skills, but
785 * it sometimes happens (maybe a leftover from bugier earlier code 786 * it sometimes happens (maybe a leftover from bugier earlier code
786 * and those character are still about). In any case, lets handle 787 * and those character are still about). In any case, lets handle
787 * it so it doesn't crash the server - otherwise, one character may 788 * it so it doesn't crash the server - otherwise, one character may
797 } 798 }
798 799
799 clear_win_info (op); 800 clear_win_info (op);
800 new_draw_info (NDI_UNIQUE, 0, op, "Player skills:"); 801 new_draw_info (NDI_UNIQUE, 0, op, "Player skills:");
801 if (num_skills_found > 1) 802 if (num_skills_found > 1)
802 qsort (skills, num_skills_found, MAX_BUF, (int (*)(const void *, const void *)) strcmp); 803 qsort (skills, num_skills_found, MAX_BUF, (int (*)(const void *, const void *)) std::strcmp);
803 804
804 for (i = 0; i < num_skills_found; i++) 805 for (i = 0; i < num_skills_found; i++)
805 {
806 new_draw_info (NDI_UNIQUE, 0, op, skills[i]); 806 new_draw_info (NDI_UNIQUE, 0, op, skills[i]);
807 }
808 807
809 new_draw_info_format (NDI_UNIQUE, 0, op, "You can handle %d weapon improvements.", op->level / 5 + 5); 808 new_draw_info_format (NDI_UNIQUE, 0, op, "You can handle %d weapon improvements.", op->level / 5 + 5);
810 809
811 cp = determine_god (op); 810 cp = determine_god (op);
812 new_draw_info_format (NDI_UNIQUE, 0, op, "You worship %s.", cp ? cp : "no god at current time"); 811 new_draw_info_format (NDI_UNIQUE, 0, op, "You worship %s.", cp ? cp : "no god at current time");
874 return 1; 873 return 1;
875 874
876 return 0; 875 return 0;
877} 876}
878 877
878static bool
879hth_skill_p (object *skill)
880{
881 for (unsigned int i = 0; i < sizeof (unarmed_skills); ++i)
882 if (skill->subtype == unarmed_skills[i])
883 return 1;
879 884
885 return 0;
886}
880 887
881/* This finds the best unarmed skill the player has, and returns 888/* This finds the first unarmed skill the player has, and returns it.
882 * it. Best can vary a little - we consider clawing to always
883 * be the best for dragons.
884 * This could be more intelligent, eg, look at the skill level
885 * of the skill and go from there (eg, a level 40 puncher is
886 * is probably better than level 1 karate). OTOH, if you
887 * don't bother to set up your skill properly, that is the players
888 * problem (although, it might be nice to have a preferred skill
889 * field the player can set.
890 * Unlike the old code, we don't give out any skills - it is
891 * possible you just don't have any ability to get into unarmed
892 * combat. If everyone race/class should have one, this should
893 * be handled in the starting treasurelists, not in the code.
894 */ 889 */
895static object * 890static object *
896find_best_player_hth_skill (object *op) 891find_player_hth_skill (object *op)
897{ 892{
898 object *tmp, *best_skill = NULL;
899 int dragon = is_dragon_pl (op), last_skill = sizeof (unarmed_skills), i;
900
901 for (tmp = op->inv; tmp; tmp = tmp->below) 893 for (object *tmp = op->inv; tmp; tmp = tmp->below)
902 { 894 if (tmp->type == SKILL && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL) && hth_skill_p (tmp))
903 if (tmp->type == SKILL)
904 {
905 if (dragon && tmp->subtype == SK_CLAWING)
906 return tmp; 895 return tmp;
907 896
908 /* The order in the array is preferred order. So basically, 897 return 0;
909 * we just cut down the number to search - eg, if we find a skill
910 * early on in flame touch, then we only need to look into the unarmed_array
911 * to the entry before flame touch - don't care about the entries afterward,
912 * because they are infrerior skills.
913 * if we end up finding the best skill (i==0) might as well return
914 * right away - can't get any better than that.
915 */
916 for (i = 0; i < last_skill; i++)
917 {
918 if (tmp->subtype == unarmed_skills[i] && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL))
919 {
920 best_skill = tmp;
921 last_skill = i;
922 if (i == 0)
923 return best_skill;
924 }
925 }
926 }
927 }
928 return best_skill;
929} 898}
930 899
931/* do_skill_attack() - We have got an appropriate opponent from either 900/* do_skill_attack() - We have got an appropriate opponent from either
932 * move_player_attack() or skill_attack(). In this part we get on with 901 * move_player_attack() or skill_attack(). In this part we get on with
933 * attacking, take care of messages from the attack and changes in invisible. 902 * attacking, take care of messages from the attack and changes in invisible.
954 */ 923 */
955 if (op->type == PLAYER) 924 if (op->type == PLAYER)
956 { 925 {
957 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 926 if (!QUERY_FLAG (op, FLAG_READY_WEAPON))
958 { 927 {
959 size_t i;
960
961 if (!skill) 928 if (!skill)
962 { 929 {
963 /* See if the players chosen skill is a combat skill, and use 930 /* See if the players chosen skill is a combat skill, and use
964 * it if appropriate. 931 * it if appropriate.
965 */ 932 */
933 if (op->chosen_skill && hth_skill_p (op->chosen_skill))
966 if (op->chosen_skill) 934 skill = op->chosen_skill;
935 else
967 { 936 {
968 for (i = 0; i < sizeof (unarmed_skills); i++)
969 if (op->chosen_skill->subtype == unarmed_skills[i])
970 {
971 skill = op->chosen_skill;
972 break;
973 }
974 }
975 /* If we didn't find a skill above, look harder for a good skill */
976 if (!skill)
977 {
978 skill = find_best_player_hth_skill (op); 937 skill = find_player_hth_skill (op);
979 938
980 if (!skill) 939 if (!skill)
981 { 940 {
982 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); 941 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!");
983 return 0; 942 return 0;
984 } 943 }
985 } 944 }
986 } 945 }
987 if (skill != op->chosen_skill) 946
988 {
989 /* now try to ready the new skill */ 947 /* now try to ready the new skill */
990 if (!change_skill (op, skill, 0)) 948 if (!change_skill (op, skill, 0))
991 { /* oh oh, trouble! */ 949 { /* oh oh, trouble! */
992 new_draw_info_format (NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name); 950 new_draw_info_format (NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name);
993 return 0; 951 return 0;
994 }
995 } 952 }
996 } 953 }
997 else 954 else
998 { 955 {
999 /* Seen some crashes below where current_weapon is not set, 956 /* Seen some crashes below where current_weapon is not set,
1019 { 976 {
1020 op->current_weapon = tmp; 977 op->current_weapon = tmp;
1021 } 978 }
1022 } 979 }
1023 980
1024 /* Has ready weapon - make sure chosen_skill is set up properly */
1025 if (!op->chosen_skill || op->current_weapon->skill != op->chosen_skill->skill)
1026 {
1027 change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1); 981 change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1);
1028 }
1029 } 982 }
1030 } 983 }
1031 984
1032 /* lose invisiblity/hiding status for running attacks */ 985 /* lose invisiblity/hiding status for running attacks */
1033 986
1034 if (op->type == PLAYER && op->contr->tmp_invis) 987 if (op->type == PLAYER && op->contr->tmp_invis)
1035 { 988 {
1036 op->contr->tmp_invis = 0; 989 op->contr->tmp_invis = 0;
1037 op->invisible = 0; 990 op->invisible = 0;
1038 op->hide = 0; 991 op->hide = 0;
1039 update_object (op, UP_OBJ_FACE); 992 update_object (op, UP_OBJ_CHANGE);
1040 } 993 }
1041 994
1042 success = attack_ob (tmp, op); 995 success = attack_ob (tmp, op);
1043 996
1044 /* print appropriate messages to the player */ 997 /* print appropriate messages to the player */
1068 1021
1069int 1022int
1070skill_attack (object *tmp, object *pl, int dir, const char *string, object *skill) 1023skill_attack (object *tmp, object *pl, int dir, const char *string, object *skill)
1071{ 1024{
1072 sint16 tx, ty; 1025 sint16 tx, ty;
1073 mapstruct *m; 1026 maptile *m;
1074 int mflags; 1027 int mflags;
1075 1028
1076 if (!dir) 1029 if (!dir)
1077 dir = pl->facing; 1030 dir = pl->facing;
1031
1078 tx = freearr_x[dir]; 1032 tx = freearr_x[dir];
1079 ty = freearr_y[dir]; 1033 ty = freearr_y[dir];
1080 1034
1081 /* If we don't yet have an opponent, find if one exists, and attack. 1035 /* If we don't yet have an opponent, find if one exists, and attack.
1082 * Legal opponents are the same as outlined in move_player_attack() 1036 * Legal opponents are the same as outlined in move_player_attack()
1094 1048
1095 /* space must be blocked for there to be anything interesting to do */ 1049 /* space must be blocked for there to be anything interesting to do */
1096 if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty))) 1050 if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty)))
1097 return 0; 1051 return 0;
1098 1052
1099 for (tmp = get_map_ob (m, tx, ty); tmp; tmp = tmp->above) 1053 for (tmp = GET_MAP_OB (m, tx, ty); tmp; tmp = tmp->above)
1100 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR) 1054 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR)
1101 { 1055 {
1102 /* Don't attack party members */ 1056 /* Don't attack party members */
1103 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) 1057 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party))
1104 return 0; 1058 return 0;
1133 { 1087 {
1134 if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED)) 1088 if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED))
1135 { 1089 {
1136 CLEAR_FLAG (weapon, FLAG_APPLIED); 1090 CLEAR_FLAG (weapon, FLAG_APPLIED);
1137 CLEAR_FLAG (pl, FLAG_READY_WEAPON); 1091 CLEAR_FLAG (pl, FLAG_READY_WEAPON);
1138 fix_player (pl); 1092 pl->update_stats ();
1139 if (pl->type == PLAYER) 1093 if (pl->type == PLAYER)
1140 { 1094 {
1141 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); 1095 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack.");
1142 esrv_update_item (UPD_FLAGS, pl, weapon); 1096 esrv_update_item (UPD_FLAGS, pl, weapon);
1143 } 1097 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines