| 12-08-2007, 12:02 PM | #1 |
I made a function using multisampling to test and return the XP required for a hero to level to next level. Here is the code, credit if you want, else no need, just a small function: JASS:function GetHeroRequiredXP takes unit Hero returns integer local integer OriXP = GetHeroXP(Hero) local integer OriLVL = GetHeroLevel(Hero) local integer TestXP = 64 local integer RemainXP = 0 local boolean DONE = false local integer MaxXP = 0 call SetHeroXP(Hero,OriXP+1,false) if (GetHeroXP(Hero)<OriXP+1) then set DONE=true set MaxXP = OriXP endif if (GetHeroLevel(Hero)>OriLVL) then call UnitStripHeroLevel(Hero,1) endif call SetHeroXP(Hero,OriXP,false) loop exitwhen DONE call SetHeroXP(Hero,OriXP+RemainXP+TestXP,false) if (GetHeroLevel(Hero)>OriLVL) then call UnitStripHeroLevel(Hero,1) call SetHeroXP(Hero,OriXP+RemainXP+TestXP-1,false) if (GetHeroLevel(Hero)==OriLVL) then set DONE = true set MaxXP = OriXP+RemainXP+TestXP else set RemainXP = RemainXP-TestXP if (TestXP>1) then set TestXP=TestXP/2 endif endif call UnitStripHeroLevel(Hero,1) else set RemainXP = RemainXP+TestXP endif endloop call SetHeroXP(Hero,OriXP,false) return MaxXP endfunction and here is a demostration map: |
| 12-08-2007, 12:12 PM | #2 |
It should have a constants header in which you can input the gameplay constants' options that generate the experience required for each level. |
| 12-08-2007, 12:31 PM | #3 |
this function isnt dependent on gamplay constants. it makes it easier for some lazy people who dont wanna check constants. With a small cost of performance (loops) EDIT: nvm this function, ammorth made a better one. very simple and smart too, dunno why i didnt think of it haha. |
| 12-08-2007, 03:04 PM | #4 |
For sake of people using the search feature, I'll link to both the preferred method and the arithmetic method. Prefered Method Arithmetic Method Some weird rounding glitch causes the arithmetic method to be off the actual exp by 1. This has something to do with how R2I() operates. It only happens with decimals that are close to integers. |
| 12-08-2007, 05:53 PM | #5 |
Here is my version of R2I that 'tweaks' the rounding problem: (handles both positive and negative integers) JASS:function R2If takes real r returns integer local integer a=R2I(r) if r >= 0. then if I2R(a) + 1. == r then return a + 1 endif return a else if I2R(a) - 1. == r then return a - 1 endif return a endif endfunction If you assume that you are only working with positive numbers, you can use this one instead: JASS:function R2If takes real r returns integer local integer a=R2I(r) if I2R(a) + 1. == r then return a + 1 endif return a endfunction As an example: R2I(45.*1.2) returns 53, while R2If(45.*1.2) returns 54. |
