#include <kplayer.h>
Collaboration diagram for KPlayer:

Public Types | |
| typedef QPtrList< KGameIO > | KGameIOList |
Signals | |
| void | signalNetworkData (int msgid, const QByteArray &buffer, Q_UINT32 sender, KPlayer *me) |
| The player object got a message which was targeted at it but has no default method to process it. | |
| 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 change. | |
Public Member Functions | |
| KPlayer () | |
| Create a new player object. | |
| KPlayer (KGame *game) | |
| Create a new player object. | |
| virtual | ~KPlayer () |
| virtual int | rtti () const |
| The idendification of the player. | |
| void | Debug () |
| Gives debug output of the game status. | |
| KGameIOList * | ioList () |
| Returns a list of input devices. | |
| void | setGame (KGame *game) |
| sets the game the player belongs to. | |
| KGame * | game () const |
| Query to which game the player belongs to. | |
| void | setAsyncInput (bool a) |
| Set whether this player can make turns/input all the time (true) or only when it is its turn (false) as it is used in turn based games. | |
| bool | asyncInput () const |
| Query whether this player does asynchronous input. | |
| bool | isVirtual () const |
| Is this player a virtual player, ie is it created by mirroring a real player from another network game. | |
| void | setVirtual (bool v) |
| bool | isActive () const |
| Is this player an active player. | |
| void | setActive (bool v) |
| Set an player as active (true) or inactive (false). | |
| Q_UINT32 | id () const |
| Returns the id of the player. | |
| void | setId (Q_UINT32 i) |
| int | userId () const |
| Returns the user defined id of the player This value can be used arbitrary by you to have some user idendification for your player, e.g. | |
| void | setUserId (int i) |
| int | networkPriority () const |
| Returns whether this player can be replaced by a network connection player. | |
| void | setNetworkPriority (int b) |
| Set whether this player can be replaced by a network player. | |
| KPlayer * | networkPlayer () const |
| Returns the player which got inactivated to allow this player to be set up via network. | |
| void | setNetworkPlayer (KPlayer *p) |
| Sets this network player replacement. | |
| void | setGroup (const QString &group) |
| A group the player belongs to. | |
| virtual const QString & | group () const |
| Query the group the player belongs to. | |
| void | setName (const QString &name) |
| Sets the name of the player. | |
| virtual const QString & | name () const |
| bool | addGameIO (KGameIO *input) |
| Adds an IO device for the player. | |
| bool | removeGameIO (KGameIO *input=0, bool deleteit=true) |
| remove (and delete) a game IO device | |
| KGameIO * | findRttiIO (int rtti) const |
| Finds the KGameIO devies with the given rtti code. | |
| bool | hasRtti (int rtti) const |
| Checks whether this player has a IO device of the given rtti type. | |
| virtual bool | forwardInput (QDataStream &msg, bool transmit=true, Q_UINT32 sender=0) |
| Forwards input to the game object. | |
| virtual bool | forwardMessage (QDataStream &msg, int msgid, Q_UINT32 receiver=0, Q_UINT32 sender=0) |
| Forwards Message to the game object. | |
| bool | myTurn () const |
| is it my turn to go | |
| bool | setTurn (bool b, bool exclusive=true) |
| Sets whether this player is the next to turn. | |
| virtual bool | load (QDataStream &stream) |
| Load a saved player, from file OR network. | |
| virtual bool | save (QDataStream &stream) |
| Save a player to a file OR to network. | |
| void | networkTransmission (QDataStream &stream, int msgid, Q_UINT32 sender) |
| Receives a message. | |
| KGamePropertyBase * | findProperty (int id) const |
| Searches for a property of the player given its id. | |
| bool | addProperty (KGamePropertyBase *data) |
| Adds a property to a player. | |
| int | calcIOValue () |
| Calculates a checksum over the IO devices. | |
| KGamePropertyHandler * | dataHandler () |
Protected Slots | |
| void | sendProperty (int msgid, QDataStream &stream, bool *sent) |
| Called by KGameProperty only! Internal function! | |
| void | emitSignal (KGamePropertyBase *me) |
| Called by KGameProperty only! Internal function! | |
The KPlayer class is the central player object. It holds information about the player and is responsible for any input the player does. For this arbitrary many KGameIO modules can be plugged into it. Main features are:
A KPlayer depends on a KGame object. Call KGame::addPlayer() to plug a KPlayer into a KGame object. Note that you cannot do much with a KPlayer object before it has been plugged into a KGame. This is because most properties of KPlayer are KGameProperty which need to send messages through a KGame object to be changed.
A KGameIO represents the input methods of a player and you should make all player inputs through it. So call something like playerInput->move(4); instead which should call KGameIO::sendInput() to actually move. This way you gain a *very* big advantage: you can exchange a KGameIO whenever you want! You can e.g. remove the KGameIO of a local (human) player and just replace it by a computerIO on the fly! So from that point on all playerInputs are done by the computerIO instead of the human player. You also can replace all network players by computer players when the network connection is broken or a player wants to quit. So remember: use KGameIO whenever possible! A KPlayer should just contain all data of the player (KGameIO must not!) and several common functions which are shared by all of your KGameIOs.
Definition at line 69 of file kplayer.h.
|
|
|
|
|
Create a new player object. It will be automatically deleted if the game it belongs to is deleted. Definition at line 62 of file kplayer.cpp. |
|
|
Create a new player object. It will be automatically deleted if the game it belongs to is deleted. This constructor automatically adds the player to the game using KGame::addPlayer() Definition at line 67 of file kplayer.cpp. References KGame::addPlayer(), and game(). Here is the call graph for this function: ![]() |
|
|
Definition at line 106 of file kplayer.cpp. References game(), id(), and KGame::playerDeleted(). Here is the call graph for this function: ![]() |
|
|
Adds an IO device for the player. Possible KGameIO devices can either be taken from the existing ones or be self written. Existing are e.g. Keyboard, Mouse, Computerplayer
Definition at line 219 of file kplayer.cpp. References KGameIO::initIO(). Referenced by KGameIO::KGameIO(). Here is the call graph for this function: ![]() |
|
|
Adds a property to a player. You would add all your player specific game data as KGameProperty and they are automatically saved and exchanged over network.
Definition at line 394 of file kplayer.cpp. |
|
|
Query whether this player does asynchronous input.
Definition at line 144 of file kplayer.h. Referenced by Debug(), forwardInput(), KGame::playerInputFinished(), KGameDebugDialog::slotUpdatePlayerData(), and KGame::systemPlayerInput(). |
|
|
Calculates a checksum over the IO devices. Can be used to restore the IO handlers. The value returned is the 'or'ed value of the KGameIO rtti's. this is itnernally used for saving and restorign a player. Definition at line 273 of file kplayer.cpp. Referenced by KGame::savePlayer(). |
|
|
Definition at line 198 of file kplayer.cpp. Referenced by KGame::loadgame(), KGamePropertyBase::registerData(), and KGameDebugDialog::slotUpdatePlayerData(). |
|
|
Gives debug output of the game status.
Definition at line 428 of file kplayer.cpp. References asyncInput(), game(), group(), id(), isActive(), isVirtual(), myTurn(), name(), networkPriority(), and rtti(). Here is the call graph for this function: ![]() |
|
|
Called by KGameProperty only! Internal function!
Definition at line 411 of file kplayer.cpp. References KGamePropertyBase::id(), KGamePropertyBase::IdTurn, and KGameProperty< type >::value(). |
|
|
Searches for a property of the player given its id.
Definition at line 389 of file kplayer.cpp. |
|
|
Finds the KGameIO devies with the given rtti code. E.g. find the mouse or network device
Definition at line 259 of file kplayer.cpp. |
|
||||||||||||||||
|
Forwards input to the game object. .internal use only This method is used by KGameIO::sendInput(). Use that function instead to send player inputs! This function forwards a player input (see KGameIO classes) to the game object, see KGame, either to KGame::sendPlayerInput() (if transmit=true, ie the message has just been created) or to KGame::playerInput() (if player=false, ie the message *was* sent through KGame::sendPlayerInput). Definition at line 142 of file kplayer.cpp. References asyncInput(), game(), isActive(), myTurn(), KGame::sendPlayerInput(), and KGame::systemPlayerInput(). Referenced by KGameIO::sendInput(). Here is the call graph for this function: ![]() |
|
||||||||||||||||||||
|
Forwards Message to the game object. .internal use only Definition at line 128 of file kplayer.cpp. References game(), isActive(), and KGameNetwork::sendSystemMessage(). Referenced by KGameProcessIO::receivedMessage(). Here is the call graph for this function: ![]() |
|
|
Query to which game the player belongs to.
Definition at line 127 of file kplayer.h. Referenced by Debug(), forwardInput(), forwardMessage(), KGameIO::game(), KPlayer(), networkTransmission(), sendProperty(), setTurn(), KGameDebugDialog::slotUpdatePlayerData(), and ~KPlayer(). |
|
|
Query the group the player belongs to.
Definition at line 186 of file kplayer.cpp. Referenced by Debug(), KGameChat::returnPressed(), KGame::sendGroupMessage(), KGameChat::setFromPlayer(), and KGameDebugDialog::slotUpdatePlayerData(). |
|
|
Checks whether this player has a IO device of the given rtti type.
|
|
|
|
Returns a list of input devices.
|
|
|
Is this player an active player. An player is usually inactivated if it is replaced by a network connection. But this could also be called manually
Definition at line 173 of file kplayer.h. Referenced by Debug(), forwardInput(), forwardMessage(), KGame::networkTransmission(), setTurn(), KGameDebugDialog::slotUpdatePlayerData(), KGame::systemActivatePlayer(), and KGame::systemInactivatePlayer(). |
|
|
Is this player a virtual player, ie is it created by mirroring a real player from another network game. This mirroring is done autmatically as soon as a network connection is build and it affects all players regardless what type
Definition at line 204 of file kplayer.cpp. Referenced by Debug(), KGame::playerDeleted(), and KGameDebugDialog::slotUpdatePlayerData(). |
|
|
Load a saved player, from file OR network. By default all KGameProperty objects in the dataHandler of this player are loaded and saved when using load or save. If you need to save/load more you have to replace this function (and save). You will probably still want to call the default implementation additionally!
Definition at line 314 of file kplayer.cpp. References id(), KPLAYER_LOAD_COOKIE, setId(), and setNetworkPriority(). Referenced by KGame::loadPlayer(). Here is the call graph for this function: ![]() |
|
|
is it my turn to go
Definition at line 349 of file kplayer.h. Referenced by Debug(), forwardInput(), and KGameDebugDialog::slotUpdatePlayerData(). |
|
|
Definition at line 192 of file kplayer.cpp. Referenced by KGameChat::addMessage(), Debug(), KGameChat::fromName(), KGameChat::returnPressed(), KGameDialogGeneralConfig::setOwner(), KGameChat::slotAddPlayer(), KGameDialogConnectionConfig::slotKickPlayerOut(), KGameDialogConnectionConfig::slotPlayerJoinedGame(), KGameDialogGeneralConfig::slotPropertyChanged(), KGameChat::slotPropertyChanged(), and KGameDebugDialog::slotUpdatePlayerData(). |
|
|
Returns the player which got inactivated to allow this player to be set up via network. Mostly internal function Definition at line 210 of file kplayer.cpp. |
|
|
Returns whether this player can be replaced by a network connection player. The name of this function can be improved ;-) If you do not overwrite the function to select what players shall play in a network the KGame does an automatic selection based on the networkPriority This is not a terrible important function at the moment.
Definition at line 213 of file kplayer.cpp. Referenced by Debug(), save(), and KGameDebugDialog::slotUpdatePlayerData(). |
|
||||||||||||||||
|
Receives a message.
Definition at line 353 of file kplayer.cpp. References game(), and KGameNetwork::gameId(). Referenced by KGame::networkTransmission(). Here is the call graph for this function: ![]() |
|
||||||||||||
|
remove (and delete) a game IO device The remove IO(s) is/are deleted by default. If you do not want this set the parameter deleteit to false
Definition at line 231 of file kplayer.cpp. References KGameIO::setPlayer(). Referenced by KGameIO::~KGameIO(), and KGameProcessIO::~KGameProcessIO(). Here is the call graph for this function: ![]() |
|
|
The idendification of the player. Overwrite this in classes inherting KPlayer to run time identify them.
Definition at line 98 of file kplayer.h. Referenced by Debug(), KGame::savePlayer(), and KGameDebugDialog::slotUpdatePlayerData(). |
|
|
Save a player to a file OR to network. See also load
Definition at line 340 of file kplayer.cpp. References KPLAYER_LOAD_COOKIE, and networkPriority(). Referenced by KGame::savePlayer(). Here is the call graph for this function: ![]() |
|
||||||||||||||||
|
Called by KGameProperty only! Internal function!
Definition at line 399 of file kplayer.cpp. References game(), and KGame::sendPlayerProperty(). |
|
|
Set an player as active (true) or inactive (false).
|
|
|
Set whether this player can make turns/input all the time (true) or only when it is its turn (false) as it is used in turn based games.
|
|
|
sets the game the player belongs to. This is usually automatically done when adding a player
|
|
|
A group the player belongs to. This Can be set arbitrary by you. Definition at line 183 of file kplayer.cpp. |
|
|
Definition at line 176 of file kplayer.cpp. Referenced by KGame::addPlayer(), and load(). |
|
|
Sets the name of the player. This can be chosen arbitrary.
Definition at line 189 of file kplayer.cpp. Referenced by KGameDialogGeneralConfig::submitToKGame(). |
|
|
Sets this network player replacement. Internal stuff Definition at line 207 of file kplayer.cpp. |
|
|
Set whether this player can be replaced by a network player. There are to possible games. The first type of game has arbitrary many players. As soon as a network players connects the game runs with more players (not tagged situation). The other type is e.g. games like chess which require a constant player number. In a network game situation you would tag one or both players of all participants. As soon as the connect the tagged player will then be replaced by the network partner and it is then controlled over the network. On connection loss the old situation is automatically restored. The name of this function can be improved;-)
Definition at line 216 of file kplayer.cpp. Referenced by load(). |
|
||||||||||||
|
Sets whether this player is the next to turn. If exclusive is given all other players are set to setTurn(false) and only this player can move
Definition at line 285 of file kplayer.cpp. References game(), id(), isActive(), KGame::playerList(), and setTurn(). Referenced by KGame::playerInputFinished(), setTurn(), and KGame::systemPlayerInput(). Here is the call graph for this function: ![]() |
|
|
|
|
|
Definition at line 201 of file kplayer.cpp. Referenced by KGame::loadPlayer(). |
|
||||||||||||||||||||
|
The player object got a message which was targeted at it but has no default method to process it. This means probably a user message. Connecting to this signal allowed to process it. |
|
||||||||||||
|
This signal is emmited if a player property changes its value and the property is set to notify this change. This is an important signal as you should base the actions on a reaction to this property changes. |
|
|
Returns the user defined id of the player This value can be used arbitrary by you to have some user idendification for your player, e.g. 0 for a white chess player, 1 for a black one. This value is more reliable than the player id whcih can even change when you make a network connection.
Definition at line 207 of file kplayer.h. Referenced by KGameProcessIO::initIO(), and KGameDebugDialog::slotUpdatePlayerData(). |
1.4.6