From 528a8b43852603585974fc1a722656958592f1cb Mon Sep 17 00:00:00 2001 From: lisyarus Date: Mon, 19 Aug 2024 12:29:25 +0300 Subject: [PATCH] Support removing zoomers --- source/application.cpp | 102 +++++++++++++++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 19 deletions(-) diff --git a/source/application.cpp b/source/application.cpp index b22acb7..c22b0b9 100644 --- a/source/application.cpp +++ b/source/application.cpp @@ -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().find(l); + if (!entity) + return; + + auto acc = map.world.get(*entity); + + if (acc.contains() || acc.contains()) + return; + + if (acc.contains()) + map.put_card(card_type::crossing); + else if (acc.contains()) + { + 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(); + + 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(); + + for (auto to : v.belts_to) + { + auto & tv = map.world.get(to).get(); + 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(); + 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()) + { + 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().find(*selected_)) - { - auto acc = map_.world.get(*entity); - if (!acc.contains() && !acc.contains() && !acc.contains()) - { - if (acc.contains()) - map_.put_card(card_type::crossing); - else if (acc.contains()) - map_.put_card(card_type::zoomer); - else if (auto t = acc.get_if()) - { - 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_); } } }