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 view_pictures () { int ec = err_OK; char x[64]; int i, pic = 0, dir = 1; game.line_min_print = 1; for (i = 0; ec == err_OK; i = 1) { while (game.dir_pic[pic].offset == _EMPTY) { pic += dir; if (pic < 0) pic = MAX_DIRS - 1; if (pic > MAX_DIRS - 1) { pic = 0; if (i == 0) { /* no pics? */ ec = 1; fprintf (stderr, "No pictures found\n"); goto end_view; } } } _D ("picture = %d", pic); if ((ec = agi_load_resource (rPICTURE, pic)) != err_OK) { _D (_D_CRIT "Whoops. bad pic %d", pic); ec = err_OK; pic += dir; goto next_pic; } print_text ("[drawing]", 0, 16, 0, strlen (x) + 1, 0, 15); /* decodes the raw data to useable form */ decode_picture (pic, TRUE); show_pic (); put_screen (); update_statusline: #ifdef USE_HIRES sprintf (x, "Picture:%3i Hi-res: %3s", pic, opt.hires ? " on" : "off"); #else sprintf (x, "Picture:%3i Hi-res: N/A", pic); #endif print_text (x, 0, 0, 0, strlen (x) + 1, 0, 15); sprintf (x, "H:Hi-res P:Vis/Prio +:Next -:Prev"); print_text (x, 0, 0, 23, strlen (x) + 1, 15, 0); sprintf (x, "R:Redraw D:Screen dump Q:Quit"); print_text (x, 0, 0, 24, strlen (x) + 1, 15, 0); while (42) { decode_picture (pic, TRUE); switch (picviewer_get_key()) { case 'q': goto end_view; #ifdef USE_HIRES #ifdef USE_MOUSE case BUTTON_RIGHT: #endif case 'h': opt.hires = !opt.hires; show_pic (); put_screen (); goto update_statusline; #endif case 'p': debug.priority = !debug.priority; show_pic (); put_screen (); break; case 'd': /*opt.showscreendraw = !opt.showscreendraw;*/ screen_dump(); goto update_statusline; case 'r': goto next_pic; #ifdef USE_MOUSE case BUTTON_LEFT: if (mouse.x < GFX_WIDTH / 2) goto previous_pic; #endif /* fall through */ case '+': _D ("next pic"); if (pic < MAX_DIRS - 1) pic++; else pic = 0; dir = 1; goto next_pic; case '-': previous_pic: _D ("previous pic"); if (pic > 0) pic--; else pic = MAX_DIRS - 1; i = 0; dir = -1; goto next_pic; } } next_pic: agi_unload_resource (rPICTURE, pic); } end_view: return ec; }