| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2009 by The qGo Project * |
| 3 | * * |
| 4 | * This file is part of qGo. * |
| 5 | * * |
| 6 | * qGo is free software: you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, see <http://www.gnu.org/licenses/> * |
| 18 | * or write to the Free Software Foundation, Inc., * |
| 19 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | |
| 23 | #ifndef MESSAGES_H |
| 24 | #define MESSAGES_H |
| 25 | #include <QtCore> |
| 26 | #include "defines.h" |
| 27 | /* This file is defined as a source file in src.pro because of a |
| 28 | * linker complaint about undefined destructors. Might be a cleaner |
| 29 | * solution though. */ |
| 30 | /* Also, for the most part these are just constructed and deleted immediately |
| 31 | * but there's a few that do odd things, like GameResult so it might be |
| 32 | * worth it to modify constructors/destructors to print out info so |
| 33 | * we could make sure there's no memory leaks FIXME */ |
| 34 | // this messages won't exist very long so no need to store anything |
| 35 | // they shouldn't be used past the one iteration of a socket read |
| 36 | /* FIXME: I think we imagined that we could do the below because each string |
| 37 | * was set only at the creation of the structure... but I'm not sure we can... |
| 38 | * we thought that was how "const" worked then, but maybe its not. It might |
| 39 | * just depend on that data not getting deleted while a connectionInfo struct |
| 40 | * uses it... so far this is a safe bet... but its something to worry about.*/ |
| 41 | |
| 42 | #define tr_macro(x) QCoreApplication::translate("Game messages", x, "") |
| 43 | |
| 44 | |
| 45 | class PlayerListing; |
| 46 | |
| 47 | class MoveRecord |
| 48 | { |
| 49 | public: |
| 50 | unsigned int number; |
| 51 | #define NOMOVENUMBER 0xffff |
| 52 | unsigned int x, y; |
| 53 | StoneColor color; //maybe we update this with mark class or something later |
| 54 | // having accept and refuse undo here is a little weird but its almost a kind |
| 55 | // of move... we'll see how other protocols handle this stuff |
| 56 | enum Flags { NONE, HANDICAP, PASS, RESIGN, REMOVE, UNREMOVE, UNDO, REQUESTUNDO, REFUSEUNDO, TERRITORY, UNDO_TERRITORY, REMOVE_AREA, UNREMOVE_AREA, DONE_SCORING, |
| 57 | SETMOVE, BACKWARD, FORWARD, RESETBRANCH, DELETEBRANCH, RESETGAME, TOEND } flags; |
| 58 | MoveRecord() : number(NOMOVENUMBER), color(stoneNone), flags(NONE) {}; |
| 59 | MoveRecord(Flags f) : number(NOMOVENUMBER), flags(f) {}; |
| 60 | MoveRecord(unsigned int n, Flags f) : number(n), flags(f) {}; |
| 61 | MoveRecord(unsigned int n, unsigned int _x, unsigned int _y, StoneColor c) : number(n), x(_x), y(_y), color(c), flags(NONE) {}; |
| 62 | }; |
| 63 | |
| 64 | /* FIXME Clockdisplay doesn't appear to use the periods, stones just |
| 65 | * makes up for it... perhaps this is okay, boarddispatch::recvTime |
| 66 | * has been altered as well to just ignore the periods... but its |
| 67 | * ugly, unclear, we should change this all around. It is true though |
| 68 | * that since the server updates us, there's almost no need to know |
| 69 | * how much is left... except when do we enter byoyomi/period time??? */ |
| 70 | class TimeRecord |
| 71 | { |
| 72 | public: |
| 73 | int time; |
| 74 | int stones_periods; |
| 75 | TimeRecord() : time(0), stones_periods(-1) {}; |
| 76 | TimeRecord(int t, int s) : time(t), stones_periods(s) {}; |
| 77 | }; |
| 78 | |
| 79 | class GameResult |
| 80 | { |
| 81 | public: |
| 82 | unsigned int game_number; |
| 83 | StoneColor winner_color; //this needs to be standardized obviously |
| 84 | QString winner_name; |
| 85 | QString loser_name; |
| 86 | /* Could be better to do black score, white score, we'll see how this |
| 87 | * is used !!!*/ |
| 88 | float winner_score; |
| 89 | float loser_score; |
| 90 | enum ResultType { SCORE, RESIGN, TIME, FORFEIT, DRAW, NOGAME, ADJOURNED } result; |
| 91 | GameResult() : winner_color(stoneNone), winner_name(QString()), loser_name(QString()), winner_score(0.0), loser_score(0.0) {}; |
| 92 | GameResult(StoneColor c, ResultType r) : winner_color(c), winner_name(QString()), loser_name(QString()), winner_score(0.0), loser_score(0.0), result(r) {}; |
| 93 | QString shortMessage(void) |
| 94 | { |
| 95 | QString msg; |
| 96 | if(winner_color == stoneWhite) |
| 97 | msg = tr_macro("W+"); |
| 98 | else |
| 99 | msg = tr_macro("B+"); |
| 100 | |
| 101 | switch(result) |
| 102 | { |
| 103 | case FORFEIT: |
| 104 | msg += tr_macro("F"); |
| 105 | break; |
| 106 | case TIME: |
| 107 | msg += tr_macro("T"); |
| 108 | break; |
| 109 | case RESIGN: |
| 110 | msg += tr_macro("R"); |
| 111 | break; |
| 112 | case SCORE: |
| 113 | msg += QString::number(winner_score - loser_score); |
| 114 | break; |
| 115 | case DRAW: |
| 116 | msg = "="; //FIXME |
| 117 | break; |
| 118 | default: |
| 119 | break; |
| 120 | } |
| 121 | return msg; |
| 122 | } |
| 123 | QString longMessage(void) |
| 124 | { |
| 125 | QString msg; |
| 126 | float margin = winner_score - loser_score; |
| 127 | |
| 128 | switch(result) |
| 129 | { |
| 130 | case FORFEIT: |
| 131 | if(winner_color == stoneWhite) |
| 132 | { |
| 133 | if(loser_name != QString()) |
| 134 | msg = loser_name + tr_macro("(B) forfeits"); |
| 135 | else |
| 136 | msg = tr_macro("Black forfeits"); |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | if(loser_name != QString()) |
| 141 | msg = loser_name + tr_macro("(W) forfeits"); |
| 142 | else |
| 143 | msg = tr_macro("White forfeits"); |
| 144 | } |
| 145 | break; |
| 146 | case TIME: |
| 147 | if(winner_color == stoneWhite) |
| 148 | { |
| 149 | if(loser_name != QString()) |
| 150 | msg = loser_name + tr_macro("(B) has lost on time"); |
| 151 | else |
| 152 | msg = tr_macro("Black has lost on time"); |
| 153 | } |
| 154 | else |
| 155 | { |
| 156 | if(loser_name != QString()) |
| 157 | msg = loser_name + tr_macro("(W) has lost on time"); |
| 158 | else |
| 159 | msg = tr_macro("White has lost on time"); |
| 160 | } |
| 161 | break; |
| 162 | case RESIGN: |
| 163 | if(winner_color == stoneWhite) |
| 164 | { |
| 165 | if(loser_name != QString()) |
| 166 | msg = loser_name + tr_macro("(B) resigns"); |
| 167 | else |
| 168 | msg = tr_macro("Black resigns"); |
| 169 | } |
| 170 | else |
| 171 | { |
| 172 | if(loser_name != QString()) |
| 173 | msg = loser_name + tr_macro("(W) resigns"); |
| 174 | else |
| 175 | msg = tr_macro("White resigns"); |
| 176 | } |
| 177 | break; |
| 178 | /* FIXME score translation is likely inappropriate given |
| 179 | * number and different translation grammars */ |
| 180 | case SCORE: |
| 181 | if(winner_color == stoneWhite) |
| 182 | { |
| 183 | if(winner_name != QString()) |
| 184 | msg = winner_name + tr_macro("(W)"); |
| 185 | else |
| 186 | msg = tr_macro("White"); |
| 187 | if(margin) |
| 188 | msg += tr_macro(" wins by ") + \ |
| 189 | QString::number(margin); |
| 190 | else |
| 191 | msg += tr_macro(" wins"); |
| 192 | } |
| 193 | else |
| 194 | { |
| 195 | if(winner_name != QString()) |
| 196 | msg = winner_name + tr_macro("(B)"); |
| 197 | else |
| 198 | msg = tr_macro("Black"); |
| 199 | if(margin) |
| 200 | msg = tr_macro("Black wins by ") + \ |
| 201 | QString::number(margin); |
| 202 | else |
| 203 | msg += tr_macro(" wins"); |
| 204 | } |
| 205 | break; |
| 206 | case DRAW: |
| 207 | msg = tr_macro("Draw"); //FIXME |
| 208 | break; |
| 209 | default: |
| 210 | break; |
| 211 | } |
| 212 | return msg; |
| 213 | } |
| 214 | }; |
| 215 | |
| 216 | /* Maybe we need consistent names for these messages!!! FIXME*/ |
| 217 | class MatchRequest |
| 218 | { |
| 219 | public: |
| 220 | QString opponent; |
| 221 | QString our_name; //for convenience (multiple accounts?) |
| 222 | QString our_rank; |
| 223 | QString their_rank; |
| 224 | enum COLORREQUEST { WHITE = 0, BLACK, NIGIRI } color_request; |
| 225 | //enum TIMERULES { CANADIAN = 0, BYOYOMI } time_rules; |
| 226 | TimeSystem timeSystem; |
| 227 | unsigned int handicap; |
| 228 | unsigned int board_size; |
| 229 | float komi; //what about that french "," FIXME?? |
| 230 | /* I long for some standard time class but I don't know |
| 231 | * enough about go time rules to write one yet ... (and maybe its not necessary) */ |
| 232 | // IGS requires maintime to, I think, be a multiple of 60 FIXME |
| 233 | /* FIXME, shouldn't we move this to stones_periods unified as well ? */ |
| 234 | int maintime; |
| 235 | int periodtime; |
| 236 | int stones_periods; |
| 237 | bool nmatch; //want to get rid of this!!! but can't... |
| 238 | int nmatch_timeMax; |
| 239 | int nmatch_BYMax; |
| 240 | int nmatch_handicapMax; |
| 241 | /* There's basically a bunch of stuff that the match request needs |
| 242 | * to carry even though there's currently no way to change it. This |
| 243 | * is because it needs to be the same on the accept/mods */ |
| 244 | unsigned char flags; |
| 245 | assessType free_rated; |
| 246 | unsigned short number; |
| 247 | unsigned short opponent_id; |
| 248 | bool opponent_is_challenger; //i.e., he initiated the exchange |
| 249 | bool challenger_is_black; |
| 250 | unsigned short last_game_code; |
| 251 | bool undoAllowed; |
| 252 | bool rematch; |
| 253 | bool first_offer; |
| 254 | MatchRequest() : opponent(""), |
| 255 | color_request(WHITE), |
| 256 | timeSystem(byoyomi), |
| 257 | handicap(0), |
| 258 | board_size(19), |
| 259 | komi(6.5), |
| 260 | maintime(0), |
| 261 | periodtime(0), |
| 262 | stones_periods(0), |
| 263 | nmatch(0), |
| 264 | nmatch_timeMax(0), |
| 265 | nmatch_BYMax(0), |
| 266 | nmatch_handicapMax(0), |
| 267 | free_rated(noREQ), |
| 268 | number(0), opponent_id(0), |
| 269 | last_game_code(0), undoAllowed(false), rematch(false), first_offer(false) {}; |
| 270 | }; |
| 271 | |
| 272 | /* Confusing name since we use games as rooms with ORO, maybe not an issue */ |
| 273 | class RoomListing |
| 274 | { |
| 275 | public: |
| 276 | int number; |
| 277 | QString name; |
| 278 | bool locked; |
| 279 | RoomListing() : number(0), name(""), locked(false) {}; |
| 280 | RoomListing(int n) : number(n), name("") {}; |
| 281 | RoomListing(QString n) : number(0), name(n) {}; |
| 282 | RoomListing(int n, QString t) : number(n), name(t) {}; |
| 283 | }; |
| 284 | |
| 285 | class ChannelListing |
| 286 | { |
| 287 | public: |
| 288 | int number; |
| 289 | QString name; |
| 290 | std::vector<PlayerListing *> members; |
| 291 | ChannelListing() : number(0), name(""){}; |
| 292 | ChannelListing(int n) : number(n), name("") {}; |
| 293 | ChannelListing(QString n) : number(0), name(n) {}; |
| 294 | ChannelListing(int n, QString t) : number(n), name(t) {}; |
| 295 | }; |
| 296 | |
| 297 | class SeekCondition |
| 298 | { |
| 299 | public: |
| 300 | int number; |
| 301 | int maintime; |
| 302 | int periodtime; |
| 303 | int periods; |
| 304 | QString bline; |
| 305 | QString strength_wished; |
| 306 | }; |
| 307 | |
| 308 | #endif //MESSAGES_H |