ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/skill_util.C
(Generate patch)

Comparing deliantra/server/server/skill_util.C (file contents):
Revision 1.26 by pippijn, Mon Jan 15 21:06:20 2007 UTC vs.
Revision 1.47 by root, Sun May 13 19:56:57 2007 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
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 *
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 -
129 * tool, this code will equip it. 115 * tool, this code will equip it.
130 */ 116 */
131object * 117object *
132find_skill_by_name (object *who, const char *name) 118find_skill_by_name (object *who, const char *name)
133{ 119{
134 object *skill = NULL, *skill_tool = NULL, *tmp;
135
136 if (!name) 120 if (!name)
137 return NULL; 121 return 0;
122
123 object *skill = 0, *skill_tool = 0;
138 124
139 /* We make sure the length of the string in the object is greater 125 /* We make sure the length of the string in the object is greater
140 * in length than the passed string. Eg, if we have a skill called 126 * in length than the passed string. Eg, if we have a skill called
141 * 'hi', we don't want to match if the user passed 'high' 127 * 'hi', we don't want to match if the user passed 'high'
142 */ 128 */
143 for (tmp = who->inv; tmp != NULL; tmp = tmp->below) 129 for (object *tmp = who->inv; tmp; tmp = tmp->below)
144 { 130 {
145 if (tmp->type == SKILL && !strncasecmp (name, tmp->skill, strlen (name)) && (size_t) strlen (tmp->skill) >= strlen (name)) 131 if (tmp->type == SKILL && !strncasecmp (name, tmp->skill, strlen (name)) && strlen (tmp->skill) >= strlen (name))
146 skill = tmp; 132 skill = tmp;
147 133
148 /* Try to find appropriate skilltool. If the player has one already 134 /* Try to find appropriate skilltool. If the player has one already
149 * applied, we try to keep using that one. 135 * applied, we try to keep using that one.
150 */ 136 */
151 else if (tmp->type == SKILL_TOOL && !strncasecmp (name, tmp->skill, strlen (name)) && (size_t) strlen (tmp->skill) >= strlen (name)) 137 else if (tmp->type == SKILL_TOOL && !strncasecmp (name, tmp->skill, strlen (name)) && strlen (tmp->skill) >= strlen (name))
152 { 138 {
153 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 139 if (QUERY_FLAG (tmp, FLAG_APPLIED))
154 skill_tool = tmp; 140 skill_tool = tmp;
155 else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED)) 141 else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED))
156 skill_tool = tmp; 142 skill_tool = tmp;
157 } 143 }
158 } 144 }
145
159 /* If this is a skill that can be used without a tool, return it */ 146 /* If this is a skill that can be used without a tool, return it */
160 if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL)) 147 if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL))
161 return skill; 148 return skill;
162 149
163 /* Player has a tool to use the skill. IF not applied, apply it - 150 /* Player has a tool to use the skill. If not applied, apply it -
164 * if not successful, return null. If they do have the skill tool 151 * if not successful, return null. If they do have the skill tool
165 * but not the skill itself, give it to them. 152 * but not the skill itself, give it to them.
166 */ 153 */
167 if (skill_tool) 154 if (skill_tool)
168 { 155 {
169 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) 156 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED))
170 {
171 if (apply_special (who, skill_tool, 0)) 157 if (apply_special (who, skill_tool, 0))
172 return NULL; 158 return 0;
173 } 159
174 if (!skill) 160 if (!skill)
175 { 161 {
176 skill = give_skill_by_name (who, skill_tool->skill); 162 skill = give_skill_by_name (who, skill_tool->skill);
177 link_player_skills (who); 163 link_player_skills (who);
178 } 164 }
165
179 return skill; 166 return skill;
180 } 167 }
168
181 return NULL; 169 return 0;
182} 170}
183
184 171
185/* This returns the skill pointer of the given name (the 172/* This returns the skill pointer of the given name (the
186 * one that accumlates exp, has the level, etc). 173 * one that accumlates exp, has the level, etc).
187 * 174 *
188 * It is presumed that the player will be needing to actually 175 * It is presumed that the player will be needing to actually
194 * this replaces find_skill. 181 * this replaces find_skill.
195 */ 182 */
196object * 183object *
197find_skill_by_number (object *who, int skillno) 184find_skill_by_number (object *who, int skillno)
198{ 185{
186 if (!IN_RANGE_EXC (skillno, 1, NUM_SKILLS))
187 return 0;
188
199 object *skill = NULL, *skill_tool = NULL, *tmp; 189 object *skill = NULL, *skill_tool = NULL;
200 190
201 if (skillno < 1 || skillno >= NUM_SKILLS)
202 return NULL;
203
204 for (tmp = who->inv; tmp != NULL; tmp = tmp->below) 191 for (object *tmp = who->inv; tmp; tmp = tmp->below)
205 { 192 {
206 if (tmp->type == SKILL && tmp->subtype == skillno) 193 if (tmp->type == SKILL && tmp->subtype == skillno)
207 skill = tmp; 194 skill = tmp;
208 195
209 /* Try to find appropriate skilltool. If the player has one already 196 /* Try to find appropriate skilltool. If the player has one already
215 skill_tool = tmp; 202 skill_tool = tmp;
216 else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED)) 203 else if (!skill_tool || !QUERY_FLAG (skill_tool, FLAG_APPLIED))
217 skill_tool = tmp; 204 skill_tool = tmp;
218 } 205 }
219 } 206 }
207
220 /* If this is a skill that can be used without a tool, return it */ 208 /* If this is a skill that can be used without a tool, return it */
221 if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL)) 209 if (skill && QUERY_FLAG (skill, FLAG_CAN_USE_SKILL))
222 return skill; 210 return skill;
223 211
224 /* Player has a tool to use the skill. IF not applied, apply it - 212 /* Player has a tool to use the skill. If not applied, apply it -
225 * if not successful, return null. If they do have the skill tool 213 * if not successful, return null. If they do have the skill tool
226 * but not the skill itself, give it to them. 214 * but not the skill itself, give it to them.
227 */ 215 */
228 if (skill_tool) 216 if (skill_tool)
229 { 217 {
230 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED)) 218 if (!QUERY_FLAG (skill_tool, FLAG_APPLIED))
246} 234}
247 235
248/* This changes the objects skill to new_skill. 236/* This changes the objects skill to new_skill.
249 * note that this function doesn't always need to get used - 237 * note that this function doesn't always need to get used -
250 * you can now add skill exp to the player without the chosen_skill being 238 * you can now add skill exp to the player without the chosen_skill being
251 * set. This function is of most interest to players to update 239 * set. This function is of most interest to players to update
252 * the various range information. 240 * the various range information.
253 * if new_skill is null, this just unapplies the skill.
254 * flag has the current meaning:
255 * 0x1: If set, don't update the range pointer. This is useful when we
256 * need to ready a new skill, but don't want to clobber range.
257 * return 1 on success, 0 on error 241 * return 1 on success, 0 on error
258 */ 242 */
259
260int 243int
261change_skill (object *who, object *new_skill, int flag) 244change_skill (object *who, object *new_skill, int flag)
262{ 245{
263 int old_range;
264
265 if (who->type != PLAYER) 246 if (who->type != PLAYER)
266 return 0; 247 return 0;
267 248
268 old_range = who->contr->shoottype; 249#if 0
269 250 // optimise this supposedly common case
270 if (who->chosen_skill && who->chosen_skill == new_skill)
271 {
272 /* optimization for changing skill to current skill */
273 if (who->type == PLAYER && !(flag & 0x1))
274 who->contr->shoottype = range_skill;
275
276 return 1;
277 }
278
279 // move skill to front, so it will be preferred next time
280 new_skill->remove ();
281 who->insert (new_skill);
282
283 if (!new_skill || who->chosen_skill) 251 if (new_skill == who->chosen_skill)
284 if (who->chosen_skill) 252 return 1;
285 apply_special (who, who->chosen_skill, AP_UNAPPLY); 253#endif
286 254
287 /* Only goal in this case was to unapply a skill */
288 if (!new_skill) 255 if (!new_skill)
256 {
257 LOG (llevError | logBacktrace, "change_skill called on %s with NULL skill\n",
258 who->debug_desc ());
289 return 0; 259 return 0;
260 }
261
262 // the skill could be readied already because it is used by a weapon.
263 who->change_weapon (0);
264 new_skill->inv_splay ();
290 265
291 if (apply_special (who, new_skill, AP_APPLY)) 266 if (apply_special (who, new_skill, AP_APPLY))
292 return 0; 267 return 0;
293 268
294 if (flag & 0x1)
295 who->contr->shoottype = (rangetype)old_range;
296
297 return 1; 269 return 1;
298} 270}
299 271
300/* This function just clears the chosen_skill and range_skill values 272/* This function just clears the chosen_skill and range_skill values
301 * inthe player. 273 * in the player.
302 */ 274 */
303void 275void
304clear_skill (object *who) 276clear_skill (object *who)
305{ 277{
306 who->chosen_skill = NULL; 278 who->chosen_skill = 0;
307 CLEAR_FLAG (who, FLAG_READY_SKILL); 279 CLEAR_FLAG (who, FLAG_READY_SKILL);
280
308 if (who->type == PLAYER) 281 if (who->type == PLAYER)
309 { 282 if (who->contr->ranged_ob && who->contr->ranged_ob->type == SKILL)
310 who->contr->ranges[range_skill] = NULL; 283 who->contr->ranged_ob = 0;
311 if (who->contr->shoottype == range_skill)
312 who->contr->shoottype = range_none;
313 }
314} 284}
315 285
316/* do_skill() - Main skills use function-similar in scope to cast_spell(). 286/* do_skill() - Main skills use function-similar in scope to cast_spell().
317 * We handle all requests for skill use outside of some combat here. 287 * We handle all requests for skill use outside of some combat here.
318 * We require a separate routine outside of fire() so as to allow monsters 288 * We require a separate routine outside of fire() so as to allow monsters
321 * exp - no caller needed that info, but it also prevented the callers 291 * exp - no caller needed that info, but it also prevented the callers
322 * from know if a skill was actually used, as many skills don't 292 * from know if a skill was actually used, as many skills don't
323 * give any exp for their direct use (eg, throwing). 293 * give any exp for their direct use (eg, throwing).
324 * It returns 0 if no skill was used. 294 * It returns 0 if no skill was used.
325 */ 295 */
326
327int 296int
328do_skill (object *op, object *part, object *skill, int dir, const char *string) 297do_skill (object *op, object *part, object *skill, int dir, const char *string)
329{ 298{
330 int success = 0, exp = 0; 299 int success = 0, exp = 0;
331 int did_alc = 0; 300 int did_alc = 0;
332 object *tmp, *next;
333 301
334 if (!skill) 302 if (!skill)
335 return 0; 303 return 0;
336 304
337 /* The code below presumes that the skill points to the object that 305 /* The code below presumes that the skill points to the object that
339 * go and try to find the actual real skill pointer, and if the 307 * go and try to find the actual real skill pointer, and if the
340 * the player doesn't have a bucket for that, create one. 308 * the player doesn't have a bucket for that, create one.
341 */ 309 */
342 if (skill->type != SKILL && op->type == PLAYER) 310 if (skill->type != SKILL && op->type == PLAYER)
343 { 311 {
344 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 312 for (object *tmp = op->inv; tmp; tmp = tmp->below)
345 {
346 if (tmp->type == SKILL && tmp->skill == skill->skill) 313 if (tmp->type == SKILL && tmp->skill == skill->skill)
347 break; 314 {
315 skill = tmp;
316 goto found;
348 } 317 }
349 if (!tmp) 318
350 tmp = give_skill_by_name (op, skill->skill); 319 skill = give_skill_by_name (op, skill->skill);
351 skill = tmp; 320found: ;
352 } 321 }
353 322
354 // skill, by_whom, on_which_object, which direction, skill_argument 323 // skill, by_whom, on_which_object, which direction, skill_argument
355 if (INVOKE_OBJECT (USE_SKILL, skill, ARG_OBJECT (op), ARG_OBJECT (part), ARG_INT (dir), ARG_STRING (string))) 324 if (INVOKE_OBJECT (USE_SKILL, skill, ARG_OBJECT (op), ARG_OBJECT (part), ARG_INT (dir), ARG_STRING (string)))
356 return 0; 325 return 0;
357 326
358 switch (skill->subtype) 327 switch (skill->subtype)
359 { 328 {
360 case SK_LEVITATION: 329 case SK_LEVITATION:
361 /* Not 100% sure if this will work with new movement code - 330 /* Not 100% sure if this will work with new movement code -
362 * the levitation skill has move_type for flying, so when 331 * the levitation skill has move_type for flying, so when
363 * equipped, that should transfer to player, when not, 332 * equipped, that should transfer to player, when not,
364 * shouldn't. 333 * shouldn't.
365 */ 334 */
366 if (QUERY_FLAG (skill, FLAG_APPLIED)) 335 if (QUERY_FLAG (skill, FLAG_APPLIED))
367 { 336 {
368 CLEAR_FLAG (skill, FLAG_APPLIED); 337 CLEAR_FLAG (skill, FLAG_APPLIED);
369 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth."); 338 new_draw_info (NDI_UNIQUE, 0, op, "You come to earth.");
370 } 339 }
371 else 340 else
372 { 341 {
373 SET_FLAG (skill, FLAG_APPLIED); 342 SET_FLAG (skill, FLAG_APPLIED);
374 new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!."); 343 new_draw_info (NDI_UNIQUE, 0, op, "You rise into the air!.");
375 } 344 }
345
376 op->update_stats (); 346 op->update_stats ();
377 success = 1; 347 success = 1;
378 break; 348 break;
379 349
380 case SK_STEALING: 350 case SK_STEALING:
381 exp = success = steal (op, dir, skill); 351 exp = success = steal (op, dir, skill);
382 break; 352 break;
383 353
384 case SK_LOCKPICKING: 354 case SK_LOCKPICKING:
385 exp = success = pick_lock (op, dir, skill); 355 exp = success = pick_lock (op, dir, skill);
386 break; 356 break;
387 357
388 case SK_HIDING: 358 case SK_HIDING:
389 exp = success = hide (op, skill); 359 exp = success = hide (op, skill);
390 break; 360 break;
391 361
392 case SK_JUMPING: 362 case SK_JUMPING:
393 success = jump (op, dir, skill); 363 success = jump (op, dir, skill);
394 break; 364 break;
395 365
396 case SK_INSCRIPTION: 366 case SK_INSCRIPTION:
397 exp = success = write_on_item (op, string, skill); 367 exp = success = write_on_item (op, string, skill);
398 break; 368 break;
399 369
400 case SK_MEDITATION: 370 case SK_MEDITATION:
401 meditate (op, skill); 371 meditate (op, skill);
402 success = 1; 372 success = 1;
403 break; 373 break;
404 /* note that the following 'attack' skills gain exp through hit_player() */ 374 /* note that the following 'attack' skills gain exp through hit_player() */
405 375
406 case SK_KARATE: 376 case SK_KARATE:
407 (void) attack_hth (op, dir, "karate-chopped", skill); 377 attack_hth (op, dir, "karate-chopped", skill);
408 break; 378 break;
409 379
410 case SK_PUNCHING: 380 case SK_PUNCHING:
411 (void) attack_hth (op, dir, "punched", skill); 381 attack_hth (op, dir, "punched", skill);
412 break; 382 break;
413 383
414 case SK_FLAME_TOUCH: 384 case SK_FLAME_TOUCH:
415 (void) attack_hth (op, dir, "flamed", skill); 385 attack_hth (op, dir, "flamed", skill);
416 break; 386 break;
417 387
418 case SK_SPARK_TOUCH: 388 case SK_SPARK_TOUCH:
419 (void) attack_hth (op, dir, "zapped", skill); 389 attack_hth (op, dir, "zapped", skill);
420 break; 390 break;
421 391
422 case SK_SHIVER: 392 case SK_SHIVER:
423 (void) attack_hth (op, dir, "froze", skill); 393 attack_hth (op, dir, "froze", skill);
424 break; 394 break;
425 395
426 case SK_ACID_SPLASH: 396 case SK_ACID_SPLASH:
427 (void) attack_hth (op, dir, "dissolved", skill); 397 attack_hth (op, dir, "dissolved", skill);
428 break; 398 break;
429 399
430 case SK_POISON_NAIL: 400 case SK_POISON_NAIL:
431 (void) attack_hth (op, dir, "injected poison into", skill); 401 attack_hth (op, dir, "injected poison into", skill);
432 break; 402 break;
433 403
434 case SK_CLAWING: 404 case SK_CLAWING:
435 (void) attack_hth (op, dir, "clawed", skill); 405 attack_hth (op, dir, "clawed", skill);
436 break; 406 break;
437 407
438 case SK_ONE_HANDED_WEAPON: 408 case SK_ONE_HANDED_WEAPON:
439 case SK_TWO_HANDED_WEAPON: 409 case SK_TWO_HANDED_WEAPON:
440 (void) attack_melee_weapon (op, dir, NULL, skill); 410 attack_melee_weapon (op, dir, NULL, skill);
441 break; 411 break;
442 412
443 case SK_FIND_TRAPS: 413 case SK_FIND_TRAPS:
444 exp = success = find_traps (op, skill); 414 exp = success = find_traps (op, skill);
445 break; 415 break;
446 416
447 case SK_SINGING: 417 case SK_SINGING:
448 exp = success = singing (op, dir, skill); 418 exp = success = singing (op, dir, skill);
449 break; 419 break;
450 420
451 case SK_ORATORY: 421 case SK_ORATORY:
452 exp = success = use_oratory (op, dir, skill); 422 exp = success = use_oratory (op, dir, skill);
453 break; 423 break;
454 424
455 case SK_SMITHERY: 425 case SK_SMITHERY:
456 case SK_BOWYER: 426 case SK_BOWYER:
457 case SK_JEWELER: 427 case SK_JEWELER:
458 case SK_ALCHEMY: 428 case SK_ALCHEMY:
459 case SK_THAUMATURGY: 429 case SK_THAUMATURGY:
460 case SK_LITERACY: 430 case SK_LITERACY:
461 case SK_WOODSMAN: 431 case SK_WOODSMAN:
462 /* first, we try to find a cauldron, and do the alchemy thing. 432 /* first, we try to find a cauldron, and do the alchemy thing.
463 * failing that, we go and identify stuff. 433 * failing that, we go and identify stuff.
464 */ 434 */
465 for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = next) 435 for (object *next, *tmp = GET_MAP_OB (op->map, op->x, op->y); tmp; tmp = next)
466 { 436 {
467 next = tmp->above; 437 next = tmp->above;
468 438
469 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON)) 439 if (QUERY_FLAG (tmp, FLAG_IS_CAULDRON))
470 { 440 {
471 attempt_do_alchemy (op, tmp); 441 attempt_do_alchemy (op, tmp);
472 442
473 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 443 if (QUERY_FLAG (tmp, FLAG_APPLIED))
474 esrv_send_inventory (op, tmp); 444 esrv_send_inventory (op, tmp);
475 445
476 did_alc = 1; 446 did_alc = 1;
477 } 447 }
478 } 448 }
479 449
480 if (did_alc == 0) 450 if (did_alc == 0)
481 exp = success = skill_ident (op, skill);
482
483 break;
484
485 case SK_DET_MAGIC:
486 case SK_DET_CURSE:
487 exp = success = skill_ident (op, skill); 451 exp = success = skill_ident (op, skill);
452
488 break; 453 break;
489 454
455 case SK_DET_MAGIC:
456 case SK_DET_CURSE:
457 exp = success = skill_ident (op, skill);
458 break;
459
490 case SK_DISARM_TRAPS: 460 case SK_DISARM_TRAPS:
491 exp = success = remove_trap (op, dir, skill); 461 exp = success = remove_trap (op, dir, skill);
492 break; 462 break;
493 463
494 case SK_THROWING: 464 case SK_THROWING:
495 success = skill_throw (op, part, dir, string, skill); 465 success = skill_throw (op, part, dir, string, skill);
496 break; 466 break;
497 467
498 case SK_SET_TRAP: 468 case SK_SET_TRAP:
499 new_draw_info (NDI_UNIQUE, 0, op, "This skill is not currently implemented."); 469 new_draw_info (NDI_UNIQUE, 0, op, "This skill is not currently implemented.");
500 break; 470 break;
501 471
502 case SK_USE_MAGIC_ITEM: 472 case SK_USE_MAGIC_ITEM:
503 case SK_MISSILE_WEAPON: 473 case SK_MISSILE_WEAPON:
504 new_draw_info (NDI_UNIQUE, 0, op, "There is no special attack for this skill."); 474 new_draw_info (NDI_UNIQUE, 0, op, "There is no special attack for this skill.");
505 break; 475 break;
506 476
507 case SK_PRAYING: 477 case SK_PRAYING:
508 success = pray (op, skill); 478 success = pray (op, skill);
509 break; 479 break;
510 480
511 case SK_BARGAINING: 481 case SK_BARGAINING:
512 success = describe_shop (op); 482 success = describe_shop (op);
513 break; 483 break;
514 484
515 case SK_SORCERY: 485 case SK_SORCERY:
516 case SK_EVOCATION: 486 case SK_EVOCATION:
517 case SK_PYROMANCY: 487 case SK_PYROMANCY:
518 case SK_SUMMONING: 488 case SK_SUMMONING:
519 case SK_CLIMBING: 489 case SK_CLIMBING:
520 new_draw_info (NDI_UNIQUE, 0, op, "This skill is already in effect."); 490 new_draw_info (NDI_UNIQUE, 0, op, "This skill is already in effect.");
521 break; 491 break;
522 492
523 default: 493 default:
524 LOG (llevDebug, "%s attempted to use unknown skill: %d\n", query_name (op), op->chosen_skill->stats.sp); 494 LOG (llevDebug, "%s attempted to use unknown skill: %d\n", query_name (op), op->chosen_skill->stats.sp);
525 break; 495 break;
526 } 496 }
527 497
528 /* For players we now update the speed_left from using the skill. 498 /* For players we now update the speed_left from using the skill.
529 * Monsters have no skill use time because of the random nature in 499 * Monsters have no skill use time because of the random nature in
530 * which use_monster_skill is called already simulates this. 500 * which use_monster_skill is called already simulates this.
531 * If certain skills should take more/less time, that should be 501 * If certain skills should take more/less time, that should be
532 * in the code for the skill itself. 502 * in the code for the skill itself.
533 */ 503 */
534 504
535 if (op->type == PLAYER) 505 if (op->type == PLAYER)
536 op->speed_left -= 1.0; 506 op->speed_left -= 1.f;
537 507
538 /* this is a good place to add experience for successfull use of skills. 508 /* this is a good place to add experience for successfull use of skills.
539 * Note that add_exp() will figure out player/monster experience 509 * Note that add_exp() will figure out player/monster experience
540 * gain problems. 510 * gain problems.
541 */ 511 */
569 * op is the object that was 'defeated'. 539 * op is the object that was 'defeated'.
570 * skill is the skill used. If no skill is used, it should just 540 * skill is the skill used. If no skill is used, it should just
571 * point back to who. 541 * point back to who.
572 * 542 *
573 */ 543 */
574
575int 544int
576calc_skill_exp (object *who, object *op, object *skill) 545calc_skill_exp (object *who, object *op, object *skill)
577{ 546{
578 int op_exp = 0, op_lvl = 0; 547 int op_exp = 0, op_lvl = 0;
579 float base, value, lvl_mult = 0.0; 548 float base, value, lvl_mult = 0.0;
668 * This one actually teaches the player the skill as something 637 * This one actually teaches the player the skill as something
669 * they can equip. 638 * they can equip.
670 * Return 0 if the player knows the skill, 1 if the 639 * Return 0 if the player knows the skill, 1 if the
671 * player learns the skill, 2 otherwise. 640 * player learns the skill, 2 otherwise.
672 */ 641 */
673
674int 642int
675learn_skill (object *pl, object *scroll) 643learn_skill (object *pl, object *scroll)
676{ 644{
677 object *tmp; 645 object *tmp;
678 646
714 link_player_skills (pl); 682 link_player_skills (pl);
715 return 1; 683 return 1;
716} 684}
717 685
718/* Gives a percentage clipped to 0% -> 100% of a/b. */ 686/* Gives a percentage clipped to 0% -> 100% of a/b. */
719
720/* Probably belongs in some global utils-type file? */ 687/* Probably belongs in some global utils-type file? */
721static int 688static int
722clipped_percent (sint64 a, sint64 b) 689clipped_percent (sint64 a, sint64 b)
723{ 690{
724 int rv; 691 int rv;
797 } 764 }
798 765
799 clear_win_info (op); 766 clear_win_info (op);
800 new_draw_info (NDI_UNIQUE, 0, op, "Player skills:"); 767 new_draw_info (NDI_UNIQUE, 0, op, "Player skills:");
801 if (num_skills_found > 1) 768 if (num_skills_found > 1)
802 qsort (skills, num_skills_found, MAX_BUF, (int (*)(const void *, const void *)) strcmp); 769 qsort (skills, num_skills_found, MAX_BUF, (int (*)(const void *, const void *)) std::strcmp);
803 770
804 for (i = 0; i < num_skills_found; i++) 771 for (i = 0; i < num_skills_found; i++)
805 {
806 new_draw_info (NDI_UNIQUE, 0, op, skills[i]); 772 new_draw_info (NDI_UNIQUE, 0, op, skills[i]);
807 }
808 773
809 new_draw_info_format (NDI_UNIQUE, 0, op, "You can handle %d weapon improvements.", op->level / 5 + 5); 774 new_draw_info_format (NDI_UNIQUE, 0, op, "You can handle %d weapon improvements.", op->level / 5 + 5);
810 775
811 cp = determine_god (op); 776 cp = determine_god (op);
812 new_draw_info_format (NDI_UNIQUE, 0, op, "You worship %s.", cp ? cp : "no god at current time"); 777 new_draw_info_format (NDI_UNIQUE, 0, op, "You worship %s.", cp ? cp : "no god at current time");
819 * direction that the user is facing. Returns false if we are unable to 784 * direction that the user is facing. Returns false if we are unable to
820 * change to the requested skill, or were unable to use the skill properly. 785 * change to the requested skill, or were unable to use the skill properly.
821 * This is tricky because skills can have spaces. We basically roll 786 * This is tricky because skills can have spaces. We basically roll
822 * our own find_skill_by_name so we can try to do better string matching. 787 * our own find_skill_by_name so we can try to do better string matching.
823 */ 788 */
824
825int 789int
826use_skill (object *op, const char *string) 790use_skill (object *op, const char *string)
827{ 791{
828 object *skop; 792 object *skop;
829 size_t len; 793 size_t len;
877} 841}
878 842
879static bool 843static bool
880hth_skill_p (object *skill) 844hth_skill_p (object *skill)
881{ 845{
882 for (unsigned int i = 0; i < sizeof (unarmed_skills); ++i) 846 return (skill_flags [skill->subtype] & (SF_COMBAT | SF_NEED_WEAPON)) == SF_COMBAT;
883 if (skill->subtype == unarmed_skills[i])
884 return 1;
885
886 return 0;
887} 847}
888 848
889/* This finds the first unarmed skill the player has, and returns it. 849/* This finds the first unarmed skill the player has, and returns it.
890 */ 850 */
891static object * 851static object *
905 * tmp is the targetted monster. 865 * tmp is the targetted monster.
906 * op is what is attacking 866 * op is what is attacking
907 * string is passed along to describe what messages to describe 867 * string is passed along to describe what messages to describe
908 * the damage. 868 * the damage.
909 */ 869 */
910
911static int 870static int
912do_skill_attack (object *tmp, object *op, const char *string, object *skill) 871do_skill_attack (object *tmp, object *op, const char *string, object *skill)
913{ 872{
914 int success;
915
916 if (INVOKE_OBJECT (SKILL_ATTACK, op, ARG_OBJECT (tmp), ARG_STRING (string), ARG_OBJECT (skill))) 873 if (INVOKE_OBJECT (SKILL_ATTACK, op, ARG_OBJECT (tmp), ARG_STRING (string), ARG_OBJECT (skill)))
917 return RESULT_INT (0); 874 return RESULT_INT (0);
918 875
919 /* For Players only: if there is no ready weapon, and no "attack" skill 876 /* For Players only: if there is no ready weapon, and no "attack" skill
920 * is readied either then try to find a skill for the player to use. 877 * is readied either then try to find a skill for the player to use.
921 * it is presumed that if skill is set, it is a valid attack skill (eg, 878 * it is presumed that if skill is set, it is a valid attack skill (eg,
922 * the caller should have set it appropriately). We still want to pass 879 * the caller should have set it appropriately). We still want to pass
923 * through that code if skill is set to change to the skill. 880 * through that code if skill is set to change to the skill.
924 */ 881 */
925 if (op->type == PLAYER) 882 if (player *pl = op->contr)
926 { 883 {
927 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 884 if (!pl->combat_ob)
928 { 885 {
929 if (!skill) 886 if (QUERY_FLAG (op, FLAG_READY_WEAPON))
930 { 887 {
931 /* See if the players chosen skill is a combat skill, and use 888 for (tmp = op->inv; tmp; tmp = tmp->below)
932 * it if appropriate. 889 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED))
933 */ 890 break;
934 if (op->chosen_skill && hth_skill_p (op->chosen_skill)) 891
935 skill = op->chosen_skill; 892 if (!tmp)
936 else
937 { 893 {
938 skill = find_player_hth_skill (op); 894 LOG (llevError, "Could not find applied weapon on %s\n", &op->name);
895 return 0;
896 }
939 897
898 change_skill (op, find_skill_by_name (op, tmp->skill), 1);
899 }
900 else
901 {
940 if (!skill) 902 if (!skill)
903 {
904 /* See if the players chosen skill is a combat skill, and use
905 * it if appropriate.
906 */
907 if (op->chosen_skill && hth_skill_p (op->chosen_skill))
908 skill = op->chosen_skill;
909 else
941 { 910 {
911 skill = find_player_hth_skill (op);
912
913 if (!skill)
914 {
942 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!"); 915 new_draw_info (NDI_BLACK, 0, op, "You have no unarmed combat skills!");
943 return 0; 916 return 0;
917 }
944 } 918 }
945 } 919 }
920
921 /* now try to ready the new skill */
922 if (!change_skill (op, skill, 0))
923 { /* oh oh, trouble! */
924 new_draw_info_format (NDI_UNIQUE, 0, op, "Couldn't change to skill %s", &skill->name);
925 return 0;
926 }
946 } 927 }
947 928
948 /* now try to ready the new skill */ 929 if (!pl->combat_ob)
949 if (!change_skill (op, skill, 0)) 930 {
950 { /* oh oh, trouble! */ 931 LOG (llevError, "Could not find anything to attack on %s\n", &op->name);
951 new_draw_info_format (NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name);
952 return 0; 932 return 0;
953 } 933 }
954 } 934 }
955 else 935
936 if (!op->change_weapon (pl->combat_ob))
937 return 0;
938
939 /* lose invisiblity/hiding status for running attacks */
940 if (pl->tmp_invis)
956 { 941 {
957 /* Seen some crashes below where current_weapon is not set, 942 pl->tmp_invis = 0;
958 * even though the flag says it is. So if current weapon isn't set, 943 op->invisible = 0;
959 * do some work in trying to find the object to use. 944 op->hide = 0;
960 */ 945 update_object (op, UP_OBJ_CHANGE);
961 if (!op->current_weapon)
962 {
963 object *tmp;
964
965 LOG (llevError, "Player %s does not have current weapon set but flag_ready_weapon is set\n", &op->name);
966 for (tmp = op->inv; tmp; tmp = tmp->below)
967 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_APPLIED))
968 break;
969
970 if (!tmp)
971 {
972 LOG (llevError, "Could not find applied weapon on %s\n", &op->name);
973 op->current_weapon = NULL;
974 return 0;
975 }
976 else
977 {
978 op->current_weapon = tmp;
979 }
980 }
981
982 change_skill (op, find_skill_by_name (op, op->current_weapon->skill), 1);
983 } 946 }
984 } 947 }
985 948
986 /* lose invisiblity/hiding status for running attacks */
987
988 if (op->type == PLAYER && op->contr->tmp_invis)
989 {
990 op->contr->tmp_invis = 0;
991 op->invisible = 0;
992 op->hide = 0;
993 update_object (op, UP_OBJ_FACE);
994 }
995
996 success = attack_ob (tmp, op); 949 int success = attack_ob (tmp, op);
997 950
998 /* print appropriate messages to the player */ 951 /* print appropriate messages to the player */
999 952
1000 if (success && string != NULL && tmp && !QUERY_FLAG (tmp, FLAG_FREED)) 953 if (success && string && tmp && !QUERY_FLAG (tmp, FLAG_FREED))
1001 { 954 {
1002 if (op->type == PLAYER) 955 if (op->type == PLAYER)
1003 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp)); 956 new_draw_info_format (NDI_UNIQUE, 0, op, "You %s %s!", string, query_name (tmp));
1004 else if (tmp->type == PLAYER) 957 else if (tmp->type == PLAYER)
1005 new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string); 958 new_draw_info_format (NDI_UNIQUE, 0, tmp, "%s %s you!", query_name (op), string);
1006 } 959 }
960
1007 return success; 961 return success;
1008} 962}
1009
1010 963
1011/* skill_attack() - Core routine for use when we attack using a skills 964/* skill_attack() - Core routine for use when we attack using a skills
1012 * system. In essence, this code handles 965 * system. In essence, this code handles
1013 * all skill-based attacks, ie hth, missile and melee weapons should be 966 * all skill-based attacks, ie hth, missile and melee weapons should be
1014 * treated here. If an opponent is already supplied by move_player(), 967 * treated here. If an opponent is already supplied by move_player(),
1017 * 970 *
1018 * This is called by move_player() and attack_hth() 971 * This is called by move_player() and attack_hth()
1019 * 972 *
1020 * Initial implementation by -bt thomas@astro.psu.edu 973 * Initial implementation by -bt thomas@astro.psu.edu
1021 */ 974 */
1022
1023int 975int
1024skill_attack (object *tmp, object *pl, int dir, const char *string, object *skill) 976skill_attack (object *tmp, object *pl, int dir, const char *string, object *skill)
1025{ 977{
1026 sint16 tx, ty; 978 sint16 tx, ty;
1027 maptile *m; 979 maptile *m;
1034 ty = freearr_y[dir]; 986 ty = freearr_y[dir];
1035 987
1036 /* If we don't yet have an opponent, find if one exists, and attack. 988 /* If we don't yet have an opponent, find if one exists, and attack.
1037 * Legal opponents are the same as outlined in move_player_attack() 989 * Legal opponents are the same as outlined in move_player_attack()
1038 */ 990 */
1039 991 if (!tmp)
1040 if (tmp == NULL)
1041 { 992 {
1042 m = pl->map; 993 m = pl->map;
1043 tx = pl->x + freearr_x[dir]; 994 tx = pl->x + freearr_x[dir];
1044 ty = pl->y + freearr_y[dir]; 995 ty = pl->y + freearr_y[dir];
1045 996
1055 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR) 1006 if ((QUERY_FLAG (tmp, FLAG_ALIVE) && tmp->stats.hp >= 0) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || tmp->type == LOCKED_DOOR)
1056 { 1007 {
1057 /* Don't attack party members */ 1008 /* Don't attack party members */
1058 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party)) 1009 if ((pl->type == PLAYER && tmp->type == PLAYER) && (pl->contr->party != NULL && pl->contr->party == tmp->contr->party))
1059 return 0; 1010 return 0;
1011
1060 break; 1012 break;
1061 } 1013 }
1062 } 1014 }
1015
1063 if (!tmp) 1016 if (!tmp)
1064 { 1017 {
1065 if (pl->type == PLAYER) 1018 if (pl->type == PLAYER)
1066 new_draw_info (NDI_UNIQUE, 0, pl, "There is nothing to attack!"); 1019 new_draw_info (NDI_UNIQUE, 0, pl, "There is nothing to attack!");
1020
1067 return 0; 1021 return 0;
1068 } 1022 }
1069 1023
1070 return do_skill_attack (tmp, pl, string, skill); 1024 return do_skill_attack (tmp, pl, string, skill);
1071} 1025}
1072
1073 1026
1074/* attack_hth() - this handles all hand-to-hand attacks -b.t. */ 1027/* attack_hth() - this handles all hand-to-hand attacks -b.t. */
1075 1028
1076/* July 5, 1995 - I broke up attack_hth() into 2 parts. In the first 1029/* July 5, 1995 - I broke up attack_hth() into 2 parts. In the first
1077 * (attack_hth) we check for weapon use, etc in the second (the new 1030 * (attack_hth) we check for weapon use, etc in the second (the new
1078 * function skill_attack() we actually attack. 1031 * function skill_attack() we actually attack.
1079 */ 1032 */
1080
1081static int 1033static int
1082attack_hth (object *pl, int dir, const char *string, object *skill) 1034attack_hth (object *pl, int dir, const char *string, object *skill)
1083{ 1035{
1084 object *enemy = NULL, *weapon; 1036 object *enemy = NULL, *weapon;
1085 1037
1094 if (pl->type == PLAYER) 1046 if (pl->type == PLAYER)
1095 { 1047 {
1096 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack."); 1048 new_draw_info (NDI_UNIQUE, 0, pl, "You unwield your weapon in order to attack.");
1097 esrv_update_item (UPD_FLAGS, pl, weapon); 1049 esrv_update_item (UPD_FLAGS, pl, weapon);
1098 } 1050 }
1051
1099 break; 1052 break;
1100 } 1053 }
1101 } 1054 }
1055
1102 return skill_attack (enemy, pl, dir, string, skill); 1056 return skill_attack (enemy, pl, dir, string, skill);
1103} 1057}
1104
1105 1058
1106/* attack_melee_weapon() - this handles melee weapon attacks -b.t. 1059/* attack_melee_weapon() - this handles melee weapon attacks -b.t.
1107 * For now we are just checking to see if we have a ready weapon here. 1060 * For now we are just checking to see if we have a ready weapon here.
1108 * But there is a real neato possible feature of this scheme which 1061 * But there is a real neato possible feature of this scheme which
1109 * bears mentioning: 1062 * bears mentioning:
1110 * Since we are only calling this from do_skill() in the future 1063 * Since we are only calling this from do_skill() in the future
1111 * we may make this routine handle 'special' melee weapons attacks 1064 * we may make this routine handle 'special' melee weapons attacks
1112 * (like disarming manuever with sai) based on player SK_level and 1065 * (like disarming manuever with sai) based on player SK_level and
1113 * weapon type. 1066 * weapon type.
1114 */ 1067 */
1115
1116static int 1068static int
1117attack_melee_weapon (object *op, int dir, const char *string, object *skill) 1069attack_melee_weapon (object *op, int dir, const char *string, object *skill)
1118{ 1070{
1119 1071
1120 if (!QUERY_FLAG (op, FLAG_READY_WEAPON)) 1072 if (!QUERY_FLAG (op, FLAG_READY_WEAPON))
1121 { 1073 {
1122 if (op->type == PLAYER) 1074 if (op->type == PLAYER)
1123 new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!"); 1075 new_draw_info (NDI_UNIQUE, 0, op, "You have no ready weapon to attack with!");
1076
1124 return 0; 1077 return 0;
1125 } 1078 }
1079
1126 return skill_attack (NULL, op, dir, string, skill); 1080 return skill_attack (NULL, op, dir, string, skill);
1127 1081
1128} 1082}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines