1 /* 2 * gtkatlantic - the gtk+ monopd client, enjoy network monopoly games 3 * 4 * 5 * Copyright © 2002-2015 Sylvain Rochet 6 * 7 * gtkatlantic is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; see the file COPYING. If not, see 19 * <http://www.gnu.org/licenses/>. 20 */ 21 22 #ifndef GLOBAL_H 23 #define GLOBAL_H 24 25 /* ** contain global variables */ 26 #include <gtk/gtk.h> 27 #include <gdk-pixbuf/gdk-pixbuf.h> 28 #include <time.h> 29 #include <sys/time.h> 30 31 #include "engine.h" 32 33 #ifndef WIN32 34 35 typedef int socket_t; 36 37 #else /* WIN32 */ 38 39 #include <winsock2.h> 40 typedef SOCKET socket_t; 41 #undef PACKAGE_DATA_DIR 42 #undef PACKAGE_ICON_DIR 43 #define PACKAGE_DATA_DIR "./data" 44 #define PACKAGE_ICON_DIR "./share/icons/hicolor" 45 46 #endif /* WIN32 */ 47 48 /* -- hierarchy 49 * 50 * player[] > player game data 51 * game[] > game data 52 * |-> estate[] > estate game data 53 * |-> group[] > group game data 54 * |-> card[] > card removed from stack (needed for trade) 55 * |-> trade[] > current trades data 56 * `-> command[] > command game data 57 * data > interface datas 58 * |-> estate[] > interface estates data (tablepos, sizes, ...) 59 * |-> playerlist_card[] > interface playerlist cards data (tablepos, sizes, ...) 60 * `-> theme[] > themes database 61 * global > main data 62 * `-> connection > connections status 63 * config > config data 64 */ 65 66 /* -- game data */ 67 #define MAX_ESTATES 50 68 #define MAX_GROUPS 50 69 #define MAX_CARDS 16 70 #define MAX_TRADES 64 71 #define MAX_COMMANDS 20 72 #define MAX_PLAYERLIST_CARDS 30 73 74 /* -- player data */ 75 #define PLAYER_ACTION_TRADE 0 76 #define PLAYER_ACTION_VERSION 1 77 #define PLAYER_ACTION_DATE 2 78 #define PLAYER_ACTION_PING 3 79 struct player_ { 80 struct player_ *next; 81 82 guint32 playerid; 83 gint32 game; 84 gchar *image; 85 gchar *name; 86 gchar *host; 87 gint32 money; 88 guint16 location; 89 gboolean jailed; 90 gboolean directmove; 91 gboolean bankrupt; 92 gboolean hasturn; 93 gboolean can_roll; 94 gboolean can_buyestate; 95 gboolean spectator; 96 gint32 turnorder; 97 98 guint16 location_to; 99 100 /* playerlist */ 101 GtkWidget *playerlist_box; 102 103 GtkWidget *playerlist_LabelNamePlayer; 104 GtkWidget *playerlist_LabelMoneyPlayer; 105 106 GtkWidget *playerlist_cards_gdkrgb; 107 eng_frame *playerlist_cards_frame; 108 eng_obj *playerlist_cards_pic[MAX_PLAYERLIST_CARDS]; 109 110 GtkWidget *playerlist_token_gdkrgb; 111 eng_frame *playerlist_token_frame; 112 eng_obj *playerlist_token_pic; 113 114 /* board */ 115 gint32 tokenid; 116 eng_obj *token_pic; 117 }; 118 typedef struct player_ player; 119 120 extern player *player_h; /* Player list */ 121 122 /* -- estate data */ 123 #define ESTATE_ACTION_BUILDHOUSE 0 124 #define ESTATE_ACTION_SELLHOUSE 1 125 #define ESTATE_ACTION_MORTGAGE 2 126 #define ESTATE_ACTION_SELL 3 127 typedef struct { 128 129 gchar *name; 130 guint8 color[3]; // R, G, B 131 guint8 bgcolor[3]; // R, G, B 132 gint32 owner; 133 guint8 houses; 134 guint32 houseprice; 135 guint32 sellhouseprice; 136 gint32 mortgageprice; 137 gint32 unmortgageprice; 138 gboolean mortgaged; 139 gint16 group; 140 gboolean can_be_owned; 141 gboolean can_toggle_mortgage; 142 gboolean can_buy_houses; 143 gboolean can_sell_houses; 144 guint32 money; 145 guint32 price; 146 guint32 rent[6]; 147 148 /* board */ 149 GtkWidget *gdkrgb; 150 eng_obj *pic; 151 eng_obj *star_pic; 152 eng_obj *house_pic; 153 154 } _estate; 155 156 157 /* -- group data */ 158 typedef struct { 159 160 gchar *name; 161 162 } _group; 163 164 165 /* -- card data */ 166 typedef struct { 167 168 gint32 cardid; 169 gint32 owner; 170 gchar *title; 171 172 } _card; 173 174 175 #define TRADE_MAX_PLAYER 9 176 177 #define TRADE_ACTION_REJECT 0 178 #define TRADE_ACTION_ACCEPT 1 179 #define TRADE_ACTION_REMOVE 2 180 181 #define TRADE_TYPE_NONE 0 182 #define TRADE_TYPE_MONEY 1 183 #define TRADE_TYPE_ESTATE 2 184 #define TRADE_TYPE_CARD 3 185 enum { 186 TRADEPROPOSALLIST_COLUMN_TYPE, 187 TRADEPROPOSALLIST_COLUMN_FROM, 188 TRADEPROPOSALLIST_COLUMN_GIVES, 189 TRADEPROPOSALLIST_COLUMN_TO, 190 TRADEPROPOSALLIST_COLUMN_WHAT, 191 TRADEPROPOSALLIST_COLUMN_TYPE_ID, 192 TRADEPROPOSALLIST_COLUMN_FROM_ID, 193 TRADEPROPOSALLIST_COLUMN_TO_ID, 194 TRADEPROPOSALLIST_COLUMN_AUX_ID, 195 TRADEPROPOSALLIST_COLUMN_NUM 196 }; 197 enum { 198 TRADEPLAYERLIST_COLUMN_NAME, 199 TRADEPLAYERLIST_BGCOLOR_NAME, 200 TRADEPLAYERLIST_COLUMN_NUM 201 }; 202 /* -- trade data */ 203 struct trade_player_ { 204 player *player; 205 gboolean accept; 206 }; 207 typedef struct trade_player_ trade_player; 208 209 typedef struct { 210 211 gboolean open; 212 213 gint32 tradeid; 214 gint32 revision; 215 trade_player player[TRADE_MAX_PLAYER]; 216 guint8 current_component; 217 218 GtkWidget *TradeWin; 219 GtkWidget *PlayerList; 220 GtkWidget *FrameComponent; 221 GtkWidget *ProposalList; 222 GtkWidget *ComponentBox; 223 GtkWidget *SubComponentBox; 224 225 guint8 select_type; // money, estate, card 226 guint32 select_from; 227 guint32 select_to; 228 guint32 select_aux; // estateid, cardid 229 230 } _trade; 231 232 233 /* -- command data */ 234 typedef struct { 235 236 gboolean open; 237 238 GtkWidget *Frame; 239 GtkWidget *gdkrgb; 240 gboolean redraw; 241 242 gchar *command; 243 244 } _command; 245 246 247 #define GAME_STATUS_NONE 0 248 #define GAME_STATUS_CONFIG 1 249 #define GAME_STATUS_INIT 2 250 #define GAME_STATUS_RUN 3 251 #define GAME_STATUS_END 4 252 enum { 253 PLAYERLIST_COLUMN_NAME, 254 PLAYERLIST_COLUMN_HOST, 255 PLAYERLIST_COLUMN_NUM 256 }; 257 enum { 258 AUCTIONPLAYERLIST_COLUMN_NAME, 259 AUCTIONPLAYERLIST_COLUMN_BID, 260 AUCTIONPLAYERLIST_COLUMN_PLAYERID, 261 AUCTIONPLAYERLIST_WEIGHT, 262 AUCTIONPLAYERLIST_WEIGHTSET, 263 AUCTIONPLAYERLIST_COLUMN_NUM 264 }; 265 266 struct game_ { 267 struct game_ *next; 268 269 guint8 status; 270 gint32 gameid; 271 gint32 master; 272 273 _estate estate[MAX_ESTATES]; 274 _group group[MAX_GROUPS]; 275 _card card[MAX_CARDS]; 276 _trade trade[MAX_TRADES]; 277 _command command[MAX_COMMANDS]; 278 279 time_t start_time; 280 eng_frame *board_frame; 281 282 GtkWidget *PlayerList; 283 284 GtkWidget *ChatBox, *Chat; 285 286 GtkWidget *GameConfigBox; 287 GtkWidget *BoardCenter; 288 GtkWidget *WinEstateTree; 289 290 guint32 timeout_token; 291 292 }; 293 typedef struct game_ game; 294 295 extern game *currentgame; /* Currently played game entry */ 296 extern game *game_h; /* Game list */ 297 298 299 /* -- connect data */ 300 #define CONNECT_TYPE_MONOPD_GETGAME 1 301 #define CONNECT_TYPE_MONOPD_GAME 2 302 #define CONNECT_TYPE_METASERVER 3 303 struct connection_ { 304 #if DEBUG 305 guint32 id; 306 #endif /* DEBUG */ 307 308 guint8 type; 309 310 gchar *host; 311 gchar *ip; 312 gint32 port; 313 socket_t socket; 314 GIOChannel *channel; 315 gint event_source_id; 316 317 gchar *server_version; 318 319 gchar *buffer_in; 320 gchar *buffer_out; 321 322 }; 323 typedef struct connection_ connection; 324 325 326 /* interface card */ 327 typedef struct { 328 329 guint16 x; 330 guint16 y; 331 guint8 z; 332 333 guint8 buffer_card; 334 guint8 estateid; 335 336 } _interface_playerlist_card; 337 338 339 /* interface estate */ 340 #define TYPE_HOUSE_NONE 0 341 #define TYPE_HOUSE_HORIZONTAL 1 342 #define TYPE_HOUSE_VERTICAL 2 343 typedef struct { 344 345 guint16 x; 346 guint16 y; 347 348 guint8 buffer_board; 349 350 guint16 x1token; 351 guint16 y1token; 352 guint16 x2token; 353 guint16 y2token; 354 355 guint16 x1jail; 356 guint16 y1jail; 357 guint16 x2jail; 358 guint16 y2jail; 359 360 guint16 xstar; 361 guint16 ystar; 362 363 guint16 xhouse; 364 guint16 yhouse; 365 guint8 type_house; 366 367 } _interface_estate; 368 369 370 /* themes database */ 371 enum { 372 THEMELIST_COLUMN_NAME, 373 THEMELIST_COLUMN_ID, 374 THEMELIST_COLUMN_NUM 375 }; 376 typedef struct { 377 378 gboolean open; 379 380 gchar *path; 381 gchar *path_preview; 382 gchar *path_conf; 383 384 gchar *name; 385 gchar *type; 386 gchar *version; 387 gchar *author; 388 gchar *email; 389 390 } _theme; 391 392 393 /* interface / pngfiles */ 394 #define MAX_PLAYERS 20 395 #define MAX_COMMANDS 20 396 #define MAX_HOUSES 10 397 #define MAX_THEMES 256 398 typedef struct { 399 400 /* pngfile board */ 401 gchar *pngfile_board_filename; 402 guint16 pngfile_board_x[MAX_ESTATES], pngfile_board_y[MAX_ESTATES]; 403 guint16 pngfile_board_width[MAX_ESTATES], pngfile_board_height[MAX_ESTATES]; 404 GdkPixbuf *pngfile_board_buf[MAX_ESTATES]; 405 406 /* pngfile_tokens */ 407 gchar *pngfile_token_filename; 408 guint16 pngfile_token_x[MAX_PLAYERS], pngfile_token_y[MAX_PLAYERS]; 409 guint16 pngfile_token_width[MAX_PLAYERS], pngfile_token_height[MAX_PLAYERS]; 410 GdkPixbuf *pngfile_token_buf[MAX_PLAYERS]; 411 412 /* pngfile_stars */ 413 gchar *pngfile_star_filename; 414 guint16 pngfile_star_x[MAX_PLAYERS], pngfile_star_y[MAX_PLAYERS]; 415 guint16 pngfile_star_width[MAX_PLAYERS], pngfile_star_height[MAX_PLAYERS]; 416 GdkPixbuf *pngfile_star_buf[MAX_PLAYERS]; 417 418 /* pngfile_stars_m (mortgaged) */ 419 gchar *pngfile_star_m_filename; 420 guint16 pngfile_star_m_x[MAX_PLAYERS], pngfile_star_m_y[MAX_PLAYERS]; 421 guint16 pngfile_star_m_width[MAX_PLAYERS], pngfile_star_m_height[MAX_PLAYERS]; 422 GdkPixbuf *pngfile_star_m_buf[MAX_PLAYERS]; 423 424 /* pngfile_cards */ 425 gchar *pngfile_card_filename; 426 guint16 pngfile_card_x[MAX_PLAYERLIST_CARDS], pngfile_card_y[MAX_PLAYERLIST_CARDS]; 427 guint16 pngfile_card_width[MAX_PLAYERLIST_CARDS], pngfile_card_height[MAX_PLAYERLIST_CARDS]; 428 GdkPixbuf *pngfile_card_buf[MAX_PLAYERLIST_CARDS]; 429 430 /* pngfile_commands */ 431 gchar *pngfile_command_filename; 432 guint16 pngfile_command_x[MAX_COMMANDS], pngfile_command_y[MAX_COMMANDS]; 433 guint16 pngfile_command_width[MAX_COMMANDS], pngfile_command_height[MAX_COMMANDS]; 434 GdkPixbuf *pngfile_command_buf[MAX_COMMANDS]; 435 436 /* pngfile_horiz_houses */ 437 gchar *pngfile_horiz_house_filename; 438 guint16 pngfile_horiz_house_x[MAX_HOUSES], pngfile_horiz_house_y[MAX_HOUSES]; 439 guint16 pngfile_horiz_house_width[MAX_HOUSES], pngfile_horiz_house_height[MAX_HOUSES]; 440 GdkPixbuf *pngfile_horiz_house_buf[MAX_HOUSES]; 441 442 /* pngfile_vert_houses */ 443 gchar *pngfile_vert_house_filename; 444 guint16 pngfile_vert_house_x[MAX_HOUSES], pngfile_vert_house_y[MAX_HOUSES]; 445 guint16 pngfile_vert_house_width[MAX_HOUSES], pngfile_vert_house_height[MAX_HOUSES]; 446 GdkPixbuf *pngfile_vert_house_buf[MAX_HOUSES]; 447 448 449 /* load flags */ 450 gboolean png_game_loaded; 451 452 453 /* interface estate */ 454 guint16 board_height, board_width; 455 guint16 board_center_x, board_center_y, board_center_width, board_center_height; 456 guint8 number_estates; 457 _interface_estate estate[MAX_ESTATES]; 458 459 /* interface playerlist token */ 460 guint16 playerlist_token_width, playerlist_token_height; 461 guint8 token_max; 462 463 /* interface playerlist cards */ 464 guint16 playerlist_cards_width, playerlist_cards_height; 465 guint8 playerlist_cards_alphaunowned, playerlist_cards_alphaowned, playerlist_cards_alphamortgage; 466 gint32 playerlist_cards_cardbgcolor, playerlist_cards_cardbgcolormortgage; 467 guint8 number_playerlist_card; 468 _interface_playerlist_card playerlist_card[MAX_PLAYERLIST_CARDS]; 469 470 471 /* themes database */ 472 _theme theme[MAX_THEMES]; 473 474 } _data; 475 476 extern _data *data; /* UI data */ 477 478 479 /* -- main data */ 480 #define PHASE_GETGAMES 1 481 #define PHASE_GAMECREATE 2 482 #define PHASE_GAMEINIT 3 483 #define PHASE_GAMEPLAY 4 484 enum { 485 GAMELIST_COLUMN_HOST, 486 GAMELIST_COLUMN_VERSION, 487 GAMELIST_COLUMN_GAME, 488 GAMELIST_COLUMN_STATUS, 489 GAMELIST_COLUMN_PLAYERS, 490 GAMELIST_COLUMN_PORT, 491 GAMELIST_COLUMN_GAMETYPE, 492 GAMELIST_COLUMN_GAMEID, 493 GAMELIST_COLUMN_SERVERID, 494 GAMELIST_COLUMN_CANBEJOINED, 495 GAMELIST_COLUMN_CANBEWATCHED, 496 GAMELIST_COLUMN_BGCOLOR, 497 GAMELIST_COLUMN_SOURCE, 498 GAMELIST_COLUMN_NUM 499 }; 500 enum { 501 GAMELIST_SOURCE_METASERVER, 502 GAMELIST_SOURCE_CUSTOM, 503 }; 504 enum { 505 SERVERLIST_COLUMN_HOST, 506 SERVERLIST_COLUMN_PORT, 507 SERVERLIST_COLUMN_VERSION, 508 SERVERLIST_COLUMN_USERS, 509 SERVERLIST_COLUMN_SERVERID, 510 SERVERLIST_COLUMN_NUM 511 }; 512 typedef struct { 513 514 gchar *path_home; 515 516 gchar *bg_green; 517 gchar *bg_red; 518 519 guint8 phase; 520 521 GtkWidget *MainWin; 522 GtkWidget *MainBox; 523 GtkWidget *Menu; 524 GtkWidget *MainVerticalBox; 525 GtkWidget *InfoLabel; 526 guint32 timeout_InfoLabel; 527 528 connection *customserver_connect; 529 connection *metaserver_connect; 530 connection *game_connect; 531 532 GtkListStore *game_store; 533 GtkListStore *server_store; 534 GtkTreeIter selected_game; 535 536 GtkWidget *ConfigWin; 537 GtkWidget *HelpWin; 538 GtkWidget *ThemeWin; 539 540 gint32 my_playerid; 541 gchar *cookie; 542 } _global; 543 544 extern _global *global; /* Global state */ 545 546 547 /* all configuration */ 548 #define METASERVER_HOST "meta.atlanticd.net" 549 #define METASERVER_PORT 1240 550 551 #define GAME_PLAYERLIST_POS_LEFT 0 552 #define GAME_PLAYERLIST_POS_RIGHT 1 553 typedef struct { 554 555 gchar *nickname; 556 557 gboolean metaserver_autoconnect; 558 gboolean metaserver_sendclientversion; 559 560 gchar *getgames_host; 561 guint32 getgames_port; 562 gboolean getgames_autoconnect; 563 564 guint32 chat_max_lines; 565 566 guint8 game_playerlist_position; 567 guint32 game_token_animation_speed; 568 gboolean game_token_transparency; 569 570 } _config; 571 572 extern _config *config; /* Configuration */ 573 574 #endif /* GLOBAL_H */ 575