You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
157 lines
4.0 KiB
157 lines
4.0 KiB
15 years ago
|
/*
|
||
|
This file is part of the KDE games library
|
||
|
Copyright (C) 2001 Martin Heni (martin@heni-online.de)
|
||
|
Copyright (C) 2001 Andreas Beckermann (b_mann@gmx.de)
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2 as published by the Free Software Foundation.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
/*
|
||
|
$Id$
|
||
|
*/
|
||
|
|
||
|
#include "kgamemessage.h"
|
||
|
|
||
|
#include <klocale.h>
|
||
|
|
||
|
#define MESSAGE_VERSION 2
|
||
|
|
||
14 years ago
|
TQ_UINT32 KGameMessage::createPlayerId(int oldplayerid,TQ_UINT32 gameid)
|
||
15 years ago
|
{
|
||
|
int p;
|
||
|
p = oldplayerid & 0x3ff; // remove game id
|
||
|
p |= (gameid << 10);
|
||
|
return p;
|
||
|
}
|
||
|
|
||
14 years ago
|
int KGameMessage::rawPlayerId(TQ_UINT32 playerid)
|
||
15 years ago
|
{
|
||
|
return playerid & 0x03ff;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQ_UINT32 KGameMessage::rawGameId(TQ_UINT32 playerid)
|
||
15 years ago
|
{
|
||
|
return (playerid & 0xfc00) >> 10;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool KGameMessage::isPlayer(TQ_UINT32 msgid)
|
||
15 years ago
|
{
|
||
|
if (msgid & 0xfc00) {
|
||
|
return true;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
bool KGameMessage::isGame(TQ_UINT32 msgid)
|
||
15 years ago
|
{
|
||
|
return !isPlayer(msgid);
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
void KGameMessage::createHeader(TQDataStream &msg,TQ_UINT32 sender,TQ_UINT32 receiver,int msgid)
|
||
15 years ago
|
{
|
||
14 years ago
|
msg << (TQ_INT16)sender << (TQ_INT16)receiver << (TQ_INT16)msgid;
|
||
15 years ago
|
}
|
||
|
|
||
14 years ago
|
void KGameMessage::extractHeader(TQDataStream &msg,TQ_UINT32 &sender,TQ_UINT32 &receiver,int &msgid)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQ_INT16 d3,d4,d5;
|
||
15 years ago
|
msg >> d3 >> d4 >> d5;
|
||
|
sender=d3;receiver=d4;msgid=d5;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KGameMessage::createPropertyHeader(TQDataStream &msg,int id)
|
||
15 years ago
|
{
|
||
14 years ago
|
msg << (TQ_INT16)id;
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KGameMessage::extractPropertyHeader(TQDataStream &msg,int &id)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQ_INT16 d1;
|
||
15 years ago
|
msg >> d1;
|
||
|
id=d1;
|
||
|
}
|
||
|
|
||
15 years ago
|
void KGameMessage::createPropertyCommand(TQDataStream &msg,int cmdid,int pid,int cmd)
|
||
15 years ago
|
{
|
||
|
createPropertyHeader(msg,cmdid);
|
||
14 years ago
|
msg << (TQ_INT16)pid ;
|
||
|
msg << (TQ_INT8)cmd ;
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void KGameMessage::extractPropertyCommand(TQDataStream &msg,int &pid,int &cmd)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQ_INT16 d1;
|
||
|
TQ_INT8 d2;
|
||
15 years ago
|
msg >> d1 >> d2;
|
||
|
pid=d1;
|
||
|
cmd=d2;
|
||
|
}
|
||
|
|
||
|
int KGameMessage::version()
|
||
|
{
|
||
|
return MESSAGE_VERSION;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString KGameMessage::messageId2Text(int msgid)
|
||
15 years ago
|
{
|
||
|
// this should contain all KGameMessage::GameMessageIds
|
||
|
// feel free to add missing ones, to remove obsolete one and even feel free to
|
||
|
// let it be ;-)
|
||
|
switch (msgid) {
|
||
|
case KGameMessage::IdSetupGame:
|
||
|
return i18n("Setup Game");
|
||
|
case KGameMessage::IdSetupGameContinue:
|
||
|
return i18n("Setup Game Continue");
|
||
|
case KGameMessage::IdGameLoad:
|
||
|
return i18n("Load Game");
|
||
|
case KGameMessage::IdGameConnected:
|
||
|
return i18n("Client game connected");
|
||
|
case KGameMessage::IdGameSetupDone:
|
||
|
return i18n("Game setup done");
|
||
|
case KGameMessage::IdSyncRandom:
|
||
|
return i18n("Synchronize Random");
|
||
|
case KGameMessage::IdDisconnect:
|
||
|
return i18n("Disconnect");
|
||
|
case KGameMessage::IdPlayerProperty:
|
||
|
return i18n("Player Property");
|
||
|
case KGameMessage::IdGameProperty:
|
||
|
return i18n("Game Property");
|
||
|
case KGameMessage::IdAddPlayer:
|
||
|
return i18n("Add Player");
|
||
|
case KGameMessage::IdRemovePlayer:
|
||
|
return i18n("Remove Player");
|
||
|
case KGameMessage::IdActivatePlayer:
|
||
|
return i18n("Activate Player");
|
||
|
case KGameMessage::IdInactivatePlayer:
|
||
|
return i18n("Inactivate Player");
|
||
|
case KGameMessage::IdTurn:
|
||
|
return i18n("Id Turn");
|
||
|
case KGameMessage::IdError:
|
||
|
return i18n("Error Message");
|
||
|
case KGameMessage::IdPlayerInput:
|
||
|
return i18n("Player Input");
|
||
|
case KGameMessage::IdIOAdded:
|
||
|
return i18n("An IO was added");
|
||
|
case KGameMessage::IdProcessQuery:
|
||
|
return i18n("Process Query");
|
||
|
case KGameMessage::IdPlayerId:
|
||
|
return i18n("Player ID");
|
||
|
case KGameMessage::IdUser: // IdUser must be unknown for use, too!
|
||
|
default:
|
||
14 years ago
|
return TQString();
|
||
15 years ago
|
}
|
||
|
}
|