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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines