Planeshift
skillcache.h
Go to the documentation of this file.
1 /*
2  * skillcache.h
3  *
4  * Copyright (C) 2006 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  *
18  */
19 
20 #ifndef PS_SKILL_CACHE_H
21 #define PS_SKILL_CACHE_H
22 
23 #include <csutil/list.h>
24 #include <csutil/csstring.h>
25 
26 class MsgEntry;
27 
38 
39  public:
40 
44  enum Oper {
47  };
48 
53 
61  psSkillCacheItem(unsigned int nameId);
62 
68  psSkillCacheItem(int skillId,
69  unsigned int nameId,
70  unsigned short R,
71  unsigned short AS,
72  unsigned short Y,
73  unsigned short YC,
74  unsigned short Z,
75  unsigned short ZC,
76  unsigned short CAT,
77  bool stat = false);
78 
80 
85  void update(unsigned short R,
86  unsigned short AS,
87  unsigned short Y,
88  unsigned short YC,
89  unsigned short Z,
90  unsigned short ZC);
91 
95  void update(psSkillCacheItem *item);
96 
100  unsigned short size() const;
101 
106  void write(MsgEntry *);
107 
112  void read(MsgEntry *);
113 
114  bool isModified() const { return modified; }
115  void setModified(bool modified) { this->modified = modified; }
116  bool isRemoved() const { return removed; };
117  void setRemoved(bool value) {removed = value; modified = true; }
118 
119  bool isStat() const { return stat; }
120  int getSkillId() const { return skillId; }
121  unsigned int getNameId() const { return nameId; }
122  unsigned short getCategory() const { return category; }
123  unsigned short getRank() const { return rank; }
124  unsigned short getActualStat() const { return actualStat; }
125  unsigned short getKnowledge() const { return knowledge; }
126  unsigned short getKnowledgeCost() const { return knowledgeCost; }
127  unsigned short getPractice() const { return practice; }
128  unsigned short getPracticeCost() const { return practiceCost; }
129 
130  private:
131  bool removed;
132  bool modified;
133 
134  unsigned int nameId;
135  int skillId;
136 
137  unsigned short rank;
138  unsigned short actualStat;
139  unsigned short knowledge;
140  unsigned short practice;
141  unsigned short knowledgeCost;
142  unsigned short practiceCost;
143  unsigned short category;
144  bool stat;
145 
146 };
147 
151 typedef csList<psSkillCacheItem *>::Iterator psSkillCacheIter;
152 
159 
160  public:
161  psSkillCache();
162  ~psSkillCache();
163 
170  void apply(psSkillCache *list);
171 
178  void addItem(int skillId, psSkillCacheItem *item);
179 
186  psSkillCacheItem *getItemBySkillId(uint id);
187 
188  psSkillCacheIter iterBegin() { return psSkillCacheIter(skillCache); }
189 
194  void clear();
195 
199  void setModified(bool modified);
200 
205  bool isModified();
206 
210  void setRemoved(bool removed);
211 
215  bool hasRemoved();
216 
217  void setProgressionPoints(unsigned int points);
218  unsigned int getProgressionPoints() const { return progressionPoints; }
219 
220  void setNew(bool value) { newList = value; }
221  bool isNew() const { return newList; }
222 
226  unsigned short size() const;
227 
231  unsigned short count() const;
232 
239  void write(MsgEntry *);
240 
245  void read(MsgEntry *);
246 
250  csString ToString() const;
251 
252  private:
253  csList<psSkillCacheItem *> skillCache;
254  bool modified;
255  bool removed;
256  unsigned int progressionPoints;
257  bool newList;
258 
262  bool deleteItem(psSkillCacheItem *item);
263 
264 };
265 
268 #endif
void write(MsgEntry *)
Writes the cache item to the message entry and changes the modified state to false.
Oper
Operations with this skill item:
Definition: skillcache.h:44
psSkillCacheItem item is one stat or skill in the skill cache.
Definition: skillcache.h:37
unsigned short getRank() const
Definition: skillcache.h:123
bool isStat() const
Definition: skillcache.h:119
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
psSkillCacheIter iterBegin()
Definition: skillcache.h:188
unsigned short getPracticeCost() const
Definition: skillcache.h:128
unsigned int getProgressionPoints() const
Definition: skillcache.h:218
void setNew(bool value)
Definition: skillcache.h:220
bool isModified() const
Definition: skillcache.h:114
The psSkillCache class implements the skill cache both on the server and on the client.
Definition: skillcache.h:158
The item is updated or added.
Definition: skillcache.h:45
bool isRemoved() const
Definition: skillcache.h:116
The item should be removed from the list.
Definition: skillcache.h:46
void setModified(bool modified)
Definition: skillcache.h:115
unsigned short getCategory() const
Definition: skillcache.h:122
unsigned short getKnowledge() const
Definition: skillcache.h:125
bool isNew() const
Definition: skillcache.h:221
csList< psSkillCacheItem * >::Iterator psSkillCacheIter
Skill cache iterator.
Definition: skillcache.h:151
unsigned short getPractice() const
Definition: skillcache.h:127
void setRemoved(bool value)
Definition: skillcache.h:117
unsigned short getKnowledgeCost() const
Definition: skillcache.h:126
unsigned short size() const
Calculates the number of bytes needed for the message entry.
psSkillCacheItem(psSkillCacheItem *item)
Constructs the cache item using values from another cache item.
void read(MsgEntry *)
Reads the cache item from the message entry and sets the modified state to true.
unsigned short getActualStat() const
Definition: skillcache.h:124
int getSkillId() const
Definition: skillcache.h:120
void update(unsigned short R, unsigned short AS, unsigned short Y, unsigned short YC, unsigned short Z, unsigned short ZC)
The update() function updates the cache item and sets the modified state if needed.
unsigned int getNameId() const
Definition: skillcache.h:121