| 754 | } |
| 755 | |
| 756 | void AddPlrExperience(int pnum, int lvl, int exp) |
| 757 | { |
| 758 | int powerLvlCap, expCap, newLvl, i; |
| 759 | |
| 760 | if (pnum != myplr) { |
| 761 | return; |
| 762 | } |
| 763 | |
| 764 | if ((DWORD)myplr >= MAX_PLRS) { |
| 765 | app_fatal("AddPlrExperience: illegal player %d", myplr); |
| 766 | } |
| 767 | |
| 768 | if (plr[myplr]._pHitPoints <= 0) { |
| 769 | return; |
| 770 | } |
| 771 | |
| 772 | // Adjust xp based on difference in level between player and monster |
| 773 | exp *= 1 + ((double)lvl - plr[pnum]._pLevel) / 10; |
| 774 | if (exp < 0) { |
| 775 | exp = 0; |
| 776 | } |
| 777 | |
| 778 | // Prevent power leveling |
| 779 | if (gbMaxPlayers > 1) { |
| 780 | powerLvlCap = plr[pnum]._pLevel < 0 ? 0 : plr[pnum]._pLevel; |
| 781 | if (powerLvlCap >= 50) { |
| 782 | powerLvlCap = 50; |
| 783 | } |
| 784 | // cap to 1/20 of current levels xp |
| 785 | if (exp >= ExpLvlsTbl[powerLvlCap] / 20) { |
| 786 | exp = ExpLvlsTbl[powerLvlCap] / 20; |
| 787 | } |
| 788 | // cap to 200 * current level |
| 789 | expCap = 200 * powerLvlCap; |
| 790 | if (exp >= expCap) { |
| 791 | exp = expCap; |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | plr[pnum]._pExperience += exp; |
| 796 | if ((DWORD)plr[pnum]._pExperience > MAXEXP) { |
| 797 | plr[pnum]._pExperience = MAXEXP; |
| 798 | } |
| 799 | |
| 800 | if (plr[pnum]._pExperience >= ExpLvlsTbl[49]) { |
| 801 | plr[pnum]._pLevel = 50; |
| 802 | return; |
| 803 | } |
| 804 | |
| 805 | // Increase player level if applicable |
| 806 | newLvl = 0; |
| 807 | while (plr[pnum]._pExperience >= ExpLvlsTbl[newLvl]) { |
| 808 | newLvl++; |
| 809 | } |
| 810 | if (newLvl != plr[pnum]._pLevel) { |
| 811 | for (i = newLvl - plr[pnum]._pLevel; i > 0; i--) { |
| 812 | NextPlrLevel(pnum); |
| 813 | } |
no test coverage detected