Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

Alignment.h

00001 /*
00002  * Alignment.h -- class interface for alignments
00003  * Copyright (C) 2002  Eric Lemings <elemings@users.sourceforge.net>
00004  *
00005  * This software is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This software is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this software; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00018  * 02111-1307, USA
00019  *
00020  * RCS: $Id: Alignment.h,v 1.2 2003/04/18 01:41:03 elemings Exp $
00021  */
00022 
00023 #ifdef __cplusplus
00024 
00025 #  ifndef OGS_CORE_DETAILS_ALIGNMENT_H
00026 #    define OGS_CORE_DETAILS_ALIGNMENT_H
00027 
00028 #    include <ogs/core/Detail.h>
00029 #    include <ogs/core/details/Namespace.h>
00030 
00031 OGS_BEGIN_CORE_DETAILS_NAMESPACE
00032 
00048 class Alignment: public Detail {
00049   public:
00059     enum Value {
00060       // Absolute alignments
00061       LAW =                         1 << 3,
00062       CHAOS =                       1 << 2,
00063       NEUTRAL_ORDER =               (LAW | CHAOS),
00064 
00065       GOOD =                        1 << 1,
00066       EVIL =                        1 << 0,
00067       NEUTRAL_MORAL =               (GOOD | EVIL),
00068 
00069       // Relative alignments
00070       LAWFUL_GOOD =                 LAW | GOOD,
00071       NEUTRAL_GOOD =                NEUTRAL_ORDER | GOOD,
00072       CHAOTIC_GOOD =                CHAOS | GOOD,
00073 
00074       LAWFUL_NEUTRAL =              LAW | NEUTRAL_MORAL,
00075       TRUE_NEUTRAL =                NEUTRAL_ORDER | NEUTRAL_MORAL,
00076       CHAOTIC_NEUTRAL =             CHAOS | NEUTRAL_MORAL,
00077 
00078       LAWFUL_EVIL =                 LAW | EVIL,
00079       NEUTRAL_EVIL =                NEUTRAL_ORDER | EVIL,
00080       CHAOTIC_EVIL =                CHAOS | EVIL,
00081     };
00082 
00083     Alignment (Value value = TRUE_NEUTRAL);
00084 
00085     bool isAbsolute () const;
00086     bool isRelative () const;
00087     bool isAligned (const Alignment& a) const;
00088 
00089     Value getValue () const;
00090     void setValue (Value value);
00091 
00092     //const char* getName () const;
00093 
00094   private:
00095     Value _value;
00096 
00097     static bool isValid (int i);
00098 };
00099 
00106 inline Alignment::Alignment (Value value):
00107   _value (value) {
00108   // empty constructor body
00109 }
00110 
00116 inline bool
00117 Alignment::isAbsolute () const {
00118   return (this->_value == LAW || this->_value == CHAOS ||
00119           this->_value == NEUTRAL_ORDER || this->_value == GOOD ||
00120           this->_value == EVIL || this->_value == NEUTRAL_MORAL);
00121 }
00122 
00128 inline bool
00129 Alignment::isRelative () const {
00130   return (isValid (this->_value) && !isAbsolute ());
00131 }
00132 
00141 inline bool
00142 Alignment::isAligned (const Alignment& a) const {
00143   if (this->isAbsolute () && a.isAbsolute ()) {
00144     return (false);
00145   }
00146 
00147   return (this->_value & a._value);
00148 }
00149 
00155 inline Alignment::Value
00156 Alignment::getValue () const {
00157   return (this->_value);
00158 }
00159 
00165 inline void
00166 Alignment::setValue (Value value) {
00167   if (isValid (value)) {
00168     this->_value = value;
00169   }
00170 }
00171 
00178 inline bool
00179 Alignment::isValid (int i) {
00180   return (i >= EVIL && i <= TRUE_NEUTRAL);
00181 }
00182 
00183 OGS_END_CORE_DETAILS_NAMESPACE
00184 
00185 #  endif /* !defined OGS_CORE_DETAILS_ALIGNMENT_H */
00186 
00187 #endif /* defined __cplusplus */
00188 

Generated on Sun Apr 20 03:36:13 2003 for Open Gaming System (OGS) by doxygen1.3