Planeshift

skillcache.h

Go to the documentation of this file.
00001 /*
00002  * skillcache.h
00003  *
00004  * Copyright (C) 2006 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_SKILL_CACHE_H
00021 #define PS_SKILL_CACHE_H
00022 
00023 #include <csutil/list.h>
00024 #include <csutil/csstring.h>
00025 
00026 class MsgEntry;
00027 
00037 class psSkillCacheItem {
00038 
00039     public:
00040 
00044         enum Oper {
00045             UPDATE_OR_ADD, 
00046             REMOVE         
00047         };
00048 
00052         psSkillCacheItem(psSkillCacheItem *item);
00053 
00061         psSkillCacheItem(unsigned int nameId);
00062 
00068         psSkillCacheItem(int skillId,
00069                          unsigned int nameId,
00070                          unsigned short R,
00071                          unsigned short AS,
00072                          unsigned short Y,
00073                          unsigned short YC,
00074                          unsigned short Z,
00075                          unsigned short ZC,
00076                          unsigned short CAT,
00077                          bool stat = false);
00078 
00079         ~psSkillCacheItem();
00080 
00085         void update(unsigned short R,
00086                     unsigned short AS,
00087                     unsigned short Y,
00088                     unsigned short YC,
00089                     unsigned short Z,
00090                     unsigned short ZC);
00091 
00095         void update(psSkillCacheItem *item);
00096 
00100         unsigned short size() const;
00101 
00106         void write(MsgEntry *);
00107 
00112         void read(MsgEntry *);
00113 
00114         bool isModified() const { return modified; }
00115         void setModified(bool modified) { this->modified = modified; }
00116         bool isRemoved() const { return removed; };
00117         void setRemoved(bool value) {removed = value; modified = true; }
00118 
00119         bool isStat() const { return stat; }
00120         int getSkillId() const { return skillId; }
00121         unsigned int getNameId() const { return nameId; }
00122         unsigned short getCategory() const { return category; }
00123         unsigned short getRank() const { return rank; }
00124         unsigned short getActualStat() const { return actualStat; }
00125         unsigned short getKnowledge() const { return knowledge; }
00126         unsigned short getKnowledgeCost() const { return knowledgeCost; }
00127         unsigned short getPractice() const { return practice; }
00128         unsigned short getPracticeCost() const { return practiceCost; }
00129 
00130     private:
00131         bool removed;
00132         bool modified;
00133         
00134         unsigned int nameId;
00135         int skillId;
00136 
00137         unsigned short rank;
00138         unsigned short actualStat;
00139         unsigned short knowledge;
00140         unsigned short practice;
00141         unsigned short knowledgeCost;
00142         unsigned short practiceCost;
00143         unsigned short category;
00144         bool stat;
00145 
00146 };
00147 
00151 typedef csList<psSkillCacheItem *>::Iterator psSkillCacheIter;
00152 
00158 class psSkillCache {
00159 
00160     public:
00161         psSkillCache();
00162         ~psSkillCache();
00163 
00170         void apply(psSkillCache *list);
00171 
00178         void addItem(int skillId, psSkillCacheItem *item);
00179 
00186         psSkillCacheItem *getItemBySkillId(uint id);
00187 
00188         psSkillCacheIter iterBegin() { return psSkillCacheIter(skillCache); }
00189 
00194         void clear();
00195 
00199         void setModified(bool modified);
00200 
00205         bool isModified();
00206         
00210         void setRemoved(bool removed);
00211         
00215         bool hasRemoved();
00216 
00217         void setProgressionPoints(unsigned int points);
00218         unsigned int getProgressionPoints() const { return progressionPoints; }
00219 
00220         void setNew(bool value) { newList = value; }
00221         bool isNew() const { return newList; }
00222 
00226         unsigned short size() const;
00227 
00231         unsigned short count() const;
00232 
00239         void write(MsgEntry *);
00240 
00245         void read(MsgEntry *);
00246 
00250         csString ToString() const;
00251 
00252     private:
00253         csList<psSkillCacheItem *> skillCache;
00254         bool modified;
00255         bool removed;
00256         unsigned int progressionPoints;
00257         bool newList;
00258 
00262         bool deleteItem(psSkillCacheItem *item);
00263 
00264 };
00265 
00268 #endif