[11585] Add countof macro

It can be used to calculate number of elements in static array. Do not use with pointers!
This commit is contained in:
zergtmn 2011-06-01 16:23:01 +06:00
parent 3788348b46
commit 4c81559800
3 changed files with 9 additions and 5 deletions

View file

@ -769,14 +769,14 @@ SpellAuraProcResult Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, Aura
case CLASS_DRUID: // 39511,40997,40998,40999,41002,41005,41009,41011,41409 case CLASS_DRUID: // 39511,40997,40998,40999,41002,41005,41009,41011,41409
{ {
uint32 RandomSpell[]={39511,40997,40998,40999,41002,41005,41009,41011,41409}; uint32 RandomSpell[]={39511,40997,40998,40999,41002,41005,41009,41011,41409};
triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; triggered_spell_id = RandomSpell[urand(0, countof(RandomSpell)-1)];
break; break;
} }
case CLASS_ROGUE: // 39511,40997,40998,41002,41005,41011 case CLASS_ROGUE: // 39511,40997,40998,41002,41005,41011
case CLASS_WARRIOR: // 39511,40997,40998,41002,41005,41011 case CLASS_WARRIOR: // 39511,40997,40998,41002,41005,41011
{ {
uint32 RandomSpell[]={39511,40997,40998,41002,41005,41011}; uint32 RandomSpell[]={39511,40997,40998,41002,41005,41011};
triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; triggered_spell_id = RandomSpell[urand(0, countof(RandomSpell)-1)];
break; break;
} }
case CLASS_PRIEST: // 40999,41002,41005,41009,41011,41406,41409 case CLASS_PRIEST: // 40999,41002,41005,41009,41011,41406,41409
@ -785,13 +785,13 @@ SpellAuraProcResult Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, Aura
case CLASS_WARLOCK: // 40999,41002,41005,41009,41011,41406,41409 case CLASS_WARLOCK: // 40999,41002,41005,41009,41011,41406,41409
{ {
uint32 RandomSpell[]={40999,41002,41005,41009,41011,41406,41409}; uint32 RandomSpell[]={40999,41002,41005,41009,41011,41406,41409};
triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; triggered_spell_id = RandomSpell[urand(0, countof(RandomSpell)-1)];
break; break;
} }
case CLASS_HUNTER: // 40997,40999,41002,41005,41009,41011,41406,41409 case CLASS_HUNTER: // 40997,40999,41002,41005,41009,41011,41406,41409
{ {
uint32 RandomSpell[]={40997,40999,41002,41005,41009,41011,41406,41409}; uint32 RandomSpell[]={40997,40999,41002,41005,41009,41011,41406,41409};
triggered_spell_id = RandomSpell[ irand(0, sizeof(RandomSpell)/sizeof(uint32) - 1) ]; triggered_spell_id = RandomSpell[urand(0, countof(RandomSpell)-1)];
break; break;
} }
default: default:

View file

@ -250,4 +250,8 @@ inline char * mangos_strdup(const char * source)
# define M_PI_F float(M_PI) # define M_PI_F float(M_PI)
#endif #endif
#ifndef countof
#define countof(array) (sizeof(array) / sizeof((array)[0]))
#endif
#endif #endif

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "11584" #define REVISION_NR "11585"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__