ID:153456
 
I'm looking for an algorithm to take a value and "reverse" it. Essentially, I have a variable (poison), and as it rises, the damage it does increases with it. However, I want to use the variable for a dual purpose, the higher it gets, the LOWER it's secondary effect. See, while you take more and more damage from the poison, you also get more weak, more ill. Therefore your attacks do less damage. I'm trying to use a modifier to decrease the damage. This needs to be essentially the opposite of a value. A 9 would return like a 1, a 6 would be a 4. And so on. Is there any mathematical algorithm I could use to achieve this? Otherwise it needs to be coded into a seperate proc to read the value and return the right value, which is just annoying. I was wondering if math itself provided an easier outlet.


~Polatrite~
var poisonVal
var otherVal

otherVal = 10 - poisonVal


Is that what you are asking? ...or did I completely misread something...again?
Subtract the current poison damage from another number. This other number could be the maximum poison damage, the victim's current attack, etc.

You may want to tweak it a little (for example, by adding 1 so the victim's attack is never <= 0), but the basic idea is this:

10-poisondamage

So if the poison is at level 1, it returns 9. If 2, 8; if 7, 3; and so on. The only thing to watch out for is getting negative numbers.
In response to CableMonkey
I think you hit the nail on the head there. With what he said he wants, what you just said looks like it would work, unless theres a few more situations he didn't mention.
If you want it to be linear (it looks like thats what you want) then you can just use y = mx + b. m, the slope, would be negative. b, the y intercept of the function would be 10, so it starts positive, but as the x value (your poison-ness value) increases the value of the function decreases.

You could also use a variation y = a/x, so that the value of the function would quickly drop, then the rate at which it decreases would lessen. Likewise, you could come up with a function so that the return value of the function starts out decreasing, but decreases faster as the x increases.
In response to Jotdaniel
I felt like I was being a complete smart*** when replying that...but I couldn't interpret it any other way. :-/
This raises an interesting idea. How about diffrent poisons. Like say someone might be good at making a poison that slowed the persons attack, but didnt actualy harm them. Or a poison that make thier attacks weakened. A skill for each maybie. If i was a master poisoner, i could create a potion that did all of the above. Just some ideas.
In response to Scoobert
Well this is for Hood (fast paced, heavy action... FAST paced). Lots of that is not fit for the game style. It's a good idea for RPGs though.

I did get what I needed to get, so thanks for the help guys. Although I have another question. Is there an easy way to get the "power" of a number? Like 2 to the power of 10. I've been checking the reference and couldn't find any such proc/operator. I need to use this to calculate bits quickly (looping through 1, 2, 4, 8, 16, etc.), and for a few other things. If not, I'll just do it manually.
In response to Crispy
Crispy wrote:
Subtract the current poison damage from another number. This other number could be the maximum poison damage, the victim's current attack, etc.

You may want to tweak it a little (for example, by adding 1 so the victim's attack is never <= 0), but the basic idea is this:

10-poisondamage

So if the poison is at level 1, it returns 9. If 2, 8; if 7, 3; and so on. The only thing to watch out for is getting negative numbers.

No worries there either.
var/inverse = max(0, 10-poisondamage)
In response to Polatrite
The power operator is **.

However, if you're just getting bits, use << and >> to shift the bits left and right, respectively.
In response to Polatrite
Heh, didnt realize it was for hood, so your right. Perhaps this will be the subject of my next design paper. Well, i should finish "Jails" first.