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

Comparing deliantra/server/server/apply.C (file contents):
Revision 1.187 by elmex, Tue Jan 13 13:29:57 2009 UTC vs.
Revision 1.194 by root, Tue May 5 04:51:56 2009 UTC

92 * Return value: 1 if money was destroyed, 0 if not. 92 * Return value: 1 if money was destroyed, 0 if not.
93 */ 93 */
94static int 94static int
95apply_id_altar (object *money, object *altar, object *pl) 95apply_id_altar (object *money, object *altar, object *pl)
96{ 96{
97 dynbuf_text buf; 97 dynbuf_text &buf = msg_dynbuf; buf.clear ();
98 98
99 if (!pl || pl->type != PLAYER) 99 if (!pl || pl->type != PLAYER)
100 return 0; 100 return 0;
101 101
102 /* Check for MONEY type is a special hack - it prevents 'nothing needs 102 /* Check for MONEY type is a special hack - it prevents 'nothing needs
396/**************************************************************************** 396/****************************************************************************
397 * Weapon improvement code follows 397 * Weapon improvement code follows
398 ****************************************************************************/ 398 ****************************************************************************/
399 399
400/** 400/**
401 * This function just checks whether who can handle equipping an item
402 * with item_power.
403 */
404
405bool
406check_item_power (object *who, int item_power)
407{
408 if (who->type == PLAYER
409 && item_power
410 && item_power + who->contr->item_power > settings.item_power_factor * who->level)
411 return false;
412 else
413 return true;
414}
415
416/**
401 * This returns the sum of nrof of item (arch name). 417 * This returns the sum of nrof of item (arch name).
402 */ 418 */
403static int 419static int
404check_item (object *op, shstr_cmp item) 420check_item (object *op, shstr_cmp item)
405{ 421{
450 } 466 }
451 467
452 prev = op; 468 prev = op;
453 op = op->below; 469 op = op->below;
454 } 470 }
455}
456
457/**
458 * This checks to see of the player (who) is sufficient level to use a weapon
459 * with improvs improvements (typically last_eat). We take an int here
460 * instead of the object so that the improvement code can pass along the
461 * increased value to see if the object is usuable.
462 * we return 1 (true) if the player can use the weapon.
463 */
464static int
465check_weapon_power (const object *who, int improvs)
466{
467/* Old code is below (commented out). Basically, since weapons are the only
468 * object players really have any control to improve, it's a bit harsh to
469 * require high level in some combat skill, so we just use overall level.
470 */
471#if 1
472 if (((who->level / 5) + 5) >= improvs)
473 return 1;
474 else
475 return 0;
476
477#else
478 int level = 0;
479
480 /* The skill system hands out wc and dam bonuses to fighters
481 * more generously than the old system (see fix_player). Thus
482 * we need to curtail the power of player enchanted weapons.
483 * I changed this to 1 improvement per "fighter" level/5 -b.t.
484 * Note: Nothing should break by allowing this ratio to be different or
485 * using normal level - it is just a matter of play balance.
486 */
487 if (who->type == PLAYER)
488 {
489 object *wc_obj = NULL;
490
491 for (wc_obj = who->inv; wc_obj; wc_obj = wc_obj->below)
492 if (wc_obj->type == SKILL && IS_COMBAT_SKILL (wc_obj->subtype) && wc_obj->level > level)
493 level = wc_obj->level;
494
495 if (!level)
496 {
497 LOG (llevError, "Error: Player: %s lacks wc experience object\n", who->name);
498 level = who->level;
499 }
500 }
501 else
502 level = who->level;
503
504 return (improvs <= ((level / 5) + 5));
505#endif
506} 471}
507 472
508/** 473/**
509 * Returns how many items of type improver->slaying there are under op. 474 * Returns how many items of type improver->slaying there are under op.
510 * Will display a message if none found, and 1 if improver->slaying is NULL. 475 * Will display a message if none found, and 1 if improver->slaying is NULL.
639 if (improver->stats.sp == IMPROVE_PREPARE) 604 if (improver->stats.sp == IMPROVE_PREPARE)
640 return prepare_weapon (op, improver, weapon); 605 return prepare_weapon (op, improver, weapon);
641 606
642 if (weapon->level == 0) 607 if (weapon->level == 0)
643 { 608 {
644 op->failmsg ("This weapon has not been prepared. H<You first ahve to prepare a weapon with a prepare weapon scroll.>"); 609 op->failmsg (
610 "This weapon has not been prepared."
611 " H<You first have to prepare a weapon with a prepare weapon scroll.>");
645 return 0; 612 return 0;
646 } 613 }
647 614
648 if (weapon->level == weapon->last_eat && weapon->item_power >= 100) 615 if (weapon->last_eat >= weapon->level // improvements used up
616 || weapon->item_power >= 100) // or item_power >= arbitrary limit of 100
649 { 617 {
650 op->failmsg ("This weapon cannot be improved any more."); 618 op->failmsg ("This weapon cannot be improved any more.");
651 return 0; 619 return 0;
652 } 620 }
653 621
654 if (QUERY_FLAG (weapon, FLAG_APPLIED) && !check_weapon_power (op, weapon->last_eat + 1)) 622 if (QUERY_FLAG (weapon, FLAG_APPLIED)
623 && !check_item_power (op, weapon->item_power + 1))
655 { 624 {
656 op->failmsg ("Improving the weapon will make it too " 625 op->failmsg ("Improving the weapon will make it too "
657 "powerful for you to use. Unready it if you " 626 "powerful for you to use. Unready it if you "
658 "really want to improve it."); 627 "really want to improve it.");
659 return 0; 628 return 0;
1776 LOG (llevError, "apply_spellbook: Book %s has no spell in it!\n", &tmp->name); 1745 LOG (llevError, "apply_spellbook: Book %s has no spell in it!\n", &tmp->name);
1777 op->failmsg ("The spellbook symbols make no sense. This is a bug, please report!"); 1746 op->failmsg ("The spellbook symbols make no sense. This is a bug, please report!");
1778 return; 1747 return;
1779 } 1748 }
1780 1749
1781 if (skop->level < int (sqrtf (spell->level) * 1.5f)) 1750 int learn_level = sqrtf (spell->level) * 1.5f;
1751 if (skop->level < learn_level)
1782 { 1752 {
1783 op->failmsg (format ("You are unable to decipher the strange symbols. H<Your %s level is too low.>", &tmp->skill)); 1753 op->failmsg (format ("You are unable to decipher the strange symbols. H<Your %s level is too low, it must be at least %d.>",
1754 &tmp->skill, learn_level));
1784 return; 1755 return;
1785 } 1756 }
1786 1757
1787 op->statusmsg (format ("The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name)); 1758 op->statusmsg (format ("The spellbook contains the %s level spell %s.", get_levelnumber (spell->level), &spell->name));
1788 1759
2339/** 2310/**
2340 * This function will try to apply a lighter and in case no lighter 2311 * This function will try to apply a lighter and in case no lighter
2341 * is specified it will try to find a lighter in the players inventory, 2312 * is specified it will try to find a lighter in the players inventory,
2342 * and inform him about this requirement. 2313 * and inform him about this requirement.
2343 * 2314 *
2344 * who - the player 2315 * who - the player
2345 * op - the item we want to light 2316 * op - the item we want to light
2346 * ligher - the lighter or 0 if a lighter has yet to be found 2317 * lighter - the lighter or 0 if a lighter has yet to be found
2347 */ 2318 */
2319static object *
2348object *auto_apply_lighter (object *who, object *op, object *lighter) 2320auto_apply_lighter (object *who, object *op, object *lighter)
2349{ 2321{
2350 if (lighter == 0) 2322 if (lighter == 0)
2351 { 2323 {
2352 for (object *tmp = who->inv; tmp; tmp = tmp->below) 2324 for (object *tmp = who->inv; tmp; tmp = tmp->below)
2353 { 2325 {
2400 int is_player_env = 0; 2372 int is_player_env = 0;
2401 2373
2402 item = find_marked_object (who); 2374 item = find_marked_object (who);
2403 if (item) 2375 if (item)
2404 { 2376 {
2405 if (!auto_apply_lighter (who, 0, lighter)) 2377 if (!auto_apply_lighter (who, item, lighter))
2406 return; 2378 return;
2407 2379
2408 /* Perhaps we should split what we are trying to light on fire? 2380 /* Perhaps we should split what we are trying to light on fire?
2409 * I can't see many times when you would want to light multiple 2381 * I can't see many times when you would want to light multiple
2410 * objects at once. 2382 * objects at once.
3390 * skill so that the dam and wc get updated 3362 * skill so that the dam and wc get updated
3391 */ 3363 */
3392 who->change_skill (skop); 3364 who->change_skill (skop);
3393 } 3365 }
3394 3366
3395 if (who->type == PLAYER 3367 if (!check_item_power (who, op->item_power))
3396 && op->item_power
3397 && op->item_power + who->contr->item_power > settings.item_power_factor * who->level)
3398 { 3368 {
3399 who->failmsg ("Equipping that combined with other items would consume your soul!" LACK_ITEM_POWER); 3369 who->failmsg ("Equipping that combined with other items would consume your soul!" LACK_ITEM_POWER);
3400 return 1; 3370 return 1;
3401 } 3371 }
3402 3372
3410 return RESULT_INT (0); 3380 return RESULT_INT (0);
3411 3381
3412 switch (op->type) 3382 switch (op->type)
3413 { 3383 {
3414 case WEAPON: 3384 case WEAPON:
3415 if (!check_weapon_power (who, op->last_eat))
3416 {
3417 op->failmsg ("This weapon is too powerful for you to use. It would consume your soul!" LACK_ITEM_POWER);
3418
3419 if (tmp)
3420 insert_ob_in_ob (tmp, who);
3421
3422 return 1;
3423 }
3424
3425 //TODO: this obviously fails for players using a shorter prefix 3385 //TODO: this obviously fails for players using a shorter prefix
3426 // i.e. "R" can use Ragnarok's sword. 3386 // i.e. "R" can use Ragnarok's sword.
3427 if (op->level && !op->name.starts_with (who->name)) 3387 if (op->level && !op->name.starts_with (who->name))
3428 { 3388 {
3429 /* if the weapon does not have the name as the character, can't use it. */ 3389 /* if the weapon does not have the name as the character, can't use it. */
3555 } 3515 }
3556 3516
3557 break; 3517 break;
3558 3518
3559 case BOW: 3519 case BOW:
3560 if (!check_weapon_power (who, op->last_eat))
3561 {
3562 who->failmsg ("That weapon is too powerful for you to use. It would consume your soul!" LACK_ITEM_POWER);
3563
3564 if (tmp)
3565 insert_ob_in_ob (tmp, who);
3566
3567 return 1;
3568 }
3569
3570 if (op->level && !op->name.starts_with (who->name)) 3520 if (op->level && !op->name.starts_with (who->name))
3571 { 3521 {
3572 who->failmsg ("The weapon does not recognize you as its owner. " 3522 who->failmsg ("The weapon does not recognize you as its owner. "
3573 "H<Its name indicates that it belongs to somebody else.>"); 3523 "H<Its name indicates that it belongs to somebody else.>");
3574 if (tmp) 3524 if (tmp)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines