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.23 by root, Tue Dec 26 08:55:00 2006 UTC vs.
Revision 1.34 by root, Mon Apr 30 05:54:14 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
3 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
4 Copryight (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copryight (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
6 7 *
7 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
8 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
9 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 11 * (at your option) any later version.
11 12 *
12 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,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 16 * GNU General Public License for more details.
16 17 *
17 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
18 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 21 *
21 The author can be reached via e-mail to <crossfire@schmorp.de> 22 * The author can be reached via e-mail to <crossfire@schmorp.de>
22*/ 23 */
23 24
24/* 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. */
25 26
26/* Reconfigured skills code to allow linking of skills to experience 27/* Reconfigured skills code to allow linking of skills to experience
27 * 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#include <object.h> 44#include <object.h>
44#include <sproto.h> 45#include <sproto.h>
45#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. */
46#include <spells.h> 47#include <spells.h>
47 48
48/* Table of unarmed attack skills. Terminated by -1. This 49const uint8_t skill_flags[NUM_SKILLS] = {
49 * is also the list that we should try to use skills when 50 0, // SK_NONE
50 * automatically applying one for the player. 51# define def(uc, flags) flags,
51 */ 52# include "skillinc.h"
52static uint8 unarmed_skills[] = { 53# undef def
53 SK_KARATE,
54 SK_CLAWING,
55 SK_FLAME_TOUCH,
56 SK_SPARK_TOUCH,
57 SK_SHIVER,
58 SK_ACID_SPLASH,
59 SK_POISON_NAIL,
60 SK_PUNCHING,
61 (uint8)-1
62}; 54};
63 55
64static 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);
65static 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);
66 58
69 * subtypes. 61 * subtypes.
70 */ 62 */
71void 63void
72init_skills (void) 64init_skills (void)
73{ 65{
74 int i;
75 archetype *at;
76
77 for (at = first_archetype; at != NULL; at = at->next) 66 for (archetype *at = first_archetype; at; at = at->next)
78 if (at->clone.type == SKILL) 67 if (at->clone.type == SKILL)
79 { 68 {
80 if (skill_names[at->clone.subtype] != NULL) 69 if (skill_names[at->clone.subtype])
81 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",
82 at->clone.subtype, &skill_names[at->clone.subtype], &at->clone.skill); 71 at->clone.subtype, &skill_names[at->clone.subtype], &at->clone.skill);
83 else 72 else
84 skill_names[at->clone.subtype] = at->clone.skill; 73 skill_names[at->clone.subtype] = at->clone.skill;
85 } 74 }
86 75
87 /* 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
88 * checking for this may catch some user errors. 77 * checking for this may catch some user errors.
89 */ 78 */
90 for (i = 1; i < NUM_SKILLS; i++) 79 for (int i = 1; i < NUM_SKILLS; i++)
91 {
92 if (!skill_names[i]) 80 if (!skill_names[i])
93 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);
94 }
95} 82}
96 83
97/* This function goes through the player inventory and sets 84/* This function goes through the player inventory and sets
98 * up the last_skills[] array in the player object. 85 * up the last_skills[] array in the player object.
99 * the last_skills[] is used to more quickly lookup skills - 86 * the last_skills[] is used to more quickly lookup skills -
100 * mostly used for sending exp. 87 * mostly used for sending exp.
101 */ 88 */
102void 89void
103link_player_skills (object *op) 90link_player_skills (object *op)
104{ 91{
105 object *tmp;
106
107 for (tmp = op->inv; tmp; tmp = tmp->below) 92 for (object *tmp = op->inv; tmp; tmp = tmp->below)
108 {
109 if (tmp->type == SKILL) 93 if (tmp->type == SKILL)
110 { 94 {
111 /* This is really a warning, hence no else below */ 95 /* This is really a warning, hence no else below */
112 if (op->contr->last_skill_ob[tmp->subtype] && op->contr->last_skill_ob[tmp->subtype] != tmp) 96 if (op->contr->last_skill_ob[tmp->subtype] && op->contr->last_skill_ob[tmp->subtype] != tmp)
113 {
114 LOG (llevError, "Multiple skills with the same subtype? %s, %s\n", 97 LOG (llevError, "Multiple skills with the same subtype? %s, %s\n",
115 &op->contr->last_skill_ob[tmp->subtype]->skill, &tmp->skill); 98 &op->contr->last_skill_ob[tmp->subtype]->skill, &tmp->skill);
116 } 99
117 if (tmp->subtype >= NUM_SKILLS) 100 if (tmp->subtype >= NUM_SKILLS)
118 {
119 LOG (llevError, "Invalid subtype number %d (range 0-%d)\n", tmp->subtype, NUM_SKILLS); 101 LOG (llevError, "Invalid subtype number %d (range 0-%d)\n", tmp->subtype, NUM_SKILLS);
120 }
121 else 102 else
122 { 103 {
123 op->contr->last_skill_ob[tmp->subtype] = tmp; 104 op->contr->last_skill_ob[tmp->subtype] = tmp;
124 op->contr->last_skill_exp[tmp->subtype] = -1; 105 op->contr->ns->last_skill_exp[tmp->subtype] = -1; //TODO: this should go
125 } 106 }
126 } 107 }
127 }
128} 108}
129 109
130/* This returns the skill pointer of the given name (the 110/* This returns the skill pointer of the given name (the
131 * one that accumlates exp, has the level, etc). 111 * one that accumlates exp, has the level, etc).
132 * 112 *
175 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) 155 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED))
176 { 156 {
177 if (apply_special (who, skill_tool, 0)) 157 if (apply_special (who, skill_tool, 0))
178 return NULL; 158 return NULL;
179 } 159 }
160
180 if (!skill) 161 if (!skill)
181 { 162 {
182 skill = give_skill_by_name (who, skill_tool->skill); 163 skill = give_skill_by_name (who, skill_tool->skill);
183 link_player_skills (who); 164 link_player_skills (who);
184 } 165 }
166
185 return skill; 167 return skill;
186 } 168 }
169
187 return NULL; 170 return NULL;
188} 171}
189 172
190 173
191/* This returns the skill pointer of the given name (the 174/* This returns the skill pointer of the given name (the
260 * flag has the current meaning: 243 * flag has the current meaning:
261 * 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
262 * 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.
263 * return 1 on success, 0 on error 246 * return 1 on success, 0 on error
264 */ 247 */
265
266int 248int
267change_skill (object *who, object *new_skill, int flag) 249change_skill (object *who, object *new_skill, int flag)
268{ 250{
269 int old_range; 251 int old_range;
270 252
271 if (who->type != PLAYER) 253 if (who->type != PLAYER)
272 return 0; 254 return 0;
273 255
274 old_range = who->contr->shoottype; 256 player *pl = who->contr;
275 257
276 if (who->chosen_skill && who->chosen_skill == new_skill) 258 if (pl->ranged_skill && pl->ranged_skill == new_skill)
277 { 259 return 1;
278 /* optimization for changing skill to current skill */
279 if (who->type == PLAYER && !(flag & 0x1))
280 who->contr->shoottype = range_skill;
281 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 */
282 return 1; 267 return 0;
283 } 268 }
284 269
285 // move skill to front, so it will be preferred next time 270 // move skill to front, so it will be preferred next time
286 new_skill->remove (); 271 new_skill->remove ();
287 who->insert (new_skill); 272 who->insert (new_skill);
288 273
289 if (!new_skill || who->chosen_skill)
290 if (who->chosen_skill)
291 apply_special (who, who->chosen_skill, AP_UNAPPLY);
292
293 /* Only goal in this case was to unapply a skill */
294 if (!new_skill)
295 return 0;
296
297 if (apply_special (who, new_skill, AP_APPLY)) 274 if (apply_special (who, new_skill, AP_APPLY))
298 return 0; 275 return 0;
299 276
300 if (flag & 0x1)
301 who->contr->shoottype = (rangetype)old_range;
302
303 return 1; 277 return 1;
304} 278}
305 279
306/* This function just clears the chosen_skill and range_skill values 280/* This function just clears the chosen_skill and range_skill values
307 * inthe player. 281 * in the player.
308 */ 282 */
309void 283void
310clear_skill (object *who) 284clear_skill (object *who)
311{ 285{
312 who->chosen_skill = NULL; 286 who->chosen_skill = 0;
313 CLEAR_FLAG (who, FLAG_READY_SKILL); 287 CLEAR_FLAG (who, FLAG_READY_SKILL);
288
314 if (who->type == PLAYER) 289 if (who->type == PLAYER)
315 { 290 {
291 if (who->contr->ranged_skill && who->contr->ranged_skill->type == SKILL)
292 {
316 who->contr->ranges[range_skill] = NULL; 293 who->contr->ranged_skill = 0;
317 if (who->contr->shoottype == range_skill) 294 who->contr->ranged_ob = 0;
318 who->contr->shoottype = range_none; 295 }
319 } 296 }
320} 297}
321 298
322/* 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().
323 * 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.
327 * 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
328 * 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
329 * give any exp for their direct use (eg, throwing). 306 * give any exp for their direct use (eg, throwing).
330 * It returns 0 if no skill was used. 307 * It returns 0 if no skill was used.
331 */ 308 */
332
333int 309int
334do_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)
335{ 311{
336 int success = 0, exp = 0; 312 int success = 0, exp = 0;
337 int did_alc = 0; 313 int did_alc = 0;
346 * the player doesn't have a bucket for that, create one. 322 * the player doesn't have a bucket for that, create one.
347 */ 323 */
348 if (skill->type != SKILL && op->type == PLAYER) 324 if (skill->type != SKILL && op->type == PLAYER)
349 { 325 {
350 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 326 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
351 {
352 if (tmp->type == SKILL && tmp->skill == skill->skill) 327 if (tmp->type == SKILL && tmp->skill == skill->skill)
353 break; 328 break;
354 } 329
355 if (!tmp) 330 if (!tmp)
356 tmp = give_skill_by_name (op, skill->skill); 331 tmp = give_skill_by_name (op, skill->skill);
332
357 skill = tmp; 333 skill = tmp;
358 } 334 }
359 335
360 // skill, by_whom, on_which_object, which direction, skill_argument 336 // skill, by_whom, on_which_object, which direction, skill_argument
361 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)))
362 return 0; 338 return 0;
363 339
364 switch (skill->subtype) 340 switch (skill->subtype)
365 { 341 {
366 case SK_LEVITATION: 342 case SK_LEVITATION:
367 /* Not 100% sure if this will work with new movement code - 343 /* Not 100% sure if this will work with new movement code -
368 * the levitation skill has move_type for flying, so when 344 * the levitation skill has move_type for flying, so when
369 * equipped, that should transfer to player, when not, 345 * equipped, that should transfer to player, when not,
370 * shouldn't. 346 * shouldn't.
371 */ 347 */
372 if (QUERY_FLAG (skill, FLAG_APPLIED)) 348 if (QUERY_FLAG (skill, FLAG_APPLIED))
373 { 349 {
374 CLEAR_FLAG (skill, FLAG_APPLIED); 350 CLEAR_FLAG (skill, FLAG_APPLIED);
375 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth."); 351 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth.");
376 } 352 }
377 else 353 else
378 { 354 {
379 SET_FLAG (skill, FLAG_APPLIED); 355 SET_FLAG (skill, FLAG_APPLIED);
380 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!.");
381 } 357 }
358
382 op->update_stats (); 359 op->update_stats ();
383 success = 1; 360 success = 1;
384 break; 361 break;
385 362
386 case SK_STEALING: 363 case SK_STEALING:
387 exp = success = steal (op, dir, skill); 364 exp = success = steal (op, dir, skill);
388 break; 365 break;
389 366
390 case SK_LOCKPICKING: 367 case SK_LOCKPICKING:
391 exp = success = pick_lock (op, dir, skill); 368 exp = success = pick_lock (op, dir, skill);
392 break; 369 break;
393 370
394 case SK_HIDING: 371 case SK_HIDING:
395 exp = success = hide (op, skill); 372 exp = success = hide (op, skill);
396 break; 373 break;
397 374
398 case SK_JUMPING: 375 case SK_JUMPING:
399 success = jump (op, dir, skill); 376 success = jump (op, dir, skill);
400 break; 377 break;
401 378
402 case SK_INSCRIPTION: 379 case SK_INSCRIPTION:
403 exp = success = write_on_item (op, string, skill); 380 exp = success = write_on_item (op, string, skill);
404 break; 381 break;
405 382
406 case SK_MEDITATION: 383 case SK_MEDITATION:
407 meditate (op, skill); 384 meditate (op, skill);
408 success = 1; 385 success = 1;
409 break; 386 break;
410 /* note that the following 'attack' skills gain exp through hit_player() */ 387 /* note that the following 'attack' skills gain exp through hit_player() */
411 388
412 case SK_KARATE: 389 case SK_KARATE:
413 (void) attack_hth (op, dir, "karate-chopped", skill); 390 attack_hth (op, dir, "karate-chopped", skill);
414 break; 391 break;
415 392
416 case SK_PUNCHING: 393 case SK_PUNCHING:
417 (void) attack_hth (op, dir, "punched", skill); 394 attack_hth (op, dir, "punched", skill);
418 break; 395 break;
419 396
420 case SK_FLAME_TOUCH: 397 case SK_FLAME_TOUCH:
421 (void) attack_hth (op, dir, "flamed", skill); 398 attack_hth (op, dir, "flamed", skill);
422 break; 399 break;
423 400
424 case SK_SPARK_TOUCH: 401 case SK_SPARK_TOUCH:
425 (void) attack_hth (op, dir, "zapped", skill); 402 attack_hth (op, dir, "zapped", skill);
426 break; 403 break;
427 404
428 case SK_SHIVER: 405 case SK_SHIVER:
429 (void) attack_hth (op, dir, "froze", skill); 406 attack_hth (op, dir, "froze", skill);
430 break; 407 break;
431 408
432 case SK_ACID_SPLASH: 409 case SK_ACID_SPLASH:
433 (void) attack_hth (op, dir, "dissolved", skill); 410 attack_hth (op, dir, "dissolved", skill);
434 break; 411 break;
435 412
436 case SK_POISON_NAIL: 413 case SK_POISON_NAIL:
437 (void) attack_hth (op, dir, "injected poison into", skill); 414 attack_hth (op, dir, "injected poison into", skill);
438 break; 415 break;
439 416
440 case SK_CLAWING: 417 case SK_CLAWING:
441 (void) attack_hth (op, dir, "clawed", skill); 418 attack_hth (op, dir, "clawed", skill);
442 break; 419 break;
443 420
444 case SK_ONE_HANDED_WEAPON: 421 case SK_ONE_HANDED_WEAPON:
445 case SK_TWO_HANDED_WEAPON: 422 case SK_TWO_HANDED_WEAPON:
446 (void) attack_melee_weapon (op, dir, NULL, skill); 423 attack_melee_weapon (op, dir, NULL, skill);
447 break; 424 break;
448 425
449 case SK_FIND_TRAPS: 426 case SK_FIND_TRAPS:
450 exp = success = find_traps (op, skill); 427 exp = success = find_traps (op, skill);
451 break; 428 break;
452 429
453 case SK_SINGING: 430 case SK_SINGING:
454 exp = success = singing (op, dir, skill); 431 exp = success = singing (op, dir, skill);
455 break; 432 break;
456 433
457 case SK_ORATORY: 434 case SK_ORATORY:
458 exp = success = use_oratory (op, dir, skill); 435 exp = success = use_oratory (op, dir, skill);
459 break; 436 break;
460 437
461 case SK_SMITHERY: 438 case SK_SMITHERY:
462 case SK_BOWYER: 439 case SK_BOWYER:
463 case SK_JEWELER: 440 case SK_JEWELER:
464 case SK_ALCHEMY: 441 case SK_ALCHEMY:
465 case SK_THAUMATURGY: 442 case SK_THAUMATURGY:
466 case SK_LITERACY: 443 case SK_LITERACY:
467 case SK_WOODSMAN: 444 case SK_WOODSMAN:
468 /* 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.
469 * failing that, we go and identify stuff. 446 * failing that, we go and identify stuff.
470 */ 447 */
471 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)
472 { 449 {
473 next = tmp->above; 450 next = tmp->above;
474 451
475 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 452 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON))
476 { 453 {
477 attempt_do_alchemy (op, tmp); 454 attempt_do_alchemy (op, tmp);
478 455
479 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 456 if (QUERY_FLAG (tmp, FLAG_APPLIED))
480 esrv_send_inventory (op, tmp); 457 esrv_send_inventory (op, tmp);
481 458
482 did_alc = 1; 459 did_alc = 1;
483 } 460 }
484 } 461 }
485 462
486 if (did_alc == 0) 463 if (did_alc == 0)
487 exp = success = skill_ident (op, skill);
488
489 break;
490
491 case SK_DET_MAGIC:
492 case SK_DET_CURSE:
493 exp = success = skill_ident (op, skill); 464 exp = success = skill_ident (op, skill);
465
494 break; 466 break;
495 467
468 case SK_DET_MAGIC:
469 case SK_DET_CURSE:
470 exp = success = skill_ident (op, skill);
471 break;
472
496 case SK_DISARM_TRAPS: 473 case SK_DISARM_TRAPS:
497 exp = success = remove_trap (op, dir, skill); 474 exp = success = remove_trap (op, dir, skill);
498 break; 475 break;
499 476
500 case SK_THROWING: 477 case SK_THROWING:
501 success = skill_throw (op, part, dir, string, skill); 478 success = skill_throw (op, part, dir, string, skill);
502 break; 479 break;
503 480
504 case SK_SET_TRAP: 481 case SK_SET_TRAP:
505 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.");
506 break; 483 break;
507 484
508 case SK_USE_MAGIC_ITEM: 485 case SK_USE_MAGIC_ITEM:
509 case SK_MISSILE_WEAPON: 486 case SK_MISSILE_WEAPON:
510 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.");
511 break; 488 break;
512 489
513 case SK_PRAYING: 490 case SK_PRAYING:
514 success = pray (op, skill); 491 success = pray (op, skill);
515 break; 492 break;
516 493
517 case SK_BARGAINING: 494 case SK_BARGAINING:
518 success = describe_shop (op); 495 success = describe_shop (op);
519 break; 496 break;
520 497
521 case SK_SORCERY: 498 case SK_SORCERY:
522 case SK_EVOCATION: 499 case SK_EVOCATION:
523 case SK_PYROMANCY: 500 case SK_PYROMANCY:
524 case SK_SUMMONING: 501 case SK_SUMMONING:
525 case SK_CLIMBING: 502 case SK_CLIMBING:
526 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.");
527 break; 504 break;
528 505
529 default: 506 default:
530 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);
531 break; 508 break;
532 } 509 }
533 510
534 /* 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.
535 * 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
536 * which use_monster_skill is called already simulates this. 513 * which use_monster_skill is called already simulates this.
575 * op is the object that was 'defeated'. 552 * op is the object that was 'defeated'.
576 * 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
577 * point back to who. 554 * point back to who.
578 * 555 *
579 */ 556 */
580
581int 557int
582calc_skill_exp (object *who, object *op, object *skill) 558calc_skill_exp (object *who, object *op, object *skill)
583{ 559{
584 int op_exp = 0, op_lvl = 0; 560 int op_exp = 0, op_lvl = 0;
585 float base, value, lvl_mult = 0.0; 561 float base, value, lvl_mult = 0.0;
674 * This one actually teaches the player the skill as something 650 * This one actually teaches the player the skill as something
675 * they can equip. 651 * they can equip.
676 * Return 0 if the player knows the skill, 1 if the 652 * Return 0 if the player knows the skill, 1 if the
677 * player learns the skill, 2 otherwise. 653 * player learns the skill, 2 otherwise.
678 */ 654 */
679
680int 655int
681learn_skill (object *pl, object *scroll) 656learn_skill (object *pl, object *scroll)
682{ 657{
683 object *tmp; 658 object *tmp;
684 659
803 } 778 }
804 779
805 clear_win_info (op); 780 clear_win_info (op);
806 new_draw_info (NDI_UNIQUE, 0, op, "Player skills:"); 781 new_draw_info (NDI_UNIQUE, 0, op, "Player skills:");
807 if (num_skills_found > 1) 782 if (num_skills_found > 1)
808 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);
809 784
810 for (i = 0; i < num_skills_found; i++) 785 for (i = 0; i < num_skills_found; i++)
811 {
812 new_draw_info (NDI_UNIQUE, 0, op, skills[i]); 786 new_draw_info (NDI_UNIQUE, 0, op, skills[i]);
813 }
814 787
815 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);
816 789
817 cp = determine_god (op); 790 cp = determine_god (op);
818 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");
883} 856}
884 857
885static bool 858static bool
886hth_skill_p (object *skill) 859hth_skill_p (object *skill)
887{ 860{
888 for (unsigned int i = 0; i < sizeof (unarmed_skills); ++i) 861 return (skill_flags [skill->subtype] & (SF_COMBAT | SF_NEED_WEAPON)) == SF_COMBAT;
889 if (skill->subtype == unarmed_skills[i])
890 return 1;
891
892 return 0;
893} 862}
894 863
895/* 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.
896 */ 865 */
897static object * 866static object *
911 * tmp is the targetted monster. 880 * tmp is the targetted monster.
912 * op is what is attacking 881 * op is what is attacking
913 * string is passed along to describe what messages to describe 882 * string is passed along to describe what messages to describe
914 * the damage. 883 * the damage.
915 */ 884 */
916
917static int 885static int
918do_skill_attack (object *tmp, object *op, const char *string, object *skill) 886do_skill_attack (object *tmp, object *op, const char *string, object *skill)
919{ 887{
920 int success;
921
922 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)))
923 return RESULT_INT (0); 889 return RESULT_INT (0);
924 890
925 /* 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
926 * 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.
978 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);
979 op->current_weapon = NULL; 945 op->current_weapon = NULL;
980 return 0; 946 return 0;
981 } 947 }
982 else 948 else
983 {
984 op->current_weapon = tmp; 949 op->current_weapon = tmp;
985 }
986 } 950 }
987 951
988 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);
989 } 953 }
990 } 954 }
994 if (op->type == PLAYER && op->contr->tmp_invis) 958 if (op->type == PLAYER && op->contr->tmp_invis)
995 { 959 {
996 op->contr->tmp_invis = 0; 960 op->contr->tmp_invis = 0;
997 op->invisible = 0; 961 op->invisible = 0;
998 op->hide = 0; 962 op->hide = 0;
999 update_object (op, UP_OBJ_FACE); 963 update_object (op, UP_OBJ_CHANGE);
1000 } 964 }
1001 965
1002 success = attack_ob (tmp, op); 966 int success = attack_ob (tmp, op);
1003 967
1004 /* print appropriate messages to the player */ 968 /* print appropriate messages to the player */
1005 969
1006 if (success && string != NULL && tmp && !QUERY_FLAG (tmp, FLAG_FREED)) 970 if (success && string && tmp && !QUERY_FLAG (tmp, FLAG_FREED))
1007 { 971 {
1008 if (op->type == PLAYER) 972 if (op->type == PLAYER)
1009 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));
1010 else if (tmp->type == PLAYER) 974 else if (tmp->type == PLAYER)
1011 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);
1012 } 976 }
977
1013 return success; 978 return success;
1014} 979}
1015
1016 980
1017/* 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
1018 * system. In essence, this code handles 982 * system. In essence, this code handles
1019 * 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
1020 * treated here. If an opponent is already supplied by move_player(), 984 * treated here. If an opponent is already supplied by move_player(),
1023 * 987 *
1024 * This is called by move_player() and attack_hth() 988 * This is called by move_player() and attack_hth()
1025 * 989 *
1026 * Initial implementation by -bt thomas@astro.psu.edu 990 * Initial implementation by -bt thomas@astro.psu.edu
1027 */ 991 */
1028
1029int 992int
1030skill_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)
1031{ 994{
1032 sint16 tx, ty; 995 sint16 tx, ty;
1033 maptile *m; 996 maptile *m;
1040 ty = freearr_y[dir]; 1003 ty = freearr_y[dir];
1041 1004
1042 /* 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.
1043 * Legal opponents are the same as outlined in move_player_attack() 1006 * Legal opponents are the same as outlined in move_player_attack()
1044 */ 1007 */
1045 1008 if (!tmp)
1046 if (tmp == NULL)
1047 { 1009 {
1048 m = pl->map; 1010 m = pl->map;
1049 tx = pl->x + freearr_x[dir]; 1011 tx = pl->x + freearr_x[dir];
1050 ty = pl->y + freearr_y[dir]; 1012 ty = pl->y + freearr_y[dir];
1051 1013
1061 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)
1062 { 1024 {
1063 /* Don't attack party members */ 1025 /* Don't attack party members */
1064 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))
1065 return 0; 1027 return 0;
1028
1066 break; 1029 break;
1067 } 1030 }
1068 } 1031 }
1032
1069 if (!tmp) 1033 if (!tmp)
1070 { 1034 {
1071 if (pl->type == PLAYER) 1035 if (pl->type == PLAYER)
1072 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
1073 return 0; 1038 return 0;
1074 } 1039 }
1075 1040
1076 return do_skill_attack (tmp, pl, string, skill); 1041 return do_skill_attack (tmp, pl, string, skill);
1077} 1042}
1103 esrv_update_item (UPD_FLAGS, pl, weapon); 1068 esrv_update_item (UPD_FLAGS, pl, weapon);
1104 } 1069 }
1105 break; 1070 break;
1106 } 1071 }
1107 } 1072 }
1073
1108 return skill_attack (enemy, pl, dir, string, skill); 1074 return skill_attack (enemy, pl, dir, string, skill);
1109} 1075}
1110
1111 1076
1112/* attack_melee_weapon() - this handles melee weapon attacks -b.t. 1077/* attack_melee_weapon() - this handles melee weapon attacks -b.t.
1113 * 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.
1114 * 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
1115 * bears mentioning: 1080 * bears mentioning:
1116 * 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
1117 * we may make this routine handle 'special' melee weapons attacks 1082 * we may make this routine handle 'special' melee weapons attacks
1118 * (like disarming manuever with sai) based on player SK_level and 1083 * (like disarming manuever with sai) based on player SK_level and
1119 * weapon type. 1084 * weapon type.
1120 */ 1085 */
1121
1122static int 1086static int
1123attack_melee_weapon (object *op, int dir, const char *string, object *skill) 1087attack_melee_weapon (object *op, int dir, const char *string, object *skill)
1124{ 1088{
1125 1089
1126 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 1090 if (!QUERY_FLAG (op, FLAG_READY_WEAPON))
1127 { 1091 {
1128 if (op->type == PLAYER) 1092 if (op->type == PLAYER)
1129 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
1130 return 0; 1095 return 0;
1131 } 1096 }
1097
1132 return skill_attack (NULL, op, dir, string, skill); 1098 return skill_attack (NULL, op, dir, string, skill);
1133 1099
1134} 1100}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines