• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libkdegames
 

libkdegames

kplayer.h

00001 /*
00002     This file is part of the KDE games library
00003     Copyright (C) 2001 Martin Heni (martin@heni-online.de)
00004     Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License version 2 as published by the Free Software Foundation.
00009 
00010     This library 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 GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018     Boston, MA 02110-1301, USA.
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   TQ_OBJECT
00073 
00074 public:
00075       typedef TQPtrList<KGameIO> KGameIOList;
00076 
00077       // KPlayer(KGame *,KGameIO * input=0);
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       // properties
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       /* Set the players id. This is done automatically by
00191        * the game object when adding a new player!
00192        *
00193        * @param i the player id
00194        */
00195       void setId(TQ_UINT32 i);
00196 
00208       int userId() const {return mUserId.value();} 
00209 
00210       /* Set the user defined players id.
00211        *
00212        * @param i the user defined player id
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       // A name and group the player belongs to
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       // set devices
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       // Message exchange
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       // Game logic
00350       bool myTurn() const {return mMyTurn.value();}
00351 
00361       bool setTurn(bool b,bool exclusive=true);
00362 
00363 
00364       // load/save
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;      // active player
00461       KGameIOList mInputList;
00462 
00463       // GameProperty // AB: I think we can't move them to KPlayerPrivate - inline
00464       // makes sense here
00465       KGamePropertyBool mAsyncInput;  // async input allowed
00466       KGamePropertyBool mMyTurn;      // Is it my turn to play (only useful if not async)?
00467       KGamePropertyInt  mUserId;      // a user defined id
00468 
00469       KPlayerPrivate* d;
00470 };
00471 
00472 #endif

libkdegames

Skip menu "libkdegames"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libkdegames

Skip menu "libkdegames"
  • libkdegames
Generated for libkdegames by doxygen 1.7.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |