Merge branch 'develop' of dfhack/dfhack into develop

develop
lethosor 2016-10-29 02:40:14 -04:00
commit a84958a390
2 changed files with 89 additions and 0 deletions

@ -206,6 +206,16 @@ message SpatterPile
repeated Spatter spatters = 1; repeated Spatter spatters = 1;
} }
message Item
{
optional int32 id = 1;
optional Coord pos = 2;
optional uint32 flags1 = 3;
optional uint32 flags2 = 4;
optional MatPair type = 5;
optional MatPair material = 6;
}
message MapBlock message MapBlock
{ {
required int32 map_x = 1; required int32 map_x = 1;
@ -233,6 +243,7 @@ message MapBlock
repeated int32 tree_z = 23; repeated int32 tree_z = 23;
repeated TileDigDesignation tile_dig_designation = 24; repeated TileDigDesignation tile_dig_designation = 24;
repeated SpatterPile spatterPile = 25; repeated SpatterPile spatterPile = 25;
repeated Item items = 26;
} }
message MatPair { message MatPair {

@ -141,6 +141,7 @@ static command_result GetPlantRaws(color_ostream &stream, const EmptyMessage *in
static command_result CopyScreen(color_ostream &stream, const EmptyMessage *in, ScreenCapture *out); static command_result CopyScreen(color_ostream &stream, const EmptyMessage *in, ScreenCapture *out);
static command_result PassKeyboardEvent(color_ostream &stream, const KeyboardEvent *in); static command_result PassKeyboardEvent(color_ostream &stream, const KeyboardEvent *in);
static command_result SendDigCommand(color_ostream &stream, const DigCommand *in); static command_result SendDigCommand(color_ostream &stream, const DigCommand *in);
void CopyItem(RemoteFortressReader::Item * NetItem, df::item * DfItem);
void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBlock, MapExtras::MapCache * MC, DFCoord pos); void CopyBlock(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBlock, MapExtras::MapCache * MC, DFCoord pos);
@ -958,12 +959,42 @@ bool IsspatterChanged(DFCoord pos)
return false; return false;
} }
map<int, uint16_t> itemHashes;
bool isItemChanged(int i)
{
uint16_t hash = 0;
auto item = df::item::find(i);
if (item)
{
hash = fletcher16((uint8_t*)item, sizeof(df::item));
}
if (itemHashes[i] != hash)
{
itemHashes[i] = hash;
return true;
}
return false;
}
bool areItemsChanged(vector<int> * items)
{
bool result = false;
for (int i = 0; i < items->size(); i++)
{
if (isItemChanged(items->at(i)))
result = true;
}
return result;
}
static command_result ResetMapHashes(color_ostream &stream, const EmptyMessage *in) static command_result ResetMapHashes(color_ostream &stream, const EmptyMessage *in)
{ {
hashes.clear(); hashes.clear();
waterHashes.clear(); waterHashes.clear();
buildingHashes.clear(); buildingHashes.clear();
spatterHashes.clear(); spatterHashes.clear();
itemHashes.clear();
return CR_OK; return CR_OK;
} }
@ -1417,6 +1448,17 @@ void CopyBuildings(df::map_block * DfBlock, RemoteFortressReader::MapBlock * Net
continue; continue;
auto out_bld = NetBlock->add_buildings(); auto out_bld = NetBlock->add_buildings();
CopyBuilding(i, out_bld); CopyBuilding(i, out_bld);
//df::building_actual* actualBuilding = strict_virtual_cast<df::building_actual>(bld);
//if (actualBuilding)
//{
// for (int i = 0; i < actualBuilding->contained_items.size(); i++)
// {
// if (isItemChanged(actualBuilding->contained_items[i]->item->id))
// {
// CopyItem(NetBlock->add_items(), actualBuilding->contained_items[i]->item);
// }
// }
//}
} }
} }
@ -1459,6 +1501,39 @@ void Copyspatters(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetB
} }
} }
void CopyItem(RemoteFortressReader::Item * NetItem, df::item * DfItem)
{
NetItem->set_id(DfItem->id);
NetItem->set_flags1(DfItem->flags.whole);
NetItem->set_flags2(DfItem->flags2.whole);
auto pos = NetItem->mutable_pos();
pos->set_x(DfItem->pos.x);
pos->set_y(DfItem->pos.y);
pos->set_z(DfItem->pos.z);
auto mat = NetItem->mutable_material();
mat->set_mat_index(DfItem->getMaterialIndex());
mat->set_mat_type(DfItem->getMaterial());
auto type = NetItem->mutable_type();
type->set_mat_type(DfItem->getType());
type->set_mat_index(DfItem->getSubtype());
}
void CopyItems(df::map_block * DfBlock, RemoteFortressReader::MapBlock * NetBlock, MapExtras::MapCache * MC, DFCoord pos)
{
NetBlock->set_map_x(DfBlock->map_pos.x);
NetBlock->set_map_y(DfBlock->map_pos.y);
NetBlock->set_map_z(DfBlock->map_pos.z);
for (int i = 0; i < DfBlock->items.size(); i++)
{
int id = DfBlock->items[i];
auto item = df::item::find(id);
if(item)
CopyItem(NetBlock->add_items(), item);
}
}
static command_result GetBlockList(color_ostream &stream, const BlockRequest *in, BlockList *out) static command_result GetBlockList(color_ostream &stream, const BlockRequest *in, BlockList *out)
{ {
int x, y, z; int x, y, z;
@ -1518,6 +1593,7 @@ static command_result GetBlockList(color_ostream &stream, const BlockRequest *in
bool desChanged = IsDesignationChanged(pos); bool desChanged = IsDesignationChanged(pos);
bool spatterChanged = IsspatterChanged(pos); bool spatterChanged = IsspatterChanged(pos);
bool buildingChanged = IsBuildingChanged(pos); bool buildingChanged = IsBuildingChanged(pos);
bool itemsChanged = areItemsChanged(&block->items);
//bool bldChanged = IsBuildingChanged(pos); //bool bldChanged = IsBuildingChanged(pos);
RemoteFortressReader::MapBlock *net_block; RemoteFortressReader::MapBlock *net_block;
if (tileChanged || desChanged || spatterChanged || buildingChanged) if (tileChanged || desChanged || spatterChanged || buildingChanged)
@ -1533,6 +1609,8 @@ static command_result GetBlockList(color_ostream &stream, const BlockRequest *in
CopyBuildings(block, net_block, &MC, pos); CopyBuildings(block, net_block, &MC, pos);
if (spatterChanged) if (spatterChanged)
Copyspatters(block, net_block, &MC, pos); Copyspatters(block, net_block, &MC, pos);
if (itemsChanged)
CopyItems(block, net_block, &MC, pos);
} }
} }
} }