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.3 by root, Sat Aug 26 08:44:07 2006 UTC vs.
Revision 1.7 by root, Sun Sep 3 00:18:42 2006 UTC

1/* 1/*
2 * static char *rcsid_skill_util_c = 2 * static char *rcsid_skill_util_c =
3 * "$Id: skill_util.C,v 1.3 2006/08/26 08:44:07 root Exp $"; 3 * "$Id: skill_util.C,v 1.7 2006/09/03 00:18:42 root Exp $";
4 */ 4 */
5/* 5/*
6 CrossFire, A Multiplayer game for X-windows 6 CrossFire, A Multiplayer game for X-windows
7 7
8 Copryight (C) 2002 Mark Wedel & Crossfire Development Team 8 Copryight (C) 2002 Mark Wedel & Crossfire Development Team
53#include <spells.h> 53#include <spells.h>
54 54
55static int attack_hth(object *pl, int dir, const char *string, object *skill); 55static int attack_hth(object *pl, int dir, const char *string, object *skill);
56static int attack_melee_weapon(object *op, int dir, const char *string, object *skill); 56static int attack_melee_weapon(object *op, int dir, const char *string, object *skill);
57 57
58const char *skill_names[NUM_SKILLS]; 58shstr skill_names[NUM_SKILLS];
59 59
60/* init_skills basically just sets up the skill_names table 60/* init_skills basically just sets up the skill_names table
61 * above. The index into the array is set up by the 61 * above. The index into the array is set up by the
62 * subtypes. 62 * subtypes.
63 */ 63 */
64void init_skills(void) { 64void init_skills(void) {
65 int i; 65 int i;
66 archetype *at; 66 archetype *at;
67 67
68 for (i=0; i<NUM_SKILLS; i++)
69 skill_names[i] = NULL;
70
71 for(at = first_archetype;at!=NULL;at=at->next) { 68 for(at = first_archetype;at!=NULL;at=at->next) {
72 if (at->clone.type == SKILL) { 69 if (at->clone.type == SKILL) {
73 if (skill_names[at->clone.subtype] != NULL) { 70 if (skill_names[at->clone.subtype] != NULL) {
74 LOG(llevError, "init_skills: multiple skill using same subtype %d, %s, %s\n", 71 LOG(llevError, "init_skills: multiple skill using same subtype %d, %s, %s\n",
75 at->clone.subtype, skill_names[at->clone.subtype], at->clone.skill); 72 at->clone.subtype, &skill_names[at->clone.subtype], &at->clone.skill);
76 } else { 73 } else {
77 skill_names[at->clone.subtype] = add_refcount(at->clone.skill); 74 skill_names[at->clone.subtype] = at->clone.skill;
78 } 75 }
79 } 76 }
80 } 77 }
81 78
82 /* This isn't really an error if there is no skill subtype set, but 79 /* This isn't really an error if there is no skill subtype set, but
83 * checking for this may catch some user errors. 80 * checking for this may catch some user errors.
84 */ 81 */
85 for (i=1; i<NUM_SKILLS; i++) { 82 for (i=1; i<NUM_SKILLS; i++) {
86 if (!skill_names[i]) 83 if (!skill_names[i])
87 LOG(llevError, "init_skills: skill subtype %d doesn't have a name?\n", 84 LOG(llevError, "init_skills: skill subtype %d doesn't have a name?\n",
88 i); 85 i);
89 } 86 }
90} 87}
91 88
92 89
93/* This function goes through the player inventory and sets 90/* This function goes through the player inventory and sets
98void link_player_skills(object *op) 95void link_player_skills(object *op)
99{ 96{
100 object *tmp; 97 object *tmp;
101 98
102 for (tmp=op->inv; tmp; tmp=tmp->below) { 99 for (tmp=op->inv; tmp; tmp=tmp->below) {
103 if (tmp->type == SKILL) { 100 if (tmp->type == SKILL) {
104 /* This is really a warning, hence no else below */ 101 /* This is really a warning, hence no else below */
105 if (op->contr->last_skill_ob[tmp->subtype] && op->contr->last_skill_ob[tmp->subtype] != tmp) { 102 if (op->contr->last_skill_ob[tmp->subtype] && op->contr->last_skill_ob[tmp->subtype] != tmp) {
106 LOG(llevError,"Multiple skills with the same subtype? %s, %s\n", 103 LOG(llevError,"Multiple skills with the same subtype? %s, %s\n",
107 op->contr->last_skill_ob[tmp->subtype]->skill, tmp->skill); 104 &op->contr->last_skill_ob[tmp->subtype]->skill, &tmp->skill);
108 } 105 }
109 if (tmp->subtype >= NUM_SKILLS) { 106 if (tmp->subtype >= NUM_SKILLS) {
110 LOG(llevError,"Invalid subtype number %d (range 0-%d)\n", 107 LOG(llevError,"Invalid subtype number %d (range 0-%d)\n",
111 tmp->subtype, NUM_SKILLS); 108 tmp->subtype, NUM_SKILLS);
112 } else { 109 } else {
113 op->contr->last_skill_ob[tmp->subtype] = tmp; 110 op->contr->last_skill_ob[tmp->subtype] = tmp;
114 op->contr->last_skill_exp[tmp->subtype] = -1; 111 op->contr->last_skill_exp[tmp->subtype] = -1;
115 } 112 }
116 } 113 }
117 } 114 }
118} 115}
119 116
120/* This returns the skill pointer of the given name (the 117/* This returns the skill pointer of the given name (the
121 * one that accumlates exp, has the level, etc). 118 * one that accumlates exp, has the level, etc).
133 /* We make sure the length of the string in the object is greater 130 /* We make sure the length of the string in the object is greater
134 * in length than the passed string. Eg, if we have a skill called 131 * in length than the passed string. Eg, if we have a skill called
135 * 'hi', we don't want to match if the user passed 'high' 132 * 'hi', we don't want to match if the user passed 'high'
136 */ 133 */
137 for (tmp=who->inv; tmp!=NULL; tmp=tmp->below) { 134 for (tmp=who->inv; tmp!=NULL; tmp=tmp->below) {
138 if (tmp->type == SKILL && !strncasecmp(name, tmp->skill, strlen(name)) && 135 if (tmp->type == SKILL && !strncasecmp(name, tmp->skill, strlen(name)) &&
139 strlen(tmp->skill) >= strlen(name)) skill = tmp; 136 strlen(tmp->skill) >= strlen(name)) skill = tmp;
140 137
141 /* Try to find appropriate skilltool. If the player has one already 138 /* Try to find appropriate skilltool. If the player has one already
142 * applied, we try to keep using that one. 139 * applied, we try to keep using that one.
143 */ 140 */
144 else if (tmp->type == SKILL_TOOL && !strncasecmp(name, tmp->skill, strlen(name)) && 141 else if (tmp->type == SKILL_TOOL && !strncasecmp(name, tmp->skill, strlen(name)) &&
145 strlen(tmp->skill) >= strlen(name)) { 142 strlen(tmp->skill) >= strlen(name)) {
146 if (QUERY_FLAG(tmp, FLAG_APPLIED)) skill_tool = tmp; 143 if (QUERY_FLAG(tmp, FLAG_APPLIED)) skill_tool = tmp;
147 else if (!skill_tool || !QUERY_FLAG(skill_tool, FLAG_APPLIED)) 144 else if (!skill_tool || !QUERY_FLAG(skill_tool, FLAG_APPLIED))
148 skill_tool = tmp; 145 skill_tool = tmp;
149 } 146 }
150 } 147 }
151 /* If this is a skill that can be used without a tool, return it */ 148 /* If this is a skill that can be used without a tool, return it */
152 if (skill && QUERY_FLAG(skill, FLAG_CAN_USE_SKILL)) return skill; 149 if (skill && QUERY_FLAG(skill, FLAG_CAN_USE_SKILL)) return skill;
153 150
154 /* Player has a tool to use the skill. IF not applied, apply it - 151 /* Player has a tool to use the skill. IF not applied, apply it -
155 * if not successful, return null. If they do have the skill tool 152 * if not successful, return null. If they do have the skill tool
156 * but not the skill itself, give it to them. 153 * but not the skill itself, give it to them.
157 */ 154 */
158 if (skill_tool) { 155 if (skill_tool) {
159 if (!QUERY_FLAG(skill_tool, FLAG_APPLIED)) { 156 if (!QUERY_FLAG(skill_tool, FLAG_APPLIED)) {
160 if (apply_special(who, skill_tool, 0)) return NULL; 157 if (apply_special(who, skill_tool, 0)) return NULL;
161 } 158 }
162 if (!skill) { 159 if (!skill) {
163 skill = give_skill_by_name(who, skill_tool->skill); 160 skill = give_skill_by_name(who, skill_tool->skill);
164 link_player_skills(who); 161 link_player_skills(who);
165 } 162 }
166 return skill; 163 return skill;
167 } 164 }
168 return NULL; 165 return NULL;
169} 166}
170 167
171 168
185 object *skill=NULL, *skill_tool=NULL, *tmp; 182 object *skill=NULL, *skill_tool=NULL, *tmp;
186 183
187 if (skillno < 1 || skillno >= NUM_SKILLS) return NULL; 184 if (skillno < 1 || skillno >= NUM_SKILLS) return NULL;
188 185
189 for (tmp=who->inv; tmp!=NULL; tmp=tmp->below) { 186 for (tmp=who->inv; tmp!=NULL; tmp=tmp->below) {
190 if (tmp->type == SKILL && tmp->subtype == skillno) skill = tmp; 187 if (tmp->type == SKILL && tmp->subtype == skillno) skill = tmp;
191 188
192 /* Try to find appropriate skilltool. If the player has one already 189 /* Try to find appropriate skilltool. If the player has one already
193 * applied, we try to keep using that one. 190 * applied, we try to keep using that one.
194 */ 191 */
195 else if (tmp->type == SKILL_TOOL && tmp->subtype == skillno) { 192 else if (tmp->type == SKILL_TOOL && tmp->subtype == skillno) {
196 if (QUERY_FLAG(tmp, FLAG_APPLIED)) skill_tool = tmp; 193 if (QUERY_FLAG(tmp, FLAG_APPLIED)) skill_tool = tmp;
197 else if (!skill_tool || !QUERY_FLAG(skill_tool, FLAG_APPLIED)) 194 else if (!skill_tool || !QUERY_FLAG(skill_tool, FLAG_APPLIED))
198 skill_tool = tmp; 195 skill_tool = tmp;
199 } 196 }
200 } 197 }
201 /* If this is a skill that can be used without a tool, return it */ 198 /* If this is a skill that can be used without a tool, return it */
202 if (skill && QUERY_FLAG(skill, FLAG_CAN_USE_SKILL)) return skill; 199 if (skill && QUERY_FLAG(skill, FLAG_CAN_USE_SKILL)) return skill;
203 200
204 /* Player has a tool to use the skill. IF not applied, apply it - 201 /* Player has a tool to use the skill. IF not applied, apply it -
205 * if not successful, return null. If they do have the skill tool 202 * if not successful, return null. If they do have the skill tool
206 * but not the skill itself, give it to them. 203 * but not the skill itself, give it to them.
207 */ 204 */
208 if (skill_tool) { 205 if (skill_tool) {
209 if (!QUERY_FLAG(skill_tool, FLAG_APPLIED)) { 206 if (!QUERY_FLAG(skill_tool, FLAG_APPLIED)) {
210 if (apply_special(who, skill_tool, 0)) return NULL; 207 if (apply_special(who, skill_tool, 0)) return NULL;
211 } 208 }
212 if (!skill) { 209 if (!skill) {
213 skill = give_skill_by_name(who, skill_tool->skill); 210 skill = give_skill_by_name(who, skill_tool->skill);
214 link_player_skills(who); 211 link_player_skills(who);
215 } 212 }
216 return skill; 213 return skill;
217 } 214 }
218 return NULL; 215 return NULL;
219} 216}
220 217
221/* This changes the objects skill to new_skill. 218/* This changes the objects skill to new_skill.
246 who->contr->shoottype = range_skill; 243 who->contr->shoottype = range_skill;
247 return 1; 244 return 1;
248 } 245 }
249 246
250 if (!new_skill || who->chosen_skill) 247 if (!new_skill || who->chosen_skill)
251 if (who->chosen_skill) apply_special(who, who->chosen_skill, AP_UNAPPLY); 248 if (who->chosen_skill) apply_special(who, who->chosen_skill, AP_UNAPPLY);
252 249
253 /* Only goal in this case was to unapply a skill */ 250 /* Only goal in this case was to unapply a skill */
254 if (!new_skill) return 0; 251 if (!new_skill) return 0;
255 252
256 if (apply_special (who, new_skill, AP_APPLY)) { 253 if (apply_special (who, new_skill, AP_APPLY)) {
257 return 0; 254 return 0;
258 } 255 }
259 if (flag & 0x1) 256 if (flag & 0x1)
260 who->contr->shoottype = (rangetype) old_range; 257 who->contr->shoottype = (rangetype) old_range;
261 258
262 return 1; 259 return 1;
263} 260}
264 261
265/* This function just clears the chosen_skill and range_skill values 262/* This function just clears the chosen_skill and range_skill values
268void clear_skill(object *who) 265void clear_skill(object *who)
269{ 266{
270 who->chosen_skill = NULL; 267 who->chosen_skill = NULL;
271 CLEAR_FLAG(who, FLAG_READY_SKILL); 268 CLEAR_FLAG(who, FLAG_READY_SKILL);
272 if (who->type == PLAYER) { 269 if (who->type == PLAYER) {
273 who->contr->ranges[range_skill] = NULL; 270 who->contr->ranges[range_skill] = NULL;
274 if (who->contr->shoottype == range_skill) 271 if (who->contr->shoottype == range_skill)
275 who->contr->shoottype = range_none; 272 who->contr->shoottype = range_none;
276 } 273 }
277} 274}
278 275
279/* do_skill() - Main skills use function-similar in scope to cast_spell(). 276/* do_skill() - Main skills use function-similar in scope to cast_spell().
280 * We handle all requests for skill use outside of some combat here. 277 * We handle all requests for skill use outside of some combat here.
298 * holds the exp, level, etc of the skill. So if this is a player 295 * holds the exp, level, etc of the skill. So if this is a player
299 * go and try to find the actual real skill pointer, and if the 296 * go and try to find the actual real skill pointer, and if the
300 * the player doesn't have a bucket for that, create one. 297 * the player doesn't have a bucket for that, create one.
301 */ 298 */
302 if (skill->type != SKILL && op->type == PLAYER) { 299 if (skill->type != SKILL && op->type == PLAYER) {
303 for (tmp = op->inv; tmp!=NULL; tmp=tmp->below) { 300 for (tmp = op->inv; tmp!=NULL; tmp=tmp->below) {
304 if (tmp->type == SKILL && tmp->skill == skill->skill) break; 301 if (tmp->type == SKILL && tmp->skill == skill->skill) break;
305 } 302 }
306 if (!tmp) tmp=give_skill_by_name(op, skill->skill); 303 if (!tmp) tmp=give_skill_by_name(op, skill->skill);
307 skill = tmp; 304 skill = tmp;
308 } 305 }
309 306
310 // skill, by_whom, on_which_object, which direction, skill_argument 307 // skill, by_whom, on_which_object, which direction, skill_argument
311 if (INVOKE_OBJECT (USE_SKILL, skill, ARG_OBJECT (op), ARG_OBJECT (part), ARG_INT (dir), ARG_STRING (string))) 308 if (INVOKE_OBJECT (USE_SKILL, skill, ARG_OBJECT (op), ARG_OBJECT (part), ARG_INT (dir), ARG_STRING (string)))
312 return 0; 309 return 0;
313 310
314 switch(skill->subtype) { 311 switch(skill->subtype) {
315 case SK_LEVITATION: 312 case SK_LEVITATION:
316 /* Not 100% sure if this will work with new movement code - 313 /* Not 100% sure if this will work with new movement code -
317 * the levitation skill has move_type for flying, so when 314 * the levitation skill has move_type for flying, so when
318 * equipped, that should transfer to player, when not, 315 * equipped, that should transfer to player, when not,
319 * shouldn't. 316 * shouldn't.
320 */ 317 */
321 if(QUERY_FLAG(skill,FLAG_APPLIED)) { 318 if(QUERY_FLAG(skill,FLAG_APPLIED)) {
322 CLEAR_FLAG(skill,FLAG_APPLIED); 319 CLEAR_FLAG(skill,FLAG_APPLIED);
323 new_draw_info(NDI_UNIQUE,0,op,"You come to earth."); 320 new_draw_info(NDI_UNIQUE,0,op,"You come to earth.");
324 } 321 }
325 else { 322 else {
326 SET_FLAG(skill,FLAG_APPLIED); 323 SET_FLAG(skill,FLAG_APPLIED);
327 new_draw_info(NDI_UNIQUE,0,op,"You rise into the air!."); 324 new_draw_info(NDI_UNIQUE,0,op,"You rise into the air!.");
328 } 325 }
329 fix_player(op); 326 fix_player(op);
330 success=1; 327 success=1;
331 break; 328 break;
332 329
333 case SK_STEALING: 330 case SK_STEALING:
334 exp = success = steal(op, dir, skill); 331 exp = success = steal(op, dir, skill);
335 break; 332 break;
336 333
337 case SK_LOCKPICKING: 334 case SK_LOCKPICKING:
338 exp = success = pick_lock(op, dir, skill); 335 exp = success = pick_lock(op, dir, skill);
339 break; 336 break;
340 337
341 case SK_HIDING: 338 case SK_HIDING:
342 exp = success = hide(op, skill); 339 exp = success = hide(op, skill);
343 break; 340 break;
344 341
345 case SK_JUMPING: 342 case SK_JUMPING:
346 success = jump(op, dir, skill); 343 success = jump(op, dir, skill);
347 break; 344 break;
348 345
349 case SK_INSCRIPTION: 346 case SK_INSCRIPTION:
350 exp = success = write_on_item(op,string, skill); 347 exp = success = write_on_item(op,string, skill);
351 break; 348 break;
352 349
353 case SK_MEDITATION: 350 case SK_MEDITATION:
354 meditate(op, skill); 351 meditate(op, skill);
355 success=1; 352 success=1;
356 break; 353 break;
357 /* note that the following 'attack' skills gain exp through hit_player() */ 354 /* note that the following 'attack' skills gain exp through hit_player() */
358 355
359 case SK_KARATE: 356 case SK_KARATE:
360 (void) attack_hth(op,dir,"karate-chopped", skill); 357 (void) attack_hth(op,dir,"karate-chopped", skill);
361 break; 358 break;
362 359
363 case SK_PUNCHING: 360 case SK_PUNCHING:
364 (void) attack_hth(op,dir,"punched", skill); 361 (void) attack_hth(op,dir,"punched", skill);
365 break; 362 break;
366 363
367 case SK_FLAME_TOUCH: 364 case SK_FLAME_TOUCH:
368 (void) attack_hth(op,dir,"flamed", skill); 365 (void) attack_hth(op,dir,"flamed", skill);
369 break; 366 break;
370 367
371 case SK_SPARK_TOUCH: 368 case SK_SPARK_TOUCH:
372 (void) attack_hth(op,dir,"zapped", skill); 369 (void) attack_hth(op,dir,"zapped", skill);
373 break; 370 break;
374 371
382 379
383 case SK_POISON_NAIL: 380 case SK_POISON_NAIL:
384 (void) attack_hth(op,dir,"injected poison into", skill); 381 (void) attack_hth(op,dir,"injected poison into", skill);
385 break; 382 break;
386 383
387 case SK_CLAWING: 384 case SK_CLAWING:
388 (void) attack_hth(op,dir,"clawed", skill); 385 (void) attack_hth(op,dir,"clawed", skill);
389 break; 386 break;
390 387
391 case SK_ONE_HANDED_WEAPON: 388 case SK_ONE_HANDED_WEAPON:
392 case SK_TWO_HANDED_WEAPON: 389 case SK_TWO_HANDED_WEAPON:
393 (void) attack_melee_weapon(op,dir,NULL, skill); 390 (void) attack_melee_weapon(op,dir,NULL, skill);
394 break; 391 break;
395 392
396 case SK_FIND_TRAPS: 393 case SK_FIND_TRAPS:
397 exp = success = find_traps(op, skill); 394 exp = success = find_traps(op, skill);
398 break; 395 break;
399 396
400 case SK_SINGING: 397 case SK_SINGING:
401 exp = success = singing(op,dir, skill); 398 exp = success = singing(op,dir, skill);
402 break; 399 break;
403 400
404 case SK_ORATORY: 401 case SK_ORATORY:
405 exp = success = use_oratory(op,dir, skill); 402 exp = success = use_oratory(op,dir, skill);
406 break; 403 break;
407 404
408 case SK_SMITHERY: 405 case SK_SMITHERY:
409 case SK_BOWYER: 406 case SK_BOWYER:
410 case SK_JEWELER: 407 case SK_JEWELER:
411 case SK_ALCHEMY: 408 case SK_ALCHEMY:
412 case SK_THAUMATURGY: 409 case SK_THAUMATURGY:
413 case SK_LITERACY: 410 case SK_LITERACY:
414 case SK_WOODSMAN: 411 case SK_WOODSMAN:
415 /* first, we try to find a cauldron, and do the alchemy thing. 412 /* first, we try to find a cauldron, and do the alchemy thing.
416 * failing that, we go and identify stuff. 413 * failing that, we go and identify stuff.
417 */ 414 */
418 for (tmp=get_map_ob(op->map, op->x, op->y); tmp != NULL;tmp=next) { 415 for (tmp=get_map_ob(op->map, op->x, op->y); tmp != NULL;tmp=next) {
419 next=tmp->above; 416 next=tmp->above;
420 if(QUERY_FLAG(tmp, FLAG_IS_CAULDRON)) { 417 if(QUERY_FLAG(tmp, FLAG_IS_CAULDRON)) {
421 attempt_do_alchemy(op, tmp); 418 attempt_do_alchemy(op, tmp);
422 if (QUERY_FLAG(tmp, FLAG_APPLIED)) 419 if (QUERY_FLAG(tmp, FLAG_APPLIED))
423 esrv_send_inventory(op, tmp); 420 esrv_send_inventory(op, tmp);
424 did_alc=1; 421 did_alc=1;
425 } 422 }
426 } 423 }
427 if (did_alc == 0) 424 if (did_alc == 0)
428 exp = success = skill_ident(op,skill); 425 exp = success = skill_ident(op,skill);
429 break; 426 break;
430 427
431 case SK_DET_MAGIC: 428 case SK_DET_MAGIC:
432 case SK_DET_CURSE: 429 case SK_DET_CURSE:
433 exp = success = skill_ident(op,skill); 430 exp = success = skill_ident(op,skill);
434 break; 431 break;
435 432
436 case SK_DISARM_TRAPS: 433 case SK_DISARM_TRAPS:
437 exp = success = remove_trap(op,dir, skill); 434 exp = success = remove_trap(op,dir, skill);
438 break; 435 break;
439 436
440 case SK_THROWING: 437 case SK_THROWING:
441 success = skill_throw(op,part,dir,string, skill); 438 success = skill_throw(op,part,dir,string, skill);
442 break; 439 break;
443 440
444 case SK_SET_TRAP: 441 case SK_SET_TRAP:
445 new_draw_info(NDI_UNIQUE, 0,op,"This skill is not currently implemented."); 442 new_draw_info(NDI_UNIQUE, 0,op,"This skill is not currently implemented.");
446 break; 443 break;
447 444
448 case SK_USE_MAGIC_ITEM: 445 case SK_USE_MAGIC_ITEM:
449 case SK_MISSILE_WEAPON: 446 case SK_MISSILE_WEAPON:
450 new_draw_info(NDI_UNIQUE, 0,op,"There is no special attack for this skill."); 447 new_draw_info(NDI_UNIQUE, 0,op,"There is no special attack for this skill.");
451 break; 448 break;
452 449
453 case SK_PRAYING: 450 case SK_PRAYING:
454 success = pray(op, skill); 451 success = pray(op, skill);
455 break; 452 break;
456 453
457 case SK_BARGAINING: 454 case SK_BARGAINING:
458 success = describe_shop(op); 455 success = describe_shop(op);
459 break; 456 break;
460 457
461 case SK_SORCERY: 458 case SK_SORCERY:
462 case SK_EVOCATION: 459 case SK_EVOCATION:
463 case SK_PYROMANCY: 460 case SK_PYROMANCY:
464 case SK_SUMMONING: 461 case SK_SUMMONING:
465 case SK_CLIMBING: 462 case SK_CLIMBING:
466 new_draw_info(NDI_UNIQUE, 0,op,"This skill is already in effect."); 463 new_draw_info(NDI_UNIQUE, 0,op,"This skill is already in effect.");
467 break; 464 break;
468 465
469 default: 466 default:
470 LOG(llevDebug,"%s attempted to use unknown skill: %d\n" 467 LOG(llevDebug,"%s attempted to use unknown skill: %d\n"
471 ,query_name(op), op->chosen_skill->stats.sp); 468 ,query_name(op), op->chosen_skill->stats.sp);
472 break; 469 break;
473 } 470 }
474 471
475 /* For players we now update the speed_left from using the skill. 472 /* For players we now update the speed_left from using the skill.
476 * Monsters have no skill use time because of the random nature in 473 * Monsters have no skill use time because of the random nature in
477 * which use_monster_skill is called already simulates this. 474 * which use_monster_skill is called already simulates this.
535 532
536 if(!op) { /* no item/creature */ 533 if(!op) { /* no item/creature */
537 op_lvl= who->map->difficulty < 1 ? 1: who->map->difficulty; 534 op_lvl= who->map->difficulty < 1 ? 1: who->map->difficulty;
538 op_exp = 0; 535 op_exp = 0;
539 } else if(op->type==RUNE || op->type==TRAP) { /* all traps. If stats.Cha > 1 we use that 536 } else if(op->type==RUNE || op->type==TRAP) { /* all traps. If stats.Cha > 1 we use that
540 * for the amount of experience */ 537 * for the amount of experience */
541 op_exp = op->stats.Cha>1 ? op->stats.Cha : op->stats.exp; 538 op_exp = op->stats.Cha>1 ? op->stats.Cha : op->stats.exp;
542 op_lvl = op->level; 539 op_lvl = op->level;
543 } else { /* all other items/living creatures */ 540 } else { /* all other items/living creatures */
544 op_exp = op->stats.exp; 541 op_exp = op->stats.exp;
545 op_lvl = op->level; 542 op_lvl = op->level;
546 if(!QUERY_FLAG(op,FLAG_ALIVE)) { /* for ident/make items */ 543 if(!QUERY_FLAG(op,FLAG_ALIVE)) { /* for ident/make items */
547 op_lvl += 5 * abs(op->magic); 544 op_lvl += 5 * abs(op->magic);
548 } 545 }
549 } 546 }
550 547
551 if(op_lvl<1) op_lvl = 1; 548 if(op_lvl<1) op_lvl = 1;
552 549
553 if(who->type!=PLAYER) { /* for monsters only */ 550 if(who->type!=PLAYER) { /* for monsters only */
554 return ((int) (op_exp*0.1)+1); /* we add one to insure positive value is returned */ 551 return ((int) (op_exp*0.1)+1); /* we add one to insure positive value is returned */
555 } else { /* for players */ 552 } else { /* for players */
556 base = op_exp; 553 base = op_exp;
557 /* if skill really is a skill, then we can look at the skill archetype for 554 /* if skill really is a skill, then we can look at the skill archetype for
558 * bse reward value (exp) and level multiplier factor. 555 * bse reward value (exp) and level multiplier factor.
559 */ 556 */
560 if (skill->type == SKILL) { 557 if (skill->type == SKILL) {
561 base += skill->arch->clone.stats.exp; 558 base += skill->arch->clone.stats.exp;
562 if (settings.simple_exp) { 559 if (settings.simple_exp) {
563 if (skill->arch->clone.level) 560 if (skill->arch->clone.level)
564 lvl_mult = (float) skill->arch->clone.level / 100.0; 561 lvl_mult = (float) skill->arch->clone.level / 100.0;
565 else 562 else
566 lvl_mult = 1.0; /* no adjustment */ 563 lvl_mult = 1.0; /* no adjustment */
567 } 564 }
568 else { 565 else {
569 if (skill->level) 566 if (skill->level)
570 lvl_mult = ((float) skill->arch->clone.level * (float) op_lvl) / ((float) skill->level * 100.0); 567 lvl_mult = ((float) skill->arch->clone.level * (float) op_lvl) / ((float) skill->level * 100.0);
571 else 568 else
572 lvl_mult = 1.0; 569 lvl_mult = 1.0;
573 } 570 }
574 } else { 571 } else {
575 /* Don't divide by zero here! */ 572 /* Don't divide by zero here! */
576 lvl_mult = (float) op_lvl / (float) (skill->level?skill->level:1); 573 lvl_mult = (float) op_lvl / (float) (skill->level?skill->level:1);
577 } 574 }
578 } 575 }
579 576
580 /* assemble the exp total, and return value */ 577 /* assemble the exp total, and return value */
581 578
582 value = base * lvl_mult; 579 value = base * lvl_mult;
583 if (value < 1) value=1; /* Always give at least 1 exp point */ 580 if (value < 1) value=1; /* Always give at least 1 exp point */
584 581
585#ifdef SKILL_UTIL_DEBUG 582#ifdef SKILL_UTIL_DEBUG
586 LOG(llevDebug,"calc_skill_exp(): who: %s(lvl:%d) op:%s(lvl:%d)\n", 583 LOG(llevDebug,"calc_skill_exp(): who: %s(lvl:%d) op:%s(lvl:%d)\n",
587 who->name,skill->level,op->name,op_lvl); 584 who->name,skill->level,op->name,op_lvl);
588#endif 585#endif
589 return ( (int) value); 586 return ( (int) value);
590} 587}
591 588
592/* Learn skill. This inserts the requested skill in the player's 589/* Learn skill. This inserts the requested skill in the player's
601int 598int
602learn_skill (object *pl, object *scroll) { 599learn_skill (object *pl, object *scroll) {
603 object *tmp; 600 object *tmp;
604 601
605 if (!scroll->skill) { 602 if (!scroll->skill) {
606 LOG(llevError,"skill scroll %s does not have skill pointer set.\n", scroll->name); 603 LOG(llevError,"skill scroll %s does not have skill pointer set.\n", &scroll->name);
607 return 2; 604 return 2;
608 } 605 }
609 606
610 /* can't use find_skill_by_name because we want skills the player knows 607 /* can't use find_skill_by_name because we want skills the player knows
611 * but can't use natively. 608 * but can't use natively.
612 */ 609 */
613 610
614 for (tmp=pl->inv; tmp!=NULL; tmp=tmp->below) 611 for (tmp=pl->inv; tmp!=NULL; tmp=tmp->below)
615 if (tmp->type == SKILL && !strncasecmp(scroll->skill, tmp->skill, strlen(scroll->skill))) break; 612 if (tmp->type == SKILL && !strncasecmp(scroll->skill, tmp->skill, strlen(scroll->skill))) break;
616 613
617 /* player already knows it */ 614 /* player already knows it */
618 if (tmp && QUERY_FLAG(tmp, FLAG_CAN_USE_SKILL)) return 0; 615 if (tmp && QUERY_FLAG(tmp, FLAG_CAN_USE_SKILL)) return 0;
619 616
620 617
622 /* now a random change to learn, based on player Int. 619 /* now a random change to learn, based on player Int.
623 * give bonus based on level - otherwise stupid characters 620 * give bonus based on level - otherwise stupid characters
624 * might never be able to learn anything. 621 * might never be able to learn anything.
625 */ 622 */
626 if(random_roll(0, 99, pl, PREFER_LOW)>(learn_spell[pl->stats.Int] + (pl->level/5))) 623 if(random_roll(0, 99, pl, PREFER_LOW)>(learn_spell[pl->stats.Int] + (pl->level/5)))
627 return 2; /* failure :< */ 624 return 2; /* failure :< */
628 625
629 if (!tmp) 626 if (!tmp)
630 tmp = give_skill_by_name(pl, scroll->skill); 627 tmp = give_skill_by_name(pl, scroll->skill);
631 628
632 if (!tmp) { 629 if (!tmp) {
633 LOG(llevError,"skill scroll %s does not have valid skill name (%s).\n", scroll->name, scroll->skill); 630 LOG(llevError,"skill scroll %s does not have valid skill name (%s).\n", &scroll->name, &scroll->skill);
634 return 2; 631 return 2;
635 } 632 }
636 633
637 SET_FLAG(tmp, FLAG_CAN_USE_SKILL); 634 SET_FLAG(tmp, FLAG_CAN_USE_SKILL);
638 link_player_skills(pl); 635 link_player_skills(pl);
639 return 1; 636 return 1;
678 /* Need to have a pointer and use strdup for qsort to work properly */ 675 /* Need to have a pointer and use strdup for qsort to work properly */
679 char skills[NUM_SKILLS][MAX_BUF]; 676 char skills[NUM_SKILLS][MAX_BUF];
680 677
681 678
682 for (tmp=op->inv; tmp!=NULL; tmp=tmp->below) { 679 for (tmp=op->inv; tmp!=NULL; tmp=tmp->below) {
683 if (tmp->type == SKILL) { 680 if (tmp->type == SKILL) {
684 if ( search && strstr(tmp->name,search)==NULL ) continue; 681 if ( search && strstr(tmp->name,search)==NULL ) continue;
685 /* Basically want to fill this out to 40 spaces with periods */ 682 /* Basically want to fill this out to 40 spaces with periods */
686 sprintf(buf,"%s%s", tmp->name, periods); 683 sprintf(buf,"%s%s", &tmp->name, periods);
687 buf[40] = 0; 684 buf[40] = 0;
688 685
689 if (settings.permanent_exp_ratio) { 686 if (settings.permanent_exp_ratio) {
690#ifdef WIN32
691 sprintf(skills[num_skills_found++],"%slvl:%3d (xp:%I64d/%I64d/%d%%)",
692 buf,tmp->level,
693 tmp->stats.exp,
694 level_exp(tmp->level+1, op->expmul),
695 clipped_percent(tmp->perm_exp,tmp->stats.exp));
696#else
697 sprintf(skills[num_skills_found++],"%slvl:%3d (xp:%lld/%lld/%d%%)", 687 sprintf(skills[num_skills_found++],"%slvl:%3d (xp:%lld/%lld/%d%%)",
698 buf,tmp->level, 688 buf,tmp->level,
699 tmp->stats.exp, 689 (long long)tmp->stats.exp,
700 level_exp(tmp->level+1, op->expmul), 690 (long long)level_exp(tmp->level+1, op->expmul),
701 clipped_percent(tmp->perm_exp,tmp->stats.exp)); 691 clipped_percent(tmp->perm_exp,tmp->stats.exp));
702#endif 692 } else {
703 } else {
704#ifdef WIN32
705 sprintf(skills[num_skills_found++], "%slvl:%3d (xp:%I64d/%I64d)",
706 buf,tmp->level,
707 tmp->stats.exp,
708 level_exp(tmp->level+1, op->expmul));
709#else
710 sprintf(skills[num_skills_found++], "%slvl:%3d (xp:%lld/%lld)", 693 sprintf(skills[num_skills_found++], "%slvl:%3d (xp:%lld/%lld)",
711 buf,tmp->level, 694 buf,tmp->level,
712 tmp->stats.exp, 695 (long long)tmp->stats.exp,
713 level_exp(tmp->level+1, op->expmul)); 696 (long long)level_exp(tmp->level+1, op->expmul));
714#endif 697 }
715 }
716 /* I don't know why some characters get a bunch of skills, but 698 /* I don't know why some characters get a bunch of skills, but
717 * it sometimes happens (maybe a leftover from bugier earlier code 699 * it sometimes happens (maybe a leftover from bugier earlier code
718 * and those character are still about). In any case, lets handle 700 * and those character are still about). In any case, lets handle
719 * it so it doesn't crash the server - otherwise, one character may 701 * it so it doesn't crash the server - otherwise, one character may
720 * crash the server numerous times. 702 * crash the server numerous times.
721 */ 703 */
722 if (num_skills_found >= NUM_SKILLS) { 704 if (num_skills_found >= NUM_SKILLS) {
723 new_draw_info(NDI_RED, 0, op, "Your character has too many skills."); 705 new_draw_info(NDI_RED, 0, op, "Your character has too many skills.");
724 new_draw_info(NDI_RED, 0, op, "Something isn't right - contact the server admin"); 706 new_draw_info(NDI_RED, 0, op, "Something isn't right - contact the server admin");
725 break; 707 break;
726 } 708 }
727 } 709 }
728 } 710 }
729 711
730 clear_win_info(op); 712 clear_win_info(op);
731 new_draw_info(NDI_UNIQUE, 0,op,"Player skills:"); 713 new_draw_info(NDI_UNIQUE, 0,op,"Player skills:");
732 if (num_skills_found > 1) qsort(skills, num_skills_found, MAX_BUF, (int (*)(const void*, const void*))strcmp); 714 if (num_skills_found > 1) qsort(skills, num_skills_found, MAX_BUF, (int (*)(const void*, const void*))strcmp);
733 715
734 for (i=0; i<num_skills_found; i++) { 716 for (i=0; i<num_skills_found; i++) {
735 new_draw_info(NDI_UNIQUE, 0, op, skills[i]); 717 new_draw_info(NDI_UNIQUE, 0, op, skills[i]);
736 } 718 }
737 719
738 new_draw_info_format(NDI_UNIQUE, 0, op, 720 new_draw_info_format(NDI_UNIQUE, 0, op,
739 "You can handle %d weapon improvements.",op->level/5+5); 721 "You can handle %d weapon improvements.",op->level/5+5);
740 722
741 cp = determine_god(op); 723 cp = determine_god(op);
742 new_draw_info_format(NDI_UNIQUE, 0, op, 724 new_draw_info_format(NDI_UNIQUE, 0, op,
743 "You worship %s.", cp?cp:"no god at current time"); 725 "You worship %s.", cp?cp:"no god at current time");
744 726
745 new_draw_info_format(NDI_UNIQUE,0,op, "Your equipped item power is %d out of %d\n", 727 new_draw_info_format(NDI_UNIQUE,0,op, "Your equipped item power is %d out of %d\n",
746 op->contr->item_power, (int) (op->level * settings.item_power_factor)); 728 op->contr->item_power, (int) (op->level * settings.item_power_factor));
747} 729}
748 730
749/* use_skill() - similar to invoke command, it executes the skill in the 731/* use_skill() - similar to invoke command, it executes the skill in the
750 * direction that the user is facing. Returns false if we are unable to 732 * direction that the user is facing. Returns false if we are unable to
751 * change to the requested skill, or were unable to use the skill properly. 733 * change to the requested skill, or were unable to use the skill properly.
758 size_t len; 740 size_t len;
759 741
760 if (!string) return 0; 742 if (!string) return 0;
761 743
762 for (skop = op->inv; skop != NULL; skop=skop->below) { 744 for (skop = op->inv; skop != NULL; skop=skop->below) {
763 if (skop->type == SKILL && QUERY_FLAG(skop, FLAG_CAN_USE_SKILL) && 745 if (skop->type == SKILL && QUERY_FLAG(skop, FLAG_CAN_USE_SKILL) &&
764 !strncasecmp(string, skop->skill, MIN(strlen(string), strlen(skop->skill)))) 746 !strncasecmp(string, skop->skill, MIN(strlen(string), strlen(skop->skill))))
765 break; 747 break;
766 else if (skop->type == SKILL_TOOL && 748 else if (skop->type == SKILL_TOOL &&
767 !strncasecmp(string, skop->skill, MIN(strlen(string), strlen(skop->skill)))) 749 !strncasecmp(string, skop->skill, MIN(strlen(string), strlen(skop->skill))))
768 break; 750 break;
769 } 751 }
770 if (!skop) { 752 if (!skop) {
771 new_draw_info_format(NDI_UNIQUE, 0, op, 753 new_draw_info_format(NDI_UNIQUE, 0, op,
772 "Unable to find skill %s", string); 754 "Unable to find skill %s", string);
773 return 0; 755 return 0;
774 } 756 }
775 757
776 len=strlen(skop->skill); 758 len=strlen(skop->skill);
777 759
778 /* All this logic goes and skips over the skill name to find any 760 /* All this logic goes and skips over the skill name to find any
779 * options given to the skill. Its pretty simple - if there 761 * options given to the skill. Its pretty simple - if there
780 * are extra parameters (as deteremined by string length), we 762 * are extra parameters (as deteremined by string length), we
781 * want to skip over any leading spaces. 763 * want to skip over any leading spaces.
782 */ 764 */
783 if(len>=strlen(string)) { 765 if(len>=strlen(string)) {
784 string=NULL; 766 string=NULL;
785 } else { 767 } else {
786 string += len; 768 string += len;
787 while(*string==0x20) string++; 769 while(*string==0x20) string++;
788 if(strlen(string)==0) string = NULL; 770 if(strlen(string)==0) string = NULL;
789 } 771 }
790 772
791#ifdef SKILL_UTIL_DEBUG 773#ifdef SKILL_UTIL_DEBUG
792 LOG(llevDebug,"use_skill() got skill: %s\n",sknum>-1?skills[sknum].name:"none"); 774 LOG(llevDebug,"use_skill() got skill: %s\n",sknum>-1?skills[sknum].name:"none");
793#endif 775#endif
818{ 800{
819 object *tmp, *best_skill=NULL; 801 object *tmp, *best_skill=NULL;
820 int dragon = is_dragon_pl(op), last_skill=sizeof(unarmed_skills), i; 802 int dragon = is_dragon_pl(op), last_skill=sizeof(unarmed_skills), i;
821 803
822 for (tmp=op->inv; tmp; tmp=tmp->below) { 804 for (tmp=op->inv; tmp; tmp=tmp->below) {
823 if (tmp->type == SKILL) { 805 if (tmp->type == SKILL) {
824 if (dragon && tmp->subtype == SK_CLAWING) return tmp; 806 if (dragon && tmp->subtype == SK_CLAWING) return tmp;
825 807
826 /* The order in the array is preferred order. So basically, 808 /* The order in the array is preferred order. So basically,
827 * we just cut down the number to search - eg, if we find a skill 809 * we just cut down the number to search - eg, if we find a skill
828 * early on in flame touch, then we only need to look into the unarmed_array 810 * early on in flame touch, then we only need to look into the unarmed_array
829 * to the entry before flame touch - don't care about the entries afterward, 811 * to the entry before flame touch - don't care about the entries afterward,
830 * because they are infrerior skills. 812 * because they are infrerior skills.
831 * if we end up finding the best skill (i==0) might as well return 813 * if we end up finding the best skill (i==0) might as well return
832 * right away - can't get any better than that. 814 * right away - can't get any better than that.
833 */ 815 */
834 for (i=0; i<last_skill; i++) { 816 for (i=0; i<last_skill; i++) {
835 if (tmp->subtype == unarmed_skills[i] && QUERY_FLAG(tmp, FLAG_CAN_USE_SKILL)) { 817 if (tmp->subtype == unarmed_skills[i] && QUERY_FLAG(tmp, FLAG_CAN_USE_SKILL)) {
836 best_skill = tmp; 818 best_skill = tmp;
837 last_skill = i; 819 last_skill = i;
838 if (i==0) return best_skill; 820 if (i==0) return best_skill;
839 } 821 }
840 } 822 }
841 } 823 }
842 } 824 }
843 return best_skill; 825 return best_skill;
844} 826}
845 827
846/* do_skill_attack() - We have got an appropriate opponent from either 828/* do_skill_attack() - We have got an appropriate opponent from either
854 */ 836 */
855 837
856static int do_skill_attack(object *tmp, object *op, const char *string, object *skill) { 838static int do_skill_attack(object *tmp, object *op, const char *string, object *skill) {
857 int success; 839 int success;
858 840
841 if (INVOKE_OBJECT (SKILL_ATTACK, op, ARG_OBJECT (tmp), ARG_STRING (string), ARG_OBJECT (skill)))
842 return RESULT_INT (0);
843
859 /* For Players only: if there is no ready weapon, and no "attack" skill 844 /* For Players only: if there is no ready weapon, and no "attack" skill
860 * is readied either then try to find a skill for the player to use. 845 * is readied either then try to find a skill for the player to use.
861 * it is presumed that if skill is set, it is a valid attack skill (eg, 846 * it is presumed that if skill is set, it is a valid attack skill (eg,
862 * the caller should have set it appropriately). We still want to pass 847 * the caller should have set it appropriately). We still want to pass
863 * through that code if skill is set to change to the skill. 848 * through that code if skill is set to change to the skill.
864 */ 849 */
865 if(op->type==PLAYER) { 850 if(op->type==PLAYER) {
866 if (!QUERY_FLAG(op,FLAG_READY_WEAPON)) { 851 if (!QUERY_FLAG(op,FLAG_READY_WEAPON)) {
867 size_t i; 852 size_t i;
868 853
869 if (!skill) { 854 if (!skill) {
870 /* See if the players chosen skill is a combat skill, and use 855 /* See if the players chosen skill is a combat skill, and use
871 * it if appropriate. 856 * it if appropriate.
872 */ 857 */
873 if (op->chosen_skill) { 858 if (op->chosen_skill) {
874 for (i=0; i<sizeof(unarmed_skills); i++) 859 for (i=0; i<sizeof(unarmed_skills); i++)
875 if (op->chosen_skill->subtype == unarmed_skills[i]) { 860 if (op->chosen_skill->subtype == unarmed_skills[i]) {
876 skill = op->chosen_skill; 861 skill = op->chosen_skill;
877 break; 862 break;
878 } 863 }
879 } 864 }
880 /* If we didn't find a skill above, look harder for a good skill */ 865 /* If we didn't find a skill above, look harder for a good skill */
881 if (!skill) { 866 if (!skill) {
882 skill = find_best_player_hth_skill(op); 867 skill = find_best_player_hth_skill(op);
883 868
884 if (!skill) { 869 if (!skill) {
885 new_draw_info(NDI_BLACK, 0, op, "You have no unarmed combat skills!"); 870 new_draw_info(NDI_BLACK, 0, op, "You have no unarmed combat skills!");
886 return 0; 871 return 0;
887 } 872 }
888 } 873 }
889 } 874 }
890 if (skill != op->chosen_skill) { 875 if (skill != op->chosen_skill) {
891 /* now try to ready the new skill */ 876 /* now try to ready the new skill */
892 if(!change_skill(op,skill,0)) { /* oh oh, trouble! */ 877 if(!change_skill(op,skill,0)) { /* oh oh, trouble! */
893 new_draw_info_format(NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", skill->name); 878 new_draw_info_format(NDI_UNIQUE, 0, tmp, "Couldn't change to skill %s", &skill->name);
894 return 0; 879 return 0;
895 } 880 }
896 } 881 }
897 } else { 882 } else {
898 /* Seen some crashes below where current_weapon is not set, 883 /* Seen some crashes below where current_weapon is not set,
899 * even though the flag says it is. So if current weapon isn't set, 884 * even though the flag says it is. So if current weapon isn't set,
900 * do some work in trying to find the object to use. 885 * do some work in trying to find the object to use.
901 */ 886 */
902 if (!op->current_weapon) { 887 if (!op->current_weapon) {
903 object *tmp; 888 object *tmp;
904 889
905 LOG(llevError,"Player %s does not have current weapon set but flag_ready_weapon is set\n", 890 LOG(llevError,"Player %s does not have current weapon set but flag_ready_weapon is set\n",
906 op->name); 891 &op->name);
907 for (tmp=op->inv; tmp; tmp=tmp->below) 892 for (tmp=op->inv; tmp; tmp=tmp->below)
908 if (tmp->type == WEAPON && QUERY_FLAG(tmp, FLAG_APPLIED)) break; 893 if (tmp->type == WEAPON && QUERY_FLAG(tmp, FLAG_APPLIED)) break;
909 894
910 if (op->current_weapon_script) 895 if (!tmp) {
911 FREE_AND_CLEAR_STR(op->current_weapon_script);
912 if (!tmp) {
913 LOG(llevError,"Could not find applied weapon on %s\n", 896 LOG(llevError,"Could not find applied weapon on %s\n",
914 op->name); 897 &op->name);
915 op->current_weapon=NULL; 898 op->current_weapon=NULL;
916 return 0; 899 return 0;
917 } else { 900 } else {
918 op->current_weapon = tmp; 901 op->current_weapon = tmp;
919 op->current_weapon_script=add_string(query_name(tmp)); 902 }
920 } 903 }
921 }
922 904
923 /* Has ready weapon - make sure chosen_skill is set up properly */ 905 /* Has ready weapon - make sure chosen_skill is set up properly */
924 if (!op->chosen_skill || op->current_weapon->skill != op->chosen_skill->skill) { 906 if (!op->chosen_skill || op->current_weapon->skill != op->chosen_skill->skill) {
925 change_skill(op, find_skill_by_name(op, op->current_weapon->skill), 1); 907 change_skill(op, find_skill_by_name(op, op->current_weapon->skill), 1);
926 } 908 }
927 } 909 }
928 } 910 }
929 911
930 /* lose invisiblity/hiding status for running attacks */ 912 /* lose invisiblity/hiding status for running attacks */
931 913
932 if(op->type==PLAYER && op->contr->tmp_invis) { 914 if(op->type==PLAYER && op->contr->tmp_invis) {
933 op->contr->tmp_invis=0; 915 op->contr->tmp_invis=0;
934 op->invisible=0; 916 op->invisible=0;
935 op->hide=0; 917 op->hide=0;
936 update_object(op,UP_OBJ_FACE); 918 update_object(op,UP_OBJ_FACE);
937 } 919 }
938 920
939 success = attack_ob(tmp,op); 921 success = attack_ob(tmp,op);
940 922
941 /* print appropriate messages to the player */ 923 /* print appropriate messages to the player */
942 924
943 if(success && string!=NULL && tmp && !QUERY_FLAG(tmp,FLAG_FREED)) { 925 if(success && string!=NULL && tmp && !QUERY_FLAG(tmp,FLAG_FREED)) {
944 if(op->type==PLAYER) 926 if(op->type==PLAYER)
945 new_draw_info_format(NDI_UNIQUE, 0,op, 927 new_draw_info_format(NDI_UNIQUE, 0,op,
946 "You %s %s!",string,query_name(tmp)); 928 "You %s %s!",string,query_name(tmp));
947 else if(tmp->type==PLAYER) 929 else if(tmp->type==PLAYER)
948 new_draw_info_format(NDI_UNIQUE, 0,tmp, 930 new_draw_info_format(NDI_UNIQUE, 0,tmp,
949 "%s %s you!",query_name(op),string); 931 "%s %s you!",query_name(op),string);
950 } 932 }
951 return success; 933 return success;
952} 934}
953 935
954 936
976 /* If we don't yet have an opponent, find if one exists, and attack. 958 /* If we don't yet have an opponent, find if one exists, and attack.
977 * Legal opponents are the same as outlined in move_player_attack() 959 * Legal opponents are the same as outlined in move_player_attack()
978 */ 960 */
979 961
980 if(tmp==NULL) { 962 if(tmp==NULL) {
981 m = pl->map; 963 m = pl->map;
982 tx = pl->x + freearr_x[dir]; 964 tx = pl->x + freearr_x[dir];
983 ty = pl->y + freearr_y[dir]; 965 ty = pl->y + freearr_y[dir];
984 966
985 mflags = get_map_flags(m, &m, tx, ty, &tx, &ty); 967 mflags = get_map_flags(m, &m, tx, ty, &tx, &ty);
986 if (mflags & P_OUT_OF_MAP) return 0; 968 if (mflags & P_OUT_OF_MAP) return 0;
987 969
988 /* space must be blocked for there to be anything interesting to do */ 970 /* space must be blocked for there to be anything interesting to do */
989 if (!OB_TYPE_MOVE_BLOCK(pl, GET_MAP_MOVE_BLOCK(m, tx,ty))) return 0; 971 if (!OB_TYPE_MOVE_BLOCK(pl, GET_MAP_MOVE_BLOCK(m, tx,ty))) return 0;
990 972
991 for(tmp=get_map_ob(m, tx, ty); tmp; tmp=tmp->above) 973 for(tmp=get_map_ob(m, tx, ty); tmp; tmp=tmp->above)
992 if((QUERY_FLAG(tmp,FLAG_ALIVE) && tmp->stats.hp>=0) 974 if((QUERY_FLAG(tmp,FLAG_ALIVE) && tmp->stats.hp>=0)
993 || QUERY_FLAG(tmp, FLAG_CAN_ROLL) 975 || QUERY_FLAG(tmp, FLAG_CAN_ROLL)
994 || tmp->type==LOCKED_DOOR ) { 976 || tmp->type==LOCKED_DOOR ) {
995 /* Don't attack party members */ 977 /* Don't attack party members */
996 if((pl->type==PLAYER && tmp->type==PLAYER) && (pl->contr->party!=NULL 978 if((pl->type==PLAYER && tmp->type==PLAYER) && (pl->contr->party!=NULL
997 && pl->contr->party==tmp->contr->party)) 979 && pl->contr->party==tmp->contr->party))
998 return 0; 980 return 0;
999 break; 981 break;
1000 } 982 }
1001 } 983 }
1002 if (!tmp) { 984 if (!tmp) {
1003 if(pl->type==PLAYER) 985 if(pl->type==PLAYER)
1004 new_draw_info(NDI_UNIQUE, 0,pl,"There is nothing to attack!"); 986 new_draw_info(NDI_UNIQUE, 0,pl,"There is nothing to attack!");
1005 return 0; 987 return 0;
1006 } 988 }
1007 989
1008 return do_skill_attack(tmp,pl,string, skill); 990 return do_skill_attack(tmp,pl,string, skill);
1009} 991}
1010 992
1017 999
1018static int attack_hth(object *pl, int dir, const char *string, object *skill) { 1000static int attack_hth(object *pl, int dir, const char *string, object *skill) {
1019 object *enemy=NULL,*weapon; 1001 object *enemy=NULL,*weapon;
1020 1002
1021 if(QUERY_FLAG(pl, FLAG_READY_WEAPON)) 1003 if(QUERY_FLAG(pl, FLAG_READY_WEAPON))
1022 for(weapon=pl->inv;weapon;weapon=weapon->below) { 1004 for(weapon=pl->inv;weapon;weapon=weapon->below) {
1023 if (weapon->type==WEAPON && QUERY_FLAG(weapon, FLAG_APPLIED)) { 1005 if (weapon->type==WEAPON && QUERY_FLAG(weapon, FLAG_APPLIED)) {
1024 CLEAR_FLAG(weapon,FLAG_APPLIED); 1006 CLEAR_FLAG(weapon,FLAG_APPLIED);
1025 CLEAR_FLAG(pl,FLAG_READY_WEAPON); 1007 CLEAR_FLAG(pl,FLAG_READY_WEAPON);
1026 fix_player(pl); 1008 fix_player(pl);
1027 if(pl->type==PLAYER) { 1009 if(pl->type==PLAYER) {
1028 new_draw_info(NDI_UNIQUE, 0,pl,"You unwield your weapon in order to attack."); 1010 new_draw_info(NDI_UNIQUE, 0,pl,"You unwield your weapon in order to attack.");
1029 esrv_update_item(UPD_FLAGS, pl, weapon); 1011 esrv_update_item(UPD_FLAGS, pl, weapon);
1030 } 1012 }
1031 break; 1013 break;
1032 } 1014 }
1033 } 1015 }
1034 return skill_attack(enemy,pl,dir,string, skill); 1016 return skill_attack(enemy,pl,dir,string, skill);
1035} 1017}
1036 1018
1037 1019
1038/* attack_melee_weapon() - this handles melee weapon attacks -b.t. 1020/* attack_melee_weapon() - this handles melee weapon attacks -b.t.
1046 */ 1028 */
1047 1029
1048static int attack_melee_weapon(object *op, int dir, const char *string, object *skill) { 1030static int attack_melee_weapon(object *op, int dir, const char *string, object *skill) {
1049 1031
1050 if(!QUERY_FLAG(op, FLAG_READY_WEAPON)) { 1032 if(!QUERY_FLAG(op, FLAG_READY_WEAPON)) {
1051 if(op->type==PLAYER) 1033 if(op->type==PLAYER)
1052 new_draw_info(NDI_UNIQUE, 0,op,"You have no ready weapon to attack with!"); 1034 new_draw_info(NDI_UNIQUE, 0,op,"You have no ready weapon to attack with!");
1053 return 0; 1035 return 0;
1054 } 1036 }
1055 return skill_attack(NULL,op,dir,string, skill); 1037 return skill_attack(NULL,op,dir,string, skill);
1056 1038
1057} 1039}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines