develop
Petr Mrázek 2013-04-24 17:36:22 +02:00
commit 222c61ab25
2 changed files with 98 additions and 71 deletions

@ -53,7 +53,7 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <Plug
{ {
//// Fill the command list with your commands. //// Fill the command list with your commands.
//commands.push_back(PluginCommand( //commands.push_back(PluginCommand(
// "isoworldremote", "Do nothing, look pretty.", // "isoworldremote", "Dump north-west embark tile to text file for debug purposes.",
// isoWorldRemote, false, /* true means that the command can't be used from non-interactive user interface */ // isoWorldRemote, false, /* true means that the command can't be used from non-interactive user interface */
// // Extended help string. Used by CR_WRONG_USAGE and the help command: // // Extended help string. Used by CR_WRONG_USAGE and the help command:
// " This command does nothing at all.\n" // " This command does nothing at all.\n"
@ -163,8 +163,6 @@ DFhackCExport command_result plugin_onupdate ( color_ostream &out )
// } // }
// debug_text << std::endl; // debug_text << std::endl;
// } // }
// //clean everything up.
// google::protobuf::ShutdownProtobufLibrary();
// // Give control back to DF. // // Give control back to DF.
// return CR_OK; // return CR_OK;
//} //}
@ -218,89 +216,112 @@ static command_result GetEmbarkInfo(color_ostream &stream, const MapRequest *in,
} }
int coord_to_index_48(int x, int y) { int coord_to_index_48(int x, int y) {
return y*48+x; return y*48+x;
} }
bool gather_embark_tile(int EmbX, int EmbY, EmbarkTile * tile, MapExtras::MapCache * MP) { bool gather_embark_tile(int EmbX, int EmbY, EmbarkTile * tile, MapExtras::MapCache * MP) {
tile->set_is_valid(false); tile->set_is_valid(false);
tile->set_world_x(df::global::world->map.region_x + (EmbX/3)); //fixme: verify. tile->set_world_x(df::global::world->map.region_x + (EmbX/3));
tile->set_world_y(df::global::world->map.region_y + (EmbY/3)); //fixme: verify. tile->set_world_y(df::global::world->map.region_y + (EmbY/3));
tile->set_world_z(df::global::world->map.region_z); //fixme: verify. tile->set_world_z(df::global::world->map.region_z + 1); //adding one because floors get shifted one downwards.
tile->set_current_year(*df::global::cur_year); tile->set_current_year(*df::global::cur_year);
tile->set_current_season(*df::global::cur_season); tile->set_current_season(*df::global::cur_season);
int num_valid_layers = 0; int num_valid_layers = 0;
for(int z = 0; z < MP->maxZ(); z++) for(int z = 0; z < MP->maxZ(); z++)
{ {
EmbarkTileLayer * tile_layer = tile->add_tile_layer(); EmbarkTileLayer * tile_layer = tile->add_tile_layer();
num_valid_layers += gather_embark_tile_layer(EmbX, EmbY, z, tile_layer, MP); num_valid_layers += gather_embark_tile_layer(EmbX, EmbY, z, tile_layer, MP);
} }
if(num_valid_layers > 0) if(num_valid_layers > 0)
tile->set_is_valid(true); tile->set_is_valid(true);
return 1; return 1;
} }
bool gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * tile, MapExtras::MapCache * MP) bool gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * tile, MapExtras::MapCache * MP)
{ {
for(int i = tile->mat_type_table_size(); i < 2304; i++) { //This is needed so we have a full array to work with, otherwise the size isn't updated correctly. for(int i = tile->mat_type_table_size(); i < 2304; i++) { //This is needed so we have a full array to work with, otherwise the size isn't updated correctly.
tile->add_mat_type_table(AIR); tile->add_mat_type_table(AIR);
tile->add_mat_subtype_table(0); tile->add_mat_subtype_table(0);
} }
int num_valid_blocks = 0; int num_valid_blocks = 0;
for(int yy = 0; yy < 3; yy++) { for(int yy = 0; yy < 3; yy++) {
for(int xx = 0; xx < 3; xx++) { for(int xx = 0; xx < 3; xx++) {
DFCoord current_coord; DFCoord current_coord, upper_coord;
current_coord.x = EmbX+xx; current_coord.x = EmbX+xx;
current_coord.y = EmbY+yy; current_coord.y = EmbY+yy;
current_coord.z = EmbZ; current_coord.z = EmbZ;
MapExtras::Block * b = MP->BlockAt(current_coord); upper_coord = current_coord;
if(b && b->getRaw()) { upper_coord.z += 1;
for(int block_y=0; block_y<16; block_y++) { MapExtras::Block * b = MP->BlockAt(current_coord);
for(int block_x=0; block_x<16; block_x++) { MapExtras::Block * b_upper = MP->BlockAt(upper_coord);
df::coord2d block_coord; if(b && b->getRaw()) {
block_coord.x = block_x; for(int block_y=0; block_y<16; block_y++) {
block_coord.y = block_y; for(int block_x=0; block_x<16; block_x++) {
DFHack::t_matpair actual_mat = b->staticMaterialAt(block_coord); df::coord2d block_coord;
df::tiletype tile_type = b->tiletypeAt(block_coord); block_coord.x = block_x;
df::tile_designation designation = b->DesignationAt(block_coord); block_coord.y = block_y;
unsigned int array_index = coord_to_index_48(xx*16+block_x, yy*16+block_y); df::tiletype tile_type = b->tiletypeAt(block_coord);
//make a new fake material at the given index df::tiletype upper_tile = df::tiletype::Void;
if(tileMaterial(tile_type) == tiletype_material::FROZEN_LIQUID) { //Ice. if(b_upper && b_upper->getRaw()) {
tile->set_mat_type_table(array_index, BasicMaterial::LIQUID); //Ice is totally a liquid, shut up. upper_tile = b_upper->tiletypeAt(block_coord);
tile->set_mat_subtype_table(array_index, 0); }
num_valid_blocks++; df::tile_designation designation = b->DesignationAt(block_coord);
} DFHack::t_matpair actual_mat;
else if(designation.bits.flow_size) { //Contains either water or lava. if(tileShapeBasic(tileShape(upper_tile)) == tiletype_shape_basic::Floor && (tileMaterial(tile_type) != tiletype_material::FROZEN_LIQUID) && (tileMaterial(tile_type) != tiletype_material::BROOK)) { //if the upper tile is a floor, use that material instead. Unless it's ice.
tile->set_mat_type_table(array_index, BasicMaterial::LIQUID); actual_mat = b_upper->staticMaterialAt(block_coord);
if(designation.bits.liquid_type) //Magma }
tile->set_mat_subtype_table(array_index, 2); else {
else //water actual_mat = b->staticMaterialAt(block_coord);
tile->set_mat_subtype_table(array_index, 1); }
if(((tileMaterial(tile_type) == tiletype_material::FROZEN_LIQUID) || (tileMaterial(tile_type) == tiletype_material::BROOK)) && (tileShapeBasic(tileShape(tile_type)) == tiletype_shape_basic::Floor)) {
tile_type = tiletype::OpenSpace;
}
unsigned int array_index = coord_to_index_48(xx*16+block_x, yy*16+block_y);
//make a new fake material at the given index
if(tileMaterial(tile_type) == tiletype_material::FROZEN_LIQUID && !((tileShapeBasic(tileShape(upper_tile)) == tiletype_shape_basic::Floor) && (tileMaterial(upper_tile) != tiletype_material::FROZEN_LIQUID))) { //Ice.
tile->set_mat_type_table(array_index, BasicMaterial::LIQUID); //Ice is totally a liquid, shut up.
tile->set_mat_subtype_table(array_index, LiquidType::ICE);
num_valid_blocks++; num_valid_blocks++;
} }
else if(tileShapeBasic(tileShape(tile_type)) != tiletype_shape_basic::Open) { else if(designation.bits.flow_size && (tileShapeBasic(tileShape(upper_tile)) != tiletype_shape_basic::Floor)) { //Contains either water or lava.
if(actual_mat.mat_type == builtin_mats::INORGANIC) { //inorganic tile->set_mat_type_table(array_index, BasicMaterial::LIQUID);
tile->set_mat_type_table(array_index, BasicMaterial::INORGANIC); if(designation.bits.liquid_type) //Magma
tile->set_mat_subtype_table(array_index, actual_mat.mat_index); tile->set_mat_subtype_table(array_index, LiquidType::MAGMA);
} else //water
else if(actual_mat.mat_type >= 419) { //Wooden constructions. Different from growing plants. tile->set_mat_subtype_table(array_index, LiquidType::WATER);
tile->set_mat_type_table(array_index, BasicMaterial::WOOD);
tile->set_mat_subtype_table(array_index, actual_mat.mat_index);
}
else { //Unknown and unsupported stuff. Will just be drawn as grey.
tile->set_mat_type_table(array_index, BasicMaterial::OTHER);
tile->set_mat_subtype_table(array_index, actual_mat.mat_type);
}
num_valid_blocks++; num_valid_blocks++;
} }
else { else if(((tileShapeBasic(tileShape(tile_type)) != tiletype_shape_basic::Open) ||
tile->set_mat_type_table(array_index, BasicMaterial::AIR); (tileShapeBasic(tileShape(upper_tile)) == tiletype_shape_basic::Floor)) &&
} ((tileShapeBasic(tileShape(tile_type)) != tiletype_shape_basic::Floor) ||
} (tileShapeBasic(tileShape(upper_tile)) == tiletype_shape_basic::Floor))) { //if the upper tile is a floor, we don't skip, otherwise we do.
} if(actual_mat.mat_type == builtin_mats::INORGANIC) { //inorganic
} tile->set_mat_type_table(array_index, BasicMaterial::INORGANIC);
} tile->set_mat_subtype_table(array_index, actual_mat.mat_index);
} }
else if(actual_mat.mat_type == 419) { //Growing plants
tile->set_mat_type_table(array_index, BasicMaterial::PLANT);
tile->set_mat_subtype_table(array_index, actual_mat.mat_index);
}
else if(actual_mat.mat_type >= 420) { //Wooden constructions. Different from growing plants.
tile->set_mat_type_table(array_index, BasicMaterial::WOOD);
tile->set_mat_subtype_table(array_index, actual_mat.mat_index);
}
else { //Unknown and unsupported stuff. Will just be drawn as grey.
tile->set_mat_type_table(array_index, BasicMaterial::OTHER);
tile->set_mat_subtype_table(array_index, actual_mat.mat_type);
}
num_valid_blocks++;
}
else {
tile->set_mat_type_table(array_index, BasicMaterial::AIR);
}
}
}
}
}
}
return (num_valid_blocks >0); return (num_valid_blocks >0);
} }
@ -333,8 +354,8 @@ static command_result GetRawNames(color_ostream &stream, const MapRequest *in, R
out->set_available(false); out->set_available(false);
return CR_OK; return CR_OK;
} }
out->set_available(true); out->set_available(true);
for(int i = 0; i < df::global::world->raws.inorganics.size(); i++){ for(int i = 0; i < df::global::world->raws.inorganics.size(); i++){
out->add_inorganic(df::global::world->raws.inorganics[i]->id); out->add_inorganic(df::global::world->raws.inorganics[i]->id);
} }

@ -12,6 +12,12 @@ enum BasicMaterial {
WOOD = 5; WOOD = 5;
}; };
enum LiquidType {
ICE = 0;
WATER = 1;
MAGMA = 2;
}
message EmbarkTileLayer { message EmbarkTileLayer {
repeated BasicMaterial mat_type_table = 4 [packed=true]; repeated BasicMaterial mat_type_table = 4 [packed=true];
repeated int32 mat_subtype_table = 5 [packed=true]; repeated int32 mat_subtype_table = 5 [packed=true];