1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/*
This file is part of the TDE games library
Copyright (C) 2001 Martin Heni ([email protected])
Copyright (C) 2001 Andreas Beckermann ([email protected])
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
TQ_UINT32 KGameMessage::createPlayerId(int oldplayerid,TQ_UINT32 gameid)
{
int p;
p = oldplayerid & 0x3ff; // remove game id
p |= (gameid << 10);
return p;
}
int KGameMessage::rawPlayerId(TQ_UINT32 playerid)
{
return playerid & 0x03ff;
}
TQ_UINT32 KGameMessage::rawGameId(TQ_UINT32 playerid)
{
return (playerid & 0xfc00) >> 10;
}
bool KGameMessage::isPlayer(TQ_UINT32 msgid)
{
if (msgid & 0xfc00) {
return true;
} else {
return false;
}
}
bool KGameMessage::isGame(TQ_UINT32 msgid)
{
return !isPlayer(msgid);
}
void KGameMessage::createHeader(TQDataStream &msg,TQ_UINT32 sender,TQ_UINT32 receiver,int msgid)
{
msg << (TQ_INT16)sender << (TQ_INT16)receiver << (TQ_INT16)msgid;
}
void KGameMessage::extractHeader(TQDataStream &msg,TQ_UINT32 &sender,TQ_UINT32 &receiver,int &msgid)
{
TQ_INT16 d3,d4,d5;
msg >> d3 >> d4 >> d5;
sender=d3;receiver=d4;msgid=d5;
}
void KGameMessage::createPropertyHeader(TQDataStream &msg,int id)
{
msg << (TQ_INT16)id;
}
void KGameMessage::extractPropertyHeader(TQDataStream &msg,int &id)
{
TQ_INT16 d1;
msg >> d1;
id=d1;
}
void KGameMessage::createPropertyCommand(TQDataStream &msg,int cmdid,int pid,int cmd)
{
createPropertyHeader(msg,cmdid);
msg << (TQ_INT16)pid ;
msg << (TQ_INT8)cmd ;
}
void KGameMessage::extractPropertyCommand(TQDataStream &msg,int &pid,int &cmd)
{
TQ_INT16 d1;
TQ_INT8 d2;
msg >> d1 >> d2;
pid=d1;
cmd=d2;
}
int KGameMessage::version()
{
return MESSAGE_VERSION;
}
TQString KGameMessage::messageId2Text(int msgid)
{
// 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:
return TQString();
}
}
|