Subversion Repositories Games.Chess Giants

Rev

Rev 192 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. // common.h
  2.  
  3. #ifndef COMMON_H
  4. #define COMMON_H
  5.  
  6.  
  7. // standard includes
  8. #include <windows.h>
  9. #include <windowsx.h>
  10. #include <iphlpapi.h>
  11. #include <icmpapi.h>
  12. #include <commctrl.h>
  13. #include <richedit.h>
  14. #include <stdio.h>
  15. #include <stdint.h>
  16. #include <io.h>
  17. #include <malloc.h>
  18. #include <math.h>
  19. #include <time.h>
  20. #include <share.h>
  21. #include <fcntl.h>
  22. #include <shlwapi.h>
  23. #pragma warning(disable:4091)
  24. #include <shlobj.h>
  25. #pragma warning(default:4091)
  26. #include <process.h>
  27. #include <sys/stat.h>
  28.  
  29.  
  30. // project resources includes
  31. #pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") // black magic to enable XP styles without a manifest =)
  32. #include "resource/resource.h"
  33.  
  34.  
  35. // link with specific libraries
  36. #pragma comment(lib, "iphlpapi.lib")
  37. #pragma comment (lib, "comctl32.lib") // for ImageList_*()
  38. #pragma comment (lib, "ws2_32.lib") // for network
  39.  
  40.  
  41. // global preprocessor defines
  42. #include "defines.h"
  43.  
  44.  
  45. // modeless message box definition
  46. typedef struct messagebox_s
  47. {
  48.    HWND hWndParent; // message box parent window
  49.    wchar_t title[128]; // message box title
  50.    wchar_t text[4096]; // message box text
  51.    int flags; // message box flags (such as MB_OK, MB_ICONEXCLAMATION, etc...)
  52. } messagebox_t;
  53.  
  54.  
  55. // resizeable buffer structure type definition
  56. typedef struct buffer_s
  57. {
  58.    char *data; // buffer data, mallocated
  59.    unsigned long size; // buffer size in bytes
  60. } buffer_t;
  61.  
  62.  
  63. // part color theme data definition
  64. typedef struct partcolor_s
  65. {
  66.    int texture; // index of the texture used for the pieces in this theme
  67.    int material; // index of the material used for the pieces in this theme
  68. } partcolor_t;
  69.  
  70.  
  71. // background sprite definition
  72. typedef struct backgroundsprite_s
  73. {
  74.    int sprite_index; // index of the sprite used as the background in this theme
  75.    int sprite_width; // nominal width of bg sprite in pixels, rounded to the nearest higher power of 2
  76.    int sprite_height; // nominal height of bg sprite in pixels, rounded to the nearest higher power of 2
  77. } backgroundsprite_t;
  78.  
  79.  
  80. // light definition
  81. typedef struct light_s
  82. {
  83.    int type; // one of LIGHT_DIRECTIONAL, LIGHT_POINT, or LIGHT_SPOT
  84.    unsigned long color; // diffuse color (RGBA)
  85.    float pos_x; // X position in space
  86.    float pos_y; // Y position in space
  87.    float pos_z; // Z position in space
  88.    float direction_x; // X direction in space
  89.    float direction_y; // Y direction in space
  90.    float direction_z; // Z direction in space
  91.    float range; // distance after which the light won't be computed
  92.    float attenuation_constant; // constant light attenuation
  93.    float attenuation_proportional; // light attenuation that is proportional to distance
  94.    float attenuation_square; // light attenuation that is proportional to distance squared
  95.    float cone_inner; // inner cone angle, in degrees
  96.    float cone_outer; // outer cone angle, in degrees
  97. } light_t;
  98.  
  99.  
  100. // definition for the scene illumination
  101. typedef struct illumination_s
  102. {
  103.    unsigned long ambient_light; // scene ambient light color (RGBA)
  104.    light_t *lights; // mallocated array of lights to render
  105.    int light_count; // size of the lights array
  106. } illumination_t;
  107.  
  108.  
  109. // theme definition
  110. typedef struct theme_s
  111. {
  112.    bool is_loaded; // set to TRUE when this theme is fully loaded
  113.    int load_index; // when loading asynchronously, index of the item to load for each pass
  114.  
  115.    wchar_t name[64]; // theme name (folder name)
  116.    wchar_t *description; // theme description or credits (mallocated)
  117.    backgroundsprite_t bg; // background sprite structure
  118.    illumination_t illum; // scene lights
  119.    int board_texture; // index of the texture used for the chess grid in this theme
  120.    int table_texture; // index of the texture used for the rest of the table in this theme
  121.    int grid_texture; // index of the texture used for the board grid numbers and letters
  122.    int trim_texture; // index of the texture used for the table/board delimiter
  123.    int board_material; // index of the material used for the chess grid in this theme
  124.    int table_material; // index of the material used for the rest of the table in this theme
  125.    int trim_material; // index of the material used for the table/board delimiter
  126.    unsigned char reflection_alpha; // table reflection alpha from 0 to 255 (high for marble, low for wood)
  127.    partcolor_t part_colors[2]; // part theme data for the two colors, COLOR_BLACK and COLOR_WHITE
  128.  
  129.    // meshes
  130.    int board_meshindex;
  131.    int table_meshindex;
  132.    int trim_meshindex;
  133.    int tile_meshindex;
  134.    int part_meshes[7]; // first slot unused
  135.    // textures
  136.    int shadow_textureindex;
  137.    int hovered_textureindex;
  138.    int check_textureindex;
  139.    int threat_textureindex;
  140.    int lastmovesource_textureindex;
  141.    int lastmovetarget_textureindex;
  142.    int selected_textureindex;
  143.    int possiblemove_textureindex;
  144.    int takeable_textureindex;
  145.    int flattextures[2][7]; // [color][part], with first slot of the 7 unused
  146.    // sprites
  147.    int flatsprites[2][7]; // [color][part], with first slot of the 7 unused
  148.    int lastmovesource_spriteindex;
  149.    int lastmovetarget_spriteindex;
  150. } theme_t;
  151.  
  152.  
  153. // local typedefs
  154. typedef struct pgngame_s
  155. {
  156.    wchar_t event_str[64]; // [Event "blah"]
  157.    wchar_t site_str[64]; // [Site "blah"]
  158.    wchar_t date_str[16]; // [Date "YYYY.MM.DD"]
  159.    wchar_t round_str[16]; // [Round "N"]
  160.    wchar_t white_str[64]; // [White "blah"]
  161.    wchar_t black_str[64]; // [Black "blah"]
  162.    wchar_t result_str[16]; // [Result "blah"]
  163.    wchar_t eco_str[8]; // [ECO "XNN"] <-- this tag is optional, but useful nevertheless
  164.    wchar_t fen_str[128]; // [FEN "start pos"] <-- this tag is optional, but VERY useful
  165.    int gamedata_start; // offset at which the game data begins for this entry
  166. } pgngame_t;
  167.  
  168.  
  169. // player definition
  170. typedef struct player_s
  171. {
  172.    // common data
  173.    int type; // PLAYER_COMPUTER, PLAYER_INTERNET or PLAYER_HUMAN
  174.    char color; // either COLOR_BLACK, COLOR_WHITE or COLOR_UNSPECIFIED
  175.    wchar_t name[64]; // player name (machine name if human vs human or human vs cpu, login if human vs network)
  176.    float view_pitch; // current view pitch (vertical axis orientation towards the table center)
  177.    float view_yaw; // current view yaw (horizontal axis orientation towards the table center)
  178.    float view_distance; // current view distance to the table center
  179.    float custom_pitch; // user-saved view pitch
  180.    float custom_yaw; // user-saved view yaw
  181.    float custom_distance; // user-saved view distance
  182.    bool wants_cancel; // set to TRUE when this player wants to cancel its last move
  183.    bool should_wakeup; // set to TRUE when the current player has just changed to us
  184.  
  185.    // PLAYER_HUMAN related data
  186.  
  187.    // PLAYER_COMPUTER related data
  188.    bool wants_hint;
  189.  
  190.    // PLAYER_INTERNET related data
  191.    int our_socket;
  192.    bool is_connected;
  193.    bool is_logged_in;
  194.    bool is_in_game;
  195.    int game_number;
  196.    int remaining_seconds;
  197.  
  198.    // PLAYER_COMPUTER and PLAYER_INTERNET related data
  199.    float sleep_time; // date until which that player should not think at all
  200.    bool sendbuffer_locked; // set to TRUE if a thread currently locks the send buffer
  201.    wchar_t *sendbuffer; // used both for PLAYER_COMPUTER and PLAYER_INTERNET, mallocated
  202.    int sendbuffer_size; // size of the sendbuffer buffer
  203.    char *ascii_recvbuffer; // mallocated
  204.    wchar_t *recvbuffer; // used both for PLAYER_COMPUTER and PLAYER_INTERNET, mallocated
  205.    int recvbuffer_size; // size of the recvbuffer buffer
  206.  
  207. } player_t;
  208.  
  209.  
  210. // definitions for a grid slot, a board side and a chess board
  211. typedef struct boardslot_s
  212. {
  213.    unsigned char part; // part ID of the part occupying this slot, or PART_NONE if not occupied
  214.    unsigned char color; // color ID of the part occupying this slot (either COLOR_WHITE or COLOR_BLACK)
  215.    unsigned char flags; // bitmap of slot flags (e.g: selected, move allowed, etc)
  216. } boardslot_t;
  217.  
  218.  
  219. typedef struct boardside_s
  220. {
  221.    unsigned char *takenparts; // mallocated array of part IDs that this side has captured from the opposing side
  222.    int takenpart_count; // size of the takenparts array
  223.    bool shortcastle_allowed; // set to TRUE if this side's king can still castle to G (column id 6)
  224.    bool longcastle_allowed; // set to TRUE if this side's king can still castle queenside, to C (column id 3)
  225. } boardside_t;
  226.  
  227.  
  228. typedef struct boardmove_s
  229. {
  230.    char color; // color this board move was for (either COLOR_UNSPECIFIED, COLOR_BLACK or COLOR_WHITE)
  231.    char part; // board move part type (to handle promotions)
  232.    char promotion_type; // in case of a pawn promotion, the new part's type
  233.    bool has_captured; // set to TRUE if this part has just captured another part
  234.    bool is_enpassant; // set to TRUE if the move was an "en passant" capture move
  235.    bool is_check; // set to TRUE if this move puts the opponent's king to check
  236.    bool is_stalemate; // set to TRUE if this move puts the opponent to stalemate
  237.    char source[2]; // this chess board's move source position ([line][column] array)
  238.    char target[2]; // this chess board's move target position ([line][column] array)
  239.    wchar_t pgntext[16]; // move PGN text
  240.    wchar_t *comment; // comment about that move (mallocated)
  241.    int comment_size; // size of the mallocated space used for comments, *IN WCHARS*
  242.    boardside_t sides[2]; // game state data structure for both opposing sides (COLOR_BLACK and COLOR_WHITE) after move is made
  243.    boardslot_t slots[8][8]; // this chess board's slots (8x8 array) after move is made
  244.    wchar_t fen_string[128]; // FEN string describing that move
  245. } boardmove_t;
  246.  
  247.  
  248. typedef struct board_s
  249. {
  250.    bool was_setup; // set to TRUE when the board has just been set up
  251.    int hovered_position[2]; // this chess board's hovered position ([line][column] array)
  252.    int selected_position[2]; // this chess board's selected position ([line][column] array)
  253.    boardmove_t *moves; // array of moves describing the game (mallocated)
  254.    int move_count; // amount of moves in this game so far
  255.    int viewed_move; // index of the move currently viewed (for watching game history)
  256.    player_t players[2]; // game state data structure for both opposing sides (COLOR_BLACK and COLOR_WHITE)
  257.    bool want_playerswap; // set to TRUE when a players swap is requested
  258.    int game_state; // one of the STATE_XXX #defines that describe the game and victory state
  259.    float lastmove_time; // date of last move
  260.    bool reevaluate; // set to TRUE if the game state should be reevaluated
  261.    wchar_t game_rules[32]; // current rules, e.g. "standard", "blitz", "lightning", "untimed", "losers", "atomic"...
  262. } board_t;
  263.  
  264.  
  265. // scene object definition
  266. typedef struct sceneobject_s
  267. {
  268.    int mesh_index; // object mesh index
  269.    int texture_index; // object texture index
  270.    int material_index; // object material index
  271.    float scale; // object scale, 1.0f = default size
  272.    float simpleshadow_size; // multiplier for the size of the original texture
  273.    float x; // X position in space
  274.    float y; // Y position in space
  275.    float z; // Z position in space
  276.    float pitch; // object pitch in degrees (leaning left/right)
  277.    float yaw; // object yaw in degrees (turning left/right)
  278. } sceneobject_t;
  279.  
  280.  
  281. // chatter channel reply
  282. typedef struct ccreply_s
  283. {
  284.    float arrival_time; // date at which this reply arrived
  285.    unsigned long color; // text color (RGBA)
  286.    wchar_t channelname[64]; // id of the channel this message is sent on (64 characters max!)
  287.    wchar_t nickname[32]; // sender's nickname
  288.    wchar_t *text; // message text (mallocated)
  289.    int text_length; // length of the above text, in characters, NOT including the null terminator
  290. } ccreply_t;
  291.  
  292.  
  293. // user interface button definition
  294. typedef struct guibutton_s
  295. {
  296.    int state; // render state: 0 = invisible, 1 = enabled, 2 = hovered
  297.    float left; // position of the top left corner, in percentage of screen width
  298.    float top; // position of the top left corner, in percentage of screen height
  299.    float width; // button tile width, in percentage of screen width
  300.    float height; // button tile height, in percentage of screen height
  301.    int sprite_index; // index of the sprite this button displays
  302.    wchar_t *font_face; // name of the font with which to display this text (should point to a static string)
  303.    float font_sizepct; // size of the font with which to display this text, in percentage of window height
  304.    bool is_bold; // set to TRUE if the font is to be displayed in bold weight
  305.    bool is_italic; // set to TRUE if the font is to be displayed in italic typeface
  306.    wchar_t text[64]; // GUI button text (64 characters max!)
  307. } guibutton_t;
  308.  
  309.  
  310. // user interface text field definition
  311. typedef struct guitext_s
  312. {
  313.    bool is_displayed; // set to TRUE if this text is displayed
  314.    float xpos_percent; // text's X position, in percents from left to right
  315.    float ypos_percent; // text's Y position, in percents from top to bottom
  316.    float maxwidth_percent; // text's max width before word wrapping, in percents of draw area width (0 meaning "use full width")
  317.    int horizontal_align; // bounding rectangle's horizontal alignment regarding the X position (one of the ALIGN_xxx defines)
  318.    int vertical_align; // bounding rectangle's vertical alignment regarding the Y position (one of the ALIGN_xxx defines)
  319.    int text_align; // text's horizontal alignment inside that bounding rectangle
  320.    wchar_t *font_face; // name of the font with which to display this text (should point to a static string)
  321.    float font_sizepct; // size of the font with which to display this text, in percentage of window height
  322.    bool is_bold; // set to TRUE if the font is to be displayed in bold weight
  323.    bool is_italic; // set to TRUE if the font is to be displayed in italic typeface
  324.    unsigned long color; // text's color (RGBA)
  325.    wchar_t *buffer; // text printed in this area of the screen (mallocated)
  326.    int buffer_size; // size of the text buffer
  327.    float appear_time; // date at which this text was put
  328.    float disappear_time; // date at which this text should disappear
  329.    bool want_fade; // set to TRUE if this text is to be faded in and out
  330. } guitext_t;
  331.  
  332.  
  333. // game user interface definition
  334. typedef struct gui_s
  335. {
  336.    // IMPORTANT: ensure all guitext_t buffers are freed in Scene_Shutdown()
  337.  
  338.    guibutton_t llarrow; // render state: 0 = invisible, 1 = enabled, 2 = hovered
  339.    guibutton_t larrow; // render state: 0 = invisible, 1 = enabled, 2 = hovered
  340.    guibutton_t rarrow; // render state: 0 = invisible, 1 = enabled, 2 = hovered
  341.    guibutton_t rrarrow; // render state: 0 = invisible, 1 = enabled, 2 = hovered
  342.    guitext_t arrow_text; // usually, viewed move number versus the total of moves
  343.    guibutton_t newgamebutton; // render state: 0 = invisible, 1 = enabled, 2 = hovered
  344.    guibutton_t opengamebutton; // render state: 0 = invisible, 1 = enabled, 2 = hovered
  345.    guibutton_t chatbutton; // render state: 0 = invisible, 1 = enabled, 2 = hovered
  346.    guibutton_t gamesbutton; // render state: 0 = invisible, 1 = enabled, 2 = hovered
  347.    guibutton_t peoplebutton; // render state: 0 = invisible, 1 = enabled, 2 = hovered
  348.    guitext_t comment_text; // text printed in the comments area
  349.    guitext_t history_text; // text printed in the moves text area
  350.    guitext_t clock_text; // text printed in the game clock area
  351.    guitext_t turn_text; // text printed in the "X moves" area
  352.    guitext_t central_text; // text printed in the center of the screen
  353.    ccreply_t *cchistory; // mallocated array of chatter channel replies
  354.    int cchistory_count; // number of elements in the above array
  355.    bool is_entering_text; // set to TRUE if player is entering text
  356.    ccreply_t entered_ccreply; // text that is currently being entered
  357.    bool is_partspick_displayed; // set to TRUE if the parts pick line is displayed
  358.    bool want_spinwheel; // set to TRUE to display a spinning wheel
  359.    char partspick_hoveredpart; // one of "PRNBQK kqbnrp"
  360.    char partspick_selectedpart; // one of "PRNBQK kqbnrp"
  361. } gui_t;
  362.  
  363.  
  364. // rendering scene definition
  365. typedef struct scene_s
  366. {
  367.    int background_spriteindex; // index of the background sprite (-1 if none)
  368.    sceneobject_t *objects; // mallocated array of objects to render
  369.    int object_count; // size of the objects array
  370.    int overlay_spriteindex; // index of the overlay sprite (-1 if none)
  371.    gui_t gui; // GUI laid over this scene
  372.    bool update; // set to TRUE if the scene needs to be updated
  373. } scene_t;
  374.  
  375.  
  376. // engine program options definition (populated from "engines/<program>/engine.ini")
  377. typedef struct engineprogram_s
  378. {
  379.    wchar_t folder[MAX_PATH]; // chess engine folder name
  380.    wchar_t friendly_name[64]; // chess engine name (will be used as player name)
  381.    wchar_t executable_name[MAX_PATH]; // chess engine binary startup command-line, e.g "gnuchess.exe"
  382.    wchar_t executable_arguments[MAX_PATH]; // chess engine command-line arguments
  383.    uint64_t kernel32_minver; // required Windows kernel32.dll version (4 words)
  384.    wchar_t replystring_move[256]; // chess engine reply string for a move (positions come right after)
  385.    wchar_t command_new[256]; // command to send the chess engine to tell him we are starting a new game
  386.    wchar_t command_setboard[256]; // command to send the chess engine to tell him to set the table in a particular way (FEN notation)
  387.    wchar_t command_go[256]; // command to send the chess engine to make it play the current move
  388.    wchar_t command_move[256]; // command to send the chess engine to instruct it that its opponent played a particular move
  389.    wchar_t command_force[256]; // command to send the chess engine to force it to play a particular move instead of the one it wants
  390.    wchar_t command_quit[256]; // command to send the chess engine to make it exit cleanly
  391.    bool already_crashed; // set to TRUE if this engine already crashed during this Chess Giants session
  392. } engineprogram_t;
  393.  
  394.  
  395. // engine options definition
  396. typedef struct engineoptions_s
  397. {
  398.    int depth; // chess engine's currently allowed search depth
  399.    int max_depth; // chess engine maximum search depth (used just for slider display)
  400.    int blunder_chances; // chess engine blunder chances, in percent
  401.    int obstinacy_level; // chess engine obstinacy level, in number of moves
  402.    bool is_expert_mode; // set to TRUE if this player claims to be an expert player (in the game settings)
  403.    engineprogram_t *programs; // engine programs
  404.    int program_count; // size of the engines array
  405.    int selected_program; // index of the selected engine
  406. } engineoptions_t;
  407.  
  408.  
  409. // network options definition
  410. typedef struct networkoptions_s
  411. {
  412.    wchar_t server_address[MAX_PATH]; // chess server URL for online gaming
  413.    int server_port; // chess server listen port (usually 5000) for online gaming
  414.    wchar_t login[32]; // login for online gaming
  415.    wchar_t password[32]; // password for online gaming
  416.    bool want_servermessages; // set to TRUE if server messages are to be displayed (MOTD, RoboAdmin messages, announcements)
  417.    bool want_publicchat; // set to TRUE if public chat messages and chatter channels list are to be displayed
  418.    bool want_motdonconnect; // set to TRUE if the MOTD is to be displayed when connecting to the chess server
  419. } networkoptions_t;
  420.  
  421.  
  422. // part letter options definition
  423. typedef struct partletter_s
  424. {
  425.    wchar_t rook[2];   // e.g. 'R' -- needs to be a string for config read/write. Only the first char is used.
  426.    wchar_t knight[2]; // e.g. 'N' -- needs to be a string for config read/write. Only the first char is used.
  427.    wchar_t bishop[2]; // e.g. 'B' -- needs to be a string for config read/write. Only the first char is used.
  428.    wchar_t queen[2];  // e.g. 'Q' -- needs to be a string for config read/write. Only the first char is used.
  429.    wchar_t king[2];   // e.g. 'K' -- needs to be a string for config read/write. Only the first char is used.
  430. } partletter_t;
  431.  
  432.  
  433. // registration options definition
  434. typedef struct registrationoptions_s
  435. {
  436.    wchar_t user_email[MAX_PATH]; // registered user's email address
  437.    unsigned __int32 activation_code; // registered user's activation code (a 32-bit integer)
  438. } registrationoptions_t;
  439.  
  440.  
  441. // game options definition
  442. typedef struct options_s
  443. {
  444.    bool want_fullscreen; // set to TRUE to run in fullscreen mode (no taskbar)
  445.    bool want_maximized; // set to TRUE to run in maximized window mode
  446.    int window_width; // window width when not in fullscreen mode
  447.    int window_height; // window height when not in fullscreen mode
  448.    bool want_sounds; // set to TRUE to enable sounds
  449.    bool want_animations; // set to TRUE to enable part animations
  450.    bool want_slidinganimations; // set to TRUE to enable SLIDING part animations
  451.    bool want_possiblemoves; // set to TRUE to show possible moves
  452.    bool want_lastmove; // set to TRUE to show the last move
  453.    bool want_threats; // set to TRUE to display king's threats
  454.    bool want_autorotateon1vs1; // set to TRUE to enable board auto-rotation when playing human vs human locally
  455.    bool want_playblackside; // set to TRUE if the local player prefers to play the black side (does not apply on local 1 vs 1)
  456.    bool want_takenparts; // set to TRUE to display the taken parts on the side of the board
  457.    bool want_turn; // set to TRUE to display the current turn
  458.    bool want_clock; // set to TRUE to display a game clock
  459.    unsigned long clock_color; // RGBA color of the game clock
  460.    bool want_history; // set to TRUE to enable the display of game history
  461.    unsigned long history_color; // RGBA color of the game history
  462.    bool want_sepiafilter; // set to TRUE to enable the sepia filter when displaying past moves
  463.    bool want_filtering; // set to TRUE to enable texture filtering
  464.    bool want_hiquality; // set to TRUE to enable maximum possible quality filtering
  465.    bool want_reflections; // set to TRUE to enable part reflections
  466.    bool want_specularlighting; // set to TRUE to enable specular lighting
  467.    bool want_startwithtopview; // set to TRUE to always start a game with the top view
  468.    int rotate_speed; // board rotation speed
  469.    partletter_t part_letters; // part abbreviation letters
  470.    registrationoptions_t registration; // registration options
  471.    engineoptions_t engine; // engine options
  472.    networkoptions_t network; // network options
  473. } options_t;
  474.  
  475.  
  476. // online player definition
  477. typedef struct onlineplayer_s
  478. {
  479.    int rating; // player rating (ELO estimate)
  480.    unsigned char ratingtype; // either one of RATING_xxx (default, estimated or provisional)
  481.    unsigned char handlestatus; // either one of HANDLESTATUS_xxx values
  482.    wchar_t nickname[32]; // this player's nickname
  483.    unsigned short handlecodes; // bitmap: one or several of HANDLECODE_xxx flag
  484. } onlineplayer_t;
  485.  
  486.  
  487. // chatter channel member definition
  488. typedef struct chatterchannelmember_s
  489. {
  490.    bool is_silenced; // set to TRUE if this player plays in silence
  491.    wchar_t nickname[32]; // this player's nickname
  492. } chatterchannelmember_t;
  493.  
  494.  
  495. // chatter channel definition
  496. typedef struct chatterchannel_s
  497. {
  498.    int id; // channel's numeric ID
  499.    bool is_open; // set to TRUE if listening is currently enabled for this channel
  500.    wchar_t theme[64]; // channel theme, as reported by the server
  501.    unsigned long color; // channel text color (RGBA)
  502.    chatterchannelmember_t *members; // mallocated array of members
  503.    int member_count; // number of members in this channel
  504. } chatterchannel_t;
  505.  
  506.  
  507. // challenge definition
  508. typedef struct challenge_s
  509. {
  510.    bool is_active; // set to TRUE if this challenge is active
  511.    wchar_t challenger[32]; // challenger nickname
  512.    HWND hWnd; // challenge window handle
  513.    int challenger_level; // challenger level
  514.    int color; // color this challenger wants to play
  515.    bool is_rated; // whether this game is rated or not
  516.    wchar_t game_type[32]; // game type, literally
  517.    float initial_time; // initial time of the game for each color
  518.    float increment; // eventual time increment (Fischer pace)
  519.    bool update_dialog; // set to TRUE when the dialog window should be updated
  520. } challenge_t;
  521.  
  522.  
  523. // sought game definition
  524. typedef struct soughtgame_s
  525. {
  526.    int id; // sought game ID
  527.    int rating; // player rating (ELO estimate)
  528.    wchar_t nickname[32]; // this player's nickname
  529.    float initial_time; // initial time of the game for each color
  530.    float increment; // eventual time increment (Fischer pace)
  531.    unsigned char rating_type; // one of GAMERATINGTYPE_xxx #defines
  532.    wchar_t game_type[32]; // game type, literally
  533.    int color; // color this player will have
  534.    int lowest_accepted; // lowest ELO accepted
  535.    int highest_accepted; // highest ELO accepted
  536.    bool manual_start; // set to TRUE if the game should start manually
  537.    bool formula_checked; // set to TRUE if the filter formula will be used
  538. } soughtgame_t;
  539.  
  540.  
  541. // chat interlocutor
  542. typedef struct interlocutor_s
  543. {
  544.    bool is_active; // set to TRUE if this interlocutor is active
  545.    wchar_t nickname[32]; // interlocutor nickname (don't point to player list, because it changes...)
  546.    HWND hWnd; // chat window handle
  547.    int current_displaypicture; // current display picture index
  548.    wchar_t *dialogtext; // mallocated wchar_t buffer of dialog text (beware: RTF is ASCII-only)
  549.    int dialogtext_size; // size of the dialog text buffer, in WCHARs
  550.    bool update_dialog; // set to TRUE when the dialog window should be updated
  551. } interlocutor_t;
  552.  
  553.  
  554. // game style ratings
  555. typedef struct gamestylerating_s
  556. {
  557.    wchar_t name[32]; // game style name (e.g, "standard", "blitz", etc.)
  558.    int rating; // ELO rating for this style of play
  559.    float rd; // unknown data ???
  560.    int win_count; // amount of won matches in this style of play
  561.    int loss_count; // amount of lost matches in this style of play
  562.    int draw_count; // amount of draw matches in this style of play
  563.    int total_matches; // amount of played matches in this style of play (basically, sum of win + loss + draws)
  564. } gamestylerating_t;
  565.  
  566.  
  567. // player cards
  568. typedef struct playercard_s
  569. {
  570.    bool is_active; // set to TRUE if this slot is active
  571.    bool is_own; // set to TRUE if this card is the local player's one
  572.    wchar_t nickname[32]; // interlocutor nickname (don't point to player list, because it changes...)
  573.    HWND hWnd; // player card window handle
  574.    bool got_reply; // set to TRUE when this player card slot got server reply (i.e, it contains actual data)
  575.    bool doesnt_exist; // set to TRUE when the chess server reports that this player doesn't exist
  576.    int minutes_online; // amount of minutes this player has been online
  577.    int seconds_idle; // amount of seconds elapsed since this player's last activity
  578.    unsigned char disconnection_day; // day of disconnection
  579.    unsigned char disconnection_month; // month of disconnection
  580.    unsigned short disconnection_year; // year of disconnection
  581.    int game_played; // index of the game currently played by this player
  582.    wchar_t game_name[64]; // name of the game currently played by this player
  583.    wchar_t *fingertext; // mallocated wchar_t buffer of personal finger text
  584.    int fingertext_length; // size of the finger text buffer, in WCHARs
  585.    gamestylerating_t *gamestyleratings; // mallocated array of game styles for which this player is rated
  586.    int gamestylerating_count; // amount of different game styles for which this player is rated
  587.    bool update_dialog; // set to TRUE when the dialog window should be updated
  588. } playercard_t;
  589.  
  590.  
  591. // handle status pictures
  592. typedef struct handlestatus_s
  593. {
  594.    HICON icon; // icon handle
  595.    HBITMAP bitmap; // bitmap handle
  596.    wchar_t *text; // pointer to the text string describing this status
  597. } handlestatus_t;
  598.  
  599.  
  600. // smilies
  601. typedef struct smiley_s
  602. {
  603.    wchar_t name[32]; // smiley name
  604.    wchar_t filename[MAX_PATH]; // filename of that smiley's PNG picture
  605.    wchar_t *rtf_data; // smiley RTF data, mallocated
  606.    int rtf_len; // length of the above data string (minus the null terminator)
  607. } smiley_t;
  608.  
  609.  
  610. // localized texts
  611. typedef struct text_s
  612. {
  613.    wchar_t *id_string; // ID string for the given text (mallocated), example: "AboutBox_Title"
  614.    wchar_t *localized_string; // localized string for the given text (mallocated), example: "A propos de ce logiciel"
  615. } text_t;
  616.  
  617.  
  618. // languages
  619. typedef struct language_s
  620. {
  621.    wchar_t name[64]; // language name, e.g. "French", "English" or "Norwegian (norsk)"
  622.    text_t *texts; // mallocated array of localized texts
  623.    int text_count; // size of the texts array
  624. } language_t;
  625.  
  626.  
  627. // global declarations
  628. #ifndef DEFINE_GLOBALS
  629. #define GLOBAL extern
  630. #else
  631. #define GLOBAL
  632. #endif
  633. GLOBAL int language_id;
  634. GLOBAL bool dont_nag;
  635. GLOBAL bool is_registered;
  636. GLOBAL bool terminate_everything;
  637. GLOBAL HINSTANCE hAppInstance;
  638. GLOBAL uint64_t kernel32_version;
  639. GLOBAL wchar_t app_path[MAX_PATH];
  640. GLOBAL wchar_t load_pathname[MAX_PATH];
  641. GLOBAL wchar_t save_pathname[MAX_PATH];
  642. GLOBAL HMENU hMainMenu;
  643. GLOBAL HACCEL hMainAccelerators;
  644. GLOBAL HWND hMainWnd;
  645. GLOBAL HWND hChatterChannelsWnd;
  646. GLOBAL HWND hGamesWnd;
  647. GLOBAL HWND hMOTDWnd;
  648. GLOBAL HWND hOpponentsWnd;
  649. GLOBAL HWND hSoughtWnd;
  650. GLOBAL messagebox_t messagebox;
  651. GLOBAL bool want_framerate;
  652. GLOBAL bool is_paused;
  653. GLOBAL float current_time;
  654. GLOBAL float stoppage_time;
  655. GLOBAL float animation_endtime;
  656. GLOBAL float command_ignoretime;
  657. GLOBAL float highlight_endtime;
  658. GLOBAL float current_pitch;
  659. GLOBAL float current_yaw;
  660. GLOBAL float current_distance;
  661. GLOBAL float lookatpoint_x;
  662. GLOBAL float lookatpoint_y;
  663. GLOBAL int current_viewer;
  664. GLOBAL handlestatus_t handlestatus[9]; // first slot unused
  665. // dialog boxes and windows
  666. GLOBAL bool is_dialogbox_displayed;
  667. GLOBAL bool is_dialogbox_about_validated;
  668. GLOBAL bool is_dialogbox_challenge_validated;
  669. GLOBAL bool is_dialogbox_changeappearance_validated;
  670. GLOBAL bool is_dialogbox_comment_validated;
  671. GLOBAL bool is_dialogbox_endgame_validated;
  672. GLOBAL bool is_dialogbox_gotomove_validated;
  673. GLOBAL bool is_dialogbox_renamesides_validated;
  674. GLOBAL bool is_dialogbox_load_validated;
  675. GLOBAL bool is_dialogbox_message_validated;
  676. GLOBAL bool is_dialogbox_newgame_validated;
  677. GLOBAL bool is_dialogbox_options_validated;
  678. GLOBAL bool is_dialogbox_pawnpromotion_validated;
  679. GLOBAL bool is_dialogbox_playercard_validated;
  680. GLOBAL bool is_dialogbox_playerinfoname_validated;
  681. GLOBAL bool is_dialogbox_quit_validated;
  682. GLOBAL bool is_dialogbox_resign_validated;
  683. GLOBAL bool is_dialogbox_save_validated;
  684. GLOBAL bool is_dialogbox_saveposition_validated;
  685. GLOBAL bool is_dialogbox_sendchallenge_validated;
  686. GLOBAL bool is_dialogbox_sendseek_validated;
  687. GLOBAL bool is_dialogbox_takeback_validated;
  688. GLOBAL bool is_window_chat_validated;
  689. GLOBAL bool is_window_chatterchannels_validated;
  690. GLOBAL bool is_window_games_validated;
  691. GLOBAL bool is_window_motd_validated;
  692. GLOBAL bool is_window_opponents_validated;
  693. GLOBAL bool is_window_sought_validated;
  694. // themes
  695. GLOBAL theme_t *themes; // mallocated, slot 0 must always be valid (default theme)
  696. GLOBAL int theme_count;
  697. GLOBAL theme_t *theme; // pointer to current theme
  698. GLOBAL wchar_t wantedtheme_name[64];
  699. GLOBAL bool want_grid;
  700. GLOBAL bool want_flaticons;
  701. GLOBAL bool want_custombackground;
  702. GLOBAL wchar_t custombackground_pathname[MAX_PATH];
  703. GLOBAL backgroundsprite_t custombg;
  704. // main objects
  705. GLOBAL options_t options;
  706. GLOBAL board_t the_board;
  707. GLOBAL scene_t the_scene;
  708. // languages
  709. GLOBAL language_t *languages; // mallocated
  710. GLOBAL int language_count;
  711. GLOBAL bool is_language_auto;
  712. // online stuff
  713. GLOBAL wchar_t server_motd[USHRT_MAX];
  714. GLOBAL onlineplayer_t *onlineplayers; // mallocated
  715. GLOBAL int onlineplayer_count; // -1 means "reply not arrived"
  716. GLOBAL bool onlineplayers_updated; // TRUE when display is to be updated
  717. GLOBAL float lastonlineplayers_time; // date at which the last update was received
  718. GLOBAL soughtgame_t *soughtgames; // mallocated
  719. GLOBAL int soughtgame_count; // -1 means "reply not arrived"
  720. GLOBAL bool soughtgames_updated; // TRUE when display is to be updated
  721. GLOBAL float lastsought_time; // date at which the last update was received
  722. GLOBAL chatterchannel_t *chatterchannels; // mallocated
  723. GLOBAL int chatterchannel_count; // -1 means "reply not arrived"
  724. GLOBAL chatterchannel_t *selected_chatterchannel;
  725. GLOBAL bool chatterchannels_updated;
  726. GLOBAL interlocutor_t *interlocutors; // mallocated
  727. GLOBAL int interlocutor_count;
  728. GLOBAL playercard_t *playercards; // mallocated
  729. GLOBAL int playercard_count;
  730. GLOBAL challenge_t *challenges; // mallocated
  731. GLOBAL int challenge_count;
  732. // smilies
  733. GLOBAL smiley_t *smilies; // mallocated
  734. GLOBAL int smiley_count;
  735. // PGN games
  736. GLOBAL pgngame_t *games; // mallocated
  737. GLOBAL int game_count;
  738. // GDI fonts
  739. GLOBAL HFONT hFontChat;
  740. // sprites
  741. GLOBAL int llarrow_spriteindex;
  742. GLOBAL int larrow_spriteindex;
  743. GLOBAL int rarrow_spriteindex;
  744. GLOBAL int rrarrow_spriteindex;
  745. GLOBAL int newgamebutton_spriteindex;
  746. GLOBAL int opengamebutton_spriteindex;
  747. GLOBAL int chatbutton_spriteindex;
  748. GLOBAL int gamesbutton_spriteindex;
  749. GLOBAL int peoplebutton_spriteindex;
  750. GLOBAL int sepia_spriteindex;
  751. GLOBAL int spinner_spriteindex[12];
  752. // debug logging facilities
  753. GLOBAL wchar_t logfile_pathname[MAX_PATH];
  754.  
  755.  
  756. // function prototypes
  757. #include "prototypes.h"
  758.  
  759.  
  760. #endif // COMMON_H
  761.