libkdegames Library API Documentation

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., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
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 
00030 class KGame;
00031 class KGameIO;
00032 class KGamePropertyBase;
00033 class KGamePropertyHandler;
00034 
00035 class KPlayerPrivate;
00036 
00068 class KPlayer : public QObject
00069 {
00070   Q_OBJECT
00071 
00072 public:
00073       typedef QPtrList<KGameIO> KGameIOList;
00074 
00075       // KPlayer(KGame *,KGameIO * input=0);
00080       KPlayer();
00081 
00087       KPlayer(KGame* game);
00088 
00089       virtual ~KPlayer();
00090 
00097       virtual int rtti() const {return 0;}
00098 
00102       void Debug();
00103 
00104       // properties
00110       KGameIOList *ioList() {return &mInputList;}
00111 
00119       void setGame(KGame *game) {mGame=game;}
00120 
00126       KGame *game() const {return mGame;}
00127 
00135       void setAsyncInput(bool a) {mAsyncInput = a;}
00136 
00143       bool asyncInput() const {return mAsyncInput.value();}
00144 
00154       bool isVirtual() const;
00155 
00163       void setVirtual(bool v);
00164 
00172       bool isActive() const {return mActive;}
00173 
00179       void setActive(bool v) {mActive=v;}
00180 
00186       Q_UINT32 id() const; 
00187 
00188       /* Set the players id. This is done automatically by
00189        * the game object when adding a new player!
00190        *
00191        * @param i the player id
00192        */
00193       void setId(Q_UINT32 i);
00194 
00206       int userId() const {return mUserId.value();} 
00207 
00208       /* Set the user defined players id.
00209        *
00210        * @param i the user defined player id
00211        */
00212       void setUserId(int i) {mUserId = i;}
00213 
00224       int networkPriority() const;
00225 
00242       void setNetworkPriority(int b);
00243 
00249       KPlayer *networkPlayer() const;
00250 
00254       void setNetworkPlayer(KPlayer *p);
00255 
00256       // A name and group the player belongs to
00261       void setGroup(const QString& group);
00262 
00266       virtual const QString& group() const;
00267 
00273       void setName(const QString& name);
00274 
00278       virtual const QString& name() const;
00279 
00280 
00281       // set devices
00290       bool addGameIO(KGameIO *input);
00291 
00302       bool removeGameIO(KGameIO *input=0,bool deleteit=true);
00303 
00311       KGameIO *findRttiIO(int rtti) const;
00312 
00320       bool hasRtti(int rtti) const  {return findRttiIO(rtti)!=0;}
00321 
00322       // Message exchange
00335       virtual bool forwardInput(QDataStream &msg,bool transmit=true, Q_UINT32 sender=0);
00336 
00340       virtual bool forwardMessage(QDataStream &msg,int msgid,Q_UINT32 receiver=0,Q_UINT32 sender=0);
00341 
00342       // Game logic
00348       bool myTurn() const {return mMyTurn.value();}
00349 
00359       bool setTurn(bool b,bool exclusive=true);
00360 
00361 
00362       // load/save
00374       virtual bool load(QDataStream &stream);
00375 
00383       virtual bool save(QDataStream &stream);
00384 
00392       void networkTransmission(QDataStream &stream,int msgid,Q_UINT32 sender);
00393 
00399       KGamePropertyBase* findProperty(int id) const;
00400 
00410       bool addProperty(KGamePropertyBase* data);
00411 
00418       int calcIOValue();
00419 
00423        KGamePropertyHandler* dataHandler();
00424 
00425 signals:
00432        void signalNetworkData(int msgid, const QByteArray& buffer, Q_UINT32 sender, KPlayer *me);
00433 
00440        void signalPropertyChanged(KGamePropertyBase *property,KPlayer *me);
00441 
00442 protected slots:
00446       void sendProperty(int msgid, QDataStream& stream, bool* sent);
00450       void emitSignal(KGamePropertyBase *me);
00451 
00452 
00453 private:
00454       void init();
00455 
00456 private:
00457       KGame *mGame;
00458       bool mActive;      // active player
00459       KGameIOList mInputList;
00460 
00461       // GameProperty // AB: I think we can't move them to KPlayerPrivate - inline
00462       // makes sense here
00463       KGamePropertyBool mAsyncInput;  // async input allowed
00464       KGamePropertyBool mMyTurn;      // Is it my turn to play (only useful if not async)?
00465       KGamePropertyInt  mUserId;      // a user defined id
00466 
00467       KPlayerPrivate* d;
00468 };
00469 
00470 #endif
KDE Logo
This file is part of the documentation for libkdegames Library Version 3.2.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Mar 12 22:53:44 2004 by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2003