diff options
Diffstat (limited to 'engines/sci/engine/game.cpp')
-rw-r--r-- | engines/sci/engine/game.cpp | 175 |
1 files changed, 76 insertions, 99 deletions
diff --git a/engines/sci/engine/game.cpp b/engines/sci/engine/game.cpp index ccf720f927..ef4012c0f4 100644 --- a/engines/sci/engine/game.cpp +++ b/engines/sci/engine/game.cpp @@ -39,18 +39,17 @@ extern int bp_flag; static int -_init_vocabulary(state_t *s) /* initialize vocabulary and related resources */ -{ +_init_vocabulary(state_t *s) { /* initialize vocabulary and related resources */ s->parser_lastmatch_word = SAID_NO_MATCH; s->parser_rules = NULL; - sciprintf("Initializing vocabulary\n"); - - if ((s->resmgr->sci_version < SCI_VERSION_01_VGA)&&(s->parser_words = vocab_get_words(s->resmgr, &(s->parser_words_nr)))) { + sciprintf("Initializing vocabulary\n"); + + if ((s->resmgr->sci_version < SCI_VERSION_01_VGA) && (s->parser_words = vocab_get_words(s->resmgr, &(s->parser_words_nr)))) { s->parser_suffices = vocab_get_suffices(s->resmgr, &(s->parser_suffices_nr)); if ((s->parser_branches = vocab_get_branches(s->resmgr, &(s->parser_branches_nr)))) - /* Now build a GNF grammar out of this */ - s->parser_rules = vocab_build_gnf(s->parser_branches, s->parser_branches_nr); + /* Now build a GNF grammar out of this */ + s->parser_rules = vocab_build_gnf(s->parser_branches, s->parser_branches_nr); } else { sciprintf("Assuming that this game does not use a parser.\n"); @@ -76,8 +75,7 @@ _init_vocabulary(state_t *s) /* initialize vocabulary and related resources */ extern int _allocd_rules; static void -_free_vocabulary(state_t *s) -{ +_free_vocabulary(state_t *s) { sciprintf("Freeing vocabulary\n"); if (s->parser_words) { @@ -99,8 +97,7 @@ _free_vocabulary(state_t *s) static int -_init_graphics_input(state_t *s) -{ +_init_graphics_input(state_t *s) { s->pic_priority_table = NULL; s->pics = NULL; s->pics_nr = 0; @@ -108,8 +105,7 @@ _init_graphics_input(state_t *s) } static void -_sci1_alloc_system_colors(state_t *s) -{ +_sci1_alloc_system_colors(state_t *s) { gfx_color_t white; gfx_color_t black; @@ -129,8 +125,7 @@ _sci1_alloc_system_colors(state_t *s) } int -_reset_graphics_input(state_t *s) -{ +_reset_graphics_input(state_t *s) { resource_t *resource; int font_nr; gfx_color_t transparent; @@ -141,33 +136,32 @@ _reset_graphics_input(state_t *s) for (i = 0; i < 16; i++) { if (gfxop_set_color(s->gfx_state, &(s->ega_colors[i]), - gfx_sci0_image_colors[sci0_palette][i].r, - gfx_sci0_image_colors[sci0_palette][i].g, - gfx_sci0_image_colors[sci0_palette][i].b, - 0, -1, -1)) + gfx_sci0_image_colors[sci0_palette][i].r, + gfx_sci0_image_colors[sci0_palette][i].g, + gfx_sci0_image_colors[sci0_palette][i].b, + 0, -1, -1)) return 1; gfxop_set_system_color(s->gfx_state, &(s->ega_colors[i])); } - } else - { + } else { /* Check for Amiga palette file. */ FILE *f = sci_fopen("spal", "rb"); if (f) { - s->gfx_state->resstate->static_palette = - gfxr_read_pal1_amiga(&s->gfx_state->resstate->static_palette_entries, f); + s->gfx_state->resstate->static_palette = + gfxr_read_pal1_amiga(&s->gfx_state->resstate->static_palette_entries, f); fclose(f); _sci1_alloc_system_colors(s); } else { resource = scir_find_resource(s->resmgr, sci_palette, 999, 1); if (resource) { - if (s->version < SCI_VERSION(1,001,000)) - s->gfx_state->resstate->static_palette = - gfxr_read_pal1(999, &s->gfx_state->resstate->static_palette_entries, - resource->data, resource->size); - else - s->gfx_state->resstate->static_palette = - gfxr_read_pal11(999, &s->gfx_state->resstate->static_palette_entries, - resource->data, resource->size); + if (s->version < SCI_VERSION(1, 001, 000)) + s->gfx_state->resstate->static_palette = + gfxr_read_pal1(999, &s->gfx_state->resstate->static_palette_entries, + resource->data, resource->size); + else + s->gfx_state->resstate->static_palette = + gfxr_read_pal11(999, &s->gfx_state->resstate->static_palette_entries, + resource->data, resource->size); _sci1_alloc_system_colors(s); scir_unlock_resource(s->resmgr, resource, sci_palette, 999); } else @@ -195,7 +189,8 @@ _reset_graphics_input(state_t *s) s->priority_first = 42; /* Priority zone 0 ends here */ if (s->version < SCI_VERSION_FTU_PRIORITY_14_ZONES) - s->priority_last = 200; else + s->priority_last = 200; + else s->priority_last = 190; font_nr = -1; @@ -214,8 +209,7 @@ _reset_graphics_input(state_t *s) s->iconbar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 200), s->ega_colors[0], transparent); s->iconbar_port->flags |= GFXW_FLAG_NO_IMPLICIT_SWITCH; - if (s->resmgr->sci_version >= SCI_VERSION_01_VGA) - { + if (s->resmgr->sci_version >= SCI_VERSION_01_VGA) { // This bit sets the foreground and background colors in VGA SCI games #if 0 gfx_color_t fgcolor; @@ -225,12 +219,12 @@ _reset_graphics_input(state_t *s) fgcolor.mask = GFX_MASK_VISUAL; bgcolor.visual = s->gfx_state->resstate->static_palette[255]; bgcolor.mask = GFX_MASK_VISUAL; - s->titlebar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 10), - fgcolor, bgcolor); + s->titlebar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 10), + fgcolor, bgcolor); #endif } else - s->titlebar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 10), - s->ega_colors[0], s->ega_colors[15]); + s->titlebar_port = gfxw_new_port(s->visual, NULL, gfx_rect(0, 0, 320, 10), + s->ega_colors[0], s->ega_colors[15]); s->titlebar_port->color.mask |= GFX_MASK_PRIORITY; s->titlebar_port->color.priority = 11; s->titlebar_port->bgcolor.mask |= GFX_MASK_PRIORITY; @@ -259,8 +253,7 @@ _reset_graphics_input(state_t *s) } int -game_init_graphics(state_t *s) -{ +game_init_graphics(state_t *s) { #ifndef WITH_PIC_SCALING if (s->gfx_state->options->pic0_unscaled == 0) sciprintf("WARNING: Pic scaling was disabled; your version of FreeSCI has no support for scaled pic drawing built in.\n"); @@ -272,8 +265,7 @@ game_init_graphics(state_t *s) static void -_free_graphics_input(state_t *s) -{ +_free_graphics_input(state_t *s) { sciprintf("Freeing graphics\n"); s->visual->widfree(GFXW(s->visual)); @@ -291,8 +283,7 @@ _free_graphics_input(state_t *s) /*------------------------------------------------------------*/ int -game_init_sound(state_t *s, int sound_flags) -{ +game_init_sound(state_t *s, int sound_flags) { if (s->resmgr->sci_version >= SCI_VERSION_01) sound_flags |= SFX_STATE_FLAG_MULTIPLAY; @@ -305,8 +296,7 @@ game_init_sound(state_t *s, int sound_flags) /* Maps a class ID to the script the corresponding class is contained in */ /* Returns the script number suggested by vocab.996, or -1 if there's none */ static int -suggested_script(resource_t *res, unsigned int classId) -{ +suggested_script(resource_t *res, unsigned int classId) { int offset; if (!res || classId >= res->size >> 2) return -1; @@ -317,9 +307,8 @@ suggested_script(resource_t *res, unsigned int classId) } -int -test_cursor_style(state_t *s) -{ +int +test_cursor_style(state_t *s) { int resource_nr = 0; int ok = 0; @@ -331,8 +320,7 @@ test_cursor_style(state_t *s) } int -create_class_table_sci11(state_t *s) -{ +create_class_table_sci11(state_t *s) { int scriptnr; unsigned int seeker_offset; char *seeker_ptr; @@ -349,24 +337,22 @@ create_class_table_sci11(state_t *s) for (scriptnr = 0; scriptnr < 1000; scriptnr++) { resource_t *heap = scir_find_resource(s->resmgr, sci_heap, - scriptnr, 0); + scriptnr, 0); if (heap) { int global_vars = getUInt16(heap->data + 2); - seeker_ptr = (char*)heap->data + 4 + global_vars*2; - seeker_offset = 4 + global_vars*2; + seeker_ptr = (char*)heap->data + 4 + global_vars * 2; + seeker_offset = 4 + global_vars * 2; - while (getUInt16((byte*)seeker_ptr) == SCRIPT_OBJECT_MAGIC_NUMBER) - { - if (getUInt16((byte*)seeker_ptr + 14) & SCRIPT_INFO_CLASS) - { + while (getUInt16((byte*)seeker_ptr) == SCRIPT_OBJECT_MAGIC_NUMBER) { + if (getUInt16((byte*)seeker_ptr + 14) & SCRIPT_INFO_CLASS) { classnr = getUInt16((byte*)seeker_ptr + 10); if (classnr >= s->classtable_size) { if (classnr >= SCRIPT_MAX_CLASSTABLE_SIZE) { - fprintf(stderr,"Invalid class number 0x%x in script.%d(0x%x), offset %04x\n", - classnr, scriptnr, scriptnr, seeker_offset); + fprintf(stderr, "Invalid class number 0x%x in script.%d(0x%x), offset %04x\n", + classnr, scriptnr, scriptnr, seeker_offset); return 1; } @@ -376,7 +362,7 @@ create_class_table_sci11(state_t *s) s->classtable_size = classnr + 1; /* Adjust maximum number of entries */ } - + s->classtable[classnr].reg.offset = seeker_offset; s->classtable[classnr].reg.segment = 0; s->classtable[classnr].script = scriptnr; @@ -391,8 +377,7 @@ create_class_table_sci11(state_t *s) return 0; } static int -create_class_table_sci0(state_t *s) -{ +create_class_table_sci0(state_t *s) { int scriptnr; unsigned int seeker; int classnr; @@ -410,7 +395,7 @@ create_class_table_sci0(state_t *s) for (scriptnr = 0; scriptnr < 1000; scriptnr++) { int objtype = 0; resource_t *script = scir_find_resource(s->resmgr, sci_script, - scriptnr, 0); + scriptnr, 0); if (script) { if (s->version < SCI_VERSION_FTU_NEW_SCRIPT_HEADER) @@ -442,8 +427,8 @@ create_class_table_sci0(state_t *s) if (classnr >= s->classtable_size) { if (classnr >= SCRIPT_MAX_CLASSTABLE_SIZE) { - fprintf(stderr,"Invalid class number 0x%x in script.%d(0x%x), offset %04x\n", - classnr, scriptnr, scriptnr, seeker); + fprintf(stderr, "Invalid class number 0x%x in script.%d(0x%x), offset %04x\n", + classnr, scriptnr, scriptnr, seeker); return 1; } @@ -481,15 +466,14 @@ create_class_table_sci0(state_t *s) /* Architectural stuff: Init/Unintialize engine */ int -script_init_engine(state_t *s, sci_version_t version) -{ +script_init_engine(state_t *s, sci_version_t version) { int result; - s->max_version = SCI_VERSION(9,999,999); /* :-) */ + s->max_version = SCI_VERSION(9, 999, 999); /* :-) */ s->min_version = 0; /* Set no real limits */ s->version = SCI_VERSION_DEFAULT_SCI0; s->kernel_opt_flags = 0; - + if (!version) { s->version_lock_flag = 0; } else { @@ -499,16 +483,15 @@ script_init_engine(state_t *s, sci_version_t version) script_detect_versions(s); - if (s->version >= SCI_VERSION(1,001,000)) - result = create_class_table_sci11(s); + if (s->version >= SCI_VERSION(1, 001, 000)) + result = create_class_table_sci11(s); else result = create_class_table_sci0(s); - - sm_init(&s->seg_manager, s->version >= SCI_VERSION(1,001,000)); + + sm_init(&s->seg_manager, s->version >= SCI_VERSION(1, 001, 000)); s->gc_countdown = GC_INTERVAL - 1; - if (result) - { + if (result) { sciprintf("Failed to initialize class table\n"); return 1; } @@ -524,7 +507,7 @@ script_init_engine(state_t *s, sci_version_t version) s->sys_strings = sm_allocate_sys_strings(&s->seg_manager, - &s->sys_strings_segment); + &s->sys_strings_segment); /* Allocate static buffer for savegame and CWD directories */ sys_string_acquire(s->sys_strings, SYS_STRING_SAVEDIR, "savedir", MAX_SAVE_DIR_SIZE); @@ -561,7 +544,7 @@ script_init_engine(state_t *s, sci_version_t version) /* Those two are used by FileIO for FIND_FIRST, FIND_NEXT */ if (s->version >= SCI_VERSION_FTU_LOFS_ABSOLUTE && - s->version < SCI_VERSION(1,001,000)) + s->version < SCI_VERSION(1, 001, 000)) sm_set_export_width(&s->seg_manager, 1); else sm_set_export_width(&s->seg_manager, 0); @@ -576,14 +559,12 @@ script_init_engine(state_t *s, sci_version_t version) void -script_set_gamestate_save_dir(state_t *s, const char* path) -{ +script_set_gamestate_save_dir(state_t *s, const char* path) { sys_string_set(s->sys_strings, SYS_STRING_SAVEDIR, path); } void -script_free_vm_memory(state_t *s) -{ +script_free_vm_memory(state_t *s) { int i; sciprintf("Freeing VM memory\n"); @@ -605,12 +586,11 @@ script_free_vm_memory(state_t *s) } extern void -free_kfunct_tables(state_t *s); + free_kfunct_tables(state_t *s); /* From kernel.c */ void -script_free_engine(state_t *s) -{ +script_free_engine(state_t *s) { script_free_vm_memory(s); sciprintf("Freeing state-dependant data\n"); @@ -622,16 +602,15 @@ script_free_engine(state_t *s) } void -script_free_breakpoints(state_t *s) -{ +script_free_breakpoints(state_t *s) { breakpoint_t *bp, *bp_next; /* Free breakpoint list */ bp = s->bp_list; while (bp) { bp_next = bp->next; - if (bp->type == BREAK_SELECTOR) sci_free (bp->data.name); - free (bp); + if (bp->type == BREAK_SELECTOR) sci_free(bp->data.name); + free(bp); bp = bp_next; } @@ -644,8 +623,7 @@ script_free_breakpoints(state_t *s) int -game_init(state_t *s) -{ +game_init(state_t *s) { #ifdef __GNUC__XX # warning "Fixme: Use new VM instantiation code all over the place" #endif @@ -653,7 +631,7 @@ game_init(state_t *s) dstack_t *stack; stack = sm_allocate_stack(&s->seg_manager, VM_STACK_SIZE, - &s->stack_segment); + &s->stack_segment); s->stack_base = stack->entries; s->stack_top = s->stack_base + VM_STACK_SIZE; @@ -701,8 +679,8 @@ game_init(state_t *s) if (!s->game_name) { sciprintf("Error: script.000, export 0 ("PREG") does not\n" - " yield an object with a name -> sanity check failed\n", - PRINT_REG(game_obj)); + " yield an object with a name -> sanity check failed\n", + PRINT_REG(game_obj)); return 1; } @@ -726,18 +704,17 @@ game_init(state_t *s) } int -game_exit(state_t *s) -{ +game_exit(state_t *s) { if (s->execution_stack) { sci_free(s->execution_stack); } sfx_exit(&s->sound); -/* Reinit because some other code depends on having a valid state */ - game_init_sound(s, SFX_STATE_FLAG_NOSOUND); + /* Reinit because some other code depends on having a valid state */ + game_init_sound(s, SFX_STATE_FLAG_NOSOUND); sm_destroy(&s->seg_manager); - + if (s->synonyms_nr) { sci_free(s->synonyms); s->synonyms = NULL; |