Added tree coords to remotefortressreader.cpp

develop
Japa 2016-01-12 00:10:16 +05:30
parent ed62f0f554
commit f02a504a00
2 changed files with 108 additions and 0 deletions

@ -164,6 +164,10 @@ message MapBlock
repeated bool water_salt = 17; repeated bool water_salt = 17;
repeated MatPair construction_items = 18; repeated MatPair construction_items = 18;
repeated BuildingInstance buildings = 19; repeated BuildingInstance buildings = 19;
repeated int32 tree_percent = 20;
repeated int32 tree_x = 21;
repeated int32 tree_y = 22;
repeated int32 tree_z = 23;
} }
message MatPair { message MatPair {
@ -407,3 +411,39 @@ message ArmyList
{ {
repeated Army armies = 1; repeated Army armies = 1;
} }
message GrowthPrint
{
optional int32 priority = 1;
optional int32 color = 2;
optional int32 timing_start = 3;
optional int32 timing_end = 4;
}
message TreeGrowth
{
optional int32 index = 1;
optional string id = 2;
optional string name = 3;
optional MatPair mat = 4;
repeated GrowthPrint prints = 5;
optional int32 timing_start = 6;
optional int32 timing_end = 7;
optional bool twigs = 8;
optional bool light_branches = 9;
optional bool heavy_branches = 10;
optional bool trunk = 11;
optional bool roots = 12;
optional bool cap = 13;
optional bool sapling = 14;
optional int32 trunk_height_start = 15;
optional int32 trunk_height_end = 16;
}
message PlantRaw
{
optional int32 index = 1;
optional string id = 2;
repeated string name = 3;
repeated TreeGrowth growths = 4;
}

@ -26,7 +26,9 @@
#include "df/plant.h" #include "df/plant.h"
#if DF_VERSION > 40001 #if DF_VERSION > 40001
#include "df/plant_tree_info.h" #include "df/plant_tree_info.h"
#include "df/plant_tree_tile.h"
#include "df/plant_growth.h" #include "df/plant_growth.h"
#include "df/plant_growth_print.h"
#endif #endif
#include "df/itemdef.h" #include "df/itemdef.h"
#include "df/building_def_workshopst.h" #include "df/building_def_workshopst.h"
@ -1018,6 +1020,68 @@ void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBloc
NetBlock->set_map_z(DfBlock->map_pos.z); NetBlock->set_map_z(DfBlock->map_pos.z);
MapExtras::Block * block = MC->BlockAtTile(DfBlock->map_pos); MapExtras::Block * block = MC->BlockAtTile(DfBlock->map_pos);
int trunk_percent[16][16];
int tree_x[16][16];
int tree_y[16][16];
int tree_z[16][16];
for (int xx = 0; xx < 16; xx++)
for (int yy = 0; yy < 16; yy++)
{
trunk_percent[xx][yy] = 255;
tree_x[xx][yy] = -3000;
tree_y[xx][yy] = -3000;
tree_z[xx][yy] = -3000;
}
df::map_block_column * column = df::global::world->map.column_index[(DfBlock->map_pos.x / 48) * 3][(DfBlock->map_pos.y / 48) * 3];
for (int i = 0; i < column->plants.size(); i++)
{
df::plant* plant = column->plants[i];
if (plant->tree_info == NULL)
continue;
df::plant_tree_info * tree_info = plant->tree_info;
if (
plant->pos.z - tree_info->roots_depth > DfBlock->map_pos.z
|| (plant->pos.z + tree_info->body_height) <= DfBlock->map_pos.z
|| (plant->pos.x - tree_info->dim_x / 2) > (DfBlock->map_pos.x + 16)
|| (plant->pos.x + tree_info->dim_x / 2) < (DfBlock->map_pos.x)
|| (plant->pos.y - tree_info->dim_y / 2) > (DfBlock->map_pos.y + 16)
|| (plant->pos.y + tree_info->dim_y / 2) < (DfBlock->map_pos.y)
)
continue;
DFCoord localPos = plant->pos - DfBlock->map_pos;
for (int xx = 0; xx < tree_info->dim_x; xx++)
for (int yy = 0; yy < tree_info->dim_y; yy++)
{
int xxx = localPos.x - (tree_info->dim_x / 2) + xx;
int yyy = localPos.y - (tree_info->dim_y / 2) + yy;
if (xxx < 0
|| yyy < 0
|| xxx >= 16
|| yyy >= 16
)
continue;
df::plant_tree_tile tile;
if (-localPos.z < 0)
{
tile = tree_info->roots[-1 + localPos.z][xx + (yy*tree_info->dim_x)];
}
else
{
tile = tree_info->body[-localPos.z][xx + (yy*tree_info->dim_x)];
}
if (!tile.whole || tile.bits.blocked)
continue;
if (tree_info->body_height <= 1)
trunk_percent[xxx][yyy] = 0;
else
trunk_percent[xxx][yyy] = -localPos.z * 100 / (tree_info->body_height - 1);
tree_x[xxx][yyy] = xx - tree_info->dim_x / 2;
tree_y[xxx][yyy] = yy - tree_info->dim_y / 2;
tree_z[xxx][yyy] = localPos.z;
}
}
for (int yy = 0; yy < 16; yy++) for (int yy = 0; yy < 16; yy++)
for (int xx = 0; xx < 16; xx++) for (int xx = 0; xx < 16; xx++)
{ {
@ -1059,6 +1123,10 @@ void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBloc
constructionItem->set_mat_index(con->item_subtype); constructionItem->set_mat_index(con->item_subtype);
} }
} }
NetBlock->add_tree_percent(trunk_percent[xx][yy]);
NetBlock->add_tree_x(tree_x[xx][yy]);
NetBlock->add_tree_y(tree_y[xx][yy]);
NetBlock->add_tree_z(tree_z[xx][yy]);
} }
} }