Support removing zoomers
This commit is contained in:
parent
dacf1ca095
commit
528a8b4385
1 changed files with 83 additions and 19 deletions
|
|
@ -273,6 +273,19 @@ namespace gmtk
|
|||
return l.coords[0] >= 0 && l.coords[0] < max && l.coords[1] >= 0 && l.coords[1] < max;
|
||||
}
|
||||
|
||||
bool within_tile(location const & tile, location const & l)
|
||||
{
|
||||
if (l.level < tile.level)
|
||||
return false;
|
||||
|
||||
int s = std::pow(3, l.level - tile.level);
|
||||
|
||||
geom::interval xrange{tile.coords[0] * s, (tile.coords[0] + 1) * s - 1};
|
||||
geom::interval yrange{tile.coords[1] * s, (tile.coords[1] + 1) * s - 1};
|
||||
|
||||
return geom::contains(xrange, l.coords[0]) && geom::contains(yrange, l.coords[1]);
|
||||
}
|
||||
|
||||
struct lab
|
||||
{
|
||||
psemek_ecs_declare_uuid("lab")
|
||||
|
|
@ -444,6 +457,75 @@ namespace gmtk
|
|||
sink(world, c, m);
|
||||
}
|
||||
|
||||
void clear_tile(map & map, location const & l)
|
||||
{
|
||||
auto entity = map.world.index<index>().find(l);
|
||||
if (!entity)
|
||||
return;
|
||||
|
||||
auto acc = map.world.get(*entity);
|
||||
|
||||
if (acc.contains<source>() || acc.contains<lab>())
|
||||
return;
|
||||
|
||||
if (acc.contains<crossing>())
|
||||
map.put_card(card_type::crossing);
|
||||
else if (acc.contains<zoomer>())
|
||||
{
|
||||
map.put_card(card_type::zoomer);
|
||||
// TODO: CLEAR ZOOMER
|
||||
|
||||
for (int y = 0; y < 3; ++y)
|
||||
{
|
||||
for (int x = 0; x < 3; ++x)
|
||||
{
|
||||
location p{l.level + 1, {3 * l.coords[0] + x, 3 * l.coords[1] + y}};
|
||||
clear_tile(map, p);
|
||||
}
|
||||
}
|
||||
|
||||
auto & index = map.world.index<path_index>();
|
||||
|
||||
for (int y = 0; y < 9; ++y)
|
||||
{
|
||||
for (int x = 0; x < 9; ++x)
|
||||
{
|
||||
location p{l.level + 2, {9 * l.coords[0] + x, 9 * l.coords[1] + y}};
|
||||
|
||||
if (auto e = index.find(p))
|
||||
{
|
||||
auto & v = map.world.get(*e).get<path_vertex>();
|
||||
|
||||
for (auto to : v.belts_to)
|
||||
{
|
||||
auto & tv = map.world.get(to).get<path_vertex>();
|
||||
if (!within_tile(l, tv.location))
|
||||
remove_belt(map.world, to, *tv.belts_to.begin());
|
||||
remove_belt(map.world, *e, to);
|
||||
}
|
||||
|
||||
for (auto from : v.belts_from)
|
||||
{
|
||||
auto & fv = map.world.get(from).get<path_vertex>();
|
||||
if (!within_tile(l, fv.location))
|
||||
remove_belt(map.world, *fv.belts_from.begin(), from);
|
||||
remove_belt(map.world, from, *e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (auto t = acc.get_if<transformer>())
|
||||
{
|
||||
if (t->type == transformer_type::furnace)
|
||||
map.put_card(card_type::furnace);
|
||||
else if (t->type == transformer_type::factory)
|
||||
map.put_card(card_type::factory);
|
||||
}
|
||||
|
||||
map.world.destroy(*entity);
|
||||
}
|
||||
|
||||
map starting_map()
|
||||
{
|
||||
map result;
|
||||
|
|
@ -893,25 +975,7 @@ namespace gmtk
|
|||
{
|
||||
if (selected_)
|
||||
{
|
||||
if (auto entity = map_.world.index<index>().find(*selected_))
|
||||
{
|
||||
auto acc = map_.world.get(*entity);
|
||||
if (!acc.contains<source>() && !acc.contains<lab>() && !acc.contains<zoomer>())
|
||||
{
|
||||
if (acc.contains<crossing>())
|
||||
map_.put_card(card_type::crossing);
|
||||
else if (acc.contains<zoomer>())
|
||||
map_.put_card(card_type::zoomer);
|
||||
else if (auto t = acc.get_if<transformer>())
|
||||
{
|
||||
if (t->type == transformer_type::furnace)
|
||||
map_.put_card(card_type::furnace);
|
||||
else if (t->type == transformer_type::factory)
|
||||
map_.put_card(card_type::factory);
|
||||
}
|
||||
map_.world.destroy(*entity);
|
||||
}
|
||||
}
|
||||
clear_tile(map_, *selected_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue