28 #include "kgamemessage.h"
29 #include "kgamepropertyhandler.h"
32 #include <tdelocale.h>
39 #define KPLAYER_LOAD_COOKIE 7285
76 kdDebug(11001) << k_funcinfo <<
": this=" <<
this <<
", sizeof(this)="<<
sizeof(
KPlayer) << endl;
77 kdDebug(11001) <<
"sizeof(m_Group)="<<
sizeof(d->mGroup)<<endl;
78 d =
new KPlayerPrivate;
80 d->mProperties.registerHandler(KGameMessage::IdPlayerProperty,
91 mUserId.
registerData(KGamePropertyBase::IdUserId,
this, i18n(
"UserId"));
93 d->mGroup.registerData(KGamePropertyBase::IdGroup,
this, i18n(
"Group"));
94 d->mGroup.setLocal(i18n(
"default"));
95 d->mName.registerData(KGamePropertyBase::IdName,
this, i18n(
"Name"));
96 d->mName.setLocal(i18n(
"default"));
98 mAsyncInput.
registerData(KGamePropertyBase::IdAsyncInput,
this, i18n(
"AsyncInput"));
100 mMyTurn.
registerData(KGamePropertyBase::IdTurn,
this, i18n(
"myTurn"));
108 kdDebug(11001) << k_funcinfo <<
": this=" <<
this <<
", id=" << this->
id() << endl;
112 while((input=mInputList.first()))
123 d->mProperties.clear();
138 kdDebug(11001) << k_funcinfo <<
": to game sender="<<sender<<
"" <<
"recv="<<receiver <<
"msgid="<<msgid << endl;
153 kdDebug(11001) << k_funcinfo <<
": to game playerInput(sender="<<sender<<
")" << endl;
156 kdDebug(11001) << k_funcinfo <<
": rejected cause it is not our turn" << endl;
166 kdDebug(11001) <<
"indirect playerInput" << endl;
171 kdDebug(11001) <<
"direct playerInput" << endl;
176 void KPlayer::setId(TQ_UINT32 newid)
184 { d->mGroup =
group; }
187 {
return d->mGroup.value(); }
193 {
return d->mName.value(); }
199 {
return &d->mProperties; }
201 void KPlayer::setVirtual(
bool v)
205 {
return d->mVirtual;}
208 { d->mNetworkPlayer = p; }
211 {
return d->mNetworkPlayer; }
214 {
return d->mPriority; }
217 { d->mPriority = p; }
225 mInputList.append(input);
233 kdDebug(11001) << k_funcinfo <<
": " << targetinput <<
" delete=" << deleteit<< endl;
238 while((input=mInputList.first()))
253 result=mInputList.remove(targetinput);
261 TQPtrListIterator<KGameIO> it(mInputList);
264 if (it.current()->rtti() ==
rtti)
276 TQPtrListIterator<KGameIO> it(mInputList);
279 value|=it.current()->rtti();
287 kdDebug(11001) << k_funcinfo <<
": " <<
id() <<
" (" <<
this <<
") to " << b << endl;
294 if (exclusive && b &&
game())
298 for ( player=list->first(); player != 0; player=list->next() )
316 TQ_INT32
id,priority;
317 stream >>
id >> priority;
323 d->mProperties.load(stream);
327 if (cookie==KPLAYER_LOAD_COOKIE)
329 kdDebug(11001) <<
" Player loaded propertly"<<endl;
333 kdError(11001) <<
" Player loading error. probably format error"<<endl;
344 d->mProperties.save(stream);
346 stream << (TQ_INT16)KPLAYER_LOAD_COOKIE;
366 if (d->mProperties.processMessage(stream,msgid,issender))
372 case KGameMessage::IdPlayerInput:
374 kdDebug(11001) << k_funcinfo <<
": Got player move "
375 <<
"KPlayer (virtual) forwards it to the game object" << endl;
381 ((TQBuffer*)stream.device())->readAll(),sender,
this);
382 kdDebug(11001) << k_funcinfo <<
": "
383 <<
"User data msgid " << msgid << endl;
391 return d->mProperties.find(
id);
396 return d->mProperties.addProperty(data);
414 if (me->
id()==KGamePropertyBase::IdTurn)
417 TQPtrListIterator<KGameIO> it(mInputList);
420 it.current()->notifyTurn(mMyTurn.
value());
430 kdDebug(11001) <<
"------------------- KPLAYER -----------------------" << endl;
431 kdDebug(11001) <<
"this: " <<
this << endl;
432 kdDebug(11001) <<
"rtti: " <<
rtti() << endl;
433 kdDebug(11001) <<
"id : " <<
id() << endl;
434 kdDebug(11001) <<
"Name : " <<
name() << endl;
435 kdDebug(11001) <<
"Group: " <<
group() << endl;
436 kdDebug(11001) <<
"Async: " <<
asyncInput() << endl;
437 kdDebug(11001) <<
"myTurn: " <<
myTurn() << endl;
438 kdDebug(11001) <<
"Virtual: " <<
isVirtual() << endl;
439 kdDebug(11001) <<
"Active: " <<
isActive() << endl;
441 kdDebug(11001) <<
"Game : " <<
game() << endl;
442 kdDebug(11001) <<
"#IOs: " << mInputList.count() << endl;
443 kdDebug(11001) <<
"---------------------------------------------------" << endl;
446 #include "kplayer.moc"
bool sendPlayerProperty(int msgid, TQDataStream &s, TQ_UINT32 playerId)
This is called by KPlayer::sendProperty only! Internal function!
bool setLocal(type v)
This function sets the value of the property directly, i.e.
virtual void initIO(KPlayer *p)
Init this device by setting the player and e.g.
bool removeGameIO(KGameIO *input=0, bool deleteit=true)
remove (and delete) a game IO device
bool myTurn() const
is it my turn to go
virtual const TQString & group() const
Query the group the player belongs to.
bool asyncInput() const
Query whether this player does asynchronous input.
virtual bool save(TQDataStream &stream)
Save a player to a file OR to network.
Base class for IO devices for games.
void setGroup(const TQString &group)
A group the player belongs to.
bool isActive() const
Is this player an active player.
KGamePlayerList * playerList()
Returns a list of all active players.
int networkPriority() const
Returns whether this player can be replaced by a network connection player.
bool setTurn(bool b, bool exclusive=true)
Sets whether this player is the next to turn.
void emitSignal(KGamePropertyBase *me)
Called by KGameProperty only! Internal function!
KGamePropertyHandler * dataHandler()
The main KDE game object.
Base class for a game player.
virtual bool forwardMessage(TQDataStream &msg, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
Forwards Message to the game object..internal use only.
void addPlayer(KPlayer *newplayer)
Note that KPlayer::save must be implemented properly, as well as KPlayer::rtti This will only send a ...
virtual int rtti() const
The idendification of the player.
void setOptimized(bool p)
Sets this property to try to optimize signal and network handling by not sending it out when the prop...
TQ_UINT32 gameId() const
The unique ID of this game.
bool addGameIO(KGameIO *input)
Adds an IO device for the player.
int calcIOValue()
Calculates a checksum over the IO devices.
virtual bool forwardInput(TQDataStream &msg, bool transmit=true, TQ_UINT32 sender=0)
Forwards input to the game object..internal use only.
void setPlayer(KPlayer *p)
Sets the player to which this IO belongs to.
void setNetworkPriority(int b)
Set whether this player can be replaced by a network player.
A collection class for KGameProperty objects.
bool sendSystemMessage(const TQByteArray &buffer, int msgid, TQ_UINT32 receiver=0, TQ_UINT32 sender=0)
Sends a network message msg with a given msg id msgid to all clients.
Base class of KGameProperty.
void networkTransmission(TQDataStream &stream, int msgid, TQ_UINT32 sender)
Receives a message.
KGamePropertyBase * findProperty(int id) const
Searches for a property of the player given its id.
bool isVirtual() const
Is this player a virtual player, ie is it created by mirroring a real player from another network gam...
bool addProperty(KGamePropertyBase *data)
Adds a property to a player.
void signalPropertyChanged(KGamePropertyBase *property, KPlayer *me)
This signal is emmited if a player property changes its value and the property is set to notify this ...
KGame * game() const
Query to which game the player belongs to.
const type & value() const
virtual bool load(TQDataStream &stream)
Load a saved player, from file OR network.
void signalNetworkData(int msgid, const TQByteArray &buffer, TQ_UINT32 sender, KPlayer *me)
The player object got a message which was targeted at it but has no default method to process it.
TQ_UINT32 id() const
Returns the id of the player.
virtual bool sendPlayerInput(TQDataStream &msg, KPlayer *player, TQ_UINT32 sender=0)
Called by KPlayer to send a player input to the KMessageServer.
KGameIO * findRttiIO(int rtti) const
Finds the KGameIO devies with the given rtti code.
virtual bool systemPlayerInput(TQDataStream &msg, KPlayer *player, TQ_UINT32 sender=0)
Called when a player input arrives from KMessageServer.
int registerData(int id, KGamePropertyHandler *owner, PropertyPolicy p, TQString name=0)
You have to register a KGamePropertyBase before you can use it.
void sendProperty(int msgid, TQDataStream &stream, bool *sent)
Called by KGameProperty only! Internal function!
void setEmittingSignal(bool p)
Sets this property to emit a signal on value changed.
void playerDeleted(KPlayer *player)
Called by the destructor of KPlayer to remove itself from the game.
void Debug()
Gives debug output of the game status.
void setNetworkPlayer(KPlayer *p)
Sets this network player replacement.
virtual const TQString & name() const
void setName(const TQString &name)
Sets the name of the player.
KPlayer * networkPlayer() const
Returns the player which got inactivated to allow this player to be set up via network.
KPlayer()
Create a new player object.