Subversion Repositories Games.Chess Giants

Rev

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