Allocate sky blocks when needed.

Allow stairs to be designated on top of each other in open space.
develop
Anuradha Dissanayake 2013-01-01 15:45:52 +13:00
parent 1ed129e1a7
commit a1eadd0f08
1 changed files with 64 additions and 16 deletions

@ -318,33 +318,51 @@ static bool is_orthogonal_to_pending_construction(building_site &site)
return false; return false;
} }
static bool is_valid_building_site(building_site &site, bool orthogonal_check, bool check_placed_constructions, bool in_future_placement_mode) static df::building_constructionst *get_construction_on_tile(const df::coord &pos)
{ {
if (!Maps::isValidTilePos(site.pos)) auto current = Buildings::findAtTile(pos);
return false; if (current)
return strict_virtual_cast<df::building_constructionst>(current);
return NULL;
}
static df::tiletype *read_tile_shapes(const df::coord &pos, df::tiletype_shape &shape, df::tiletype_shape_basic &shape_basic)
{
if (!Maps::isValidTilePos(pos))
return NULL;
auto ttype = Maps::getTileType(site.pos); auto ttype = Maps::getTileType(pos);
if (!ttype) if (!ttype)
return false; return NULL;
auto shape = tileShape(*ttype); shape = tileShape(*ttype);
auto shapeBasic = tileShapeBasic(shape); shape_basic = tileShapeBasic(shape);
if (shapeBasic == tiletype_shape_basic::Open) return ttype;
}
static bool is_valid_building_site(building_site &site, bool orthogonal_check, bool check_placed_constructions, bool in_future_placement_mode)
{
df::tiletype_shape shape;
df::tiletype_shape_basic shape_basic;
auto ttype = read_tile_shapes(site.pos, shape, shape_basic);
if (!ttype)
return false;
if (shape_basic == tiletype_shape_basic::Open)
{ {
if (orthogonal_check) if (orthogonal_check)
{ {
// Check if this is a valid tile to have a construction placed orthogonally to it
if (!in_future_placement_mode) if (!in_future_placement_mode)
return false; return false;
auto current = Buildings::findAtTile(site.pos); df::building_constructionst *cons = get_construction_on_tile(site.pos);
if (current) if (cons && cons == construction_type::Floor)
{ {
auto cons = strict_virtual_cast<df::building_constructionst>(current);
if (!cons || cons->type != construction_type::Floor)
return false;
site.in_open_air = true; site.in_open_air = true;
return true; return true;
} }
@ -352,6 +370,35 @@ static bool is_valid_building_site(building_site &site, bool orthogonal_check, b
return false; return false;
} }
// Stairs can be placed in open space, if they can connect to other stairs
df::tiletype_shape shape_s;
df::tiletype_shape_basic shape_basic_s;
if (ui_build_selector->building_subtype == construction_type::DownStair ||
ui_build_selector->building_subtype == construction_type::UpDownStair)
{
df::coord below(site.pos.x, site.pos.y, site.pos.z - 1);
auto ttype_s = read_tile_shapes(below, shape_s, shape_basic_s);
if (ttype_s)
{
if (shape_s == tiletype_shape::STAIR_UP || shape_s == tiletype_shape::STAIR_UPDOWN)
return true;
}
}
if (ui_build_selector->building_subtype == construction_type::UpStair ||
ui_build_selector->building_subtype == construction_type::UpDownStair)
{
df::coord above(site.pos.x, site.pos.y, site.pos.z + 1);
auto ttype_s = read_tile_shapes(above, shape_s, shape_basic_s);
if (ttype_s)
{
if (shape_s == tiletype_shape::STAIR_DOWN || shape_s == tiletype_shape::STAIR_UPDOWN)
return true;
}
}
// Check if there is a valid tile orthogonally adjacent
bool valid_orthogonal_tile_found = false; bool valid_orthogonal_tile_found = false;
df::coord orthagonal_pos; df::coord orthagonal_pos;
orthagonal_pos.z = site.pos.z; orthagonal_pos.z = site.pos.z;
@ -382,7 +429,7 @@ static bool is_valid_building_site(building_site &site, bool orthogonal_check, b
} }
else if (orthogonal_check) else if (orthogonal_check)
{ {
if (shape != tiletype_shape::RAMP && shapeBasic != tiletype_shape_basic::Floor) if (shape != tiletype_shape::RAMP && shape_basic != tiletype_shape_basic::Floor)
return false; return false;
} }
else else
@ -395,7 +442,7 @@ static bool is_valid_building_site(building_site &site, bool orthogonal_check, b
} }
else else
{ {
if (shapeBasic != tiletype_shape_basic::Floor) if (shape_basic != tiletype_shape_basic::Floor)
return false; return false;
if (material == tiletype_material::CONSTRUCTION) if (material == tiletype_material::CONSTRUCTION)
@ -544,6 +591,7 @@ static bool designate_new_construction(df::coord &pos, df::construction_type &ty
vector<df::item*> items; vector<df::item*> items;
items.push_back(item); items.push_back(item);
Maps::ensureTileBlock(pos);
if (!Buildings::constructWithItems(newinst, items)) if (!Buildings::constructWithItems(newinst, items))
{ {