static void init_boards(void) { current_info.level.level = 0; current_info.level.moves = 0; current_info.level.boxes_to_go = 0; current_info.player.row = 0; current_info.player.col = 0; current_info.player.spot = ' '; current_info.max_level = 0; current_info.level_offset = 0; current_info.loaded_level = 0; init_undo(); }
int glkunix_startup_code(glkunix_startup_t *data) { myargc = data->argc; myargv = data->argv; os_init_setup (); os_process_arguments (myargc, myargv); init_buffer (); init_err (); init_memory (); init_proc (); init_sound (); init_text (); os_init_screen (); init_undo (); z_restart (); return TRUE; }
int cdecl frotz_main (void) { os_init_setup (); init_buffer (); init_err (); init_memory (); init_process (); init_sound (); os_init_screen (); init_undo (); z_restart (); interpret (); script_close (); record_close (); replay_close (); reset_memory (); os_reset_screen (); return 0; }/* main */
static bool sokoban_loop(void) { char new_spot; bool moved = true; int i = 0, button = 0, lastbutton = 0; short r = 0, c = 0; current_info.level.level = 1; load_level(); update_screen(); while (1) { moved = true; r = current_info.player.row; c = current_info.player.col; button = rb->button_get(true); add_undo(button); switch(button) { case BUTTON_OFF: /* get out of here */ return PLUGIN_OK; case SOKOBAN_UNDO: #ifdef SOKOBAN_UNDO_PRE if (lastbutton != SOKOBAN_UNDO_PRE) break; #else /* repeat can't work here for Ondio */ case SOKOBAN_UNDO | BUTTON_REPEAT: #endif /* this is UNDO */ undo(); rb->lcd_clear_display(); update_screen(); moved = false; break; case SOKOBAN_LEVEL_UP: case SOKOBAN_LEVEL_UP | BUTTON_REPEAT: /* increase level */ init_undo(); current_info.level.boxes_to_go=0; moved = true; break; case SOKOBAN_LEVEL_DOWN: case SOKOBAN_LEVEL_DOWN | BUTTON_REPEAT: /* previous level */ init_undo(); if (current_info.level.level > 1) current_info.level.level--; draw_level(); moved = false; break; case SOKOBAN_LEVEL_REPEAT: case SOKOBAN_LEVEL_REPEAT | BUTTON_REPEAT: /* same level */ init_undo(); draw_level(); moved = false; break; case BUTTON_LEFT: switch(current_info.board[r][c-1]) { case ' ': /* if it is a blank spot */ case '.': /* if it is a home spot */ new_spot = current_info.board[r][c-1]; current_info.board[r][c-1] = '@'; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = new_spot; break; case '$': switch(current_info.board[r][c-2]) { case ' ': /* going from blank to blank */ current_info.board[r][c-2] = current_info.board[r][c-1]; current_info.board[r][c-1] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = ' '; break; case '.': /* going from a blank to home */ current_info.board[r][c-2] = '%'; current_info.board[r][c-1] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = ' '; current_info.level.boxes_to_go--; break; default: moved = false; break; } break; case '%': switch(current_info.board[r][c-2]) { case ' ': /* we are going from a home to a blank */ current_info.board[r][c-2] = '$'; current_info.board[r][c-1] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = '.'; current_info.level.boxes_to_go++; break; case '.': /* if we are going from a home to home */ current_info.board[r][c-2] = '%'; current_info.board[r][c-1] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = '.'; break; default: moved = false; break; } break; default: moved = false; break; } if (moved) current_info.player.col--; break; case BUTTON_RIGHT: /* if it is a blank spot */ switch(current_info.board[r][c+1]) { case ' ': case '.': /* if it is a home spot */ new_spot = current_info.board[r][c+1]; current_info.board[r][c+1] = '@'; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = new_spot; break; case '$': switch(current_info.board[r][c+2]) { case ' ': /* going from blank to blank */ current_info.board[r][c+2] = current_info.board[r][c+1]; current_info.board[r][c+1] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = ' '; break; case '.': /* going from a blank to home */ current_info.board[r][c+2] = '%'; current_info.board[r][c+1] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = ' '; current_info.level.boxes_to_go--; break; default: moved = false; break; } break; case '%': switch(current_info.board[r][c+2]) { case ' ': /* going from a home to a blank */ current_info.board[r][c+2] = '$'; current_info.board[r][c+1] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = '.'; current_info.level.boxes_to_go++; break; case '.': current_info.board[r][c+2] = '%'; current_info.board[r][c+1] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = '.'; break; default: moved = false; break; } break; default: moved = false; break; } if (moved) current_info.player.col++; break; case BUTTON_UP: switch(current_info.board[r-1][c]) { case ' ': /* if it is a blank spot */ case '.': /* if it is a home spot */ new_spot = current_info.board[r-1][c]; current_info.board[r-1][c] = '@'; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = new_spot; break; case '$': switch(current_info.board[r-2][c]) { case ' ': /* going from blank to blank */ current_info.board[r-2][c] = current_info.board[r-1][c]; current_info.board[r-1][c] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = ' '; break; case '.': /* going from a blank to home */ current_info.board[r-2][c] = '%'; current_info.board[r-1][c] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = ' '; current_info.level.boxes_to_go--; break; default: moved = false; break; } break; case '%': switch(current_info.board[r-2][c]) { case ' ': /* we are going from a home to a blank */ current_info.board[r-2][c] = '$'; current_info.board[r-1][c] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = '.'; current_info.level.boxes_to_go++; break; case '.': /* if we are going from a home to home */ current_info.board[r-2][c] = '%'; current_info.board[r-1][c] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = '.'; break; default: moved = false; break; } break; default: moved = false; break; } if (moved) current_info.player.row--; break; case BUTTON_DOWN: switch(current_info.board[r+1][c]) { case ' ': /* if it is a blank spot */ case '.': /* if it is a home spot */ new_spot = current_info.board[r+1][c]; current_info.board[r+1][c] = '@'; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = new_spot; break; case '$': switch(current_info.board[r+2][c]) { case ' ': /* going from blank to blank */ current_info.board[r+2][c] = current_info.board[r+1][c]; current_info.board[r+1][c] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = ' '; break; case '.': /* going from a blank to home */ current_info.board[r+2][c] = '%'; current_info.board[r+1][c] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = ' '; current_info.level.boxes_to_go--; break; default: moved = false; break; } break; case '%': switch(current_info.board[r+2][c]) { case ' ': /* going from a home to a blank */ current_info.board[r+2][c] = '$'; current_info.board[r+1][c] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = '.'; current_info.level.boxes_to_go++; break; case '.': /* going from a home to home */ current_info.board[r+2][c] = '%'; current_info.board[r+1][c] = current_info.board[r][c]; current_info.board[r][c] = current_info.player.spot; current_info.player.spot = '.'; break; default: moved = false; break; } break; default: moved = false; break; } if (moved) current_info.player.row++; break; default: if (rb->default_event_handler(button) == SYS_USB_CONNECTED) return PLUGIN_USB_CONNECTED; moved = false; break; } if (button != BUTTON_NONE) lastbutton = button; if (moved) { current_info.level.moves++; rb->lcd_clear_display(); update_screen(); } /* We have completed this level */ if (current_info.level.boxes_to_go == 0) { current_info.level.level++; /* clear undo stats */ init_undo(); rb->lcd_clear_display(); if (current_info.level.level > current_info.max_level) { rb->lcd_putsxy(10, 20, "You WIN!!"); rb->lcd_set_drawmode(DRMODE_COMPLEMENT); for (i = 0; i < 30000 ; i++) { rb->lcd_fillrect(0, 0, 111, 63); rb->lcd_update(); button = rb->button_get(false); if (button && ((button & BUTTON_REL) != BUTTON_REL)) break; } rb->lcd_set_drawmode(DRMODE_SOLID); return PLUGIN_OK; } load_level(); update_screen(); } } /* end while */ return PLUGIN_OK; }
BOOL saveundo(BOOL in_instruction) { move_difference newdiff; strid_t stack; stream_result_t poo; if(!allow_saveundo) return TRUE; /* In games which provide @save_undo, we will have already issued a faked saveundo before the first @save_undo hits, since there hadn't been any @save_undo before the first read line. So when this happens, wipe the fake saveundo in favor of the real one */ if(in_instruction && movelist && !movelist->next && !movelist->PC_in_instruction) init_undo(); if(!quetzal_diff(z_memory, prevstate, dynamic_size, &newdiff.delta, &newdiff.deltalength, TRUE)) return FALSE; #ifdef PARANOID { char *newmem = (char *) n_malloc(dynamic_size); n_memcpy(newmem, prevstate, dynamic_size); quetzal_undiff(newmem, dynamic_size, newdiff.delta, newdiff.deltalength, TRUE); if(n_memcmp(z_memory, newmem, dynamic_size)) { n_show_error(E_SAVE, "save doesn't match itself", 0); } n_free(newmem); } #endif newdiff.PC = PC; newdiff.oldPC = oldPC; newdiff.PC_in_instruction = in_instruction; newdiff.stacklength = get_quetzal_stack_size(); newdiff.stackchunk = (zbyte *) n_malloc(newdiff.stacklength); stack = glk_stream_open_memory((char *) newdiff.stackchunk, newdiff.stacklength, filemode_Write, 0); if(!stack) { n_free(newdiff.delta); n_free(newdiff.stackchunk); return FALSE; } if(!quetzal_stack_save(stack)) { glk_stream_close(stack, NULL); n_free(newdiff.delta); n_free(newdiff.stackchunk); return FALSE; } glk_stream_close(stack, &poo); if(poo.writecount != newdiff.stacklength) { n_show_error(E_SAVE, "incorrect stack size assessment", poo.writecount); n_free(newdiff.delta); n_free(newdiff.stackchunk); return FALSE; } while(move_index-- > 0) { n_free(movelist->delta); n_free(movelist->stackchunk); LEremove(movelist); } LEadd(movelist, newdiff); move_index++; n_memcpy(prevstate, z_memory, dynamic_size); has_done_save_undo = TRUE; return TRUE; }