Planeshift

vitals.h

Go to the documentation of this file.
00001 /*
00002  * vitals.h
00003  *
00004  * Copyright (C) 2005 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program 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  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00020 #ifndef PS_VITAL_HEADER
00021 #define PS_VITAL_HEADER
00022 
00023 #define HP_REGEN_RATE  0.2F
00024 #define MANA_REGEN_RATE  0.2F
00025 
00026 
00030 enum PS_VITALS
00031 {
00032     VITAL_HITPOINTS,
00033     VITAL_MANA,
00034     VITAL_PYSSTAMINA,
00035     VITAL_MENSTAMINA,
00036     VITAL_COUNT   // Count used to build a array of vitals, not a legal vital name
00037 };
00038 
00040 enum PS_DIRTY_VITALS
00041 {
00042     DIRTY_VITAL_HP              = 0x0001,
00043     DIRTY_VITAL_HP_MAX          = 0x0002,
00044     DIRTY_VITAL_HP_RATE         = 0x0004,
00045     DIRTY_VITAL_MANA            = 0x0008,
00046     DIRTY_VITAL_MANA_MAX        = 0x0010,
00047     DIRTY_VITAL_MANA_RATE       = 0x0020,
00048     DIRTY_VITAL_PYSSTAMINA      = 0x0040,
00049     DIRTY_VITAL_PYSSTAMINA_MAX  = 0x0080,
00050     DIRTY_VITAL_PYSSTAMINA_RATE = 0x0100,
00051     DIRTY_VITAL_MENSTAMINA      = 0x0200,
00052     DIRTY_VITAL_MENSTAMINA_MAX  = 0x0400,
00053     DIRTY_VITAL_MENSTAMINA_RATE = 0x0800,
00054     DIRTY_VITAL_EXPERIENCE      = 0x1000,
00055     DIRTY_VITAL_PROGRESSION     = 0x2000,
00056     DIRTY_VITAL_ALL = DIRTY_VITAL_HP | DIRTY_VITAL_HP_MAX | DIRTY_VITAL_HP_RATE |
00057                       DIRTY_VITAL_MANA | DIRTY_VITAL_MANA_MAX |DIRTY_VITAL_MANA_RATE |
00058                       DIRTY_VITAL_PYSSTAMINA | DIRTY_VITAL_PYSSTAMINA_MAX | DIRTY_VITAL_PYSSTAMINA_RATE |
00059                       DIRTY_VITAL_MENSTAMINA | DIRTY_VITAL_MENSTAMINA_MAX | DIRTY_VITAL_MENSTAMINA_RATE |
00060                       DIRTY_VITAL_EXPERIENCE |
00061                       DIRTY_VITAL_PROGRESSION
00062 };
00063 
00067 template <typename Vital>
00068 class psVitalManager
00069 {
00070 public:
00071     psVitalManager()
00072     {
00073         experiencePoints  = 0;
00074         progressionPoints = 0;
00075         lastDRUpdate = 0;
00076     }
00077     ~psVitalManager() {}
00078     
00079     void SetVitals(const psVitalManager & newVitalMgr)
00080     {
00081         for(int i = 0; i < VITAL_COUNT; i++)
00082         {
00083             vitals[i] = newVitalMgr.vitals[i];
00084         }
00085     }
00086 
00088     void ResetVitals()
00089     {
00090         for (int i = 0; i < VITAL_COUNT; i++)
00091             vitals[i] = origVitals[i];
00092     }
00093 
00095     void SetOrigVitals()
00096     {
00097         for (int i = 0; i < VITAL_COUNT; i++)
00098             origVitals[i] = vitals[i];
00099     }
00100 
00106     Vital & GetVital(int vital)
00107     {
00108         CS_ASSERT(vital >= 0 && vital < VITAL_COUNT);
00109         return vitals[vital];
00110     }
00111 
00112     // Quick accessors
00113     float GetHP()
00114     {
00115         return vitals[VITAL_HITPOINTS].value;
00116     }
00117 
00118     float GetMana()
00119     {
00120         return vitals[VITAL_MANA].value;
00121     }
00122 
00123     float GetPStamina()
00124     {
00125         return vitals[VITAL_PYSSTAMINA].value;
00126     }
00127 
00128     float GetMStamina()
00129     {
00130         return vitals[VITAL_MENSTAMINA].value;
00131     }
00132 
00134     unsigned int GetExp() { return experiencePoints; }
00135 
00137     unsigned int GetPP()  { return progressionPoints; }
00138 
00139 protected:
00140     csTicks lastDRUpdate;
00141 
00143     Vital vitals[VITAL_COUNT];
00144     Vital origVitals[VITAL_COUNT]; // saved copy for quick restore
00145 
00147     unsigned int experiencePoints;
00148 
00150     unsigned int progressionPoints;
00151 };
00152 #endif