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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines