| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include "global.h" |
| 20 |
|
| 21 |
|
| 22 |
#include <math.h> |
| 23 |
#include <stdlib.h> |
| 24 |
#include <string.h> |
| 25 |
|
| 26 |
#include "living.h" |
| 27 |
#include "skills.h" |
| 28 |
#include "sounds.h" |
| 29 |
#include "spells.h" |
| 30 |
#include "sproto.h" |
| 31 |
#include "tod.h" |
| 32 |
|
| 33 |
static int apply_check_apply_restrictions(object *who, object *op, int aflags); |
| 34 |
static int apply_check_personalized_blessings(object *who, const object *op); |
| 35 |
static int apply_check_item_power(const object *who, const object *op, int aflags); |
| 36 |
static int apply_check_owner(const object *who, const object *op, int aflags); |
| 37 |
static void apply_update_ranged_skill(const object *who, object *op, int aflags); |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
int transport_can_hold(const object *transport, const object *op, int nrof) { |
| 55 |
return op->weight*nrof+transport->carrying <= transport->weight_limit; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
int should_director_abort(const object *op, const object *victim) { |
| 69 |
int arch_flag, name_flag, race_flag; |
| 70 |
|
| 71 |
|
| 72 |
if (victim->type == DOOR) |
| 73 |
return 1; |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
if (op->subtype) { |
| 86 |
arch_flag = op->subtype&1; |
| 87 |
name_flag = op->subtype&2; |
| 88 |
race_flag = op->subtype&4; |
| 89 |
} else { |
| 90 |
arch_flag = 1; |
| 91 |
name_flag = 1; |
| 92 |
race_flag = 1; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
if (op->race |
| 98 |
&& (!(victim->arch && arch_flag && victim->arch->name) || strcmp(op->race, victim->arch->name)) |
| 99 |
&& (!(victim->name && name_flag) || strcmp(op->race, victim->name)) |
| 100 |
&& (!(victim->race && race_flag) || strcmp(op->race, victim->race))) |
| 101 |
return 1; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
if (op->slaying |
| 107 |
&& ((victim->arch && arch_flag && victim->arch->name && !strcmp(op->slaying, victim->arch->name)) |
| 108 |
|| (victim->name && name_flag && !strcmp(op->slaying, victim->name)) |
| 109 |
|| (victim->race && race_flag && !strcmp(op->slaying, victim->race)))) |
| 110 |
return 1; |
| 111 |
|
| 112 |
return 0; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
void apply_handle_yield(object *tmp) { |
| 123 |
const char *yield; |
| 124 |
|
| 125 |
yield = object_get_value(tmp, "on_use_yield"); |
| 126 |
if (yield != NULL) { |
| 127 |
object *drop = create_archetype(yield); |
| 128 |
if (tmp->env) |
| 129 |
drop = object_insert_in_ob(drop, tmp->env); |
| 130 |
else |
| 131 |
object_insert_in_map_at(drop, tmp->map, tmp, INS_BELOW_ORIGINATOR, tmp->x, tmp->y); |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
int set_object_face_main(object *op) { |
| 147 |
const Face *newface = op->arch->clone.face; |
| 148 |
sstring saved = object_get_value(op, "face_closed"); |
| 149 |
|
| 150 |
if (op->more) |
| 151 |
set_object_face_main(op->more); |
| 152 |
|
| 153 |
if (saved) |
| 154 |
newface = find_face(saved, newface); |
| 155 |
if (newface && op->face != newface) { |
| 156 |
op->face = newface; |
| 157 |
return TRUE; |
| 158 |
} |
| 159 |
return FALSE; |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
static int set_object_face_other(object *op) { |
| 174 |
sstring custom; |
| 175 |
const Face *newface = NULL; |
| 176 |
object *head = op->head ? op->head : op; |
| 177 |
|
| 178 |
if (op->more) |
| 179 |
set_object_face_other(op->more); |
| 180 |
|
| 181 |
if (head->face && head->other_arch && head->other_arch->clone.face) |
| 182 |
newface = head->other_arch->clone.face; |
| 183 |
|
| 184 |
if (op->face != op->arch->clone.face) { |
| 185 |
|
| 186 |
object_set_value(op, "face_closed", op->face->name, 1); |
| 187 |
} |
| 188 |
|
| 189 |
custom = object_get_value(head, "face_opened"); |
| 190 |
if (custom) |
| 191 |
newface = find_face(custom, newface); |
| 192 |
if (newface && op->face != newface) { |
| 193 |
op->face = newface; |
| 194 |
return TRUE; |
| 195 |
} |
| 196 |
return FALSE; |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
int apply_container(object *op, object *sack, int aflags) { |
| 223 |
char name_sack[MAX_BUF], name_tmp[MAX_BUF]; |
| 224 |
object *tmp = op->container; |
| 225 |
|
| 226 |
if (op->type != PLAYER) |
| 227 |
return 0; |
| 228 |
|
| 229 |
if (sack == NULL || sack->type != CONTAINER) { |
| 230 |
LOG(llevError, "apply_container: '%s' tried to apply %s, which is not a container\n", op->name, sack ? sack->name : "(null)"); |
| 231 |
return 0; |
| 232 |
} |
| 233 |
|
| 234 |
if (sack->head) |
| 235 |
sack = sack->head; |
| 236 |
|
| 237 |
query_name(sack, name_sack, MAX_BUF); |
| 238 |
|
| 239 |
if ( aflags == AP_APPLY || aflags == AP_UNAPPLY || aflags == AP_OPEN ) { |
| 240 |
|
| 241 |
if ( sack->env != op ) { |
| 242 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 243 |
"Not in your inventory: %s", |
| 244 |
name_sack); |
| 245 |
return 0; |
| 246 |
} |
| 247 |
} |
| 248 |
if ( aflags == AP_APPLY ) { |
| 249 |
|
| 250 |
if ( op->container == sack ) { |
| 251 |
op->container = NULL; |
| 252 |
if (op->contr != NULL) |
| 253 |
op->contr->socket.container_position = 0; |
| 254 |
CLEAR_FLAG(sack, FLAG_APPLIED); |
| 255 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 256 |
"You readied %s.", |
| 257 |
name_sack); |
| 258 |
SET_FLAG(sack, FLAG_APPLIED); |
| 259 |
|
| 260 |
if (set_object_face_main(sack)) |
| 261 |
esrv_update_item(UPD_FLAGS|UPD_FACE, op, sack); |
| 262 |
else |
| 263 |
esrv_update_item(UPD_FLAGS, op, sack); |
| 264 |
return 0; |
| 265 |
} |
| 266 |
|
| 267 |
if (QUERY_FLAG(sack, FLAG_APPLIED)) { |
| 268 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 269 |
"Already readied %s.", |
| 270 |
name_sack); |
| 271 |
return 0; |
| 272 |
} |
| 273 |
|
| 274 |
aflags = AP_NULL; |
| 275 |
} |
| 276 |
|
| 277 |
if ( aflags == AP_OPEN ) { |
| 278 |
|
| 279 |
if ( op->container == sack ) { |
| 280 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 281 |
"Already opened %s.", |
| 282 |
name_sack); |
| 283 |
return 0; |
| 284 |
} |
| 285 |
|
| 286 |
SET_FLAG(sack, FLAG_APPLIED); |
| 287 |
aflags = AP_NULL; |
| 288 |
} |
| 289 |
|
| 290 |
if ( aflags == AP_UNAPPLY ) { |
| 291 |
|
| 292 |
if ( op->container != sack ) { |
| 293 |
if (QUERY_FLAG(sack, FLAG_APPLIED)) { |
| 294 |
CLEAR_FLAG(sack, FLAG_APPLIED); |
| 295 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 296 |
"You closed %s.", |
| 297 |
name_sack); |
| 298 |
esrv_update_item(UPD_FLAGS, op, sack); |
| 299 |
return 0; |
| 300 |
} |
| 301 |
else { |
| 302 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 303 |
"Already closed %s.", |
| 304 |
name_sack); |
| 305 |
return 0; |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
aflags = AP_NULL; |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
if (op->container && QUERY_FLAG(op->container, FLAG_APPLIED) && |
| 318 |
(QUERY_FLAG(sack, FLAG_APPLIED) || sack->env != op) ) |
| 319 |
{ |
| 320 |
tag_t tmp_tag = op->container->count; |
| 321 |
|
| 322 |
if (op->container->env != op) { |
| 323 |
object *part = op->container->head ? op->container->head : op->container; |
| 324 |
while (part) { |
| 325 |
part->move_off = 0; |
| 326 |
part = part->more; |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
query_name(op->container, name_tmp, MAX_BUF); |
| 332 |
|
| 333 |
|
| 334 |
if (execute_event(tmp, EVENT_CLOSE, op, NULL, NULL, SCRIPT_FIX_ALL) != 0) |
| 335 |
return 1; |
| 336 |
|
| 337 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 338 |
MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 339 |
"You close %s.", |
| 340 |
name_tmp); |
| 341 |
|
| 342 |
op->container = NULL; |
| 343 |
if (op->contr != NULL) |
| 344 |
op->contr->socket.container_position = 0; |
| 345 |
|
| 346 |
|
| 347 |
if (!object_was_destroyed(tmp, tmp_tag)) { |
| 348 |
CLEAR_FLAG(tmp, FLAG_APPLIED); |
| 349 |
if (set_object_face_main(tmp)) |
| 350 |
esrv_update_item(UPD_FLAGS|UPD_FACE, op, tmp); |
| 351 |
else |
| 352 |
esrv_update_item(UPD_FLAGS, op, tmp); |
| 353 |
} |
| 354 |
if (tmp == sack) |
| 355 |
return 1; |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
if (sack->slaying) { |
| 364 |
tmp = find_key(op, op, sack); |
| 365 |
if (tmp) { |
| 366 |
query_name(tmp, name_tmp, MAX_BUF); |
| 367 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 368 |
MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 369 |
"You unlock %s with %s.", |
| 370 |
name_sack, name_tmp); |
| 371 |
} else { |
| 372 |
draw_ext_info_format(NDI_UNIQUE, 0, op, |
| 373 |
MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 374 |
"You don't have the key to unlock %s.", |
| 375 |
name_sack); |
| 376 |
return 0; |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
if (sack->env != op) { |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
if (sack->env) { |
| 399 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 400 |
"You can't open %s", |
| 401 |
name_sack); |
| 402 |
return 0; |
| 403 |
} |
| 404 |
|
| 405 |
if (sack->nrof > 1) { |
| 406 |
object *left = object_split(sack, sack->nrof-1, NULL, 0); |
| 407 |
|
| 408 |
object_insert_in_map_at(left, sack->map, NULL, INS_NO_MERGE, sack->x, sack->y); |
| 409 |
|
| 410 |
query_name(sack, name_sack, MAX_BUF); |
| 411 |
} |
| 412 |
|
| 413 |
|
| 414 |
{ |
| 415 |
object *part = sack->head ? sack->head : sack; |
| 416 |
while (part) { |
| 417 |
part->move_off = MOVE_ALL; |
| 418 |
part = part->more; |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
CLEAR_FLAG(sack, FLAG_APPLIED); |
| 423 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 424 |
"You open %s.", |
| 425 |
name_sack); |
| 426 |
SET_FLAG(sack, FLAG_APPLIED); |
| 427 |
op->container = sack; |
| 428 |
if (op->contr != NULL) |
| 429 |
op->contr->socket.container_position = 0; |
| 430 |
|
| 431 |
if (set_object_face_other(sack)) |
| 432 |
esrv_update_item(UPD_FLAGS|UPD_FACE, op, sack); |
| 433 |
else |
| 434 |
esrv_update_item(UPD_FLAGS, op, sack); |
| 435 |
esrv_send_inventory(op, sack); |
| 436 |
} else { |
| 437 |
if (QUERY_FLAG(sack, FLAG_APPLIED)) { |
| 438 |
CLEAR_FLAG(sack, FLAG_APPLIED); |
| 439 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 440 |
"You open %s.", |
| 441 |
name_sack); |
| 442 |
SET_FLAG(sack, FLAG_APPLIED); |
| 443 |
op->container = sack; |
| 444 |
if (op->contr != NULL) |
| 445 |
op->contr->socket.container_position = 0; |
| 446 |
|
| 447 |
if (set_object_face_other(sack)) |
| 448 |
esrv_update_item(UPD_FLAGS|UPD_FACE, op, sack); |
| 449 |
else |
| 450 |
esrv_update_item(UPD_FLAGS, op, sack); |
| 451 |
esrv_send_inventory(op, sack); |
| 452 |
} else { |
| 453 |
object *left = NULL; |
| 454 |
|
| 455 |
if (sack->nrof > 1) |
| 456 |
left = object_split(sack, sack->nrof-1, NULL, 1); |
| 457 |
|
| 458 |
CLEAR_FLAG(sack, FLAG_APPLIED); |
| 459 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 460 |
"You readied %s.", |
| 461 |
name_sack); |
| 462 |
SET_FLAG(sack, FLAG_APPLIED); |
| 463 |
esrv_update_item(UPD_FLAGS, op, sack); |
| 464 |
|
| 465 |
if (left) { |
| 466 |
object_insert_in_ob(left, sack->env); |
| 467 |
esrv_send_item(op, left); |
| 468 |
} |
| 469 |
} |
| 470 |
} |
| 471 |
return 1; |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
void do_learn_spell(object *op, object *spell, int special_prayer) { |
| 486 |
object *tmp; |
| 487 |
|
| 488 |
if (op->type != PLAYER) { |
| 489 |
LOG(llevError, "BUG: do_learn_spell(): not a player\n"); |
| 490 |
return; |
| 491 |
} |
| 492 |
|
| 493 |
|
| 494 |
tmp = check_spell_known(op, spell->name); |
| 495 |
if (tmp != NULL) { |
| 496 |
if (special_prayer && !QUERY_FLAG(tmp, FLAG_STARTEQUIP)) { |
| 497 |
LOG(llevError, "BUG: do_learn_spell(): spell already known, but not marked as startequip\n"); |
| 498 |
return; |
| 499 |
} |
| 500 |
return; |
| 501 |
} |
| 502 |
|
| 503 |
play_sound_player_only(op->contr, SOUND_TYPE_SPELL, spell, 0, "learn"); |
| 504 |
tmp = object_new(); |
| 505 |
object_copy(spell, tmp); |
| 506 |
object_insert_in_ob(tmp, op); |
| 507 |
|
| 508 |
if (special_prayer) |
| 509 |
SET_FLAG(tmp, FLAG_STARTEQUIP); |
| 510 |
|
| 511 |
draw_ext_info_format(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 512 |
"Type 'bind cast %s to store the spell in a key.", |
| 513 |
spell->name); |
| 514 |
|
| 515 |
esrv_add_spells(op->contr, tmp); |
| 516 |
} |
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
void do_forget_spell(object *op, const char *spell) { |
| 527 |
object *spob; |
| 528 |
|
| 529 |
if (op->type != PLAYER) { |
| 530 |
LOG(llevError, "BUG: do_forget_spell(): not a player\n"); |
| 531 |
return; |
| 532 |
} |
| 533 |
spob = check_spell_known(op, spell); |
| 534 |
if (spob == NULL) { |
| 535 |
LOG(llevError, "BUG: do_forget_spell(): spell not known\n"); |
| 536 |
return; |
| 537 |
} |
| 538 |
|
| 539 |
draw_ext_info_format(NDI_UNIQUE|NDI_NAVY, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_CURSED, |
| 540 |
"You lose knowledge of %s.", |
| 541 |
spell); |
| 542 |
player_unready_range_ob(op->contr, spob); |
| 543 |
esrv_remove_spell(op->contr, spob); |
| 544 |
object_remove(spob); |
| 545 |
object_free(spob, 0); |
| 546 |
} |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
static int apply_check_race_restrictions(object *who, object *item) { |
| 559 |
char buf[MAX_BUF]; |
| 560 |
sstring restriction; |
| 561 |
|
| 562 |
if (who->type != PLAYER || QUERY_FLAG(who, FLAG_WIZ)) |
| 563 |
return 1; |
| 564 |
|
| 565 |
restriction = object_get_value(item, "race_restriction"); |
| 566 |
if (!restriction) |
| 567 |
return 1; |
| 568 |
|
| 569 |
snprintf(buf, sizeof(buf), ":%s:", who->race); |
| 570 |
buf[sizeof(buf)-1] = '\0'; |
| 571 |
|
| 572 |
if (strstr(restriction, buf) != NULL) |
| 573 |
return 1; |
| 574 |
|
| 575 |
query_name(item, buf, sizeof(buf)); |
| 576 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_PROHIBITION, "Somehow you can't seem to use the %s.", buf); |
| 577 |
|
| 578 |
return 0; |
| 579 |
} |
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
int apply_manual(object *op, object *tmp, int aflag) { |
| 599 |
tmp = HEAD(tmp); |
| 600 |
|
| 601 |
if (QUERY_FLAG(tmp, FLAG_UNPAID) && !QUERY_FLAG(tmp, FLAG_APPLIED)) { |
| 602 |
if (op->type == PLAYER) { |
| 603 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 604 |
"You should pay for it first."); |
| 605 |
return METHOD_SILENT_ERROR; |
| 606 |
} |
| 607 |
return 0; |
| 608 |
} |
| 609 |
|
| 610 |
if (!apply_check_race_restrictions(op, tmp)) |
| 611 |
return METHOD_SILENT_ERROR; |
| 612 |
|
| 613 |
if (op->contr) |
| 614 |
play_sound_player_only(op->contr, SOUND_TYPE_ITEM, tmp, 0, "apply"); |
| 615 |
|
| 616 |
return ob_apply(tmp, op, aflag); |
| 617 |
} |
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
int apply_by_living(object *pl, object *op, int aflag, int quiet) { |
| 639 |
int tmp; |
| 640 |
|
| 641 |
if (op->env == NULL && (pl->move_type&MOVE_FLYING)) { |
| 642 |
|
| 643 |
if (!QUERY_FLAG(pl, FLAG_WIZ) && !(op->move_type&MOVE_FLYING)) { |
| 644 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 645 |
"But you are floating high above the ground!"); |
| 646 |
return 0; |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
if (op->type != PLAYER |
| 654 |
&& QUERY_FLAG(op, FLAG_WAS_WIZ) |
| 655 |
&& !QUERY_FLAG(pl, FLAG_WAS_WIZ)) { |
| 656 |
play_sound_map(SOUND_TYPE_ITEM, op, 0, "evaporate"); |
| 657 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 658 |
"The object disappears in a puff of smoke!"); |
| 659 |
draw_ext_info(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 660 |
"It must have been an illusion."); |
| 661 |
object_remove(op); |
| 662 |
object_free(op, 0); |
| 663 |
return 1; |
| 664 |
} |
| 665 |
|
| 666 |
tmp = apply_manual(pl, op, aflag); |
| 667 |
if (!quiet) { |
| 668 |
if (tmp == METHOD_UNHANDLED) { |
| 669 |
char name[MAX_BUF]; |
| 670 |
|
| 671 |
query_name(op, name, MAX_BUF); |
| 672 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 673 |
"I don't know how to apply the %s.", |
| 674 |
name); |
| 675 |
} else if (tmp == METHOD_ERROR) |
| 676 |
draw_ext_info_format(NDI_UNIQUE, 0, pl, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 677 |
"You must get it first!\n"); |
| 678 |
else if (tmp == METHOD_SILENT_ERROR) |
| 679 |
return tmp; |
| 680 |
} |
| 681 |
if (tmp == METHOD_OK) { |
| 682 |
if (op->anim_suffix != NULL) |
| 683 |
apply_anim_suffix(pl, op->anim_suffix); |
| 684 |
} |
| 685 |
return tmp; |
| 686 |
} |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
void apply_by_living_below(object *pl) { |
| 697 |
object *tmp; |
| 698 |
int floors; |
| 699 |
|
| 700 |
if (pl->contr->transport && pl->contr->transport->type == TRANSPORT) { |
| 701 |
ob_apply(pl->contr->transport, pl, 0); |
| 702 |
return; |
| 703 |
} |
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
tmp = pl->container != NULL ? pl->container->inv : pl->below; |
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
floors = 0; |
| 717 |
FOR_OB_AND_BELOW_PREPARE(tmp) { |
| 718 |
if (QUERY_FLAG(tmp, FLAG_IS_FLOOR)) |
| 719 |
floors++; |
| 720 |
else if (floors > 0) |
| 721 |
return; |
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
if (!tmp->invisible || (tmp->move_on&pl->move_type)) { |
| 729 |
if (apply_by_living(pl, tmp, 0, 1) == METHOD_OK) |
| 730 |
return; |
| 731 |
} |
| 732 |
if (floors >= 2) |
| 733 |
return; |
| 734 |
} FOR_OB_AND_BELOW_FINISH(); |
| 735 |
} |
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
static int unapply_special(object *who, object *op, int aflags) { |
| 753 |
char name[MAX_BUF]; |
| 754 |
|
| 755 |
if (op->type != LAMP) |
| 756 |
CLEAR_FLAG(op, FLAG_APPLIED); |
| 757 |
query_name(op, name, MAX_BUF); |
| 758 |
switch (op->type) { |
| 759 |
case WEAPON: |
| 760 |
if (!(aflags&AP_NOPRINT)) |
| 761 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 762 |
"You unwield %s.", |
| 763 |
name); |
| 764 |
(void)change_abil(who, op); |
| 765 |
CLEAR_FLAG(who, FLAG_READY_WEAPON); |
| 766 |
who->current_weapon = NULL; |
| 767 |
clear_skill(who); |
| 768 |
break; |
| 769 |
|
| 770 |
case SKILL: |
| 771 |
case SKILL_TOOL: |
| 772 |
if (op != who->chosen_skill) |
| 773 |
LOG(llevError, "BUG: unapply_special(): applied skill is not a chosen skill\n"); |
| 774 |
if (who->type == PLAYER) { |
| 775 |
if (who->contr->shoottype == range_skill) |
| 776 |
who->contr->shoottype = range_none; |
| 777 |
if (!op->invisible) { |
| 778 |
if (!(aflags&AP_NOPRINT)) |
| 779 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 780 |
"You stop using the %s.", |
| 781 |
name); |
| 782 |
} else { |
| 783 |
if (!(aflags&AP_NOPRINT)) |
| 784 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 785 |
"You can no longer use the skill: %s.", |
| 786 |
op->skill); |
| 787 |
} |
| 788 |
} |
| 789 |
(void)change_abil(who, op); |
| 790 |
who->chosen_skill = NULL; |
| 791 |
CLEAR_FLAG(who, FLAG_READY_SKILL); |
| 792 |
break; |
| 793 |
|
| 794 |
case ARMOUR: |
| 795 |
case HELMET: |
| 796 |
case SHIELD: |
| 797 |
case RING: |
| 798 |
case BOOTS: |
| 799 |
case GLOVES: |
| 800 |
case AMULET: |
| 801 |
case GIRDLE: |
| 802 |
case BRACERS: |
| 803 |
case CLOAK: |
| 804 |
if (!(aflags&AP_NOPRINT)) |
| 805 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 806 |
"You unwear %s.", |
| 807 |
name); |
| 808 |
(void)change_abil(who, op); |
| 809 |
break; |
| 810 |
|
| 811 |
case BOW: |
| 812 |
case WAND: |
| 813 |
case ROD: |
| 814 |
clear_skill(who); |
| 815 |
if (!(aflags&AP_NOPRINT)) |
| 816 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 817 |
"You unready %s.", |
| 818 |
name); |
| 819 |
if (who->type == PLAYER) |
| 820 |
who->contr->shoottype = range_none; |
| 821 |
else if (op->type == BOW) |
| 822 |
CLEAR_FLAG(who, FLAG_READY_BOW); |
| 823 |
else |
| 824 |
CLEAR_FLAG(who, FLAG_READY_RANGE); |
| 825 |
break; |
| 826 |
|
| 827 |
case BUILDER: |
| 828 |
if (!(aflags&AP_NOPRINT)) |
| 829 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 830 |
"You unready %s.", |
| 831 |
name); |
| 832 |
who->contr->shoottype = range_none; |
| 833 |
who->contr->ranges[range_builder] = NULL; |
| 834 |
break; |
| 835 |
|
| 836 |
default: |
| 837 |
if (!(aflags&AP_NOPRINT)) |
| 838 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 839 |
"You unapply %s.", |
| 840 |
name); |
| 841 |
break; |
| 842 |
} |
| 843 |
|
| 844 |
fix_object(who); |
| 845 |
|
| 846 |
if (!(aflags&AP_NO_MERGE)) { |
| 847 |
object *tmp; |
| 848 |
|
| 849 |
tmp = object_merge(op, NULL); |
| 850 |
if (who->type == PLAYER) { |
| 851 |
if (tmp) { |
| 852 |
op = tmp; |
| 853 |
} |
| 854 |
esrv_update_item(UPD_FLAGS, who, op); |
| 855 |
} |
| 856 |
} |
| 857 |
return 0; |
| 858 |
} |
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
static object *get_item_from_body_location(object *start, int loc) { |
| 880 |
object *tmp; |
| 881 |
|
| 882 |
if (!start) |
| 883 |
return NULL; |
| 884 |
|
| 885 |
tmp = start; |
| 886 |
FOR_OB_AND_BELOW_PREPARE(tmp) |
| 887 |
if (QUERY_FLAG(tmp, FLAG_APPLIED) |
| 888 |
&& tmp->body_info[loc] |
| 889 |
&& (!tmp->invisible || tmp->type == SKILL)) |
| 890 |
return tmp; |
| 891 |
FOR_OB_AND_BELOW_FINISH(); |
| 892 |
return NULL; |
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
static int unapply_for_ob(object *who, object *op, int aflags) { |
| 917 |
int i; |
| 918 |
object *tmp = NULL, *last; |
| 919 |
char name[MAX_BUF]; |
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
if (op->type == WEAPON || op->type == SHIELD) { |
| 925 |
FOR_INV_PREPARE(who, tmp) { |
| 926 |
if (QUERY_FLAG(tmp, FLAG_APPLIED) && tmp->type == op->type) { |
| 927 |
if (!(aflags&AP_IGNORE_CURSE) |
| 928 |
&& !(aflags&AP_PRINT) |
| 929 |
&& (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED))) { |
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
if (!(aflags&AP_NOPRINT)) { |
| 936 |
query_name(tmp, name, MAX_BUF); |
| 937 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 938 |
"No matter how hard you try, you just can't remove %s.", |
| 939 |
name); |
| 940 |
} |
| 941 |
return 1; |
| 942 |
} |
| 943 |
|
| 944 |
if (aflags&AP_PRINT) { |
| 945 |
query_name(tmp, name, MAX_BUF); |
| 946 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 947 |
name); |
| 948 |
} else |
| 949 |
unapply_special(who, tmp, aflags); |
| 950 |
} |
| 951 |
} FOR_INV_FINISH(); |
| 952 |
} |
| 953 |
|
| 954 |
for (i = 0; i < NUM_BODY_LOCATIONS; i++) { |
| 955 |
|
| 956 |
if (op->body_info[i]) { |
| 957 |
last = who->inv; |
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
while (who->body_used[i]+op->body_info[i] < 0) { |
| 963 |
tmp = get_item_from_body_location(last, i); |
| 964 |
if (!tmp) |
| 965 |
return 1; |
| 966 |
|
| 967 |
|
| 968 |
if ((aflags&AP_IGNORE_CURSE) |
| 969 |
|| (aflags&AP_PRINT) |
| 970 |
|| (!(QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)))) { |
| 971 |
if (aflags&AP_PRINT) { |
| 972 |
query_name(tmp, name, MAX_BUF); |
| 973 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 974 |
name); |
| 975 |
} else |
| 976 |
unapply_special(who, tmp, aflags); |
| 977 |
} else { |
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
if (!(aflags&AP_NOPRINT)) { |
| 984 |
query_name(tmp, name, MAX_BUF); |
| 985 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 986 |
"The %s just won't come off", |
| 987 |
name); |
| 988 |
} |
| 989 |
} |
| 990 |
last = tmp->below; |
| 991 |
} |
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
} |
| 997 |
} |
| 998 |
return 0; |
| 999 |
} |
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
int apply_can_apply_object(const object *who, const object *op) { |
| 1018 |
int i, retval = 0; |
| 1019 |
object *tmp = NULL, *ws = NULL; |
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
if (op->type == WEAPON || op->type == SHIELD) { |
| 1027 |
tmp = object_find_by_type_applied(who, op->type); |
| 1028 |
if (tmp != NULL) { |
| 1029 |
retval = CAN_APPLY_UNAPPLY; |
| 1030 |
ws = tmp; |
| 1031 |
} |
| 1032 |
} |
| 1033 |
|
| 1034 |
for (i = 0; i < NUM_BODY_LOCATIONS; i++) { |
| 1035 |
if (op->body_info[i]) { |
| 1036 |
|
| 1037 |
if (FABS(op->body_info[i]) > who->body_info[i]) { |
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
retval |= CAN_APPLY_NEVER; |
| 1042 |
} else if (who->body_used[i]+op->body_info[i] < 0) { |
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
object *tmp1; |
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
if (ws) { |
| 1058 |
if (who->body_used[i]-ws->body_info[i]+op->body_info[i] >= 0) { |
| 1059 |
retval |= CAN_APPLY_UNAPPLY; |
| 1060 |
continue; |
| 1061 |
} |
| 1062 |
} |
| 1063 |
|
| 1064 |
tmp1 = get_item_from_body_location(who->inv, i); |
| 1065 |
if (!tmp1) |
| 1066 |
retval |= CAN_APPLY_NEVER; |
| 1067 |
else { |
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
retval |= CAN_APPLY_UNAPPLY; |
| 1073 |
if (!tmp) |
| 1074 |
tmp = tmp1; |
| 1075 |
else if (tmp != tmp1) |
| 1076 |
retval |= CAN_APPLY_UNAPPLY_MULT; |
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
if (who->body_used[i]-tmp1->body_info[i] != who->body_info[i] |
| 1083 |
&& FABS(op->body_info[i]) < who->body_info[i]) |
| 1084 |
retval |= CAN_APPLY_UNAPPLY_CHOICE; |
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
if (who->body_used[i]+op->body_info[i]-tmp1->body_info[i] < 0) |
| 1091 |
retval |= CAN_APPLY_UNAPPLY_MULT; |
| 1092 |
} |
| 1093 |
} |
| 1094 |
} |
| 1095 |
} |
| 1096 |
|
| 1097 |
|
| 1098 |
if (IS_WEAPON(op) && !QUERY_FLAG(who, FLAG_USE_WEAPON)) |
| 1099 |
retval |= CAN_APPLY_RESTRICTION; |
| 1100 |
if (IS_SHIELD(op) && !QUERY_FLAG(who, FLAG_USE_SHIELD)) |
| 1101 |
retval |= CAN_APPLY_RESTRICTION; |
| 1102 |
if (IS_ARMOR(op) && !QUERY_FLAG(who, FLAG_USE_ARMOUR)) |
| 1103 |
retval |= CAN_APPLY_RESTRICTION; |
| 1104 |
|
| 1105 |
if (who->type != PLAYER) { |
| 1106 |
if ((op->type == WAND || op->type == ROD) |
| 1107 |
&& !QUERY_FLAG(who, FLAG_USE_RANGE)) |
| 1108 |
retval |= CAN_APPLY_RESTRICTION; |
| 1109 |
if (op->type == BOW && !QUERY_FLAG(who, FLAG_USE_BOW)) |
| 1110 |
retval |= CAN_APPLY_RESTRICTION; |
| 1111 |
if (op->type == RING && !QUERY_FLAG(who, FLAG_USE_RING)) |
| 1112 |
retval |= CAN_APPLY_RESTRICTION; |
| 1113 |
} |
| 1114 |
return retval; |
| 1115 |
} |
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
int apply_check_weapon_power(const object *who, int improves) { |
| 1133 |
return (who->level/5)+5 >= improves; |
| 1134 |
} |
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
int apply_special(object *who, object *op, int aflags) { |
| 1158 |
int basic_flag = aflags&AP_BASIC_FLAGS; |
| 1159 |
object *tmp, *skop; |
| 1160 |
char name_op[MAX_BUF]; |
| 1161 |
|
| 1162 |
if (who == NULL) { |
| 1163 |
LOG(llevError, "apply_special() from object without environment.\n"); |
| 1164 |
return 1; |
| 1165 |
} |
| 1166 |
|
| 1167 |
if (op->env != who) |
| 1168 |
return 1; |
| 1169 |
|
| 1170 |
|
| 1171 |
if (QUERY_FLAG(op, FLAG_APPLIED)) { |
| 1172 |
|
| 1173 |
if (basic_flag == AP_APPLY) |
| 1174 |
return 0; |
| 1175 |
|
| 1176 |
if (!(aflags&AP_IGNORE_CURSE) |
| 1177 |
&& (QUERY_FLAG(op, FLAG_CURSED) || QUERY_FLAG(op, FLAG_DAMNED))) { |
| 1178 |
if (!(aflags&AP_NOPRINT)) { |
| 1179 |
query_name(op, name_op, MAX_BUF); |
| 1180 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 1181 |
"No matter how hard you try, you just can't remove %s.", |
| 1182 |
name_op); |
| 1183 |
} |
| 1184 |
return 1; |
| 1185 |
} |
| 1186 |
return unapply_special(who, op, aflags); |
| 1187 |
} |
| 1188 |
|
| 1189 |
if (basic_flag == AP_UNAPPLY) |
| 1190 |
return 0; |
| 1191 |
|
| 1192 |
if (!apply_check_apply_restrictions(who, op, aflags)) |
| 1193 |
return 1; |
| 1194 |
|
| 1195 |
if (op->skill && op->type != SKILL && op->type != SKILL_TOOL) { |
| 1196 |
skop = find_skill_by_name(who, op->skill); |
| 1197 |
if (!skop) { |
| 1198 |
if (!(aflags&AP_NOPRINT)) |
| 1199 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 1200 |
"You need the %s skill to use this item!", |
| 1201 |
op->skill); |
| 1202 |
if (who->type == PLAYER) |
| 1203 |
return 1; |
| 1204 |
|
| 1205 |
|
| 1206 |
} else |
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
change_skill(who, skop, (aflags&AP_NOPRINT)); |
| 1211 |
} else |
| 1212 |
skop = NULL; |
| 1213 |
|
| 1214 |
if (!apply_check_item_power(who, op, aflags)) |
| 1215 |
return 1; |
| 1216 |
|
| 1217 |
if (!apply_check_personalized_blessings(who, op)) |
| 1218 |
return 1; |
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
tmp = op->nrof <= 1 ? NULL : object_split(op, op->nrof-1, NULL, 0); |
| 1226 |
|
| 1227 |
switch (op->type) { |
| 1228 |
case WEAPON: |
| 1229 |
if (!apply_check_weapon_power(who, op->last_eat)) { |
| 1230 |
if (!(aflags&AP_NOPRINT)) |
| 1231 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 1232 |
"That weapon is too powerful for you to use. It would consume your soul!"); |
| 1233 |
if (tmp != NULL) |
| 1234 |
(void)object_insert_in_ob(tmp, who); |
| 1235 |
return 1; |
| 1236 |
} |
| 1237 |
|
| 1238 |
if (!apply_check_owner(who, op, aflags)) { |
| 1239 |
if (tmp != NULL) |
| 1240 |
(void)object_insert_in_ob(tmp, who); |
| 1241 |
return 1; |
| 1242 |
} |
| 1243 |
|
| 1244 |
SET_FLAG(op, FLAG_APPLIED); |
| 1245 |
|
| 1246 |
if (skop) |
| 1247 |
change_skill(who, skop, 1); |
| 1248 |
SET_FLAG(who, FLAG_READY_WEAPON); |
| 1249 |
|
| 1250 |
if (!(aflags&AP_NOPRINT)) { |
| 1251 |
query_name(op, name_op, MAX_BUF); |
| 1252 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 1253 |
"You wield %s.", |
| 1254 |
name_op); |
| 1255 |
} |
| 1256 |
|
| 1257 |
(void)change_abil(who, op); |
| 1258 |
break; |
| 1259 |
|
| 1260 |
case ARMOUR: |
| 1261 |
case HELMET: |
| 1262 |
case SHIELD: |
| 1263 |
case BOOTS: |
| 1264 |
case GLOVES: |
| 1265 |
case GIRDLE: |
| 1266 |
case BRACERS: |
| 1267 |
case CLOAK: |
| 1268 |
case RING: |
| 1269 |
case AMULET: |
| 1270 |
SET_FLAG(op, FLAG_APPLIED); |
| 1271 |
if (!(aflags&AP_NOPRINT)) { |
| 1272 |
query_name(op, name_op, MAX_BUF); |
| 1273 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 1274 |
"You wear %s.", |
| 1275 |
name_op); |
| 1276 |
} |
| 1277 |
(void)change_abil(who, op); |
| 1278 |
break; |
| 1279 |
|
| 1280 |
|
| 1281 |
case SKILL: |
| 1282 |
case SKILL_TOOL: |
| 1283 |
if (who->chosen_skill) { |
| 1284 |
LOG(llevError, "BUG: apply_special(): can't apply two skills\n"); |
| 1285 |
return 1; |
| 1286 |
} |
| 1287 |
|
| 1288 |
apply_update_ranged_skill(who, op, aflags); |
| 1289 |
SET_FLAG(op, FLAG_APPLIED); |
| 1290 |
(void)change_abil(who, op); |
| 1291 |
who->chosen_skill = op; |
| 1292 |
SET_FLAG(who, FLAG_READY_SKILL); |
| 1293 |
break; |
| 1294 |
|
| 1295 |
case BOW: |
| 1296 |
if (!apply_check_weapon_power(who, op->last_eat)) { |
| 1297 |
if (!(aflags&AP_NOPRINT)) |
| 1298 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 1299 |
"That weapon is too powerful for you to use. It would consume your soul!"); |
| 1300 |
if (tmp != NULL) |
| 1301 |
(void)object_insert_in_ob(tmp, who); |
| 1302 |
return 1; |
| 1303 |
} |
| 1304 |
|
| 1305 |
if (!apply_check_owner(who, op, aflags)) { |
| 1306 |
if (tmp != NULL) |
| 1307 |
(void)object_insert_in_ob(tmp, who); |
| 1308 |
return 1; |
| 1309 |
} |
| 1310 |
|
| 1311 |
case WAND: |
| 1312 |
case ROD: |
| 1313 |
|
| 1314 |
SET_FLAG(op, FLAG_APPLIED); |
| 1315 |
if (skop) |
| 1316 |
change_skill(who, skop, 0); |
| 1317 |
if (!(aflags&AP_NOPRINT)) { |
| 1318 |
query_name(op, name_op, MAX_BUF); |
| 1319 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 1320 |
"You ready %s.", |
| 1321 |
name_op); |
| 1322 |
} |
| 1323 |
if (who->type == PLAYER) { |
| 1324 |
if (op->type == BOW) { |
| 1325 |
(void)change_abil(who, op); |
| 1326 |
if (!(aflags&AP_NOPRINT)) { |
| 1327 |
query_name(op, name_op, MAX_BUF); |
| 1328 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 1329 |
"You will now fire %s with %s.", |
| 1330 |
op->race ? op->race : "nothing", |
| 1331 |
name_op); |
| 1332 |
} |
| 1333 |
who->contr->shoottype = range_bow; |
| 1334 |
} else |
| 1335 |
who->contr->shoottype = range_misc; |
| 1336 |
} else { |
| 1337 |
if (op->type == BOW) |
| 1338 |
SET_FLAG(who, FLAG_READY_BOW); |
| 1339 |
else |
| 1340 |
SET_FLAG(who, FLAG_READY_RANGE); |
| 1341 |
} |
| 1342 |
break; |
| 1343 |
|
| 1344 |
case BUILDER: |
| 1345 |
if (who->contr->ranges[range_builder]) |
| 1346 |
unapply_special(who, who->contr->ranges[range_builder], 0); |
| 1347 |
who->contr->shoottype = range_builder; |
| 1348 |
who->contr->ranges[range_builder] = op; |
| 1349 |
if (!(aflags&AP_NOPRINT)) { |
| 1350 |
query_name(op, name_op, MAX_BUF); |
| 1351 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 1352 |
"You ready your %s.", |
| 1353 |
name_op); |
| 1354 |
} |
| 1355 |
break; |
| 1356 |
|
| 1357 |
default: |
| 1358 |
query_name(op, name_op, MAX_BUF); |
| 1359 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 1360 |
"You apply %s.", |
| 1361 |
name_op); |
| 1362 |
break; |
| 1363 |
} |
| 1364 |
|
| 1365 |
SET_FLAG(op, FLAG_APPLIED); |
| 1366 |
|
| 1367 |
if (tmp != NULL) |
| 1368 |
tmp = object_insert_in_ob(tmp, who); |
| 1369 |
|
| 1370 |
fix_object(who); |
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
if (who->type == PLAYER && op->type != WAND && op->type != ROD) |
| 1377 |
SET_FLAG(op, FLAG_BEEN_APPLIED); |
| 1378 |
|
| 1379 |
if (QUERY_FLAG(op, FLAG_CURSED) || QUERY_FLAG(op, FLAG_DAMNED)) { |
| 1380 |
if (who->type == PLAYER) { |
| 1381 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_CURSED, |
| 1382 |
"Oops, it feels deadly cold!"); |
| 1383 |
SET_FLAG(op, FLAG_KNOWN_CURSED); |
| 1384 |
} |
| 1385 |
} |
| 1386 |
if (who->type == PLAYER) |
| 1387 |
esrv_update_item(UPD_NAME|UPD_NROF|UPD_FLAGS|UPD_WEIGHT, who, op); |
| 1388 |
return 0; |
| 1389 |
} |
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
int apply_auto(object *op) { |
| 1402 |
object *tmp; |
| 1403 |
|
| 1404 |
switch (op->type) { |
| 1405 |
case SHOP_FLOOR: |
| 1406 |
if (!HAS_RANDOM_ITEMS(op)) |
| 1407 |
return 0; |
| 1408 |
do { |
| 1409 |
int i; |
| 1410 |
|
| 1411 |
i = 10; |
| 1412 |
while ((tmp = generate_treasure(op->randomitems, op->stats.exp ? (int)op->stats.exp : MAX(op->map->difficulty, 5))) == NULL |
| 1413 |
&& --i) |
| 1414 |
; |
| 1415 |
if (tmp == NULL) |
| 1416 |
return 0; |
| 1417 |
if (QUERY_FLAG(tmp, FLAG_CURSED) || QUERY_FLAG(tmp, FLAG_DAMNED)) { |
| 1418 |
object_free(tmp, FREE_OBJ_NO_DESTROY_CALLBACK); |
| 1419 |
tmp = NULL; |
| 1420 |
} |
| 1421 |
} while (!tmp); |
| 1422 |
SET_FLAG(tmp, FLAG_UNPAID); |
| 1423 |
object_insert_in_map_at(tmp, op->map, NULL, 0, op->x, op->y); |
| 1424 |
CLEAR_FLAG(op, FLAG_AUTO_APPLY); |
| 1425 |
identify(tmp); |
| 1426 |
return 1; |
| 1427 |
break; |
| 1428 |
|
| 1429 |
case TREASURE: |
| 1430 |
if (QUERY_FLAG(op, FLAG_IS_A_TEMPLATE)) |
| 1431 |
return 0; |
| 1432 |
while (op->stats.hp-- > 0) |
| 1433 |
create_treasure(op->randomitems, op, (op->map ? GT_ENVIRONMENT : 0) | (QUERY_FLAG(op, FLAG_BLESSED) ? GT_ONLY_GOOD : 0), op->stats.exp ? (int)op->stats.exp : op->map == NULL ? 14 : op->map->difficulty, 0); |
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
FOR_INV_PREPARE(op, tmp) { |
| 1441 |
object_remove(tmp); |
| 1442 |
if (op->env) |
| 1443 |
object_insert_in_ob(tmp, op->env); |
| 1444 |
else |
| 1445 |
object_free_drop_inventory(tmp); |
| 1446 |
} FOR_INV_FINISH(); |
| 1447 |
object_remove(op); |
| 1448 |
object_free(op, FREE_OBJ_NO_DESTROY_CALLBACK); |
| 1449 |
break; |
| 1450 |
} |
| 1451 |
return 0; |
| 1452 |
} |
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
|
| 1462 |
|
| 1463 |
|
| 1464 |
void apply_auto_fix(mapstruct *m) { |
| 1465 |
int x, y; |
| 1466 |
|
| 1467 |
if (m == NULL) |
| 1468 |
return; |
| 1469 |
|
| 1470 |
for (x = 0; x < MAP_WIDTH(m); x++) |
| 1471 |
for (y = 0; y < MAP_HEIGHT(m); y++) |
| 1472 |
FOR_MAP_PREPARE(m, x, y, tmp) { |
| 1473 |
if (tmp->inv) { |
| 1474 |
FOR_INV_PREPARE(tmp, invtmp) { |
| 1475 |
if (QUERY_FLAG(invtmp, FLAG_AUTO_APPLY)) |
| 1476 |
apply_auto(invtmp); |
| 1477 |
else if (invtmp->type == TREASURE && HAS_RANDOM_ITEMS(invtmp)) { |
| 1478 |
while (invtmp->stats.hp-- > 0) |
| 1479 |
create_treasure(invtmp->randomitems, invtmp, 0, m->difficulty, 0); |
| 1480 |
invtmp->randomitems = NULL; |
| 1481 |
} else if (invtmp && invtmp->arch |
| 1482 |
&& invtmp->type != TREASURE |
| 1483 |
&& invtmp->type != SPELL |
| 1484 |
&& invtmp->type != CLASS |
| 1485 |
&& HAS_RANDOM_ITEMS(invtmp)) { |
| 1486 |
create_treasure(invtmp->randomitems, invtmp, 0, m->difficulty, 0); |
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
invtmp->randomitems = NULL; |
| 1491 |
} |
| 1492 |
} FOR_INV_FINISH(); |
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
if (tmp->type == WAND |
| 1507 |
|| tmp->type == ROD |
| 1508 |
|| tmp->type == SCROLL |
| 1509 |
|| tmp->type == FIREWALL |
| 1510 |
|| tmp->type == POTION |
| 1511 |
|| tmp->type == ALTAR |
| 1512 |
|| tmp->type == SPELLBOOK) |
| 1513 |
tmp->randomitems = NULL; |
| 1514 |
} |
| 1515 |
|
| 1516 |
if (QUERY_FLAG(tmp, FLAG_AUTO_APPLY)) |
| 1517 |
apply_auto(tmp); |
| 1518 |
else if ((tmp->type == TREASURE || tmp->type == CONTAINER) |
| 1519 |
&& HAS_RANDOM_ITEMS(tmp)) { |
| 1520 |
while (tmp->stats.hp-- > 0) |
| 1521 |
create_treasure(tmp->randomitems, tmp, 0, m->difficulty, 0); |
| 1522 |
tmp->randomitems = NULL; |
| 1523 |
} else if (tmp->type == TIMED_GATE) { |
| 1524 |
object *head = HEAD(tmp); |
| 1525 |
|
| 1526 |
if (QUERY_FLAG(head, FLAG_IS_LINKED)) { |
| 1527 |
tmp->speed = 0; |
| 1528 |
object_update_speed(tmp); |
| 1529 |
} |
| 1530 |
} |
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
|
| 1539 |
else if (tmp |
| 1540 |
&& tmp->arch |
| 1541 |
&& tmp->type != PLAYER |
| 1542 |
&& tmp->type != TREASURE |
| 1543 |
&& tmp->type != SPELL |
| 1544 |
&& tmp->type != PLAYER_CHANGER |
| 1545 |
&& tmp->type != CLASS |
| 1546 |
&& HAS_RANDOM_ITEMS(tmp)) { |
| 1547 |
create_treasure(tmp->randomitems, tmp, 0, m->difficulty, 0); |
| 1548 |
tmp->randomitems = NULL; |
| 1549 |
} |
| 1550 |
|
| 1551 |
if (QUERY_FLAG(tmp, FLAG_MONSTER)) |
| 1552 |
monster_check_apply_all(tmp); |
| 1553 |
} FOR_MAP_FINISH(); |
| 1554 |
|
| 1555 |
for (x = 0; x < MAP_WIDTH(m); x++) |
| 1556 |
for (y = 0; y < MAP_HEIGHT(m); y++) |
| 1557 |
FOR_MAP_PREPARE(m, x, y, tmp) { |
| 1558 |
if (tmp->above |
| 1559 |
&& (tmp->type == TRIGGER_BUTTON || tmp->type == TRIGGER_PEDESTAL)) |
| 1560 |
check_trigger(tmp, tmp->above); |
| 1561 |
} FOR_MAP_FINISH(); |
| 1562 |
} |
| 1563 |
|
| 1564 |
|
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
void scroll_failure(object *op, int failure, int power) { |
| 1579 |
if (abs(failure/4) > power) |
| 1580 |
power = abs(failure/4); |
| 1581 |
|
| 1582 |
if (failure <= -1 && failure > -15) { |
| 1583 |
object *tmp; |
| 1584 |
|
| 1585 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 1586 |
"Your spell warps!"); |
| 1587 |
tmp = create_archetype(SPELL_WONDER); |
| 1588 |
cast_wonder(op, op, 0, tmp); |
| 1589 |
if (op->stats.sp < 0) |
| 1590 |
|
| 1591 |
op->stats.sp = 0; |
| 1592 |
object_free(tmp, FREE_OBJ_NO_DESTROY_CALLBACK); |
| 1593 |
return; |
| 1594 |
} |
| 1595 |
|
| 1596 |
if (settings.spell_failure_effects == TRUE) { |
| 1597 |
if (failure <= -35 && failure > -60) { |
| 1598 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 1599 |
"The magic recoils on you!"); |
| 1600 |
confuse_living(op, op, power); |
| 1601 |
return; |
| 1602 |
} |
| 1603 |
|
| 1604 |
if (failure <= -60 && failure > -70) { |
| 1605 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 1606 |
"The magic recoils and paralyzes you!"); |
| 1607 |
paralyze_living(op, power); |
| 1608 |
return; |
| 1609 |
} |
| 1610 |
|
| 1611 |
if (failure <= -70 && failure > -80) { |
| 1612 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 1613 |
"The magic recoils on you!"); |
| 1614 |
blind_living(op, op, power); |
| 1615 |
return; |
| 1616 |
} |
| 1617 |
|
| 1618 |
if (failure <= -80) { |
| 1619 |
object *tmp; |
| 1620 |
|
| 1621 |
tmp = create_archetype(LOOSE_MANA); |
| 1622 |
cast_magic_storm(op, tmp, power); |
| 1623 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 1624 |
"You unlease uncontrolled mana!"); |
| 1625 |
object_free(tmp, FREE_OBJ_NO_DESTROY_CALLBACK); |
| 1626 |
return; |
| 1627 |
} |
| 1628 |
} |
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
draw_ext_info(NDI_UNIQUE, 0, op, MSG_TYPE_APPLY, MSG_TYPE_APPLY_FAILURE, |
| 1633 |
"Your mana is drained!"); |
| 1634 |
op->stats.sp -= random_roll(0, power-1, op, PREFER_LOW); |
| 1635 |
if (op->stats.sp < 0) |
| 1636 |
op->stats.sp = 0; |
| 1637 |
} |
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
void apply_changes_to_player(object *pl, object *change, int limit_stats) { |
| 1651 |
int i, j; |
| 1652 |
int excess_stat = 0; |
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
if (change->type != CLASS) return; |
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
if (! (limit_stats & AC_PLAYER_STAT_NO_CHANGE)) { |
| 1664 |
for (i = 0; i < NUM_STATS; i++) { |
| 1665 |
int8_t stat = get_attr_value(&pl->contr->orig_stats, i); |
| 1666 |
int race_bonus = get_attr_value(&pl->arch->clone.stats, i); |
| 1667 |
|
| 1668 |
stat += get_attr_value(&change->stats, i); |
| 1669 |
if (limit_stats & AC_PLAYER_STAT_LIMIT) { |
| 1670 |
if (stat > 20+race_bonus) { |
| 1671 |
excess_stat++; |
| 1672 |
stat = 20+race_bonus; |
| 1673 |
} else if (stat < 1) { |
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
excess_stat += stat; |
| 1682 |
stat = 1; |
| 1683 |
} |
| 1684 |
} |
| 1685 |
set_attr_value(&pl->contr->orig_stats, i, stat); |
| 1686 |
} |
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
if (excess_stat < 0) excess_stat = 0; |
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
for (j = 0; excess_stat > 0 && j < 100; j++) { |
| 1698 |
|
| 1699 |
int i = rndm(0, NUM_STATS-1); |
| 1700 |
int stat = get_attr_value(&pl->contr->orig_stats, i); |
| 1701 |
int race_bonus = get_attr_value(&pl->arch->clone.stats, i); |
| 1702 |
|
| 1703 |
if (i == CHARISMA) { |
| 1704 |
continue; |
| 1705 |
} |
| 1706 |
|
| 1707 |
if (stat < 20+race_bonus) { |
| 1708 |
change_attr_value(&pl->contr->orig_stats, i, 1); |
| 1709 |
excess_stat--; |
| 1710 |
} |
| 1711 |
} |
| 1712 |
} |
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
if (change->randomitems != NULL) |
| 1719 |
give_initial_items(pl, change->randomitems); |
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
|
| 1727 |
int has_noclassfacechange = (object_find_by_name(pl, "NOCLASSFACECHANGE") != NULL); |
| 1728 |
const Animations *anim = NULL; |
| 1729 |
|
| 1730 |
if (change->anim_suffix) { |
| 1731 |
char buf[MAX_BUF]; |
| 1732 |
|
| 1733 |
snprintf(buf, MAX_BUF, "%s_%s", pl->animation->name, change->anim_suffix); |
| 1734 |
anim = try_find_animation(buf); |
| 1735 |
if (anim) { |
| 1736 |
pl->animation = anim; |
| 1737 |
pl->anim_speed = -1; |
| 1738 |
CLEAR_FLAG(pl, FLAG_ANIMATE); |
| 1739 |
animate_object(pl, pl->facing); |
| 1740 |
} |
| 1741 |
} |
| 1742 |
|
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
if ((!has_noclassfacechange) && anim == 0) { |
| 1748 |
pl->animation = GET_ANIM(change); |
| 1749 |
pl->face = change->face; |
| 1750 |
|
| 1751 |
if (QUERY_FLAG(change, FLAG_ANIMATE)) |
| 1752 |
SET_FLAG(pl, FLAG_ANIMATE); |
| 1753 |
else |
| 1754 |
CLEAR_FLAG(pl, FLAG_ANIMATE); |
| 1755 |
} |
| 1756 |
|
| 1757 |
|
| 1758 |
|
| 1759 |
|
| 1760 |
if (object_present_in_ob_by_name(FORCE, "no weapon force", pl)) |
| 1761 |
CLEAR_FLAG(pl, FLAG_USE_WEAPON); |
| 1762 |
|
| 1763 |
} |
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
|
| 1777 |
|
| 1778 |
static int apply_check_apply_restrictions(object *who, object *op, int aflags) { |
| 1779 |
int i; |
| 1780 |
|
| 1781 |
i = apply_can_apply_object(who, op); |
| 1782 |
if (i == 0) |
| 1783 |
return 1; |
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
if (i&CAN_APPLY_NEVER) { |
| 1788 |
if (!(aflags&AP_NOPRINT)) { |
| 1789 |
char name_op[MAX_BUF]; |
| 1790 |
|
| 1791 |
query_name(op, name_op, MAX_BUF); |
| 1792 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_BADBODY, |
| 1793 |
"You don't have the body to use a %s", |
| 1794 |
name_op); |
| 1795 |
} |
| 1796 |
return 0; |
| 1797 |
} |
| 1798 |
|
| 1799 |
if (i&CAN_APPLY_RESTRICTION) { |
| 1800 |
if (!(aflags&AP_NOPRINT)) { |
| 1801 |
char name_op[MAX_BUF]; |
| 1802 |
|
| 1803 |
query_name(op, name_op, MAX_BUF); |
| 1804 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_PROHIBITION, |
| 1805 |
"You have a prohibition against using a %s", |
| 1806 |
name_op); |
| 1807 |
} |
| 1808 |
return 0; |
| 1809 |
} |
| 1810 |
|
| 1811 |
if (who->type != PLAYER) { |
| 1812 |
|
| 1813 |
return !unapply_for_ob(who, op, aflags); |
| 1814 |
} |
| 1815 |
|
| 1816 |
if (who->contr->unapply == unapply_never |
| 1817 |
|| (i&CAN_APPLY_UNAPPLY_CHOICE && who->contr->unapply == unapply_nochoice)) { |
| 1818 |
if (!(aflags&AP_NOPRINT)) |
| 1819 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_UNAPPLY, |
| 1820 |
"You need to unapply some item(s):"); |
| 1821 |
unapply_for_ob(who, op, AP_PRINT); |
| 1822 |
return 0; |
| 1823 |
} |
| 1824 |
|
| 1825 |
if (who->contr->unapply == unapply_always |
| 1826 |
|| !(i&CAN_APPLY_UNAPPLY_CHOICE)) { |
| 1827 |
return !unapply_for_ob(who, op, aflags); |
| 1828 |
} |
| 1829 |
|
| 1830 |
return 1; |
| 1831 |
} |
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
static int apply_check_item_power(const object *who, const object *op, int aflags) { |
| 1846 |
if (who->type != PLAYER) |
| 1847 |
return 1; |
| 1848 |
|
| 1849 |
if (op->item_power == 0 |
| 1850 |
|| op->item_power+who->contr->item_power <= settings.item_power_factor*who->level) |
| 1851 |
return 1; |
| 1852 |
|
| 1853 |
if (!(aflags&AP_NOPRINT)) |
| 1854 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 1855 |
"Equipping that combined with other items would consume your soul!"); |
| 1856 |
return 0; |
| 1857 |
} |
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
static int apply_check_personalized_blessings(object *who, const object *op) { |
| 1874 |
const char *owner; |
| 1875 |
const char *will; |
| 1876 |
long item_will; |
| 1877 |
long margin; |
| 1878 |
const char *msg; |
| 1879 |
int random_effect; |
| 1880 |
int damage_percentile; |
| 1881 |
|
| 1882 |
if (!settings.personalized_blessings) { |
| 1883 |
return 1; |
| 1884 |
} |
| 1885 |
|
| 1886 |
owner = object_get_value(op, "item_owner"); |
| 1887 |
if (owner == NULL || strcmp(owner, who->name) == 0) |
| 1888 |
return 1; |
| 1889 |
|
| 1890 |
will = object_get_value(op, "item_willpower"); |
| 1891 |
item_will = will != NULL ? atol(will) : 0; |
| 1892 |
if (item_will > who->stats.exp) { |
| 1893 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 1894 |
"This %s refuses to serve you - it keeps evading your hand !", |
| 1895 |
op->name); |
| 1896 |
return 0; |
| 1897 |
} |
| 1898 |
|
| 1899 |
margin = item_will != 0 ? who->stats.exp/item_will : who->stats.exp; |
| 1900 |
random_effect = random_roll(0, 100, who, 1)-margin*20; |
| 1901 |
if (random_effect > 80) { |
| 1902 |
msg = "You don't know why, but you have the feeling that the %s is angry at you !"; |
| 1903 |
damage_percentile = 60; |
| 1904 |
} else if (random_effect > 60) { |
| 1905 |
msg = "The %s seems to look at you nastily !"; |
| 1906 |
damage_percentile = 45; |
| 1907 |
} else if (random_effect > 40) { |
| 1908 |
msg = "You have the strange feeling that the %s is annoyed..."; |
| 1909 |
damage_percentile = 30; |
| 1910 |
} else if (random_effect > 20) { |
| 1911 |
msg = "The %s seems tired, or bored, in a way. Very strange !"; |
| 1912 |
damage_percentile = 15; |
| 1913 |
} else if (random_effect > 0) { |
| 1914 |
msg = "You hear the %s sighing !"; |
| 1915 |
damage_percentile = 0; |
| 1916 |
} else { |
| 1917 |
msg = NULL; |
| 1918 |
damage_percentile = 0; |
| 1919 |
} |
| 1920 |
if (msg != NULL) |
| 1921 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 1922 |
msg, op->name); |
| 1923 |
if (damage_percentile > 0) { |
| 1924 |
int weapon_bite = (who->stats.hp*damage_percentile)/100; |
| 1925 |
if (weapon_bite < 1) |
| 1926 |
weapon_bite = 1; |
| 1927 |
who->stats.hp -= weapon_bite; |
| 1928 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_VICTIM, MSG_TYPE_VICTIM_WAS_HIT, |
| 1929 |
"You get a nasty bite in the hand !"); |
| 1930 |
} |
| 1931 |
|
| 1932 |
return 1; |
| 1933 |
} |
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
|
| 1942 |
|
| 1943 |
|
| 1944 |
|
| 1945 |
|
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
static int apply_check_owner(const object *who, const object *op, int aflags) { |
| 1950 |
const char *quotepos; |
| 1951 |
|
| 1952 |
if (op->level == 0) |
| 1953 |
return 1; |
| 1954 |
|
| 1955 |
quotepos = strstr(op->name, "'"); |
| 1956 |
if (quotepos == NULL || strncmp(op->name, who->name, quotepos-op->name) == 0) |
| 1957 |
return 1; |
| 1958 |
|
| 1959 |
if (!(aflags&AP_NOPRINT)) |
| 1960 |
draw_ext_info(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_ERROR, |
| 1961 |
"The weapon does not recognize you as its owner."); |
| 1962 |
return 0; |
| 1963 |
} |
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
static void apply_update_ranged_skill(const object *who, object *op, int aflags) { |
| 1976 |
if (who->type != PLAYER) { |
| 1977 |
return; |
| 1978 |
} |
| 1979 |
|
| 1980 |
who->contr->shoottype = range_skill; |
| 1981 |
who->contr->ranges[range_skill] = op; |
| 1982 |
if (op->invisible) { |
| 1983 |
if (!(aflags&AP_NOPRINT)) |
| 1984 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 1985 |
"Readied skill: %s.", |
| 1986 |
op->skill ? op->skill : op->name); |
| 1987 |
} else { |
| 1988 |
if (!(aflags&AP_NOPRINT)) { |
| 1989 |
char name_op[MAX_BUF]; |
| 1990 |
|
| 1991 |
query_name(op, name_op, MAX_BUF); |
| 1992 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 1993 |
"You ready %s.", |
| 1994 |
name_op); |
| 1995 |
draw_ext_info_format(NDI_UNIQUE, 0, who, MSG_TYPE_APPLY, MSG_TYPE_APPLY_SUCCESS, |
| 1996 |
"You can now use the skill: %s.", |
| 1997 |
op->skill); |
| 1998 |
} |
| 1999 |
} |
| 2000 |
} |