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

Comparing deliantra/server/common/living.C (file contents):
Revision 1.82 by root, Mon Apr 21 23:35:24 2008 UTC vs.
Revision 1.112 by root, Sun Mar 28 16:41:45 2010 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation, either version 3 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
20 * 21 *
21 * The authors can be reached via e-mail to <support@deliantra.net> 22 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 23 */
23 24
24#include <global.h> 25#include <global.h>
261/* Rather than having a whole bunch of if (flag) new_draw.. else new_draw, 262/* Rather than having a whole bunch of if (flag) new_draw.. else new_draw,
262 * make this macro to clean those up. Not usuable outside change_abil 263 * make this macro to clean those up. Not usuable outside change_abil
263 * function since some of the values passed to new_draw_info are hardcoded. 264 * function since some of the values passed to new_draw_info are hardcoded.
264 */ 265 */
265#define DIFF_MSG(flag, msg1, msg2) \ 266#define DIFF_MSG(flag, msg1, msg2) \
266 new_draw_info(NDI_UNIQUE, 0, op, (flag>0)?msg1:msg2); 267 new_draw_info (NDI_UNIQUE, 0, op, (flag > 0) ? msg1 : msg2);
267 268
268/* return 1 if we sucessfully changed a stat, 0 if nothing was changed. */ 269/* return 1 if we sucessfully changed a stat, 0 if nothing was changed. */
269 270
270/* flag is set to 1 if we are applying the object, -1 if we are removing 271/* flag is set to 1 if we are applying the object, -1 if we are removing
271 * the object. 272 * the object.
279 * that gives them that ability. 280 * that gives them that ability.
280 */ 281 */
281int 282int
282change_abil (object *op, object *tmp) 283change_abil (object *op, object *tmp)
283{ 284{
284 int flag = QUERY_FLAG (tmp, FLAG_APPLIED) ? 1 : -1, success = 0; 285 int flag = tmp->flag [FLAG_APPLIED] ? 1 : -1;
286 int success = 0;
285 char message[MAX_BUF]; 287 char message[MAX_BUF];
286 int potion_max = 0; 288 int potion_max = 0;
287 289
288 /* remember what object was like before it was changed. note that 290 // keep some stats for comparison purposes
289 * refop is a local copy of op only to be used for detecting changes 291 object::flags_t prev_flag = op->flag;
290 * found by update_stats. refop is not a real object 292 MoveType prev_move_type = op->move_type;
291 */ 293 sint16 prev_resist [NROFATTACKS]; // clumsy
292 object_copy refop = *op; 294 assert (sizeof (prev_resist) == sizeof (op->resist));
295 memcpy (prev_resist, op->resist, sizeof (prev_resist));
293 296
294 if (op->type == PLAYER) 297 if (op->type == PLAYER)
295 { 298 {
296 if (tmp->type == POTION) 299 if (tmp->type == POTION)
297 { 300 {
298 potion_max = 1; 301 potion_max = 1;
302
299 for (int j = 0; j < NUM_STATS; j++) 303 for (int j = 0; j < NUM_STATS; j++)
300 { 304 {
301 int ostat = op->contr->orig_stats.stat (j); 305 int ostat = op->contr->orig_stats.stat (j);
302 int i = tmp->stats.stat (j); 306 int i = tmp->stats.stat (j);
303 307
304 /* nstat is what the stat will be after use of the potion */ 308 /* nstat is what the stat will be after use of the potion */
305 int nstat = flag * i + ostat; 309 int nstat = flag * i + ostat;
306 310
307 /* Do some bounds checking. While I don't think any 311 /* Do some bounds checking. There is the potential for potions
308 * potions do so right now, there is the potential for potions
309 * that adjust that stat by more than one point, so we need 312 * that adjust that stat by more than one point, so we need
310 * to allow for that. 313 * to allow for that.
311 */ 314 */
312 if (nstat < 1 && i * flag < 0) 315 if (nstat < 1 && i * flag < 0)
313 nstat = 1; 316 nstat = 1;
365 { 368 {
366 success = 1; 369 success = 1;
367 DIFF_MSG (flag, "Your hands begin to glow red.", "Your hands stop glowing red."); 370 DIFF_MSG (flag, "Your hands begin to glow red.", "Your hands stop glowing red.");
368 } 371 }
369 372
370 if (QUERY_FLAG (op, FLAG_LIFESAVE) != QUERY_FLAG (&refop, FLAG_LIFESAVE)) 373 if (op->flag [FLAG_LIFESAVE] != prev_flag [FLAG_LIFESAVE])
371 { 374 {
372 success = 1; 375 success = 1;
373 DIFF_MSG (flag, "You feel very protected.", "You don't feel protected anymore."); 376 DIFF_MSG (flag, "You feel very protected.", "You don't feel protected anymore.");
374 } 377 }
375 378
376 if (QUERY_FLAG (op, FLAG_REFL_MISSILE) != QUERY_FLAG (&refop, FLAG_REFL_MISSILE)) 379 if (op->flag [FLAG_REFL_MISSILE] != prev_flag [FLAG_REFL_MISSILE])
377 { 380 {
378 success = 1; 381 success = 1;
379 DIFF_MSG (flag, "A magic force shimmers around you.", "The magic force fades away."); 382 DIFF_MSG (flag, "A magic force shimmers around you.", "The magic force fades away.");
380 } 383 }
381 384
382 if (QUERY_FLAG (op, FLAG_REFL_SPELL) != QUERY_FLAG (&refop, FLAG_REFL_SPELL)) 385 if (op->flag [FLAG_REFL_SPELL] != prev_flag [FLAG_REFL_SPELL])
383 { 386 {
384 success = 1; 387 success = 1;
385 DIFF_MSG (flag, "You feel more safe now, somehow.", "Suddenly you feel less safe, somehow."); 388 DIFF_MSG (flag, "You feel more safe now, somehow.", "Suddenly you feel less safe, somehow.");
386 } 389 }
387 390
389 * user has multiple items giving the same type appled like we 392 * user has multiple items giving the same type appled like we
390 * used to - that is more work than what we gain, plus messages 393 * used to - that is more work than what we gain, plus messages
391 * can be misleading (a little higher could be miscontrued from 394 * can be misleading (a little higher could be miscontrued from
392 * from fly high) 395 * from fly high)
393 */ 396 */
394 if (tmp->move_type && op->move_type != refop.move_type) 397 if (tmp->move_type && op->move_type != prev_move_type)
395 { 398 {
396 success = 1; 399 success = 1;
397 400
398 /* MOVE_FLY_HIGH trumps MOVE_FLY_LOW - changing your move_fly_low 401 /* MOVE_FLY_HIGH trumps MOVE_FLY_LOW - changing your move_fly_low
399 * status doesn't make a difference if you are flying high 402 * status doesn't make a difference if you are flying high
400 */ 403 */
401 if (tmp->move_type & MOVE_FLY_LOW && !(op->move_type & MOVE_FLY_HIGH)) 404 if (tmp->move_type & MOVE_FLY_LOW && !(op->move_type & MOVE_FLY_HIGH))
402 { 405 {
403 DIFF_MSG (flag, "You start to float in the air!.", "You float down to the ground."); 406 DIFF_MSG (flag, "You start to float in the air!", "You float down to the ground.");
404 } 407 }
405 408
406 if (tmp->move_type & MOVE_FLY_HIGH) 409 if (tmp->move_type & MOVE_FLY_HIGH)
407 { 410 {
408 /* double conditional - second case covers if you have move_fly_low - 411 /* double conditional - second case covers if you have move_fly_low -
412 (op->move_type & MOVE_FLY_LOW ? "You fly lower in the air" : "You float down to the ground.")); 415 (op->move_type & MOVE_FLY_LOW ? "You fly lower in the air" : "You float down to the ground."));
413 } 416 }
414 417
415 if (tmp->move_type & MOVE_SWIM) 418 if (tmp->move_type & MOVE_SWIM)
416 DIFF_MSG (flag, "You feel ready for a swim", "You no longer feel like swimming"); 419 DIFF_MSG (flag, "You feel ready for a swim", "You no longer feel like swimming");
417
418 /* Changing move status may mean you are affected by things you weren't before */
419 check_move_on (op, op);
420 } 420 }
421 421
422 /* becoming UNDEAD... a special treatment for this flag. Only those not 422 /* becoming UNDEAD... a special treatment for this flag. Only those not
423 * originally undead may change their status 423 * originally undead may change their status
424 */ 424 */
425 if (!QUERY_FLAG (op->arch, FLAG_UNDEAD)) 425 if (!op->arch->flag [FLAG_UNDEAD])
426 if (QUERY_FLAG (op, FLAG_UNDEAD) != QUERY_FLAG (&refop, FLAG_UNDEAD)) 426 if (op->flag [FLAG_UNDEAD] != prev_flag [FLAG_UNDEAD])
427 { 427 {
428 success = 1; 428 success = 1;
429 if (flag > 0) 429 if (flag > 0)
430 { 430 {
431 op->race = "undead"; 431 op->race = "undead";
436 op->race = op->arch->race; 436 op->race = op->arch->race;
437 new_draw_info (NDI_UNIQUE, 0, op, "Your lifeforce returns!"); 437 new_draw_info (NDI_UNIQUE, 0, op, "Your lifeforce returns!");
438 } 438 }
439 } 439 }
440 440
441 if (QUERY_FLAG (op, FLAG_STEALTH) != QUERY_FLAG (&refop, FLAG_STEALTH)) 441 if (op->flag [FLAG_STEALTH] != prev_flag [FLAG_STEALTH])
442 { 442 {
443 success = 1; 443 success = 1;
444 DIFF_MSG (flag, "You walk more quietly.", "You walk more noisily."); 444 DIFF_MSG (flag, "You walk more quietly.", "You walk more noisily.");
445 } 445 }
446 446
447 if (QUERY_FLAG (op, FLAG_MAKE_INVIS) != QUERY_FLAG (&refop, FLAG_MAKE_INVIS)) 447 if (op->flag [FLAG_MAKE_INVIS] != prev_flag [FLAG_MAKE_INVIS])
448 { 448 {
449 success = 1; 449 success = 1;
450 DIFF_MSG (flag, "You become transparent.", "You can see yourself."); 450 DIFF_MSG (flag, "You become transparent.", "You can see yourself.");
451 } 451 }
452 452
453 /* blinded you can tell if more blinded since blinded player has minimal 453 /* blinded you can tell if more blinded since blinded player has minimal
454 * vision 454 * vision
455 */ 455 */
456 if (QUERY_FLAG (tmp, FLAG_BLIND)) 456 if (tmp->flag [FLAG_BLIND])
457 { 457 {
458 success = 1; 458 success = 1;
459 if (flag > 0) 459 if (flag > 0)
460 { 460 {
461 if (QUERY_FLAG (op, FLAG_WIZ)) 461 if (op->flag [FLAG_WIZ])
462 new_draw_info (NDI_UNIQUE, 0, op, "Your mortal self is blinded."); 462 new_draw_info (NDI_UNIQUE, 0, op, "Your mortal self is blinded.");
463 else 463 else
464 { 464 {
465 new_draw_info (NDI_UNIQUE, 0, op, "You are blinded."); 465 new_draw_info (NDI_UNIQUE, 0, op, "You are blinded.");
466 SET_FLAG (op, FLAG_BLIND); 466 SET_FLAG (op, FLAG_BLIND);
468 op->contr->do_los = 1; 468 op->contr->do_los = 1;
469 } 469 }
470 } 470 }
471 else 471 else
472 { 472 {
473 if (QUERY_FLAG (op, FLAG_WIZ)) 473 if (op->flag [FLAG_WIZ])
474 new_draw_info (NDI_UNIQUE, 0, op, "Your mortal self can now see again."); 474 new_draw_info (NDI_UNIQUE, 0, op, "Your mortal self can now see again.");
475 else 475 else
476 { 476 {
477 new_draw_info (NDI_UNIQUE, 0, op, "Your vision returns."); 477 new_draw_info (NDI_UNIQUE, 0, op, "Your vision returns.");
478 CLEAR_FLAG (op, FLAG_BLIND); 478 CLEAR_FLAG (op, FLAG_BLIND);
480 op->contr->do_los = 1; 480 op->contr->do_los = 1;
481 } 481 }
482 } 482 }
483 } 483 }
484 484
485 if (QUERY_FLAG (op, FLAG_SEE_IN_DARK) != QUERY_FLAG (&refop, FLAG_SEE_IN_DARK)) 485 if (op->flag [FLAG_SEE_IN_DARK] != prev_flag [FLAG_SEE_IN_DARK])
486 { 486 {
487 success = 1; 487 success = 1;
488 if (op->type == PLAYER) 488 if (op->type == PLAYER)
489 op->contr->do_los = 1; 489 op->contr->do_los = 1;
490 DIFF_MSG (flag, "Your vision is better in the dark.", "You see less well in the dark."); 490 DIFF_MSG (flag, "Your vision is better in the dark.", "You see less well in the dark.");
491 } 491 }
492 492
493 if (QUERY_FLAG (op, FLAG_XRAYS) != QUERY_FLAG (&refop, FLAG_XRAYS)) 493 if (op->flag [FLAG_XRAYS] != prev_flag [FLAG_XRAYS])
494 { 494 {
495 success = 1; 495 success = 1;
496 if (flag > 0) 496 if (flag > 0)
497 { 497 {
498 if (QUERY_FLAG (op, FLAG_WIZ)) 498 if (op->flag [FLAG_WIZ])
499 new_draw_info (NDI_UNIQUE, 0, op, "Your vision becomes a little clearer."); 499 new_draw_info (NDI_UNIQUE, 0, op, "Your vision becomes a little clearer.");
500 else 500 else
501 { 501 {
502 new_draw_info (NDI_UNIQUE, 0, op, "Everything becomes transparent."); 502 new_draw_info (NDI_UNIQUE, 0, op, "Everything becomes transparent.");
503 if (op->type == PLAYER) 503 if (op->type == PLAYER)
504 op->contr->do_los = 1; 504 op->contr->do_los = 1;
505 } 505 }
506 } 506 }
507 else 507 else
508 { 508 {
509 if (QUERY_FLAG (op, FLAG_WIZ)) 509 if (op->flag [FLAG_WIZ])
510 new_draw_info (NDI_UNIQUE, 0, op, "Your vision becomes a bit out of focus."); 510 new_draw_info (NDI_UNIQUE, 0, op, "Your vision becomes a bit out of focus.");
511 else 511 else
512 { 512 {
513 new_draw_info (NDI_UNIQUE, 0, op, "Everything suddenly looks very solid."); 513 new_draw_info (NDI_UNIQUE, 0, op, "Everything suddenly looks very solid.");
514 if (op->type == PLAYER) 514 if (op->type == PLAYER)
552 for (int i = 0; i < NROFATTACKS; i++) 552 for (int i = 0; i < NROFATTACKS; i++)
553 { 553 {
554 if (i == ATNR_PHYSICAL) 554 if (i == ATNR_PHYSICAL)
555 continue; /* Don't display about armour */ 555 continue; /* Don't display about armour */
556 556
557 if (op->resist[i] != refop.resist[i]) 557 if (op->resist [i] != prev_resist [i])
558 { 558 {
559 success = 1; 559 success = 1;
560
560 if (op->resist[i] > refop.resist[i]) 561 if (op->resist [i] > prev_resist [i])
561 sprintf (message, "Your resistance to %s rises to %d%%.", change_resist_msg[i], op->resist[i]); 562 sprintf (message, "Your resistance to %s rises to %d%%.", change_resist_msg [i], op->resist [i]);
562 else 563 else
563 sprintf (message, "Your resistance to %s drops to %d%%.", change_resist_msg[i], op->resist[i]); 564 sprintf (message, "Your resistance to %s drops to %d%%.", change_resist_msg [i], op->resist [i]);
564 565
565 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, op, message); 566 new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, op, message);
566 } 567 }
567 } 568 }
568 569
569 if (!potion_max) 570 if (!potion_max)
570 {
571 for (int j = 0; j < NUM_STATS; j++) 571 for (int j = 0; j < NUM_STATS; j++)
572 {
573 if (int i = tmp->stats.stat (j)) 572 if (int i = tmp->stats.stat (j))
574 { 573 {
575 success = 1; 574 success = 1;
576 DIFF_MSG (i * flag, gain_msg[j], lose_msg[j]); 575 DIFF_MSG (i * flag, gain_msg[j], lose_msg[j]);
577 } 576 }
578 }
579 }
580 577
581 return success; 578 return success;
582} 579}
583 580
584/* 581/*
595object::drain_specific_stat (int deplete_stats) 592object::drain_specific_stat (int deplete_stats)
596{ 593{
597 object *tmp; 594 object *tmp;
598 archetype *at; 595 archetype *at;
599 596
600 at = archetype::find (ARCH_DEPLETION); 597 at = archetype::find (shstr_depletion);
601 if (!at) 598 if (!at)
602 { 599 {
603 LOG (llevError, "Couldn't find archetype depletion.\n"); 600 LOG (llevError, "Couldn't find archetype depletion.\n");
604 return; 601 return;
605 } 602 }
607 { 604 {
608 tmp = present_arch_in_ob (at, this); 605 tmp = present_arch_in_ob (at, this);
609 606
610 if (!tmp) 607 if (!tmp)
611 { 608 {
612 tmp = arch_to_object (at); 609 tmp = at->instance ();
613 tmp = insert_ob_in_ob (tmp, this); 610 tmp = insert_ob_in_ob (tmp, this);
614 SET_FLAG (tmp, FLAG_APPLIED); 611 SET_FLAG (tmp, FLAG_APPLIED);
615 } 612 }
616 } 613 }
617 614
625 * via an applied bad_luck object. 622 * via an applied bad_luck object.
626 */ 623 */
627void 624void
628object::change_luck (int value) 625object::change_luck (int value)
629{ 626{
630 archetype *at = archetype::find ("luck"); 627 archetype *at = archetype::find (shstr_luck);
631 if (!at) 628 if (!at)
632 LOG (llevError, "Couldn't find archetype luck.\n"); 629 LOG (llevError, "Couldn't find archetype luck.\n");
633 else 630 else
634 { 631 {
635 object *tmp = present_arch_in_ob (at, this); 632 object *tmp = present_arch_in_ob (at, this);
637 if (!tmp) 634 if (!tmp)
638 { 635 {
639 if (!value) 636 if (!value)
640 return; 637 return;
641 638
642 tmp = arch_to_object (at); 639 tmp = at->instance ();
643 tmp = insert_ob_in_ob (tmp, this); 640 tmp = insert_ob_in_ob (tmp, this);
644 SET_FLAG (tmp, FLAG_APPLIED); 641 SET_FLAG (tmp, FLAG_APPLIED);
645 } 642 }
646 643
647 if (value) 644 if (value)
764 int prot[NROFATTACKS], vuln[NROFATTACKS], potion_resist[NROFATTACKS]; 761 int prot[NROFATTACKS], vuln[NROFATTACKS], potion_resist[NROFATTACKS];
765 object *grace_obj = NULL, *mana_obj = NULL, *tmp; 762 object *grace_obj = NULL, *mana_obj = NULL, *tmp;
766 float old_speed = speed; 763 float old_speed = speed;
767 int stat_sum [NUM_STATS]; 764 int stat_sum [NUM_STATS];
768 765
766 MoveType move_type; // we use change_move_type to change it, so use a local copy
767
769 /* First task is to clear all the values back to their original values */ 768 /* First task is to clear all the values back to their original values */
770 if (type == PLAYER) 769 if (type == PLAYER)
771 { 770 {
771 contr->delayed_update = false;
772
772 for (int i = 0; i < NUM_STATS; i++) 773 for (int i = 0; i < NUM_STATS; i++)
773 stat_sum [i] = contr->orig_stats.stat (i); 774 stat_sum [i] = contr->orig_stats.stat (i);
774 775
775 if (settings.spell_encumbrance == TRUE) 776 if (settings.spell_encumbrance == TRUE)
776 contr->encumbrance = 0; 777 contr->encumbrance = 0;
809 path_repelled = arch->path_repelled; 810 path_repelled = arch->path_repelled;
810 path_denied = arch->path_denied; 811 path_denied = arch->path_denied;
811 glow_radius = arch->glow_radius; 812 glow_radius = arch->glow_radius;
812 move_type = arch->move_type; 813 move_type = arch->move_type;
813 814
814 chosen_skill = 0; 815 object *chosen_skill = 0;
815 816
816 /* initializing resistances from the values in player/monster's 817 /* initializing resistances from the values in player/monster's
817 * archetype clone 818 * archetype clone
818 */ 819 */
819 memcpy (&resist, &arch->resist, sizeof (resist)); 820 memcpy (&resist, &arch->resist, sizeof (resist));
859 * then calls this function. 860 * then calls this function.
860 */ 861 */
861 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == POTION) 862 if (QUERY_FLAG (tmp, FLAG_APPLIED) && tmp->type == POTION)
862 continue; 863 continue;
863 864
864 /* See note in map.c:update_position about making this additive
865 * since light sources are never applied, need to put check here.
866 */
867 if (tmp->glow_radius > glow_radius)
868 glow_radius = tmp->glow_radius; 865 glow_radius += tmp->glow_radius;
869 866
870 /* For some things, we don't care what is equipped */ 867 /* For some things, we don't care what is equipped */
871 if (tmp->type == SKILL) 868 if (tmp->type == SKILL)
872 { 869 {
873 /* Want to take the highest skill here. */ 870 /* Want to take the highest skill here. */
886 else if (tmp->level > grace_obj->level) 883 else if (tmp->level > grace_obj->level)
887 grace_obj = tmp; 884 grace_obj = tmp;
888 } 885 }
889 } 886 }
890 887
891 /* Container objects are not meant to adjust a players, but other applied 888 /* Container objects are not meant to adjust players, but other applied
892 * objects need to make adjustments. 889 * objects need to make adjustments.
893 * This block should handle all player specific changes 890 * This block should handle all player specific changes
894 * The check for Praying is a bit of a hack - god given bonuses are put 891 * The check for Praying is a bit of a hack - god given bonuses are put
895 * in the praying skill, and the player should always get those. 892 * in the praying skill, and the player should always get those.
896 * It also means we need to put in additional checks for applied below, 893 * It also means we need to put in additional checks for applied below,
898 * up, etc. 895 * up, etc.
899 */ 896 */
900 if ((tmp->flag [FLAG_APPLIED] 897 if ((tmp->flag [FLAG_APPLIED]
901 && tmp->type != CONTAINER 898 && tmp->type != CONTAINER
902 && tmp->type != CLOSE_CON) 899 && tmp->type != CLOSE_CON)
903 || (tmp->type == SKILL
904 && tmp->subtype == SK_PRAYING)) 900 || (tmp->type == SKILL && tmp->subtype == SK_PRAYING))
905 { 901 {
906 if (type == PLAYER) 902 if (type == PLAYER)
907 { 903 {
908 contr->item_power += tmp->item_power; 904 contr->item_power += tmp->item_power;
909 905
913 && !tmp->flag [FLAG_CURSED] 909 && !tmp->flag [FLAG_CURSED]
914 && !tmp->flag [FLAG_DAMNED]) 910 && !tmp->flag [FLAG_DAMNED])
915 continue; 911 continue;
916 912
917 for (int i = 0; i < NUM_STATS; i++) 913 for (int i = 0; i < NUM_STATS; i++)
918 stat_sum [i] = stat_sum [i] + tmp->stats.stat (i); 914 stat_sum [i] += tmp->stats.stat (i);
919 915
920 if (digest_types [tmp->type]) 916 if (digest_types [tmp->type])
921 { 917 {
922 contr->digestion += tmp->stats.food; 918 contr->digestion += tmp->stats.food;
923 contr->gen_hp += tmp->stats.hp; 919 contr->gen_hp += tmp->stats.hp;
920 if (tmp->type != BOW) // ugly exception for bows
924 contr->gen_sp += tmp->stats.sp; 921 contr->gen_sp += tmp->stats.sp;
925 contr->gen_grace += tmp->stats.grace; 922 contr->gen_grace += tmp->stats.grace;
926 contr->gen_sp_armour += tmp->gen_sp_armour; 923 contr->gen_sp_armour += tmp->gen_sp_armour;
927 } 924 }
928 } /* if this is a player */ 925 } /* if this is a player */
929 else 926 else
931 if (tmp->type == WEAPON) 928 if (tmp->type == WEAPON)
932 current_weapon = tmp; 929 current_weapon = tmp;
933 } 930 }
934 931
935 /* Update slots used for items */ 932 /* Update slots used for items */
936 if (QUERY_FLAG (tmp, FLAG_APPLIED)) 933 if (tmp->flag [FLAG_APPLIED])
937 for (int i = 0; i < NUM_BODY_LOCATIONS; i++) 934 for (int i = 0; i < NUM_BODY_LOCATIONS; i++)
938 slot[i].used += tmp->slot[i].info; 935 slot[i].used += tmp->slot[i].info;
939 936
940 if (tmp->type == SYMPTOM) 937 if (tmp->type == SYMPTOM)
941 speed_reduce_from_disease =
942 min (speed_reduce_from_disease, tmp->last_sp ? tmp->last_sp / 100.f : 1.f); 938 min_it (speed_reduce_from_disease, tmp->last_sp ? tmp->last_sp / 100.f : 1.f);
943 939
944 /* Pos. and neg. protections are counted seperate (-> pro/vuln). 940 /* Pos. and neg. protections are counted separate (-> pro/vuln).
945 * (Negative protections are calculated exactly like positive.) 941 * (Negative protections are calculated exactly like positive.)
946 * Resistance from potions are treated special as well. If there's 942 * Resistance from potions are treated special as well. If there's
947 * more than one potion-effect, the bigger prot.-value is taken. 943 * more than one potion-effect, the bigger prot.-value is taken.
948 */ 944 */
949 if (tmp->type != POTION) 945 if (tmp->type == POTION_EFFECT)
950 {
951 for (int i = 0; i < NROFATTACKS; i++) 946 for (int i = 0; i < NROFATTACKS; i++)
952 { 947 {
953 /* Potential for cursed potions, in which case we just can use 948 /* Potential for cursed potions, in which case we just can use
954 * a straight MAX, as potion_resist is initialised to zero. 949 * a straight MAX, as potion_resist is initialised to zero.
950 // TODO: this is askign for a magic marker optimisation
955 */ 951 */
956 if (tmp->type == POTION_EFFECT)
957 {
958 if (potion_resist[i]) 952 if (potion_resist[i])
959 potion_resist[i] = max (potion_resist[i], tmp->resist[i]); 953 max_it (potion_resist[i], tmp->resist[i]);
960 else 954 else
961 potion_resist[i] = tmp->resist[i]; 955 potion_resist[i] = tmp->resist[i];
962 } 956 }
957 else if (tmp->type != POTION)
958 for (int i = 0; i < NROFATTACKS; i++)
963 else if (tmp->resist[i] > 0) 959 if (tmp->resist[i] > 0)
964 prot[i] += ((100 - prot[i]) * tmp->resist[i]) / 100; 960 prot[i] += ((100 - prot[i]) * tmp->resist[i]) / 100;
965 else if (tmp->resist[i] < 0) 961 else if (tmp->resist[i] < 0)
966 vuln[i] += ((100 - vuln[i]) * -tmp->resist[i]) / 100; 962 vuln[i] += ((100 - vuln[i]) * -tmp->resist[i]) / 100;
967 }
968 }
969 963
970 /* There may be other things that should not adjust the attacktype */ 964 /* There may be other things that should not adjust the attacktype */
971 if (tmp->type != SYMPTOM) 965 if (tmp->type != SYMPTOM)
972 { 966 {
973 attacktype |= tmp->attacktype; 967 attacktype |= tmp->attacktype;
1000 added_speed += tmp->stats.exp; 994 added_speed += tmp->stats.exp;
1001 } 995 }
1002 996
1003 switch (tmp->type) 997 switch (tmp->type)
1004 { 998 {
1005#if 0
1006 case WAND:
1007 case ROD:
1008 case HORN:
1009 if (type != PLAYER || current_weapon == tmp)
1010 chosen_skill = tmp;
1011 break;
1012#endif
1013
1014 /* skills modifying the character -b.t. */ 999 /* skills modifying the character -b.t. */
1015 /* for all skills and skill granting objects */ 1000 /* for all skills and skill granting objects */
1016 case SKILL: 1001 case SKILL:
1017 { 1002 {
1018 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || skill_flags [tmp->subtype] & SF_APPLY) 1003 if (!QUERY_FLAG (tmp, FLAG_APPLIED) || skill_flags [tmp->subtype] & SF_APPLY)
1053 1038
1054 if (tmp->stats.ac) 1039 if (tmp->stats.ac)
1055 ac -= tmp->stats.ac + tmp->magic; 1040 ac -= tmp->stats.ac + tmp->magic;
1056 1041
1057 if (settings.spell_encumbrance == TRUE && type == PLAYER) 1042 if (settings.spell_encumbrance == TRUE && type == PLAYER)
1058 contr->encumbrance += (int) 3 *tmp->weight / 1000; 1043 contr->encumbrance += 3 * tmp->weight / 1000;
1059 } 1044 }
1060 1045
1061 break; 1046 break;
1062 1047
1063 case SHIELD: 1048 case SHIELD:
1064 if (settings.spell_encumbrance == TRUE && type == PLAYER) 1049 if (settings.spell_encumbrance == TRUE && type == PLAYER)
1065 contr->encumbrance += (int) tmp->weight / 2000; 1050 contr->encumbrance += tmp->weight / 2000;
1051 //FALLTHROUGH
1066 case RING: 1052 case RING:
1067 case AMULET: 1053 case AMULET:
1068 case GIRDLE: 1054 case GIRDLE:
1069 case HELMET: 1055 case HELMET:
1070 case BOOTS: 1056 case BOOTS:
1079 if (tmp->stats.ac) 1065 if (tmp->stats.ac)
1080 ac -= tmp->stats.ac + tmp->magic; 1066 ac -= tmp->stats.ac + tmp->magic;
1081 1067
1082 break; 1068 break;
1083 1069
1070 case WAND:
1071 case ROD:
1072 case HORN:
1073 case SKILL_TOOL:
1074 if (type != PLAYER)
1075 chosen_skill = find_skill_by_name (this, tmp->skill);
1076 break;
1077
1084 case BOW: 1078 case BOW:
1085 case WEAPON: 1079 case WEAPON:
1086 if (type != PLAYER || current_weapon == tmp) 1080 if (type != PLAYER || current_weapon == tmp)
1087 { 1081 {
1082 chosen_skill = find_skill_by_name (this, tmp->skill);
1083
1088 wc -= tmp->stats.wc + tmp->magic; 1084 wc -= tmp->stats.wc + tmp->magic;
1089 1085
1090 if (tmp->stats.ac && tmp->stats.ac + tmp->magic > 0) 1086 if (tmp->stats.ac && tmp->stats.ac + tmp->magic > 0)
1091 ac -= tmp->stats.ac + tmp->magic; 1087 ac -= tmp->stats.ac + tmp->magic;
1092 1088
1138 else /* To nullify the below effect */ 1134 else /* To nullify the below effect */
1139 ac += tmp->stats.ac + tmp->magic; 1135 ac += tmp->stats.ac + tmp->magic;
1140 } 1136 }
1141 1137
1142 if (tmp->stats.wc) 1138 if (tmp->stats.wc)
1143 wc -= (tmp->stats.wc + tmp->magic); 1139 wc -= tmp->stats.wc + tmp->magic;
1144 1140
1145 if (tmp->stats.ac) 1141 if (tmp->stats.ac)
1146 ac -= (tmp->stats.ac + tmp->magic); 1142 ac -= tmp->stats.ac + tmp->magic;
1147 1143
1148 if (ARMOUR_SPEED (tmp)) 1144 if (ARMOUR_SPEED (tmp))
1149 max_speed = min (max_speed, ARMOUR_SPEED (tmp) / 10.f); 1145 max_speed = min (max_speed, ARMOUR_SPEED (tmp) / 10.f);
1150 1146
1151 break; 1147 break;
1152 } /* switch tmp->type */ 1148 } /* switch tmp->type */
1153 } /* item is equipped */ 1149 } /* item is equipped */
1154 } /* for loop of items */ 1150 } /* for loop of items */
1151
1152 if (type != PLAYER)
1153 this->chosen_skill = chosen_skill;
1154
1155 glow_radius = min (glow_radius, MAX_LIGHT_RADIUS);
1155 1156
1156 /* We've gone through all the objects the player has equipped. For many things, we 1157 /* We've gone through all the objects the player has equipped. For many things, we
1157 * have generated intermediate values which we now need to assign. 1158 * have generated intermediate values which we now need to assign.
1158 */ 1159 */
1159 1160
1173 1174
1174 if (type == PLAYER) 1175 if (type == PLAYER)
1175 { 1176 {
1176 // clamp various player stats 1177 // clamp various player stats
1177 for (int i = 0; i < NUM_STATS; ++i) 1178 for (int i = 0; i < NUM_STATS; ++i)
1178 stats.stat (i) = clamp (stat_sum [i], MIN_STAT, MAX_STAT); 1179 stats.stat (i) = stat_sum [i];
1180
1181 check_stat_bounds (&stats);
1179 1182
1180 contr->digestion = clamp (contr->digestion, MIN_DIGESTION, MAX_DIGESTION); 1183 contr->digestion = clamp (contr->digestion, MIN_DIGESTION, MAX_DIGESTION);
1181 1184
1182 /* Figure out the players sp/mana/hp totals. */ 1185 /* Figure out the players sp/mana/hp totals. */
1183 int pl_level; 1186 int pl_level;
1184 1187
1185 check_stat_bounds (&(stats));
1186 pl_level = level;
1187
1188 if (pl_level < 1)
1189 pl_level = 1; /* safety, we should always get 1 levels worth of hp! */ 1188 pl_level = max (1, level); /* safety, we should always get 1 levels worth of hp! */
1190 1189
1191 /* You basically get half a con bonus/level. But we do take into account rounding, 1190 /* You basically get half a con bonus/level. But we do take into account rounding,
1192 * so if your bonus is 7, you still get 7 worth of bonus every 2 levels. 1191 * so if your bonus is 7, you still get 7 worth of bonus every 2 levels.
1193 */ 1192 */
1194 stats.maxhp = 0; 1193 stats.maxhp = 0;
1329 1328
1330 speed = 1.f + speed_bonus[stats.Dex]; 1329 speed = 1.f + speed_bonus[stats.Dex];
1331 1330
1332 if (settings.search_items && contr->search_str[0]) 1331 if (settings.search_items && contr->search_str[0])
1333 speed -= 1; 1332 speed -= 1;
1334
1335 if (attacktype == 0)
1336 attacktype = arch->attacktype;
1337 } /* End if player */ 1333 } /* End if player */
1338 1334
1339 if (added_speed >= 0) 1335 if (added_speed >= 0)
1340 speed += added_speed / 10.f; 1336 speed += added_speed / 10.f;
1341 else /* Something wrong here...: */ 1337 else /* Something wrong here...: */
1360 speed *= speed_reduce_from_disease; 1356 speed *= speed_reduce_from_disease;
1361 1357
1362 /* Put a lower limit on speed. Note with this speed, you move once every 1358 /* Put a lower limit on speed. Note with this speed, you move once every
1363 * 25 ticks or so. This amounts to once every 3 seconds of realtime. 1359 * 25 ticks or so. This amounts to once every 3 seconds of realtime.
1364 */ 1360 */
1365 if (speed < 0.04f && type == PLAYER) 1361 max_it (speed, is_player () ? MIN_PLAYER_SPEED : MIN_ACTIVE_SPEED);
1366 speed = 0.04f;
1367 1362
1368 if (speed != old_speed) 1363 if (speed != old_speed)
1369 set_speed (speed); 1364 set_speed (speed);
1370 1365
1371 if (type == PLAYER) 1366 if (type == PLAYER)
1406 if (move_type == 0) 1401 if (move_type == 0)
1407 move_type = MOVE_WALK; 1402 move_type = MOVE_WALK;
1408 else if (move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH)) 1403 else if (move_type & (MOVE_FLY_LOW | MOVE_FLY_HIGH))
1409 move_type &= ~MOVE_WALK; 1404 move_type &= ~MOVE_WALK;
1410 1405
1406 // now apply the new move_type
1407 if (this->move_type != move_type)
1408 change_move_type (move_type);
1409
1411 /* It is quite possible that a player's spell costing might have changed, 1410 /* It is quite possible that a player's spell costing might have changed,
1412 * so we will check that now. 1411 * so we will check that now.
1413 */ 1412 */
1414 if (type == PLAYER) 1413 if (is_player ())
1415 { 1414 contr->update_spells ();
1416 esrv_update_stats (contr);
1417 esrv_update_spells (contr);
1418 }
1419 1415
1420 // update the mapspace, if we are on a map 1416 // update the mapspace, if we are on a map
1421 if (!flag [FLAG_REMOVED] && map) 1417 if (!flag [FLAG_REMOVED] && map)
1422 map->at (x, y).flags_ = 0; 1418 map->at (x, y).flags_ = 0;
1419}
1420
1421void
1422object::set_glow_radius (sint8 rad)
1423{
1424 glow_radius = rad;
1425
1426 if (is_on_map ())
1427 update_all_los (map, x, y);
1428 else if (object *env = outer_env ())
1429 {
1430 env->update_stats ();
1431
1432 if (env->is_on_map ())
1433 update_all_los (env->map, env->x, env->y);
1434 }
1423} 1435}
1424 1436
1425/* 1437/*
1426 * Returns true if the given player is a legal class. 1438 * Returns true if the given player is a legal class.
1427 * The function to add and remove class-bonuses to the stats doesn't 1439 * The function to add and remove class-bonuses to the stats doesn't
1443 1455
1444/* 1456/*
1445 * set the new dragon name after gaining levels or 1457 * set the new dragon name after gaining levels or
1446 * changing ability focus (later this can be extended to 1458 * changing ability focus (later this can be extended to
1447 * eventually change the player's face and animation) 1459 * eventually change the player's face and animation)
1448 *
1449 * Note that the title is written to 'own_title' in the
1450 * player struct. This should be changed to 'ext_title'
1451 * as soon as clients support this!
1452 * Please, anyone, write support for 'ext_title'.
1453 */ 1460 */
1454void 1461void
1455set_dragon_name (object *pl, const object *abil, const object *skin) 1462set_dragon_name (object *pl, const object *abil, const object *skin)
1456{ 1463{
1457 int atnr = -1; /* attacknumber of highest level */ 1464 int atnr = -1; /* attacknumber of highest level */
1475 /* now if there are equals at highest level, pick the one with focus, 1482 /* now if there are equals at highest level, pick the one with focus,
1476 or else at random */ 1483 or else at random */
1477 if (atnr_is_dragon_enabled (abil->stats.exp) && abil->resist[abil->stats.exp] >= level) 1484 if (atnr_is_dragon_enabled (abil->stats.exp) && abil->resist[abil->stats.exp] >= level)
1478 atnr = abil->stats.exp; 1485 atnr = abil->stats.exp;
1479 1486
1480 level = (int) (level / 25.);
1481
1482 /* now set the new title */ 1487 /* now set the new title */
1483 if (pl->contr)
1484 {
1485 if (level == 0)
1486 sprintf (pl->contr->title, "%s hatchling", attacks[atnr]); 1488 if (level < 25) sprintf (pl->contr->title, "%s hatchling", attacks[atnr]);
1487 else if (level == 1)
1488 sprintf (pl->contr->title, "%s wyrm", attacks[atnr]); 1489 else if (level < 50) sprintf (pl->contr->title, "%s wyrm" , attacks[atnr]);
1489 else if (level == 2)
1490 sprintf (pl->contr->title, "%s wyvern", attacks[atnr]); 1490 else if (level < 75) sprintf (pl->contr->title, "%s wyvern" , attacks[atnr]);
1491 else if (level == 3)
1492 sprintf (pl->contr->title, "%s dragon", attacks[atnr]); 1491 else if (level < 100) sprintf (pl->contr->title, "%s dragon" , attacks[atnr]);
1493 else 1492 else
1494 { 1493 {
1495 /* special titles for extra high resistance! */ 1494 /* special titles for extra high resistance! */
1496 if (skin->resist[atnr] > 80)
1497 sprintf (pl->contr->title, "legendary %s dragon", attacks[atnr]); 1495 if (skin->resist[atnr] > 80) sprintf (pl->contr->title, "legendary %s dragon", attacks[atnr]);
1498 else if (skin->resist[atnr] > 50)
1499 sprintf (pl->contr->title, "ancient %s dragon", attacks[atnr]); 1496 else if (skin->resist[atnr] > 50) sprintf (pl->contr->title, "ancient %s dragon" , attacks[atnr]);
1500 else
1501 sprintf (pl->contr->title, "big %s dragon", attacks[atnr]); 1497 else sprintf (pl->contr->title, "big %s dragon" , attacks[atnr]);
1502 }
1503 } 1498 }
1504 1499
1505 strcpy (pl->contr->own_title, ""); 1500 strcpy (pl->contr->own_title, "");
1506} 1501}
1507 1502
1508/* 1503/*
1509 * This function is called when a dragon-player gains 1504 * This function is called when a dragon-player gains
1510 * an overall level. Here, the dragon might gain new abilities 1505 * an overall level. Here, the dragon might gain new abilities
1511 * or change the ability-focus. 1506 * or change the ability-focus.
1512 */ 1507 */
1513void 1508static void
1514dragon_level_gain (object *who) 1509dragon_level_gain (object *who)
1515{ 1510{
1516 object *abil = NULL; /* pointer to dragon ability force */ 1511 object *abil = NULL; /* pointer to dragon ability force */
1517 object *skin = NULL; /* pointer to dragon skin force */ 1512 object *skin = NULL; /* pointer to dragon skin force */
1518 object *tmp = NULL; /* tmp. object */ 1513 object *tmp = NULL; /* tmp. object */
1574 object *skill_obj; 1569 object *skill_obj;
1575 1570
1576 skill_obj = get_archetype_by_skill_name (skill_name, SKILL); 1571 skill_obj = get_archetype_by_skill_name (skill_name, SKILL);
1577 if (!skill_obj) 1572 if (!skill_obj)
1578 { 1573 {
1579 LOG (llevError, "add_player_exp: couldn't find skill %s\n", skill_name); 1574 LOG (llevError, "give_skill_by_name: couldn't find skill %s\n", skill_name);
1580 return NULL; 1575 return NULL;
1581 } 1576 }
1582 1577
1583 /* clear the flag - exp goes into this bucket, but player 1578 /* clear the flag - exp goes into this bucket, but player
1584 * still doesn't know it. 1579 * still doesn't know it.
1585 */ 1580 */
1586 CLEAR_FLAG (skill_obj, FLAG_CAN_USE_SKILL); 1581 CLEAR_FLAG (skill_obj, FLAG_CAN_USE_SKILL);
1587 skill_obj->stats.exp = 0; 1582 skill_obj->stats.exp = 0;
1588 skill_obj->level = 1; 1583 skill_obj->level = 1;
1589 insert_ob_in_ob (skill_obj, op); 1584 op->insert (skill_obj);
1590 1585
1591 if (player *pl = op->contr) 1586 if (player *pl = op->contr)
1592 { 1587 pl->link_skills ();
1593 pl->last_skill_ob [skill_obj->subtype] = skill_obj;
1594 if (pl->ns)
1595 pl->ns->last_skill_exp[skill_obj->subtype] = -1;//TODO: should be made superfluous
1596 }
1597 1588
1598 return skill_obj; 1589 return skill_obj;
1599} 1590}
1600 1591
1601/* player_lvl_adj() - for the new exp system. we are concerned with 1592/* player_lvl_adj() - for the new exp system. we are concerned with
1618 { 1609 {
1619 changed = true; 1610 changed = true;
1620 1611
1621 op->level++; 1612 op->level++;
1622 1613
1623 if (op && op == who && op->stats.exp > 1 && is_dragon_pl (who)) 1614 if (op && op == who && op->stats.exp > 1 && who->is_dragon ())
1624 dragon_level_gain (who); 1615 dragon_level_gain (who);
1625 1616
1626 /* Only roll these if it is the player (who) that gained the level */ 1617 /* Only roll these if it is the player (who) that gained the level */
1627 if (op == who && (who->level < 11) && who->type == PLAYER) 1618 if (op == who && (who->level < 11) && who->type == PLAYER)
1628 { 1619 {
1661 new_draw_info (NDI_UNIQUE | NDI_RED, 0, who, buf); 1652 new_draw_info (NDI_UNIQUE | NDI_RED, 0, who, buf);
1662 } 1653 }
1663 } 1654 }
1664 1655
1665 if (changed) 1656 if (changed)
1666 { 1657 who->update_stats (); // should cause esrv_update_stats and esrv_update_spells
1667 who->update_stats ();
1668 esrv_update_stats (who->contr);
1669 /* check if the spell data has changed */
1670 esrv_update_spells (who->contr);
1671 }
1672} 1658}
1673 1659
1674/* 1660/*
1675 * Returns how much experience is needed for a player to become 1661 * Returns how much experience is needed for a player to become
1676 * the given level. level should really never exceed max_level 1662 * the given level. level should really never exceed max_level
1720 * flag is what to do if the player doesn't have the skill: 1706 * flag is what to do if the player doesn't have the skill:
1721 */ 1707 */
1722static void 1708static void
1723add_player_exp (object *op, sint64 exp, const char *skill_name, int flag) 1709add_player_exp (object *op, sint64 exp, const char *skill_name, int flag)
1724{ 1710{
1725 object *skill_obj = NULL; 1711 object *skill_obj;
1726 sint64 limit, exp_to_add; 1712 sint64 limit, exp_to_add;
1727 int i; 1713 int i;
1728 1714
1729 /* prevents some forms of abuse. */ 1715 /* prevents some forms of abuse. */
1730 if (op->contr->braced) 1716 if (op->contr->braced)
1733 /* Try to find the matching skill. 1719 /* Try to find the matching skill.
1734 * We do a shortcut/time saving mechanism first - see if it matches 1720 * We do a shortcut/time saving mechanism first - see if it matches
1735 * chosen_skill. This means we don't need to search through 1721 * chosen_skill. This means we don't need to search through
1736 * the players inventory. 1722 * the players inventory.
1737 */ 1723 */
1724 skill_obj = 0;
1725
1738 if (skill_name) 1726 if (skill_name)
1739 { 1727 {
1740 if (op->chosen_skill && op->chosen_skill->type == SKILL && !strcmp (skill_name, op->chosen_skill->skill)) 1728 skill_obj = op->contr->find_skill (skill_name);
1741 skill_obj = op->chosen_skill;
1742 else
1743 {
1744 for (i = 0; i < NUM_SKILLS; i++)
1745 if (op->contr->last_skill_ob[i] && !strcmp (op->contr->last_skill_ob[i]->skill, skill_name))
1746 {
1747 skill_obj = op->contr->last_skill_ob[i];
1748 break;
1749 }
1750 1729
1751 /* Player doesn't have the skill. Check to see what to do, and give 1730 /* Player doesn't have the skill. Check to see what to do, and give
1752 * it to the player if necessary 1731 * it to the player if necessary
1753 */ 1732 */
1754 if (!skill_obj) 1733 if (!skill_obj)
1755 { 1734 {
1756 if (flag == SK_EXP_NONE) 1735 if (flag == SK_EXP_NONE)
1757 return; 1736 return;
1737
1758 else if (flag == SK_EXP_ADD_SKILL) 1738 if (flag == SK_EXP_ADD_SKILL)
1759 give_skill_by_name (op, skill_name); 1739 skill_obj = give_skill_by_name (op, skill_name);
1760 }
1761 } 1740 }
1762 } 1741 }
1763 1742
1764 if (flag != SK_EXP_SKILL_ONLY) 1743 if (flag != SK_EXP_SKILL_ONLY)
1765 { 1744 {
1798 player_lvl_adj (op, skill_obj); 1777 player_lvl_adj (op, skill_obj);
1799 } 1778 }
1800} 1779}
1801 1780
1802/* This function checks to make sure that object 'op' can 1781/* This function checks to make sure that object 'op' can
1803 * lost 'exp' experience. It returns the amount of exp 1782 * lose 'exp' experience. It returns the amount of exp
1804 * object 'op' can in fact lose - it basically makes 1783 * object 'op' can in fact lose - it basically makes
1805 * adjustments based on permanent exp and the like. 1784 * adjustments based on permanent exp and the like.
1806 * This function should always be used for losing experience - 1785 * This function should always be used for losing experience -
1807 * the 'exp' value passed should be positive - this is the 1786 * the 'exp' value passed should be positive - this is the
1808 * amount that should get subtract from the player. 1787 * amount that should get subtract from the player.
1809 */ 1788 */
1810sint64 1789static sint64
1811check_exp_loss (const object *op, sint64 exp) 1790check_exp_loss (const object *op, sint64 exp)
1812{ 1791{
1813 sint64 del_exp; 1792 sint64 del_exp;
1814 1793
1815 if (exp > op->stats.exp) 1794 if (exp > op->stats.exp)
1816 exp = op->stats.exp; 1795 exp = op->stats.exp;
1796
1817 if (settings.permanent_exp_ratio) 1797 if (settings.permanent_exp_ratio)
1818 { 1798 {
1819 del_exp = (sint64) ((op->stats.exp - op->perm_exp) * PERM_EXP_MAX_LOSS_RATIO); 1799 del_exp = (sint64) ((op->stats.exp - op->perm_exp) * PERM_EXP_MAX_LOSS_RATIO);
1800
1820 if (del_exp < 0) 1801 if (del_exp < 0)
1821 del_exp = 0; 1802 del_exp = 0;
1803
1822 if (exp > del_exp) 1804 if (exp > del_exp)
1823 exp = del_exp; 1805 exp = del_exp;
1824 } 1806 }
1807
1825 return exp; 1808 return exp;
1826} 1809}
1827 1810
1828sint64 1811sint64
1829check_exp_adjust (const object *op, sint64 exp) 1812check_exp_adjust (const object *op, sint64 exp)
1830{ 1813{
1831 if (exp < 0) 1814 if (exp < 0)
1832 return check_exp_loss (op, exp); 1815 return check_exp_loss (op, exp);
1833 else 1816 else
1834 return MIN (exp, (sint64) MAX_EXPERIENCE - op->stats.exp); 1817 return min (exp, (sint64)MAX_EXPERIENCE - op->stats.exp);
1835} 1818}
1836
1837 1819
1838/* Subtracts experience from player. 1820/* Subtracts experience from player.
1839 * if skill is set and flag == SK_SUBTRACT_SKILL_EXP, then we 1821 * if skill is set and flag == SK_SUBTRACT_SKILL_EXP, then we
1840 * only subtract from the matching skill. Otherwise, 1822 * only subtract from the matching skill. Otherwise,
1841 * this subtracts a portion from all 1823 * this subtracts a portion from all
1855 sint64 del_exp; 1837 sint64 del_exp;
1856 1838
1857 for (tmp = op->inv; tmp; tmp = tmp->below) 1839 for (tmp = op->inv; tmp; tmp = tmp->below)
1858 if (tmp->type == SKILL && tmp->stats.exp) 1840 if (tmp->type == SKILL && tmp->stats.exp)
1859 { 1841 {
1860 if (flag == SK_SUBTRACT_SKILL_EXP && skill && !strcmp (tmp->skill, skill)) 1842 if (flag == SK_SUBTRACT_SKILL_EXP && skill && !strcmp (&tmp->skill, skill))
1861 { 1843 {
1862 del_exp = check_exp_loss (tmp, exp); 1844 del_exp = check_exp_loss (tmp, exp);
1863 tmp->stats.exp -= del_exp; 1845 tmp->stats.exp -= del_exp;
1864 player_lvl_adj (op, tmp); 1846 player_lvl_adj (op, tmp);
1865 } 1847 }
1953 * amount of permenent experience, whichever gives the lowest loss. 1935 * amount of permenent experience, whichever gives the lowest loss.
1954 */ 1936 */
1955void 1937void
1956apply_death_exp_penalty (object *op) 1938apply_death_exp_penalty (object *op)
1957{ 1939{
1958 object *tmp;
1959 sint64 loss; 1940 sint64 loss;
1960 sint64 percentage_loss; /* defined by the setting 'death_penalty_percent' */ 1941 sint64 percentage_loss; /* defined by the setting 'death_penalty_percent' */
1961 sint64 level_loss; /* defined by the setting 'death_penalty_levels */ 1942 sint64 level_loss; /* defined by the setting 'death_penalty_levels */
1962 1943
1963 for (tmp = op->inv; tmp; tmp = tmp->below) 1944 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1964 if (tmp->type == SKILL && tmp->stats.exp) 1945 if (tmp->type == SKILL && tmp->stats.exp)
1965 { 1946 {
1966
1967 percentage_loss = tmp->stats.exp * settings.death_penalty_ratio / 100; 1947 percentage_loss = tmp->stats.exp * settings.death_penalty_ratio / 100;
1968 level_loss = tmp->stats.exp - levels[MAX (0, tmp->level - settings.death_penalty_level)]; 1948 level_loss = tmp->stats.exp - levels [max (0, tmp->level - settings.death_penalty_level)];
1969 1949
1970 /* With the revised exp system, you can get cases where 1950 /* With the revised exp system, you can get cases where
1971 * losing several levels would still require that you have more 1951 * losing several levels would still require that you have more
1972 * exp than you currently have - this is true if the levels 1952 * exp than you currently have - this is true if the levels
1973 * tables is a lot harder. 1953 * tables is a lot harder.
1974 */ 1954 */
1975 if (level_loss < 0) 1955 if (level_loss < 0)
1976 level_loss = 0; 1956 level_loss = 0;
1977 1957
1978 loss = check_exp_loss (tmp, MIN (level_loss, percentage_loss)); 1958 loss = check_exp_loss (tmp, min (level_loss, percentage_loss));
1979 1959
1980 tmp->stats.exp -= loss; 1960 tmp->stats.exp -= loss;
1981 player_lvl_adj (op, tmp); 1961 player_lvl_adj (op, tmp);
1982 } 1962 }
1983 1963
1984 percentage_loss = op->stats.exp * settings.death_penalty_ratio / 100; 1964 percentage_loss = op->stats.exp * settings.death_penalty_ratio / 100;
1985 level_loss = op->stats.exp - levels[MAX (0, op->level - settings.death_penalty_level)]; 1965 level_loss = op->stats.exp - levels[max (0, op->level - settings.death_penalty_level)];
1986 1966
1987 if (level_loss < 0) 1967 if (level_loss < 0)
1988 level_loss = 0; 1968 level_loss = 0;
1969
1989 loss = check_exp_loss (op, MIN (level_loss, percentage_loss)); 1970 loss = check_exp_loss (op, min (level_loss, percentage_loss));
1990 1971
1991 op->stats.exp -= loss; 1972 op->stats.exp -= loss;
1992 player_lvl_adj (op, NULL); 1973 player_lvl_adj (op, NULL);
1993} 1974}
1994 1975

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines