/*! \brief Delete game * * You guessed it... delete the game. */ static void delete_game (void) { int a, stop = 0; int pointer_offset = (save_ptr - top_pointer) * 48; sprintf (strbuf, "sg%d.sav", save_ptr); a = remove (kqres (SAVE_DIR, strbuf)); if (a == 0) { menubox (double_buffer, 128, pointer_offset + 12, 12, 1, DARKBLUE); print_font (double_buffer, 136, pointer_offset + 20, _("File Deleted"), FNORMAL); snc[save_ptr] = 0; sgp[save_ptr] = 0; shr[save_ptr] = 0; smin[save_ptr] = 0; for (a = 0; a < PSIZE; a++) { sid[save_ptr][a] = 0; shp[save_ptr][a] = 0; smp[save_ptr][a] = 0; slv[save_ptr][a] = 0; } } else { menubox (double_buffer, 128, pointer_offset + 12, 16, 1, DARKBLUE); print_font (double_buffer, 136, pointer_offset + 20, _("File Not Deleted"), FNORMAL); } blit2screen (0, 0); blit (back, double_buffer, 0, 0, 0, 0, 352, 280); while (!stop) { readcontrols (); if (balt || bctrl) { unpress (); stop = 1; } kq_yield (); } }
/*! \brief Load game * * Uh-huh. * PH 20030805 Made endian-safe * PH 20030914 Now ignores keyboard settings etc in the save file * \returns 1 if load succeeded, 0 otherwise */ static int load_game (void) { PACKFILE *sdat; int a; unsigned char tv; sprintf (strbuf, "sg%d.sav", save_ptr); sdat = pack_fopen (kqres (SAVE_DIR, strbuf), F_READ_PACKED); if (!sdat) { message (_("Could not load saved game."), 255, 0, 0, 0); return 0; } tv = pack_getc (sdat); if (tv == 92) a = load_game_92(sdat); else if (tv == 91) a = load_game_91(sdat); else { a = 0; message (_("Saved game format is not current."), 255, 0, 0, 0); } pack_fclose (sdat); if (!a) return 0; timer_count = 0; ksec = 0; hold_fade = 0; change_map (curmap, g_ent[0].tilex, g_ent[0].tiley, g_ent[0].tilex, g_ent[0].tiley); /* Set music and sound volume */ set_volume (gsvol, -1); set_music_volume (((float) gmvol) / 255.0); return 1; }
/*! \brief Save game 92 * * Save the game, using KQ Save Game Format 92 (Beta) * Author: Winter Knight * * \returns 0 if save failed, 1 if success */ static int save_game_92 (void) { size_t a, b, c, d; PACKFILE *sdat; for (b = 0; b < PSIZE; b++) { sid[save_ptr][b] = 0; shp[save_ptr][b] = 0; smp[save_ptr][b] = 0; slv[save_ptr][b] = 0; } for (b = 0; b < numchrs; b++) { sid[save_ptr][b] = pidx[b]; shp[save_ptr][b] = party[pidx[b]].hp * 100 / party[pidx[b]].mhp; if (party[pidx[b]].mmp > 0) smp[save_ptr][b] = party[pidx[b]].mp * 100 / party[pidx[b]].mmp; slv[save_ptr][b] = party[pidx[b]].lvl; } snc[save_ptr] = numchrs; sgp[save_ptr] = gp; smin[save_ptr] = kmin; shr[save_ptr] = khr; sprintf (strbuf, "sg%d.sav", save_ptr); sdat = pack_fopen (kqres (SAVE_DIR, strbuf), F_WRITE_PACKED); if (!sdat) { message (_("Could not save game data."), 255, 0, 0, 0); return 0; } pack_putc (kq_version, sdat); pack_iputl (gp, sdat); pack_iputw (shr[save_ptr], sdat); pack_iputw (smin[save_ptr], sdat); /* Save number of, and which characters are in the party */ pack_iputw (numchrs, sdat); for (a = 0; a < numchrs; a++) { pack_iputw (pidx[a], sdat); } /* Save number of, and data on all characters in game */ pack_iputw (MAXCHRS, sdat); for (a = 0; a < MAXCHRS; a++) { save_s_player (&party[a], sdat); } /* Save map name and location */ pack_iputw (strlen (curmap), sdat); pack_fwrite (curmap, strlen (curmap), sdat); pack_iputw (g_ent[0].tilex, sdat); pack_iputw (g_ent[0].tiley, sdat); /* Save quest info */ for (a = sizeof (progress); a > 0; a--) { if (progress[a - 1] > 0) break; } pack_iputw (a, sdat); for (b = 0; b < a; b++) pack_putc (progress[b], sdat); /* Save treasure info */ for (a = sizeof (treasure); a > 0; a--) { if (treasure[a - 1] > 0) break; } pack_iputw (a, sdat); for (b = 0; b < a; b++) pack_putc (treasure[b], sdat); /* Save spell info (P_REPULSE is 48) */ pack_iputw (sizeof (save_spells), sdat); for (a = 0; a < sizeof (save_spells); a++) { /* sizeof(save_spells) is 50 */ pack_putc (save_spells[a], sdat); } /* Save player inventory */ pack_iputw (MAX_INV, sdat); for (a = 0; a < MAX_INV; a++) { pack_iputw (g_inv[a][0], sdat); pack_iputw (g_inv[a][1], sdat); } /* Save special items */ for (a = MAX_SPECIAL_ITEMS + 1; a > 0; a--) { if (player_special_items[a - 1]) break; } pack_iputw (a, sdat); for (b = 0; b < a; b++) { pack_putc (player_special_items[b], sdat); } /* Save shop info (last visit time and number of items) */ /* Find last index of shop that the player has visited. */ for (a = num_shops; a > 0; a--) { if (shop_time[a - 1] > 0) break; } pack_iputw (a, sdat); for (b = 0; b < a; b++) { pack_iputw (shop_time[b], sdat); /* Find last valid (non-zero) shop item for this shop */ for (c = SHOPITEMS; c > 0; c--) if (shops[b].items[c - 1] > 0) break; pack_iputw (c, sdat); for (d = 0; d < c; d++) pack_iputw (shops[b].items_current[d], sdat); } pack_fclose (sdat); return 1; }
/*! \brief Save game * * You guessed it... save the game. * * \returns 0 if save failed, 1 if success */ static int save_game (void) { PACKFILE *sdat; size_t a, b; return save_game_92 (); /* Rest of this function is no longer used */ for (b = 0; b < PSIZE; b++) { sid[save_ptr][b] = 0; shp[save_ptr][b] = 0; smp[save_ptr][b] = 0; slv[save_ptr][b] = 0; } for (b = 0; b < numchrs; b++) { sid[save_ptr][b] = pidx[b]; shp[save_ptr][b] = party[pidx[b]].hp * 100 / party[pidx[b]].mhp; if (party[pidx[b]].mmp > 0) smp[save_ptr][b] = party[pidx[b]].mp * 100 / party[pidx[b]].mmp; slv[save_ptr][b] = party[pidx[b]].lvl; } snc[save_ptr] = numchrs; sgp[save_ptr] = gp; smin[save_ptr] = kmin; shr[save_ptr] = khr; sprintf (strbuf, "sg%d.sav", save_ptr); sdat = pack_fopen (kqres (SAVE_DIR, strbuf), F_WRITE_PACKED); if (!sdat) { message (_("Could not save game data."), 255, 0, 0, 0); return 0; } pack_putc (kq_version, sdat); pack_iputl (numchrs, sdat); pack_iputl (gp, sdat); pack_iputl (shr[save_ptr], sdat); pack_iputl (smin[save_ptr], sdat); for (a = 0; a < PSIZE; a++) { pack_iputl (pidx[a], sdat); } for (a = 0; a < MAXCHRS; a++) { save_s_player (&party[a], sdat); } pack_fwrite (curmap, 16, sdat); for (a = 0; a < sizeof (progress); a++) { /* sizeof(progress) is 1750 */ pack_putc (progress[a], sdat); } for (a = 0; a < NUMSHOPS; a++) { /* NUMSHOPS is 50 */ pack_putc (shop_time[a], sdat); } for (a = 0; a < SIZE_SAVE_RESERVE1; a++) { /* SAVE_RESERVE_SIZE1 is 150 */ pack_putc (0, sdat); } for (a = 0; a < sizeof (save_spells); a++) { /* sizeof(save_spells) is 50 */ pack_putc (save_spells[a], sdat); } for (a = 0; a < sizeof (treasure); a++) { /* sizeof(treasure) is 1000 */ pack_putc (treasure[a], sdat); } for (a = 0; a < NUMSHOPS; a++) { for (b = 0; b < SHOPITEMS; b++) { pack_iputw (shops[a].items_current[b], sdat); } } for (a = 0; a < MAX_INV; a++) { pack_iputw (g_inv[a][0], sdat); pack_iputw (g_inv[a][1], sdat); } /* PH FIXME: do we _really_ want things like controls and screen */ /* mode to be saved/loaded ? */ /* WK: No. */ pack_iputl (gsvol, sdat); pack_iputl (gmvol, sdat); pack_putc (windowed, sdat); pack_putc (stretch_view, sdat); pack_putc (wait_retrace, sdat); pack_iputl (kup, sdat); pack_iputl (kdown, sdat); pack_iputl (kleft, sdat); pack_iputl (kright, sdat); pack_iputl (kalt, sdat); pack_iputl (kctrl, sdat); pack_iputl (kenter, sdat); pack_iputl (kesc, sdat); pack_iputl (jbalt, sdat); pack_iputl (jbctrl, sdat); pack_iputl (jbenter, sdat); pack_iputl (jbesc, sdat); /* End worthless */ pack_iputw (g_ent[0].tilex, sdat); pack_iputw (g_ent[0].tiley, sdat); pack_fclose (sdat); return 1; }
/*! \brief Load mini stats * * This loads the mini stats for each saved game. * These mini stats are just for displaying info about the save game on the * save/load game screen. */ void load_sgstats (void) { PACKFILE *ldat; int a, b, c; unsigned char vc; s_player tpm; for (a = 0; a < NUMSG; a++) { sprintf (strbuf, "sg%d.sav", a); ldat = pack_fopen (kqres (SAVE_DIR, strbuf), F_READ_PACKED); if (!ldat) { snc[a] = 0; sgp[a] = 0; shr[a] = 0; smin[a] = 0; for (b = 0; b < PSIZE; b++) { sid[a][b] = 0; shp[a][b] = 0; smp[a][b] = 0; } } else { vc = pack_getc (ldat); if (vc == 92) { sgp[a] = pack_igetl (ldat); shr[a] = pack_igetw (ldat); smin[a] = pack_igetw (ldat); snc[a] = pack_igetw (ldat); for (b = 0; b < snc[a]; b++) { sid[a][b] = pack_igetw (ldat); // sid[a][b] = 0; // Temp: Debugging / Testing } pack_igetw (ldat); // Number of characters in game. Assume MAXCHRS for (b = 0; b < MAXCHRS; b++) { load_s_player (&tpm, ldat); for (c = 0; c < snc[a]; c++) { if (b == sid[a][c]) { slv[a][c] = tpm.lvl; shp[a][c] = tpm.hp * 100 / tpm.mhp; if (tpm.mmp > 0) smp[a][c] = tpm.mp * 100 / tpm.mmp; else smp[a][c] = 0; } } } } else if (vc == 91) { snc[a] = pack_igetl (ldat); sgp[a] = pack_igetl (ldat); shr[a] = pack_igetl (ldat); smin[a] = pack_igetl (ldat); for (b = 0; b < PSIZE; b++) { sid[a][b] = pack_igetl (ldat); } for (b = 0; b < MAXCHRS; b++) { load_s_player (&tpm, ldat); for (c = 0; c < PSIZE; c++) { if (b == sid[a][c]) { slv[a][c] = tpm.lvl; shp[a][c] = tpm.hp * 100 / tpm.mhp; if (tpm.mmp > 0) smp[a][c] = tpm.mp * 100 / tpm.mmp; else smp[a][c] = 0; } } } } else snc[a] = -1; pack_fclose (ldat); } } }
/*! \brief Load all enemies from disk * * Loads up enemies from the *.mon files and fills the enemies[] array. * \author PH * \date 2003???? */ static void load_enemies (void) { int i, tmp, lx, ly, p; FILE *edat; s_fighter *f; if (enemies != NULL) { /* Already done the loading */ return; } enemy_pcx = load_datafile_object (PCX_DATAFILE, "ENEMY_PCX"); if (enemy_pcx == NULL) { program_death (_("Could not load enemy sprites from datafile!")); } edat = fopen (kqres (DATA_DIR, "allstat.mon"), "r"); if (!edat) program_death (_("Could not load 1st enemy datafile!")); enemies_n = 0; enemies_cap = 128; enemies = (s_fighter **) malloc (sizeof (s_fighter *) * enemies_cap); // Loop through for every monster in allstat.mon while (fscanf (edat, "%s", strbuf) != EOF) { if (enemies_n >= enemies_cap) { enemies_cap *= 2; enemies = (s_fighter **) realloc (enemies, sizeof (s_fighter *) * enemies_cap); } f = enemies[enemies_n++] = (s_fighter *) malloc (sizeof (s_fighter)); memset (f, 0, sizeof (s_fighter)); // Enemy name strncpy (f->name, strbuf, sizeof (f->name)); // Index number (ignored; automatically generated) fscanf (edat, "%d", &tmp); // x-coord of image in datafile fscanf (edat, "%d", &tmp); lx = tmp; // y-coord of image in datafile fscanf (edat, "%d", &tmp); ly = tmp; // Image width fscanf (edat, "%d", &tmp); f->cw = tmp; // Image length (height) fscanf (edat, "%d", &tmp); f->cl = tmp; // Experience points earned fscanf (edat, "%d", &tmp); f->xp = tmp; // Gold received fscanf (edat, "%d", &tmp); f->gp = tmp; // Level fscanf (edat, "%d", &tmp); f->lvl = tmp; // Max HP fscanf (edat, "%d", &tmp); f->mhp = tmp; // Max MP fscanf (edat, "%d", &tmp); f->mmp = tmp; // Defeat Item Probability: chance of finding any items after defeat fscanf (edat, "%d", &tmp); f->dip = tmp; // Defeat Item Common: item found commonly of the time fscanf (edat, "%d", &tmp); f->defeat_item_common = tmp; // Defeat Item Rare: item found rarely fscanf (edat, "%d", &tmp); f->defeat_item_rare = tmp; // Steal Item Common: item found commonly from stealing fscanf (edat, "%d", &tmp); f->steal_item_common = tmp; // Steal Item Rare: item found rarely when stealing fscanf (edat, "%d", &tmp); f->steal_item_rare = tmp; // Enemy's strength (agility & vitality set to zero) fscanf (edat, "%d", &tmp); f->stats[A_STR] = tmp; f->stats[A_AGI] = 0; f->stats[A_VIT] = 0; // Intelligence & Sagacity (both the same) fscanf (edat, "%d", &tmp); f->stats[A_INT] = tmp; f->stats[A_SAG] = tmp; // Defense against: Speed, Spirit, Attack, Hit, Defence, Evade, Magic (in that order) for (p = 5; p < 13; p++) { fscanf (edat, "%d", &tmp); f->stats[p] = tmp; } // Bonus fscanf (edat, "%d", &tmp); f->bonus = tmp; f->bstat = 0; // Current weapon type fscanf (edat, "%d", &tmp); f->cwt = tmp; // Weapon elemental type fscanf (edat, "%d", &tmp); f->welem = tmp; // Undead Level (defense against Undead attacks) fscanf (edat, "%d", &tmp); f->unl = tmp; // Critical attacks fscanf (edat, "%d", &tmp); f->crit = tmp; // Temp Sag & Int for Imbued fscanf (edat, "%d", &tmp); f->imb_s = tmp; // Imbued stat type (Spd, Spi, Att, Hit, Def, Evd, Mag) fscanf (edat, "%d", &tmp); f->imb_a = tmp; f->img = create_sub_bitmap ((BITMAP *) enemy_pcx->dat, lx, ly, f->cw, f->cl); for (p = 0; p < 2; p++) { fscanf (edat, "%d", &tmp); f->imb[p] = tmp; } } fclose (edat); edat = fopen (kqres (DATA_DIR, "resabil.mon"), "r"); if (!edat) program_death (_("Could not load 2nd enemy datafile!")); for (i = 0; i < enemies_n; i++) { f = enemies[i]; fscanf (edat, "%s", strbuf); fscanf (edat, "%d", &tmp); for (p = 0; p < R_TOTAL_RES; p++) { fscanf (edat, "%d", &tmp); f->res[p] = tmp; } for (p = 0; p < 8; p++) { fscanf (edat, "%d", &tmp); f->ai[p] = tmp; } for (p = 0; p < 8; p++) { fscanf (edat, "%d", &tmp); f->aip[p] = tmp; f->atrack[p] = 0; } f->hp = f->mhp; f->mp = f->mmp; for (p = 0; p < 24; p++) f->sts[p] = 0; f->aux = 0; f->mrp = 100; } fclose (edat); }
/*! \brief Display configuration menu * * This is the config menu that is called from the system * menu. Here you can adjust the music or sound volume, or * the speed that the battle gauge moves at. */ void config_menu (void) { int stop = 0, ptr = 0, p; int temp_key = 0; #ifdef DEBUGMODE #define MENU_SIZE 18 #else #define MENU_SIZE 17 #endif static const char *dc[MENU_SIZE]; /* Define rows with appropriate spacings for breaks between groups */ int row[MENU_SIZE]; for (p = 0; p < 4; p++) row[p] = (p + 4) * 8; // (p * 8) + 32 for (p = 4; p < 12; p++) row[p] = (p + 5) * 8; // (p * 8) + 40 for (p = 12; p < 15; p++) row[p] = (p + 6) * 8; // (p * 8) + 48 for (p = 15; p < MENU_SIZE; p++) row[p] = (p + 7) * 8; // (p * 8) + 56 /* Helper strings */ dc[0]=_("Display KQ in a window."); dc[1]=_("Stretch to fit 640x480 resolution."); dc[2]=_("Display the frame rate during play."); dc[3]=_("Wait for vertical retrace."); dc[4]=_("Key used to move up."); dc[5]=_("Key used to move down."); dc[6]=_("Key used to move left."); dc[7]=_("Key used to move right."); dc[8]=_("Key used to confirm action."); dc[9]=_("Key used to cancel action."); dc[10]=_("Key used to call character menu."); dc[11]=_("Key used to call system menu."); dc[12]=_("Toggle sound and music on/off."); dc[13]=_("Overall sound volume (affects music)."); dc[14]=_("Music volume."); dc[15]=_("Animation speed-ups for slow machines."); dc[16]=_("Toggle how to allocate CPU usage."); #ifdef DEBUGMODE dc[17]=_("Things you can do only in DebugMode."); #endif unpress (); push_config_state (); set_config_file (kqres (SETTINGS_DIR, "kq.cfg")); while (!stop) { check_animation (); drawmap (); menubox (double_buffer, 88 + xofs, yofs, 16, 1, BLUE); print_font (double_buffer, 96 + xofs, 8 + yofs, _("KQ Configuration"), FGOLD); menubox (double_buffer, 32 + xofs, 24 + yofs, 30, MENU_SIZE + 3, BLUE); citem (row[0], _("Windowed mode:"), windowed == 1 ? _("YES") : _("NO"), FNORMAL); citem (row[1], _("Stretch Display:"), stretch_view == 1 ? _("YES") : _("NO"), FNORMAL); citem (row[2], _("Show Frame Rate:"), show_frate == 1 ? _("YES") : _("NO"), FNORMAL); citem (row[3], _("Wait for Retrace:"), wait_retrace == 1 ? _("YES") : _("NO"), FNORMAL); citem (row[4], _("Up Key:"), kq_keyname (kup), FNORMAL); citem (row[5], _("Down Key:"), kq_keyname (kdown), FNORMAL); citem (row[6], _("Left Key:"), kq_keyname (kleft), FNORMAL); citem (row[7], _("Right Key:"), kq_keyname (kright), FNORMAL); citem (row[8], _("Confirm Key:"), kq_keyname (kalt), FNORMAL); citem (row[9], _("Cancel Key:"), kq_keyname (kctrl), FNORMAL); citem (row[10], _("Menu Key:"), kq_keyname (kenter), FNORMAL); citem (row[11], _("System Menu Key:"), kq_keyname (kesc), FNORMAL); citem (row[12], _("Sound System:"), is_sound ? _("ON") : _("OFF"), FNORMAL); p = FNORMAL; /* TT: This needs to check for ==0 because 1 means sound init */ if (is_sound == 0) p = FDARK; sprintf (strbuf, "%3d%%", gsvol * 100 / 250); citem (row[13], _("Sound Volume:"), strbuf, p); sprintf (strbuf, "%3d%%", gmvol * 100 / 250); citem (row[14], _("Music Volume:"), strbuf, p); citem (row[15], _("Slow Computer:"), slow_computer ? _("YES") : _("NO"), FNORMAL); if (cpu_usage) sprintf (strbuf, _("rest(%d)"), cpu_usage - 1); else sprintf (strbuf, "yield_timeslice()"); citem (row[16], _("CPU Usage:"), strbuf, FNORMAL); #ifdef DEBUGMODE if (debugging) sprintf (strbuf, "%d", debugging); citem (row[17], _("DebugMode Stuff:"), debugging ? strbuf : _("OFF"), FNORMAL); #endif /* This affects the VISUAL placement of the arrow */ p = ptr; if (ptr > 3) p++; if (ptr > 11) p++; if (ptr > 14) p++; draw_sprite (double_buffer, menuptr, 32 + xofs, p * 8 + 32 + yofs); /* This is the bottom window, where the description goes */ menubox (double_buffer, xofs, 216 + yofs, 38, 1, BLUE); print_font (double_buffer, 8 + xofs, 224 + yofs, dc[ptr], FNORMAL); blit2screen (xofs, yofs); readcontrols (); if (up) { unpress (); // "jump" over unusable options if (ptr == 15 && is_sound == 0) ptr -= 2; ptr--; if (ptr < 0) ptr = MENU_SIZE - 1; play_effect (SND_CLICK, 128); } if (down) { unpress (); // "jump" over unusable options if (ptr == 12 && is_sound == 0) ptr += 2; ptr++; if (ptr > MENU_SIZE - 1) ptr = 0; play_effect (SND_CLICK, 128); } if (balt) { unpress (); switch (ptr) { case 0: #ifdef __DJGPP__ text_ex (B_TEXT, 255, _("This version of KQ was compiled for DOS and does not support windowed mode")); #else text_ex (B_TEXT, 255, _("Changing the display mode to or from windowed view could have serious ramifications. It is advised that you save first.")); if (windowed == 0) sprintf (strbuf, _("Switch to windowed mode?")); else sprintf (strbuf, _("Switch to full screen?")); p = prompt (255, 2, B_TEXT, strbuf, _(" no"), _(" yes"), ""); if (p == 1) { if (windowed == 0) windowed = 1; else windowed = 0; set_config_int (NULL, "windowed", windowed); set_graphics_mode (); } #endif break; case 1: #ifdef __DJGPP__ text_ex (B_TEXT, 255, _("This version of KQ was compiled for DOS and does not support stretching")); #else text_ex (B_TEXT, 255, _("Changing the stretched view option could have serious ramifications. It is advised that you save your game before trying this.")); if (stretch_view == 0) sprintf (strbuf, _("Try to stretch the display?")); else sprintf (strbuf, _("Switch to unstretched display?")); p = prompt (255, 2, B_TEXT, strbuf, _(" no"), _(" yes"), ""); if (p == 1) { if (stretch_view == 0) stretch_view = 1; else stretch_view = 0; set_config_int (NULL, "stretch_view", stretch_view); set_graphics_mode (); } #endif break; case 2: if (show_frate == 0) show_frate = 1; else show_frate = 0; set_config_int (NULL, "show_frate", show_frate); break; case 3: if (wait_retrace == 0) wait_retrace = 1; else wait_retrace = 0; set_config_int (NULL, "wait_retrace", wait_retrace); break; case 4: while ((temp_key = getakey ()) == 0); kup = temp_key; unpress (); set_config_int (NULL, "kup", kup); break; case 5: while ((temp_key = getakey ()) == 0); kdown = temp_key; unpress (); set_config_int (NULL, "kdown", kdown); break; case 6: while ((temp_key = getakey ()) == 0); kleft = temp_key; unpress (); set_config_int (NULL, "kleft", kleft); break; case 7: while ((temp_key = getakey ()) == 0); kright = temp_key; unpress (); set_config_int (NULL, "kright", kright); break; case 8: while ((temp_key = getakey ()) == 0); kalt = temp_key; unpress (); set_config_int (NULL, "kalt", kalt); break; case 9: while ((temp_key = getakey ()) == 0); kctrl = temp_key; unpress (); set_config_int (NULL, "kctrl", kctrl); break; case 10: while ((temp_key = getakey ()) == 0); kenter = temp_key; unpress (); set_config_int (NULL, "kenter", kenter); break; case 11: while ((temp_key = getakey ()) == 0); kesc = temp_key; unpress (); set_config_int (NULL, "kesc", kesc); break; case 12: if (is_sound == 2) sound_init (); else { if (is_sound == 0) { is_sound = 1; print_font (double_buffer, 92 + 2 + xofs, 204 + yofs, _("...please wait..."), FNORMAL); blit2screen (xofs, yofs); sound_init (); play_music (g_map.song_file, 0); } } set_config_int (NULL, "is_sound", is_sound != 0); break; case 13: if (is_sound == 2) { p = getavalue (_("Sound Volume"), 0, 25, gsvol / 10, 1); if (p != -1) gsvol = p * 10; /* make sure to set it no matter what */ set_volume (gsvol, 0); set_config_int (NULL, "gsvol", gsvol); } else /* Not as daft as it seems, SND_BAD also wobbles the screen */ play_effect (SND_BAD, 128); break; case 14: if (is_sound == 2) { p = getavalue (_("Music Volume"), 0, 25, gmvol / 10, 1); if (p != -1) gmvol = p * 10; /* make sure to set it no matter what */ set_music_volume (gmvol / 250.0); set_config_int (NULL, "gmvol", gmvol); } else play_effect (SND_BAD, 128); break; case 15: /* TT: toggle slow_computer */ slow_computer = !slow_computer; set_config_int (NULL, "slow_computer", slow_computer); break; case 16: /* TT: Adjust the CPU usage:yield_timeslice() or rest() */ cpu_usage++; if (cpu_usage > 2) cpu_usage = 0; break; #ifdef DEBUGMODE case 17: /* TT: Things we only have access to when we're in debug mode */ if (debugging < 4) debugging++; else debugging = 0; break; #endif } } if (bctrl) { unpress (); stop = 1; } } pop_config_state (); }
/*! \brief Parse setup.cfg * * Read settings from file * Parse the setup.cfg file for key configurations. * This file would also contain sound options, but that * isn't necessary right now. * * Remember that setup.cfg is found in the /saves dir! */ static void parse_jb_setup (void) { FILE *s; int dab = 0; /* Default key assignments */ kup = KEY_UP; kdown = KEY_DOWN; kright = KEY_RIGHT; kleft = KEY_LEFT; kalt = KEY_ALT; kctrl = KEY_LCONTROL; kenter = KEY_ENTER; kesc = KEY_ESC; jbalt = 0; jbctrl = 1; jbenter = 2; jbesc = 3; /* PH Why in the world doesn't he use Allegro cfg functions here? */ if (!(s = fopen (kqres (SETTINGS_DIR, "setup.cfg"), "r"))) { klog (_("Could not open saves/setup.cfg - Using defaults.")); return; } fscanf (s, "%s", strbuf); while (!feof (s)) { if (strbuf[0] == '#') fgets (strbuf, 254, s); #ifdef KQ_CHEATS if (!strcmp (strbuf, "cheat")) { fscanf (s, "%d", &dab); cheat = dab; } #endif if (!strcmp (strbuf, "debug")) { fscanf (s, "%d", &dab); debugging = dab; } if (!strcmp (strbuf, "intro")) { fscanf (s, "%s", strbuf); if (!strcmp (strbuf, "no")) skip_intro = 1; } if (!strcmp (strbuf, "windowed")) { fscanf (s, "%s", strbuf); if (!strcmp (strbuf, "yes")) windowed = 1; } if (!strcmp (strbuf, "stretch")) { fscanf (s, "%s", strbuf); if (!strcmp (strbuf, "yes")) stretch_view = 1; } if (!strcmp (strbuf, "framerate")) { fscanf (s, "%s", strbuf); if (!strcmp (strbuf, "on")) show_frate = 1; } if (!strcmp (strbuf, "sound")) { fscanf (s, "%s", strbuf); if (!strcmp (strbuf, "off")) is_sound = 0; } if (!strcmp (strbuf, "joystick")) { fscanf (s, "%s", strbuf); if (!strcmp (strbuf, "no")) use_joy = 0; } if (!strcmp (strbuf, "slow_computer")) { fscanf (s, "%s", strbuf); if (!strcmp (strbuf, "yes")) slow_computer = 1; } if (!strcmp (strbuf, "rightkey")) { fscanf (s, "%s", strbuf); kright = atoi (strbuf); } if (!strcmp (strbuf, "leftkey")) { fscanf (s, "%s", strbuf); kleft = atoi (strbuf); } if (!strcmp (strbuf, "upkey")) { fscanf (s, "%s", strbuf); kup = atoi (strbuf); } if (!strcmp (strbuf, "downkey")) { fscanf (s, "%s", strbuf); kdown = atoi (strbuf); } if (!strcmp (strbuf, "sysmenukey")) { fscanf (s, "%s", strbuf); kesc = atoi (strbuf); } if (!strcmp (strbuf, "cancelkey")) { fscanf (s, "%s", strbuf); kctrl = atoi (strbuf); } if (!strcmp (strbuf, "confirmkey")) { fscanf (s, "%s", strbuf); kalt = atoi (strbuf); } if (!strcmp (strbuf, "chrmenukey")) { fscanf (s, "%s", strbuf); kenter = atoi (strbuf); } fscanf (s, "%s", strbuf); } fclose (s); }
/*! \brief Parse allegro file kq.cfg * * This is like parse_setup(), but using Allegro format files * * \author PH * \date 20030831 */ static void parse_allegro_setup (void) { const char *cfg = kqres (SETTINGS_DIR, "kq.cfg"); if (!exists (cfg)) { /* config file does not exist. Fall back to setup.cfg */ /* Transitional code */ parse_jb_setup (); push_config_state (); set_config_file (cfg); set_config_int (NULL, "skip_intro", skip_intro); set_config_int (NULL, "windowed", windowed); set_config_int (NULL, "stretch_view", stretch_view); set_config_int (NULL, "show_frate", show_frate); set_config_int (NULL, "is_sound", is_sound); set_config_int (NULL, "use_joy", use_joy); set_config_int (NULL, "slow_computer", slow_computer); set_config_int (NULL, "kup", kup); set_config_int (NULL, "kdown", kdown); set_config_int (NULL, "kleft", kleft); set_config_int (NULL, "kright", kright); set_config_int (NULL, "kesc", kesc); set_config_int (NULL, "kalt", kalt); set_config_int (NULL, "kctrl", kctrl); set_config_int (NULL, "kenter", kenter); #ifdef DEBUGMODE set_config_int (NULL, "debugging", debugging); #endif pop_config_state (); return; } push_config_state (); set_config_file (cfg); /* NB. JB's config file uses intro=yes --> skip_intro=0 */ skip_intro = get_config_int (NULL, "skip_intro", 0); #ifdef __DJGPP__ /* In DJGPP, it's always non-windowed non-stretched (DOS-era stuff!) */ windowed = 0; stretch_view = 0; #else windowed = get_config_int (NULL, "windowed", 1); stretch_view = get_config_int (NULL, "stretch_view", 1); #endif wait_retrace = get_config_int (NULL, "wait_retrace", 1); show_frate = get_config_int (NULL, "show_frate", 0); is_sound = get_config_int (NULL, "is_sound", 1); use_joy = get_config_int (NULL, "use_joy", 0); slow_computer = get_config_int (NULL, "slow_computer", 0); cpu_usage = get_config_int (NULL, "cpu_usage", 2); #ifdef KQ_CHEATS cheat = get_config_int (NULL, "cheat", 0); no_random_encounters = get_config_int (NULL, "no_random_encounters", 0); no_monsters = get_config_int (NULL, "no_monsters", 0); every_hit_999 = get_config_int (NULL, "every_hit_999", 0); #endif #ifdef DEBUGMODE debugging = get_config_int (NULL, "debugging", 0); #endif kup = get_config_int (NULL, "kup", KEY_UP); kdown = get_config_int (NULL, "kdown", KEY_DOWN); kleft = get_config_int (NULL, "kleft", KEY_LEFT); kright = get_config_int (NULL, "kright", KEY_RIGHT); kesc = get_config_int (NULL, "kesc", KEY_ESC); kalt = get_config_int (NULL, "kalt", KEY_ALT); kctrl = get_config_int (NULL, "kctrl", KEY_LCONTROL); kenter = get_config_int (NULL, "kenter", KEY_ENTER); pop_config_state (); }