diff options
Diffstat (limited to 'src/main-win.c')
-rw-r--r-- | src/main-win.c | 1096 |
1 files changed, 38 insertions, 1058 deletions
diff --git a/src/main-win.c b/src/main-win.c index 92a2a775..54336a37 100644 --- a/src/main-win.c +++ b/src/main-win.c @@ -36,14 +36,8 @@ * * Compiling this file, and using the resulting executable, requires * several extra files not distributed with the standard Angband code. - * If "USE_GRAPHICS" is defined, then "readdib.h" and "readdib.c" must - * be placed into "src/", and the "8X8.BMP" bitmap file must be placed - * into "lib/xtra/graf". In any case, some "*.fon" files (including - * "8X13.FON" if nothing else) must be placed into "lib/xtra/font/". - * If "USE_SOUND" is defined, then some special library (for example, - * "winmm.lib") may need to be linked in, and desired "*.WAV" sound - * files must be placed into "lib/xtra/sound/". All of these extra - * files can be found in the "ext-win" archive. + * In any case, some "*.fon" files (including "8X13.FON" if nothing + * else) must be placed into "lib/xtra/font/". * * * The "Term_xtra_win_clear()" function should probably do a low-level @@ -74,10 +68,11 @@ #include "angband.h" - - -#ifdef WINDOWS - +#include "dungeon.h" +#include "files.h" +#include "init2.h" +#include "util.h" +#include "variable.h" /* * Extract the "WIN32" flag from the compiler @@ -101,11 +96,7 @@ #define IDM_FILE_NEW 100 #define IDM_FILE_OPEN 101 #define IDM_FILE_SAVE 110 -#ifdef ALLOW_QUITTING -# define IDM_FILE_ABORT 120 -#else -# define IDM_FILE_SCORE 120 -#endif +#define IDM_FILE_SCORE 120 #define IDM_FILE_EXIT 121 #define IDM_WINDOW_VIS_0 200 @@ -171,17 +162,9 @@ #define IDM_WINDOW_D_HGT_6 276 #define IDM_WINDOW_D_HGT_7 277 -#define IDM_OPTIONS_OLD_GRAPHICS 400 -#define IDM_OPTIONS_NEW_GRAPHICS 401 -#define IDM_OPTIONS_ASCII_GRAPHICS 403 -#define IDM_OPTIONS_SOUND 402 -#define IDM_OPTIONS_BIGTILE 409 #define IDM_OPTIONS_UNUSED 410 #define IDM_OPTIONS_SAVER 411 -#define IDM_HELP_GENERAL 901 -#define IDM_HELP_SPOILERS 902 - /* * This may need to be removed for some compilers XXX XXX XXX @@ -254,9 +237,6 @@ /* * Include the support for loading bitmaps */ -#ifdef USE_GRAPHICS -# include "readdib.h" -#endif /* * Hack -- Fake declarations from "dos.h" XXX XXX XXX @@ -447,39 +427,8 @@ static HWND hwndSaver; #endif /* USE_SAVER */ -#ifdef USE_GRAPHICS - -/* - * Flag set once "graphics" has been initialized - */ -static bool_ can_use_graphics = FALSE; - -/* - * The global bitmap - */ -static DIBINIT infGraph; - -/* - * The global bitmap mask - */ -static DIBINIT infMask; - -#endif /* USE_GRAPHICS */ - - -#ifdef USE_SOUND - -/* - * Flag set once "sound" has been initialized - */ -static bool_ can_use_sound = FALSE; -/* - * An array of sound file names - */ -static cptr sound_file[SOUND_MAX]; -#endif /* USE_SOUND */ /* @@ -502,7 +451,6 @@ static cptr AngList = "AngList"; */ static cptr ANGBAND_DIR_XTRA_FONT; static cptr ANGBAND_DIR_XTRA_GRAF; -static cptr ANGBAND_DIR_XTRA_SOUND; static cptr ANGBAND_DIR_XTRA_HELP; @@ -548,7 +496,6 @@ static BYTE win_pal[256] = static bool_ special_key[256]; static bool_ ignore_key[256]; -#if 1 /* * Hack -- initialization list for "special_key" */ @@ -574,88 +521,6 @@ static byte ignore_key_list[] = { VK_LSHIFT, VK_RSHIFT, VK_LCONTROL, VK_RCONTROL, VK_LMENU, VK_RMENU, 0 }; -#else -/* -* Hack -- initialization list for "special_key" -* -* We ignore the modifier keys (shift, control, alt, num lock, scroll lock), -* and the normal keys (escape, tab, return, letters, numbers, etc), but we -* catch the keypad keys (with and without numlock set, including keypad 5), -* the function keys (including the "menu" key which maps to F10), and the -* "pause" key (between scroll lock and numlock). We also catch a few odd -* keys which I do not recognize, but which are listed among keys which we -* do catch, so they should be harmless to catch. -*/ -static byte special_key_list[] = -{ - VK_CLEAR, /* 0x0C (KP<5>) */ - - VK_PAUSE, /* 0x13 (pause) */ - - VK_PRIOR, /* 0x21 (KP<9>) */ - VK_NEXT, /* 0x22 (KP<3>) */ - VK_END, /* 0x23 (KP<1>) */ - VK_HOME, /* 0x24 (KP<7>) */ - VK_LEFT, /* 0x25 (KP<4>) */ - VK_UP, /* 0x26 (KP<8>) */ - VK_RIGHT, /* 0x27 (KP<6>) */ - VK_DOWN, /* 0x28 (KP<2>) */ - VK_SELECT, /* 0x29 (?????) */ - VK_PRINT, /* 0x2A (?????) */ - VK_EXECUTE, /* 0x2B (?????) */ - VK_SNAPSHOT, /* 0x2C (?????) */ - VK_INSERT, /* 0x2D (KP<0>) */ - VK_DELETE, /* 0x2E (KP<.>) */ - VK_HELP, /* 0x2F (?????) */ - -#if 0 - VK_NUMPAD0, /* 0x60 (KP<0>) */ - VK_NUMPAD1, /* 0x61 (KP<1>) */ - VK_NUMPAD2, /* 0x62 (KP<2>) */ - VK_NUMPAD3, /* 0x63 (KP<3>) */ - VK_NUMPAD4, /* 0x64 (KP<4>) */ - VK_NUMPAD5, /* 0x65 (KP<5>) */ - VK_NUMPAD6, /* 0x66 (KP<6>) */ - VK_NUMPAD7, /* 0x67 (KP<7>) */ - VK_NUMPAD8, /* 0x68 (KP<8>) */ - VK_NUMPAD9, /* 0x69 (KP<9>) */ - VK_MULTIPLY, /* 0x6A (KP<*>) */ - VK_ADD, /* 0x6B (KP<+>) */ - VK_SEPARATOR, /* 0x6C (?????) */ - VK_SUBTRACT, /* 0x6D (KP<->) */ - VK_DECIMAL, /* 0x6E (KP<.>) */ - VK_DIVIDE, /* 0x6F (KP</>) */ -#endif - - VK_F1, /* 0x70 */ - VK_F2, /* 0x71 */ - VK_F3, /* 0x72 */ - VK_F4, /* 0x73 */ - VK_F5, /* 0x74 */ - VK_F6, /* 0x75 */ - VK_F7, /* 0x76 */ - VK_F8, /* 0x77 */ - VK_F9, /* 0x78 */ - VK_F10, /* 0x79 */ - VK_F11, /* 0x7A */ - VK_F12, /* 0x7B */ - VK_F13, /* 0x7C */ - VK_F14, /* 0x7D */ - VK_F15, /* 0x7E */ - VK_F16, /* 0x7F */ - VK_F17, /* 0x80 */ - VK_F18, /* 0x81 */ - VK_F19, /* 0x82 */ - VK_F20, /* 0x83 */ - VK_F21, /* 0x84 */ - VK_F22, /* 0x85 */ - VK_F23, /* 0x86 */ - VK_F24, /* 0x87 */ - - 0 -}; -#endif - /* * Hack -- given a pathname, point at the filename @@ -980,18 +845,6 @@ static void save_prefs(void) char buf[128]; - /* Save the "arg_graphics" flag */ - sprintf(buf, "%d", arg_graphics); - WritePrivateProfileString("Angband", "Graphics", buf, ini_file); - - /* Save the "arg_bigtile" flag */ - strcpy(buf, arg_bigtile ? "1" : "0"); - WritePrivateProfileString("Angband", "Bigtile", buf, ini_file); - - /* Save the "arg_sound" flag */ - strcpy(buf, arg_sound ? "1" : "0"); - WritePrivateProfileString("Angband", "Sound", buf, ini_file); - /* Save window prefs */ for (i = 0; i < MAX_TERM_DATA; ++i) { @@ -1023,7 +876,7 @@ static void load_prefs_aux(term_data *td, cptr sec_name) td->bizarre = (GetPrivateProfileInt(sec_name, "Bizarre", td->bizarre, ini_file) != 0); /* Analyze font, save desired font name */ - td->font_want = string_make(analyze_font(tmp, &wid, &hgt)); + td->font_want = strdup(analyze_font(tmp, &wid, &hgt)); /* Tile size */ td->tile_wid = GetPrivateProfileInt(sec_name, "TileWid", wid, ini_file); @@ -1048,16 +901,6 @@ static void load_prefs(void) char buf[1024]; - /* Extract the "arg_graphics" flag */ - arg_graphics = GetPrivateProfileInt("Angband", "Graphics", 0, ini_file); - - /* Extract the "arg_bigtile" flag */ - arg_bigtile = GetPrivateProfileInt("Angband", "Bigtile", FALSE, ini_file); - use_bigtile = arg_bigtile; - - /* Extract the "arg_sound" flag */ - arg_sound = (GetPrivateProfileInt("Angband", "Sound", 0, ini_file) != 0); - /* Load window prefs */ for (i = 0; i < MAX_TERM_DATA; ++i) { @@ -1108,37 +951,16 @@ static int new_palette(void) lppe = NULL; nEntries = 0; -#ifdef USE_GRAPHICS - - /* Check the bitmap palette */ - hBmPal = infGraph.hPalette; - - /* Use the bitmap */ - if (hBmPal) - { - lppeSize = 256 * sizeof(PALETTEENTRY); - lppe = (LPPALETTEENTRY)ralloc(lppeSize); - nEntries = GetPaletteEntries(hBmPal, 0, 255, lppe); - if ((nEntries == 0) || (nEntries > 220)) - { - /* Warn the user */ - plog_fmt("Unusable bitmap palette (%d entries)", nEntries); - - /* Cleanup */ - rnfree(lppe, lppeSize); - - /* Fail */ - return (FALSE); - } - } - -#endif /* Size of palette */ pLogPalSize = sizeof(LOGPALETTE) + (nEntries + 16) * sizeof(PALETTEENTRY); /* Allocate palette */ - pLogPal = (LPLOGPALETTE)ralloc(pLogPalSize); + pLogPal = (LPLOGPALETTE) calloc(1, pLogPalSize); + if (pLogPal == NULL) + { + abort(); + } /* Version */ pLogPal->palVersion = 0x300; @@ -1170,14 +992,19 @@ static int new_palette(void) } /* Free something */ - if (lppe) rnfree(lppe, lppeSize); + if (lppe) + { + free(lppe); + lppe = NULL; + } /* Create a new palette, or fail */ hNewPal = CreatePalette(pLogPal); if (!hNewPal) quit("Cannot create palette!"); /* Free the palette */ - rnfree(pLogPal, pLogPalSize); + free(pLogPal); + pLogPal = NULL; /* Main window */ td = &data[0]; @@ -1210,120 +1037,6 @@ static int new_palette(void) } -/* - * Initialize graphics - */ -static bool_ init_graphics() -{ - /* Initialize once */ - /*if (can_use_graphics != arg_graphics) */ - { - char buf[1024]; - int wid, hgt; - cptr name; - - /* Unused */ - PALETTEENTRY entry = - { - 0, 0, 0, 0 - }; - (void)entry; - - if (arg_graphics == 2) - { - wid = 16; - hgt = 16; - - name = "16X16.BMP"; - - ANGBAND_GRAF = "new"; - } - else - { - wid = 8; - hgt = 8; - - name = "8X8.BMP"; - ANGBAND_GRAF = "old"; - } - - /* Access the bitmap file */ - path_build(buf, 1024, ANGBAND_DIR_XTRA_GRAF, name); - - /* Load the bitmap or quit */ - if (!ReadDIB(data[0].w, buf, &infGraph)) - { - plog_fmt("Cannot read bitmap file '%s'", name); - return (FALSE); - } - - /* Save the new sizes */ - infGraph.CellWidth = wid; - infGraph.CellHeight = hgt; - - - path_build(buf, 1024, ANGBAND_DIR_XTRA_GRAF, "mask.bmp"); - /* Load the bitmap or quit */ - if (!ReadDIB(data[0].w, buf, &infMask)) - { - plog_fmt("Cannot read bitmap file '%s'", name); - return (FALSE); - } - - /* Activate a palette */ - if (!new_palette()) - { - /* Free bitmap XXX XXX XXX */ - - /* Oops */ - plog("Cannot activate palette!"); - return (FALSE); - } - - /* Graphics available */ - can_use_graphics = arg_graphics; - } - - /* Result */ - return (can_use_graphics); -} - - -/* - * Initialize sound - */ -static bool_ init_sound() -{ - /* Initialize once */ - if (!can_use_sound) - { - int i; - - char wav[128]; - char buf[1024]; - - /* Prepare the sounds */ - for (i = 1; i < SOUND_MAX; i++) - { - /* Extract name of sound file */ - sprintf(wav, "%s.wav", angband_sound_name[i]); - - /* Access the sound */ - path_build(buf, 1024, ANGBAND_DIR_XTRA_SOUND, wav); - - /* Save the sound filename, if it exists */ - if (check_file(buf)) sound_file[i] = string_make(buf); - } - - /* Sound available */ - can_use_sound = TRUE; - } - - /* Result */ - return (can_use_sound); -} - - /* * Resize a window @@ -1388,9 +1101,7 @@ static errr term_force_font(term_data *td, cptr path) if (!used) RemoveFontResource(td->font_file); /* Free the old name */ - string_free(td->font_file); - - /* Forget it */ + free(td->font_file); td->font_file = NULL; } @@ -1415,7 +1126,7 @@ static errr term_force_font(term_data *td, cptr path) if (!AddFontResource(buf)) return (1); /* Save new font name */ - td->font_file = string_make(base); + td->font_file = strdup(base); /* Remove the "suffix" */ base[strlen(base) - 4] = '\0'; @@ -1531,38 +1242,6 @@ static void term_data_redraw(term_data *td) /*** Function hooks needed by "Term" ***/ -#if 0 - -/* - * Initialize a new Term - */ -static void Term_init_win(term *t) -{ - /* XXX Unused */ -} - - -/* - * Nuke an old Term - */ -static void Term_nuke_win(term *t) -{ - /* XXX Unused */ -} - -#endif - - -/* - * Interact with the User - */ -static errr Term_user_win(int n) -{ - /* Success */ - return (0); -} - - /* * React to global changes */ @@ -1618,51 +1297,8 @@ static errr Term_xtra_win_react(void) } -#ifdef USE_SOUND - - /* Handle "arg_sound" */ - if (use_sound != arg_sound) - { - /* Initialize (if needed) */ - if (arg_sound && !init_sound()) - { - /* Warning */ - plog("Cannot initialize sound!"); - - /* Cannot enable */ - arg_sound = FALSE; - } - - /* Change setting */ - use_sound = arg_sound; - } - -#endif - - -#ifdef USE_GRAPHICS - - /* Handle "arg_graphics" */ - if (use_graphics != arg_graphics) - { - /* Initialize (if needed) */ - if (arg_graphics && !init_graphics()) - { - /* Warning */ - plog("Cannot initialize graphics!"); - - /* Cannot enable */ - arg_graphics = FALSE; - } - /* Change setting */ - use_graphics = arg_graphics; - /* Reset visuals */ - reset_visuals(); - } - -#endif /* USE_GRAPHICS */ /* Clean up windows */ @@ -1789,41 +1425,6 @@ static errr Term_xtra_win_noise(void) /* - * Hack -- make a sound - */ -static errr Term_xtra_win_sound(int v) -{ - /* Sound disabled */ - if (!use_sound) return (1); - - /* Illegal sound */ - if ((v < 0) || (v >= SOUND_MAX)) return (1); - - /* Unknown sound */ - if (!sound_file[v]) return (1); - -#ifdef USE_SOUND - -#ifdef WIN32 - - /* Play the sound, catch errors */ - return (PlaySound(sound_file[v], 0, SND_FILENAME | SND_ASYNC)); - -#else /* WIN32 */ - -/* Play the sound, catch errors */ - return (sndPlaySound(sound_file[v], SND_ASYNC)); - -#endif /* WIN32 */ - -#endif /* USE_SOUND */ - - /* Oops */ - return (1); -} - - -/* * Delay for "x" milliseconds */ static int Term_xtra_win_delay(int v) @@ -1881,12 +1482,6 @@ static errr Term_xtra_win(int n, int v) return (Term_xtra_win_noise()); } - /* Make a special sound */ - case TERM_XTRA_SOUND: - { - return (Term_xtra_win_sound(v)); - } - /* Process random events */ case TERM_XTRA_BORED: { @@ -1923,40 +1518,6 @@ static errr Term_xtra_win(int n, int v) return (Term_xtra_win_delay(v)); } - /* Get the current time in milliseconds */ - case TERM_XTRA_GET_DELAY: - { - DWORD t; - - t = GetTickCount(); - Term_xtra_long = t; - return 0; - } - - /* - * Scans for subdirectories in a directory "scansubdir_dir" - * and place teh result in "scansubdir_result/scansubdir_max" - */ - case TERM_XTRA_SCANSUBDIR: - { - BOOL ok; - HANDLE h; - WIN32_FIND_DATA fd; - for (h = FindFirstFile(format("%s\\*", scansubdir_dir), &fd), ok = 1; - h != INVALID_HANDLE_VALUE && ok; - ok = FindNextFile(h, &fd)) - { - if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (strcmp(fd.cFileName, ".")) && (strcmp(fd.cFileName, ".."))) - { - string_free(scansubdir_result[scansubdir_max]); - scansubdir_result[scansubdir_max] = string_make(fd.cFileName); - scansubdir_max++; - } - } - - return 0; - } - /* Rename main window */ case TERM_XTRA_RENAME_MAIN_WIN: SetWindowText(get_main_hwnd(), angband_term_name[0]); return (0); @@ -1986,9 +1547,6 @@ static errr Term_curs_win(int x, int y) rc.top = y * td->tile_hgt + td->size_oh1; rc.bottom = rc.top + td->tile_hgt; - if (use_bigtile && x + 1 < Term->wid && Term->old->a[y][x + 1] == 255) - rc.right += td->tile_wid; - /* Cursor is done as a yellow "box" */ hdc = GetDC(data[0].w); FrameRect(hdc, &rc, hbrYellow); @@ -2000,34 +1558,6 @@ static errr Term_curs_win(int x, int y) /* - * Low level graphics (Assumes valid input). - * - * Erase a "block" of "n" characters starting at (x,y). - */ -static errr Term_wipe_win(int x, int y, int n) -{ - term_data *td = (term_data*)(Term->data); - - HDC hdc; - RECT rc; - - /* Rectangle to erase in client coords */ - rc.left = x * td->tile_wid + td->size_ow1; - rc.right = rc.left + n * td->tile_wid; - rc.top = y * td->tile_hgt + td->size_oh1; - rc.bottom = rc.top + td->tile_hgt; - - hdc = GetDC(td->w); - SetBkColor(hdc, RGB(0, 0, 0)); - SelectObject(hdc, td->font_id); - ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL); - ReleaseDC(td->w, hdc); - - /* Success */ - return 0; -} - -/* * Low level graphics. Assumes valid input. * * Draw several ("n") chars, with an attr, at a given location. @@ -2119,197 +1649,6 @@ static errr Term_text_win(int x, int y, int n, byte a, const char *s) } -/* - * Low level graphics. Assumes valid input. - * - * Draw an array of "special" attr/char pairs at the given location. - * - * We use the "Term_pict_win()" function for "graphic" data, which are - * encoded by setting the "high-bits" of both the "attr" and the "char" - * data. We use the "attr" to represent the "row" of the main bitmap, - * and the "char" to represent the "col" of the main bitmap. The use - * of this function is induced by the "higher_pict" flag. - * - * If "graphics" is not available, we simply "wipe" the given grids. - */ -static errr Term_pict_win(int x, int y, int n, const byte *ap, const char *cp, const byte *tap, const char *tcp, const byte *eap, const char *ecp) -{ - term_data *td = (term_data*)(Term->data); - -#ifdef USE_GRAPHICS - - int i; - int x1, y1, w1, h1; - int x2, y2, w2, h2, tw2; - - int x3, y3; - - HDC hdcMask = NULL; - - int x4, y4; - - HDC hdc; - HDC hdcSrc; - HBITMAP hbmSrcOld; - - /* Paranoia */ - if (!use_graphics) - { - /* Erase the grids */ - return (Term_wipe_win(x, y, n)); - } - - /* Size of bitmap cell */ - w1 = infGraph.CellWidth; - h1 = infGraph.CellHeight; - - /* Size of window cell */ - w2 = td->tile_wid; - h2 = td->tile_hgt; - tw2 = w2; - - /* big tile mode */ - if (use_bigtile) tw2 *= 2; - - /* Location of window cell */ - x2 = x * w2 + td->size_ow1; - y2 = y * h2 + td->size_oh1; - - /* Info */ - hdc = GetDC(td->w); - - /* More info */ - hdcSrc = CreateCompatibleDC(hdc); - hbmSrcOld = SelectObject(hdcSrc, infGraph.hBitmap); - - if (arg_graphics == 2) - { - hdcMask = CreateCompatibleDC(hdc); - SelectObject(hdcMask, infMask.hBitmap); - } - - /* Draw attr/char pairs */ - for (i = 0; i < n; i++, x2 += w2) - { - byte a = ap[i]; - char c = cp[i]; - - /* Extract picture */ - int row = (a & 0x7F); - int col = (c & 0x7F); - - /* Location of bitmap cell */ - x1 = col * w1; - y1 = row * h1; - - if (arg_graphics == 2) - { - x3 = (tcp[i] & 0x7F) * w1; - y3 = (tap[i] & 0x7F) * h1; - - /* Perfect size */ - if ((w1 == tw2) && (h1 == h2)) - { - /* Copy the terrain picture from the bitmap to the window */ - BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, SRCCOPY); - - /* Mask out the tile */ - BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, SRCAND); - - /* Draw the tile */ - BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCPAINT); - - if (ecp[i] != 0 && eap[i] != 0) - { - x4 = (ecp[i] & 0x7F) * w1; - y4 = (eap[i] & 0x7F) * h1; - - /* Mask out the tile */ - BitBlt(hdc, x2, y2, tw2, h2, hdcMask, x4, y4, SRCAND); - - /* Draw the tile */ - BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x4, y4, SRCPAINT); - } - } - - /* Need to stretch */ - else - { - /* Set the correct mode for stretching the tiles */ - SetStretchBltMode(hdc, COLORONCOLOR); - - /* Copy the terrain picture from the bitmap to the window */ - StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x3, y3, w1, h1, SRCCOPY); - - /* Only draw if terrain and overlay are different */ - if ((x1 != x3) || (y1 != y3)) - { - /* Mask out the tile */ - StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x1, y1, w1, h1, SRCAND); - - /* Draw the tile */ - StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCPAINT); - } - - if (ecp[i] != 0 && eap[i] != 0) - { - x4 = (ecp[i] & 0x7F) * w1; - y4 = (eap[i] & 0x7F) * h1; - - /* Mask out the tile */ - StretchBlt(hdc, x2, y2, tw2, h2, hdcMask, x4, y4, w1, h1, SRCAND); - - /* Draw the tile */ - StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x4, y4, w1, h1, SRCPAINT); - } - } - } - else - { - /* Perfect size */ - if ((w1 == tw2) && (h1 == h2)) - { - /* Copy the picture from the bitmap to the window */ - BitBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, SRCCOPY); - } - - /* Need to stretch */ - else - { - /* Set the correct mode for stretching the tiles */ - SetStretchBltMode(hdc, COLORONCOLOR); - - /* Copy the picture from the bitmap to the window */ - StretchBlt(hdc, x2, y2, tw2, h2, hdcSrc, x1, y1, w1, h1, SRCCOPY); - } - } - } - - /* Release */ - SelectObject(hdcSrc, hbmSrcOld); - DeleteDC(hdcSrc); - - if (arg_graphics == 2) - { - /* Release */ - SelectObject(hdcMask, hbmSrcOld); - DeleteDC(hdcMask); - } - - /* Release */ - ReleaseDC(td->w, hdc); - -#else /* USE_GRAPHICS */ - - /* Just erase this grid */ - return (Term_wipe_win(x, y, n)); - -#endif /* USE_GRAPHICS */ - - /* Success */ - return 0; -} - /*** Other routines ***/ @@ -2327,26 +1666,10 @@ static void term_data_link(term_data *td) /* Use a "software" cursor */ t->soft_cursor = TRUE; - /* Use "Term_pict" for "graphic" data */ - t->higher_pict = TRUE; - - /* Erase with "white space" */ - t->attr_blank = TERM_WHITE; - t->char_blank = ' '; - -#if 0 - /* Prepare the init/nuke hooks */ - t->init_hook = Term_init_win; - t->nuke_hook = Term_nuke_win; -#endif - /* Prepare the template hooks */ - t->user_hook = Term_user_win; t->xtra_hook = Term_xtra_win; t->curs_hook = Term_curs_win; - t->wipe_hook = Term_wipe_win; t->text_hook = Term_text_win; - t->pict_hook = Term_pict_win; /* Remember where we came from */ t->data = (vptr)(td); @@ -2373,7 +1696,7 @@ static void init_windows(void) /* Main window */ td = &data[0]; - WIPE(td, term_data); + memset(td, 0, sizeof(term_data)); td->s = angband_term_name[0]; td->keys = 1024; td->rows = 24; @@ -2390,7 +1713,7 @@ static void init_windows(void) for (i = 1; i < MAX_TERM_DATA; i++) { td = &data[i]; - WIPE(td, term_data); + memset(td, 0, sizeof(term_data)); td->s = angband_term_name[i]; td->keys = 16; td->rows = 24; @@ -2548,13 +1871,8 @@ static void setup_menus(void) MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); EnableMenuItem(hm, IDM_FILE_SAVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); -#ifdef ALLOW_QUITTING - EnableMenuItem(hm, IDM_FILE_ABORT, - MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); -#else EnableMenuItem(hm, IDM_FILE_SCORE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); -#endif /* ALLOW_QUITTING */ EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); @@ -2578,14 +1896,6 @@ static void setup_menus(void) MF_BYCOMMAND | MF_ENABLED); } -#ifdef ALLOW_QUITTING - - /* Menu "File", Item "Abort" */ - EnableMenuItem(hm, IDM_FILE_ABORT, - MF_BYCOMMAND | MF_ENABLED); - -#else - /* Menu "File", Item "Score" */ if (initialized && character_generated && !character_icky) { @@ -2593,8 +1903,6 @@ static void setup_menus(void) MF_BYCOMMAND | MF_ENABLED); } -#endif - /* Menu "File", Item "Exit" */ EnableMenuItem(hm, IDM_FILE_EXIT, MF_BYCOMMAND | MF_ENABLED); @@ -2700,52 +2008,18 @@ static void setup_menus(void) } /* Menu "Options", disable all */ - EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, - MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); - EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, - MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); - EnableMenuItem(hm, IDM_OPTIONS_ASCII_GRAPHICS, - MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); - EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, - MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); - EnableMenuItem(hm, IDM_OPTIONS_SOUND, - MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); EnableMenuItem(hm, IDM_OPTIONS_UNUSED, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); EnableMenuItem(hm, IDM_OPTIONS_SAVER, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); /* Menu "Options", update all */ - CheckMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, - (arg_graphics == 1 ? MF_CHECKED : MF_UNCHECKED)); - CheckMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, - (arg_graphics == 2 ? MF_CHECKED : MF_UNCHECKED)); - CheckMenuItem(hm, IDM_OPTIONS_ASCII_GRAPHICS, - (arg_graphics == 0 ? MF_CHECKED : MF_UNCHECKED)); - CheckMenuItem(hm, IDM_OPTIONS_BIGTILE, - (arg_bigtile ? MF_CHECKED : MF_UNCHECKED)); - CheckMenuItem(hm, IDM_OPTIONS_SOUND, - (arg_sound ? MF_CHECKED : MF_UNCHECKED)); CheckMenuItem(hm, IDM_OPTIONS_UNUSED, (0 ? MF_CHECKED : MF_UNCHECKED)); CheckMenuItem(hm, IDM_OPTIONS_SAVER, (hwndSaver ? MF_CHECKED : MF_UNCHECKED)); -#ifdef USE_GRAPHICS - /* Menu "Options", Item "Graphics" */ - EnableMenuItem(hm, IDM_OPTIONS_OLD_GRAPHICS, MF_ENABLED); - /* Menu "Options", Item "Graphics" */ - EnableMenuItem(hm, IDM_OPTIONS_NEW_GRAPHICS, MF_ENABLED); - /* Menu "Options", Item "Graphics" */ - EnableMenuItem(hm, IDM_OPTIONS_ASCII_GRAPHICS, MF_ENABLED); - /* Menu "Options", Item "Graphics" */ - EnableMenuItem(hm, IDM_OPTIONS_BIGTILE, MF_ENABLED); -#endif -#ifdef USE_SOUND - /* Menu "Options", Item "Sound" */ - EnableMenuItem(hm, IDM_OPTIONS_SOUND, MF_ENABLED); -#endif #ifdef USE_SAVER /* Menu "Options", Item "ScreenSaver" */ @@ -2789,7 +2063,7 @@ static void check_for_save_file(LPSTR cmd_line) game_in_progress = TRUE; /* Play game */ - play_game(FALSE); + play_game(); } @@ -2822,7 +2096,7 @@ static void process_menus(WORD wCmd) { game_in_progress = TRUE; Term_flush(); - play_game(TRUE); + play_game(); quit(NULL); } break; @@ -2861,7 +2135,7 @@ ofn.lStructSize = sizeof(OPENFILENAME); validate_file(savefile); game_in_progress = TRUE; Term_flush(); - play_game(FALSE); + play_game(); quit(NULL); } } @@ -2915,102 +2189,15 @@ ofn.lStructSize = sizeof(OPENFILENAME); break; } -#ifdef ALLOW_QUITTING - - /* Abort */ - case IDM_FILE_ABORT: - { - if (game_in_progress && character_generated) - { - /* XXX XXX XXX */ - if (MessageBox(data[0].w, - "Your character will be not saved!", "Warning", - MB_ICONEXCLAMATION | MB_OKCANCEL) == IDCANCEL) - { - break; - } - } - quit(NULL); - break; - } - -#else - /* Score */ case IDM_FILE_SCORE: { - char buf[1024]; - - /* Paranoia */ - if (!initialized || character_icky || - !game_in_progress || !character_generated) - { - /* Can't happen but just in case */ - plog("You may not do that right now."); - - break; - } - - /* Build the pathname of the score file */ - path_build(buf, sizeof(buf), ANGBAND_DIR_APEX, "scores.raw"); - - /* Hack - open the score file for reading */ - highscore_fd = fd_open(buf, O_RDONLY); - - /* Paranoia - No score file */ - if (highscore_fd < 0) - { - msg_print("Score file is not available."); - - break; - } - - /* Mega-Hack - prevent various functions XXX XXX XXX */ - initialized = FALSE; - - /* Save screen */ - screen_save(); - - /* Clear screen */ - Term_clear(); - - /* Prepare scores */ - if (game_in_progress && character_generated) - { - predict_score(); - } - -#if 0 /* I don't like this - pelpel */ - - /* Mega-Hack - No current player XXX XXX XXX XXX */ - else - { - display_scores_aux(0, MAX_HISCORES, -1, NULL); - } - -#endif - - /* Close the high score file */ - (void)fd_close(highscore_fd); - - /* Forget the fd */ - highscore_fd = -1; - - /* Restore screen */ - screen_load(); - - /* Hack - Flush it */ - Term_fresh(); - - /* Mega-Hack - We are ready again */ - initialized = TRUE; + predict_score_gui(&initialized, &game_in_progress); /* Done */ break; } -#endif - case IDM_WINDOW_VIS_0: { plog("You are not allowed to do that!"); @@ -3194,114 +2381,6 @@ ofn.lStructSize = sizeof(OPENFILENAME); break; } - case IDM_OPTIONS_OLD_GRAPHICS: - { - /* Paranoia */ - if (!inkey_flag) - { - plog("You may not do that right now."); - break; - } - - /* Set "arg_graphics" */ - arg_graphics = 1; - - /* React to changes */ - Term_xtra_win_react(); - - /* Hack -- Force redraw */ - Term_key_push(KTRL('R')); - - break; - } - - case IDM_OPTIONS_NEW_GRAPHICS: - { - /* Paranoia */ - if (!inkey_flag) - { - plog("You may not do that right now."); - break; - } - - /* Set "arg_graphics" */ - arg_graphics = 2; - - /* React to changes */ - Term_xtra_win_react(); - - /* Hack -- Force redraw */ - Term_key_push(KTRL('R')); - - break; - } - case IDM_OPTIONS_ASCII_GRAPHICS: - { - /* Paranoia */ - if (!inkey_flag) - { - plog("You may not do that right now."); - break; - } - - /* Set "ASCII Graphics" */ - arg_graphics = 0; - /* React to Changes */ - Term_xtra_win_react(); - - /* Hack -- Force redraw */ - Term_key_push(KTRL('R')); - - break; - } - - case IDM_OPTIONS_BIGTILE: - { - term_data *td = &data[0]; - - /* Paranoia */ - if (!inkey_flag) - { - plog("You may not do that right now."); - break; - } - - /* Toggle "arg_sound" */ - arg_bigtile = !arg_bigtile; - - /* Activate */ - Term_activate(&td->t); - - /* Resize the term */ - Term_resize(td->cols, td->rows); - - /* Redraw later */ - InvalidateRect(td->w, NULL, TRUE); - - break; - } - - case IDM_OPTIONS_SOUND: - { - /* Paranoia */ - if (!inkey_flag) - { - plog("You may not do that right now."); - break; - } - - /* Toggle "arg_sound" */ - arg_sound = !arg_sound; - - /* React to changes */ - Term_xtra_win_react(); - - /* Hack -- Force redraw */ - Term_key_push(KTRL('R')); - - break; - } - case IDM_OPTIONS_UNUSED: { /* Unused for now XXX XXX XXX */ @@ -3343,55 +2422,12 @@ ofn.lStructSize = sizeof(OPENFILENAME); #endif - case IDM_HELP_GENERAL: - { - char buf[1024]; - char tmp[1024]; - path_build(tmp, 1024, ANGBAND_DIR_XTRA_HELP, "angband.hlp"); - if (check_file(tmp)) - { - sprintf(buf, "winhelp.exe %s", tmp); - WinExec(buf, SW_NORMAL); - } - else - { - plog_fmt("Cannot find help file: %s", tmp); - plog("Use the online help files instead."); - } - break; - } - - case IDM_HELP_SPOILERS: - { - char buf[1024]; - char tmp[1024]; - path_build(tmp, 1024, ANGBAND_DIR_XTRA_HELP, "spoilers.hlp"); - if (check_file(tmp)) - { - sprintf(buf, "winhelp.exe %s", tmp); - WinExec(buf, SW_NORMAL); - } - else - { - plog_fmt("Cannot find help file: %s", tmp); - plog("Use the online help files instead."); - } - break; - } - } } -#ifdef __MWERKS__ -LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, - WPARAM wParam, LPARAM lParam); -LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, - WPARAM wParam, LPARAM lParam) -#else /* __MWERKS__ */ LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -#endif /* __MWERKS__ */ { PAINTSTRUCT ps; HDC hdc; @@ -3671,15 +2707,8 @@ LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, } -#ifdef __MWERKS__ -LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg, - WPARAM wParam, LPARAM lParam); LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -#else /* __MWERKS__ */ -LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg, - WPARAM wParam, LPARAM lParam) -#endif /* __MWERKS__ */ { term_data *td; MINMAXINFO FAR *lpmmi; @@ -3883,15 +2912,8 @@ LRESULT FAR PASCAL AngbandListProc(HWND hWnd, UINT uMsg, #define MOUSE_SENS 40 -#ifdef __MWERKS__ -LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg, - WPARAM wParam, LPARAM lParam); -LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg, - WPARAM wParam, LPARAM lParam) -#else /* __MWERKS__ */ LRESULT FAR PASCAL AngbandSaverProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) -#endif /* __MWERKS__ */ { static int iMouse = 0; static WORD xMouse = 0; @@ -3915,15 +2937,6 @@ WPARAM wParam, LPARAM lParam) return 0; } -#if 0 - case WM_ACTIVATE: - { - if (LOWORD(wParam) == WA_INACTIVE) break; - - /* else fall through */ - } -#endif - case WM_LBUTTONDOWN: case WM_MBUTTONDOWN: case WM_RBUTTONDOWN: @@ -4059,7 +3072,11 @@ static void hook_quit(cptr str) for (i = MAX_TERM_DATA - 1; i >= 0; --i) { term_force_font(&data[i], NULL); - if (data[i].font_want) string_free(data[i].font_want); + if (data[i].font_want) + { + free(data[i].font_want); + data[i].font_want = NULL; + } if (data[i].w) DestroyWindow(data[i].w); data[i].w = 0; } @@ -4098,7 +3115,7 @@ static void init_stuff(void) strcpy(path + strlen(path) - 4, ".INI"); /* Save the the name of the ini-file */ - ini_file = string_make(path); + ini_file = strdup(path); /* Validate the ini-file */ validate_file(ini_file); @@ -4131,12 +3148,11 @@ static void init_stuff(void) path_build(path, 1024, ANGBAND_DIR_XTRA, "font"); /* Allocate the path */ - ANGBAND_DIR_XTRA_FONT = string_make(path); + ANGBAND_DIR_XTRA_FONT = strdup(path); /*** Validate the paths to ensure we have a working install ***/ - validate_dir(ANGBAND_DIR_APEX); validate_dir(ANGBAND_DIR_DATA); validate_dir(ANGBAND_DIR_EDIT); validate_dir(ANGBAND_DIR_FILE); @@ -4157,45 +3173,15 @@ static void init_stuff(void) validate_file(path); -#ifdef USE_GRAPHICS - - /* Build the "graf" path */ - path_build(path, 1024, ANGBAND_DIR_XTRA, "graf"); - /* Allocate the path */ - ANGBAND_DIR_XTRA_GRAF = string_make(path); - /* Validate the "graf" directory */ - validate_dir(ANGBAND_DIR_XTRA_GRAF); - - /* Build the filename */ - path_build(path, 1024, ANGBAND_DIR_XTRA_GRAF, "8X8.BMP"); - - /* Hack -- Validate the basic graf */ - validate_file(path); - -#endif - - -#ifdef USE_SOUND - - /* Build the "sound" path */ - path_build(path, 1024, ANGBAND_DIR_XTRA, "sound"); - - /* Allocate the path */ - ANGBAND_DIR_XTRA_SOUND = string_make(path); - - /* Validate the "sound" directory */ - validate_dir(ANGBAND_DIR_XTRA_SOUND); - -#endif /* Build the "help" path */ path_build(path, 1024, ANGBAND_DIR_XTRA, "help"); /* Allocate the path */ - ANGBAND_DIR_XTRA_HELP = string_make(path); + ANGBAND_DIR_XTRA_HELP = strdup(path); /* Validate the "help" directory */ /* validate_dir(ANGBAND_DIR_XTRA_HELP); */ @@ -4252,7 +3238,6 @@ int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, /* Temporary hooks */ plog_aux = hack_plog; quit_aux = hack_quit; - core_aux = hack_quit; /* Prepare the filepaths */ init_stuff(); @@ -4338,7 +3323,7 @@ int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, check_for_save_file(lpCmdLine); game_in_progress = TRUE; - play_game(FALSE); + play_game(); /* Prompt the user */ Term_fresh(); @@ -4361,8 +3346,3 @@ int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, /* Paranoia */ return (0); } - - -#endif /* WINDOWS */ - - |