kplayer.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __KPLAYER_H_
00022 #define __KPLAYER_H_
00023
00024 #include <qstring.h>
00025 #include <qobject.h>
00026 #include <qptrlist.h>
00027
00028 #include "kgameproperty.h"
00029 #include <kdemacros.h>
00030
00031 class KGame;
00032 class KGameIO;
00033 class KGamePropertyBase;
00034 class KGamePropertyHandler;
00035
00036 class KPlayerPrivate;
00037
00069 class KDE_EXPORT KPlayer : public QObject
00070 {
00071 Q_OBJECT
00072
00073 public:
00074 typedef QPtrList<KGameIO> KGameIOList;
00075
00076
00081 KPlayer();
00082
00088 KPlayer(KGame* game);
00089
00090 virtual ~KPlayer();
00091
00098 virtual int rtti() const {return 0;}
00099
00103 void Debug();
00104
00105
00111 KGameIOList *ioList() {return &mInputList;}
00112
00120 void setGame(KGame *game) {mGame=game;}
00121
00127 KGame *game() const {return mGame;}
00128
00136 void setAsyncInput(bool a) {mAsyncInput = a;}
00137
00144 bool asyncInput() const {return mAsyncInput.value();}
00145
00155 bool isVirtual() const;
00156
00164 void setVirtual(bool v);
00165
00173 bool isActive() const {return mActive;}
00174
00180 void setActive(bool v) {mActive=v;}
00181
00187 Q_UINT32 id() const;
00188
00189
00190
00191
00192
00193
00194 void setId(Q_UINT32 i);
00195
00207 int userId() const {return mUserId.value();}
00208
00209
00210
00211
00212
00213 void setUserId(int i) {mUserId = i;}
00214
00225 int networkPriority() const;
00226
00243 void setNetworkPriority(int b);
00244
00250 KPlayer *networkPlayer() const;
00251
00255 void setNetworkPlayer(KPlayer *p);
00256
00257
00262 void setGroup(const QString& group);
00263
00267 virtual const QString& group() const;
00268
00274 void setName(const QString& name);
00275
00279 virtual const QString& name() const;
00280
00281
00282
00291 bool addGameIO(KGameIO *input);
00292
00303 bool removeGameIO(KGameIO *input=0,bool deleteit=true);
00304
00312 KGameIO *findRttiIO(int rtti) const;
00313
00321 bool hasRtti(int rtti) const {return findRttiIO(rtti)!=0;}
00322
00323
00336 virtual bool forwardInput(QDataStream &msg,bool transmit=true, Q_UINT32 sender=0);
00337
00341 virtual bool forwardMessage(QDataStream &msg,int msgid,Q_UINT32 receiver=0,Q_UINT32 sender=0);
00342
00343
00349 bool myTurn() const {return mMyTurn.value();}
00350
00360 bool setTurn(bool b,bool exclusive=true);
00361
00362
00363
00375 virtual bool load(QDataStream &stream);
00376
00384 virtual bool save(QDataStream &stream);
00385
00393 void networkTransmission(QDataStream &stream,int msgid,Q_UINT32 sender);
00394
00400 KGamePropertyBase* findProperty(int id) const;
00401
00411 bool addProperty(KGamePropertyBase* data);
00412
00419 int calcIOValue();
00420
00424 KGamePropertyHandler* dataHandler();
00425
00426 signals:
00433 void signalNetworkData(int msgid, const QByteArray& buffer, Q_UINT32 sender, KPlayer *me);
00434
00441 void signalPropertyChanged(KGamePropertyBase *property,KPlayer *me);
00442
00443 protected slots:
00447 void sendProperty(int msgid, QDataStream& stream, bool* sent);
00451 void emitSignal(KGamePropertyBase *me);
00452
00453
00454 private:
00455 void init();
00456
00457 private:
00458 KGame *mGame;
00459 bool mActive;
00460 KGameIOList mInputList;
00461
00462
00463
00464 KGamePropertyBool mAsyncInput;
00465 KGamePropertyBool mMyTurn;
00466 KGamePropertyInt mUserId;
00467
00468 KPlayerPrivate* d;
00469 };
00470
00471 #endif
|