File: global.h

package info (click to toggle)
gtkatlantic 0.4.2-3
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 4,236 kB
  • ctags: 745
  • sloc: sh: 8,786; ansic: 8,311; xml: 191; makefile: 40
file content (526 lines) | stat: -rw-r--r-- 12,326 bytes parent folder | download | duplicates (4)
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
/*
 *     gtkatlantic - the gtk+ monopd client, enjoy network monopoly games
 *
 *
 *  Copyright (C) 2002-2004 Rochet Sylvain
 *
 *  gtkatlantic is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/* ** contain global variables */

#include <gtk/gtk.h>
#include <time.h>
#include <sys/time.h>


/* -- hierarchy
 *
 *  connection[]             > connections status
 *  game[]                   > game data
 *    |-> estate[]           > estate game data
 *    |-> group[]            > group game data
 *    |-> player[]           > player game data
 *    |-> card[]             > card removed from stack (needed for trade)
 *    |-> trade[]            > current trades data
 *    `-> command[]          > command game data
 *  data                     > interface datas
 *    |-> estate[]           > interface estates data (tablepos, sizes, ...)
 *    |-> playerlist_card[]  > interface playerlist cards data (tablepos, sizes, ...)
 *    `-> theme[]            > themes database
 *  global                   > main data
 *  config                   > config data
 */

/* -- game data */
#define MAX_ESTATES 50
#define MAX_GROUPS 50
#define MAX_PLAYERS 400
#define MAX_CARDS 16
#define MAX_TRADES 64
#define MAX_COMMANDS 20
#define MAX_LENGTH_NICK 16
#define MAX_PLAYERLIST_CARDS 30

/* -- player data */
typedef struct {

	guint32  playerid;
	gint32   game;
	guchar   *image;
	guchar   *name;
	guchar   *host;
	gboolean master;
	gint32   money;
	guint16  location;
	gboolean jailed;
	gboolean directmove;
	gboolean bankrupt;
	gboolean hasturn;
	gboolean can_roll;
	gboolean can_buyestate;

	guint16 location_to;

	/* playerlist */
	GtkWidget *playerlist_AlignementNamePlayer;
	GtkWidget *playerlist_LabelNamePlayer;
	GtkWidget *playerlist_AlignementMoneyPlayer;
	GtkWidget *playerlist_LabelMoneyPlayer;

	GtkWidget *playerlist_cards_gdkrgb;
	gboolean   playerlist_cards_redraw;
	guint16    playerlist_cards_frame;
	guint16    playerlist_cards_pic[MAX_PLAYERLIST_CARDS];

	GtkWidget *playerlist_token_gdkrgb;
	gboolean   playerlist_token_redraw;
	guint16    playerlist_token_frame;
	guint16    playerlist_token_pic;
	guint16    playerlist_token_alpha;

	/* playerlistt2 */


	/* board */
	guint32 buffer_token;
	guint32 buffer_star;

	guint16 token_pic;
	guint16 token_alpha;

} _player;


/* -- estate data */
typedef struct {

	guchar   *name;
	guint8   color[3];   // R, G, B
	guint8   bgcolor[3]; // R, G, B
	gint32   owner;
	guint8   houses;
	guint32  houseprice;
	guint32  sellhouseprice;
	gint32   mortgageprice;
	gint32   unmortgageprice;
	gboolean mortgaged;
	gint16   group;
	gboolean can_be_owned;
	gboolean can_toggle_mortgage;
	gboolean can_buy_houses;
	gboolean can_sell_houses;
	guint32  money;
	guint32  price;
	guint32  rent[6];

	/* board */
	GtkWidget *gdkrgb;
	gboolean   redraw;
	guint16    pic;

	guint16 star_alpha;
	guint16 star_pic;

	guint16 house_alpha;
	guint16 house_pic;

} _estate;


/* -- group data */
typedef struct {

	guchar *name;

} _group;


/* -- card data */
typedef struct {

	gint32 cardid;
	gint32 owner;

} _card;


#define TRADE_CURRENT_COMPONENT_MONEY 0
#define TRADE_CURRENT_COMPONENT_ESTATE 1
#define TRADE_CURRENT_COMPONENT_CARD 2

#define TRADE_PLAYER_PARTICIPATE 0
#define TRADE_PLAYER_ACCEPT 1

#define TRADE_SELECT_MONEY 1
#define TRADE_SELECT_ESTATE 2
#define TRADE_SELECT_CARD 3
/* -- trade data */
typedef struct {

	gboolean open;

	gint32 tradeid;
	gboolean player[MAX_PLAYERS][2];
	guint8 current_component;

	GtkWidget *TradeWin;
	GtkWidget *PlayerCList;
	GtkWidget *FrameComponent;
	GtkWidget *ProposalCList;
	GtkWidget *ComponentBox;
	GtkWidget *SubComponentBox;

	guint8  select_type;  // money, estate, card
	guint32 select_from;
	guint32 select_to;
	guint32 select_value;  // estateid, cardid

} _trade;


/* -- command data */
typedef struct {

	gboolean open;

	GtkWidget *Frame;
	GtkWidget *gdkrgb;
	gboolean   redraw;

	guchar *command;

} _command;


#define GAME_STATUS_NONE 0
#define GAME_STATUS_CONFIG 1
#define GAME_STATUS_INIT 2
#define GAME_STATUS_RUN 3
#define GAME_STATUS_END 4
#define GAME_TYPE_CREATE 1
#define GAME_TYPE_JOIN 2
typedef struct {

	guint8 status, type;
	gint32 gameid;

	_estate estate[MAX_ESTATES];
	_group group[MAX_GROUPS];
	_card card[MAX_CARDS];
	_trade trade[MAX_TRADES];
	_command command[MAX_COMMANDS];

	guint16 connectid;
	time_t start_time;
	guint16 board_frame;
	guint8 nb_players;

	guint32 my_playerid;
	gboolean i_am_the_master;

	GtkWidget *PlayerCList;

	GtkWidget *BoxMessageAndChat;
	gboolean   chat_float, message_float; // 0 = fixed, 1 = float
	GtkWidget *ChatFrame, *ChatWindow, *ChatBox, *Chat;
	guint32    chat_nb_lines;

	GtkWidget *GameConfigBox;
	GtkWidget *CommandsBox;
	GtkWidget *BoardCenter;
	GtkWidget *WinEstateTree;

	guint32 timeout_token;

} _game;

_game *game;



/* -- connect data */
#define MAX_CONNECTION 128
#define CONNECT_TYPE_MONOPD_GETGAME 1
#define CONNECT_TYPE_MONOPD_GAME 2
#define CONNECT_TYPE_META_GETLIST 3
#define CONNECT_TYPE_META_GETGAME 4
typedef struct {

	// connection setting
	guint8   type;  // type of connection
	gboolean connected;

	gchar   *host;
	gint32  port;
	guint32 socket;
	guchar  *server_version;

	guchar *buffer_in;

} _connect;

gboolean connection_is_open[MAX_CONNECTION];
_connect *connection[MAX_CONNECTION];



/* interface card */
typedef struct  {

	guint16 x;
	guint16 y;
	guint8  z;

	guint8  buffer_card;
	guint8  estateid;

} _interface_playerlist_card;


/* interface estate */
#define TYPE_HOUSE_NONE 0
#define TYPE_HOUSE_HORIZONTAL 1
#define TYPE_HOUSE_VERTICAL 2
typedef struct  {

	guint16 x;
	guint16 y;

	guint8  buffer_board;

	guint16 x1token;
	guint16 y1token;
	guint16 x2token;
	guint16 y2token;

	guint16 x1jail;
	guint16 y1jail;
	guint16 x2jail;
	guint16 y2jail;

	guint16 xstar;
	guint16 ystar;

	guint16 xhouse;
	guint16 yhouse;
	guint8  type_house;

} _interface_estate;


/* themes database */
typedef struct {

	gboolean open;

	guchar *path;
	guchar *path_preview;
	guchar *path_conf;

	guchar *name;
	guchar *type;
	guchar *version;
	guchar *author;
	guchar *email;

} _theme;


/* interface / pngfiles */
#define MAX_COMMANDS 20
#define MAX_HOUSES 10
#define MAX_THEMES 256
typedef struct  {

	/* pngfile logo */
	guchar  *pngfile_logo_filename;
	gboolean pngfile_logo_need_alpha;
	guchar  *pngfile_logo_image, *pngfile_logo_alpha;

	/* pngfile board */
	guchar  *pngfile_board_filename;
	gboolean pngfile_board_need_alpha;
	guint16  pngfile_board_x[MAX_ESTATES],     pngfile_board_y[MAX_ESTATES];
	guint16  pngfile_board_width[MAX_ESTATES], pngfile_board_height[MAX_ESTATES];
	guchar  *pngfile_board_image[MAX_ESTATES];

	/* pngfile_tokens */
	guchar  *pngfile_token_filename;
	gboolean pngfile_token_need_alpha;
	guint16  pngfile_token_x[MAX_PLAYERS],      pngfile_token_y[MAX_PLAYERS];
	guint16  pngfile_token_width[MAX_PLAYERS],  pngfile_token_height[MAX_PLAYERS];
	guchar  *pngfile_token_image[MAX_PLAYERS], *pngfile_token_alpha[MAX_PLAYERS];

	/* pngfile_stars */
	guchar  *pngfile_star_filename;
	gboolean pngfile_star_need_alpha;
	guint16  pngfile_star_x[MAX_PLAYERS],      pngfile_star_y[MAX_PLAYERS];
	guint16  pngfile_star_width[MAX_PLAYERS],  pngfile_star_height[MAX_PLAYERS];
	guchar  *pngfile_star_image[MAX_PLAYERS], *pngfile_star_alpha[MAX_PLAYERS];

	/* pngfile_stars_m (mortgaged) */
	guchar  *pngfile_star_m_filename;
	gboolean pngfile_star_m_need_alpha;
	guint16  pngfile_star_m_x[MAX_PLAYERS],      pngfile_star_m_y[MAX_PLAYERS];
	guint16  pngfile_star_m_width[MAX_PLAYERS],  pngfile_star_m_height[MAX_PLAYERS];
	guchar  *pngfile_star_m_image[MAX_PLAYERS], *pngfile_star_m_alpha[MAX_PLAYERS];

	/* pngfile_cards */
	guchar  *pngfile_card_filename;
	gboolean pngfile_card_need_alpha;
	guint16  pngfile_card_x[MAX_PLAYERLIST_CARDS],     pngfile_card_y[MAX_PLAYERLIST_CARDS];
	guint16  pngfile_card_width[MAX_PLAYERLIST_CARDS], pngfile_card_height[MAX_PLAYERLIST_CARDS];
	guchar  *pngfile_card_image[MAX_PLAYERLIST_CARDS];

	/* pngfile_commands */
	guchar  *pngfile_command_filename;
	gboolean pngfile_command_need_alpha;
	guint16  pngfile_command_x[MAX_COMMANDS],      pngfile_command_y[MAX_COMMANDS];
	guint16  pngfile_command_width[MAX_COMMANDS],  pngfile_command_height[MAX_COMMANDS];
	guchar  *pngfile_command_image[MAX_COMMANDS], *pngfile_command_alpha[MAX_COMMANDS];

	/* pngfile_horiz_houses */
	guchar  *pngfile_horiz_house_filename;
	gboolean pngfile_horiz_house_need_alpha;
	guint16  pngfile_horiz_house_x[MAX_HOUSES],      pngfile_horiz_house_y[MAX_HOUSES];
	guint16  pngfile_horiz_house_width[MAX_HOUSES],  pngfile_horiz_house_height[MAX_HOUSES];
	guchar  *pngfile_horiz_house_image[MAX_HOUSES], *pngfile_horiz_house_alpha[MAX_HOUSES];

	/* pngfile_vert_houses */
	guchar  *pngfile_vert_house_filename;
	gboolean pngfile_vert_house_need_alpha;
	guint16  pngfile_vert_house_x[MAX_HOUSES],      pngfile_vert_house_y[MAX_HOUSES];
	guint16  pngfile_vert_house_width[MAX_HOUSES],  pngfile_vert_house_height[MAX_HOUSES];
	guchar  *pngfile_vert_house_image[MAX_HOUSES], *pngfile_vert_house_alpha[MAX_HOUSES];


	/* load flags */
	gboolean png_intro_loaded;
	gboolean png_game_loaded;


	/* interface logo */
	guint16  logo_width, logo_height;

	/* interface estate */
	guint16 board_height, board_width;
	guint8  number_estates;
	_interface_estate estate[MAX_ESTATES];

	/* interface playerlist token */
	guint16 playerlist_token_width, playerlist_token_height;
	gint32  playerlist_token_bgcolor;

	/* interface playerlist cards */
	guint16 playerlist_cards_width, playerlist_cards_height;
	guint8  playerlist_cards_alphaunowned, playerlist_cards_alphaowned, playerlist_cards_alphamortgage;
	gint32  playerlist_cards_cardbgcolor, playerlist_cards_cardbgcolormortgage, playerlist_cards_bgcolor;
	guint8  number_playerlist_card;
	_interface_playerlist_card playerlist_card[MAX_PLAYERLIST_CARDS];


	/* themes database */
	_theme theme[MAX_THEMES];

} _data;

_data *data;


/* -- main data */
#define GAMECLIST_MODE_SERVERLIST 1
#define GAMECLIST_MODE_GAMELIST   2
#define PHASE_LOGO       1
#define PHASE_GETGAMES   2
#define PHASE_GAMECREATE 3
#define PHASE_GAMEINIT   4
#define PHASE_GAMEPLAY   5
typedef struct  {

	guchar *path_home;

	guint8 phase;

	GtkWidget *MainWin;
	GtkWidget *MainBox;
	GtkWidget *MainVerticalBox;

	GdkPixmap *icon_pixmap;
	GdkBitmap *icon_mask;

	GtkWidget *GameCList;
	guint8     mode_gameclist;  // serverlist or gamelist ?
	gchar     *selected_host;
	guint32    selected_port;
	gchar     *selected_gametype;
	gint32     selected_gameid;

	GtkWidget *ConfigWin;
	GtkWidget *HelpWin;

	GtkWidget *ThemeWin;
	gboolean   theme_redraw;

	GtkWidget *Trick;  //used for reparent some widgets shouldn't be displayed

	GtkWidget *MessageFrame, *MessageWindow, *MessageBox, *Message;
	guint32    message_nb_lines;

	_player player[MAX_PLAYERS];

	/* logo */
	GtkWidget *gdkrgb_logo;
	guint16    logo_frame, logo_pic, logo_alpha;
	gboolean   logo_redraw;

	/* gtk styles */
	GtkStyle *style_normal;
	GtkStyle *style_player_normal;
	GtkStyle *style_player_turn;
	GtkStyle *style_estate_title;

} _global;

_global *global;


/* all configuration */
#define GAME_PLAYERLIST_POS_LEFT  0
#define GAME_PLAYERLIST_POS_RIGHT 1
typedef struct  {

	guchar   *nickname;

	guchar   *metaserver_host;
	guint32   metaserver_port;
	gboolean  metaserver_autogetlist;
	gboolean  metaserver_autogetgames;
	gboolean  metaserver_sendclientversion;

	guchar   *getgames_host;
	guint32   getgames_port;
	gboolean  getgames_autogetgames;

	guint32   message_max_lines;
	guint32   chat_max_lines;

	guint8    game_playerlist_position;
	guint32   game_token_animation_speed;
	gboolean  game_token_transparency;

} _config;

_config *config;