Planeshift

servervitals.h

Go to the documentation of this file.
00001 /*
00002  * servervitals.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 SERVER_VITALS_HEADER
00021 #define SERVER_VITALS_HEADER
00022 #include "psstdint.h"
00023 
00024 //=============================================================================
00025 // Crystal Space Includes
00026 //=============================================================================
00027 
00028 //=============================================================================
00029 // Project Includes
00030 //=============================================================================
00031 #include "util/psconst.h"
00032 #include "rpgrules/vitals.h"
00033 #include "../playergroup.h"
00034 
00035 //=============================================================================
00036 // Local Includes
00037 //=============================================================================
00038 
00039 class MsgEntry;
00040 class psCharacter;
00041 
00043 class VitalBuffable : public Buffable<float>
00044 {
00045 public:
00046     virtual ~VitalBuffable() { }
00047 
00048     void Initialize(unsigned int* sDirty, int dirtyF)
00049     {
00050         statsDirty = sDirty;
00051         dirtyFlag = dirtyF;
00052     }
00053 
00054 protected:
00055     virtual void OnChange()
00056     {
00057         *statsDirty |= dirtyFlag;
00058     }
00059 
00060     int dirtyFlag; 
00061     unsigned int* statsDirty; 
00062 };
00063 
00065 struct Vital
00066 {
00067     Vital() : value(0.0) {}
00068 
00069     float value;
00070     VitalBuffable drRate; 
00071     VitalBuffable max;
00072 };
00073 
00074 //----------------------------------------------------------------------------
00075 
00080 class psServerVitals : public psVitalManager<Vital>
00081 {
00082 public:
00083     psServerVitals(psCharacter* character);
00084 
00087     bool SendStatDRMessage(uint32_t clientnum, EID eid, unsigned int flags, csRef<PlayerGroup> group = NULL);
00088 
00089     bool Update(csTicks now);
00090 
00091     void SetExp(unsigned int exp);
00092     void SetPP(unsigned int pp);
00093 
00094     void SetVital(int vitalName, int dirtyFlag, float value);
00095     void AdjustVital(int vitalName, int dirtyFlag, float delta);
00096 
00099     unsigned int GetStatsDirtyFlags() const;
00100 
00103     void SetAllStatsDirty();
00104 
00107     void ClearStatsDirtyFlags(unsigned int dirtyFlags);
00108 
00109 private:
00111     void ClampVital(int vital);
00112 
00120     Vital &DirtyVital(int vitalName, int dirtyFlag);
00121 
00123     unsigned int statsDirty;
00124     unsigned char version;
00125     psCharacter* character;  
00126 };
00127 
00128 #endif
00129