void replay_image_stack_call(UINT8 type, SINT16 p1, SINT16 p2, SINT16 p3, SINT16 p4, SINT16 p5, SINT16 p6, SINT16 p7) { switch(type) { case ADD_PIC: _D (_D_WARN "--- decoding picture %d ---", p1); agi_load_resource (rPICTURE, p1); decode_picture (p1, p2); break; case ADD_VIEW: agi_load_resource (rVIEW, p1); add_to_pic (p1, p2, p3, p4, p5, p6, p7); break; } }
/** * Set up new room. * This function is called when ego enters a new room. * @param n room number */ void new_room(int n) { struct vt_entry *v; int i; debugC(4, kDebugLevelMain, "*** room %d ***", n); stop_sound(); i = 0; for (v = game.view_table; v < &game.view_table[MAX_VIEWTABLE]; v++) { v->entry = i++; v->flags &= ~(ANIMATED | DRAWN); v->flags |= UPDATE; v->step_time = 1; v->step_time_count = 1; v->cycle_time = 1; v->cycle_time_count = 1; v->step_size = 1; } agi_unload_resources(); game.player_control = true; game.block.active = false; game.horizon = 36; game.vars[V_prev_room] = game.vars[V_cur_room]; game.vars[V_cur_room] = n; game.vars[V_border_touch_obj] = 0; game.vars[V_border_code] = 0; game.vars[V_ego_view_resource] = game.view_table[0].current_view; agi_load_resource(rLOGIC, n); /* Reposition ego in the new room */ switch (game.vars[V_border_touch_ego]) { case 1: game.view_table[0].y_pos = _HEIGHT - 1; break; case 2: game.view_table[0].x_pos = 0; break; case 3: game.view_table[0].y_pos = HORIZON + 1; break; case 4: game.view_table[0].x_pos = _WIDTH - game.view_table[0].x_size; break; } game.vars[V_border_touch_ego] = 0; setflag(F_new_room_exec, true); game.exit_all_logics = true; _text->write_status(); _text->write_prompt(); }
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; }
/** * 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() */ }
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; }