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.10 by root, Tue Sep 12 00:26:16 2006 UTC vs.
Revision 1.34 by root, Mon Apr 30 05:54:14 2007 UTC

1
2/* 1/*
3 * static char *rcsid_skill_util_c =
4 * "$Id: skill_util.C,v 1.10 2006/09/12 00:26:16 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>
48
49const uint8_t skill_flags[NUM_SKILLS] = {
50 0, // SK_NONE
51# define def(uc, flags) flags,
52# include "skillinc.h"
53# undef def
54};
57 55
58static 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);
59static 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);
60 58
61/* init_skills basically just sets up the skill_names table 59/* init_skills basically just sets up the skill_names table
63 * subtypes. 61 * subtypes.
64 */ 62 */
65void 63void
66init_skills (void) 64init_skills (void)
67{ 65{
68 int i;
69 archetype *at;
70
71 for (at = first_archetype; at != NULL; at = at->next) 66 for (archetype *at = first_archetype; at; at = at->next)
72 if (at->clone.type == SKILL) 67 if (at->clone.type == SKILL)
73 { 68 {
74 if (skill_names[at->clone.subtype] != NULL) 69 if (skill_names[at->clone.subtype])
75 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",
76 at->clone.subtype, &skill_names[at->clone.subtype], &at->clone.skill); 71 at->clone.subtype, &skill_names[at->clone.subtype], &at->clone.skill);
77 else 72 else
78 skill_names[at->clone.subtype] = at->clone.skill; 73 skill_names[at->clone.subtype] = at->clone.skill;
79 } 74 }
80 75
81 /* 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
82 * checking for this may catch some user errors. 77 * checking for this may catch some user errors.
83 */ 78 */
84 for (i = 1; i < NUM_SKILLS; i++) 79 for (int i = 1; i < NUM_SKILLS; i++)
85 {
86 if (!skill_names[i]) 80 if (!skill_names[i])
87 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);
88 }
89} 82}
90
91 83
92/* This function goes through the player inventory and sets 84/* This function goes through the player inventory and sets
93 * up the last_skills[] array in the player object. 85 * up the last_skills[] array in the player object.
94 * the last_skills[] is used to more quickly lookup skills - 86 * the last_skills[] is used to more quickly lookup skills -
95 * mostly used for sending exp. 87 * mostly used for sending exp.
96 */ 88 */
97void 89void
98link_player_skills (object *op) 90link_player_skills (object *op)
99{ 91{
100 object *tmp;
101
102 for (tmp = op->inv; tmp; tmp = tmp->below) 92 for (object *tmp = op->inv; tmp; tmp = tmp->below)
103 {
104 if (tmp->type == SKILL) 93 if (tmp->type == SKILL)
105 { 94 {
106 /* This is really a warning, hence no else below */ 95 /* This is really a warning, hence no else below */
107 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)
108 {
109 LOG (llevError, "Multiple skills with the same subtype? %s, %s\n", 97 LOG (llevError, "Multiple skills with the same subtype? %s, %s\n",
110 &op->contr->last_skill_ob[tmp->subtype]->skill, &tmp->skill); 98 &op->contr->last_skill_ob[tmp->subtype]->skill, &tmp->skill);
111 } 99
112 if (tmp->subtype >= NUM_SKILLS) 100 if (tmp->subtype >= NUM_SKILLS)
113 {
114 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);
115 }
116 else 102 else
117 { 103 {
118 op->contr->last_skill_ob[tmp->subtype] = tmp; 104 op->contr->last_skill_ob[tmp->subtype] = tmp;
119 op->contr->last_skill_exp[tmp->subtype] = -1; 105 op->contr->ns->last_skill_exp[tmp->subtype] = -1; //TODO: this should go
120 } 106 }
121 } 107 }
122 }
123} 108}
124 109
125/* This returns the skill pointer of the given name (the 110/* This returns the skill pointer of the given name (the
126 * one that accumlates exp, has the level, etc). 111 * one that accumlates exp, has the level, etc).
127 * 112 *
170 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) 155 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED))
171 { 156 {
172 if (apply_special (who, skill_tool, 0)) 157 if (apply_special (who, skill_tool, 0))
173 return NULL; 158 return NULL;
174 } 159 }
160
175 if (!skill) 161 if (!skill)
176 { 162 {
177 skill = give_skill_by_name (who, skill_tool->skill); 163 skill = give_skill_by_name (who, skill_tool->skill);
178 link_player_skills (who); 164 link_player_skills (who);
179 } 165 }
166
180 return skill; 167 return skill;
181 } 168 }
169
182 return NULL; 170 return NULL;
183} 171}
184 172
185 173
186/* This returns the skill pointer of the given name (the 174/* This returns the skill pointer of the given name (the
231 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) 219 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED))
232 { 220 {
233 if (apply_special (who, skill_tool, 0)) 221 if (apply_special (who, skill_tool, 0))
234 return NULL; 222 return NULL;
235 } 223 }
224
236 if (!skill) 225 if (!skill)
237 { 226 {
238 skill = give_skill_by_name (who, skill_tool->skill); 227 skill = give_skill_by_name (who, skill_tool->skill);
239 link_player_skills (who); 228 link_player_skills (who);
240 } 229 }
230
241 return skill; 231 return skill;
242 } 232 }
233
243 return NULL; 234 return NULL;
244} 235}
245 236
246/* This changes the objects skill to new_skill. 237/* This changes the objects skill to new_skill.
247 * note that this function doesn't always need to get used - 238 * note that this function doesn't always need to get used -
252 * flag has the current meaning: 243 * flag has the current meaning:
253 * 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
254 * 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.
255 * return 1 on success, 0 on error 246 * return 1 on success, 0 on error
256 */ 247 */
257
258int 248int
259change_skill (object *who, object *new_skill, int flag) 249change_skill (object *who, object *new_skill, int flag)
260{ 250{
261 int old_range; 251 int old_range;
262 252
263 if (who->type != PLAYER) 253 if (who->type != PLAYER)
264 return 0; 254 return 0;
265 255
266 old_range = who->contr->shoottype; 256 player *pl = who->contr;
267 257
268 if (who->chosen_skill && who->chosen_skill == new_skill) 258 if (pl->ranged_skill && pl->ranged_skill == new_skill)
269 {
270 /* optimization for changing skill to current skill */
271 if (who->type == PLAYER && !(flag & 0x1))
272 who->contr->shoottype = range_skill;
273 return 1; 259 return 1;
274 }
275 260
276 if (!new_skill || who->chosen_skill)
277 if (who->chosen_skill)
278 apply_special (who, who->chosen_skill, AP_UNAPPLY);
279
280 /* Only goal in this case was to unapply a skill */
281 if (!new_skill) 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 */
267 return 0;
268 }
269
270 // move skill to front, so it will be preferred next time
271 new_skill->remove ();
272 who->insert (new_skill);
273
274 if (apply_special (who, new_skill, AP_APPLY))
282 return 0; 275 return 0;
283 276
284 if (apply_special (who, new_skill, AP_APPLY))
285 {
286 return 0;
287 }
288 if (flag & 0x1)
289 who->contr->shoottype = (rangetype) old_range;
290
291 return 1; 277 return 1;
292} 278}
293 279
294/* This function just clears the chosen_skill and range_skill values 280/* This function just clears the chosen_skill and range_skill values
295 * inthe player. 281 * in the player.
296 */ 282 */
297void 283void
298clear_skill (object *who) 284clear_skill (object *who)
299{ 285{
300 who->chosen_skill = NULL; 286 who->chosen_skill = 0;
301 CLEAR_FLAG (who, FLAG_READY_SKILL); 287 CLEAR_FLAG (who, FLAG_READY_SKILL);
288
302 if (who->type == PLAYER) 289 if (who->type == PLAYER)
303 { 290 {
291 if (who->contr->ranged_skill && who->contr->ranged_skill->type == SKILL)
292 {
304 who->contr->ranges[range_skill] = NULL; 293 who->contr->ranged_skill = 0;
305 if (who->contr->shoottype == range_skill) 294 who->contr->ranged_ob = 0;
306 who->contr->shoottype = range_none; 295 }
307 } 296 }
308} 297}
309 298
310/* 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().
311 * 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.
315 * 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
316 * 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
317 * give any exp for their direct use (eg, throwing). 306 * give any exp for their direct use (eg, throwing).
318 * It returns 0 if no skill was used. 307 * It returns 0 if no skill was used.
319 */ 308 */
320
321int 309int
322do_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)
323{ 311{
324 int success = 0, exp = 0; 312 int success = 0, exp = 0;
325 int did_alc = 0; 313 int did_alc = 0;
334 * the player doesn't have a bucket for that, create one. 322 * the player doesn't have a bucket for that, create one.
335 */ 323 */
336 if (skill->type != SKILL && op->type == PLAYER) 324 if (skill->type != SKILL && op->type == PLAYER)
337 { 325 {
338 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 326 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
339 {
340 if (tmp->type == SKILL && tmp->skill == skill->skill) 327 if (tmp->type == SKILL && tmp->skill == skill->skill)
341 break; 328 break;
342 } 329
343 if (!tmp) 330 if (!tmp)
344 tmp = give_skill_by_name (op, skill->skill); 331 tmp = give_skill_by_name (op, skill->skill);
332
345 skill = tmp; 333 skill = tmp;
346 } 334 }
347 335
348 // skill, by_whom, on_which_object, which direction, skill_argument 336 // skill, by_whom, on_which_object, which direction, skill_argument
349 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)))
350 return 0; 338 return 0;
351 339
352 switch (skill->subtype) 340 switch (skill->subtype)
353 { 341 {
354 case SK_LEVITATION: 342 case SK_LEVITATION:
355 /* Not 100% sure if this will work with new movement code - 343 /* Not 100% sure if this will work with new movement code -
356 * the levitation skill has move_type for flying, so when 344 * the levitation skill has move_type for flying, so when
357 * equipped, that should transfer to player, when not, 345 * equipped, that should transfer to player, when not,
358 * shouldn't. 346 * shouldn't.
359 */ 347 */
360 if (QUERY_FLAG (skill, FLAG_APPLIED)) 348 if (QUERY_FLAG (skill, FLAG_APPLIED))
361 { 349 {
362 CLEAR_FLAG (skill, FLAG_APPLIED); 350 CLEAR_FLAG (skill, FLAG_APPLIED);
363 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth."); 351 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth.");
364 } 352 }
365 else 353 else
366 { 354 {
367 SET_FLAG (skill, FLAG_APPLIED); 355 SET_FLAG (skill, FLAG_APPLIED);
368 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!.");
369 } 357 }
370 fix_player (op); 358
359 op->update_stats ();
371 success = 1; 360 success = 1;
372 break; 361 break;
373 362
374 case SK_STEALING: 363 case SK_STEALING:
375 exp = success = steal (op, dir, skill); 364 exp = success = steal (op, dir, skill);
376 break; 365 break;
377 366
378 case SK_LOCKPICKING: 367 case SK_LOCKPICKING:
379 exp = success = pick_lock (op, dir, skill); 368 exp = success = pick_lock (op, dir, skill);
380 break; 369 break;
381 370
382 case SK_HIDING: 371 case SK_HIDING:
383 exp = success = hide (op, skill); 372 exp = success = hide (op, skill);
384 break; 373 break;
385 374
386 case SK_JUMPING: 375 case SK_JUMPING:
387 success = jump (op, dir, skill); 376 success = jump (op, dir, skill);
388 break; 377 break;
389 378
390 case SK_INSCRIPTION: 379 case SK_INSCRIPTION:
391 exp = success = write_on_item (op, string, skill); 380 exp = success = write_on_item (op, string, skill);
392 break; 381 break;
393 382
394 case SK_MEDITATION: 383 case SK_MEDITATION:
395 meditate (op, skill); 384 meditate (op, skill);
396 success = 1; 385 success = 1;
397 break; 386 break;
398 /* note that the following 'attack' skills gain exp through hit_player() */ 387 /* note that the following 'attack' skills gain exp through hit_player() */
399 388
400 case SK_KARATE: 389 case SK_KARATE:
401 (void) attack_hth (op, dir, "karate-chopped", skill); 390 attack_hth (op, dir, "karate-chopped", skill);
402 break; 391 break;
403 392
404 case SK_PUNCHING: 393 case SK_PUNCHING:
405 (void) attack_hth (op, dir, "punched", skill); 394 attack_hth (op, dir, "punched", skill);
406 break; 395 break;
407 396
408 case SK_FLAME_TOUCH: 397 case SK_FLAME_TOUCH:
409 (void) attack_hth (op, dir, "flamed", skill); 398 attack_hth (op, dir, "flamed", skill);
410 break; 399 break;
411 400
412 case SK_SPARK_TOUCH: 401 case SK_SPARK_TOUCH:
413 (void) attack_hth (op, dir, "zapped", skill); 402 attack_hth (op, dir, "zapped", skill);
414 break; 403 break;
415 404
416 case SK_SHIVER: 405 case SK_SHIVER:
417 (void) attack_hth (op, dir, "froze", skill); 406 attack_hth (op, dir, "froze", skill);
418 break; 407 break;
419 408
420 case SK_ACID_SPLASH: 409 case SK_ACID_SPLASH:
421 (void) attack_hth (op, dir, "dissolved", skill); 410 attack_hth (op, dir, "dissolved", skill);
422 break; 411 break;
423 412
424 case SK_POISON_NAIL: 413 case SK_POISON_NAIL:
425 (void) attack_hth (op, dir, "injected poison into", skill); 414 attack_hth (op, dir, "injected poison into", skill);
426 break; 415 break;
427 416
428 case SK_CLAWING: 417 case SK_CLAWING:
429 (void) attack_hth (op, dir, "clawed", skill); 418 attack_hth (op, dir, "clawed", skill);
430 break; 419 break;
431 420
432 case SK_ONE_HANDED_WEAPON: 421 case SK_ONE_HANDED_WEAPON:
433 case SK_TWO_HANDED_WEAPON: 422 case SK_TWO_HANDED_WEAPON:
434 (void) attack_melee_weapon (op, dir, NULL, skill); 423 attack_melee_weapon (op, dir, NULL, skill);
435 break; 424 break;
436 425
437 case SK_FIND_TRAPS: 426 case SK_FIND_TRAPS:
438 exp = success = find_traps (op, skill); 427 exp = success = find_traps (op, skill);
439 break; 428 break;
440 429
441 case SK_SINGING: 430 case SK_SINGING:
442 exp = success = singing (op, dir, skill); 431 exp = success = singing (op, dir, skill);
443 break; 432 break;
444 433
445 case SK_ORATORY: 434 case SK_ORATORY:
446 exp = success = use_oratory (op, dir, skill); 435 exp = success = use_oratory (op, dir, skill);
447 break; 436 break;
448 437
449 case SK_SMITHERY: 438 case SK_SMITHERY:
450 case SK_BOWYER: 439 case SK_BOWYER:
451 case SK_JEWELER: 440 case SK_JEWELER:
452 case SK_ALCHEMY: 441 case SK_ALCHEMY:
453 case SK_THAUMATURGY: 442 case SK_THAUMATURGY:
454 case SK_LITERACY: 443 case SK_LITERACY:
455 case SK_WOODSMAN: 444 case SK_WOODSMAN:
456 /* 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.
457 * failing that, we go and identify stuff. 446 * failing that, we go and identify stuff.
458 */ 447 */
459 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)
460 { 449 {
461 next = tmp->above; 450 next = tmp->above;
451
462 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 452 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON))
463 { 453 {
464 attempt_do_alchemy (op, tmp); 454 attempt_do_alchemy (op, tmp);
455
465 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 456 if (QUERY_FLAG (tmp, FLAG_APPLIED))
466 esrv_send_inventory (op, tmp); 457 esrv_send_inventory (op, tmp);
458
467 did_alc = 1; 459 did_alc = 1;
468 } 460 }
469 } 461 }
462
470 if (did_alc == 0) 463 if (did_alc == 0)
471 exp = success = skill_ident (op, skill);
472 break;
473
474 case SK_DET_MAGIC:
475 case SK_DET_CURSE:
476 exp = success = skill_ident (op, skill); 464 exp = success = skill_ident (op, skill);
465
477 break; 466 break;
478 467
468 case SK_DET_MAGIC:
469 case SK_DET_CURSE:
470 exp = success = skill_ident (op, skill);
471 break;
472
479 case SK_DISARM_TRAPS: 473 case SK_DISARM_TRAPS:
480 exp = success = remove_trap (op, dir, skill); 474 exp = success = remove_trap (op, dir, skill);
481 break; 475 break;
482 476
483 case SK_THROWING: 477 case SK_THROWING:
484 success = skill_throw (op, part, dir, string, skill); 478 success = skill_throw (op, part, dir, string, skill);
485 break; 479 break;
486 480
487 case SK_SET_TRAP: 481 case SK_SET_TRAP:
488 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.");
489 break; 483 break;
490 484
491 case SK_USE_MAGIC_ITEM: 485 case SK_USE_MAGIC_ITEM:
492 case SK_MISSILE_WEAPON: 486 case SK_MISSILE_WEAPON:
493 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.");
494 break; 488 break;
495 489
496 case SK_PRAYING: 490 case SK_PRAYING:
497 success = pray (op, skill); 491 success = pray (op, skill);
498 break; 492 break;
499 493
500 case SK_BARGAINING: 494 case SK_BARGAINING:
501 success = describe_shop (op); 495 success = describe_shop (op);
502 break; 496 break;
503 497
504 case SK_SORCERY: 498 case SK_SORCERY:
505 case SK_EVOCATION: 499 case SK_EVOCATION:
506 case SK_PYROMANCY: 500 case SK_PYROMANCY:
507 case SK_SUMMONING: 501 case SK_SUMMONING:
508 case SK_CLIMBING: 502 case SK_CLIMBING:
509 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.");
510 break; 504 break;
511 505
512 default: 506 default:
513 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);
514 break; 508 break;
515 } 509 }
516 510
517 /* 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.
518 * 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
519 * which use_monster_skill is called already simulates this. 513 * which use_monster_skill is called already simulates this.
558 * op is the object that was 'defeated'. 552 * op is the object that was 'defeated'.
559 * 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
560 * point back to who. 554 * point back to who.
561 * 555 *
562 */ 556 */
563
564int 557int
565calc_skill_exp (object *who, object *op, object *skill) 558calc_skill_exp (object *who, object *op, object *skill)
566{ 559{
567 int op_exp = 0, op_lvl = 0; 560 int op_exp = 0, op_lvl = 0;
568 float base, value, lvl_mult = 0.0; 561 float base, value, lvl_mult = 0.0;
657 * This one actually teaches the player the skill as something 650 * This one actually teaches the player the skill as something
658 * they can equip. 651 * they can equip.
659 * Return 0 if the player knows the skill, 1 if the 652 * Return 0 if the player knows the skill, 1 if the
660 * player learns the skill, 2 otherwise. 653 * player learns the skill, 2 otherwise.
661 */ 654 */
662
663int 655int
664learn_skill (object *pl, object *scroll) 656learn_skill (object *pl, object *scroll)
665{ 657{
666 object *tmp; 658 object *tmp;
667 659
680 break; 672 break;
681 673
682 /* player already knows it */ 674 /* player already knows it */
683 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL)) 675 if (tmp && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL))
684 return 0; 676 return 0;
685
686
687 677
688 /* now a random change to learn, based on player Int. 678 /* now a random change to learn, based on player Int.
689 * give bonus based on level - otherwise stupid characters 679 * give bonus based on level - otherwise stupid characters
690 * might never be able to learn anything. 680 * might never be able to learn anything.
691 */ 681 */
761 sprintf (buf, "%s%s", &tmp->name, periods); 751 sprintf (buf, "%s%s", &tmp->name, periods);
762 buf[40] = 0; 752 buf[40] = 0;
763 753
764 if (settings.permanent_exp_ratio) 754 if (settings.permanent_exp_ratio)
765 { 755 {
766 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%lld/%lld/%d%%)", 756 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%" PRId64 "/%" PRId64 "/%d%%)",
767 buf, tmp->level, 757 buf, tmp->level, tmp->stats.exp,
768 (long long) tmp->stats.exp,
769 (long long) level_exp (tmp->level + 1, op->expmul), clipped_percent (tmp->perm_exp, tmp->stats.exp)); 758 level_exp (tmp->level + 1, op->expmul), clipped_percent (tmp->perm_exp, tmp->stats.exp));
770 } 759 }
771 else 760 else
772 { 761 {
773 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%lld/%lld)", 762 sprintf (skills[num_skills_found++], "%slvl:%3d (xp:%" PRId64 "/%" PRId64 ")",
774 buf, tmp->level, (long long) tmp->stats.exp, (long long) level_exp (tmp->level + 1, op->expmul)); 763 buf, tmp->level, tmp->stats.exp, level_exp (tmp->level + 1, op->expmul));
775 } 764 }
776 /* I don't know why some characters get a bunch of skills, but 765 /* I don't know why some characters get a bunch of skills, but
777 * it sometimes happens (maybe a leftover from bugier earlier code 766 * it sometimes happens (maybe a leftover from bugier earlier code
778 * and those character are still about). In any case, lets handle 767 * and those character are still about). In any case, lets handle
779 * it so it doesn't crash the server - otherwise, one character may 768 * it so it doesn't crash the server - otherwise, one character may
789 } 778 }
790 779
791 clear_win_info (op); 780 clear_win_info (op);
792 new_draw_info (NDI_UNIQUE, 0, op, "Player skills:"); 781 new_draw_info (NDI_UNIQUE, 0, op, "Player skills:");
793 if (num_skills_found > 1) 782 if (num_skills_found > 1)
794 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);
795 784
796 for (i = 0; i < num_skills_found; i++) 785 for (i = 0; i < num_skills_found; i++)
797 {
798 new_draw_info (NDI_UNIQUE, 0, op, skills[i]); 786 new_draw_info (NDI_UNIQUE, 0, op, skills[i]);
799 }
800 787
801 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);
802 789
803 cp = determine_god (op); 790 cp = determine_god (op);
804 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");
866 return 1; 853 return 1;
867 854
868 return 0; 855 return 0;
869} 856}
870 857
858static bool
859hth_skill_p (object *skill)
860{
861 return (skill_flags [skill->subtype] & (SF_COMBAT | SF_NEED_WEAPON)) == SF_COMBAT;
862}
871 863
872
873/* This finds the best unarmed skill the player has, and returns 864/* This finds the first unarmed skill the player has, and returns it.
874 * it. Best can vary a little - we consider clawing to always
875 * be the best for dragons.
876 * This could be more intelligent, eg, look at the skill level
877 * of the skill and go from there (eg, a level 40 puncher is
878 * is probably better than level 1 karate). OTOH, if you
879 * don't bother to set up your skill properly, that is the players
880 * problem (although, it might be nice to have a preferred skill
881 * field the player can set.
882 * Unlike the old code, we don't give out any skills - it is
883 * possible you just don't have any ability to get into unarmed
884 * combat. If everyone race/class should have one, this should
885 * be handled in the starting treasurelists, not in the code.
886 */ 865 */
887static object * 866static object *
888find_best_player_hth_skill (object *op) 867find_player_hth_skill (object *op)
889{ 868{
890 object *tmp, *best_skill = NULL;
891 int dragon = is_dragon_pl (op), last_skill = sizeof (unarmed_skills), i;
892
893 for (tmp = op->inv; tmp; tmp = tmp->below) 869 for (object *tmp = op->inv; tmp; tmp = tmp->below)
894 { 870 if (tmp->type == SKILL && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL) && hth_skill_p (tmp))
895 if (tmp->type == SKILL)
896 {
897 if (dragon && tmp->subtype == SK_CLAWING)
898 return tmp; 871 return tmp;
899 872
900 /* The order in the array is preferred order. So basically, 873 return 0;
901 * we just cut down the number to search - eg, if we find a skill
902 * early on in flame touch, then we only need to look into the unarmed_array
903 * to the entry before flame touch - don't care about the entries afterward,
904 * because they are infrerior skills.
905 * if we end up finding the best skill (i==0) might as well return
906 * right away - can't get any better than that.
907 */
908 for (i = 0; i < last_skill; i++)
909 {
910 if (tmp->subtype == unarmed_skills[i] && QUERY_FLAG (tmp, FLAG_CAN_USE_SKILL))
911 {
912 best_skill = tmp;
913 last_skill = i;
914 if (i == 0)
915 return best_skill;
916 }
917 }
918 }
919 }
920 return best_skill;
921} 874}
922 875
923/* do_skill_attack() - We have got an appropriate opponent from either 876/* do_skill_attack() - We have got an appropriate opponent from either
924 * move_player_attack() or skill_attack(). In this part we get on with 877 * move_player_attack() or skill_attack(). In this part we get on with
925 * attacking, take care of messages from the attack and changes in invisible. 878 * attacking, take care of messages from the attack and changes in invisible.
927 * tmp is the targetted monster. 880 * tmp is the targetted monster.
928 * op is what is attacking 881 * op is what is attacking
929 * string is passed along to describe what messages to describe 882 * string is passed along to describe what messages to describe
930 * the damage. 883 * the damage.
931 */ 884 */
932
933static int 885static int
934do_skill_attack (object *tmp, object *op, const char *string, object *skill) 886do_skill_attack (object *tmp, object *op, const char *string, object *skill)
935{ 887{
936 int success;
937
938 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)))
939 return RESULT_INT (0); 889 return RESULT_INT (0);
940 890
941 /* 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
942 * 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.
946 */ 896 */
947 if (op->type == PLAYER) 897 if (op->type == PLAYER)
948 { 898 {
949 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 899 if (!QUERY_FLAG (op, FLAG_READY_WEAPON))
950 { 900 {
951 size_t i;
952
953 if (!skill) 901 if (!skill)
954 { 902 {
955 /* See if the players chosen skill is a combat skill, and use 903 /* See if the players chosen skill is a combat skill, and use
956 * it if appropriate. 904 * it if appropriate.
957 */ 905 */
906 if (op->chosen_skill && hth_skill_p (op->chosen_skill))
958 if (op->chosen_skill) 907 skill = op->chosen_skill;
908 else
959 { 909 {
960 for (i = 0; i < sizeof (unarmed_skills); i++)
961 if (op->chosen_skill->subtype == unarmed_skills[i])
962 {
963 skill = op->chosen_skill;
964 break;
965 }
966 }
967 /* If we didn't find a skill above, look harder for a good skill */
968 if (!skill)
969 {
970 skill = find_best_player_hth_skill (op); 910 skill = find_player_hth_skill (op);
971 911
972 if (!skill) 912 if (!skill)
973 { 913 {
974 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); 914 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!");
975 return 0; 915 return 0;
976 } 916 }
977 } 917 }
978 } 918 }
979 if (skill != op->chosen_skill) 919
980 {
981 /* now try to ready the new skill */ 920 /* now try to ready the new skill */
982 if (!change_skill (op, skill, 0)) 921 if (!change_skill (op, skill, 0))
983 { /* oh oh, trouble! */ 922 { /* oh oh, trouble! */
984 new_draw_info_format (NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name); 923 new_draw_info_format (NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name);
985 return 0; 924 return 0;
986 }
987 } 925 }
988 } 926 }
989 else 927 else
990 { 928 {
991 /* Seen some crashes below where current_weapon is not set, 929 /* Seen some crashes below where current_weapon is not set,
1006 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);
1007 op->current_weapon = NULL; 945 op->current_weapon = NULL;
1008 return 0; 946 return 0;
1009 } 947 }
1010 else 948 else
1011 {
1012 op->current_weapon = tmp; 949 op->current_weapon = tmp;
1013 }
1014 } 950 }
1015 951
1016 /* Has ready weapon - make sure chosen_skill is set up properly */
1017 if (!op->chosen_skill || op->current_weapon->skill != op->chosen_skill->skill)
1018 {
1019 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);
1020 }
1021 } 953 }
1022 } 954 }
1023 955
1024 /* lose invisiblity/hiding status for running attacks */ 956 /* lose invisiblity/hiding status for running attacks */
1025 957
1026 if (op->type == PLAYER && op->contr->tmp_invis) 958 if (op->type == PLAYER && op->contr->tmp_invis)
1027 { 959 {
1028 op->contr->tmp_invis = 0; 960 op->contr->tmp_invis = 0;
1029 op->invisible = 0; 961 op->invisible = 0;
1030 op->hide = 0; 962 op->hide = 0;
1031 update_object (op, UP_OBJ_FACE); 963 update_object (op, UP_OBJ_CHANGE);
1032 } 964 }
1033 965
1034 success = attack_ob (tmp, op); 966 int success = attack_ob (tmp, op);
1035 967
1036 /* print appropriate messages to the player */ 968 /* print appropriate messages to the player */
1037 969
1038 if (success && string != NULL && tmp && !QUERY_FLAG (tmp, FLAG_FREED)) 970 if (success && string && tmp && !QUERY_FLAG (tmp, FLAG_FREED))
1039 { 971 {
1040 if (op->type == PLAYER) 972 if (op->type == PLAYER)
1041 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));
1042 else if (tmp->type == PLAYER) 974 else if (tmp->type == PLAYER)
1043 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);
1044 } 976 }
977
1045 return success; 978 return success;
1046} 979}
1047
1048 980
1049/* 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
1050 * system. In essence, this code handles 982 * system. In essence, this code handles
1051 * 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
1052 * treated here. If an opponent is already supplied by move_player(), 984 * treated here. If an opponent is already supplied by move_player(),
1055 * 987 *
1056 * This is called by move_player() and attack_hth() 988 * This is called by move_player() and attack_hth()
1057 * 989 *
1058 * Initial implementation by -bt thomas@astro.psu.edu 990 * Initial implementation by -bt thomas@astro.psu.edu
1059 */ 991 */
1060
1061int 992int
1062skill_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)
1063{ 994{
1064 sint16 tx, ty; 995 sint16 tx, ty;
1065 mapstruct *m; 996 maptile *m;
1066 int mflags; 997 int mflags;
1067 998
1068 if (!dir) 999 if (!dir)
1069 dir = pl->facing; 1000 dir = pl->facing;
1001
1070 tx = freearr_x[dir]; 1002 tx = freearr_x[dir];
1071 ty = freearr_y[dir]; 1003 ty = freearr_y[dir];
1072 1004
1073 /* 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.
1074 * Legal opponents are the same as outlined in move_player_attack() 1006 * Legal opponents are the same as outlined in move_player_attack()
1075 */ 1007 */
1076 1008 if (!tmp)
1077 if (tmp == NULL)
1078 { 1009 {
1079 m = pl->map; 1010 m = pl->map;
1080 tx = pl->x + freearr_x[dir]; 1011 tx = pl->x + freearr_x[dir];
1081 ty = pl->y + freearr_y[dir]; 1012 ty = pl->y + freearr_y[dir];
1082 1013
1086 1017
1087 /* space must be blocked for there to be anything interesting to do */ 1018 /* space must be blocked for there to be anything interesting to do */
1088 if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty))) 1019 if (!OB_TYPE_MOVE_BLOCK (pl, GET_MAP_MOVE_BLOCK (m, tx, ty)))
1089 return 0; 1020 return 0;
1090 1021
1091 for (tmp = get_map_ob (m, tx, ty); tmp; tmp = tmp->above) 1022 for (tmp = GET_MAP_OB (m, tx, ty); tmp; tmp = tmp->above)
1092 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)
1093 { 1024 {
1094 /* Don't attack party members */ 1025 /* Don't attack party members */
1095 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))
1096 return 0; 1027 return 0;
1028
1097 break; 1029 break;
1098 } 1030 }
1099 } 1031 }
1032
1100 if (!tmp) 1033 if (!tmp)
1101 { 1034 {
1102 if (pl->type == PLAYER) 1035 if (pl->type == PLAYER)
1103 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
1104 return 0; 1038 return 0;
1105 } 1039 }
1106 1040
1107 return do_skill_attack (tmp, pl, string, skill); 1041 return do_skill_attack (tmp, pl, string, skill);
1108} 1042}
1125 { 1059 {
1126 if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED)) 1060 if (weapon->type == WEAPON && QUERY_FLAG (weapon, FLAG_APPLIED))
1127 { 1061 {
1128 CLEAR_FLAG (weapon, FLAG_APPLIED); 1062 CLEAR_FLAG (weapon, FLAG_APPLIED);
1129 CLEAR_FLAG (pl, FLAG_READY_WEAPON); 1063 CLEAR_FLAG (pl, FLAG_READY_WEAPON);
1130 fix_player (pl); 1064 pl->update_stats ();
1131 if (pl->type == PLAYER) 1065 if (pl->type == PLAYER)
1132 { 1066 {
1133 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); 1067 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack.");
1134 esrv_update_item (UPD_FLAGS, pl, weapon); 1068 esrv_update_item (UPD_FLAGS, pl, weapon);
1135 } 1069 }
1136 break; 1070 break;
1137 } 1071 }
1138 } 1072 }
1073
1139 return skill_attack (enemy, pl, dir, string, skill); 1074 return skill_attack (enemy, pl, dir, string, skill);
1140} 1075}
1141
1142 1076
1143/* attack_melee_weapon() - this handles melee weapon attacks -b.t. 1077/* attack_melee_weapon() - this handles melee weapon attacks -b.t.
1144 * 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.
1145 * 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
1146 * bears mentioning: 1080 * bears mentioning:
1147 * 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
1148 * we may make this routine handle 'special' melee weapons attacks 1082 * we may make this routine handle 'special' melee weapons attacks
1149 * (like disarming manuever with sai) based on player SK_level and 1083 * (like disarming manuever with sai) based on player SK_level and
1150 * weapon type. 1084 * weapon type.
1151 */ 1085 */
1152
1153static int 1086static int
1154attack_melee_weapon (object *op, int dir, const char *string, object *skill) 1087attack_melee_weapon (object *op, int dir, const char *string, object *skill)
1155{ 1088{
1156 1089
1157 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 1090 if (!QUERY_FLAG (op, FLAG_READY_WEAPON))
1158 { 1091 {
1159 if (op->type == PLAYER) 1092 if (op->type == PLAYER)
1160 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
1161 return 0; 1095 return 0;
1162 } 1096 }
1097
1163 return skill_attack (NULL, op, dir, string, skill); 1098 return skill_attack (NULL, op, dir, string, skill);
1164 1099
1165} 1100}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines