void mapgen_generate(mapgen_settings *settings) { sint32 x, y, mapSize, floorTexture, wallTexture, waterLevel; rct_map_element *mapElement; util_srand((sint32)SDL_GetTicks()); mapSize = settings->mapSize; floorTexture = settings->floor; wallTexture = settings->wall; waterLevel = settings->waterLevel; if (floorTexture == -1) floorTexture = BaseTerrain[util_rand() % countof(BaseTerrain)]; if (wallTexture == -1) { // Base edge type on surface type switch (floorTexture) { case TERRAIN_DIRT: wallTexture = TERRAIN_EDGE_WOOD_RED; break; case TERRAIN_ICE: wallTexture = TERRAIN_EDGE_ICE; break; default: wallTexture = TERRAIN_EDGE_ROCK; break; } } map_clear_all_elements(); // Initialise the base map map_init(mapSize); for (y = 1; y < mapSize - 1; y++) { for (x = 1; x < mapSize - 1; x++) { mapElement = map_get_surface_element_at(x, y); map_element_set_terrain(mapElement, floorTexture); map_element_set_terrain_edge(mapElement, wallTexture); mapElement->base_height = settings->height; mapElement->clearance_height = settings->height; } } // Create the temporary height map and initialise _heightSize = mapSize * 2; _height = (uint8*)malloc(_heightSize * _heightSize * sizeof(uint8)); memset(_height, 0, _heightSize * _heightSize * sizeof(uint8)); if (1) { mapgen_simplex(settings); mapgen_smooth_height(2 + (util_rand() % 6)); } else { // Keep overwriting the map with rough cicular blobs of different sizes and heights. // This procedural method can produce intersecting contour like land and lakes. // Large blobs, general shape of map mapgen_blobs(6, _heightSize / 2, _heightSize * 4, 4, 16); // Medium blobs mapgen_blobs(12, _heightSize / 16, _heightSize / 8, 4, 18); // Small blobs, small hills and lakes mapgen_blobs(32, _heightSize / 32, _heightSize / 16, 4, 18); // Smooth the land so that their aren't cliffs round every blob. mapgen_smooth_height(2); } // Set the game map to the height map mapgen_set_height(); free(_height); // Set the tile slopes so that there are no cliffs while (map_smooth(1, 1, mapSize - 1, mapSize - 1)) { } // Add the water mapgen_set_water_level(waterLevel); // Add sandy beaches sint32 beachTexture = floorTexture; if (settings->floor == -1 && floorTexture == TERRAIN_GRASS) { switch (util_rand() % 4) { case 0: beachTexture = TERRAIN_SAND; break; case 1: beachTexture = TERRAIN_SAND_LIGHT; break; } } for (y = 1; y < mapSize - 1; y++) { for (x = 1; x < mapSize - 1; x++) { mapElement = map_get_surface_element_at(x, y); if (mapElement->base_height < waterLevel + 6) map_element_set_terrain(mapElement, beachTexture); } } // Place the trees if (settings->trees != 0) mapgen_place_trees(); map_reorganise_elements(); }
int rct2_init() { log_verbose("initialising game"); RCT2_GLOBAL(RCT2_ADDRESS_SCENARIO_TICKS, uint32) = 0; RCT2_GLOBAL(0x009AC310, char*) = RCT2_GLOBAL(RCT2_ADDRESS_CMDLINE, char*); get_system_time(); util_srand((unsigned int)time(0)); RCT2_GLOBAL(0x009DEA69, short) = RCT2_GLOBAL(RCT2_ADDRESS_OS_TIME_DAY, short); RCT2_GLOBAL(0x009DEA6B, short) = RCT2_GLOBAL(RCT2_ADDRESS_OS_TIME_MONTH, short); if (!rct2_init_directories()) return 0; if (!rct2_startup_checks()) return 0; config_reset_shortcut_keys(); config_shortcut_keys_load(); RCT2_GLOBAL(RCT2_ADDRESS_PLACE_OBJECT_MODIFIER, uint8) = 0; // config_load(); object_list_load(); scenario_load_list(); ride_list_item item = { 253, 0 }; track_load_list(item); gfx_load_g1(); gfx_load_g2(); font_sprite_initialise_characters(); if (!gOpenRCT2Headless) { platform_init(); audio_init_ride_sounds_and_info(); } viewport_init_all(); news_item_init_queue(); get_local_time(); reset_park_entrances(); user_string_clear_all(); reset_sprite_list(); ride_init_all(); window_guest_list_init_vars_a(); staff_reset_modes(); map_init(150); park_init(); if (!gOpenRCT2Headless) window_title_menu_open(); date_reset(); climate_reset(CLIMATE_COOL_AND_WET); scenery_set_default_placement_configuration(); window_new_ride_init_vars(); window_guest_list_init_vars_b(); window_staff_list_init_vars(); if (!gOpenRCT2Headless) { title_load(); gfx_clear(RCT2_ADDRESS(RCT2_ADDRESS_SCREEN_DPI, rct_drawpixelinfo), 10); } log_verbose("initialising game finished"); return 1; }