enum struct just "sugar coating" code.
If you want get items work as array, using index, one way is this.
PHP Code:
enum
{
LifeStealChance = 0,
ArmorStealChance,
FlashProtectionChance,
DamageChance,
CameraShakeChance,
FreezeChance,
ChanceTOTAL
};
enum struct EPlayerChances
{
float Chance[ChanceTOTAL];
}
EPlayerChances FPlayerChances[MAXPLAYERS+1];
// You use it like this:
// FPlayerChances[attacker].Chance[CameraShakeChance];
Second way.
You can create function, inside enum struct as well
Code:
enum
{
LifeStealChance = 0,
ArmorStealChance,
FlashProtectionChance,
DamageChance,
CameraShakeChance,
FreezeChance,
MaxChances
}
enum struct EPlayerChances
{
float LifeStealChance;
float ArmorStealChance;
float FlashProtectionChance;
float DamageChance;
float CameraShakeChance;
float FreezeChance;
bool CanUseAbility(int index)
{
// out of bounds
if(index < LifeStealChance || index >= MaxChances)
return false;
float a;
float b = GetRandomFloat(0.0, 1.0);
switch(index)
{
case LifeStealChance:
{
a = this.LifeStealChance;
}
case ArmorStealChance:
{
a = this.ArmorStealChance;
}
case FlashProtectionChance:
{
a = this.FlashProtectionChance;
}
case DamageChance:
{
a = this.DamageChance;
}
case CameraShakeChance:
{
a = this.CameraShakeChance;
}
case FreezeChance:
{
a = this.FreezeChance;
}
}
if(a >= b)
return true;
return false;
}
}
EPlayerChances PlayerChances[MAXPLAYERS+1];
enum struct EPlayerProperties
{
float CameraShake;
}
EPlayerProperties PlayerProperties[MAXPLAYERS+1];
bool Game_ShakeVictimOnAttack(int victim, int attacker)
{
float ShakeAmplitude = PlayerProperties[attacker].CameraShake;
if(ShakeAmplitude > 0.0 && PlayerChances[attacker].CanUseAbility(CameraShakeChance))
{
// Gonna be too much figure these out
//Game_IsAbilityCoolingDown()
return true;
}
return false;
}
Anyone, please mention, if this code sample is wrong. I just throw this from my head.
__________________