Translate histfig mats into creature mats, rather than sending the entire histfig population.

develop
Japa 2016-08-26 23:48:32 +05:30
parent 91cb734a25
commit 7d145de4a7
1 changed files with 365 additions and 372 deletions

@ -855,6 +855,22 @@ static command_result CheckHashes(color_ostream &stream, const EmptyMessage *in)
return CR_OK;
}
void CopyMat(RemoteFortressReader::MatPair * mat, int type, int index)
{
if (type >= MaterialInfo::FIGURE_BASE && type < MaterialInfo::PLANT_BASE)
{
df::historical_figure * figure = df::historical_figure::find(index);
if (figure)
{
type -= MaterialInfo::GROUP_SIZE;
index = figure->race;
}
}
mat->set_mat_type(type);
mat->set_mat_index(index);
}
map<DFCoord, uint16_t> hashes;
//check if the tiletypes have changed
@ -1033,31 +1049,31 @@ static command_result GetMaterialList(color_ostream &stream, const EmptyMessage
}
}
}
for (int i = 0; i < history->figures.size(); i++)
{
df::historical_figure * figure = history->figures[i];
if (figure->race < 0)
continue;
df::creature_raw * creature = raws->creatures.all[figure->race];
for (int j = 0; j < creature->material.size(); j++)
{
mat.decode(j + MaterialInfo::FIGURE_BASE, i);
MaterialDefinition *mat_def = out->add_material_list();
mat_def->mutable_mat_pair()->set_mat_type(j + MaterialInfo::FIGURE_BASE);
mat_def->mutable_mat_pair()->set_mat_index(i);
stringstream id;
id << "HF" << i << mat.getToken();
mat_def->set_id(id.str());
mat_def->set_name(mat.toString()); //find the name at cave temperature;
if (creature->material[j]->state_color[GetState(creature->material[j])] < raws->language.colors.size())
{
df::descriptor_color *color = raws->language.colors[creature->material[j]->state_color[GetState(creature->material[j])]];
mat_def->mutable_state_color()->set_red(color->red * 255);
mat_def->mutable_state_color()->set_green(color->green * 255);
mat_def->mutable_state_color()->set_blue(color->blue * 255);
}
}
}
//for (int i = 0; i < history->figures.size(); i++)
//{
// df::historical_figure * figure = history->figures[i];
// if (figure->race < 0)
// continue;
// df::creature_raw * creature = raws->creatures.all[figure->race];
// for (int j = 0; j < creature->material.size(); j++)
// {
// mat.decode(j + MaterialInfo::FIGURE_BASE, i);
// MaterialDefinition *mat_def = out->add_material_list();
// mat_def->mutable_mat_pair()->set_mat_type(j + MaterialInfo::FIGURE_BASE);
// mat_def->mutable_mat_pair()->set_mat_index(i);
// stringstream id;
// id << "HF" << i << mat.getToken();
// mat_def->set_id(id.str());
// mat_def->set_name(mat.toString()); //find the name at cave temperature;
// if (creature->material[j]->state_color[GetState(creature->material[j])] < raws->language.colors.size())
// {
// df::descriptor_color *color = raws->language.colors[creature->material[j]->state_color[GetState(creature->material[j])]];
// mat_def->mutable_state_color()->set_red(color->red * 255);
// mat_def->mutable_state_color()->set_green(color->green * 255);
// mat_def->mutable_state_color()->set_blue(color->blue * 255);
// }
// }
//}
for (int i = 0; i < raws->plants.all.size(); i++)
{
df::plant_raw * plant = raws->plants.all[i];
@ -1241,28 +1257,18 @@ void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBloc
default:
break;
}
RemoteFortressReader::MatPair * material = NetBlock->add_materials();
material->set_mat_type(staticMat.mat_type);
material->set_mat_index(staticMat.mat_index);
RemoteFortressReader::MatPair * layerMaterial = NetBlock->add_layer_materials();
layerMaterial->set_mat_type(0);
layerMaterial->set_mat_index(block->layerMaterialAt(p));
RemoteFortressReader::MatPair * veinMaterial = NetBlock->add_vein_materials();
veinMaterial->set_mat_type(0);
veinMaterial->set_mat_index(block->veinMaterialAt(p));
RemoteFortressReader::MatPair * baseMaterial = NetBlock->add_base_materials();
baseMaterial->set_mat_type(baseMat.mat_type);
baseMaterial->set_mat_index(baseMat.mat_index);
CopyMat(NetBlock->add_materials(), staticMat.mat_type, staticMat.mat_index);
CopyMat(NetBlock->add_layer_materials(), 0, block->layerMaterialAt(p));
CopyMat(NetBlock->add_vein_materials(), 0, block->veinMaterialAt(p));
CopyMat(NetBlock->add_base_materials(), baseMat.mat_type, baseMat.mat_index);
RemoteFortressReader::MatPair * constructionItem = NetBlock->add_construction_items();
constructionItem->set_mat_type(-1);
constructionItem->set_mat_index(-1);
CopyMat(constructionItem, -1, -1);
if (tileMaterial(tile) == tiletype_material::CONSTRUCTION)
{
df::construction *con = df::construction::find(DfBlock->map_pos + df::coord(xx, yy, 0));
if (con)
{
constructionItem->set_mat_type(con->item_type);
constructionItem->set_mat_index(con->item_subtype);
CopyMat(constructionItem, con->item_type, con->item_subtype);
}
}
NetBlock->add_tree_percent(trunk_percent[xx][yy]);
@ -1388,9 +1394,7 @@ void Copyspatters(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetB
continue;
auto send_spat = send_pile->add_spatters();
send_spat->set_state((MatterState)mat->mat_state);
auto send_mat = send_spat->mutable_material();
send_mat->set_mat_index(mat->mat_index);
send_mat->set_mat_type(mat->mat_type);
CopyMat(send_spat->mutable_material(), mat->mat_type, mat->mat_index);
send_spat->set_amount(mat->amount[xx][yy]);
}
for each (auto item in items)
@ -1398,9 +1402,7 @@ void Copyspatters(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetB
if (item->amount[xx][yy] == 0)
continue;
auto send_spat = send_pile->add_spatters();
auto send_mat = send_spat->mutable_material();
send_mat->set_mat_index(item->matindex);
send_mat->set_mat_type(item->mattype);
CopyMat(send_spat->mutable_material(), item->mattype, item->matindex);
send_spat->set_amount(item->amount[xx][yy]);
auto send_item = send_spat->mutable_item();
send_item->set_mat_type(item->item_type);
@ -2469,15 +2471,12 @@ static void CopyLocalMap(df::world_data * worldData, df::world_region_details* w
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);
CopyMat(out_building->mutable_material(), in_building->item.mat_type, in_building->item.mat_index);
STRICT_VIRTUAL_CAST_VAR(tower_info, df::site_realization_building_info_castle_towerst, in_building->building_info);
if (tower_info)
{
mat->set_mat_index(tower_info->wall_item.mat_index);
mat->set_mat_type(tower_info->wall_item.mat_type);
CopyMat(out_building->mutable_material(), tower_info->wall_item.mat_type, tower_info->wall_item.mat_index);
auto out_tower = out_building->mutable_tower_info();
out_tower->set_roof_z(tower_info->roof_z);
@ -2487,8 +2486,7 @@ static void CopyLocalMap(df::world_data * worldData, df::world_region_details* w
STRICT_VIRTUAL_CAST_VAR(wall_info, df::site_realization_building_info_castle_wallst, in_building->building_info);
if (wall_info)
{
mat->set_mat_index(wall_info->wall_item.mat_index);
mat->set_mat_type(wall_info->wall_item.mat_type);
CopyMat(out_building->mutable_material(), wall_info->wall_item.mat_type, wall_info->wall_item.mat_index);
auto out_wall = out_building->mutable_wall_info();
@ -2720,10 +2718,7 @@ static command_result GetCreatureRaws(color_ostream &stream, const EmptyMessage
send_tissue->set_name(orig_tissue->tissue_name_singular);
send_tissue->set_subordinate_to_tissue(orig_tissue->subordinate_to_tissue);
auto send_mat = send_tissue->mutable_material();
send_mat->set_mat_index(orig_tissue->mat_index);
send_mat->set_mat_type(orig_tissue->mat_type);
CopyMat(send_tissue->mutable_material(), orig_tissue->mat_type, orig_tissue->mat_index);
}
}
@ -2779,9 +2774,7 @@ static command_result GetPlantRaws(color_ostream &stream, const EmptyMessage *in
growth_remote->set_timing_end(growth_local->timing_2);
growth_remote->set_trunk_height_start(growth_local->trunk_height_perc_1);
growth_remote->set_trunk_height_end(growth_local->trunk_height_perc_2);
auto growthMat = growth_remote->mutable_mat();
growthMat->set_mat_index(growth_local->mat_index);
growthMat->set_mat_type(growth_local->mat_type);
CopyMat(growth_remote->mutable_mat(), growth_local->mat_type, growth_local->mat_index);
}
}
return CR_OK;