00001
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 <tqstring.h>
00025 #include <tqobject.h>
00026 #include <tqptrlist.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 TQObject
00070 {
00071 Q_OBJECT
00072
00073
00074 public:
00075 typedef TQPtrList<KGameIO> KGameIOList;
00076
00077
00082 KPlayer();
00083
00089 KPlayer(KGame* game);
00090
00091 virtual ~KPlayer();
00092
00099 virtual int rtti() const {return 0;}
00100
00104 void Debug();
00105
00106
00112 KGameIOList *ioList() {return &mInputList;}
00113
00121 void setGame(KGame *game) {mGame=game;}
00122
00128 KGame *game() const {return mGame;}
00129
00137 void setAsyncInput(bool a) {mAsyncInput = a;}
00138
00145 bool asyncInput() const {return mAsyncInput.value();}
00146
00156 bool isVirtual() const;
00157
00165 void setVirtual(bool v);
00166
00174 bool isActive() const {return mActive;}
00175
00181 void setActive(bool v) {mActive=v;}
00182
00188 TQ_UINT32 id() const;
00189
00190
00191
00192
00193
00194
00195 void setId(TQ_UINT32 i);
00196
00208 int userId() const {return mUserId.value();}
00209
00210
00211
00212
00213
00214 void setUserId(int i) {mUserId = i;}
00215
00226 int networkPriority() const;
00227
00244 void setNetworkPriority(int b);
00245
00251 KPlayer *networkPlayer() const;
00252
00256 void setNetworkPlayer(KPlayer *p);
00257
00258
00263 void setGroup(const TQString& group);
00264
00268 virtual const TQString& group() const;
00269
00275 void setName(const TQString& name);
00276
00280 virtual const TQString& name() const;
00281
00282
00283
00292 bool addGameIO(KGameIO *input);
00293
00304 bool removeGameIO(KGameIO *input=0,bool deleteit=true);
00305
00313 KGameIO *findRttiIO(int rtti) const;
00314
00322 bool hasRtti(int rtti) const {return findRttiIO(rtti)!=0;}
00323
00324
00337 virtual bool forwardInput(TQDataStream &msg,bool transmit=true, TQ_UINT32 sender=0);
00338
00342 virtual bool forwardMessage(TQDataStream &msg,int msgid,TQ_UINT32 receiver=0,TQ_UINT32 sender=0);
00343
00344
00350 bool myTurn() const {return mMyTurn.value();}
00351
00361 bool setTurn(bool b,bool exclusive=true);
00362
00363
00364
00376 virtual bool load(TQDataStream &stream);
00377
00385 virtual bool save(TQDataStream &stream);
00386
00394 void networkTransmission(TQDataStream &stream,int msgid,TQ_UINT32 sender);
00395
00401 KGamePropertyBase* findProperty(int id) const;
00402
00412 bool addProperty(KGamePropertyBase* data);
00413
00420 int calcIOValue();
00421
00425 KGamePropertyHandler* dataHandler();
00426
00427 signals:
00434 void signalNetworkData(int msgid, const TQByteArray& buffer, TQ_UINT32 sender, KPlayer *me);
00435
00442 void signalPropertyChanged(KGamePropertyBase *property,KPlayer *me);
00443
00444 protected slots:
00448 void sendProperty(int msgid, TQDataStream& stream, bool* sent);
00452 void emitSignal(KGamePropertyBase *me);
00453
00454
00455 private:
00456 void init();
00457
00458 private:
00459 KGame *mGame;
00460 bool mActive;
00461 KGameIOList mInputList;
00462
00463
00464
00465 KGamePropertyBool mAsyncInput;
00466 KGamePropertyBool mMyTurn;
00467 KGamePropertyInt mUserId;
00468
00469 KPlayerPrivate* d;
00470 };
00471
00472 #endif