| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#define _GNU_SOURCE |
| 16 |
|
| 17 |
#include "global.h" |
| 18 |
|
| 19 |
#include <stdlib.h> |
| 20 |
#include <string.h> |
| 21 |
|
| 22 |
#include "book.h" |
| 23 |
#include "living.h" |
| 24 |
#include "object.h" |
| 25 |
#include "skills.h" |
| 26 |
#include "spells.h" |
| 27 |
#include "sproto.h" |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
static int adj_stealchance(object *op, object *victim, int roll) { |
| 44 |
if (!op || !victim || !roll) |
| 45 |
return -1; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
if (op->type == PLAYER |
| 51 |
&& op->body_used[BODY_ARMS] <= 0 |
| 52 |
&& op->body_info[BODY_ARMS]) { |
| 53 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 54 |
"But you have no free hands to steal with!"); |
| 55 |
return -1; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
if (!QUERY_FLAG(victim, FLAG_UNAGGRESSIVE)) |
| 62 |
roll = roll/2; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
if (QUERY_FLAG(victim, FLAG_SLEEP)) |
| 67 |
roll = roll*3; |
| 68 |
else if (op->invisible) |
| 69 |
roll = roll*2; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
FOR_INV_PREPARE(op, equip) { |
| 75 |
if (equip->type == WEAPON && QUERY_FLAG(equip, FLAG_APPLIED)) { |
| 76 |
roll -= equip->weight/10000; |
| 77 |
} |
| 78 |
if (equip->type == BOW && QUERY_FLAG(equip, FLAG_APPLIED)) |
| 79 |
roll -= equip->weight/5000; |
| 80 |
if (equip->type == SHIELD && QUERY_FLAG(equip, FLAG_APPLIED)) { |
| 81 |
roll -= equip->weight/2000; |
| 82 |
} |
| 83 |
if (equip->type == ARMOUR && QUERY_FLAG(equip, FLAG_APPLIED)) |
| 84 |
roll -= equip->weight/5000; |
| 85 |
if (equip->type == GLOVES && QUERY_FLAG(equip, FLAG_APPLIED)) |
| 86 |
roll -= equip->weight/100; |
| 87 |
} FOR_INV_FINISH(); |
| 88 |
if (roll < 0) |
| 89 |
roll = 0; |
| 90 |
return roll; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
static int attempt_steal(object *op, object *who, object *skill) { |
| 112 |
object *success = NULL, *tmp = NULL; |
| 113 |
int roll = 0, chance = 0, stats_value; |
| 114 |
rv_vector rv; |
| 115 |
char name[MAX_BUF]; |
| 116 |
|
| 117 |
stats_value = ((who->stats.Dex+who->stats.Int)*3)/2; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
if (op->type != PLAYER && QUERY_FLAG(op, FLAG_NO_STEAL)) { |
| 124 |
if (monster_can_detect_enemy(op, who, &rv)) { |
| 125 |
monster_npc_call_help(op); |
| 126 |
CLEAR_FLAG(op, FLAG_UNAGGRESSIVE); |
| 127 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 128 |
"Your attempt is prevented!"); |
| 129 |
return 0; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
op->stats.Wis += (op->stats.Int/5)+1; |
| 138 |
if (op->stats.Wis > settings.max_stat) |
| 139 |
op->stats.Wis = settings.max_stat; |
| 140 |
} |
| 141 |
if (op->type == PLAYER && QUERY_FLAG(op, FLAG_WIZ)) { |
| 142 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 143 |
"You can't steal from the dungeon master!"); |
| 144 |
return 0; |
| 145 |
} |
| 146 |
if (op->type == PLAYER && who->type == PLAYER && settings.no_player_stealing) { |
| 147 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 148 |
"You can't steal from other players!"); |
| 149 |
return 0; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
FOR_INV_PREPARE(op, inv) { |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
if (QUERY_FLAG(inv, FLAG_WAS_WIZ) |
| 166 |
|| QUERY_FLAG(inv, FLAG_APPLIED) |
| 167 |
|| !(inv->type) |
| 168 |
|| inv->type == SPELL |
| 169 |
|| QUERY_FLAG(inv, FLAG_STARTEQUIP) |
| 170 |
|| QUERY_FLAG(inv, FLAG_NO_STEAL) |
| 171 |
|| inv->invisible) |
| 172 |
continue; |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
roll = die_roll(2, 100, who, PREFER_LOW)/2; |
| 179 |
|
| 180 |
chance = adj_stealchance(who, op, stats_value+skill->level*10-op->level*3); |
| 181 |
if (chance == -1) |
| 182 |
return 0; |
| 183 |
if (roll < chance) { |
| 184 |
tag_t inv_count = inv->count; |
| 185 |
|
| 186 |
pick_up(who, inv); |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
if (object_was_destroyed(inv, inv_count) || inv->env != op) { |
| 193 |
|
| 194 |
success = inv; |
| 195 |
CLEAR_FLAG(inv, FLAG_INV_LOCKED); |
| 196 |
} |
| 197 |
tmp = inv; |
| 198 |
break; |
| 199 |
} |
| 200 |
} FOR_INV_FINISH(); |
| 201 |
|
| 202 |
if (!tmp) { |
| 203 |
query_name(op, name, MAX_BUF); |
| 204 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 205 |
"%s%s has nothing you can steal!", |
| 206 |
op->type == PLAYER ? "" : "The ", name); |
| 207 |
return 0; |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
if (roll >= skill->level |
| 216 |
|| !chance |
| 217 |
|| (tmp && tmp->weight > 250*random_roll(0, stats_value+skill->level*10-1, who, PREFER_LOW))) { |
| 218 |
|
| 219 |
if (who->hide) |
| 220 |
make_visible(who); |
| 221 |
|
| 222 |
if (op->type != PLAYER) { |
| 223 |
|
| 224 |
if (who->type == PLAYER) { |
| 225 |
monster_npc_call_help(op); |
| 226 |
query_name(op, name, MAX_BUF); |
| 227 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 228 |
"%s notices your attempted pilfering!", |
| 229 |
name); |
| 230 |
} |
| 231 |
CLEAR_FLAG(op, FLAG_UNAGGRESSIVE); |
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
SET_FLAG(op, FLAG_NO_STEAL); |
| 236 |
} else { |
| 237 |
char buf[MAX_BUF]; |
| 238 |
|
| 239 |
|
| 240 |
if (success && who->stats.Int > random_roll(0, 19, op, PREFER_LOW)) { |
| 241 |
query_name(success, name, MAX_BUF); |
| 242 |
snprintf(buf, sizeof(buf), "Your %s is missing!", name); |
| 243 |
} else { |
| 244 |
snprintf(buf, sizeof(buf), "Your pack feels strangely lighter."); |
| 245 |
} |
| 246 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ITEM, MSG_TYPE_ITEM_REMOVE, |
| 247 |
buf); |
| 248 |
if (!success) { |
| 249 |
if (who->invisible) { |
| 250 |
snprintf(buf, sizeof(buf), "you feel itchy fingers getting at your pack."); |
| 251 |
} else { |
| 252 |
query_name(who, name, MAX_BUF); |
| 253 |
snprintf(buf, sizeof(buf), "%s looks very shifty.", name); |
| 254 |
} |
| 255 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_STEAL, |
| 256 |
buf); |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
} |
| 261 |
return success ? 1 : 0; |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
int steal(object *op, int dir, object *skill) { |
| 278 |
object *tmp; |
| 279 |
int16_t x, y; |
| 280 |
mapstruct *m; |
| 281 |
int mflags; |
| 282 |
|
| 283 |
x = op->x+freearr_x[dir]; |
| 284 |
y = op->y+freearr_y[dir]; |
| 285 |
|
| 286 |
if (dir == 0) { |
| 287 |
|
| 288 |
return 0; |
| 289 |
} |
| 290 |
|
| 291 |
m = op->map; |
| 292 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
if ((mflags&P_OUT_OF_MAP) || !(mflags&P_IS_ALIVE)) |
| 297 |
return 0; |
| 298 |
|
| 299 |
|
| 300 |
if (OB_TYPE_MOVE_BLOCK(op, GET_MAP_MOVE_BLOCK(m, x, y))) |
| 301 |
return 0; |
| 302 |
|
| 303 |
|
| 304 |
tmp = GET_MAP_OB(m, x, y); |
| 305 |
FOR_OB_AND_ABOVE_PREPARE(tmp) |
| 306 |
if (tmp->above == NULL) |
| 307 |
break; |
| 308 |
FOR_OB_AND_ABOVE_FINISH(); |
| 309 |
|
| 310 |
|
| 311 |
FOR_OB_AND_BELOW_PREPARE(tmp) { |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
tmp = HEAD(tmp); |
| 316 |
if (tmp->type != PLAYER && !QUERY_FLAG(tmp, FLAG_MONSTER)) |
| 317 |
continue; |
| 318 |
|
| 319 |
|
| 320 |
if (tmp->type == PLAYER && QUERY_FLAG(tmp, FLAG_WIZ) && tmp->contr->hidden) |
| 321 |
continue; |
| 322 |
if (attempt_steal(tmp, op, skill)) { |
| 323 |
if (tmp->type == PLAYER) |
| 324 |
return 0; |
| 325 |
|
| 326 |
|
| 327 |
if (QUERY_FLAG(tmp, FLAG_FRIENDLY) && tmp->attack_movement == PETMOVE) { |
| 328 |
object *owner = object_get_owner(tmp); |
| 329 |
if (owner != NULL && owner->type == PLAYER) |
| 330 |
return 0; |
| 331 |
} |
| 332 |
|
| 333 |
return (calc_skill_exp(op, tmp, skill)); |
| 334 |
} |
| 335 |
} FOR_OB_AND_BELOW_FINISH(); |
| 336 |
return 0; |
| 337 |
} |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
static int attempt_pick_lock(object *door, object *pl, object *skill) { |
| 354 |
int difficulty = pl->map->difficulty ? pl->map->difficulty : 0; |
| 355 |
int success = 0, number; |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
number = (die_roll(2, 40, pl, PREFER_LOW)-2)/2; |
| 362 |
|
| 363 |
if (door->inv && (door->inv->type == RUNE || door->inv->type == TRAP)) { |
| 364 |
spring_trap(door->inv, pl); |
| 365 |
} |
| 366 |
if (number < pl->stats.Dex + skill->level*2 - difficulty ) { |
| 367 |
remove_door(door); |
| 368 |
success = difficulty; |
| 369 |
} |
| 370 |
return success; |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
int pick_lock(object *pl, int dir, object *skill) { |
| 390 |
object *tmp; |
| 391 |
int x = pl->x+freearr_x[dir]; |
| 392 |
int y = pl->y+freearr_y[dir]; |
| 393 |
int difficulty=0; |
| 394 |
|
| 395 |
if (!dir) |
| 396 |
dir = pl->facing; |
| 397 |
|
| 398 |
|
| 399 |
if (OUT_OF_REAL_MAP(pl->map, x, y)) { |
| 400 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 401 |
"There is no lock there."); |
| 402 |
return 0; |
| 403 |
} |
| 404 |
|
| 405 |
for (tmp = GET_MAP_OB(pl->map, x, y); tmp; tmp = tmp->above) |
| 406 |
if (tmp->type == DOOR || tmp->type == LOCKED_DOOR) |
| 407 |
break; |
| 408 |
|
| 409 |
if (!tmp) { |
| 410 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 411 |
"There is no lock there."); |
| 412 |
return 0; |
| 413 |
} |
| 414 |
|
| 415 |
if (execute_event(tmp, EVENT_TRIGGER, pl, skill, NULL, SCRIPT_FIX_ALL) != 0) |
| 416 |
return 0; |
| 417 |
|
| 418 |
if (tmp->type == LOCKED_DOOR) { |
| 419 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 420 |
"You can't pick that lock!"); |
| 421 |
return 0; |
| 422 |
} |
| 423 |
|
| 424 |
if (!tmp->move_block) { |
| 425 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 426 |
"The door has no lock!"); |
| 427 |
return 0; |
| 428 |
} |
| 429 |
|
| 430 |
difficulty = attempt_pick_lock(tmp, pl, skill); |
| 431 |
|
| 432 |
if (!difficulty) { |
| 433 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 434 |
"You fail to pick the lock."); |
| 435 |
return 0; |
| 436 |
} |
| 437 |
|
| 438 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 439 |
"You pick the lock."); |
| 440 |
return (calc_skill_exp(pl, NULL, skill) * isqrt(difficulty)); |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
static int attempt_hide(object *op, object *skill) { |
| 464 |
int number, difficulty = op->map->difficulty; |
| 465 |
int terrain = hideability(op); |
| 466 |
|
| 467 |
if (terrain < -10) |
| 468 |
return 0; |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
number = (die_roll(2, 25, op, PREFER_LOW)-2)/2; |
| 475 |
if (!stand_near_hostile(op) && number < op->stats.Dex+skill->level+terrain-difficulty) { |
| 476 |
op->invisible += 100; |
| 477 |
if (op->type == PLAYER) |
| 478 |
op->contr->tmp_invis = 1; |
| 479 |
op->hide = 1; |
| 480 |
return 1; |
| 481 |
} |
| 482 |
return 0; |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
int hide(object *op, object *skill) { |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
if (QUERY_FLAG(op, FLAG_MAKE_INVIS)) { |
| 499 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 500 |
"You don't need to hide while invisible!"); |
| 501 |
return 0; |
| 502 |
} |
| 503 |
|
| 504 |
if (!op->hide && op->invisible > 0 && op->type == PLAYER) { |
| 505 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_ATTRIBUTE, MSG_TYPE_ATTRIBUTE_GOOD_EFFECT_END, |
| 506 |
"Your attempt to hide breaks the invisibility spell!"); |
| 507 |
make_visible(op); |
| 508 |
} |
| 509 |
|
| 510 |
if (op->invisible > 50*skill->level) { |
| 511 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 512 |
"You are as hidden as you can get."); |
| 513 |
return 0; |
| 514 |
} |
| 515 |
|
| 516 |
if (attempt_hide(op, skill)) { |
| 517 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 518 |
"You hide in the shadows."); |
| 519 |
object_update(op, UP_OBJ_FACE); |
| 520 |
return calc_skill_exp(op, NULL, skill); |
| 521 |
} |
| 522 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 523 |
"You fail to conceal yourself."); |
| 524 |
return 0; |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
static void stop_jump(object *pl) { |
| 535 |
fix_object(pl); |
| 536 |
object_insert_in_map_at(pl, pl->map, pl, 0, pl->x, pl->y); |
| 537 |
|
| 538 |
if (pl->contr) |
| 539 |
check_pick(pl); |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
static int attempt_jump(object *pl, int dir, int spaces, object *skill) { |
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
if (pl->contr && pl->contr->transport){ |
| 561 |
char trans_name[MAX_BUF]; |
| 562 |
query_name(pl->contr->transport, trans_name, MAX_BUF); |
| 563 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 564 |
"Your bounce off the walls of %s.", trans_name); |
| 565 |
|
| 566 |
return 0; |
| 567 |
} |
| 568 |
|
| 569 |
int i, dx = freearr_x[dir], dy = freearr_y[dir], mflags; |
| 570 |
int16_t x, y; |
| 571 |
mapstruct *m; |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
object_remove(pl); |
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
pl->move_type |= MOVE_FLY_LOW; |
| 588 |
|
| 589 |
for (i = 0; i <= spaces; i++) { |
| 590 |
x = pl->x+dx; |
| 591 |
y = pl->y+dy; |
| 592 |
m = pl->map; |
| 593 |
|
| 594 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 595 |
|
| 596 |
if (mflags&P_OUT_OF_MAP) { |
| 597 |
(void)stop_jump(pl); |
| 598 |
return 0; |
| 599 |
} |
| 600 |
if (OB_TYPE_MOVE_BLOCK(pl, GET_MAP_MOVE_BLOCK(m, x, y))) { |
| 601 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 602 |
"Your jump is blocked."); |
| 603 |
stop_jump(pl); |
| 604 |
return 0; |
| 605 |
} |
| 606 |
|
| 607 |
FOR_MAP_PREPARE(m, x, y, tmp) { |
| 608 |
tmp = HEAD(tmp); |
| 609 |
|
| 610 |
if (QUERY_FLAG(tmp, FLAG_MONSTER) |
| 611 |
|| (tmp->type == PLAYER && (!QUERY_FLAG(tmp, FLAG_WIZ) || !tmp->contr->hidden))) { |
| 612 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 613 |
"You jump into %s%s.", |
| 614 |
tmp->type == PLAYER ? "" : "the ", tmp->name); |
| 615 |
|
| 616 |
stop_jump(pl); |
| 617 |
if (tmp->type != PLAYER |
| 618 |
|| (pl->type == PLAYER && pl->contr->party == NULL) |
| 619 |
|| (pl->type == PLAYER && tmp->type == PLAYER && pl->contr->party != tmp->contr->party)) |
| 620 |
skill_attack(tmp, pl, pl->facing, "kicked", skill); |
| 621 |
|
| 622 |
return 1; |
| 623 |
} |
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
if (tmp->move_on&MOVE_FLY_LOW) { |
| 629 |
pl->x = x; |
| 630 |
pl->y = y; |
| 631 |
pl->map = m; |
| 632 |
if (pl->contr) |
| 633 |
esrv_map_scroll(&pl->contr->socket, dx, dy); |
| 634 |
stop_jump(pl); |
| 635 |
return 1; |
| 636 |
} |
| 637 |
} FOR_MAP_FINISH(); |
| 638 |
pl->x = x; |
| 639 |
pl->y = y; |
| 640 |
pl->map = m; |
| 641 |
if (pl->contr) |
| 642 |
esrv_map_scroll(&pl->contr->socket, dx, dy); |
| 643 |
} |
| 644 |
stop_jump(pl); |
| 645 |
return 1; |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
int jump(object *pl, int dir, object *skill) { |
| 665 |
int spaces = 0, stats; |
| 666 |
int str = pl->stats.Str; |
| 667 |
int dex = pl->stats.Dex; |
| 668 |
|
| 669 |
dex = dex ? dex : 15; |
| 670 |
str = str ? str : 10; |
| 671 |
|
| 672 |
stats = str*str*str*dex*skill->level; |
| 673 |
|
| 674 |
if (pl->carrying != 0) |
| 675 |
spaces = (int)(stats/pl->carrying); |
| 676 |
else |
| 677 |
spaces = 2; |
| 678 |
|
| 679 |
if (spaces > 2) |
| 680 |
spaces = 2; |
| 681 |
else if (spaces == 0) { |
| 682 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 683 |
"You are carrying too much weight to jump."); |
| 684 |
return 0; |
| 685 |
} |
| 686 |
return attempt_jump(pl, dir, spaces, skill); |
| 687 |
} |
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
int detect_curse_on_item(object *pl, object *tmp, object *skill) { |
| 702 |
if (!QUERY_FLAG(tmp, FLAG_IDENTIFIED) && !QUERY_FLAG(tmp, FLAG_KNOWN_CURSED) |
| 703 |
&& (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)) |
| 704 |
&& tmp->item_power < skill->level) { |
| 705 |
SET_FLAG(tmp, FLAG_KNOWN_CURSED); |
| 706 |
esrv_update_item(UPD_FLAGS, pl, tmp); |
| 707 |
return calc_skill_exp(pl, tmp, skill); |
| 708 |
} |
| 709 |
return 0; |
| 710 |
} |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
static int do_skill_detect_curse(object *pl, object *skill) { |
| 722 |
int success = 0; |
| 723 |
|
| 724 |
FOR_INV_PREPARE(pl, tmp) |
| 725 |
if (!tmp->invisible) success += detect_curse_on_item(pl, tmp, skill); |
| 726 |
FOR_INV_FINISH(); |
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
FOR_MAP_PREPARE(pl->map, pl->x, pl->y, tmp) |
| 731 |
if (object_can_pick(pl, tmp) || QUERY_FLAG(tmp, FLAG_IS_CAULDRON)) |
| 732 |
success += detect_curse_on_item(pl, tmp, skill); |
| 733 |
FOR_MAP_FINISH(); |
| 734 |
|
| 735 |
return success; |
| 736 |
} |
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
int detect_magic_on_item(object *pl, object *tmp, object *skill) { |
| 751 |
if (!QUERY_FLAG(tmp, FLAG_IDENTIFIED) && !QUERY_FLAG(tmp, FLAG_KNOWN_MAGICAL) |
| 752 |
&& (is_magical(tmp)) && tmp->item_power < skill->level) { |
| 753 |
SET_FLAG(tmp, FLAG_KNOWN_MAGICAL); |
| 754 |
esrv_update_item(UPD_FLAGS, pl, tmp); |
| 755 |
return calc_skill_exp(pl, tmp, skill); |
| 756 |
} |
| 757 |
return 0; |
| 758 |
} |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
static int do_skill_detect_magic(object *pl, object *skill) { |
| 771 |
int success = 0; |
| 772 |
|
| 773 |
FOR_INV_PREPARE(pl, tmp) |
| 774 |
if (!tmp->invisible) |
| 775 |
success += detect_magic_on_item(pl, tmp, skill); |
| 776 |
FOR_INV_FINISH(); |
| 777 |
|
| 778 |
|
| 779 |
FOR_MAP_PREPARE(pl->map, pl->x, pl->y, tmp) |
| 780 |
if (object_can_pick(pl, tmp)) |
| 781 |
success += detect_magic_on_item(pl, tmp, skill); |
| 782 |
FOR_MAP_FINISH(); |
| 783 |
|
| 784 |
return success; |
| 785 |
} |
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
int identify_object_with_skill(object *tmp, object *pl, object *skill, int print_on_success) { |
| 803 |
int success = 0, chance, ip; |
| 804 |
int skill_value = (skill->level && pl->stats.Int) ? pl->stats.Int : 10; |
| 805 |
|
| 806 |
if (!tmp->invisible && !QUERY_FLAG(tmp, FLAG_NO_SKILL_IDENT) && !is_identified(tmp)) { |
| 807 |
ip = tmp->magic; |
| 808 |
if (tmp->item_power > ip) |
| 809 |
ip = tmp->item_power; |
| 810 |
|
| 811 |
chance = die_roll(3, 10, pl, PREFER_LOW)-3+rndm(0, (tmp->magic ? tmp->magic*5 : 1)-1); |
| 812 |
if (skill_value >= chance) { |
| 813 |
tmp = identify(tmp); |
| 814 |
if (pl->type == PLAYER && print_on_success) { |
| 815 |
char desc[MAX_BUF]; |
| 816 |
|
| 817 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 818 |
"You identify %s.", |
| 819 |
ob_describe(tmp, pl, 1, desc, sizeof(desc))); |
| 820 |
if (tmp->msg) { |
| 821 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_ITEM, MSG_TYPE_ITEM_INFO, |
| 822 |
"The item has a story:\n%s", |
| 823 |
tmp->msg); |
| 824 |
} |
| 825 |
} |
| 826 |
success += calc_skill_exp(pl, tmp, skill); |
| 827 |
} else |
| 828 |
SET_FLAG(tmp, FLAG_NO_SKILL_IDENT); |
| 829 |
} |
| 830 |
return success; |
| 831 |
} |
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
static int do_skill_ident(object *pl, int obj_class, object *skill) { |
| 846 |
int success = 0, area, i; |
| 847 |
|
| 848 |
|
| 849 |
FOR_INV_PREPARE(pl, tmp) |
| 850 |
if (tmp->type == obj_class) |
| 851 |
success += identify_object_with_skill(tmp, pl, skill, 1); |
| 852 |
FOR_INV_FINISH(); |
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
if (skill->level > 64) { |
| 860 |
area = 49; |
| 861 |
} else if (skill->level > 16) { |
| 862 |
area = 25; |
| 863 |
} else if (skill->level > 4) { |
| 864 |
area = 9; |
| 865 |
} else { |
| 866 |
area = 1; |
| 867 |
} |
| 868 |
|
| 869 |
for (i = 0; i < area; i++) { |
| 870 |
int16_t x = pl->x+freearr_x[i]; |
| 871 |
int16_t y = pl->y+freearr_y[i]; |
| 872 |
mapstruct *m = pl->map; |
| 873 |
int mflags; |
| 874 |
|
| 875 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 876 |
if (mflags&P_OUT_OF_MAP) |
| 877 |
continue; |
| 878 |
|
| 879 |
if (can_see_monsterP(m, pl->x, pl->y, i)) { |
| 880 |
FOR_MAP_PREPARE(m, x, y, tmp) |
| 881 |
if (tmp->type == obj_class) |
| 882 |
success += identify_object_with_skill(tmp, pl, skill, 1); |
| 883 |
FOR_MAP_FINISH(); |
| 884 |
} |
| 885 |
} |
| 886 |
return success; |
| 887 |
} |
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
int skill_ident(object *pl, object *skill) { |
| 899 |
int success = 0; |
| 900 |
int i, identifiable_types=0; |
| 901 |
const typedata *tmptype; |
| 902 |
|
| 903 |
if (pl->type != PLAYER) |
| 904 |
return 0; |
| 905 |
|
| 906 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 907 |
"You look at the objects nearby..."); |
| 908 |
|
| 909 |
switch (skill->subtype) { |
| 910 |
case SK_DET_CURSE: |
| 911 |
success = do_skill_detect_curse(pl, skill); |
| 912 |
if (success) |
| 913 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 914 |
"...and discover cursed items!"); |
| 915 |
break; |
| 916 |
|
| 917 |
case SK_DET_MAGIC: |
| 918 |
success = do_skill_detect_magic(pl, skill); |
| 919 |
if (success) |
| 920 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 921 |
"...and discover items imbued with mystic forces!"); |
| 922 |
break; |
| 923 |
|
| 924 |
default: |
| 925 |
|
| 926 |
for (i=0; i<=OBJECT_TYPE_MAX; i++) { |
| 927 |
tmptype = get_typedata(i); |
| 928 |
if (tmptype) { |
| 929 |
if (skill->subtype == tmptype->identifyskill || skill->subtype == tmptype->identifyskill2) { |
| 930 |
success += do_skill_ident(pl, i, skill); |
| 931 |
identifiable_types++; |
| 932 |
} |
| 933 |
} |
| 934 |
} |
| 935 |
if (identifiable_types == 0) { |
| 936 |
LOG(llevError, "Error: skill_ident() called with skill %d which can't identify any items\n", skill->subtype); |
| 937 |
return 0; |
| 938 |
break; |
| 939 |
} |
| 940 |
break; |
| 941 |
} |
| 942 |
if (!success) { |
| 943 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 944 |
"...and learn nothing more."); |
| 945 |
} |
| 946 |
return success; |
| 947 |
} |
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
int use_oratory(object *pl, int dir, object *skill) { |
| 969 |
int16_t x = pl->x+freearr_x[dir], y = pl->y+freearr_y[dir]; |
| 970 |
int mflags, chance; |
| 971 |
object *tmp; |
| 972 |
mapstruct *m; |
| 973 |
char name[MAX_BUF]; |
| 974 |
|
| 975 |
if (pl->type != PLAYER) |
| 976 |
return 0; |
| 977 |
m = pl->map; |
| 978 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 979 |
if (mflags&P_OUT_OF_MAP) |
| 980 |
return 0; |
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
if (!(mflags&P_IS_ALIVE)) { |
| 985 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 986 |
"There is nothing to orate to."); |
| 987 |
return 0; |
| 988 |
} |
| 989 |
|
| 990 |
tmp = NULL; |
| 991 |
FOR_MAP_PREPARE(m, x, y, tmp2) { |
| 992 |
tmp2 = HEAD(tmp2); |
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
if (tmp2->type == PLAYER) |
| 997 |
return 0; |
| 998 |
|
| 999 |
if (QUERY_FLAG(tmp2, FLAG_MONSTER)) { |
| 1000 |
const char *value = object_get_value(tmp2, "no_mood_change"); |
| 1001 |
if (value && strcmp(value, "1") == 0) |
| 1002 |
return 0; |
| 1003 |
|
| 1004 |
tmp = tmp2; |
| 1005 |
break; |
| 1006 |
} |
| 1007 |
} FOR_MAP_FINISH(); |
| 1008 |
|
| 1009 |
if (!tmp) { |
| 1010 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 1011 |
"There is nothing to orate to."); |
| 1012 |
return 0; |
| 1013 |
} |
| 1014 |
|
| 1015 |
query_name(tmp, name, MAX_BUF); |
| 1016 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 1017 |
"You orate to the %s.", |
| 1018 |
name); |
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
if (!QUERY_FLAG(tmp, FLAG_UNAGGRESSIVE) && !QUERY_FLAG(tmp, FLAG_FRIENDLY)) { |
| 1024 |
query_name(tmp, name, MAX_BUF); |
| 1025 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 1026 |
"Too bad the %s isn't listening!", |
| 1027 |
name); |
| 1028 |
return 0; |
| 1029 |
} |
| 1030 |
|
| 1031 |
|
| 1032 |
if (QUERY_FLAG(tmp, FLAG_FRIENDLY) && tmp->attack_movement == PETMOVE) { |
| 1033 |
if (object_get_owner(tmp) == pl) { |
| 1034 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 1035 |
"Your follower loves your speech."); |
| 1036 |
return 0; |
| 1037 |
} |
| 1038 |
|
| 1039 |
if (skill->level > tmp->level) { |
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
object_set_owner(tmp, pl); |
| 1044 |
query_name(tmp, name, MAX_BUF); |
| 1045 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 1046 |
"You convince the %s to follow you instead!", |
| 1047 |
name); |
| 1048 |
|
| 1049 |
FREE_AND_COPY(tmp->skill, skill->skill); |
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
return 0; |
| 1055 |
} |
| 1056 |
|
| 1057 |
|
| 1058 |
return 0; |
| 1059 |
} |
| 1060 |
|
| 1061 |
chance = skill->level*2+(pl->stats.Cha-2*tmp->stats.Int)/2; |
| 1062 |
|
| 1063 |
|
| 1064 |
if (chance > 0 && tmp->level < random_roll(0, chance-1, pl, PREFER_HIGH)-1) { |
| 1065 |
int64_t exp; |
| 1066 |
query_name(tmp, name, MAX_BUF); |
| 1067 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 1068 |
"You convince the %s to become your follower.", |
| 1069 |
name); |
| 1070 |
|
| 1071 |
object_set_owner(tmp, pl); |
| 1072 |
|
| 1073 |
tmp->stats.exp /= 5; |
| 1074 |
exp = calc_skill_exp(pl, tmp, skill); |
| 1075 |
tmp->stats.exp = 0; |
| 1076 |
add_friendly_object(tmp); |
| 1077 |
SET_FLAG(tmp, FLAG_FRIENDLY); |
| 1078 |
tmp->attack_movement = PETMOVE; |
| 1079 |
|
| 1080 |
FREE_AND_COPY(tmp->skill, skill->skill); |
| 1081 |
return exp; |
| 1082 |
} |
| 1083 |
|
| 1084 |
|
| 1085 |
if (skill->level+(pl->stats.Cha-10)/2 < random_roll(1, 2*tmp->level, pl, PREFER_LOW)) { |
| 1086 |
query_name(tmp, name, MAX_BUF); |
| 1087 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 1088 |
"Your speech angers the %s!", |
| 1089 |
name); |
| 1090 |
|
| 1091 |
if (QUERY_FLAG(tmp, FLAG_FRIENDLY)) { |
| 1092 |
CLEAR_FLAG(tmp, FLAG_FRIENDLY); |
| 1093 |
remove_friendly_object(tmp); |
| 1094 |
tmp->attack_movement = 0; |
| 1095 |
} |
| 1096 |
CLEAR_FLAG(tmp, FLAG_UNAGGRESSIVE); |
| 1097 |
} |
| 1098 |
|
| 1099 |
return 0; |
| 1100 |
} |
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
int singing(object *pl, int dir, object *skill) { |
| 1123 |
int i, exp = 0, chance, mflags; |
| 1124 |
object *tmp; |
| 1125 |
mapstruct *m; |
| 1126 |
int16_t x, y; |
| 1127 |
char name[MAX_BUF]; |
| 1128 |
const char *value; |
| 1129 |
|
| 1130 |
if (pl->type != PLAYER) |
| 1131 |
return 0; |
| 1132 |
|
| 1133 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 1134 |
"You sing"); |
| 1135 |
for (i = dir; i < (dir+MIN(skill->level, SIZEOFFREE)); i++) { |
| 1136 |
x = pl->x+freearr_x[i]; |
| 1137 |
y = pl->y+freearr_y[i]; |
| 1138 |
m = pl->map; |
| 1139 |
|
| 1140 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 1141 |
if (mflags&P_OUT_OF_MAP) |
| 1142 |
continue; |
| 1143 |
if (!(mflags&P_IS_ALIVE)) |
| 1144 |
continue; |
| 1145 |
|
| 1146 |
tmp = NULL; |
| 1147 |
FOR_MAP_PREPARE(m, x, y, tmp2) { |
| 1148 |
tmp2 = HEAD(tmp2); |
| 1149 |
if (QUERY_FLAG(tmp2, FLAG_MONSTER)) { |
| 1150 |
tmp = tmp2; |
| 1151 |
break; |
| 1152 |
} |
| 1153 |
|
| 1154 |
if (tmp2->type == PLAYER) { |
| 1155 |
tmp = tmp2; |
| 1156 |
break; |
| 1157 |
} |
| 1158 |
} FOR_MAP_FINISH(); |
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
if (tmp |
| 1164 |
&& QUERY_FLAG(tmp, FLAG_MONSTER) |
| 1165 |
&& !QUERY_FLAG(tmp, FLAG_NO_STEAL) |
| 1166 |
&& !QUERY_FLAG(tmp, FLAG_SPLITTING) |
| 1167 |
&& !QUERY_FLAG(tmp, FLAG_HITBACK) |
| 1168 |
&& (tmp->level <= skill->level) |
| 1169 |
&& !QUERY_FLAG(tmp, FLAG_UNDEAD) |
| 1170 |
&& !QUERY_FLAG(tmp, FLAG_UNAGGRESSIVE) |
| 1171 |
&& !QUERY_FLAG(tmp, FLAG_FRIENDLY)) { |
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
chance = skill->level*2+(pl->stats.Cha-5-tmp->stats.Int)/2; |
| 1177 |
|
| 1178 |
value = object_get_value(tmp, "no_mood_change"); |
| 1179 |
if (value && strcmp(value, "1") == 0) |
| 1180 |
chance = 0; |
| 1181 |
|
| 1182 |
if (chance && tmp->level*2 < random_roll(0, chance-1, pl, PREFER_HIGH)) { |
| 1183 |
SET_FLAG(tmp, FLAG_UNAGGRESSIVE); |
| 1184 |
query_name(tmp, name, MAX_BUF); |
| 1185 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 1186 |
"You calm down the %s", |
| 1187 |
name); |
| 1188 |
|
| 1189 |
|
| 1190 |
if (!QUERY_FLAG(tmp, FLAG_NO_STEAL)) |
| 1191 |
exp += calc_skill_exp(pl, tmp, skill); |
| 1192 |
SET_FLAG(tmp, FLAG_NO_STEAL); |
| 1193 |
} else { |
| 1194 |
query_name(tmp, name, MAX_BUF); |
| 1195 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 1196 |
"Too bad the %s isn't listening!", |
| 1197 |
name); |
| 1198 |
SET_FLAG(tmp, FLAG_NO_STEAL); |
| 1199 |
} |
| 1200 |
} |
| 1201 |
} |
| 1202 |
return exp; |
| 1203 |
} |
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
int find_traps(object *pl, object *skill) { |
| 1216 |
int i, expsum = 0, mflags; |
| 1217 |
int16_t x, y; |
| 1218 |
mapstruct *m; |
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
for (i = 0; i < 9; i++) { |
| 1225 |
x = pl->x+freearr_x[i]; |
| 1226 |
y = pl->y+freearr_y[i]; |
| 1227 |
m = pl->map; |
| 1228 |
|
| 1229 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 1230 |
if (mflags&P_OUT_OF_MAP) |
| 1231 |
continue; |
| 1232 |
|
| 1233 |
|
| 1234 |
FOR_MAP_PREPARE(m, x, y, tmp) { |
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
if (tmp->type != PLAYER && !QUERY_FLAG(tmp, FLAG_MONSTER)) { |
| 1241 |
FOR_INV_PREPARE(tmp, tmp2) |
| 1242 |
if (tmp2->type == RUNE || tmp2->type == TRAP) |
| 1243 |
if (trap_see(pl, tmp2)) { |
| 1244 |
trap_show(tmp2, tmp); |
| 1245 |
if (tmp2->stats.Cha > 1) { |
| 1246 |
object *owner; |
| 1247 |
|
| 1248 |
owner = object_get_owner(tmp2); |
| 1249 |
if (owner == NULL || owner->type != PLAYER) |
| 1250 |
expsum += calc_skill_exp(pl, tmp2, skill); |
| 1251 |
|
| 1252 |
tmp2->stats.Cha = 1; |
| 1253 |
} |
| 1254 |
} |
| 1255 |
FOR_INV_FINISH(); |
| 1256 |
} |
| 1257 |
if ((tmp->type == RUNE || tmp->type == TRAP) && trap_see(pl, tmp)) { |
| 1258 |
trap_show(tmp, tmp); |
| 1259 |
if (tmp->stats.Cha > 1) { |
| 1260 |
object *owner; |
| 1261 |
|
| 1262 |
owner = object_get_owner(tmp); |
| 1263 |
if (owner == NULL || owner->type != PLAYER) |
| 1264 |
expsum += calc_skill_exp(pl, tmp, skill); |
| 1265 |
tmp->stats.Cha = 1; |
| 1266 |
} |
| 1267 |
} |
| 1268 |
} FOR_MAP_FINISH(); |
| 1269 |
} |
| 1270 |
draw_ext_info(NDI_BLACK, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 1271 |
"You search the area."); |
| 1272 |
return expsum; |
| 1273 |
} |
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
int remove_trap(object *op, object *skill) { |
| 1287 |
int i, success = 0, mflags; |
| 1288 |
mapstruct *m; |
| 1289 |
int16_t x, y; |
| 1290 |
|
| 1291 |
for (i = 0; i < 9; i++) { |
| 1292 |
x = op->x+freearr_x[i]; |
| 1293 |
y = op->y+freearr_y[i]; |
| 1294 |
m = op->map; |
| 1295 |
|
| 1296 |
mflags = get_map_flags(m, &m, x, y, &x, &y); |
| 1297 |
if (mflags&P_OUT_OF_MAP) |
| 1298 |
continue; |
| 1299 |
|
| 1300 |
|
| 1301 |
FOR_MAP_PREPARE(m, x, y, tmp) { |
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
if (tmp->type != PLAYER && !QUERY_FLAG(tmp, FLAG_MONSTER)) { |
| 1308 |
FOR_INV_PREPARE(tmp, tmp2) |
| 1309 |
if ((tmp2->type == RUNE || tmp2->type == TRAP) && tmp2->stats.Cha <= 1) { |
| 1310 |
object *owner; |
| 1311 |
|
| 1312 |
trap_show(tmp2, tmp); |
| 1313 |
if (trap_disarm(op, tmp2, 1, skill) && ((owner = object_get_owner(tmp2)) == NULL || owner->type != PLAYER)) { |
| 1314 |
tmp2->stats.exp = tmp2->stats.Cha*tmp2->level; |
| 1315 |
success += calc_skill_exp(op, tmp2, skill); |
| 1316 |
} else { |
| 1317 |
|
| 1318 |
return success; |
| 1319 |
} |
| 1320 |
} |
| 1321 |
FOR_INV_FINISH(); |
| 1322 |
} |
| 1323 |
if ((tmp->type == RUNE || tmp->type == TRAP) && tmp->stats.Cha <= 1) { |
| 1324 |
object *owner; |
| 1325 |
|
| 1326 |
trap_show(tmp, tmp); |
| 1327 |
if (trap_disarm(op, tmp, 1, skill) && ((owner = object_get_owner(tmp)) == NULL || owner->type != PLAYER)) { |
| 1328 |
tmp->stats.exp = tmp->stats.Cha*tmp->level; |
| 1329 |
success += calc_skill_exp(op, tmp, skill); |
| 1330 |
} else { |
| 1331 |
|
| 1332 |
return success; |
| 1333 |
} |
| 1334 |
} |
| 1335 |
} FOR_MAP_FINISH(); |
| 1336 |
} |
| 1337 |
return success; |
| 1338 |
} |
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
int pray(object *pl, object *skill) { |
| 1360 |
char buf[MAX_BUF]; |
| 1361 |
|
| 1362 |
if (pl->type != PLAYER) |
| 1363 |
return 0; |
| 1364 |
|
| 1365 |
snprintf(buf, sizeof(buf), "You pray."); |
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
FOR_BELOW_PREPARE(pl, tmp) |
| 1373 |
|
| 1374 |
if (tmp->type == HOLY_ALTAR && tmp->other_arch) { |
| 1375 |
snprintf(buf, sizeof(buf), "You pray over the %s.", tmp->name); |
| 1376 |
pray_at_altar(pl, tmp, skill); |
| 1377 |
break; |
| 1378 |
} |
| 1379 |
FOR_BELOW_FINISH(); |
| 1380 |
|
| 1381 |
draw_ext_info(NDI_BLACK, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 1382 |
buf); |
| 1383 |
|
| 1384 |
if (pl->stats.grace < pl->stats.maxgrace) { |
| 1385 |
pl->stats.grace++; |
| 1386 |
pl->last_grace = -1; |
| 1387 |
} |
| 1388 |
return 0; |
| 1389 |
} |
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
void meditate(object *pl, object *skill) { |
| 1408 |
if (pl->type != PLAYER) |
| 1409 |
return; |
| 1410 |
|
| 1411 |
|
| 1412 |
if (QUERY_FLAG(pl, FLAG_READY_WEAPON) && skill->level < 6) { |
| 1413 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 1414 |
"You can't concentrate while wielding a weapon!"); |
| 1415 |
return; |
| 1416 |
} |
| 1417 |
|
| 1418 |
FOR_INV_PREPARE(pl, tmp) |
| 1419 |
if (((tmp->type == ARMOUR && skill->level < 12) |
| 1420 |
|| (tmp->type == HELMET && skill->level < 10) |
| 1421 |
|| (tmp->type == SHIELD && skill->level < 6) |
| 1422 |
|| (tmp->type == BOOTS && skill->level < 4) |
| 1423 |
|| (tmp->type == GLOVES && skill->level < 2)) |
| 1424 |
&& QUERY_FLAG(tmp, FLAG_APPLIED)) { |
| 1425 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 1426 |
"You can't concentrate while wearing so much armour!"); |
| 1427 |
return; |
| 1428 |
} |
| 1429 |
FOR_INV_FINISH(); |
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
draw_ext_info(NDI_BLACK, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 1440 |
"You meditate."); |
| 1441 |
|
| 1442 |
if (pl->stats.sp < pl->stats.maxsp) { |
| 1443 |
pl->stats.sp++; |
| 1444 |
pl->last_sp = -1; |
| 1445 |
} else if (pl->stats.hp < pl->stats.maxhp) { |
| 1446 |
pl->stats.hp++; |
| 1447 |
pl->last_heal = -1; |
| 1448 |
} |
| 1449 |
} |
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
static int write_note(object *pl, object *item, const char *msg) { |
| 1465 |
char buf[BOOK_BUF]; |
| 1466 |
object *newBook = NULL; |
| 1467 |
|
| 1468 |
|
| 1469 |
if (!item || item->type != BOOK) { |
| 1470 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 1471 |
"That was interesting..."); |
| 1472 |
|
| 1473 |
return 0; |
| 1474 |
} |
| 1475 |
|
| 1476 |
|
| 1477 |
if (!msg) { |
| 1478 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 1479 |
"Hmm... what was I going to write?"); |
| 1480 |
|
| 1481 |
return 0; |
| 1482 |
} |
| 1483 |
|
| 1484 |
|
| 1485 |
if (strcasestr_local(msg, "endmsg")) { |
| 1486 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 1487 |
"Trying to cheat now are we?"); |
| 1488 |
return 0; |
| 1489 |
} |
| 1490 |
|
| 1491 |
|
| 1492 |
if (execute_event(item, EVENT_TRIGGER, pl, NULL, msg, SCRIPT_FIX_ALL) != 0) |
| 1493 |
return strlen(msg); |
| 1494 |
|
| 1495 |
buf[0] = 0; |
| 1496 |
|
| 1497 |
|
| 1498 |
if (!book_overflow(item->msg, msg, BOOK_BUF)) { |
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
if (item->msg) { |
| 1503 |
snprintf(buf, sizeof(buf), "%s%s\n", item->msg, msg); |
| 1504 |
} else { |
| 1505 |
snprintf(buf, sizeof(buf), "%s\n", msg); |
| 1506 |
} |
| 1507 |
|
| 1508 |
|
| 1509 |
if (item->nrof > 1) { |
| 1510 |
newBook = object_new(); |
| 1511 |
object_copy(item, newBook); |
| 1512 |
object_decrease_nrof_by_one(item); |
| 1513 |
newBook->nrof = 1; |
| 1514 |
object_set_msg(newBook, buf); |
| 1515 |
newBook = object_insert_in_ob(newBook, pl); |
| 1516 |
} else { |
| 1517 |
object_set_msg(item, buf); |
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
} |
| 1522 |
|
| 1523 |
|
| 1524 |
query_short_name(item, buf, BOOK_BUF); |
| 1525 |
draw_ext_info_format( |
| 1526 |
NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 1527 |
"You write in the %s.", buf); |
| 1528 |
|
| 1529 |
|
| 1530 |
return strlen(msg); |
| 1531 |
} else { |
| 1532 |
query_short_name(item, buf, BOOK_BUF); |
| 1533 |
draw_ext_info_format( |
| 1534 |
NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 1535 |
"Your message won't fit in the %s!", buf); |
| 1536 |
return 0; |
| 1537 |
} |
| 1538 |
} |
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
static int write_scroll(object *pl, object *scroll, object *skill) { |
| 1555 |
int success = 0, confused = 0, grace_cost = 0; |
| 1556 |
object *newscroll, *chosen_spell, *tmp; |
| 1557 |
|
| 1558 |
|
| 1559 |
if (!scroll || scroll->type != SCROLL) { |
| 1560 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 1561 |
"A spell must be written on a magic scroll!"); |
| 1562 |
|
| 1563 |
return 0; |
| 1564 |
} |
| 1565 |
|
| 1566 |
|
| 1567 |
chosen_spell = pl->contr->ranges[range_magic]; |
| 1568 |
if (!chosen_spell) { |
| 1569 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 1570 |
"You should ready the spell you wish to inscribe."); |
| 1571 |
return 0; |
| 1572 |
} |
| 1573 |
|
| 1574 |
|
| 1575 |
grace_cost = SP_level_spellpoint_cost(pl, chosen_spell, SPELL_GRACE); |
| 1576 |
if (grace_cost > 0 && grace_cost > pl->stats.grace) { |
| 1577 |
draw_ext_info_format( |
| 1578 |
NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 1579 |
"You don't have enough grace to write a scroll of %s.", |
| 1580 |
chosen_spell->name); |
| 1581 |
return 0; |
| 1582 |
} |
| 1583 |
|
| 1584 |
if (SP_level_spellpoint_cost(pl, chosen_spell, SPELL_MANA) > pl->stats.sp) { |
| 1585 |
draw_ext_info_format( |
| 1586 |
NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 1587 |
"You don't have enough mana to write a scroll of %s.", |
| 1588 |
chosen_spell->name); |
| 1589 |
return 0; |
| 1590 |
} |
| 1591 |
|
| 1592 |
|
| 1593 |
if (chosen_spell->path_attuned & pl->path_denied |
| 1594 |
&& settings.allow_denied_spells_writing == 0) { |
| 1595 |
char name[MAX_BUF]; |
| 1596 |
|
| 1597 |
query_name(chosen_spell, name, MAX_BUF); |
| 1598 |
draw_ext_info_format( |
| 1599 |
NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 1600 |
"Just the idea of writing a scroll of %s makes you sick!", |
| 1601 |
name); |
| 1602 |
return 0; |
| 1603 |
} |
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
if ((scroll->stats.sp || scroll->inv) && |
| 1609 |
random_roll(0, scroll->level*2, pl, PREFER_LOW) > skill->level) { |
| 1610 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 1611 |
"Oops! You accidently read it while trying to write on it."); |
| 1612 |
apply_manual(pl, scroll, 0); |
| 1613 |
return 0; |
| 1614 |
} |
| 1615 |
|
| 1616 |
if (execute_event(scroll, EVENT_TRIGGER, pl, chosen_spell, NULL, 0) != 0) { |
| 1617 |
return 0; |
| 1618 |
} |
| 1619 |
|
| 1620 |
|
| 1621 |
if (QUERY_FLAG(pl, FLAG_CONFUSED)) { |
| 1622 |
confused = 1; |
| 1623 |
} |
| 1624 |
|
| 1625 |
|
| 1626 |
pl->stats.grace -= SP_level_spellpoint_cost(pl, chosen_spell, SPELL_GRACE); |
| 1627 |
pl->stats.sp -= SP_level_spellpoint_cost(pl, chosen_spell, SPELL_MANA); |
| 1628 |
|
| 1629 |
if (random_roll(0, chosen_spell->level * 4 - 1, pl, PREFER_LOW) < |
| 1630 |
skill->level) { |
| 1631 |
|
| 1632 |
if (scroll->nrof > 1) { |
| 1633 |
newscroll = object_new(); |
| 1634 |
object_copy(scroll, newscroll); |
| 1635 |
object_decrease_nrof_by_one(scroll); |
| 1636 |
newscroll->nrof = 1; |
| 1637 |
} else { |
| 1638 |
newscroll = scroll; |
| 1639 |
} |
| 1640 |
|
| 1641 |
|
| 1642 |
newscroll->level = MAX(skill->level, chosen_spell->level); |
| 1643 |
|
| 1644 |
if (!confused) { |
| 1645 |
draw_ext_info( |
| 1646 |
NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_SUCCESS, |
| 1647 |
"You succeed in writing a new scroll."); |
| 1648 |
} else { |
| 1649 |
chosen_spell = find_random_spell_in_ob(pl, NULL); |
| 1650 |
if (!chosen_spell) { |
| 1651 |
return 0; |
| 1652 |
} |
| 1653 |
|
| 1654 |
draw_ext_info( |
| 1655 |
NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 1656 |
"In your confused state, you write down some odd spell."); |
| 1657 |
} |
| 1658 |
|
| 1659 |
if (newscroll->inv) { |
| 1660 |
object *ninv; |
| 1661 |
ninv = newscroll->inv; |
| 1662 |
object_remove(ninv); |
| 1663 |
object_free(ninv, FREE_OBJ_NO_DESTROY_CALLBACK); |
| 1664 |
} |
| 1665 |
|
| 1666 |
tmp = object_new(); |
| 1667 |
object_copy(chosen_spell, tmp); |
| 1668 |
object_insert_in_ob(tmp, newscroll); |
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
newscroll->path_attuned = tmp->path_repelled; |
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
newscroll->value = newscroll->arch->clone.value * |
| 1677 |
newscroll->inv->value * (newscroll->level + 50 ) / |
| 1678 |
(newscroll->inv->level + 50); |
| 1679 |
newscroll->stats.exp = newscroll->value / 5; |
| 1680 |
|
| 1681 |
|
| 1682 |
if (newscroll == scroll) { |
| 1683 |
|
| 1684 |
object_remove(newscroll); |
| 1685 |
} |
| 1686 |
|
| 1687 |
newscroll = object_insert_in_ob(newscroll, pl); |
| 1688 |
success = calc_skill_exp(pl, newscroll, skill); |
| 1689 |
|
| 1690 |
if (!confused) { |
| 1691 |
success *= 2; |
| 1692 |
} |
| 1693 |
|
| 1694 |
success = success * skill->level; |
| 1695 |
return success; |
| 1696 |
} |
| 1697 |
|
| 1698 |
|
| 1699 |
if (chosen_spell->level > skill->level || confused) { |
| 1700 |
draw_ext_info( |
| 1701 |
NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 1702 |
"Ouch! Your attempt to write a new scroll strains your mind!"); |
| 1703 |
|
| 1704 |
|
| 1705 |
if (random_roll(0, 1, pl, PREFER_LOW) == 1) { |
| 1706 |
drain_specific_stat(pl, 4); |
| 1707 |
} else { |
| 1708 |
confuse_living(pl, pl, 99); |
| 1709 |
return -30 * chosen_spell->level; |
| 1710 |
} |
| 1711 |
} else if (random_roll(0, pl->stats.Int-1, pl, PREFER_HIGH) < 15) { |
| 1712 |
draw_ext_info( |
| 1713 |
NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 1714 |
"Your attempt to write a new scroll rattles your mind!"); |
| 1715 |
confuse_living(pl, pl, 99); |
| 1716 |
} else { |
| 1717 |
draw_ext_info( |
| 1718 |
NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 1719 |
"You fail to write a new scroll."); |
| 1720 |
} |
| 1721 |
|
| 1722 |
return 0; |
| 1723 |
} |
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
int write_on_item(object *pl, const char *params, object *skill) { |
| 1739 |
object *item; |
| 1740 |
const char *string = params; |
| 1741 |
int msgtype; |
| 1742 |
archetype *skat; |
| 1743 |
|
| 1744 |
|
| 1745 |
if (pl->type != PLAYER) { |
| 1746 |
return 0; |
| 1747 |
} |
| 1748 |
|
| 1749 |
|
| 1750 |
if (!params) { |
| 1751 |
params = ""; |
| 1752 |
string = params; |
| 1753 |
} |
| 1754 |
|
| 1755 |
|
| 1756 |
skat = get_archetype_by_type_subtype(SKILL, SK_LITERACY); |
| 1757 |
|
| 1758 |
if (!find_skill_by_name(pl, skat->clone.skill)) { |
| 1759 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_MISSING, |
| 1760 |
"You must learn to read before you can write!"); |
| 1761 |
return 0; |
| 1762 |
} |
| 1763 |
|
| 1764 |
|
| 1765 |
if (QUERY_FLAG(pl, FLAG_BLIND) && !QUERY_FLAG(pl, FLAG_WIZ)) { |
| 1766 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 1767 |
"You are unable to write while blind."); |
| 1768 |
return 0; |
| 1769 |
} |
| 1770 |
|
| 1771 |
|
| 1772 |
if (string[0] != '\0') { |
| 1773 |
msgtype = BOOK; |
| 1774 |
} else { |
| 1775 |
msgtype = SCROLL; |
| 1776 |
} |
| 1777 |
|
| 1778 |
|
| 1779 |
item = find_marked_object(pl); |
| 1780 |
if (item == NULL) { |
| 1781 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 1782 |
"You haven't marked any items to write on yet."); |
| 1783 |
return 0; |
| 1784 |
} |
| 1785 |
|
| 1786 |
|
| 1787 |
if (QUERY_FLAG(item, FLAG_UNPAID)) { |
| 1788 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 1789 |
"You had better pay for that before you write on it!"); |
| 1790 |
return 0; |
| 1791 |
} |
| 1792 |
|
| 1793 |
|
| 1794 |
if (msgtype != item->type) { |
| 1795 |
draw_ext_info_format( |
| 1796 |
NDI_UNIQUE, 0, pl, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 1797 |
"You must mark a %s to write %s.", |
| 1798 |
msgtype == BOOK ? "book" : "magic scroll", |
| 1799 |
msgtype == BOOK ? "your message on" : "your spell down"); |
| 1800 |
return 0; |
| 1801 |
} |
| 1802 |
|
| 1803 |
if (msgtype == BOOK) { |
| 1804 |
return write_note(pl, item, string); |
| 1805 |
} else if (msgtype == SCROLL) { |
| 1806 |
return write_scroll(pl, item, skill); |
| 1807 |
} else { |
| 1808 |
|
| 1809 |
abort(); |
| 1810 |
} |
| 1811 |
} |
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
|
| 1821 |
|
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
static object *find_throw_ob(object *op, sstring race) { |
| 1826 |
object *tmp; |
| 1827 |
char name[MAX_BUF]; |
| 1828 |
|
| 1829 |
if (!op) { |
| 1830 |
LOG(llevError, "find_throw_ob(): confused! have a NULL thrower!\n"); |
| 1831 |
return (object *)NULL; |
| 1832 |
} |
| 1833 |
|
| 1834 |
|
| 1835 |
tmp = find_marked_object(op); |
| 1836 |
if (tmp != NULL) { |
| 1837 |
|
| 1838 |
if (tmp->invisible || QUERY_FLAG(tmp, FLAG_INV_LOCKED)) { |
| 1839 |
tmp = NULL; |
| 1840 |
} |
| 1841 |
} |
| 1842 |
|
| 1843 |
|
| 1844 |
if (tmp == NULL) { |
| 1845 |
FOR_INV_PREPARE(op, tmp2) { |
| 1846 |
|
| 1847 |
if (tmp2->invisible) |
| 1848 |
continue; |
| 1849 |
|
| 1850 |
if (tmp2->type == CONTAINER && QUERY_FLAG(tmp2, FLAG_APPLIED) && tmp2->race == race) { |
| 1851 |
tmp = find_throw_ob(tmp2, race); |
| 1852 |
if (tmp != NULL) { |
| 1853 |
break; |
| 1854 |
} |
| 1855 |
} |
| 1856 |
|
| 1857 |
|
| 1858 |
if (tmp2->type == CONTAINER || QUERY_FLAG(tmp2, FLAG_INV_LOCKED)) |
| 1859 |
continue; |
| 1860 |
|
| 1861 |
if (tmp2->race == race) { |
| 1862 |
tmp = tmp2; |
| 1863 |
break; |
| 1864 |
} |
| 1865 |
|
| 1866 |
} FOR_INV_FINISH(); |
| 1867 |
} |
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
if (!tmp) |
| 1874 |
return NULL; |
| 1875 |
|
| 1876 |
if (QUERY_FLAG(tmp, FLAG_APPLIED)) { |
| 1877 |
if (tmp->type != WEAPON) { |
| 1878 |
query_name(tmp, name, MAX_BUF); |
| 1879 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 1880 |
"You can't throw %s.", |
| 1881 |
name); |
| 1882 |
tmp = NULL; |
| 1883 |
} else if (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)) { |
| 1884 |
query_name(tmp, name, MAX_BUF); |
| 1885 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 1886 |
MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 1887 |
"The %s sticks to your hand!", |
| 1888 |
name); |
| 1889 |
tmp = NULL; |
| 1890 |
} else { |
| 1891 |
if (apply_special(op, tmp, AP_UNAPPLY|AP_NO_MERGE)) { |
| 1892 |
LOG(llevError, "BUG: find_throw_ob(): couldn't unapply\n"); |
| 1893 |
tmp = NULL; |
| 1894 |
} |
| 1895 |
} |
| 1896 |
} else if (QUERY_FLAG(tmp, FLAG_UNPAID)) { |
| 1897 |
query_name(tmp, name, MAX_BUF); |
| 1898 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 1899 |
"You should pay for the %s first.", |
| 1900 |
name); |
| 1901 |
tmp = NULL; |
| 1902 |
} |
| 1903 |
|
| 1904 |
if (tmp && QUERY_FLAG(tmp, FLAG_INV_LOCKED)) { |
| 1905 |
LOG(llevError, "BUG: find_throw_ob(): object is locked\n"); |
| 1906 |
tmp = NULL; |
| 1907 |
} |
| 1908 |
return tmp; |
| 1909 |
} |
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
static object *make_throw_ob(object *orig) { |
| 1923 |
object *toss_item; |
| 1924 |
|
| 1925 |
if (!orig) |
| 1926 |
return NULL; |
| 1927 |
|
| 1928 |
toss_item = object_new(); |
| 1929 |
if (QUERY_FLAG(orig, FLAG_APPLIED)) { |
| 1930 |
LOG(llevError, "BUG: make_throw_ob(): ob is applied\n"); |
| 1931 |
|
| 1932 |
CLEAR_FLAG(orig, FLAG_APPLIED); |
| 1933 |
} |
| 1934 |
object_copy(orig, toss_item); |
| 1935 |
toss_item->type = THROWN_OBJ; |
| 1936 |
CLEAR_FLAG(toss_item, FLAG_CHANGING); |
| 1937 |
toss_item->stats.dam = 0; |
| 1938 |
object_insert_in_ob(orig, toss_item); |
| 1939 |
return toss_item; |
| 1940 |
} |
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
static int do_throw(object *op, object *part, object *toss_item, int dir, object *skill) { |
| 1964 |
object *throw_ob = toss_item, *left = NULL; |
| 1965 |
int eff_str = 0, str = op->stats.Str, dam = 0; |
| 1966 |
int pause_f, weight_f = 0, mflags; |
| 1967 |
float str_factor = 1.0, load_factor = 1.0, item_factor = 1.0; |
| 1968 |
mapstruct *m; |
| 1969 |
int16_t sx, sy; |
| 1970 |
tag_t tag; |
| 1971 |
char name[MAX_BUF]; |
| 1972 |
|
| 1973 |
if (throw_ob == NULL) { |
| 1974 |
if (op->type == PLAYER) { |
| 1975 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 1976 |
"You have nothing to throw."); |
| 1977 |
} |
| 1978 |
return 0; |
| 1979 |
} |
| 1980 |
if (QUERY_FLAG(throw_ob, FLAG_STARTEQUIP)) { |
| 1981 |
if (op->type == PLAYER) { |
| 1982 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 1983 |
"The gods won't let you throw that."); |
| 1984 |
} |
| 1985 |
return 0; |
| 1986 |
} |
| 1987 |
|
| 1988 |
|
| 1989 |
tag = throw_ob->count; |
| 1990 |
execute_event(throw_ob, EVENT_THROW, op, NULL, NULL, SCRIPT_FIX_ACTIVATOR); |
| 1991 |
if (object_was_destroyed(throw_ob, tag)) { |
| 1992 |
return 1; |
| 1993 |
} |
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
if (str > settings.max_stat) { |
| 2002 |
str_factor = (float)str/(float)settings.max_stat; |
| 2003 |
str = settings.max_stat; |
| 2004 |
} |
| 2005 |
|
| 2006 |
|
| 2007 |
if (op->type == PLAYER |
| 2008 |
&& op->carrying > (get_weight_limit(op->stats.Str)*FREE_PLAYER_LOAD_PERCENT) |
| 2009 |
&& (FREE_PLAYER_LOAD_PERCENT < 1.0)) { |
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
load_factor = 2.0f - (float)(op->carrying) / (float)(get_weight_limit(op->stats.Str)*FREE_PLAYER_LOAD_PERCENT); |
| 2025 |
|
| 2026 |
load_factor = MIN(load_factor, 1.0f); |
| 2027 |
} |
| 2028 |
|
| 2029 |
|
| 2030 |
if (throw_ob->weight > 0) |
| 2031 |
item_factor = (float)(get_weight_limit(op->stats.Str)*FREE_PLAYER_LOAD_PERCENT)/(float)(3.0*throw_ob->weight); |
| 2032 |
else { |
| 2033 |
query_name(throw_ob, name, MAX_BUF); |
| 2034 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_ERROR, |
| 2035 |
"You can't throw %s.", |
| 2036 |
name); |
| 2037 |
return 0; |
| 2038 |
} |
| 2039 |
|
| 2040 |
eff_str = str*load_factor; |
| 2041 |
eff_str = (float)eff_str*item_factor*str_factor; |
| 2042 |
|
| 2043 |
|
| 2044 |
|
| 2045 |
if (eff_str > settings.max_stat) |
| 2046 |
eff_str = settings.max_stat; |
| 2047 |
|
| 2048 |
#ifdef DEBUG_THROW |
| 2049 |
LOG(llevDebug, "%s carries %d, eff_str=%d\n", op->name, op->carrying, eff_str); |
| 2050 |
LOG(llevDebug, " max_c=%d, item_f=%f, load_f=%f, str=%d\n", (get_weight_limit(op->stats.Str)*FREE_PLAYER_LOAD_PERCENT), item_factor, load_factor, op->stats.Str); |
| 2051 |
LOG(llevDebug, " str_factor=%f\n", str_factor); |
| 2052 |
LOG(llevDebug, " item %s weight= %d\n", throw_ob->name, throw_ob->weight); |
| 2053 |
#endif |
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
mflags = get_map_flags(part->map, &m, part->x+freearr_x[dir], part->y+freearr_y[dir], &sx, &sy); |
| 2060 |
|
| 2061 |
if (!dir |
| 2062 |
|| (eff_str <= 1) |
| 2063 |
|| (mflags&P_OUT_OF_MAP) |
| 2064 |
|| (GET_MAP_MOVE_BLOCK(m, sx, sy)&MOVE_FLY_LOW)) { |
| 2065 |
|
| 2066 |
object_remove(throw_ob); |
| 2067 |
object_insert_in_map_at(throw_ob, part->map, op, 0, part->x, part->y); |
| 2068 |
if (op->type == PLAYER) { |
| 2069 |
if (eff_str <= 1) { |
| 2070 |
query_name(throw_ob, name, MAX_BUF); |
| 2071 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 2072 |
"Your load is so heavy you drop %s to the ground.", |
| 2073 |
name); |
| 2074 |
} else if (!dir) { |
| 2075 |
query_name(throw_ob, name, MAX_BUF); |
| 2076 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 2077 |
"You throw %s at the ground.", |
| 2078 |
name); |
| 2079 |
} else |
| 2080 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_SKILL, MSG_TYPE_SKILL_FAILURE, |
| 2081 |
"Something is in the way."); |
| 2082 |
} |
| 2083 |
return 0; |
| 2084 |
} |
| 2085 |
|
| 2086 |
left = throw_ob; |
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
throw_ob = object_split(throw_ob, 1, NULL, 0); |
| 2092 |
if (throw_ob == NULL) { |
| 2093 |
throw_ob = left; |
| 2094 |
object_remove(left); |
| 2095 |
} |
| 2096 |
|
| 2097 |
|
| 2098 |
if (throw_ob->type == POTION && throw_ob->subtype == POT_DUST) { |
| 2099 |
cast_dust(op, throw_ob, dir); |
| 2100 |
return 1; |
| 2101 |
} |
| 2102 |
|
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
toss_item = make_throw_ob(throw_ob); |
| 2108 |
if (toss_item) { |
| 2109 |
throw_ob = toss_item; |
| 2110 |
if (throw_ob->skill) |
| 2111 |
free_string(throw_ob->skill); |
| 2112 |
throw_ob->skill = add_string(skill->skill); |
| 2113 |
} else { |
| 2114 |
object_insert_in_ob(throw_ob, op); |
| 2115 |
return 0; |
| 2116 |
} |
| 2117 |
|
| 2118 |
object_set_owner(throw_ob, op); |
| 2119 |
|
| 2120 |
|
| 2121 |
|
| 2122 |
|
| 2123 |
object_set_owner(throw_ob->inv, op); |
| 2124 |
throw_ob->direction = dir; |
| 2125 |
|
| 2126 |
|
| 2127 |
dam = str_factor*get_dam_bonus(eff_str); |
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
throw_ob->last_sp = (eff_str*3)/5; |
| 2133 |
|
| 2134 |
|
| 2135 |
throw_ob->speed = (get_speed_bonus(eff_str)+1.0)/1.5; |
| 2136 |
throw_ob->speed = MIN(1.0, throw_ob->speed); |
| 2137 |
|
| 2138 |
|
| 2139 |
weight_f = MIN(throw_ob->weight/2000, settings.max_stat); |
| 2140 |
throw_ob->stats.dam += (dam/3)+get_dam_bonus(weight_f)+(throw_ob->weight/15000)-2; |
| 2141 |
|
| 2142 |
|
| 2143 |
throw_ob->stats.food = (dam/2)+(throw_ob->weight/60000); |
| 2144 |
|
| 2145 |
|
| 2146 |
throw_ob->stats.wc = 25-get_dex_bonus(op->stats.Dex)-get_thaco_bonus(eff_str)-skill->level; |
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
if (QUERY_FLAG(throw_ob->inv, FLAG_IS_THROWN)) { |
| 2155 |
throw_ob->last_sp += eff_str/3; |
| 2156 |
throw_ob->stats.dam += throw_ob->inv->stats.dam+throw_ob->magic+2; |
| 2157 |
throw_ob->stats.wc -= throw_ob->magic+throw_ob->inv->stats.wc; |
| 2158 |
|
| 2159 |
if (GET_ANIM_ID(throw_ob) && NUM_ANIMATIONS(throw_ob)) |
| 2160 |
object_update_turn_face(throw_ob); |
| 2161 |
} else { |
| 2162 |
|
| 2163 |
if (throw_ob->material&M_LEATHER) { |
| 2164 |
throw_ob->stats.dam -= 1; |
| 2165 |
throw_ob->stats.food -= 10; |
| 2166 |
} |
| 2167 |
if (throw_ob->material&M_GLASS) |
| 2168 |
throw_ob->stats.food += 60; |
| 2169 |
|
| 2170 |
if (throw_ob->material&M_ORGANIC) { |
| 2171 |
throw_ob->stats.dam -= 3; |
| 2172 |
throw_ob->stats.food += 55; |
| 2173 |
} |
| 2174 |
if (throw_ob->material&M_PAPER || throw_ob->material&M_CLOTH) { |
| 2175 |
throw_ob->stats.dam -= 5; |
| 2176 |
throw_ob->speed *= 0.8; |
| 2177 |
throw_ob->stats.wc += 3; |
| 2178 |
throw_ob->stats.food -= 30; |
| 2179 |
} |
| 2180 |
|
| 2181 |
if (throw_ob->weight > 500) |
| 2182 |
throw_ob->speed *= 0.8; |
| 2183 |
if (throw_ob->weight > 50) |
| 2184 |
throw_ob->speed *= 0.5; |
| 2185 |
} |
| 2186 |
|
| 2187 |
|
| 2188 |
if (throw_ob->stats.dam < 0) |
| 2189 |
throw_ob->stats.dam = 0; |
| 2190 |
if (throw_ob->last_sp > eff_str) |
| 2191 |
throw_ob->last_sp = eff_str; |
| 2192 |
if (throw_ob->stats.food < 0) |
| 2193 |
throw_ob->stats.food = 0; |
| 2194 |
if (throw_ob->stats.food > 100) |
| 2195 |
throw_ob->stats.food = 100; |
| 2196 |
if (throw_ob->stats.wc > 30) |
| 2197 |
throw_ob->stats.wc = 30; |
| 2198 |
|
| 2199 |
|
| 2200 |
pause_f = ((2*eff_str)/3)+20+skill->level; |
| 2201 |
|
| 2202 |
|
| 2203 |
if (pause_f < 10) |
| 2204 |
pause_f = 10; |
| 2205 |
if (pause_f > 100) |
| 2206 |
pause_f = 100; |
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
op->speed_left -= 50.0/pause_f; |
| 2213 |
|
| 2214 |
object_update_speed(throw_ob); |
| 2215 |
throw_ob->speed_left = 0; |
| 2216 |
|
| 2217 |
throw_ob->move_type = MOVE_FLY_LOW; |
| 2218 |
throw_ob->move_on = MOVE_FLY_LOW|MOVE_WALK; |
| 2219 |
|
| 2220 |
#ifdef DEBUG_THROW |
| 2221 |
LOG(llevDebug, " pause_f=%d \n", pause_f); |
| 2222 |
LOG(llevDebug, " %s stats: wc=%d dam=%d dist=%d spd=%f break=%d\n", throw_ob->name, throw_ob->stats.wc, throw_ob->stats.dam, throw_ob->last_sp, throw_ob->speed, throw_ob->stats.food); |
| 2223 |
LOG(llevDebug, "inserting tossitem (%d) into map\n", throw_ob->count); |
| 2224 |
#endif |
| 2225 |
tag = throw_ob->count; |
| 2226 |
object_insert_in_map_at(throw_ob, part->map, op, 0, part->x, part->y); |
| 2227 |
if (!object_was_destroyed(throw_ob, tag)) |
| 2228 |
ob_process(throw_ob); |
| 2229 |
return 1; |
| 2230 |
} |
| 2231 |
|
| 2232 |
|
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
|
| 2247 |
int skill_throw(object *op, object *part, int dir, object *skill) { |
| 2248 |
object *throw_ob; |
| 2249 |
|
| 2250 |
if (op->type == PLAYER) |
| 2251 |
throw_ob = find_throw_ob(op, find_string("throwing")); |
| 2252 |
else |
| 2253 |
throw_ob = monster_find_throw_ob(op); |
| 2254 |
|
| 2255 |
return do_throw(op, part, throw_ob, dir, skill); |
| 2256 |
} |