void yaml_oarchive_t::end_map() { RAMEN_ASSERT( map_level() > 0); out_ << YAML::EndMap; --map_level_; check_errors(); }
void yaml_oarchive_t::write_to_file( const boost::filesystem::path& p) { RAMEN_ASSERT( map_level() <= 1); if( map_level() == 1) end_map(); boost::filesystem::ofstream ofs( p); if( !ofs.is_open() || !ofs.good()) throw std::runtime_error( "Can't write to file"); if( 1) ofs << out_.c_str(); else { std::string buffer( out_.c_str(), out_.size()); // encrypt & base 64 string ofs << buffer; } std::flush( ofs); ofs.close(); }
void do_work (const RPG_Map_FloorPlan_Configuration_t& mapConfig_in, bool generateLevel_in, const std::string& outputFile_in, bool dump_in, bool random_in) { RPG_TRACE (ACE_TEXT ("::do_work")); // step1: initialize: random seed, string conversion facilities, ... RPG_Dice::initialize (); RPG_Dice_Common_Tools::initStringConversionTables (); RPG_Common_Tools::initStringConversionTables (); RPG_Graphics_Common_Tools::preInitialize (); // step2: generate level data RPG_Engine_Level_t level; if (generateLevel_in) { if (random_in) { level.metadata.environment.plane = RPG_COMMON_PLANE_INVALID; level.metadata.environment.terrain = RPG_COMMON_TERRAIN_INVALID; level.metadata.environment.climate = RPG_COMMON_CLIMATE_INVALID; level.metadata.environment.time = RPG_COMMON_TIMEOFDAY_INVALID; level.metadata.environment.lighting = RPG_COMMON_AMBIENTLIGHTING_INVALID; level.metadata.environment.outdoors = false; level.metadata.max_num_spawned = 0; level.metadata.name.clear(); level.metadata.spawns.clear(); RPG_Engine_Level::random(level.metadata, mapConfig_in, level); } // end IF else { level.metadata.name = ACE_TEXT_ALWAYS_CHAR(RPG_ENGINE_LEVEL_DEF_NAME); level.metadata.environment.plane = RPG_ENGINE_ENVIRONMENT_DEF_PLANE; level.metadata.environment.terrain = RPG_ENGINE_ENVIRONMENT_DEF_TERRAIN; level.metadata.environment.climate = RPG_ENGINE_ENVIRONMENT_DEF_CLIMATE; level.metadata.environment.time = RPG_ENGINE_ENVIRONMENT_DEF_TIMEOFDAY; level.metadata.environment.lighting = RPG_ENGINE_ENVIRONMENT_DEF_LIGHTING; level.metadata.environment.outdoors = RPG_ENGINE_ENVIRONMENT_DEF_OUTDOORS; RPG_Engine_Spawn_t spawn; spawn.spawn.amble_probability = RPG_ENGINE_ENCOUNTER_DEF_AMBLE_PROBABILITY; spawn.spawn.interval.seconds = RPG_ENGINE_ENCOUNTER_DEF_TIMER_INTERVAL; spawn.spawn.interval.u_seconds = 0; spawn.spawn.max_num_spawned = RPG_ENGINE_ENCOUNTER_DEF_NUM_SPAWNED_MAX; spawn.spawn.probability = RPG_ENGINE_ENCOUNTER_DEF_PROBABILITY; spawn.spawn.type = ACE_TEXT_ALWAYS_CHAR(RPG_ENGINE_ENCOUNTER_DEF_TYPE); spawn.timer_id = -1; level.metadata.spawns.push_back(spawn); level.metadata.max_num_spawned = RPG_ENGINE_ENCOUNTER_DEF_NUM_SPAWNED_MAX; RPG_Engine_Level::create(mapConfig_in, level); } // end ELSE } // end IF else { if (random_in) RPG_Map_Level::random(mapConfig_in, level.map); else RPG_Map_Level::create(mapConfig_in, level.map); } // end ELSE // step3: write output file (if any) RPG_Engine_Level engine_level; engine_level.init(level); RPG_Map_Level map_level(level.map); if (!outputFile_in.empty()) { if (generateLevel_in) engine_level.save(outputFile_in); else map_level.save(outputFile_in); } // end IF // step4: display the result if (dump_in) { if (generateLevel_in) engine_level.print(level); else map_level.print(level.map); } // end IF ACE_DEBUG((LM_DEBUG, ACE_TEXT("finished working...\n"))); } // end do_work