void Model::newSimulation() { try { TimerPtr timer(new Timer(time(NULL))); world_ = WorldPtr(new World(dbName_, dbUser_, dbPassword_)); objectManager_ = ObjectManagerPtr(new ObjectManager(world_, timer, dbName_, dbUser_, dbPassword_, objectsLimit_)); addSimulationPart(std::dynamic_pointer_cast<SimulationPart>(timer)); addSimulationPart(std::dynamic_pointer_cast<SimulationPart>(world_)); addSimulationPart(std::dynamic_pointer_cast<SimulationPart>(objectManager_)); } catch(GeneralException& e) { std::cout << "An unhandable problem occured while running application" << std::endl; std::cout << "Application will be killed as there is nothing we can do." << std::endl; std::cout << "Here are some details: " << std::endl; std::cout << e.what(); std::cout << "\nHTH." << std::endl; exit(1); } }
//pass over the map, calculate the temp & moisture void TerraformClimate () { int x, y; float rainfall, rain_loss, temp; Region r; GLvector2 from_center; float distance; GLcoord walk; World* w; rainfall = 1.0f; w = WorldPtr (); walk.Clear (); do { //Wind (and thus rainfall) come from west. if (w->wind_from_west) x = walk.x; else x = (WORLD_GRID - 1) - walk.x; y = walk.y; r = WorldRegionGet (x, y); //************ TEMPERATURE *******************// //The north 25% is max cold. The south 25% is all tropical //On a southern hemisphere map, this is reversed. if (w->northern_hemisphere) temp = ((float)y - (WORLD_GRID / 4)) / WORLD_GRID_CENTER; else temp = ((float)(WORLD_GRID - y) - (WORLD_GRID / 4)) / WORLD_GRID_CENTER; //Mountains are cooler at the top if (r.mountain_height) temp -= (float)r.mountain_height * 0.15f; //We add a slight bit of heat to the center of the map, to //round off climate boundaries. from_center = glVector ((float)(x - WORLD_GRID_CENTER), (float)(x - WORLD_GRID_CENTER)); distance = from_center.Length () / WORLD_GRID_CENTER; temp += distance * 0.2f; temp = clamp (temp, MIN_TEMP, MAX_TEMP); //************ RAINFALL *******************// //Oceans are ALWAYS WET. if (r.climate == CLIMATE_OCEAN) rainfall = 1.0f; rain_loss = 0.0f; //We lose rainfall as we move inland. if (r.climate != CLIMATE_OCEAN && r.climate != CLIMATE_COAST && r.climate != CLIMATE_LAKE) rain_loss = 1.0f / WORLD_GRID_CENTER; //We lose rainfall more slowly as it gets colder. if (temp < 0.5f) rain_loss *= temp; rainfall -= rain_loss; //Mountains block rainfall if (r.climate == CLIMATE_MOUNTAIN) rainfall -= 0.1f * r.mountain_height; r.moisture = max (rainfall, 0); //Rivers always give some moisture if (r.climate == CLIMATE_RIVER || r.climate == CLIMATE_RIVER_BANK) { r.moisture = max (r.moisture, 0.75f); rainfall += 0.05f; rainfall = min (rainfall, 1); } //oceans have a moderating effect on climate if (r.climate == CLIMATE_OCEAN) temp = (temp + 0.5f) / 2.0f; r.temperature = temp; //r.moisture = min (1, r.moisture + WorldNoisef (walk.x + walk.y * WORLD_GRID) * 0.1f); //r.temperature = min (1, r.temperature + WorldNoisef (walk.x + walk.y * WORLD_GRID) * 0.1f); WorldRegionSet (x, y, r); } while (!walk.Walk (WORLD_GRID)); }