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

libtdegames

  • libtdegames
  • kgame
kplayer.h
1 /*
2  This file is part of the TDE games library
3  Copyright (C) 2001 Martin Heni (martin@heni-online.de)
4  Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #ifndef __KPLAYER_H_
22 #define __KPLAYER_H_
23 
24 #include <tqstring.h>
25 #include <tqobject.h>
26 #include <tqptrlist.h>
27 
28 #include "kgameproperty.h"
29 #include <tdemacros.h>
30 
31 class KGame;
32 class KGameIO;
33 class KGamePropertyBase;
34 class KGamePropertyHandler;
35 
36 class KPlayerPrivate;
37 
69 class TDE_EXPORT KPlayer : public TQObject
70 {
71  TQ_OBJECT
72 
73 
74 public:
75  typedef TQPtrList<KGameIO> KGameIOList;
76 
77  // KPlayer(KGame *,KGameIO * input=0);
82  KPlayer();
83 
89  KPlayer(KGame* game);
90 
91  virtual ~KPlayer();
92 
99  virtual int rtti() const {return 0;}
100 
104  void Debug();
105 
106  // properties
112  KGameIOList *ioList() {return &mInputList;}
113 
121  void setGame(KGame *game) {mGame=game;}
122 
128  KGame *game() const {return mGame;}
129 
137  void setAsyncInput(bool a) {mAsyncInput = a;}
138 
145  bool asyncInput() const {return mAsyncInput.value();}
146 
156  bool isVirtual() const;
157 
165  void setVirtual(bool v);
166 
174  bool isActive() const {return mActive;}
175 
181  void setActive(bool v) {mActive=v;}
182 
188  TQ_UINT32 id() const;
189 
190  /* Set the players id. This is done automatically by
191  * the game object when adding a new player!
192  *
193  * @param i the player id
194  */
195  void setId(TQ_UINT32 i);
196 
208  int userId() const {return mUserId.value();}
209 
210  /* Set the user defined players id.
211  *
212  * @param i the user defined player id
213  */
214  void setUserId(int i) {mUserId = i;}
215 
226  int networkPriority() const;
227 
244  void setNetworkPriority(int b);
245 
251  KPlayer *networkPlayer() const;
252 
256  void setNetworkPlayer(KPlayer *p);
257 
258  // A name and group the player belongs to
263  void setGroup(const TQString& group);
264 
268  virtual const TQString& group() const;
269 
275  void setName(const TQString& name);
276 
280  virtual const TQString& name() const;
281 
282 
283  // set devices
292  bool addGameIO(KGameIO *input);
293 
304  bool removeGameIO(KGameIO *input=0,bool deleteit=true);
305 
313  KGameIO *findRttiIO(int rtti) const;
314 
322  bool hasRtti(int rtti) const {return findRttiIO(rtti)!=0;}
323 
324  // Message exchange
337  virtual bool forwardInput(TQDataStream &msg,bool transmit=true, TQ_UINT32 sender=0);
338 
342  virtual bool forwardMessage(TQDataStream &msg,int msgid,TQ_UINT32 receiver=0,TQ_UINT32 sender=0);
343 
344  // Game logic
350  bool myTurn() const {return mMyTurn.value();}
351 
361  bool setTurn(bool b,bool exclusive=true);
362 
363 
364  // load/save
376  virtual bool load(TQDataStream &stream);
377 
385  virtual bool save(TQDataStream &stream);
386 
394  void networkTransmission(TQDataStream &stream,int msgid,TQ_UINT32 sender);
395 
401  KGamePropertyBase* findProperty(int id) const;
402 
412  bool addProperty(KGamePropertyBase* data);
413 
420  int calcIOValue();
421 
425  KGamePropertyHandler* dataHandler();
426 
427 signals:
434  void signalNetworkData(int msgid, const TQByteArray& buffer, TQ_UINT32 sender, KPlayer *me);
435 
442  void signalPropertyChanged(KGamePropertyBase *property,KPlayer *me);
443 
444 protected slots:
448  void sendProperty(int msgid, TQDataStream& stream, bool* sent);
452  void emitSignal(KGamePropertyBase *me);
453 
454 
455 private:
456  void init();
457 
458 private:
459  KGame *mGame;
460  bool mActive; // active player
461  KGameIOList mInputList;
462 
463  // GameProperty // AB: I think we can't move them to KPlayerPrivate - inline
464  // makes sense here
465  KGamePropertyBool mAsyncInput; // async input allowed
466  KGamePropertyBool mMyTurn; // Is it my turn to play (only useful if not async)?
467  KGamePropertyInt mUserId; // a user defined id
468 
469  KPlayerPrivate* d;
470 };
471 
472 #endif
KPlayer::game
KGame * game() const
Query to which game the player belongs to.
Definition: kplayer.h:128
KPlayer::rtti
virtual int rtti() const
The idendification of the player.
Definition: kplayer.h:99
KGamePropertyHandler
A collection class for KGameProperty objects.
Definition: kgamepropertyhandler.h:72
KPlayer::ioList
KGameIOList * ioList()
Returns a list of input devices.
Definition: kplayer.h:112
KPlayer::hasRtti
bool hasRtti(int rtti) const
Checks whether this player has a IO device of the given rtti type.
Definition: kplayer.h:322
KPlayer::setActive
void setActive(bool v)
Set an player as active (true) or inactive (false)
Definition: kplayer.h:181
KPlayer::asyncInput
bool asyncInput() const
Query whether this player does asynchronous input.
Definition: kplayer.h:145
KPlayer
Base class for a game player.
Definition: kplayer.h:69
KPlayer::userId
int userId() const
Returns the user defined id of the player This value can be used arbitrary by you to have some user i...
Definition: kplayer.h:208
KGamePropertyBase
Base class of KGameProperty.
Definition: kgameproperty.h:42
KPlayer::isActive
bool isActive() const
Is this player an active player.
Definition: kplayer.h:174
KPlayer::setGame
void setGame(KGame *game)
sets the game the player belongs to.
Definition: kplayer.h:121
KGame
The main KDE game object.
Definition: kgame.h:62
KPlayer::setAsyncInput
void setAsyncInput(bool a)
Set whether this player can make turns/input all the time (true) or only when it is its turn (false) ...
Definition: kplayer.h:137
KGameIO
Base class for IO devices for games.
Definition: kgameio.h:55
KGameProperty< TQ_INT8 >
KPlayer::myTurn
bool myTurn() const
is it my turn to go
Definition: kplayer.h:350

libtdegames

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

libtdegames

Skip menu "libtdegames"
  • libtdegames
Generated for libtdegames by doxygen 1.8.13
This website is maintained by Timothy Pearson.