int loadgame_simple () { char home[MAX_PATH], path[MAX_PATH]; int rc = 0; if (get_app_dir (home, MAX_PATH) < 0) { message_box ("Error loading game."); return err_BadFileOpen; } sprintf(path, "%s/" DATA_DIR "/%05X.%s/%08d.sav", home, game.crc, game.id, 0); erase_both(); stop_sound(); close_window(); if ((rc = load_game (path)) == err_OK) { message_box ("Game restored."); game.exit_all_logics = 1; menu_enable_all(); } else { message_box ("Error restoring game."); } return rc; }
static void refresh_screen() { erase_both (); show_pic (); blit_both (); commit_both (); put_screen (); }
int loadgame_dialog () { char home[MAX_PATH], path[MAX_PATH]; int rc, slot = 0; int hm, vm, hp, vp; /* box margins */ int w; hm = 2; vm = 3; hp = hm * CHAR_COLS; vp = vm * CHAR_LINES; w = (40 - 2 * hm) - 1; if (get_app_dir (home, MAX_PATH) < 0) { message_box ("Error loading game."); return err_BadFileOpen; } sprintf (path, "%s/" DATA_DIR "/%05X.%s/", home, game.crc, game.id); erase_both(); stop_sound(); draw_window (hp, vp, GFX_WIDTH - hp, GFX_HEIGHT - vp); print_text ("Select a game which you wish to\nrestore:", 0, hm + 1, vm + 1, w, MSG_BOX_TEXT, MSG_BOX_COLOUR); print_text ("Press ENTER to select, ESC cancels", 0, hm + 1, vm + 17, w, MSG_BOX_TEXT, MSG_BOX_COLOUR); slot = select_slot (path); if (slot < 0) { message_box ("Game NOT restored."); return err_OK; } sprintf(path, "%s/" DATA_DIR "/%05X.%s/%08d.sav", home, game.crc, game.id, slot); if ((rc = load_game (path)) == err_OK) { message_box ("Game restored."); game.exit_all_logics = 1; menu_enable_all(); } else { message_box ("Error restoring game."); } return rc; }
int loadgame_simple () { char home[MAX_PATH], path[MAX_PATH]; int rc = 0; printf("here?\n"); #ifdef DREAMCAST uint8 addr, port, unit; addr = maple_first_vmu(); if (addr) { maple_create_port (addr, &port, &unit); sprintf (g_vmu_port, "%c%d", port + 'a', unit); } else { message_box("No VMU found."); return err_OK; } sprintf(path, VMU_PATH, g_vmu_port, game.id, slot); #else if (get_app_dir (home, MAX_PATH) < 0) { message_box ("Error loading game."); return err_BadFileOpen; } sprintf(path, "%s/" DATA_DIR "/%05X.%s/%08d.sav", home, game.crc, game.id, 0); #endif erase_both(); stop_sound(); close_window(); if ((rc = load_game (path)) == err_OK) { message_box ("Game restored."); game.exit_all_logics = 1; menu_enable_all(); } else { message_box ("Error restoring game."); } return rc; }
int savegame_dialog () { char home[MAX_PATH], path[MAX_PATH]; char *desc; char *buttons[] = { "Do as I say!", "I regret", NULL }; char dstr[200]; int rc, slot = 0; int hm, vm, hp, vp; /* box margins */ int w; hm = 2; vm = 3; hp = hm * CHAR_COLS; vp = vm * CHAR_LINES; w = (40 - 2 * hm) - 1; if (get_app_dir (home, MAX_PATH) < 0) { message_box ("Couldn't save game."); return err_BadFileOpen; } /* DATADIR conflicts with ObjIdl.h in win32 SDK, renamed to DATA_DIR */ sprintf (path, "%s/" DATA_DIR "/", home); MKDIR (path, 0755); sprintf (path, "%s/" DATA_DIR "/%05X.%s/", home, game.crc, game.id); MKDIR (path, 0711); erase_both (); draw_window (hp, vp, GFX_WIDTH - hp, GFX_HEIGHT - vp); print_text ("Select a slot in which you wish to save the game:", 0, hm + 1, vm + 1, w, MSG_BOX_TEXT, MSG_BOX_COLOUR); print_text ("Press ENTER to select, ESC cancels", 0, hm + 1, vm + 17, w, MSG_BOX_TEXT, MSG_BOX_COLOUR); slot = select_slot (path); if (slot < 0) /* ESC pressed */ return err_OK; /* Get savegame description */ draw_window (hp, vp + 5 * CHAR_LINES, GFX_WIDTH - hp, GFX_HEIGHT - vp - 9 * CHAR_LINES); print_text ("Enter a description for this game:", 0, hm + 1, vm + 6, w, MSG_BOX_TEXT, MSG_BOX_COLOUR); draw_rectangle (3 * CHAR_COLS, 11 * CHAR_LINES - 1, 37 * CHAR_COLS, 12 * CHAR_LINES, MSG_BOX_TEXT); flush_block (3 * CHAR_COLS, 11 * CHAR_LINES - 1, 37 * CHAR_COLS, 12 * CHAR_LINES); get_string (2, 11, 33, MAX_STRINGS); print_character (3, 11, game.cursor_char, MSG_BOX_COLOUR, MSG_BOX_TEXT); do { main_cycle (); } while (game.input_mode == INPUT_GETSTRING); close_window (); desc = game.strings[MAX_STRINGS]; sprintf (dstr, "Are you sure you want to save the game " "described as:\n\n%s\n\nin slot %d?\n\n\n", desc, slot); rc = selection_box (dstr, buttons); if (rc != 0) { message_box ("Game NOT saved."); return err_OK; } sprintf (path, "%s/" DATA_DIR "/%05X.%s/%08d.sav", home, game.crc, game.id, slot); _D (_D_WARN "file is [%s]", path); save_game (path, desc); message_box ("Game saved."); return err_OK; }
int load_game(char* s) { int i, ver, vt_entries = MAX_VIEWTABLE; UINT8 t; SINT16 parm[7]; char sig[8]; char id[8]; char description[256]; FILE *f = fopen(s, "rb"); if(!f) return err_BadFileOpen; read_bytes(f, sig, 8); if (strncmp (sig, strSig, 8)) { fclose(f); return err_BadFileOpen; } read_string (f, description); ver = read_uint8(f); if (ver == 0) vt_entries = 64; game.state = read_uint8(f); /* game.name - not saved */ read_string(f, id); if(strcmp(id, game.id)) { fclose(f); return err_BadFileOpen; } /* game.crc - not saved */ for (i = 0; i < MAX_FLAGS; i++) game.flags[i] = read_uint8(f); for (i = 0; i < MAX_VARS; i++) game.vars[i] = read_uint8(f); game.horizon = read_sint16(f); game.line_status = read_sint16(f); game.line_user_input = read_sint16(f); game.line_min_print = read_sint16(f); /* These are never saved */ game.cursor_pos = 0; game.input_buffer[0] = 0; game.echo_buffer[0] = 0; game.keypress = 0; game.input_mode = read_sint16(f); game.lognum = read_sint16(f); game.player_control = read_sint16(f); game.quit_prog_now = read_sint16(f); game.status_line = read_sint16(f); game.clock_enabled = read_sint16(f); game.exit_all_logics = read_sint16(f); game.picture_shown = read_sint16(f); game.has_prompt = read_sint16(f); game.game_flags = read_sint16(f); game.input_enabled = !read_sint16(f); for (i = 0; i < _HEIGHT; i++) game.pri_table[i] = read_uint8(f); if(game.has_window) close_window(); game.msg_box_ticks = 0; game.block.active = FALSE; /* game.window - fixed by close_window() */ /* game.has_window - fixed by close_window() */ game.gfx_mode = read_sint16(f); game.cursor_char = read_uint8(f); game.color_fg = read_sint16(f); game.color_bg = read_sint16(f); /* game.hires (#ifdef USE_HIRES) - rebuilt from image stack */ /* game.sbuf - rebuilt from image stack */ /* game.ego_words - fixed by clean_input */ /* game.num_ego_words - fixed by clean_input */ game.num_objects = read_sint16(f); for(i = 0; i < (SINT16)game.num_objects; i++) object_set_location(i, read_sint16(f)); /* Those are not serialized */ for (i = 0; i < MAX_DIRS; i++) { game.ev_keyp[i].occured = FALSE; } for (i = 0; i < MAX_STRINGS; i++) read_string (f, game.strings[i]); for (i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource (rLOGIC, i); else agi_unload_resource (rLOGIC, i); game.logics[i].sIP = read_sint16(f); game.logics[i].cIP = read_sint16(f); } for (i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource(rPICTURE, i); else agi_unload_resource(rPICTURE, i); } for (i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource(rVIEW, i); else agi_unload_resource(rVIEW, i); } for(i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource(rSOUND, i); else agi_unload_resource(rSOUND, i); } /* game.pictures - loaded above */ /* game.logics - loaded above */ /* game.views - loaded above */ /* game.sounds - loaded above */ for (i = 0; i < vt_entries; i++) { struct vt_entry* v = &game.view_table[i]; v->step_time = read_uint8(f); v->step_time_count = read_uint8(f); v->entry = read_uint8(f); v->x_pos = read_sint16(f); v->y_pos = read_sint16(f); v->current_view = read_uint8(f); /* v->view_data - fixed below */ v->current_loop = read_uint8(f); v->num_loops = read_uint8(f); /* v->loop_data - fixed below */ v->current_cel = read_uint8(f); v->num_cels = read_uint8(f); /* v->cel_data - fixed below */ /* v->cel_data_2 - fixed below */ v->x_pos2 = read_sint16(f); v->y_pos2 = read_sint16(f); /* v->s - fixed below */ v->x_size = read_sint16(f); v->y_size = read_sint16(f); v->step_size = read_uint8(f); v->cycle_time = read_uint8(f); v->cycle_time_count = read_uint8(f); v->direction = read_uint8(f); v->motion = read_uint8(f); v->cycle = read_uint8(f); v->priority = read_uint8(f); v->flags = read_uint16(f); v->parm1 = read_uint8(f); v->parm2 = read_uint8(f); v->parm3 = read_uint8(f); v->parm4 = read_uint8(f); } for (i = vt_entries; i < MAX_VIEWTABLE; i++) { memset (&game.view_table[i], 0, sizeof (struct vt_entry)); } /* Fix some pointers in viewtable */ for (i = 0; i < MAX_VIEWTABLE; i++) { struct vt_entry* v = &game.view_table[i]; if(game.dir_view[v->current_view].offset == _EMPTY) continue; if(!(game.dir_view[v->current_view].flags & RES_LOADED)) agi_load_resource(rVIEW, v->current_view); set_view(v, v->current_view); /* Fix v->view_data */ set_loop(v, v->current_loop); /* Fix v->loop_data */ set_cel(v, v->current_cel); /* Fix v->cel_data */ v->cel_data_2 = v->cel_data; v->s = NULL; /* not sure if it is used... */ } erase_both(); /* Clear input line */ clear_screen(0); write_status(); /* Recreate background from saved image stack */ clear_image_stack(); while ((t = read_uint8(f)) != 0) { for (i = 0; i < 7; i++) parm[i] = read_sint16(f); replay_image_stack_call (t, parm[0], parm[1], parm[2], parm[3], parm[4], parm[5], parm[6]); } fclose(f); setflag(F_restore_just_ran, TRUE); game.has_prompt = 0; /* force input line repaint if necessary*/ clean_input(); erase_both(); blit_both(); commit_both(); show_pic(); do_update(); return err_OK; }
int loadgame_dialog () { #ifndef PALMOS char home[MAX_PATH], path[MAX_PATH]; int rc, slot = 0; int hm, vm, hp, vp; /* box margins */ int w; hm = 2; vm = 3; hp = hm * CHAR_COLS; vp = vm * CHAR_LINES; w = (40 - 2 * hm) - 1; #ifdef DREAMCAST uint8 addr, port, unit; addr = maple_first_vmu(); if (addr) { maple_create_port (addr, &port, &unit); sprintf (g_vmu_port, "%c%d", port + 'a', unit); } else { message_box("No VMU found."); return err_OK; } #else if (get_app_dir (home, MAX_PATH) < 0) { message_box ("Error loading game."); return err_BadFileOpen; } # ifdef CIBYL sprintf (path, "recordstore://%05X.%s:", game.crc, game.id); # else sprintf (path, "%s/" DATA_DIR "/%05X.%s/", home, game.crc, game.id); # endif #endif erase_both(); stop_sound(); draw_window (hp, vp, GFX_WIDTH - hp, GFX_HEIGHT - vp); print_text ("Select a game which you wish to\nrestore:", 0, hm + 1, vm + 1, w, MSG_BOX_TEXT, MSG_BOX_COLOUR); print_text ("Press ENTER to select, ESC cancels", 0, hm + 1, vm + 17, w, MSG_BOX_TEXT, MSG_BOX_COLOUR); slot = select_slot (path); if (slot < 0) { message_box ("Game NOT restored."); return err_OK; } #ifdef DREAMCAST sprintf(path, VMU_PATH, g_vmu_port, game.id, slot); #elif CIBYL sprintf (path, "recordstore://%05X.%s:%d", game.crc, game.id, slot+1); printf("path: %s\n", path); #else sprintf(path, "%s/" DATA_DIR "/%05X.%s/%08d.sav", home, game.crc, game.id, slot); #endif if ((rc = load_game (path)) == err_OK) { message_box ("Game restored."); game.exit_all_logics = 1; menu_enable_all(); } else { message_box ("Error restoring game."); } return rc; #endif /* PALMOS */ }
int savegame_dialog () { #ifndef PALMOS /* FIXME */ char home[MAX_PATH], path[MAX_PATH]; char *desc; char *buttons[] = { "Do as I say!", "I regret", NULL }; char dstr[200]; int rc, slot = 0; int hm, vm, hp, vp; /* box margins */ int w; hm = 2; vm = 3; hp = hm * CHAR_COLS; vp = vm * CHAR_LINES; w = (40 - 2 * hm) - 1; #ifdef DREAMCAST uint8 addr, port, unit; addr = maple_first_vmu(); if(addr) { maple_create_port(addr, &port, &unit); sprintf(g_vmu_port, "%c%d", port + 'a', unit); } else { message_box("No VMU found."); return err_OK; } #else if (get_app_dir (home, MAX_PATH) < 0) { message_box ("Couldn't save game."); return err_BadFileOpen; } # ifdef CIBYL sprintf (path, "recordstore://%05X.%s:", game.crc, game.id); # else /* DATADIR conflicts with ObjIdl.h in win32 SDK, renamed to DATA_DIR */ sprintf (path, "%s/" DATA_DIR "/", home); MKDIR (path, 0755); sprintf (path, "%s/" DATA_DIR "/%05X.%s/", home, game.crc, game.id); MKDIR (path, 0711); # endif #endif erase_both (); draw_window (hp, vp, GFX_WIDTH - hp, GFX_HEIGHT - vp); print_text ("Select a slot in which you wish to save the game:", 0, hm + 1, vm + 1, w, MSG_BOX_TEXT, MSG_BOX_COLOUR); print_text ("Press ENTER to select, ESC cancels", 0, hm + 1, vm + 17, w, MSG_BOX_TEXT, MSG_BOX_COLOUR); slot = select_slot (path); if (slot < 0) /* ESC pressed */ return err_OK; /* Get savegame description */ draw_window (hp, vp + 5 * CHAR_LINES, GFX_WIDTH - hp, GFX_HEIGHT - vp - 9 * CHAR_LINES); print_text ("Enter a description for this game:", 0, hm + 1, vm + 6, w, MSG_BOX_TEXT, MSG_BOX_COLOUR); draw_rectangle (3 * CHAR_COLS, 11 * CHAR_LINES - 1, 37 * CHAR_COLS, 12 * CHAR_LINES, MSG_BOX_TEXT); flush_block (3 * CHAR_COLS, 11 * CHAR_LINES - 1, 37 * CHAR_COLS, 12 * CHAR_LINES); get_string (2, 11, 33, MAX_STRINGS); print_character (3, 11, game.cursor_char, MSG_BOX_COLOUR, MSG_BOX_TEXT); do { main_cycle (); } while (game.input_mode == INPUT_GETSTRING); close_window (); desc = game.strings[MAX_STRINGS]; sprintf (dstr, "Are you sure you want to save the game " "described as:\n\n%s\n\nin slot %d?\n\n\n", desc, slot); rc = selection_box (dstr, buttons); if (rc != 0) { message_box ("Game NOT saved."); return err_OK; } #ifdef DREAMCAST sprintf(path, VMU_PATH, g_vmu_port, game.id, slot); fs_unlink(path); #elif CIBYL sprintf (path, "recordstore://%05X.%s:%d", game.crc, game.id, slot+1); printf("path: %s\n", path); #else sprintf (path, "%s/" DATA_DIR "/%05X.%s/%08d.sav", home, game.crc, game.id, slot); #endif _D (_D_WARN "file is [%s]", path); save_game (path, desc); message_box ("Game saved."); #endif /* PALMOS */ return err_OK; }
/** * Execute a logic script * @param n Number of the logic resource to execute */ int run_logic (int n) { UINT8 op = 0; UINT8 p[CMD_BSIZE] = { 0 }; UINT8 *code = NULL; int num = 0; /* If logic not loaded, load it */ if (~game.dir_logic[n].flags & RES_LOADED) { _D (_D_WARN "logic %d not loaded!", n); agi_load_resource (rLOGIC, n); } game.lognum = n; cur_logic = &game.logics[game.lognum]; code = cur_logic->data; cur_logic->cIP = cur_logic->sIP; timer_hack = 0; while (ip < game.logics[n].size && !game.quit_prog_now) { #ifdef USE_CONSOLE if (debug.enabled) { if (debug.steps > 0) { if (debug.logic0 || n) { debug_console (n, lCOMMAND_MODE, NULL); debug.steps--; } } else { blit_both (); console_prompt (); do { main_cycle (); } while (!debug.steps && debug.enabled); console_lock (); erase_both (); } } #endif switch (op = *(code + ip++)) { case 0xff: /* if (open/close) */ test_if_code (n); break; case 0xfe: /* goto */ /* +2 covers goto size */ ip += 2 + ((SINT16)lohi_getword (code + ip)); /* timer must keep running even in goto loops, * but Sarien can't do that :( */ if (timer_hack > 20) { poll_timer (); update_timer (); timer_hack = 0; } break; case 0x00: /* return */ return 1; default: num = logic_names_cmd[op].num_args; memmove (p, code + ip, num); memset (p + num, 0, CMD_BSIZE - num); agi_command[op](p); ip += num; } if (game.exit_all_logics) break; } return 0; /* after executing new.room() */ }