Ayanami
칼리
- Reaction score
- 288
Basically, I'm trying to reduce movement speed of a unit by a flat amount. Let's say I want to reduce a unit's movement speed by 50, initially it was like this (using T32):
Let's take a scenario. A unit with 300 MS. Let's say unit has Boots, which boosts 50 MS permanently. Above formula would work fine as it sets the unit's speed to default (300), but then would also take account of permanent MS bonus like Boots, thus the unit's speed is actually set to 350. Unit's current speed is then retrieved (350) then is reduced by 50. Thus, unit would have a total of 300 MS after the 50 MS reduction, which works fine. But when % MS factor comes in, the above doesn't work anymore.
Again, unit has 300 MS. Unit now has aura that boosts 10% MS. Unit has a total of 330 MS. Unit's MS is set to default, which becomes 330 after aura effect. Unit's speed is then reduced to 280 (330 - 50). However, due to the aura, Unit's speed is set to 308 (280 * 1.1). Thus, I came up with a new code:
As you can see, the above works fine. Since Unit's speed is set to 250, the actual Unit's MS would be 275 (250 * 1.1). Thus, now my code works fine for % MS factor cases.
Now there's one final problem. Whenever my new variable exceeds 522, the value returned is always 522. I'm guessing this is due to the fact that WC3 has the 522 limitation. So by theory, if my new SHOULD be 600, it always remain as 522. Is there a way to solve this? Thanks!
JASS:
private static method periodic takes nothing returns nothing
// other code
// movement speed part, this.u relates to the unit
call SetUnitMoveSpeed(this.u, GetUnitDefaultMoveSpeed(this.u))
call SetUnitMoveSpeed(this.u, GetUnitMoveSpeed(this.u) - 50)
endmethod
Let's take a scenario. A unit with 300 MS. Let's say unit has Boots, which boosts 50 MS permanently. Above formula would work fine as it sets the unit's speed to default (300), but then would also take account of permanent MS bonus like Boots, thus the unit's speed is actually set to 350. Unit's current speed is then retrieved (350) then is reduced by 50. Thus, unit would have a total of 300 MS after the 50 MS reduction, which works fine. But when % MS factor comes in, the above doesn't work anymore.
Again, unit has 300 MS. Unit now has aura that boosts 10% MS. Unit has a total of 330 MS. Unit's MS is set to default, which becomes 330 after aura effect. Unit's speed is then reduced to 280 (330 - 50). However, due to the aura, Unit's speed is set to 308 (280 * 1.1). Thus, I came up with a new code:
JASS:
private static method periodic takes nothing returns nothing
// other code
// movement speed part, this.u relates to the unit (comment shows the value of the variables for clarity sake)
local real old
local real new
local real r
call SetUnitMoveSpeed(this.u, GetUnitDefaultMoveSpeed(this.u))
set old = GetUnitMoveSpeed(this.u)
// old = 330
set r = old - 50
// r = 330 - 50 = 280
call SetUnitMoveSpeed(this.u, r)
set new = GetUnitMoveSpeed(this.u)
// new = 280 * 1.1 = 308
set r = (r - ((new - old) / new) * r) - 50
// r = (280 - ((308 - 330) / 308) * 280) - 50
// r = (280 - (-22 / 308) * 280) - 50
// r = (280 - (-20)) - 50
// r = 300 - 50
// r = 250
call SetUnitMoveSpeed(this.u, r)
endmethod
As you can see, the above works fine. Since Unit's speed is set to 250, the actual Unit's MS would be 275 (250 * 1.1). Thus, now my code works fine for % MS factor cases.
Now there's one final problem. Whenever my new variable exceeds 522, the value returned is always 522. I'm guessing this is due to the fact that WC3 has the 522 limitation. So by theory, if my new SHOULD be 600, it always remain as 522. Is there a way to solve this? Thanks!