Planeshift

psclientchar.h

Go to the documentation of this file.
00001 /*
00002  * psclientchar.h 
00003  *
00004  * Copyright (C) 2002 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  * Manages details about the player as it talks to it's server version
00019  */
00020 #ifndef PS_CLIENT_CHAR_H
00021 #define PS_CLIENT_CHAR_H
00022 //=============================================================================
00023 // Crystal Space Includes
00024 //=============================================================================
00025 #include <csutil/ref.h>
00026 #include <iutil/document.h>
00027 #include <csutil/refarr.h>
00028 #include <imesh/spritecal3d.h>
00029 #include <csgeom/vector4.h>
00030 
00031 //=============================================================================
00032 // Project Includes
00033 //=============================================================================
00034 #include "net/cmdbase.h"
00035 #include "net/charmessages.h"
00036 
00037 #include "util/namegenerator.h"
00038 
00039 //=============================================================================
00040 // Local Includes
00041 //=============================================================================
00042 
00043 struct iVFS;
00044 struct iObjectRegistry;
00045 struct iSector;
00046 struct iMeshObjectFactory;
00047 
00048 class MsgHandler;
00049 class MsgEntry;
00050 
00051 class psCelClient;
00052 class psCreationManager;
00053 
00054 class GEMClientObject;
00055 
00058 struct Trait
00059 {
00060     void Load( iDocumentNode * node);
00061     PSTRAIT_LOCATION ConvertTraitLocationString(const char *locationstring);
00062 
00063     static const char* locationString[];
00064     const char* GetLocationString() const;
00065     unsigned int uid;
00066     unsigned int next_trait_uid;
00067     Trait *next_trait,*prev_trait;
00068     unsigned int raceID;
00069     PSCHARACTER_GENDER gender;
00070     PSTRAIT_LOCATION location;
00071     csString name;
00072     csString mesh;
00073     csString material;
00074     csString subMesh;
00075     csVector3 shader;   
00076 };
00077 
00078 
00083 class psClientCharManager : public psClientNetSubscriber
00084 {
00085 public:
00086     psClientCharManager(iObjectRegistry *objectreg);    
00087     virtual ~psClientCharManager();
00088     bool Initialize( MsgHandler* msghandler, psCelClient* );
00089        
00091     bool Ready() { return ready; }
00092     
00094     virtual void HandleMessage( MsgEntry* me );
00095     
00096     psCreationManager* GetCreation() { return charCreation; }
00097 
00106     void SetTarget(GEMClientObject *newTarget, const char *action, bool notifyServer=true);
00107 
00111     void LockTarget(bool state);
00112 
00116     GEMClientObject * GetTarget() { return target; };
00117 
00118 protected:
00120     void ChangeTrait(MsgEntry* me);
00121 
00123     void HandleAction(MsgEntry* me);
00124 
00126     void HandleEquipment(MsgEntry* me);
00127 
00129     void HandleEffect(MsgEntry* me);
00130 
00131     void HandleEffectStop(MsgEntry* me);
00132 
00134     void HandleRejectCharMessage(MsgEntry* me);
00135 
00137     void HandlePlaySound(MsgEntry* me);
00138 
00140     void HandleTargetUpdate(MsgEntry* me);
00141 
00142     csRef<MsgHandler>         msghandler;
00143     iObjectRegistry*          objectReg;
00144     csRef<iVFS>               vfs;
00145 
00146     psCreationManager* charCreation;
00147 
00149     unsigned int targetEffect;
00150 
00152     GEMClientObject * target;
00153 
00154     psCelClient *cel;
00155     bool ready;
00156 
00158     bool lockedTarget;
00159 
00160     csHash<unsigned int, uint32_t> effectMapper;
00161 };
00162 
00163 
00164 //------------------------------------------------------------------------------
00165     
00166 
00167 #define REQUESTING_CP -1
00168 
00169 
00172 struct CustomChoice
00173 {    
00174     void Load( iDocumentNode* node );
00175     csString mesh;
00176     csString material;
00177     csString name; 
00178     csString texture;
00179     PSCHARACTER_GENDER gender;
00180     int id;
00181 };
00182 
00183 //------------------------------------------------------------------------------
00184 
00188 struct MaterialSet
00189 {
00190     void Load( iDocumentNode* node );
00191     csString name;
00192     PSCHARACTER_GENDER gender;
00193     csPDelArray<CustomChoice> materials;
00194     int id;
00195 };
00196 
00197 
00198 //------------------------------------------------------------------------------
00199 
00205 struct RaceDefinition
00206 {
00207     csString name;              
00208     csString description;       
00209     
00210     csString femaleModelName;   
00211     csString maleModelName;
00212 
00213     bool femaleAvailable;
00214     bool maleAvailable;
00215             
00216     int startingCP;    
00217     
00218     // Camera positions for this race allows different heights
00219     csVector3 FollowPos, LookatPos, FirstPos, ViewerPos;
00220     
00221     csArray<Trait*> location[PSTRAIT_LOCATION_COUNT][PSCHARACTER_GENDER_COUNT];
00222     
00224     csVector3 zoomLocations[PSTRAIT_LOCATION_COUNT];
00225 };
00226 
00227 //------------------------------------------------------------------------------
00228 
00231 struct PathDefinition
00232 {
00233     csString name;
00234 
00235     struct Bonus
00236     {
00237         csString name;
00238         float value;
00239     };
00240 
00241     csPDelArray<Bonus> statBonuses;
00242     csPDelArray<Bonus> skillBonuses;
00243     
00244     csString info;
00245     csString parents;
00246     csString life;
00247 };
00248 
00249 //------------------------------------------------------------------------------
00250 
00261 class psCreationManager : public psClientNetSubscriber
00262 {
00263 public:
00264     
00265     psCreationManager(iObjectRegistry *objectreg);
00266     virtual ~psCreationManager();
00267 
00268     void HandleMessage( MsgEntry* me );
00269    
00277     int GetRaceCP( int race );
00278     
00286     const char* GetRaceDescription( int race );
00287     
00288     RaceDefinition* GetRace( int race );
00289     RaceDefinition* GetRace( const char* name );
00290 
00291     typedef csPDelArray<PathDefinition>::Iterator PathIterator;
00292     PathIterator GetPathIterator();
00293 
00294     PathDefinition* GetPath(int i);
00295 
00296     typedef csPDelArray<Trait>::Iterator TraitIterator;
00297     TraitIterator GetTraitIterator() { return traits.GetIterator(); };
00298     Trait* GetTrait(unsigned int uid);
00299     
00303     void GetParentData();
00304     void GetChildhoodData();
00305     void GetLifeEventData();
00306     void GetTraitData();
00307 
00308     
00310     bool HasParentData() { return hasParentData; }
00311     bool HasChildhoodData() { return hasChildhoodData; }
00312     bool HasLifeEventData() { return hasLifeEventData; }
00313 
00321     const char* GetModelName( int race, int gender );
00322     
00324     csArray<CreationChoice> parentData;  
00325     
00327     csArray<CreationChoice> childhoodData;
00328  
00329     //
00330     csArray<LifeEventChoice> lifeEventData;
00331     
00332     const char* GetDescription( int choiceID );
00333     
00334     int GetCurrentCP() { return currentCP; }
00335     void SetCurrentCP( int value ) { currentCP = value; }
00336     
00338     void SetRace( int selectedRace );
00339     int  GetSelectedRace() { return selectedRace; }
00340     
00341     void SetGender( int gender ) { selectedGender = gender; }
00342     int  GetSelectedGender() { return selectedGender; }
00343     
00344     void UploadChar( bool doVerify = false );
00345     void SetName( const char* newName );
00346     const char* GetName();
00347     
00348     LifeEventChoice* FindLifeEvent( int idNumber );
00349 
00350     void AddChoice( int choice, int modifier = 1 );
00351     void RemoveChoice( uint32_t choice, int modifier = 1 );
00352     csArray<uint32_t> GetChoicesMade() { return choicesMade;}
00353     CreationChoice* GetChoice(int id);
00354     void AddLifeEvent( int event );
00355     void RemoveLifeEvent( uint32_t event );
00356     csArray<uint32_t> GetLifeChoices() { return lifeEventsMade;}
00357     size_t GetNumberOfLifeChoices() { return lifeEventsMade.GetSize(); }
00358     
00359     int GetCost(int idChoice);
00360     int GetLifeCost( int id );
00361     
00362     void SetCustomization( int face, int hairStyle, int beardStyle, int hairColour, int skinColour );
00370     void GetCustomization( int& face, int& hairStyle, int& beardStyle, int& hairColour, int& skinColour);
00371     
00372     void GenerateName(int type,csString &namebuffer,int max_low,int max_high)
00373     { nameGenerator->GenerateName( type, namebuffer, max_low, max_high ); }
00374         
00375     const char* GetLifeEventDescription( int id );
00376 
00377     bool IsAvailable(int id,int gender);
00378     
00379     void SetFatherMod( int mod ) { fatherMod = mod; }
00380     void SetMotherMod( int mod ) { motherMod = mod; }
00381     const char *GetFatherModAsText( void ) { switch (fatherMod) { case 2: return "Famous "; case 3: return "Exceptional "; default: return "";} }
00382     const char *GetMotherModAsText( void ) { switch (motherMod) { case 2: return "Famous "; case 3: return "Exceptional "; default: return "";} }
00383 
00384     void ClearChoices();
00385     void SetPath( const char* name ) { path = name; }
00386 private:
00387     iObjectRegistry* objectReg;
00388 
00390     csString path;
00391     
00393     void LoadRaceInformation();
00394 
00396     void LoadPathInfo();
00397    
00399     csPDelArray<RaceDefinition> raceDescriptions;    
00400 
00402     csPDelArray<PathDefinition> pathDefinitions;
00403 
00405     csPDelArray<Trait> traits;    
00406     
00407     csRef<MsgHandler> msgHandler;
00408     
00410     bool hasParentData;
00411     bool hasChildhoodData;
00412     bool hasLifeEventData;
00413     bool hasTraitData;
00414 
00415     void HandleVerify( MsgEntry* me );
00416     void HandleParentsData( MsgEntry* me );  
00417     void HandleChildhoodData( MsgEntry* me );
00418     void HandleLifeEventData( MsgEntry* me );
00419     void HandleTraitData( MsgEntry* me );
00420     
00421     NameGenerationSystem * nameGenerator;
00422     
00424     // Data chosen in char creation screens
00426     csString selectedName;
00427     int selectedRace;
00428     int selectedGender;
00429     int currentCP;
00430     csArray<uint32_t> choicesMade;
00431     csArray<uint32_t> lifeEventsMade;     
00432     
00433     int selectedFace;
00434     int selectedHairStyle;
00435     int selectedBeardStyle;
00436     int selectedHairColour;
00437     int selectedSkinColour;  
00438     
00439     int fatherMod;
00440     int motherMod;
00441 };
00442 
00443 
00444 
00445 #endif