#include "settlement/core/checkpoint.hpp" #include #include #include #include #include #include using namespace settlement; constexpr Void::Uuid::Uuid uuid{{0x91,2,3,4,5,6,0x47,8,0x89,10,11,12,13,14,15,16}}; std::string prefix; void capture(const World& world, const std::string& name) { auto rules=default_rules_manifest(); auto data=encode_checkpoint(world,uuid,7,*rules); if(!data) throw std::runtime_error(data.error().message); std::ofstream(prefix+name+".checkpoint",std::ios::binary).write(data->data(),data->size()); std::ofstream raw(prefix+name+".raw14",std::ios::binary); world.write_save(raw,WorldSaveFormat::Current14);raw.close(); std::ofstream legacy(prefix+name+".raw13",std::ios::binary); world.write_save(legacy,WorldSaveFormat::Legacy13);legacy.close(); const auto&a=world.agents().front(); std::cout<write_save(frame,WorldSaveFormat::Legacy13); const auto bytes=frame.str(); std::uint32_t count=bytes.size(); continuation.write(reinterpret_cast(&count),4); continuation.write(bytes.data(),bytes.size()); copy->step();} } int main(int argc,char**argv){ if(argc!=2)return 2;prefix=argv[1]; World w(43,20,8,1,ExecutionMode::SerialReference); auto a=w.add_storage({3,3},20),b=w.add_storage({8,3},20); w.stock_storage(a,ItemType::Plank,3);w.stock_storage(b,ItemType::StoneBlock,2); (void)w.spawn_agent({1,3}); w.queue_production({14,3},RecipeId::BuildCabin); std::set seen; for(unsigned i=0;i<80;++i){w.step();const auto&agent=w.agents().front();const auto&o=w.production_orders().front(); std::string name; if(agent.state==AgentState::FetchingMaterials)name="cabin-before-pickup"; if(agent.state==AgentState::Hauling&&o.collected_stops==1)name="cabin-between-stops"; if(agent.state==AgentState::Hauling&&o.collected_stops==2)name="cabin-to-site"; if(agent.state==AgentState::Working)name="cabin-working"; if(!name.empty()&&seen.insert(name).second)capture(w,name); } for(auto recipe:{RecipeId::SawPlank,RecipeId::CutStoneBlock,RecipeId::WeaveCloth}){ World d(43,20,8,1,ExecutionMode::SerialReference);auto s=d.add_storage({3,3},20); d.stock_storage(s,recipe==RecipeId::SawPlank?ItemType::Wood:recipe==RecipeId::CutStoneBlock?ItemType::Stone:ItemType::Flax,1); (void)d.spawn_agent({2,3});d.queue_production({6,3},recipe); for(int i=0;i<40;++i){d.step();if(d.agents().front().state==AgentState::Working){capture(d,"direct-"+std::to_string(int(recipe)));break;}} } World c(43,24,24,1,ExecutionMode::SerialReference);c.start_scenario({2,2});auto s=c.add_storage({3,3},20);c.stock_storage(s,ItemType::Wood,5); const auto carpenter=c.spawn_agent({2,3}); (void)c.apply_command({1,1,CommandKind::AssignProfession,{},static_cast(Profession::Carpenter),{},carpenter});c.queue_production(*c.carpenter_workshop(),RecipeId::CraftWoodenDoor); for(int i=0;i<120;++i){c.step();if(c.agents().front().state==AgentState::Hauling&&c.agents().front().production_id==0&&c.agents().front().inventory.item_count(ItemType::WoodenDoor)){capture(c,"carpenter-output");break;}} World h(43,20,8,1,ExecutionMode::SerialReference);(void)h.add_storage({14,3},20);(void)h.add_resource_node({3,3},ItemType::Wood,1);(void)h.spawn_agent({1,3}); bool gathering=false,hauling=false; for(int i=0;i<60;++i){h.step();if(!gathering&&h.agents().front().state==AgentState::Gathering){capture(h,"harvest-gathering");gathering=true;}if(!hauling&&h.agents().front().state==AgentState::Hauling){capture(h,"harvest-hauled");hauling=true;}} World m(43,20,8,1,ExecutionMode::SerialReference);auto pantry=m.add_storage({14,3},20,StorageKind::Pantry);m.stock_storage(pantry,ItemType::Berries,5);(void)m.spawn_agent({1,3});m.enable_hunger(); bool going=false,eating=false; for(int i=0;i<220;++i){m.step();if(!going&&m.agents().front().state==AgentState::GoingToEat){capture(m,"meal-going");going=true;}if(!eating&&m.agents().front().state==AgentState::Eating){capture(m,"meal-eating");eating=true;}} World t(43,20,8,1,ExecutionMode::SerialReference);t.start_scenario({2,2});(void)t.spawn_agent({1,3});(void)t.apply_command({1,1,CommandKind::PlaceTreePlot,{5,3}}); bool tending=false; for(int i=0;i<60;++i){t.step();if(t.agents().front().state==AgentState::Gathering&&t.agents().front().storage_id==0){capture(t,"tending");tending=true;break;}} return seen.size()==4&&gathering&&hauling&&going&&eating&&tending?0:3; }