--- deliantra/server/include/living.h 2007/05/12 18:14:47 1.13 +++ deliantra/server/include/living.h 2007/05/12 18:34:19 1.14 @@ -25,6 +25,8 @@ #ifndef LIVING_H #define LIVING_H +#include + // corresponds to some arrays in common/living.C enum { STR, @@ -83,8 +85,31 @@ sint16 ACC (RW, grace); /* Grace. Used to invoke clerical prayers. */ sint16 ACC (RW, maxgrace); /* Grace. Used to invoke clerical prayers. */ - sint8 &stat (int index); - sint8 stat (int index) const; + // this method enforces field ordering and should not normally result in + // any code being generated strictly speaking, c++ compilers may reorder + // stat fields, so check for it and declare those compilers unsupported. + void check_ordering () const + { + assert ((sint8 *)&Str - (sint8 *)&Str == STR); + assert ((sint8 *)&Dex - (sint8 *)&Str == DEX); + assert ((sint8 *)&Con - (sint8 *)&Str == CON); + assert ((sint8 *)&Int - (sint8 *)&Str == INT); + assert ((sint8 *)&Wis - (sint8 *)&Str == WIS); + assert ((sint8 *)&Pow - (sint8 *)&Str == POW); + assert ((sint8 *)&Cha - (sint8 *)&Str == CHA); + } + + sint8 &stat (int index) + { + check_ordering (); + return ((sint8 *)&Str)[index]; + } + + sint8 stat (int index) const + { + check_ordering (); + return ((const sint8 *)&Str)[index]; + } }; #endif