Planeshift
psclientchar.h
Go to the documentation of this file.
1 /*
2  * psclientchar.h
3  *
4  * Copyright (C) 2002 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  * Manages details about the player as it talks to it's server version
19  */
20 #ifndef PS_CLIENT_CHAR_H
21 #define PS_CLIENT_CHAR_H
22 //=============================================================================
23 // Crystal Space Includes
24 //=============================================================================
25 #include <csutil/ref.h>
26 #include <iutil/document.h>
27 #include <csutil/refarr.h>
28 #include <imesh/spritecal3d.h>
29 #include <csgeom/vector4.h>
30 
31 //=============================================================================
32 // Project Includes
33 //=============================================================================
34 #include "net/cmdbase.h"
35 #include "net/charmessages.h"
36 
37 #include "util/namegenerator.h"
38 
39 //=============================================================================
40 // Local Includes
41 //=============================================================================
42 
43 struct iVFS;
44 struct iObjectRegistry;
45 struct iSector;
46 struct iMeshObjectFactory;
47 
48 class MsgHandler;
49 class MsgEntry;
50 
51 class psCelClient;
52 class psCreationManager;
53 
54 class GEMClientObject;
55 
58 struct Trait
59 {
60  void Load( iDocumentNode * node);
61  PSTRAIT_LOCATION ConvertTraitLocationString(const char *locationstring);
62 
63  static const char* locationString[];
64  const char* GetLocationString() const;
65  unsigned int uid;
66  unsigned int next_trait_uid;
68  unsigned int raceID;
71  csString name;
72  csString mesh;
73  csString material;
74  csString subMesh;
75  csVector3 shader;
76 };
77 
78 
84 {
85 public:
86  psClientCharManager(iObjectRegistry *objectreg);
87  virtual ~psClientCharManager();
88  bool Initialize( MsgHandler* msghandler, psCelClient* );
89 
91  bool Ready() { return ready; }
92 
94  virtual void HandleMessage( MsgEntry* me );
95 
96  psCreationManager* GetCreation() { return charCreation; }
97 
106  void SetTarget(GEMClientObject *newTarget, const char *action, bool notifyServer=true);
107 
111  void LockTarget(bool state);
112 
116  GEMClientObject * GetTarget() { return target; };
117 
118 protected:
120  void ChangeTrait(MsgEntry* me);
121 
123  void HandleAction(MsgEntry* me);
124 
126  void HandleEquipment(MsgEntry* me);
127 
129  void HandleEffect(MsgEntry* me);
130 
131  void HandleEffectStop(MsgEntry* me);
132 
134  void HandleRejectCharMessage(MsgEntry* me);
135 
137  void HandlePlaySound(MsgEntry* me);
138 
140  void HandleTargetUpdate(MsgEntry* me);
141 
142  csRef<MsgHandler> msghandler;
143  iObjectRegistry* objectReg;
144  csRef<iVFS> vfs;
145 
147 
149  unsigned int targetEffect;
150 
153 
155  bool ready;
156 
159 
160  csHash<unsigned int, uint32_t> effectMapper;
161 };
162 
163 
164 //------------------------------------------------------------------------------
165 
166 
167 #define REQUESTING_CP -1
168 
169 
173 {
174  void Load( iDocumentNode* node );
175  csString mesh;
176  csString material;
177  csString name;
178  csString texture;
180  int id;
181 };
182 
183 //------------------------------------------------------------------------------
184 
189 {
190  void Load( iDocumentNode* node );
191  csString name;
193  csPDelArray<CustomChoice> materials;
194  int id;
195 };
196 
197 
198 //------------------------------------------------------------------------------
199 
206 {
207  csString name;
208  csString description;
209 
210  csString femaleModelName;
211  csString maleModelName;
212 
215 
217 
218  // Camera positions for this race allows different heights
219  csVector3 FollowPos, LookatPos, FirstPos, ViewerPos;
220 
222 
224  csVector3 zoomLocations[PSTRAIT_LOCATION_COUNT];
225 };
226 
227 //------------------------------------------------------------------------------
228 
232 {
233  csString name;
234 
235  struct Bonus
236  {
237  csString name;
238  float value;
239  };
240 
241  csPDelArray<Bonus> statBonuses;
242  csPDelArray<Bonus> skillBonuses;
243 
244  csString info;
245  csString parents;
246  csString life;
247 };
248 
249 //------------------------------------------------------------------------------
250 
262 {
263 public:
264 
265  psCreationManager(iObjectRegistry *objectreg);
266  virtual ~psCreationManager();
267 
268  void HandleMessage( MsgEntry* me );
269 
277  int GetRaceCP( int race );
278 
286  const char* GetRaceDescription( int race );
287 
288  RaceDefinition* GetRace( int race );
289  RaceDefinition* GetRace( const char* name );
290 
291  typedef csPDelArray<PathDefinition>::Iterator PathIterator;
292  PathIterator GetPathIterator();
293 
294  PathDefinition* GetPath(int i);
295 
296  typedef csPDelArray<Trait>::Iterator TraitIterator;
297  TraitIterator GetTraitIterator() { return traits.GetIterator(); };
298  Trait* GetTrait(unsigned int uid);
299 
303  void GetParentData();
304  void GetChildhoodData();
305  void GetLifeEventData();
306  void GetTraitData();
307 
308 
310  bool HasParentData() { return hasParentData; }
311  bool HasChildhoodData() { return hasChildhoodData; }
312  bool HasLifeEventData() { return hasLifeEventData; }
313 
321  const char* GetModelName( int race, int gender );
322 
324  csArray<CreationChoice> parentData;
325 
327  csArray<CreationChoice> childhoodData;
328 
329  //
330  csArray<LifeEventChoice> lifeEventData;
331 
332  const char* GetDescription( int choiceID );
333 
334  int GetCurrentCP() { return currentCP; }
335  void SetCurrentCP( int value ) { currentCP = value; }
336 
338  void SetRace( int selectedRace );
339  int GetSelectedRace() { return selectedRace; }
340 
341  void SetGender( int gender ) { selectedGender = gender; }
342  int GetSelectedGender() { return selectedGender; }
343 
344  void UploadChar( bool doVerify = false );
345  void SetName( const char* newName );
346  const char* GetName();
347 
348  LifeEventChoice* FindLifeEvent( int idNumber );
349 
350  void AddChoice( int choice, int modifier = 1 );
351  void RemoveChoice( uint32_t choice, int modifier = 1 );
352  csArray<uint32_t> GetChoicesMade() { return choicesMade;}
353  CreationChoice* GetChoice(int id);
354  void AddLifeEvent( int event );
355  void RemoveLifeEvent( uint32_t event );
356  csArray<uint32_t> GetLifeChoices() { return lifeEventsMade;}
357  size_t GetNumberOfLifeChoices() { return lifeEventsMade.GetSize(); }
358 
359  int GetCost(int idChoice);
360  int GetLifeCost( int id );
361 
362  void SetCustomization( int face, int hairStyle, int beardStyle, int hairColour, int skinColour );
370  void GetCustomization( int& face, int& hairStyle, int& beardStyle, int& hairColour, int& skinColour);
371 
372  void GenerateName(int type,csString &namebuffer,int max_low,int max_high)
373  { nameGenerator->GenerateName( type, namebuffer, max_low, max_high ); }
374 
375  const char* GetLifeEventDescription( int id );
376 
377  bool IsAvailable(int id,int gender);
378 
379  void SetFatherMod( int mod ) { fatherMod = mod; }
380  void SetMotherMod( int mod ) { motherMod = mod; }
381  const char *GetFatherModAsText( void ) { switch (fatherMod) { case 2: return "Famous "; case 3: return "Exceptional "; default: return "";} }
382  const char *GetMotherModAsText( void ) { switch (motherMod) { case 2: return "Famous "; case 3: return "Exceptional "; default: return "";} }
383 
384  void ClearChoices();
385  void SetPath( const char* name ) { path = name; }
386 private:
387  iObjectRegistry* objectReg;
388 
390  csString path;
391 
393  void LoadRaceInformation();
394 
396  void LoadPathInfo();
397 
399  csPDelArray<RaceDefinition> raceDescriptions;
400 
402  csPDelArray<PathDefinition> pathDefinitions;
403 
405  csPDelArray<Trait> traits;
406 
407  csRef<MsgHandler> msgHandler;
408 
410  bool hasParentData;
411  bool hasChildhoodData;
412  bool hasLifeEventData;
413  bool hasTraitData;
414 
415  void HandleVerify( MsgEntry* me );
416  void HandleParentsData( MsgEntry* me );
417  void HandleChildhoodData( MsgEntry* me );
418  void HandleLifeEventData( MsgEntry* me );
419  void HandleTraitData( MsgEntry* me );
420 
421  NameGenerationSystem * nameGenerator;
422 
424  // Data chosen in char creation screens
426  csString selectedName;
427  int selectedRace;
428  int selectedGender;
429  int currentCP;
430  csArray<uint32_t> choicesMade;
431  csArray<uint32_t> lifeEventsMade;
432 
433  int selectedFace;
434  int selectedHairStyle;
435  int selectedBeardStyle;
436  int selectedHairColour;
437  int selectedSkinColour;
438 
439  int fatherMod;
440  int motherMod;
441 };
442 
443 
444 
445 #endif
Manages character details for the client.
Definition: psclientchar.h:83
csString femaleModelName
Definition: psclientchar.h:210
Defines the structure needed to send a life event across the network.
Definition: charmessages.h:296
unsigned int raceID
Definition: psclientchar.h:68
csString material
Definition: psclientchar.h:73
void SetCurrentCP(int value)
Definition: psclientchar.h:335
void GenerateName(int type, csString &namebuffer, int max_low, int max_high)
Definition: psclientchar.h:372
A Creation Choice that the client can make.
Definition: charmessages.h:225
psCreationManager * GetCreation()
Definition: psclientchar.h:96
Defines a race.
Definition: psclientchar.h:205
Defines a character trait.
Definition: psclientchar.h:58
const char * GetName(int id)
csString mesh
Definition: psclientchar.h:175
PSCHARACTER_GENDER gender
Definition: psclientchar.h:192
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
csArray< CreationChoice > childhoodData
Holds data for the childhood data screen.
Definition: psclientchar.h:327
csPDelArray< Bonus > statBonuses
Definition: psclientchar.h:241
csArray< CreationChoice > parentData
A list of all the choices that are for the parent screen.
Definition: psclientchar.h:324
psCelClient * cel
Definition: psclientchar.h:154
static const char * locationString[]
Definition: psclientchar.h:63
csString maleModelName
Definition: psclientchar.h:211
csString name
Definition: psclientchar.h:177
PSTRAIT_LOCATION
Define the player controled base customization that their model can have.
Definition: charmessages.h:24
Client version of the Cel Manager Requests world loading.
Definition: pscelclient.h:108
Defines a material set.
Definition: psclientchar.h:188
csString description
Description of race ( for character creation )
Definition: psclientchar.h:208
const char * GetFatherModAsText(void)
Definition: psclientchar.h:381
bool HasParentData()
returns true if the parent data is cached.
Definition: psclientchar.h:310
bool lockedTarget
stores if target is locked
Definition: psclientchar.h:158
csPDelArray< Trait >::Iterator TraitIterator
Definition: psclientchar.h:296
csString name
Definition: psclientchar.h:71
csString mesh
Definition: psclientchar.h:72
unsigned int targetEffect
keeps track of the target effect ID
Definition: psclientchar.h:149
const char * GetMotherModAsText(void)
Definition: psclientchar.h:382
bool Ready()
Returns true when the character has been acked on the server.
Definition: psclientchar.h:91
Used to define a path in character creation.
Definition: psclientchar.h:231
iObjectRegistry * objectReg
Definition: psclientchar.h:143
csString name
Definition: psclientchar.h:191
csVector3 ViewerPos
Definition: psclientchar.h:219
unsigned int next_trait_uid
Definition: psclientchar.h:66
csArray< uint32_t > GetChoicesMade()
Definition: psclientchar.h:352
psCreationManager * charCreation
Definition: psclientchar.h:146
PSCHARACTER_GENDER
Definition: charmessages.h:14
PSTRAIT_LOCATION location
Definition: psclientchar.h:70
void void Initialize(iObjectRegistry *object_reg)
Trait * next_trait
Definition: psclientchar.h:67
An object that the client knows about.
Definition: pscelclient.h:373
csString subMesh
Definition: psclientchar.h:74
This class is the client&#39;s and server&#39;s main interface for either sending network messages out or get...
Definition: msghandler.h:106
csPDelArray< PathDefinition >::Iterator PathIterator
Definition: psclientchar.h:291
csPDelArray< CustomChoice > materials
Definition: psclientchar.h:193
GEMClientObject * target
keeps track of what object you have targetted
Definition: psclientchar.h:152
csString parents
Definition: psclientchar.h:245
Trait * prev_trait
Definition: psclientchar.h:67
void Load(iDocumentNode *node)
csArray< LifeEventChoice > lifeEventData
Definition: psclientchar.h:330
Defines a character creation choice for change of appearance.
Definition: psclientchar.h:172
const char * GetLocationString() const
unsigned int uid
Definition: psclientchar.h:65
csRef< iVFS > vfs
Definition: psclientchar.h:144
PSCHARACTER_GENDER gender
Definition: psclientchar.h:179
csHash< unsigned int, uint32_t > effectMapper
Definition: psclientchar.h:160
csArray< uint32_t > GetLifeChoices()
Definition: psclientchar.h:356
void SetPath(const char *name)
Definition: psclientchar.h:385
void SetFatherMod(int mod)
Definition: psclientchar.h:379
csString material
Definition: psclientchar.h:176
csRef< MsgHandler > msghandler
Definition: psclientchar.h:142
csVector3 shader
The shader colour set for this trait.
Definition: psclientchar.h:75
csString texture
Definition: psclientchar.h:178
csPDelArray< Bonus > skillBonuses
Definition: psclientchar.h:242
size_t GetNumberOfLifeChoices()
Definition: psclientchar.h:357
PSCHARACTER_GENDER gender
Definition: psclientchar.h:69
TraitIterator GetTraitIterator()
Definition: psclientchar.h:297
PSTRAIT_LOCATION ConvertTraitLocationString(const char *locationstring)
Handles all the details of the character creation on the client side.
Definition: psclientchar.h:261
GEMClientObject * GetTarget()
Gets the target of the character.
Definition: psclientchar.h:116
void SetMotherMod(int mod)
Definition: psclientchar.h:380
void SetGender(int gender)
Definition: psclientchar.h:341