ID:157222
 
I'm currently thinking of the most convenient way to implement the attack chart into my Pokemon game. Basically, some attacks do less damage,some do more, and some don't do any at all depending on the type of attacks. I'd really rather not make this long and overcomplicated. Does anyone have any ideas on how I should make it?

http://www.serebii.net/games/type.shtml
You can always just use a two dimensional array and then insert the various resists/weaknesses into it.

Ideally you'd want to #define a type to a number since that's essentially how the actual games work. The type-number ordering is important as it makes calculating hidden power simple as well as some other aspects.

#define FIRE  1
#define WATER 2
etc.


Then you'd want to fill this chart in on world/New() with all 1's and then go through and just fill in specific cases where there's a weakness, resist or immunity.
var/type_chart[whatever][whatever]

proc/set_type_chart()
type_chart[WATER][FIRE] = 2
type_chart[NORMAL][GHOST] = 0
type_chart[NORMAL][ROCK] = 0.5
... and so on


You really need to only worry about the first half of that chart.
In response to tenkuu
Thanks for the help but could you please go into more detail about it? I sort of understand what you're telling me but what would the type-number ordering be? And what is the point of var/type_chart[whatever][whatever]? Thanks.
In response to tenkuu
Yeah, and if you were to cut out one type so that there was only 16, you could use bits.
In response to DisturbedSixx
The ordering of the numbers for the types is irrelevant so long as it's consistent (hence the use of constants). The assignment statements are putting numbers into the array, so that type_chart[NORMAL][FIRE] tells you how much damage NORMAL takes from FIRE (or FIRE takes from NORMAL I forget which way he set up it).

Anyway, that's the wrong way to input these values. What you should do is this:

var/const
NORMAL = 1
FIRE = 2
WATER = 3
ELECTRIC = 4
DAMAGE_CHART = list(
list( 1, 1, 1, 1),
list( 1,.5, 2, 1),
list( 1,.5,.5, 2),
list( 1, 1, 1,.5)
)


The consts match the order of the types given in the chart you linked. 1 corresponds to normal damage, .5 to half, 2 to double, and 0 to no damage. To determine the damage multiplier of an attack, look up DAMAGE_CHART[defender_type][attack_type]. For pokemon with multiple types, look up the value for each type and multiply the results together, so you'd get DAMAGE_CHART[defender_type_1][attacker_type] * DAMAGE_CHART[defender_type_2][attack_type]. A pokemon's (or attack's) type is technically just a number, which is where the constants are useful, so that you can define something's type to be ELECTRIC rather than 4.

You just need to copy the 17x17 base grid from the website you linked. You don't need any of the hybrid types in it, because as I said those are simply found by multiplying the values gotten from each type.
In response to Garthor
Okay thank you very much.
In response to Garthor
Am I doing something wrong? It's giving me these errors:
Calculations.dm:109:error: : invalid expression
Calculations.dm:110:error: : invalid expression
Calculations.dm:108:error: =: constant initializer required
var/const
Normal=1
Fire=2
Water=3
Electric=4
Grass=5
Ice=6
Fight=7
Poison=8
Ground=9
Flying=10
Psychic=11
Bug=12
Rock=13
Ghost=14
Dragon=15
Dark=16
Steel=17
TYPE_DAMAGE = list(
list=( 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1),
list=( 1,0.5, 2, 1,0.5,0.5, 1, 1, 2, 1, 1,0.5, 2, 1, 1, 1,0.5)
)

Do I need to finish all of the rows first?
In response to DisturbedSixx
If I remember correctly, you cannot break open those parenthesis () like that - do not get them confused with braces {}.
You need to escape the newlines:
X  = list(\
Y, \
Z)
In response to DisturbedSixx
Whoops, the list should be under its own var/ thing, not var/const.

And you shouldn't have list=(, just list(.
In response to Garthor
Okay thanks.
In response to DisturbedSixx
Ya, I have a question.

I am using something similar to this. Or, at least can use something like this to make my objective simpler. I tried this out, but how would I change a variable with it? Like...

 damagevar *= DMGCHART[type1][type2]


Thats the only way I can think of.
Thanks for any help.
In response to Sensaku
That's pretty much it. Calculate the base damage, then multiply it by DMGCHART[A][B].