--- deliantra/server/include/living.h 2007/01/15 21:06:19 1.12 +++ deliantra/server/include/living.h 2007/05/12 18:34:19 1.14 @@ -1,5 +1,5 @@ /* - * CrossFire, A Multiplayer game for X-windows + * CrossFire, A Multiplayer game * * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team * Copyright (C) 2002 Mark Wedel & Crossfire Development Team @@ -25,6 +25,8 @@ #ifndef LIVING_H #define LIVING_H +#include + // corresponds to some arrays in common/living.C enum { STR, @@ -82,6 +84,32 @@ sint16 ACC (RW, grace); /* Grace. Used to invoke clerical prayers. */ sint16 ACC (RW, maxgrace); /* Grace. Used to invoke clerical prayers. */ + + // 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