From 9189e3dc7e765fad822708c8869163cc1b4af4b7 Mon Sep 17 00:00:00 2001 From: Japa Date: Tue, 2 Aug 2016 10:30:17 +0530 Subject: [PATCH] Send world buildings through remotefortressreader.cpp --- library/xml | 2 +- plugins/proto/RemoteFortressReader.proto | 39 +++++++++++++++++++ plugins/remotefortressreader.cpp | 48 ++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) diff --git a/library/xml b/library/xml index 7d312334c..84f5de34c 160000 --- a/library/xml +++ b/library/xml @@ -1 +1 @@ -Subproject commit 7d312334c320022cd6275cddcdb8a64d4ed8d722 +Subproject commit 84f5de34c1a269420204c81f3244a70843bb9c5c diff --git a/plugins/proto/RemoteFortressReader.proto b/plugins/proto/RemoteFortressReader.proto index 889159682..7422d4962 100644 --- a/plugins/proto/RemoteFortressReader.proto +++ b/plugins/proto/RemoteFortressReader.proto @@ -411,6 +411,44 @@ message WorldMap repeated RegionTile region_tiles = 25; } +enum SiteRealizationBuildingType +{ + cottage_plot = 0; + castle_wall = 1; + castle_tower = 2; + castle_courtyard = 3; + house = 4; + temple = 5; + tomb = 6; + shop_house = 7; + warehouse = 8; + market_square = 9; + pasture = 10; + waste = 11; + courtyard = 12; + well = 13; + vault = 14; + great_tower = 15; + trenches = 16; + tree_house = 17; + hillock_house = 18; + mead_hall = 19; + fortress_entrance = 20; + library = 21; + tavern = 22; +} + +message SiteRealizationBuilding +{ + optional int32 id = 1; + optional SiteRealizationBuildingType type = 2; + optional int32 min_x = 3; + optional int32 min_y = 4; + optional int32 max_x = 5; + optional int32 max_y = 6; + optional MatPair material = 7; +} + message RegionTile { optional int32 elevation = 1; @@ -426,6 +464,7 @@ message RegionTile optional int32 water_elevation = 11; optional MatPair surface_material = 12; repeated MatPair plant_materials = 13; + repeated SiteRealizationBuilding buildings = 14; } message RegionMap diff --git a/plugins/remotefortressreader.cpp b/plugins/remotefortressreader.cpp index 3e372547d..9ab407e7d 100644 --- a/plugins/remotefortressreader.cpp +++ b/plugins/remotefortressreader.cpp @@ -61,6 +61,9 @@ #include "df/world_geo_biome.h" #include "df/world_geo_layer.h" #include "df/world_population.h" +#include "df/world_site.h" +#include "df/world_site_realization.h" +#include "df/site_realization_building.h" #include "df/unit.h" #include "df/creature_raw.h" @@ -2251,10 +2254,13 @@ static void CopyLocalMap(df::world_data * worldData, df::world_region_details* w south = region; } + RegionTile* outputTiles[17][17]; + for (int yy = 0; yy < 17; yy++) for (int xx = 0; xx < 17; xx++) { auto tile = out->add_tiles(); + outputTiles[xx][yy] = tile; //This is because the bottom row doesn't line up. if (xx == 16 && yy == 16 && southEast != NULL) { @@ -2303,6 +2309,48 @@ static void CopyLocalMap(df::world_data * worldData, df::world_region_details* w east->set_min_pos(worldRegionDetails->rivers_horizontal.y_min[xx + 1][yy]); east->set_max_pos(worldRegionDetails->rivers_horizontal.y_max[xx + 1][yy]); } + + auto regionMap = worldData->region_map[pos_x][pos_y]; + + for (int i = 0; i < regionMap.sites.size(); i++) + { + df::world_site* site = regionMap.sites[i]; + + if (site->realization == NULL) + continue; + + int region_min_x = pos_x * 16; + int region_min_y = pos_y * 16; + + auto realization = site->realization; + for (int site_x = 0; site_x < 17; site_x++) + for (int site_y = 0; site_y < 17; site_y++) + { + int region_x = site->global_min_x - region_min_x + site_x; + int region_y = site->global_min_y - region_min_y + site_y; + + if (region_x < 0 || region_y < 0 || region_x >= 16 || region_y >= 16) + continue; + + for (int j = 0; j < realization->building_map[site_x][site_y].buildings.size(); j++) + { + auto in_building = realization->building_map[site_x][site_y].buildings[j]; + auto out_building = outputTiles[region_x][region_y]->add_buildings(); + + out_building->set_id(in_building->id); + out_building->set_type((SiteRealizationBuildingType)in_building->type); + out_building->set_min_x(in_building->min_x - (site_x * 48)); + out_building->set_min_y(in_building->min_y - (site_y * 48)); + out_building->set_max_x(in_building->max_x - (site_x * 48)); + out_building->set_max_y(in_building->max_y - (site_y * 48)); + + auto mat = out_building->mutable_material(); + mat->set_mat_type(in_building->item.mat_type); + mat->set_mat_index(in_building->item.mat_index); + } + + } + } } static command_result GetRegionMaps(color_ostream &stream, const EmptyMessage *in, RegionMaps *out)