int main(int argc, char*argv[]) { setenv( "LCUI_FONTFILE", "../../fonts/msyh.ttf", FALSE ); LCUI_Init(); /* 初始化LCUI */ Create_GUI(); /* 创建图形界面 */ clear_game(); /* 清理游戏 */ Show_GUI(); /* 显示图形界面 */ return LCUI_Main(); }
int MlxLib::redraw(const std::list<Position>& pos, const Position& food) { clear_game(); draw_snake(pos); draw_food(food); repaint(); return (LIB_SUCCESS); }
static void next() /* 功能:进行下一局 */ { Widget_Enable( btn_j ); Widget_Enable( btn_s ); Widget_Enable( btn_b ); Widget_Disable( btn_next ); clear_game(); }
/* high level init */ static SDL_bool init_game(session *s, game_state *gs, char const *root) { int i; json_t *game, *res; char const *path; path = set_path("%s/%s/%s", root, CONF_DIR, GAME_CONF); json_error_t err; game = json_load_file(path, 0, &err); if (*err.text != 0) { fprintf(stderr, "error: in %s:%d: %s\n", path, err.line, err.text); return SDL_FALSE; } i = TTF_Init(); if (i < 0) { fprintf(stderr, "error: could not init font library: %s\n", TTF_GetError()); return SDL_FALSE; } res = json_object_get(game, "resolution"); s->screen.x = json_integer_value(json_array_get(res, 0)); s->screen.y = json_integer_value(json_array_get(res, 1)); i = SDL_Init(SDL_INIT_VIDEO); if (i < 0) { fprintf(stderr, "error: could not init video: %s\n", SDL_GetError()); return SDL_FALSE; } s->w = SDL_CreateWindow("Fridge Filler", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, s->screen.x, s->screen.y, 0); if (!s->w) { fprintf(stderr, "Could not init video: %s\n", SDL_GetError()); return SDL_FALSE; } path = set_path("%s/%s", root, "icon.gif"); SDL_Surface *ico = IMG_Load(path); if (ico) { puts("have icon"); SDL_SetWindowIcon(s->w, ico); SDL_FreeSurface(ico); } s->r = SDL_CreateRenderer(s->w, -1, 0); gs->debug.font = 0; SDL_bool ok = load_config(s, gs, game, root); if (!ok) { return SDL_FALSE; } gs->run = gs->logo.active ? MODE_LOGO : gs->intro.active ? MODE_INTRO : MODE_GAME; clear_game(gs); return SDL_TRUE; }
void new_city (int* originx, int* originy, int random_village) { clear_game (); coal_reserve_setup (); setup_river (); ore_reserve_setup (); init_pbars (); /* Initial population is 100 for empty board or 200 for random village (100 are housed). */ people_pool = 100; if (random_village != 0) { random_start (originx, originy); update_pbar(PPOP,200,1); /* So pbars don't flash */ } else { *originx = *originy = WORLD_SIDE_LEN/2 ; update_pbar(PPOP,100,1); } connect_transport (1,1,WORLD_SIDE_LEN-2,WORLD_SIDE_LEN-2); refresh_pbars (); }
// Algorithm goes as follows: // Clear map // Spawn a vehicle // Set its fuel up to some percentage - remember exact fuel counts that were set here // Drive it for a while, always moving it back to start point every turn to avoid it going off the bubble // When moving back, record the sum of the tiles moved so far // Repeat that for a set number of turns or until all fuel is drained // Compare saved percentage (set before) to current percentage // Rescale the recorded number of tiles based on fuel percentage left // (ie. 0% fuel left means no scaling, 50% fuel left means double the effective distance) // Return the rescaled number long test_efficiency( const vproto_id &veh_id, int &expected_mass, const ter_id &terrain, const int reset_velocity_turn, const long target_distance, const bool smooth_stops = false, const bool test_mass = true ) { long min_dist = target_distance * 0.99; long max_dist = target_distance * 1.01; clear_game( terrain ); const tripoint map_starting_point( 60, 60, 0 ); vehicle *veh_ptr = g->m.add_vehicle( veh_id, map_starting_point, -90, 0, 0 ); REQUIRE( veh_ptr != nullptr ); if( veh_ptr == nullptr ) { return 0; } vehicle &veh = *veh_ptr; // Remove all items from cargo to normalize weight. for( const vpart_reference vp : veh.get_all_parts() ) { while( veh.remove_item( vp.part_index(), 0 ) ); vp.part().ammo_consume( vp.part().ammo_remaining(), vp.pos() ); } for( const vpart_reference vp : veh.get_avail_parts( "OPENABLE" ) ) { veh.close( vp.part_index() ); } veh.refresh_insides(); if( test_mass ) { CHECK( to_gram( veh.total_mass() ) == expected_mass ); } expected_mass = to_gram( veh.total_mass() ); veh.check_falling_or_floating(); REQUIRE( !veh.is_in_water() ); const auto &starting_fuel = set_vehicle_fuel( veh, fuel_level ); // This is ugly, but improves accuracy: compare the result of fuel approx function // rather than the amount of fuel we actually requested const float starting_fuel_per = fuel_percentage_left( veh, starting_fuel ); REQUIRE( std::abs( starting_fuel_per - 1.0f ) < 0.001f ); const tripoint starting_point = veh.global_pos3(); veh.tags.insert( "IN_CONTROL_OVERRIDE" ); veh.engine_on = true; const int target_velocity = std::min( 70 * 100, veh.safe_ground_velocity( false ) ); veh.cruise_velocity = target_velocity; // If we aren't testing repeated cold starts, start the vehicle at cruising velocity. // Otherwise changing the amount of fuel in the tank perturbs the test results. if( reset_velocity_turn == -1 ) { veh.velocity = target_velocity; } int reset_counter = 0; long tiles_travelled = 0; int cycles_left = cycle_limit; bool accelerating = true; CHECK( veh.safe_velocity() > 0 ); while( veh.engine_on && veh.safe_velocity() > 0 && cycles_left > 0 ) { cycles_left--; g->m.vehmove(); veh.idle( true ); // If the vehicle starts skidding, the effects become random and test is RUINED REQUIRE( !veh.skidding ); for( const tripoint &pos : veh.get_points() ) { REQUIRE( g->m.ter( pos ) ); } // How much it moved tiles_travelled += square_dist( starting_point, veh.global_pos3() ); // Bring it back to starting point to prevent it from leaving the map const tripoint displacement = starting_point - veh.global_pos3(); tripoint veh_pos = veh.global_pos3(); g->m.displace_vehicle( veh_pos, displacement ); if( reset_velocity_turn < 0 ) { continue; } reset_counter++; if( reset_counter > reset_velocity_turn ) { if( smooth_stops ) { accelerating = !accelerating; veh.cruise_velocity = accelerating ? target_velocity : 0; } else { veh.velocity = 0; veh.last_turn = 0; veh.of_turn_carry = 0; } reset_counter = 0; } } float fuel_left = fuel_percentage_left( veh, starting_fuel ); REQUIRE( starting_fuel_per - fuel_left > 0.0001f ); const float fuel_percentage_used = fuel_level * ( starting_fuel_per - fuel_left ); long adjusted_tiles_travelled = tiles_travelled / fuel_percentage_used; if( target_distance >= 0 ) { CHECK( adjusted_tiles_travelled >= min_dist ); CHECK( adjusted_tiles_travelled <= max_dist ); } return adjusted_tiles_travelled; }
void load_city_2(char *cname) { int i, x, y, p; int dumbint = 0; int num_pbars, pbar_data_size; int pbar_tmp; int dummy; gzFile gzfile; char s[512]; clear_game(); gzfile = gzopen(cname, "rb"); if (gzfile == NULL) { printf(_("Can't open <%s> (gzipped)"), cname); do_error("Can't open it!"); } sscanf(gzgets(gzfile, s, 256), "%d", &ldsv_version); if (ldsv_version < WATERWELL_V2) { gzclose(gzfile); load_city_old( cname ); /* Fix desert frontier for old saved games and scenarios */ desert_frontier(0, 0, WORLD_SIDE_LEN, WORLD_SIDE_LEN); return; } fprintf(stderr, " ldsv_version = %i \n", ldsv_version); use_waterwell = true; init_pbars(); num_pbars = NUM_PBARS; pbar_data_size = PBAR_DATA_SIZE; init_inventory(); print_time_for_year(); // Easier debugging from saved game: #Line = 100 x + y + 1 (first line = ldsv_version) for (x = 0; x < WORLD_SIDE_LEN; x++) { for (y = 0; y < WORLD_SIDE_LEN; y++) { gzgets(gzfile, s, 512); // TY po fl cr or i1 i2 i3 i4 i5 i6 i7 PL al ec ws gp wa wp ww wn g1 g2 g3 g4 DA TK AN d4 d5 d6 d7 d8 d9 sscanf(s, "%hi %d %i %hu %hu %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d" , &MP_TYPE(x, y) , &MP_INFO(x, y).population , &MP_INFO(x, y).flags , &MP_INFO(x, y).coal_reserve , &MP_INFO(x, y).ore_reserve , &MP_INFO(x, y).int_1 , &MP_INFO(x, y).int_2 , &MP_INFO(x, y).int_3 , &MP_INFO(x, y).int_4 , &MP_INFO(x, y).int_5 , &MP_INFO(x, y).int_6 , &MP_INFO(x, y).int_7 , &MP_POL(x, y) , &ground[x][y].altitude , &ground[x][y].ecotable , &ground[x][y].wastes , &ground[x][y].pollution , &ground[x][y].water_alt , &ground[x][y].water_pol , &ground[x][y].water_wast , &ground[x][y].water_next , &ground[x][y].int1 , &ground[x][y].int2 , &ground[x][y].int3 , &ground[x][y].int4 , &MP_DATE(x,y) // d1 = date of built , &MP_TECH(x,y) // d2 = tech at build time , &MP_ANIM(x,y) // d3 = animation_time (see reset_animation_time mess :) , &dumbint // d4 could be image index for smooth animation, cf windmill anim_tile , &dumbint // d5 percentage of activity to choose family of pic , &dumbint // d6 , &dumbint // d7 , &dumbint // d8 , &dumbint // d9 ); if (get_group_of_type(MP_TYPE(x, y)) == GROUP_MARKET) inventory(x, y); } } set_map_groups(); sscanf(gzgets(gzfile, s, 256), "%d", &main_screen_originx); sscanf(gzgets(gzfile, s, 256), "%d", &main_screen_originy); sscanf(gzgets(gzfile, s, 256), "%d", &total_time); for (x = 0; x < MAX_NUMOF_SUBSTATIONS; x++) { sscanf(gzgets(gzfile, s, 256), "%d", &substationx[x]); sscanf(gzgets(gzfile, s, 256), "%d", &substationy[x]); } sscanf(gzgets(gzfile, s, 256), "%d", &numof_substations); for (x = 0; x < MAX_NUMOF_MARKETS; x++) { sscanf(gzgets(gzfile, s, 256), "%d", &marketx[x]); sscanf(gzgets(gzfile, s, 256), "%d", &markety[x]); } sscanf(gzgets(gzfile, s, 256), "%d", &numof_markets); sscanf(gzgets(gzfile, s, 256), "%d", &people_pool); sscanf(gzgets(gzfile, s, 256), "%o", &total_money); sscanf(gzgets(gzfile, s, 256), "%d", &income_tax_rate); sscanf(gzgets(gzfile, s, 256), "%d", &coal_tax_rate); sscanf(gzgets(gzfile, s, 256), "%d", &dole_rate); sscanf(gzgets(gzfile, s, 256), "%d", &transport_cost_rate); sscanf(gzgets(gzfile, s, 256), "%d", &goods_tax_rate); sscanf(gzgets(gzfile, s, 256), "%d", &export_tax); sscanf(gzgets(gzfile, s, 256), "%d", &export_tax_rate); sscanf(gzgets(gzfile, s, 256), "%d", &import_cost); sscanf(gzgets(gzfile, s, 256), "%d", &import_cost_rate); sscanf(gzgets(gzfile, s, 256), "%d", &tech_level); sscanf(gzgets(gzfile, s, 256), "%d", &tpopulation); sscanf(gzgets(gzfile, s, 256), "%d", &tstarving_population); sscanf(gzgets(gzfile, s, 256), "%d", &tunemployed_population); sscanf(gzgets(gzfile, s, 256), "%d", &x); /* waste_goods obsolete */ sscanf(gzgets(gzfile, s, 256), "%d", &power_made); sscanf(gzgets(gzfile, s, 256), "%d", &power_used); sscanf(gzgets(gzfile, s, 256), "%d", &coal_made); sscanf(gzgets(gzfile, s, 256), "%d", &coal_used); sscanf(gzgets(gzfile, s, 256), "%d", &goods_made); sscanf(gzgets(gzfile, s, 256), "%d", &goods_used); sscanf(gzgets(gzfile, s, 256), "%d", &ore_made); sscanf(gzgets(gzfile, s, 256), "%d", &ore_used); sscanf(gzgets(gzfile, s, 256), "%d", &dummy); /* &diff_old_population */ /* Update variables calculated from those above */ housed_population = tpopulation / ((total_time % NUMOF_DAYS_IN_MONTH) + 1); /* Get size of monthgraph array */ sscanf(gzgets(gzfile, s, 256), "%d", &i); for (x = 0; x < i; x++) { /* If more entries in file than will fit on screen, then we need to skip past them. */ if (x >= monthgraph_size) { sscanf(gzgets(gzfile, s, 256), "%d", &dummy); /* &monthgraph_pop[x] */ sscanf(gzgets(gzfile, s, 256), "%d", &dummy); /* &monthgraph_starve[x] */ sscanf(gzgets(gzfile, s, 256), "%d", &dummy); /* &monthgraph_nojobs[x] */ sscanf(gzgets(gzfile, s, 256), "%d", &dummy); /* &monthgraph_ppool[x] */ } else { sscanf(gzgets(gzfile, s, 256), "%d", &monthgraph_pop[x]); sscanf(gzgets(gzfile, s, 256), "%d", &monthgraph_starve[x]); sscanf(gzgets(gzfile, s, 256), "%d", &monthgraph_nojobs[x]); sscanf(gzgets(gzfile, s, 256), "%d", &monthgraph_ppool[x]); } } /* If screen bigger than number of entries in file, pad with zeroes */ while (x < monthgraph_size) { monthgraph_pop[x] = 0; monthgraph_starve[x] = 0; monthgraph_nojobs[x] = 0; monthgraph_ppool[x] = 0; x++; } sscanf(gzgets(gzfile, s, 256), "%d", &rockets_launched); sscanf(gzgets(gzfile, s, 256), "%d", &rockets_launched_success); sscanf(gzgets(gzfile, s, 256), "%d", &coal_survey_done); for (x = 0; x < pbar_data_size; x++) { for (p = 0; p < num_pbars; p++) { sscanf(gzgets(gzfile, s, 256), "%d", &(pbar_tmp)); update_pbar(p, pbar_tmp, 1); } } for (p = 0; p < num_pbars; p++) pbars[p].data_size = pbar_data_size; for (p = 0; p < num_pbars; p++) { sscanf(gzgets(gzfile, s, 256), "%d", &(pbars[p].oldtot)); sscanf(gzgets(gzfile, s, 256), "%d", &(pbars[p].diff)); } sscanf(gzgets(gzfile, s, 256), "%d", &cheat_flag); sscanf(gzgets(gzfile, s, 256), "%d", &total_pollution_deaths); sscanf(gzgets(gzfile, s, 256), "%f", &pollution_deaths_history); sscanf(gzgets(gzfile, s, 256), "%d", &total_starve_deaths); sscanf(gzgets(gzfile, s, 256), "%f", &starve_deaths_history); sscanf(gzgets(gzfile, s, 256), "%d", &total_unemployed_years); sscanf(gzgets(gzfile, s, 256), "%f", &unemployed_history); sscanf(gzgets(gzfile, s, 256), "%d", &max_pop_ever); sscanf(gzgets(gzfile, s, 256), "%d", &total_evacuated); sscanf(gzgets(gzfile, s, 256), "%d", &total_births); for (x = 0; x < NUMOF_MODULES; x++) sscanf(gzgets(gzfile, s, 256), "%d", &(module_help_flag[x])); sscanf(gzgets(gzfile, s, 256), "%128s", given_scene); if (strncmp(given_scene, "dummy", 5) == 0 || strlen(given_scene) < 3) given_scene[0] = 0; sscanf(gzgets(gzfile, s, 256), "%128s", s); if (strncmp(given_scene, "dummy", 5) != 0) sscanf(s, "%d", &highest_tech_level); else highest_tech_level = 0; gzgets(gzfile, s, 200); if (sscanf (s, "sust %d %d %d %d %d %d %d %d %d %d", &sust_dig_ore_coal_count, &sust_port_count, &sust_old_money_count, &sust_old_population_count, &sust_old_tech_count, &sust_fire_count, &sust_old_money, &sust_old_population, &sust_old_tech, &sustain_flag) == 10) { sust_dig_ore_coal_tip_flag = sust_port_flag = 1; } else sustain_flag = sust_dig_ore_coal_count = sust_port_count = sust_old_money_count = sust_old_population_count = sust_old_tech_count = sust_fire_count = sust_old_money = sust_old_population = sust_old_tech = 0; gzgets(gzfile, s, 80); sscanf(s, "arid %d %d", &global_aridity, &global_mountainity); gzclose(gzfile); /* FIXME: AL1 this is initialisation stuff, should go elsewhere */ // Engine stuff if (tech_level > MODERN_WINDMILL_TECH) modern_windmill_flag = 1; numof_shanties = count_groups(GROUP_SHANTY); numof_communes = count_groups(GROUP_COMMUNE); /* set up the university intake. */ x = count_groups(GROUP_UNIVERSITY); if (x > 0) { university_intake_rate = (count_groups(GROUP_SCHOOL) * 20) / x; if (university_intake_rate > 100) university_intake_rate = 100; } else university_intake_rate = 50; print_total_money(); //reset_animation_times //get alt_min, alt_max alt_min = 2000000000; alt_max = -alt_min; for ( y = 0; y < WORLD_SIDE_LEN; y++){ for ( x = 0; x < WORLD_SIDE_LEN; x++) { MP_ANIM(x,y) = 0; if (MP_GROUP(x, y) == GROUP_FIRE){ MP_INFO(x, y).int_3 = 0; } if (alt_min > ALT(x,y)){ alt_min = ALT(x,y); } if (alt_max < ALT(x,y)){ alt_max = ALT(x,y); } } } alt_step = (alt_max - alt_min) /10; map_power_grid(true); /* WCK: Is this safe to do here? * AL1: No, in NG_1.1 * In case of error message with ok_dial_box * the dialog cannot appear because the screen * is not set up => crash. * FIXME: move all initialisation elsewhere, in * engine.cpp or simulate.cpp. */ // UI stuff if (main_screen_originx > WORLD_SIDE_LEN - getMainWindowWidth() / 16 - 1) main_screen_originx = WORLD_SIDE_LEN - getMainWindowWidth() / 16 - 1; if (main_screen_originy > WORLD_SIDE_LEN - getMainWindowHeight() / 16 - 1) main_screen_originy = WORLD_SIDE_LEN - getMainWindowHeight() / 16 - 1; unhighlight_module_button(selected_module); selected_module = sbut[7]; /* 7 is track. Watch out though! */ highlight_module_button(selected_module); set_selected_module(CST_TRACK_LR); connect_transport(1, 1, WORLD_SIDE_LEN - 2, WORLD_SIDE_LEN - 2); /* Fix desert frontier for old saved games and scenarios */ desert_frontier(0, 0, WORLD_SIDE_LEN, WORLD_SIDE_LEN); }
// Algorithm goes as follows: // Clear map // Spawn a vehicle // Set its fuel up to some percentage - remember exact fuel counts that were set here // Drive it for a while, always moving it back to start point every turn to avoid it going off the bubble // When moving back, record the sum of the tiles moved so far // Repeat that for a set number of turns or until all fuel is drained // Compare saved percentage (set before) to current percentage // Rescale the recorded number of tiles based on fuel percentage left // (ie. 0% fuel left means no scaling, 50% fuel left means double the effective distance) // Return the rescaled number long test_efficiency( const vproto_id &veh_id, const ter_id &terrain, int reset_velocity_turn, long target_distance, bool smooth_stops = false ) { long min_dist = target_distance * 0.99; long max_dist = target_distance * 1.01; clear_game( terrain ); const tripoint map_starting_point( 60, 60, 0 ); vehicle *veh_ptr = g->m.add_vehicle( veh_id, map_starting_point, -90, 100, 0 ); REQUIRE( veh_ptr != nullptr ); if( veh_ptr == nullptr ) { return 0; } vehicle &veh = *veh_ptr; // Remove all items from cargo to normalize weight. for( size_t p = 0; p < veh.parts.size(); p++ ) { auto &pt = veh.parts[ p ]; while( veh.remove_item( p, 0 ) ); } const auto &starting_fuel = set_vehicle_fuel( veh, fuel_level ); // This is ugly, but improves accuracy: compare the result of fuel approx function // rather than the amount of fuel we actually requested const float starting_fuel_per = fuel_percentage_left( veh, starting_fuel ); REQUIRE( std::abs( starting_fuel_per - 1.0f ) < 0.001f ); const tripoint starting_point = veh.global_pos3(); veh.tags.insert( "IN_CONTROL_OVERRIDE" ); veh.engine_on = true; veh.cruise_velocity = veh.safe_velocity(); // If we aren't testing repeated cold starts, start the vehicle at cruising velocity. // Otherwise changing the amount of fuel in the tank perturbs the test results. if( reset_velocity_turn == -1 ) { veh.velocity = veh.cruise_velocity; } int reset_counter = 0; long tiles_travelled = 0; int turn_count = 0; int cycles_left = cycle_limit; bool accelerating = true; CHECK( veh.safe_velocity() > 0 ); while( veh.engine_on && veh.safe_velocity() > 0 && cycles_left > 0 ) { cycles_left--; g->m.vehmove(); veh.idle( true ); // If the vehicle starts skidding, the effects become random and test is RUINED REQUIRE( !veh.skidding ); // How much it moved tiles_travelled += square_dist( starting_point, veh.global_pos3() ); // Bring it back to starting point to prevent it from leaving the map const tripoint displacement = starting_point - veh.global_pos3(); tripoint veh_pos = veh.global_pos3(); g->m.displace_vehicle( veh_pos, displacement ); if( reset_velocity_turn < 0 ) { continue; } reset_counter++; if( reset_counter > reset_velocity_turn ) { if( smooth_stops ) { accelerating = !accelerating; veh.cruise_velocity = accelerating ? veh.safe_velocity() : 0; } else { veh.velocity = 0; veh.last_turn = 0; veh.of_turn_carry = 0; } reset_counter = 0; } } float fuel_left = fuel_percentage_left( veh, starting_fuel ); REQUIRE( starting_fuel_per - fuel_left > 0.0001f ); float fuel_percentage_used = fuel_level * ( starting_fuel_per - fuel_left ); long adjusted_tiles_travelled = tiles_travelled / fuel_percentage_used; if( target_distance >= 0 ) { CHECK( adjusted_tiles_travelled >= min_dist ); CHECK( adjusted_tiles_travelled <= max_dist ); } return adjusted_tiles_travelled; }